gnome-packagekit r185 - trunk/src



Author: rhughes
Date: Tue Apr 22 18:30:13 2008
New Revision: 185
URL: http://svn.gnome.org/viewvc/gnome-packagekit?rev=185&view=rev

Log:
from git

Added:
   trunk/src/gpk-firmware.c
   trunk/src/gpk-firmware.h
Modified:
   trunk/src/gpk-client.c
   trunk/src/gpk-common.c

Modified: trunk/src/gpk-client.c
==============================================================================
--- trunk/src/gpk-client.c	(original)
+++ trunk/src/gpk-client.c	Tue Apr 22 18:30:13 2008
@@ -34,9 +34,11 @@
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 #include <gconf/gconf-client.h>
+#include <polkit-gnome/polkit-gnome.h>
 #include <pk-debug.h>
 #include <pk-client.h>
 #include <pk-package-id.h>
+#include <pk-common.h>
 #include <pk-control.h>
 
 #include <gpk-client.h>
@@ -67,6 +69,7 @@
 	PkControl		*control;
 	PkRoleEnum		 roles;
 	gboolean		 do_key_auth;
+	gboolean		 retry_untrusted_value;
 };
 
 typedef enum {
@@ -240,6 +243,109 @@
 }
 
 /**
+ * gpk_client_button_retry_untrusted:
+ **/
+static void
+gpk_client_button_retry_untrusted (PolKitGnomeAction *action, GpkClient *gclient)
+{
+	pk_debug ("need to retry...");
+	gclient->priv->retry_untrusted_value = TRUE;
+	gtk_main_quit ();
+}
+
+/**
+ * gpk_client_error_dialog_retry_untrusted:
+ **/
+static gboolean
+gpk_client_error_dialog_retry_untrusted (GpkClient *gclient, PkErrorCodeEnum code, const gchar *details)
+{
+	GtkWidget *widget;
+	GtkWidget *button;
+	PolKitAction *pk_action;
+	GladeXML *glade_xml;
+	GtkTextBuffer *buffer = NULL;
+	gchar *text;
+	const gchar *title;
+	const gchar *message;
+	PolKitGnomeAction *update_system_action;
+
+	title = gpk_error_enum_to_localised_text (code);
+	message = gpk_error_enum_to_localised_message (code);
+
+	glade_xml = glade_xml_new (PK_DATA "/gpk-error.glade", NULL, NULL);
+
+	/* connect up actions */
+	widget = glade_xml_get_widget (glade_xml, "window_error");
+	g_signal_connect_swapped (widget, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+
+	/* set icon name */
+	gtk_window_set_icon_name (GTK_WINDOW (widget), PK_STOCK_WINDOW_ICON);
+
+	/* close button */
+	widget = glade_xml_get_widget (glade_xml, "button_close");
+	g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL);
+
+	/* title */
+	widget = glade_xml_get_widget (glade_xml, "label_title");
+	text = g_strdup_printf ("<b><big>%s</big></b>", title);
+	gtk_label_set_label (GTK_LABEL (widget), text);
+	g_free (text);
+
+	/* message */
+	widget = glade_xml_get_widget (glade_xml, "label_message");
+	gtk_label_set_label (GTK_LABEL (widget), message);
+
+	/* show text in the expander */
+	if (pk_strzero (details)) {
+		widget = glade_xml_get_widget (glade_xml, "expander_details");
+		gtk_widget_hide (widget);
+	} else {
+		buffer = gtk_text_buffer_new (NULL);
+		gtk_text_buffer_insert_at_cursor (buffer, details, strlen (details));
+		widget = glade_xml_get_widget (glade_xml, "textview_details");
+		gtk_text_view_set_buffer (GTK_TEXT_VIEW (widget), buffer);
+	}
+
+	/* add the extra button and connect up to a Policykit action */
+	pk_action = polkit_action_new ();
+	polkit_action_set_action_id (pk_action, "org.freedesktop.packagekit.localinstall-untrusted");
+	update_system_action = polkit_gnome_action_new_default ("localinstall-untrusted",
+								pk_action,
+								_("_Force install"),
+								_("Force installing package"));
+	g_object_set (update_system_action,
+		      "no-icon-name", GTK_STOCK_APPLY,
+		      "auth-icon-name", GTK_STOCK_APPLY,
+		      "yes-icon-name", GTK_STOCK_APPLY,
+		      "self-blocked-icon-name", GTK_STOCK_APPLY,
+		      NULL);
+	polkit_action_unref (pk_action);
+	g_signal_connect (update_system_action, "activate",
+			  G_CALLBACK (gpk_client_button_retry_untrusted), gclient);
+	button = polkit_gnome_action_create_button (update_system_action);
+	widget = glade_xml_get_widget (glade_xml, "hbuttonbox2");
+	gtk_box_pack_start (GTK_BOX (widget), button, FALSE, FALSE, 0);
+	gtk_box_reorder_child (GTK_BOX (widget), button, 0);
+
+	/* show window */
+	widget = glade_xml_get_widget (glade_xml, "window_error");
+	gtk_widget_show (widget);
+
+	/* wait for button press */
+	gtk_main ();
+
+	/* hide window */
+	if (GTK_IS_WIDGET (widget)) {
+		gtk_widget_hide (widget);
+	}
+	g_object_unref (glade_xml);
+	if (buffer != NULL) {
+		g_object_unref (buffer);
+	}
+	return TRUE;
+}
+
+/**
  * gpk_client_error_code_cb:
  **/
 static void
@@ -256,6 +362,16 @@
 		pk_warning ("did not auth");
 	}
 
+	/* have we handled? */
+	if (code == PK_ERROR_ENUM_BAD_GPG_SIGNATURE ||
+	    code == PK_ERROR_ENUM_MISSING_GPG_SIGNATURE) {
+		pk_debug ("handle and requeue");
+		gpk_client_error_dialog_retry_untrusted (gclient, code, details);
+		return;
+	}
+
+	pk_debug ("code was %s", pk_error_enum_to_text (code));
+
 	//remove GPK_CLIENT_PAGE_ERROR?
 	gpk_error_dialog (gpk_error_enum_to_localised_text (code),
 			  gpk_error_enum_to_localised_message (code), details);
@@ -321,7 +437,7 @@
 }
 
 /**
- * gpk_client_error_message:
+ * gpk_client_error_msg:
  **/
 static void
 gpk_client_error_msg (GpkClient *gclient, const gchar *title, const gchar *message)
@@ -379,6 +495,47 @@
 }
 
 /**
+ * gpk_client_install_local_file_internal:
+ **/
+static gboolean
+gpk_client_install_local_file_internal (GpkClient *gclient, gboolean trusted,
+					const gchar *file_rel, GError **error)
+{
+	gboolean ret;
+	GError *error_local = NULL;
+	gchar *text;
+
+	/* reset */
+	ret = pk_client_reset (gclient->priv->client_action, &error_local);
+	if (!ret) {
+		gpk_client_error_msg (gclient, _("Failed to reset client"), _("Failed to reset resolve"));
+		gpk_client_error_set (error, GPK_CLIENT_ERROR_FAILED, error_local->message);
+		g_error_free (error_local);
+		return FALSE;
+	}
+
+	/* install local file */
+	ret = pk_client_install_file (gclient->priv->client_action, trusted, file_rel, &error_local);
+	if (ret) {
+		return TRUE;
+	}
+
+	/* check if we got a permission denied */
+	if (g_str_has_prefix (error_local->message, "org.freedesktop.packagekit.")) {
+		gpk_client_error_msg (gclient, _("Failed to install file"),
+				      _("You don't have the necessary privileges to install local files"));
+		gpk_client_error_set (error, GPK_CLIENT_ERROR_FAILED, error_local->message);
+	} else {
+		text = g_markup_escape_text (error_local->message, -1);
+		gpk_client_error_msg (gclient, _("Failed to install file"), text);
+		g_free (text);
+		gpk_client_error_set (error, GPK_CLIENT_ERROR_FAILED, error_local->message);
+	}
+	g_error_free (error_local);
+	return FALSE;
+}
+
+/**
  * gpk_client_install_local_file:
  * @gclient: a valid #GpkClient instance
  * @file_rel: a file such as <literal>./hal-devel-0.10.0.rpm</literal>
@@ -393,8 +550,6 @@
 gpk_client_install_local_file (GpkClient *gclient, const gchar *file_rel, GError **error)
 {
 	gboolean ret;
-	GError *error_local = NULL;
-	gchar *text;
 	GtkWidget *widget;
 
 	g_return_val_if_fail (GPK_IS_CLIENT (gclient), FALSE);
@@ -404,26 +559,25 @@
 	widget = glade_xml_get_widget (gclient->priv->glade_xml, "window_updates");
 	gtk_widget_show (widget);
 
-	ret = pk_client_install_file (gclient->priv->client_action, file_rel, &error_local);
+	gclient->priv->retry_untrusted_value = FALSE;
+	ret = gpk_client_install_local_file_internal (gclient, TRUE, file_rel, error);
 	if (!ret) {
-		/* check if we got a permission denied */
-		if (g_str_has_prefix (error_local->message, "org.freedesktop.packagekit.")) {
-			gpk_client_error_msg (gclient, _("Failed to install file"),
-					      _("You don't have the necessary privileges to install local files"));
-			gpk_client_error_set (error, GPK_CLIENT_ERROR_FAILED, error_local->message);
-		} else {
-			text = g_markup_escape_text (error_local->message, -1);
-			gpk_client_error_msg (gclient, _("Failed to install file"), text);
-			g_free (text);
-			gpk_client_error_set (error, GPK_CLIENT_ERROR_FAILED, error_local->message);
-		}
-		g_error_free (error_local);
 		goto out;
 	}
 
 	/* wait for completion */
 	gtk_main ();
 
