diff options
author | kh <karsten.heimrich@theqtcompany.com> | 2014-11-24 13:03:17 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2014-11-24 17:44:58 +0100 |
commit | 68b3092d32a285850bd55ed4ac4f66a335c02ba0 (patch) | |
tree | cab771ecef1cfffc55bf40604c0f36585775247d /src | |
parent | bdb0247bea51ed296ae31ea2efaff3380607a00e (diff) |
Rename the exceptions class to be more generic.
Change-Id: Ia96477920055ee6a6f15be1334516746ddf3573b
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/abstractfiletask.cpp | 2 | ||||
-rw-r--r-- | src/libs/installer/abstractfiletask.h | 18 | ||||
-rw-r--r-- | src/libs/installer/abstracttask.h | 17 | ||||
-rw-r--r-- | src/libs/installer/copyfiletask.cpp | 8 | ||||
-rw-r--r-- | src/libs/installer/downloadfiletask.cpp | 24 | ||||
-rw-r--r-- | src/libs/installer/downloadfiletask.h | 2 | ||||
-rw-r--r-- | src/libs/installer/metadatajob.cpp | 4 |
7 files changed, 38 insertions, 37 deletions
diff --git a/src/libs/installer/abstractfiletask.cpp b/src/libs/installer/abstractfiletask.cpp index cc40d23bf..90cc862ee 100644 --- a/src/libs/installer/abstractfiletask.cpp +++ b/src/libs/installer/abstractfiletask.cpp @@ -104,7 +104,7 @@ void AbstractFileTask::registerMetaTypes() { qRegisterMetaType<QInstaller::FileTaskItem>(); qRegisterMetaType<QInstaller::FileTaskResult>(); - qRegisterMetaType<QInstaller::FileTaskException>(); + qRegisterMetaType<QInstaller::TaskException>(); } } // namespace QInstaller diff --git a/src/libs/installer/abstractfiletask.h b/src/libs/installer/abstractfiletask.h index 927082a45..54a7af3ba 100644 --- a/src/libs/installer/abstractfiletask.h +++ b/src/libs/installer/abstractfiletask.h @@ -88,22 +88,6 @@ public: FileTaskItem taskItem() const { return value(TaskRole::TaskItem).value<FileTaskItem>(); } }; -class FileTaskException : public QException -{ -public: - FileTaskException() {} - ~FileTaskException() throw() {} - explicit FileTaskException(const QString &message) - : m_message(message) {} - - void raise() const { throw *this; } - QString message() const { return m_message; } - FileTaskException *clone() const { return new FileTaskException(*this); } - -private: - QString m_message; -}; - class INSTALLER_EXPORT AbstractFileTask : public AbstractTask<FileTaskResult> { Q_OBJECT @@ -138,6 +122,6 @@ private: Q_DECLARE_METATYPE(QInstaller::FileTaskItem) Q_DECLARE_METATYPE(QInstaller::FileTaskResult) -Q_DECLARE_METATYPE(QInstaller::FileTaskException) +Q_DECLARE_METATYPE(QInstaller::TaskException) #endif // ABSTRACTFILETASK_H diff --git a/src/libs/installer/abstracttask.h b/src/libs/installer/abstracttask.h index 1caa33957..36faa0e1e 100644 --- a/src/libs/installer/abstracttask.h +++ b/src/libs/installer/abstracttask.h @@ -55,6 +55,23 @@ private: }; inline AbstractTaskData::~AbstractTaskData() {} +class TaskException : public QException +{ +public: + TaskException() {} + ~TaskException() throw() {} + explicit TaskException(const QString &message) + : m_message(message) + {} + + void raise() const { throw *this; } + QString message() const { return m_message; } + TaskException *clone() const { return new TaskException(*this); } + +private: + QString m_message; +}; + template <typename T> class AbstractTask : public QObject { diff --git a/src/libs/installer/copyfiletask.cpp b/src/libs/installer/copyfiletask.cpp index 979cdeeb5..37fd3cb1f 100644 --- a/src/libs/installer/copyfiletask.cpp +++ b/src/libs/installer/copyfiletask.cpp @@ -60,7 +60,7 @@ void CopyFileTask::doTask(QFutureInterface<FileTaskResult> &fi) fi.setExpectedResultCount(1); if (taskItems().isEmpty()) { - fi.reportException(FileTaskException(QLatin1String("Invalid task item count."))); + fi.reportException(TaskException(QLatin1String("Invalid task item count."))); fi.reportFinished(); return; // error } @@ -69,7 +69,7 @@ void CopyFileTask::doTask(QFutureInterface<FileTaskResult> &fi) QFile source(item.source()); if (!source.open(QIODevice::ReadOnly)) { - fi.reportException(FileTaskException(QString::fromLatin1("Could not open source '%1' " + fi.reportException(TaskException(QString::fromLatin1("Could not open source '%1' " "for read. Error: %2.").arg(source.fileName(), source.errorString()))); fi.reportFinished(); return; // error } @@ -85,7 +85,7 @@ void CopyFileTask::doTask(QFutureInterface<FileTaskResult> &fi) file.reset(new QFile(target)); } if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) { - fi.reportException(FileTaskException(QString::fromLatin1("Could not open target '%1' " + fi.reportException(TaskException(QString::fromLatin1("Could not open target '%1' " "for write. Error: %2.").arg(file->fileName(), file->errorString()))); fi.reportFinished(); return; // error } @@ -102,7 +102,7 @@ void CopyFileTask::doTask(QFutureInterface<FileTaskResult> &fi) while (written < read) { const qint64 toWrite = file->write(buffer.constData() + written, read - written); if (toWrite < 0) { - fi.reportException(FileTaskException(QString::fromLatin1("Writing to target " + fi.reportException(TaskException(QString::fromLatin1("Writing to target " "'%1' failed. Error: %2.").arg(file->fileName(), file->errorString()))); } written += toWrite; diff --git a/src/libs/installer/downloadfiletask.cpp b/src/libs/installer/downloadfiletask.cpp index 0bd38615e..bdab318b4 100644 --- a/src/libs/installer/downloadfiletask.cpp +++ b/src/libs/installer/downloadfiletask.cpp @@ -48,7 +48,7 @@ namespace QInstaller { ProxyAuthenticationRequiredException::ProxyAuthenticationRequiredException(const QNetworkProxy &proxy) - : FileTaskException(QCoreApplication::translate("ProxyAuthenticationRequiredException", + : TaskException(QCoreApplication::translate("ProxyAuthenticationRequiredException", "Proxy requires authentication.")), m_proxy(proxy) { @@ -124,7 +124,7 @@ void Downloader::onReadyRead() if (!data.file->isOpen()) { //: %2 is a sentence describing the error. m_futureInterface->reportException( - FileTaskException(tr("Target '%1' not open for write. Error: %2.").arg( + TaskException(tr("Target '%1' not open for write. Error: %2.").arg( data.file->fileName(), data.file->errorString()))); return; } @@ -143,7 +143,7 @@ void Downloader::onReadyRead() if (toWrite < 0) { //: %2 is a sentence describing the error. m_futureInterface->reportException( - FileTaskException(tr("Writing to target '%1' failed. Error: %2.").arg( + TaskException(tr("Writing to target '%1' failed. Error: %2.").arg( data.file->fileName(), data.file->errorString()))); return; } @@ -193,7 +193,7 @@ void Downloader::onFinished(QNetworkReply *reply) return; } else { m_futureInterface->reportException( - FileTaskException(tr("Redirect loop detected '%1'.").arg(url.toString()))); + TaskException(tr("Redirect loop detected '%1'.").arg(url.toString()))); return; } } @@ -210,7 +210,7 @@ void Downloader::onFinished(QNetworkReply *reply) if (!expectedCheckSum.isEmpty()) { if (expectedCheckSum != data.observer->checkSum().toHex()) { m_futureInterface->reportException( - FileTaskException(tr("Checksum mismatch detected '%1'.").arg( + TaskException(tr("Checksum mismatch detected '%1'.").arg( reply->url().toString()))); } } @@ -244,12 +244,12 @@ void Downloader::onError(QNetworkReply::NetworkError error) const Data &data = m_downloads[reply]; //: %2 is a sentence describing the error m_futureInterface->reportException( - FileTaskException(tr("Network error while downloading '%1': %2.").arg( + TaskException(tr("Network error while downloading '%1': %2.").arg( data.taskItem.source(), reply->errorString()))); } else { //: %1 is a sentence describing the error m_futureInterface->reportException( - FileTaskException(tr("Unknown network error while downloading: %1.").arg(error))); + TaskException(tr("Unknown network error while downloading: %1.").arg(error))); } } @@ -286,7 +286,7 @@ void Downloader::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator * item->insert(TaskRole::Authenticator, QVariant()); // clear so we fail on next call } else { m_futureInterface->reportException( - FileTaskException(tr("Could not authenticate using the provided credentials. " + TaskException(tr("Could not authenticate using the provided credentials. " "Source: '%1'.").arg(reply->url().toString()))); } } @@ -307,7 +307,7 @@ bool Downloader::testCanceled() if (m_futureInterface->isPaused()) { m_futureInterface->togglePaused(); // Note: this will trigger cancel m_futureInterface->reportException( - FileTaskException(tr("Pause and resume not supported by network transfers."))); + TaskException(tr("Pause and resume not supported by network transfers."))); } return m_futureInterface->isCanceled(); } @@ -318,7 +318,7 @@ QNetworkReply *Downloader::startDownload(const FileTaskItem &item) if (!source.isValid()) { //: %2 is a sentence describing the error m_futureInterface->reportException( - FileTaskException(tr("Invalid source '%1'. Error: %2.").arg( + TaskException(tr("Invalid source '%1'. Error: %2.").arg( source.toString(), source.errorString()))); return 0; } @@ -335,7 +335,7 @@ QNetworkReply *Downloader::startDownload(const FileTaskItem &item) if (file->exists() && (!QFileInfo(file->fileName()).isFile())) { m_futureInterface->reportException( - FileTaskException(tr("Target file '%1' already exists but is not a file.").arg( + TaskException(tr("Target file '%1' already exists but is not a file.").arg( file->fileName()))); return 0; } @@ -343,7 +343,7 @@ QNetworkReply *Downloader::startDownload(const FileTaskItem &item) if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) { //: %2 is a sentence describing the error m_futureInterface->reportException( - FileTaskException(tr("Could not open target '%1' for write. Error: %2.").arg( + TaskException(tr("Could not open target '%1' for write. Error: %2.").arg( file->fileName(), file->errorString()))); return 0; } diff --git a/src/libs/installer/downloadfiletask.h b/src/libs/installer/downloadfiletask.h index 6b3ddf24e..c9f7281da 100644 --- a/src/libs/installer/downloadfiletask.h +++ b/src/libs/installer/downloadfiletask.h @@ -50,7 +50,7 @@ enum }; } -class ProxyAuthenticationRequiredException : public FileTaskException +class ProxyAuthenticationRequiredException : public TaskException { public: ProxyAuthenticationRequiredException(const QNetworkProxy &proxy); diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp index 6cb5652c2..ead3dd922 100644 --- a/src/libs/installer/metadatajob.cpp +++ b/src/libs/installer/metadatajob.cpp @@ -136,7 +136,7 @@ void MetadataJob::xmlTaskFinished() reset(); emitFinishedWithError(QInstaller::DownloadError, tr("Missing proxy credentials.")); } - } catch (const FileTaskException &e) { + } catch (const TaskException &e) { reset(); emitFinishedWithError(QInstaller::DownloadError, e.message()); } catch (const QUnhandledException &e) { @@ -218,7 +218,7 @@ void MetadataJob::metadataTaskFinished() } else { emitFinished(); } - } catch (const FileTaskException &e) { + } catch (const TaskException &e) { reset(); emitFinishedWithError(QInstaller::DownloadError, e.message()); } catch (const QUnhandledException &e) { |