[file-roller: 1/6] started packagekit support



commit e433938845985d9d8ff757020d8c89823285d194
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Oct 22 20:40:17 2009 +0200

    started packagekit support

 configure.ac                |   18 +++
 src/Makefile.am             |    8 +-
 src/dlg-package-installer.c |  241 +++++++++++++++++++++++++++++++++++++++++++
 src/dlg-package-installer.h |   32 ++++++
 src/fr-archive.c            |    3 +-
 src/fr-window.c             |    9 ++-
 src/typedefs.h              |    3 +-
 7 files changed, 309 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0099de7..12f295a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,6 +90,23 @@ AC_CHECK_FUNC(mkdtemp,
     mkdtemp_missing=true)
 AM_CONDITIONAL(MKDTEMP_MISSING, test x$mkdtemp_missing = xtrue)
 
+dnl ==========================================================================
+
+AC_ARG_ENABLE(packagekit,
+	      [AC_HELP_STRING([--disable-packagekit],[build without PackageKit support])],,
+	      [enable_packagekit=yes])
+if test "x$enable_packagekit" != "xno"; then
+	if pkg-config dbus-glib-1; then
+		AC_DEFINE(ENABLE_PACKAGEKIT, 1, [define to enable PackageKit installer])
+		DBUS_CFLAGS = `pkg-config --cflags dbus-glib-1`
+		DBUS_LIBS = `pkg-config --libs dbus-glib-1`
+        else
+		enable_packagekit=no
+        fi
+fi
+AC_SUBST(DBUS_CFLAGS)
+AC_SUBST(DBUS_LIBS)
+
 dnl ******************************
 
 GETTEXT_PACKAGE=file-roller
@@ -164,5 +181,6 @@ Configuration:
 	Compiler:               ${CC}
 	Internal mkdtemp:       ${mkdtemp_missing}
 	Nautilus support:       ${build_nautilus_actions}
+	PackageKit support:     ${enable_packagekit}
 	Run in place            ${enable_run_in_place}
 "
diff --git a/src/Makefile.am b/src/Makefile.am
index 32d07e8..2eedf46 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,7 +39,8 @@ INCLUDES =						\
 	-DPRIVEXECDIR=\"$(privexecdir)\"		\
 	-DSHDIR=\"$(shdir)\"				\
 	$(DISABLE_DEPRECATED)				\
-	$(FR_CFLAGS)
+	$(FR_CFLAGS)					\
+	$(DBUS_CFLAGS)
 
 BUILT_SOURCES =			\
 	fr-marshal.c		\
@@ -66,6 +67,8 @@ file_roller_SOURCES = 			\
 	dlg-new.h			\
 	dlg-open-with.c			\
 	dlg-open-with.h			\
+	dlg-package-installer.c		\
+	dlg-package-installer.h		\
 	dlg-password.c			\
 	dlg-password.h			\
 	dlg-prop.c			\
@@ -175,7 +178,8 @@ fr-enum-types.c: typedefs.h fr-enum-types.h
 
 file_roller_LDADD =							\
 		    $(top_builddir)/copy-n-paste/libeggsmclient.la	\
-		    $(FR_LIBS)
+		    $(FR_LIBS)						\
+		    $(DBUS_LIBS)
 
 EXTRA_DIST = fr-marshal.list
 
