2 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
6 * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <glib/gi18n.h>
29 static void babel_ui_selector_add_entry_cb ( gpointer data, gpointer user_data )
31 BabelFile *file = (BabelFile*)data;
32 GtkWidget *combo = GTK_WIDGET(user_data);
34 GList *formats = g_object_get_data ( G_OBJECT(combo), "formats" );
35 formats = g_list_append ( formats, file );
36 g_object_set_data ( G_OBJECT(combo), "formats", formats );
38 const gchar *label = file->label;
39 vik_combo_box_text_append ( combo, label );
42 void a_babel_ui_type_selector_dialog_sensitivity_cb ( GtkComboBox *widget, gpointer user_data )
44 /* user_data is the GtkDialog */
45 GtkDialog *dialog = GTK_DIALOG(user_data);
47 /* Retrieve the associated file format descriptor */
48 BabelFile *file = a_babel_ui_file_type_selector_get ( GTK_WIDGET(widget) );
51 /* Not NULL => valid selection */
52 gtk_dialog_set_response_sensitive ( dialog, GTK_RESPONSE_ACCEPT, TRUE );
54 /* NULL => invalid selection */
55 gtk_dialog_set_response_sensitive ( dialog, GTK_RESPONSE_ACCEPT, FALSE );
59 * a_babel_ui_file_type_selector_new:
60 * @mode: the mode to filter the file types
62 * Create a file type selector.
64 * This widget relies on a combo box listing labels of file formats.
65 * We store in the "data" of the GtkWidget a list with the BabelFile
66 * entries, in order to retrieve the selected file format.
68 * Returns: a GtkWidget
70 GtkWidget *a_babel_ui_file_type_selector_new ( BabelMode mode )
72 GList *formats = NULL;
73 /* Create the combo */
74 GtkWidget * combo = vik_combo_box_text_new ();
76 /* Add a first label to invite user to select a file format */
77 /* We store a NULL pointer to distinguish this entry */
78 formats = g_list_append ( formats, NULL );
79 vik_combo_box_text_append ( combo, _("Select a file format") );
81 /* Prepare space for file format list */
82 g_object_set_data ( G_OBJECT(combo), "formats", formats );
84 /* Add all known and compatible file formats */
85 a_babel_foreach_file_with_mode ( mode, babel_ui_selector_add_entry_cb, combo );
87 /* Initialize the selection with the really first entry */
88 gtk_combo_box_set_active ( GTK_COMBO_BOX(combo), 0 );
94 * a_babel_ui_file_type_selector_destroy:
95 * @selector: the selector to destroy
97 * Destroy the selector and any related data.
99 void a_babel_ui_file_type_selector_destroy ( GtkWidget *selector )
101 GList *formats = g_object_get_data ( G_OBJECT(selector), "formats" );
106 * a_babel_ui_file_type_selector_get:
107 * @selector: the selector
109 * Retrieve the selected file type.
111 * Returns: the selected BabelFile or NULL
113 BabelFile *a_babel_ui_file_type_selector_get ( GtkWidget *selector )
115 gint active = gtk_combo_box_get_active ( GTK_COMBO_BOX(selector) );
117 GList *formats = g_object_get_data ( G_OBJECT(selector), "formats" );
118 return (BabelFile*)g_list_nth_data ( formats, active );
125 * a_babel_ui_modes_new:
130 * Creates a selector for babel modes.
131 * This selector is based on 3 checkboxes.
133 * Returns: a GtkWidget packing all checkboxes.
135 GtkWidget *a_babel_ui_modes_new ( gboolean tracks, gboolean routes, gboolean waypoints )
137 GtkWidget *hbox = gtk_hbox_new( FALSE, 0 );
138 GtkWidget *button = NULL;
140 button = gtk_check_button_new_with_label ( _("Tracks") );
141 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), tracks );
142 gtk_box_pack_start ( GTK_BOX(hbox), button, TRUE, TRUE, 0 );
143 gtk_widget_show ( button );
145 button = gtk_check_button_new_with_label ( _("Routes") );
146 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(button), routes );
147 gtk_box_pack_start ( GTK_BOX(hbox), button, TRUE, TRUE, 0 );
148 gtk_widget_show ( button );
150 button = gtk_check_button_new_with_label ( _("Waypoints") );
151 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(button), waypoints );
152 gtk_box_pack_start ( GTK_BOX(hbox), button, TRUE, TRUE, 0 );
153 gtk_widget_show ( button );
159 * a_babel_ui_modes_get:
161 * @tracks: return value
162 * @routes: return value
163 * @waypoints: return value
165 * Retrieve state of checkboxes.
167 void a_babel_ui_modes_get ( GtkWidget *container, gboolean *tracks, gboolean *routes, gboolean *waypoints )
169 GList* children = gtk_container_get_children ( GTK_CONTAINER(container) );
170 GtkWidget *child = NULL;
172 child = g_list_nth_data ( children, 0 );
173 *tracks = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );
175 child = g_list_nth_data ( children, 1 );
176 *routes = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );
178 child = g_list_nth_data ( children, 2 );
179 *waypoints = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );