gnome-packagekit r119 - trunk/src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-packagekit r119 - trunk/src
- Date: Sun, 16 Mar 2008 22:25:12 +0000 (GMT)
Author: rhughes
Date: Sun Mar 16 22:25:12 2008
New Revision: 119
URL: http://svn.gnome.org/viewvc/gnome-packagekit?rev=119&view=rev
Log:
from git
Modified:
trunk/src/pk-common-gui.c
trunk/src/pk-common-gui.h
trunk/src/pk-notify.c
trunk/src/pk-watch.c
Modified: trunk/src/pk-common-gui.c
==============================================================================
--- trunk/src/pk-common-gui.c (original)
+++ trunk/src/pk-common-gui.c Sun Mar 16 22:25:12 2008
@@ -26,6 +26,7 @@
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
+#include <dbus/dbus-glib.h>
#include <pk-debug.h>
#include <pk-package-id.h>
@@ -154,6 +155,42 @@
};
/**
+ * pk_restart_system:
+ **/
+gboolean
+pk_restart_system (void)
+{
+ DBusGProxy *proxy;
+ DBusGConnection *connection;
+ GError *error = NULL;
+ gboolean ret;
+
+ /* check dbus connections, exit if not valid */
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (error != NULL) {
+ pk_warning ("cannot acccess the session bus: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ /* get a connection */
+ proxy = dbus_g_proxy_new_for_name (connection, GPM_DBUS_SERVICE, GPM_DBUS_PATH, GPM_DBUS_INTERFACE);
+ if (proxy == NULL) {
+ pk_warning ("Cannot connect to gnome-power-manager");
+ return FALSE;
+ }
+
+ /* do the method */
+ ret = dbus_g_proxy_call (proxy, "Reboot", &error, G_TYPE_INVALID, G_TYPE_INVALID);
+ if (!ret) {
+ pk_warning ("cannot reboot: %s", error->message);
+ g_error_free (error);
+ }
+ g_object_unref (G_OBJECT (proxy));
+ return ret;
+}
+
+/**
* pk_execute_url:
**/
gboolean
Modified: trunk/src/pk-common-gui.h
==============================================================================
--- trunk/src/pk-common-gui.h (original)
+++ trunk/src/pk-common-gui.h Sun Mar 16 22:25:12 2008
@@ -64,6 +64,7 @@
gboolean pk_error_modal_dialog (const gchar *title,
const gchar *message);
gboolean pk_execute_url (const gchar *url);
+gboolean pk_restart_system (void);
const gchar *pk_role_enum_to_localised_past (PkRoleEnum role);
const gchar *pk_role_enum_to_localised_present (PkRoleEnum role);
const gchar *pk_role_enum_to_icon_name (PkRoleEnum role);
Modified: trunk/src/pk-notify.c
==============================================================================
--- trunk/src/pk-notify.c (original)
+++ trunk/src/pk-notify.c Sun Mar 16 22:25:12 2008
@@ -297,6 +297,13 @@
pk_notify_update_system_finished_cb (PkClient *client, PkExitEnum exit_code, guint runtime, PkNotify *notify)
{
PkRestartEnum restart;
+ guint i;
+ guint length;
+ PkPackageId *ident;
+ PkPackageItem *item;
+ GString *message_text;
+ guint skipped_number = 0;
+ const gchar *message;
g_return_if_fail (notify != NULL);
g_return_if_fail (PK_IS_NOTIFY (notify));
@@ -308,23 +315,70 @@
pk_notify_query_updates (notify);
}
- /* close the libnotify bubble if it exists */
- pk_smart_icon_notify_close (notify->priv->sicon);
+ /* check we got some packages */
+ length = pk_client_package_buffer_get_size (client);
+ pk_debug ("length=%i", length);
+ if (length == 0) {
+ pk_debug ("no updates");
+ return;
+ }
+
+ message_text = g_string_new ("");
+
+ /* find any we skipped */
+ for (i=0; i<length; i++) {
+ item = pk_client_package_buffer_get_item (client, i);
+ pk_debug ("%s, %s, %s", pk_info_enum_to_text (item->info),
+ item->package_id, item->summary);
+ ident = pk_package_id_new_from_string (item->package_id);
+ if (item->info == PK_INFO_ENUM_BLOCKED) {
+ skipped_number++;
+ g_string_append_printf (message_text, "<b>%s</b> - %s\n",
+ ident->name, item->summary);
+ }
+ pk_package_id_free (ident);
+ }
+
+ /* notify the user if there were skipped entries */
+ if (skipped_number > 0) {
+ message = ngettext (_("One package was skipped:\n"),
+ _("Some packages were skipped:\n"), skipped_number);
+ g_string_prepend (message_text, message);
+ }
+ /* add a message that we need to restart */
restart = pk_client_get_require_restart (client);
if (restart != PK_RESTART_ENUM_NONE) {
- const gchar *message;
message = pk_restart_enum_to_localised_text (restart);
- pk_debug ("Doing requires-restart notification");
- pk_smart_icon_notify_new (notify->priv->sicon,
- _("The system update has completed"), message, "software-update-available",
- PK_NOTIFY_URGENCY_LOW, PK_NOTIFY_TIMEOUT_LONG);
+ /* add a gap if we are putting both */
+ if (skipped_number > 0) {
+ g_string_append (message_text, "\n");
+ }
+
+ g_string_append (message_text, message);
+ g_string_append (message_text, "\n");
+ }
+
+ /* trim off extra newlines */
+ if (message_text->len != 0) {
+ g_string_set_size (message_text, message_text->len-1);
+ }
+
+ /* do the notify, and show the right buttons */
+ pk_debug ("Doing notification");
+ pk_smart_icon_notify_new (notify->priv->sicon,
+ _("The system update has completed"), message_text->str,
+ "software-update-available",
+ PK_NOTIFY_URGENCY_LOW, PK_NOTIFY_TIMEOUT_LONG);
+ if (restart == PK_RESTART_ENUM_SYSTEM) {
pk_smart_icon_notify_button (notify->priv->sicon, PK_NOTIFY_BUTTON_RESTART_COMPUTER, NULL);
- pk_smart_icon_notify_button (notify->priv->sicon, PK_NOTIFY_BUTTON_DO_NOT_SHOW_AGAIN, PK_CONF_NOTIFY_RESTART);
- pk_smart_icon_notify_show (notify->priv->sicon);
}
+ pk_smart_icon_notify_button (notify->priv->sicon, PK_NOTIFY_BUTTON_DO_NOT_SHOW_AGAIN, PK_CONF_NOTIFY_RESTART);
+ pk_smart_icon_notify_show (notify->priv->sicon);
+
pk_debug ("resetting client %p", client);
+ g_string_free (message_text, TRUE);
pk_client_reset (client, NULL);
}
@@ -829,6 +883,8 @@
pk_notify_smart_icon_notify_button (PkSmartIcon *sicon, PkNotifyButton button,
const gchar *data, PkNotify *notify)
{
+ gboolean ret;
+
g_return_if_fail (notify != NULL);
g_return_if_fail (PK_IS_NOTIFY (notify));
@@ -856,7 +912,11 @@
} else if (button == PK_NOTIFY_BUTTON_UPDATE_COMPUTER) {
pk_notify_update_system (notify);
} else if (button == PK_NOTIFY_BUTTON_RESTART_COMPUTER) {
- pk_warning ("reboot now");
+ /* restart using gnome-power-manager */
+ ret = pk_restart_system ();
+ if (!ret) {
+ pk_warning ("failed to reboot");
+ }
}
}
@@ -901,6 +961,7 @@
/* use a client to get the updates-changed signal */
notify->priv->client_update_system = pk_client_new ();
+ pk_client_set_use_buffer (notify->priv->client_update_system, TRUE, NULL);
g_signal_connect (notify->priv->client_update_system, "updates-changed",
G_CALLBACK (pk_notify_updates_changed_cb), notify);
g_signal_connect (notify->priv->client_update_system, "finished",
Modified: trunk/src/pk-watch.c
==============================================================================
--- trunk/src/pk-watch.c (original)
+++ trunk/src/pk-watch.c Sun Mar 16 22:25:12 2008
@@ -61,6 +61,7 @@
{
PkClient *client;
PkSmartIcon *sicon;
+ PkSmartIcon *sicon_restart;
PkInhibit *inhibit;
PkConnection *pconnection;
PkTaskList *tlist;
@@ -252,13 +253,26 @@
gboolean ret;
gboolean value;
PkRoleEnum role;
+ PkRestartEnum restart;
gchar *package_id;
gchar *message = NULL;
gchar *package;
+ const gchar *restart_message;
+ const gchar *icon_name;
g_return_if_fail (watch != NULL);
g_return_if_fail (PK_IS_WATCH (watch));
+ /* show an icon if the user needs to reboot */
+ restart = pk_client_get_require_restart (client);
+ if (restart == PK_RESTART_ENUM_SYSTEM ||
+ restart == PK_RESTART_ENUM_SESSION) {
+ restart_message = pk_restart_enum_to_localised_text (restart);
+ icon_name = pk_restart_enum_to_icon_name (restart);
+ pk_smart_icon_set_tooltip (watch->priv->sicon_restart, restart_message);
+ pk_smart_icon_set_icon_name (watch->priv->sicon_restart, icon_name);
+ }
+
/* is it worth showing a UI? */
if (runtime < 3000) {
pk_debug ("no notification, too quick");
@@ -541,6 +555,25 @@
}
/**
+ * pk_watch_restart_cb:
+ **/
+static void
+pk_watch_restart_cb (GtkMenuItem *item, gpointer data)
+{
+ gboolean ret;
+ PkWatch *watch = PK_WATCH (data);
+
+ g_return_if_fail (watch != NULL);
+ g_return_if_fail (PK_IS_WATCH (watch));
+
+ /* restart using gnome-power-manager */
+ ret = pk_restart_system ();
+ if (!ret) {
+ pk_warning ("failed to reboot");
+ }
+}
+
+/**
* pk_watch_refresh_cache_cb:
**/
static void
@@ -707,6 +740,39 @@
}
/**
+ * pk_watch_activate_status_restart_cb:
+ * @button: Which buttons are pressed
+ *
+ * Callback when the icon is clicked
+ **/
+static void
+pk_watch_activate_status_restart_cb (GtkStatusIcon *status_icon, PkWatch *watch)
+{
+ GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
+ GtkWidget *widget;
+ GtkWidget *image;
+
+ g_return_if_fail (watch != NULL);
+ g_return_if_fail (PK_IS_WATCH (watch));
+
+ pk_debug ("icon left clicked");
+
+ /* restart computer */
+ widget = gtk_image_menu_item_new_with_mnemonic (_("_Restart computer"));
+ image = gtk_image_new_from_icon_name ("system-shutdown", GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
+ g_signal_connect (G_OBJECT (widget), "activate",
+ G_CALLBACK (pk_watch_restart_cb), watch);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
+
+ /* show the menu */
+ gtk_widget_show_all (GTK_WIDGET (menu));
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ gtk_status_icon_position_menu, status_icon,
+ 1, gtk_get_current_event_time());
+}
+
+/**
* pk_connection_changed_cb:
**/
static void
@@ -753,6 +819,7 @@
watch->priv->show_refresh_in_menu = TRUE;
watch->priv->gconf_client = gconf_client_get_default ();
watch->priv->sicon = pk_smart_icon_new ();
+ watch->priv->sicon_restart = pk_smart_icon_new ();
/* we need to get ::locked */
watch->priv->client = pk_client_new ();
@@ -772,13 +839,14 @@
/* right click actions are common */
status_icon = pk_smart_icon_get_status_icon (watch->priv->sicon);
g_signal_connect_object (G_OBJECT (status_icon),
- "popup_menu",
- G_CALLBACK (pk_watch_popup_menu_cb),
- watch, 0);
+ "popup_menu", G_CALLBACK (pk_watch_popup_menu_cb), watch, 0);
+ g_signal_connect_object (G_OBJECT (status_icon),
+ "activate", G_CALLBACK (pk_watch_activate_status_cb), watch, 0);
+
+ /* provide the user with a way to restart */
+ status_icon = pk_smart_icon_get_status_icon (watch->priv->sicon_restart);
g_signal_connect_object (G_OBJECT (status_icon),
- "activate",
- G_CALLBACK (pk_watch_activate_status_cb),
- watch, 0);
+ "activate", G_CALLBACK (pk_watch_activate_status_restart_cb), watch, 0);
watch->priv->tlist = pk_task_list_new ();
g_signal_connect (watch->priv->tlist, "task-list-changed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]