Changeset View
Changeset View
Standalone View
Standalone View
kcms/notifications/kcm.cpp
Show All 14 Lines | |||||
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "kcm.h" | 21 | #include "kcm.h" | ||
22 | 22 | | |||
23 | #include <QAction> | ||||
23 | #include <QCommandLineParser> | 24 | #include <QCommandLineParser> | ||
24 | #include <QDialog> | 25 | #include <QDialog> | ||
25 | #include <QDialogButtonBox> | 26 | #include <QDialogButtonBox> | ||
26 | #include <QPushButton> | 27 | #include <QPushButton> | ||
27 | #include <QQuickItem> | 28 | #include <QQuickItem> | ||
28 | #include <QQuickRenderControl> | 29 | #include <QQuickRenderControl> | ||
29 | #include <QQuickWindow> | 30 | #include <QQuickWindow> | ||
30 | #include <QStandardPaths> | 31 | #include <QStandardPaths> | ||
31 | #include <QVBoxLayout> | 32 | #include <QVBoxLayout> | ||
32 | #include <QWindow> | 33 | #include <QWindow> | ||
33 | 34 | | |||
34 | #include <KAboutData> | 35 | #include <KAboutData> | ||
35 | #include <KConfigGroup> | 36 | #include <KConfigGroup> | ||
37 | #include <KGlobalAccel> | ||||
36 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
37 | #include <KNotifyConfigWidget> | 39 | #include <KNotifyConfigWidget> | ||
38 | #include <KPluginFactory> | 40 | #include <KPluginFactory> | ||
39 | 41 | | |||
40 | #include <algorithm> | 42 | #include <algorithm> | ||
41 | 43 | | |||
42 | #include "sourcesmodel.h" | 44 | #include "sourcesmodel.h" | ||
43 | #include "filterproxymodel.h" | 45 | #include "filterproxymodel.h" | ||
44 | 46 | | |||
45 | #include <notificationmanager/settings.h> | 47 | #include <notificationmanager/settings.h> | ||
46 | 48 | | |||
47 | K_PLUGIN_FACTORY_WITH_JSON(KCMNotificationsFactory, "kcm_notifications.json", registerPlugin<KCMNotifications>();) | 49 | K_PLUGIN_FACTORY_WITH_JSON(KCMNotificationsFactory, "kcm_notifications.json", registerPlugin<KCMNotifications>();) | ||
48 | 50 | | |||
49 | KCMNotifications::KCMNotifications(QObject *parent, const QVariantList &args) | 51 | KCMNotifications::KCMNotifications(QObject *parent, const QVariantList &args) | ||
50 | : KQuickAddons::ConfigModule(parent, args) | 52 | : KQuickAddons::ConfigModule(parent, args) | ||
51 | , m_sourcesModel(new SourcesModel(this)) | 53 | , m_sourcesModel(new SourcesModel(this)) | ||
52 | , m_filteredModel(new FilterProxyModel(this)) | 54 | , m_filteredModel(new FilterProxyModel(this)) | ||
53 | , m_settings(new NotificationManager::Settings(this)) | 55 | , m_settings(new NotificationManager::Settings(this)) | ||
56 | , m_toggleDoNotDisturbAction(new QAction(this)) | ||||
54 | { | 57 | { | ||
55 | 58 | | |||
56 | const char uri[] = "org.kde.private.kcms.notifications"; | 59 | const char uri[] = "org.kde.private.kcms.notifications"; | ||
57 | qmlRegisterUncreatableType<SourcesModel>(uri, 1, 0, "SourcesModel", | 60 | qmlRegisterUncreatableType<SourcesModel>(uri, 1, 0, "SourcesModel", | ||
58 | QStringLiteral("Cannot create instances of SourcesModel")); | 61 | QStringLiteral("Cannot create instances of SourcesModel")); | ||
59 | qmlRegisterType<FilterProxyModel>(); | 62 | qmlRegisterType<FilterProxyModel>(); | ||
63 | qmlRegisterType<QKeySequence>(); | ||||
60 | qmlProtectModule(uri, 1); | 64 | qmlProtectModule(uri, 1); | ||
61 | 65 | | |||
62 | KAboutData *about = new KAboutData(QStringLiteral("kcm_notifications"), i18n("Notifications"), | 66 | KAboutData *about = new KAboutData(QStringLiteral("kcm_notifications"), i18n("Notifications"), | ||
63 | QStringLiteral("5.0"), QString(), KAboutLicense::GPL); | 67 | QStringLiteral("5.0"), QString(), KAboutLicense::GPL); | ||
64 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@privat.broulik.de")); | 68 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@privat.broulik.de")); | ||
65 | setAboutData(about); | 69 | setAboutData(about); | ||
66 | 70 | | |||
67 | m_filteredModel->setSourceModel(m_sourcesModel); | 71 | m_filteredModel->setSourceModel(m_sourcesModel); | ||
68 | 72 | | |||
73 | // for KGlobalAccel... | ||||
74 | // keep in sync with globalshortcuts.cpp in notification plasmoid! | ||||
75 | m_toggleDoNotDisturbAction->setObjectName(QStringLiteral("toggle do not disturb")); | ||||
76 | m_toggleDoNotDisturbAction->setProperty("componentName", QStringLiteral("plasmashell")); | ||||
77 | m_toggleDoNotDisturbAction->setText(i18n("Toggle do not disturb")); | ||||
78 | m_toggleDoNotDisturbAction->setIcon(QIcon::fromTheme(QStringLiteral("notifications-disabled"))); | ||||
79 | | ||||
69 | QStringList stringArgs; | 80 | QStringList stringArgs; | ||
70 | stringArgs.reserve(args.count() + 1); | 81 | stringArgs.reserve(args.count() + 1); | ||
71 | // need to add a fake argv[0] for QCommandLineParser | 82 | // need to add a fake argv[0] for QCommandLineParser | ||
72 | stringArgs.append(QStringLiteral("kcm_notifications")); | 83 | stringArgs.append(QStringLiteral("kcm_notifications")); | ||
73 | for (const QVariant &arg : args) { | 84 | for (const QVariant &arg : args) { | ||
74 | stringArgs.append(arg.toString()); | 85 | stringArgs.append(arg.toString()); | ||
75 | } | 86 | } | ||
76 | 87 | | |||
Show All 28 Lines | 115 | { | |||
105 | return m_filteredModel; | 116 | return m_filteredModel; | ||
106 | } | 117 | } | ||
107 | 118 | | |||
108 | NotificationManager::Settings *KCMNotifications::settings() const | 119 | NotificationManager::Settings *KCMNotifications::settings() const | ||
109 | { | 120 | { | ||
110 | return m_settings; | 121 | return m_settings; | ||
111 | } | 122 | } | ||
112 | 123 | | |||
124 | QKeySequence KCMNotifications::toggleDoNotDisturbShortcut() const | ||||
125 | { | ||||
126 | return m_toggleDoNotDisturbShortcut; | ||||
127 | } | ||||
128 | | ||||
129 | void KCMNotifications::setToggleDoNotDisturbShortcut(const QKeySequence &shortcut) | ||||
130 | { | ||||
131 | if (m_toggleDoNotDisturbShortcut == shortcut) { | ||||
132 | return; | ||||
133 | } | ||||
134 | | ||||
135 | m_toggleDoNotDisturbShortcut = shortcut; | ||||
136 | m_toggleDoNotDisturbShortcutDirty = true; | ||||
137 | emit toggleDoNotDisturbShortcutChanged(); | ||||
138 | setNeedsSave(true); | ||||
139 | } | ||||
140 | | ||||
113 | QString KCMNotifications::initialDesktopEntry() const | 141 | QString KCMNotifications::initialDesktopEntry() const | ||
114 | { | 142 | { | ||
115 | return m_initialDesktopEntry; | 143 | return m_initialDesktopEntry; | ||
116 | } | 144 | } | ||
117 | 145 | | |||
118 | void KCMNotifications::setInitialDesktopEntry(const QString &desktopEntry) | 146 | void KCMNotifications::setInitialDesktopEntry(const QString &desktopEntry) | ||
119 | { | 147 | { | ||
120 | if (m_initialDesktopEntry != desktopEntry) { | 148 | if (m_initialDesktopEntry != desktopEntry) { | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 181 | { | |||
189 | w->selectEvent(eventId); | 217 | w->selectEvent(eventId); | ||
190 | 218 | | |||
191 | dialog->show(); | 219 | dialog->show(); | ||
192 | } | 220 | } | ||
193 | 221 | | |||
194 | void KCMNotifications::load() | 222 | void KCMNotifications::load() | ||
195 | { | 223 | { | ||
196 | m_settings->load(); | 224 | m_settings->load(); | ||
225 | | ||||
226 | const QKeySequence toggleDoNotDisturbShortcut = KGlobalAccel::self()->globalShortcut( | ||||
227 | m_toggleDoNotDisturbAction->property("componentName").toString(), | ||||
228 | m_toggleDoNotDisturbAction->objectName()).value(0); | ||||
229 | | ||||
230 | if (m_toggleDoNotDisturbShortcut != toggleDoNotDisturbShortcut) { | ||||
231 | m_toggleDoNotDisturbShortcut = toggleDoNotDisturbShortcut; | ||||
232 | emit toggleDoNotDisturbShortcutChanged(); | ||||
233 | } | ||||
234 | | ||||
235 | m_toggleDoNotDisturbShortcutDirty = false; | ||||
236 | setNeedsSave(false); | ||||
197 | } | 237 | } | ||
198 | 238 | | |||
199 | void KCMNotifications::save() | 239 | void KCMNotifications::save() | ||
200 | { | 240 | { | ||
201 | m_settings->save(); | 241 | m_settings->save(); | ||
242 | | ||||
243 | if (m_toggleDoNotDisturbShortcutDirty) { | ||||
244 | // KeySequenceItem will already have checked whether the shortcut is available | ||||
245 | KGlobalAccel::self()->setShortcut(m_toggleDoNotDisturbAction, | ||||
246 | {m_toggleDoNotDisturbShortcut}, | ||||
247 | KGlobalAccel::NoAutoloading); | ||||
248 | } | ||||
249 | | ||||
250 | setNeedsSave(false); | ||||
202 | } | 251 | } | ||
203 | 252 | | |||
204 | void KCMNotifications::defaults() | 253 | void KCMNotifications::defaults() | ||
205 | { | 254 | { | ||
206 | m_settings->defaults(); | 255 | m_settings->defaults(); | ||
256 | | ||||
257 | setToggleDoNotDisturbShortcut(QKeySequence()); | ||||
207 | } | 258 | } | ||
208 | 259 | | |||
209 | #include "kcm.moc" | 260 | #include "kcm.moc" |