Merge lp:~azzar1/libunity/fix-1506744 into lp:libunity

Proposed by Andrea Azzarone on 2016-05-16
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2016-05-16
Approved revision: 324
Merged at revision: 323
Proposed branch: lp:~azzar1/libunity/fix-1506744
Merge into: lp:libunity
Diff against target: 84 lines (+37/-17)
1 file modified
src/unity-appinfo-manager.vala (+37/-17)
To merge this branch: bzr merge lp:~azzar1/libunity/fix-1506744
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing on 2016-05-16
Marco Trevisan (Treviño) 2016-05-16 Approve on 2016-05-16
Review via email: mp+294855@code.launchpad.net

Commit message

Process GFileMonitors signals with a small timeout.

Description of the change

Process GFileMonitors signals with a small timeout. Please note that https://bugs.launchpad.net/ubuntu/+source/libunity/+bug/1506744/comments/42 is also required.

To post a comment you must log in.
Marco Trevisan (Treviño) (3v1n0) wrote :

Good one, thanks

review: Approve
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-appinfo-manager.vala'
2--- src/unity-appinfo-manager.vala 2014-02-03 17:22:39 +0000
3+++ src/unity-appinfo-manager.vala 2016-05-16 23:13:54 +0000
4@@ -62,13 +62,15 @@
5 private HashTable<string, StringArrayWrapper> categories_by_id; /* desktop id or path -> xdg cats */
6 private HashTable<string, StringArrayWrapper> keywords_by_id; /* desktop id or path -> X-GNOME-Keywords and X-AppInstall-Keywords */
7 private HashTable<string,string?> paths_by_id; /* desktop id -> full path to desktop file */
8-
9+ private List<uint> timeout_handlers;
10+
11 private AppInfoManager ()
12 {
13 appinfo_by_id = new HashTable<string,AppInfo?> (str_hash, str_equal);
14 categories_by_id = new HashTable<string,StringArrayWrapper> (str_hash, str_equal);
15 keywords_by_id = new HashTable<string,StringArrayWrapper> (str_hash, str_equal);
16 paths_by_id = new HashTable<string,string?> (str_hash, str_equal);
17+ timeout_handlers = new List<uint> ();
18
19 monitors = new HashTable<string,FileMonitor> (str_hash, str_equal);
20
21@@ -86,7 +88,15 @@
22 }
23 }
24 }
25-
26+
27+ ~AppInfoManager ()
28+ {
29+ timeout_handlers.foreach ((id) =>
30+ {
31+ Source.remove (id);
32+ });
33+ }
34+
35 [Deprecated (replacement = "AppInfoManager.get_default")]
36 public static AppInfoManager get_instance ()
37 {
38@@ -114,21 +124,31 @@
39 * we remove it from the cache */
40 private void on_dir_changed (FileMonitor mon, File file, File? other_file, FileMonitorEvent e)
41 {
42- var desktop_id = file.get_basename ();
43- var path = file.get_path ();
44- AppInfo? appinfo;
45-
46- if (appinfo_by_id.remove (desktop_id))
47- {
48- appinfo = lookup (desktop_id);
49- changed (desktop_id, appinfo);
50- }
51-
52- if (appinfo_by_id.remove (path))
53- {
54- appinfo = lookup (path);
55- changed (path, appinfo);
56- }
57+ uint timeout_handler = 0;
58+
59+ timeout_handler = Timeout.add_seconds (2, () =>
60+ {
61+ var desktop_id = file.get_basename ();
62+ var path = file.get_path ();
63+ AppInfo? appinfo;
64+
65+ if (appinfo_by_id.remove (desktop_id))
66+ {
67+ appinfo = lookup (desktop_id);
68+ changed (desktop_id, appinfo);
69+ }
70+
71+ if (appinfo_by_id.remove (path))
72+ {
73+ appinfo = lookup (path);
74+ changed (path, appinfo);
75+ }
76+
77+ timeout_handlers.remove (timeout_handler);
78+ return false;
79+ });
80+
81+ timeout_handlers.append (timeout_handler);
82 }
83
84 /**

Subscribers

People subscribed via source and target branches