[gnome-packagekit] Never, ever, show a second status area notification
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-packagekit] Never, ever, show a second status area notification
- Date: Sun, 1 Aug 2010 12:53:40 +0000 (UTC)
commit 5d292f8687f17baf7d8ca4f043cf8a35ecae6a9b
Author: Richard Hughes <richard hughsie com>
Date: Sun Aug 1 13:53:22 2010 +0100
Never, ever, show a second status area notification
contrib/gnome-packagekit.spec.in | 1 -
data/org.gnome.packagekit.gschema.xml | 4 -
src/cc-update-panel.c | 3 +-
src/gpk-check-update.c | 34 +-
src/gpk-check-update.h | 2 +
src/gpk-common.h | 1 -
src/gpk-update-icon.c | 7 +
src/gpk-watch.c | 830 ++++-----------------------------
src/gpk-watch.h | 2 +
9 files changed, 123 insertions(+), 761 deletions(-)
---
diff --git a/contrib/gnome-packagekit.spec.in b/contrib/gnome-packagekit.spec.in
index 3ae1a05..42b0756 100644
--- a/contrib/gnome-packagekit.spec.in
+++ b/contrib/gnome-packagekit.spec.in
@@ -133,7 +133,6 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%{_datadir}/gnome-packagekit/gpk-update-viewer.ui
%{_datadir}/gnome-packagekit/gpk-error.ui
%{_datadir}/gnome-packagekit/gpk-log.ui
-%{_datadir}/gnome-packagekit/gpk-repo.ui
%{_datadir}/gnome-packagekit/gpk-signature.ui
%dir %{_datadir}/gnome-packagekit/icons
%dir %{_datadir}/gnome-packagekit/icons/hicolor
diff --git a/data/org.gnome.packagekit.gschema.xml b/data/org.gnome.packagekit.gschema.xml
index 5e14085..f3f586a 100644
--- a/data/org.gnome.packagekit.gschema.xml
+++ b/data/org.gnome.packagekit.gschema.xml
@@ -119,10 +119,6 @@
<summary>Use WiFi connections</summary>
<description>Use WiFi (wireless LAN) connections to check for updates.</description>
</key>
- <key name="watch-active-transactions" type="b">
- <default>false</default>
- <summary>Show transactions that have the original application running</summary>
- </key>
<key name="autocomplete" type="b">
<default>false</default>
<summary>If search terms should be completed automatically</summary>
diff --git a/src/cc-update-panel.c b/src/cc-update-panel.c
index 32c07bb..1fc302f 100644
--- a/src/cc-update-panel.c
+++ b/src/cc-update-panel.c
@@ -427,7 +427,6 @@ cc_update_panel_status_changed_timeout_cb (CcUpdatePanel *panel)
static void
cc_update_panel_progress_cb (PkProgress *progress, PkProgressType type, CcUpdatePanel *panel)
{
- PkStatusEnum status;
GtkWidget *widget;
if (type != PK_PROGRESS_TYPE_STATUS)
@@ -437,7 +436,7 @@ cc_update_panel_progress_cb (PkProgress *progress, PkProgressType type, CcUpdate
g_object_get (progress,
"status", &panel->priv->status,
NULL);
- egg_debug ("now %s", pk_status_enum_to_text (status));
+ egg_debug ("now %s", pk_status_enum_to_text (panel->priv->status));
if (panel->priv->status == PK_STATUS_ENUM_FINISHED) {
/* we've not yet shown, so don't bother */
diff --git a/src/gpk-check-update.c b/src/gpk-check-update.c
index 79f4b9d..226221a 100644
--- a/src/gpk-check-update.c
+++ b/src/gpk-check-update.c
@@ -1470,6 +1470,26 @@ out:
}
/**
+ * gpk_check_update_set_status_icon:
+ **/
+void
+gpk_check_update_set_status_icon (GpkCheckUpdate *cupdate, GtkStatusIcon *status_icon)
+{
+ g_assert (cupdate->priv->status_icon == NULL);
+ cupdate->priv->status_icon = g_object_ref (status_icon);
+
+ /* right click actions are common */
+ g_signal_connect_object (G_OBJECT (cupdate->priv->status_icon),
+ "popup_menu",
+ G_CALLBACK (gpk_check_update_popup_menu_cb),
+ cupdate, 0);
+ g_signal_connect_object (G_OBJECT (cupdate->priv->status_icon),
+ "activate",
+ G_CALLBACK (gpk_check_update_activate_update_cb),
+ cupdate, 0);
+}
+
+/**
* gpk_check_update_init:
* @cupdate: This class instance
**/
@@ -1486,7 +1506,6 @@ gpk_check_update_init (GpkCheckUpdate *cupdate)
cupdate->priv->notification_error = NULL;
cupdate->priv->gicon = NULL;
cupdate->priv->number_updates_critical_last_shown = 0;
- cupdate->priv->status_icon = gtk_status_icon_new ();
cupdate->priv->cancellable = g_cancellable_new ();
cupdate->priv->error_code = NULL;
cupdate->priv->settings = g_settings_new (GPK_SETTINGS_SCHEMA);
@@ -1499,16 +1518,6 @@ gpk_check_update_init (GpkCheckUpdate *cupdate)
g_signal_connect (cupdate->priv->arefresh, "get-upgrades",
G_CALLBACK (gpk_check_update_auto_get_upgrades_cb), cupdate);
- /* right click actions are common */
- g_signal_connect_object (G_OBJECT (cupdate->priv->status_icon),
- "popup_menu",
- G_CALLBACK (gpk_check_update_popup_menu_cb),
- cupdate, 0);
- g_signal_connect_object (G_OBJECT (cupdate->priv->status_icon),
- "activate",
- G_CALLBACK (gpk_check_update_activate_update_cb),
- cupdate, 0);
-
cupdate->priv->dbus_monitor_viewer = egg_dbus_monitor_new ();
egg_dbus_monitor_assign (cupdate->priv->dbus_monitor_viewer,
EGG_DBUS_MONITOR_SESSION,
@@ -1568,7 +1577,8 @@ gpk_check_update_finalize (GObject *object)
g_return_if_fail (cupdate->priv != NULL);
- g_object_unref (cupdate->priv->status_icon);
+ if (cupdate->priv->status_icon != NULL)
+ g_object_unref (cupdate->priv->status_icon);
g_object_unref (cupdate->priv->tlist);
g_object_unref (cupdate->priv->arefresh);
g_object_unref (cupdate->priv->settings);
diff --git a/src/gpk-check-update.h b/src/gpk-check-update.h
index e813979..a7b278a 100644
--- a/src/gpk-check-update.h
+++ b/src/gpk-check-update.h
@@ -50,6 +50,8 @@ typedef struct
GType gpk_check_update_get_type (void);
GpkCheckUpdate *gpk_check_update_new (void);
+void gpk_check_update_set_status_icon (GpkCheckUpdate *check_update,
+ GtkStatusIcon *status_icon);
G_END_DECLS
diff --git a/src/gpk-common.h b/src/gpk-common.h
index b79dd93..174469c 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -79,7 +79,6 @@ G_BEGIN_DECLS
#define GPK_SETTINGS_SHOW_COPY_CONFIRM "show-copy-confirm"
#define GPK_SETTINGS_SHOW_DEPENDS "show-depends"
#define GPK_SETTINGS_UPDATE_BATTERY "update-battery"
-#define GPK_SETTINGS_WATCH_ACTIVE_TRANSACTIONS "watch-active-transactions"
#define GPK_BUGZILLA_URL "https://bugs.freedesktop.org/"
diff --git a/src/gpk-update-icon.c b/src/gpk-update-icon.c
index 8437f2a..603bd34 100644
--- a/src/gpk-update-icon.c
+++ b/src/gpk-update-icon.c
@@ -66,6 +66,7 @@ main (int argc, char *argv[])
GpkWatch *watch = NULL;
GpkFirmware *firmware = NULL;
GpkHardware *hardware = NULL;
+ GtkStatusIcon *status_icon;
GOptionContext *context;
GtkApplication *application;
gboolean ret;
@@ -127,6 +128,11 @@ main (int argc, char *argv[])
firmware = gpk_firmware_new ();
hardware = gpk_hardware_new ();
+ /* assign status area notification */
+ status_icon = gtk_status_icon_new ();
+ gpk_watch_set_status_icon (watch, status_icon);
+ gpk_check_update_set_status_icon (cupdate, status_icon);
+
/* Only timeout if we have specified iton the command line */
if (timed_exit) {
timer_id = g_timeout_add_seconds (120, (GSourceFunc) gpk_icon_timed_exit_cb, application);
@@ -138,6 +144,7 @@ main (int argc, char *argv[])
/* run */
gtk_application_run (application);
+ g_object_unref (status_icon);
g_object_unref (cupdate);
g_object_unref (watch);
g_object_unref (firmware);
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 1f933e7..d40fe62 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -56,7 +56,6 @@
static void gpk_watch_finalize (GObject *object);
#define GPK_WATCH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPK_TYPE_WATCH, GpkWatchPrivate))
-#define GPK_WATCH_MAXIMUM_TOOLTIP_LINES 10
#define GPK_WATCH_SET_PROXY_RATE_LIMIT 200 /* ms */
struct GpkWatchPrivate
@@ -65,15 +64,14 @@ struct GpkWatchPrivate
GtkStatusIcon *status_icon;
GPtrArray *restart_package_names;
NotifyNotification *notification_message;
+ NotifyNotification *notification_restart;
GpkInhibit *inhibit;
- GpkModalDialog *dialog;
PkTask *task;
PkTransactionList *tlist;
PkRestartEnum restart;
GSettings *settings;
guint set_proxy_id;
gchar *error_details;
- gboolean hide_warning;
EggConsoleKit *console;
GCancellable *cancellable;
GPtrArray *array_progress;
@@ -94,245 +92,6 @@ gpk_watch_class_init (GpkWatchClass *klass)
g_type_class_add_private (klass, sizeof (GpkWatchPrivate));
}
-/**
- * gpk_watch_get_restart_required_tooltip:
- **/
-static gchar *
-gpk_watch_get_restart_required_tooltip (GpkWatch *watch)
-{
- gchar *package_loc = NULL;
- gchar **packages = NULL;
- guint len;
- const gchar *title;
- gchar *message = NULL;
- gchar *text = NULL;
-
- /* nothing */
- if (watch->priv->restart == PK_RESTART_ENUM_NONE)
- goto out;
-
- /* size */
- len = watch->priv->restart_package_names->len;
- if (len == 0)
- goto out;
-
- /* localised title */
- title = gpk_restart_enum_to_localised_text (watch->priv->restart);
-
- /* non-security require */
- if (watch->priv->restart == PK_RESTART_ENUM_SESSION ||
- watch->priv->restart == PK_RESTART_ENUM_SYSTEM) {
-
- /* get localised list */
- packages = pk_ptr_array_to_strv (watch->priv->restart_package_names);
- package_loc = gpk_strv_join_locale (packages);
- if (package_loc != NULL) {
- /* TRANSLATORS: a list of packages is shown that need to restarted */
- message = g_strdup_printf (ngettext ("This is due to the %s package being updated.",
- "This is due to the following packages being updated: %s.", len), package_loc);
- } else {
- /* TRANSLATORS: over 5 packages require the system to be restarted, don't list them all here */
- message = g_strdup_printf (ngettext ("This is because %i package has been updated.",
- "This is because %i packages have been updated.", len), len);
- }
-
- /* join */
- text = g_strdup_printf ("%s %s", title, message);
- goto out;
- }
-
- /* just use title, as security requires are not the package that are updated */
- text = g_strdup (title);
-out:
- g_strfreev (packages);
- g_free (package_loc);
- g_free (message);
- return text;
-}
-
-/**
- * gpk_watch_refresh_tooltip:
- **/
-static gboolean
-gpk_watch_refresh_tooltip (GpkWatch *watch)
-{
- guint i;
- guint idx = 0;
- PkProgress *progress;
- GString *string;
- PkStatusEnum status;
- PkRoleEnum role;
- gchar *text;
- GPtrArray *array;
-
- g_return_val_if_fail (GPK_IS_WATCH (watch), FALSE);
-
- string = g_string_new ("");
- array = watch->priv->array_progress;
- egg_debug ("refresh tooltip %i", array->len);
- if (array->len == 0) {
-
- /* any restart required? */
- text = gpk_watch_get_restart_required_tooltip (watch);
- if (text != NULL)
- g_string_append (string, text);
- g_free (text);
-
- egg_debug ("nothing to show");
- goto out;
- }
-
- /* print all the running transactions */
- for (i=0; i<array->len; i++) {
- progress = g_ptr_array_index (array, i);
- g_object_get (progress,
- "role", &role,
- "status", &status,
- NULL);
-
- /* ignore boring status values */
- if (status == PK_STATUS_ENUM_FINISHED)
- continue;
-
- /* should we display the text */
- g_string_append_printf (string, "%s: %s\n", gpk_role_enum_to_localised_present (role), gpk_status_enum_to_localised_text (status));
-
- /* don't fill the screen with a giant tooltip */
- if (idx++ > GPK_WATCH_MAXIMUM_TOOLTIP_LINES)
- break;
- }
-
- /* remove trailing newline */
- if (string->len > 0)
- g_string_set_size (string, string->len-1);
-out:
- gtk_status_icon_set_tooltip_text (watch->priv->status_icon, string->str);
- g_string_free (string, TRUE);
- return TRUE;
-}
-
-/**
- * gpk_watch_task_list_to_status_bitfield:
- **/
-static PkBitfield
-gpk_watch_task_list_to_status_bitfield (GpkWatch *watch)
-{
- gboolean active;
- gboolean watch_active;
- guint i;
- PkBitfield bitfield = 0;
- PkStatusEnum status;
- PkProgress *progress;
- gchar *transaction_id;
- GPtrArray *array;
-
- g_return_val_if_fail (GPK_IS_WATCH (watch), 0);
-
- /* shortcut */
- array = watch->priv->array_progress;
- if (array->len == 0)
- goto out;
-
- /* do we watch active transactions */
- watch_active = g_settings_get_boolean (watch->priv->settings, GPK_SETTINGS_WATCH_ACTIVE_TRANSACTIONS);
-
- /* add each status to a list */
- for (i=0; i<array->len; i++) {
- progress = g_ptr_array_index (array, i);
-
- /* only show an icon for this if the application isn't still on the bus */
- g_object_get (progress,
- "caller-active", &active,
- "status", &status,
- "transaction-id", &transaction_id,
- NULL);
-
- /* add to bitfield calculation */
- egg_debug ("%s %s (active:%i)", transaction_id, pk_status_enum_to_text (status), active);
- if ((!active || watch_active) && status != PK_STATUS_ENUM_FINISHED)
- pk_bitfield_add (bitfield, status);
- g_free (transaction_id);
- }
-out:
- return bitfield;
-}
-
-/**
- * gpk_watch_refresh_icon:
- **/
-static gboolean
-gpk_watch_refresh_icon (GpkWatch *watch)
-{
- const gchar *icon_name = NULL;
- PkBitfield status;
- gint value = -1;
-
- g_return_val_if_fail (GPK_IS_WATCH (watch), FALSE);
-
- egg_debug ("rescan");
- status = gpk_watch_task_list_to_status_bitfield (watch);
-
- /* something in list */
- if (status != 0) {
- /* get the most important icon */
- value = pk_bitfield_contain_priority (status,
- PK_STATUS_ENUM_REFRESH_CACHE,
- PK_STATUS_ENUM_LOADING_CACHE,
- PK_STATUS_ENUM_CANCEL,
- PK_STATUS_ENUM_INSTALL,
- PK_STATUS_ENUM_REMOVE,
- PK_STATUS_ENUM_CLEANUP,
- PK_STATUS_ENUM_OBSOLETE,
- PK_STATUS_ENUM_SETUP,
- PK_STATUS_ENUM_RUNNING,
- PK_STATUS_ENUM_UPDATE,
- PK_STATUS_ENUM_DOWNLOAD,
- PK_STATUS_ENUM_DOWNLOAD_REPOSITORY,
- PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST,
- PK_STATUS_ENUM_DOWNLOAD_FILELIST,
- PK_STATUS_ENUM_DOWNLOAD_CHANGELOG,
- PK_STATUS_ENUM_DOWNLOAD_GROUP,
- PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO,
- PK_STATUS_ENUM_SCAN_APPLICATIONS,
- PK_STATUS_ENUM_GENERATE_PACKAGE_LIST,
- PK_STATUS_ENUM_QUERY,
- PK_STATUS_ENUM_INFO,
- PK_STATUS_ENUM_DEP_RESOLVE,
- PK_STATUS_ENUM_ROLLBACK,
- PK_STATUS_ENUM_TEST_COMMIT,
- PK_STATUS_ENUM_COMMIT,
- PK_STATUS_ENUM_REQUEST,
- PK_STATUS_ENUM_SIG_CHECK,
- PK_STATUS_ENUM_CLEANUP,
- PK_STATUS_ENUM_REPACKAGING,
- PK_STATUS_ENUM_WAIT,
- PK_STATUS_ENUM_WAITING_FOR_LOCK,
- -1);
- }
-
- /* only set if in the list and not unknown */
- if (value != PK_STATUS_ENUM_UNKNOWN && value != -1) {
- icon_name = gpk_status_enum_to_icon_name (value);
- goto out;
- }
-
- /* any restart required? */
- if (watch->priv->restart != PK_RESTART_ENUM_NONE &&
- watch->priv->hide_warning == FALSE) {
- icon_name = gpk_restart_enum_to_icon_name (watch->priv->restart);
- goto out;
- }
-out:
- /* no icon, hide */
- if (icon_name == NULL) {
- gtk_status_icon_set_visible (watch->priv->status_icon, FALSE);
- return FALSE;
- }
- gtk_status_icon_set_from_icon_name (watch->priv->status_icon, icon_name);
- gtk_status_icon_set_visible (watch->priv->status_icon, TRUE);
- return TRUE;
-}
-
#ifdef HAVE_NOTIFY
/**
* gpk_watch_libnotify_cb:
@@ -340,6 +99,8 @@ out:
static void
gpk_watch_libnotify_cb (NotifyNotification *notification, gchar *action, gpointer data)
{
+ gboolean ret;
+ GError *error = NULL;
GpkWatch *watch = GPK_WATCH (data);
if (g_strcmp0 (action, "do-not-show-notify-complete") == 0) {
@@ -350,135 +111,26 @@ gpk_watch_libnotify_cb (NotifyNotification *notification, gchar *action, gpointe
/* TRANSLATORS: The detailed error if the user clicks "more info" */
gpk_error_dialog (_("Error details"), _("Package manager error details"), watch->priv->error_details);
- } else {
- egg_warning ("unknown action id: %s", action);
- }
-}
-#endif
-
-/**
- * gpk_watch_show_about_cb:
- **/
-static void
-gpk_watch_show_about_cb (GtkMenuItem *item, gpointer data)
-{
- const char *authors[] = {
- "Richard Hughes <richard hughsie com>",
- NULL};
- const char *documenters[] = {
- "Richard Hughes <richard hughsie com>",
- NULL};
- const char *license[] = {
- N_("Licensed under the GNU General Public License Version 2"),
- N_("PackageKit 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."),
- N_("PackageKit 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."),
- N_("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., 51 Franklin Street, Fifth Floor, Boston, MA "
- "02110-1301, USA.")
- };
- const char *translators = _("translator-credits");
- char *license_trans;
-
- /* Translators comment: put your own name here to appear in the about dialog. */
- if (!strcmp (translators, "translator-credits"))
- translators = NULL;
-
- license_trans = g_strconcat (_(license[0]), "", _(license[1]), "",
- _(license[2]), "", _(license[3]), "", NULL);
-
- gtk_window_set_default_icon_name (GPK_ICON_SOFTWARE_LOG);
- gtk_show_about_dialog (NULL,
- "version", VERSION,
- "copyright", "Copyright \xc2\xa9 2007-2009 Richard Hughes",
- "license", license_trans,
- "wrap-license", TRUE,
- "website-label", _("PackageKit Website"),
- "website", "http://www.packagekit.org",
- "comments", "PackageKit",
- "authors", authors,
- "documenters", documenters,
- "translator-credits", translators,
- "logo-icon-name", GPK_ICON_SOFTWARE_LOG,
- NULL);
- g_free (license_trans);
-}
-
-/**
- * gpk_watch_popup_menu_cb:
- *
- * Display the popup menu.
- **/
-static void
-gpk_watch_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, GpkWatch *watch)
-{
- GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
- GtkWidget *item;
- GtkWidget *image;
-
- g_return_if_fail (GPK_IS_WATCH (watch));
- egg_debug ("icon right clicked");
-
- /* TRANSLATORS: this is the right click menu item */
- item = gtk_image_menu_item_new_with_mnemonic (_("_About"));
- image = gtk_image_new_from_icon_name (GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- g_signal_connect (G_OBJECT (item), "activate",
- G_CALLBACK (gpk_watch_show_about_cb), watch);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- /* 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,
- button, timestamp);
- if (button == 0)
- gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
-}
-
-/**
- * gpk_watch_set_status:
- **/
-static gboolean
-gpk_watch_set_status (GpkWatch *watch, PkStatusEnum status)
-{
- /* do we force progress? */
- if (status == PK_STATUS_ENUM_DOWNLOAD_REPOSITORY ||
- status == PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST ||
- status == PK_STATUS_ENUM_DOWNLOAD_FILELIST ||
- status == PK_STATUS_ENUM_DOWNLOAD_CHANGELOG ||
- status == PK_STATUS_ENUM_DOWNLOAD_GROUP ||
- status == PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO ||
- status == PK_STATUS_ENUM_REFRESH_CACHE) {
- gpk_modal_dialog_setup (watch->priv->dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, 0);
- }
-
- /* set icon */
- gpk_modal_dialog_set_image_status (watch->priv->dialog, status);
-
- /* set label */
- gpk_modal_dialog_set_title (watch->priv->dialog, gpk_status_enum_to_localised_text (status));
+ } else if (g_strcmp0 (action, "logout") == 0) {
+ GpkSession *session;
+ session = gpk_session_new ();
+ gpk_session_logout (session);
+ g_object_unref (session);
- /* spin */
- if (status == PK_STATUS_ENUM_WAIT)
- gpk_modal_dialog_set_percentage (watch->priv->dialog, -1);
+ } else if (g_strcmp0 (action, "restart") == 0) {
- /* do visual stuff when finished */
- if (status == PK_STATUS_ENUM_FINISHED) {
- /* make insensitive */
- gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, FALSE);
+ /* restart using ConsoleKit */
+ ret = egg_console_kit_restart (watch->priv->console, &error);
+ if (!ret) {
+ egg_warning ("restarting failed: %s", error->message);
+ g_error_free (error);
+ }
- /* stop spinning */
- gpk_modal_dialog_set_percentage (watch->priv->dialog, 100);
+ } else {
+ egg_warning ("unknown action id: %s", action);
}
- return TRUE;
}
+#endif
/**
* gpk_watch_lookup_progress_from_transaction_id:
@@ -509,272 +161,6 @@ out:
}
/**
- * gpk_watch_monitor_tid:
- **/
-static gboolean
-gpk_watch_monitor_tid (GpkWatch *watch, const gchar *transaction_id)
-{
- gboolean allow_cancel;
- gchar *package_id = NULL;
- gchar *text;
- guint percentage;
- guint remaining_time;
- PkProgress *progress;
- PkRoleEnum role;
- PkStatusEnum status;
-
- g_free (watch->priv->transaction_id);
- watch->priv->transaction_id = g_strdup (transaction_id);
-
- /* find progress */
- progress = gpk_watch_lookup_progress_from_transaction_id (watch, transaction_id);
- if (progress == NULL) {
- egg_warning ("could not find: %s", transaction_id);
- return FALSE;
- }
-
- /* coldplug */
- g_object_get (progress,
- "role", &role,
- "status", &status,
- "allow-cancel", &allow_cancel,
- "percentage", &percentage,
- "remaining-time", &remaining_time,
- "package-id", &package_id,
- NULL);
-
- /* fill in role */
- gpk_modal_dialog_set_title (watch->priv->dialog, gpk_role_enum_to_localised_present (role));
-
- /* are we cancellable? */
- gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, allow_cancel);
- gpk_modal_dialog_set_percentage (watch->priv->dialog, percentage);
- gpk_modal_dialog_set_remaining (watch->priv->dialog, remaining_time);
-
- /* setup the UI */
- if (role == PK_ROLE_ENUM_SEARCH_NAME ||
- role == PK_ROLE_ENUM_SEARCH_GROUP ||
- role == PK_ROLE_ENUM_SEARCH_DETAILS ||
- role == PK_ROLE_ENUM_SEARCH_FILE ||
- role == PK_ROLE_ENUM_SEARCH_NAME ||
- role == PK_ROLE_ENUM_GET_UPDATES)
- gpk_modal_dialog_setup (watch->priv->dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, 0);
- else
- gpk_modal_dialog_setup (watch->priv->dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, GPK_MODAL_DIALOG_PACKAGE_PADDING);
-
- /* set the status */
- gpk_watch_set_status (watch, status);
-
- /* do the best we can, and get the last package */
- text = gpk_package_id_format_twoline (package_id, NULL);
- gpk_modal_dialog_set_message (watch->priv->dialog, text);
-
- gpk_modal_dialog_present (watch->priv->dialog);
- g_free (package_id);
- g_free (text);
- return TRUE;
-}
-
-/**
- * gpk_watch_menu_job_status_cb:
- **/
-static void
-gpk_watch_menu_job_status_cb (GtkMenuItem *item, GpkWatch *watch)
-{
- gchar *tid;
-
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- /* find the job we should bind to */
- tid = (gchar *) g_object_get_data (G_OBJECT (item), "tid");
- if (egg_strzero(tid) || tid[0] != '/') {
- egg_warning ("invalid job, maybe transaction already removed");
- return;
- }
-
- /* launch the UI */
- gpk_watch_monitor_tid (watch, tid);
-}
-
-/**
- * gpk_watch_populate_menu_with_jobs:
- **/
-static void
-gpk_watch_populate_menu_with_jobs (GpkWatch *watch, GtkMenu *menu)
-{
- guint i;
- PkProgress *progress;
- GtkWidget *widget;
- GtkWidget *image;
- PkRoleEnum role;
- PkStatusEnum status;
- const gchar *icon_name;
- gchar *text;
- gchar *transaction_id;
- GPtrArray *array;
-
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- array = watch->priv->array_progress;
- if (array->len == 0)
- goto out;
-
- /* do a menu item for each job */
- for (i=0; i<array->len; i++) {
- progress = g_ptr_array_index (array, i);
- g_object_get (progress,
- "role", &role,
- "status", &status,
- NULL);
-
- /* ignore boring status values */
- if (status == PK_STATUS_ENUM_FINISHED)
- continue;
-
- /* do this in two steps as this data needs to be freed */
- g_object_get (progress,
- "transaction-id", &transaction_id,
- NULL);
-
- icon_name = gpk_status_enum_to_icon_name (status);
- text = g_strdup_printf ("%s (%s)",
- gpk_role_enum_to_localised_present (role),
- gpk_status_enum_to_localised_text (status));
-
- /* add a job */
- widget = gtk_image_menu_item_new_with_mnemonic (text);
-
- /* we need the job ID so we know what transaction to show */
- g_object_set_data_full (G_OBJECT (widget), "tid", g_strdup (transaction_id), g_free);
-
- image = gtk_image_new_from_icon_name (icon_name, 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 (gpk_watch_menu_job_status_cb), watch);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
- g_free (transaction_id);
- g_free (text);
- }
-out:
- return;
-}
-
-/**
- * gpk_watch_menu_hide_restart_cb:
- **/
-static void
-gpk_watch_menu_hide_restart_cb (GtkMenuItem *item, gpointer data)
-{
- GpkWatch *watch = GPK_WATCH (data);
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- /* hide */
- watch->priv->hide_warning = TRUE;
- gpk_watch_refresh_icon (watch);
-}
-
-/**
- * gpk_watch_menu_log_out_cb:
- **/
-static void
-gpk_watch_menu_log_out_cb (GtkMenuItem *item, gpointer data)
-{
- GpkWatch *watch = GPK_WATCH (data);
- GpkSession *session;
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- /* just ask for logout */
- session = gpk_session_new ();
- gpk_session_logout (session);
- g_object_unref (session);
-}
-
-/**
- * gpk_watch_menu_restart_cb:
- **/
-static void
-gpk_watch_menu_restart_cb (GtkMenuItem *item, GpkWatch *watch)
-{
- gboolean ret;
- GError *error = NULL;
-
- /* restart using ConsoleKit */
- ret = egg_console_kit_restart (watch->priv->console, &error);
- if (!ret) {
- egg_warning ("restarting failed: %s", error->message);
- g_error_free (error);
- }
-}
-
-/**
- * gpk_watch_activate_status_cb:
- * @button: Which buttons are pressed
- *
- * Callback when the icon is clicked
- **/
-static void
-gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
-{
- GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
- GtkWidget *widget;
- GtkWidget *image;
- gboolean show_hide = FALSE;
- gboolean can_restart = FALSE;
-
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- egg_debug ("icon left clicked");
-
- /* add jobs as drop down */
- gpk_watch_populate_menu_with_jobs (watch, menu);
-
- /* log out session */
- if (watch->priv->restart == PK_RESTART_ENUM_SESSION ||
- watch->priv->restart == PK_RESTART_ENUM_SECURITY_SESSION) {
- /* TRANSLATORS: log out of the session */
- widget = gtk_image_menu_item_new_with_mnemonic (_("_Log out"));
- image = gtk_image_new_from_icon_name ("system-log-out", 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 (gpk_watch_menu_log_out_cb), watch);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
- show_hide = TRUE;
- }
-
- /* restart computer */
- egg_console_kit_can_restart (watch->priv->console, &can_restart, NULL);
- if (can_restart &&
- (watch->priv->restart == PK_RESTART_ENUM_SYSTEM ||
- watch->priv->restart == PK_RESTART_ENUM_SECURITY_SYSTEM)) {
- /* TRANSLATORS: this menu item restarts the computer after an update */
- 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 (gpk_watch_menu_restart_cb), watch);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
- show_hide = TRUE;
- }
-
- /* anything we're allowed to hide? */
- if (show_hide) {
- /* TRANSLATORS: This hides the 'restart required' icon */
- widget = gtk_image_menu_item_new_with_mnemonic (_("_Hide this icon"));
- image = gtk_image_new_from_icon_name ("dialog-information", 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 (gpk_watch_menu_hide_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());
-}
-
-/**
* gpk_watch_get_proxy_ftp:
* Return value: server.lan:8080
**/
@@ -1016,27 +402,6 @@ gpk_watch_key_changed_cb (GSettings *client, const gchar *key, GpkWatch *watch)
}
/**
- * gpk_watch_button_close_cb:
- **/
-static void
-gpk_watch_button_close_cb (GtkWidget *widget, GpkWatch *watch)
-{
- /* close, don't abort */
- gpk_modal_dialog_close (watch->priv->dialog);
-}
-
-/**
- * gpk_watch_button_cancel_cb:
- **/
-static void
-gpk_watch_button_cancel_cb (GtkWidget *widget, GpkWatch *watch)
-{
- /* we might have a transaction running */
- egg_debug ("cancelling transaction: %p", watch->priv->cancellable);
- g_cancellable_cancel (watch->priv->cancellable);
-}
-
-/**
* gpk_watch_set_connected:
**/
static void
@@ -1047,8 +412,6 @@ gpk_watch_set_connected (GpkWatch *watch, gboolean connected)
/* daemon has just appeared */
egg_debug ("dameon has just appeared");
- gpk_watch_refresh_icon (watch);
- gpk_watch_refresh_tooltip (watch);
gpk_watch_set_proxies (watch);
gpk_watch_set_root (watch);
}
@@ -1160,8 +523,7 @@ gpk_watch_process_messages_cb (PkMessage *item, GpkWatch *watch)
ret = notify_notification_close (watch->priv->notification_message, &error);
if (!ret) {
egg_warning ("error: %s", error->message);
- g_error_free (error);
- error = NULL;
+ g_clear_error (&error);
}
}
@@ -1173,7 +535,10 @@ gpk_watch_process_messages_cb (PkMessage *item, GpkWatch *watch)
}
/* do the bubble */
- notification = notify_notification_new_with_status_icon (gpk_message_enum_to_localised_text (type), details, "emblem-important", watch->priv->status_icon);
+ notification = notify_notification_new_with_status_icon (gpk_message_enum_to_localised_text (type),
+ details,
+ "emblem-important",
+ watch->priv->status_icon);
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
ret = notify_notification_show (notification, &error);
@@ -1233,7 +598,8 @@ gpk_watch_process_error_code (GpkWatch *watch, PkError *error_code)
title_prefix = g_strdup_printf ("%s: %s", _("Package Manager"), title);
/* do the bubble */
- notification = notify_notification_new (title_prefix, message, "help-browser", NULL);
+ notification = notify_notification_new_with_status_icon (title_prefix, message, "help-browser",
+ watch->priv->status_icon);
notify_notification_set_timeout (notification, 15000);
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
notify_notification_add_action (notification, "show-error-details",
@@ -1250,6 +616,16 @@ out:
}
/**
+ * gpk_watch_set_status_icon:
+ **/
+void
+gpk_watch_set_status_icon (GpkWatch *watch, GtkStatusIcon *status_icon)
+{
+ g_assert (watch->priv->status_icon == NULL);
+ watch->priv->status_icon = g_object_ref (status_icon);
+}
+
+/**
* gpk_watch_process_require_restart_cb:
**/
static void
@@ -1258,10 +634,16 @@ gpk_watch_process_require_restart_cb (PkRequireRestart *item, GpkWatch *watch)
GPtrArray *array = NULL;
GPtrArray *names = NULL;
const gchar *name;
+ gboolean ret;
+ GError *error = NULL;
gchar **split = NULL;
guint i;
PkRestartEnum restart;
gchar *package_id = NULL;
+ NotifyNotification *notification;
+ const gchar *title;
+ const gchar *message;
+ const gchar *icon;
/* get data */
g_object_get (item,
@@ -1291,6 +673,47 @@ gpk_watch_process_require_restart_cb (PkRequireRestart *item, GpkWatch *watch)
}
}
+ /* localised title */
+ title = gpk_restart_enum_to_localised_text (restart);
+ message = gpk_restart_enum_to_localised_text (restart);
+ icon = gpk_restart_enum_to_dialog_icon_name (restart);
+
+ /* close existing */
+ if (watch->priv->notification_restart != NULL) {
+ ret = notify_notification_close (watch->priv->notification_restart, &error);
+ if (!ret) {
+ egg_warning ("error: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+
+ /* do the bubble */
+ notification = notify_notification_new_with_status_icon (title, message,
+ icon, watch->priv->status_icon);
+ notify_notification_set_timeout (notification, 15000);
+ notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+ if (restart == PK_RESTART_ENUM_APPLICATION ||
+ restart == PK_RESTART_ENUM_SESSION ||
+ restart == PK_RESTART_ENUM_SECURITY_SESSION) {
+ /* we can't handle application restarting this in a sane way yet */
+ notify_notification_add_action (notification, "logout",
+ /* TRANSLATORS: log out of the session */
+ _("Log out"), gpk_watch_libnotify_cb, watch, NULL);
+ } else if (restart == PK_RESTART_ENUM_SYSTEM ||
+ restart == PK_RESTART_ENUM_SECURITY_SYSTEM) {
+ notify_notification_add_action (notification, "restart",
+ /* TRANSLATORS: restart the computer */
+ _("Restart"), gpk_watch_libnotify_cb, watch, NULL);
+ } else {
+ egg_warning ("failed to handle restart action: %s", pk_restart_enum_to_string (restart));
+ }
+ ret = notify_notification_show (notification, &error);
+ if (!ret) {
+ egg_warning ("error: %s", error->message);
+ g_error_free (error);
+ }
+ watch->priv->notification_restart = notification;
+
/* add to list */
egg_debug ("adding %s to restart list", split[PK_PACKAGE_ID_NAME]);
g_ptr_array_add (names, g_strdup (split[PK_PACKAGE_ID_NAME]));
@@ -1346,18 +769,6 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
/* get the error */
error_code = pk_results_get_error_code (results);
- /* is the watched transaction */
- if (g_strcmp0 (transaction_id, watch->priv->transaction_id) == 0) {
- egg_debug ("watched transaction %s", watch->priv->transaction_id);
-
- /* stop spinning */
- gpk_modal_dialog_set_percentage (watch->priv->dialog, 100);
-
- /* autoclose if success */
- if (error_code == NULL)
- gpk_modal_dialog_close (watch->priv->dialog);
- }
-
/* process messages */
if (error_code == NULL) {
array = pk_results_get_message_array (results);
@@ -1370,9 +781,7 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
gpk_watch_process_error_code (watch, error_code);
/* process restarts */
- if (role == PK_ROLE_ENUM_UPDATE_PACKAGES ||
- role == PK_ROLE_ENUM_INSTALL_PACKAGES ||
- role == PK_ROLE_ENUM_UPDATE_SYSTEM) {
+ if (!caller_active) {
array = pk_results_get_require_restart_array (results);
g_ptr_array_foreach (array, (GFunc) gpk_watch_process_require_restart_cb, watch);
g_ptr_array_unref (array);
@@ -1412,7 +821,9 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
goto out;
/* TRANSLATORS: title: an action has finished, and we are showing the libnotify bubble */
- notification = notify_notification_new (_("Task completed"), message, "help-browser", NULL);
+ notification = notify_notification_new_with_status_icon (_("Task completed"),
+ message, "help-browser",
+ watch->priv->status_icon);
notify_notification_set_timeout (notification, 5000);
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
notify_notification_add_action (notification, "do-not-show-notify-complete",
@@ -1438,16 +849,10 @@ out:
static void
gpk_watch_progress_cb (PkProgress *progress, PkProgressType type, GpkWatch *watch)
{
- PkStatusEnum status;
- guint percentage;
- gboolean allow_cancel;
- gchar *package_id = NULL;
- gchar *transaction_id = NULL;
GPtrArray *array;
guint i;
gboolean ret = FALSE;
PkProgress *progress_tmp;
- guint remaining_time;
gchar *text = NULL;
/* add if not already in list */
@@ -1461,43 +866,7 @@ gpk_watch_progress_cb (PkProgress *progress, PkProgressType type, GpkWatch *watc
egg_debug ("adding progress %p", progress);
g_ptr_array_add (array, g_object_ref (progress));
}
-
- /* get data */
- g_object_get (progress,
- "status", &status,
- "percentage", &percentage,
- "allow-cancel", &allow_cancel,
- "package-id", &package_id,
- "remaining-time", &remaining_time,
- "transaction-id", &transaction_id,
- NULL);
-
- /* refresh both */
- if (type == PK_PROGRESS_TYPE_STATUS) {
- gpk_watch_refresh_icon (watch);
- gpk_watch_refresh_tooltip (watch);
- }
-
- /* is not the watched transaction */
- if (g_strcmp0 (transaction_id, watch->priv->transaction_id) != 0)
- goto out;
-
- if (type == PK_PROGRESS_TYPE_PACKAGE_ID) {
- text = gpk_package_id_format_twoline (package_id, NULL);
- gpk_modal_dialog_set_message (watch->priv->dialog, text);
- } else if (type == PK_PROGRESS_TYPE_PERCENTAGE) {
- gpk_modal_dialog_set_percentage (watch->priv->dialog, percentage);
- } else if (type == PK_PROGRESS_TYPE_REMAINING_TIME) {
- gpk_modal_dialog_set_remaining (watch->priv->dialog, remaining_time);
- } else if (type == PK_PROGRESS_TYPE_ALLOW_CANCEL) {
- gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, allow_cancel);
- } else if (type == PK_PROGRESS_TYPE_STATUS) {
- gpk_watch_set_status (watch, status);
- }
-out:
g_free (text);
- g_free (package_id);
- g_free (transaction_id);
}
/**
@@ -1536,10 +905,6 @@ gpk_watch_transaction_list_removed_cb (PkTransactionList *tlist, const gchar *tr
}
egg_debug ("removed: %s", transaction_id);
g_ptr_array_remove_fast (watch->priv->array_progress, progress);
-
- /* refresh both */
- gpk_watch_refresh_icon (watch);
- gpk_watch_refresh_tooltip (watch);
}
/**
@@ -1583,28 +948,19 @@ gpk_watch_init (GpkWatch *watch)
watch->priv = GPK_WATCH_GET_PRIVATE (watch);
watch->priv->error_details = NULL;
watch->priv->notification_message = NULL;
- watch->priv->transaction_id = NULL;
watch->priv->restart = PK_RESTART_ENUM_NONE;
- watch->priv->hide_warning = FALSE;
watch->priv->console = egg_console_kit_new ();
watch->priv->cancellable = g_cancellable_new ();
watch->priv->array_progress = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
watch->priv->settings = g_settings_new (GPK_SETTINGS_SCHEMA);
g_signal_connect (watch->priv->settings, "changed", G_CALLBACK (gpk_watch_key_changed_cb), watch);
- watch->priv->status_icon = gtk_status_icon_new ();
watch->priv->set_proxy_id = 0;
watch->priv->restart_package_names = g_ptr_array_new_with_free_func (g_free);
watch->priv->task = PK_TASK(gpk_task_new ());
g_object_set (watch->priv->task,
"background", TRUE,
NULL);
- watch->priv->dialog = gpk_modal_dialog_new ();
- gpk_modal_dialog_set_window_icon (watch->priv->dialog, "pk-package-installed");
- g_signal_connect (watch->priv->dialog, "cancel",
- G_CALLBACK (gpk_watch_button_cancel_cb), watch);
- g_signal_connect (watch->priv->dialog, "close",
- G_CALLBACK (gpk_watch_button_close_cb), watch);
/* we need to get ::locked */
watch->priv->control = pk_control_new ();
@@ -1619,12 +975,6 @@ gpk_watch_init (GpkWatch *watch)
/* do session inhibit */
watch->priv->inhibit = gpk_inhibit_new ();
- /* right click actions are common */
- g_signal_connect_object (G_OBJECT (watch->priv->status_icon),
- "popup_menu", G_CALLBACK (gpk_watch_popup_menu_cb), watch, 0);
- g_signal_connect_object (G_OBJECT (watch->priv->status_icon),
- "activate", G_CALLBACK (gpk_watch_activate_status_cb), watch, 0);
-
watch->priv->tlist = pk_transaction_list_new ();
g_signal_connect (watch->priv->tlist, "added",
G_CALLBACK (gpk_watch_transaction_list_added_cb), watch);
@@ -1654,17 +1004,15 @@ gpk_watch_finalize (GObject *object)
/* we might we waiting for a proxy update */
if (watch->priv->set_proxy_id != 0)
g_source_remove (watch->priv->set_proxy_id);
-
+ if (watch->priv->status_icon != NULL)
+ g_object_unref (watch->priv->status_icon);
g_free (watch->priv->error_details);
- g_free (watch->priv->transaction_id);
g_object_unref (watch->priv->cancellable);
- g_object_unref (PK_CLIENT(watch->priv->task));
+ g_object_unref (watch->priv->task);
g_object_unref (watch->priv->console);
g_object_unref (watch->priv->control);
- g_object_unref (watch->priv->dialog);
g_object_unref (watch->priv->settings);
g_object_unref (watch->priv->inhibit);
- g_object_unref (watch->priv->status_icon);
g_object_unref (watch->priv->tlist);
g_ptr_array_unref (watch->priv->array_progress);
g_ptr_array_unref (watch->priv->restart_package_names);
diff --git a/src/gpk-watch.h b/src/gpk-watch.h
index 528b020..a16508d 100644
--- a/src/gpk-watch.h
+++ b/src/gpk-watch.h
@@ -50,6 +50,8 @@ typedef struct
GType gpk_watch_get_type (void);
GpkWatch *gpk_watch_new (void);
+void gpk_watch_set_status_icon (GpkWatch *watch,
+ GtkStatusIcon *status_icon);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]