[gnome-packagekit] Remove GpkSmartIcon and use GpkStatusIcon directly
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-packagekit] Remove GpkSmartIcon and use GpkStatusIcon directly
- Date: Tue, 26 May 2009 13:22:13 -0400 (EDT)
commit 164cfcf6ed14d70d8d783dcdc624795301030c4f
Author: Richard Hughes <richard hughsie com>
Date: Tue May 26 18:21:03 2009 +0100
Remove GpkSmartIcon and use GpkStatusIcon directly
---
src/Makefile.am | 2 -
src/gpk-check-update.c | 43 +++++------
src/gpk-smart-icon.c | 185 ------------------------------------------------
src/gpk-smart-icon.h | 59 ---------------
src/gpk-watch.c | 32 +++++----
5 files changed, 38 insertions(+), 283 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 57302d2..71be513 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -96,8 +96,6 @@ shared_SOURCES = \
gpk-helper-chooser.h \
gpk-helper-media-change.c \
gpk-helper-media-change.h \
- gpk-smart-icon.c \
- gpk-smart-icon.h \
gpk-gnome.c \
gpk-gnome.h \
gpk-common.c \
diff --git a/src/gpk-check-update.c b/src/gpk-check-update.c
index f68e5a8..04fb88c 100644
--- a/src/gpk-check-update.c
+++ b/src/gpk-check-update.c
@@ -47,7 +47,6 @@
#include "gpk-consolekit.h"
#include "gpk-common.h"
#include "gpk-gnome.h"
-#include "gpk-smart-icon.h"
#include "gpk-auto-refresh.h"
#include "gpk-check-update.h"
#include "gpk-enum.h"
@@ -63,7 +62,7 @@ static void gpk_check_update_finalize (GObject *object);
struct GpkCheckUpdatePrivate
{
- GpkSmartIcon *sicon;
+ GtkStatusIcon *status_icon;
PkConnection *pconnection;
PkTaskList *tlist;
PkControl *control;
@@ -314,7 +313,7 @@ gpk_check_update_update_system (GpkCheckUpdate *cupdate)
/* we failed, show the icon */
egg_warning ("cannot update system: %s", error->message);
g_error_free (error);
- gpk_smart_icon_set_icon_name (cupdate->priv->sicon, NULL);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, FALSE);
/* we failed, so re-get the update list */
g_timeout_add_seconds (2, (GSourceFunc) gpk_check_update_get_updates_post_update_cb, cupdate);
}
@@ -602,12 +601,12 @@ gpk_check_update_get_best_update_icon (GpkCheckUpdate *cupdate, PkPackageList *l
/* get the most important icon */
value = pk_bitfield_contain_priority (infos,
- PK_INFO_ENUM_SECURITY,
- PK_INFO_ENUM_IMPORTANT,
- PK_INFO_ENUM_BUGFIX,
- PK_INFO_ENUM_NORMAL,
- PK_INFO_ENUM_ENHANCEMENT,
- PK_INFO_ENUM_LOW, -1);
+ PK_INFO_ENUM_SECURITY,
+ PK_INFO_ENUM_IMPORTANT,
+ PK_INFO_ENUM_BUGFIX,
+ PK_INFO_ENUM_NORMAL,
+ PK_INFO_ENUM_ENHANCEMENT,
+ PK_INFO_ENUM_LOW, -1);
if (value == -1) {
egg_warning ("should not be possible!");
value = PK_INFO_ENUM_LOW;
@@ -821,7 +820,7 @@ gpk_check_update_process_updates (GpkCheckUpdate *cupdate, PkPackageList *list,
/* we have no updates */
if (length == 0) {
egg_debug ("no updates");
- gpk_smart_icon_set_icon_name (cupdate->priv->sicon, NULL);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, FALSE);
goto out;
}
@@ -854,9 +853,9 @@ gpk_check_update_process_updates (GpkCheckUpdate *cupdate, PkPackageList *list,
}
}
- /* work out icon */
+ /* work out icon (cannot be NULL) */
icon = gpk_check_update_get_best_update_icon (cupdate, list);
- gpk_smart_icon_set_icon_name (cupdate->priv->sicon, icon);
+ gtk_status_icon_set_from_icon_name (cupdate->priv->status_icon, icon);
/* make tooltip */
if (status_security->len != 0)
@@ -864,7 +863,7 @@ gpk_check_update_process_updates (GpkCheckUpdate *cupdate, PkPackageList *list,
/* TRANSLATORS: tooltip: how many updates are waiting to be applied */
g_string_append_printf (status_tooltip, ngettext ("There is %d update available",
"There are %d updates available", length), length);
- gtk_status_icon_set_tooltip_text (GTK_STATUS_ICON (cupdate->priv->sicon), status_tooltip->str);
+ gtk_status_icon_set_tooltip_text (cupdate->priv->status_icon, status_tooltip->str);
/* if we are just refreshing after a failed update, don't try to do the actions */
if (!policy_action) {
@@ -1021,7 +1020,7 @@ gpk_check_update_task_list_changed_cb (PkTaskList *tlist, GpkCheckUpdate *cupdat
/* hide icon if we are updating */
if (pk_task_list_contains_role (tlist, PK_ROLE_ENUM_UPDATE_SYSTEM) ||
pk_task_list_contains_role (tlist, PK_ROLE_ENUM_UPDATE_PACKAGES)) {
- gpk_smart_icon_set_icon_name (cupdate->priv->sicon, NULL);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, FALSE);
}
}
@@ -1162,9 +1161,9 @@ gpk_check_update_network_status_changed_cb (PkControl *control, PkNetworkEnum st
{
//TODO: check that set_visible (TRUE) on a unset icon doesn't cause an icon to show
if (state == PK_NETWORK_ENUM_OFFLINE)
- gtk_status_icon_set_visible (GTK_STATUS_ICON(cupdate->priv->sicon), FALSE);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, FALSE);
else
- gtk_status_icon_set_visible (GTK_STATUS_ICON(cupdate->priv->sicon), TRUE);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, TRUE);
}
/**
@@ -1176,7 +1175,7 @@ gpk_cupdate_connection_changed_cb (EggDbusMonitor *monitor, gboolean connected,
g_return_if_fail (GPK_IS_CHECK_UPDATE (cupdate));
if (connected) {
egg_debug ("update viewer on the bus, so hiding icon");
- gpk_smart_icon_set_icon_name (cupdate->priv->sicon, NULL);
+ gtk_status_icon_set_visible (cupdate->priv->status_icon, FALSE);
}
}
@@ -1438,13 +1437,12 @@ gpk_check_update_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runt
static void
gpk_check_update_init (GpkCheckUpdate *cupdate)
{
- GtkStatusIcon *status_icon;
cupdate->priv = GPK_CHECK_UPDATE_GET_PRIVATE (cupdate);
cupdate->priv->notification_updates_available = NULL;
cupdate->priv->important_updates_array = NULL;
cupdate->priv->number_updates_critical_last_shown = 0;
- cupdate->priv->sicon = gpk_smart_icon_new ();
+ cupdate->priv->status_icon = gtk_status_icon_new ();
/* preload all the common GConf keys */
cupdate->priv->gconf_client = gconf_client_get_default ();
@@ -1460,12 +1458,11 @@ gpk_check_update_init (GpkCheckUpdate *cupdate)
G_CALLBACK (gpk_check_update_auto_get_upgrades_cb), cupdate);
/* right click actions are common */
- status_icon = GTK_STATUS_ICON (cupdate->priv->sicon);
- g_signal_connect_object (G_OBJECT (status_icon),
+ 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 (status_icon),
+ g_signal_connect_object (G_OBJECT (cupdate->priv->status_icon),
"activate",
G_CALLBACK (gpk_check_update_activate_update_cb),
cupdate, 0);
@@ -1534,7 +1531,7 @@ gpk_check_update_finalize (GObject *object)
g_return_if_fail (cupdate->priv != NULL);
- g_object_unref (cupdate->priv->sicon);
+ g_object_unref (cupdate->priv->status_icon);
g_object_unref (cupdate->priv->pconnection);
g_object_unref (cupdate->priv->tlist);
g_object_unref (cupdate->priv->arefresh);
diff --git a/src/gpk-smart-icon.c b/src/gpk-smart-icon.c
deleted file mode 100644
index 15199bd..0000000
--- a/src/gpk-smart-icon.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007-2009 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 <gtk/gtkstatusicon.h>
-#include <packagekit-glib/packagekit.h>
-
-#include "egg-debug.h"
-#include "gpk-marshal.h"
-#include "gpk-common.h"
-#include "gpk-smart-icon.h"
-
-static void gpk_smart_icon_finalize (GObject *object);
-
-#define GPK_SMART_ICON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPK_TYPE_SMART_ICON, GpkSmartIconPrivate))
-#define GPK_SMART_ICON_PERSIST_TIMEOUT 100
-
-struct GpkSmartIconPrivate
-{
- gchar *current;
- gchar *new;
- guint event_source;
-};
-
-G_DEFINE_TYPE (GpkSmartIcon, gpk_smart_icon, GTK_TYPE_STATUS_ICON)
-
-/**
- * gpk_smart_icon_class_init:
- * @klass: The GpkSmartIconClass
- **/
-static void
-gpk_smart_icon_class_init (GpkSmartIconClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gpk_smart_icon_finalize;
- g_type_class_add_private (klass, sizeof (GpkSmartIconPrivate));
-}
-
-/**
- * gpk_smart_icon_set_icon_name_cb:
- **/
-static gboolean
-gpk_smart_icon_set_icon_name_cb (gpointer data)
-{
- GpkSmartIcon *sicon = (GpkSmartIcon *) data;
-
- /* no point setting the same */
- if (g_strcmp0 (sicon->priv->new, sicon->priv->current) == 0) {
- egg_debug ("setting the same: %s", sicon->priv->new);
- return FALSE;
- }
-
- /* save new version of what we have */
- g_free (sicon->priv->current);
- sicon->priv->current = g_strdup (sicon->priv->new);
- egg_debug ("setting new: %s", sicon->priv->new);
-
- /* set the correct thing */
- if (sicon->priv->new == NULL) {
- gtk_status_icon_set_visible (GTK_STATUS_ICON (sicon), FALSE);
- } else {
- gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (sicon), sicon->priv->new);
- gtk_status_icon_set_visible (GTK_STATUS_ICON (sicon), TRUE);
- }
- return FALSE;
-}
-
-/**
- * gpk_smart_icon_set_icon:
- **/
-gboolean
-gpk_smart_icon_set_icon_name (GpkSmartIcon *sicon, const gchar *icon_name)
-{
- g_return_val_if_fail (GPK_IS_SMART_ICON (sicon), FALSE);
-
- /* if we have a request pending, then cancel it in preference to this one */
- if (sicon->priv->event_source != 0) {
- g_source_remove (sicon->priv->event_source);
- sicon->priv->event_source = 0;
- }
-
- /* tell us what we -want- */
- g_free (sicon->priv->new);
- egg_debug ("setting icon name %s", icon_name);
- sicon->priv->new = g_strdup (icon_name);
-
- /* wait a little while to see if it's worth displaying the icon */
- sicon->priv->event_source = g_timeout_add (GPK_SMART_ICON_PERSIST_TIMEOUT, gpk_smart_icon_set_icon_name_cb, sicon);
- return TRUE;
-}
-
-/**
- * gpk_smart_icon_set_priority:
- **/
-gboolean
-gpk_smart_icon_set_priority (GpkSmartIcon *sicon, guint number)
-{
- g_return_val_if_fail (GPK_IS_SMART_ICON (sicon), FALSE);
- egg_debug ("set priority %i", number);
- return TRUE;
-}
-
-/**
- * gpk_smart_icon_init:
- * @smart_icon: This class instance
- **/
-static void
-gpk_smart_icon_init (GpkSmartIcon *sicon)
-{
- sicon->priv = GPK_SMART_ICON_GET_PRIVATE (sicon);
- sicon->priv->new = NULL;
- sicon->priv->current = NULL;
- sicon->priv->event_source = 0;
- gtk_status_icon_set_visible (GTK_STATUS_ICON (sicon), FALSE);
-}
-
-/**
- * gpk_smart_icon_finalize:
- * @object: The object to finalize
- **/
-static void
-gpk_smart_icon_finalize (GObject *object)
-{
- GpkSmartIcon *sicon;
-
- g_return_if_fail (GPK_IS_SMART_ICON (object));
-
- sicon = GPK_SMART_ICON (object);
- g_return_if_fail (sicon->priv != NULL);
-
- /* remove any timers that may be pending */
- if (sicon->priv->event_source != 0)
- g_source_remove (sicon->priv->event_source);
-
- g_free (sicon->priv->new);
- g_free (sicon->priv->current);
-
- G_OBJECT_CLASS (gpk_smart_icon_parent_class)->finalize (object);
-}
-
-/**
- * gpk_smart_icon_new:
- *
- * Return value: a new GpkSmartIcon object.
- **/
-GpkSmartIcon *
-gpk_smart_icon_new (void)
-{
- GpkSmartIcon *sicon;
- sicon = g_object_new (GPK_TYPE_SMART_ICON, NULL);
- return GPK_SMART_ICON (sicon);
-}
-
diff --git a/src/gpk-smart-icon.h b/src/gpk-smart-icon.h
deleted file mode 100644
index abf80e0..0000000
--- a/src/gpk-smart-icon.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007-2009 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_SMART_ICON_H
-#define __GPK_SMART_ICON_H
-
-#include <glib-object.h>
-#include <gtk/gtkstatusicon.h>
-
-G_BEGIN_DECLS
-
-#define GPK_TYPE_SMART_ICON (gpk_smart_icon_get_type ())
-#define GPK_SMART_ICON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPK_TYPE_SMART_ICON, GpkSmartIcon))
-#define GPK_SMART_ICON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPK_TYPE_SMART_ICON, GpkSmartIconClass))
-#define GPK_IS_SMART_ICON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPK_TYPE_SMART_ICON))
-#define GPK_IS_SMART_ICON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPK_TYPE_SMART_ICON))
-#define GPK_SMART_ICON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPK_TYPE_SMART_ICON, GpkSmartIconClass))
-#define GPK_SMART_ICON_ERROR (gpk_smart_icon_error_quark ())
-#define GPK_SMART_ICON_TYPE_ERROR (gpk_smart_icon_error_get_type ())
-
-typedef struct GpkSmartIconPrivate GpkSmartIconPrivate;
-
-typedef struct
-{
- GtkStatusIcon parent;
- GpkSmartIconPrivate *priv;
-} GpkSmartIcon;
-
-typedef struct
-{
- GtkStatusIconClass parent_class;
-} GpkSmartIconClass;
-
-GType gpk_smart_icon_get_type (void);
-GpkSmartIcon *gpk_smart_icon_new (void);
-gboolean gpk_smart_icon_set_icon_name (GpkSmartIcon *sicon,
- const gchar *icon_name);
-
-G_END_DECLS
-
-#endif /* __GPK_SMART_ICON_H */
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 5d8c284..639dd82 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -48,7 +48,6 @@
#include "gpk-watch.h"
#include "gpk-modal-dialog.h"
#include "gpk-inhibit.h"
-#include "gpk-smart-icon.h"
#include "gpk-consolekit.h"
#include "gpk-enum.h"
@@ -63,7 +62,7 @@ static void gpk_watch_finalize (GObject *object);
struct GpkWatchPrivate
{
PkControl *control;
- GpkSmartIcon *sicon;
+ GtkStatusIcon *status_icon;
GPtrArray *cached_messages;
GPtrArray *restart_package_names;
NotifyNotification *notification_cached_messages;
@@ -212,9 +211,9 @@ gpk_watch_refresh_tooltip (GpkWatch *watch)
out:
#if GTK_CHECK_VERSION(2,15,0)
- gtk_status_icon_set_tooltip_text (GTK_STATUS_ICON (watch->priv->sicon), status->str);
+ gtk_status_icon_set_tooltip_text (watch->priv->status_icon, status->str);
#else
- gtk_status_icon_set_tooltip (GTK_STATUS_ICON (watch->priv->sicon), status->str);
+ gtk_status_icon_set_tooltip (watch->priv->status_icon, status->str);
#endif
g_string_free (status, TRUE);
return TRUE;
@@ -326,7 +325,12 @@ gpk_watch_refresh_icon (GpkWatch *watch)
}
out:
- gpk_smart_icon_set_icon_name (watch->priv->sicon, icon_name);
+ /* 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);
return TRUE;
}
@@ -632,7 +636,7 @@ gpk_watch_message_cb (PkTaskList *tlist, PkClient *client, PkMessageEnum message
}
/* do the bubble */
- notification = notify_notification_new_with_status_icon (_("New package manager message"), NULL, "emblem-important", GTK_STATUS_ICON(watch->priv->sicon));
+ notification = notify_notification_new_with_status_icon (_("New package manager message"), NULL, "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);
@@ -1193,7 +1197,9 @@ gpk_watch_menu_hide_restart_cb (GtkMenuItem *item, gpointer data)
{
GpkWatch *watch = GPK_WATCH (data);
g_return_if_fail (GPK_IS_WATCH (watch));
- gpk_smart_icon_set_icon_name (watch->priv->sicon, NULL);
+
+ /* hide */
+ gtk_status_icon_set_visible (watch->priv->status_icon, FALSE);
}
/**
@@ -1290,7 +1296,7 @@ pk_connection_changed_cb (PkConnection *pconnection, gboolean connected, GpkWatc
gpk_watch_refresh_icon (watch);
gpk_watch_refresh_tooltip (watch);
} else {
- gpk_smart_icon_set_icon_name (watch->priv->sicon, NULL);
+ gtk_status_icon_set_visible (watch->priv->status_icon, FALSE);
}
}
@@ -1548,7 +1554,6 @@ gpk_watch_button_cancel_cb (GtkWidget *widget, GpkWatch *watch)
static void
gpk_watch_init (GpkWatch *watch)
{
- GtkStatusIcon *status_icon;
PolKitAction *pk_action;
PolKitGnomeAction *restart_action;
@@ -1559,7 +1564,7 @@ gpk_watch_init (GpkWatch *watch)
watch->priv->gconf_client = gconf_client_get_default ();
- watch->priv->sicon = gpk_smart_icon_new ();
+ watch->priv->status_icon = gtk_status_icon_new ();
watch->priv->set_proxy_timeout = 0;
watch->priv->cached_messages = g_ptr_array_new ();
watch->priv->restart_package_names = g_ptr_array_new ();
@@ -1592,10 +1597,9 @@ gpk_watch_init (GpkWatch *watch)
watch->priv->inhibit = gpk_inhibit_new ();
/* right click actions are common */
- status_icon = GTK_STATUS_ICON (watch->priv->sicon);
- g_signal_connect_object (G_OBJECT (status_icon),
+ 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 (status_icon),
+ g_signal_connect_object (G_OBJECT (watch->priv->status_icon),
"activate", G_CALLBACK (gpk_watch_activate_status_cb), watch, 0);
watch->priv->tlist = pk_task_list_new ();
@@ -1675,7 +1679,7 @@ gpk_watch_finalize (GObject *object)
g_ptr_array_free (watch->priv->restart_package_names, TRUE);
g_free (watch->priv->error_details);
- g_object_unref (watch->priv->sicon);
+ g_object_unref (watch->priv->status_icon);
g_object_unref (watch->priv->inhibit);
g_object_unref (watch->priv->tlist);
g_object_unref (watch->priv->control);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]