Merge lp:~donadigo/wingpanel-indicator-notifications/memory-improvements into lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Felipe Escoto
Approved revision: 109
Merged at revision: 106
Proposed branch: lp:~donadigo/wingpanel-indicator-notifications/memory-improvements
Merge into: lp:~wingpanel-devs/wingpanel-indicator-notifications/wingpanel-indicator-notifications
Diff against target: 705 lines (+178/-230)
6 files modified
src/Indicator.vala (+5/-9)
src/Services/Notification.vala (+28/-18)
src/Services/Session.vala (+17/-20)
src/Widgets/AppEntry.vala (+25/-43)
src/Widgets/NotificationEntry.vala (+5/-8)
src/Widgets/NotificationsList.vala (+98/-132)
To merge this branch: bzr merge lp:~donadigo/wingpanel-indicator-notifications/memory-improvements
Reviewer Review Type Date Requested Status
Felipe Escoto Approve
Review via email: mp+300662@code.launchpad.net

Commit message

- Memory improvements
- Removed unneded code logic
- Code cleanup
- Simplified code
- Fixed: session would not load on startup
- Added: DesktopID key to session to be able to recognize sender

Description of the change

This branch aims to lower the memory use, remove unneded logic and simplify the code for easier reading. It also fixes that the previous session wouldn't load because it was cleared before it actually loaded.

The most changes were made to NotificationsList class where we now don't store all entries, only app entries which already contain every information we need.

Improvements were also made to the Session class where we only store one key file object and use it for both write / read operations. We now also save DesktopID key which will help the indicator recognize the sender from previous session.

The branch does not introduce any new features. However it needs extensive testing & code review before it can get merged.

To post a comment you must log in.
107. By Adam Bieńkowski

Init app_entry with null

108. By Adam Bieńkowski

Use foreach function

109. By Adam Bieńkowski

Rename add_app_entry to add_entry_internal; bring back the resort function for AppEntry

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

