[yelp/yelp-3-0] [yelp-window] Handle install: links with PackageKit, FTW



commit c64413773989cd0f2e25c2313d83d5d19e148b14
Author: Shaun McCance <shaunm gnome org>
Date:   Wed Mar 17 20:51:50 2010 -0500

    [yelp-window] Handle install: links with PackageKit, FTW

 src/yelp-application.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/yelp-application.h |    8 +++++-
 src/yelp-window.c      |    9 ++++++-
 3 files changed, 70 insertions(+), 4 deletions(-)
---
diff --git a/src/yelp-application.c b/src/yelp-application.c
index 1e0dc57..5c47386 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -26,6 +26,7 @@
 
 #include <dbus/dbus-glib-bindings.h>
 #include <dbus/dbus-glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include "yelp-settings.h"
@@ -122,7 +123,7 @@ yelp_application_adjust_font (YelpApplication  *app,
 {
     GSList *cur;
     YelpSettings *settings = yelp_settings_get_default ();
-    GParamSpec *spec = g_object_class_find_property (YELP_SETTINGS_GET_CLASS (settings),
+    GParamSpec *spec = g_object_class_find_property ((GObjectClass *) YELP_SETTINGS_GET_CLASS (settings),
                                                      "font-adjustment");
     gint adjustment = yelp_settings_get_font_adjustment (settings);
     YelpApplicationPrivate *priv = GET_PRIV (app);
@@ -328,3 +329,57 @@ application_maybe_quit (YelpApplication *app)
 
     return FALSE;
 }
+
+/******************************************************************************/
+
+static void
+packages_installed (DBusGProxy     *proxy,
+                    DBusGProxyCall *call,
+                    gpointer        data)
+{
+    GError *error = NULL;
+    dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+    g_strfreev ((gchar **) data);
+    if (error) {
+        const gchar *err = NULL;
+        if (error->domain == DBUS_GERROR) {
+            if (error->code == DBUS_GERROR_SERVICE_UNKNOWN) {
+                err = _("You do not have PackageKit installed.  Package installation links require PackageKit.");
+            }
+            else if (error->code != DBUS_GERROR_REMOTE_EXCEPTION &&
+                     error->code != DBUS_GERROR_NO_REPLY) {
+                err = error->message;
+            }
+        }
+        if (err) {
+            GtkWidget *dialog = gtk_message_dialog_new (NULL, 0,
+                                                        GTK_MESSAGE_ERROR,
+                                                        GTK_BUTTONS_CLOSE,
+                                                        "%s", err);
+            gtk_dialog_run ((GtkDialog *) dialog);
+            gtk_widget_destroy (dialog);
+        }
+    }
+}
+
+void
+yelp_application_install_package (YelpApplication  *app,
+                                  const gchar      *pkg,
+                                  const gchar      *alt)
+{
+    YelpApplicationPrivate *priv = GET_PRIV (app);
+    guint32 xid = 0;
+    DBusGProxy *proxy = dbus_g_proxy_new_for_name (priv->connection,
+                                                   "org.freedesktop.PackageKit",
+                                                   "/org/freedesktop/PackageKit",
+                                                   "org.freedesktop.PackageKit.Modify");
+    gchar **pkgs = g_new0 (gchar *, 2);
+    pkgs[0] = g_strdup (pkg);
+
+    dbus_g_proxy_begin_call (proxy, "InstallPackageNames",
+                             packages_installed, pkgs, NULL,
+                             G_TYPE_UINT, xid,
+                             G_TYPE_STRV, pkgs,
+                             G_TYPE_STRING, "",
+                             G_TYPE_INVALID, G_TYPE_INVALID);
+}
diff --git a/src/yelp-application.h b/src/yelp-application.h
index b66e02c..2387e5b 100644
--- a/src/yelp-application.h
+++ b/src/yelp-application.h
@@ -55,7 +55,11 @@ gboolean          yelp_application_load_uri    (YelpApplication  *app,
                                                 guint             timestamp,
                                                 GError          **error);
 
-void              yelp_application_adjust_font (YelpApplication  *app,
-                                                gint              adjust);
+void              yelp_application_adjust_font     (YelpApplication  *app,
+                                                    gint              adjust);
+
+void              yelp_application_install_package (YelpApplication  *app,
+                                                    const gchar      *pkg,
+                                                    const gchar      *alt);
 
 #endif /* __YELP_APPLICATION_H__ */
diff --git a/src/yelp-window.c b/src/yelp-window.c
index c4c6364..a643d18 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -489,7 +489,14 @@ view_external_uri (YelpView   *view,
                    YelpWindow *window)
 {
     gchar *struri = yelp_uri_get_canonical_uri (uri);
-    g_app_info_launch_default_for_uri (struri, NULL, NULL);
+    if (g_str_has_prefix (struri, "install:")) {
+        YelpWindowPrivate *priv = GET_PRIV (window);
+        gchar *pkg = struri + 8;
+        yelp_application_install_package (priv->application, pkg, "");
+    }
+    else
+        g_app_info_launch_default_for_uri (struri, NULL, NULL);
+
     g_free (struri);
 }
 



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