diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk.c | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c new file mode 100644 index 00000000..2fe466e4 --- /dev/null +++ b/src/fs/gnunet-fs-gtk.c | |||
@@ -0,0 +1,249 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010 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/gnunet-gtk.c | ||
23 | * @brief Main function of gnunet-gtk | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "common.h" | ||
27 | #include "fs_event_handler.h" | ||
28 | |||
29 | /** | ||
30 | * Should gnunet-gtk start in tray mode? | ||
31 | */ | ||
32 | static int tray_only; | ||
33 | |||
34 | /** | ||
35 | * Handle to our main loop. | ||
36 | */ | ||
37 | static struct GNUNET_GTK_MainLoop *ml; | ||
38 | |||
39 | /** | ||
40 | * Handle for file-sharing operations. | ||
41 | */ | ||
42 | static struct GNUNET_FS_Handle *fs; | ||
43 | |||
44 | /** | ||
45 | * List of plugins for meta data extraction. | ||
46 | */ | ||
47 | static struct EXTRACTOR_PluginList *plugins; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Return handle for file-sharing operations. | ||
52 | * | ||
53 | * @return NULL on error | ||
54 | */ | ||
55 | struct GNUNET_FS_Handle * | ||
56 | GNUNET_FS_GTK_get_fs_handle () | ||
57 | { | ||
58 | return fs; | ||
59 | } | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Get LE plugin list. | ||
64 | */ | ||
65 | struct EXTRACTOR_PluginList * | ||
66 | GNUNET_FS_GTK_get_le_plugins () | ||
67 | { | ||
68 | return plugins; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Get cfg. | ||
74 | */ | ||
75 | const struct GNUNET_CONFIGURATION_Handle * | ||
76 | GNUNET_FS_GTK_get_configuration (void) | ||
77 | { | ||
78 | return GNUNET_GTK_main_loop_get_configuration (ml); | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Get an object from the main window. | ||
84 | * | ||
85 | * @param name name of the object | ||
86 | * @return NULL on error | ||
87 | */ | ||
88 | GObject * | ||
89 | GNUNET_FS_GTK_get_main_window_object (const char *name) | ||
90 | { | ||
91 | return GNUNET_GTK_main_loop_get_object (ml, name); | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Task run on shutdown. | ||
97 | * FIXME: does this need to be a separate task!? | ||
98 | */ | ||
99 | static void | ||
100 | shutdown_task (void *cls, | ||
101 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
102 | { | ||
103 | if (fs != NULL) | ||
104 | { | ||
105 | GNUNET_FS_stop (fs); | ||
106 | fs = NULL; | ||
107 | } | ||
108 | EXTRACTOR_plugin_remove_all (plugins); | ||
109 | plugins = NULL; | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Callback invoked if the application is supposed to exit. | ||
115 | */ | ||
116 | void | ||
117 | GNUNET_GTK_quit_cb (GtkObject *object, | ||
118 | gpointer user_data) | ||
119 | { | ||
120 | GNUNET_GTK_tray_icon_destroy (); | ||
121 | GNUNET_GTK_main_loop_quit (ml); | ||
122 | GNUNET_SCHEDULER_add_now (&shutdown_task, | ||
123 | NULL); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Search selected in 'file' menu. (from main_window_file_search.c) | ||
129 | */ | ||
130 | void | ||
131 | GNUNET_GTK_main_menu_file_search_activate_cb (GtkWidget * dummy, | ||
132 | gpointer data); | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Add the tab with the 'new' icon for starting a search. | ||
137 | */ | ||
138 | static void | ||
139 | add_new_tab () | ||
140 | { | ||
141 | GtkNotebook *notebook; | ||
142 | GtkWindow *sf; | ||
143 | gint pages; | ||
144 | GtkBuilder *builder; | ||
145 | GtkWidget *label; | ||
146 | GtkWidget *frame; | ||
147 | |||
148 | builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_main_tab_new_frame.glade"); | ||
149 | |||
150 | /* load frame */ | ||
151 | sf = GTK_WINDOW (gtk_builder_get_object (builder, | ||
152 | "_main_tab_new_frame")); | ||
153 | label = gtk_bin_get_child (GTK_BIN (sf)); | ||
154 | gtk_widget_ref (label); | ||
155 | gtk_container_remove (GTK_CONTAINER (sf), label); | ||
156 | gtk_widget_destroy (GTK_WIDGET (sf)); | ||
157 | g_object_unref (builder); | ||
158 | g_signal_connect(G_OBJECT(label), "clicked", | ||
159 | G_CALLBACK(&GNUNET_GTK_main_menu_file_search_activate_cb), NULL); | ||
160 | |||
161 | notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); | ||
162 | pages = gtk_notebook_get_n_pages (notebook); | ||
163 | frame = gtk_label_new (""); | ||
164 | gtk_widget_show (frame); | ||
165 | gtk_notebook_append_page (notebook, | ||
166 | frame, | ||
167 | label); | ||
168 | gtk_notebook_set_current_page (notebook, | ||
169 | pages); | ||
170 | gtk_widget_show (GTK_WIDGET (notebook)); | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Actual main function run right after GNUnet's scheduler | ||
176 | * is initialized. Initializes up GTK and Glade. | ||
177 | */ | ||
178 | static void | ||
179 | run (void *cls, | ||
180 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
181 | { | ||
182 | GtkWidget *main_window; | ||
183 | ml = cls; | ||
184 | |||
185 | GNUNET_GTK_set_icon_search_path (); | ||
186 | GNUNET_GTK_setup_nls (); | ||
187 | |||
188 | /* setup main window */ | ||
189 | main_window = GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window")); | ||
190 | gtk_window_maximize (GTK_WINDOW (main_window)); | ||
191 | GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), | ||
192 | "gnunet-gtk" /* FIXME: rename icon? */, | ||
193 | "gnunet-fs-gtk"); | ||
194 | |||
195 | /* initialize file-sharing */ | ||
196 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
197 | fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml), | ||
198 | "gnunet-gtk", | ||
199 | &GNUNET_GTK_fs_event_handler, | ||
200 | NULL, | ||
201 | GNUNET_FS_FLAGS_NONE /* fixme later for persistence/probes */, | ||
202 | /* set other options here later! */ | ||
203 | GNUNET_FS_OPTIONS_END); | ||
204 | if (fs != NULL) | ||
205 | { | ||
206 | add_new_tab (); | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_create_pseudonym"))); | ||
211 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_advertise_pseudonym"))); | ||
212 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_publish"))); | ||
213 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_search"))); | ||
214 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_download_uri"))); | ||
215 | gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_menu_file_open_gnunet_directory"))); | ||
216 | /* FIXME: set warning in status bar... */ | ||
217 | } | ||
218 | /* make GUI visible */ | ||
219 | if (!tray_only) | ||
220 | { | ||
221 | gtk_widget_show (main_window); | ||
222 | gtk_window_present (GTK_WINDOW (main_window)); | ||
223 | } | ||
224 | } | ||
225 | |||
226 | |||
227 | int | ||
228 | main (int argc, char *const *argv) | ||
229 | { | ||
230 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
231 | {'t', "tray", NULL, | ||
232 | gettext_noop ("start in tray mode"), 0, | ||
233 | &GNUNET_GETOPT_set_one, &tray_only}, | ||
234 | GNUNET_GETOPT_OPTION_END | ||
235 | }; | ||
236 | |||
237 | if (GNUNET_OK != | ||
238 | GNUNET_GTK_main_loop_start ("gnunet-gtk", | ||
239 | "GTK GUI for GNUnet", | ||
240 | argc, argv, | ||
241 | options, | ||
242 | "gnunet_fs_gtk_main_window.glade", | ||
243 | &run)) | ||
244 | return 1; | ||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | |||
249 | /* end of gnunet-fs-gtk.c */ | ||