status icon
[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 static void cb_activate(GtkStatusIcon *icon,
28                         gpointer data)
29 {
30         struct ui_psensor *ui;
31
32         log_printf(LOG_DEBUG, "cb_activate()");
33
34         ui = (struct ui_psensor *)data;
35         gtk_window_present(GTK_WINDOW(ui->main_window));
36 }
37
38 static void cb_popup_menu(GtkStatusIcon *icon,
39                           guint button,
40                           guint activate_time,
41                           gpointer data)
42 {
43         log_printf(LOG_DEBUG, "cb_popup_menu()");
44 }
45
46 void ui_status_init(struct ui_psensor *ui)
47 {
48         log_printf(LOG_DEBUG, "ui_status_create()");
49
50         status = gtk_status_icon_new();
51         gtk_status_icon_set_from_icon_name(status, "psensor");
52         gtk_status_icon_set_visible(status, TRUE);
53
54         g_signal_connect(G_OBJECT(status),
55                          "popup-menu",
56                          G_CALLBACK(cb_popup_menu),
57                          NULL);
58
59         g_signal_connect(G_OBJECT(status),
60                          "activate",
61                          G_CALLBACK(cb_activate),
62                          ui);
63 }
64
65 int is_status_supported()
66 {
67         return gtk_status_icon_is_embedded(status);
68 }
69
70 void ui_status_cleanup()
71 {
72         log_printf(LOG_DEBUG, "ui_status_cleanup()");
73
74         g_object_unref(G_OBJECT(status));
75 }
76
77 void ui_status_update(struct ui_psensor *ui, unsigned int attention)
78 {
79         log_printf(LOG_DEBUG, "ui_status_update()");
80 }