Debian Codegraph @

src/gui/operations/NotifyOperation.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "NotifyOperation.h"
21
22 NotifyOperation::NotifyOperation(
23 const QString &title,
24 const QString &message,
25 const QString &contentUrl,
26 NotificationTypes notificationType,
27 const QSharedPointer<INotificationService> &notificationService,
28 const QSharedPointer<IConfig> &config) :
29 NotifyOperation(title, message, notificationType, notificationService, config)
30 {
31 mContentUrl = contentUrl;
32 }
33
34 NotifyOperation::NotifyOperation(
35 const QString &title,
36 const QString &message,
37 NotificationTypes notificationType,
38 const QSharedPointer<INotificationService> &notificationService,
39 const QSharedPointer<IConfig> &config) :
40 mNotificationService(notificationService),
41 mTitle(title),
42 mMessage(message),
43 mNotificationType(notificationType),
44 mConfig(config)
45 {
46 Q_ASSERT(mNotificationService != nullptr);
47 }
48
49 bool NotifyOperation::execute()
50 {
51 if(mConfig->trayIconNotificationsEnabled()) {
52 notifyViaToastMessage();
53 }
54
55 notifyViaConsoleMessage();
56
57 return true;
58 }
59
60 void NotifyOperation::notifyViaToastMessage() const
61 {
62 switch (mNotificationType) {
63 case NotificationTypes::Information:
64 mNotificationService->showInfo(mTitle, mMessage, mContentUrl);
65 break;
66 case NotificationTypes::Warning:
67 mNotificationService->showWarning(mTitle, mMessage, mContentUrl);
68 break;
69 case NotificationTypes::Critical:
70 mNotificationService->showCritical(mTitle, mMessage, mContentUrl);
71 break;
72 }
73 }
74
75 void NotifyOperation::notifyViaConsoleMessage() const
76 {
77 switch (mNotificationType) {
78 case NotificationTypes::Information:
79 qInfo("%s: %s", qPrintable(mTitle), qPrintable(mMessage));
80 break;
81 case NotificationTypes::Warning:
82 qWarning("%s: %s", qPrintable(mTitle), qPrintable(mMessage));
83 break;
84 case NotificationTypes::Critical:
85 qCritical("%s: %s", qPrintable(mTitle), qPrintable(mMessage));
86 break;
87 }
88 }
89