From c76320fbcdd6ec5a8e9a9de945d2faec71169d9a Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 21 Jul 2023 10:06:06 +0200 Subject: [PATCH] better code flow when app starts + correctly show number badge when tray icon is active on windows startup + correctly show tray messages on app startup + remove some redundant code --- src/librssguard/gui/dialogs/formabout.cpp | 6 +- src/librssguard/gui/dialogs/formabout.h | 4 +- src/librssguard/gui/dialogs/formmain.cpp | 2 +- src/librssguard/gui/messagesview.cpp | 23 ------ src/librssguard/miscellaneous/application.cpp | 77 +++++++++++-------- src/rssguard/main.cpp | 2 - 6 files changed, 52 insertions(+), 62 deletions(-) diff --git a/src/librssguard/gui/dialogs/formabout.cpp b/src/librssguard/gui/dialogs/formabout.cpp index 8ab51c83c..530210171 100644 --- a/src/librssguard/gui/dialogs/formabout.cpp +++ b/src/librssguard/gui/dialogs/formabout.cpp @@ -19,7 +19,7 @@ #include #include -FormAbout::FormAbout(QWidget* parent) : QDialog(parent) { +FormAbout::FormAbout(bool go_to_changelog, QWidget* parent) : QDialog(parent) { m_ui.setupUi(this); m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH)); GuiUtilities::applyDialogProperties(*this, @@ -27,6 +27,10 @@ FormAbout::FormAbout(QWidget* parent) : QDialog(parent) { tr("About %1").arg(QSL(APP_NAME))); loadLicenseAndInformation(); loadSettingsAndPaths(); + + if (go_to_changelog) { + m_ui.m_tabAbout->setCurrentWidget(m_ui.m_tabChangelog); + } } FormAbout::~FormAbout() {} diff --git a/src/librssguard/gui/dialogs/formabout.h b/src/librssguard/gui/dialogs/formabout.h index f0e4599de..0faf4b700 100644 --- a/src/librssguard/gui/dialogs/formabout.h +++ b/src/librssguard/gui/dialogs/formabout.h @@ -8,10 +8,10 @@ #include "ui_formabout.h" class RSSGUARD_DLLSPEC FormAbout : public QDialog { - Q_OBJECT + Q_OBJECT public: - explicit FormAbout(QWidget* parent); + explicit FormAbout(bool go_to_changelog, QWidget* parent); virtual ~FormAbout(); private slots: diff --git a/src/librssguard/gui/dialogs/formmain.cpp b/src/librssguard/gui/dialogs/formmain.cpp index 881294f54..3c603546f 100644 --- a/src/librssguard/gui/dialogs/formmain.cpp +++ b/src/librssguard/gui/dialogs/formmain.cpp @@ -768,7 +768,7 @@ void FormMain::createConnections() { // Menu "Help" connections. connect(m_ui->m_actionAboutGuard, &QAction::triggered, this, [this]() { - FormAbout(this).exec(); + FormAbout(false, this).exec(); }); connect(m_ui->m_actionCheckForUpdates, &QAction::triggered, this, [this]() { FormUpdate(this).exec(); diff --git a/src/librssguard/gui/messagesview.cpp b/src/librssguard/gui/messagesview.cpp index a54b88a30..e36d6bd39 100644 --- a/src/librssguard/gui/messagesview.cpp +++ b/src/librssguard/gui/messagesview.cpp @@ -710,15 +710,6 @@ void MessagesView::selectItemWithCursorAction(CursorAction act) { if (index_previous.isValid()) { setCurrentIndex(index_previous); - - scrollTo(index_previous, - !m_processingAnyMouseButton && - qApp->settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool() - ? QAbstractItemView::ScrollHint::PositionAtCenter - : QAbstractItemView::ScrollHint::PositionAtTop); - - selectionModel()->select(index_previous, - QItemSelectionModel::SelectionFlag::Select | QItemSelectionModel::SelectionFlag::Rows); setFocus(); } } @@ -738,21 +729,7 @@ void MessagesView::selectNextUnreadItem() { const QModelIndex next_unread = m_proxyModel->getNextPreviousUnreadItemIndex(active_row); if (next_unread.isValid()) { - // We found unread message, mark it. setCurrentIndex(next_unread); - - // Make sure that item is properly visible even if - // message previewer was hidden and shows up. - qApp->processEvents(); - - scrollTo(next_unread, - !m_processingAnyMouseButton && - qApp->settings()->value(GROUP(Messages), SETTING(Messages::KeepCursorInCenter)).toBool() - ? QAbstractItemView::ScrollHint::PositionAtCenter - : QAbstractItemView::ScrollHint::PositionAtTop); - - selectionModel()->select(next_unread, - QItemSelectionModel::SelectionFlag::Select | QItemSelectionModel::SelectionFlag::Rows); setFocus(); } } diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index 06c304e35..1a7d182a7 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -299,8 +299,10 @@ void Application::showPolls() const { {QSL("%1 survey").arg(QSL(APP_NAME)), QSL("Please, fill the survey."), QSystemTrayIcon::MessageIcon::Warning}, - {false, true, false}); - qApp->web()->openUrlInExternalBrowser(QSL("https://forms.gle/FdzrwFGozCGViK8QA")); + {false, true, false}, + {tr("Go to survey"), [] { + qApp->web()->openUrlInExternalBrowser(QSL("https://forms.gle/FdzrwFGozCGViK8QA")); + }}); } */ } @@ -312,10 +314,10 @@ void Application::offerChanges() const { tr("Welcome to %1.\n\nPlease, check NEW stuff included in this\n" "version by clicking this popup notification.") .arg(QSL(APP_LONG_NAME)), - QSystemTrayIcon::MessageIcon::NoIcon}, + QSystemTrayIcon::MessageIcon::Information}, {}, {tr("Go to changelog"), [] { - FormAbout(qApp->mainForm()).exec(); + FormAbout(true, qApp->mainForm()).exec(); }}); } } @@ -607,27 +609,28 @@ void Application::showTrayIcon() { if (SystemTrayIcon::isSystemTrayDesired()) { qDebugNN << LOGSEC_GUI << "User wants to have tray icon."; -#if defined(Q_OS_WIN) - if (SystemTrayIcon::isSystemTrayAreaAvailable()) { - qDebugNN << LOGSEC_GUI << "Tray icon is available, showing now."; - trayIcon()->show(); - } - else { - m_feedReader->feedsModel()->notifyWithCounts(); - } -#else // Delay avoids race conditions and tray icon is properly displayed. - qWarningNN << LOGSEC_GUI << "Showing tray icon with 3000 ms delay."; - QTimer::singleShot(3000, this, [=]() { - if (SystemTrayIcon::isSystemTrayAreaAvailable()) { - qWarningNN << LOGSEC_GUI << "Tray icon is available, showing now."; - trayIcon()->show(); - } - else { - m_feedReader->feedsModel()->notifyWithCounts(); - } - }); + qWarningNN << LOGSEC_GUI << "Showing tray icon with little delay."; + + QTimer::singleShot( +#if defined(Q_OS_WIN) + 500, +#else + 3000, #endif + this, + [=]() { + if (SystemTrayIcon::isSystemTrayAreaAvailable()) { + qWarningNN << LOGSEC_GUI << "Tray icon is available, showing now."; + trayIcon()->show(); + + offerChanges(); + showPolls(); + } + else { + m_feedReader->feedsModel()->notifyWithCounts(); + } + }); } else { m_feedReader->feedsModel()->notifyWithCounts(); @@ -651,7 +654,6 @@ void Application::showGuiMessage(Notification::Event event, const GuiMessageDestination& dest, const GuiAction& action, QWidget* parent) { - if (SystemTrayIcon::areNotificationsEnabled()) { auto notification = m_notifications->notificationForEvent(event); @@ -796,25 +798,34 @@ void Application::showMessagesNumber(int unread_messages, bool any_feed_has_new_ bool task_bar_count_enabled = settings()->value(GROUP(GUI), SETTING(GUI::UnreadNumbersOnTaskBar)).toBool(); if (m_mainForm != nullptr) { - QImage overlay_icon = generateOverlayIcon(unread_messages); + bool any_count = task_bar_count_enabled && unread_messages > 0; + HRESULT overlay_result; + + if (any_count) { + QImage overlay_icon = generateOverlayIcon(unread_messages); #if QT_VERSION_MAJOR == 5 - HICON overlay_hicon = QtWin::toHICON(QPixmap::fromImage(overlay_icon)); + HICON overlay_hicon = QtWin::toHICON(QPixmap::fromImage(overlay_icon)); #else - HICON overlay_hicon = overlay_icon.toHICON(); + HICON overlay_hicon = overlay_icon.toHICON(); #endif - HRESULT overlay_result = - m_windowsTaskBar->SetOverlayIcon(reinterpret_cast(m_mainForm->winId()), - (task_bar_count_enabled && unread_messages > 0) ? overlay_hicon : nullptr, - nullptr); + overlay_result = + m_windowsTaskBar->SetOverlayIcon(reinterpret_cast(m_mainForm->winId()), overlay_hicon, nullptr); - DestroyIcon(overlay_hicon); + DestroyIcon(overlay_hicon); + } + else { + overlay_result = m_windowsTaskBar->SetOverlayIcon(reinterpret_cast(m_mainForm->winId()), nullptr, nullptr); + } if (FAILED(overlay_result)) { - qCriticalNN << LOGSEC_CORE << "Failed to set overlay icon with HRESULT:" << QUOTE_W_SPACE_DOT(overlay_result); + qCriticalNN << LOGSEC_GUI << "Failed to set overlay icon with HRESULT:" << QUOTE_W_SPACE_DOT(overlay_result); } } + else { + qCriticalNN << LOGSEC_GUI << "Main form not set for setting numbers."; + } #endif if (m_mainForm != nullptr) { diff --git a/src/rssguard/main.cpp b/src/rssguard/main.cpp index cf84535e5..620b20450 100644 --- a/src/rssguard/main.cpp +++ b/src/rssguard/main.cpp @@ -111,8 +111,6 @@ int main(int argc, char* argv[]) { qApp->feedReader()->loadSavedMessageFilters(); qApp->feedReader()->feedsModel()->loadActivatedServiceAccounts(); qApp->showTrayIcon(); - qApp->offerChanges(); - qApp->showPolls(); main_window.tabWidget()->feedMessageViewer()->respondToMainWindowResizes(); main_window.tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates();