Discussion:
[pulseaudio-discuss] [PATCH 0/2] [paprefs] Port to gdbus
Jan Tojnar
2018-07-15 13:56:04 UTC
Permalink
I wanted to get rid of the deprecated dbus-glib dependency in favour of
GDBus built into GLib.

I tested the Install button and it does seem to open GNOME Software correctly,
and the DBus message sent by the app is the same as the one sent by the stable
version. I also verified that the install-button appears (disappears) when
I start (kill) GNOME Software.

This is the first time I am touching DBus APIs and GLib stuff in C++,
so please let me know of any issues with the patches.

Jan Tojnar (2):
Port from dbus-glib to gdbus
Remove libdbus dependency

meson.build | 1 -
src/meson.build | 1 -
src/paprefs.cc | 80 +++++++++++++++++++++++--------------------------
3 files changed, 38 insertions(+), 44 deletions(-)
--
2.18.0
Jan Tojnar
2018-07-15 13:56:06 UTC
Permalink
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
Jan Tojnar
2018-07-15 13:56:07 UTC
Permalink
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.
---
meson.build | 1 -
src/meson.build | 1 -
src/paprefs.cc | 27 +++++++++++++++------------
3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index 6368165..45e4789 100644
--- 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')
-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 7d61175..32a1945 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,7 +6,6 @@ paprefs_dependencies = [
giomm,
gtkmm,
sigc,
- libdbus,
libpulse,
]

diff --git a/src/paprefs.cc b/src/paprefs.cc
index 29fb1bb..2b1d389 100644
--- a/src/paprefs.cc
+++ b/src/paprefs.cc
@@ -25,7 +25,6 @@

#include <gtkmm.h>
#include <libintl.h>
-#include <dbus/dbus.h>
#include <giomm/dbusconnection.h>
#include <giomm/dbusproxy.h>
#include <gdk/gdkx.h>
@@ -121,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);

@@ -721,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();
}
--
2.18.0
Tanu Kaskinen
2018-08-11 10:36:01 UTC
Permalink
Post by Jan Tojnar
I wanted to get rid of the deprecated dbus-glib dependency in favour of
GDBus built into GLib.
I tested the Install button and it does seem to open GNOME Software correctly,
and the DBus message sent by the app is the same as the one sent by the stable
version. I also verified that the install-button appears (disappears) when
I start (kill) GNOME Software.
This is the first time I am touching DBus APIs and GLib stuff in C++,
so please let me know of any issues with the patches.
Port from dbus-glib to gdbus
Remove libdbus dependency
meson.build | 1 -
src/meson.build | 1 -
src/paprefs.cc | 80 +++++++++++++++++++++++--------------------------
3 files changed, 38 insertions(+), 44 deletions(-)
Thanks! I applied both patches.
--
Tanu

https://www.patreon.com/tanuk
https://liberapay.com/tanuk
Loading...