diff --git a/src/browser/BrowserOptionDialog.cpp b/src/browser/BrowserOptionDialog.cpp index f6d634a823..ab372892d5 100755 --- a/src/browser/BrowserOptionDialog.cpp +++ b/src/browser/BrowserOptionDialog.cpp @@ -22,14 +22,23 @@ #include "BrowserSettings.h" #include "core/FilePath.h" -#include #include +#include "gui/MessageBox.h" -BrowserOptionDialog::BrowserOptionDialog(QWidget* parent) : +BrowserOptionDialog::BrowserOptionDialog(DatabaseTabWidget* parent) : QWidget(parent), - m_ui(new Ui::BrowserOptionDialog()) + m_dbTabWidget(parent), + m_ui(new Ui::BrowserOptionDialog()), + m_customData(new CustomData(this)), + m_customDataModel(new QStandardItemModel(this)) { m_ui->setupUi(this); + m_ui->removeCustomDataButton->setEnabled(false); + m_ui->customDataTable->setModel(m_customDataModel); + connect(m_ui->customDataTable->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + SLOT(toggleRemoveButton(QItemSelection))); + connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedKey())); + connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys())); connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions())); @@ -51,6 +60,17 @@ BrowserOptionDialog::~BrowserOptionDialog() { } +CustomData* BrowserOptionDialog::customData() const +{ + // Returns the current database customData from metadata. Otherwise return an empty customData member. + if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget()) { + if (Database* db = dbWidget->database()) { + return db->metadata()->customData(); + } + } + return m_customData; +} + void BrowserOptionDialog::loadSettings() { BrowserSettings settings; @@ -84,6 +104,9 @@ void BrowserOptionDialog::loadSettings() m_ui->chromiumSupport->setChecked(settings.chromiumSupport()); m_ui->firefoxSupport->setChecked(settings.firefoxSupport()); m_ui->vivaldiSupport->setChecked(settings.vivaldiSupport()); + + // Update the stored key list every time settings are loaded + updateModel(); } void BrowserOptionDialog::saveSettings() @@ -124,3 +147,42 @@ void BrowserOptionDialog::showProxyLocationFileDialog() fileTypeFilter); m_ui->customProxyLocation->setText(proxyLocation); } + +void BrowserOptionDialog::removeSelectedKey() +{ + if (QMessageBox::Yes != MessageBox::question(this, + tr("Delete the selected key?"), + tr("Do you really want to delete the selected key?\n" + "This may cause the affected plugins to malfunction."), + QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel)) { + return; + } + + const QItemSelectionModel* itemSelectionModel = m_ui->customDataTable->selectionModel(); + if (itemSelectionModel) { + for (const QModelIndex& index : itemSelectionModel->selectedRows(0)) { + const QString key = index.data().toString(); + customData()->remove(key); + } + updateModel(); + } +} + +void BrowserOptionDialog::toggleRemoveButton(const QItemSelection& selected) +{ + m_ui->removeCustomDataButton->setEnabled(!selected.isEmpty()); +} + +void BrowserOptionDialog::updateModel() +{ + m_customDataModel->clear(); + m_customDataModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")}); + + for (const QString& key : customData()->keys()) { + m_customDataModel->appendRow(QList() + << new QStandardItem(key) + << new QStandardItem(customData()->value(key))); + } + + m_ui->removeCustomDataButton->setEnabled(false); +} diff --git a/src/browser/BrowserOptionDialog.h b/src/browser/BrowserOptionDialog.h index b562f6c18a..4f6855798d 100755 --- a/src/browser/BrowserOptionDialog.h +++ b/src/browser/BrowserOptionDialog.h @@ -22,6 +22,11 @@ #include #include +#include +#include +#include +#include "core/CustomData.h" +#include "gui/DatabaseTabWidget.h" namespace Ui { class BrowserOptionDialog; @@ -32,9 +37,11 @@ class BrowserOptionDialog : public QWidget Q_OBJECT public: - explicit BrowserOptionDialog(QWidget* parent = nullptr); + explicit BrowserOptionDialog(DatabaseTabWidget* parent = nullptr); ~BrowserOptionDialog(); + CustomData* customData() const; + public slots: void loadSettings(); void saveSettings(); @@ -45,9 +52,16 @@ public slots: private slots: void showProxyLocationFileDialog(); + void removeSelectedKey(); + void toggleRemoveButton(const QItemSelection& selected); private: + void updateModel(); QScopedPointer m_ui; + + QPointer m_customData; + QPointer m_customDataModel; + DatabaseTabWidget* const m_dbTabWidget; }; #endif // BROWSEROPTIONDIALOG_H diff --git a/src/browser/BrowserOptionDialog.ui b/src/browser/BrowserOptionDialog.ui index 9bb0250b34..0391ad05d3 100755 --- a/src/browser/BrowserOptionDialog.ui +++ b/src/browser/BrowserOptionDialog.ui @@ -227,6 +227,58 @@ + + + + Stored Keys + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + 200 + + + true + + + false + + + + + + + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 76f1ffb603..dd0c036019 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -116,7 +116,9 @@ class HttpPlugin: public ISettingsPage class BrowserPlugin: public ISettingsPage { public: - BrowserPlugin(DatabaseTabWidget* tabWidget) { + BrowserPlugin(DatabaseTabWidget* tabWidget) : + m_dbTabWidget(tabWidget) + { m_nativeMessagingHost = QSharedPointer(new NativeMessagingHost(tabWidget)); } @@ -135,7 +137,7 @@ class BrowserPlugin: public ISettingsPage } QWidget* createWidget() override { - BrowserOptionDialog* dlg = new BrowserOptionDialog(); + BrowserOptionDialog* dlg = new BrowserOptionDialog(m_dbTabWidget); QObject::connect(dlg, SIGNAL(removeSharedEncryptionKeys()), m_nativeMessagingHost.data(), SLOT(removeSharedEncryptionKeys())); QObject::connect(dlg, SIGNAL(removeStoredPermissions()), m_nativeMessagingHost.data(), SLOT(removeStoredPermissions())); return dlg; @@ -156,7 +158,8 @@ class BrowserPlugin: public ISettingsPage } } private: - QSharedPointer m_nativeMessagingHost; + QSharedPointer m_nativeMessagingHost; + DatabaseTabWidget* const m_dbTabWidget; }; #endif @@ -169,7 +172,7 @@ MainWindow::MainWindow() , m_appExiting(false) { m_ui->setupUi(this); - + #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) new MainWindowAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -891,7 +894,7 @@ void MainWindow::updateTrayIcon() connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow())); m_trayIcon->setContextMenu(menu); - + m_trayIcon->setIcon(filePath()->applicationIcon()); m_trayIcon->show(); } @@ -1150,4 +1153,4 @@ void MainWindow::closeAllDatabases() void MainWindow::lockAllDatabases() { lockDatabasesAfterInactivity(); -} \ No newline at end of file +}