diff --git a/src/Application.h b/src/Application.h index 03f1cabc..c5ef04a8 100644 --- a/src/Application.h +++ b/src/Application.h @@ -16,6 +16,8 @@ public: bool dontShowMainWindow() { return m_dontShowMainWindow; } + MainWindow* mainWindow() { return m_mainWindow; } + protected: bool event(QEvent* event); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 3ccc3f73..7fb1eed4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1691,7 +1691,7 @@ void MainWindow::reloadSettings() // Hide or show the File → Remote menu as needed QAction *remoteMenuAction = ui->menuRemote->menuAction(); - remoteMenuAction->setVisible(Settings::getSettingsValue("MainWindow", "remotemenu").toBool()); + remoteMenuAction->setVisible(Settings::getSettingsValue("remote", "active").toBool()); // Update the remote database connection settings m_remoteDb.reloadSettings(); diff --git a/src/MainWindow.h b/src/MainWindow.h index b56ba8e8..2f404503 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -33,6 +33,7 @@ public: ~MainWindow(); DBBrowserDB& getDb() { return db; } + const RemoteDatabase& getRemote() const { return m_remoteDb; } struct PlotSettings { diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index 948efc7e..a060f374 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -3,6 +3,8 @@ #include "sqlitedb.h" #include "FileDialog.h" #include "Settings.h" +#include "Application.h" +#include "MainWindow.h" #include #include @@ -59,7 +61,7 @@ void PreferencesDialog::loadSettings() ui->comboDefaultLocation->setCurrentIndex(Settings::getSettingsValue("db", "savedefaultlocation").toInt()); ui->locationEdit->setText(Settings::getSettingsValue("db", "defaultlocation").toString()); ui->checkUpdates->setChecked(Settings::getSettingsValue("checkversion", "enabled").toBool()); - ui->checkUseRemotes->setChecked(Settings::getSettingsValue("MainWindow", "remotemenu").toBool()); + ui->checkHideSchemaLinebreaks->setChecked(Settings::getSettingsValue("db", "hideschemalinebreaks").toBool()); ui->foreignKeysCheckBox->setChecked(Settings::getSettingsValue("db", "foreignkeys").toBool()); ui->spinPrefetchSize->setValue(Settings::getSettingsValue("db", "prefetchsize").toInt()); @@ -108,6 +110,35 @@ void PreferencesDialog::loadSettings() } } + // Remote settings + ui->checkUseRemotes->setChecked(Settings::getSettingsValue("remote", "active").toBool()); + auto ca_certs = static_cast(qApp)->mainWindow()->getRemote().caCertificates(); + ui->tableCaCerts->setRowCount(ca_certs.size()); + for(int i=0;isetFlags(Qt::ItemIsSelectable); + ui->tableCaCerts->setItem(i, 0, cert_cn); + + QTableWidgetItem* cert_o = new QTableWidgetItem(cert.subjectInfo(QSslCertificate::Organization).at(0)); + cert_o->setFlags(Qt::ItemIsSelectable); + ui->tableCaCerts->setItem(i, 1, cert_o); + + QTableWidgetItem* cert_from = new QTableWidgetItem(cert.effectiveDate().toString()); + cert_from->setFlags(Qt::ItemIsSelectable); + ui->tableCaCerts->setItem(i, 2, cert_from); + + QTableWidgetItem* cert_to = new QTableWidgetItem(cert.expiryDate().toString()); + cert_to->setFlags(Qt::ItemIsSelectable); + ui->tableCaCerts->setItem(i, 3, cert_to); + + QTableWidgetItem* cert_serialno = new QTableWidgetItem(QString(cert.serialNumber())); + cert_serialno->setFlags(Qt::ItemIsSelectable); + ui->tableCaCerts->setItem(i, 4, cert_serialno); + } + // Gracefully handle the preferred Editor font not being available matchingFont = ui->comboEditorFont->findText(Settings::getSettingsValue("editor", "font").toString(), Qt::MatchExactly); if (matchingFont == -1) @@ -138,7 +169,6 @@ void PreferencesDialog::saveSettings() Settings::setSettingsValue("db", "defaultfieldtype", ui->defaultFieldTypeComboBox->currentIndex()); - Settings::setSettingsValue("MainWindow", "remotemenu", ui->checkUseRemotes->isChecked()); Settings::setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked()); Settings::setSettingsValue("databrowser", "font", ui->comboDataBrowserFont->currentText()); @@ -176,6 +206,8 @@ void PreferencesDialog::saveSettings() Settings::setSettingsValue("extensions", "list", extList); Settings::setSettingsValue("extensions", "disableregex", ui->checkRegexDisabled->isChecked()); + Settings::setSettingsValue("remote", "active", ui->checkUseRemotes->isChecked()); + // Warn about restarting to change language QVariant newLanguage = ui->languageComboBox->itemData(ui->languageComboBox->currentIndex()); if (newLanguage != Settings::getSettingsValue("General", "language")) @@ -336,3 +368,8 @@ void PreferencesDialog::saveColorSetting(QFrame *frame, const QString & settingN Settings::setSettingsValue("databrowser", settingName + "_colour", frame->palette().color(frame->backgroundRole())); } + +void PreferencesDialog::activateRemoteTab(bool active) +{ + ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->tabRemote), active); +} diff --git a/src/PreferencesDialog.h b/src/PreferencesDialog.h index c6cd3f57..533727b5 100644 --- a/src/PreferencesDialog.h +++ b/src/PreferencesDialog.h @@ -28,6 +28,7 @@ private slots: virtual void showColourDialog(QTreeWidgetItem* item, int column); virtual void addExtension(); virtual void removeExtension(); + virtual void activateRemoteTab(bool active); private: Ui::PreferencesDialog *ui; diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index 50d272b0..0f24234c 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -7,7 +7,7 @@ 0 0 590 - 555 + 614 @@ -26,180 +26,137 @@ &General - - - - 32 - 20 - 503 - 251 - - - - - - - Default &location - - - locationEdit - - - - - - - - - - Remember last location - - - - - Always use this location - - - - - Remember last location for session only - - - - - - - - - - false - - - - 0 - 0 - - - - - 316 - 0 - - - - - - - - ... - - - - - - - - - - - Lan&guage - - - languageComboBox - - - - - - - Show remote options - - - - - - - Automatic &updates - - - checkUpdates - - - - - - - enabled - - - - - - - - 0 - 0 - - - - QComboBox::AdjustToContents - - - 35 - - - - 20 - 15 - - - - - - - - + + + + + Default &location + + + locationEdit + + + + + + + + - enabled + Remember last location - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + - Remote server + Always use this location - - - - - - - dbhub.io + + + + Remember last location for session only + + + + + + + + + + false - - - - - - - + + + 0 + 0 + + + + + 316 + 0 + + + + + + + + ... + + + + + + + + + + + Lan&guage + + + languageComboBox + + + + + + + + 0 + 0 + + + + QComboBox::AdjustToContents + + + 35 + + + + 20 + 15 + + + + + + + + Show remote options + + + + + + + enabled + + + true + + + + + + + Automatic &updates + + + checkUpdates + + + + + + + enabled + + + + @@ -1049,6 +1006,55 @@ + + + Remote + + + + + + CA certificates + + + + + + + + Subject CN + + + Common Name + + + + + Subject O + + + Organization + + + + + Valid from + + + + + Valid to + + + + + Serial number + + + + + + @@ -1118,8 +1124,8 @@ saveSettings() - 281 - 525 + 287 + 607 155 @@ -1134,8 +1140,8 @@ reject() - 349 - 525 + 355 + 607 286 @@ -1151,7 +1157,7 @@ 571 - 99 + 97 245 @@ -1167,7 +1173,7 @@ 571 - 137 + 135 245 @@ -1198,8 +1204,8 @@ chooseLocation() - 567 - 100 + 571 + 114 294 @@ -1214,12 +1220,12 @@ setVisible(bool) - 375 - 202 + 365 + 207 - 64 - 243 + 55 + 252 @@ -1230,12 +1236,28 @@ setVisible(bool) - 375 - 202 + 365 + 207 - 375 - 251 + 365 + 252 + + + + + checkUseRemotes + toggled(bool) + PreferencesDialog + activateRemoteTab(bool) + + + 161 + 172 + + + 382 + 572 @@ -1246,5 +1268,6 @@ showColourDialog(QTreeWidgetItem*,int) addExtension() removeExtension() + activateRemoteTab(bool) diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index 2246adf9..b3d28dbb 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -14,25 +14,6 @@ RemoteDatabase::RemoteDatabase() : m_manager(new QNetworkAccessManager), m_progress(nullptr), m_currentReply(nullptr) -{ - // Load settings and set up some more stuff while doing so - reloadSettings(); - - // TODO Add support for proxies here - - // Set up signals - connect(m_manager, &QNetworkAccessManager::finished, this, &RemoteDatabase::gotReply); - connect(m_manager, &QNetworkAccessManager::encrypted, this, &RemoteDatabase::gotEncrypted); - connect(m_manager, &QNetworkAccessManager::sslErrors, this, &RemoteDatabase::gotError); -} - -RemoteDatabase::~RemoteDatabase() -{ - delete m_manager; - delete m_progress; -} - -void RemoteDatabase::reloadSettings() { // Set up SSL configuration m_sslConfiguration = QSslConfiguration::defaultConfiguration(); @@ -59,6 +40,25 @@ void RemoteDatabase::reloadSettings() QSslKey clientKey(&fileClientKey, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "password"); fileClientKey.close(); m_sslConfiguration.setPrivateKey(clientKey); + + // Load settings and set up some more stuff while doing so + reloadSettings(); + + // Set up signals + connect(m_manager, &QNetworkAccessManager::finished, this, &RemoteDatabase::gotReply); + connect(m_manager, &QNetworkAccessManager::encrypted, this, &RemoteDatabase::gotEncrypted); + connect(m_manager, &QNetworkAccessManager::sslErrors, this, &RemoteDatabase::gotError); +} + +RemoteDatabase::~RemoteDatabase() +{ + delete m_manager; + delete m_progress; +} + +void RemoteDatabase::reloadSettings() +{ + // TODO Add support for proxies here } void RemoteDatabase::fetchDatabase(const QString& url) @@ -201,3 +201,9 @@ void RemoteDatabase::updateProgress(qint64 bytesReceived, qint64 bytesTotal) m_progress->hide(); } } + +const QList& RemoteDatabase::caCertificates() const +{ + static QList certs = m_sslConfiguration.caCertificates(); + return certs; +} diff --git a/src/RemoteDatabase.h b/src/RemoteDatabase.h index 24ac0d7b..3dba9b2a 100644 --- a/src/RemoteDatabase.h +++ b/src/RemoteDatabase.h @@ -20,6 +20,8 @@ public: void reloadSettings(); + const QList& caCertificates() const; + void fetchDatabase(const QString& url); signals: diff --git a/src/Settings.cpp b/src/Settings.cpp index 35caafe2..5b59ae90 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -109,10 +109,6 @@ QVariant Settings::getSettingsDefaultValue(const QString& group, const QString& if(group == "MainWindow" && name == "windowState") return ""; - // Enable the File → Remote menu by default - if(group == "MainWindow" && name == "remotemenu") - return true; - // SQLLogDock/Log? if(group == "SQLLogDock" && name == "Log") return "Application"; @@ -250,6 +246,10 @@ QVariant Settings::getSettingsDefaultValue(const QString& group, const QString& return 4; } + // Enable the File → Remote menu by default + if(group == "remote" && name == "active") + return true; + // Unknown combination of group and name? Return an invalid QVariant! return QVariant(); }