Merge lp:~donadigo/wingpanel-indicator-notifications/code-cleanup into lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications
- code-cleanup
- Merge into wingpanel-indicator-notifi...
Proposed by
Adam Bieńkowski
Status: | Merged |
---|---|
Approved by: | Felipe Escoto |
Approved revision: | 92 |
Merged at revision: | 92 |
Proposed branch: | lp:~donadigo/wingpanel-indicator-notifications/code-cleanup |
Merge into: | lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications |
Diff against target: |
942 lines (+245/-220) 11 files modified
src/CMakeLists.txt (+2/-1) src/Indicator.vala (+48/-70) src/Services/Interfaces.vala (+39/-0) src/Services/Notification.vala (+46/-46) src/Services/NotificationsMonitor.vala (+18/-31) src/Services/NotifySettings.vala (+14/-3) src/Services/Session.vala (+11/-1) src/Widgets/AppEntry.vala (+11/-11) src/Widgets/NotificationEntry.vala (+8/-8) src/Widgets/NotificationsList.vala (+45/-45) src/Widgets/SeparatorEntry.vala (+3/-4) |
To merge this branch: | bzr merge lp:~donadigo/wingpanel-indicator-notifications/code-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Felipe Escoto | Approve | ||
Review via email: mp+295888@code.launchpad.net |
Commit message
Code cleanup:
* Remove all global variables: use get_instance instead.
* Remove all unneded variables.
* Update code guidelines.
* Separate big callback functions into their own method.
* More constant variables.
* Remove "this." prefixes.
Description of the change
This branch is meant to make the current code easier to read & recognize.
Detailed changes:
* Remove all global variables: use get_instance instead.
* Remove all unneded variables.
* Update code guidelines.
* Separate big callback functions into their own method.
* More constant variables.
* Remove "this." prefixes.
To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote : | # |
Revision history for this message
Adam Bieńkowski (donadigo) wrote : | # |
> Looks like a couple times you have new copyright headers that say 2015 ;)
Updated.
- 92. By Adam Bieńkowski
-
Code cleanup
Revision history for this message
Felipe Escoto (philip.scott) wrote : | # |
Looks good, and it all still woks!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2015-09-26 12:51:32 +0000 |
3 | +++ src/CMakeLists.txt 2016-05-27 15:11:10 +0000 |
4 | @@ -22,8 +22,9 @@ |
5 | Widgets/SeparatorEntry.vala |
6 | Services/NotificationsMonitor.vala |
7 | Services/Notification.vala |
8 | - Services/NSettings.vala |
9 | + Services/NotifySettings.vala |
10 | Services/Session.vala |
11 | + Services/Interfaces.vala |
12 | ${CMAKE_CURRENT_BINARY_DIR}/config.vala |
13 | PACKAGES |
14 | wingpanel-2.0 |
15 | |
16 | === modified file 'src/Indicator.vala' |
17 | --- src/Indicator.vala 2016-05-26 20:09:37 +0000 |
18 | +++ src/Indicator.vala 2016-05-27 15:11:10 +0000 |
19 | @@ -15,27 +15,16 @@ |
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ |
22 | |
23 | -/* Reflects current state of popover. |
24 | - * Used to inform the time_label to |
25 | - * not change when the popover is shown. |
26 | - */ |
27 | -public bool indicator_opened = false; |
28 | - |
29 | -/* Notiifcations monitor */ |
30 | -public NotificationMonitor monitor; |
31 | - |
32 | -public NSettings nsettings; |
33 | -public Settings settings; |
34 | - |
35 | -public Session session; |
36 | - |
37 | public class Indicator : Wingpanel.Indicator { |
38 | + private const string[] EXCEPTIONS = { "wingpanel-indicator-sound", "indicator-sound", "NetworkManager", "gnome-settings-daemon" }; |
39 | + private const string CHILD_SCHEMA_ID = "org.pantheon.desktop.gala.notifications.application"; |
40 | + private const string CHILD_PATH = "/org/pantheon/desktop/gala/notifications/applications/%s/"; |
41 | + private const string REMEMBER_KEY = "remember"; |
42 | + |
43 | private const uint16 BOX_WIDTH = 300; |
44 | private const uint16 BOX_HEIGHT = 400; |
45 | - private const string[] EXCEPTIONS = { "wingpanel-indicator-sound", "indicator-sound", "NetworkManager", "gnome-settings-daemon" }; |
46 | - private static const string CHILD_SCHEMA_ID = "org.pantheon.desktop.gala.notifications.application"; |
47 | - private static const string CHILD_PATH = "/org/pantheon/desktop/gala/notifications/applications/%s/"; |
48 | - private static const string REMEMBER_KEY = "remember"; |
49 | + private const string LIST_ID = "list"; |
50 | + private const string NO_NOTIFICATIONS_ID = "no-notifications"; |
51 | |
52 | private Wingpanel.Widgets.OverlayIcon? dynamic_icon = null; |
53 | private Gtk.Box? main_box = null; |
54 | @@ -51,13 +40,9 @@ |
55 | display_name: _("Notifications indicator"), |
56 | description:_("The notifications indicator")); |
57 | |
58 | - this.visible = true; |
59 | + visible = true; |
60 | |
61 | app_settings_cache = new Gee.HashMap<string, Settings> (); |
62 | - |
63 | - nsettings = new NSettings (); |
64 | - monitor = new NotificationMonitor (); |
65 | - session = new Session (); |
66 | } |
67 | |
68 | public override Gtk.Widget get_display_widget () { |
69 | @@ -66,7 +51,7 @@ |
70 | |
71 | dynamic_icon.button_press_event.connect ((e) => { |
72 | if (e.button == Gdk.BUTTON_MIDDLE) { |
73 | - nsettings.do_not_disturb = !nsettings.do_not_disturb; |
74 | + NotifySettings.get_instance ().do_not_disturb = !NotifySettings.get_instance ().do_not_disturb; |
75 | return Gdk.EVENT_STOP; |
76 | } |
77 | |
78 | @@ -96,43 +81,30 @@ |
79 | scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER; |
80 | scrolled.add_with_viewport (nlist); |
81 | |
82 | - stack.add_named (scrolled, "list"); |
83 | - stack.add_named (no_notifications_label, "no-notifications"); |
84 | + stack.add_named (scrolled, LIST_ID); |
85 | + stack.add_named (no_notifications_label, NO_NOTIFICATIONS_ID); |
86 | |
87 | - var not_disturb_switch = new Wingpanel.Widgets.Switch (_("Do Not Disturb"), nsettings.do_not_disturb); |
88 | + var not_disturb_switch = new Wingpanel.Widgets.Switch (_("Do Not Disturb"), NotifySettings.get_instance ().do_not_disturb); |
89 | not_disturb_switch.get_label ().get_style_context ().add_class ("h4"); |
90 | not_disturb_switch.get_switch ().notify["active"].connect (() => { |
91 | - nsettings.do_not_disturb = not_disturb_switch.get_switch ().active; |
92 | + NotifySettings.get_instance ().do_not_disturb = not_disturb_switch.get_switch ().active; |
93 | }); |
94 | |
95 | clear_all_btn = new Wingpanel.Widgets.Button (_("Clear All Notifications")); |
96 | clear_all_btn.clicked.connect (() => { |
97 | nlist.clear_all (); |
98 | - session.clear (); |
99 | + Session.get_instance ().clear (); |
100 | }); |
101 | |
102 | var settings_btn = new Wingpanel.Widgets.Button (_("Notifications Settings…")); |
103 | settings_btn.clicked.connect (show_settings); |
104 | |
105 | - nlist.close_popover.connect (() => { |
106 | - this.close (); |
107 | - }); |
108 | - |
109 | - nlist.switch_stack.connect ((list) => { |
110 | - if (list) { |
111 | - stack.set_visible_child_name ("list"); |
112 | - clear_all_btn.sensitive = true; |
113 | - } else { |
114 | - stack.set_visible_child_name ("no-notifications"); |
115 | - dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
116 | - clear_all_btn.sensitive = false; |
117 | - } |
118 | - }); |
119 | - |
120 | - monitor.received.connect (on_notification_received); |
121 | - |
122 | - nsettings.changed["do-not-disturb"].connect (() => { |
123 | - not_disturb_switch.get_switch ().active = nsettings.do_not_disturb; |
124 | + nlist.close_popover.connect (() => close ()); |
125 | + nlist.switch_stack.connect (on_switch_stack); |
126 | + NotificationMonitor.get_instance ().received.connect (on_notification_received); |
127 | + |
128 | + NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => { |
129 | + not_disturb_switch.get_switch ().active = NotifySettings.get_instance ().do_not_disturb; |
130 | dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
131 | }); |
132 | |
133 | @@ -145,17 +117,7 @@ |
134 | main_box.show_all (); |
135 | |
136 | nlist.clear_all (); |
137 | - var previous_session = session.get_session_notifications (); |
138 | - if (previous_session.length () > 0) { |
139 | - previous_session.@foreach ((notification) => { |
140 | - if (notification.message_body.strip () != "" && notification.summary.strip () != "") { |
141 | - var entry = new NotificationEntry (notification); |
142 | - nlist.add_item (entry); |
143 | - |
144 | - dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
145 | - } |
146 | - }); |
147 | - } |
148 | + restore_previous_session (); |
149 | |
150 | dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
151 | } |
152 | @@ -164,18 +126,11 @@ |
153 | } |
154 | |
155 | public override void opened () { |
156 | - indicator_opened = true; |
157 | |
158 | - nlist.switch_stack (nlist.get_items_length () > 0); |
159 | - if (nlist.get_items_length () > 0) { |
160 | - clear_all_btn.sensitive = true; |
161 | - } else { |
162 | - clear_all_btn.sensitive = false; |
163 | - } |
164 | } |
165 | |
166 | public override void closed () { |
167 | - indicator_opened = false; |
168 | + |
169 | } |
170 | |
171 | private void on_notification_received (DBusMessage message, uint32 id) { |
172 | @@ -196,7 +151,7 @@ |
173 | |
174 | if (schema != null && app_settings == null && appid != "") { |
175 | app_settings = new Settings.full (schema, null, CHILD_PATH.printf (appid)); |
176 | - app_settings_cache.set (app_name, app_settings); |
177 | + app_settings_cache.set (appid, app_settings); |
178 | } |
179 | |
180 | if (app_settings == null || (app_settings != null && app_settings.get_boolean (REMEMBER_KEY))) { |
181 | @@ -207,8 +162,31 @@ |
182 | dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
183 | } |
184 | |
185 | + private void on_switch_stack (bool show_list) { |
186 | + clear_all_btn.sensitive = show_list; |
187 | + if (show_list) { |
188 | + stack.set_visible_child_name (LIST_ID); |
189 | + } else { |
190 | + stack.set_visible_child_name (NO_NOTIFICATIONS_ID); |
191 | + } |
192 | + |
193 | + dynamic_icon.set_main_icon_name (get_display_icon_name ()); |
194 | + } |
195 | + |
196 | + private void restore_previous_session () { |
197 | + var previous_session = Session.get_instance ().get_session_notifications (); |
198 | + if (previous_session.length () > 0) { |
199 | + previous_session.@foreach ((notification) => { |
200 | + if (notification.message_body.strip () != "" && notification.summary.strip () != "") { |
201 | + var entry = new NotificationEntry (notification); |
202 | + nlist.add_item (entry); |
203 | + } |
204 | + }); |
205 | + } |
206 | + } |
207 | + |
208 | private string get_display_icon_name () { |
209 | - if (nsettings.do_not_disturb) { |
210 | + if (NotifySettings.get_instance ().do_not_disturb) { |
211 | return "notification-disabled-symbolic"; |
212 | } else if (nlist != null && nlist.get_items_length () > 0) { |
213 | return "notification-new-symbolic"; |
214 | @@ -218,7 +196,7 @@ |
215 | } |
216 | |
217 | private void show_settings () { |
218 | - this.close (); |
219 | + close (); |
220 | |
221 | var list = new List<string> (); |
222 | list.append ("notifications"); |
223 | |
224 | === added file 'src/Services/Interfaces.vala' |
225 | --- src/Services/Interfaces.vala 1970-01-01 00:00:00 +0000 |
226 | +++ src/Services/Interfaces.vala 2016-05-27 15:11:10 +0000 |
227 | @@ -0,0 +1,39 @@ |
228 | +/*- |
229 | + * Copyright (c) 2016 Wingpanel Developers (http://launchpad.net/wingpanel) |
230 | + * |
231 | + * This program is free software: you can redistribute it and/or modify |
232 | + * it under the terms of the GNU Library General Public License as published by |
233 | + * the Free Software Foundation, either version 2.1 of the License, or |
234 | + * (at your option) any later version. |
235 | + * |
236 | + * This program is distributed in the hope that it will be useful, |
237 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
238 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
239 | + * GNU Library General Public License for more details. |
240 | + * |
241 | + * You should have received a copy of the GNU Library General Public License |
242 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
243 | + */ |
244 | + |
245 | +[DBus (name = "org.freedesktop.Notifications")] |
246 | +public interface INotifications : Object { |
247 | + public signal void notification_closed (uint32 id, uint32 reason); |
248 | + public signal void action_invoked (string action, uint32 id); |
249 | + public abstract uint32 notify (string app_name, |
250 | + uint32 replaces_id, |
251 | + string app_icon, |
252 | + string summary, |
253 | + string body, |
254 | + string[] actions, |
255 | + HashTable<string, Variant> hints, |
256 | + int32 expire_timeout) throws Error; |
257 | +} |
258 | + |
259 | +[DBus (name = "org.freedesktop.DBus")] |
260 | +public interface IDBus : Object { |
261 | + [DBus (name = "NameHasOwner")] |
262 | + public abstract bool name_has_owner (string name) throws Error; |
263 | + |
264 | + [DBus (name = "GetConnectionUnixProcessID")] |
265 | + public abstract uint32 get_connection_unix_process_id (string name) throws Error; |
266 | +} |
267 | |
268 | === modified file 'src/Services/Notification.vala' |
269 | --- src/Services/Notification.vala 2016-05-26 20:09:37 +0000 |
270 | +++ src/Services/Notification.vala 2016-05-27 15:11:10 +0000 |
271 | @@ -59,26 +59,26 @@ |
272 | public Notification.from_message (DBusMessage message, uint32 _id) { |
273 | var body = message.get_body (); |
274 | |
275 | - this.data_session = false; |
276 | - |
277 | - this.app_name = this.get_string (body, Column.APP_NAME); |
278 | - this.display_name = app_name; |
279 | - this.app_icon = this.get_string (body, Column.APP_ICON); |
280 | - this.summary = this.get_string (body, Column.SUMMARY); |
281 | - this.message_body = this.get_string (body, Column.BODY); |
282 | - this.hints = body.get_child_value (Column.HINTS); |
283 | - this.expire_timeout = this.get_int32 (body, Column.EXPIRE_TIMEOUT); |
284 | - this.replaces_id = this.get_uint32 (body, Column.REPLACES_ID); |
285 | - this.id = _id; |
286 | - this.sender = message.get_sender (); |
287 | - |
288 | - this.actions = body.get_child_value (Column.ACTIONS).dup_strv (); |
289 | - this.timestamp = new DateTime.now_local (); |
290 | - this.unix_time = timestamp.to_unix (); |
291 | - |
292 | - this.desktop_id = lookup_string (this.hints, DESKTOP_ENTRY_KEY); |
293 | + data_session = false; |
294 | + |
295 | + app_name = get_string (body, Column.APP_NAME); |
296 | + display_name = app_name; |
297 | + app_icon = get_string (body, Column.APP_ICON); |
298 | + summary = get_string (body, Column.SUMMARY); |
299 | + message_body = get_string (body, Column.BODY); |
300 | + hints = body.get_child_value (Column.HINTS); |
301 | + expire_timeout = get_int32 (body, Column.EXPIRE_TIMEOUT); |
302 | + replaces_id = get_uint32 (body, Column.REPLACES_ID); |
303 | + id = _id; |
304 | + sender = message.get_sender (); |
305 | + |
306 | + actions = body.get_child_value (Column.ACTIONS).dup_strv (); |
307 | + timestamp = new DateTime.now_local (); |
308 | + unix_time = timestamp.to_unix (); |
309 | + |
310 | + desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY); |
311 | if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) { |
312 | - this.desktop_id += DESKTOP_ID_EXT; |
313 | + desktop_id += DESKTOP_ID_EXT; |
314 | } |
315 | |
316 | appinfo = Utils.get_appinfo_from_app_name (app_name); |
317 | @@ -95,26 +95,26 @@ |
318 | public Notification.from_data (uint32 _id, string _app_name, string _app_icon, |
319 | string _summary, string _message_body, |
320 | string[] _actions, int64 _unix_time, string _sender) { |
321 | - this.data_session = true; |
322 | + data_session = true; |
323 | |
324 | - this.app_name = _app_name; |
325 | - this.display_name = app_name; |
326 | - this.app_icon = _app_icon; |
327 | - this.summary = _summary; |
328 | - this.message_body = _message_body; |
329 | - this.expire_timeout = -1; |
330 | - this.replaces_id = 0; |
331 | - this.id = _id; |
332 | - this.sender = _sender; |
333 | + app_name = _app_name; |
334 | + display_name = app_name; |
335 | + app_icon = _app_icon; |
336 | + summary = _summary; |
337 | + message_body = _message_body; |
338 | + expire_timeout = -1; |
339 | + replaces_id = 0; |
340 | + id = _id; |
341 | + sender = _sender; |
342 | |
343 | set_properties (); |
344 | setup_pid (); |
345 | |
346 | - this.actions = _actions; |
347 | - this.unix_time = _unix_time; |
348 | - this.timestamp = new DateTime.from_unix_local (unix_time); |
349 | + actions = _actions; |
350 | + unix_time = _unix_time; |
351 | + timestamp = new DateTime.from_unix_local (unix_time); |
352 | |
353 | - this.desktop_id = ""; |
354 | + desktop_id = ""; |
355 | |
356 | Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func); |
357 | } |
358 | @@ -125,40 +125,40 @@ |
359 | |
360 | private void set_properties () { |
361 | if (app_name in OTHER_WHITELIST) { |
362 | - this.display_name = _("Other"); |
363 | - this.app_icon = "dialog-information"; |
364 | + display_name = _("Other"); |
365 | + app_icon = "dialog-information"; |
366 | } |
367 | } |
368 | |
369 | private void setup_pid () { |
370 | - this.pid_accuired = this.try_get_pid (); |
371 | - nsettings.changed["do-not-disturb"].connect (() => { |
372 | + pid_accuired = try_get_pid (); |
373 | + NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => { |
374 | if (!pid_accuired) { |
375 | - this.try_get_pid (); |
376 | + try_get_pid (); |
377 | } |
378 | }); |
379 | } |
380 | |
381 | private bool try_get_pid () { |
382 | - if (nsettings.do_not_disturb) { |
383 | + if (NotifySettings.get_instance ().do_not_disturb) { |
384 | return false; |
385 | } |
386 | |
387 | try { |
388 | - DBusIface? dbusiface = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/"); |
389 | - if (dbusiface.name_has_owner (sender)) { |
390 | - this.pid = dbusiface.get_connection_unix_process_id (sender); |
391 | + IDBus? dbus_iface = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/"); |
392 | + if (dbus_iface != null && dbus_iface.name_has_owner (sender)) { |
393 | + pid = dbus_iface.get_connection_unix_process_id (sender); |
394 | } |
395 | } catch (Error e) { |
396 | - error ("%s\n", e.message); |
397 | + warning ("%s\n", e.message); |
398 | } |
399 | |
400 | return true; |
401 | } |
402 | |
403 | public bool run_default_action () { |
404 | - if (DEFAULT_ACTION in actions) { |
405 | - monitor.niface.action_invoked (DEFAULT_ACTION, id); |
406 | + if (DEFAULT_ACTION in actions && NotificationMonitor.get_instance ().notifications_iface != null) { |
407 | + NotificationMonitor.get_instance ().notifications_iface.action_invoked (DEFAULT_ACTION, id); |
408 | return true; |
409 | } |
410 | |
411 | @@ -191,6 +191,6 @@ |
412 | } |
413 | |
414 | private bool source_func () { |
415 | - return this.time_changed (timestamp.difference (new DateTime.now_local ())); |
416 | + return time_changed (timestamp.difference (new DateTime.now_local ())); |
417 | } |
418 | } |
419 | |
420 | === modified file 'src/Services/NotificationsMonitor.vala' |
421 | --- src/Services/NotificationsMonitor.vala 2016-05-25 19:20:28 +0000 |
422 | +++ src/Services/NotificationsMonitor.vala 2016-05-27 15:11:10 +0000 |
423 | @@ -20,46 +20,33 @@ |
424 | * http://bazaar.launchpad.net/~jconti/recent-notifications/gnome3/view/head:/src/recent-notifications.vala |
425 | */ |
426 | |
427 | -[DBus (name = "org.freedesktop.Notifications")] |
428 | -public interface NIface : Object { |
429 | - public signal void notification_closed (uint32 id, uint32 reason); |
430 | - public signal void action_invoked (string action, uint32 id); |
431 | - public abstract uint32 notify (string app_name, |
432 | - uint32 replaces_id, |
433 | - string app_icon, |
434 | - string summary, |
435 | - string body, |
436 | - string[] actions, |
437 | - HashTable<string, Variant> hints, |
438 | - int32 expire_timeout) throws Error; |
439 | -} |
440 | - |
441 | -[DBus (name = "org.freedesktop.DBus")] |
442 | -public interface DBusIface : Object { |
443 | - [DBus (name = "NameHasOwner")] |
444 | - public abstract bool name_has_owner (string name) throws Error; |
445 | - |
446 | - [DBus (name = "GetConnectionUnixProcessID")] |
447 | - public abstract uint32 get_connection_unix_process_id (string name) throws Error; |
448 | -} |
449 | - |
450 | public class NotificationMonitor : Object { |
451 | private const string NOTIFY_IFACE = "org.freedesktop.Notifications"; |
452 | private const string NOTIFY_PATH = "/org/freedesktop/Notifications"; |
453 | private const string MATCH_STRING = "eavesdrop='true',type='method_call',interface='org.freedesktop.Notifications',member='Notify'"; |
454 | private const uint32 REASON_DISMISSED = 2; |
455 | |
456 | + private static NotificationMonitor? instance = null; |
457 | + |
458 | private DBusConnection connection; |
459 | - public NIface? niface = null; |
460 | - public DBusIface? dbusiface = null; |
461 | + public INotifications? notifications_iface = null; |
462 | + public IDBus? dbus_iface = null; |
463 | private uint32 id_counter = 0; |
464 | |
465 | public signal void received (DBusMessage message, uint32 id); |
466 | |
467 | - public NotificationMonitor () { |
468 | + public static NotificationMonitor get_instance () { |
469 | + if (instance == null) { |
470 | + instance = new NotificationMonitor (); |
471 | + } |
472 | + |
473 | + return instance; |
474 | + } |
475 | + |
476 | + private NotificationMonitor () { |
477 | try { |
478 | connection = Bus.get_sync (BusType.SESSION); |
479 | - this.add_filter (); |
480 | + add_filter (); |
481 | } catch (Error e) { |
482 | error ("%s\n", e.message); |
483 | } |
484 | @@ -75,7 +62,7 @@ |
485 | message.set_body (body); |
486 | |
487 | try { |
488 | - niface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH); |
489 | + notifications_iface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH); |
490 | } catch (Error e) { |
491 | error ("%s\n", e.message); |
492 | } |
493 | @@ -103,10 +90,10 @@ |
494 | current_id = id_counter; |
495 | } |
496 | |
497 | - if (nsettings.do_not_disturb) { |
498 | + if (NotifySettings.get_instance ().do_not_disturb) { |
499 | this.received (message, current_id); |
500 | } else { |
501 | - niface.notification_closed.connect ((id, reason) => { |
502 | + notifications_iface.notification_closed.connect ((id, reason) => { |
503 | if (id == 1) { |
504 | id_counter = id; |
505 | current_id = id_counter; |
506 | @@ -133,7 +120,7 @@ |
507 | hints.insert ("suppress-sound", new Variant.boolean (true)); |
508 | string[] actions = {}; |
509 | try { |
510 | - return niface.notify ("", 0, "", "", "", actions, hints, 1); |
511 | + return notifications_iface.notify ("", 0, "", "", "", actions, hints, 1); |
512 | } catch (Error e) { |
513 | error ("%s\n", e.message); |
514 | } |
515 | |
516 | === renamed file 'src/Services/NSettings.vala' => 'src/Services/NotifySettings.vala' |
517 | --- src/Services/NSettings.vala 2015-09-22 14:51:12 +0000 |
518 | +++ src/Services/NotifySettings.vala 2016-05-27 15:11:10 +0000 |
519 | @@ -1,5 +1,5 @@ |
520 | /*- |
521 | - * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel) |
522 | + * Copyright (c) 2016 Wingpanel Developers (http://launchpad.net/wingpanel) |
523 | * |
524 | * This program is free software: you can redistribute it and/or modify |
525 | * it under the terms of the GNU Library General Public License as published by |
526 | @@ -15,10 +15,21 @@ |
527 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
528 | */ |
529 | |
530 | -public class NSettings : Granite.Services.Settings { |
531 | +public class NotifySettings : Granite.Services.Settings { |
532 | + public static const string DO_NOT_DISTURB_KEY = "do-not-disturb"; |
533 | + public static NotifySettings? instance = null; |
534 | + |
535 | public bool do_not_disturb { get; set; } |
536 | |
537 | - public NSettings () { |
538 | + public static unowned NotifySettings get_instance () { |
539 | + if (instance == null) { |
540 | + instance = new NotifySettings (); |
541 | + } |
542 | + |
543 | + return instance; |
544 | + } |
545 | + |
546 | + private NotifySettings () { |
547 | base ("org.pantheon.desktop.gala.notifications"); |
548 | } |
549 | } |
550 | \ No newline at end of file |
551 | |
552 | === modified file 'src/Services/Session.vala' |
553 | --- src/Services/Session.vala 2016-05-26 19:56:13 +0000 |
554 | +++ src/Services/Session.vala 2016-05-27 15:11:10 +0000 |
555 | @@ -23,6 +23,8 @@ |
556 | */ |
557 | public class Session : GLib.Object { |
558 | private const string SESSION_NAME_FILE = "/.notifications.session"; |
559 | + private static Session? instance = null; |
560 | + |
561 | private static File? session_file = null; |
562 | private static string full_path; |
563 | |
564 | @@ -36,7 +38,15 @@ |
565 | |
566 | private KeyFile key; |
567 | |
568 | - public Session () { |
569 | + public static Session get_instance () { |
570 | + if (instance == null) { |
571 | + instance = new Session (); |
572 | + } |
573 | + |
574 | + return instance; |
575 | + } |
576 | + |
577 | + private Session () { |
578 | full_path = Environment.get_user_cache_dir () + SESSION_NAME_FILE; |
579 | session_file = File.new_for_path (full_path); |
580 | if (!session_file.query_exists ()) |
581 | |
582 | === modified file 'src/Widgets/AppEntry.vala' |
583 | --- src/Widgets/AppEntry.vala 2016-05-26 18:51:03 +0000 |
584 | +++ src/Widgets/AppEntry.vala 2016-05-27 15:11:10 +0000 |
585 | @@ -33,11 +33,11 @@ |
586 | margin_end = 6; |
587 | |
588 | var notification = entry.notification; |
589 | - this.app_name = notification.app_name; |
590 | - this.app_window = _app_window; |
591 | + app_name = notification.app_name; |
592 | + app_window = _app_window; |
593 | |
594 | app_notifications = new List<NotificationEntry> (); |
595 | - this.add_notification_entry (entry); |
596 | + add_notification_entry (entry); |
597 | |
598 | appinfo = notification.appinfo; |
599 | |
600 | @@ -59,7 +59,7 @@ |
601 | clear_btn_entry = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.SMALL_TOOLBAR); |
602 | clear_btn_entry.get_style_context ().add_class ("flat"); |
603 | clear_btn_entry.clicked.connect (() => { |
604 | - this.destroy_entry (); |
605 | + destroy_entry (); |
606 | }); |
607 | |
608 | string icon = ""; |
609 | @@ -75,33 +75,33 @@ |
610 | hbox.pack_start (label, false, false, 0); |
611 | hbox.pack_end (clear_btn_entry, false, false, 0); |
612 | |
613 | - this.connect_entry (entry); |
614 | + connect_entry (entry); |
615 | |
616 | - this.add (hbox); |
617 | - this.show_all (); |
618 | + add (hbox); |
619 | + show_all (); |
620 | } |
621 | |
622 | private void connect_entry (NotificationEntry entry) { |
623 | entry.clear.connect (() => { |
624 | if (entry != null) { |
625 | - this.remove_notification_entry (entry); |
626 | + remove_notification_entry (entry); |
627 | } |
628 | }); |
629 | } |
630 | |
631 | public unowned List<NotificationEntry> get_notifications () { |
632 | - return this.app_notifications; |
633 | + return app_notifications; |
634 | } |
635 | |
636 | public void add_notification_entry (NotificationEntry entry) { |
637 | app_notifications.prepend (entry); |
638 | - this.connect_entry (entry); |
639 | + connect_entry (entry); |
640 | } |
641 | |
642 | public void remove_notification_entry (NotificationEntry entry) { |
643 | app_notifications.remove (entry); |
644 | if (app_notifications.length () == 0) { |
645 | - this.destroy_entry (); |
646 | + destroy_entry (); |
647 | } |
648 | } |
649 | } |
650 | |
651 | === modified file 'src/Widgets/NotificationEntry.vala' |
652 | --- src/Widgets/NotificationEntry.vala 2016-05-24 17:51:39 +0000 |
653 | +++ src/Widgets/NotificationEntry.vala 2016-05-27 15:11:10 +0000 |
654 | @@ -40,20 +40,20 @@ |
655 | } |
656 | |
657 | public NotificationEntry (Notification _notification) { |
658 | - this.notification = _notification; |
659 | - this.entry_summary = notification.summary; |
660 | - this.entry_body = notification.message_body; |
661 | + notification = _notification; |
662 | + entry_summary = notification.summary; |
663 | + entry_body = notification.message_body; |
664 | |
665 | - this.get_style_context ().add_class ("menuitem"); |
666 | + get_style_context ().add_class ("menuitem"); |
667 | |
668 | notification.time_changed.connect ((timespan) => { |
669 | string label = get_string_from_timespan (timespan); |
670 | time_label.label = label; |
671 | |
672 | - return this.active; |
673 | + return active; |
674 | }); |
675 | |
676 | - this.hexpand = true; |
677 | + hexpand = true; |
678 | add_widgets (); |
679 | |
680 | if (notification.data_session) { |
681 | @@ -90,8 +90,8 @@ |
682 | grid.attach (body_label, 0, 1, 2, 1); |
683 | } |
684 | |
685 | - this.add (grid); |
686 | - this.show_all (); |
687 | + add (grid); |
688 | + show_all (); |
689 | } |
690 | |
691 | /** |
692 | |
693 | === modified file 'src/Widgets/NotificationsList.vala' |
694 | --- src/Widgets/NotificationsList.vala 2016-05-26 19:35:36 +0000 |
695 | +++ src/Widgets/NotificationsList.vala 2016-05-27 15:11:10 +0000 |
696 | @@ -16,7 +16,7 @@ |
697 | */ |
698 | |
699 | public class NotificationsList : Gtk.ListBox { |
700 | - public signal void switch_stack (bool list); |
701 | + public signal void switch_stack (bool show_list); |
702 | public signal void close_popover (); |
703 | private List<AppEntry> app_entries; |
704 | private List<NotificationEntry> items; |
705 | @@ -26,11 +26,11 @@ |
706 | private static Wnck.Screen screen; |
707 | |
708 | public NotificationsList () { |
709 | - this.margin_top = 2; |
710 | + margin_top = 2; |
711 | |
712 | - this.activate_on_single_click = true; |
713 | - this.selection_mode = Gtk.SelectionMode.NONE; |
714 | - this.row_activated.connect (on_row_activated); |
715 | + activate_on_single_click = true; |
716 | + selection_mode = Gtk.SelectionMode.NONE; |
717 | + row_activated.connect (on_row_activated); |
718 | |
719 | items = new List<NotificationEntry> (); |
720 | app_entries = new List<AppEntry> (); |
721 | @@ -38,34 +38,34 @@ |
722 | |
723 | screen = Wnck.Screen.get_default (); |
724 | |
725 | - this.vexpand = true; |
726 | - this.show_all (); |
727 | + vexpand = true; |
728 | + show_all (); |
729 | } |
730 | |
731 | public void add_item (NotificationEntry entry) { |
732 | - var app_entry = this.add_app_entry (entry); |
733 | + var app_entry = add_app_entry (entry); |
734 | |
735 | items.prepend (entry); |
736 | - this.switch_stack (true); |
737 | + switch_stack (true); |
738 | |
739 | app_entry.add_notification_entry (entry); |
740 | - this.resort_from_app_entry (app_entry); |
741 | + resort_from_app_entry (app_entry); |
742 | |
743 | entry.clear.connect (() => { |
744 | - this.destroy_notification_entry (entry); |
745 | + destroy_notification_entry (entry); |
746 | }); |
747 | |
748 | app_entry.destroy_entry.connect (() => { |
749 | - this.destroy_app_entry (app_entry); |
750 | + destroy_app_entry (app_entry); |
751 | }); |
752 | |
753 | counter = counter + 2; |
754 | |
755 | - session.add_notification (entry.notification); |
756 | + Session.get_instance ().add_notification (entry.notification); |
757 | entry.show_all (); |
758 | |
759 | - this.update_separators (); |
760 | - this.show_all (); |
761 | + update_separators (); |
762 | + show_all (); |
763 | } |
764 | |
765 | |
766 | @@ -76,47 +76,47 @@ |
767 | public void clear_all () { |
768 | items.@foreach ((item) => { |
769 | items.remove (item); |
770 | - this.remove (item); |
771 | + remove (item); |
772 | item.active = false; |
773 | }); |
774 | |
775 | app_entries.@foreach ((entry) => { |
776 | app_entries.remove (entry); |
777 | - this.remove (entry); |
778 | + remove (entry); |
779 | }); |
780 | |
781 | counter = 0; |
782 | |
783 | - session.clear (); |
784 | - this.switch_stack (false); |
785 | - this.close_popover (); |
786 | - this.show_all (); |
787 | + Session.get_instance ().clear (); |
788 | + switch_stack (false); |
789 | + close_popover (); |
790 | + show_all (); |
791 | } |
792 | |
793 | private void update_separators () { |
794 | - if (this.get_children ().length () > 0) { |
795 | - foreach (var child in this.get_children ()) { |
796 | + if (get_children ().length () > 0) { |
797 | + foreach (var child in get_children ()) { |
798 | if (child is SeparatorEntry) { |
799 | - this.remove (child); |
800 | + remove (child); |
801 | } |
802 | } |
803 | |
804 | foreach (var app_entry in app_entries) { |
805 | - if (app_entry.get_index () != 0 && this.get_children ().nth_data (1) != app_entry) { |
806 | + if (app_entry.get_index () != 0 && get_children ().nth_data (1) != app_entry) { |
807 | var row = new SeparatorEntry (); |
808 | - this.insert (row, app_entry.get_index ()); |
809 | + insert (row, app_entry.get_index ()); |
810 | } |
811 | } |
812 | } |
813 | |
814 | - this.show_all (); |
815 | + show_all (); |
816 | } |
817 | |
818 | private AppEntry add_app_entry (NotificationEntry entry) { |
819 | AppEntry app_entry; |
820 | bool add = !(entry.notification.app_name in construct_app_names ()); |
821 | if (add) { |
822 | - var window = this.get_window_from_entry (entry); |
823 | + var window = get_window_from_entry (entry); |
824 | app_entry = new AppEntry (entry, window); |
825 | |
826 | screen.active_window_changed.connect (() => { |
827 | @@ -126,14 +126,14 @@ |
828 | }); |
829 | |
830 | app_entries.append (app_entry); |
831 | - this.prepend (app_entry); |
832 | - this.insert (entry, 1); |
833 | + prepend (app_entry); |
834 | + insert (entry, 1); |
835 | table.insert (app_entry.app_name, 0); |
836 | } else { |
837 | app_entry = get_app_entry_from_app_name (entry.notification.app_name); |
838 | if (app_entry != null) { |
839 | int insert_pos = table.@get (app_entry.app_name); |
840 | - this.insert (entry, insert_pos + 1); |
841 | + insert (entry, insert_pos + 1); |
842 | } |
843 | } |
844 | |
845 | @@ -157,9 +157,9 @@ |
846 | items.remove (entry); |
847 | entry.active = false; |
848 | |
849 | - session.remove_notification (entry.notification); |
850 | + Session.get_instance ().remove_notification (entry.notification); |
851 | if (items.length () == 0) { |
852 | - this.clear_all (); |
853 | + clear_all (); |
854 | } |
855 | } |
856 | |
857 | @@ -167,7 +167,7 @@ |
858 | app_entries.remove (app_entry); |
859 | |
860 | app_entry.get_notifications ().@foreach ((notification_entry) => { |
861 | - this.remove (notification_entry); |
862 | + remove (notification_entry); |
863 | items.remove (notification_entry); |
864 | }); |
865 | |
866 | @@ -180,20 +180,20 @@ |
867 | }); |
868 | |
869 | if (items.length () == 0) { |
870 | - this.clear_all (); |
871 | + clear_all (); |
872 | } |
873 | |
874 | - this.update_separators (); |
875 | + update_separators (); |
876 | } |
877 | |
878 | private void resort_from_app_entry (AppEntry app_entry) { |
879 | - if (this.get_row_at_index (0) != app_entry) { |
880 | - this.remove (app_entry); |
881 | - this.prepend (app_entry); |
882 | + if (get_row_at_index (0) != app_entry) { |
883 | + remove (app_entry); |
884 | + prepend (app_entry); |
885 | int counter = 1; |
886 | app_entry.get_notifications ().@foreach ((notification_entry) => { |
887 | - this.remove (notification_entry); |
888 | - this.add_item (notification_entry); |
889 | + remove (notification_entry); |
890 | + add_item (notification_entry); |
891 | counter++; |
892 | }); |
893 | } |
894 | @@ -232,7 +232,7 @@ |
895 | if (((AppEntry) row).app_window != null) { |
896 | ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ()); |
897 | ((AppEntry) row).clear_btn_entry.clicked (); |
898 | - this.close_popover (); |
899 | + close_popover (); |
900 | } else if (((AppEntry) row).appinfo != null) { |
901 | try { |
902 | ((AppEntry) row).appinfo.launch (null, null); |
903 | @@ -241,17 +241,17 @@ |
904 | } |
905 | |
906 | ((AppEntry) row).clear_btn_entry.clicked (); |
907 | - this.close_popover (); |
908 | + close_popover (); |
909 | } |
910 | } else { |
911 | if (((NotificationEntry) row).notification.run_default_action ()) { |
912 | ((NotificationEntry) row).active = false; |
913 | - this.close_popover (); |
914 | + close_popover (); |
915 | } |
916 | |
917 | ((NotificationEntry) row).clear (); |
918 | } |
919 | |
920 | - this.update_separators (); |
921 | + update_separators (); |
922 | } |
923 | } |
924 | |
925 | === modified file 'src/Widgets/SeparatorEntry.vala' |
926 | --- src/Widgets/SeparatorEntry.vala 2015-07-16 10:11:58 +0000 |
927 | +++ src/Widgets/SeparatorEntry.vala 2016-05-27 15:11:10 +0000 |
928 | @@ -16,10 +16,9 @@ |
929 | */ |
930 | |
931 | public class SeparatorEntry : Gtk.ListBoxRow { |
932 | - |
933 | public SeparatorEntry () { |
934 | - this.activatable = this.selectable = false; |
935 | - this.add (new Wingpanel.Widgets.Separator ()); |
936 | - this.show_all (); |
937 | + activatable = selectable = false; |
938 | + add (new Wingpanel.Widgets.Separator ()); |
939 | + show_all (); |
940 | } |
941 | } |
942 | \ No newline at end of file |
Looks like a couple times you have new copyright headers that say 2015 ;)