From a81c7e6e5b2fe2c4d9cf228bf874a4ac0cd8327c Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 29 Mar 2016 10:57:50 +0200 Subject: [PATCH] Added preset export/import to/from base64 text file --- .gitignore | 1 + sdrbase/mainwindow.cpp | 80 ++++++++++++++++++ sdrbase/mainwindow.h | 2 + sdrbase/mainwindow.ui | 153 ++++++++++++++--------------------- sdrbase/resources/export.png | Bin 0 -> 1075 bytes sdrbase/resources/import.png | Bin 0 -> 1049 bytes sdrbase/resources/res.qrc | 3 + 7 files changed, 147 insertions(+), 92 deletions(-) create mode 100644 sdrbase/resources/export.png create mode 100644 sdrbase/resources/import.png diff --git a/.gitignore b/.gitignore index 5901da274..1eedf653a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ CMakeLists.txt.user* build/* qtbuild/* sdriq/* +presets/* LOCAL/* sdrangelove.supp .cproject diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 04b6c0065..659d292f4 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -19,6 +19,10 @@ #include #include #include +#include +#include +#include + #include "mainwindow.h" #include "ui_mainwindow.h" #include "audio/audiodeviceinfo.h" @@ -529,6 +533,82 @@ void MainWindow::on_presetUpdate_clicked() } } +void MainWindow::on_presetExport_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if(item != 0) { + if(item->type() == PItem) + { + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); + QString base64Str = preset->serialize().toBase64(); + QString fileName = QFileDialog::getSaveFileName(this, + tr("Open preset export file"), ".", tr("Preset export files (*.prex)")); + + if (fileName != "") + { + QFile exportFile(fileName); + + if (exportFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream outstream(&exportFile); + outstream << base64Str; + exportFile.close(); + } + else + { + QMessageBox::information(this, tr("Message"), tr("Cannot open file for writing")); + } + } + } + } +} + +void MainWindow::on_presetImport_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if(item != 0) + { + QString group; + + if (item->type() == PGroup) { + group = item->text(0); + } else if (item->type() == PItem) { + group = item->parent()->text(0); + } else { + return; + } + + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open preset export file"), ".", tr("Preset export files (*.prex)")); + + if (fileName != "") + { + QFile exportFile(fileName); + + if (exportFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QByteArray base64Str; + QTextStream instream(&exportFile); + instream >> base64Str; + exportFile.close(); + + Preset* preset = new Preset(); + preset->deserialize(QByteArray::fromBase64(base64Str)); + preset->setGroup(group); + + savePresetSettings(preset); + ui->presetTree->setCurrentItem(addPresetToTree(preset)); + } + else + { + QMessageBox::information(this, tr("Message"), tr("Cannot open file for reading")); + } + } + } +} + void MainWindow::on_settingsSave_clicked() { saveSettings(); diff --git a/sdrbase/mainwindow.h b/sdrbase/mainwindow.h index 88f5f45db..585c9c826 100644 --- a/sdrbase/mainwindow.h +++ b/sdrbase/mainwindow.h @@ -144,6 +144,8 @@ private slots: void on_action_View_Fullscreen_toggled(bool checked); void on_presetSave_clicked(); void on_presetUpdate_clicked(); + void on_presetExport_clicked(); + void on_presetImport_clicked(); void on_settingsSave_clicked(); void on_presetLoad_clicked(); void on_presetDelete_clicked(); diff --git a/sdrbase/mainwindow.ui b/sdrbase/mainwindow.ui index 6d033638b..41bbd3b58 100644 --- a/sdrbase/mainwindow.ui +++ b/sdrbase/mainwindow.ui @@ -33,16 +33,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -75,7 +66,7 @@ 0 0 1012 - 22 + 20 @@ -180,16 +171,7 @@ - - 2 - - - 2 - - - 2 - - + 2 @@ -215,7 +197,7 @@ - + Load selected preset @@ -235,7 +217,7 @@ - + Qt::Horizontal @@ -248,7 +230,7 @@ - + Delete selected preset @@ -268,7 +250,7 @@ - + true @@ -305,7 +287,7 @@ - + Qt::Horizontal @@ -338,6 +320,47 @@ + + + + Export current preset to file + + + + + + + :/export.png:/export.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Import preset from file into current group + + + + + + + :/import.png:/import.png + + + @@ -359,16 +382,7 @@ 3 - - 2 - - - 2 - - - 2 - - + 2 @@ -399,16 +413,7 @@ 3 - - 2 - - - 2 - - - 2 - - + 2 @@ -439,16 +444,7 @@ 3 - - 2 - - - 2 - - - 2 - - + 2 @@ -469,10 +465,7 @@ E&xit - - Sans Serif - 9 - + Ctrl+Q @@ -483,10 +476,7 @@ &Start - - Sans Serif - 9 - + F5 @@ -497,10 +487,7 @@ &Stop - - Sans Serif - 9 - + F6 @@ -514,10 +501,7 @@ &Fullscreen - - Sans Serif - 9 - + F11 @@ -539,10 +523,7 @@ &About SDRangel... - - Sans Serif - 9 - + @@ -550,10 +531,7 @@ &Preferences... - - Sans Serif - 9 - + @@ -561,10 +539,7 @@ Loaded &Plugins... - - Sans Serif - 9 - + @@ -572,10 +547,7 @@ Start Recording - - Sans Serif - 9 - + F7 @@ -586,10 +558,7 @@ Stop Recording - - Sans Serif - 9 - + F8 diff --git a/sdrbase/resources/export.png b/sdrbase/resources/export.png new file mode 100644 index 0000000000000000000000000000000000000000..da915cbe9df8526eed9decbdddd75a36d74513f2 GIT binary patch literal 1075 zcmV-31kC%1P)3clWe-#WQji^B;rqu6e|J22oWY_y5gd3QA44Ws;~wvC`tuU z#8^a89}50}J_r)%gEl2?lk~w*(h@`TrRiI;2(eADNvuk2jj2t^EiQy$ry_79b+(>bgf{vkRJ;v!3U@wQt`uV~dNI(b94o zYpnr*05AX+0r{&pLS9BTyMRpQITOJBkw|2Cc=+TIKw@HIQVStOAV2^}1d$_9ykTf9 z%KuBlFy6j!;o|wZxw+%Jb1Mu!rKn5gQ&aqJDk zp6Aij)QsU5;5KsH5_m_B?k^16u$3&Y?|h00Fqmf1Ar-| ze4|v-pVx9g0AxHKr;(9S-}Ah8Ow)WH{~fN_tm8*UM*TvekiJQB0Qk0+0A0QM8y`D1 z6tyht%bOrBG4odg1J7r`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