dbhub: Code refactoring

This commit is contained in:
Martin Kleusberg
2017-03-19 16:56:14 +01:00
parent 7426e2c143
commit dec1c6acb1
4 changed files with 19 additions and 15 deletions

View File

@@ -92,14 +92,14 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
}
// What type of data is this?
QString type = reply->property("type").toString();
RequestType type = static_cast<RequestType>(reply->property("type").toInt());
// Hide progress dialog before opening a file dialog to make sure the progress dialog doesn't interfer with the file dialog
if(type == "database" || type == "push")
if(type == RequestTypeDatabase || type == RequestTypePush)
m_progress->reset();
// Handle the reply data
if(type == "database")
if(type == 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());
@@ -114,7 +114,7 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
// Tell the application to open this file
emit openFile(saveFileAs);
}
} else if(type == "dir") {
} else if(type == RequestTypeDirectory) {
emit gotDirList(reply->readAll(), reply->property("userdata"));
}
@@ -247,7 +247,7 @@ void RemoteDatabase::prepareProgressDialog(bool upload, const QString& url)
connect(m_currentReply, &QNetworkReply::downloadProgress, this, &RemoteDatabase::updateProgress);
}
void RemoteDatabase::fetch(const QString& url, bool isDatabase, const QString& clientCert, QVariant userdata)
void RemoteDatabase::fetch(const QString& url, RequestType type, const QString& clientCert, QVariant userdata)
{
// Check if network is accessible. If not, abort right here
if(m_manager->networkAccessible() == QNetworkAccessManager::NotAccessible)
@@ -272,15 +272,12 @@ void RemoteDatabase::fetch(const QString& url, bool isDatabase, const QString& c
// Fetch database and save pending reply. Note that we're only supporting one active download here at the moment.
m_currentReply = m_manager->get(request);
if(isDatabase)
m_currentReply->setProperty("type", "database");
else
m_currentReply->setProperty("type", "dir");
m_currentReply->setProperty("type", type);
m_currentReply->setProperty("userdata", userdata);
// Initialise the progress dialog for this request, but only if this is a database file. Directory listing are small enough to be loaded
// without progress dialog.
if(isDatabase)
if(type == RequestTypeDatabase)
prepareProgressDialog(false, url);
}
@@ -323,7 +320,7 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
// Fetch database and save pending reply. Note that we're only supporting one active download here at the moment.
m_currentReply = m_manager->put(request, file_data);
m_currentReply->setProperty("type", "push");
m_currentReply->setProperty("type", RequestTypePush);
// Initialise the progress dialog for this request
prepareProgressDialog(true, url);

View File

@@ -24,7 +24,14 @@ public:
const QList<QSslCertificate>& caCertificates() const;
const QMap<QString, QSslCertificate>& clientCertificates() const { return m_clientCertFiles; }
void fetch(const QString& url, bool isDatabase, const QString& clientCert, QVariant userdata = QVariant());
enum RequestType
{
RequestTypeDatabase,
RequestTypeDirectory,
RequestTypePush,
};
void fetch(const QString& url, RequestType type, const QString& clientCert, QVariant userdata = QVariant());
void push(const QString& filename, const QString& url, const QString& clientCert);
signals:

View File

@@ -70,5 +70,5 @@ void RemoteDock::fetchDatabase(const QModelIndex& idx)
// Only open database file
if(item->value(RemoteModelColumnType).toString() == "database")
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), true, remoteModel->currentClientCertificate());
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), RemoteDatabase::RequestTypeDatabase, remoteModel->currentClientCertificate());
}

View File

@@ -115,7 +115,7 @@ void RemoteModel::setNewRootDir(const QString& url, const QString& cert)
currentClientCert = cert;
// Fetch root directory and put the reply data under the root item
remoteDatabase.fetch(currentRootDirectory, false, currentClientCert, QModelIndex());
remoteDatabase.fetch(currentRootDirectory, RemoteDatabase::RequestTypeDirectory, currentClientCert, QModelIndex());
}
void RemoteModel::parseDirectoryListing(const QString& json, const QVariant& userdata)
@@ -298,7 +298,7 @@ void RemoteModel::fetchMore(const QModelIndex& parent)
// Fetch item URL
item->setFetchedDirectoryList(true);
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), false, currentClientCert, parent);
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), RemoteDatabase::RequestTypeDirectory, currentClientCert, parent);
}
const QString& RemoteModel::currentClientCertificate() const