2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "vikfilelist.h"
29 GtkWidget
*file_selector
;
33 static void file_list_add ( VikFileList
*vfl
)
35 if ( ! vfl
->file_selector
)
38 g_assert ( (win
= gtk_widget_get_toplevel(GTK_WIDGET(vfl
))) );
39 vfl
->file_selector
= gtk_file_selection_new ("Choose file(s)");
40 gtk_file_selection_set_select_multiple ( GTK_FILE_SELECTION(vfl
->file_selector
), TRUE
);
41 gtk_window_set_transient_for ( GTK_WINDOW(vfl
->file_selector
), GTK_WINDOW(win
) );
42 gtk_window_set_destroy_with_parent ( GTK_WINDOW(vfl
->file_selector
), TRUE
);
45 if ( gtk_dialog_run ( GTK_DIALOG(vfl
->file_selector
) ) == GTK_RESPONSE_OK
) {
46 gchar
**files
= gtk_file_selection_get_selections ( GTK_FILE_SELECTION(vfl
->file_selector
) );
47 gchar
**fiter
= files
;
50 gtk_list_store_append ( GTK_LIST_STORE(vfl
->model
), &iter
);
51 gtk_list_store_set ( GTK_LIST_STORE(vfl
->model
), &iter
, 0, *fiter
, -1 );
56 gtk_widget_hide ( vfl
->file_selector
);
59 static void file_list_del ( VikFileList
*vfl
)
61 GtkTreeSelection
*ts
= gtk_tree_view_get_selection (GTK_TREE_VIEW(vfl
->treeview
));
63 if ( gtk_tree_selection_get_selected(ts
, NULL
, &iter
) )
64 gtk_list_store_remove(GTK_LIST_STORE(vfl
->model
), &iter
);
67 GType
vik_file_list_get_type (void)
69 static GType vs_type
= 0;
73 static const GTypeInfo vs_info
=
75 sizeof (VikFileListClass
),
77 NULL
, /* base_finalize */
78 NULL
, /* class init */
79 NULL
, /* class_finalize */
80 NULL
, /* class_data */
83 NULL
/* instance init */
85 vs_type
= g_type_register_static ( GTK_TYPE_VBOX
, "VikFileList", &vs_info
, 0 );
91 GtkWidget
*vik_file_list_new ( const gchar
*title
)
93 GtkWidget
*add_btn
, *del_btn
;
94 GtkWidget
*hbox
, *scrolledwindow
;
95 VikFileList
*vfl
= VIK_FILE_LIST ( g_object_new ( VIK_FILE_LIST_TYPE
, NULL
) );
97 GtkTreeViewColumn
*column
;
99 vfl
->model
= GTK_TREE_MODEL ( gtk_list_store_new(1, G_TYPE_STRING
) );
101 vfl
->treeview
= gtk_tree_view_new ( );
102 gtk_tree_view_set_model ( GTK_TREE_VIEW(vfl
->treeview
), vfl
->model
);
103 column
= gtk_tree_view_column_new_with_attributes ( title
, gtk_cell_renderer_text_new (), "text", 0, NULL
);
104 gtk_tree_view_append_column (GTK_TREE_VIEW (vfl
->treeview
), column
);
106 gtk_widget_set_size_request ( vfl
->treeview
, 200, 100);
108 add_btn
= gtk_button_new_with_label("Add...");
109 del_btn
= gtk_button_new_with_label("Delete");
111 g_signal_connect_swapped ( G_OBJECT(add_btn
), "clicked", G_CALLBACK(file_list_add
), vfl
);
112 g_signal_connect_swapped ( G_OBJECT(del_btn
), "clicked", G_CALLBACK(file_list_del
), vfl
);
114 hbox
= gtk_hbox_new(FALSE
, 2);
116 scrolledwindow
= gtk_scrolled_window_new ( NULL
, NULL
);
117 gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
118 gtk_container_add ( GTK_CONTAINER(scrolledwindow
), GTK_WIDGET(vfl
->treeview
) );
120 gtk_box_pack_start ( GTK_BOX(vfl
), scrolledwindow
, TRUE
, TRUE
, 3 );
123 gtk_box_pack_start ( GTK_BOX(hbox
), add_btn
, TRUE
, TRUE
, 3 );
124 gtk_box_pack_start ( GTK_BOX(hbox
), del_btn
, TRUE
, TRUE
, 3 );
125 gtk_box_pack_start ( GTK_BOX(vfl
), hbox
, FALSE
, FALSE
, 3 );
126 gtk_widget_show_all(GTK_WIDGET(vfl
));
128 vfl
->file_selector
= NULL
;
130 return GTK_WIDGET(vfl
);
133 static gboolean
get_file_name(GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
, GList
**list
)
136 gtk_tree_model_get ( model
, iter
, 0, &str
, -1 );
137 g_debug("get_file_name: %s", str
);
138 (*list
) = g_list_append((*list
), g_strdup(str
));
142 GList
*vik_file_list_get_files ( VikFileList
*vfl
)
145 gtk_tree_model_foreach (vfl
->model
, (GtkTreeModelForeachFunc
) get_file_name
, &list
);
149 void vik_file_list_set_files ( VikFileList
*vfl
, GList
*files
)
153 gtk_list_store_append ( GTK_LIST_STORE(vfl
->model
), &iter
);
154 gtk_list_store_set ( GTK_LIST_STORE(vfl
->model
), &iter
, 0, files
->data
, -1 );