diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index 902db928..58bec5d6 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -149,6 +149,7 @@ void PreferencesDialog::loadSettings() addClientCertToTable(file, cert); } } + ui->editRemoteCloneDirectory->setText(Settings::getSettingsValue("remote", "clonedirectory").toString()); // Gracefully handle the preferred Editor font not being available matchingFont = ui->comboEditorFont->findText(Settings::getSettingsValue("editor", "font").toString(), Qt::MatchExactly); @@ -258,6 +259,7 @@ void PreferencesDialog::saveSettings() QFile::remove(file); } Settings::setSettingsValue("remote", "client_certificates", new_client_certs); + Settings::setSettingsValue("remote", "clonedirectory", ui->editRemoteCloneDirectory->text()); // Warn about restarting to change language QVariant newLanguage = ui->languageComboBox->itemData(ui->languageComboBox->currentIndex()); @@ -497,3 +499,14 @@ void PreferencesDialog::addClientCertToTable(const QString& path, const QSslCert cert_serialno->setFlags(Qt::ItemIsSelectable); ui->tableClientCerts->setItem(row, 5, cert_serialno); } + +void PreferencesDialog::chooseRemoteCloneDirectory() +{ + QString s = FileDialog::getExistingDirectory( + this, + tr("Choose a directory"), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + if(!s.isEmpty()) + ui->editRemoteCloneDirectory->setText(s); +} diff --git a/src/PreferencesDialog.h b/src/PreferencesDialog.h index 65451dd5..646878db 100644 --- a/src/PreferencesDialog.h +++ b/src/PreferencesDialog.h @@ -33,6 +33,7 @@ private slots: virtual void activateRemoteTab(bool active); virtual void addClientCertificate(); virtual void removeClientCertificate(); + void chooseRemoteCloneDirectory(); private: Ui::PreferencesDialog *ui; diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index 101965ed..8c0fb1aa 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -1011,14 +1011,14 @@ Remote - + CA certificates - + QAbstractItemView::SingleSelection @@ -1062,14 +1062,14 @@ - + Your certificates - + @@ -1158,6 +1158,43 @@ + + + + Clone databases into + + + + + + + + + false + + + + 0 + 0 + + + + + 316 + 0 + + + + + + + + ... + + + + + @@ -1187,6 +1224,8 @@ locationEdit setLocationButton languageComboBox + checkUseRemotes + checkUpdates encodingComboBox foreignKeysCheckBox checkHideSchemaLinebreaks @@ -1196,6 +1235,7 @@ editDatabaseDefaultSqlText comboDataBrowserFont spinDataBrowserFontSize + spinSymbolLimit txtNull fr_null_fg fr_null_bg @@ -1217,6 +1257,13 @@ buttonAddExtension buttonRemoveExtension checkRegexDisabled + editRemoteCloneDirectory + buttonRemoteBrowseCloneDirectory + tableCaCerts + tableClientCerts + buttonClientCertAdd + buttonClientCertRemove + tabWidget @@ -1373,8 +1420,8 @@ addClientCertificate() - 563 - 257 + 578 + 315 596 @@ -1389,8 +1436,8 @@ removeClientCertificate() - 561 - 289 + 578 + 353 597 @@ -1398,6 +1445,22 @@ + + buttonRemoteBrowseCloneDirectory + clicked() + PreferencesDialog + chooseRemoteCloneDirectory() + + + 567 + 54 + + + 595 + 41 + + + saveSettings() @@ -1408,5 +1471,6 @@ activateRemoteTab(bool) addClientCertificate() removeClientCertificate() + chooseRemoteCloneDirectory() diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index 86eab712..72979d8a 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -118,19 +118,20 @@ void RemoteDatabase::gotReply(QNetworkReply* reply) { case RequestTypeDatabase: { - // It's a database file. Ask user where to store the database file. - QString saveFileAs = FileDialog::getSaveFileName(0, qApp->applicationName(), FileDialog::getSqlDatabaseFileFilter(), reply->url().fileName()); - if(!saveFileAs.isEmpty()) - { - // Save the downloaded data under the selected file name - QFile file(saveFileAs); - file.open(QIODevice::WriteOnly); - file.write(reply->readAll()); - file.close(); + // It's a database file. - // Tell the application to open this file - emit openFile(saveFileAs); - } + // Generate a unique file name to save the file under + QString saveFileAs = Settings::getSettingsValue("remote", "clonedirectory").toString() + + QString("/%2_%1.remotedb").arg(QDateTime::currentMSecsSinceEpoch()).arg(reply->url().fileName()); + + // Save the downloaded data under the generated file name + QFile file(saveFileAs); + file.open(QIODevice::WriteOnly); + file.write(reply->readAll()); + file.close(); + + // Tell the application to open this file + emit openFile(saveFileAs); } break; case RequestTypeDirectory: diff --git a/src/Settings.cpp b/src/Settings.cpp index 5b59ae90..6808a054 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -5,6 +5,7 @@ #include #include #include +#include QHash Settings::m_hCache; @@ -246,9 +247,17 @@ QVariant Settings::getSettingsDefaultValue(const QString& group, const QString& return 4; } - // Enable the File → Remote menu by default - if(group == "remote" && name == "active") - return true; + // Remote settings? + if(group == "remote") + { + // Enable the File → Remote menu by default + if(name == "active") + return true; + + // Clone directory + if(name == "clonedirectory") + return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + } // Unknown combination of group and name? Return an invalid QVariant! return QVariant();