aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk.c')
-rw-r--r--src/fs/gnunet-fs-gtk.c92
1 files changed, 61 insertions, 31 deletions
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index ccc05c15..7cee7ac3 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -23,6 +23,7 @@
23 * @brief Main function of gnunet-fs-gtk 23 * @brief Main function of gnunet-fs-gtk
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-fs-gtk.h"
26#include "gnunet-fs-gtk_common.h" 27#include "gnunet-fs-gtk_common.h"
27#include "gnunet-fs-gtk_event-handler.h" 28#include "gnunet-fs-gtk_event-handler.h"
28#include <gdk/gdkkeysyms.h> 29#include <gdk/gdkkeysyms.h>
@@ -172,14 +173,14 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172void 173void
173GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) 174GNUNET_GTK_quit_cb (GObject * object, gpointer user_data)
174{ 175{
175 GtkWidget *main_window = GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ( 176 struct GNUNET_GTK_MainWindowContext *main_context;
176 "GNUNET_GTK_main_window"));
177 177
178 main_window_save_position (main_window); 178 main_window_save_position (main_context->main_window);
179 179
180 GNUNET_GTK_tray_icon_destroy (); 180 GNUNET_GTK_tray_icon_destroy ();
181 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 181 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
182 &shutdown_task, NULL); 182 &shutdown_task, NULL);
183 GNUNET_free (main_context);
183} 184}
184 185
185 186
@@ -193,72 +194,97 @@ GNUNET_GTK_quit_cb (GObject * object, gpointer user_data)
193static void 194static void
194run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 195run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
195{ 196{
196 GtkWidget *main_window;
197 GtkTreeView *metadata_tree;
198 unsigned long long dl_parallel, req_parallel, window_x, window_y, 197 unsigned long long dl_parallel, req_parallel, window_x, window_y,
199 window_width, window_height; 198 window_width, window_height;
200 int maximized; 199 int maximized;
201 const struct GNUNET_CONFIGURATION_Handle *cfg; 200
201 struct GNUNET_GTK_MainWindowContext *main_context;
202
203 main_context = GNUNET_malloc (sizeof (struct GNUNET_GTK_MainWindowContext));
202 204
203 ml = cls; 205 ml = cls;
204 206
207 /* setup main context */
208 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (cls, main_context))
209 {
210 GNUNET_free (main_context);
211 return;
212 }
213
214 main_context->builder = GNUNET_GTK_main_loop_get_builder (cls);
215 main_context->cfg = GNUNET_GTK_main_loop_get_configuration (cls);
216 main_context->search_ns_treestore = GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_treestore"));
217 main_context->main_window = GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window"));
218 main_context->ns_selector_treeview = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object ("namespace_selector_treeview"));
219 main_context->ns_selector_window = GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("namespace_selector_window"));
220 main_context->ns_dropdown_button = GTK_TOGGLE_BUTTON (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_dropdown_button"));
221 main_context->search_ns_label = GTK_LABEL (GNUNET_FS_GTK_get_main_window_object ("main_window_search_selected_namespace_label"));
222
223 main_context->search_entry = GTK_ENTRY (GNUNET_FS_GTK_get_main_window_object ("main_window_search_entry"));
224
225 main_context->anonymity_combo = GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object ("main_window_search_anonymity_combobox"));
226 main_context->anonymity_level_liststore = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("anonymity_level_liststore"));
227
228 main_context->preview_image = GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_preview_image"));
229 main_context->md_liststore = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_meta_data_list_store"));
230 main_context->md_treeview = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_metadata_treeview"));
231 main_context->ns_callback_registered = GNUNET_NO;
232
205 GNUNET_GTK_set_icon_search_path (); 233 GNUNET_GTK_set_icon_search_path ();
206 GNUNET_GTK_setup_nls (); 234 GNUNET_GTK_setup_nls ();
207 235
208 /* setup main window */ 236 /* Make sure button class is realized */
209 main_window = 237 g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
210 GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object 238 /* GNUnet main window assumes that images on buttons are visible,
211 ("GNUNET_GTK_main_window")); 239 * override the theme's gtkrc setting
212 240 */
213 cfg = GNUNET_GTK_main_loop_get_configuration (ml); 241 g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
214 242
215 maximized = GNUNET_CONFIGURATION_get_value_yesno (cfg, 243 /* setup main window */
244 maximized = GNUNET_CONFIGURATION_get_value_yesno (main_context->cfg,
216 "gnunet-gtk", "MAIN_WINDOW_MAXIMIZED"); 245 "gnunet-gtk", "MAIN_WINDOW_MAXIMIZED");
217 if (GNUNET_SYSERR == maximized) 246 if (GNUNET_SYSERR == maximized)
218 maximized = GNUNET_YES; 247 maximized = GNUNET_YES;
219 if ( (GNUNET_NO == maximized) && 248 if ( (GNUNET_NO == maximized) &&
220 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 249 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
221 "MAIN_WINDOW_X", &window_x)) && 250 "MAIN_WINDOW_X", &window_x)) &&
222 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 251 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
223 "MAIN_WINDOW_Y", &window_y)) && 252 "MAIN_WINDOW_Y", &window_y)) &&
224 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 253 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
225 "MAIN_WINDOW_WIDTH", &window_width)) && 254 "MAIN_WINDOW_WIDTH", &window_width)) &&
226 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 255 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
227 "MAIN_WINDOW_HEIGHT", &window_height)) ) 256 "MAIN_WINDOW_HEIGHT", &window_height)) )
228 { 257 {
229 gtk_window_move (GTK_WINDOW (main_window), window_x, window_y); 258 gtk_window_move (GTK_WINDOW (main_context->main_window), window_x, window_y);
230 gtk_window_resize (GTK_WINDOW (main_window), window_width, window_height); 259 gtk_window_resize (GTK_WINDOW (main_context->main_window), window_width, window_height);
231 } 260 }
232 else 261 else
233 { 262 {
234 /* If anything is wrong - play safe and show it maximized */ 263 /* If anything is wrong - play safe and show it maximized */
235 gtk_window_maximize (GTK_WINDOW (main_window)); 264 gtk_window_maximize (GTK_WINDOW (main_context->main_window));
236 } 265 }
237 266
238 /* Allow multiple selection in metadata view; */ 267 /* Allow multiple selection in metadata view; */
239 /* FIXME-GTK3: this can be done within (modern versions of) glade */ 268 /* FIXME-GTK3: this can be done within (modern versions of) glade */
240 metadata_tree = 269 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (main_context->md_treeview),
241 GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
242 ("GNUNET_GTK_main_window_metadata_treeview"));
243 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (metadata_tree),
244 GTK_SELECTION_MULTIPLE); 270 GTK_SELECTION_MULTIPLE);
245 271
246 GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), 272 GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_context->main_window),
247 "gnunet-fs-gtk", 273 "gnunet-fs-gtk",
248 "gnunet-fs-gtk"); 274 "gnunet-fs-gtk");
249 275
250 /* FIXME: should these '1's be here? Maybe better to put them into 276 /* FIXME: should these '1's be here? Maybe better to put them into
251 * default config files? 277 * default config files?
252 */ 278 */
253 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 279 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
254 "MAX_PARALLEL_DOWNLOADS", &dl_parallel)) 280 "MAX_PARALLEL_DOWNLOADS", &dl_parallel))
255 dl_parallel = 1; 281 dl_parallel = 1;
256 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "gnunet-gtk", 282 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (main_context->cfg, "gnunet-gtk",
257 "MAX_PARALLEL_REQUESTS", &req_parallel)) 283 "MAX_PARALLEL_REQUESTS", &req_parallel))
258 req_parallel = 1; 284 req_parallel = 1;
259 285
260 /* initialize file-sharing */ 286 /* initialize file-sharing */
261 fs = GNUNET_FS_start (cfg, "gnunet-fs-gtk", 287 fs = GNUNET_FS_start (main_context->cfg, "gnunet-fs-gtk",
262 &GNUNET_GTK_fs_event_handler, NULL, 288 &GNUNET_GTK_fs_event_handler, NULL,
263 GNUNET_FS_FLAGS_NONE | GNUNET_FS_FLAGS_PERSISTENCE 289 GNUNET_FS_FLAGS_NONE | GNUNET_FS_FLAGS_PERSISTENCE
264 /* | GNUNET_FS_FLAGS_DO_PROBES */ , 290 /* | GNUNET_FS_FLAGS_DO_PROBES */ ,
@@ -269,14 +295,18 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
269 GNUNET_FS_OPTIONS_END); 295 GNUNET_FS_OPTIONS_END);
270 if (NULL == fs) 296 if (NULL == fs)
271 { 297 {
272 GNUNET_GTK_main_loop_quit (ml); 298 GNUNET_GTK_main_loop_quit (cls);
299 GNUNET_free (main_context);
273 return; 300 return;
274 } 301 }
302
303 GNUNET_GTK_main_window_refresh_ns_list (main_context);
304
275 /* make GUI visible */ 305 /* make GUI visible */
276 if (!tray_only) 306 if (!tray_only)
277 { 307 {
278 gtk_widget_show (main_window); 308 gtk_widget_show (main_context->main_window);
279 gtk_window_present (GTK_WINDOW (main_window)); 309 gtk_window_present (GTK_WINDOW (main_context->main_window));
280 } 310 }
281 311
282} 312}