Merge lp:~victored/slingshot/app-launcher-dbus into lp:~elementary-pantheon/slingshot/trunk

Proposed by Victor Martinez
Status: Merged
Approved by: Tom Beckmann
Approved revision: 239
Merged at revision: 317
Proposed branch: lp:~victored/slingshot/app-launcher-dbus
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 116 lines (+78/-1)
3 files modified
CMakeLists.txt (+1/-0)
src/Backend/DBusService.vala (+72/-0)
src/Slingshot.vala (+5/-1)
To merge this branch: bzr merge lp:~victored/slingshot/app-launcher-dbus
Reviewer Review Type Date Requested Status
Sergey "Shnatsel" Davidoff (community) Approve
Review via email: mp+114771@code.launchpad.net

Description of the change

Implement org.pantheon.desktop.AppLauncherService DBus service.

Currently, the API only exports the app's current state via a signal. I've based the implementation on the GtkWidget::visible property, emitting a signal whenever it changes. Clients of this service can know the current state of Slingshot by connecting a handler to the visibility_changed() signal. Wingpanel is supposed to be one of those clients. See the related implementation at lp:~victored/wingpanel/app-launcher-dbus

To post a comment you must log in.
238. By Victor Martinez

Connect to "show" and "hide" signals instead of using notify for the "visible" property.

239. By Victor Martinez

Emit initial state as soon as the dbus service name registration succeeds

Revision history for this message
Victor Martinez (victored) wrote :

Hey guys, you've got a pending review here!

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

I like the approach.
Note that it makes it impossible to run several instances of Slingshot; make sure claiming d-bus name is wrapped in try-catch or something, that it doesn't crash if the name is already claimed.

review: Approve
Revision history for this message
Removed by request (removed2115751) wrote :

Built and installed with lp:~victored/wingpanel/app-launcher-dbus, works great so far.

Revision history for this message
Andrea Basso (voluntatefaber) wrote :

I'd like to release Slingshot beta1 tomorrow and I was thinking about merging this later, so that we don't get any unexpected bug. Do you all agree or think this should make it for beta1 despite the risk of new bugs?

Revision history for this message
Victor Martinez (victored) wrote :

That sounds good to me Andrea. I'm pretty sure I've not introduced any major issue though.

Revision history for this message
Andrea Basso (voluntatefaber) wrote :

Victor, I know you probably haven't, but for example, we merged Ricotz's gmenu-3 branch more than a month ago, IIRC, and it all seemed alright. Only yesterday we found out it introduced a severe regression, for this reason I'd like to wait. I'll merge it as soon as Slingshot gets released and I have a bit of spare time (probably from Friday).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-07-13 11:57:20 +0000
3+++ CMakeLists.txt 2012-07-18 17:46:21 +0000
4@@ -42,6 +42,7 @@
5 src/Settings.vala
6 src/Utils.vala
7 src/Backend/AppSystem.vala
8+ src/Backend/DBusService.vala
9 src/Backend/App.vala
10 src/Backend/RelevancyService.vala
11 src/Widgets/AppEntry.vala
12
13=== added file 'src/Backend/DBusService.vala'
14--- src/Backend/DBusService.vala 1970-01-01 00:00:00 +0000
15+++ src/Backend/DBusService.vala 2012-07-18 17:46:21 +0000
16@@ -0,0 +1,72 @@
17+// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
18+//
19+// Copyright (C) 2012 Slingshot Developers
20+//
21+// This program is free software: you can redistribute it and/or modify
22+// it under the terms of the GNU General Public License as published by
23+// the Free Software Foundation, either version 3 of the License, or
24+// (at your option) any later version.
25+//
26+// This program is distributed in the hope that it will be useful,
27+// but WITHOUT ANY WARRANTY; without even the implied warranty of
28+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+// GNU General Public License for more details.
30+//
31+// You should have received a copy of the GNU General Public License
32+// along with this program. If not, see <http://www.gnu.org/licenses/>.
33+
34+
35+namespace Slingshot {
36+
37+ public class DBusService : Object {
38+
39+ [DBus (name = "org.pantheon.desktop.AppLauncherService")]
40+ private class Service : Object {
41+ public signal void visibility_changed (bool launcher_visible);
42+ private Gtk.Widget? view = null;
43+
44+ public Service (Gtk.Widget view) {
45+ this.view = view;
46+ view.show.connect (on_view_visibility_change);
47+ view.hide.connect (on_view_visibility_change);
48+ }
49+
50+ internal void on_view_visibility_change () {
51+ debug ("Visibility changed. Sending visible = %s over DBus", view.visible.to_string ());
52+ this.visibility_changed (view.visible);
53+ }
54+ }
55+
56+ private Service? service = null;
57+
58+ public DBusService (SlingshotView view) {
59+ // Own bus name
60+ // try to register service name in session bus
61+ Bus.own_name (BusType.SESSION,
62+ "org.pantheon.desktop.AppLauncherService",
63+ BusNameOwnerFlags.NONE,
64+ (conn) => { on_bus_aquired (conn, view); },
65+ name_acquired_handler,
66+ () => { critical ("Could not aquire service name"); });
67+
68+ }
69+
70+ private void on_bus_aquired (DBusConnection connection, SlingshotView view) {
71+ try {
72+ // start service and register it as dbus object
73+ service = new Service (view);
74+ connection.register_object ("/org/pantheon/desktop/AppLauncherService", service);
75+ } catch (IOError e) {
76+ critical ("Could not register service: %s", e.message);
77+ return_if_reached ();
78+ }
79+ }
80+
81+ private void name_acquired_handler (DBusConnection connection, string name) {
82+ message ("Service registration suceeded");
83+ return_if_fail (service != null);
84+ // Emit initial state
85+ service.on_view_visibility_change ();
86+ }
87+ }
88+}
89\ No newline at end of file
90
91=== modified file 'src/Slingshot.vala'
92--- src/Slingshot.vala 2012-06-24 10:18:48 +0000
93+++ src/Slingshot.vala 2012-07-18 17:46:21 +0000
94@@ -30,6 +30,7 @@
95 public static Settings settings { get; private set; default = null; }
96 //public static CssProvider style_provider { get; private set; default = null; }
97 public static IconTheme icon_theme { get; set; default = null; }
98+ private DBusService? dbus_service = null;
99
100 construct {
101
102@@ -82,10 +83,13 @@
103 }
104
105 protected override void activate () {
106-
107 if (get_windows () == null) {
108 view = new SlingshotView ();
109 view.set_application (this);
110+
111+ if (dbus_service == null)
112+ dbus_service = new DBusService (view);
113+
114 if (!silent) {
115 //view.move_to_coords (0, 0);
116 view.show_slingshot ();

Subscribers

People subscribed via source and target branches