Mercurial > projects > pk-update-icon
view main.c @ 2:847ae02bc13b
added GPLv2 headers
author | Pavol Rusnak <stick@gk2.sk> |
---|---|
date | Tue, 27 Sep 2011 02:31:31 +0200 |
parents | 483f5fe9d2b2 |
children | f8ad23e60000 |
line wrap: on
line source
/* * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk> * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "notify.h" #include "packagekit.h" #include <gtk/gtk.h> struct updates_info { int normal; int critical; } UpdatesInfo; GtkStatusIcon *tray_icon; void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) { char *argv[2] = { "gpk-update-viewer", NULL }; g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); } static void tray_menu_destroy(GtkWidget *menu, gpointer userdata) { gtk_widget_destroy(menu); g_object_unref(menu); } void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) { GtkWidget *item; GtkWidget *menu = gtk_menu_new(); item = gtk_menu_item_new_with_mnemonic("_Quit"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data); gtk_widget_show(item); g_object_ref(menu); g_object_ref_sink(menu); g_object_unref(menu); g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(tray_menu_destroy), NULL); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, user_data, button, activate_time); gtk_widget_show_all(GTK_WIDGET(menu)); } static GtkStatusIcon *create_tray_icon() { tray_icon = gtk_status_icon_new(); g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); 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."); } 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."); } return TRUE; } int main(int argc, char **argv) { GtkStatusIcon *tray_icon; gtk_init(&argc, &argv); tray_icon = create_tray_icon(); init_notify(); periodic_check(NULL); g_timeout_add(15 * 60 * 1000, periodic_check, NULL); gtk_main(); return 0; }