[gnome-packagekit] Watch when removable discs are inserted and call GetUpdates() if it is detected as repo media



commit b8e737ff64a8b7395e2b2dfd916cd07043495ea8
Author: Richard Hughes <richard hughsie com>
Date:   Wed May 12 09:47:00 2010 +0100

    Watch when removable discs are inserted and call GetUpdates() if it is detected as repo media

 data/gnome-packagekit.schemas.in |   19 ++++++++++
 src/gpk-check-update.c           |   73 ++++++++++++++++++++++++++++++++++++++
 src/gpk-common.h                 |    1 +
 3 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/data/gnome-packagekit.schemas.in b/data/gnome-packagekit.schemas.in
index 51e86e5..502a9ce 100644
--- a/data/gnome-packagekit.schemas.in
+++ b/data/gnome-packagekit.schemas.in
@@ -606,6 +606,25 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/gnome-packagekit/media_repo_filenames</key>
+      <applyto>/apps/gnome-packagekit/media_repo_filenames</applyto>
+      <owner>gnome-packagekit</owner>
+      <type>string</type>
+      <default>media.repo,.discinfo</default>
+      <locale name="C">
+        <short>
+	  The filenames on removable media that designate it important.
+	</short>
+        <long>
+          When removable media is inserted, it is checked to see if it contains
+          any important filenames in the root directory.
+          If the filename matches, then an updates check is performed.
+          This allows post-install disks to be used to update running systems.
+        </long>
+      </locale>
+    </schema>
+
   </schemalist>
 </gconfschemafile>
 
diff --git a/src/gpk-check-update.c b/src/gpk-check-update.c
index d6a454c..edecfe1 100644
--- a/src/gpk-check-update.c
+++ b/src/gpk-check-update.c
@@ -39,6 +39,7 @@
 #include <libnotify/notify.h>
 #include <packagekit-glib2/packagekit.h>
 #include <canberra-gtk.h>
+#include <gio/gio.h>
 
 #include "egg-debug.h"
 #include "egg-string.h"
@@ -85,6 +86,7 @@ struct GpkCheckUpdatePrivate
 	guint			 updates_changed_id;
 	GCancellable		*cancellable;
 	PkError			*error_code;
+	GVolumeMonitor		*volume_monitor;
 };
 
 G_DEFINE_TYPE (GpkCheckUpdate, gpk_check_update, G_TYPE_OBJECT)
@@ -1403,6 +1405,72 @@ out:
 }
 
 /**
+ * gpk_check_update_file_exist_in_root:
+ */
+static gboolean
+gpk_check_update_file_exist_in_root (const gchar *root, const gchar *filename)
+{
+	gboolean ret;
+	GFile *source;
+	gchar *source_path;
+
+	source_path = g_build_filename (root, filename, NULL);
+	source = g_file_new_for_path (source_path);
+
+	/* an interesting file exists */
+	ret = g_file_query_exists (source, NULL);
+	egg_debug ("checking for %s: %s", source_path, ret ? "yes" : "no");
+	if (!ret)
+		goto out;
+out:
+	g_free (source_path);
+	g_object_unref (source);
+	return ret;
+}
+
+/**
+ * gpk_check_update_mount_added_cb:
+ */
+static void
+gpk_check_update_mount_added_cb (GVolumeMonitor *volume_monitor, GMount *mount, GpkCheckUpdate *cupdate)
+{
+	gboolean ret = FALSE;
+	gchar **filenames = NULL;
+	gchar *media_repo_filenames;
+	gchar *root_path;
+	GFile *root;
+	guint i;
+
+	/* check if any installed media is an install disk */
+	root = g_mount_get_root (mount);
+	root_path = g_file_get_path (root);
+
+	/* use settings from gconf */
+	media_repo_filenames = gconf_client_get_string (cupdate->priv->gconf_client, GPK_CONF_MEDIA_REPO_FILENAMES, NULL);
+	if (media_repo_filenames == NULL) {
+		egg_warning ("failed to get media repo filenames");
+		goto out;
+	}
+
+	/* search each possible filename */
+	filenames = g_strsplit (media_repo_filenames, ",", -1);
+	for (i=0; filenames[i] != NULL; i++) {
+		ret = gpk_check_update_file_exist_in_root (root_path, filenames[i]);
+		if (ret)
+			break;
+	}
+
+	/* do an updates check with the new media */
+	if (ret)
+		gpk_check_update_query_updates (cupdate);
+out:
+	g_strfreev (filenames);
+	g_free (media_repo_filenames);
+	g_free (root_path);
+	g_object_unref (root);
+}
+
+/**
  * gpk_check_update_init:
  * @cupdate: This class instance
  **/
@@ -1453,6 +1521,10 @@ gpk_check_update_init (GpkCheckUpdate *cupdate)
 	g_signal_connect (cupdate->priv->dbus_monitor_viewer, "connection-changed",
 			  G_CALLBACK (gpk_cupdate_connection_changed_cb), cupdate);
 
+	/* get a volume monitor so we can watch media */
+	cupdate->priv->volume_monitor = g_volume_monitor_get ();
+	g_signal_connect (cupdate->priv->volume_monitor, "mount-added", G_CALLBACK (gpk_check_update_mount_added_cb), cupdate);
+
 	/* use an asynchronous query object */
 	cupdate->priv->task = PK_TASK (gpk_task_new ());
 	g_object_set (cupdate->priv->task,
@@ -1509,6 +1581,7 @@ gpk_check_update_finalize (GObject *object)
 	g_object_unref (cupdate->priv->task);
 	g_object_unref (cupdate->priv->dbus_monitor_viewer);
 	g_object_unref (cupdate->priv->cancellable);
+	g_object_unref (cupdate->priv->volume_monitor);
 	if (cupdate->priv->gicon != NULL)
 		g_object_unref (cupdate->priv->gicon);
 	if (cupdate->priv->error_code != NULL)
diff --git a/src/gpk-common.h b/src/gpk-common.h
index 8d9300d..8b7a39c 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -79,6 +79,7 @@ G_BEGIN_DECLS
 #define GPK_CONF_UPDATE_VIEWER_MOBILE_BBAND	"/apps/gnome-packagekit/update-viewer/notify_mobile_connection"
 #define GPK_CONF_UPDATE_VIEWER_ONLY_NEWEST	"/apps/gnome-packagekit/update-viewer/only_newest"
 #define GPK_CONF_UPDATE_VIEWER_SCROLL_ACTIVE	"/apps/gnome-packagekit/update-viewer/scroll_active"
+#define GPK_CONF_MEDIA_REPO_FILENAMES		"/apps/gnome-packagekit/media_repo_filenames"
 
 #define GPK_BUGZILLA_URL			"https://bugs.freedesktop.org/";
 



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