From: lvaatamoinen Date: Fri, 20 Nov 2009 06:50:48 +0000 (+0000) Subject: -Added some error checking to torrent file writing X-Git-Url: http://git.maemo.org/git/?p=qtrapids;a=commitdiff_plain;h=a25be1792ef730256ea47908df24b1bbbded553d -Added some error checking to torrent file writing git-svn-id: file:///svnroot/qtrapids/trunk@44 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- diff --git a/src/plugins/searchplugin/DownloadManager.cpp b/src/plugins/searchplugin/DownloadManager.cpp index 01e2cb4..a16d457 100644 --- a/src/plugins/searchplugin/DownloadManager.cpp +++ b/src/plugins/searchplugin/DownloadManager.cpp @@ -58,7 +58,10 @@ void DownloadManager::start() void DownloadManager::on_readyRead() { //qDebug() << "on_readyRead()"; - WriteToFile(); + if(!WriteToFile()) { + qWarning() << "DownloadManager::on_readyRead(): Writing to file: " + << filepath_ << " failed."; + } } void DownloadManager::on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal) @@ -83,14 +86,18 @@ void DownloadManager::on_replyFinished() } -void DownloadManager::WriteToFile() +bool DownloadManager::WriteToFile() { QByteArray readData = reply_->readAll(); if (readData.isEmpty()) { qDebug() << "on_replyFinished(): No data available for reading"; } else { - file_.write(readData); - /// @todo check file_.error() + // If writing failed, see error message. + if (file_.write(readData) == -1) { + qWarning() << file_.error(); + return false; + } } + return true; } diff --git a/src/plugins/searchplugin/DownloadManager.h b/src/plugins/searchplugin/DownloadManager.h index f95a3d0..2b65c16 100644 --- a/src/plugins/searchplugin/DownloadManager.h +++ b/src/plugins/searchplugin/DownloadManager.h @@ -50,7 +50,7 @@ class DownloadManager : public QObject void finished(QString filepath); private: - void WriteToFile(); + bool WriteToFile(); private: QNetworkAccessManager manager_; diff --git a/src/plugins/searchplugin/SearchPlugin.cpp b/src/plugins/searchplugin/SearchPlugin.cpp index 55e104e..4440063 100644 --- a/src/plugins/searchplugin/SearchPlugin.cpp +++ b/src/plugins/searchplugin/SearchPlugin.cpp @@ -100,15 +100,19 @@ namespace qtrapids void SearchPlugin::on_loadFinished(bool ok) { +#ifdef QTRAPIDS_DEBUG if (ok) { - qDebug() << "on_loadFinished()"; + qDebug() << "on_loadFinished(): success"; } +#endif } void SearchPlugin::on_searchResult(QWidget* resultWidget) { +#ifdef QTRAPIDS_DEBUG qDebug() << "on_searchResult()"; +#endif if (host_) { host_->addPluginWidget(resultWidget, qtrapids::PluginHostInterface::TAB_PAGE); } @@ -124,7 +128,9 @@ namespace qtrapids /// @todo We should also check MIME-type, instead of relying on file suffix. /// @todo Also, after downloading, the torrent bencoding validity should be checked at plugin host.. if (fInfo.suffix() == "torrent") { +#ifdef QTRAPIDS_DEBUG qDebug() << "IS TORRENT"; +#endif QString filename = fInfo.fileName(); // Destroy ongoing download, if any. @@ -147,7 +153,9 @@ namespace qtrapids void SearchPlugin::on_downloadFinished(QString filepath) { +#ifdef QTRAPIDS_DEBUG qDebug() << "TORRENT DOWNLOADED: " << filepath; +#endif delete dlManager_; dlManager_ = NULL; host_->eventRequest(QVariant(filepath), qtrapids::PluginHostInterface::OPEN_FILE);