[gnome-games] aisleriot: Port card themes installer to gdbus
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] aisleriot: Port card themes installer to gdbus
- Date: Tue, 18 May 2010 22:08:14 +0000 (UTC)
commit 574d09b6c06ce5371837f8f2e996edcc10fef876
Author: Christian Persch <chpe gnome org>
Date: Wed May 19 00:06:55 2010 +0200
aisleriot: Port card themes installer to gdbus
Remove libdbus-glib dependency, and use gio 2.25 for the dbus call to
PackageKit.
aisleriot/data/Makefile.am | 2 -
aisleriot/lib/Makefile.am | 10 +-
aisleriot/lib/ar-card-themes.c | 181 ++++++++++++++++------------------------
aisleriot/window.c | 16 ++--
configure.in | 25 +-----
5 files changed, 88 insertions(+), 146 deletions(-)
---
diff --git a/aisleriot/data/Makefile.am b/aisleriot/data/Makefile.am
index 29a4bee..9ab4f69 100644
--- a/aisleriot/data/Makefile.am
+++ b/aisleriot/data/Makefile.am
@@ -12,9 +12,7 @@ slotdir = $(pkgdatadir)/pixmaps
dist_slot_DATA = slot.svg
endif # HAVE_RSVG
-if ENABLE_CARD_THEMES_INSTALLER
themeinstalldir = $(commondatadir)
dist_themeinstall_DATA = theme-install.ini
-endif # ENABLE_CARD_THEMES_INSTALLER
-include $(top_srcdir)/git.mk
diff --git a/aisleriot/lib/Makefile.am b/aisleriot/lib/Makefile.am
index 8a97579..2df7958 100644
--- a/aisleriot/lib/Makefile.am
+++ b/aisleriot/lib/Makefile.am
@@ -65,6 +65,11 @@ libaisleriot_la_LIBADD = \
$(top_builddir)/libgames-support/libgames-support.la \
$(GTK_LIBS)
+if HAVE_GIO_2_26
+libaisleriot_la_CFLAGS += $(GIO_CFLAGS)
+libaisleriot_la_LIBADD += $(GIO_LIBS)
+endif # HAVE_GIO_2_26
+
if HAVE_RSVG
libaisleriot_la_CFLAGS += $(RSVG_CFLAGS)
libaisleriot_la_LIBADD += $(RSVG_LIBS)
@@ -75,11 +80,6 @@ libaisleriot_la_CFLAGS += $(CLUTTER_CFLAGS)
libaisleriot_la_LIBADD += $(CLUTTER_LIBS)
endif # HAVE_CLUTTER
-if ENABLE_CARD_THEMES_INSTALLER
-libaisleriot_la_CFLAGS += $(DBUS_GLIB_CFLAGS)
-libaisleriot_la_LIBADD += $(DBUS_GLIB_LIBS)
-endif # ENABLE_CARD_THEMES_INSTALLER
-
if HAVE_HILDON
libaisleriot_la_CFLAGS += $(HILDON_CFLAGS)
libaisleriot_la_LIBADD += $(HILDON_LIBS)
diff --git a/aisleriot/lib/ar-card-themes.c b/aisleriot/lib/ar-card-themes.c
index 1e9072f..e82904f 100644
--- a/aisleriot/lib/ar-card-themes.c
+++ b/aisleriot/lib/ar-card-themes.c
@@ -25,8 +25,8 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
-#ifdef ENABLE_CARD_THEMES_INSTALLER
-#include <dbus/dbus-glib.h>
+#if GLIB_CHECK_VERSION (2, 25, 5)
+#include <gio/gio.h>
#endif
#ifdef GDK_WINDOWING_X11
@@ -368,42 +368,34 @@ themes_foreach_any (gpointer key,
data->theme = ar_card_themes_get_theme (data->theme_manager, theme_info);
}
-#ifdef ENABLE_CARD_THEMES_INSTALLER
-
-typedef struct {
- ArCardThemes *theme_manager;
- DBusGProxy *proxy;
-} ThemeInstallData;
-
-static void
-theme_install_data_free (ThemeInstallData *data)
-{
- g_object_unref (data->theme_manager);
- g_object_unref (data->proxy);
- g_free (data);
-}
+#if GLIB_CHECK_VERSION (2, 25, 5)
static void
-theme_install_reply_cb (DBusGProxy *proxy,
- DBusGProxyCall *call,
- ThemeInstallData *data)
+theme_install_reply_cb (GDBusConnection *connection,
+ GAsyncResult *result,
+ ArCardThemes *theme_manager)
{
- ArCardThemes *theme_manager = data->theme_manager;
+ GVariant *variant;
GError *error = NULL;
- if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
+ variant = g_dbus_connection_call_finish (connection, result, &error);
+ if (variant == NULL) {
_games_debug_print (GAMES_DEBUG_CARD_THEME,
"Failed to call InstallPackages: %s\n",
error->message);
g_error_free (error);
+ g_object_unref (theme_manager);
return;
}
/* Installation succeeded. Now re-scan the theme directories */
ar_card_themes_load_theme_infos (theme_manager);
+
+ g_variant_unref (variant);
+ g_object_unref (theme_manager);
}
-#endif /* ENABLE_CARD_THEMES_INSTALLER */
+#endif /* GLIB >= 2.25.5 */
/* Class implementation */
@@ -658,7 +650,7 @@ ar_card_themes_get_themes (ArCardThemes *theme_manager)
gboolean
ar_card_themes_can_install_themes (ArCardThemes *theme_manager)
{
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#if GLIB_CHECK_VERSION (2, 25, 5)
return TRUE;
#else
return FALSE;
@@ -678,7 +670,7 @@ ar_card_themes_install_themes (ArCardThemes *theme_manager,
GtkWindow *parent_window,
guint user_time)
{
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#if GLIB_CHECK_VERSION (2, 25, 5)
static const char *formats[] = {
#ifdef ENABLE_CARD_THEME_FORMAT_SVG
"ThemesSVG",
@@ -691,111 +683,80 @@ ar_card_themes_install_themes (ArCardThemes *theme_manager,
#endif
NULL
};
- GKeyFile *key_file;
char *path;
- const char *group;
- GPtrArray *arr;
- char **packages;
- gsize n_packages, i, j;
- DBusGConnection *connection;
- ThemeInstallData *data;
- guint xid = 0;
+ GKeyFile *key_file;
+ GDBusConnection *connection;
+ GVariantBuilder builder;
+ gsize i;
GError *error = NULL;
- arr = g_ptr_array_new ();
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to get the session bus: %s\n",
+ error->message);
+ g_error_free (error);
+ return;
+ }
key_file = g_key_file_new ();
path = games_runtime_get_file (GAMES_RUNTIME_COMMON_DATA_DIRECTORY, "theme-install.ini");
- if (!g_key_file_load_from_file (key_file, path, 0, NULL))
- goto do_install;
+ if (!g_key_file_load_from_file (key_file, path, 0, NULL)) {
+ g_free (path);
+ g_key_file_free (key_file);
+ g_object_unref (connection);
+ return;
+ }
+ g_free (path);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("(uass)"));
+
+#ifdef GDK_WINDOWING_X11
+ if (parent_window) {
+ g_variant_builder_add (&builder, "u",
+ (guint) GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (parent_window))));
+ } else
+#endif
+ g_variant_builder_add (&builder, "u", (guint) 0);
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
/* If there's a group for the specific distribution, use that one, or
* otherwise the generic one. E.g.:
* If "Ubuntu 8.10" group exists, use it, else fallback to "Ubuntu" group.
*/
- if (g_key_file_has_group (key_file, LSB_DISTRIBUTION))
- group = LSB_DISTRIBUTION;
- else if (g_key_file_has_group (key_file, LSB_DISTRIBUTOR))
- group = LSB_DISTRIBUTOR;
- else
- goto do_install;
-
for (i = 0; formats[i] != NULL; ++i) {
- packages = g_key_file_get_string_list (key_file, group, formats[i], &n_packages, NULL);
- if (!packages)
+ char **packages;
+ gsize n_packages, j;
+
+ packages = g_key_file_get_string_list (key_file, LSB_DISTRIBUTION, formats[i], &n_packages, NULL);
+ if (packages == NULL)
+ packages = g_key_file_get_string_list (key_file, LSB_DISTRIBUTOR, formats[i], &n_packages, NULL);
+ if (packages == NULL)
continue;
for (j = 0; j < n_packages; ++j) {
- g_ptr_array_add (arr, packages[j]);
+ g_variant_builder_add (&builder, "s", packages[j]);
}
- g_free (packages); /* The strings are now owned by the ptr array */
- }
- g_ptr_array_add (arr, NULL);
-
-do_install:
- g_key_file_free (key_file);
- g_free (path);
- n_packages = arr->len;
- packages = (char **) g_ptr_array_free (arr, FALSE);
- if (n_packages == 0) {
g_strfreev (packages);
- return; /* FIXME: show dialogue? */
- }
-
-#ifdef GNOME_ENABLE_DEBUG
- _GAMES_DEBUG_IF (GAMES_DEBUG_CARD_THEME) {
- _games_debug_print (GAMES_DEBUG_CARD_THEME, "Packages to install: ");
- for (i = 0; packages[i]; ++i)
- _games_debug_print (GAMES_DEBUG_CARD_THEME, "%s ", packages[i]);
- _games_debug_print (GAMES_DEBUG_CARD_THEME, "\n");
- }
-#endif
-
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (!connection) {
- _games_debug_print (GAMES_DEBUG_CARD_THEME,
- "Failed to get the session bus: %s\n",
- error->message);
- g_error_free (error);
- return;
}
- data = g_new (ThemeInstallData, 1);
- data->theme_manager = g_object_ref (theme_manager);
-
- /* PackageKit-GNOME interface */
- data->proxy = dbus_g_proxy_new_for_name (connection,
- "org.freedesktop.PackageKit",
- "/org/freedesktop/PackageKit",
- "org.freedesktop.PackageKit.Modify");
- g_assert (data->proxy != NULL); /* the call above never fails */
-
-#ifdef GDK_WINDOWING_X11
- if (parent_window) {
- xid = GDK_WINDOW_XID (GTK_WIDGET (parent_window)->window);
- }
-#endif
-
- /* Installing can take a long time; don't do the automatic timeout */
- dbus_g_proxy_set_default_timeout (data->proxy, G_MAXINT);
-
- if (!dbus_g_proxy_begin_call (data->proxy,
- "InstallPackageNames",
- (DBusGProxyCallNotify) theme_install_reply_cb,
- data,
- (GDestroyNotify) theme_install_data_free,
- G_TYPE_UINT, xid,
- G_TYPE_STRV, packages,
- G_TYPE_STRING, "" /* FIXME? interaction type */,
- G_TYPE_INVALID)) {
- /* Failed; cleanup. FIXME: can this happen at all? */
- _games_debug_print (GAMES_DEBUG_CARD_THEME,
- "Failed to call the InstallPackages method\n");
-
- theme_install_data_free (data);
- }
+ g_key_file_free (key_file);
- g_strfreev (packages);
-#endif
+ g_variant_builder_close (&builder);
+ g_variant_builder_add (&builder, "s", "hide-confirm-search");
+
+ g_dbus_connection_call (connection,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit.Modify",
+ "InstallPackageNames",
+ g_variant_builder_end (&builder),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT /* no timeout */,
+ NULL,
+ (GAsyncReadyCallback) theme_install_reply_cb,
+ g_object_ref (theme_manager));
+#endif /* GLIB >= 2.25.5 */
}
diff --git a/aisleriot/window.c b/aisleriot/window.c
index dc3a17a..da7a884 100644
--- a/aisleriot/window.c
+++ b/aisleriot/window.c
@@ -560,7 +560,7 @@ statistics_cb (GtkAction *action,
gtk_window_present (GTK_WINDOW (priv->stats_dialog));
}
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#ifndef HAVE_HILDON
static void
install_themes_cb (GtkAction *action,
@@ -573,7 +573,7 @@ install_themes_cb (GtkAction *action,
gtk_get_current_event_time ());
}
-#endif /* ENABLE_CARD_THEMES_INSTALLER */
+#endif /* !HAVE_HILDON */
#ifdef ENABLE_DEBUG_UI
@@ -2214,11 +2214,11 @@ aisleriot_window_init (AisleriotWindow *window)
{ "About", GTK_STOCK_ABOUT, NULL, NULL,
ACTION_TOOLTIP (N_("About this game")),
G_CALLBACK (help_about_cb) },
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#ifndef HAVE_HILDON
{ "InstallThemes", NULL, N_("Install card themesâ?¦"), NULL,
ACTION_TOOLTIP (N_("Install new card themes from the distribution packages repositories")),
G_CALLBACK (install_themes_cb) },
-#endif /* ENABLE_CARD_THEMES_INSTALLER */
+#endif /* HAVE_HILDON */
/* Toolbar-only actions */
{ "LeaveFullscreen", GAMES_STOCK_LEAVE_FULLSCREEN, NULL, NULL, NULL,
@@ -2373,7 +2373,7 @@ aisleriot_window_init (AisleriotWindow *window)
"<separator/>"
"<menu action='ThemeMenu'>"
"<placeholder name='ThemesPH'/>"
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#ifndef HAVE_HILDON
"<separator/>"
"<menuitem action='InstallThemes'/>"
#endif
@@ -2687,10 +2687,10 @@ aisleriot_window_init (AisleriotWindow *window)
priv->statusbar_visible);
#endif /* !HAVE_HILDON */
-#ifdef ENABLE_CARD_THEMES_INSTALLER
+#ifndef HAVE_HILDON
action = gtk_action_group_get_action (priv->action_group, "InstallThemes");
- gtk_action_set_sensitive (action, ar_card_themes_can_install_themes (priv->theme_manager));
-#endif /* ENABLE_CARD_THEMES_INSTALLER */
+ gtk_action_set_visible (action, ar_card_themes_can_install_themes (priv->theme_manager));
+#endif /* HAVE_HILDON */
set_fullscreen_actions (window, FALSE);
diff --git a/configure.in b/configure.in
index 55d3e57..3e2c5f9 100644
--- a/configure.in
+++ b/configure.in
@@ -482,27 +482,6 @@ esac
AC_DEFINE_UNQUOTED([AR_CARD_THEME_DEFAULT_FORMAT_STRING],["$with_default_card_theme_format"],[The default card theme format type string])
-# ********************
-# Card theme installer
-# ********************
-
-AC_MSG_CHECKING([whether card themes installer support is requested])
-AC_ARG_ENABLE([card-themes-installer],
- [AS_HELP_STRING([--enable-card-themes-installer],[Enable card theme installer with PackageKit (default: disabled)])],
- [],[enable_card_themes_installer=no])
-AC_MSG_RESULT([$enable_card_themes_installer])
-
-if test "$enable_card_themes_installer" = "yes"; then
- if test -z "$LSB_DISTRIBUTOR" -o -z "$LSB_DISTRIBUTION"; then
- AC_MSG_ERROR([couldn't determine the distribution information using lsb_release])
- fi
-
- AC_DEFINE([ENABLE_CARD_THEMES_INSTALLER],[1],[Define if card theme installer support is enabled])
- need_gio_2_26=yes
-fi
-
-AM_CONDITIONAL([ENABLE_CARD_THEMES_INSTALLER],[test "$enable_card_themes_installer" = "yes"])
-
# ******************
# Extra Debugging UI
# ******************
@@ -568,6 +547,10 @@ PKG_CHECK_MODULES([GIO],[gio-2.0 >= $GIO_REQUIRED],
[],[enable_schemas_install=yes])
AC_SUBST([GLIB_COMPILE_SCHEMAS],["$($PKG_CONFIG --variable glib_compile_schemas gio-2.0)]")
+
+ if test -z "$LSB_DISTRIBUTOR" -o -z "$LSB_DISTRIBUTION"; then
+ AC_MSG_ERROR([couldn't determine the distribution information using lsb_release])
+ fi
],[
have_gio_2_26=no
enable_schemas_install=no
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]