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

This commit is contained in:
Martin Rotter 2023-07-21 10:06:06 +02:00
parent 81f4b1102b
commit c76320fbcd
6 changed files with 52 additions and 62 deletions

View File

@ -19,7 +19,7 @@
#include <QPlainTextEdit>
#include <QTextStream>
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() {}

View File

@ -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:

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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<HWND>(m_mainForm->winId()),
(task_bar_count_enabled && unread_messages > 0) ? overlay_hicon : nullptr,
nullptr);
overlay_result =
m_windowsTaskBar->SetOverlayIcon(reinterpret_cast<HWND>(m_mainForm->winId()), overlay_hicon, nullptr);
DestroyIcon(overlay_hicon);
DestroyIcon(overlay_hicon);
}
else {
overlay_result = m_windowsTaskBar->SetOverlayIcon(reinterpret_cast<HWND>(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) {

View File

@ -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();