diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 7c01729ad..54415b169 100755 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -105,10 +105,12 @@ void FeedDownloader::oneFeedUpdateFinished(const QList &messages) { << feed->id() << " in thread: \'" << QThread::currentThreadId() << "\'."; - int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages); + if (!m_stopUpdate) { + int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages); - if (updated_messages > 0) { - m_results.appendUpdatedFeed(QPair(feed->title(), updated_messages)); + if (updated_messages > 0) { + m_results.appendUpdatedFeed(QPair(feed->title(), updated_messages)); + } } qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id()); diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 9ae8fc752..8a964466a 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -76,34 +76,6 @@ FeedsModel::~FeedsModel() { delete m_rootItem; } -/* -void FeedsModel::onFeedUpdatesStarted() { - //: Text display in status bar when feed update is started. - qApp->mainForm()->statusBar()->showProgressFeeds(0, tr("Feed update started")); - - emit feedsUpdateStarted(); -} - -void FeedsModel::onFeedUpdatesProgress(const Feed *feed, int current, int total) { - // Some feed got updated. - qApp->mainForm()->statusBar()->showProgressFeeds((current * 100.0) / total, - //: Text display in status bar when particular feed is updated. - tr("Updated feed '%1'").arg(feed->title())); -} - -void FeedsModel::onFeedUpdatesFinished(const FeedDownloadResults &results) { - qApp->feedUpdateLock()->unlock(); - qApp->mainForm()->statusBar()->clearProgressFeeds(); - - if (!results.updatedFeeds().isEmpty()) { - // Now, inform about results via GUI message/notification. - qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, 0, false); - } - - emit feedsUpdateFinished(); -} -*/ - QMimeData *FeedsModel::mimeData(const QModelIndexList &indexes) const { QMimeData *mime_data = new QMimeData(); QByteArray encoded_data; diff --git a/src/definitions/definitions.h b/src/definitions/definitions.h index 066abfff2..c6293ddd4 100755 --- a/src/definitions/definitions.h +++ b/src/definitions/definitions.h @@ -45,7 +45,7 @@ #define ID_RECYCLE_BIN -2 #define TRAY_ICON_BUBBLE_TIMEOUT 20000 #define KEY_MESSAGES_VIEW "messages_view_column_" -#define CLOSE_LOCK_TIMEOUT 1500 +#define CLOSE_LOCK_TIMEOUT 500 #define DOWNLOAD_TIMEOUT 5000 #define MESSAGES_VIEW_DEFAULT_COL 170 #define FEEDS_VIEW_COLUMN_COUNT 2 diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index 41c0f5480..545e8923b 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -331,7 +331,10 @@ void FormMain::updateAccountsMenu() { } void FormMain::onFeedUpdatesFinished(FeedDownloadResults results) { + Q_UNUSED(results) + statusBar()->clearProgressFeeds(); + tabWidget()->feedMessageViewer()->messagesView()->reloadSelections(false); } void FormMain::onFeedUpdatesStarted() { diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 86edcc302..2e0c8c3ed 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -214,7 +214,6 @@ void FeedMessageViewer::createConnections() { // to reload selections. connect(m_feedsView->sourceModel(), SIGNAL(reloadMessageListRequested(bool)), m_messagesView, SLOT(reloadSelections(bool))); - connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateFinished()), this, SLOT(onFeedsUpdateFinished())); } void FeedMessageViewer::initialize() { @@ -298,7 +297,3 @@ void FeedMessageViewer::refreshVisualProperties() { m_toolBarFeeds->setToolButtonStyle(button_style); m_toolBarMessages->setToolButtonStyle(button_style); } - -void FeedMessageViewer::onFeedsUpdateFinished() { - m_messagesView->reloadSelections(false); -} diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 587802352..b9d0262cb 100755 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -73,9 +73,6 @@ class FeedMessageViewer : public TabContent { void refreshVisualProperties(); private slots: - // Called when feed update finishes. - void onFeedsUpdateFinished(); - // Switches visibility of feed list and related // toolbar. void switchFeedComponentVisibility(); diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index 588668eaf..3c523ab2f 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -225,26 +225,30 @@ void Application::restoreDatabaseSettings(bool restore_database, bool restore_se void Application::processExecutionMessage(const QString &message) { qDebug("Received '%s' execution message from another application instance.", qPrintable(message)); - foreach (const QString &msg, message.split(ARGUMENTS_LIST_SEPARATOR)) { - if (msg == APP_IS_RUNNING) { - showGuiMessage(APP_NAME, tr("Application is already running."), QSystemTrayIcon::Information); - mainForm()->display(); - } - else if (msg == APP_QUIT_INSTANCE) { - quit(); - } - else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) { - // Application was running, and someone wants to add new feed. - StandardServiceRoot *root = qApp->feedReader()->feedsModel()->standardServiceRoot(); + const QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR); - if (root != nullptr) { - root->checkArgumentForFeedAdding(msg); + if (messages.contains(APP_QUIT_INSTANCE)) { + quit(); + } + else { + foreach (const QString &msg, message.split(ARGUMENTS_LIST_SEPARATOR)) { + if (msg == APP_IS_RUNNING) { + showGuiMessage(APP_NAME, tr("Application is already running."), QSystemTrayIcon::Information); + mainForm()->display(); } - else { - showGuiMessage(tr("Cannot add feed"), - tr("Feed cannot be added because standard RSS/ATOM account is not enabled."), - QSystemTrayIcon::Warning, qApp->mainForm(), - true); + else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) { + // Application was running, and someone wants to add new feed. + StandardServiceRoot *root = qApp->feedReader()->feedsModel()->standardServiceRoot(); + + if (root != nullptr) { + root->checkArgumentForFeedAdding(msg); + } + else { + showGuiMessage(tr("Cannot add feed"), + tr("Feed cannot be added because standard RSS/ATOM account is not enabled."), + QSystemTrayIcon::Warning, qApp->mainForm(), + true); + } } } } @@ -322,9 +326,11 @@ void Application::onAboutToQuit() { #endif qApp->feedReader()->stop(); - database()->saveDatabase(); - mainForm()->saveSize(); + + if (mainForm() != nullptr) { + mainForm()->saveSize(); + } if (locked_safely) { // Application obtained permission to close in a safe way. @@ -356,8 +362,6 @@ void Application::onFeedUpdatesProgress(const Feed *feed, int current, int total } void Application::onFeedUpdatesFinished(FeedDownloadResults results) { - qApp->feedUpdateLock()->unlock(); - if (!results.updatedFeeds().isEmpty()) { // Now, inform about results via GUI message/notification. qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, 0, false); diff --git a/src/miscellaneous/feedreader.cpp b/src/miscellaneous/feedreader.cpp index faaf2cdd2..630f60687 100755 --- a/src/miscellaneous/feedreader.cpp +++ b/src/miscellaneous/feedreader.cpp @@ -85,6 +85,7 @@ void FeedReader::updateFeeds(const QList &feeds) { connect(m_feedDownloader, &FeedDownloader::updateFinished, this, &FeedReader::feedUpdatesFinished); connect(m_feedDownloader, &FeedDownloader::updateProgress, this, &FeedReader::feedUpdatesProgress); connect(m_feedDownloader, &FeedDownloader::updateStarted, this, &FeedReader::feedUpdatesStarted); + connect(m_feedDownloader, &FeedDownloader::updateFinished, qApp->feedUpdateLock(), &Mutex::unlock); // Connections are made, start the feed downloader thread. m_feedDownloaderThread->start(); diff --git a/src/miscellaneous/mutex.h b/src/miscellaneous/mutex.h index e91c77bdd..95e1e0c91 100755 --- a/src/miscellaneous/mutex.h +++ b/src/miscellaneous/mutex.h @@ -31,14 +31,16 @@ class Mutex : public QObject { virtual ~Mutex(); // Main methods. - void lock(); bool tryLock(); bool tryLock(int timeout); - void unlock(); // Identifies if mutes is locked or not. bool isLocked() const; + public slots: + void lock(); + void unlock(); + protected: // These methods set proper value for m_isLocked and emit signals. void setLocked();