diff main.c @ 3:f8ad23e60000

code rework, show notify window just once
author Pavol Rusnak <stick@gk2.sk>
date Tue, 27 Sep 2011 12:15:39 +0200
parents 847ae02bc13b
children 58a3312a1c59
line wrap: on
line diff
--- 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 <gtk/gtk.h>
 
-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();