/* This file is part of GNUnet. (C) 2010, 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file src/fs/gnunet-fs-gtk.c * @brief Main function of gnunet-fs-gtk * @author Christian Grothoff */ #include "gnunet-fs-gtk_common.h" #include "gnunet-fs-gtk_event-handler.h" #include /** * Should gnunet-fs-gtk start in tray mode? */ static int tray_only; /** * Handle to our main loop. */ static struct GNUNET_GTK_MainLoop *ml; /** * Handle for file-sharing operations. */ static struct GNUNET_FS_Handle *fs; /** * Return handle for file-sharing operations. * * @return NULL on error */ struct GNUNET_FS_Handle * GNUNET_FS_GTK_get_fs_handle () { return fs; } /** * Get our configuration. * * @return configuration handle */ const struct GNUNET_CONFIGURATION_Handle * GNUNET_FS_GTK_get_configuration (void) { return GNUNET_GTK_main_loop_get_configuration (ml); } /** * Get an object from the main window. * * @param name name of the object * @return NULL on error */ GObject * GNUNET_FS_GTK_get_main_window_object (const char *name) { return GNUNET_GTK_main_loop_get_object (ml, name); } /** * Return the list store with anonymity levels. * * @return the list store */ GtkTreeModel * GNUNET_FS_GTK_get_anonymity_level_list_store () { return GTK_TREE_MODEL (GNUNET_FS_GTK_get_main_window_object ("anonymity_level_liststore")); } /** * Task run on shutdown. * FIXME-STYLE: does this need to be a separate task!? * * @param cls NULL * @param tc scheduler context, unused */ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_GTK_main_loop_quit (ml); if (fs != NULL) { GNUNET_FS_stop (fs); fs = NULL; } } /** * Callback invoked if the application is supposed to exit. * * @param object origin of the quit event, unused * @param user_data global builder instance, unused */ void GNUNET_GTK_quit_cb (GObject * object, gpointer user_data) { GNUNET_GTK_tray_icon_destroy (); GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &shutdown_task, NULL); } /** * Actual main function run right after GNUnet's scheduler * is initialized. Initializes up GTK and Glade. * * @param cls handle to the main loop ('struct GNUNET_GTK_MainLoop') * @param tc scheduler context, unused */ static void run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GtkWidget *main_window; GtkTreeView *metadata_tree; ml = cls; GNUNET_GTK_set_icon_search_path (); GNUNET_GTK_setup_nls (); /* setup main window */ main_window = GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window")); gtk_window_maximize (GTK_WINDOW (main_window)); /* Allow multiple selection in metadata view; */ /* FIXME-GTK3: this can be done within (modern versions of) glade */ metadata_tree = GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object ("GNUNET_GTK_main_window_metadata_treeview")); gtk_tree_selection_set_mode (gtk_tree_view_get_selection (metadata_tree), GTK_SELECTION_MULTIPLE); GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window), "gnunet-fs-gtk", "gnunet-fs-gtk"); /* initialize file-sharing */ fs = GNUNET_FS_start (GNUNET_GTK_main_loop_get_configuration (ml), "gnunet-fs-gtk", &GNUNET_GTK_fs_event_handler, NULL, GNUNET_FS_FLAGS_NONE /* | GNUNET_FS_FLAGS_PERSISTENCE | * GNUNET_FS_FLAGS_DO_PROBES */ , GNUNET_FS_OPTIONS_END); if (NULL == fs) { GNUNET_GTK_main_loop_quit (ml); return; } /* make GUI visible */ if (!tray_only) { gtk_widget_show (main_window); gtk_window_present (GTK_WINDOW (main_window)); } } int main (int argc, char *const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { {'t', "tray", NULL, gettext_noop ("start in tray mode"), 0, &GNUNET_GETOPT_set_one, &tray_only}, GNUNET_GETOPT_OPTION_END }; if (GNUNET_OK != GNUNET_GTK_main_loop_start ("gnunet-fs-gtk", "GTK GUI for GNUnet", argc, argv, options, "gnunet_fs_gtk_main_window.glade", &run)) return 1; return 0; } /* end of gnunet-fs-gtk.c */