diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index ec8a3400..2d6fb42a 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -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(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); diff --git a/src/RemoteDatabase.h b/src/RemoteDatabase.h index 7d002992..756d5680 100644 --- a/src/RemoteDatabase.h +++ b/src/RemoteDatabase.h @@ -24,7 +24,14 @@ public: const QList& caCertificates() const; const QMap& 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: diff --git a/src/RemoteDock.cpp b/src/RemoteDock.cpp index 8a1db1e8..1834be6e 100644 --- a/src/RemoteDock.cpp +++ b/src/RemoteDock.cpp @@ -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()); } diff --git a/src/RemoteModel.cpp b/src/RemoteModel.cpp index e0dbe06a..5e3235fe 100644 --- a/src/RemoteModel.cpp +++ b/src/RemoteModel.cpp @@ -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