]> git.street.me.uk Git - andy/viking.git/blame - src/babel_ui.c
Use the last selected date when initializing the date search.
[andy/viking.git] / src / babel_ui.c
CommitLineData
b666a8ba
GB
1
2/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3/*
4 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
5 *
6 * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23#include <glib/gi18n.h>
24
25#include "babel.h"
26#include "babel_ui.h"
27
28
29static void babel_ui_selector_add_entry_cb ( gpointer data, gpointer user_data )
30{
31 BabelFile *file = (BabelFile*)data;
32 GtkWidget *combo = GTK_WIDGET(user_data);
33
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 );
37
38 const gchar *label = file->label;
39 vik_combo_box_text_append ( combo, label );
40}
41
42void a_babel_ui_type_selector_dialog_sensitivity_cb ( GtkComboBox *widget, gpointer user_data )
43{
44 /* user_data is the GtkDialog */
45 GtkDialog *dialog = GTK_DIALOG(user_data);
46
47 /* Retrieve the associated file format descriptor */
48 BabelFile *file = a_babel_ui_file_type_selector_get ( GTK_WIDGET(widget) );
49
50 if ( file )
51 /* Not NULL => valid selection */
52 gtk_dialog_set_response_sensitive ( dialog, GTK_RESPONSE_ACCEPT, TRUE );
53 else
54 /* NULL => invalid selection */
55 gtk_dialog_set_response_sensitive ( dialog, GTK_RESPONSE_ACCEPT, FALSE );
56}
57
58/**
59 * a_babel_ui_file_type_selector_new:
60 * @mode: the mode to filter the file types
61 *
62 * Create a file type selector.
63 *
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.
67 *
68 * Returns: a GtkWidget
69 */
70GtkWidget *a_babel_ui_file_type_selector_new ( BabelMode mode )
71{
72 GList *formats = NULL;
73 /* Create the combo */
74 GtkWidget * combo = vik_combo_box_text_new ();
75
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") );
80
81 /* Prepare space for file format list */
82 g_object_set_data ( G_OBJECT(combo), "formats", formats );
83
84 /* Add all known and compatible file formats */
85 a_babel_foreach_file_with_mode ( mode, babel_ui_selector_add_entry_cb, combo );
86
87 /* Initialize the selection with the really first entry */
88 gtk_combo_box_set_active ( GTK_COMBO_BOX(combo), 0 );
89
90 return combo;
91}
92
93/**
94 * a_babel_ui_file_type_selector_destroy:
95 * @selector: the selector to destroy
96 *
97 * Destroy the selector and any related data.
98 */
99void a_babel_ui_file_type_selector_destroy ( GtkWidget *selector )
100{
101 GList *formats = g_object_get_data ( G_OBJECT(selector), "formats" );
102 g_free ( formats );
103}
104
105/**
106 * a_babel_ui_file_type_selector_get:
107 * @selector: the selector
108 *
109 * Retrieve the selected file type.
110 *
111 * Returns: the selected BabelFile or NULL
112 */
113BabelFile *a_babel_ui_file_type_selector_get ( GtkWidget *selector )
114{
115 gint active = gtk_combo_box_get_active ( GTK_COMBO_BOX(selector) );
116 if (active >= 0) {
117 GList *formats = g_object_get_data ( G_OBJECT(selector), "formats" );
118 return (BabelFile*)g_list_nth_data ( formats, active );
119 } else {
120 return NULL;
121 }
122}
123
124/**
125 * a_babel_ui_modes_new:
126 * @tracks:
127 * @routes:
128 * @waypoints:
129 *
130 * Creates a selector for babel modes.
131 * This selector is based on 3 checkboxes.
132 *
133 * Returns: a GtkWidget packing all checkboxes.
134 */
135GtkWidget *a_babel_ui_modes_new ( gboolean tracks, gboolean routes, gboolean waypoints )
136{
137 GtkWidget *hbox = gtk_hbox_new( FALSE, 0 );
138 GtkWidget *button = NULL;
139
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 );
144
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 );
149
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 );
154
155 return hbox;
156}
157
158/**
159 * a_babel_ui_modes_get:
160 * @container:
161 * @tracks: return value
162 * @routes: return value
163 * @waypoints: return value
164 *
165 * Retrieve state of checkboxes.
166 */
167void a_babel_ui_modes_get ( GtkWidget *container, gboolean *tracks, gboolean *routes, gboolean *waypoints )
168{
169 GList* children = gtk_container_get_children ( GTK_CONTAINER(container) );
170 GtkWidget *child = NULL;
171
172 child = g_list_nth_data ( children, 0 );
173 *tracks = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );
174
175 child = g_list_nth_data ( children, 1 );
176 *routes = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );
177
178 child = g_list_nth_data ( children, 2 );
179 *waypoints = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(child) );
180}
181