diff --git a/src/dlg-package-installer.c b/src/dlg-package-installer.c
new file mode 100644
index 0000000..a1c0db4
--- /dev/null
+++ b/src/dlg-package-installer.c
@@ -0,0 +1,241 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001-2009 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <glib/gi18n.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <dbus/dbus-glib.h>
+#include "dlg-package-installer.h"
+
+
+typedef struct {
+	FrWindow  *window;
+	FrArchive *archive;
+	FrAction   action;
+} InstallerData;
+
+
+static void
+installer_data_free (InstallerData *idata)
+{
+	g_object_unref (idata->archive);
+	g_object_unref (idata->window);
+	g_free (idata);
+}
+
+
+static void
+package_installer_terminated (InstallerData *idata,
+			      const char    *error)
+{
+	if (error != NULL) {
+		fr_archive_action_completed (idata->archive,
+					     FR_ACTION_CREATING_NEW_ARCHIVE,
+					     FR_PROC_ERROR_GENERIC,
+					     error);
+	}
+	else {
+		/* FIXME: continue batch operation */
+	}
+
+	installer_data_free (idata);
+}
+
+
+static void
+packagekit_install_package_call_notify_cb (DBusGProxy     *proxy,
+					   DBusGProxyCall *call,
+					   gpointer        user_data)
+{
+	InstallerData *idata = user_data;
+	gboolean       success;
+	GError        *error = NULL;
+	char          *message = NULL;
+
+	success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+	if (! success) {
+		const char *remote = NULL;
+
+		if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
+			remote = dbus_g_error_get_name (error);
+		if ((remote == NULL) || (strcmp (remote, "org.freedesktop.PackageKit.Modify.Failed") == 0))
+			message = g_strdup_printf ("%s\n%s",
+                                                   _("There was an internal error trying to search for applications:"),
+                                                   error->message);
+		g_error_free (error);
+	}
+
+	package_installer_terminated (idata, message);
+
+	g_free (message);
+	g_object_unref (proxy);
+}
+
+
+static void
+install_packages (InstallerData *idata)
+{
+	gboolean         success = FALSE;
+	DBusGConnection *connection;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+	if (connection != NULL) {
+		DBusGProxy *proxy;
+
+		proxy = dbus_g_proxy_new_for_name (connection,
+						   "org.freedesktop.PackageKit",
+						   "/org/freedesktop/PackageKit",
+						   "org.freedesktop.PackageKit.Modify");
+
+		if (proxy != NULL) {
+			GdkWindow       *window;
+			guint            xid;
+			char           **names;
+			DBusGProxyCall  *call;
+
+			window = gtk_widget_get_window (GTK_WIDGET (idata->window));
+		        if (window != NULL)
+		        	xid = GDK_WINDOW_XID (window);
+		        else
+		        	xid = 0;
+
+		        names = g_strsplit ("rar,unrar", ",", -1);
+			call = dbus_g_proxy_begin_call (proxy,
+							"InstallPackageNames",
+							(DBusGProxyCallNotify) packagekit_install_package_call_notify_cb,
+							idata,
+							NULL,
+							G_TYPE_UINT, xid,
+							G_TYPE_STRV, names,
+							G_TYPE_STRING, "",
+							G_TYPE_INVALID);
+			success = (call != NULL);
+
+			g_strfreev (names);
+		}
+	}
+
+	if (! success)
+		package_installer_terminated (idata, _("Archive type not supported."));
+}
+
+
+static void
+confirm_search_dialog_response_cb (GtkDialog *dialog,
+				   int        response_id,
+				   gpointer   user_data)
+{
+	InstallerData *idata = user_data;
+
+	gtk_widget_destroy (GTK_WIDGET (dialog));
+
+	if (response_id == GTK_RESPONSE_YES) {
+		install_packages (idata);
+	}
+	else {
+		/* FIXME: cancel the batch operation */
+		installer_data_free (idata);
+	}
+}
+
+
+static void
+dbus_name_has_owner_call_notify_cb (DBusGProxy     *proxy,
+				    DBusGProxyCall *call,
+				    gpointer        user_data)
+{
+	InstallerData *idata = user_data;
+	GError        *error = NULL;
+	gboolean       success;
+	gboolean       present;
+	GtkWidget     *dialog;
+
+	success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &present, G_TYPE_INVALID);
+	if (! success) {
+		package_installer_terminated (idata, error->message);
+		g_error_free (error);
+		return;
+	}
+
+	if (! present) {
+		package_installer_terminated (idata, _("Archive type not supported."));
+		return;
+	}
+
+	dialog = gtk_message_dialog_new (GTK_WINDOW (idata->window),
+					 GTK_DIALOG_MODAL,
+					 GTK_MESSAGE_ERROR,
+					 GTK_BUTTONS_YES_NO,
+					 "%s", "error");
+	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+						  _("There is no command installed for %s files.\nDo you want to search for an command to open this file?"),
+						  g_content_type_get_description (idata->archive->content_type));
+	gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+	g_signal_connect (dialog, "response", G_CALLBACK (confirm_search_dialog_response_cb), idata);
+	gtk_widget_show_all (dialog);
+}
+
+
+void
+dlg_package_installer (FrWindow  *window,
+		       FrArchive *archive,
+		       FrAction   action)
+{
+	gboolean         success = FALSE;
+	InstallerData   *idata;
+	DBusGConnection *connection;
+
+	idata = g_new0 (InstallerData, 1);
+	idata->window = g_object_ref (window);
+	idata->archive = g_object_ref (archive);
+	idata->action = action;
+
+#ifdef ENABLE_PACKAGEKIT
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+	if (connection != NULL) {
+		DBusGProxy *proxy;
+
+		proxy = dbus_g_proxy_new_for_name (connection,
+						   DBUS_SERVICE_DBUS,
+						   DBUS_PATH_DBUS,
+						   DBUS_INTERFACE_DBUS);
+		if (proxy != NULL) {
+			DBusGProxyCall *call;
+
+			call = dbus_g_proxy_begin_call (proxy,
+							"NameHasOwner",
+							(DBusGProxyCallNotify) dbus_name_has_owner_call_notify_cb,
+							idata,
+							NULL,
+							G_TYPE_STRING, "org.freedesktop.PackageKit",
+							G_TYPE_INVALID);
+			success = (call != NULL);
+		}
+	}
+#endif /* ENABLE_PACKAGEKIT */
+
+	if (! success)
+		package_installer_terminated (idata, _("Archive type not supported."));
+}
diff --git a/src/dlg-package-installer.h b/src/dlg-package-installer.h
new file mode 100644
index 0000000..f7df874
--- /dev/null
+++ b/src/dlg-package-installer.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001-2009 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DLG_PACKAGE_INSTALLER_H
+#define DLG_PACKAGE_INSTALLER_H
+
+#include "fr-window.h"
+
+void dlg_package_installer (FrWindow  *window,
+			    FrArchive *archive,
+			    FrAction   action);
+
+#endif /* DLG_PACKAGE_INSTALLER_H */
diff --git a/src/fr-archive.c b/src/fr-archive.c
index db62454..bce77ee 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -877,9 +877,10 @@ load_local_archive (FrArchive  *archive,
 			mime_type = get_mime_type_from_magic_numbers (archive->file);
 			if (! create_command_to_load_archive (archive, mime_type)) {
 				archive->command = tmp_command;
+				archive->content_type = mime_type;
 				fr_archive_action_completed (archive,
 							     FR_ACTION_LOADING_ARCHIVE,
-							     FR_PROC_ERROR_GENERIC,
+							     FR_PROC_ERROR_UNSUPPORTED_FORMAT,
 							     _("Archive type not supported."));
 				return;
 			}
diff --git a/src/fr-window.c b/src/fr-window.c
index 168bec0..ba56c21 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -35,6 +35,7 @@
 #include "dlg-extract.h"
 #include "dlg-open-with.h"
 #include "dlg-ask-password.h"
+#include "dlg-package-installer.h"
 #include "dlg-update.h"
 #include "eggtreemultidnd.h"
 #include "fr-marshal.h"
@@ -2878,8 +2879,13 @@ handle_errors (FrWindow    *window,
 		dlg_ask_password (window);
 		return FALSE;
 	}
+	else if (error->type == FR_PROC_ERROR_UNSUPPORTED_FORMAT) {
+		close_progress_dialog (window, TRUE);
+		dlg_package_installer (window, archive, action);
+		return FALSE;
+	}
 #if 0
-	if (error->type == FR_PROC_ERROR_BAD_CHARSET) {
+	else if (error->type == FR_PROC_ERROR_BAD_CHARSET) {
 		close_progress_dialog (window, TRUE);
 		/* dlg_ask_archive_charset (window); FIXME: implement after feature freeze */
 		return FALSE;
@@ -3049,6 +3055,7 @@ action_performed (FrArchive   *archive,
 	continue_batch = handle_errors (window, archive, action, error);
 
 	if ((error->type == FR_PROC_ERROR_ASK_PASSWORD)
+	    || (error->type == FR_PROC_ERROR_UNSUPPORTED_FORMAT)
 	    /*|| (error->type == FR_PROC_ERROR_BAD_CHARSET)*/)
 	{
 		return;
diff --git a/src/typedefs.h b/src/typedefs.h
index 5faf964..06fda21 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -65,7 +65,8 @@ typedef enum { /*< skip >*/
 	FR_PROC_ERROR_ASK_PASSWORD,
 	FR_PROC_ERROR_MISSING_VOLUME,
 	FR_PROC_ERROR_IO_CHANNEL,
-	FR_PROC_ERROR_BAD_CHARSET
+	FR_PROC_ERROR_BAD_CHARSET,
+	FR_PROC_ERROR_UNSUPPORTED_FORMAT
 } FrProcErrorType;
 
 typedef struct {



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