Skip to content
Commits on Source (2)
  • Jan Tojnar's avatar
    Port from dbus-glib to gdbus · b8246d3f
    Jan Tojnar authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
    dbus-glib has been deprecated in favour of D-Bus library built into
    GLib for a while now.
    b8246d3f
  • Jan Tojnar's avatar
    Remove libdbus dependency · 0a5e8a94
    Jan Tojnar authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
    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.
    0a5e8a94
......@@ -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)
......
......@@ -6,7 +6,6 @@ paprefs_dependencies = [
giomm,
gtkmm,
sigc,
dbus_glib,
libpulse,
]
......
......@@ -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();
}
......