+	/* do we need to try again with better auth? */
+	if (gclient->priv->retry_untrusted_value) {
+		ret = gpk_client_install_local_file_internal (gclient, FALSE, file_rel, error);
+		if (!ret) {
+			goto out;
+		}
+		/* wait again */
+		gtk_main ();
+	}
+
 	/* we're done */
 	if (gclient->priv->pulse_timeout != 0) {
 		g_source_remove (gclient->priv->pulse_timeout);

Modified: trunk/src/gpk-common.c
==============================================================================
--- trunk/src/gpk-common.c	(original)
+++ trunk/src/gpk-common.c	Tue Apr 22 18:30:13 2008
@@ -433,6 +433,9 @@
 	case PK_ERROR_ENUM_BAD_GPG_SIGNATURE:
 		text = _("Bad GPG signature");
 		break;
+	case PK_ERROR_ENUM_MISSING_GPG_SIGNATURE:
+		text = _("Missing GPG signature");
+		break;
 	case PK_ERROR_ENUM_REPO_CONFIGURATION_ERROR:
 		text = _("Repository configuration invalid");
 		break;
@@ -569,7 +572,11 @@
 			 "More information is available in the detailed report.");
 		break;
 	case PK_ERROR_ENUM_BAD_GPG_SIGNATURE:
-		text = _("The software source signature could not be verified.");
+		text = _("The package signature could not be verified.");
+		break;
+	case PK_ERROR_ENUM_MISSING_GPG_SIGNATURE:
+		text = _("The package signature was missing and this package is untrusted.\n"
+			 "This package was not signed with a GPG key when created.");
 		break;
 	case PK_ERROR_ENUM_REPO_CONFIGURATION_ERROR:
 		text = _("Repository configuration was invalid and could not be read.");

