# HG changeset patch # User Pavol Rusnak # Date 1317118539 -7200 # Node ID f8ad23e600002df793ddb5408dee6c0fa6ebc80d # Parent 847ae02bc13b77759efc0ca5bae2841350df099f code rework, show notify window just once diff -r 847ae02bc13b -r f8ad23e60000 main.c --- a/main.c Tue Sep 27 02:31:31 2011 +0200 +++ b/main.c Tue Sep 27 12:15:39 2011 +0200 @@ -18,14 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "main.h" #include "notify.h" #include "packagekit.h" #include -struct updates_info { - int normal; - int critical; -} UpdatesInfo; +struct UpdatesInfo info; GtkStatusIcon *tray_icon; @@ -65,22 +63,19 @@ gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update"); gtk_status_icon_set_title(tray_icon, "Software Update"); gtk_status_icon_set_visible(tray_icon, TRUE); - return tray_icon; } gboolean periodic_check(gpointer user_data) { - struct UpdatesInfo info; query_packagekit(&info); - send_notify(info.normal, info.critical); if (info.critical > 0) { gtk_status_icon_set_from_icon_name(tray_icon, "software-update-urgent"); - gtk_status_icon_set_tooltip_text(tray_icon, "Critical updates available."); + gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); } else if (info.normal > 0) { gtk_status_icon_set_from_icon_name(tray_icon, "software-update-available"); - gtk_status_icon_set_tooltip_text(tray_icon, "Updates available."); + gtk_status_icon_set_tooltip_text(tray_icon, notify_text(&info)); } return TRUE; } @@ -94,7 +89,9 @@ init_notify(); periodic_check(NULL); - g_timeout_add(15 * 60 * 1000, periodic_check, NULL); + send_notify(&info); + // update tray icon and tooltip every 2 hours + g_timeout_add_seconds(2*3600, periodic_check, NULL); gtk_main(); diff -r 847ae02bc13b -r f8ad23e60000 main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue Sep 27 12:15:39 2011 +0200 @@ -0,0 +1,9 @@ +#ifndef MAIN_H +#define MAIN_H 1 + +struct UpdatesInfo { + int normal; + int critical; +}; + +#endif diff -r 847ae02bc13b -r f8ad23e60000 notify.c --- a/notify.c Tue Sep 27 02:31:31 2011 +0200 +++ b/notify.c Tue Sep 27 12:15:39 2011 +0200 @@ -28,17 +28,22 @@ notify_init(NOTIFY_NAME); } -void send_notify(int normal, int critical) +void send_notify(struct UpdatesInfo *info) { NotifyNotification *ntfy; - char buf[128]; - if (critical > 0) { - snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", normal + critical, critical); - } else { - snprintf(buf, sizeof(buf), "There are %d software updates available.", normal); - } - ntfy = notify_notification_new(NOTIFY_NAME, buf, critical > 0 ? "software-update-urgent" : "software-update-available"); + ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available"); notify_notification_set_timeout(ntfy, 3000); - notify_notification_set_urgency(ntfy, critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL); + notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL); notify_notification_show(ntfy, NULL); } + +const char *notify_text(struct UpdatesInfo *info) +{ + static char buf[128]; + if (info->critical > 0) { + snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical); + } else { + snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal); + } + return buf; +} diff -r 847ae02bc13b -r f8ad23e60000 notify.h --- a/notify.h Tue Sep 27 02:31:31 2011 +0200 +++ b/notify.h Tue Sep 27 12:15:39 2011 +0200 @@ -21,7 +21,10 @@ #ifndef NOTIFY_H #define NOTIFY_H +#include "main.h" + void init_notify(); -void send_notify(int normal, int critical); +void send_notify(struct UpdatesInfo *info); +const char *notify_text(struct UpdatesInfo *info); #endif diff -r 847ae02bc13b -r f8ad23e60000 packagekit.h --- a/packagekit.h Tue Sep 27 02:31:31 2011 +0200 +++ b/packagekit.h Tue Sep 27 12:15:39 2011 +0200 @@ -21,10 +21,7 @@ #ifndef PACKAGEKIT_H #define PACKAGEKIT_H 1 -struct UpdatesInfo { - int normal; - int critical; -}; +#include "main.h" void query_packagekit(struct UpdatesInfo *info);