[cheese] Use PackageKit for nautilus-sendto dependency



commit b2c1cec7dd6f8df9e8e41341dab5d18e47b4f40e
Author: Patricia Santana Cruz <patriciasantanacruz gmail com>
Date:   Wed Jan 25 14:37:01 2012 +0000

    Use PackageKit for nautilus-sendto dependency
    
    The user has the option to install nautilus-sendto runtime dependency
    with PackageKit, in case it is not already installed.
    
    Fixes bug 668072.

 Makefile.am            |    3 +-
 README                 |    4 ++-
 src/cheese-window.vala |   54 ++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 46 insertions(+), 15 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 8b26ebd..6c78593 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,7 +67,8 @@ VALAFLAGS = \
 	--pkg eogthumbnav \
 	--pkg cheese-thumbview \
 	--pkg cheese-common \
-	--pkg gdk-x11-3.0
+	--pkg gdk-x11-3.0 \
+	--pkg gio-2.0
 
 lib_LTLIBRARIES = libcheese.la libcheese-gtk.la
 
diff --git a/README b/README
index d6a71df..fcb89b4 100644
--- a/README
+++ b/README
@@ -13,4 +13,6 @@ test this, you can use the 'gstreamer-properties' tool.
 
 Sharing images and videos:
 In order to be able to share images and videos from Cheese, you will need to
-install the 'nautilus-sendto' package first.
+install the 'nautilus-sendto' package first. In case you try to use the sharing
+functionality and nautilus-sendto is not installed, PackageKit will be used in
+order to install it at runtime.
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 1aac873..e7b8d94 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -29,6 +29,11 @@ using Gst;
 using Gee;
 using CanberraGtk;
 
+[DBus(name = "org.freedesktop.PackageKit.Modify")]
+interface PkProxy : GLib.Object {
+        public abstract async void install_package_names (uint xid, string[] packages_names, string interaction) throws IOError;
+}
+
 const int FULLSCREEN_TIMEOUT_INTERVAL = 5 * 1000;
 const int EFFECTS_PER_PAGE            = 9;
 const string SENDTO_EXEC = "nautilus-sendto";
@@ -174,14 +179,7 @@ public class Cheese.MainWindow : Gtk.Window
     if (event.type == Gdk.EventType.BUTTON_PRESS)
     {
       if (event.button == 3)
-      {
 	thumbnail_popup.popup (null, thumb_view, null, event.button, event.time);
-
-	// Check whether nautilus-sendto is installed or not. In case it is, set
-	// the "Share" action to sensitive, if it is not, set it to insensitive.
-	bool nautilus_sendto_installed = Environment.find_program_in_path(SENDTO_EXEC) != null;
-	share_action.set_sensitive (nautilus_sendto_installed);
-      }
     }
     else
     if (event.type == Gdk.EventType.2BUTTON_PRESS)
@@ -388,7 +386,39 @@ public class Cheese.MainWindow : Gtk.Window
   [CCode (instance_pos = -1)]
   public void on_share_files (Gtk.Action action)
   {
-    shareable_media.share_files (thumb_view.get_selected_images_list ());
+    bool nautilus_sendto_installed = Environment.find_program_in_path (SENDTO_EXEC) != null;
+
+    if (!nautilus_sendto_installed)
+      install_packages ((obj, res) => {
+                        install_packages.end (res);
+                        get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.LEFT_PTR));
+                       });
+    else
+      shareable_media.share_files (thumb_view.get_selected_images_list ());
+  }
+
+  /**
+   * Install nautilus-sendto runtime dependency.
+   *
+   */
+  private async void install_packages ()
+  {
+    get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.WATCH));
+
+    try {
+      PkProxy pk_proxy = yield Bus.get_proxy (BusType.SESSION,
+                                              "org.freedesktop.PackageKit",
+                                              "/org/freedesktop/PackageKit");
+
+      string[] packages = { "nautilus-sendto" };
+      var interaction = "hide-finished,hide-warning,show-confirm-install";
+
+      yield pk_proxy.install_package_names ((uint) Gdk.X11Window.get_xid (this.get_window ()),
+                                            packages,
+                                            interaction);
+    } catch (IOError error) {
+      critical ("D-Bus error: %s\n", error.message);
+    }
   }
 
   /**
@@ -1521,12 +1551,10 @@ public class Cheese.MainWindow : Gtk.Window
   {
      if (strcmp (action.get_name(), "edit_action") == 0)
      {
-        if (thumb_view.get_selected_images_list () != null)
-        {
-           bool nautilus_sendto_installed = Environment.find_program_in_path(SENDTO_EXEC) != null;
-           share_action.set_sensitive (nautilus_sendto_installed);
-        } else
+        if (thumb_view.get_selected_images_list () == null)
            share_action.set_sensitive (false);
+        else
+           share_action.set_sensitive (true);
      }
   }
 



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