Still working as intended :) good job!

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-07-18 15:57:23 +0000
+++ src/Indicator.vala 2016-07-21 12:53:02 +0000
@@ -117,7 +117,6 @@
117 main_box.pack_end (clear_all_btn, false, false, 0);117 main_box.pack_end (clear_all_btn, false, false, 0);
118 main_box.show_all ();118 main_box.show_all ();
119119
120 nlist.clear_all ();
121 restore_previous_session ();120 restore_previous_session ();
122121
123 dynamic_icon.set_main_icon_name (get_display_icon_name ());122 dynamic_icon.set_main_icon_name (get_display_icon_name ());
@@ -155,7 +154,7 @@
155154
156 if (app_settings == null || app_settings.get_boolean (REMEMBER_KEY)) {155 if (app_settings == null || app_settings.get_boolean (REMEMBER_KEY)) {
157 var entry = new NotificationEntry (notification);156 var entry = new NotificationEntry (notification);
158 nlist.add_item (entry);157 nlist.add_entry (entry);
159 }158 }
160159
161 dynamic_icon.set_main_icon_name (get_display_icon_name ()); 160 dynamic_icon.set_main_icon_name (get_display_icon_name ());
@@ -174,18 +173,15 @@
174173
175 private void restore_previous_session () {174 private void restore_previous_session () {
176 var previous_session = Session.get_instance ().get_session_notifications ();175 var previous_session = Session.get_instance ().get_session_notifications ();
177 if (previous_session.length () > 0) {176 previous_session.foreach ((notification) => {
178 previous_session.@foreach ((notification) => {177 nlist.add_entry (new NotificationEntry (notification));
179 var entry = new NotificationEntry (notification);178 });
180 nlist.add_item (entry);
181 });
182 }
183 }179 }
184180
185 private string get_display_icon_name () {181 private string get_display_icon_name () {
186 if (NotifySettings.get_instance ().do_not_disturb) {182 if (NotifySettings.get_instance ().do_not_disturb) {
187 return "notification-disabled-symbolic";183 return "notification-disabled-symbolic";
188 } else if (nlist != null && nlist.get_items_length () > 0) {184 } else if (nlist != null && nlist.get_entries_length () > 0) {
189 return "notification-new-symbolic";185 return "notification-new-symbolic";
190 }186 }
191 187
192188
=== modified file 'src/Services/Notification.vala'
--- src/Services/Notification.vala 2016-07-18 15:42:58 +0000
+++ src/Services/Notification.vala 2016-07-21 12:53:02 +0000
@@ -21,7 +21,6 @@
21 public bool data_session;21 public bool data_session;
2222
23 public string app_name;23 public string app_name;
24 public string display_name;
25 public string summary;24 public string summary;
26 public string message_body;25 public string message_body;
27 public string app_icon;26 public string app_icon;
@@ -63,7 +62,6 @@
63 data_session = false;62 data_session = false;
6463
65 app_name = get_string (body, Column.APP_NAME);64 app_name = get_string (body, Column.APP_NAME);
66 display_name = app_name;
67 app_icon = get_string (body, Column.APP_ICON);65 app_icon = get_string (body, Column.APP_ICON);
68 summary = get_string (body, Column.SUMMARY);66 summary = get_string (body, Column.SUMMARY);
69 message_body = get_string (body, Column.BODY);67 message_body = get_string (body, Column.BODY);
@@ -102,11 +100,10 @@
102100
103 public Notification.from_data (uint32 _id, string _app_name, string _app_icon,101 public Notification.from_data (uint32 _id, string _app_name, string _app_icon,
104 string _summary, string _message_body,102 string _summary, string _message_body,
105 string[] _actions, int64 _unix_time, string _sender) {103 string[] _actions, string _desktop_id, int64 _unix_time, string _sender) {
106 data_session = true;104 data_session = true;
107105
108 app_name = _app_name;106 app_name = _app_name;
109 display_name = app_name;
110 app_icon = _app_icon;107 app_icon = _app_icon;
111 summary = _summary;108 summary = _summary;
112 message_body = _message_body;109 message_body = _message_body;
@@ -115,15 +112,14 @@
115 id = _id;112 id = _id;
116 sender = _sender;113 sender = _sender;
117114
118 app_info = Utils.get_appinfo_from_app_name (app_name);
119
120 setup_pid ();
121
122 actions = _actions;115 actions = _actions;
123 unix_time = _unix_time;116 unix_time = _unix_time;
124 timestamp = new DateTime.from_unix_local (unix_time);117 timestamp = new DateTime.from_unix_local (unix_time);
125118
126 desktop_id = "";119 desktop_id = _desktop_id;
120 app_info = new DesktopAppInfo (desktop_id);
121
122 setup_pid ();
127123
128 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);124 Timeout.add_seconds_full (Priority.DEFAULT, 60, source_func);
129 }125 }
@@ -132,6 +128,29 @@
132 return app_info != null;128 return app_info != null;
133 }129 }
134130
131 public bool run_default_action () {
132 if (DEFAULT_ACTION in actions && NotificationMonitor.get_instance ().notifications_iface != null) {
133 NotificationMonitor.get_instance ().notifications_iface.action_invoked (DEFAULT_ACTION, id);
134 return true;
135 }
136
137 return false;
138 }
139
140 public Wnck.Window? get_app_window () {
141 Wnck.Window? window = null;
142 if (pid_accuired) {
143 Wnck.Screen.get_default ().get_windows ().foreach ((_window) => {
144 if (_window.get_pid () == pid && window == null) {
145 window = _window;
146 return;
147 }
148 });
149 }
150
151 return window;
152 }
153
135 private void setup_pid () {154 private void setup_pid () {
136 pid_accuired = try_get_pid ();155 pid_accuired = try_get_pid ();
137 NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => {156 NotifySettings.get_instance ().changed[NotifySettings.DO_NOT_DISTURB_KEY].connect (() => {
@@ -158,15 +177,6 @@
158 return true;177 return true;
159 }178 }
160179
161 public bool run_default_action () {
162 if (DEFAULT_ACTION in actions && NotificationMonitor.get_instance ().notifications_iface != null) {
163 NotificationMonitor.get_instance ().notifications_iface.action_invoked (DEFAULT_ACTION, id);
164 return true;
165 }
166
167 return false;
168 }
169
170 private string get_string (Variant tuple, int column) {180 private string get_string (Variant tuple, int column) {
171 var child = tuple.get_child_value (column);181 var child = tuple.get_child_value (column);
172 return child.dup_string ();182 return child.dup_string ();
173183
=== modified file 'src/Services/Session.vala'
--- src/Services/Session.vala 2016-07-17 17:49:54 +0000
+++ src/Services/Session.vala 2016-07-21 12:53:02 +0000
@@ -25,14 +25,14 @@
25 private const string SESSION_FILE_NAME = ".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 File session_file = null;
29 private static string full_path;
30 29
31 private const string APP_NAME_KEY = "AppName";30 private const string APP_NAME_KEY = "AppName";
32 private const string APP_ICON_KEY = "AppIcon";31 private const string APP_ICON_KEY = "AppIcon";
33 private const string SUMMARY_KEY = "Summary";32 private const string SUMMARY_KEY = "Summary";
34 private const string BODY_KEY = "Body";33 private const string BODY_KEY = "Body";
35 private const string ACTIONS_KEY = "Actions";34 private const string ACTIONS_KEY = "Actions";
35 private const string DESKTOP_ID_KEY = "DesktopID";
36 private const string UNIX_TIME_KEY = "UnixTime";36 private const string UNIX_TIME_KEY = "UnixTime";
37 private const string SENDER_KEY = "Sender";37 private const string SENDER_KEY = "Sender";
3838
@@ -47,29 +47,29 @@
47 }47 }
4848
49 private Session () {49 private Session () {
50 full_path = Path.build_filename (Environment.get_user_cache_dir (), SESSION_FILE_NAME);50 session_file = File.new_for_path (Path.build_filename (Environment.get_user_cache_dir (), SESSION_FILE_NAME));
51 session_file = File.new_for_path (full_path);51 if (!session_file.query_exists ()) {
52 if (!session_file.query_exists ())
53 create_session_file ();52 create_session_file ();
53 }
5454
55 key = new KeyFile ();55 key = new KeyFile ();
56 key.set_list_separator (',');56 key.set_list_separator (';');
57 }57 }
5858
59 public List<Notification> get_session_notifications () {59 public List<Notification> get_session_notifications () {
60 var list = new List<Notification> ();60 var list = new List<Notification> ();
61 var _key = new KeyFile ();
62 try {61 try {
63 _key.load_from_file (full_path, KeyFileFlags.NONE);62 key.load_from_file (session_file.get_path (), KeyFileFlags.NONE);
64 foreach (unowned string group in _key.get_groups ()) {63 foreach (unowned string group in key.get_groups ()) {
65 var notification = new Notification.from_data ((uint32)int.parse (group),64 var notification = new Notification.from_data ((uint32)int.parse (group),
66 _key.get_string (group, APP_NAME_KEY),65 key.get_string (group, APP_NAME_KEY),
67 _key.get_string (group, APP_ICON_KEY),66 key.get_string (group, APP_ICON_KEY),
68 _key.get_string (group, SUMMARY_KEY),67 key.get_string (group, SUMMARY_KEY),
69 _key.get_string (group, BODY_KEY),68 key.get_string (group, BODY_KEY),
70 _key.get_string_list (group, ACTIONS_KEY),69 key.get_string_list (group, ACTIONS_KEY),
71 _key.get_int64 (group, UNIX_TIME_KEY),70 key.get_string (group, DESKTOP_ID_KEY),
72 _key.get_string (group, SENDER_KEY));71 key.get_int64 (group, UNIX_TIME_KEY),
72 key.get_string (group, SENDER_KEY));
73 list.append (notification);73 list.append (notification);
74 }74 }
75 } catch (KeyFileError e) {75 } catch (KeyFileError e) {
@@ -88,6 +88,7 @@
88 key.set_string (id, SUMMARY_KEY, notification.summary);88 key.set_string (id, SUMMARY_KEY, notification.summary);
89 key.set_string (id, BODY_KEY, notification.message_body);89 key.set_string (id, BODY_KEY, notification.message_body);
90 key.set_string_list (id, ACTIONS_KEY, notification.actions);90 key.set_string_list (id, ACTIONS_KEY, notification.actions);
91 key.set_string (id, DESKTOP_ID_KEY, notification.desktop_id);
91 key.set_int64 (id, UNIX_TIME_KEY, notification.unix_time);92 key.set_int64 (id, UNIX_TIME_KEY, notification.unix_time);
92 key.set_string (id, SENDER_KEY, notification.sender);93 key.set_string (id, SENDER_KEY, notification.sender);
9394
@@ -106,7 +107,6 @@
106107
107 public void clear () {108 public void clear () {
108 try {109 try {
109 key = new KeyFile ();
110 FileUtils.set_contents (session_file.get_path (), "");110 FileUtils.set_contents (session_file.get_path (), "");
111 } catch (FileError e) {111 } catch (FileError e) {
112 warning (e.message);112 warning (e.message);
@@ -122,9 +122,6 @@
122 }122 }
123123
124 private void write_contents () {124 private void write_contents () {
125 if (session_file == null)
126 create_session_file ();
127
128 try {125 try {
129 FileUtils.set_contents (session_file.get_path (), key.to_data ());126 FileUtils.set_contents (session_file.get_path (), key.to_data ());
130 } catch (FileError e) {127 } catch (FileError e) {
131128
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2016-07-17 18:46:38 +0000
+++ src/Widgets/AppEntry.vala 2016-07-21 12:53:02 +0000
@@ -16,49 +16,32 @@
16 */16 */
1717
18public class AppEntry : Gtk.ListBoxRow {18public class AppEntry : Gtk.ListBoxRow {
19 public string desktop_id;19 public signal void clear ();
20 public Gtk.Button clear_btn_entry;20
21 public AppInfo? app_info = null;21 public AppInfo app_info;
22 public Wnck.Window? app_window;22 public List<NotificationEntry> app_notifications;
2323
24 public signal void destroy_entry ();24 public AppEntry (NotificationEntry entry) {
25
26 private List<NotificationEntry> app_notifications;
27 private string display_name;
28
29 public AppEntry (NotificationEntry entry, Wnck.Window? _app_window) {
30 margin_bottom = 3;25 margin_bottom = 3;
31 margin_top = 3;26 margin_top = 3;
32 margin_start = 12;27 margin_start = 12;
33 margin_end = 6;28 margin_end = 6;
3429
30 app_notifications = new List<NotificationEntry> ();
31 add_notification_entry (entry);
32
35 var notification = entry.notification;33 var notification = entry.notification;
36 desktop_id = notification.desktop_id;
37 app_window = _app_window;
38 app_info = notification.app_info;34 app_info = notification.app_info;
3935
40 app_notifications = new List<NotificationEntry> ();
41 add_notification_entry (entry);
42
43 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);36 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
4437
45 /* Capitalize the first letter */38 var label = new Gtk.Label (app_info.get_name ());
46 char[] utf8 = notification.display_name.to_utf8 ();
47 utf8[0] = utf8[0].toupper ();
48
49 if (app_info != null) {
50 display_name = app_info.get_name ();
51 } else {
52 display_name = string.join ("", utf8);
53 }
54
55 var label = new Gtk.Label (display_name);
56 label.get_style_context ().add_class ("h3");39 label.get_style_context ().add_class ("h3");
5740
58 clear_btn_entry = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.SMALL_TOOLBAR);41 var clear_btn_entry = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
59 clear_btn_entry.get_style_context ().add_class ("flat");42 clear_btn_entry.get_style_context ().add_class ("flat");
60 clear_btn_entry.clicked.connect (() => {43 clear_btn_entry.clicked.connect (() => {
61 destroy_entry ();44 clear ();
62 });45 });
6346
64 string icon = "";47 string icon = "";
@@ -74,33 +57,32 @@
74 hbox.pack_start (label, false, false, 0);57 hbox.pack_start (label, false, false, 0);
75 hbox.pack_end (clear_btn_entry, false, false, 0);58 hbox.pack_end (clear_btn_entry, false, false, 0);
7659
77 connect_entry (entry);
78
79 add (hbox);60 add (hbox);
80 show_all ();61 show_all ();
81 }62 }
8263
83 private void connect_entry (NotificationEntry entry) {64 public Wnck.Window? get_app_window () {
84 entry.clear.connect (() => {65 if (app_notifications.length () == 0) {
85 if (entry != null) {66 return null;
86 remove_notification_entry (entry);67 }
87 }
88 });
89 }
9068
91 public unowned List<NotificationEntry> get_notifications () {69 var entry = app_notifications.first ().data;
92 return app_notifications;70 return entry.notification.get_app_window ();
93 }71 }
9472
95 public void add_notification_entry (NotificationEntry entry) {73 public void add_notification_entry (NotificationEntry entry) {
96 app_notifications.prepend (entry);74 app_notifications.prepend (entry);
97 connect_entry (entry);75 entry.clear.connect (remove_notification_entry);
98 }76 }
9977
100 public void remove_notification_entry (NotificationEntry entry) {78 public async void remove_notification_entry (NotificationEntry entry) {
101 app_notifications.remove (entry);79 app_notifications.remove (entry);
80 entry.active = false;
81 entry.destroy ();
82
83 Session.get_instance ().remove_notification (entry.notification);
102 if (app_notifications.length () == 0) {84 if (app_notifications.length () == 0) {
103 destroy_entry ();85 clear ();
104 }86 }
105 }87 }
106}88}
10789
=== modified file 'src/Widgets/NotificationEntry.vala'
--- src/Widgets/NotificationEntry.vala 2016-05-27 15:10:53 +0000
+++ src/Widgets/NotificationEntry.vala 2016-07-21 12:53:02 +0000
@@ -54,14 +54,7 @@
54 });54 });
5555
56 hexpand = true;56 hexpand = true;
57 add_widgets ();57
58
59 if (notification.data_session) {
60 notification.time_changed (notification.timestamp.difference (new DateTime.now_local ()));
61 }
62 }
63
64 private void add_widgets () {
65 var grid = new Gtk.Grid ();58 var grid = new Gtk.Grid ();
66 grid.margin_start = 40;59 grid.margin_start = 40;
67 grid.margin_end = 6;60 grid.margin_end = 6;
@@ -92,6 +85,10 @@
9285
93 add (grid);86 add (grid);
94 show_all ();87 show_all ();
88
89 if (notification.data_session) {
90 notification.time_changed (notification.timestamp.difference (new DateTime.now_local ()));
91 }
95 }92 }
9693
97 /**94 /**
9895
=== modified file 'src/Widgets/NotificationsList.vala'
--- src/Widgets/NotificationsList.vala 2016-07-17 18:46:38 +0000
+++ src/Widgets/NotificationsList.vala 2016-07-21 12:53:02 +0000
@@ -18,13 +18,11 @@
18public class NotificationsList : Gtk.ListBox {18public class NotificationsList : Gtk.ListBox {
19 public signal void switch_stack (bool show_list);19 public signal void switch_stack (bool show_list);
20 public signal void close_popover ();20 public signal void close_popover ();
21
21 private List<AppEntry> app_entries;22 private List<AppEntry> app_entries;
22 private List<NotificationEntry> items;
23 private HashTable<string, int> table;23 private HashTable<string, int> table;
24 private int counter = 0;24 private int counter = 0;
2525
26 private static Wnck.Screen screen;
27
28 public NotificationsList () {26 public NotificationsList () {
29 margin_top = 2;27 margin_top = 2;
3028
@@ -32,57 +30,41 @@
32 selection_mode = Gtk.SelectionMode.NONE;30 selection_mode = Gtk.SelectionMode.NONE;
33 row_activated.connect (on_row_activated);31 row_activated.connect (on_row_activated);
3432
35 items = new List<NotificationEntry> ();
36 app_entries = new List<AppEntry> ();33 app_entries = new List<AppEntry> ();
37 table = new HashTable<string, int> (str_hash, str_equal);34 table = new HashTable<string, int> (str_hash, str_equal);
3835
39 screen = Wnck.Screen.get_default ();
40
41 vexpand = true;36 vexpand = true;
42 show_all ();37 show_all ();
38
39 monitor_active_window ();
43 }40 }
4441
45 public void add_item (NotificationEntry entry) {42 public void add_entry (NotificationEntry entry) {
46 var app_entry = add_app_entry (entry);43 var app_entry = add_entry_internal (entry);
44 if (app_entry == null) {
45 return;
46 }
4747
48 items.prepend (entry);
49 switch_stack (true);48 switch_stack (true);
5049
51 app_entry.add_notification_entry (entry);50 app_entry.clear.connect (clear_app_entry);
52 resort_from_app_entry (app_entry);51
5352 counter += 2;
54 entry.clear.connect (() => {
55 destroy_notification_entry (entry);
56 });
57
58 app_entry.destroy_entry.connect (() => {
59 destroy_app_entry (app_entry);
60 });
61
62 counter = counter + 2;
6353
64 Session.get_instance ().add_notification (entry.notification);54 Session.get_instance ().add_notification (entry.notification);
65 entry.show_all ();
6655
67 update_separators ();56 update_separators ();
68 show_all ();57 show_all ();
69 }58 }
7059
7160
72 public uint get_items_length () {61 public uint get_entries_length () {
73 return items.length ();62 return app_entries.length ();
74 }63 }
7564
76 public void clear_all () {65 public void clear_all () {
77 items.@foreach ((item) => {66 app_entries.foreach ((app_entry) => {
78 items.remove (item);67 app_entry.clear ();
79 remove (item);
80 item.active = false;
81 });
82
83 app_entries.@foreach ((entry) => {
84 app_entries.remove (entry);
85 remove (entry);
86 });68 });
8769
88 counter = 0;70 counter = 0;
@@ -93,6 +75,17 @@
93 show_all ();75 show_all ();
94 }76 }
9577
78 private void resort_app_entry (AppEntry app_entry) {
79 if (get_row_at_index (0) != app_entry) {
80 remove (app_entry);
81 prepend (app_entry);
82 app_entry.app_notifications.foreach ((notification_entry) => {
83 remove (notification_entry);
84 insert (notification_entry, 1);
85 });
86 }
87 }
88
96 private void update_separators () {89 private void update_separators () {
97 if (get_children ().length () > 0) {90 if (get_children ().length () > 0) {
98 foreach (var child in get_children ()) {91 foreach (var child in get_children ()) {
@@ -112,27 +105,24 @@
112 show_all ();105 show_all ();
113 }106 }
114107
115 private AppEntry add_app_entry (NotificationEntry entry) {108 private AppEntry? add_entry_internal (NotificationEntry entry) {
116 AppEntry app_entry;109 AppEntry? app_entry = null;
117 bool add = !(entry.notification.desktop_id in construct_desktop_id_list ());110 bool add = !(entry.notification.desktop_id in construct_desktop_id_list ());
118 if (add) {111 if (add) {
119 var window = get_window_from_entry (entry);112 app_entry = new AppEntry (entry);
120 app_entry = new AppEntry (entry, window);
121
122 screen.active_window_changed.connect (() => {
123 if (screen.get_active_window () == app_entry.app_window) {
124 app_entry.clear_btn_entry.clicked ();
125 }
126 });
127113
128 app_entries.append (app_entry);114 app_entries.append (app_entry);
129 prepend (app_entry);115 prepend (app_entry);
130 insert (entry, 1);116 insert (entry, 1);
131 table.insert (app_entry.desktop_id, 0);117 table.insert (app_entry.app_info.get_id (), 0);
132 } else {118 } else {
133 app_entry = get_app_entry_from_desktop_id (entry.notification.desktop_id);119 app_entry = get_app_entry_from_desktop_id (entry.notification.desktop_id);
120
134 if (app_entry != null) {121 if (app_entry != null) {
135 int insert_pos = table.@get (app_entry.desktop_id);122 resort_app_entry (app_entry);
123 app_entry.add_notification_entry (entry);
124
125 int insert_pos = table.get (app_entry.app_info.get_id ());
136 insert (entry, insert_pos + 1); 126 insert (entry, insert_pos + 1);
137 }127 }
138 }128 }
@@ -140,118 +130,94 @@
140 return app_entry;130 return app_entry;
141 }131 }
142132
143 private Wnck.Window? get_window_from_entry (NotificationEntry entry) {133 private void monitor_active_window () {
144 Wnck.Window? window = null;134 var screen = Wnck.Screen.get_default ();
145 screen.get_windows ().@foreach ((_window) => {135 screen.active_window_changed.connect (() => {
146 if (_window.get_pid () == entry.notification.pid) {136 app_entries.foreach ((app_entry) => {
147 window = _window;137 if (screen.get_active_window () == app_entry.get_app_window ()) {
148 return;138 app_entry.clear ();
149 }139 }
140 });
150 });141 });
151142 }
152 return window;143
153 }144 private void clear_app_entry (AppEntry app_entry) {
154
155 private async void destroy_notification_entry (NotificationEntry entry) {
156 entry.destroy ();
157 items.remove (entry);
158 entry.active = false;
159
160 Session.get_instance ().remove_notification (entry.notification);
161 if (items.length () == 0) {
162 clear_all ();
163 }
164 }
165
166 private void destroy_app_entry (AppEntry app_entry) {
167 app_entries.remove (app_entry);145 app_entries.remove (app_entry);
168146
169 app_entry.get_notifications ().@foreach ((notification_entry) => {147 app_entry.app_notifications.foreach ((notification_entry) => {
170 notification_entry.destroy ();148 app_entry.remove_notification_entry.begin (notification_entry);
171 items.remove (notification_entry);149 });
172 });150
173151 app_entry.destroy ();
174 Idle.add (() => {152 update_separators ();
175 if (app_entry != null) {153
176 app_entry.destroy ();154 if (get_entries_length () == 0) {
177 }
178
179 return false;
180 });
181
182 if (items.length () == 0) {
183 clear_all ();155 clear_all ();
184 }156 }
185
186 update_separators ();
187 }
188
189 private void resort_from_app_entry (AppEntry app_entry) {
190 if (get_row_at_index (0) != app_entry) {
191 remove (app_entry);
192 prepend (app_entry);
193 int counter = 1;
194 app_entry.get_notifications ().@foreach ((notification_entry) => {
195 remove (notification_entry);
196 add_item (notification_entry);
197 counter++;
198 });
199 }
200 }157 }
201158
202 private AppEntry? get_app_entry_from_desktop_id (string desktop_id) {159 private AppEntry? get_app_entry_from_desktop_id (string desktop_id) {
203 AppEntry? entry = null;160 AppEntry? app_entry = null;
204 app_entries.@foreach ((_entry) => {161 app_entries.foreach ((_app_entry) => {
205 if (_entry.desktop_id == desktop_id) {162 if (_app_entry.app_info.get_id () == desktop_id && app_entry == null) {
206 entry = _entry;163 app_entry = _app_entry;
207 return;
208 }164 }
209 });165 });
210166
211 return entry;167 return app_entry;
212 }168 }
213169
214 private string[] construct_desktop_id_list () {170 private string[] construct_desktop_id_list () {
215 string[] desktop_id_list = {};171 string[] desktop_id_list = {};
216 app_entries.@foreach ((entry) => {172 app_entries.foreach ((app_entry) => {
217 desktop_id_list += entry.desktop_id;173 desktop_id_list += app_entry.app_info.get_id ();
218 });174 });
219175
220 return desktop_id_list;176 return desktop_id_list;
221 }177 }
222178
223 private void on_row_activated (Gtk.ListBoxRow row) {179 private void on_row_activated (Gtk.ListBoxRow row) {
224 if (row.get_path ().get_object_type () == typeof (AppEntry)) {180 bool close = true;
225 if (((AppEntry) row).app_window == null) {181
226 var window = get_window_from_entry (((AppEntry) row).get_notifications ().nth_data (0));182 if (row is AppEntry) {
227 if (window != null) {183 var app_entry = (AppEntry)row;
228 ((AppEntry) row).app_window = window;184 close = focus_notification_app (app_entry.get_app_window (),
229 }185 app_entry.app_info);
230 }186
231187 app_entry.clear ();
232 if (((AppEntry) row).app_window != null) {188 } else if (row is NotificationEntry) {
233 ((AppEntry) row).app_window.unminimize (Gtk.get_current_event_time ());189 var notification_entry = (NotificationEntry)row;
234 ((AppEntry) row).clear_btn_entry.clicked ();190
235 close_popover ();191 if (!notification_entry.notification.run_default_action ()) {
236 } else if (((AppEntry) row).app_info != null) {192 close = focus_notification_app (notification_entry.notification.get_app_window (),
237 try {193 notification_entry.notification.app_info);
238 ((AppEntry) row).app_info.launch (null, null);194 }
239 } catch (Error e) {195
240 error ("%s\n", e.message);196 notification_entry.clear ();
241 }
242
243 ((AppEntry) row).clear_btn_entry.clicked ();
244 close_popover ();
245 }
246 } else {197 } else {
247 if (((NotificationEntry) row).notification.run_default_action ()) {198 close = false;
248 ((NotificationEntry) row).active = false;199 }
249 close_popover ();
250 }
251200
252 ((NotificationEntry) row).clear ();201 if (close) {
202 close_popover ();
253 }203 }
254204
255 update_separators ();205 update_separators ();
256 }206 }
207
208 private bool focus_notification_app (Wnck.Window? app_window, AppInfo? app_info) {
209 if (app_window != null) {
210 app_window.unminimize (Gtk.get_current_event_time ());
211 return true;
212 } else if (app_info != null) {
213 try {
214 app_info.launch (null, null);
215 return true;
216 } catch (Error e) {
217 warning ("%s\n", e.message);
218 }
219 }
220
221 return false;
222 }
257}223}

Subscribers

People subscribed via source and target branches

to all changes: