Notifications now provide API.

This commit is contained in:
Martin Rotter 2015-06-29 18:58:10 +02:00
parent a5e1b1b116
commit 598a83b7cb
11 changed files with 36 additions and 27 deletions

View file

@ -131,7 +131,7 @@ void FormCategoryDetails::apply() {
qApp->showGuiMessage(tr("Cannot add category"), qApp->showGuiMessage(tr("Cannot add category"),
tr("Category was not added due to error."), tr("Category was not added due to error."),
QSystemTrayIcon::Critical, QSystemTrayIcon::Critical,
qApp->mainForm()); qApp->mainForm(), true);
} }
} }
else { else {
@ -142,7 +142,7 @@ void FormCategoryDetails::apply() {
qApp->showGuiMessage(tr("Cannot edit category"), qApp->showGuiMessage(tr("Cannot edit category"),
tr("Category was not edited due to error."), tr("Category was not edited due to error."),
QSystemTrayIcon::Critical, QSystemTrayIcon::Critical,
qApp->mainForm()); qApp->mainForm(), true);
} }
} }
} }

View file

@ -246,7 +246,7 @@ void FormFeedDetails::apply() {
else { else {
qApp->showGuiMessage(tr("Cannot add feed"), qApp->showGuiMessage(tr("Cannot add feed"),
tr("Feed was not added due to error."), tr("Feed was not added due to error."),
QSystemTrayIcon::Critical); QSystemTrayIcon::Critical, this, true);
} }
} }
else { else {
@ -257,7 +257,7 @@ void FormFeedDetails::apply() {
else { else {
qApp->showGuiMessage(tr("Cannot edit feed"), qApp->showGuiMessage(tr("Cannot edit feed"),
tr("Feed was not edited due to error."), tr("Feed was not edited due to error."),
QSystemTrayIcon::Critical); QSystemTrayIcon::Critical, this, true);
} }
} }
} }

View file

@ -79,8 +79,6 @@ FormMain::FormMain(QWidget *parent, Qt::WindowFlags f)
// Initialize the web factory. // Initialize the web factory.
WebFactory::instance()->loadState(); 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() { FormMain::~FormMain() {
@ -466,7 +464,7 @@ void FormMain::showWiki() {
if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_WIKI)) { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_WIKI)) {
qApp->showGuiMessage(tr("Cannot open external browser"), qApp->showGuiMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."), 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)) { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW_GITHUB)) {
qApp->showGuiMessage(tr("Cannot open external browser"), qApp->showGuiMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."), 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)) { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW_BITBUCKET)) {
qApp->showGuiMessage(tr("Cannot open external browser"), qApp->showGuiMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."), 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)) { if (!WebFactory::instance()->openUrlInExternalBrowser(APP_DONATE_URL)) {
qApp->showGuiMessage(tr("Cannot open external browser"), qApp->showGuiMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."), tr("Cannot open external browser. Navigate to application website manually."),
QSystemTrayIcon::Warning); QSystemTrayIcon::Warning, this, true);
} }
} }

View file

@ -237,7 +237,7 @@ void FormUpdate::startUpdate() {
qApp->showGuiMessage(tr("Cannot update application"), qApp->showGuiMessage(tr("Cannot update application"),
tr("Cannot navigate to installation file. Check new installation downloads manually on project website."), tr("Cannot navigate to installation file. Check new installation downloads manually on project website."),
QSystemTrayIcon::Warning, QSystemTrayIcon::Warning,
this); this, true);
} }
} }
} }

View file

@ -504,7 +504,7 @@ void FeedMessageViewer::showDbCleanupAssistant() {
else { else {
qApp->showGuiMessage(tr("Cannot cleanup database"), qApp->showGuiMessage(tr("Cannot cleanup database"),
tr("Cannot cleanup database, because another critical action is running."), 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<FeedsModelFeed *> feeds) {
if (!qApp->feedUpdateLock()->tryLock()) { if (!qApp->feedUpdateLock()->tryLock()) {
qApp->showGuiMessage(tr("Cannot update all items"), qApp->showGuiMessage(tr("Cannot update all items"),
tr("You cannot update all items because another another critical operation is ongoing."), tr("You cannot update all items because another another critical operation is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm()); QSystemTrayIcon::Warning, qApp->mainForm(), true);
return; return;
} }

View file

@ -244,7 +244,7 @@ void FeedsView::addNewCategory() {
// is quitting. // is quitting.
qApp->showGuiMessage(tr("Cannot add standard category"), qApp->showGuiMessage(tr("Cannot add standard category"),
tr("You cannot add new standard category now because another critical operation is ongoing."), tr("You cannot add new standard category now because another critical operation is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm()); QSystemTrayIcon::Warning, qApp->mainForm(), true);
return; return;
} }
@ -273,7 +273,7 @@ void FeedsView::addNewFeed() {
// is quitting. // is quitting.
qApp->showGuiMessage(tr("Cannot add standard feed"), qApp->showGuiMessage(tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because another critical operation is ongoing."), tr("You cannot add new standard feed now because another critical operation is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm()); QSystemTrayIcon::Warning, qApp->mainForm(), true);
return; return;
} }
@ -338,7 +338,7 @@ void FeedsView::editSelectedItem() {
// is quitting. // is quitting.
qApp->showGuiMessage(tr("Cannot edit item"), qApp->showGuiMessage(tr("Cannot edit item"),
tr("Selected item cannot be edited because another critical operation is ongoing."), 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. // Thus, cannot delete and quit the method.
return; return;
@ -365,7 +365,7 @@ void FeedsView::deleteSelectedItem() {
// is quitting. // is quitting.
qApp->showGuiMessage(tr("Cannot delete item"), qApp->showGuiMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because another critical operation is ongoing."), 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. // Thus, cannot delete and quit the method.
return; return;
@ -396,7 +396,7 @@ void FeedsView::deleteSelectedItem() {
// or update is undergoing. // or update is undergoing.
qApp->showGuiMessage(tr("Deletion of item failed."), qApp->showGuiMessage(tr("Deletion of item failed."),
tr("Selected item was not deleted due to error."), 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. // Changes are done, unlock the update master lock.

View file

@ -41,6 +41,7 @@ Notification::Notification() : QWidget(0), m_title(QString()), m_text(QString())
} }
Notification::~Notification() { Notification::~Notification() {
qDebug("Destroying Notification instance.");
} }
bool Notification::areNotificationsActivated() { bool Notification::areNotificationsActivated() {

View file

@ -31,7 +31,7 @@ class Notification : public QWidget {
explicit Notification(); explicit Notification();
virtual ~Notification(); virtual ~Notification();
inline static bool areNotificationsActivated(); static bool areNotificationsActivated();
public slots: public slots:
void notify(const QString &text, const QString &title, const QIcon &icon); void notify(const QString &text, const QString &title, const QIcon &icon);

View file

@ -132,6 +132,8 @@ int main(int argc, char *argv[]) {
// Setup single-instance behavior. // Setup single-instance behavior.
QObject::connect(&application, SIGNAL(messageReceived(QString)), &application, SLOT(processExecutionMessage(QString))); 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. // Enter global event loop.
return Application::exec(); return Application::exec();

View file

@ -169,19 +169,27 @@ void Application::deleteTrayIcon() {
} }
void Application::showGuiMessage(const QString &title, const QString &message, void Application::showGuiMessage(const QString &title, const QString &message,
QSystemTrayIcon::MessageIcon message_type, QSystemTrayIcon::MessageIcon message_type, QWidget *parent,
QWidget *parent, int duration) { bool show_at_least_msgbox, const QIcon &custom_icon) {
/*if (true) { if (Notification::areNotificationsActivated()) {
// Show OSD instead if tray icon bubble, depending on settings. // 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()) { else if (SystemTrayIcon::isSystemTrayActivated()) {
trayIcon()->showMessage(title, message, message_type, duration); 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. // Tray icon or OSD is not available, display simple text box.
MessageBox::show(parent, (QMessageBox::Icon) message_type, title, message); MessageBox::show(parent, (QMessageBox::Icon) message_type, title, message);
} }
else {
qDebug("Silencing GUI message: '%s'.", qPrintable(message));
}
} }
void Application::onCommitData(QSessionManager &manager) { void Application::onCommitData(QSessionManager &manager) {

View file

@ -146,7 +146,7 @@ class Application : public QtSingleApplication {
// Displays given simple message in tray icon bubble or OSD // Displays given simple message in tray icon bubble or OSD
// or in message box if tray icon is disabled. // or in message box if tray icon is disabled.
void showGuiMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon message_type, 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. // Returns pointer to "GOD" application singleton.
inline static Application *instance() { inline static Application *instance() {