Added: trunk/src/gpk-firmware.c
==============================================================================
--- (empty file)
+++ trunk/src/gpk-firmware.c	Tue Apr 22 18:30:13 2008
@@ -0,0 +1,200 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gconf/gconf-client.h>
+
+#include <pk-debug.h>
+#include <pk-client.h>
+#include <pk-common.h>
+#include <pk-task-list.h>
+
+#include <gpk-client.h>
+#include <gpk-common.h>
+
+#include "gpk-firmware.h"
+#include "gpk-smart-icon.h"
+
+static void     gpk_firmware_class_init	(GpkFirmwareClass *klass);
+static void     gpk_firmware_init	(GpkFirmware      *firmware);
+static void     gpk_firmware_finalize	(GObject	  *object);
+
+#define GPK_FIRMWARE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPK_TYPE_FIRMWARE, GpkFirmwarePrivate))
+#define GPK_FIRMWARE_STATE_FILE		"/var/run/PackageKit/udev-firmware"
+#define GPK_FIRMWARE_LOGIN_DELAY	1 /* seconds */
+
+struct GpkFirmwarePrivate
+{
+	GpkSmartIcon		*sicon;
+	gchar			**files;
+};
+
+G_DEFINE_TYPE (GpkFirmware, gpk_firmware, G_TYPE_OBJECT)
+
+static gboolean
+gpk_firmware_timeout_cb (gpointer data)
+{
+	const gchar *message;
+	GpkFirmware *firmware = (GpkFirmware *) data;
+
+	message = _("Additional firmware is required to make hardware in this computer function correctly.");
+	gpk_smart_icon_notify_new (firmware->priv->sicon, _("Additional firmware required"), message,
+				   "help-browser", GPK_NOTIFY_URGENCY_LOW, GPK_NOTIFY_TIMEOUT_NEVER);
+	gpk_smart_icon_notify_button (firmware->priv->sicon, GPK_NOTIFY_BUTTON_INSTALL_FIRMWARE, NULL);
+	gpk_smart_icon_notify_button (firmware->priv->sicon, GPK_NOTIFY_BUTTON_DO_NOT_SHOW_AGAIN, GPK_CONF_PROMPT_FIRMWARE);
+	gpk_smart_icon_notify_show (firmware->priv->sicon);
+
+	return FALSE;
+}
+
+/**
+ * gpk_firmware_install_file:
+ **/
+static gboolean
+gpk_firmware_install_file (GpkFirmware *firmware)
+{
+	GpkClient *gclient;
+	gboolean ret;
+
+	gclient = gpk_client_new ();
+	ret = gpk_client_install_provide_file (gclient, firmware->priv->files[0], NULL);
+	g_object_unref (gclient);
+	return ret;
+}
+
+/**
+ * gpk_firmware_smart_icon_notify_button:
+ **/
+static void
+gpk_firmware_smart_icon_notify_button (GpkSmartIcon *sicon, GpkNotifyButton button,
+				       const gchar *data, GpkFirmware *firmware)
+{
+	pk_debug ("got: %i with data %s", button, data);
+	/* find the localised text */
+	if (button == GPK_NOTIFY_BUTTON_INSTALL_FIRMWARE) {
+		gpk_firmware_install_file (firmware);
+	}
+}
+
+/**
+ * gpk_firmware_class_init:
+ * @klass: The GpkFirmwareClass
+ **/
+static void
+gpk_firmware_class_init (GpkFirmwareClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gpk_firmware_finalize;
+	g_type_class_add_private (klass, sizeof (GpkFirmwarePrivate));
+}
+
+/**
+ * gpk_firmware_init:
+ * @firmware: This class instance
+ **/
+static void
+gpk_firmware_init (GpkFirmware *firmware)
+{
+	gboolean ret;
+	gchar *files;
+	GError *error = NULL;
+
+	firmware->priv = GPK_FIRMWARE_GET_PRIVATE (firmware);
+	firmware->priv->files = NULL;
+	firmware->priv->sicon = gpk_smart_icon_new ();
+	g_signal_connect (firmware->priv->sicon, "notification-button",
+			  G_CALLBACK (gpk_firmware_smart_icon_notify_button), firmware);
+
+	/* file exists? */
+	ret = g_file_test (GPK_FIRMWARE_STATE_FILE, G_FILE_TEST_EXISTS);
+	if (!ret) {
+		pk_debug ("file '%s' not found", GPK_FIRMWARE_STATE_FILE);
+		return;
+	}
+	/* can we get the contents */
+	ret = g_file_get_contents (GPK_FIRMWARE_STATE_FILE, &files, NULL, &error);
+	if (!ret) {
+		pk_warning ("can't open file %s, %s", GPK_FIRMWARE_STATE_FILE, error->message);
+		g_error_free (error);
+		return;
+	}
+
+	/* split, as we can use multiple lines */
+	firmware->priv->files = g_strsplit (files, "\n", 0);
+
+	/* file already exists */
+	ret = g_file_test (firmware->priv->files[0], G_FILE_TEST_EXISTS);
+	if (ret) {
+		pk_debug ("file '%s' already exists", firmware->priv->files[0]);
+		return;
+	}
+
+	/* don't spam the user at startup */
+	g_timeout_add_seconds (GPK_FIRMWARE_LOGIN_DELAY, gpk_firmware_timeout_cb, firmware);
+}
+
+/**
+ * gpk_firmware_finalize:
+ * @object: The object to finalize
+ **/
+static void
+gpk_firmware_finalize (GObject *object)
+{
+	GpkFirmware *firmware;
+
+	g_return_if_fail (GPK_IS_FIRMWARE (object));
+
+	firmware = GPK_FIRMWARE (object);
+
+	g_return_if_fail (firmware->priv != NULL);
+	g_strfreev (firmware->priv->files);
+	g_object_unref (firmware->priv->sicon);
+
+	G_OBJECT_CLASS (gpk_firmware_parent_class)->finalize (object);
+}
+
+/**
+ * gpk_firmware_new:
+ *
+ * Return value: a new GpkFirmware object.
+ **/
+GpkFirmware *
+gpk_firmware_new (void)
+{
+	GpkFirmware *firmware;
+	firmware = g_object_new (GPK_TYPE_FIRMWARE, NULL);
+	return GPK_FIRMWARE (firmware);
+}
+

