Merge lp:~mhr3/unity-lens-applications/exclude-running-apps into lp:unity-lens-applications

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 258
Merged at revision: 258
Proposed branch: lp:~mhr3/unity-lens-applications/exclude-running-apps
Merge into: lp:unity-lens-applications
Diff against target: 207 lines (+158/-2)
3 files modified
src/Makefile.am (+1/-0)
src/app-watcher.vala (+141/-0)
src/daemon.vala (+16/-2)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/exclude-running-apps
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+89082@code.launchpad.net

Description of the change

Exclude running applications (not just favourites) from the Recent list. Also; set the "no-results-hint" hint when we have zero results.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks perfect! Holding on branch approval until we land the bamf requirements

review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

The bamf branch is in!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-10-06 11:53:27 +0000
3+++ src/Makefile.am 2012-01-18 17:10:28 +0000
4@@ -51,6 +51,7 @@
5 $(NULL)
6
7 unity_applications_daemon_VALASOURCES = \
8+ app-watcher.vala \
9 config.vala \
10 daemon.vala \
11 main.vala \
12
13=== added file 'src/app-watcher.vala'
14--- src/app-watcher.vala 1970-01-01 00:00:00 +0000
15+++ src/app-watcher.vala 2012-01-18 17:10:28 +0000
16@@ -0,0 +1,141 @@
17+/*
18+ * Copyright (C) 2012 Canonical Ltd
19+ *
20+ * This program is free software: you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License version 3 as
22+ * published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by Michal Hruby <michal.hruby@canonical.com>
33+ *
34+ */
35+
36+using Unity;
37+using Gee;
38+
39+namespace Unity.ApplicationsLens
40+{
41+
42+ public class AppWatcher : Object
43+ {
44+ private string[] prefixes;
45+ Gee.Set<string> running_apps;
46+
47+ public AppWatcher ()
48+ {
49+ Object ();
50+ }
51+
52+ public bool has_app_id (string desktop_id)
53+ {
54+ return desktop_id in running_apps;
55+ }
56+
57+ public signal void running_applications_changed ();
58+
59+ construct
60+ {
61+ running_apps = new HashSet<string> ();
62+ foreach (unowned string data_dir in Environment.get_system_data_dirs ())
63+ {
64+ prefixes += Path.build_path (Path.DIR_SEPARATOR_S,
65+ data_dir,
66+ "applications",
67+ Path.DIR_SEPARATOR_S, null);
68+ }
69+
70+ var connection = Bus.get_sync (BusType.SESSION);
71+ connection.signal_subscribe ("org.ayatana.bamf",
72+ "org.ayatana.bamf.matcher",
73+ "RunningApplicationsChanged",
74+ "/org/ayatana/bamf/matcher",
75+ null,
76+ DBusSignalFlags.NONE,
77+ this.running_apps_changed);
78+ connection.call.begin ("org.ayatana.bamf",
79+ "/org/ayatana/bamf/matcher",
80+ "org.ayatana.bamf.matcher",
81+ "RunningApplicationsDesktopFiles",
82+ null,
83+ null,
84+ 0,
85+ -1,
86+ null,
87+ this.got_running_apps);
88+ }
89+
90+ private void got_running_apps (Object? src_obj,
91+ AsyncResult res)
92+ {
93+ var connection = src_obj as DBusConnection;
94+ try
95+ {
96+ Variant reply = connection.call.end (res);
97+ string[] paths = (string[]) reply.get_child_value (0);
98+
99+ foreach (var p in paths) running_apps.add (extract_desktop_id (p));
100+ this.running_applications_changed ();
101+ }
102+ catch (Error e)
103+ {
104+ warning ("%s", e.message);
105+ }
106+ }
107+
108+ private void running_apps_changed (DBusConnection connection,
109+ string sender_name,
110+ string object_path,
111+ string interface_name,
112+ string signal_name,
113+ Variant parameters)
114+ {
115+ if (!parameters.is_of_type (new VariantType ("(asas)")))
116+ {
117+ warning ("RunningApplicationsChanged signal has incorrect type!");
118+ return;
119+ }
120+
121+ Variant opened_apps_variant;
122+ Variant closed_apps_variant;
123+ parameters.get ("(@as@as)", out opened_apps_variant,
124+ out closed_apps_variant);
125+ string[] opened_paths = (string[]) opened_apps_variant;
126+ string[] closed_paths = (string[]) closed_apps_variant;
127+
128+ foreach (unowned string closed in closed_paths)
129+ running_apps.remove (extract_desktop_id (closed));
130+ foreach (unowned string opened in opened_paths)
131+ running_apps.add (extract_desktop_id (opened));
132+
133+ this.running_applications_changed ();
134+ }
135+
136+ private string extract_desktop_id (string path)
137+ {
138+ if (!path.has_prefix ("/")) return path;
139+
140+ /* fdo menu-spec compliant desktop id extraction */
141+ foreach (unowned string prefix in prefixes)
142+ {
143+ if (path.has_prefix (prefix))
144+ {
145+ string without_prefix = path.substring (prefix.length);
146+ if (Path.DIR_SEPARATOR_S in without_prefix)
147+ return without_prefix.replace (Path.DIR_SEPARATOR_S, "-");
148+
149+ return without_prefix;
150+ }
151+ }
152+
153+ return Path.get_basename (path);
154+ }
155+ }
156+
157+}
158
159=== modified file 'src/daemon.vala'
160--- src/daemon.vala 2012-01-16 09:38:11 +0000
161+++ src/daemon.vala 2012-01-18 17:10:28 +0000
162@@ -61,7 +61,8 @@
163 /* Monitor the favorite apps in the launcher, so we can filter them
164 * out of the results for Recent Apps */
165 private Unity.LauncherFavorites favorite_apps;
166-
167+ private AppWatcher app_watcher;
168+
169 private PtrArray zg_templates;
170
171 /* Gnome menu structure - also used to check whether apps are installed */
172@@ -176,6 +177,12 @@
173 }
174
175 favorite_apps = Unity.LauncherFavorites.get_default ();
176+ app_watcher = new AppWatcher ();
177+ app_watcher.running_applications_changed.connect (() =>
178+ {
179+ scope.queue_search_changed (SearchType.GLOBAL);
180+ scope.queue_search_changed (SearchType.DEFAULT);
181+ });
182
183 lens = new Unity.Lens ("/com/canonical/unity/lens/applications", "applications");
184 lens.search_hint = _("Search Applications");
185@@ -473,6 +480,12 @@
186 }
187 }
188
189+ if (model.get_n_rows () == 0)
190+ {
191+ search.set_reply_hint ("no-results-hint",
192+ _("Sorry, there are no applications that match your search."));
193+ }
194+
195 search.finished ();
196 }
197
198@@ -822,7 +835,8 @@
199 /* Discard Recently Used apps that are in the launcher */
200 if (category_id == Category.RECENT &&
201 !include_favorites &&
202- favorite_apps.has_app_id (desktop_id))
203+ (favorite_apps.has_app_id (desktop_id)
204+ || app_watcher.has_app_id (desktop_id)))
205 continue;
206
207 var appmanager = AppInfoManager.get_default ();

Subscribers

People subscribed via source and target branches