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:
Martin Kleusberg
2017-03-20 23:06:58 +01:00
parent 1e9fec270b
commit e6390b4d22
5 changed files with 111 additions and 23 deletions

View File

@@ -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: