Merge lp:~stolowski/unity/hide-dash-dbus-iface into lp:unity

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: no longer in the source branch.
Merged at revision: 2678
Proposed branch: lp:~stolowski/unity/hide-dash-dbus-iface
Merge into: lp:unity
Diff against target: 197 lines (+98/-1)
4 files modified
dash/DashController.cpp (+70/-0)
dash/DashController.h (+10/-0)
tests/autopilot/unity/emulators/dash.py (+9/-1)
tests/autopilot/unity/tests/test_dash.py (+9/-0)
To merge this branch: bzr merge lp:~stolowski/unity/hide-dash-dbus-iface
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+123271@code.launchpad.net

Commit message

Implemented DBus interface for DashController and made HideDash() method available via DBus. Added autopilot test for it.
This is needed by music-preview-player codec installation functionality for hiding the dash when codec installation starts.

Description of the change

Implemented DBus interface for DashController and made HideDash() method available via DBus. Added autopilot test for it.
This is needed by music-preview-player codec installation functionality for hiding the dash when codec installation starts.

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

9 +const std::string DBUS_NAME = "com.canonical.Unity.Dash";
148 + dash_object = session_bus.get_object('com.canonical.Unity.Dash',

I don't think we need to request yet another name for the dash, "com.canonical.Unity" (which is already used elsewhere in the code) is good enough.

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

40 + g_bus_get (G_BUS_TYPE_SESSION, nullptr, OnBusAcquired, this);

To be safe we should use a cancellable here and cancel the call in destructor.

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

Looking good now. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dash/DashController.cpp'
2--- dash/DashController.cpp 2012-09-11 01:44:39 +0000
3+++ dash/DashController.cpp 2012-09-11 10:51:20 +0000
4@@ -20,6 +20,7 @@
5
6 #include <NuxCore/Logger.h>
7 #include <Nux/HLayout.h>
8+#include <UnityCore/GLibWrapper.h>
9
10 #include "unity-shared/UnitySettings.h"
11 #include "unity-shared/PanelStyle.h"
12@@ -38,8 +39,22 @@
13 {
14 nux::logging::Logger logger("unity.dash.controller");
15 const unsigned int PRELOAD_TIMEOUT_LENGTH = 40;
16+
17+const std::string DBUS_PATH = "/com/canonical/Unity/Dash";
18+const std::string DBUS_INTROSPECTION =\
19+ "<node>"
20+ " <interface name='com.canonical.Unity.Dash'>"
21+ ""
22+ " <method name='HideDash'>"
23+ " </method>"
24+ ""
25+ " </interface>"
26+ "</node>";
27 }
28
29+GDBusInterfaceVTable Controller::interface_vtable =
30+ { Controller::OnDBusMethodCall, NULL, NULL};
31+
32 Controller::Controller()
33 : launcher_width(64)
34 , use_primary(false)
35@@ -49,6 +64,7 @@
36 , view_(nullptr)
37 , ensure_timeout_(PRELOAD_TIMEOUT_LENGTH)
38 , timeline_animator_(90)
39+ , dbus_connect_cancellable_(g_cancellable_new())
40 {
41 SetupRelayoutCallbacks();
42 RegisterUBusInterests();
43@@ -70,6 +86,13 @@
44
45 auto spread_cb = sigc::bind(sigc::mem_fun(this, &Controller::HideDash), true);
46 PluginAdapter::Default()->initiate_spread.connect(spread_cb);
47+
48+ g_bus_get (G_BUS_TYPE_SESSION, dbus_connect_cancellable_, OnBusAcquired, this);
49+}
50+
51+Controller::~Controller()
52+{
53+ g_cancellable_cancel(dbus_connect_cancellable_);
54 }
55
56 void Controller::SetupWindow()
57@@ -377,6 +400,53 @@
58 .add("monitor", monitor_);
59 }
60
61+void Controller::OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data)
62+{
63+ glib::Error error;
64+ glib::Object<GDBusConnection> connection(g_bus_get_finish (result, &error));
65+
66+ if (!connection || error)
67+ {
68+ LOG_WARNING(logger) << "Failed to connect to DBus:" << error;
69+ }
70+ else
71+ {
72+ GDBusNodeInfo* introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTROSPECTION.c_str(), nullptr);
73+ unsigned int reg_id;
74+
75+ if (!introspection_data)
76+ {
77+ LOG_WARNING(logger) << "No introspection data loaded.";
78+ return;
79+ }
80+
81+ reg_id = g_dbus_connection_register_object(connection, DBUS_PATH.c_str(),
82+ introspection_data->interfaces[0],
83+ &interface_vtable, user_data,
84+ nullptr, nullptr);
85+ if (!reg_id)
86+ {
87+ LOG_WARNING(logger) << "Object registration failed. Dash DBus interface not available.";
88+ }
89+
90+ g_dbus_node_info_unref(introspection_data);
91+ }
92+}
93+
94+void Controller::OnDBusMethodCall(GDBusConnection* connection, const gchar* sender,
95+ const gchar* object_path, const gchar* interface_name,
96+ const gchar* method_name, GVariant* parameters,
97+ GDBusMethodInvocation* invocation, gpointer user_data)
98+{
99+ if (g_strcmp0(method_name, "HideDash") == 0)
100+ {
101+ auto self = static_cast<Controller*>(user_data);
102+ self->HideDash();
103+ g_dbus_method_invocation_return_value(invocation, nullptr);
104+ }
105+}
106+
107+
108
109 }
110 }
111
112=== modified file 'dash/DashController.h'
113--- dash/DashController.h 2012-08-25 03:17:58 +0000
114+++ dash/DashController.h 2012-09-11 10:51:20 +0000
115@@ -45,6 +45,7 @@
116 typedef std::shared_ptr<Controller> Ptr;
117
118 Controller();
119+ ~Controller();
120
121 nux::BaseWindow* window() const;
122
123@@ -84,6 +85,12 @@
124 void StartShowHideTimeline();
125 void OnViewShowHideFrame(double progress);
126
127+ static void OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data);
128+ static void OnDBusMethodCall(GDBusConnection* connection, const gchar* sender,
129+ const gchar* object_path, const gchar* interface_name,
130+ const gchar* method_name, GVariant* parameters,
131+ GDBusMethodInvocation* invocation, gpointer user_data);
132+
133 static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data);
134
135 private:
136@@ -100,6 +107,9 @@
137 glib::SourceManager sources_;
138 Animator timeline_animator_;
139 UBusManager ubus_manager_;
140+ unsigned int dbus_owner_;
141+ glib::Object<GCancellable> dbus_connect_cancellable_;
142+ static GDBusInterfaceVTable interface_vtable;
143 };
144
145
146
147=== modified file 'tests/autopilot/unity/emulators/dash.py'
148--- tests/autopilot/unity/emulators/dash.py 2012-09-06 04:25:16 +0000
149+++ tests/autopilot/unity/emulators/dash.py 2012-09-11 10:51:20 +0000
150@@ -9,6 +9,7 @@
151
152 from __future__ import absolute_import
153
154+from autopilot.emulators.dbus_handler import session_bus
155 from autopilot.emulators.X11 import Keyboard, Mouse
156 from autopilot.keybindings import KeybindingsHelper
157 from testtools.matchers import GreaterThan
158@@ -16,7 +17,7 @@
159 from unity.emulators import UnityIntrospectionObject
160 import logging
161 from time import sleep
162-
163+import dbus
164
165 logger = logging.getLogger(__name__)
166
167@@ -162,6 +163,13 @@
168 """Get the dash view that's attached to this controller."""
169 return self.get_children_by_type(DashView)[0]
170
171+ def hide_dash_via_dbus(self):
172+ """ Emulate a DBus call for dash hiding """
173+ dash_object = session_bus.get_object('com.canonical.Unity',
174+ '/com/canonical/Unity/Dash')
175+ dash_iface = dbus.Interface(dash_object, 'com.canonical.Unity.Dash')
176+ dash_iface.HideDash()
177+
178
179 class DashView(UnityIntrospectionObject):
180 """The dash view."""
181
182=== modified file 'tests/autopilot/unity/tests/test_dash.py'
183--- tests/autopilot/unity/tests/test_dash.py 2012-09-06 04:25:16 +0000
184+++ tests/autopilot/unity/tests/test_dash.py 2012-09-11 10:51:20 +0000
185@@ -847,3 +847,12 @@
186
187 self.assertThat(self.dash.preview_displaying, Eventually(Equals(False)))
188
189+class DashDBusIfaceTests(DashTestCase):
190+ """Test the Unity dash DBus interface."""
191+
192+ def test_dash_hide(self):
193+ """Ensure we can hide the dash via HideDash() dbus method."""
194+ self.dash.ensure_visible()
195+ self.dash.controller.hide_dash_via_dbus()
196+ self.assertThat(self.dash.visible, Eventually(Equals(False)))
197+ self.dash.ensure_hidden()