From 1f420ee5cf2d853e55efde335b8a4e3939e5aa9e Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 11 Apr 2014 12:21:00 +0200 Subject: [PATCH] Some updates... --- CMakeLists.txt | 5 ++--- src/core/feedsmodelfeed.cpp | 4 ++-- src/gui/formupdate.cpp | 2 +- src/miscellaneous/systemfactory.cpp | 2 +- src/network-web/downloader.cpp | 8 +++++++ src/network-web/downloader.h | 24 +++++++++++++++++++++ src/network-web/networkfactory.cpp | 33 ++++++++++++++++++----------- src/network-web/networkfactory.h | 2 +- src/updater/definitions.h.in | 17 +++++++++++++++ src/updater/detector.cpp | 14 ------------ src/updater/detector.h | 17 --------------- src/updater/main.cpp | 7 ------ 12 files changed, 77 insertions(+), 58 deletions(-) create mode 100644 src/network-web/downloader.cpp create mode 100644 src/network-web/downloader.h delete mode 100644 src/updater/detector.cpp delete mode 100644 src/updater/detector.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c3d327af4..05d0a6689 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,6 +346,7 @@ set(APP_SOURCES src/network-web/webfactory.cpp src/network-web/webbrowser.cpp src/network-web/webview.cpp + src/network-web/downloader.cpp # MAIN sources. src/application.cpp @@ -418,6 +419,7 @@ set(APP_HEADERS src/network-web/webfactory.h src/network-web/webbrowser.h src/network-web/webview.h + src/network-web/downloader.h # MAIN headers. src/application.h @@ -470,7 +472,6 @@ if(WIN32 OR OS2) src/qtsingleapplication/qtlocalpeer.cpp src/qtsingleapplication/qtsinglecoreapplication.cpp - src/updater/detector.cpp src/updater/main.cpp ) @@ -478,8 +479,6 @@ if(WIN32 OR OS2) # QTSINGLEAPPLICATION headers. src/qtsingleapplication/qtlocalpeer.h src/qtsingleapplication/qtsinglecoreapplication.h - - src/updater/detector.h ) endif(WIN32 OR OS2) diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index 255d8ce93..7100b705a 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -145,7 +145,7 @@ QPair FeedsModelFeed::guessFeed(co } QByteArray feed_contents; - if ((result.second = NetworkFactory::downloadFile(url, + if ((result.second = NetworkFactory::downloadFeedFile(url, Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(), feed_contents, !username.isEmpty(), @@ -349,7 +349,7 @@ QVariant FeedsModelFeed::data(int column, int role) const { void FeedsModelFeed::update() { QByteArray feed_contents; int download_timeout = Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(); - QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(), + QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url(), download_timeout, feed_contents, passwordProtected(), diff --git a/src/gui/formupdate.cpp b/src/gui/formupdate.cpp index 163b233f5..451f3c6f1 100755 --- a/src/gui/formupdate.cpp +++ b/src/gui/formupdate.cpp @@ -116,7 +116,7 @@ void FormUpdate::startUpdate() { // On Windows/OS2 we can update the application right away. // Download the files. QByteArray output; - QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url_file, + QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url_file, 10 * DOWNLOAD_TIMEOUT, output); diff --git a/src/miscellaneous/systemfactory.cpp b/src/miscellaneous/systemfactory.cpp index 20baed197..4e21c5f55 100644 --- a/src/miscellaneous/systemfactory.cpp +++ b/src/miscellaneous/systemfactory.cpp @@ -170,7 +170,7 @@ QPair SystemFactory::checkForUpdates() QPair result; QByteArray releases_xml; - result.second = NetworkFactory::downloadFile(RELEASES_LIST, + result.second = NetworkFactory::downloadFeedFile(RELEASES_LIST, 5000, releases_xml); diff --git a/src/network-web/downloader.cpp b/src/network-web/downloader.cpp new file mode 100644 index 000000000..6025a4fe7 --- /dev/null +++ b/src/network-web/downloader.cpp @@ -0,0 +1,8 @@ +#include "network-web/downloader.h" + + +Downloader::Downloader(QObject *parent) : QObject(parent) { +} + +Downloader::~Downloader() { +} diff --git a/src/network-web/downloader.h b/src/network-web/downloader.h new file mode 100644 index 000000000..3f2d941ee --- /dev/null +++ b/src/network-web/downloader.h @@ -0,0 +1,24 @@ +#ifndef DOWNLOADER_H +#define DOWNLOADER_H + +#include + + +class Downloader : public QObject { + Q_OBJECT + + public: + // Constructors and destructors. + explicit Downloader(QObject *parent = 0); + virtual ~Downloader(); + + // TODO: zakladni downloader s timeoutem a signalem kerej informuje o prubehu + // stahovani + + signals: + + public slots: + +}; + +#endif // DOWNLOADER_H diff --git a/src/network-web/networkfactory.cpp b/src/network-web/networkfactory.cpp index 424adab5d..31c6844f7 100644 --- a/src/network-web/networkfactory.cpp +++ b/src/network-web/networkfactory.cpp @@ -25,7 +25,6 @@ #include #include #include -#include NetworkFactory::NetworkFactory() { @@ -105,9 +104,9 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url, #endif QByteArray icon_data; - QNetworkReply::NetworkError network_result = downloadFile(google_s2_with_url, - timeout, - icon_data); + QNetworkReply::NetworkError network_result = downloadFeedFile(google_s2_with_url, + timeout, + icon_data); if (network_result == QNetworkReply::NoError) { QPixmap icon_pixmap; @@ -118,12 +117,12 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url, return network_result; } -QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, - int timeout, - QByteArray &output, - bool protected_contents, - const QString &username, - const QString &password) { +QNetworkReply::NetworkError NetworkFactory::downloadFeedFile(const QString &url, + int timeout, + QByteArray &output, + bool protected_contents, + const QString &username, + const QString &password) { // Original asynchronous behavior of QNetworkAccessManager // is replaced by synchronous behavior in order to make // process of downloading of a file easier to understand. @@ -171,7 +170,10 @@ QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, timer.stop(); } else { - reply->deleteLater(); + if (reply != NULL) { + delete reply; + reply = NULL; + } // Timer already fired. Download is NOT successful. return QNetworkReply::TimeoutError; @@ -184,6 +186,9 @@ QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, // Communication indicates that HTTP redirection is needed. // Setup redirection URL and download again. request.setUrl(redirection_url); + + delete reply; + reply = NULL; } else { // No redirection is indicated. Final file is obtained @@ -203,6 +208,10 @@ QNetworkReply::NetworkError NetworkFactory::downloadFile(const QString &url, reply_error); // Delete needed stuff and exit. - reply->deleteLater(); + if (reply != NULL) { + delete reply; + reply = NULL; + } + return reply_error; } diff --git a/src/network-web/networkfactory.h b/src/network-web/networkfactory.h index 6c245f1cd..c6707ca2d 100644 --- a/src/network-web/networkfactory.h +++ b/src/network-web/networkfactory.h @@ -41,7 +41,7 @@ class NetworkFactory { // Performs SYNCHRONOUS download of file with given URL // and given timeout. - static QNetworkReply::NetworkError downloadFile(const QString &url, + static QNetworkReply::NetworkError downloadFeedFile(const QString &url, int timeout, QByteArray &output, bool protected_contents = false, diff --git a/src/updater/definitions.h.in b/src/updater/definitions.h.in index 44ca5ad18..c4b45fac8 100644 --- a/src/updater/definitions.h.in +++ b/src/updater/definitions.h.in @@ -1,3 +1,20 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + #ifndef DEFINITIONS_H_IN #define DEFINITIONS_H_IN diff --git a/src/updater/detector.cpp b/src/updater/detector.cpp deleted file mode 100644 index 7207b5961..000000000 --- a/src/updater/detector.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "updater/detector.h" - - -Detector::Detector(QObject *parent) : QObject(parent) { -} - -void Detector::handleMessage(const QString &message) { - if (message == "app_is_running") { - qDebug("Another instance of RSS Guard/Updater was starting..."); - } - else if (message == "app_quit") { - // zprava na vypnuti, tu ignorujeme. - } -} diff --git a/src/updater/detector.h b/src/updater/detector.h deleted file mode 100644 index e54d46e2a..000000000 --- a/src/updater/detector.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DETECTOR_H -#define DETECTOR_H - -#include - - -class Detector : public QObject { - Q_OBJECT - - public: - explicit Detector(QObject *parent = 0); - - public slots: - void handleMessage(const QString& message); -}; - -#endif // DETECTOR_H diff --git a/src/updater/main.cpp b/src/updater/main.cpp index 6eb9bb639..8af7caf70 100644 --- a/src/updater/main.cpp +++ b/src/updater/main.cpp @@ -16,7 +16,6 @@ // along with RSS Guard. If not, see . #include "qtsingleapplication/qtsinglecoreapplication.h" -#include "updater/detector.h" #include "updater/definitions.h" #include @@ -125,15 +124,9 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - Detector detector; - qDebug().nospace() << "Running updater in thread: \'" << QThread::currentThreadId() << "\'."; - // Setup single-instance behavior. - QObject::connect(&application, SIGNAL(messageReceived(QString)), - &detector, SLOT(handleMessage(QString))); - QString extractor_program(EXECUTABLE_7ZA); QStringList arguments; QString output_temp_directory = temp_directory + QDir::separator() + RSSGUARD_LOW_NAME;