diff --git a/sdrbase/commands/command.h b/sdrbase/commands/command.h index 194f99d3f..8010b2360 100644 --- a/sdrbase/commands/command.h +++ b/sdrbase/commands/command.h @@ -58,7 +58,7 @@ public: bool getRelease() const { return m_release; } QString getKeyLabel() const; - void run(const QString& apiAddress, int apiPort, int deviceSetIndex); + void run(const QString& apiAddress, int apiPort, int deviceSetIndex = 0); void kill(); QProcess::ProcessState getLastProcessState() const; bool getLastProcessError(QProcess::ProcessError& error) const; diff --git a/sdrbase/maincore.h b/sdrbase/maincore.h index 37ca9d563..1ed670e70 100644 --- a/sdrbase/maincore.h +++ b/sdrbase/maincore.h @@ -742,6 +742,7 @@ public: friend class MainServer; friend class MainWindow; friend class WebAPIAdapter; + friend class CommandsDialog; signals: void deviceSetAdded(int index, DeviceAPI *device); diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 2b8a85c4a..3a58139d0 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -21,6 +21,7 @@ set(sdrgui_SOURCES gui/clickablelabel.cpp gui/colormapper.cpp gui/commanditem.cpp + gui/commandsdialog.cpp gui/commandoutputdialog.cpp gui/crightclickenabler.cpp gui/customtextedit.cpp @@ -117,6 +118,7 @@ set(sdrgui_HEADERS gui/channelwindow.h gui/colormapper.h gui/commanditem.h + gui/commandsdialog.h gui/commandoutputdialog.h gui/crightclickenabler.h gui/customtextedit.h @@ -208,6 +210,7 @@ set(sdrgui_FORMS gui/basicdevicesettingsdialog.ui gui/basicfeaturesettingsdialog.ui gui/channeladddialog.ui + gui/commandsdialog.ui gui/commandoutputdialog.ui gui/cwkeyergui.ui gui/devicestreamselectiondialog.ui diff --git a/sdrgui/gui/commandsdialog.cpp b/sdrgui/gui/commandsdialog.cpp new file mode 100644 index 000000000..6efab2cb5 --- /dev/null +++ b/sdrgui/gui/commandsdialog.cpp @@ -0,0 +1,318 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2022 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "commands/command.h" +#include "commands/commandkeyreceiver.h" +#include "editcommanddialog.h" +#include "addpresetdialog.h" +#include "commandoutputdialog.h" +#include "commanditem.h" +#include "maincore.h" +#include "mainwindow.h" + +#include "commandsdialog.h" +#include "ui_commandsdialog.h" + +CommandsDialog::CommandsDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::CommandsDialog), + m_apiHost("127.0.0.1"), + m_apiPort(8091), + m_commandKeyReceiver(nullptr) +{ + ui->setupUi(this); + ui->commandKeyboardConnect->hide(); // FIXME +} + +CommandsDialog::~CommandsDialog() +{ + delete ui; +} + +void CommandsDialog::populateTree() +{ + MainCore::instance()->m_settings.sortCommands(); + ui->commandTree->clear(); + QTreeWidgetItem *treeItem; + + for (int i = 0; i < MainCore::instance()->m_settings.getCommandCount(); ++i) { + treeItem = addCommandToTree(MainCore::instance()->m_settings.getCommand(i)); + } +} + +void CommandsDialog::on_commandNew_clicked() +{ + QStringList groups; + QString group = ""; + QString description = ""; + + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { + groups.append(ui->commandTree->topLevelItem(i)->text(0)); + } + + QTreeWidgetItem* item = ui->commandTree->currentItem(); + + if(item != 0) + { + if(item->type() == PGroup) { + group = item->text(0); + } else if(item->type() == PItem) { + group = item->parent()->text(0); + description = item->text(0); + } + } + + Command *command = new Command(); + command->setGroup(group); + command->setDescription(description); + EditCommandDialog editCommandDialog(groups, group, this); + editCommandDialog.fromCommand(*command); + + if (editCommandDialog.exec() == QDialog::Accepted) + { + editCommandDialog.toCommand(*command); + MainCore::instance()->m_settings.addCommand(command); + ui->commandTree->setCurrentItem(addCommandToTree(command)); + MainCore::instance()->m_settings.sortCommands(); + } +} + +void CommandsDialog::on_commandDuplicate_clicked() +{ + QTreeWidgetItem* item = ui->commandTree->currentItem(); + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + Command *commandCopy = new Command(*command); + MainCore::instance()->m_settings.addCommand(commandCopy); + ui->commandTree->setCurrentItem(addCommandToTree(commandCopy)); + MainCore::instance()->m_settings.sortCommands(); +} + +void CommandsDialog::on_commandEdit_clicked() +{ + QTreeWidgetItem* item = ui->commandTree->currentItem(); + bool change = false; + const Command *changedCommand = 0; + QString newGroupName; + + QStringList groups; + + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { + groups.append(ui->commandTree->topLevelItem(i)->text(0)); + } + + if(item != 0) + { + if (item->type() == PItem) + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + + if (command != 0) + { + EditCommandDialog editCommandDialog(groups, command->getGroup(), this); + editCommandDialog.fromCommand(*command); + + if (editCommandDialog.exec() == QDialog::Accepted) + { + Command* command_mod = const_cast(command); + editCommandDialog.toCommand(*command_mod); + change = true; + changedCommand = command; + } + } + } + else if (item->type() == PGroup) + { + AddPresetDialog dlg(groups, item->text(0), this); + dlg.showGroupOnly(); + dlg.setDialogTitle("Edit command group"); + dlg.setDescriptionBoxTitle("Command details"); + + if (dlg.exec() == QDialog::Accepted) + { + MainCore::instance()->m_settings.renameCommandGroup(item->text(0), dlg.group()); + newGroupName = dlg.group(); + change = true; + } + } + } + + if (change) + { + MainCore::instance()->m_settings.sortCommands(); + ui->commandTree->clear(); + + for (int i = 0; i < MainCore::instance()->m_settings.getCommandCount(); ++i) + { + QTreeWidgetItem *item_x = addCommandToTree(MainCore::instance()->m_settings.getCommand(i)); + const Command* command_x = qvariant_cast(item_x->data(0, Qt::UserRole)); + if (changedCommand && (command_x == changedCommand)) { // set cursor on changed command + ui->commandTree->setCurrentItem(item_x); + } + } + + if (!changedCommand) // on group name change set cursor on the group that has been changed + { + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = ui->commandTree->topLevelItem(i); + + if (item->text(0) == newGroupName) { + ui->commandTree->setCurrentItem(item); + } + } + } + } +} + +void CommandsDialog::on_commandRun_clicked() +{ + QTreeWidgetItem* item = ui->commandTree->currentItem(); + + if (item) + { + if (item->type() == PItem) // run individual command + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + Command* command_mod = const_cast(command); + command_mod->run(m_apiHost, m_apiPort); + } + else if (item->type() == PGroup) // run all commands in this group + { + QString group = item->text(0); + + for (int i = 0; i < MainCore::instance()->m_settings.getCommandCount(); ++i) + { + Command *command_mod = const_cast(MainCore::instance()->m_settings.getCommand(i)); + + if (command_mod->getGroup() == group) { + command_mod->run(m_apiHost, m_apiPort); + } + } + } + } +} + +void CommandsDialog::on_commandOutput_clicked() +{ + QTreeWidgetItem* item = ui->commandTree->currentItem(); + + if ((item != 0) && (item->type() == PItem)) + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + Command* command_mod = const_cast(command); + CommandOutputDialog commandOutputDialog(*command_mod); + commandOutputDialog.exec(); + } +} + +void CommandsDialog::on_commandsSave_clicked() +{ + MainCore::instance()->m_settings.save(); +} + +void CommandsDialog::on_commandDelete_clicked() +{ + QTreeWidgetItem* item = ui->commandTree->currentItem(); + + if (item != 0) + { + if (item->type() == PItem) // delete individual command + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + + if(command) + { + if (QMessageBox::question(this, + tr("Delete command"), + tr("Do you want to delete command '%1'?") + .arg(command->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + delete item; + MainCore::instance()->m_settings.deleteCommand(command); + } + } + } + else if (item->type() == PGroup) // delete all commands in this group + { + if (QMessageBox::question(this, + tr("Delete command group"), + tr("Do you want to delete command group '%1'?") + .arg(item->text(0)), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + MainCore::instance()->m_settings.deleteCommandGroup(item->text(0)); + + ui->commandTree->clear(); + + for (int i = 0; i < MainCore::instance()->m_settings.getCommandCount(); ++i) { + addCommandToTree(MainCore::instance()->m_settings.getCommand(i)); + } + } + } + } +} + +void CommandsDialog::on_commandKeyboardConnect_toggled(bool checked) +{ + qDebug("CommandsDialog::on_commandKeyboardConnect_toggled: %s", checked ? "true" : "false"); + + if (checked) { + MainWindow::getInstance()->commandKeysConnect(MainWindow::getInstance(), SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); + } else { + MainWindow::getInstance()->commandKeysDisconnect(MainWindow::getInstance(), SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); + } +} + +QTreeWidgetItem* CommandsDialog::addCommandToTree(const Command* command) +{ + QTreeWidgetItem* group = 0; + + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) + { + if(ui->commandTree->topLevelItem(i)->text(0) == command->getGroup()) + { + group = ui->commandTree->topLevelItem(i); + break; + } + } + + if(group == 0) + { + QStringList sl; + sl.append(command->getGroup()); + group = new QTreeWidgetItem(ui->commandTree, sl, PGroup); + group->setFirstColumnSpanned(true); + group->setExpanded(true); + ui->commandTree->sortByColumn(0, Qt::AscendingOrder); + } + + QStringList sl; + sl.append(QString("%1").arg(command->getDescription())); // Descriptions column + sl.append(QString("%1").arg(command->getAssociateKey() ? command->getRelease() ? "R" : "P" : "-")); // key press/release column + sl.append(QString("%1").arg(command->getKeyLabel())); // key column + CommandItem* item = new CommandItem(group, sl, command->getDescription(), PItem); + item->setData(0, Qt::UserRole, QVariant::fromValue(command)); + item->setTextAlignment(0, Qt::AlignLeft); + ui->commandTree->resizeColumnToContents(0); // Resize description column to minimum + ui->commandTree->resizeColumnToContents(1); // Resize key column to minimum + ui->commandTree->resizeColumnToContents(2); // Resize key press/release column to minimum + + //updatePresetControls(); + return item; +} diff --git a/sdrgui/gui/commandsdialog.h b/sdrgui/gui/commandsdialog.h new file mode 100644 index 000000000..508bf97e4 --- /dev/null +++ b/sdrgui/gui/commandsdialog.h @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2022 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRGUI_GUI_COMMANDSDIALOG_H_ +#define SDRGUI_GUI_COMMANDSDIALOG_H_ + +#include + +#include "export.h" + +class CommandKeyReceiver; + +namespace Ui { + class CommandsDialog; +} + +class SDRGUI_API CommandsDialog : public QDialog +{ + Q_OBJECT +public: + explicit CommandsDialog(QWidget* parent = nullptr); + ~CommandsDialog(); + + void setApiHost(const QString& apiHost) { m_apiHost = apiHost; } + void setApiPort(int apiPort) { m_apiPort = apiPort; } + void setCommandKeyReceiver(CommandKeyReceiver *commandKeyReceiver) { m_commandKeyReceiver = commandKeyReceiver; } + void populateTree(); + +private: + enum { + PGroup, + PItem + }; + + Ui::CommandsDialog* ui; + QString m_apiHost; + int m_apiPort; + CommandKeyReceiver *m_commandKeyReceiver; + + QTreeWidgetItem* addCommandToTree(const Command* command); + +private slots: + void on_commandNew_clicked(); + void on_commandDuplicate_clicked(); + void on_commandEdit_clicked(); + void on_commandRun_clicked(); + void on_commandOutput_clicked(); + void on_commandsSave_clicked(); + void on_commandDelete_clicked(); + void on_commandKeyboardConnect_toggled(bool checked); +}; + +#endif // SDRGUI_GUI_COMMANDSDIALOG_H_ diff --git a/sdrgui/gui/commandsdialog.ui b/sdrgui/gui/commandsdialog.ui new file mode 100644 index 000000000..10e606ee3 --- /dev/null +++ b/sdrgui/gui/commandsdialog.ui @@ -0,0 +1,252 @@ + + + CommandsDialog + + + + 0 + 0 + 400 + 300 + + + + + Liberation Sans + 9 + + + + Commands + + + + + + 5 + + + true + + + 3 + + + 5 + + + + Description + + + + + P/R + + + + + Key + + + + + + + + + + Create new command + + + + + + + :/create.png:/create.png + + + + + + + Duplicate command + + + + + + + :/duplicate.png:/duplicate.png + + + + + + + Edit command details + + + + + + + :/edit.png:/edit.png + + + + + + + Run command + + + + + + + :/play.png:/play.png + + + + + + + View last run status and output + + + + + + + :/listing.png:/listing.png + + + + + + + Save commands in settings + + + + + + + :/save.png:/save.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete selected command + + + + + + + :/bin.png:/bin.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Toggle keyboard to command connection + + + + + + + :/keyboard.png:/keyboard.png + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
+
+ + + + + + buttonBox + accepted() + CommandsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CommandsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 595067bdd..a98ae3a54 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -49,10 +50,7 @@ #include "commands/commandkeyreceiver.h" #include "gui/indicator.h" #include "gui/presetitem.h" -#include "gui/commanditem.h" #include "gui/addpresetdialog.h" -#include "gui/editcommanddialog.h" -#include "gui/commandoutputdialog.h" #include "gui/pluginsdialog.h" #include "gui/aboutdialog.h" #include "gui/rollupwidget.h" @@ -67,6 +65,7 @@ #include "gui/ambedevicesdialog.h" #include "gui/workspace.h" #include "gui/featurepresetsdialog.h" +#include "gui/commandsdialog.h" #include "dsp/dspengine.h" #include "dsp/spectrumvis.h" #include "dsp/dspcommands.h" @@ -975,6 +974,9 @@ void MainWindow::createMenuBar() QAction *userArgumentsAction = devicesMenu->addAction("User arguments"); userArgumentsAction->setToolTip("Device custom user arguments"); QObject::connect(userArgumentsAction, &QAction::triggered, this, &MainWindow::on_action_DeviceUserArguments_triggered); + QAction *commandsAction = preferencesMenu->addAction("Commands"); + commandsAction->setToolTip("External commands dialog"); + QObject::connect(commandsAction, &QAction::triggered, this, &MainWindow::on_action_commands_triggered); QMenu *helpMenu = menuBar->addMenu("Help"); QAction *quickStartAction = helpMenu->addAction("Quick start"); @@ -1427,245 +1429,25 @@ void MainWindow::on_action_View_Fullscreen_toggled(bool checked) } } -void MainWindow::on_commandNew_clicked() -{ - // QStringList groups; - // QString group = ""; - // QString description = ""; - - // for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { - // groups.append(ui->commandTree->topLevelItem(i)->text(0)); - // } - - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - - // if(item != 0) - // { - // if(item->type() == PGroup) { - // group = item->text(0); - // } else if(item->type() == PItem) { - // group = item->parent()->text(0); - // description = item->text(0); - // } - // } - - // Command *command = new Command(); - // command->setGroup(group); - // command->setDescription(description); - // EditCommandDialog editCommandDialog(groups, group, this); - // editCommandDialog.fromCommand(*command); - - // if (editCommandDialog.exec() == QDialog::Accepted) - // { - // editCommandDialog.toCommand(*command); - // m_mainCore->m_settings.addCommand(command); - // ui->commandTree->setCurrentItem(addCommandToTree(command)); - // m_mainCore->m_settings.sortCommands(); - // } -} - -void MainWindow::on_commandDuplicate_clicked() -{ - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - // const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - // Command *commandCopy = new Command(*command); - // m_mainCore->m_settings.addCommand(commandCopy); - // ui->commandTree->setCurrentItem(addCommandToTree(commandCopy)); - // m_mainCore->m_settings.sortCommands(); -} - -void MainWindow::on_commandEdit_clicked() -{ - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - // bool change = false; - // const Command *changedCommand = 0; - // QString newGroupName; - - // QStringList groups; - - // for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { - // groups.append(ui->commandTree->topLevelItem(i)->text(0)); - // } - - // if(item != 0) - // { - // if (item->type() == PItem) - // { - // const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - - // if (command != 0) - // { - // EditCommandDialog editCommandDialog(groups, command->getGroup(), this); - // editCommandDialog.fromCommand(*command); - - // if (editCommandDialog.exec() == QDialog::Accepted) - // { - // Command* command_mod = const_cast(command); - // editCommandDialog.toCommand(*command_mod); - // change = true; - // changedCommand = command; - // } - // } - // } - // else if (item->type() == PGroup) - // { - // AddPresetDialog dlg(groups, item->text(0), this); - // dlg.showGroupOnly(); - // dlg.setDialogTitle("Edit command group"); - // dlg.setDescriptionBoxTitle("Command details"); - - // if (dlg.exec() == QDialog::Accepted) - // { - // m_mainCore->m_settings.renameCommandGroup(item->text(0), dlg.group()); - // newGroupName = dlg.group(); - // change = true; - // } - // } - // } - - // if (change) - // { - // m_mainCore->m_settings.sortCommands(); - // ui->commandTree->clear(); - - // for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) - // { - // QTreeWidgetItem *item_x = addCommandToTree(m_mainCore->m_settings.getCommand(i)); - // const Command* command_x = qvariant_cast(item_x->data(0, Qt::UserRole)); - // if (changedCommand && (command_x == changedCommand)) { // set cursor on changed command - // ui->commandTree->setCurrentItem(item_x); - // } - // } - - // if (!changedCommand) // on group name change set cursor on the group that has been changed - // { - // for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) - // { - // QTreeWidgetItem* item = ui->commandTree->topLevelItem(i); - - // if (item->text(0) == newGroupName) { - // ui->commandTree->setCurrentItem(item); - // } - // } - // } - // } -} - -void MainWindow::on_commandDelete_clicked() -{ - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - - // if (item != 0) - // { - // if (item->type() == PItem) // delete individual command - // { - // const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - - // if(command) - // { - // if (QMessageBox::question(this, - // tr("Delete command"), - // tr("Do you want to delete command '%1'?") - // .arg(command->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) - // { - // delete item; - // m_mainCore->m_settings.deleteCommand(command); - // } - // } - // } - // else if (item->type() == PGroup) // delete all commands in this group - // { - // if (QMessageBox::question(this, - // tr("Delete command group"), - // tr("Do you want to delete command group '%1'?") - // .arg(item->text(0)), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) - // { - // m_mainCore->m_settings.deleteCommandGroup(item->text(0)); - - // ui->commandTree->clear(); - - // for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) { - // addCommandToTree(m_mainCore->m_settings.getCommand(i)); - // } - // } - // } - // } -} - -void MainWindow::on_commandRun_clicked() -{ - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - - // if (item != 0) - // { - // int currentDeviceSetIndex = ui->tabInputsView->currentIndex(); - - // if (item->type() == PItem) // run individual command - // { - // const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - // Command* command_mod = const_cast(command); - // command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); - // } - // else if (item->type() == PGroup) // run all commands in this group - // { - // QString group = item->text(0); - - // for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) - // { - // Command *command_mod = const_cast(m_mainCore->m_settings.getCommand(i)); - - // if (command_mod->getGroup() == group) { - // command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); - // } - // } - // } - // } -} - -void MainWindow::on_commandOutput_clicked() -{ - // QTreeWidgetItem* item = ui->commandTree->currentItem(); - - // if ((item != 0) && (item->type() == PItem)) - // { - // const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - // Command* command_mod = const_cast(command); - // CommandOutputDialog commandOutputDialog(*command_mod); - // commandOutputDialog.exec(); - // } -} - -void MainWindow::on_commandsSave_clicked() -{ - saveCommandSettings(); - m_mainCore->m_settings.save(); -} - void MainWindow::commandKeysConnect(QObject *object, const char *slot) { setFocus(); - connect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), - object, slot); + connect( + m_commandKeyReceiver, + SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), + object, + slot + ); } void MainWindow::commandKeysDisconnect(QObject *object, const char *slot) { - disconnect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), - object, slot); -} - -void MainWindow::on_commandKeyboardConnect_toggled(bool checked) -{ - qDebug("on_commandKeyboardConnect_toggled: %s", checked ? "true" : "false"); - - if (checked) - { - commandKeysConnect(this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); - } - else - { - commandKeysDisconnect(this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); - } + disconnect( + m_commandKeyReceiver, + SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), + object, + slot + ); } void MainWindow::on_presetSave_clicked() @@ -2021,6 +1803,17 @@ void MainWindow::on_action_DeviceUserArguments_triggered() deviceUserArgsDialog.exec(); } +void MainWindow::on_action_commands_triggered() +{ + qDebug("MainWindow::on_action_commands_triggered"); + CommandsDialog commandsDialog(this); + commandsDialog.setApiHost(m_apiServer->getHost()); + commandsDialog.setApiPort(m_apiServer->getPort()); + commandsDialog.setCommandKeyReceiver(m_commandKeyReceiver); + commandsDialog.populateTree(); + commandsDialog.exec(); +} + void MainWindow::on_action_FFT_triggered() { qDebug("MainWindow::on_action_FFT_triggered"); @@ -2659,22 +2452,22 @@ void MainWindow::updateStatus() void MainWindow::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release) { - //qDebug("MainWindow::commandKeyPressed: key: %x mod: %x %s", (int) key, (int) keyModifiers, release ? "release" : "press"); - // int currentDeviceSetIndex = ui->tabInputsView->currentIndex(); + qDebug("MainWindow::commandKeyPressed: key: %x mod: %x %s", (int) key, (int) keyModifiers, release ? "release" : "press"); + int currentDeviceSetIndex = 0; - // for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) - // { - // const Command* command = m_mainCore->m_settings.getCommand(i); + for (int i = 0; i < m_mainCore->m_settings.getCommandCount(); ++i) + { + const Command* command = m_mainCore->m_settings.getCommand(i); - // if (command->getAssociateKey() - // && (command->getRelease() == release) - // && (command->getKey() == key) - // && (command->getKeyModifiers() == keyModifiers)) - // { - // Command* command_mod = const_cast(command); - // command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); - // } - // } + if (command->getAssociateKey() + && (command->getRelease() == release) + && (command->getKey() == key) + && (command->getKeyModifiers() == keyModifiers)) + { + Command* command_mod = const_cast(command); + command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); + } + } } void MainWindow::restoreDeviceTabs() diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index 83415be6d..13f077016 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -174,14 +174,6 @@ private slots: void on_presetDelete_clicked(); void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_presetTree_itemActivated(QTreeWidgetItem *item, int column); - void on_commandNew_clicked(); - void on_commandDuplicate_clicked(); - void on_commandEdit_clicked(); - void on_commandDelete_clicked(); - void on_commandRun_clicked(); - void on_commandOutput_clicked(); - void on_commandsSave_clicked(); - void on_commandKeyboardConnect_toggled(bool checked); void on_action_Audio_triggered(); void on_action_Logging_triggered(); void on_action_FFT_triggered(); @@ -189,6 +181,7 @@ private slots: void on_action_LimeRFE_triggered(); void on_action_My_Position_triggered(); void on_action_DeviceUserArguments_triggered(); + void on_action_commands_triggered(); void samplingDeviceChanged(int deviceType, int tabIndex, int newDeviceIndex); void channelAddClicked(int channelIndex); void featureAddClicked(Workspace *workspace, int featureIndex);