gnome-control-center r8695 - trunk/capplets/appearance



Author: jensg
Date: Wed May  7 20:19:36 2008
New Revision: 8695
URL: http://svn.gnome.org/viewvc/gnome-control-center?rev=8695&view=rev

Log:
2008-05-07  Jens Granseuer  <jensgr gmx net>

	Add support for installing missing GTK+ theme engines via
	packagekit (bug #511065)

	* appearance-themes.c: (theme_message_area_response_cb),
	(theme_message_area_update): when we detect a missing engine,
	check if packagekit is available on the session bus. If it is show
	an install button to pull the corresponding package
	* appearance.h:
	* theme-util.c: (packagekit_available), (theme_install_file):
	* theme-util.h: add support functions


Modified:
   trunk/capplets/appearance/ChangeLog
   trunk/capplets/appearance/appearance-themes.c
   trunk/capplets/appearance/appearance.h
   trunk/capplets/appearance/theme-util.c
   trunk/capplets/appearance/theme-util.h

Modified: trunk/capplets/appearance/appearance-themes.c
==============================================================================
--- trunk/capplets/appearance/appearance-themes.c	(original)
+++ trunk/capplets/appearance/appearance-themes.c	Wed May  7 20:19:36 2008
@@ -42,7 +42,8 @@
 {
   RESPONSE_APPLY_BG,
   RESPONSE_REVERT_FONT,
-  RESPONSE_APPLY_FONT
+  RESPONSE_APPLY_FONT,
+  RESPONSE_INSTALL_ENGINE
 };
 
 enum
@@ -57,6 +58,8 @@
   {"_NETSCAPE_URL", 0, TARGET_NS_URL}
 };
 
+static void theme_message_area_update (AppearanceData *data);
+
 static time_t
 theme_get_mtime (const char *name)
 {
@@ -441,6 +444,7 @@
 {
   const GnomeThemeMetaInfo *theme;
   gchar *tmpfont;
+  gchar *engine_path;
 
   theme = theme_get_selected (GTK_ICON_VIEW (glade_xml_get_widget (data->xml, "theme_list")), data);
   if (!theme)
@@ -566,6 +570,16 @@
                                  theme->monospace_font, NULL);
       }
       break;
+
+    case RESPONSE_INSTALL_ENGINE:
+      engine_path = gtk_theme_info_missing_engine (theme->gtk_theme_name, FALSE);
+      if (engine_path != NULL) {
+              theme_install_file (GTK_WINDOW (gtk_widget_get_toplevel (data->install_button)),
+                                  engine_path);
+              g_free (engine_path);
+      }
+      theme_message_area_update (data);
+      break;
   }
 }
 
@@ -583,8 +597,11 @@
 
   theme = theme_get_selected (GTK_ICON_VIEW (glade_xml_get_widget (data->xml, "theme_list")), data);
 
-  if (!theme)
+  if (!theme) {
+    if (data->theme_message_area != NULL)
+      gtk_widget_hide (data->theme_message_area);
     return;
+  }
 
   show_error = !gnome_theme_meta_info_validate (theme, &error);
 
@@ -663,6 +680,10 @@
         GEDIT_MESSAGE_AREA (data->theme_message_area),
         _("Revert Font"),
         RESPONSE_REVERT_FONT);
+    data->install_button = gedit_message_area_add_button (
+        GEDIT_MESSAGE_AREA (data->theme_message_area),
+        _("Install"),
+        RESPONSE_INSTALL_ENGINE);
 
     data->theme_message_label = gtk_label_new (NULL);
     gtk_widget_show (data->theme_message_label);
@@ -718,6 +739,13 @@
   else
     gtk_widget_hide (data->revert_font_button);
 
+  if (show_error
+      && g_error_matches (error, GNOME_THEME_ERROR, GNOME_THEME_ERROR_GTK_ENGINE_NOT_AVAILABLE)
+      && packagekit_available ())
+    gtk_widget_show (data->install_button);
+  else
+    gtk_widget_hide (data->install_button);
+
   if (show_error || show_apply_background || show_apply_font || show_revert_font) {
     gtk_widget_show (data->theme_message_area);
     gtk_widget_queue_draw (data->theme_message_area);

Modified: trunk/capplets/appearance/appearance.h
==============================================================================
--- trunk/capplets/appearance/appearance.h	(original)
+++ trunk/capplets/appearance/appearance.h	Wed May  7 20:19:36 2008
@@ -62,6 +62,7 @@
   GtkWidget *apply_background_button;
   GtkWidget *revert_font_button;
   GtkWidget *apply_font_button;
+  GtkWidget *install_button;
   GtkWidget *theme_info_icon;
   GtkWidget *theme_error_icon;
   gchar *revert_application_font;

Modified: trunk/capplets/appearance/theme-util.c
==============================================================================
--- trunk/capplets/appearance/theme-util.c	(original)
+++ trunk/capplets/appearance/theme-util.c	Wed May  7 20:19:36 2008
@@ -20,10 +20,13 @@
  */
 
 #include "appearance.h"
-#include "theme-util.h"
 
-#include <glib/gi18n.h>
 #include <string.h>
+#include <glib/gi18n.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include "theme-util.h"
 
 static gboolean
 directory_delete_recursive (GFile *directory, GError **error)
@@ -235,3 +238,72 @@
 
   return FALSE;
 }
+
+gboolean
+packagekit_available (void)
+{
+  DBusGConnection *connection;
+  DBusGProxy *proxy;
+  gboolean available = FALSE;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+  if (connection == NULL) {
+    return FALSE;
+  }
+
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     DBUS_SERVICE_DBUS,
+                                     DBUS_PATH_DBUS,
+                                     DBUS_INTERFACE_DBUS);
+
+  org_freedesktop_DBus_name_has_owner (proxy,
+                                       "org.freedesktop.PackageKit",
+                                       &available,
+                                       NULL);
+
+  g_object_unref (proxy);
+  dbus_g_connection_unref (connection);
+
+  return available;
+}
+
+void
+theme_install_file (GtkWindow *parent, const gchar *path)
+{
+  DBusGConnection *connection;
+  DBusGProxy *proxy;
+  GError *error = NULL;
+  gboolean ret;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+  if (connection == NULL) {
+    g_warning ("Could not get session bus");
+    return;
+  }
+
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     "org.freedesktop.PackageKit",
+                                     "/org/freedesktop/PackageKit",
+                                     "org.freedesktop.PackageKit");
+
+
+  ret = dbus_g_proxy_call (proxy, "InstallProvideFile", &error,
+                           G_TYPE_STRING, path,
+                           G_TYPE_INVALID, G_TYPE_INVALID);
+
+  g_object_unref (proxy);
+
+  if (!ret) {
+    GtkWidget *dialog = gtk_message_dialog_new (NULL,
+			GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+			GTK_MESSAGE_ERROR,
+			GTK_BUTTONS_OK,
+			_("Could not install theme engine"));
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), error->message);
+
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+    g_error_free (error);
+  }
+  dbus_g_connection_unref (connection);
+}

Modified: trunk/capplets/appearance/theme-util.h
==============================================================================
--- trunk/capplets/appearance/theme-util.h	(original)
+++ trunk/capplets/appearance/theme-util.h	Wed May  7 20:19:36 2008
@@ -57,3 +57,6 @@
 
 gboolean theme_model_iter_last (GtkTreeModel *model, GtkTreeIter *iter);
 gboolean theme_find_in_model (GtkTreeModel *model, const gchar *name, GtkTreeIter *iter);
+
+void     theme_install_file (GtkWindow *parent, const gchar *path);
+gboolean packagekit_available (void);



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