[PATCH 1/2] [paprefs] Port from dbus-glib to gdbus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dbus-glib has been deprecated in favour of D-Bus library built into
GLib for a while now.
---
 meson.build     |  2 +-
 src/meson.build |  2 +-
 src/paprefs.cc  | 53 +++++++++++++++++++++----------------------------
 3 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/meson.build b/meson.build
index d2d002e..6368165 100644
--- a/meson.build
+++ b/meson.build
@@ -14,7 +14,7 @@ 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')
+libdbus = dependency('dbus-1')
 libpulse = dependency('libpulse')
 
 lynx = find_program('lynx', required: with_lynx)
diff --git a/src/meson.build b/src/meson.build
index 54740eb..7d61175 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,7 +6,7 @@ paprefs_dependencies = [
   giomm,
   gtkmm,
   sigc,
-  dbus_glib,
+  libdbus,
   libpulse,
 ]
 
diff --git a/src/paprefs.cc b/src/paprefs.cc
index 123fea5..29fb1bb 100644
--- a/src/paprefs.cc
+++ b/src/paprefs.cc
@@ -25,8 +25,9 @@
 
 #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>
@@ -339,36 +340,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) {
-- 
2.18.0



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux