Tanu Kaskinen pushed to branch master at PulseAudio / paprefs

Commits:
b8246d3f by Jan Tojnar at 2018-08-11T10:21:42Z
Port from dbus-glib to gdbus

dbus-glib has been deprecated in favour of D-Bus library built into
GLib for a while now.

- - - - -
0a5e8a94 by Jan Tojnar at 2018-08-11T10:30:13Z
Remove libdbus dependency

Previously, we used bare libdbus to detect PackageKit presence on start-up.
Since GLib contains its own independent D-Bus library and we are already
using it for invoking PackageKit, we ported the detection to GDBus too.

Because there is not any equivalent of dbus_bus_name_has_owner() in gdbus,
we replaced it with g_bus_watch_name(). As a bonus, the user interface will
be updated when PackageKit daemon starts or stops when the app is running.

- - - - -


3 changed files:

- meson.build
- src/meson.build
- src/paprefs.cc


Changes:

=====================================
meson.build
=====================================
--- a/meson.build
+++ b/meson.build
@@ -14,7 +14,6 @@ i18n = import('i18n')
 gtkmm = dependency('gtkmm-3.0')
 giomm = dependency('giomm-2.4', version: '>= 2.26')
 sigc = dependency('sigc++-2.0')
-dbus_glib = dependency('dbus-glib-1')
 libpulse = dependency('libpulse')
 
 lynx = find_program('lynx', required: with_lynx)


=====================================
src/meson.build
=====================================
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,7 +6,6 @@ paprefs_dependencies = [
   giomm,
   gtkmm,
   sigc,
-  dbus_glib,
   libpulse,
 ]
 


=====================================
src/paprefs.cc
=====================================
--- a/src/paprefs.cc
+++ b/src/paprefs.cc
@@ -25,8 +25,8 @@
 
 #include <gtkmm.h>
 #include <libintl.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
+#include <giomm/dbusconnection.h>
+#include <giomm/dbusproxy.h>
 #include <gdk/gdkx.h>
 
 #include <pulse/version.h>
@@ -120,6 +120,9 @@ public:
     void installFiles(const char *a, const char *b);
     void installModules(const char *a, const char *b);
 
+    void onPackageKitAppeared(const Glib::RefPtr<Gio::DBus::Connection>& 
connection, const Glib::ustring& name, const Glib::ustring& name_owner);
+    void onPackageKitVanished(const Glib::RefPtr<Gio::DBus::Connection>& 
connection, const Glib::ustring& name);
+
     bool moduleExists(const gchar *name);
     gchar *modulePath(const gchar *name);
 
@@ -339,36 +342,28 @@ void MainWindow::showInstallButton(Gtk::Button *button, 
bool available) {
 }
 
 void MainWindow::installFiles(const char *a, const char *b = NULL) {
-    DBusGConnection *connection;
-    DBusGProxy *proxy;
-    gboolean ret;
-    GError *error = NULL;
-    const gchar *packages[] = {a, b, NULL};
-
-    connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-
-    proxy = dbus_g_proxy_new_for_name(connection,
-                                      "org.freedesktop.PackageKit",
-                                      "/org/freedesktop/PackageKit",
-                                      "org.freedesktop.PackageKit.Modify");
-
-    ret = dbus_g_proxy_call(
-            proxy, "InstallProvideFiles", &error,
-            G_TYPE_UINT, GDK_WINDOW_XID(get_window()->gobj()),
-            G_TYPE_STRV, packages,
-            G_TYPE_STRING, "show-confirm-search,hide-finished",
-            G_TYPE_INVALID, G_TYPE_INVALID);
-
-    if (!ret) {
-        g_warning("Installation failed: %s", error->message);
-        g_error_free(error);
+    Glib::RefPtr<Gio::DBus::Proxy> proxy;
+    const std::vector<Glib::ustring> packages = {a, b};
+
+    proxy = 
Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BusType::BUS_TYPE_SESSION,
+                                                      
"org.freedesktop.PackageKit",
+                                                      
"/org/freedesktop/PackageKit",
+                                                      
"org.freedesktop.PackageKit.Modify");
+
+    Glib::VariantContainerBase params = 
Glib::VariantContainerBase::create_tuple(std::vector<Glib::VariantBase>({
+        Glib::Variant<guint>::create(GDK_WINDOW_XID(get_window()->gobj())),
+        Glib::Variant<std::vector<Glib::ustring>>::create(packages),
+        
Glib::Variant<Glib::ustring>::create("show-confirm-search,hide-finished")
+    }));
+
+    try {
+        proxy->call_sync("InstallProvideFiles", params);
+
+        checkForModules();
+        updateSensitive();
+    } catch (const Glib::Error& err) {
+        g_warning("Installation failed: %s", err.what().c_str());
     }
-
-    g_object_unref(proxy);
-    dbus_g_connection_unref(connection);
-
-    checkForModules();
-    updateSensitive();
 }
 
 void MainWindow::installModules(const char *a, const char *b = NULL) {
@@ -728,19 +723,20 @@ void MainWindow::checkForModules() {
 }
 
 void MainWindow::checkForPackageKit() {
+    Gio::DBus::watch_name(Gio::DBus::BusType::BUS_TYPE_SESSION,
+                          "org.freedesktop.PackageKit",
+                          sigc::mem_fun(*this, 
&MainWindow::onPackageKitAppeared),
+                          sigc::mem_fun(*this, 
&MainWindow::onPackageKitVanished));
+}
 
-    DBusError err;
-    dbus_error_init(&err);
-    DBusConnection *sessionBus = dbus_bus_get(DBUS_BUS_SESSION, &err);
+void MainWindow::onPackageKitAppeared(const 
Glib::RefPtr<Gio::DBus::Connection>& connection,const Glib::ustring& name,const 
Glib::ustring& name_owner) {
+    packageKitAvailable = TRUE;
+    updateSensitive();
+}
 
-    if(dbus_error_is_set(&err)) {
-        g_warning("Error connecting to DBus: %s", err.message);
-        packageKitAvailable = FALSE;
-    } else {
-        packageKitAvailable = dbus_bus_name_has_owner(sessionBus, 
"org.freedesktop.PackageKit", NULL);
-        dbus_connection_unref(sessionBus);
-    }
-    dbus_error_free(&err);
+void MainWindow::onPackageKitVanished(const 
Glib::RefPtr<Gio::DBus::Connection>& connection,const Glib::ustring& name) {
+    packageKitAvailable = FALSE;
+    updateSensitive();
 }
 
 



View it on GitLab: 
https://gitlab.freedesktop.org/pulseaudio/paprefs/compare/9963030dc010ee691c4f15fe22d78bcd4beb198a...0a5e8a94392df3f1af80d79d8253638b4945078f

-- 
View it on GitLab: 
https://gitlab.freedesktop.org/pulseaudio/paprefs/compare/9963030dc010ee691c4f15fe22d78bcd4beb198a...0a5e8a94392df3f1af80d79d8253638b4945078f
You're receiving this email because of your account on gitlab.freedesktop.org.
_______________________________________________
pulseaudio-commits mailing list
pulseaudio-commits@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits

Reply via email to