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