Merge lp:~donadigo/wingpanel-indicator-notifications/gala-changes-update into lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications

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

Revision history for this message
Felipe Escoto (philip.scott) wrote :

Working and looking good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Indicator.vala'
--- src/Indicator.vala 2016-05-27 15:10:53 +0000
+++ src/Indicator.vala 2016-07-18 15:43:26 +0000
@@ -43,6 +43,7 @@
43 visible = true;43 visible = true;
4444
45 app_settings_cache = new Gee.HashMap<string, Settings> ();45 app_settings_cache = new Gee.HashMap<string, Settings> ();
46 Utils.init ();
46 }47 }
4748
48 public override Gtk.Widget get_display_widget () {49 public override Gtk.Widget get_display_widget () {
@@ -135,26 +136,24 @@
135136
136 private void on_notification_received (DBusMessage message, uint32 id) {137 private void on_notification_received (DBusMessage message, uint32 id) {
137 var notification = new Notification.from_message (message, id);138 var notification = new Notification.from_message (message, id);
138 string app_name = notification.app_name;139 if (!notification.get_is_valid () || notification.app_name in EXCEPTIONS) {
139
140 if (!notification.get_is_valid () || app_name in EXCEPTIONS) {
141 return;140 return;
142 }141 }
143142
144 Settings? app_settings = app_settings_cache.get (app_name);143 string app_id = notification.desktop_id.replace (Notification.DESKTOP_ID_EXT, "");
144 if (!((DesktopAppInfo)notification.app_info).get_boolean ("X-GNOME-UsesNotifications")) {
145 app_id = "gala-other";
146 }
147
148 Settings? app_settings = app_settings_cache.get (app_id);
145149
146 var schema = SettingsSchemaSource.get_default ().lookup (CHILD_SCHEMA_ID, true);150 var schema = SettingsSchemaSource.get_default ().lookup (CHILD_SCHEMA_ID, true);
147 string appid = "";151 if (schema != null && app_settings == null && app_id != "") {
148 if (notification.appinfo != null) {152 app_settings = new Settings.full (schema, null, CHILD_PATH.printf (app_id));
149 appid = notification.appinfo.get_id ().replace (Notification.DESKTOP_ID_EXT, "");153 app_settings_cache.set (app_id, app_settings);
150 }154 }
151155
152 if (schema != null && app_settings == null && appid != "") {156 if (app_settings == null || app_settings.get_boolean (REMEMBER_KEY)) {
153 app_settings = new Settings.full (schema, null, CHILD_PATH.printf (appid));
154 app_settings_cache.set (appid, app_settings);
155 }
156
157 if (app_settings == null || (app_settings != null && app_settings.get_boolean (REMEMBER_KEY))) {
158 var entry = new NotificationEntry (notification);157 var entry = new NotificationEntry (notification);
159 nlist.add_item (entry);158 nlist.add_item (entry);
160 }159 }
@@ -177,10 +176,8 @@
177 var previous_session = Session.get_instance ().get_session_notifications ();176 var previous_session = Session.get_instance ().get_session_notifications ();
178 if (previous_session.length () > 0) {177 if (previous_session.length () > 0) {
179 previous_session.@foreach ((notification) => {178 previous_session.@foreach ((notification) => {
180 if (notification.message_body.strip () != "" && notification.summary.strip () != "") {179 var entry = new NotificationEntry (notification);
181 var entry = new NotificationEntry (notification);180 nlist.add_item (entry);
182 nlist.add_item (entry);
183 }
184 });181 });
185 } 182 }
186 }183 }
187184
=== modified file 'src/Services/Notification.vala'
--- src/Services/Notification.vala 2016-05-27 15:10:53 +0000
+++ src/Services/Notification.vala 2016-07-18 15:43:26 +0000
@@ -16,6 +16,8 @@
16 */16 */
1717
18public class Notification : Object {18public class Notification : Object {
19 public static const string DESKTOP_ID_EXT = ".desktop";
20
19 public bool data_session;21 public bool data_session;
2022
21 public string app_name;23 public string app_name;
@@ -34,7 +36,7 @@
34 public int64 unix_time;36 public int64 unix_time;
3537
36 public string desktop_id;38 public string desktop_id;
37 public AppInfo? appinfo = null;39 public AppInfo? app_info = null;
3840
39 public signal bool time_changed (TimeSpan span);41 public signal bool time_changed (TimeSpan span);
4042
@@ -50,10 +52,9 @@
50 COUNT52 COUNT
51 }53 }
5254
53 public static const string DESKTOP_ID_EXT = ".desktop";
54 private const string DEFAULT_ACTION = "default";55 private const string DEFAULT_ACTION = "default";
55 private const string DESKTOP_ENTRY_KEY = "desktop-entry";56 private const string DESKTOP_ENTRY_KEY = "desktop-entry";
56 private const string[] OTHER_WHITELIST = { "notify-send" };57 private const string FALLBACK_DESKTOP_ID = "gala-other" + DESKTOP_ID_EXT;
57 private bool pid_accuired;58 private bool pid_accuired;
5859
59 public Notification.from_message (DBusMessage message, uint32 _id) {60 public Notification.from_message (DBusMessage message, uint32 _id) {
@@ -76,17 +77,24 @@
76 timestamp = new DateTime.now_local ();77 timestamp = new DateTime.now_local ();
77 unix_time = timestamp.to_unix ();78 unix_time = timestamp.to_unix ();
7879
79 desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY);80 app_info = Utils.get_appinfo_from_app_name (app_name);
81 if (app_info != null) {
82 desktop_id = app_info.get_id ();
83 } else {
84 desktop_id = lookup_string (hints, DESKTOP_ENTRY_KEY);
85 }
86
80 if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) {87 if (desktop_id != "" && !desktop_id.has_suffix (DESKTOP_ID_EXT)) {
81 desktop_id += DESKTOP_ID_EXT;88 desktop_id += DESKTOP_ID_EXT;
82 }89
8390 app_info = new DesktopAppInfo (desktop_id);
84 appinfo = Utils.get_appinfo_from_app_name (app_name);91 }
85 if (desktop_id != "" && appinfo == null) {92
86 appinfo = new DesktopAppInfo (desktop_id);93 if (app_info == null) {
87 }94 desktop_id = FALLBACK_DESKTOP_ID;
8895 app_info = new DesktopAppInfo (desktop_id);
89 set_properties ();96 }
97
90 setup_pid ();98 setup_pid ();
9199
92 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);100 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);
@@ -107,7 +115,8 @@
107 id = _id;115 id = _id;
108 sender = _sender;116 sender = _sender;
109117
110 set_properties ();118 app_info = Utils.get_appinfo_from_app_name (app_name);
119
111 setup_pid ();120 setup_pid ();
112121
113 actions = _actions;122 actions = _actions;
@@ -120,14 +129,7 @@
120 }129 }
121130
122 public bool get_is_valid () {131 public bool get_is_valid () {
123 return app_name in OTHER_WHITELIST || appinfo != null;132 return app_info != null;
124 }
125
126 private void set_properties () {
127 if (app_name in OTHER_WHITELIST) {
128 display_name = _("Other");
129 app_icon = "dialog-information";
130 }
131 }133 }
132134
133 private void setup_pid () {135 private void setup_pid () {
134136
=== modified file 'src/Services/Session.vala'
--- src/Services/Session.vala 2016-05-27 15:10:53 +0000
+++ src/Services/Session.vala 2016-07-18 15:43:26 +0000
@@ -22,7 +22,7 @@
22 *22 *
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_FILE_NAME = ".notifications.session";
26 private static Session? instance = null;26 private static Session? instance = null;
2727
28 private static File? session_file = null;28 private static File? session_file = null;
@@ -47,7 +47,7 @@
47 }47 }
4848
49 private Session () {49 private Session () {
50 full_path = Environment.get_user_cache_dir () + SESSION_NAME_FILE;50 full_path = Path.build_filename (Environment.get_user_cache_dir (), SESSION_FILE_NAME);
51 session_file = File.new_for_path (full_path);51 session_file = File.new_for_path (full_path);
52 if (!session_file.query_exists ())52 if (!session_file.query_exists ())
53 create_session_file ();53 create_session_file ();
5454
=== modified file 'src/Utils.vala'
--- src/Utils.vala 2016-05-26 19:00:36 +0000
+++ src/Utils.vala 2016-07-18 15:43:26 +0000
@@ -1,51 +1,76 @@
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 */
117
2public class Utils : Object {18public class Utils : Object {
19 private static Gee.HashMap<string, AppInfo> app_info_cache;
20
21 public static void init () {
22 app_info_cache = new Gee.HashMap<string, AppInfo> ();
23 }
24
3 public static AppInfo? get_appinfo_from_app_name (string app_name) {25 public static AppInfo? get_appinfo_from_app_name (string app_name) {
4 if (app_name.strip () == "") {26 if (app_name.strip () == "") {
5 return null;27 return null;
6 }28 }
729
8 AppInfo? appinfo = null;30 AppInfo? app_info = app_info_cache.get (app_name);
9 AppInfo.get_all ().@foreach ((_appinfo) => {31 foreach (unowned AppInfo info in AppInfo.get_all ()) {
10 if (_appinfo != null && validate (_appinfo, app_name)) {32 if (info == null || !validate (info, app_name)) {
11 appinfo = _appinfo;33 continue;
12 return;
13 }34 }
14 });35
1536 app_info = info;
16 return appinfo;37 break;
38 }
39
40 app_info_cache.set (app_name, app_info);
41 return app_info;
17 }42 }
1843
19 private static bool validate (AppInfo appinfo, string app_name) {44 private static bool validate (AppInfo appinfo, string name) {
20 string token = app_name.down ().strip ();45 string? app_executable = appinfo.get_executable ();
2146 string? app_name = appinfo.get_name ();
22 string? token_executable = token;47 string? app_display_name = appinfo.get_display_name ();
23 if (!token_executable.has_prefix (Path.DIR_SEPARATOR_S)) {48
24 token_executable = Environment.find_program_in_path (token_executable);49 if (app_name == null || app_executable == null || app_display_name == null) {
25 } 50 return false;
2651 }
27 string? app_executable = appinfo.get_executable ();52
28 if (!app_executable.has_prefix (Path.DIR_SEPARATOR_S)) {53 string token = name.down ().strip ();
29 app_executable = Environment.find_program_in_path (app_executable);54 string? token_executable = token;
30 }55 if (!token_executable.has_prefix (Path.DIR_SEPARATOR_S)) {
3156 token_executable = Environment.find_program_in_path (token_executable);
32 string[] args;57 }
33 try {58
34 Shell.parse_argv (appinfo.get_commandline (), out args);59 if (!app_executable.has_prefix (Path.DIR_SEPARATOR_S)) {
35 } catch (ShellError e) {60 app_executable = Environment.find_program_in_path (app_executable);
36 warning ("%s\n", e.message);61 }
37 }62
3863 string[] args;
39 if (appinfo.get_name () != null64
40 && appinfo.get_executable () != null65 try {
41 && appinfo.get_display_name () != null) {66 Shell.parse_argv (appinfo.get_commandline (), out args);
42 if (appinfo.get_name ().down () == token67 } catch (ShellError e) {
43 || token_executable == app_executable68 warning ("%s", e.message);
44 || args[0] == token69 }
45 || appinfo.get_display_name ().down ().contains (token))70
46 return true;71 return (app_name.down () == token
47 } 72 || token_executable == app_executable
48 73 || args[0] == token
49 return false; 74 || app_display_name.down ().contains (token));
50 }75 }
51}76}
52\ No newline at end of file77\ No newline at end of file
5378
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2016-05-27 15:10:53 +0000
+++ src/Widgets/AppEntry.vala 2016-07-18 15:43:26 +0000
@@ -16,9 +16,9 @@
16 */16 */
1717
18public class AppEntry : Gtk.ListBoxRow {18public class AppEntry : Gtk.ListBoxRow {
19 public string app_name;19 public string desktop_id;
20 public Gtk.Button clear_btn_entry;20 public Gtk.Button clear_btn_entry;
21 public AppInfo? appinfo = null;21 public AppInfo? app_info = null;
22 public Wnck.Window? app_window;22 public Wnck.Window? app_window;
2323
24 public signal void destroy_entry ();24 public signal void destroy_entry ();
@@ -33,22 +33,21 @@
33 margin_end = 6;33 margin_end = 6;
3434
35 var notification = entry.notification;35 var notification = entry.notification;
36 app_name = notification.app_name;36 desktop_id = notification.desktop_id;
37 app_window = _app_window;37 app_window = _app_window;
38 app_info = notification.app_info;
3839
39 app_notifications = new List<NotificationEntry> ();40 app_notifications = new List<NotificationEntry> ();
40 add_notification_entry (entry);41 add_notification_entry (entry);
4142
42 appinfo = notification.appinfo;
43
44 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);43 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
4544
46 /* Capitalize the first letter */45 /* Capitalize the first letter */
47 char[] utf8 = notification.display_name.to_utf8 ();46 char[] utf8 = notification.display_name.to_utf8 ();
48 utf8[0] = utf8[0].toupper ();47 utf8[0] = utf8[0].toupper ();
4948
50 if (appinfo != null) {49 if (app_info != null) {
51 display_name = appinfo.get_name ();50 display_name = app_info.get_name ();
52 } else {51 } else {
53 display_name = string.join ("", utf8);52 display_name = string.join ("", utf8);
54 }53 }
@@ -63,8 +62,8 @@
63 });62 });
6463
65 string icon = "";64 string icon = "";
66 if (notification.app_icon == "" && appinfo != null) {65 if (notification.app_icon == "" && app_info != null) {
67 var glib_icon = appinfo.get_icon ();66 var glib_icon = app_info.get_icon ();
68 icon = glib_icon.to_string ();67 icon = glib_icon.to_string ();
69 } else {68 } else {
70 icon = notification.app_icon;69 icon = notification.app_icon;
7170
=== modified file 'src/Widgets/NotificationsList.vala'
--- src/Widgets/NotificationsList.vala 2016-06-20 12:37:34 +0000
+++ src/Widgets/NotificationsList.vala 2016-07-18 15:43:26 +0000
@@ -114,7 +114,7 @@
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.desktop_id in construct_desktop_id_list ());
118 if (add) {118 if (add) {
119 var window = 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);
@@ -128,11 +128,11 @@
128 app_entries.append (app_entry);128 app_entries.append (app_entry);
129 prepend (app_entry);129 prepend (app_entry);
130 insert (entry, 1);130 insert (entry, 1);
131 table.insert (app_entry.app_name, 0);131 table.insert (app_entry.desktop_id, 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_desktop_id (entry.notification.desktop_id);
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.desktop_id);
136 insert (entry, insert_pos + 1); 136 insert (entry, insert_pos + 1);
137 }137 }
138 }138 }
@@ -199,10 +199,10 @@
199 }199 }
200 }200 }
201201
202 private AppEntry? get_app_entry_from_app_name (string app_name) {202 private AppEntry? get_app_entry_from_desktop_id (string desktop_id) {
203 AppEntry? entry = null;203 AppEntry? entry = null;
204 app_entries.@foreach ((_entry) => {204 app_entries.@foreach ((_entry) => {
205 if (_entry.app_name == app_name) {205 if (_entry.desktop_id == desktop_id) {
206 entry = _entry;206 entry = _entry;
207 return;207 return;
208 }208 }
@@ -211,13 +211,13 @@
211 return entry;211 return entry;
212 }212 }
213213
214 private string[] construct_app_names () {214 private string[] construct_desktop_id_list () {
215 string[] app_names = {};215 string[] desktop_id_list = {};
216 app_entries.@foreach ((entry) => {216 app_entries.@foreach ((entry) => {
217 app_names += entry.app_name;217 desktop_id_list += entry.desktop_id;
218 });218 });
219219
220 return app_names;220 return desktop_id_list;
221 }221 }
222222
223 private void on_row_activated (Gtk.ListBoxRow row) {223 private void on_row_activated (Gtk.ListBoxRow row) {
@@ -233,9 +233,9 @@
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 close_popover ();235 close_popover ();
236 } else if (((AppEntry) row).appinfo != null) {236 } else if (((AppEntry) row).app_info != null) {
237 try {237 try {
238 ((AppEntry) row).appinfo.launch (null, null);238 ((AppEntry) row).app_info.launch (null, null);
239 } catch (Error e) {239 } catch (Error e) {
240 error ("%s\n", e.message);240 error ("%s\n", e.message);
241 }241 }

Subscribers

People subscribed via source and target branches

to all changes: