Mercurial > audlegacy
annotate src/audacious/ui_fileopener.c @ 2535:97a305e550cf trunk
[svn] - make libmcs a forced requirement
- remove legacy configdb engines
- remove RcFile class (use g_keyfile instead)
author | nenolod |
---|---|
date | Sat, 17 Feb 2007 00:59:50 -0800 |
parents | 04642d2d0941 |
children | 4b8db8c0521d |
rev | line source |
---|---|
2417 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; under version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * You should have received a copy of the GNU General Public License | |
14 * along with this program; if not, write to the Free Software | |
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
16 */ | |
17 | |
18 #include "ui_fileopener.h" | |
19 | |
20 #include <glib/gi18n.h> | |
21 #include <string.h> | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
22 #include <gdk/gdkkeysyms.h> |
2417 | 23 |
24 #include "input.h" | |
25 #include "main.h" | |
26 #include "playback.h" | |
27 #include "strings.h" | |
28 #include "ui_playlist.h" | |
29 | |
30 static void | |
31 filebrowser_add_files(GtkFileChooser * browser, | |
32 GSList * files) | |
33 { | |
34 GSList *cur; | |
35 gchar *ptr; | |
36 guint ctr = 0; | |
37 Playlist *playlist = playlist_get_active(); | |
38 | |
39 for (cur = files; cur; cur = g_slist_next(cur)) { | |
40 | |
41 if (g_file_test(cur->data,G_FILE_TEST_IS_DIR)) { | |
42 playlist_add_dir(playlist, (const gchar *) cur->data); | |
43 } else { | |
44 playlist_add(playlist, (const gchar *) cur->data); | |
45 } | |
46 | |
47 if (++ctr == 20) { | |
48 playlistwin_update_list(playlist); | |
49 ctr = 0; | |
50 while (gtk_events_pending() ) gtk_main_iteration(); | |
51 } | |
52 } | |
53 | |
54 playlistwin_update_list(playlist); | |
55 | |
56 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
57 | |
58 g_free(cfg.filesel_path); | |
59 cfg.filesel_path = ptr; | |
60 } | |
61 | |
62 static void | |
63 action_button_cb(GtkWidget *widget, gpointer data) | |
64 { | |
65 GtkWidget *window = g_object_get_data(data, "window"); | |
66 GtkWidget *chooser = g_object_get_data(data, "chooser"); | |
67 GtkWidget *toggle = g_object_get_data(data, "toggle-button"); | |
68 cfg.close_dialog_open = | |
69 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)); | |
70 | |
71 gboolean play_button = | |
72 GPOINTER_TO_INT(g_object_get_data(data, "play-button")); | |
73 | |
74 | |
75 GSList *files; | |
76 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser)); | |
77 if (!files) return; | |
78 | |
79 if (play_button) | |
80 playlist_clear(playlist_get_active()); | |
81 | |
82 filebrowser_add_files(GTK_FILE_CHOOSER(chooser), files); | |
83 g_slist_foreach(files, (GFunc) g_free, NULL); | |
84 g_slist_free(files); | |
85 | |
86 if (play_button) | |
87 playback_initiate(); | |
88 | |
89 if (cfg.close_dialog_open) | |
90 gtk_widget_destroy(window); | |
91 } | |
92 | |
93 | |
94 static void | |
95 close_button_cb(GtkWidget *widget, gpointer data) | |
96 { | |
97 gtk_widget_destroy(GTK_WIDGET(data)); | |
98 } | |
99 | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
100 static gboolean |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
101 filebrowser_on_keypress(GtkWidget * browser, |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
102 GdkEventKey * event, |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
103 gpointer data) |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
104 { |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
105 if (event->keyval == GDK_Escape) { |
2449 | 106 gtk_widget_destroy(browser); |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
107 return TRUE; |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
108 } |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
109 |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
110 return FALSE; |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
111 } |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
112 |
2417 | 113 void |
114 util_run_filebrowser_gtk2style(gboolean play_button) | |
115 { | |
2449 | 116 static GtkWidget *window = NULL; |
2417 | 117 GtkWidget *vbox, *hbox, *bbox; |
118 GtkWidget *chooser; | |
119 GtkWidget *action_button, *close_button; | |
120 GtkWidget *toggle; | |
121 | |
2490
49e27e4d8426
[svn] - trying to open filebrowser when it is already open will raise the filebrowser.
yaz
parents:
2449
diff
changeset
|
122 if(window) { |
49e27e4d8426
[svn] - trying to open filebrowser when it is already open will raise the filebrowser.
yaz
parents:
2449
diff
changeset
|
123 gtk_window_present(GTK_WINDOW(window)); /* raise filebrowser */ |
2449 | 124 return; |
2490
49e27e4d8426
[svn] - trying to open filebrowser when it is already open will raise the filebrowser.
yaz
parents:
2449
diff
changeset
|
125 } |
2449 | 126 |
2417 | 127 gchar *window_title = play_button ? _("Open Files") : _("Add Files"); |
128 gchar *toggle_text = play_button ? | |
129 _("Close dialog on Open") : _("Close dialog on Add"); | |
130 gpointer action_stock = play_button ? GTK_STOCK_OPEN : GTK_STOCK_ADD; | |
131 | |
132 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
133 gtk_window_set_title(GTK_WINDOW(window), window_title); | |
134 gtk_window_set_default_size(GTK_WINDOW(window), 700, 450); | |
2440
7f0318090690
[svn] - set the gtk2 fileopener position to the center of the screen
giacomo
parents:
2432
diff
changeset
|
135 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
2417 | 136 gtk_container_set_border_width(GTK_CONTAINER(window), 10); |
137 | |
138 vbox = gtk_vbox_new(FALSE, 0); | |
139 gtk_container_add(GTK_CONTAINER(window), vbox); | |
140 | |
141 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
142 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
143 if (cfg.filesel_path) | |
144 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
145 cfg.filesel_path); | |
2422 | 146 gtk_box_pack_start(GTK_BOX(vbox), chooser, TRUE, TRUE, 3); |
2417 | 147 |
148 hbox = gtk_hbox_new(TRUE, 0); | |
2422 | 149 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 3); |
2417 | 150 |
151 toggle = gtk_check_button_new_with_label(toggle_text); | |
152 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
153 cfg.close_dialog_open ? TRUE : FALSE); | |
2422 | 154 gtk_box_pack_start(GTK_BOX(hbox), toggle, TRUE, TRUE, 3); |
2417 | 155 |
156 bbox = gtk_hbutton_box_new(); | |
157 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
2422 | 158 gtk_box_set_spacing(GTK_BOX(bbox), 6); |
159 gtk_box_pack_end(GTK_BOX(hbox), bbox, TRUE, TRUE, 3); | |
2417 | 160 |
161 close_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
162 action_button = gtk_button_new_from_stock(action_stock); | |
163 gtk_container_add(GTK_CONTAINER(bbox), close_button); | |
164 gtk_container_add(GTK_CONTAINER(bbox), action_button); | |
165 | |
2420 | 166 /* this storage object holds several other objects which are used in the |
167 * callback functions | |
168 */ | |
2417 | 169 gpointer storage = g_object_new(G_TYPE_OBJECT, NULL); |
170 g_object_set_data(storage, "window", window); | |
171 g_object_set_data(storage, "chooser", chooser); | |
172 g_object_set_data(storage, "toggle-button", toggle); | |
173 g_object_set_data(storage, "play-button", GINT_TO_POINTER(play_button)); | |
174 | |
175 g_signal_connect(chooser, "file-activated", | |
176 G_CALLBACK(action_button_cb), storage); | |
177 g_signal_connect(action_button, "clicked", | |
178 G_CALLBACK(action_button_cb), storage); | |
179 g_signal_connect(close_button, "clicked", | |
180 G_CALLBACK(close_button_cb), window); | |
181 g_signal_connect(window, "destroy", | |
182 G_CALLBACK(gtk_widget_destroyed), &window); | |
183 | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
184 g_signal_connect(window, "key_press_event", |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
185 G_CALLBACK(filebrowser_on_keypress), |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
186 NULL); |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
187 |
2417 | 188 gtk_widget_show_all(window); |
189 } | |
190 | |
191 /* | |
192 * Derived from Beep Media Player 0.9.6.1. | |
193 * Which is (C) 2003 - 2006 Milosz Derezynski &c | |
194 * | |
195 * Although I changed it quite a bit. -nenolod | |
196 */ | |
197 static void filebrowser_changed_classic(GtkFileSelection * filesel) | |
198 { | |
199 GList *list; | |
200 GList *node; | |
201 char *filename = (char *) | |
202 gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); | |
203 GtkListStore *store; | |
204 GtkTreeIter iter; | |
205 | |
206 if ((list = input_scan_dir(filename)) != NULL) | |
207 { | |
208 /* | |
209 * We enter a directory that has been "hijacked" by an | |
210 * input-plugin. This is used by the CDDA plugin | |
211 */ | |
212 store = | |
213 GTK_LIST_STORE(gtk_tree_view_get_model | |
214 (GTK_TREE_VIEW(filesel->file_list))); | |
215 gtk_list_store_clear(store); | |
216 | |
217 node = list; | |
218 while (node) { | |
219 gtk_list_store_append(store, &iter); | |
220 gtk_list_store_set(store, &iter, 0, node->data, -1); | |
221 g_free(node->data); | |
222 node = g_list_next(node); | |
223 } | |
224 | |
225 g_list_free(list); | |
226 } | |
227 } | |
228 | |
229 static void filebrowser_entry_changed_classic(GtkEditable * entry, gpointer data) | |
230 { | |
231 filebrowser_changed_classic(GTK_FILE_SELECTION(data)); | |
232 } | |
233 | |
234 | |
235 static gboolean | |
236 util_filebrowser_is_dir_classic(GtkFileSelection * filesel) | |
237 { | |
238 char *text; | |
239 struct stat buf; | |
240 gboolean retv = FALSE; | |
241 | |
242 text = g_strdup(gtk_file_selection_get_filename(filesel)); | |
243 | |
244 if (stat(text, &buf) == 0 && S_ISDIR(buf.st_mode)) { | |
245 /* Selected directory */ | |
246 int len = strlen(text); | |
247 if (len > 3 && !strcmp(text + len - 4, "/../")) { | |
248 if (len == 4) | |
249 /* At the root already */ | |
250 *(text + len - 3) = '\0'; | |
251 else { | |
252 char *ptr; | |
253 *(text + len - 4) = '\0'; | |
254 ptr = strrchr(text, '/'); | |
255 *(ptr + 1) = '\0'; | |
256 } | |
257 } else if (len > 2 && !strcmp(text + len - 3, "/./")) | |
258 *(text + len - 2) = '\0'; | |
259 gtk_file_selection_set_filename(filesel, text); | |
260 retv = TRUE; | |
261 } | |
262 g_free(text); | |
263 return retv; | |
264 } | |
265 | |
266 static void filebrowser_add_files_classic(gchar ** files, | |
267 GtkFileSelection * filesel) | |
268 { | |
269 int ctr = 0; | |
270 char *ptr; | |
271 Playlist *playlist = playlist_get_active(); | |
272 | |
273 | |
274 while (files[ctr] != NULL) { | |
2500 | 275 playlist_add(playlist, files[ctr++]); |
2417 | 276 } |
277 playlistwin_update_list(playlist); | |
278 | |
279 gtk_label_get(GTK_LABEL(GTK_BIN(filesel->history_pulldown)->child), | |
280 &ptr); | |
281 | |
282 /* This will give an extra slash if the current dir is the root. */ | |
283 cfg.filesel_path = g_strconcat(ptr, "/", NULL); | |
284 } | |
285 | |
286 static void filebrowser_ok_classic(GtkWidget * w, GtkWidget * filesel) | |
287 { | |
288 gchar **files; | |
289 | |
290 if (util_filebrowser_is_dir_classic(GTK_FILE_SELECTION(filesel))) | |
291 return; | |
292 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); | |
293 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); | |
294 gtk_widget_destroy(filesel); | |
295 } | |
296 | |
297 static void filebrowser_play_classic(GtkWidget * w, GtkWidget * filesel) | |
298 { | |
299 gchar **files; | |
300 | |
301 if (util_filebrowser_is_dir_classic | |
302 (GTK_FILE_SELECTION(GTK_FILE_SELECTION(filesel)))) | |
303 return; | |
304 playlist_clear(playlist_get_active()); | |
305 files = gtk_file_selection_get_selections(GTK_FILE_SELECTION(filesel)); | |
306 filebrowser_add_files_classic(files, GTK_FILE_SELECTION(filesel)); | |
307 gtk_widget_destroy(filesel); | |
308 playback_initiate(); | |
309 } | |
310 | |
311 static void filebrowser_add_selected_files_classic(GtkWidget * w, gpointer data) | |
312 { | |
313 gchar **files; | |
314 | |
315 GtkFileSelection *filesel = GTK_FILE_SELECTION(data); | |
316 files = gtk_file_selection_get_selections(filesel); | |
317 | |
318 filebrowser_add_files_classic(files, filesel); | |
319 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection | |
320 (GTK_TREE_VIEW(filesel->file_list))); | |
321 | |
322 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); | |
323 } | |
324 | |
325 static void filebrowser_add_all_files_classic(GtkWidget * w, gpointer data) | |
326 { | |
327 gchar **files; | |
328 GtkFileSelection *filesel; | |
329 | |
330 filesel = data; | |
331 gtk_tree_selection_select_all(gtk_tree_view_get_selection | |
332 (GTK_TREE_VIEW(filesel->file_list))); | |
333 files = gtk_file_selection_get_selections(filesel); | |
334 filebrowser_add_files_classic(files, filesel); | |
335 gtk_tree_selection_unselect_all(gtk_tree_view_get_selection | |
336 (GTK_TREE_VIEW(filesel->file_list))); | |
337 gtk_entry_set_text(GTK_ENTRY(filesel->selection_entry), ""); | |
338 } | |
339 | |
340 void | |
341 util_run_filebrowser_classic(gboolean play_button) | |
342 { | |
343 static GtkWidget *dialog; | |
344 GtkWidget *button_add_selected, *button_add_all, *button_close, | |
345 *button_add; | |
346 char *title; | |
347 | |
348 if (dialog != NULL) { | |
349 gtk_window_present(GTK_WINDOW(dialog)); | |
350 return; | |
351 } | |
352 | |
353 if (play_button) | |
354 title = _("Play files"); | |
355 else | |
356 title = _("Load files"); | |
357 | |
358 dialog = gtk_file_selection_new(title); | |
359 | |
360 gtk_file_selection_set_select_multiple | |
361 (GTK_FILE_SELECTION(dialog), TRUE); | |
362 | |
363 if (cfg.filesel_path) | |
364 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), | |
365 cfg.filesel_path); | |
366 | |
367 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(dialog)); | |
368 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | |
369 | |
370 gtk_widget_hide(GTK_FILE_SELECTION(dialog)->ok_button); | |
371 gtk_widget_destroy(GTK_FILE_SELECTION(dialog)->cancel_button); | |
372 | |
373 /* | |
374 * The mnemonics are quite unorthodox, but that should guarantee they're unique in any locale | |
375 * plus kinda easy to use | |
376 */ | |
377 button_add_selected = | |
378 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add selected", | |
379 GTK_RESPONSE_NONE); | |
380 gtk_button_set_use_underline(GTK_BUTTON(button_add_selected), TRUE); | |
381 g_signal_connect(G_OBJECT(button_add_selected), "clicked", | |
382 G_CALLBACK(filebrowser_add_selected_files_classic), dialog); | |
383 | |
384 button_add_all = | |
385 gtk_dialog_add_button(GTK_DIALOG(dialog), "Add all", | |
386 GTK_RESPONSE_NONE); | |
387 gtk_button_set_use_underline(GTK_BUTTON(button_add_all), TRUE); | |
388 g_signal_connect(G_OBJECT(button_add_all), "clicked", | |
389 G_CALLBACK(filebrowser_add_all_files_classic), dialog); | |
390 | |
391 if (play_button) { | |
392 button_add = | |
393 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_MEDIA_PLAY, | |
394 GTK_RESPONSE_NONE); | |
395 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); | |
396 g_signal_connect(G_OBJECT(button_add), "clicked", | |
397 G_CALLBACK(filebrowser_play_classic), dialog); | |
398 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), | |
399 "clicked", G_CALLBACK(filebrowser_play_classic), dialog); | |
400 } else { | |
401 button_add = | |
402 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_ADD, | |
403 GTK_RESPONSE_NONE); | |
404 gtk_button_set_use_stock(GTK_BUTTON(button_add), TRUE); | |
405 g_signal_connect(G_OBJECT(button_add), "clicked", | |
406 G_CALLBACK(filebrowser_ok_classic), dialog); | |
407 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog)->ok_button), | |
408 "clicked", G_CALLBACK(filebrowser_ok_classic), dialog); | |
409 } | |
410 | |
411 button_close = | |
412 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE, | |
413 GTK_RESPONSE_NONE); | |
414 gtk_button_set_use_stock(GTK_BUTTON(button_close), TRUE); | |
415 g_signal_connect_swapped(G_OBJECT(button_close), "clicked", | |
416 G_CALLBACK(gtk_widget_destroy), | |
417 G_OBJECT(dialog)); | |
418 | |
419 gtk_widget_set_size_request(dialog, 600, 450); | |
420 gtk_widget_realize(dialog); | |
421 | |
422 g_signal_connect(G_OBJECT | |
423 (GTK_FILE_SELECTION(dialog)->history_pulldown), | |
424 "changed", G_CALLBACK(filebrowser_entry_changed_classic), | |
425 dialog); | |
426 | |
427 g_signal_connect(G_OBJECT(dialog), "destroy", | |
428 G_CALLBACK(gtk_widget_destroyed), &dialog); | |
429 | |
430 filebrowser_changed_classic(GTK_FILE_SELECTION(dialog)); | |
431 | |
432 gtk_widget_show(dialog); | |
433 } | |
434 | |
435 /* | |
436 * util_run_filebrowser(gboolean play_button) | |
437 * | |
438 * Inputs: | |
439 * - whether or not a play button should be used | |
440 * | |
441 * Outputs: | |
442 * - none | |
443 * | |
444 * Side Effects: | |
445 * - either a GTK1 or a GTK2 fileselector is launched | |
446 */ | |
447 void | |
448 run_filebrowser(gboolean play_button) | |
449 { | |
450 if (!cfg.use_xmms_style_fileselector) | |
451 util_run_filebrowser_gtk2style(play_button); | |
452 else | |
453 util_run_filebrowser_classic(play_button); | |
454 } |