diff options
| author | Pawel Stolowski <pawel.stolowski@canonical.com> | 2012-09-11 08:01:20 -0400 |
|---|---|---|
| committer | Tarmac <> | 2012-09-11 08:01:20 -0400 |
| commit | 0502fb641b9d36bd41b3eed09eccbbb9593ba7f3 (patch) | |
| tree | 14ed92cf16492a7df073f7d7c46960d04c6960fb /dash | |
| parent | 06cd7e75b1550e415f33e3553366da0f2e607567 (diff) | |
| parent | 5563207ce3d6bf782708daecf0c1c36b8273324a (diff) | |
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.. Fixes: https://bugs.launchpad.net/bugs/1043825. Approved by Michal Hruby. (bzr r2678)
Diffstat (limited to 'dash')
| -rw-r--r-- | dash/DashController.cpp | 70 | ||||
| -rw-r--r-- | dash/DashController.h | 10 |
2 files changed, 80 insertions, 0 deletions
diff --git a/dash/DashController.cpp b/dash/DashController.cpp index 8593d7a20..a419bb7f6 100644 --- a/dash/DashController.cpp +++ b/dash/DashController.cpp @@ -20,6 +20,7 @@ #include <NuxCore/Logger.h> #include <Nux/HLayout.h> +#include <UnityCore/GLibWrapper.h> #include "unity-shared/UnitySettings.h" #include "unity-shared/PanelStyle.h" @@ -38,8 +39,22 @@ namespace { nux::logging::Logger logger("unity.dash.controller"); const unsigned int PRELOAD_TIMEOUT_LENGTH = 40; + +const std::string DBUS_PATH = "/com/canonical/Unity/Dash"; +const std::string DBUS_INTROSPECTION =\ + "<node>" + " <interface name='com.canonical.Unity.Dash'>" + "" + " <method name='HideDash'>" + " </method>" + "" + " </interface>" + "</node>"; } +GDBusInterfaceVTable Controller::interface_vtable = + { Controller::OnDBusMethodCall, NULL, NULL}; + Controller::Controller() : launcher_width(64) , use_primary(false) @@ -49,6 +64,7 @@ Controller::Controller() , view_(nullptr) , ensure_timeout_(PRELOAD_TIMEOUT_LENGTH) , timeline_animator_(90) + , dbus_connect_cancellable_(g_cancellable_new()) { SetupRelayoutCallbacks(); RegisterUBusInterests(); @@ -70,6 +86,13 @@ Controller::Controller() auto spread_cb = sigc::bind(sigc::mem_fun(this, &Controller::HideDash), true); PluginAdapter::Default()->initiate_spread.connect(spread_cb); + + g_bus_get (G_BUS_TYPE_SESSION, dbus_connect_cancellable_, OnBusAcquired, this); +} + +Controller::~Controller() +{ + g_cancellable_cancel(dbus_connect_cancellable_); } void Controller::SetupWindow() @@ -377,6 +400,53 @@ void Controller::AddProperties(GVariantBuilder* builder) .add("monitor", monitor_); } +void Controller::OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data) +{ + glib::Error error; + glib::Object<GDBusConnection> connection(g_bus_get_finish (result, &error)); + + if (!connection || error) + { + LOG_WARNING(logger) << "Failed to connect to DBus:" << error; + } + else + { + GDBusNodeInfo* introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTROSPECTION.c_str(), nullptr); + unsigned int reg_id; + + if (!introspection_data) + { + LOG_WARNING(logger) << "No introspection data loaded."; + return; + } + + reg_id = g_dbus_connection_register_object(connection, DBUS_PATH.c_str(), + introspection_data->interfaces[0], + &interface_vtable, user_data, + nullptr, nullptr); + if (!reg_id) + { + LOG_WARNING(logger) << "Object registration failed. Dash DBus interface not available."; + } + + g_dbus_node_info_unref(introspection_data); + } +} + +void Controller::OnDBusMethodCall(GDBusConnection* connection, const gchar* sender, + const gchar* object_path, const gchar* interface_name, + const gchar* method_name, GVariant* parameters, + GDBusMethodInvocation* invocation, gpointer user_data) +{ + if (g_strcmp0(method_name, "HideDash") == 0) + { + auto self = static_cast<Controller*>(user_data); + self->HideDash(); + g_dbus_method_invocation_return_value(invocation, nullptr); + } +} + + } } diff --git a/dash/DashController.h b/dash/DashController.h index a03745782..e3e210c1a 100644 --- a/dash/DashController.h +++ b/dash/DashController.h @@ -45,6 +45,7 @@ public: typedef std::shared_ptr<Controller> Ptr; Controller(); + ~Controller(); nux::BaseWindow* window() const; @@ -84,6 +85,12 @@ private: void StartShowHideTimeline(); void OnViewShowHideFrame(double progress); + static void OnBusAcquired(GObject *obj, GAsyncResult *result, gpointer user_data); + static void OnDBusMethodCall(GDBusConnection* connection, const gchar* sender, + const gchar* object_path, const gchar* interface_name, + const gchar* method_name, GVariant* parameters, + GDBusMethodInvocation* invocation, gpointer user_data); + static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data); private: @@ -100,6 +107,9 @@ private: glib::SourceManager sources_; Animator timeline_animator_; UBusManager ubus_manager_; + unsigned int dbus_owner_; + glib::Object<GCancellable> dbus_connect_cancellable_; + static GDBusInterfaceVTable interface_vtable; }; |
