1b27b6e12bf281464e781897b1608a4e9563a4d0
[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 "log.h"
21 #include "ui_status.h"
22
23 static GtkStatusIcon *status;
24 static unsigned status_attention;
25
26 static void cb_activate(GtkStatusIcon *icon,
27                         gpointer data)
28 {
29         log_printf(LOG_DEBUG, "cb_activate()");
30
31         ui_window_show((struct ui_psensor *)data);
32 }
33
34 static void cb_popup_menu(GtkStatusIcon *icon,
35                           guint button,
36                           guint activate_time,
37                           gpointer data)
38 {
39         log_printf(LOG_DEBUG, "cb_popup_menu()");
40 }
41
42 void ui_status_init(struct ui_psensor *ui)
43 {
44         if (status)
45                 return ;
46
47         log_printf(LOG_DEBUG, "ui_status_create()");
48
49         status = gtk_status_icon_new();
50         gtk_status_icon_set_from_icon_name(status, "psensor_normal");
51         gtk_status_icon_set_visible(status, TRUE);
52
53         g_signal_connect(G_OBJECT(status),
54                          "popup-menu",
55                          G_CALLBACK(cb_popup_menu),
56                          NULL);
57
58         g_signal_connect(G_OBJECT(status),
59                          "activate",
60                          G_CALLBACK(cb_activate),
61                          ui);
62 }
63
64 int is_status_supported()
65 {
66         return gtk_status_icon_is_embedded(status);
67 }
68
69 void ui_status_cleanup()
70 {
71         log_printf(LOG_DEBUG, "ui_status_cleanup()");
72
73         g_object_unref(G_OBJECT(status));
74 }
75
76 void ui_status_update(struct ui_psensor *ui, unsigned int attention)
77 {
78         log_printf(LOG_DEBUG, "ui_status_update()");
79
80         if (status_attention && !attention)
81                 gtk_status_icon_set_from_icon_name(status, "psensor_normal");
82         else if (!status_attention && attention)
83                 gtk_status_icon_set_from_icon_name(status, "psensor_hot");
84
85         status_attention = attention;
86 }
87
88 GtkStatusIcon *ui_status_get_icon()
89 {
90         return status;
91 }