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