Merge lp:~donadigo/wingpanel-indicator-notifications/gala-changes-update into lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications
- gala-changes-update
- Merge into wingpanel-indicator-notifi...
Proposed by
Adam Bieńkowski
Status: | Merged |
---|---|
Approved by: | Felipe Escoto |
Approved revision: | 106 |
Merged at revision: | 103 |
Proposed branch: | lp:~donadigo/wingpanel-indicator-notifications/gala-changes-update |
Merge into: | lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications |
Diff against target: |
426 lines (+125/-102) 6 files modified
src/Indicator.vala (+16/-19) src/Services/Notification.vala (+23/-21) src/Services/Session.vala (+2/-2) src/Utils.vala (+64/-39) src/Widgets/AppEntry.vala (+8/-9) src/Widgets/NotificationsList.vala (+12/-12) |
To merge this branch: | bzr merge lp:~donadigo/wingpanel-indicator-notifications/gala-changes-update |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Felipe Escoto | Approve | ||
Review via email: mp+300263@code.launchpad.net |
Commit message
- Update backend to fit newest gala changes
Description of the change
This branch adjusts the code to fit the newest gala changes made by Felipe. There are also minor changes like improving code logic and added header to Utils.vala file.
Keep in mind that for this branch to work you will need the latest gala from trunk installed.
To post a comment you must log in.
- 104. By Adam Bieńkowski
-
Find app entries by their desktop id, not by app name
- 105. By Adam Bieńkowski
-
If does not have UsesNotifications key, use notifications from fallback
- 106. By Adam Bieńkowski
-
Set desktop_id when found AppInfo from name
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/Indicator.vala' |
2 | --- src/Indicator.vala 2016-05-27 15:10:53 +0000 |
3 | +++ src/Indicator.vala 2016-07-18 15:43:26 +0000 |
4 | @@ -43,6 +43,7 @@ |
5 | visible = true; |
6 | |
7 | app_settings_cache = new Gee.HashMap<string, Settings> (); |
8 | + Utils.init (); |
9 | } |
10 | |
11 | public override Gtk.Widget get_display_widget () { |
12 | @@ -135,26 +136,24 @@ |
13 | |
14 | private void on_notification_received (DBusMessage message, uint32 id) { |
15 | var notification = new Notification.from_message (message, id); |
16 | - string app_name = notification.app_name; |
17 | - |
18 | - if (!notification.get_is_valid () || app_name in EXCEPTIONS) { |
19 | + if (!notification.get_is_valid () || notification.app_name in EXCEPTIONS) { |
20 | return; |
21 | } |
22 | |
23 | - Settings? app_settings = app_settings_cache.get (app_name); |
24 | + string app_id = notification.desktop_id.replace (Notification.DESKTOP_ID_EXT, ""); |
25 | + if (!((DesktopAppInfo)notification.app_info).get_boolean ("X-GNOME-UsesNotifications")) { |
26 | + app_id = "gala-other"; |
27 | + } |
28 | + |
29 | + Settings? app_settings = app_settings_cache.get (app_id); |
30 | |
31 | var schema = SettingsSchemaSource.get_default ().lookup (CHILD_SCHEMA_ID, true); |
32 | - string appid = ""; |
33 | - if (notification.appinfo != null) { |
34 | - appid = notification.appinfo.get_id ().replace (Notification.DESKTOP_ID_EXT, ""); |
35 | - } |
36 | - |
37 | - if (schema != null && app_settings == null && appid != "") { |
38 | - app_settings = new Settings.full (schema, null, CHILD_PATH.printf (appid)); |
39 | - app_settings_cache.set (appid, app_settings); |
40 | - } |
41 | - |
42 | - if (app_settings == null || (app_settings != null && app_settings.get_boolean (REMEMBER_KEY))) { |
43 | + if (schema != null && app_settings == null && app_id != "") { |
44 | + app_settings = new Settings.full (schema, null, CHILD_PATH.printf (app_id)); |
45 | + app_settings_cache.set (app_id, app_settings); |
46 | + } |
47 | + |
48 | + if (app_settings == null || app_settings.get_boolean (REMEMBER_KEY)) { |
49 | var entry = new NotificationEntry (notification); |
50 | nlist.add_item (entry); |
51 | } |
52 | @@ -177,10 +176,8 @@ |
53 | var previous_session = Session.get_instance ().get_session_notifications (); |
54 | if (previous_session.length () > 0) { |
55 | previous_session.@foreach ((notification) => { |
56 | - if (notification.message_body.strip () != "" && notification.summary.strip () != "") { |
57 | - var entry = new NotificationEntry (notification); |
58 | - nlist.add_item (entry); |
59 | - } |
60 | + var entry = new NotificationEntry (notification); |
61 | + nlist.add_item (entry); |
62 | }); |
63 | } |
64 | } |
65 | |
66 | === modified file 'src/Services/Notification.vala' |
67 | --- src/Services/Notification.vala 2016-05-27 15:10:53 +0000 |
68 | +++ src/Services/Notification.vala 2016-07-18 15:43:26 +0000 |
69 | @@ -16,6 +16,8 @@ |
70 | */ |
71 | |
72 | public class Notification : Object { |
73 | + public static const string DESKTOP_ID_EXT = ".desktop"; |
74 | + |
75 | public bool data_session; |
76 | |
77 | public string app_name; |
78 | @@ -34,7 +36,7 @@ |
79 | public int64 unix_time; |
80 | |
81 | public string desktop_id; |
82 | - public AppInfo? appinfo = null; |
83 | + public AppInfo? app_info = null; |
84 | |
85 | public signal bool time_changed (TimeSpan span); |
86 | |
87 | @@ -50,10 +52,9 @@ |
88 | COUNT |
89 | } |
90 | |
91 | - public static const string DESKTOP_ID_EXT = ".desktop"; |
92 | private const string DEFAULT_ACTION = "default"; |
93 | private const string DESKTOP_ENTRY_KEY = "desktop-entry"; |
94 | - private const string[] OTHER_WHITELIST = { "notify-send" }; |
95 | + private const string FALLBACK_DESKTOP_ID = "gala-other" + DESKTOP_ID_EXT; |
96 | private bool pid_accuired; |
97 | |
98 | public Notification.from_message (DBusMessage message, uint32 _id) { |
99 | @@ -76,17 +77,24 @@ |
100 | timestamp = new DateTime.now_local (); |
101 | unix_time = timestamp.to_unix (); |
102 | |
103 | - desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY); |
104 | + app_info = Utils.get_appinfo_from_app_name (app_name); |
105 | + if (app_info != null) { |
106 | + desktop_id = app_info.get_id (); |
107 | + } else { |
108 | + desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY); |
109 | + } |
110 | + |
111 | if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) { |
112 | desktop_id += DESKTOP_ID_EXT; |
113 | - } |
114 | - |
115 | - appinfo = Utils.get_appinfo_from_app_name (app_name); |
116 | - if (desktop_id != "" && appinfo == null) { |
117 | - appinfo = new DesktopAppInfo (desktop_id); |
118 | - } |
119 | - |
120 | - set_properties (); |
121 | + |
122 | + app_info = new DesktopAppInfo (desktop_id); |
123 | + } |
124 | + |
125 | + if (app_info == null) { |
126 | + desktop_id = FALLBACK_DESKTOP_ID; |
127 | + app_info = new DesktopAppInfo (desktop_id); |
128 | + } |
129 | + |
130 | setup_pid (); |
131 | |
132 | Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func); |
133 | @@ -107,7 +115,8 @@ |
134 | id = _id; |
135 | sender = _sender; |
136 | |
137 | - set_properties (); |
138 | + app_info = Utils.get_appinfo_from_app_name (app_name); |
139 | + |
140 | setup_pid (); |
141 | |
142 | actions = _actions; |
143 | @@ -120,14 +129,7 @@ |
144 | } |
145 | |
146 | public bool get_is_valid () { |
147 | - return app_name in OTHER_WHITELIST || appinfo != null; |
148 | - } |
149 | - |
150 | - private void set_properties () { |
151 | - if (app_name in OTHER_WHITELIST) { |
152 | - display_name = _("Other"); |
153 | - app_icon = "dialog-information"; |
154 | - } |
155 | + return app_info != null; |
156 | } |
157 | |
158 | private void setup_pid () { |
159 | |
160 | === modified file 'src/Services/Session.vala' |
161 | --- src/Services/Session.vala 2016-05-27 15:10:53 +0000 |
162 | +++ src/Services/Session.vala 2016-07-18 15:43:26 +0000 |
163 | @@ -22,7 +22,7 @@ |
164 | * |
165 | */ |
166 | public class Session : GLib.Object { |
167 | - private const string SESSION_NAME_FILE = "/.notifications.session"; |
168 | + private const string SESSION_FILE_NAME = ".notifications.session"; |
169 | private static Session? instance = null; |
170 | |
171 | private static File? session_file = null; |
172 | @@ -47,7 +47,7 @@ |
173 | } |
174 | |
175 | private Session () { |
176 | - full_path = Environment.get_user_cache_dir () + SESSION_NAME_FILE; |
177 | + full_path = Path.build_filename (Environment.get_user_cache_dir (), SESSION_FILE_NAME); |
178 | session_file = File.new_for_path (full_path); |
179 | if (!session_file.query_exists ()) |
180 | create_session_file (); |
181 | |
182 | === modified file 'src/Utils.vala' |
183 | --- src/Utils.vala 2016-05-26 19:00:36 +0000 |
184 | +++ src/Utils.vala 2016-07-18 15:43:26 +0000 |
185 | @@ -1,51 +1,76 @@ |
186 | +/*- |
187 | + * Copyright (c) 2016 Wingpanel Developers (http://launchpad.net/wingpanel) |
188 | + * |
189 | + * This program is free software: you can redistribute it and/or modify |
190 | + * it under the terms of the GNU Library General Public License as published by |
191 | + * the Free Software Foundation, either version 2.1 of the License, or |
192 | + * (at your option) any later version. |
193 | + * |
194 | + * This program is distributed in the hope that it will be useful, |
195 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
196 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
197 | + * GNU Library General Public License for more details. |
198 | + * |
199 | + * You should have received a copy of the GNU Library General Public License |
200 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
201 | + */ |
202 | |
203 | public class Utils : Object { |
204 | + private static Gee.HashMap<string, AppInfo> app_info_cache; |
205 | + |
206 | + public static void init () { |
207 | + app_info_cache = new Gee.HashMap<string, AppInfo> (); |
208 | + } |
209 | + |
210 | public static AppInfo? get_appinfo_from_app_name (string app_name) { |
211 | if (app_name.strip () == "") { |
212 | return null; |
213 | } |
214 | |
215 | - AppInfo? appinfo = null; |
216 | - AppInfo.get_all ().@foreach ((_appinfo) => { |
217 | - if (_appinfo != null && validate (_appinfo, app_name)) { |
218 | - appinfo = _appinfo; |
219 | - return; |
220 | + AppInfo? app_info = app_info_cache.get (app_name); |
221 | + foreach (unowned AppInfo info in AppInfo.get_all ()) { |
222 | + if (info == null || !validate (info, app_name)) { |
223 | + continue; |
224 | } |
225 | - }); |
226 | - |
227 | - return appinfo; |
228 | + |
229 | + app_info = info; |
230 | + break; |
231 | + } |
232 | + |
233 | + app_info_cache.set (app_name, app_info); |
234 | + return app_info; |
235 | } |
236 | |
237 | - private static bool validate (AppInfo appinfo, string app_name) { |
238 | - string token = app_name.down ().strip (); |
239 | - |
240 | - string? token_executable = token; |
241 | - if (!token_executable.has_prefix (Path.DIR_SEPARATOR_S)) { |
242 | - token_executable = Environment.find_program_in_path (token_executable); |
243 | - } |
244 | - |
245 | - string? app_executable = appinfo.get_executable (); |
246 | - if (!app_executable.has_prefix (Path.DIR_SEPARATOR_S)) { |
247 | - app_executable = Environment.find_program_in_path (app_executable); |
248 | - } |
249 | - |
250 | - string[] args; |
251 | - try { |
252 | - Shell.parse_argv (appinfo.get_commandline (), out args); |
253 | - } catch (ShellError e) { |
254 | - warning ("%s\n", e.message); |
255 | - } |
256 | - |
257 | - if (appinfo.get_name () != null |
258 | - && appinfo.get_executable () != null |
259 | - && appinfo.get_display_name () != null) { |
260 | - if (appinfo.get_name ().down () == token |
261 | - || token_executable == app_executable |
262 | - || args[0] == token |
263 | - || appinfo.get_display_name ().down ().contains (token)) |
264 | - return true; |
265 | - } |
266 | - |
267 | - return false; |
268 | + private static bool validate (AppInfo appinfo, string name) { |
269 | + string? app_executable = appinfo.get_executable (); |
270 | + string? app_name = appinfo.get_name (); |
271 | + string? app_display_name = appinfo.get_display_name (); |
272 | + |
273 | + if (app_name == null || app_executable == null || app_display_name == null) { |
274 | + return false; |
275 | + } |
276 | + |
277 | + string token = name.down ().strip (); |
278 | + string? token_executable = token; |
279 | + if (!token_executable.has_prefix (Path.DIR_SEPARATOR_S)) { |
280 | + token_executable = Environment.find_program_in_path (token_executable); |
281 | + } |
282 | + |
283 | + if (!app_executable.has_prefix (Path.DIR_SEPARATOR_S)) { |
284 | + app_executable = Environment.find_program_in_path (app_executable); |
285 | + } |
286 | + |
287 | + string[] args; |
288 | + |
289 | + try { |
290 | + Shell.parse_argv (appinfo.get_commandline (), out args); |
291 | + } catch (ShellError e) { |
292 | + warning ("%s", e.message); |
293 | + } |
294 | + |
295 | + return (app_name.down () == token |
296 | + || token_executable == app_executable |
297 | + || args[0] == token |
298 | + || app_display_name.down ().contains (token)); |
299 | } |
300 | } |
301 | \ No newline at end of file |
302 | |
303 | === modified file 'src/Widgets/AppEntry.vala' |
304 | --- src/Widgets/AppEntry.vala 2016-05-27 15:10:53 +0000 |
305 | +++ src/Widgets/AppEntry.vala 2016-07-18 15:43:26 +0000 |
306 | @@ -16,9 +16,9 @@ |
307 | */ |
308 | |
309 | public class AppEntry : Gtk.ListBoxRow { |
310 | - public string app_name; |
311 | + public string desktop_id; |
312 | public Gtk.Button clear_btn_entry; |
313 | - public AppInfo? appinfo = null; |
314 | + public AppInfo? app_info = null; |
315 | public Wnck.Window? app_window; |
316 | |
317 | public signal void destroy_entry (); |
318 | @@ -33,22 +33,21 @@ |
319 | margin_end = 6; |
320 | |
321 | var notification = entry.notification; |
322 | - app_name = notification.app_name; |
323 | + desktop_id = notification.desktop_id; |
324 | app_window = _app_window; |
325 | + app_info = notification.app_info; |
326 | |
327 | app_notifications = new List<NotificationEntry> (); |
328 | add_notification_entry (entry); |
329 | |
330 | - appinfo = notification.appinfo; |
331 | - |
332 | var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12); |
333 | |
334 | /* Capitalize the first letter */ |
335 | char[] utf8 = notification.display_name.to_utf8 (); |
336 | utf8[0] = utf8[0].toupper (); |
337 | |
338 | - if (appinfo != null) { |
339 | - display_name = appinfo.get_name (); |
340 | + if (app_info != null) { |
341 | + display_name = app_info.get_name (); |
342 | } else { |
343 | display_name = string.join ("", utf8); |
344 | } |
345 | @@ -63,8 +62,8 @@ |
346 | }); |
347 | |
348 | string icon = ""; |
349 | - if (notification.app_icon == "" && appinfo != null) { |
350 | - var glib_icon = appinfo.get_icon (); |
351 | + if (notification.app_icon == "" && app_info != null) { |
352 | + var glib_icon = app_info.get_icon (); |
353 | icon = glib_icon.to_string (); |
354 | } else { |
355 | icon = notification.app_icon; |
356 | |
357 | === modified file 'src/Widgets/NotificationsList.vala' |
358 | --- src/Widgets/NotificationsList.vala 2016-06-20 12:37:34 +0000 |
359 | +++ src/Widgets/NotificationsList.vala 2016-07-18 15:43:26 +0000 |
360 | @@ -114,7 +114,7 @@ |
361 | |
362 | private AppEntry add_app_entry (NotificationEntry entry) { |
363 | AppEntry app_entry; |
364 | - bool add = !(entry.notification.app_name in construct_app_names ()); |
365 | + bool add = !(entry.notification.desktop_id in construct_desktop_id_list ()); |
366 | if (add) { |
367 | var window = get_window_from_entry (entry); |
368 | app_entry = new AppEntry (entry, window); |
369 | @@ -128,11 +128,11 @@ |
370 | app_entries.append (app_entry); |
371 | prepend (app_entry); |
372 | insert (entry, 1); |
373 | - table.insert (app_entry.app_name, 0); |
374 | + table.insert (app_entry.desktop_id, 0); |
375 | } else { |
376 | - app_entry = get_app_entry_from_app_name (entry.notification.app_name); |
377 | + app_entry = get_app_entry_from_desktop_id (entry.notification.desktop_id); |
378 | if (app_entry != null) { |
379 | - int insert_pos = table.@get (app_entry.app_name); |
380 | + int insert_pos = table.@get (app_entry.desktop_id); |
381 | insert (entry, insert_pos + 1); |
382 | } |
383 | } |
384 | @@ -199,10 +199,10 @@ |
385 | } |
386 | } |
387 | |
388 | - private AppEntry? get_app_entry_from_app_name (string app_name) { |
389 | + private AppEntry? get_app_entry_from_desktop_id (string desktop_id) { |
390 | AppEntry? entry = null; |
391 | app_entries.@foreach ((_entry) => { |
392 | - if (_entry.app_name == app_name) { |
393 | + if (_entry.desktop_id == desktop_id) { |
394 | entry = _entry; |
395 | return; |
396 | } |
397 | @@ -211,13 +211,13 @@ |
398 | return entry; |
399 | } |
400 | |
401 | - private string[] construct_app_names () { |
402 | - string[] app_names = {}; |
403 | + private string[] construct_desktop_id_list () { |
404 | + string[] desktop_id_list = {}; |
405 | app_entries.@foreach ((entry) => { |
406 | - app_names += entry.app_name; |
407 | + desktop_id_list += entry.desktop_id; |
408 | }); |
409 | |
410 | - return app_names; |
411 | + return desktop_id_list; |
412 | } |
413 | |
414 | private void on_row_activated (Gtk.ListBoxRow row) { |
415 | @@ -233,9 +233,9 @@ |
416 | ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ()); |
417 | ((AppEntry) row).clear_btn_entry.clicked (); |
418 | close_popover (); |
419 | - } else if (((AppEntry) row).appinfo != null) { |
420 | + } else if (((AppEntry) row).app_info != null) { |
421 | try { |
422 | - ((AppEntry) row).appinfo.launch (null, null); |
423 | + ((AppEntry) row).app_info.launch (null, null); |
424 | } catch (Error e) { |
425 | error ("%s\n", e.message); |
426 | } |
Working and looking good!