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 000000000..da915cbe9 Binary files /dev/null and b/sdrbase/resources/export.png differ diff --git a/sdrbase/resources/import.png b/sdrbase/resources/import.png new file mode 100644 index 000000000..de24a88c7 Binary files /dev/null and b/sdrbase/resources/import.png differ diff --git a/sdrbase/resources/res.qrc b/sdrbase/resources/res.qrc index 36cd44bd4..dc3d2a5f2 100644 --- a/sdrbase/resources/res.qrc +++ b/sdrbase/resources/res.qrc @@ -1,5 +1,8 @@ + res.qrc + export.png + import.png compressed.png locked.png appicon.png