aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_gtk.h35
-rw-r--r--src/lib/Makefile.am5
-rw-r--r--src/lib/glade.c14
-rw-r--r--src/lib/trayicon.c132
4 files changed, 183 insertions, 3 deletions
diff --git a/src/include/gnunet_gtk.h b/src/include/gnunet_gtk.h
index 4403ab4b..7857538d 100644
--- a/src/include/gnunet_gtk.h
+++ b/src/include/gnunet_gtk.h
@@ -40,6 +40,7 @@
40#include <gladeui/glade.h> 40#include <gladeui/glade.h>
41#include <gtk/gtk.h> 41#include <gtk/gtk.h>
42 42
43/* ****************** Initialization *************** */
43 44
44/** 45/**
45 * Initialize natural language support. 46 * Initialize natural language support.
@@ -49,6 +50,13 @@ GNUNET_GTK_setup_nls (void);
49 50
50 51
51/** 52/**
53 * Initialize GTK search path for icons.
54 */
55void
56GNUNET_GTK_set_icon_search_path ();
57
58
59/**
52 * Get the name of the directory where all of our package 60 * Get the name of the directory where all of our package
53 * data is stored ($PREFIX/share/) 61 * data is stored ($PREFIX/share/)
54 * 62 *
@@ -68,6 +76,8 @@ char *
68GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind); 76GNUNET_GTK_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind);
69 77
70 78
79/* **************** Glade/Gtk helpers *************** */
80
71/** 81/**
72 * Create an initialize a new builder based on the GNUnet-GTK glade 82 * Create an initialize a new builder based on the GNUnet-GTK glade
73 * file. 83 * file.
@@ -90,6 +100,29 @@ GNUNET_GTK_display_about (const char *dialogfile,
90 const char *dialogname); 100 const char *dialogname);
91 101
92 102
103
104/**
105 * Create our tray icon.
106 *
107 * @param main handle to the main window (show or hide)
108 * @param icon_name name of the tray icon file
109 * @param tooltip tooltip for the tray icon
110 */
111void
112GNUNET_GTK_tray_icon_create (GtkWindow *main,
113 const char *icon_name,
114 const char *tooltip);
115
116
117/**
118 * Destroy the tray icon.
119 */
120void
121GNUNET_GTK_tray_icon_destroy (void);
122
123
124/* ******************* main loop ***************** */
125
93/** 126/**
94 * Handle for our main loop. 127 * Handle for our main loop.
95 */ 128 */
@@ -117,7 +150,6 @@ GNUNET_GTK_main_loop_start (const char *binary_name,
117 const char *main_window_file, 150 const char *main_window_file,
118 GNUNET_SCHEDULER_Task main_task); 151 GNUNET_SCHEDULER_Task main_task);
119 152
120
121/** 153/**
122 * Get an object from the main window. 154 * Get an object from the main window.
123 * 155 *
@@ -130,6 +162,7 @@ GNUNET_GTK_main_loop_get_object (struct GNUNET_GTK_MainLoop *ml,
130 const char *name); 162 const char *name);
131 163
132 164
165
133/** 166/**
134 * Get the configuration. 167 * Get the configuration.
135 * 168 *
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 6a87dc4e..a5662334 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -12,11 +12,12 @@ endif
12lib_LTLIBRARIES = libgnunetgtk.la 12lib_LTLIBRARIES = libgnunetgtk.la
13 13
14libgnunetgtk_la_SOURCES = \ 14libgnunetgtk_la_SOURCES = \
15 about.c \
15 eventloop.c \ 16 eventloop.c \
16 glade.c \ 17 glade.c \
17 os_installation.c \
18 nls.c \ 18 nls.c \
19 about.c 19 os_installation.c \
20 trayicon.c
20libgnunetgtk_la_LIBADD = \ 21libgnunetgtk_la_LIBADD = \
21 -lgnunetutil $(XLIB) 22 -lgnunetutil $(XLIB)
22 23
diff --git a/src/lib/glade.c b/src/lib/glade.c
index 386a676b..3853ea93 100644
--- a/src/lib/glade.c
+++ b/src/lib/glade.c
@@ -28,6 +28,20 @@
28 28
29 29
30/** 30/**
31 * Initialize GTK search path for icons.
32 */
33void
34GNUNET_GTK_set_icon_search_path ()
35{
36 char *buf;
37
38 buf = GNUNET_GTK_installation_get_path (GNUNET_OS_IPK_ICONDIR);
39 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), buf);
40 GNUNET_free (buf);
41}
42
43
44/**
31 * Get the name of the directory where all of our package 45 * Get the name of the directory where all of our package
32 * data is stored ($PREFIX/share/) 46 * data is stored ($PREFIX/share/)
33 * 47 *
diff --git a/src/lib/trayicon.c b/src/lib/trayicon.c
new file mode 100644
index 00000000..200c9068
--- /dev/null
+++ b/src/lib/trayicon.c
@@ -0,0 +1,132 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/lib/trayicon.c
23 * @brief trayicon support
24 * @author Christian Grothoff
25 */
26#include "gnunet_gtk_config.h"
27#include "gnunet_gtk.h"
28
29
30/**
31 * Our tray icon.
32 */
33static GtkStatusIcon *tray_icon;
34
35/**
36 * The main window.
37 */
38static GtkWindow *main_window;
39
40
41/**
42 * We got a click on our tray icon. Toggle visibility of the main
43 * window.
44 */
45static void
46tray_icon_on_click(GtkStatusIcon *status_icon,
47 gpointer user_data)
48{
49 if (gtk_window_is_active (main_window))
50 gtk_widget_hide (GTK_WIDGET (main_window));
51 else
52 gtk_window_present (main_window);
53}
54
55
56/**
57 * We got a right-click on the tray icon. Display the context
58 * menu (which should have a 'quit' button).
59 */
60static int
61tray_icon_on_menu(GtkWidget *widget,
62 GdkEvent *event,
63 gpointer user_data)
64{
65 GtkMenu *tray_menu;
66 GdkEventButton *event_button;
67 GtkBuilder *builder;
68
69 if (event->type == GDK_BUTTON_PRESS)
70 {
71 event_button = (GdkEventButton *) event;
72 if (event_button->button == 3)
73 {
74 builder = GNUNET_GTK_get_new_builder ("gnunet_gtk_status_bar_menu.glade");
75 tray_menu = GTK_MENU (gtk_builder_get_object (builder,
76 "GNUNET_GTK_status_bar_popup_menu"));
77 gtk_menu_popup (tray_menu, NULL, NULL, NULL, NULL,
78 event_button->button, event_button->time);
79 g_object_unref (builder);
80 }
81 }
82 return FALSE;
83}
84
85
86/**
87 * Create our tray icon.
88 *
89 * @param main handle to the main window (show or hide)
90 * @param icon_name name of the tray icon file
91 * @param tooltip tooltip for the tray icon
92 */
93void
94GNUNET_GTK_tray_icon_create (GtkWindow *main,
95 const char *icon_name,
96 const char *tooltip)
97{
98 if (NULL != tray_icon)
99 {
100 GNUNET_break (0);
101 return;
102 }
103 main_window = main;
104 tray_icon = gtk_status_icon_new();
105 g_signal_connect(G_OBJECT(tray_icon), "activate",
106 G_CALLBACK(tray_icon_on_click), NULL);
107 g_signal_connect (G_OBJECT(tray_icon),
108 "button_press_event",
109 G_CALLBACK(tray_icon_on_menu),
110 tray_icon);
111 gtk_status_icon_set_from_icon_name (tray_icon,
112 icon_name);
113 gtk_status_icon_set_tooltip(tray_icon,
114 tooltip);
115 gtk_status_icon_set_visible(tray_icon, TRUE);
116}
117
118
119/**
120 * Destroy the tray icon.
121 */
122void
123GNUNET_GTK_tray_icon_destroy ()
124{
125 if (tray_icon == NULL)
126 return;
127 g_object_unref (G_OBJECT (tray_icon));
128 tray_icon = NULL;
129 main_window = NULL;
130}
131
132/* end of trayicon.c */