mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-04-27 07:29:13 -05:00
dbhub: Automatically generate a file name to save a database under
When fetching a remote database automatically generate a file name to save the database as instead of asking the user for a path and name. Also add a preferences option to set the directory for all cloned remote databases. This is obviously a trade-off: on the one hand this makes opening remote databases simpler (it's just a double click), on the other hand it takes control away from the users. The main reason for doing this, however, is to indicate to the user that the cloned databases are going to be controlled by DB4S. We have to keep track of the local databases in order to update them from the right place, push them back to the right place, etc. And because the local copies are under DB4S control we don't want the user to move, rename, or delete them.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ private slots:
|
||||
virtual void activateRemoteTab(bool active);
|
||||
virtual void addClientCertificate();
|
||||
virtual void removeClientCertificate();
|
||||
void chooseRemoteCloneDirectory();
|
||||
|
||||
private:
|
||||
Ui::PreferencesDialog *ui;
|
||||
|
||||
@@ -1011,14 +1011,14 @@
|
||||
<string>Remote</string>
|
||||
</attribute>
|
||||
<layout class="QFormLayout" name="formLayout_5">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="text">
|
||||
<string>CA certificates</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QTableWidget" name="tableCaCerts">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
@@ -1062,14 +1062,14 @@
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_22">
|
||||
<property name="text">
|
||||
<string>Your certificates</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableClientCerts">
|
||||
@@ -1158,6 +1158,43 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_23">
|
||||
<property name="text">
|
||||
<string>Clone databases into</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editRemoteCloneDirectory">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>316</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonRemoteBrowseCloneDirectory">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
@@ -1187,6 +1224,8 @@
|
||||
<tabstop>locationEdit</tabstop>
|
||||
<tabstop>setLocationButton</tabstop>
|
||||
<tabstop>languageComboBox</tabstop>
|
||||
<tabstop>checkUseRemotes</tabstop>
|
||||
<tabstop>checkUpdates</tabstop>
|
||||
<tabstop>encodingComboBox</tabstop>
|
||||
<tabstop>foreignKeysCheckBox</tabstop>
|
||||
<tabstop>checkHideSchemaLinebreaks</tabstop>
|
||||
@@ -1196,6 +1235,7 @@
|
||||
<tabstop>editDatabaseDefaultSqlText</tabstop>
|
||||
<tabstop>comboDataBrowserFont</tabstop>
|
||||
<tabstop>spinDataBrowserFontSize</tabstop>
|
||||
<tabstop>spinSymbolLimit</tabstop>
|
||||
<tabstop>txtNull</tabstop>
|
||||
<tabstop>fr_null_fg</tabstop>
|
||||
<tabstop>fr_null_bg</tabstop>
|
||||
@@ -1217,6 +1257,13 @@
|
||||
<tabstop>buttonAddExtension</tabstop>
|
||||
<tabstop>buttonRemoveExtension</tabstop>
|
||||
<tabstop>checkRegexDisabled</tabstop>
|
||||
<tabstop>editRemoteCloneDirectory</tabstop>
|
||||
<tabstop>buttonRemoteBrowseCloneDirectory</tabstop>
|
||||
<tabstop>tableCaCerts</tabstop>
|
||||
<tabstop>tableClientCerts</tabstop>
|
||||
<tabstop>buttonClientCertAdd</tabstop>
|
||||
<tabstop>buttonClientCertRemove</tabstop>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="icons/icons.qrc"/>
|
||||
@@ -1373,8 +1420,8 @@
|
||||
<slot>addClientCertificate()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>563</x>
|
||||
<y>257</y>
|
||||
<x>578</x>
|
||||
<y>315</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>596</x>
|
||||
@@ -1389,8 +1436,8 @@
|
||||
<slot>removeClientCertificate()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>561</x>
|
||||
<y>289</y>
|
||||
<x>578</x>
|
||||
<y>353</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>597</x>
|
||||
@@ -1398,6 +1445,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonRemoteBrowseCloneDirectory</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>chooseRemoteCloneDirectory()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>567</x>
|
||||
<y>54</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>595</x>
|
||||
<y>41</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>saveSettings()</slot>
|
||||
@@ -1408,5 +1471,6 @@
|
||||
<slot>activateRemoteTab(bool)</slot>
|
||||
<slot>addClientCertificate()</slot>
|
||||
<slot>removeClientCertificate()</slot>
|
||||
<slot>chooseRemoteCloneDirectory()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
+13
-12
@@ -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:
|
||||
|
||||
+12
-3
@@ -5,6 +5,7 @@
|
||||
#include <QColor>
|
||||
#include <QFontInfo>
|
||||
#include <QLocale>
|
||||
#include <QStandardPaths>
|
||||
|
||||
QHash<QString, QVariant> 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();
|
||||
|
||||
Reference in New Issue
Block a user