From 598a83b7cb6124f4feb2033634afb1cf14a33059 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 29 Jun 2015 18:58:10 +0200 Subject: [PATCH] Notifications now provide API. --- src/gui/dialogs/formcategorydetails.cpp | 4 ++-- src/gui/dialogs/formfeeddetails.cpp | 4 ++-- src/gui/dialogs/formmain.cpp | 10 ++++------ src/gui/dialogs/formupdate.cpp | 2 +- src/gui/feedmessageviewer.cpp | 4 ++-- src/gui/feedsview.cpp | 10 +++++----- src/gui/notifications/notification.cpp | 1 + src/gui/notifications/notification.h | 2 +- src/main.cpp | 2 ++ src/miscellaneous/application.cpp | 22 +++++++++++++++------- src/miscellaneous/application.h | 2 +- 11 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/gui/dialogs/formcategorydetails.cpp b/src/gui/dialogs/formcategorydetails.cpp index 3edf511be..5d2e2c6a9 100755 --- a/src/gui/dialogs/formcategorydetails.cpp +++ b/src/gui/dialogs/formcategorydetails.cpp @@ -131,7 +131,7 @@ void FormCategoryDetails::apply() { qApp->showGuiMessage(tr("Cannot add category"), tr("Category was not added due to error."), QSystemTrayIcon::Critical, - qApp->mainForm()); + qApp->mainForm(), true); } } else { @@ -142,7 +142,7 @@ void FormCategoryDetails::apply() { qApp->showGuiMessage(tr("Cannot edit category"), tr("Category was not edited due to error."), QSystemTrayIcon::Critical, - qApp->mainForm()); + qApp->mainForm(), true); } } } diff --git a/src/gui/dialogs/formfeeddetails.cpp b/src/gui/dialogs/formfeeddetails.cpp index 3ba5d7fb7..41a3054c7 100755 --- a/src/gui/dialogs/formfeeddetails.cpp +++ b/src/gui/dialogs/formfeeddetails.cpp @@ -246,7 +246,7 @@ void FormFeedDetails::apply() { else { qApp->showGuiMessage(tr("Cannot add feed"), tr("Feed was not added due to error."), - QSystemTrayIcon::Critical); + QSystemTrayIcon::Critical, this, true); } } else { @@ -257,7 +257,7 @@ void FormFeedDetails::apply() { else { qApp->showGuiMessage(tr("Cannot edit feed"), tr("Feed was not edited due to error."), - QSystemTrayIcon::Critical); + QSystemTrayIcon::Critical, this, true); } } } diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index d4d5f21d4..9df1aa4b7 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -79,8 +79,6 @@ FormMain::FormMain(QWidget *parent, Qt::WindowFlags f) // Initialize the web factory. WebFactory::instance()->loadState(); - - (new Notification())->notify("abcd abcd abcd abcd abcd abcd \naaa\n\n\nabcd abcd abcd abcd abcd", "def def def def def", qApp->icons()->fromTheme("item-update-all")); } FormMain::~FormMain() { @@ -466,7 +464,7 @@ void FormMain::showWiki() { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_WIKI)) { qApp->showGuiMessage(tr("Cannot open external browser"), tr("Cannot open external browser. Navigate to application website manually."), - QSystemTrayIcon::Warning); + QSystemTrayIcon::Warning, this, true); } } @@ -474,7 +472,7 @@ void FormMain::reportABugOnGitHub() { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW_GITHUB)) { qApp->showGuiMessage(tr("Cannot open external browser"), tr("Cannot open external browser. Navigate to application website manually."), - QSystemTrayIcon::Warning); + QSystemTrayIcon::Warning, this, true); } } @@ -482,7 +480,7 @@ void FormMain::reportABugOnBitBucket() { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW_BITBUCKET)) { qApp->showGuiMessage(tr("Cannot open external browser"), tr("Cannot open external browser. Navigate to application website manually."), - QSystemTrayIcon::Warning); + QSystemTrayIcon::Warning, this, true); } } @@ -490,7 +488,7 @@ void FormMain::donate() { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_DONATE_URL)) { qApp->showGuiMessage(tr("Cannot open external browser"), tr("Cannot open external browser. Navigate to application website manually."), - QSystemTrayIcon::Warning); + QSystemTrayIcon::Warning, this, true); } } diff --git a/src/gui/dialogs/formupdate.cpp b/src/gui/dialogs/formupdate.cpp index 7ce58bd53..7c59f1ac8 100755 --- a/src/gui/dialogs/formupdate.cpp +++ b/src/gui/dialogs/formupdate.cpp @@ -237,7 +237,7 @@ void FormUpdate::startUpdate() { qApp->showGuiMessage(tr("Cannot update application"), tr("Cannot navigate to installation file. Check new installation downloads manually on project website."), QSystemTrayIcon::Warning, - this); + this, true); } } } diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index cc2af5b72..8ffb92e9a 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -504,7 +504,7 @@ void FeedMessageViewer::showDbCleanupAssistant() { else { qApp->showGuiMessage(tr("Cannot cleanup database"), tr("Cannot cleanup database, because another critical action is running."), - QSystemTrayIcon::Warning, this); + QSystemTrayIcon::Warning, qApp->mainForm(), true); } } @@ -520,7 +520,7 @@ void FeedMessageViewer::updateFeeds(QList feeds) { if (!qApp->feedUpdateLock()->tryLock()) { qApp->showGuiMessage(tr("Cannot update all items"), tr("You cannot update all items because another another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); return; } diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 381676983..d12a5de85 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -244,7 +244,7 @@ void FeedsView::addNewCategory() { // is quitting. qApp->showGuiMessage(tr("Cannot add standard category"), tr("You cannot add new standard category now because another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); return; } @@ -273,7 +273,7 @@ void FeedsView::addNewFeed() { // is quitting. qApp->showGuiMessage(tr("Cannot add standard feed"), tr("You cannot add new standard feed now because another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); return; } @@ -338,7 +338,7 @@ void FeedsView::editSelectedItem() { // is quitting. qApp->showGuiMessage(tr("Cannot edit item"), tr("Selected item cannot be edited because another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); // Thus, cannot delete and quit the method. return; @@ -365,7 +365,7 @@ void FeedsView::deleteSelectedItem() { // is quitting. qApp->showGuiMessage(tr("Cannot delete item"), tr("Selected item cannot be deleted because another critical operation is ongoing."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); // Thus, cannot delete and quit the method. return; @@ -396,7 +396,7 @@ void FeedsView::deleteSelectedItem() { // or update is undergoing. qApp->showGuiMessage(tr("Deletion of item failed."), tr("Selected item was not deleted due to error."), - QSystemTrayIcon::Warning, qApp->mainForm()); + QSystemTrayIcon::Warning, qApp->mainForm(), true); } // Changes are done, unlock the update master lock. diff --git a/src/gui/notifications/notification.cpp b/src/gui/notifications/notification.cpp index e130e501d..a0067e8fb 100644 --- a/src/gui/notifications/notification.cpp +++ b/src/gui/notifications/notification.cpp @@ -41,6 +41,7 @@ Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString()) } Notification::~Notification() { + qDebug("Destroying Notification instance."); } bool Notification::areNotificationsActivated() { diff --git a/src/gui/notifications/notification.h b/src/gui/notifications/notification.h index c10adf196..0390d57c4 100644 --- a/src/gui/notifications/notification.h +++ b/src/gui/notifications/notification.h @@ -31,7 +31,7 @@ class Notification : public QWidget { explicit Notification(); virtual ~Notification(); - inline static bool areNotificationsActivated(); + static bool areNotificationsActivated(); public slots: void notify(const QString &text, const QString &title, const QIcon &icon); diff --git a/src/main.cpp b/src/main.cpp index cbb2a7d3b..456167870 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,6 +132,8 @@ int main(int argc, char *argv[]) { // Setup single-instance behavior. QObject::connect(&application, SIGNAL(messageReceived(QString)), &application, SLOT(processExecutionMessage(QString))); + qApp->showGuiMessage(QSL(APP_NAME), QObject::tr("Welcome to %1 %2.").arg(APP_NAME, APP_VERSION), QSystemTrayIcon::Information, + NULL, false, qApp->icons()->fromTheme(APP_LOW_NAME)); // Enter global event loop. return Application::exec(); diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index 5fea05a46..5da7f0ac0 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -169,19 +169,27 @@ void Application::deleteTrayIcon() { } void Application::showGuiMessage(const QString &title, const QString &message, - QSystemTrayIcon::MessageIcon message_type, - QWidget *parent, int duration) { - /*if (true) { + QSystemTrayIcon::MessageIcon message_type, QWidget *parent, + bool show_at_least_msgbox, const QIcon &custom_icon) { + if (Notification::areNotificationsActivated()) { // Show OSD instead if tray icon bubble, depending on settings. - notification()->notify(message, title, message_type); + if (custom_icon.isNull()) { + notification()->notify(message, title, message_type); + } + else { + notification()->notify(message, title, custom_icon); + } } - else */if (SystemTrayIcon::isSystemTrayActivated()) { - trayIcon()->showMessage(title, message, message_type, duration); + else if (SystemTrayIcon::isSystemTrayActivated()) { + trayIcon()->showMessage(title, message, message_type, TRAY_ICON_BUBBLE_TIMEOUT); } - else { + else if (show_at_least_msgbox) { // Tray icon or OSD is not available, display simple text box. MessageBox::show(parent, (QMessageBox::Icon) message_type, title, message); } + else { + qDebug("Silencing GUI message: '%s'.", qPrintable(message)); + } } void Application::onCommitData(QSessionManager &manager) { diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h index d874af0d1..afa6248e3 100755 --- a/src/miscellaneous/application.h +++ b/src/miscellaneous/application.h @@ -146,7 +146,7 @@ class Application : public QtSingleApplication { // Displays given simple message in tray icon bubble or OSD // or in message box if tray icon is disabled. void showGuiMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon message_type, - QWidget *parent = NULL, int duration = TRAY_ICON_BUBBLE_TIMEOUT); + QWidget *parent = NULL, bool show_at_least_msgbox = false, const QIcon &custom_icon = QIcon()); // Returns pointer to "GOD" application singleton. inline static Application *instance() {