Merge lp:~artmello/ubuntu-system-settings/ubuntu-system-settings-new_notifications_panel into lp:ubuntu-system-settings
- ubuntu-system-settings-new_notifications_panel
- Merge into trunk
Proposed by
Arthur Mello
Status: | Needs review |
---|---|
Proposed branch: | lp:~artmello/ubuntu-system-settings/ubuntu-system-settings-new_notifications_panel |
Merge into: | lp:ubuntu-system-settings |
Diff against target: |
1928 lines (+1770/-0) 28 files modified
CMakeLists.txt (+1/-0) debian/control (+1/-0) plugins/new_notifications/CMakeLists.txt (+36/-0) plugins/new_notifications/ClickAppNotifications.qml (+140/-0) plugins/new_notifications/ClickAppsSoundsNotify.qml (+94/-0) plugins/new_notifications/ClickAppsVibrationsNotify.qml (+123/-0) plugins/new_notifications/PageComponent.qml (+224/-0) plugins/new_notifications/click_applications_model.cpp (+382/-0) plugins/new_notifications/click_applications_model.h (+98/-0) plugins/new_notifications/click_applications_notify_model.cpp (+114/-0) plugins/new_notifications/click_applications_notify_model.h (+72/-0) plugins/new_notifications/notifications.settings (+23/-0) plugins/new_notifications/plugin.cpp (+47/-0) plugins/new_notifications/plugin.h (+33/-0) plugins/new_notifications/qmldir (+2/-0) tests/mocks/CMakeLists.txt (+34/-0) tests/mocks/Ubuntu/CMakeLists.txt (+1/-0) tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt (+1/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/CMakeLists.txt (+22/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.cpp (+102/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.h (+35/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.cpp (+35/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.h (+35/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.cpp (+37/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.h (+31/-0) tests/mocks/Ubuntu/SystemSettings/Notifications/qmldir (+2/-0) tests/plugins/notifications/CMakeLists.txt (+40/-0) tests/plugins/notifications/NotificationsSource/qmldir (+5/-0) |
To merge this branch: | bzr merge lp:~artmello/ubuntu-system-settings/ubuntu-system-settings-new_notifications_panel |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonas G. Drange (community) | Needs Information | ||
system-apps-ci-bot | continuous-integration | Needs Fixing | |
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+297656@code.launchpad.net |
Commit message
Add new Notifications panel but keep it hidden until backend changes lands
Description of the change
Add new Notifications panel but keep it hidden until backend changes lands
To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Revision history for this message
Jonas G. Drange (jonas-drange) wrote : | # |
Is this sill in review, Arthur? I see the Notifications panel has changed in trunk?
review:
Needs Information
Unmerged revisions
- 1665. By Arthur Mello
-
Add new Notificantions panel but keep it hidden until backend lands
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-02-23 20:23:18 +0000 |
3 | +++ CMakeLists.txt 2016-06-16 16:49:39 +0000 |
4 | @@ -46,6 +46,7 @@ |
5 | pkg_check_modules(QTDBUSTEST REQUIRED libqtdbustest-1 REQUIRED) |
6 | pkg_search_module(POLKIT_AGENT polkit-agent-1) |
7 | pkg_search_module(CLICK REQUIRED click-0.4) |
8 | +pkg_check_modules(QTGSETTINGS REQUIRED gsettings-qt) |
9 | |
10 | find_program(XGETTEXT_BIN xgettext) |
11 | find_program(MSGFMT_BIN msgfmt) |
12 | |
13 | === modified file 'debian/control' |
14 | --- debian/control 2016-05-25 06:02:03 +0000 |
15 | +++ debian/control 2016-06-16 16:49:39 +0000 |
16 | @@ -32,6 +32,7 @@ |
17 | qtdeclarative5-dev, |
18 | libapt-pkg-dev, |
19 | libgnome-desktop-3-dev, |
20 | + libgsettings-qt-dev, |
21 | # test-deps |
22 | qml-module-qttest, |
23 | qml-module-qtquick2, |
24 | |
25 | === added directory 'plugins/new_notifications' |
26 | === added file 'plugins/new_notifications/CMakeLists.txt' |
27 | --- plugins/new_notifications/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
28 | +++ plugins/new_notifications/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
29 | @@ -0,0 +1,36 @@ |
30 | +SET (CMAKE_AUTOMOC ON) |
31 | + |
32 | +set(QML_SOURCES |
33 | + PageComponent.qml |
34 | + ClickAppNotifications.qml |
35 | + ClickAppsSoundsNotify.qml |
36 | + ClickAppsVibrationsNotify.qml |
37 | + ) |
38 | + |
39 | +set(ubuntu_notifications_panel_HDRS |
40 | + plugin.h |
41 | + click_applications_model.h |
42 | + click_applications_notify_model.h |
43 | + ) |
44 | + |
45 | +set(ubuntu_notifications_panel_SRCS |
46 | + plugin.cpp |
47 | + click_applications_model.cpp |
48 | + click_applications_notify_model.cpp |
49 | + ) |
50 | + |
51 | +add_library(UbuntuNotificationsPanel MODULE ${ubuntu_notifications_panel_HDRS} ${ubuntu_notifications_panel_SRCS} ${QML_SOURCES}) |
52 | + |
53 | +add_definitions(-DQT_NO_KEYWORDS) |
54 | +include_directories(${GIO_INCLUDE_DIRS}) |
55 | +include_directories(${QTGSETTINGS_INCLUDE_DIRS}) |
56 | + |
57 | +target_link_libraries(UbuntuNotificationsPanel ${GIO_LDFLAGS} ${QTGSETTINGS_LDFLAGS}) |
58 | +qt5_use_modules(UbuntuNotificationsPanel Qml Quick) |
59 | + |
60 | +set(PLUG_DIR ${PLUGIN_PRIVATE_MODULE_DIR}/Ubuntu/SystemSettings/Notifications) |
61 | +install(TARGETS UbuntuNotificationsPanel DESTINATION ${PLUG_DIR}) |
62 | +install(FILES qmldir DESTINATION ${PLUG_DIR}) |
63 | +install(FILES ${QML_SOURCES} DESTINATION ${PLUGIN_QML_DIR}/notifications) |
64 | + |
65 | +install(FILES notifications.settings DESTINATION ${PLUGIN_MANIFEST_DIR}) |
66 | |
67 | === added file 'plugins/new_notifications/ClickAppNotifications.qml' |
68 | --- plugins/new_notifications/ClickAppNotifications.qml 1970-01-01 00:00:00 +0000 |
69 | +++ plugins/new_notifications/ClickAppNotifications.qml 2016-06-16 16:49:39 +0000 |
70 | @@ -0,0 +1,140 @@ |
71 | +/* |
72 | + * This file is part of system-settings |
73 | + * |
74 | + * Copyright (C) 2016 Canonical Ltd. |
75 | + * |
76 | + * This program is free software: you can redistribute it and/or modify it |
77 | + * under the terms of the GNU General Public License version 3, as published |
78 | + * by the Free Software Foundation. |
79 | + * |
80 | + * This program is distributed in the hope that it will be useful, but |
81 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
82 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
83 | + * PURPOSE. See the GNU General Public License for more details. |
84 | + * |
85 | + * You should have received a copy of the GNU General Public License along |
86 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
87 | + */ |
88 | + |
89 | +import QtQuick 2.4 |
90 | +import Ubuntu.Components 1.3 |
91 | +import SystemSettings 1.0 |
92 | + |
93 | +ItemPage { |
94 | + id: appNotificationsPage |
95 | + |
96 | + property alias enableNotifications: enableNotificationsSwitch.checked |
97 | + property alias soundsNotify: soundsChecked.checked |
98 | + property alias vibrationsNotify: vibrationsChecked.checked |
99 | + property alias bubblesNotify: bubblesChecked.checked |
100 | + property alias listNotify: listChecked.checked |
101 | + |
102 | + function disableNotificationsWhenAllUnchecked() { |
103 | + if (!soundsNotify && !vibrationsNotify && !bubblesNotify && !listNotify) { |
104 | + enableNotifications = false |
105 | + } |
106 | + } |
107 | + |
108 | + onSoundsNotifyChanged: { |
109 | + if (!soundsNotify) { |
110 | + disableNotificationsWhenAllUnchecked() |
111 | + } |
112 | + } |
113 | + |
114 | + onVibrationsNotifyChanged: { |
115 | + if (!vibrationsNotify) { |
116 | + disableNotificationsWhenAllUnchecked() |
117 | + } |
118 | + } |
119 | + |
120 | + onBubblesNotifyChanged: { |
121 | + if (!bubblesNotify) { |
122 | + disableNotificationsWhenAllUnchecked() |
123 | + } |
124 | + } |
125 | + |
126 | + onListNotifyChanged: { |
127 | + if (!listNotify) { |
128 | + disableNotificationsWhenAllUnchecked() |
129 | + } |
130 | + } |
131 | + |
132 | + Column { |
133 | + id: notificationsColumn |
134 | + |
135 | + anchors.fill: parent |
136 | + |
137 | + ListItem { |
138 | + height: enableNotificationsLayout.height + (divider.visible ? divider.height : 0) |
139 | + ListItemLayout { |
140 | + id: enableNotificationsLayout |
141 | + title.text: i18n.tr("Enable Notifications") |
142 | + Switch { |
143 | + id: enableNotificationsSwitch |
144 | + objectName: "enableNotificationsSwitch" |
145 | + SlotsLayout.position: SlotsLayout.Leading |
146 | + } |
147 | + } |
148 | + } |
149 | + |
150 | + ListItem { |
151 | + ListItemLayout { title.text: i18n.tr("Let this app alert me using:") } |
152 | + } |
153 | + |
154 | + ListItem { |
155 | + height: soundsLayout.height + (divider.visible ? divider.height : 0) |
156 | + ListItemLayout { |
157 | + id: soundsLayout |
158 | + title.text: i18n.tr("Sounds") |
159 | + CheckBox { |
160 | + id: soundsChecked |
161 | + objectName: "soundsChecked" |
162 | + SlotsLayout.position: SlotsLayout.Leading |
163 | + enabled: appNotificationsPage.enableNotifications |
164 | + } |
165 | + } |
166 | + } |
167 | + |
168 | + ListItem { |
169 | + height: vibrationsLayout.height + (divider.visible ? divider.height : 0) |
170 | + ListItemLayout { |
171 | + id: vibrationsLayout |
172 | + title.text: i18n.tr("Vibrations") |
173 | + CheckBox { |
174 | + id: vibrationsChecked |
175 | + objectName: "vibrationsChecked" |
176 | + SlotsLayout.position: SlotsLayout.Leading |
177 | + enabled: appNotificationsPage.enableNotifications |
178 | + } |
179 | + } |
180 | + } |
181 | + |
182 | + ListItem { |
183 | + height: bubblesLayout.height + (divider.visible ? divider.height : 0) |
184 | + ListItemLayout { |
185 | + id: bubblesLayout |
186 | + title.text: i18n.tr("Notification Bubbles") |
187 | + CheckBox { |
188 | + id: bubblesChecked |
189 | + objectName: "bubblesChecked" |
190 | + SlotsLayout.position: SlotsLayout.Leading |
191 | + enabled: appNotificationsPage.enableNotifications |
192 | + } |
193 | + } |
194 | + } |
195 | + |
196 | + ListItem { |
197 | + height: listLayout.height + (divider.visible ? divider.height : 0) |
198 | + ListItemLayout { |
199 | + id: listLayout |
200 | + title.text: i18n.tr("Notification List") |
201 | + CheckBox { |
202 | + id: listChecked |
203 | + objectName: "listChecked" |
204 | + SlotsLayout.position: SlotsLayout.Leading |
205 | + enabled: appNotificationsPage.enableNotifications |
206 | + } |
207 | + } |
208 | + } |
209 | + } |
210 | +} |
211 | |
212 | === added file 'plugins/new_notifications/ClickAppsSoundsNotify.qml' |
213 | --- plugins/new_notifications/ClickAppsSoundsNotify.qml 1970-01-01 00:00:00 +0000 |
214 | +++ plugins/new_notifications/ClickAppsSoundsNotify.qml 2016-06-16 16:49:39 +0000 |
215 | @@ -0,0 +1,94 @@ |
216 | +/* |
217 | + * This file is part of system-settings |
218 | + * |
219 | + * Copyright (C) 2013-2014 Canonical Ltd. |
220 | + * |
221 | + * This program is free software: you can redistribute it and/or modify it |
222 | + * under the terms of the GNU General Public License version 3, as published |
223 | + * by the Free Software Foundation. |
224 | + * |
225 | + * This program is distributed in the hope that it will be useful, but |
226 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
227 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
228 | + * PURPOSE. See the GNU General Public License for more details. |
229 | + * |
230 | + * You should have received a copy of the GNU General Public License along |
231 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
232 | + */ |
233 | + |
234 | +import QtQuick 2.4 |
235 | +import Ubuntu.Components 1.3 |
236 | +import Ubuntu.SystemSettings.Notifications 1.0 |
237 | +import SystemSettings 1.0 |
238 | + |
239 | +ItemPage { |
240 | + id: appsSoundsNotifyPage |
241 | + objectName: "appsSoundsNotifyPage" |
242 | + |
243 | + property alias model: appsSoundsNotifyList.model |
244 | + |
245 | + property var uncheckedIndexes: [] |
246 | + |
247 | + title: i18n.tr("Sound") |
248 | + |
249 | + ListView { |
250 | + id: appsSoundsNotifyList |
251 | + objectName: "appsSoundsNotifyList" |
252 | + |
253 | + anchors { |
254 | + left: parent.left |
255 | + right: parent.right |
256 | + top: parent.top |
257 | + bottom: parent.bottom |
258 | + } |
259 | + |
260 | + clip: true |
261 | + contentHeight: contentItem.childrenRect.height |
262 | + |
263 | + header: ListItem { |
264 | + ListItemLayout { title.text: i18n.tr("Apps that notify with sound:") } |
265 | + } |
266 | + |
267 | + delegate: ListItem { |
268 | + ListItemLayout { |
269 | + Component.onCompleted: { |
270 | + var iconPath = model.icon.toString() |
271 | + if (iconPath.search("/") == -1) { |
272 | + icon.name = model.icon |
273 | + } else { |
274 | + icon.source = model.icon |
275 | + } |
276 | + } |
277 | + |
278 | + title.text: model.displayName |
279 | + |
280 | + Row { |
281 | + spacing: units.gu(2) |
282 | + |
283 | + SlotsLayout.position: SlotsLayout.Leading; |
284 | + |
285 | + CheckBox { |
286 | + anchors.verticalCenter: icon.verticalCenter |
287 | + checked: model.soundsNotify |
288 | + |
289 | + onCheckedChanged: { |
290 | + if (!checked) { |
291 | + uncheckedIndexes.push(index) |
292 | + } else { |
293 | + var i = uncheckedIndexes.indexOf(index) |
294 | + if (i >= 0) { |
295 | + uncheckedIndexes.splice(i, 1) |
296 | + } |
297 | + } |
298 | + } |
299 | + } |
300 | + |
301 | + Icon { |
302 | + id: icon |
303 | + width: units.gu(5) |
304 | + } |
305 | + } |
306 | + } |
307 | + } |
308 | + } |
309 | +} |
310 | |
311 | === added file 'plugins/new_notifications/ClickAppsVibrationsNotify.qml' |
312 | --- plugins/new_notifications/ClickAppsVibrationsNotify.qml 1970-01-01 00:00:00 +0000 |
313 | +++ plugins/new_notifications/ClickAppsVibrationsNotify.qml 2016-06-16 16:49:39 +0000 |
314 | @@ -0,0 +1,123 @@ |
315 | +/* |
316 | + * This file is part of system-settings |
317 | + * |
318 | + * Copyright (C) 2013-2014 Canonical Ltd. |
319 | + * |
320 | + * This program is free software: you can redistribute it and/or modify it |
321 | + * under the terms of the GNU General Public License version 3, as published |
322 | + * by the Free Software Foundation. |
323 | + * |
324 | + * This program is distributed in the hope that it will be useful, but |
325 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
326 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
327 | + * PURPOSE. See the GNU General Public License for more details. |
328 | + * |
329 | + * You should have received a copy of the GNU General Public License along |
330 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
331 | + */ |
332 | + |
333 | +import QtQuick 2.4 |
334 | +import Ubuntu.Components 1.3 |
335 | +import Ubuntu.SystemSettings.Notifications 1.0 |
336 | +import SystemSettings 1.0 |
337 | + |
338 | +ItemPage { |
339 | + id: appsVibrationsNotifyPage |
340 | + objectName: "appsVibrationsNotifyPage" |
341 | + |
342 | + property alias model: appsVibrationsNotifyList.model |
343 | + |
344 | + property var uncheckedIndexes: [] |
345 | + |
346 | + title: i18n.tr("Vibration") |
347 | + |
348 | + ListView { |
349 | + id: appsVibrationsNotifyList |
350 | + objectName: "appsVibrationsNotifyList" |
351 | + |
352 | + anchors { |
353 | + left: parent.left |
354 | + right: parent.right |
355 | + top: parent.top |
356 | + bottom: parent.bottom |
357 | + } |
358 | + |
359 | + clip: true |
360 | + contentHeight: contentItem.childrenRect.height |
361 | + |
362 | + header: Column { |
363 | + anchors { |
364 | + left: parent.left |
365 | + right: parent.right |
366 | + } |
367 | + |
368 | + ListItem { |
369 | + ListItemLayout { title.text: i18n.tr("When in Silent mode:") } |
370 | + } |
371 | + |
372 | + ListItem { |
373 | + height: layout.height + (divider.visible ? divider.height : 0) |
374 | + SlotsLayout { |
375 | + id: layout |
376 | + |
377 | + mainSlot: Item { |
378 | + height: optionSelector.itemHeight * 2 |
379 | + width: parent.width - 2 * (layout.padding.leading + layout.padding.trailing) |
380 | + OptionSelector { |
381 | + id: optionSelector |
382 | + expanded: true |
383 | + model: [i18n.tr("Vibrate as normal"), |
384 | + i18n.tr("Don't vibrate")] |
385 | + } |
386 | + } |
387 | + } |
388 | + } |
389 | + |
390 | + ListItem { |
391 | + ListItemLayout { title.text: i18n.tr("Apps that notify with vibrations:") } |
392 | + } |
393 | + } |
394 | + |
395 | + delegate: ListItem { |
396 | + ListItemLayout { |
397 | + Component.onCompleted: { |
398 | + var iconPath = model.icon.toString() |
399 | + if (iconPath.search("/") == -1) { |
400 | + icon.name = model.icon |
401 | + } else { |
402 | + icon.source = model.icon |
403 | + } |
404 | + } |
405 | + |
406 | + title.text: model.displayName |
407 | + |
408 | + Row { |
409 | + spacing: units.gu(2) |
410 | + |
411 | + SlotsLayout.position: SlotsLayout.Leading; |
412 | + |
413 | + CheckBox { |
414 | + anchors.verticalCenter: icon.verticalCenter |
415 | + checked: model.vibrationsNotify |
416 | + |
417 | + onCheckedChanged: { |
418 | + if (!checked) { |
419 | + uncheckedIndexes.push(index) |
420 | + } else { |
421 | + var i = uncheckedIndexes.indexOf(index) |
422 | + if (i >= 0) { |
423 | + uncheckedIndexes.splice(i, 1) |
424 | + } |
425 | + } |
426 | + } |
427 | + } |
428 | + |
429 | + Icon { |
430 | + id: icon |
431 | + width: units.gu(5) |
432 | + } |
433 | + } |
434 | + } |
435 | + } |
436 | + } |
437 | +} |
438 | |
439 | === added file 'plugins/new_notifications/PageComponent.qml' |
440 | --- plugins/new_notifications/PageComponent.qml 1970-01-01 00:00:00 +0000 |
441 | +++ plugins/new_notifications/PageComponent.qml 2016-06-16 16:49:39 +0000 |
442 | @@ -0,0 +1,224 @@ |
443 | +/* |
444 | + * This file is part of system-settings |
445 | + * |
446 | + * Copyright (C) 2013-2014 Canonical Ltd. |
447 | + * |
448 | + * This program is free software: you can redistribute it and/or modify it |
449 | + * under the terms of the GNU General Public License version 3, as published |
450 | + * by the Free Software Foundation. |
451 | + * |
452 | + * This program is distributed in the hope that it will be useful, but |
453 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
454 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
455 | + * PURPOSE. See the GNU General Public License for more details. |
456 | + * |
457 | + * You should have received a copy of the GNU General Public License along |
458 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
459 | + */ |
460 | + |
461 | +import QtQuick 2.4 |
462 | +import Ubuntu.Components 1.3 |
463 | +import Ubuntu.Components.ListItems 1.3 as ListItems |
464 | +import Ubuntu.SystemSettings.Notifications 1.0 |
465 | +import SystemSettings 1.0 |
466 | + |
467 | +ItemPage { |
468 | + id: root |
469 | + objectName: "systemNotificationsPage" |
470 | + |
471 | + title: i18n.tr("Notifications") |
472 | + |
473 | + ClickApplicationsNotifyModel { |
474 | + id: clickAppsSoundsNotifyModel |
475 | + objectName: "clickAppsSoundsNotifyModel" |
476 | + notifyType: ClickApplicationsNotifyModel.SoundsNotify |
477 | + sourceModel: ClickApplicationsModel |
478 | + } |
479 | + |
480 | + ClickApplicationsNotifyModel { |
481 | + id: clickAppsVibrationsNotifyModel |
482 | + objectName: "clickAppsVibrationsNotifyModel" |
483 | + notifyType: ClickApplicationsNotifyModel.VibrationsNotify |
484 | + sourceModel: ClickApplicationsModel |
485 | + } |
486 | + |
487 | + ListView { |
488 | + id: notificationsList |
489 | + objectName: "notificationsList" |
490 | + anchors { |
491 | + left: parent.left |
492 | + right: parent.right |
493 | + top: parent.top |
494 | + bottom: parent.bottom |
495 | + } |
496 | + model: ClickApplicationsModel |
497 | + clip: true |
498 | + |
499 | + header: Column { |
500 | + anchors { |
501 | + left: parent.left |
502 | + right: parent.right |
503 | + } |
504 | + |
505 | + ListItems.Base { |
506 | + height: labelSubtitle.height + units.gu(2) |
507 | + Label { |
508 | + id: labelSubtitle |
509 | + text: i18n.tr("Selected apps can alert you using notification bubbles, sounds, vibrations, and the Notifications list.") |
510 | + wrapMode: Text.WordWrap |
511 | + anchors { |
512 | + top: parent.top |
513 | + left: parent.left |
514 | + right: parent.right |
515 | + topMargin: units.gu(1) |
516 | + } |
517 | + } |
518 | + |
519 | + highlightWhenPressed: false |
520 | + } |
521 | + |
522 | + ListItem { |
523 | + ListItemLayout { |
524 | + title.text: i18n.tr("Apps that notify with sound"); |
525 | + Label { |
526 | + objectName: "clickAppsSoundsNotifyLabel" |
527 | + text: clickAppsSoundsNotifyModel.count |
528 | + fontSize: "large" |
529 | + SlotsLayout.position: SlotsLayout.Trailing; |
530 | + } |
531 | + Icon { |
532 | + name: "next" |
533 | + SlotsLayout.position: SlotsLayout.Trailing; |
534 | + width: units.gu(2) |
535 | + } |
536 | + } |
537 | + |
538 | + onClicked: { |
539 | + if (clickAppsSoundsNotifyModel.count <= 0) { |
540 | + return |
541 | + } |
542 | + |
543 | + var page = pageStack.push(Qt.resolvedUrl("ClickAppsSoundsNotify.qml"), { model: clickAppsSoundsNotifyModel }) |
544 | + page.Component.onDestruction.connect( function() { |
545 | + var indexes = page.uncheckedIndexes |
546 | + indexes.sort() |
547 | + for (var i = indexes.length - 1; i >= 0; i--) { |
548 | + clickAppsSoundsNotifyModel.disableNotify(indexes[i]) |
549 | + } |
550 | + }) |
551 | + } |
552 | + } |
553 | + |
554 | + ListItem { |
555 | + ListItemLayout { |
556 | + title.text: i18n.tr("Apps that notify with vibration"); |
557 | + Label { |
558 | + objectName: "clickAppsVibrationsNotifyLabel" |
559 | + text: clickAppsVibrationsNotifyModel.count |
560 | + fontSize: "large" |
561 | + SlotsLayout.position: SlotsLayout.Trailing; |
562 | + } |
563 | + Icon { |
564 | + name: "next" |
565 | + SlotsLayout.position: SlotsLayout.Trailing; |
566 | + width: units.gu(2) |
567 | + } |
568 | + } |
569 | + |
570 | + onClicked: { |
571 | + if (clickAppsVibrationsNotifyModel.count <= 0) { |
572 | + return |
573 | + } |
574 | + |
575 | + var page = pageStack.push(Qt.resolvedUrl("ClickAppsVibrationsNotify.qml"), { model: clickAppsVibrationsNotifyModel }) |
576 | + page.Component.onDestruction.connect( function() { |
577 | + var indexes = page.uncheckedIndexes |
578 | + indexes.sort() |
579 | + for (var i = indexes.length - 1; i >= 0; i--) { |
580 | + clickAppsVibrationsNotifyModel.disableNotify(indexes[i]) |
581 | + } |
582 | + }) |
583 | + } |
584 | + } |
585 | + |
586 | + ListItem { |
587 | + ListItemLayout { title.text: i18n.tr("All installed apps:") } |
588 | + } |
589 | + |
590 | + } |
591 | + |
592 | + delegate: ListItem { |
593 | + height: layout.height + (divider.visible ? divider.height : 0) |
594 | + |
595 | + onClicked: { |
596 | + var page = pageStack.push(Qt.resolvedUrl("ClickAppNotifications.qml"), |
597 | + { title: model.displayName, |
598 | + enableNotifications: model.enableNotifications, |
599 | + soundsNotify: model.soundsNotify, |
600 | + vibrationsNotify: model.vibrationsNotify, |
601 | + bubblesNotify: model.bubblesNotify, |
602 | + listNotify: model.listNotify }) |
603 | + |
604 | + page.Component.onDestruction.connect( function() { |
605 | + page.disableNotificationsWhenAllUnchecked() |
606 | + |
607 | + if (!ClickApplicationsModel) { |
608 | + return |
609 | + } |
610 | + |
611 | + ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.EnableNotifications, index, page.enableNotifications) |
612 | + ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.SoundsNotify, index, page.soundsNotify) |
613 | + ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.VibrationsNotify, index, page.vibrationsNotify) |
614 | + ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.BubblesNotify, index, page.bubblesNotify) |
615 | + ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.ListNotify, index, page.listNotify) |
616 | + }) |
617 | + } |
618 | + |
619 | + ListItemLayout { |
620 | + id: layout |
621 | + |
622 | + Component.onCompleted: { |
623 | + var iconPath = model.icon.toString() |
624 | + if (iconPath.search("/") == -1) { |
625 | + icon.name = model.icon |
626 | + } else { |
627 | + icon.source = model.icon |
628 | + } |
629 | + } |
630 | + |
631 | + title.text: model.displayName |
632 | + subtitle.text: { |
633 | + if (!model.enableNotifications) { |
634 | + return i18n.tr("Disabled") |
635 | + } |
636 | + |
637 | + var arr = [] |
638 | + if (model.soundsNotify) { |
639 | + arr.push(i18n.tr("Sounds")) |
640 | + } |
641 | + if (model.vibrationsNotify) { |
642 | + arr.push(i18n.tr("Vibrations")) |
643 | + } |
644 | + if (model.bubblesNotify) { |
645 | + arr.push(i18n.tr("Bubbles")) |
646 | + } |
647 | + if (model.listNotify) { |
648 | + arr.push(i18n.tr("Notification List")) |
649 | + } |
650 | + |
651 | + return arr.join(", ") |
652 | + } |
653 | + Icon { |
654 | + id: icon |
655 | + SlotsLayout.position: SlotsLayout.Leading; |
656 | + width: units.gu(5) |
657 | + } |
658 | + Icon { |
659 | + name: "next" |
660 | + SlotsLayout.position: SlotsLayout.Trailing; |
661 | + width: units.gu(2) |
662 | + } |
663 | + } |
664 | + } |
665 | + } |
666 | +} |
667 | |
668 | === added file 'plugins/new_notifications/click_applications_model.cpp' |
669 | --- plugins/new_notifications/click_applications_model.cpp 1970-01-01 00:00:00 +0000 |
670 | +++ plugins/new_notifications/click_applications_model.cpp 2016-06-16 16:49:39 +0000 |
671 | @@ -0,0 +1,382 @@ |
672 | +/* |
673 | + * Copyright (C) 2016 Canonical Ltd |
674 | + * |
675 | + * This program is free software: you can redistribute it and/or modify |
676 | + * it under the terms of the GNU General Public License version 3 as |
677 | + * published by the Free Software Foundation. |
678 | + * |
679 | + * This program is distributed in the hope that it will be useful, |
680 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
681 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
682 | + * GNU General Public License for more details. |
683 | + * |
684 | + * You should have received a copy of the GNU General Public License |
685 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
686 | + * |
687 | +*/ |
688 | + |
689 | +#include <gio/gdesktopappinfo.h> |
690 | + |
691 | +#include <QtCore/QTimer> |
692 | +#include <QtCore/QDebug> |
693 | + |
694 | +#include "click_applications_model.h" |
695 | + |
696 | +#define GSETTINGS_APPS_SCHEMA_ID "com.ubuntu.notifications.settings.applications" |
697 | +#define GSETTINGS_APPLICATIONS_KEY "applications" |
698 | +#define GSETTINGS_NOTIFICATIONS_SCHEMA_ID "com.ubuntu.notifications.settings" |
699 | +#define GSETTINGS_BASE_PATH "/com/ubuntu/NotificationSettings/" |
700 | +#define GSETTINGS_ENABLE_NOTIFICATIONS_KEY "enable-notifications" |
701 | +#define GSETTINGS_SOUNDS_NOTIFY_KEY "use-sounds-notifications" |
702 | +#define GSETTINGS_VIBRATIONS_NOTIFY_KEY "use-vibrations-notifications" |
703 | +#define GSETTINGS_BUBBLES_NOTIFY_KEY "use-bubbles-notifications" |
704 | +#define GSETTINGS_LIST_NOTIFY_KEY "use-list-notifications" |
705 | + |
706 | +ClickApplicationsModel::ClickApplicationsModel(QObject* parent) |
707 | + : QAbstractListModel(parent), |
708 | + m_applications(0) |
709 | +{ |
710 | + // This way populateModel can be override during tests |
711 | + QTimer::singleShot(0, this, SLOT(populateModel())); |
712 | + |
713 | + m_checkMissingDesktopDataTimer = new QTimer(this); |
714 | + m_checkMissingDesktopDataTimer->setInterval(1000); |
715 | + connect(m_checkMissingDesktopDataTimer, SIGNAL(timeout()), SLOT(checkMissingDesktopData())); |
716 | +} |
717 | + |
718 | +ClickApplicationsModel::~ClickApplicationsModel() |
719 | +{ |
720 | +} |
721 | + |
722 | +QHash<int, QByteArray> ClickApplicationsModel::roleNames() const |
723 | +{ |
724 | + static QHash<int, QByteArray> roles; |
725 | + if (roles.isEmpty()) { |
726 | + roles[DisplayName] = "displayName"; |
727 | + roles[Icon] = "icon"; |
728 | + roles[EnableNotifications] = "enableNotifications"; |
729 | + roles[SoundsNotify] = "soundsNotify"; |
730 | + roles[VibrationsNotify] = "vibrationsNotify"; |
731 | + roles[BubblesNotify] = "bubblesNotify"; |
732 | + roles[ListNotify] = "listNotify"; |
733 | + } |
734 | + return roles; |
735 | +} |
736 | + |
737 | +int ClickApplicationsModel::rowCount(const QModelIndex& parent) const |
738 | +{ |
739 | + Q_UNUSED(parent); |
740 | + return m_entries.count(); |
741 | +} |
742 | + |
743 | +QVariant ClickApplicationsModel::data(const QModelIndex& index, int role) const |
744 | +{ |
745 | + if (!index.isValid()) { |
746 | + return QVariant(); |
747 | + } |
748 | + |
749 | + const ClickApplicationEntry& entry = m_entries.at(index.row()); |
750 | + switch (role) { |
751 | + case DisplayName: |
752 | + return entry.displayName; |
753 | + case Icon: |
754 | + return entry.icon; |
755 | + case EnableNotifications: |
756 | + return entry.enableNotifications; |
757 | + case SoundsNotify: |
758 | + return entry.soundsNotify; |
759 | + case VibrationsNotify: |
760 | + return entry.vibrationsNotify; |
761 | + case BubblesNotify: |
762 | + return entry.bubblesNotify; |
763 | + case ListNotify: |
764 | + return entry.listNotify; |
765 | + default: |
766 | + return QVariant(); |
767 | + } |
768 | +} |
769 | + |
770 | +bool ClickApplicationsModel::setNotifyEnabled(int role, int idx, bool enabled) |
771 | +{ |
772 | + if (idx < 0 || idx >= rowCount()) { |
773 | + return false; |
774 | + } |
775 | + |
776 | + if (!saveNotifyEnabled(m_entries[idx], role, enabled)) { |
777 | + return false; |
778 | + } |
779 | + |
780 | + QVector<int> roles; |
781 | + roles << role; |
782 | + |
783 | + if (role != EnableNotifications) { |
784 | + if (!m_entries[idx].soundsNotify && |
785 | + !m_entries[idx].vibrationsNotify && |
786 | + !m_entries[idx].bubblesNotify && |
787 | + !m_entries[idx].listNotify) { |
788 | + |
789 | + if (saveNotifyEnabled(m_entries[idx], EnableNotifications, false)) { |
790 | + roles << EnableNotifications; |
791 | + } |
792 | + } |
793 | + } |
794 | + |
795 | + Q_EMIT dataChanged(this->index(idx, 0), this->index(idx, 0), roles); |
796 | + return true; |
797 | +} |
798 | + |
799 | +bool ClickApplicationsModel::saveNotifyEnabled(ClickApplicationEntry& entry, int role, bool enabled) |
800 | +{ |
801 | + QString path = GSETTINGS_BASE_PATH; |
802 | + |
803 | + if (entry.appName.isEmpty()) { |
804 | + path = path + "dpkg/" + entry.pkgName + "/"; |
805 | + } else { |
806 | + path = path + entry.pkgName + "/" + entry.appName + "/"; |
807 | + } |
808 | + |
809 | + QScopedPointer<QGSettings> settings(new QGSettings(GSETTINGS_NOTIFICATIONS_SCHEMA_ID, path.toUtf8().constData())); |
810 | + |
811 | + switch (role) { |
812 | + case EnableNotifications: |
813 | + if (entry.enableNotifications == enabled) { |
814 | + return false; |
815 | + } |
816 | + |
817 | + entry.enableNotifications = enabled; |
818 | + settings->set(GSETTINGS_ENABLE_NOTIFICATIONS_KEY, enabled); |
819 | + return true; |
820 | + |
821 | + case SoundsNotify: |
822 | + if (entry.soundsNotify == enabled) { |
823 | + return false; |
824 | + } |
825 | + |
826 | + entry.soundsNotify = enabled; |
827 | + settings->set(GSETTINGS_SOUNDS_NOTIFY_KEY, enabled); |
828 | + return true; |
829 | + |
830 | + case VibrationsNotify: |
831 | + if (entry.vibrationsNotify == enabled) { |
832 | + return false; |
833 | + } |
834 | + |
835 | + entry.vibrationsNotify = enabled; |
836 | + settings->set(GSETTINGS_VIBRATIONS_NOTIFY_KEY, enabled); |
837 | + return true; |
838 | + |
839 | + case BubblesNotify: |
840 | + if (entry.bubblesNotify == enabled) { |
841 | + return false; |
842 | + } |
843 | + |
844 | + entry.bubblesNotify = enabled; |
845 | + settings->set(GSETTINGS_BUBBLES_NOTIFY_KEY, enabled); |
846 | + return true; |
847 | + |
848 | + case ListNotify: |
849 | + if (entry.listNotify == enabled) { |
850 | + return false; |
851 | + } |
852 | + |
853 | + entry.listNotify = enabled; |
854 | + settings->set(GSETTINGS_LIST_NOTIFY_KEY, enabled); |
855 | + return true; |
856 | + |
857 | + default: |
858 | + return false; |
859 | + } |
860 | +} |
861 | + |
862 | +bool ClickApplicationsModel::getApplicationDataFromDesktopFile(ClickApplicationEntry& entry) |
863 | +{ |
864 | + QString desktopFile = entry.pkgName + ".desktop"; |
865 | + if (!entry.appName.isEmpty() && !entry.version.isEmpty()) { |
866 | + desktopFile = entry.pkgName + "_" + entry.appName + "_" + entry.version + ".desktop"; |
867 | + } |
868 | + |
869 | + GAppInfo* appInfo = (GAppInfo*)g_desktop_app_info_new(desktopFile.toUtf8().constData()); |
870 | + if (appInfo == nullptr) { |
871 | + qWarning() << Q_FUNC_INFO << "[ERROR] Unable to get desktop file:" << desktopFile; |
872 | + return false; |
873 | + } |
874 | + |
875 | + entry.displayName = g_strdup(g_app_info_get_display_name(appInfo)); |
876 | + GIcon* icon = g_app_info_get_icon(appInfo); |
877 | + if (icon != nullptr) { |
878 | + QString iconPath = g_icon_to_string(icon); |
879 | + entry.icon = iconPath; |
880 | + } |
881 | + |
882 | + g_object_unref(appInfo); |
883 | + return true; |
884 | +} |
885 | + |
886 | +void ClickApplicationsModel::getNotificationsSettings(ClickApplicationEntry& entry) |
887 | +{ |
888 | + QString path = GSETTINGS_BASE_PATH; |
889 | + |
890 | + if (entry.appName.isEmpty()) { |
891 | + path = path + "dpkg/" + entry.pkgName + "/"; |
892 | + } else { |
893 | + path = path + entry.pkgName + "/" + entry.appName + "/"; |
894 | + } |
895 | + |
896 | + QScopedPointer<QGSettings> settings(new QGSettings(GSETTINGS_NOTIFICATIONS_SCHEMA_ID, path.toUtf8().constData())); |
897 | + |
898 | + entry.enableNotifications = settings->get(GSETTINGS_ENABLE_NOTIFICATIONS_KEY).toBool(); |
899 | + entry.soundsNotify = settings->get(GSETTINGS_SOUNDS_NOTIFY_KEY).toBool(); |
900 | + entry.vibrationsNotify = settings->get(GSETTINGS_VIBRATIONS_NOTIFY_KEY).toBool(); |
901 | + entry.bubblesNotify = settings->get(GSETTINGS_BUBBLES_NOTIFY_KEY).toBool(); |
902 | + entry.listNotify = settings->get(GSETTINGS_LIST_NOTIFY_KEY).toBool(); |
903 | +} |
904 | + |
905 | +bool ClickApplicationsModel::parseApplicationKeyFromSettings(ClickApplicationEntry& entry, const QString& appEntry) |
906 | +{ |
907 | + QStringList entryData = appEntry.split('/'); |
908 | + if (entryData.size() != 3) { |
909 | + return false; |
910 | + } |
911 | + |
912 | + if (entryData[0] == "dpkg" && entryData[2] == "0") { |
913 | + // Legacy dpkg application |
914 | + entry.pkgName = entryData[1]; |
915 | + } else { |
916 | + entry.pkgName = entryData[0]; |
917 | + entry.appName = entryData[1]; |
918 | + entry.version = entryData[2]; |
919 | + } |
920 | + |
921 | + return true; |
922 | +} |
923 | + |
924 | +int ClickApplicationsModel::getIndexByApplicationData(ClickApplicationEntry& entry) |
925 | +{ |
926 | + for (int i = 0; i < rowCount(); ++i) { |
927 | + if (m_entries.at(i).pkgName != entry.pkgName) { |
928 | + continue; |
929 | + } |
930 | + |
931 | + if (m_entries.at(i).appName != entry.appName) { |
932 | + continue; |
933 | + } |
934 | + |
935 | + return i; |
936 | + } |
937 | + |
938 | + return -1; |
939 | +} |
940 | + |
941 | +void ClickApplicationsModel::addMissingDesktopDataEntry(ClickApplicationEntry& entry) |
942 | +{ |
943 | + m_missingDesktopDataEntries << entry; |
944 | + m_checkMissingDesktopDataTimer->start(); |
945 | +} |
946 | + |
947 | +void ClickApplicationsModel::addEntry(ClickApplicationEntry& entry) |
948 | +{ |
949 | + getNotificationsSettings(entry); |
950 | + |
951 | + beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
952 | + m_entries << entry; |
953 | + endInsertRows(); |
954 | + Q_EMIT rowCountChanged(); |
955 | +} |
956 | + |
957 | +void ClickApplicationsModel::removeEntryByIndex(int index) |
958 | +{ |
959 | + beginRemoveRows(QModelIndex(), index, index); |
960 | + m_entries.removeAt(index); |
961 | + endRemoveRows(); |
962 | + Q_EMIT rowCountChanged(); |
963 | +} |
964 | + |
965 | +void ClickApplicationsModel::populateModel() |
966 | +{ |
967 | + m_applications.reset(new QGSettings(GSETTINGS_APPS_SCHEMA_ID)); |
968 | + |
969 | + connect(m_applications.data(), SIGNAL(changed(const QString&)), SLOT(onApplicationsListChanged(const QString&))); |
970 | + |
971 | + Q_FOREACH (QString appEntry, m_applications->get(GSETTINGS_APPLICATIONS_KEY).toStringList()) { |
972 | + ClickApplicationEntry entry; |
973 | + if (!parseApplicationKeyFromSettings(entry, appEntry)) { |
974 | + continue; |
975 | + } |
976 | + |
977 | + if (!getApplicationDataFromDesktopFile(entry)) { |
978 | + addMissingDesktopDataEntry(entry); |
979 | + continue; |
980 | + } |
981 | + |
982 | + addEntry(entry); |
983 | + } |
984 | +} |
985 | + |
986 | +void ClickApplicationsModel::onApplicationsListChanged(const QString& key) { |
987 | + if (key != GSETTINGS_APPLICATIONS_KEY) { |
988 | + return; |
989 | + } |
990 | + |
991 | + //Check for removed entries |
992 | + for (int i = rowCount() - 1; i >= 0; --i) { |
993 | + bool removed = true; |
994 | + |
995 | + Q_FOREACH (QString appEntry, m_applications->get(GSETTINGS_APPLICATIONS_KEY).toStringList()) { |
996 | + ClickApplicationEntry entry; |
997 | + if (!parseApplicationKeyFromSettings(entry, appEntry)) { |
998 | + continue; |
999 | + } |
1000 | + |
1001 | + if (m_entries.at(i).pkgName == entry.pkgName && m_entries.at(i).appName == entry.appName) { |
1002 | + removed = false; |
1003 | + continue; |
1004 | + } |
1005 | + } |
1006 | + |
1007 | + if (!removed) { |
1008 | + continue; |
1009 | + } |
1010 | + |
1011 | + removeEntryByIndex(i); |
1012 | + } |
1013 | + |
1014 | + //Check for added entries |
1015 | + Q_FOREACH (QString appEntry, m_applications->get(GSETTINGS_APPLICATIONS_KEY).toStringList()) { |
1016 | + ClickApplicationEntry entry; |
1017 | + if (!parseApplicationKeyFromSettings(entry, appEntry)) { |
1018 | + continue; |
1019 | + } |
1020 | + |
1021 | + if (getIndexByApplicationData(entry) >= 0) { |
1022 | + continue; |
1023 | + } |
1024 | + |
1025 | + if (!getApplicationDataFromDesktopFile(entry)) { |
1026 | + addMissingDesktopDataEntry(entry); |
1027 | + continue; |
1028 | + } |
1029 | + |
1030 | + addEntry(entry); |
1031 | + } |
1032 | +} |
1033 | + |
1034 | +void ClickApplicationsModel::checkMissingDesktopData() |
1035 | +{ |
1036 | + QList<ClickApplicationEntry> stillMissing; |
1037 | + |
1038 | + while (!m_missingDesktopDataEntries.isEmpty()) { |
1039 | + ClickApplicationEntry entry = m_missingDesktopDataEntries.takeFirst(); |
1040 | + |
1041 | + if (!getApplicationDataFromDesktopFile(entry)) { |
1042 | + stillMissing << entry; |
1043 | + } else { |
1044 | + addEntry(entry); |
1045 | + } |
1046 | + } |
1047 | + |
1048 | + if (stillMissing.isEmpty()) { |
1049 | + m_checkMissingDesktopDataTimer->stop(); |
1050 | + } else { |
1051 | + m_missingDesktopDataEntries.append(stillMissing); |
1052 | + } |
1053 | +} |
1054 | |
1055 | === added file 'plugins/new_notifications/click_applications_model.h' |
1056 | --- plugins/new_notifications/click_applications_model.h 1970-01-01 00:00:00 +0000 |
1057 | +++ plugins/new_notifications/click_applications_model.h 2016-06-16 16:49:39 +0000 |
1058 | @@ -0,0 +1,98 @@ |
1059 | +/* |
1060 | + * Copyright (C) 2016 Canonical Ltd |
1061 | + * |
1062 | + * This program is free software: you can redistribute it and/or modify |
1063 | + * it under the terms of the GNU General Public License version 3 as |
1064 | + * published by the Free Software Foundation. |
1065 | + * |
1066 | + * This program is distributed in the hope that it will be useful, |
1067 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1068 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1069 | + * GNU General Public License for more details. |
1070 | + * |
1071 | + * You should have received a copy of the GNU General Public License |
1072 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1073 | + * |
1074 | +*/ |
1075 | + |
1076 | +#ifndef CLICKAPPLICATIONSMODEL_H |
1077 | +#define CLICKAPPLICATIONSMODEL_H |
1078 | + |
1079 | +// Qt |
1080 | +#include <QtCore/QAbstractListModel> |
1081 | +#include <QtCore/QUrl> |
1082 | + |
1083 | +#include <QGSettings/QGSettings> |
1084 | + |
1085 | +class QTimer; |
1086 | + |
1087 | +class ClickApplicationsModel : public QAbstractListModel |
1088 | +{ |
1089 | + Q_OBJECT |
1090 | + |
1091 | + Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged) |
1092 | + |
1093 | + Q_ENUMS(Roles) |
1094 | + |
1095 | +public: |
1096 | + ClickApplicationsModel(QObject* parent=0); |
1097 | + ~ClickApplicationsModel(); |
1098 | + |
1099 | + enum Roles { |
1100 | + DisplayName = Qt::UserRole + 1, |
1101 | + Icon, |
1102 | + EnableNotifications, |
1103 | + SoundsNotify, |
1104 | + VibrationsNotify, |
1105 | + BubblesNotify, |
1106 | + ListNotify |
1107 | + }; |
1108 | + |
1109 | + // reimplemented from QAbstractListModel |
1110 | + QHash<int, QByteArray> roleNames() const; |
1111 | + int rowCount(const QModelIndex& parent=QModelIndex()) const; |
1112 | + QVariant data(const QModelIndex& index, int role) const; |
1113 | + |
1114 | + Q_INVOKABLE bool setNotifyEnabled(int role, int idx, bool enabled); |
1115 | + |
1116 | +protected: |
1117 | + struct ClickApplicationEntry { |
1118 | + QString pkgName; |
1119 | + QString appName; |
1120 | + QString version; |
1121 | + QString displayName; |
1122 | + QUrl icon; |
1123 | + bool enableNotifications = true; |
1124 | + bool soundsNotify = true; |
1125 | + bool vibrationsNotify = true; |
1126 | + bool bubblesNotify = true; |
1127 | + bool listNotify = true; |
1128 | + }; |
1129 | + QList<ClickApplicationEntry> m_entries; |
1130 | + |
1131 | +protected Q_SLOTS: |
1132 | + virtual void populateModel(); |
1133 | + |
1134 | +Q_SIGNALS: |
1135 | + void rowCountChanged(); |
1136 | + |
1137 | +private Q_SLOTS: |
1138 | + void onApplicationsListChanged(const QString& key); |
1139 | + void checkMissingDesktopData(); |
1140 | + |
1141 | +private: |
1142 | + bool saveNotifyEnabled(ClickApplicationEntry& entry, int role, bool enabled); |
1143 | + bool getApplicationDataFromDesktopFile(ClickApplicationEntry& entry); |
1144 | + void getNotificationsSettings(ClickApplicationEntry& entry); |
1145 | + bool parseApplicationKeyFromSettings(ClickApplicationEntry& entry, const QString& appEntry); |
1146 | + int getIndexByApplicationData(ClickApplicationEntry& entry); |
1147 | + void addMissingDesktopDataEntry(ClickApplicationEntry& entry); |
1148 | + void addEntry(ClickApplicationEntry& entry); |
1149 | + void removeEntryByIndex(int index); |
1150 | + |
1151 | + QScopedPointer<QGSettings> m_applications; |
1152 | + QList<ClickApplicationEntry> m_missingDesktopDataEntries; |
1153 | + QTimer *m_checkMissingDesktopDataTimer; |
1154 | +}; |
1155 | + |
1156 | +#endif // CLICKAPPLICATIONSMODEL_H |
1157 | |
1158 | === added file 'plugins/new_notifications/click_applications_notify_model.cpp' |
1159 | --- plugins/new_notifications/click_applications_notify_model.cpp 1970-01-01 00:00:00 +0000 |
1160 | +++ plugins/new_notifications/click_applications_notify_model.cpp 2016-06-16 16:49:39 +0000 |
1161 | @@ -0,0 +1,114 @@ |
1162 | +/* |
1163 | + * Copyright (C) 2016 Canonical Ltd |
1164 | + * |
1165 | + * This program is free software: you can redistribute it and/or modify |
1166 | + * it under the terms of the GNU General Public License version 3 as |
1167 | + * published by the Free Software Foundation. |
1168 | + * |
1169 | + * This program is distributed in the hope that it will be useful, |
1170 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1171 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1172 | + * GNU General Public License for more details. |
1173 | + * |
1174 | + * You should have received a copy of the GNU General Public License |
1175 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1176 | + * |
1177 | +*/ |
1178 | + |
1179 | +#include "click_applications_notify_model.h" |
1180 | +#include "click_applications_model.h" |
1181 | + |
1182 | +ClickApplicationsNotifyModel::ClickApplicationsNotifyModel(QObject* parent) |
1183 | + : QSortFilterProxyModel(parent), |
1184 | + m_notifyType(-1) |
1185 | +{ |
1186 | + connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(onModelChanged())); |
1187 | + connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(onModelChanged())); |
1188 | +} |
1189 | + |
1190 | +ClickApplicationsModel* ClickApplicationsNotifyModel::sourceModel() const |
1191 | +{ |
1192 | + return qobject_cast<ClickApplicationsModel*>(QSortFilterProxyModel::sourceModel()); |
1193 | +} |
1194 | + |
1195 | +void ClickApplicationsNotifyModel::setSourceModel(ClickApplicationsModel* sourceModel) |
1196 | +{ |
1197 | + if (sourceModel != this->sourceModel()) { |
1198 | + QSortFilterProxyModel::setSourceModel(sourceModel); |
1199 | + Q_EMIT sourceModelChanged(); |
1200 | + Q_EMIT countChanged(); |
1201 | + } |
1202 | +} |
1203 | + |
1204 | +int ClickApplicationsNotifyModel::notifyType() const |
1205 | +{ |
1206 | + return m_notifyType; |
1207 | +} |
1208 | + |
1209 | +void ClickApplicationsNotifyModel::setNotifyType(int type) |
1210 | +{ |
1211 | + if (m_notifyType != type) { |
1212 | + m_notifyType = type; |
1213 | + invalidate(); |
1214 | + Q_EMIT notifyTypeChanged(); |
1215 | + Q_EMIT countChanged(); |
1216 | + } |
1217 | +} |
1218 | + |
1219 | +int ClickApplicationsNotifyModel::count() const |
1220 | +{ |
1221 | + return rowCount(); |
1222 | +} |
1223 | + |
1224 | +bool ClickApplicationsNotifyModel::disableNotify(int row) |
1225 | +{ |
1226 | + if (row < 0 || row >= rowCount()) { |
1227 | + return false; |
1228 | + } |
1229 | + |
1230 | + QModelIndex idx = mapToSource(index(row, 0)); |
1231 | + |
1232 | + switch (m_notifyType) { |
1233 | + case SoundsNotify: |
1234 | + return sourceModel()->setNotifyEnabled(ClickApplicationsModel::SoundsNotify, idx.row(), false); |
1235 | + case VibrationsNotify: |
1236 | + return sourceModel()->setNotifyEnabled(ClickApplicationsModel::VibrationsNotify, idx.row(), false); |
1237 | + case BubblesNotify: |
1238 | + return sourceModel()->setNotifyEnabled(ClickApplicationsModel::BubblesNotify, idx.row(), false); |
1239 | + case ListNotify: |
1240 | + return sourceModel()->setNotifyEnabled(ClickApplicationsModel::ListNotify, idx.row(), false); |
1241 | + default: |
1242 | + return false; |
1243 | + } |
1244 | + |
1245 | + return false; |
1246 | +} |
1247 | + |
1248 | +bool ClickApplicationsNotifyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const |
1249 | +{ |
1250 | + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); |
1251 | + |
1252 | + if (!sourceModel()->data(index, ClickApplicationsModel::EnableNotifications).toBool()) { |
1253 | + return false; |
1254 | + } |
1255 | + |
1256 | + if (m_notifyType == SoundsNotify) { |
1257 | + return sourceModel()->data(index, ClickApplicationsModel::SoundsNotify).toBool(); |
1258 | + } |
1259 | + if (m_notifyType == VibrationsNotify) { |
1260 | + return sourceModel()->data(index, ClickApplicationsModel::VibrationsNotify).toBool(); |
1261 | + } |
1262 | + if (m_notifyType == BubblesNotify) { |
1263 | + return sourceModel()->data(index, ClickApplicationsModel::BubblesNotify).toBool(); |
1264 | + } |
1265 | + if (m_notifyType == ListNotify) { |
1266 | + return sourceModel()->data(index, ClickApplicationsModel::ListNotify).toBool(); |
1267 | + } |
1268 | + |
1269 | + return false; |
1270 | +} |
1271 | + |
1272 | +void ClickApplicationsNotifyModel::onModelChanged() |
1273 | +{ |
1274 | + Q_EMIT countChanged(); |
1275 | +} |
1276 | |
1277 | === added file 'plugins/new_notifications/click_applications_notify_model.h' |
1278 | --- plugins/new_notifications/click_applications_notify_model.h 1970-01-01 00:00:00 +0000 |
1279 | +++ plugins/new_notifications/click_applications_notify_model.h 2016-06-16 16:49:39 +0000 |
1280 | @@ -0,0 +1,72 @@ |
1281 | +/* |
1282 | + * Copyright (C) 2016 Canonical Ltd |
1283 | + * |
1284 | + * This program is free software: you can redistribute it and/or modify |
1285 | + * it under the terms of the GNU General Public License version 3 as |
1286 | + * published by the Free Software Foundation. |
1287 | + * |
1288 | + * This program is distributed in the hope that it will be useful, |
1289 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1290 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1291 | + * GNU General Public License for more details. |
1292 | + * |
1293 | + * You should have received a copy of the GNU General Public License |
1294 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1295 | + * |
1296 | +*/ |
1297 | + |
1298 | +#ifndef CLICKAPPLICATIONSNOTIFYMODEL_H |
1299 | +#define CLICKAPPLICATIONSNOTIFYMODEL_H |
1300 | + |
1301 | +// Qt |
1302 | +#include <QtCore/QSortFilterProxyModel> |
1303 | + |
1304 | +class ClickApplicationsModel; |
1305 | +class ClickApplicationEntry; |
1306 | + |
1307 | +class ClickApplicationsNotifyModel : public QSortFilterProxyModel |
1308 | +{ |
1309 | + Q_OBJECT |
1310 | + |
1311 | + Q_PROPERTY(ClickApplicationsModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged) |
1312 | + Q_PROPERTY(int notifyType READ notifyType WRITE setNotifyType NOTIFY notifyTypeChanged) |
1313 | + Q_PROPERTY(int count READ count NOTIFY countChanged) |
1314 | + |
1315 | + Q_ENUMS(NotifyTypes) |
1316 | + |
1317 | +public: |
1318 | + ClickApplicationsNotifyModel(QObject* parent=0); |
1319 | + |
1320 | + enum NotifyTypes { |
1321 | + SoundsNotify, |
1322 | + VibrationsNotify, |
1323 | + BubblesNotify, |
1324 | + ListNotify |
1325 | + }; |
1326 | + |
1327 | + ClickApplicationsModel* sourceModel() const; |
1328 | + void setSourceModel(ClickApplicationsModel* sourceModel); |
1329 | + |
1330 | + int notifyType() const; |
1331 | + void setNotifyType(int type); |
1332 | + |
1333 | + int count() const; |
1334 | + Q_INVOKABLE bool disableNotify(int row); |
1335 | + |
1336 | +Q_SIGNALS: |
1337 | + void sourceModelChanged() const; |
1338 | + void notifyTypeChanged() const; |
1339 | + void countChanged() const; |
1340 | + |
1341 | +protected: |
1342 | + // reimplemented from QSortFilterProxyModel |
1343 | + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; |
1344 | + |
1345 | +private Q_SLOTS: |
1346 | + void onModelChanged(); |
1347 | + |
1348 | +private: |
1349 | + int m_notifyType; |
1350 | +}; |
1351 | + |
1352 | +#endif // CLICKAPPLICATIONSNOTIFYMODEL_H |
1353 | |
1354 | === added file 'plugins/new_notifications/notifications.settings' |
1355 | --- plugins/new_notifications/notifications.settings 1970-01-01 00:00:00 +0000 |
1356 | +++ plugins/new_notifications/notifications.settings 2016-06-16 16:49:39 +0000 |
1357 | @@ -0,0 +1,23 @@ |
1358 | +{ |
1359 | + "icon": "preferences-desktop-notifications-symbolic", |
1360 | + "name": "Notifications", |
1361 | + "translations": "ubuntu-system-settings", |
1362 | + "category": "personal", |
1363 | + "priority": 5, |
1364 | + "keywords": [ |
1365 | + "software", |
1366 | + "notifications", |
1367 | + "apps", |
1368 | + "authorize", |
1369 | + "alerts", |
1370 | + "permissions", |
1371 | + "badges", |
1372 | + "facebook", |
1373 | + "twitter", |
1374 | + "flickr", |
1375 | + "gmail" |
1376 | + ], |
1377 | + "has-dynamic-keywords": false, |
1378 | + "has-dynamic-visibility": false, |
1379 | + "page-component": "PageComponent.qml" |
1380 | +} |
1381 | |
1382 | === added file 'plugins/new_notifications/plugin.cpp' |
1383 | --- plugins/new_notifications/plugin.cpp 1970-01-01 00:00:00 +0000 |
1384 | +++ plugins/new_notifications/plugin.cpp 2016-06-16 16:49:39 +0000 |
1385 | @@ -0,0 +1,47 @@ |
1386 | +/* |
1387 | + * Copyright (C) 2013-2014 Canonical Ltd |
1388 | + * |
1389 | + * This program is free software: you can redistribute it and/or modify |
1390 | + * it under the terms of the GNU General Public License version 3 as |
1391 | + * published by the Free Software Foundation. |
1392 | + * |
1393 | + * This program is distributed in the hope that it will be useful, |
1394 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1395 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1396 | + * GNU General Public License for more details. |
1397 | + * |
1398 | + * You should have received a copy of the GNU General Public License |
1399 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1400 | + * |
1401 | +*/ |
1402 | + |
1403 | +#include "plugin.h" |
1404 | + |
1405 | +// Qt |
1406 | +#include <QtQml/QtQml> |
1407 | +#include <QtQml/QQmlContext> |
1408 | + |
1409 | +#include "click_applications_model.h" |
1410 | +#include "click_applications_notify_model.h" |
1411 | + |
1412 | +#define MAKE_SINGLETON_FACTORY(type) \ |
1413 | + static QObject* type##_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine) { \ |
1414 | + Q_UNUSED(engine); \ |
1415 | + Q_UNUSED(scriptEngine); \ |
1416 | + return new type(); \ |
1417 | + } |
1418 | + |
1419 | +MAKE_SINGLETON_FACTORY(ClickApplicationsModel) |
1420 | + |
1421 | +void BackendPlugin::registerTypes(const char *uri) |
1422 | +{ |
1423 | + Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.Notifications")); |
1424 | + |
1425 | + qmlRegisterSingletonType<ClickApplicationsModel>(uri, 1, 0, "ClickApplicationsModel", ClickApplicationsModel_singleton_factory); |
1426 | + qmlRegisterType<ClickApplicationsNotifyModel>(uri, 1, 0, "ClickApplicationsNotifyModel"); |
1427 | +} |
1428 | + |
1429 | +void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri) |
1430 | +{ |
1431 | + QQmlExtensionPlugin::initializeEngine(engine, uri); |
1432 | +} |
1433 | |
1434 | === added file 'plugins/new_notifications/plugin.h' |
1435 | --- plugins/new_notifications/plugin.h 1970-01-01 00:00:00 +0000 |
1436 | +++ plugins/new_notifications/plugin.h 2016-06-16 16:49:39 +0000 |
1437 | @@ -0,0 +1,33 @@ |
1438 | +/* |
1439 | + * Copyright (C) 2013 Canonical Ltd |
1440 | + * |
1441 | + * This program is free software: you can redistribute it and/or modify |
1442 | + * it under the terms of the GNU General Public License version 3 as |
1443 | + * published by the Free Software Foundation. |
1444 | + * |
1445 | + * This program is distributed in the hope that it will be useful, |
1446 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1447 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1448 | + * GNU General Public License for more details. |
1449 | + * |
1450 | + * You should have received a copy of the GNU General Public License |
1451 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1452 | + * |
1453 | +*/ |
1454 | + |
1455 | +#ifndef PLUGIN_H |
1456 | +#define PLUGIN_H |
1457 | + |
1458 | +#include <QtQml/QQmlEngine> |
1459 | +#include <QtQml/QQmlExtensionPlugin> |
1460 | + |
1461 | +class BackendPlugin : public QQmlExtensionPlugin |
1462 | +{ |
1463 | + Q_OBJECT |
1464 | + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") |
1465 | + |
1466 | +public: |
1467 | + void registerTypes(const char *uri); |
1468 | + void initializeEngine(QQmlEngine *engine, const char *uri); |
1469 | +}; |
1470 | +#endif // PLUGIN_H |
1471 | |
1472 | === added file 'plugins/new_notifications/qmldir' |
1473 | --- plugins/new_notifications/qmldir 1970-01-01 00:00:00 +0000 |
1474 | +++ plugins/new_notifications/qmldir 2016-06-16 16:49:39 +0000 |
1475 | @@ -0,0 +1,2 @@ |
1476 | +module Ubuntu.SystemSettings.Notifications |
1477 | +plugin UbuntuNotificationsPanel |
1478 | |
1479 | === added directory 'tests/mocks' |
1480 | === added file 'tests/mocks/CMakeLists.txt' |
1481 | --- tests/mocks/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1482 | +++ tests/mocks/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
1483 | @@ -0,0 +1,34 @@ |
1484 | +# Set up and optionally install a mock plugin for ubuntu-system-setting. |
1485 | +# add_uss_mock(plugin version path) |
1486 | + |
1487 | +macro(add_uss_mock PLUGIN VERSION PATH) |
1488 | + cmake_parse_arguments(MOCK "" "${single}" "" ${ARGN}) |
1489 | + |
1490 | + if(NOT QMLFILES_SEARCH_PATH) |
1491 | + set(QMLFILES_SEARCH_PATH ${CMAKE_CURRENT_SOURCE_DIR}) |
1492 | + endif() |
1493 | + |
1494 | + set(qmlfiles_dir ${CMAKE_CURRENT_BINARY_DIR}) |
1495 | + |
1496 | + file(GLOB QMLFILES |
1497 | + ${QMLFILES_SEARCH_PATH}/*.qml |
1498 | + ${QMLFILES_SEARCH_PATH}/*.js |
1499 | + ${QMLFILES_SEARCH_PATH}/*.jpg |
1500 | + ${QMLFILES_SEARCH_PATH}/*.png |
1501 | + ${QMLFILES_SEARCH_PATH}/*.sci |
1502 | + ${QMLFILES_SEARCH_PATH}/*.svg |
1503 | + ${QMLFILES_SEARCH_PATH}/*.qmltypes |
1504 | + ${QMLFILES_SEARCH_PATH}/qmldir |
1505 | + ) |
1506 | + |
1507 | + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${qmlfiles_dir}) |
1508 | + |
1509 | + # copy the files |
1510 | + add_custom_target(${QMLFILES_TARGET_PREFIX}${PLUGIN}-qmlfiles ALL |
1511 | + COMMAND cp ${QMLFILES} ${qmlfiles_dir} |
1512 | + DEPENDS ${QMLFILES} |
1513 | + SOURCES ${QMLFILES} |
1514 | + ) |
1515 | +endmacro() |
1516 | + |
1517 | +add_subdirectory(Ubuntu) |
1518 | |
1519 | === added directory 'tests/mocks/Ubuntu' |
1520 | === added file 'tests/mocks/Ubuntu/CMakeLists.txt' |
1521 | --- tests/mocks/Ubuntu/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1522 | +++ tests/mocks/Ubuntu/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
1523 | @@ -0,0 +1,1 @@ |
1524 | +add_subdirectory(SystemSettings) |
1525 | |
1526 | === added directory 'tests/mocks/Ubuntu/SystemSettings' |
1527 | === added file 'tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt' |
1528 | --- tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1529 | +++ tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
1530 | @@ -0,0 +1,1 @@ |
1531 | +add_subdirectory(Notifications) |
1532 | |
1533 | === added directory 'tests/mocks/Ubuntu/SystemSettings/Notifications' |
1534 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/CMakeLists.txt' |
1535 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1536 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
1537 | @@ -0,0 +1,22 @@ |
1538 | +include_directories( |
1539 | + ${CMAKE_CURRENT_BINARY_DIR} |
1540 | + ${CMAKE_SOURCE_DIR}/plugins/notifications/ |
1541 | + ${GIO_INCLUDE_DIRS} |
1542 | + ${QTGSETTINGS_INCLUDE_DIRS} |
1543 | +) |
1544 | + |
1545 | +set(MOCK_NOTIFICATIONS_SRCS |
1546 | + ${CMAKE_SOURCE_DIR}/plugins/notifications/click_applications_model.cpp |
1547 | + ${CMAKE_SOURCE_DIR}/plugins/notifications/click_applications_notify_model.cpp |
1548 | + MockClickApplicationsModel.cpp |
1549 | + MockClickApplicationsNotifyModel.cpp |
1550 | + plugin.cpp |
1551 | +) |
1552 | + |
1553 | +add_library(MockUbuntuNotificationsPanel MODULE ${MOCK_NOTIFICATIONS_SRCS}) |
1554 | + |
1555 | +target_link_libraries(MockUbuntuNotificationsPanel ${GIO_LDFLAGS} ${QTGSETTINGS_LDFLAGS}) |
1556 | +qt5_use_modules(MockUbuntuNotificationsPanel Qml Quick Core) |
1557 | + |
1558 | +add_uss_mock(Ubuntu.SystemSettings.Notifications 1.0 Ubuntu/SystemSettings/Notifications |
1559 | + TARGETS MockUbuntuNotificationsPanel) |
1560 | |
1561 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.cpp' |
1562 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.cpp 1970-01-01 00:00:00 +0000 |
1563 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.cpp 2016-06-16 16:49:39 +0000 |
1564 | @@ -0,0 +1,102 @@ |
1565 | +/* |
1566 | + * Copyright 2016 Canonical Ltd. |
1567 | + * |
1568 | + * This file is part of system-settings. |
1569 | + * |
1570 | + * webbrowser-app is free software; you can redistribute it and/or modify |
1571 | + * it under the terms of the GNU General Public License as published by |
1572 | + * the Free Software Foundation; version 3. |
1573 | + * |
1574 | + * webbrowser-app is distributed in the hope that it will be useful, |
1575 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1576 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1577 | + * GNU General Public License for more details. |
1578 | + * |
1579 | + * You should have received a copy of the GNU General Public License |
1580 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1581 | + */ |
1582 | + |
1583 | +// local |
1584 | +#include "MockClickApplicationsModel.h" |
1585 | + |
1586 | +void MockClickApplicationsModel::addApplication(const QString& pkgName, const QString& appName) |
1587 | +{ |
1588 | + ClickApplicationEntry entry; |
1589 | + |
1590 | + entry.pkgName = pkgName; |
1591 | + entry.appName = appName; |
1592 | + entry.displayName = appName; |
1593 | + |
1594 | + entry.enableNotifications = true; |
1595 | + entry.soundsNotify = true; |
1596 | + entry.vibrationsNotify = true; |
1597 | + entry.bubblesNotify = true; |
1598 | + entry.listNotify = true; |
1599 | + |
1600 | + beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
1601 | + m_entries << entry; |
1602 | + endInsertRows(); |
1603 | + Q_EMIT rowCountChanged(); |
1604 | +} |
1605 | + |
1606 | +void MockClickApplicationsModel::removeApplicationByIndex(int index) |
1607 | +{ |
1608 | + beginRemoveRows(QModelIndex(), index, index); |
1609 | + m_entries.removeAt(index); |
1610 | + endRemoveRows(); |
1611 | + Q_EMIT rowCountChanged(); |
1612 | +} |
1613 | + |
1614 | +void MockClickApplicationsModel::setNotificationByIndex(int role, int idx, bool enabled) |
1615 | +{ |
1616 | + switch (role) { |
1617 | + case EnableNotifications: |
1618 | + m_entries[idx].enableNotifications = enabled; |
1619 | + break; |
1620 | + |
1621 | + case SoundsNotify: |
1622 | + m_entries[idx].soundsNotify = enabled; |
1623 | + break; |
1624 | + |
1625 | + case VibrationsNotify: |
1626 | + m_entries[idx].vibrationsNotify = enabled; |
1627 | + break; |
1628 | + |
1629 | + case BubblesNotify: |
1630 | + m_entries[idx].bubblesNotify = enabled; |
1631 | + break; |
1632 | + |
1633 | + case ListNotify: |
1634 | + m_entries[idx].listNotify = enabled; |
1635 | + break; |
1636 | + |
1637 | + default: |
1638 | + return; |
1639 | + } |
1640 | + |
1641 | + QVector<int> roles; |
1642 | + roles << role; |
1643 | + |
1644 | + if (role != EnableNotifications) { |
1645 | + if (!m_entries[idx].soundsNotify && |
1646 | + !m_entries[idx].vibrationsNotify && |
1647 | + !m_entries[idx].bubblesNotify && |
1648 | + !m_entries[idx].listNotify ) { |
1649 | + |
1650 | + if (m_entries[idx].enableNotifications) { |
1651 | + m_entries[idx].enableNotifications = false; |
1652 | + roles << EnableNotifications; |
1653 | + } |
1654 | + } |
1655 | + } |
1656 | + |
1657 | + Q_EMIT dataChanged(this->index(idx, 0), this->index(idx, 0), roles); |
1658 | +} |
1659 | + |
1660 | +void MockClickApplicationsModel::cleanup() |
1661 | +{ |
1662 | + beginResetModel(); |
1663 | + m_entries.clear(); |
1664 | + endResetModel(); |
1665 | + Q_EMIT rowCountChanged(); |
1666 | +} |
1667 | |
1668 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.h' |
1669 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.h 1970-01-01 00:00:00 +0000 |
1670 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsModel.h 2016-06-16 16:49:39 +0000 |
1671 | @@ -0,0 +1,35 @@ |
1672 | +/* |
1673 | + * Copyright 2016 Canonical Ltd. |
1674 | + * |
1675 | + * This file is part of system-settings. |
1676 | + * |
1677 | + * webbrowser-app is free software; you can redistribute it and/or modify |
1678 | + * it under the terms of the GNU General Public License as published by |
1679 | + * the Free Software Foundation; version 3. |
1680 | + * |
1681 | + * webbrowser-app is distributed in the hope that it will be useful, |
1682 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1683 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1684 | + * GNU General Public License for more details. |
1685 | + * |
1686 | + * You should have received a copy of the GNU General Public License |
1687 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1688 | + */ |
1689 | + |
1690 | +// local |
1691 | +#include "click_applications_model.h" |
1692 | + |
1693 | +class MockClickApplicationsModel : public ClickApplicationsModel { |
1694 | + Q_OBJECT |
1695 | + |
1696 | +public: |
1697 | + Q_INVOKABLE void addApplication(const QString& pkgName, const QString& appName); |
1698 | + Q_INVOKABLE void removeApplicationByIndex(int index); |
1699 | + Q_INVOKABLE void setNotificationByIndex(int role, int idx, bool enabled); |
1700 | + Q_INVOKABLE void cleanup(); |
1701 | + |
1702 | +protected Q_SLOTS: |
1703 | + void populateModel() { /* DO NOTHING */ } |
1704 | +}; |
1705 | + |
1706 | + |
1707 | |
1708 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.cpp' |
1709 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.cpp 1970-01-01 00:00:00 +0000 |
1710 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.cpp 2016-06-16 16:49:39 +0000 |
1711 | @@ -0,0 +1,35 @@ |
1712 | +/* |
1713 | + * Copyright 2016 Canonical Ltd. |
1714 | + * |
1715 | + * This file is part of system-settings. |
1716 | + * |
1717 | + * webbrowser-app is free software; you can redistribute it and/or modify |
1718 | + * it under the terms of the GNU General Public License as published by |
1719 | + * the Free Software Foundation; version 3. |
1720 | + * |
1721 | + * webbrowser-app is distributed in the hope that it will be useful, |
1722 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1723 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1724 | + * GNU General Public License for more details. |
1725 | + * |
1726 | + * You should have received a copy of the GNU General Public License |
1727 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1728 | + */ |
1729 | + |
1730 | +// local |
1731 | +#include "MockClickApplicationsNotifyModel.h" |
1732 | +#include "MockClickApplicationsModel.h" |
1733 | + |
1734 | +MockClickApplicationsModel* MockClickApplicationsNotifyModel::sourceModel() const |
1735 | +{ |
1736 | + return qobject_cast<MockClickApplicationsModel*>(QSortFilterProxyModel::sourceModel()); |
1737 | +} |
1738 | + |
1739 | +void MockClickApplicationsNotifyModel::setSourceModel(MockClickApplicationsModel* sourceModel) |
1740 | +{ |
1741 | + if (sourceModel != this->sourceModel()) { |
1742 | + QSortFilterProxyModel::setSourceModel(sourceModel); |
1743 | + Q_EMIT sourceModelChanged(); |
1744 | + Q_EMIT countChanged(); |
1745 | + } |
1746 | +} |
1747 | |
1748 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.h' |
1749 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.h 1970-01-01 00:00:00 +0000 |
1750 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/MockClickApplicationsNotifyModel.h 2016-06-16 16:49:39 +0000 |
1751 | @@ -0,0 +1,35 @@ |
1752 | +/* |
1753 | + * Copyright 2016 Canonical Ltd. |
1754 | + * |
1755 | + * This file is part of system-settings. |
1756 | + * |
1757 | + * webbrowser-app is free software; you can redistribute it and/or modify |
1758 | + * it under the terms of the GNU General Public License as published by |
1759 | + * the Free Software Foundation; version 3. |
1760 | + * |
1761 | + * webbrowser-app is distributed in the hope that it will be useful, |
1762 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1763 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1764 | + * GNU General Public License for more details. |
1765 | + * |
1766 | + * You should have received a copy of the GNU General Public License |
1767 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1768 | + */ |
1769 | + |
1770 | +// local |
1771 | +#include "click_applications_notify_model.h" |
1772 | + |
1773 | +class MockClickApplicationsModel; |
1774 | + |
1775 | +class MockClickApplicationsNotifyModel : public ClickApplicationsNotifyModel { |
1776 | + Q_OBJECT |
1777 | + |
1778 | + Q_PROPERTY(MockClickApplicationsModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged) |
1779 | + |
1780 | +public: |
1781 | + MockClickApplicationsModel* sourceModel() const; |
1782 | + void setSourceModel(MockClickApplicationsModel* sourceModel); |
1783 | + |
1784 | +Q_SIGNALS: |
1785 | + void sourceModelChanged() const; |
1786 | +}; |
1787 | |
1788 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.cpp' |
1789 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.cpp 1970-01-01 00:00:00 +0000 |
1790 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.cpp 2016-06-16 16:49:39 +0000 |
1791 | @@ -0,0 +1,37 @@ |
1792 | +/* |
1793 | + * Copyright (C) 2016 Canonical, Ltd. |
1794 | + * |
1795 | + * This program is free software; you can redistribute it and/or modify |
1796 | + * it under the terms of the GNU General Public License as published by |
1797 | + * the Free Software Foundation; version 3. |
1798 | + * |
1799 | + * This program is distributed in the hope that it will be useful, |
1800 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1801 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1802 | + * GNU General Public License for more details. |
1803 | + * |
1804 | + * You should have received a copy of the GNU General Public License |
1805 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1806 | + */ |
1807 | + |
1808 | +#include "plugin.h" |
1809 | +#include "MockClickApplicationsModel.h" |
1810 | +#include "MockClickApplicationsNotifyModel.h" |
1811 | + |
1812 | +#include <QtQml> |
1813 | + |
1814 | +#define MAKE_SINGLETON_FACTORY(type) \ |
1815 | + static QObject* type##_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine) { \ |
1816 | + Q_UNUSED(engine); \ |
1817 | + Q_UNUSED(scriptEngine); \ |
1818 | + return new type(); \ |
1819 | + } |
1820 | + |
1821 | +MAKE_SINGLETON_FACTORY(MockClickApplicationsModel) |
1822 | + |
1823 | +void BackendPlugin::registerTypes(const char *uri) |
1824 | +{ |
1825 | + Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.Notifications")); |
1826 | + qmlRegisterSingletonType<MockClickApplicationsModel>(uri, 1, 0, "ClickApplicationsModel", MockClickApplicationsModel_singleton_factory); |
1827 | + qmlRegisterType<MockClickApplicationsNotifyModel>(uri, 1, 0, "ClickApplicationsNotifyModel"); |
1828 | +} |
1829 | |
1830 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.h' |
1831 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.h 1970-01-01 00:00:00 +0000 |
1832 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/plugin.h 2016-06-16 16:49:39 +0000 |
1833 | @@ -0,0 +1,31 @@ |
1834 | +/* |
1835 | + * Copyright (C) 2016 Canonical, Ltd. |
1836 | + * |
1837 | + * This program is free software; you can redistribute it and/or modify |
1838 | + * it under the terms of the GNU General Public License as published by |
1839 | + * the Free Software Foundation; version 3. |
1840 | + * |
1841 | + * This program is distributed in the hope that it will be useful, |
1842 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1843 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1844 | + * GNU General Public License for more details. |
1845 | + * |
1846 | + * You should have received a copy of the GNU General Public License |
1847 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1848 | + */ |
1849 | + |
1850 | +#ifndef MOCK_SYSTEMSETTINGS_NOTIFICATIONS_PLUGIN_H |
1851 | +#define MOCK_SYSTEMSETTINGS_NOTIFICATIONS_PLUGIN_H |
1852 | + |
1853 | +#include <QQmlExtensionPlugin> |
1854 | + |
1855 | +class BackendPlugin : public QQmlExtensionPlugin |
1856 | +{ |
1857 | + Q_OBJECT |
1858 | + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") |
1859 | + |
1860 | +public: |
1861 | + void registerTypes(const char *uri) override; |
1862 | +}; |
1863 | + |
1864 | +#endif // MOCK_SYSTEMSETTINGS_NOTIFICATIONS_PLUGIN_H |
1865 | |
1866 | === added file 'tests/mocks/Ubuntu/SystemSettings/Notifications/qmldir' |
1867 | --- tests/mocks/Ubuntu/SystemSettings/Notifications/qmldir 1970-01-01 00:00:00 +0000 |
1868 | +++ tests/mocks/Ubuntu/SystemSettings/Notifications/qmldir 2016-06-16 16:49:39 +0000 |
1869 | @@ -0,0 +1,2 @@ |
1870 | +module Ubuntu.SystemSettings.Notifications |
1871 | +plugin MockUbuntuNotificationsPanel |
1872 | |
1873 | === added directory 'tests/plugins/notifications' |
1874 | === added file 'tests/plugins/notifications/CMakeLists.txt' |
1875 | --- tests/plugins/notifications/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
1876 | +++ tests/plugins/notifications/CMakeLists.txt 2016-06-16 16:49:39 +0000 |
1877 | @@ -0,0 +1,40 @@ |
1878 | +find_package(Qt5Core REQUIRED) |
1879 | +find_package(Qt5Gui REQUIRED) |
1880 | +find_package(Qt5Qml REQUIRED) |
1881 | +find_package(Qt5Quick REQUIRED) |
1882 | +find_package(Qt5QuickTest REQUIRED) |
1883 | +add_definitions(-DTESTS) |
1884 | + |
1885 | +set(XVFB_COMMAND) |
1886 | +find_program(XVFBRUN xvfb-run) |
1887 | +if(XVFBRUN) |
1888 | + set(XVFB_COMMAND ${XVFBRUN} -s "-screen 0 640x480x24" -a) |
1889 | +else() |
1890 | + message(WARNING "Cannot find xvfb-run.") |
1891 | +endif() |
1892 | + |
1893 | +set(TEST tst_notifications) |
1894 | +set(QML_SOURCES tst_PageComponent.qml) |
1895 | +set(SOURCES tst_QmlTests.cpp) |
1896 | + |
1897 | +add_executable(${TEST} ${SOURCES}) |
1898 | + |
1899 | +include_directories( |
1900 | + ${CMAKE_CURRENT_BINARY_DIR} |
1901 | + ${CMAKE_SOURCE_DIR}/src/ |
1902 | +) |
1903 | + |
1904 | +target_link_libraries(${TEST} |
1905 | + Qt5::Core |
1906 | + Qt5::Gui |
1907 | + Qt5::Qml |
1908 | + Qt5::Quick |
1909 | + Qt5::QuickTest |
1910 | +) |
1911 | + |
1912 | +add_test(${TEST} ${XVFB_COMMAND} ${CMAKE_CURRENT_BINARY_DIR}/${TEST} |
1913 | + -input ${CMAKE_SOURCE_DIR}/tests/plugins/notifications/ |
1914 | + -import ${CMAKE_BINARY_DIR}/tests/mocks/ |
1915 | + -import ${CMAKE_SOURCE_DIR}/tests/plugins/notifications |
1916 | + -import ${CMAKE_SOURCE_DIR}/src/ |
1917 | +) |
1918 | |
1919 | === added directory 'tests/plugins/notifications/NotificationsSource' |
1920 | === added file 'tests/plugins/notifications/NotificationsSource/qmldir' |
1921 | --- tests/plugins/notifications/NotificationsSource/qmldir 1970-01-01 00:00:00 +0000 |
1922 | +++ tests/plugins/notifications/NotificationsSource/qmldir 2016-06-16 16:49:39 +0000 |
1923 | @@ -0,0 +1,5 @@ |
1924 | +module NotificationsSource |
1925 | +PageComponent 1.0 ../../../../plugins/notifications/PageComponent.qml |
1926 | +ClickAppNotifications 1.0 ../../../../plugins/notifications/ClickAppNotifications.qml |
1927 | +ClickAppsSoundsNotify 1.0 ../../../../plugins/notifications/ClickAppsSoundsNotify.qml |
1928 | +ClickAppsVibrationsNotify 1.0 ../../../../plugins/notifications/ClickAppsVibrationsNotify.qml |
FAILED: Continuous integration, rev:1665 /jenkins. canonical. com/system- apps/job/ lp-ubuntu- system- settings- ci/20/ /jenkins. canonical. com/system- apps/job/ build/633/ console /jenkins. canonical. com/system- apps/job/ build-0- fetch/633 /jenkins. canonical. com/system- apps/job/ build-1- sourcepkg/ release= vivid+overlay/ 602 /jenkins. canonical. com/system- apps/job/ build-1- sourcepkg/ release= xenial/ 602 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=amd64, release= vivid+overlay/ 595/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=amd64, release= xenial/ 595/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=armhf, release= vivid+overlay/ 595/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=armhf, release= xenial/ 595/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= vivid+overlay/ 595/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= xenial/ 595/console
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/system- apps/job/ lp-ubuntu- system- settings- ci/20/rebuild
https:/