Merge lp:~donadigo/wingpanel-indicator-notifications/code-cleanup into lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications

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
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 :

Looks like a couple times you have new copyright headers that say 2015 ;)

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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2015-09-26 12:51:32 +0000
+++ src/CMakeLists.txt 2016-05-27 15:11:10 +0000
@@ -22,8 +22,9 @@
22 Widgets/SeparatorEntry.vala22 Widgets/SeparatorEntry.vala
23 Services/NotificationsMonitor.vala23 Services/NotificationsMonitor.vala
24 Services/Notification.vala24 Services/Notification.vala
25 Services/NSettings.vala25 Services/NotifySettings.vala
26 Services/Session.vala26 Services/Session.vala
27 Services/Interfaces.vala
27 ${CMAKE_CURRENT_BINARY_DIR}/config.vala28 ${CMAKE_CURRENT_BINARY_DIR}/config.vala
28PACKAGES29PACKAGES
29 wingpanel-2.030 wingpanel-2.0
3031
=== modified file 'src/Indicator.vala'
--- src/Indicator.vala 2016-05-26 20:09:37 +0000
+++ src/Indicator.vala 2016-05-27 15:11:10 +0000
@@ -15,27 +15,16 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */16 */
1717
18/* Reflects current state of popover.
19 * Used to inform the time_label to
20 * not change when the popover is shown.
21 */
22public bool indicator_opened = false;
23
24/* Notiifcations monitor */
25public NotificationMonitor monitor;
26
27public NSettings nsettings;
28public Settings settings;
29
30public Session session;
31
32public class Indicator : Wingpanel.Indicator {18public class Indicator : Wingpanel.Indicator {
19 private const string[] EXCEPTIONS = { "wingpanel-indicator-sound", "indicator-sound", "NetworkManager", "gnome-settings-daemon" };
20 private const string CHILD_SCHEMA_ID = "org.pantheon.desktop.gala.notifications.application";
21 private const string CHILD_PATH = "/org/pantheon/desktop/gala/notifications/applications/%s/";
22 private const string REMEMBER_KEY = "remember";
23
33 private const uint16 BOX_WIDTH = 300;24 private const uint16 BOX_WIDTH = 300;
34 private const uint16 BOX_HEIGHT = 400;25 private const uint16 BOX_HEIGHT = 400;
35 private const string[] EXCEPTIONS = { "wingpanel-indicator-sound", "indicator-sound", "NetworkManager", "gnome-settings-daemon" };26 private const string LIST_ID = "list";
36 private static const string CHILD_SCHEMA_ID = "org.pantheon.desktop.gala.notifications.application";27 private const string NO_NOTIFICATIONS_ID = "no-notifications";
37 private static const string CHILD_PATH = "/org/pantheon/desktop/gala/notifications/applications/%s/";
38 private static const string REMEMBER_KEY = "remember";
3928
40 private Wingpanel.Widgets.OverlayIcon? dynamic_icon = null;29 private Wingpanel.Widgets.OverlayIcon? dynamic_icon = null;
41 private Gtk.Box? main_box = null;30 private Gtk.Box? main_box = null;
@@ -51,13 +40,9 @@
51 display_name: _("Notifications indicator"),40 display_name: _("Notifications indicator"),
52 description:_("The notifications indicator"));41 description:_("The notifications indicator"));
5342
54 this.visible = true;43 visible = true;
5544
56 app_settings_cache = new Gee.HashMap<string, Settings> ();45 app_settings_cache = new Gee.HashMap<string, Settings> ();
57
58 nsettings = new NSettings ();
59 monitor = new NotificationMonitor ();
60 session = new Session ();
61 }46 }
6247
63 public override Gtk.Widget get_display_widget () {48 public override Gtk.Widget get_display_widget () {
@@ -66,7 +51,7 @@
6651
67 dynamic_icon.button_press_event.connect ((e) => {52 dynamic_icon.button_press_event.connect ((e) => {
68 if (e.button == Gdk.BUTTON_MIDDLE) {53 if (e.button == Gdk.BUTTON_MIDDLE) {
69 nsettings.do_not_disturb = !nsettings.do_not_disturb;54 NotifySettings.get_instance ().do_not_disturb = !NotifySettings.get_instance ().do_not_disturb;
70 return Gdk.EVENT_STOP;55 return Gdk.EVENT_STOP;
71 }56 }
7257
@@ -96,43 +81,30 @@
96 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;81 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
97 scrolled.add_with_viewport (nlist);82 scrolled.add_with_viewport (nlist);
9883
99 stack.add_named (scrolled, "list");84 stack.add_named (scrolled, LIST_ID);
100 stack.add_named (no_notifications_label, "no-notifications");85 stack.add_named (no_notifications_label, NO_NOTIFICATIONS_ID);
10186
102 var not_disturb_switch = new Wingpanel.Widgets.Switch (_("Do Not Disturb"), nsettings.do_not_disturb);87 var not_disturb_switch = new Wingpanel.Widgets.Switch (_("Do Not Disturb"), NotifySettings.get_instance ().do_not_disturb);
103 not_disturb_switch.get_label ().get_style_context ().add_class ("h4");88 not_disturb_switch.get_label ().get_style_context ().add_class ("h4");
104 not_disturb_switch.get_switch ().notify["active"].connect (() => {89 not_disturb_switch.get_switch ().notify["active"].connect (() => {
105 nsettings.do_not_disturb = not_disturb_switch.get_switch ().active;90 NotifySettings.get_instance ().do_not_disturb = not_disturb_switch.get_switch ().active;
106 });91 });
10792
108 clear_all_btn = new Wingpanel.Widgets.Button (_("Clear All Notifications"));93 clear_all_btn = new Wingpanel.Widgets.Button (_("Clear All Notifications"));
109 clear_all_btn.clicked.connect (() => {94 clear_all_btn.clicked.connect (() => {
110 nlist.clear_all ();95 nlist.clear_all ();
111 session.clear ();96 Session.get_instance ().clear ();
112 });97 });
11398
114 var settings_btn = new Wingpanel.Widgets.Button (_("Notifications Settings…"));99 var settings_btn = new Wingpanel.Widgets.Button (_("Notifications Settings…"));
115 settings_btn.clicked.connect (show_settings);100 settings_btn.clicked.connect (show_settings);
116101
117 nlist.close_popover.connect (() => {102 nlist.close_popover.connect (() => close ());
118 this.close ();103 nlist.switch_stack.connect (on_switch_stack);
119 });104 NotificationMonitor.get_instance ().received.connect (on_notification_received);
120105
121 nlist.switch_stack.connect ((list) => {106 NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => {
122 if (list) {107 not_disturb_switch.get_switch ().active = NotifySettings.get_instance ().do_not_disturb;
123 stack.set_visible_child_name ("list");
124 clear_all_btn.sensitive = true;
125 } else {
126 stack.set_visible_child_name ("no-notifications");
127 dynamic_icon.set_main_icon_name (get_display_icon_name ());
128 clear_all_btn.sensitive = false;
129 }
130 });
131
132 monitor.received.connect (on_notification_received);
133
134 nsettings.changed["do-not-disturb"].connect (() => {
135 not_disturb_switch.get_switch ().active = nsettings.do_not_disturb;
136 dynamic_icon.set_main_icon_name (get_display_icon_name ());108 dynamic_icon.set_main_icon_name (get_display_icon_name ());
137 });109 });
138110
@@ -145,17 +117,7 @@
145 main_box.show_all ();117 main_box.show_all ();
146118
147 nlist.clear_all ();119 nlist.clear_all ();
148 var previous_session = session.get_session_notifications ();120 restore_previous_session ();
149 if (previous_session.length () > 0) {
150 previous_session.@foreach ((notification) => {
151 if (notification.message_body.strip () != "" && notification.summary.strip () != "") {
152 var entry = new NotificationEntry (notification);
153 nlist.add_item (entry);
154
155 dynamic_icon.set_main_icon_name (get_display_icon_name ());
156 }
157 });
158 }
159121
160 dynamic_icon.set_main_icon_name (get_display_icon_name ());122 dynamic_icon.set_main_icon_name (get_display_icon_name ());
161 }123 }
@@ -164,18 +126,11 @@
164 }126 }
165127
166 public override void opened () {128 public override void opened () {
167 indicator_opened = true;
168129
169 nlist.switch_stack (nlist.get_items_length () > 0);
170 if (nlist.get_items_length () > 0) {
171 clear_all_btn.sensitive = true;
172 } else {
173 clear_all_btn.sensitive = false;
174 }
175 }130 }
176131
177 public override void closed () {132 public override void closed () {
178 indicator_opened = false;133
179 }134 }
180135
181 private void on_notification_received (DBusMessage message, uint32 id) {136 private void on_notification_received (DBusMessage message, uint32 id) {
@@ -196,7 +151,7 @@
196151
197 if (schema != null && app_settings == null && appid != "") {152 if (schema != null && app_settings == null && appid != "") {
198 app_settings = new Settings.full (schema, null, CHILD_PATH.printf (appid));153 app_settings = new Settings.full (schema, null, CHILD_PATH.printf (appid));
199 app_settings_cache.set (app_name, app_settings);154 app_settings_cache.set (appid, app_settings);
200 }155 }
201156
202 if (app_settings == null || (app_settings != null && app_settings.get_boolean (REMEMBER_KEY))) {157 if (app_settings == null || (app_settings != null && app_settings.get_boolean (REMEMBER_KEY))) {
@@ -207,8 +162,31 @@
207 dynamic_icon.set_main_icon_name (get_display_icon_name ()); 162 dynamic_icon.set_main_icon_name (get_display_icon_name ());
208 }163 }
209164
165 private void on_switch_stack (bool show_list) {
166 clear_all_btn.sensitive = show_list;
167 if (show_list) {
168 stack.set_visible_child_name (LIST_ID);
169 } else {
170 stack.set_visible_child_name (NO_NOTIFICATIONS_ID);
171 }
172
173 dynamic_icon.set_main_icon_name (get_display_icon_name ());
174 }
175
176 private void restore_previous_session () {
177 var previous_session = Session.get_instance ().get_session_notifications ();
178 if (previous_session.length () > 0) {
179 previous_session.@foreach ((notification) => {
180 if (notification.message_body.strip () != "" && notification.summary.strip () != "") {
181 var entry = new NotificationEntry (notification);
182 nlist.add_item (entry);
183 }
184 });
185 }
186 }
187
210 private string get_display_icon_name () {188 private string get_display_icon_name () {
211 if (nsettings.do_not_disturb) {189 if (NotifySettings.get_instance ().do_not_disturb) {
212 return "notification-disabled-symbolic";190 return "notification-disabled-symbolic";
213 } else if (nlist != null && nlist.get_items_length () > 0) {191 } else if (nlist != null && nlist.get_items_length () > 0) {
214 return "notification-new-symbolic";192 return "notification-new-symbolic";
@@ -218,7 +196,7 @@
218 }196 }
219197
220 private void show_settings () {198 private void show_settings () {
221 this.close ();199 close ();
222200
223 var list = new List<string> ();201 var list = new List<string> ();
224 list.append ("notifications");202 list.append ("notifications");
225203
=== added file 'src/Services/Interfaces.vala'
--- src/Services/Interfaces.vala 1970-01-01 00:00:00 +0000
+++ src/Services/Interfaces.vala 2016-05-27 15:11:10 +0000
@@ -0,0 +1,39 @@
1/*-
2 * Copyright (c) 2016 Wingpanel Developers (http://launchpad.net/wingpanel)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18[DBus (name = "org.freedesktop.Notifications")]
19public interface INotifications : Object {
20 public signal void notification_closed (uint32 id, uint32 reason);
21 public signal void action_invoked (string action, uint32 id);
22 public abstract uint32 notify (string app_name,
23 uint32 replaces_id,
24 string app_icon,
25 string summary,
26 string body,
27 string[] actions,
28 HashTable<string, Variant> hints,
29 int32 expire_timeout) throws Error;
30}
31
32[DBus (name = "org.freedesktop.DBus")]
33public interface IDBus : Object {
34 [DBus (name = "NameHasOwner")]
35 public abstract bool name_has_owner (string name) throws Error;
36
37 [DBus (name = "GetConnectionUnixProcessID")]
38 public abstract uint32 get_connection_unix_process_id (string name) throws Error;
39}
040
=== modified file 'src/Services/Notification.vala'
--- src/Services/Notification.vala 2016-05-26 20:09:37 +0000
+++ src/Services/Notification.vala 2016-05-27 15:11:10 +0000
@@ -59,26 +59,26 @@
59 public Notification.from_message (DBusMessage message, uint32 _id) {59 public Notification.from_message (DBusMessage message, uint32 _id) {
60 var body = message.get_body ();60 var body = message.get_body ();
6161
62 this.data_session = false;62 data_session = false;
6363
64 this.app_name = this.get_string (body, Column.APP_NAME);64 app_name = get_string (body, Column.APP_NAME);
65 this.display_name = app_name;65 display_name = app_name;
66 this.app_icon = this.get_string (body, Column.APP_ICON);66 app_icon = get_string (body, Column.APP_ICON);
67 this.summary = this.get_string (body, Column.SUMMARY);67 summary = get_string (body, Column.SUMMARY);
68 this.message_body = this.get_string (body, Column.BODY);68 message_body = get_string (body, Column.BODY);
69 this.hints = body.get_child_value (Column.HINTS);69 hints = body.get_child_value (Column.HINTS);
70 this.expire_timeout = this.get_int32 (body, Column.EXPIRE_TIMEOUT);70 expire_timeout = get_int32 (body, Column.EXPIRE_TIMEOUT);
71 this.replaces_id = this.get_uint32 (body, Column.REPLACES_ID);71 replaces_id = get_uint32 (body, Column.REPLACES_ID);
72 this.id = _id;72 id = _id;
73 this.sender = message.get_sender ();73 sender = message.get_sender ();
7474
75 this.actions = body.get_child_value (Column.ACTIONS).dup_strv ();75 actions = body.get_child_value (Column.ACTIONS).dup_strv ();
76 this.timestamp = new DateTime.now_local ();76 timestamp = new DateTime.now_local ();
77 this.unix_time = timestamp.to_unix ();77 unix_time = timestamp.to_unix ();
7878
79 this.desktop_id = lookup_string (this.hints, DESKTOP_ENTRY_KEY);79 desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY);
80 if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) {80 if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) {
81 this.desktop_id += DESKTOP_ID_EXT;81 desktop_id += DESKTOP_ID_EXT;
82 }82 }
8383
84 appinfo = Utils.get_appinfo_from_app_name (app_name);84 appinfo = Utils.get_appinfo_from_app_name (app_name);
@@ -95,26 +95,26 @@
95 public Notification.from_data (uint32 _id, string _app_name, string _app_icon,95 public Notification.from_data (uint32 _id, string _app_name, string _app_icon,
96 string _summary, string _message_body,96 string _summary, string _message_body,
97 string[] _actions, int64 _unix_time, string _sender) {97 string[] _actions, int64 _unix_time, string _sender) {
98 this.data_session = true;98 data_session = true;
9999
100 this.app_name = _app_name;100 app_name = _app_name;
101 this.display_name = app_name;101 display_name = app_name;
102 this.app_icon = _app_icon;102 app_icon = _app_icon;
103 this.summary = _summary;103 summary = _summary;
104 this.message_body = _message_body;104 message_body = _message_body;
105 this.expire_timeout = -1;105 expire_timeout = -1;
106 this.replaces_id = 0;106 replaces_id = 0;
107 this.id = _id;107 id = _id;
108 this.sender = _sender;108 sender = _sender;
109109
110 set_properties ();110 set_properties ();
111 setup_pid ();111 setup_pid ();
112112
113 this.actions = _actions;113 actions = _actions;
114 this.unix_time = _unix_time;114 unix_time = _unix_time;
115 this.timestamp = new DateTime.from_unix_local (unix_time);115 timestamp = new DateTime.from_unix_local (unix_time);
116116
117 this.desktop_id = "";117 desktop_id = "";
118118
119 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);119 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);
120 }120 }
@@ -125,40 +125,40 @@
125125
126 private void set_properties () {126 private void set_properties () {
127 if (app_name in OTHER_WHITELIST) {127 if (app_name in OTHER_WHITELIST) {
128 this.display_name = _("Other");128 display_name = _("Other");
129 this.app_icon = "dialog-information"; 129 app_icon = "dialog-information";
130 }130 }
131 }131 }
132132
133 private void setup_pid () {133 private void setup_pid () {
134 this.pid_accuired = this.try_get_pid ();134 pid_accuired = try_get_pid ();
135 nsettings.changed["do-not-disturb"].connect (() => {135 NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => {
136 if (!pid_accuired) {136 if (!pid_accuired) {
137 this.try_get_pid ();137 try_get_pid ();
138 }138 }
139 });139 });
140 }140 }
141141
142 private bool try_get_pid () {142 private bool try_get_pid () {
143 if (nsettings.do_not_disturb) {143 if (NotifySettings.get_instance ().do_not_disturb) {
144 return false;144 return false;
145 }145 }
146146
147 try {147 try {
148 DBusIface? dbusiface = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/");148 IDBus? dbus_iface = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/");
149 if (dbusiface.name_has_owner (sender)) {149 if (dbus_iface != null && dbus_iface.name_has_owner (sender)) {
150 this.pid = dbusiface.get_connection_unix_process_id (sender);150 pid = dbus_iface.get_connection_unix_process_id (sender);
151 }151 }
152 } catch (Error e) {152 } catch (Error e) {
153 error ("%s\n", e.message);153 warning ("%s\n", e.message);
154 }154 }
155155
156 return true;156 return true;
157 }157 }
158158
159 public bool run_default_action () {159 public bool run_default_action () {
160 if (DEFAULT_ACTION in actions) {160 if (DEFAULT_ACTION in actions && NotificationMonitor.get_instance ().notifications_iface != null) {
161 monitor.niface.action_invoked (DEFAULT_ACTION, id);161 NotificationMonitor.get_instance ().notifications_iface.action_invoked (DEFAULT_ACTION, id);
162 return true;162 return true;
163 }163 }
164164
@@ -191,6 +191,6 @@
191 }191 }
192192
193 private bool source_func () {193 private bool source_func () {
194 return this.time_changed (timestamp.difference (new DateTime.now_local ()));194 return time_changed (timestamp.difference (new DateTime.now_local ()));
195 }195 }
196}196}
197197
=== modified file 'src/Services/NotificationsMonitor.vala'
--- src/Services/NotificationsMonitor.vala 2016-05-25 19:20:28 +0000
+++ src/Services/NotificationsMonitor.vala 2016-05-27 15:11:10 +0000
@@ -20,46 +20,33 @@
20 * http://bazaar.launchpad.net/~jconti/recent-notifications/gnome3/view/head:/src/recent-notifications.vala20 * http://bazaar.launchpad.net/~jconti/recent-notifications/gnome3/view/head:/src/recent-notifications.vala
21 */21 */
2222
23[DBus (name = "org.freedesktop.Notifications")]
24public interface NIface : Object {
25 public signal void notification_closed (uint32 id, uint32 reason);
26 public signal void action_invoked (string action, uint32 id);
27 public abstract uint32 notify (string app_name,
28 uint32 replaces_id,
29 string app_icon,
30 string summary,
31 string body,
32 string[] actions,
33 HashTable<string, Variant> hints,
34 int32 expire_timeout) throws Error;
35}
36
37[DBus (name = "org.freedesktop.DBus")]
38public interface DBusIface : Object {
39 [DBus (name = "NameHasOwner")]
40 public abstract bool name_has_owner (string name) throws Error;
41
42 [DBus (name = "GetConnectionUnixProcessID")]
43 public abstract uint32 get_connection_unix_process_id (string name) throws Error;
44}
45
46public class NotificationMonitor : Object {23public class NotificationMonitor : Object {
47 private const string NOTIFY_IFACE = "org.freedesktop.Notifications";24 private const string NOTIFY_IFACE = "org.freedesktop.Notifications";
48 private const string NOTIFY_PATH = "/org/freedesktop/Notifications";25 private const string NOTIFY_PATH = "/org/freedesktop/Notifications";
49 private const string MATCH_STRING = "eavesdrop='true',type='method_call',interface='org.freedesktop.Notifications',member='Notify'";26 private const string MATCH_STRING = "eavesdrop='true',type='method_call',interface='org.freedesktop.Notifications',member='Notify'";
50 private const uint32 REASON_DISMISSED = 2;27 private const uint32 REASON_DISMISSED = 2;
5128
29 private static NotificationMonitor? instance = null;
30
52 private DBusConnection connection;31 private DBusConnection connection;
53 public NIface? niface = null;32 public INotifications? notifications_iface = null;
54 public DBusIface? dbusiface = null;33 public IDBus? dbus_iface = null;
55 private uint32 id_counter = 0;34 private uint32 id_counter = 0;
5635
57 public signal void received (DBusMessage message, uint32 id);36 public signal void received (DBusMessage message, uint32 id);
5837
59 public NotificationMonitor () {38 public static NotificationMonitor get_instance () {
39 if (instance == null) {
40 instance = new NotificationMonitor ();
41 }
42
43 return instance;
44 }
45
46 private NotificationMonitor () {
60 try {47 try {
61 connection = Bus.get_sync (BusType.SESSION);48 connection = Bus.get_sync (BusType.SESSION);
62 this.add_filter (); 49 add_filter ();
63 } catch (Error e) {50 } catch (Error e) {
64 error ("%s\n", e.message);51 error ("%s\n", e.message);
65 }52 }
@@ -75,7 +62,7 @@
75 message.set_body (body);62 message.set_body (body);
76 63
77 try {64 try {
78 niface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH); 65 notifications_iface = Bus.get_proxy_sync (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH);
79 } catch (Error e) {66 } catch (Error e) {
80 error ("%s\n", e.message);67 error ("%s\n", e.message);
81 }68 }
@@ -103,10 +90,10 @@
103 current_id = id_counter;90 current_id = id_counter;
104 }91 }
10592
106 if (nsettings.do_not_disturb) {93 if (NotifySettings.get_instance ().do_not_disturb) {
107 this.received (message, current_id);94 this.received (message, current_id);
108 } else {95 } else {
109 niface.notification_closed.connect ((id, reason) => {96 notifications_iface.notification_closed.connect ((id, reason) => {
110 if (id == 1) {97 if (id == 1) {
111 id_counter = id;98 id_counter = id;
112 current_id = id_counter;99 current_id = id_counter;
@@ -133,7 +120,7 @@
133 hints.insert ("suppress-sound", new Variant.boolean (true));120 hints.insert ("suppress-sound", new Variant.boolean (true));
134 string[] actions = {};121 string[] actions = {};
135 try {122 try {
136 return niface.notify ("", 0, "", "", "", actions, hints, 1);123 return notifications_iface.notify ("", 0, "", "", "", actions, hints, 1);
137 } catch (Error e) {124 } catch (Error e) {
138 error ("%s\n", e.message);125 error ("%s\n", e.message);
139 }126 }
140127
=== renamed file 'src/Services/NSettings.vala' => 'src/Services/NotifySettings.vala'
--- src/Services/NSettings.vala 2015-09-22 14:51:12 +0000
+++ src/Services/NotifySettings.vala 2016-05-27 15:11:10 +0000
@@ -1,5 +1,5 @@
1/*-1/*-
2 * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel)2 * Copyright (c) 2016 Wingpanel Developers (http://launchpad.net/wingpanel)
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published by5 * it under the terms of the GNU Library General Public License as published by
@@ -15,10 +15,21 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */16 */
1717
18public class NSettings : Granite.Services.Settings {18public class NotifySettings : Granite.Services.Settings {
19 public static const string DO_NOT_DISTURB_KEY = "do-not-disturb";
20 public static NotifySettings? instance = null;
21
19 public bool do_not_disturb { get; set; }22 public bool do_not_disturb { get; set; }
2023
21 public NSettings () {24 public static unowned NotifySettings get_instance () {
25 if (instance == null) {
26 instance = new NotifySettings ();
27 }
28
29 return instance;
30 }
31
32 private NotifySettings () {
22 base ("org.pantheon.desktop.gala.notifications");33 base ("org.pantheon.desktop.gala.notifications");
23 }34 }
24}35}
25\ No newline at end of file36\ No newline at end of file
2637
=== modified file 'src/Services/Session.vala'
--- src/Services/Session.vala 2016-05-26 19:56:13 +0000
+++ src/Services/Session.vala 2016-05-27 15:11:10 +0000
@@ -23,6 +23,8 @@
23 */23 */
24public class Session : GLib.Object {24public class Session : GLib.Object {
25 private const string SESSION_NAME_FILE = "/.notifications.session";25 private const string SESSION_NAME_FILE = "/.notifications.session";
26 private static Session? instance = null;
27
26 private static File? session_file = null;28 private static File? session_file = null;
27 private static string full_path;29 private static string full_path;
28 30
@@ -36,7 +38,15 @@
3638
37 private KeyFile key;39 private KeyFile key;
3840
39 public Session () {41 public static Session get_instance () {
42 if (instance == null) {
43 instance = new Session ();
44 }
45
46 return instance;
47 }
48
49 private Session () {
40 full_path = Environment.get_user_cache_dir () + SESSION_NAME_FILE;50 full_path = Environment.get_user_cache_dir () + SESSION_NAME_FILE;
41 session_file = File.new_for_path (full_path);51 session_file = File.new_for_path (full_path);
42 if (!session_file.query_exists ())52 if (!session_file.query_exists ())
4353
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2016-05-26 18:51:03 +0000
+++ src/Widgets/AppEntry.vala 2016-05-27 15:11:10 +0000
@@ -33,11 +33,11 @@
33 margin_end = 6;33 margin_end = 6;
3434
35 var notification = entry.notification;35 var notification = entry.notification;
36 this.app_name = notification.app_name;36 app_name = notification.app_name;
37 this.app_window = _app_window;37 app_window = _app_window;
3838
39 app_notifications = new List<NotificationEntry> ();39 app_notifications = new List<NotificationEntry> ();
40 this.add_notification_entry (entry);40 add_notification_entry (entry);
4141
42 appinfo = notification.appinfo;42 appinfo = notification.appinfo;
4343
@@ -59,7 +59,7 @@
59 clear_btn_entry = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.SMALL_TOOLBAR);59 clear_btn_entry = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
60 clear_btn_entry.get_style_context ().add_class ("flat");60 clear_btn_entry.get_style_context ().add_class ("flat");
61 clear_btn_entry.clicked.connect (() => {61 clear_btn_entry.clicked.connect (() => {
62 this.destroy_entry ();62 destroy_entry ();
63 });63 });
6464
65 string icon = "";65 string icon = "";
@@ -75,33 +75,33 @@
75 hbox.pack_start (label, false, false, 0);75 hbox.pack_start (label, false, false, 0);
76 hbox.pack_end (clear_btn_entry, false, false, 0);76 hbox.pack_end (clear_btn_entry, false, false, 0);
7777
78 this.connect_entry (entry);78 connect_entry (entry);
7979
80 this.add (hbox);80 add (hbox);
81 this.show_all ();81 show_all ();
82 }82 }
8383
84 private void connect_entry (NotificationEntry entry) {84 private void connect_entry (NotificationEntry entry) {
85 entry.clear.connect (() => {85 entry.clear.connect (() => {
86 if (entry != null) {86 if (entry != null) {
87 this.remove_notification_entry (entry);87 remove_notification_entry (entry);
88 }88 }
89 });89 });
90 }90 }
9191
92 public unowned List<NotificationEntry> get_notifications () {92 public unowned List<NotificationEntry> get_notifications () {
93 return this.app_notifications;93 return app_notifications;
94 }94 }
9595
96 public void add_notification_entry (NotificationEntry entry) {96 public void add_notification_entry (NotificationEntry entry) {
97 app_notifications.prepend (entry);97 app_notifications.prepend (entry);
98 this.connect_entry (entry);98 connect_entry (entry);
99 }99 }
100100
101 public void remove_notification_entry (NotificationEntry entry) {101 public void remove_notification_entry (NotificationEntry entry) {
102 app_notifications.remove (entry);102 app_notifications.remove (entry);
103 if (app_notifications.length () == 0) {103 if (app_notifications.length () == 0) {
104 this.destroy_entry ();104 destroy_entry ();
105 }105 }
106 }106 }
107}107}
108108
=== modified file 'src/Widgets/NotificationEntry.vala'
--- src/Widgets/NotificationEntry.vala 2016-05-24 17:51:39 +0000
+++ src/Widgets/NotificationEntry.vala 2016-05-27 15:11:10 +0000
@@ -40,20 +40,20 @@
40 }40 }
4141
42 public NotificationEntry (Notification _notification) {42 public NotificationEntry (Notification _notification) {
43 this.notification = _notification;43 notification = _notification;
44 this.entry_summary = notification.summary;44 entry_summary = notification.summary;
45 this.entry_body = notification.message_body;45 entry_body = notification.message_body;
4646
47 this.get_style_context ().add_class ("menuitem");47 get_style_context ().add_class ("menuitem");
4848
49 notification.time_changed.connect ((timespan) => {49 notification.time_changed.connect ((timespan) => {
50 string label = get_string_from_timespan (timespan);50 string label = get_string_from_timespan (timespan);
51 time_label.label = label;51 time_label.label = label;
5252
53 return this.active;53 return active;
54 });54 });
5555
56 this.hexpand = true;56 hexpand = true;
57 add_widgets ();57 add_widgets ();
5858
59 if (notification.data_session) {59 if (notification.data_session) {
@@ -90,8 +90,8 @@
90 grid.attach (body_label, 0, 1, 2, 1);90 grid.attach (body_label, 0, 1, 2, 1);
91 }91 }
9292
93 this.add (grid);93 add (grid);
94 this.show_all ();94 show_all ();
95 }95 }
9696
97 /**97 /**
9898
=== modified file 'src/Widgets/NotificationsList.vala'
--- src/Widgets/NotificationsList.vala 2016-05-26 19:35:36 +0000
+++ src/Widgets/NotificationsList.vala 2016-05-27 15:11:10 +0000
@@ -16,7 +16,7 @@
16 */16 */
1717
18public class NotificationsList : Gtk.ListBox {18public class NotificationsList : Gtk.ListBox {
19 public signal void switch_stack (bool list);19 public signal void switch_stack (bool show_list);
20 public signal void close_popover ();20 public signal void close_popover ();
21 private List<AppEntry> app_entries;21 private List<AppEntry> app_entries;
22 private List<NotificationEntry> items;22 private List<NotificationEntry> items;
@@ -26,11 +26,11 @@
26 private static Wnck.Screen screen;26 private static Wnck.Screen screen;
2727
28 public NotificationsList () {28 public NotificationsList () {
29 this.margin_top = 2;29 margin_top = 2;
3030
31 this.activate_on_single_click = true;31 activate_on_single_click = true;
32 this.selection_mode = Gtk.SelectionMode.NONE;32 selection_mode = Gtk.SelectionMode.NONE;
33 this.row_activated.connect (on_row_activated);33 row_activated.connect (on_row_activated);
3434
35 items = new List<NotificationEntry> ();35 items = new List<NotificationEntry> ();
36 app_entries = new List<AppEntry> ();36 app_entries = new List<AppEntry> ();
@@ -38,34 +38,34 @@
3838
39 screen = Wnck.Screen.get_default ();39 screen = Wnck.Screen.get_default ();
4040
41 this.vexpand = true;41 vexpand = true;
42 this.show_all ();42 show_all ();
43 }43 }
4444
45 public void add_item (NotificationEntry entry) {45 public void add_item (NotificationEntry entry) {
46 var app_entry = this.add_app_entry (entry);46 var app_entry = add_app_entry (entry);
4747
48 items.prepend (entry);48 items.prepend (entry);
49 this.switch_stack (true);49 switch_stack (true);
5050
51 app_entry.add_notification_entry (entry);51 app_entry.add_notification_entry (entry);
52 this.resort_from_app_entry (app_entry);52 resort_from_app_entry (app_entry);
5353
54 entry.clear.connect (() => {54 entry.clear.connect (() => {
55 this.destroy_notification_entry (entry);55 destroy_notification_entry (entry);
56 });56 });
5757
58 app_entry.destroy_entry.connect (() => {58 app_entry.destroy_entry.connect (() => {
59 this.destroy_app_entry (app_entry);59 destroy_app_entry (app_entry);
60 });60 });
6161
62 counter = counter + 2;62 counter = counter + 2;
6363
64 session.add_notification (entry.notification);64 Session.get_instance ().add_notification (entry.notification);
65 entry.show_all ();65 entry.show_all ();
6666
67 this.update_separators ();67 update_separators ();
68 this.show_all ();68 show_all ();
69 }69 }
7070
7171
@@ -76,47 +76,47 @@
76 public void clear_all () {76 public void clear_all () {
77 items.@foreach ((item) => {77 items.@foreach ((item) => {
78 items.remove (item);78 items.remove (item);
79 this.remove (item);79 remove (item);
80 item.active = false;80 item.active = false;
81 });81 });
8282
83 app_entries.@foreach ((entry) => {83 app_entries.@foreach ((entry) => {
84 app_entries.remove (entry);84 app_entries.remove (entry);
85 this.remove (entry);85 remove (entry);
86 });86 });
8787
88 counter = 0;88 counter = 0;
8989
90 session.clear ();90 Session.get_instance ().clear ();
91 this.switch_stack (false);91 switch_stack (false);
92 this.close_popover ();92 close_popover ();
93 this.show_all ();93 show_all ();
94 }94 }
9595
96 private void update_separators () {96 private void update_separators () {
97 if (this.get_children ().length () > 0) {97 if (get_children ().length () > 0) {
98 foreach (var child in this.get_children ()) {98 foreach (var child in get_children ()) {
99 if (child is SeparatorEntry) {99 if (child is SeparatorEntry) {
100 this.remove (child);100 remove (child);
101 }101 }
102 }102 }
103103
104 foreach (var app_entry in app_entries) {104 foreach (var app_entry in app_entries) {
105 if (app_entry.get_index () != 0 && this.get_children ().nth_data (1) != app_entry) {105 if (app_entry.get_index () != 0 && get_children ().nth_data (1) != app_entry) {
106 var row = new SeparatorEntry ();106 var row = new SeparatorEntry ();
107 this.insert (row, app_entry.get_index ());107 insert (row, app_entry.get_index ());
108 }108 }
109 }109 }
110 }110 }
111111
112 this.show_all ();112 show_all ();
113 }113 }
114114
115 private AppEntry add_app_entry (NotificationEntry entry) {115 private AppEntry add_app_entry (NotificationEntry entry) {
116 AppEntry app_entry;116 AppEntry app_entry;
117 bool add = !(entry.notification.app_name in construct_app_names ());117 bool add = !(entry.notification.app_name in construct_app_names ());
118 if (add) {118 if (add) {
119 var window = this.get_window_from_entry (entry);119 var window = get_window_from_entry (entry);
120 app_entry = new AppEntry (entry, window);120 app_entry = new AppEntry (entry, window);
121121
122 screen.active_window_changed.connect (() => {122 screen.active_window_changed.connect (() => {
@@ -126,14 +126,14 @@
126 });126 });
127127
128 app_entries.append (app_entry);128 app_entries.append (app_entry);
129 this.prepend (app_entry);129 prepend (app_entry);
130 this.insert (entry, 1);130 insert (entry, 1);
131 table.insert (app_entry.app_name, 0);131 table.insert (app_entry.app_name, 0);
132 } else {132 } else {
133 app_entry = get_app_entry_from_app_name (entry.notification.app_name);133 app_entry = get_app_entry_from_app_name (entry.notification.app_name);
134 if (app_entry != null) {134 if (app_entry != null) {
135 int insert_pos = table.@get (app_entry.app_name);135 int insert_pos = table.@get (app_entry.app_name);
136 this.insert (entry, insert_pos + 1); 136 insert (entry, insert_pos + 1);
137 }137 }
138 }138 }
139139
@@ -157,9 +157,9 @@
157 items.remove (entry);157 items.remove (entry);
158 entry.active = false;158 entry.active = false;
159159
160 session.remove_notification (entry.notification);160 Session.get_instance ().remove_notification (entry.notification);
161 if (items.length () == 0) {161 if (items.length () == 0) {
162 this.clear_all ();162 clear_all ();
163 }163 }
164 }164 }
165165
@@ -167,7 +167,7 @@
167 app_entries.remove (app_entry);167 app_entries.remove (app_entry);
168168
169 app_entry.get_notifications ().@foreach ((notification_entry) => {169 app_entry.get_notifications ().@foreach ((notification_entry) => {
170 this.remove (notification_entry);170 remove (notification_entry);
171 items.remove (notification_entry);171 items.remove (notification_entry);
172 });172 });
173173
@@ -180,20 +180,20 @@
180 });180 });
181181
182 if (items.length () == 0) {182 if (items.length () == 0) {
183 this.clear_all ();183 clear_all ();
184 }184 }
185185
186 this.update_separators ();186 update_separators ();
187 }187 }
188188
189 private void resort_from_app_entry (AppEntry app_entry) {189 private void resort_from_app_entry (AppEntry app_entry) {
190 if (this.get_row_at_index (0) != app_entry) {190 if (get_row_at_index (0) != app_entry) {
191 this.remove (app_entry);191 remove (app_entry);
192 this.prepend (app_entry);192 prepend (app_entry);
193 int counter = 1;193 int counter = 1;
194 app_entry.get_notifications ().@foreach ((notification_entry) => {194 app_entry.get_notifications ().@foreach ((notification_entry) => {
195 this.remove (notification_entry);195 remove (notification_entry);
196 this.add_item (notification_entry);196 add_item (notification_entry);
197 counter++;197 counter++;
198 });198 });
199 }199 }
@@ -232,7 +232,7 @@
232 if (((AppEntry) row).app_window != null) {232 if (((AppEntry) row).app_window != null) {
233 ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ());233 ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ());
234 ((AppEntry) row).clear_btn_entry.clicked ();234 ((AppEntry) row).clear_btn_entry.clicked ();
235 this.close_popover ();235 close_popover ();
236 } else if (((AppEntry) row).appinfo != null) {236 } else if (((AppEntry) row).appinfo != null) {
237 try {237 try {
238 ((AppEntry) row).appinfo.launch (null, null);238 ((AppEntry) row).appinfo.launch (null, null);
@@ -241,17 +241,17 @@
241 }241 }
242242
243 ((AppEntry) row).clear_btn_entry.clicked ();243 ((AppEntry) row).clear_btn_entry.clicked ();
244 this.close_popover ();244 close_popover ();
245 }245 }
246 } else {246 } else {
247 if (((NotificationEntry) row).notification.run_default_action ()) {247 if (((NotificationEntry) row).notification.run_default_action ()) {
248 ((NotificationEntry) row).active = false;248 ((NotificationEntry) row).active = false;
249 this.close_popover ();249 close_popover ();
250 }250 }
251251
252 ((NotificationEntry) row).clear ();252 ((NotificationEntry) row).clear ();
253 }253 }
254254
255 this.update_separators ();255 update_separators ();
256 }256 }
257}257}
258258
=== modified file 'src/Widgets/SeparatorEntry.vala'
--- src/Widgets/SeparatorEntry.vala 2015-07-16 10:11:58 +0000
+++ src/Widgets/SeparatorEntry.vala 2016-05-27 15:11:10 +0000
@@ -16,10 +16,9 @@
16 */16 */
1717
18 public class SeparatorEntry : Gtk.ListBoxRow {18 public class SeparatorEntry : Gtk.ListBoxRow {
19
20 public SeparatorEntry () {19 public SeparatorEntry () {
21 this.activatable = this.selectable = false;20 activatable = selectable = false;
22 this.add (new Wingpanel.Widgets.Separator ());21 add (new Wingpanel.Widgets.Separator ());
23 this.show_all ();22 show_all ();
24 }23 }
25 }24 }
26\ No newline at end of file25\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: