Mercurial > audlegacy
annotate src/audacious/ui_fileopener.c @ 4799:142a28417ced
- renamed executable as audlegacy
- made the legacy interface default.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 24 Nov 2008 22:25:58 +0900 |
parents | f04094af8d57 |
children |
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 | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2986
diff
changeset
|
6 * the Free Software Foundation; under version 3 of the License. |
2417 | 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 | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2986
diff
changeset
|
14 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
15 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
16 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
17 * Audacious or using our public API to be a derived work. |
2417 | 18 */ |
19 | |
20 #include "ui_fileopener.h" | |
21 | |
22 #include <glib/gi18n.h> | |
23 #include <string.h> | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
24 #include <gdk/gdkkeysyms.h> |
2417 | 25 |
26 #include "input.h" | |
27 #include "main.h" | |
28 #include "playback.h" | |
29 #include "strings.h" | |
30 | |
31 static void | |
32 filebrowser_add_files(GtkFileChooser * browser, | |
33 GSList * files) | |
34 { | |
35 GSList *cur; | |
36 gchar *ptr; | |
37 Playlist *playlist = playlist_get_active(); | |
38 | |
39 for (cur = files; cur; cur = g_slist_next(cur)) { | |
3235
c48ce3f67130
gtk_file_chooser_get_uris() results in unpredictable behaviour when GNOME is not installed. Build URIs ourselves.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
40 gchar *filename = g_filename_to_uri((const gchar *) cur->data, NULL, NULL); |
2417 | 41 |
2984
df71b1cef70a
Use vfs_file_test() instead of g_file_test() where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2658
diff
changeset
|
42 if (vfs_file_test(cur->data, G_FILE_TEST_IS_DIR)) { |
3235
c48ce3f67130
gtk_file_chooser_get_uris() results in unpredictable behaviour when GNOME is not installed. Build URIs ourselves.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
43 playlist_add_dir(playlist, filename ? filename : (const gchar *) cur->data); |
2417 | 44 } else { |
3235
c48ce3f67130
gtk_file_chooser_get_uris() results in unpredictable behaviour when GNOME is not installed. Build URIs ourselves.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
45 playlist_add(playlist, filename ? filename : (const gchar *) cur->data); |
2417 | 46 } |
47 | |
3235
c48ce3f67130
gtk_file_chooser_get_uris() results in unpredictable behaviour when GNOME is not installed. Build URIs ourselves.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
48 g_free(filename); |
2417 | 49 } |
50 | |
4716 | 51 hook_call("playlist update", playlist); |
2417 | 52 |
53 ptr = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(browser)); | |
54 | |
55 g_free(cfg.filesel_path); | |
56 cfg.filesel_path = ptr; | |
57 } | |
58 | |
59 static void | |
60 action_button_cb(GtkWidget *widget, gpointer data) | |
61 { | |
62 GtkWidget *window = g_object_get_data(data, "window"); | |
63 GtkWidget *chooser = g_object_get_data(data, "chooser"); | |
64 GtkWidget *toggle = g_object_get_data(data, "toggle-button"); | |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
65 gboolean play_button; |
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
66 GSList *files; |
2417 | 67 cfg.close_dialog_open = |
68 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)); | |
69 | |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
70 play_button = |
2417 | 71 GPOINTER_TO_INT(g_object_get_data(data, "play-button")); |
72 | |
3235
c48ce3f67130
gtk_file_chooser_get_uris() results in unpredictable behaviour when GNOME is not installed. Build URIs ourselves.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
73 files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser)); |
2417 | 74 if (!files) return; |
75 | |
76 if (play_button) | |
77 playlist_clear(playlist_get_active()); | |
78 | |
79 filebrowser_add_files(GTK_FILE_CHOOSER(chooser), files); | |
80 g_slist_foreach(files, (GFunc) g_free, NULL); | |
81 g_slist_free(files); | |
82 | |
83 if (play_button) | |
84 playback_initiate(); | |
85 | |
86 if (cfg.close_dialog_open) | |
87 gtk_widget_destroy(window); | |
88 } | |
89 | |
90 | |
91 static void | |
92 close_button_cb(GtkWidget *widget, gpointer data) | |
93 { | |
94 gtk_widget_destroy(GTK_WIDGET(data)); | |
95 } | |
96 | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
97 static gboolean |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
98 filebrowser_on_keypress(GtkWidget * browser, |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
99 GdkEventKey * event, |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
100 gpointer data) |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
101 { |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
102 if (event->keyval == GDK_Escape) { |
2449 | 103 gtk_widget_destroy(browser); |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
104 return TRUE; |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
105 } |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
106 |
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
107 return FALSE; |
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 |
3917 | 110 static void |
4786 | 111 run_filebrowser_gtk2style(gboolean play_button, gboolean show) |
2417 | 112 { |
2449 | 113 static GtkWidget *window = NULL; |
2417 | 114 GtkWidget *vbox, *hbox, *bbox; |
115 GtkWidget *chooser; | |
116 GtkWidget *action_button, *close_button; | |
117 GtkWidget *toggle; | |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
118 gchar *window_title, *toggle_text; |
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
119 gpointer action_stock, storage; |
2417 | 120 |
4784 | 121 if (!show) { |
122 if (window){ | |
3917 | 123 gtk_widget_hide(window); |
124 return; | |
125 } | |
126 else | |
127 return; | |
128 } | |
129 else { | |
4784 | 130 if (window) { |
3917 | 131 gtk_window_present(GTK_WINDOW(window)); /* raise filebrowser */ |
132 return; | |
133 } | |
2490
49e27e4d8426
[svn] - trying to open filebrowser when it is already open will raise the filebrowser.
yaz
parents:
2449
diff
changeset
|
134 } |
4784 | 135 |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
136 window_title = play_button ? _("Open Files") : _("Add Files"); |
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
137 toggle_text = play_button ? |
2417 | 138 _("Close dialog on Open") : _("Close dialog on Add"); |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
139 action_stock = play_button ? GTK_STOCK_OPEN : GTK_STOCK_ADD; |
2417 | 140 |
141 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
142 gtk_window_set_title(GTK_WINDOW(window), window_title); | |
143 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
|
144 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
2417 | 145 gtk_container_set_border_width(GTK_CONTAINER(window), 10); |
146 | |
147 vbox = gtk_vbox_new(FALSE, 0); | |
148 gtk_container_add(GTK_CONTAINER(window), vbox); | |
149 | |
150 chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN); | |
151 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE); | |
152 if (cfg.filesel_path) | |
153 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), | |
154 cfg.filesel_path); | |
2422 | 155 gtk_box_pack_start(GTK_BOX(vbox), chooser, TRUE, TRUE, 3); |
2417 | 156 |
157 hbox = gtk_hbox_new(TRUE, 0); | |
2422 | 158 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 3); |
2417 | 159 |
160 toggle = gtk_check_button_new_with_label(toggle_text); | |
161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
162 cfg.close_dialog_open ? TRUE : FALSE); | |
2422 | 163 gtk_box_pack_start(GTK_BOX(hbox), toggle, TRUE, TRUE, 3); |
2417 | 164 |
165 bbox = gtk_hbutton_box_new(); | |
166 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
2422 | 167 gtk_box_set_spacing(GTK_BOX(bbox), 6); |
168 gtk_box_pack_end(GTK_BOX(hbox), bbox, TRUE, TRUE, 3); | |
2417 | 169 |
170 close_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
171 action_button = gtk_button_new_from_stock(action_stock); | |
172 gtk_container_add(GTK_CONTAINER(bbox), close_button); | |
173 gtk_container_add(GTK_CONTAINER(bbox), action_button); | |
174 | |
2420 | 175 /* this storage object holds several other objects which are used in the |
176 * callback functions | |
177 */ | |
2658
4b8db8c0521d
[svn] - fixed c++ish declaration in a c file (part 5)
giacomo
parents:
2500
diff
changeset
|
178 storage = g_object_new(G_TYPE_OBJECT, NULL); |
2417 | 179 g_object_set_data(storage, "window", window); |
180 g_object_set_data(storage, "chooser", chooser); | |
181 g_object_set_data(storage, "toggle-button", toggle); | |
182 g_object_set_data(storage, "play-button", GINT_TO_POINTER(play_button)); | |
183 | |
184 g_signal_connect(chooser, "file-activated", | |
185 G_CALLBACK(action_button_cb), storage); | |
186 g_signal_connect(action_button, "clicked", | |
187 G_CALLBACK(action_button_cb), storage); | |
188 g_signal_connect(close_button, "clicked", | |
189 G_CALLBACK(close_button_cb), window); | |
190 g_signal_connect(window, "destroy", | |
191 G_CALLBACK(gtk_widget_destroyed), &window); | |
192 | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
193 g_signal_connect(window, "key_press_event", |
4784 | 194 G_CALLBACK(filebrowser_on_keypress), |
195 NULL); | |
2432
4a1d1c324685
[svn] - restore shortcut key (esc) to close gtk2 fileopener.
yaz
parents:
2422
diff
changeset
|
196 |
2417 | 197 gtk_widget_show_all(window); |
198 } | |
199 | |
200 /* | |
4785 | 201 * run_filebrowser(gboolean play_button) |
2417 | 202 * |
203 * Inputs: | |
4595
d69b2bcea170
NO_PLAY_BUTTON and PLAY_BUTTON defines don't quite make sense
Tomasz Mon <desowin@gmail.com>
parents:
3917
diff
changeset
|
204 * - gboolean play_button |
d69b2bcea170
NO_PLAY_BUTTON and PLAY_BUTTON defines don't quite make sense
Tomasz Mon <desowin@gmail.com>
parents:
3917
diff
changeset
|
205 * TRUE - open files |
d69b2bcea170
NO_PLAY_BUTTON and PLAY_BUTTON defines don't quite make sense
Tomasz Mon <desowin@gmail.com>
parents:
3917
diff
changeset
|
206 * FALSE - add files |
2417 | 207 * |
208 * Outputs: | |
209 * - none | |
210 */ | |
211 void | |
212 run_filebrowser(gboolean play_button) | |
213 { | |
4787 | 214 run_filebrowser_gtk2style(play_button, TRUE); |
2417 | 215 } |
3917 | 216 |
217 void | |
218 hide_filebrowser(void) | |
219 { | |
4787 | 220 run_filebrowser_gtk2style(FALSE, FALSE); |
3917 | 221 } |