Debian Codegraph @

src/tray.c

raw symbols SCIP
1 /*
2 *
3 * Connection Manager UI
4 *
5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include <connman-ui-gtk.h>
23
24 #define CUI_TRAYICON_UI_PATH CUI_UI_PATH "/tray.ui"
25
26 static GtkStatusIcon *cui_trayicon = NULL;
27 static void (*popup_left_menu_f)(GtkStatusIcon *, gpointer);
28 static void (*popup_rigt_menu_f)(GtkStatusIcon *, guint, guint, gpointer);
29 static int left_menu_handler_id = 0;
30 static int right_menu_handler_id = 0;
31
32 void cui_trayicon_update_icon(void)
33 {
34 enum connman_state state;
35 GdkPixbuf *image = NULL;
36 const char *info = NULL;
37
38 state = connman_manager_get_state();
39
40 cui_theme_get_state_icone_and_info(state, &image, &info);
41
42 gtk_status_icon_set_from_pixbuf(cui_trayicon, image);
43
44 gtk_status_icon_set_tooltip_text(cui_trayicon, info);
45 gtk_status_icon_set_visible(cui_trayicon, TRUE);
46 }
47
48 void cui_tray_hook_left_menu(gpointer callback)
49 {
50 popup_left_menu_f = callback;
51 }
52
53 void cui_tray_hook_right_menu(gpointer callback)
54 {
55 popup_rigt_menu_f = callback;
56 }
57
58 void cui_tray_left_menu_disable(void)
59 {
60 if (left_menu_handler_id != 0) {
61 g_signal_handler_disconnect(cui_trayicon, left_menu_handler_id);
62 left_menu_handler_id = 0;
63 }
64 }
65
66 void cui_tray_enable(void)
67 {
68 if (left_menu_handler_id == 0)
69 left_menu_handler_id = g_signal_connect(cui_trayicon,
70 "activate", G_CALLBACK(popup_left_menu_f), NULL);
71 if (right_menu_handler_id == 0)
72 right_menu_handler_id = g_signal_connect(cui_trayicon,
73 "popup-menu", G_CALLBACK(popup_rigt_menu_f), NULL);
74 }
75
76 void cui_tray_disable(void)
77 {
78 if (left_menu_handler_id != 0)
79 g_signal_handler_disconnect(cui_trayicon,
80 left_menu_handler_id);
81 if (right_menu_handler_id != 0)
82 g_signal_handler_disconnect(cui_trayicon,
83 right_menu_handler_id);
84
85 left_menu_handler_id = 0;
86 right_menu_handler_id = 0;
87 }
88
89 gint cui_load_trayicon(GtkBuilder *builder)
90 {
91 GError *error = NULL;
92
93 gtk_builder_add_from_file(builder, CUI_TRAYICON_UI_PATH, &error);
94 if (error != NULL) {
95 printf("Error: %s\n", error->message);
96 g_error_free(error);
97
98 return -EINVAL;
99 }
100
101 cui_trayicon = (GtkStatusIcon *) gtk_builder_get_object(builder,
102 "cui_trayicon");
103
104 cui_trayicon_update_icon();
105
106 cui_load_left_menu(builder, cui_trayicon);
107 cui_load_right_menu(builder, cui_trayicon);
108
109 return 0;
110 }