Added: trunk/src/gpk-firmware.h
==============================================================================
--- (empty file)
+++ trunk/src/gpk-firmware.h	Tue Apr 22 18:30:13 2008
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GPK_FIRMWARE_H
+#define __GPK_FIRMWARE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GPK_TYPE_FIRMWARE		(gpk_firmware_get_type ())
+#define GPK_FIRMWARE(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GPK_TYPE_FIRMWARE, GpkFirmware))
+#define GPK_FIRMWARE_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GPK_TYPE_FIRMWARE, GpkFirmwareClass))
+#define GPK_IS_FIRMWARE(o)	 	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GPK_TYPE_FIRMWARE))
+#define GPK_IS_FIRMWARE_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GPK_TYPE_FIRMWARE))
+#define GPK_FIRMWARE_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GPK_TYPE_FIRMWARE, GpkFirmwareClass))
+#define GPK_FIRMWARE_ERROR		(gpk_firmware_error_quark ())
+#define GPK_FIRMWARE_TYPE_ERROR		(gpk_firmware_error_get_type ())
+
+typedef struct GpkFirmwarePrivate GpkFirmwarePrivate;
+
+typedef struct
+{
+	 GObject		 parent;
+	 GpkFirmwarePrivate	*priv;
+} GpkFirmware;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+} GpkFirmwareClass;
+
+GType		 gpk_firmware_get_type		  	(void) G_GNUC_CONST;
+GpkFirmware	*gpk_firmware_new			(void);
+
+G_END_DECLS
+
+#endif /* __GPK_FIRMWARE_H */



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