status icon changes when temperature alert is raised
[psensor.git] / src / ui_status.c
1 /*
2  * Copyright (C) 2010-2011 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <gtk/gtk.h>
21
22 #include "log.h"
23 #include "ui_status.h"
24
25 GtkStatusIcon *status;
26
27 unsigned status_attention;
28
29 static void cb_activate(GtkStatusIcon *icon,
30                         gpointer data)
31 {
32         struct ui_psensor *ui;
33
34         log_printf(LOG_DEBUG, "cb_activate()");
35
36         ui = (struct ui_psensor *)data;
37         gtk_window_present(GTK_WINDOW(ui->main_window));
38 }
39
40 static void cb_popup_menu(GtkStatusIcon *icon,
41                           guint button,
42                           guint activate_time,
43                           gpointer data)
44 {
45         log_printf(LOG_DEBUG, "cb_popup_menu()");
46 }
47
48 void ui_status_init(struct ui_psensor *ui)
49 {
50         log_printf(LOG_DEBUG, "ui_status_create()");
51
52         status = gtk_status_icon_new();
53         gtk_status_icon_set_from_icon_name(status, "psensor");
54         gtk_status_icon_set_visible(status, TRUE);
55
56         g_signal_connect(G_OBJECT(status),
57                          "popup-menu",
58                          G_CALLBACK(cb_popup_menu),
59                          NULL);
60
61         g_signal_connect(G_OBJECT(status),
62                          "activate",
63                          G_CALLBACK(cb_activate),
64                          ui);
65 }
66
67 int is_status_supported()
68 {
69         return gtk_status_icon_is_embedded(status);
70 }
71
72 void ui_status_cleanup()
73 {
74         log_printf(LOG_DEBUG, "ui_status_cleanup()");
75
76         g_object_unref(G_OBJECT(status));
77 }
78
79 void ui_status_update(struct ui_psensor *ui, unsigned int attention)
80 {
81         log_printf(LOG_DEBUG, "ui_status_update()");
82
83         if (status_attention && !attention)
84                 gtk_status_icon_set_from_icon_name(status, "psensor");
85         else if (!status_attention && attention)
86                 gtk_status_icon_set_from_icon_name(status, "psensor_hot");
87
88         status_attention = attention;
89 }