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