Mercurial > audlegacy-plugins
annotate src/skins/ui_playlist.c @ 2674:b84f2aca1675
Fixed js's commit, and few other things.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 01 Jun 2008 01:02:11 +0300 |
parents | a1431a900f28 |
children | 32e99af83a3e |
rev | line source |
---|---|
2620 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2006 Audacious development team. | |
3 * | |
4 * BMP - Cross-platform multimedia player | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 3 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
21 * | |
22 * The Audacious team does not consider modular code linking to | |
23 * Audacious or using our public API to be a derived work. | |
24 */ | |
25 | |
26 /* #define AUD_DEBUG 1 */ | |
27 | |
28 #include "ui_playlist.h" | |
29 | |
30 #include <glib.h> | |
31 #include <glib/gi18n.h> | |
32 #include <gdk/gdk.h> | |
33 #include <gdk/gdkkeysyms.h> | |
34 #include <gtk/gtk.h> | |
35 #include <string.h> | |
36 | |
37 #include "platform/smartinclude.h" | |
38 | |
39 #include <unistd.h> | |
40 #include <errno.h> | |
41 | |
42 #include "actions-playlist.h" | |
2629
2ce9e17525dc
make dnd working in playlistwin
Tomasz Mon <desowin@gmail.com>
parents:
2621
diff
changeset
|
43 #include "dnd.h" |
2620 | 44 #if 0 |
45 #include "input.h" | |
46 #include "main.h" | |
47 #include "playback.h" | |
48 #include "playlist.h" | |
49 #include "playlist_container.h" | |
50 #include "strings.h" | |
51 #endif | |
52 #include "ui_dock.h" | |
53 #include "ui_equalizer.h" | |
54 #include "ui_main.h" | |
55 #include "ui_manager.h" | |
56 #include "ui_playlist_evlisteners.h" | |
57 #if 0 | |
58 #include "ui_playlist_manager.h" | |
59 #endif | |
60 #include "util.h" | |
61 | |
62 #include "ui_skinned_window.h" | |
63 #include "ui_skinned_button.h" | |
64 #include "ui_skinned_textbox.h" | |
65 #include "ui_skinned_playlist_slider.h" | |
66 #include "ui_skinned_playlist.h" | |
67 | |
68 #include "icons-stock.h" | |
69 #include "images/audacious_playlist.xpm" | |
70 | |
71 GtkWidget *playlistwin; | |
72 | |
73 static GMutex *resize_mutex = NULL; | |
74 | |
75 static GtkWidget *playlistwin_list = NULL; | |
76 static GtkWidget *playlistwin_shade, *playlistwin_close; | |
77 | |
78 static gboolean playlistwin_hint_flag = FALSE; | |
79 | |
80 static GtkWidget *playlistwin_slider; | |
81 static GtkWidget *playlistwin_time_min, *playlistwin_time_sec; | |
82 static GtkWidget *playlistwin_info, *playlistwin_sinfo; | |
83 static GtkWidget *playlistwin_srew, *playlistwin_splay; | |
84 static GtkWidget *playlistwin_spause, *playlistwin_sstop; | |
85 static GtkWidget *playlistwin_sfwd, *playlistwin_seject; | |
86 static GtkWidget *playlistwin_sscroll_up, *playlistwin_sscroll_down; | |
87 | |
88 static void playlistwin_select_search_cbt_cb(GtkWidget *called_cbt, | |
89 gpointer other_cbt); | |
90 static gboolean playlistwin_select_search_kp_cb(GtkWidget *entry, | |
91 GdkEventKey *event, | |
92 gpointer searchdlg_win); | |
93 | |
94 static gboolean playlistwin_resizing = FALSE; | |
95 static gint playlistwin_resize_x, playlistwin_resize_y; | |
96 | |
97 gboolean | |
98 playlistwin_is_shaded(void) | |
99 { | |
100 return config.playlist_shaded; | |
101 } | |
102 | |
103 gint | |
104 playlistwin_get_width(void) | |
105 { | |
106 config.playlist_width /= PLAYLISTWIN_WIDTH_SNAP; | |
107 config.playlist_width *= PLAYLISTWIN_WIDTH_SNAP; | |
108 return config.playlist_width; | |
109 } | |
110 | |
111 gint | |
112 playlistwin_get_height_unshaded(void) | |
113 { | |
114 config.playlist_height /= PLAYLISTWIN_HEIGHT_SNAP; | |
115 config.playlist_height *= PLAYLISTWIN_HEIGHT_SNAP; | |
116 return config.playlist_height; | |
117 } | |
118 | |
119 gint | |
120 playlistwin_get_height_shaded(void) | |
121 { | |
122 return PLAYLISTWIN_SHADED_HEIGHT; | |
123 } | |
124 | |
125 gint | |
126 playlistwin_get_height(void) | |
127 { | |
128 if (playlistwin_is_shaded()) | |
129 return playlistwin_get_height_shaded(); | |
130 else | |
131 return playlistwin_get_height_unshaded(); | |
132 } | |
133 | |
134 static void | |
135 playlistwin_update_info(Playlist *playlist) | |
136 { | |
2634
43a07a0607da
make playlistwin_update_info and playlistwin_update_sinfo working
Tomasz Mon <desowin@gmail.com>
parents:
2629
diff
changeset
|
137 g_return_if_fail(playlist != NULL); |
43a07a0607da
make playlistwin_update_info and playlistwin_update_sinfo working
Tomasz Mon <desowin@gmail.com>
parents:
2629
diff
changeset
|
138 |
2620 | 139 gchar *text, *sel_text, *tot_text; |
140 gulong selection, total; | |
141 gboolean selection_more, total_more; | |
142 | |
143 aud_playlist_get_total_time(playlist, &total, &selection, &total_more, &selection_more); | |
144 | |
145 if (selection > 0 || (selection == 0 && !selection_more)) { | |
146 if (selection > 3600) | |
147 sel_text = | |
148 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", selection / 3600, | |
149 (selection / 60) % 60, selection % 60, | |
150 (selection_more ? "+" : "")); | |
151 else | |
152 sel_text = | |
153 g_strdup_printf("%lu:%-2.2lu%s", selection / 60, | |
154 selection % 60, (selection_more ? "+" : "")); | |
155 } | |
156 else | |
157 sel_text = g_strdup("?"); | |
158 if (total > 0 || (total == 0 && !total_more)) { | |
159 if (total > 3600) | |
160 tot_text = | |
161 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", total / 3600, | |
162 (total / 60) % 60, total % 60, | |
163 total_more ? "+" : ""); | |
164 else | |
165 tot_text = | |
166 g_strdup_printf("%lu:%-2.2lu%s", total / 60, total % 60, | |
167 total_more ? "+" : ""); | |
168 } | |
169 else | |
170 tot_text = g_strdup("?"); | |
171 text = g_strconcat(sel_text, "/", tot_text, NULL); | |
172 ui_skinned_textbox_set_text(playlistwin_info, text ? text : ""); | |
173 g_free(text); | |
174 g_free(tot_text); | |
175 g_free(sel_text); | |
176 } | |
177 | |
178 static void | |
179 playlistwin_update_sinfo(Playlist *playlist) | |
180 { | |
2634
43a07a0607da
make playlistwin_update_info and playlistwin_update_sinfo working
Tomasz Mon <desowin@gmail.com>
parents:
2629
diff
changeset
|
181 g_return_if_fail(playlist != NULL); |
43a07a0607da
make playlistwin_update_info and playlistwin_update_sinfo working
Tomasz Mon <desowin@gmail.com>
parents:
2629
diff
changeset
|
182 |
2620 | 183 gchar *posstr, *timestr, *title, *info; |
184 gint pos, time; | |
185 | |
186 pos = aud_playlist_get_position(playlist); | |
187 title = aud_playlist_get_songtitle(playlist, pos); | |
188 | |
189 if (!title) { | |
190 ui_skinned_textbox_set_text(playlistwin_sinfo, ""); | |
191 return; | |
192 } | |
193 | |
194 aud_convert_title_text(title); | |
195 | |
196 time = aud_playlist_get_songtime(playlist, pos); | |
197 | |
198 if (config.show_numbers_in_pl) | |
199 posstr = g_strdup_printf("%d. ", pos + 1); | |
200 else | |
201 posstr = g_strdup(""); | |
202 | |
203 if (time != -1) { | |
204 timestr = g_strdup_printf(" (%d:%-2.2d)", time / 60000, | |
205 (time / 1000) % 60); | |
206 } | |
207 else | |
208 timestr = g_strdup(""); | |
209 | |
210 info = g_strdup_printf("%s%s%s", posstr, title, timestr); | |
211 | |
212 g_free(posstr); | |
213 g_free(title); | |
214 g_free(timestr); | |
215 | |
216 ui_skinned_textbox_set_text(playlistwin_sinfo, info ? info : ""); | |
217 g_free(info); | |
218 } | |
219 | |
220 gboolean | |
221 playlistwin_item_visible(gint index) | |
222 { | |
223 g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), FALSE); | |
224 | |
225 if (index >= UI_SKINNED_PLAYLIST(playlistwin_list)->first && | |
226 index < (UI_SKINNED_PLAYLIST(playlistwin_list)->first + UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible) ) { | |
227 return TRUE; | |
228 } | |
229 return FALSE; | |
230 } | |
231 | |
232 gint | |
233 playlistwin_list_get_visible_count(void) | |
234 { | |
235 g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1); | |
236 | |
237 return UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible; | |
238 } | |
239 | |
240 gint | |
241 playlistwin_list_get_first(void) | |
242 { | |
243 g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1); | |
244 | |
245 return UI_SKINNED_PLAYLIST(playlistwin_list)->first; | |
246 } | |
247 | |
248 gint | |
249 playlistwin_get_toprow(void) | |
250 { | |
251 g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1); | |
252 | |
253 return (UI_SKINNED_PLAYLIST(playlistwin_list)->first); | |
254 } | |
255 | |
256 void | |
257 playlistwin_set_toprow(gint toprow) | |
258 { | |
259 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) | |
260 UI_SKINNED_PLAYLIST(playlistwin_list)->first = toprow; | |
261 #if 0 | |
262 g_cond_signal(cond_scan); | |
263 #endif | |
264 playlistwin_update_list(aud_playlist_get_active()); | |
265 } | |
266 | |
267 void | |
268 playlistwin_update_list(Playlist *playlist) | |
269 { | |
270 /* this can happen early on. just bail gracefully. */ | |
271 g_return_if_fail(playlistwin_list); | |
272 | |
273 playlistwin_update_info(playlist); | |
274 playlistwin_update_sinfo(playlist); | |
275 gtk_widget_queue_draw(playlistwin_list); | |
276 gtk_widget_queue_draw(playlistwin_slider); | |
277 } | |
278 | |
279 static void | |
280 playlistwin_set_geometry_hints(gboolean shaded) | |
281 { | |
282 GdkGeometry geometry; | |
283 GdkWindowHints mask; | |
284 | |
285 geometry.min_width = PLAYLISTWIN_MIN_WIDTH; | |
286 geometry.max_width = G_MAXUINT16; | |
287 | |
288 geometry.width_inc = PLAYLISTWIN_WIDTH_SNAP; | |
289 geometry.height_inc = PLAYLISTWIN_HEIGHT_SNAP; | |
290 | |
291 if (shaded) { | |
292 geometry.min_height = PLAYLISTWIN_SHADED_HEIGHT; | |
293 geometry.max_height = PLAYLISTWIN_SHADED_HEIGHT; | |
294 geometry.base_height = PLAYLISTWIN_SHADED_HEIGHT; | |
295 } | |
296 else { | |
297 geometry.min_height = PLAYLISTWIN_MIN_HEIGHT; | |
298 geometry.max_height = G_MAXUINT16; | |
299 } | |
300 | |
301 mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_RESIZE_INC; | |
302 | |
303 gtk_window_set_geometry_hints(GTK_WINDOW(playlistwin), | |
304 playlistwin, &geometry, mask); | |
305 } | |
306 | |
307 void | |
308 playlistwin_set_sinfo_font(gchar *font) | |
309 { | |
310 gchar *tmp = NULL, *tmp2 = NULL; | |
311 | |
312 g_return_if_fail(font); | |
313 AUDDBG("Attempt to set font \"%s\"\n", font); | |
314 | |
315 tmp = g_strdup(font); | |
316 g_return_if_fail(tmp); | |
317 | |
318 *strrchr(tmp, ' ') = '\0'; | |
319 tmp2 = g_strdup_printf("%s 8", tmp); | |
320 g_return_if_fail(tmp2); | |
321 | |
322 ui_skinned_textbox_set_xfont(playlistwin_sinfo, !config.mainwin_use_bitmapfont, tmp2); | |
323 | |
324 g_free(tmp); | |
325 g_free(tmp2); | |
326 } | |
327 | |
328 void | |
329 playlistwin_set_sinfo_scroll(gboolean scroll) | |
330 { | |
331 if(playlistwin_is_shaded()) | |
332 ui_skinned_textbox_set_scroll(playlistwin_sinfo, config.autoscroll); | |
333 else | |
334 ui_skinned_textbox_set_scroll(playlistwin_sinfo, FALSE); | |
335 } | |
336 | |
337 void | |
338 playlistwin_set_shade(gboolean shaded) | |
339 { | |
340 config.playlist_shaded = shaded; | |
341 | |
342 if (shaded) { | |
2642 | 343 playlistwin_set_sinfo_font(config.playlist_font); |
2620 | 344 playlistwin_set_sinfo_scroll(config.autoscroll); |
345 gtk_widget_show(playlistwin_sinfo); | |
346 ui_skinned_set_push_button_data(playlistwin_shade, 128, 45, 150, 42); | |
347 ui_skinned_set_push_button_data(playlistwin_close, 138, 45, -1, -1); | |
348 } | |
349 else { | |
350 gtk_widget_hide(playlistwin_sinfo); | |
351 playlistwin_set_sinfo_scroll(FALSE); | |
352 ui_skinned_set_push_button_data(playlistwin_shade, 157, 3, 62, 42); | |
353 ui_skinned_set_push_button_data(playlistwin_close, 167, 3, -1, -1); | |
354 } | |
355 | |
356 dock_shade(get_dock_window_list(), GTK_WINDOW(playlistwin), | |
357 playlistwin_get_height()); | |
358 | |
359 playlistwin_set_geometry_hints(config.playlist_shaded); | |
360 | |
361 gtk_window_resize(GTK_WINDOW(playlistwin), | |
362 playlistwin_get_width(), | |
363 playlistwin_get_height()); | |
364 } | |
365 | |
366 static void | |
367 playlistwin_set_shade_menu(gboolean shaded) | |
368 { | |
369 GtkAction *action = gtk_action_group_get_action( | |
370 toggleaction_group_others , "roll up playlist editor" ); | |
371 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , shaded ); | |
372 | |
373 playlistwin_set_shade(shaded); | |
374 playlistwin_update_list(aud_playlist_get_active()); | |
375 } | |
376 | |
377 void | |
378 playlistwin_shade_toggle(void) | |
379 { | |
380 playlistwin_set_shade_menu(!config.playlist_shaded); | |
381 } | |
382 | |
383 static gboolean | |
384 playlistwin_release(GtkWidget * widget, | |
385 GdkEventButton * event, | |
386 gpointer callback_data) | |
387 { | |
388 playlistwin_resizing = FALSE; | |
389 return FALSE; | |
390 } | |
391 | |
392 void | |
393 playlistwin_scroll(gint num) | |
394 { | |
395 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) | |
396 UI_SKINNED_PLAYLIST(playlistwin_list)->first += num; | |
397 playlistwin_update_list(aud_playlist_get_active()); | |
398 } | |
399 | |
400 void | |
401 playlistwin_scroll_up_pushed(void) | |
402 { | |
403 playlistwin_scroll(-3); | |
404 } | |
405 | |
406 void | |
407 playlistwin_scroll_down_pushed(void) | |
408 { | |
409 playlistwin_scroll(3); | |
410 } | |
411 | |
412 static void | |
413 playlistwin_select_all(void) | |
414 { | |
415 Playlist *playlist = aud_playlist_get_active(); | |
416 | |
417 aud_playlist_select_all(playlist, TRUE); | |
418 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) { | |
419 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = 0; | |
420 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = 0; | |
421 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_max = aud_playlist_get_length(playlist) - 1; | |
422 } | |
423 playlistwin_update_list(playlist); | |
424 } | |
425 | |
426 static void | |
427 playlistwin_select_none(void) | |
428 { | |
429 aud_playlist_select_all(aud_playlist_get_active(), FALSE); | |
430 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) { | |
431 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1; | |
432 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1; | |
433 } | |
434 playlistwin_update_list(aud_playlist_get_active()); | |
435 } | |
436 | |
437 static void | |
438 playlistwin_select_search(void) | |
439 { | |
440 Playlist *playlist = aud_playlist_get_active(); | |
441 GtkWidget *searchdlg_win, *searchdlg_table; | |
442 GtkWidget *searchdlg_hbox, *searchdlg_logo, *searchdlg_helptext; | |
443 GtkWidget *searchdlg_entry_title, *searchdlg_label_title; | |
444 GtkWidget *searchdlg_entry_album, *searchdlg_label_album; | |
445 GtkWidget *searchdlg_entry_file_name, *searchdlg_label_file_name; | |
446 GtkWidget *searchdlg_entry_performer, *searchdlg_label_performer; | |
447 GtkWidget *searchdlg_checkbt_clearprevsel; | |
448 GtkWidget *searchdlg_checkbt_newplaylist; | |
449 GtkWidget *searchdlg_checkbt_autoenqueue; | |
450 gint result; | |
451 | |
452 /* create dialog */ | |
453 searchdlg_win = gtk_dialog_new_with_buttons( | |
454 _("Search entries in active playlist") , GTK_WINDOW(mainwin) , | |
455 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT , | |
456 GTK_STOCK_CANCEL , GTK_RESPONSE_REJECT , GTK_STOCK_OK , GTK_RESPONSE_ACCEPT , NULL ); | |
457 gtk_window_set_position(GTK_WINDOW(searchdlg_win), GTK_WIN_POS_CENTER); | |
458 | |
459 /* help text and logo */ | |
460 searchdlg_hbox = gtk_hbox_new( FALSE , 4 ); | |
461 searchdlg_logo = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_DIALOG ); | |
462 searchdlg_helptext = gtk_label_new( _("Select entries in playlist by filling one or more " | |
463 "fields. Fields use regular expressions syntax, case-insensitive. If you don't know how " | |
464 "regular expressions work, simply insert a literal portion of what you're searching for.") ); | |
465 gtk_label_set_line_wrap( GTK_LABEL(searchdlg_helptext) , TRUE ); | |
466 gtk_box_pack_start( GTK_BOX(searchdlg_hbox) , searchdlg_logo , FALSE , FALSE , 0 ); | |
467 gtk_box_pack_start( GTK_BOX(searchdlg_hbox) , searchdlg_helptext , FALSE , FALSE , 0 ); | |
468 | |
469 /* title */ | |
470 searchdlg_label_title = gtk_label_new( _("Title: ") ); | |
471 searchdlg_entry_title = gtk_entry_new(); | |
472 gtk_misc_set_alignment( GTK_MISC(searchdlg_label_title) , 0 , 0.5 ); | |
473 g_signal_connect( G_OBJECT(searchdlg_entry_title) , "key-press-event" , | |
474 G_CALLBACK(playlistwin_select_search_kp_cb) , searchdlg_win ); | |
475 | |
476 /* album */ | |
477 searchdlg_label_album= gtk_label_new( _("Album: ") ); | |
478 searchdlg_entry_album= gtk_entry_new(); | |
479 gtk_misc_set_alignment( GTK_MISC(searchdlg_label_album) , 0 , 0.5 ); | |
480 g_signal_connect( G_OBJECT(searchdlg_entry_album) , "key-press-event" , | |
481 G_CALLBACK(playlistwin_select_search_kp_cb) , searchdlg_win ); | |
482 | |
483 /* artist */ | |
484 searchdlg_label_performer = gtk_label_new( _("Artist: ") ); | |
485 searchdlg_entry_performer = gtk_entry_new(); | |
486 gtk_misc_set_alignment( GTK_MISC(searchdlg_label_performer) , 0 , 0.5 ); | |
487 g_signal_connect( G_OBJECT(searchdlg_entry_performer) , "key-press-event" , | |
488 G_CALLBACK(playlistwin_select_search_kp_cb) , searchdlg_win ); | |
489 | |
490 /* file name */ | |
491 searchdlg_label_file_name = gtk_label_new( _("Filename: ") ); | |
492 searchdlg_entry_file_name = gtk_entry_new(); | |
493 gtk_misc_set_alignment( GTK_MISC(searchdlg_label_file_name) , 0 , 0.5 ); | |
494 g_signal_connect( G_OBJECT(searchdlg_entry_file_name) , "key-press-event" , | |
495 G_CALLBACK(playlistwin_select_search_kp_cb) , searchdlg_win ); | |
496 | |
497 /* some options that control behaviour */ | |
498 searchdlg_checkbt_clearprevsel = gtk_check_button_new_with_label( | |
499 _("Clear previous selection before searching") ); | |
500 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(searchdlg_checkbt_clearprevsel) , TRUE ); | |
501 searchdlg_checkbt_autoenqueue = gtk_check_button_new_with_label( | |
502 _("Automatically toggle queue for matching entries") ); | |
503 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(searchdlg_checkbt_autoenqueue) , FALSE ); | |
504 searchdlg_checkbt_newplaylist = gtk_check_button_new_with_label( | |
505 _("Create a new playlist with matching entries") ); | |
506 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(searchdlg_checkbt_newplaylist) , FALSE ); | |
507 g_signal_connect( G_OBJECT(searchdlg_checkbt_autoenqueue) , "clicked" , | |
508 G_CALLBACK(playlistwin_select_search_cbt_cb) , searchdlg_checkbt_newplaylist ); | |
509 g_signal_connect( G_OBJECT(searchdlg_checkbt_newplaylist) , "clicked" , | |
510 G_CALLBACK(playlistwin_select_search_cbt_cb) , searchdlg_checkbt_autoenqueue ); | |
511 | |
512 /* place fields in searchdlg_table */ | |
513 searchdlg_table = gtk_table_new( 8 , 2 , FALSE ); | |
514 gtk_table_set_row_spacing( GTK_TABLE(searchdlg_table) , 0 , 8 ); | |
515 gtk_table_set_row_spacing( GTK_TABLE(searchdlg_table) , 4 , 8 ); | |
516 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_hbox , | |
517 0 , 2 , 0 , 1 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
518 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_label_title , | |
519 0 , 1 , 1 , 2 , GTK_FILL , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
520 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_entry_title , | |
521 1 , 2 , 1 , 2 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
522 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_label_album, | |
523 0 , 1 , 2 , 3 , GTK_FILL , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
524 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_entry_album, | |
525 1 , 2 , 2 , 3 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
526 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_label_performer , | |
527 0 , 1 , 3 , 4 , GTK_FILL , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
528 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_entry_performer , | |
529 1 , 2 , 3 , 4 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
530 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_label_file_name , | |
531 0 , 1 , 4 , 5 , GTK_FILL , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
532 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_entry_file_name , | |
533 1 , 2 , 4 , 5 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 2 ); | |
534 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_checkbt_clearprevsel , | |
535 0 , 2 , 5 , 6 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 1 ); | |
536 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_checkbt_autoenqueue , | |
537 0 , 2 , 6 , 7 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 1 ); | |
538 gtk_table_attach( GTK_TABLE(searchdlg_table) , searchdlg_checkbt_newplaylist , | |
539 0 , 2 , 7 , 8 , GTK_FILL | GTK_EXPAND , GTK_FILL | GTK_EXPAND , 0 , 1 ); | |
540 | |
541 gtk_container_set_border_width( GTK_CONTAINER(searchdlg_table) , 5 ); | |
542 gtk_container_add( GTK_CONTAINER(GTK_DIALOG(searchdlg_win)->vbox) , searchdlg_table ); | |
543 gtk_widget_show_all( searchdlg_win ); | |
544 result = gtk_dialog_run( GTK_DIALOG(searchdlg_win) ); | |
545 switch(result) | |
546 { | |
547 case GTK_RESPONSE_ACCEPT: | |
548 { | |
549 gint matched_entries_num = 0; | |
550 /* create a TitleInput tuple with user search data */ | |
551 Tuple *tuple = aud_tuple_new(); | |
552 gchar *searchdata = NULL; | |
553 | |
554 searchdata = (gchar*)gtk_entry_get_text( GTK_ENTRY(searchdlg_entry_title) ); | |
555 AUDDBG("title=\"%s\"\n", searchdata); | |
556 aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, searchdata); | |
557 | |
558 searchdata = (gchar*)gtk_entry_get_text( GTK_ENTRY(searchdlg_entry_album) ); | |
559 AUDDBG("album=\"%s\"\n", searchdata); | |
560 aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, searchdata); | |
561 | |
562 searchdata = (gchar*)gtk_entry_get_text( GTK_ENTRY(searchdlg_entry_performer) ); | |
563 AUDDBG("performer=\"%s\"\n", searchdata); | |
564 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, searchdata); | |
565 | |
566 searchdata = (gchar*)gtk_entry_get_text( GTK_ENTRY(searchdlg_entry_file_name) ); | |
567 AUDDBG("filename=\"%s\"\n", searchdata); | |
568 aud_tuple_associate_string(tuple, FIELD_FILE_NAME, NULL, searchdata); | |
569 | |
570 /* check if previous selection should be cleared before searching */ | |
571 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(searchdlg_checkbt_clearprevsel)) == TRUE ) | |
572 playlistwin_select_none(); | |
573 /* now send this tuple to the real search function */ | |
574 matched_entries_num = aud_playlist_select_search( playlist , tuple , 0 ); | |
575 /* we do not need the tuple and its data anymore */ | |
576 mowgli_object_unref(tuple); | |
577 playlistwin_update_list(aud_playlist_get_active()); | |
578 /* check if a new playlist should be created after searching */ | |
579 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(searchdlg_checkbt_newplaylist)) == TRUE ) | |
580 aud_playlist_new_from_selected(); | |
581 /* check if matched entries should be queued */ | |
582 else if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(searchdlg_checkbt_autoenqueue)) == TRUE ) | |
583 aud_playlist_queue(aud_playlist_get_active()); | |
584 break; | |
585 } | |
586 default: | |
587 break; | |
588 } | |
589 /* done here :) */ | |
590 gtk_widget_destroy( searchdlg_win ); | |
591 } | |
592 | |
593 static void | |
594 playlistwin_inverse_selection(void) | |
595 { | |
596 aud_playlist_select_invert_all(aud_playlist_get_active()); | |
597 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) { | |
598 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1; | |
599 UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1; | |
600 } | |
601 playlistwin_update_list(aud_playlist_get_active()); | |
602 } | |
603 | |
604 static void | |
605 playlistwin_resize(gint width, gint height) | |
606 { | |
607 gint tx, ty; | |
608 gint dx, dy; | |
609 | |
610 g_return_if_fail(width > 0 && height > 0); | |
611 | |
612 tx = (width - PLAYLISTWIN_MIN_WIDTH) / PLAYLISTWIN_WIDTH_SNAP; | |
613 tx = (tx * PLAYLISTWIN_WIDTH_SNAP) + PLAYLISTWIN_MIN_WIDTH; | |
614 if (tx < PLAYLISTWIN_MIN_WIDTH) | |
615 tx = PLAYLISTWIN_MIN_WIDTH; | |
616 | |
617 if (!config.playlist_shaded) | |
618 { | |
619 ty = (height - PLAYLISTWIN_MIN_HEIGHT) / PLAYLISTWIN_HEIGHT_SNAP; | |
620 ty = (ty * PLAYLISTWIN_HEIGHT_SNAP) + PLAYLISTWIN_MIN_HEIGHT; | |
621 if (ty < PLAYLISTWIN_MIN_HEIGHT) | |
622 ty = PLAYLISTWIN_MIN_HEIGHT; | |
623 } | |
624 else | |
625 ty = config.playlist_height; | |
626 | |
627 if (tx == config.playlist_width && ty == config.playlist_height) | |
628 return; | |
629 | |
630 /* difference between previous size and new size */ | |
631 dx = tx - config.playlist_width; | |
632 dy = ty - config.playlist_height; | |
633 | |
634 config.playlist_width = width = tx; | |
635 config.playlist_height = height = ty; | |
636 | |
637 g_mutex_lock(resize_mutex); | |
638 ui_skinned_playlist_resize_relative(playlistwin_list, dx, dy); | |
639 | |
640 ui_skinned_playlist_slider_move_relative(playlistwin_slider, dx); | |
641 ui_skinned_playlist_slider_resize_relative(playlistwin_slider, dy); | |
642 | |
643 playlistwin_update_sinfo(aud_playlist_get_active()); | |
644 | |
645 ui_skinned_button_move_relative(playlistwin_shade, dx, 0); | |
646 ui_skinned_button_move_relative(playlistwin_close, dx, 0); | |
647 ui_skinned_textbox_move_relative(playlistwin_time_min, dx, dy); | |
648 ui_skinned_textbox_move_relative(playlistwin_time_sec, dx, dy); | |
649 ui_skinned_textbox_move_relative(playlistwin_info, dx, dy); | |
650 ui_skinned_button_move_relative(playlistwin_srew, dx, dy); | |
651 ui_skinned_button_move_relative(playlistwin_splay, dx, dy); | |
652 ui_skinned_button_move_relative(playlistwin_spause, dx, dy); | |
653 ui_skinned_button_move_relative(playlistwin_sstop, dx, dy); | |
654 ui_skinned_button_move_relative(playlistwin_sfwd, dx, dy); | |
655 ui_skinned_button_move_relative(playlistwin_seject, dx, dy); | |
656 ui_skinned_button_move_relative(playlistwin_sscroll_up, dx, dy); | |
657 ui_skinned_button_move_relative(playlistwin_sscroll_down, dx, dy); | |
658 | |
659 gtk_widget_set_size_request(playlistwin_sinfo, playlistwin_get_width() - 35, | |
660 aud_active_skin->properties.textbox_bitmap_font_height); | |
661 GList *iter; | |
662 for (iter = GTK_FIXED (SKINNED_WINDOW(playlistwin)->fixed)->children; iter; iter = g_list_next (iter)) { | |
663 GtkFixedChild *child_data = (GtkFixedChild *) iter->data; | |
664 GtkWidget *child = child_data->widget; | |
665 g_signal_emit_by_name(child, "redraw"); | |
666 } | |
667 g_mutex_unlock(resize_mutex); | |
668 } | |
669 | |
670 static void | |
671 playlistwin_motion(GtkWidget * widget, | |
672 GdkEventMotion * event, | |
673 gpointer callback_data) | |
674 { | |
675 /* | |
676 * GDK2's resize is broken and doesn't really play nice, so we have | |
677 * to do all of this stuff by hand. | |
678 */ | |
679 if (playlistwin_resizing == TRUE) | |
680 { | |
681 if (event->x + playlistwin_resize_x != playlistwin_get_width() || | |
682 event->y + playlistwin_resize_y != playlistwin_get_height()) | |
683 { | |
684 playlistwin_resize(event->x + playlistwin_resize_x, | |
685 event->y + playlistwin_resize_y); | |
686 gdk_window_resize(playlistwin->window, | |
687 config.playlist_width, playlistwin_get_height()); | |
688 gdk_flush(); | |
689 } | |
690 } | |
691 else if (dock_is_moving(GTK_WINDOW(playlistwin))) | |
692 dock_move_motion(GTK_WINDOW(playlistwin), event); | |
693 } | |
694 | |
695 static void | |
696 playlistwin_show_filebrowser(void) | |
697 { | |
2640 | 698 action_playlist_add_files(); |
2620 | 699 } |
700 | |
701 static void | |
702 playlistwin_fileinfo(void) | |
703 { | |
704 Playlist *playlist = aud_playlist_get_active(); | |
705 | |
706 /* Show the first selected file, or the current file if nothing is | |
707 * selected */ | |
708 GList *list = aud_playlist_get_selected(playlist); | |
709 if (list) { | |
2639 | 710 aud_playlist_fileinfo(playlist, GPOINTER_TO_INT(list->data)); |
2620 | 711 g_list_free(list); |
712 } | |
713 else | |
2639 | 714 aud_playlist_fileinfo_current(playlist); |
2620 | 715 } |
716 | |
717 static void | |
718 show_playlist_save_error(GtkWindow *parent, | |
719 const gchar *filename) | |
720 { | |
721 GtkWidget *dialog; | |
722 | |
723 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
724 g_return_if_fail(filename); | |
725 | |
726 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
727 GTK_DIALOG_DESTROY_WITH_PARENT, | |
728 GTK_MESSAGE_ERROR, | |
729 GTK_BUTTONS_OK, | |
730 _("Error writing playlist \"%s\": %s"), | |
731 filename, strerror(errno)); | |
732 | |
733 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ | |
734 gtk_dialog_run(GTK_DIALOG(dialog)); | |
735 gtk_widget_destroy(dialog); | |
736 } | |
737 | |
738 static gboolean | |
739 show_playlist_overwrite_prompt(GtkWindow * parent, | |
740 const gchar * filename) | |
741 { | |
742 GtkWidget *dialog; | |
743 gint result; | |
744 | |
745 g_return_val_if_fail(GTK_IS_WINDOW(parent), FALSE); | |
746 g_return_val_if_fail(filename != NULL, FALSE); | |
747 | |
748 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
749 GTK_DIALOG_DESTROY_WITH_PARENT, | |
750 GTK_MESSAGE_QUESTION, | |
751 GTK_BUTTONS_YES_NO, | |
752 _("%s already exist. Continue?"), | |
753 filename); | |
754 | |
755 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ | |
756 result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
757 gtk_widget_destroy(dialog); | |
758 | |
759 return (result == GTK_RESPONSE_YES); | |
760 } | |
761 | |
762 static void | |
763 show_playlist_save_format_error(GtkWindow * parent, | |
764 const gchar * filename) | |
765 { | |
766 const gchar *markup = | |
767 N_("<b><big>Unable to save playlist.</big></b>\n\n" | |
768 "Unknown file type for '%s'.\n"); | |
769 | |
770 GtkWidget *dialog; | |
771 | |
772 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
773 g_return_if_fail(filename != NULL); | |
774 | |
775 dialog = | |
776 gtk_message_dialog_new_with_markup(GTK_WINDOW(parent), | |
777 GTK_DIALOG_DESTROY_WITH_PARENT, | |
778 GTK_MESSAGE_ERROR, | |
779 GTK_BUTTONS_OK, | |
780 _(markup), | |
781 filename); | |
782 | |
783 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ | |
784 gtk_dialog_run(GTK_DIALOG(dialog)); | |
785 gtk_widget_destroy(dialog); | |
786 } | |
787 | |
788 static void | |
789 playlistwin_save_playlist(const gchar * filename) | |
790 { | |
791 PlaylistContainer *plc; | |
792 gchar *ext = strrchr(filename, '.') + 1; | |
793 | |
794 plc = aud_playlist_container_find(ext); | |
795 if (plc == NULL) { | |
796 show_playlist_save_format_error(GTK_WINDOW(playlistwin), filename); | |
797 return; | |
798 } | |
799 | |
800 aud_str_replace_in(&aud_cfg->playlist_path, g_path_get_dirname(filename)); | |
801 | |
802 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
803 if (!show_playlist_overwrite_prompt(GTK_WINDOW(playlistwin), filename)) | |
804 return; | |
805 | |
806 if (!aud_playlist_save(aud_playlist_get_active(), filename)) | |
807 show_playlist_save_error(GTK_WINDOW(playlistwin), filename); | |
808 } | |
809 | |
810 static void | |
811 playlistwin_load_playlist(const gchar * filename) | |
812 { | |
813 const gchar *title; | |
814 Playlist *playlist = aud_playlist_get_active(); | |
815 | |
816 g_return_if_fail(filename != NULL); | |
817 | |
818 aud_str_replace_in(&aud_cfg->playlist_path, g_path_get_dirname(filename)); | |
819 | |
820 aud_playlist_clear(playlist); | |
821 mainwin_clear_song_info(); | |
822 | |
823 aud_playlist_load(playlist, filename); | |
824 title = aud_playlist_get_current_name(playlist); | |
825 if(!title || !title[0]) | |
826 aud_playlist_set_current_name(playlist, filename); | |
827 } | |
828 | |
829 static gchar * | |
830 playlist_file_selection_load(const gchar * title, | |
831 const gchar * default_filename) | |
832 { | |
833 GtkWidget *dialog; | |
834 gchar *filename; | |
835 | |
836 g_return_val_if_fail(title != NULL, NULL); | |
837 | |
838 dialog = make_filebrowser(title, FALSE); | |
839 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), aud_cfg->playlist_path); | |
840 if (default_filename) | |
841 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), default_filename); | |
842 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); /* centering */ | |
843 | |
844 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
845 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
846 else | |
847 filename = NULL; | |
848 | |
849 gtk_widget_destroy(dialog); | |
850 return filename; | |
851 } | |
852 | |
853 static void | |
854 on_static_toggle(GtkToggleButton *button, gpointer data) | |
855 { | |
856 Playlist *playlist = aud_playlist_get_active(); | |
857 | |
858 playlist->attribute = | |
859 gtk_toggle_button_get_active(button) ? | |
860 playlist->attribute | PLAYLIST_STATIC : | |
861 playlist->attribute & ~PLAYLIST_STATIC; | |
862 } | |
863 | |
864 static void | |
865 on_relative_toggle(GtkToggleButton *button, gpointer data) | |
866 { | |
867 Playlist *playlist = aud_playlist_get_active(); | |
868 | |
869 playlist->attribute = | |
870 gtk_toggle_button_get_active(button) ? | |
871 playlist->attribute | PLAYLIST_USE_RELATIVE : | |
872 playlist->attribute & ~PLAYLIST_USE_RELATIVE; | |
873 } | |
874 | |
875 static gchar * | |
876 playlist_file_selection_save(const gchar * title, | |
877 const gchar * default_filename) | |
878 { | |
879 GtkWidget *dialog; | |
880 gchar *filename; | |
881 GtkWidget *hbox; | |
882 GtkWidget *toggle, *toggle2; | |
883 | |
884 g_return_val_if_fail(title != NULL, NULL); | |
885 | |
886 dialog = make_filebrowser(title, TRUE); | |
887 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), aud_cfg->playlist_path); | |
888 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), default_filename); | |
889 | |
890 hbox = gtk_hbox_new(FALSE, 5); | |
891 | |
892 /* static playlist */ | |
893 toggle = gtk_check_button_new_with_label(_("Save as Static Playlist")); | |
894 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
895 (aud_playlist_get_active()->attribute & PLAYLIST_STATIC) ? TRUE : FALSE); | |
896 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(on_static_toggle), dialog); | |
897 gtk_box_pack_start(GTK_BOX(hbox), toggle, FALSE, FALSE, 0); | |
898 | |
899 /* use relative path */ | |
900 toggle2 = gtk_check_button_new_with_label(_("Use Relative Path")); | |
901 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle2), | |
902 (aud_playlist_get_active()->attribute & PLAYLIST_USE_RELATIVE) ? TRUE : FALSE); | |
903 g_signal_connect(G_OBJECT(toggle2), "toggled", G_CALLBACK(on_relative_toggle), dialog); | |
904 gtk_box_pack_start(GTK_BOX(hbox), toggle2, FALSE, FALSE, 0); | |
905 | |
906 gtk_widget_show_all(hbox); | |
907 gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), hbox); | |
908 | |
909 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
910 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
911 else | |
912 filename = NULL; | |
913 | |
914 gtk_widget_destroy(dialog); | |
915 return filename; | |
916 } | |
917 | |
918 void | |
919 playlistwin_select_playlist_to_load(const gchar * default_filename) | |
920 { | |
921 gchar *filename = | |
922 playlist_file_selection_load(_("Load Playlist"), default_filename); | |
923 | |
924 if (filename) { | |
925 playlistwin_load_playlist(filename); | |
926 g_free(filename); | |
927 } | |
928 } | |
929 | |
930 static void | |
931 playlistwin_select_playlist_to_save(const gchar * default_filename) | |
932 { | |
933 gchar *dot = NULL, *basename = NULL; | |
934 gchar *filename = | |
935 playlist_file_selection_save(_("Save Playlist"), default_filename); | |
936 | |
937 if (filename) { | |
938 /* Default extension */ | |
939 basename = g_path_get_basename(filename); | |
940 dot = strrchr(basename, '.'); | |
941 if( dot == NULL || dot == basename) { | |
942 gchar *oldname = filename; | |
943 #ifdef HAVE_XSPF_PLAYLIST | |
944 filename = g_strconcat(oldname, ".xspf", NULL); | |
945 #else | |
946 filename = g_strconcat(oldname, ".m3u", NULL); | |
947 #endif | |
948 g_free(oldname); | |
949 } | |
950 g_free(basename); | |
951 | |
952 playlistwin_save_playlist(filename); | |
953 g_free(filename); | |
954 } | |
955 } | |
956 | |
957 #define REGION_L(x1,x2,y1,y2) \ | |
958 (event->x >= (x1) && event->x < (x2) && \ | |
959 event->y >= config.playlist_height - (y1) && \ | |
960 event->y < config.playlist_height - (y2)) | |
961 | |
962 #define REGION_R(x1,x2,y1,y2) \ | |
963 (event->x >= playlistwin_get_width() - (x1) && \ | |
964 event->x < playlistwin_get_width() - (x2) && \ | |
965 event->y >= config.playlist_height - (y1) && \ | |
966 event->y < config.playlist_height - (y2)) | |
967 | |
968 static void | |
969 playlistwin_scrolled(GtkWidget * widget, | |
970 GdkEventScroll * event, | |
971 gpointer callback_data) | |
972 { | |
973 if (event->direction == GDK_SCROLL_DOWN) | |
974 playlistwin_scroll(config.scroll_pl_by); | |
975 | |
976 if (event->direction == GDK_SCROLL_UP) | |
977 playlistwin_scroll(-config.scroll_pl_by); | |
978 #if 0 | |
979 g_cond_signal(cond_scan); | |
980 #endif | |
981 } | |
982 | |
983 static gboolean | |
984 playlistwin_press(GtkWidget * widget, | |
985 GdkEventButton * event, | |
986 gpointer callback_data) | |
987 { | |
988 gint xpos, ypos; | |
989 GtkRequisition req; | |
990 | |
991 gtk_window_get_position(GTK_WINDOW(playlistwin), &xpos, &ypos); | |
992 | |
993 if (event->button == 1 && !config.show_wm_decorations && | |
994 ((!config.playlist_shaded && | |
995 event->x > playlistwin_get_width() - 20 && | |
996 event->y > config.playlist_height - 20) || | |
997 (config.playlist_shaded && | |
998 event->x >= playlistwin_get_width() - 31 && | |
999 event->x < playlistwin_get_width() - 22))) { | |
1000 | |
1001 if (event->type != GDK_2BUTTON_PRESS && | |
1002 event->type != GDK_3BUTTON_PRESS) { | |
1003 playlistwin_resizing = TRUE; | |
1004 playlistwin_resize_x = config.playlist_width - event->x; | |
1005 playlistwin_resize_y = config.playlist_height - event->y; | |
1006 } | |
1007 } | |
1008 else if (event->button == 1 && REGION_L(12, 37, 29, 11)) { | |
1009 /* ADD button menu */ | |
1010 gtk_widget_size_request(playlistwin_pladd_menu, &req); | |
1011 ui_manager_popup_menu_show(GTK_MENU(playlistwin_pladd_menu), | |
1012 xpos + 12, | |
1013 (ypos + playlistwin_get_height()) - 8 - req.height, | |
1014 event->button, | |
1015 event->time); | |
1016 } | |
1017 else if (event->button == 1 && REGION_L(41, 66, 29, 11)) { | |
1018 /* SUB button menu */ | |
1019 gtk_widget_size_request(playlistwin_pldel_menu, &req); | |
1020 ui_manager_popup_menu_show(GTK_MENU(playlistwin_pldel_menu), | |
1021 xpos + 40, | |
1022 (ypos + playlistwin_get_height()) - 8 - req.height, | |
1023 event->button, | |
1024 event->time); | |
1025 } | |
1026 else if (event->button == 1 && REGION_L(70, 95, 29, 11)) { | |
1027 /* SEL button menu */ | |
1028 gtk_widget_size_request(playlistwin_plsel_menu, &req); | |
1029 ui_manager_popup_menu_show(GTK_MENU(playlistwin_plsel_menu), | |
1030 xpos + 68, | |
1031 (ypos + playlistwin_get_height()) - 8 - req.height, | |
1032 event->button, | |
1033 event->time); | |
1034 } | |
1035 else if (event->button == 1 && REGION_L(99, 124, 29, 11)) { | |
1036 /* MISC button menu */ | |
1037 gtk_widget_size_request(playlistwin_plsort_menu, &req); | |
1038 ui_manager_popup_menu_show(GTK_MENU(playlistwin_plsort_menu), | |
1039 xpos + 100, | |
1040 (ypos + playlistwin_get_height()) - 8 - req.height, | |
1041 event->button, | |
1042 event->time); | |
1043 } | |
1044 else if (event->button == 1 && REGION_R(46, 23, 29, 11)) { | |
1045 /* LIST button menu */ | |
1046 gtk_widget_size_request(playlistwin_pllist_menu, &req); | |
1047 ui_manager_popup_menu_show(GTK_MENU(playlistwin_pllist_menu), | |
1048 xpos + playlistwin_get_width() - req.width - 12, | |
1049 (ypos + playlistwin_get_height()) - 8 - req.height, | |
1050 event->button, | |
1051 event->time); | |
1052 } | |
1053 else if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
1054 (config.easy_move || event->y < 14)) | |
1055 { | |
1056 return FALSE; | |
1057 } | |
1058 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS | |
1059 && event->y < 14) { | |
1060 /* double click on title bar */ | |
1061 playlistwin_shade_toggle(); | |
1062 if (dock_is_moving(GTK_WINDOW(playlistwin))) | |
1063 dock_move_release(GTK_WINDOW(playlistwin)); | |
1064 return TRUE; | |
1065 } | |
1066 else if (event->button == 3) { | |
1067 /* | |
1068 * Pop up the main menu a few pixels down to avoid | |
1069 * anything to be selected initially. | |
1070 */ | |
1071 ui_manager_popup_menu_show(GTK_MENU(mainwin_general_menu), event->x_root, | |
1072 event->y_root + 2, 3, event->time); | |
1073 } | |
1074 | |
1075 return TRUE; | |
1076 } | |
1077 | |
1078 static gboolean | |
1079 playlistwin_delete(GtkWidget * w, gpointer data) | |
1080 { | |
1081 playlistwin_hide(); | |
1082 return TRUE; | |
1083 } | |
1084 | |
1085 static gboolean | |
1086 playlistwin_keypress_up_down_handler(UiSkinnedPlaylist * pl, | |
1087 gboolean up, guint state) | |
1088 { | |
1089 Playlist *playlist = aud_playlist_get_active(); | |
1090 if ((!(pl->prev_selected || pl->first) && up) || | |
1091 ((pl->prev_selected >= aud_playlist_get_length(playlist) - 1) && !up)) | |
1092 return FALSE; | |
1093 | |
1094 if ((state & GDK_MOD1_MASK) && (state & GDK_SHIFT_MASK)) | |
1095 return FALSE; | |
1096 if (!(state & GDK_MOD1_MASK)) | |
1097 aud_playlist_select_all(playlist, FALSE); | |
1098 | |
1099 if (pl->prev_selected == -1 || | |
1100 (!playlistwin_item_visible(pl->prev_selected) && | |
1101 !(state & GDK_SHIFT_MASK && pl->prev_min != -1))) { | |
1102 pl->prev_selected = pl->first; | |
1103 } | |
1104 else if (state & GDK_SHIFT_MASK) { | |
1105 if (pl->prev_min == -1) { | |
1106 pl->prev_max = pl->prev_selected; | |
1107 pl->prev_min = pl->prev_selected; | |
1108 } | |
1109 pl->prev_max += (up ? -1 : 1); | |
1110 pl->prev_max = | |
1111 CLAMP(pl->prev_max, 0, aud_playlist_get_length(playlist) - 1); | |
1112 | |
1113 pl->first = MIN(pl->first, pl->prev_max); | |
1114 pl->first = MAX(pl->first, pl->prev_max - | |
1115 pl->num_visible + 1); | |
1116 aud_playlist_select_range(playlist, pl->prev_min, pl->prev_max, TRUE); | |
1117 return TRUE; | |
1118 } | |
1119 else if (state & GDK_MOD1_MASK) { | |
1120 if (up) | |
1121 ui_skinned_playlist_move_up(pl); | |
1122 else | |
1123 ui_skinned_playlist_move_down(pl); | |
1124 if (pl->prev_min < pl->first) | |
1125 pl->first = pl->prev_min; | |
1126 else if (pl->prev_max >= (pl->first + pl->num_visible)) | |
1127 pl->first = pl->prev_max - pl->num_visible + 1; | |
1128 return TRUE; | |
1129 } | |
1130 else if (up) | |
1131 pl->prev_selected--; | |
1132 else | |
1133 pl->prev_selected++; | |
1134 | |
1135 pl->prev_selected = | |
1136 CLAMP(pl->prev_selected, 0, aud_playlist_get_length(playlist) - 1); | |
1137 | |
1138 if (pl->prev_selected < pl->first) | |
1139 pl->first--; | |
1140 else if (pl->prev_selected >= (pl->first + pl->num_visible)) | |
1141 pl->first++; | |
1142 | |
1143 aud_playlist_select_range(playlist, pl->prev_selected, pl->prev_selected, TRUE); | |
1144 pl->prev_min = -1; | |
1145 | |
1146 return TRUE; | |
1147 } | |
1148 | |
1149 /* FIXME: Handle the keys through menu */ | |
1150 | |
1151 static gboolean | |
1152 playlistwin_keypress(GtkWidget * w, GdkEventKey * event, gpointer data) | |
1153 { | |
1154 g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), FALSE); | |
1155 Playlist *playlist = aud_playlist_get_active(); | |
1156 | |
1157 guint keyval; | |
1158 gboolean refresh = FALSE; | |
1159 guint cur_pos; | |
1160 | |
1161 if (config.playlist_shaded) | |
1162 return FALSE; | |
1163 | |
1164 switch (keyval = event->keyval) { | |
1165 case GDK_KP_Up: | |
1166 case GDK_KP_Down: | |
1167 case GDK_Up: | |
1168 case GDK_Down: | |
1169 refresh = playlistwin_keypress_up_down_handler(UI_SKINNED_PLAYLIST(playlistwin_list), | |
1170 keyval == GDK_Up | |
1171 || keyval == GDK_KP_Up, | |
1172 event->state); | |
1173 break; | |
1174 case GDK_Page_Up: | |
1175 playlistwin_scroll(-UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); | |
1176 refresh = TRUE; | |
1177 break; | |
1178 case GDK_Page_Down: | |
1179 playlistwin_scroll(UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); | |
1180 refresh = TRUE; | |
1181 break; | |
1182 case GDK_Home: | |
1183 UI_SKINNED_PLAYLIST(playlistwin_list)->first = 0; | |
1184 refresh = TRUE; | |
1185 break; | |
1186 case GDK_End: | |
1187 UI_SKINNED_PLAYLIST(playlistwin_list)->first = | |
1188 aud_playlist_get_length(playlist) - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible; | |
1189 refresh = TRUE; | |
1190 break; | |
1191 case GDK_Return: | |
1192 if (UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected > -1 | |
1193 && playlistwin_item_visible(UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected)) { | |
1194 aud_playlist_set_position(playlist, UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected); | |
1195 if (!audacious_drct_get_playing()) | |
1196 audacious_drct_initiate(); | |
1197 } | |
1198 refresh = TRUE; | |
1199 break; | |
1200 case GDK_3: | |
1201 if (event->state & GDK_CONTROL_MASK) | |
1202 playlistwin_fileinfo(); | |
1203 break; | |
1204 case GDK_Delete: | |
1205 if (event->state & GDK_CONTROL_MASK) | |
1206 aud_playlist_delete(playlist, TRUE); | |
1207 else | |
1208 aud_playlist_delete(playlist, FALSE); | |
1209 break; | |
1210 case GDK_Insert: | |
1211 if (event->state & GDK_MOD1_MASK) | |
1212 mainwin_show_add_url_window(); | |
1213 else | |
1214 playlistwin_show_filebrowser(); | |
1215 break; | |
1216 case GDK_Left: | |
1217 case GDK_KP_Left: | |
1218 case GDK_KP_7: | |
1219 if (aud_playlist_get_current_length(playlist) != -1) | |
1220 audacious_drct_seek(CLAMP | |
1221 (audacious_drct_get_time() - 5000, 0, | |
1222 aud_playlist_get_current_length(playlist))); | |
1223 break; | |
1224 case GDK_Right: | |
1225 case GDK_KP_Right: | |
1226 case GDK_KP_9: | |
1227 if (aud_playlist_get_current_length(playlist) != -1) | |
1228 audacious_drct_seek(CLAMP | |
1229 (audacious_drct_get_time() + 5000, 0, | |
1230 aud_playlist_get_current_length(playlist))); | |
1231 break; | |
1232 case GDK_KP_4: | |
1233 aud_playlist_prev(playlist); | |
1234 break; | |
1235 case GDK_KP_6: | |
1236 aud_playlist_next(playlist); | |
1237 break; | |
1238 | |
1239 case GDK_Escape: | |
1240 mainwin_minimize_cb(); | |
1241 break; | |
1242 case GDK_Tab: | |
1243 if (event->state & GDK_CONTROL_MASK) { | |
1244 if (config.player_visible) | |
1245 gtk_window_present(GTK_WINDOW(mainwin)); | |
1246 else if (config.equalizer_visible) | |
1247 gtk_window_present(GTK_WINDOW(equalizerwin)); | |
1248 } | |
1249 break; | |
1250 case GDK_space: | |
1251 cur_pos=aud_playlist_get_position(playlist); | |
1252 UI_SKINNED_PLAYLIST(playlistwin_list)->first = | |
1253 cur_pos - (UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible >> 1); | |
1254 refresh = TRUE; | |
1255 break; | |
1256 default: | |
1257 return FALSE; | |
1258 } | |
1259 #if 0 | |
1260 if (refresh) { | |
1261 g_cond_signal(cond_scan); | |
1262 playlistwin_update_list(aud_playlist_get_active()); | |
1263 } | |
1264 #endif | |
1265 return TRUE; | |
1266 } | |
1267 | |
1268 void | |
1269 playlistwin_hide_timer(void) | |
1270 { | |
1271 ui_skinned_textbox_set_text(playlistwin_time_min, " "); | |
1272 ui_skinned_textbox_set_text(playlistwin_time_sec, " "); | |
1273 } | |
1274 | |
1275 void | |
1276 playlistwin_set_time(gint time, gint length, TimerMode mode) | |
1277 { | |
1278 gchar *text, sign; | |
1279 | |
1280 if (mode == TIMER_REMAINING && length != -1) { | |
1281 time = length - time; | |
1282 sign = '-'; | |
1283 } | |
1284 else | |
1285 sign = ' '; | |
1286 | |
1287 time /= 1000; | |
1288 | |
1289 if (time < 0) | |
1290 time = 0; | |
1291 if (time > 99 * 60) | |
1292 time /= 60; | |
1293 | |
1294 text = g_strdup_printf("%c%-2.2d", sign, time / 60); | |
1295 ui_skinned_textbox_set_text(playlistwin_time_min, text); | |
1296 g_free(text); | |
1297 | |
1298 text = g_strdup_printf("%-2.2d", time % 60); | |
1299 ui_skinned_textbox_set_text(playlistwin_time_sec, text); | |
1300 g_free(text); | |
1301 } | |
1302 | |
1303 static void | |
1304 playlistwin_drag_motion(GtkWidget * widget, | |
1305 GdkDragContext * context, | |
1306 gint x, gint y, | |
1307 GtkSelectionData * selection_data, | |
1308 guint info, guint time, gpointer user_data) | |
1309 { | |
1310 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) { | |
1311 UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = TRUE; | |
1312 UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_x = x; | |
1313 UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_y = y; | |
1314 } | |
1315 playlistwin_update_list(aud_playlist_get_active()); | |
1316 playlistwin_hint_flag = TRUE; | |
1317 } | |
1318 | |
1319 static void | |
1320 playlistwin_drag_end(GtkWidget * widget, | |
1321 GdkDragContext * context, gpointer user_data) | |
1322 { | |
1323 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) | |
1324 UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = FALSE; | |
1325 playlistwin_hint_flag = FALSE; | |
1326 playlistwin_update_list(aud_playlist_get_active()); | |
1327 } | |
1328 | |
1329 static void | |
1330 playlistwin_drag_data_received(GtkWidget * widget, | |
1331 GdkDragContext * context, | |
1332 gint x, gint y, | |
1333 GtkSelectionData * | |
1334 selection_data, guint info, | |
1335 guint time, gpointer user_data) | |
1336 { | |
1337 gint pos; | |
1338 Playlist *playlist = aud_playlist_get_active(); | |
1339 | |
1340 g_return_if_fail(selection_data); | |
1341 | |
1342 if (!selection_data->data) { | |
1343 g_message("Received no DND data!"); | |
1344 return; | |
1345 } | |
1346 if (UI_SKINNED_IS_PLAYLIST(playlistwin_list) && | |
1347 (x < playlistwin_get_width() - 20 || y < config.playlist_height - 38)) { | |
1348 pos = y / UI_SKINNED_PLAYLIST(playlistwin_list)->fheight + UI_SKINNED_PLAYLIST(playlistwin_list)->first; | |
1349 | |
1350 pos = MIN(pos, aud_playlist_get_length(playlist)); | |
1351 aud_playlist_ins_url(playlist, (gchar *) selection_data->data, pos); | |
1352 } | |
1353 else | |
1354 aud_playlist_add_url(playlist, (gchar *) selection_data->data); | |
1355 } | |
1356 | |
1357 static void | |
1358 local_playlist_prev(void) | |
1359 { | |
1360 aud_playlist_prev(aud_playlist_get_active()); | |
1361 } | |
1362 | |
1363 static void | |
1364 local_playlist_next(void) | |
1365 { | |
1366 aud_playlist_next(aud_playlist_get_active()); | |
1367 } | |
1368 | |
1369 static void | |
1370 playlistwin_create_widgets(void) | |
1371 { | |
1372 /* This function creates the custom widgets used by the playlist editor */ | |
1373 | |
1374 /* text box for displaying song title in shaded mode */ | |
1375 playlistwin_sinfo = ui_skinned_textbox_new(SKINNED_WINDOW(playlistwin)->fixed, | |
1376 4, 4, playlistwin_get_width() - 35, TRUE, SKIN_TEXT); | |
1377 | |
2642 | 1378 playlistwin_set_sinfo_font(config.playlist_font); |
2620 | 1379 |
1380 playlistwin_shade = ui_skinned_button_new(); | |
1381 /* shade/unshade window push button */ | |
1382 if (config.playlist_shaded) | |
1383 ui_skinned_push_button_setup(playlistwin_shade, SKINNED_WINDOW(playlistwin)->fixed, | |
1384 playlistwin_get_width() - 21, 3, | |
1385 9, 9, 128, 45, 150, 42, SKIN_PLEDIT); | |
1386 else | |
1387 ui_skinned_push_button_setup(playlistwin_shade, SKINNED_WINDOW(playlistwin)->fixed, | |
1388 playlistwin_get_width() - 21, 3, | |
1389 9, 9, 157, 3, 62, 42, SKIN_PLEDIT); | |
1390 | |
1391 g_signal_connect(playlistwin_shade, "clicked", playlistwin_shade_toggle, NULL ); | |
1392 | |
1393 /* close window push button */ | |
1394 playlistwin_close = ui_skinned_button_new(); | |
1395 ui_skinned_push_button_setup(playlistwin_close, SKINNED_WINDOW(playlistwin)->fixed, | |
1396 playlistwin_get_width() - 11, 3, 9, 9, | |
1397 config.playlist_shaded ? 138 : 167, | |
1398 config.playlist_shaded ? 45 : 3, 52, 42, SKIN_PLEDIT); | |
1399 | |
1400 g_signal_connect(playlistwin_close, "clicked", playlistwin_hide, NULL ); | |
1401 | |
1402 /* playlist list box */ | |
1403 playlistwin_list = ui_skinned_playlist_new(SKINNED_WINDOW(playlistwin)->fixed, 12, 20, | |
1404 playlistwin_get_width() - 31, | |
1405 config.playlist_height - 58); | |
2642 | 1406 ui_skinned_playlist_set_font(config.playlist_font); |
2620 | 1407 |
1408 /* playlist list box slider */ | |
1409 playlistwin_slider = ui_skinned_playlist_slider_new(SKINNED_WINDOW(playlistwin)->fixed, playlistwin_get_width() - 15, | |
1410 20, config.playlist_height - 58); | |
1411 | |
1412 /* track time (minute) */ | |
1413 playlistwin_time_min = ui_skinned_textbox_new(SKINNED_WINDOW(playlistwin)->fixed, | |
1414 playlistwin_get_width() - 82, | |
1415 config.playlist_height - 15, 15, FALSE, SKIN_TEXT); | |
1416 g_signal_connect(playlistwin_time_min, "button-press-event", G_CALLBACK(change_timer_mode_cb), NULL); | |
1417 | |
1418 /* track time (second) */ | |
1419 playlistwin_time_sec = ui_skinned_textbox_new(SKINNED_WINDOW(playlistwin)->fixed, | |
1420 playlistwin_get_width() - 64, | |
1421 config.playlist_height - 15, 10, FALSE, SKIN_TEXT); | |
1422 g_signal_connect(playlistwin_time_sec, "button-press-event", G_CALLBACK(change_timer_mode_cb), NULL); | |
1423 | |
1424 /* playlist information (current track length / total track length) */ | |
1425 playlistwin_info = ui_skinned_textbox_new(SKINNED_WINDOW(playlistwin)->fixed, | |
1426 playlistwin_get_width() - 143, | |
1427 config.playlist_height - 28, 90, FALSE, SKIN_TEXT); | |
1428 | |
1429 /* mini play control buttons at right bottom corner */ | |
1430 | |
1431 /* rewind button */ | |
1432 playlistwin_srew = ui_skinned_button_new(); | |
1433 ui_skinned_small_button_setup(playlistwin_srew, SKINNED_WINDOW(playlistwin)->fixed, | |
1434 playlistwin_get_width() - 144, | |
1435 config.playlist_height - 16, 8, 7); | |
1436 g_signal_connect(playlistwin_srew, "clicked", local_playlist_prev, NULL); | |
1437 | |
1438 /* play button */ | |
1439 playlistwin_splay = ui_skinned_button_new(); | |
1440 ui_skinned_small_button_setup(playlistwin_splay, SKINNED_WINDOW(playlistwin)->fixed, | |
1441 playlistwin_get_width() - 138, | |
1442 config.playlist_height - 16, 10, 7); | |
1443 g_signal_connect(playlistwin_splay, "clicked", mainwin_play_pushed, NULL); | |
1444 | |
1445 /* pause button */ | |
1446 playlistwin_spause = ui_skinned_button_new(); | |
1447 ui_skinned_small_button_setup(playlistwin_spause, SKINNED_WINDOW(playlistwin)->fixed, | |
1448 playlistwin_get_width() - 128, | |
1449 config.playlist_height - 16, 10, 7); | |
1450 g_signal_connect(playlistwin_spause, "clicked", audacious_drct_pause, NULL); | |
1451 | |
1452 /* stop button */ | |
1453 playlistwin_sstop = ui_skinned_button_new(); | |
1454 ui_skinned_small_button_setup(playlistwin_sstop, SKINNED_WINDOW(playlistwin)->fixed, | |
1455 playlistwin_get_width() - 118, | |
1456 config.playlist_height - 16, 9, 7); | |
1457 g_signal_connect(playlistwin_sstop, "clicked", mainwin_stop_pushed, NULL); | |
1458 | |
1459 /* forward button */ | |
1460 playlistwin_sfwd = ui_skinned_button_new(); | |
1461 ui_skinned_small_button_setup(playlistwin_sfwd, SKINNED_WINDOW(playlistwin)->fixed, | |
1462 playlistwin_get_width() - 109, | |
1463 config.playlist_height - 16, 8, 7); | |
1464 g_signal_connect(playlistwin_sfwd, "clicked", local_playlist_next, NULL); | |
1465 | |
1466 /* eject button */ | |
1467 playlistwin_seject = ui_skinned_button_new(); | |
1468 ui_skinned_small_button_setup(playlistwin_seject, SKINNED_WINDOW(playlistwin)->fixed, | |
1469 playlistwin_get_width() - 100, | |
1470 config.playlist_height - 16, 9, 7); | |
1471 g_signal_connect(playlistwin_seject, "clicked", mainwin_eject_pushed, NULL); | |
1472 | |
1473 playlistwin_sscroll_up = ui_skinned_button_new(); | |
1474 ui_skinned_small_button_setup(playlistwin_sscroll_up, SKINNED_WINDOW(playlistwin)->fixed, | |
1475 playlistwin_get_width() - 14, | |
1476 config.playlist_height - 35, 8, 5); | |
1477 g_signal_connect(playlistwin_sscroll_up, "clicked", playlistwin_scroll_up_pushed, NULL); | |
1478 | |
1479 playlistwin_sscroll_down = ui_skinned_button_new(); | |
1480 ui_skinned_small_button_setup(playlistwin_sscroll_down, SKINNED_WINDOW(playlistwin)->fixed, | |
1481 playlistwin_get_width() - 14, | |
1482 config.playlist_height - 30, 8, 5); | |
1483 g_signal_connect(playlistwin_sscroll_down, "clicked", playlistwin_scroll_down_pushed, NULL); | |
1484 | |
1485 ui_playlist_evlistener_init(); | |
1486 } | |
1487 | |
1488 static void | |
1489 selection_received(GtkWidget * widget, | |
1490 GtkSelectionData * selection_data, gpointer data) | |
1491 { | |
1492 if (selection_data->type == GDK_SELECTION_TYPE_STRING && | |
1493 selection_data->length > 0) | |
1494 aud_playlist_add_url(aud_playlist_get_active(), (gchar *) selection_data->data); | |
1495 } | |
1496 | |
1497 static void | |
1498 playlistwin_create_window(void) | |
1499 { | |
1500 GdkPixbuf *icon; | |
1501 | |
1502 playlistwin = ui_skinned_window_new("playlist"); | |
1503 gtk_window_set_title(GTK_WINDOW(playlistwin), _("Audacious Playlist Editor")); | |
1504 gtk_window_set_role(GTK_WINDOW(playlistwin), "playlist"); | |
1505 gtk_window_set_default_size(GTK_WINDOW(playlistwin), | |
1506 playlistwin_get_width(), | |
1507 playlistwin_get_height()); | |
1508 gtk_window_set_resizable(GTK_WINDOW(playlistwin), TRUE); | |
1509 playlistwin_set_geometry_hints(config.playlist_shaded); | |
1510 | |
1511 gtk_window_set_transient_for(GTK_WINDOW(playlistwin), | |
1512 GTK_WINDOW(mainwin)); | |
1513 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(playlistwin), TRUE); | |
1514 | |
1515 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_playlist_icon); | |
1516 gtk_window_set_icon(GTK_WINDOW(playlistwin), icon); | |
1517 g_object_unref(icon); | |
1518 | |
1519 if (config.playlist_x != -1 && config.save_window_position) | |
1520 gtk_window_move(GTK_WINDOW(playlistwin), | |
1521 config.playlist_x, config.playlist_y); | |
1522 | |
1523 gtk_widget_add_events(playlistwin, GDK_POINTER_MOTION_MASK | | |
1524 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
1525 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1526 GDK_SCROLL_MASK | GDK_VISIBILITY_NOTIFY_MASK); | |
1527 gtk_widget_realize(playlistwin); | |
1528 | |
1529 g_signal_connect(playlistwin, "delete_event", | |
1530 G_CALLBACK(playlistwin_delete), NULL); | |
1531 g_signal_connect(playlistwin, "button_press_event", | |
1532 G_CALLBACK(playlistwin_press), NULL); | |
1533 g_signal_connect(playlistwin, "button_release_event", | |
1534 G_CALLBACK(playlistwin_release), NULL); | |
1535 g_signal_connect(playlistwin, "scroll_event", | |
1536 G_CALLBACK(playlistwin_scrolled), NULL); | |
1537 g_signal_connect(playlistwin, "motion_notify_event", | |
1538 G_CALLBACK(playlistwin_motion), NULL); | |
2629
2ce9e17525dc
make dnd working in playlistwin
Tomasz Mon <desowin@gmail.com>
parents:
2621
diff
changeset
|
1539 |
2620 | 1540 aud_drag_dest_set(playlistwin); |
2629
2ce9e17525dc
make dnd working in playlistwin
Tomasz Mon <desowin@gmail.com>
parents:
2621
diff
changeset
|
1541 |
2620 | 1542 /* DnD stuff */ |
1543 g_signal_connect(playlistwin, "drag-leave", | |
1544 G_CALLBACK(playlistwin_drag_end), NULL); | |
1545 g_signal_connect(playlistwin, "drag-data-delete", | |
1546 G_CALLBACK(playlistwin_drag_end), NULL); | |
1547 g_signal_connect(playlistwin, "drag-end", | |
1548 G_CALLBACK(playlistwin_drag_end), NULL); | |
1549 g_signal_connect(playlistwin, "drag-drop", | |
1550 G_CALLBACK(playlistwin_drag_end), NULL); | |
1551 g_signal_connect(playlistwin, "drag-data-received", | |
1552 G_CALLBACK(playlistwin_drag_data_received), NULL); | |
1553 g_signal_connect(playlistwin, "drag-motion", | |
1554 G_CALLBACK(playlistwin_drag_motion), NULL); | |
1555 | |
1556 g_signal_connect(playlistwin, "key_press_event", | |
1557 G_CALLBACK(playlistwin_keypress), NULL); | |
1558 g_signal_connect(playlistwin, "selection_received", | |
1559 G_CALLBACK(selection_received), NULL); | |
1560 } | |
1561 | |
1562 void | |
1563 playlistwin_create(void) | |
1564 { | |
1565 resize_mutex = g_mutex_new(); | |
1566 playlistwin_create_window(); | |
1567 | |
1568 playlistwin_create_widgets(); | |
1569 playlistwin_update_info(aud_playlist_get_active()); | |
1570 | |
1571 gtk_window_add_accel_group(GTK_WINDOW(playlistwin), ui_manager_get_accel_group()); | |
1572 } | |
1573 | |
1574 | |
1575 void | |
1576 playlistwin_show(void) | |
1577 { | |
1578 gtk_window_move(GTK_WINDOW(playlistwin), config.playlist_x, config.playlist_y); | |
1579 GtkAction *action = gtk_action_group_get_action( | |
1580 toggleaction_group_others , "show playlist editor" ); | |
1581 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , TRUE ); | |
1582 | |
1583 config.playlist_visible = TRUE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2658
diff
changeset
|
1584 ui_skinned_button_set_inside(mainwin_pl, TRUE); |
2620 | 1585 |
1586 playlistwin_set_toprow(0); | |
1587 aud_playlist_check_pos_current(aud_playlist_get_active()); | |
1588 | |
1589 gtk_widget_show_all(playlistwin); | |
1590 if (!config.playlist_shaded) | |
1591 gtk_widget_hide(playlistwin_sinfo); | |
1592 gtk_window_present(GTK_WINDOW(playlistwin)); | |
1593 } | |
1594 | |
1595 void | |
1596 playlistwin_hide(void) | |
1597 { | |
1598 GtkAction *action = gtk_action_group_get_action( | |
1599 toggleaction_group_others , "show playlist editor" ); | |
1600 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , FALSE ); | |
1601 | |
1602 gtk_widget_hide(playlistwin); | |
1603 config.playlist_visible = FALSE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2658
diff
changeset
|
1604 ui_skinned_button_set_inside(mainwin_pl, FALSE); |
2620 | 1605 |
1606 if ( config.player_visible ) | |
1607 { | |
1608 gtk_window_present(GTK_WINDOW(mainwin)); | |
1609 gtk_widget_grab_focus(mainwin); | |
1610 } | |
1611 } | |
1612 | |
1613 void action_playlist_track_info(void) | |
1614 { | |
1615 playlistwin_fileinfo(); | |
1616 } | |
1617 | |
1618 void action_queue_toggle(void) | |
1619 { | |
1620 aud_playlist_queue(aud_playlist_get_active()); | |
1621 } | |
1622 | |
1623 void action_playlist_sort_by_playlist_entry(void) | |
1624 { | |
1625 Playlist *playlist = aud_playlist_get_active(); | |
1626 | |
1627 aud_playlist_sort(playlist, PLAYLIST_SORT_PLAYLIST); | |
1628 playlistwin_update_list(playlist); | |
1629 } | |
1630 | |
1631 void action_playlist_sort_by_track_number(void) | |
1632 { | |
1633 Playlist *playlist = aud_playlist_get_active(); | |
1634 | |
1635 aud_playlist_sort(playlist, PLAYLIST_SORT_TRACK); | |
1636 playlistwin_update_list(playlist); | |
1637 } | |
1638 | |
1639 void action_playlist_sort_by_title(void) | |
1640 { | |
1641 Playlist *playlist = aud_playlist_get_active(); | |
1642 | |
1643 aud_playlist_sort(playlist, PLAYLIST_SORT_TITLE); | |
1644 playlistwin_update_list(playlist); | |
1645 } | |
1646 | |
1647 void action_playlist_sort_by_artist(void) | |
1648 { | |
1649 Playlist *playlist = aud_playlist_get_active(); | |
1650 | |
1651 aud_playlist_sort(playlist, PLAYLIST_SORT_ARTIST); | |
1652 playlistwin_update_list(playlist); | |
1653 } | |
1654 | |
1655 void action_playlist_sort_by_full_path(void) | |
1656 { | |
1657 Playlist *playlist = aud_playlist_get_active(); | |
1658 | |
1659 aud_playlist_sort(playlist, PLAYLIST_SORT_PATH); | |
1660 playlistwin_update_list(playlist); | |
1661 } | |
1662 | |
1663 void action_playlist_sort_by_date(void) | |
1664 { | |
1665 Playlist *playlist = aud_playlist_get_active(); | |
1666 | |
1667 aud_playlist_sort(playlist, PLAYLIST_SORT_DATE); | |
1668 playlistwin_update_list(playlist); | |
1669 } | |
1670 | |
1671 void action_playlist_sort_by_filename(void) | |
1672 { | |
1673 Playlist *playlist = aud_playlist_get_active(); | |
1674 | |
1675 aud_playlist_sort(playlist, PLAYLIST_SORT_FILENAME); | |
1676 playlistwin_update_list(playlist); | |
1677 } | |
1678 | |
1679 void action_playlist_sort_selected_by_playlist_entry(void) | |
1680 { | |
1681 Playlist *playlist = aud_playlist_get_active(); | |
1682 | |
1683 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_PLAYLIST); | |
1684 playlistwin_update_list(playlist); | |
1685 } | |
1686 | |
1687 void action_playlist_sort_selected_by_track_number(void) | |
1688 { | |
1689 Playlist *playlist = aud_playlist_get_active(); | |
1690 | |
1691 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_TRACK); | |
1692 playlistwin_update_list(playlist); | |
1693 } | |
1694 | |
1695 void action_playlist_sort_selected_by_title(void) | |
1696 { | |
1697 Playlist *playlist = aud_playlist_get_active(); | |
1698 | |
1699 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_TITLE); | |
1700 playlistwin_update_list(playlist); | |
1701 } | |
1702 | |
1703 void action_playlist_sort_selected_by_artist(void) | |
1704 { | |
1705 Playlist *playlist = aud_playlist_get_active(); | |
1706 | |
1707 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_ARTIST); | |
1708 playlistwin_update_list(playlist); | |
1709 } | |
1710 | |
1711 void action_playlist_sort_selected_by_full_path(void) | |
1712 { | |
1713 Playlist *playlist = aud_playlist_get_active(); | |
1714 | |
1715 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_PATH); | |
1716 playlistwin_update_list(playlist); | |
1717 } | |
1718 | |
1719 void action_playlist_sort_selected_by_date(void) | |
1720 { | |
1721 Playlist *playlist = aud_playlist_get_active(); | |
1722 | |
1723 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_DATE); | |
1724 playlistwin_update_list(playlist); | |
1725 } | |
1726 | |
1727 void action_playlist_sort_selected_by_filename(void) | |
1728 { | |
1729 Playlist *playlist = aud_playlist_get_active(); | |
1730 | |
1731 aud_playlist_sort_selected(playlist, PLAYLIST_SORT_FILENAME); | |
1732 playlistwin_update_list(playlist); | |
1733 } | |
1734 | |
1735 void action_playlist_randomize_list(void) | |
1736 { | |
1737 Playlist *playlist = aud_playlist_get_active(); | |
1738 | |
1739 aud_playlist_random(playlist); | |
1740 playlistwin_update_list(playlist); | |
1741 } | |
1742 | |
1743 void action_playlist_reverse_list(void) | |
1744 { | |
1745 Playlist *playlist = aud_playlist_get_active(); | |
1746 | |
1747 aud_playlist_reverse(playlist); | |
1748 playlistwin_update_list(playlist); | |
1749 } | |
1750 | |
1751 void | |
1752 action_playlist_clear_queue(void) | |
1753 { | |
1754 aud_playlist_clear_queue(aud_playlist_get_active()); | |
1755 } | |
1756 | |
1757 void | |
1758 action_playlist_remove_unavailable(void) | |
1759 { | |
1760 aud_playlist_remove_dead_files(aud_playlist_get_active()); | |
1761 } | |
1762 | |
1763 void | |
1764 action_playlist_remove_dupes_by_title(void) | |
1765 { | |
1766 aud_playlist_remove_duplicates(aud_playlist_get_active(), PLAYLIST_DUPS_TITLE); | |
1767 } | |
1768 | |
1769 void | |
1770 action_playlist_remove_dupes_by_filename(void) | |
1771 { | |
1772 aud_playlist_remove_duplicates(aud_playlist_get_active(), PLAYLIST_DUPS_FILENAME); | |
1773 } | |
1774 | |
1775 void | |
1776 action_playlist_remove_dupes_by_full_path(void) | |
1777 { | |
1778 aud_playlist_remove_duplicates(aud_playlist_get_active(), PLAYLIST_DUPS_PATH); | |
1779 } | |
1780 | |
1781 void | |
1782 action_playlist_remove_all(void) | |
1783 { | |
1784 aud_playlist_clear(aud_playlist_get_active()); | |
1785 | |
1786 /* XXX -- should this really be coupled here? -nenolod */ | |
1787 mainwin_clear_song_info(); | |
1788 } | |
1789 | |
1790 void | |
1791 action_playlist_remove_selected(void) | |
1792 { | |
1793 aud_playlist_delete(aud_playlist_get_active(), FALSE); | |
1794 } | |
1795 | |
1796 void | |
1797 action_playlist_remove_unselected(void) | |
1798 { | |
1799 aud_playlist_delete(aud_playlist_get_active(), TRUE); | |
1800 } | |
1801 | |
1802 void | |
1803 action_playlist_add_files(void) | |
1804 { | |
2640 | 1805 gboolean button = FALSE; /* FALSE = NO_PLAY_BUTTON */ |
1806 aud_hook_call("filebrowser show", &button); | |
2620 | 1807 } |
1808 | |
1809 void | |
1810 action_playlist_add_url(void) | |
1811 { | |
1812 mainwin_show_add_url_window(); | |
1813 } | |
1814 | |
1815 void | |
1816 action_playlist_new( void ) | |
1817 { | |
1818 Playlist *new_pl = aud_playlist_new(); | |
1819 aud_playlist_add_playlist(new_pl); | |
1820 aud_playlist_select_playlist(new_pl); | |
1821 } | |
1822 | |
1823 void | |
1824 action_playlist_prev( void ) | |
1825 { | |
1826 aud_playlist_select_prev(); | |
1827 } | |
1828 | |
1829 void | |
1830 action_playlist_next( void ) | |
1831 { | |
1832 aud_playlist_select_next(); | |
1833 } | |
1834 | |
1835 void | |
1836 action_playlist_delete( void ) | |
1837 { | |
1838 aud_playlist_remove_playlist( aud_playlist_get_active() ); | |
1839 } | |
1840 | |
1841 void | |
1842 action_playlist_save_list(void) | |
1843 { | |
1844 Playlist *playlist = aud_playlist_get_active(); | |
1845 | |
1846 playlistwin_select_playlist_to_save(aud_playlist_get_current_name(playlist)); | |
1847 } | |
1848 | |
1849 void | |
1850 action_playlist_save_default_list(void) | |
1851 { | |
1852 #if 0 | |
1853 Playlist *playlist = aud_playlist_get_active(); | |
1854 | |
1855 aud_playlist_save(playlist, aud_paths[BMP_PATH_PLAYLIST_FILE]); | |
1856 #endif | |
1857 } | |
1858 | |
1859 void | |
1860 action_playlist_load_list(void) | |
1861 { | |
1862 Playlist *playlist = aud_playlist_get_active(); | |
1863 | |
1864 playlistwin_select_playlist_to_load(aud_playlist_get_current_name(playlist)); | |
1865 } | |
1866 | |
1867 void | |
1868 action_playlist_refresh_list(void) | |
1869 { | |
1870 Playlist *playlist = aud_playlist_get_active(); | |
1871 | |
1872 aud_playlist_read_info_selection(playlist); | |
1873 playlistwin_update_list(playlist); | |
1874 } | |
1875 | |
1876 void | |
1877 action_open_list_manager(void) | |
1878 { | |
1879 #if 0 | |
1880 playlist_manager_ui_show(); | |
1881 #endif | |
1882 } | |
1883 | |
1884 void | |
1885 action_playlist_search_and_select(void) | |
1886 { | |
1887 playlistwin_select_search(); | |
1888 } | |
1889 | |
1890 void | |
1891 action_playlist_invert_selection(void) | |
1892 { | |
1893 playlistwin_inverse_selection(); | |
1894 } | |
1895 | |
1896 void | |
1897 action_playlist_select_none(void) | |
1898 { | |
1899 playlistwin_select_none(); | |
1900 } | |
1901 | |
1902 void | |
1903 action_playlist_select_all(void) | |
1904 { | |
1905 playlistwin_select_all(); | |
1906 } | |
1907 | |
1908 | |
1909 static void | |
1910 playlistwin_select_search_cbt_cb(GtkWidget *called_cbt, gpointer other_cbt) | |
1911 { | |
1912 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(called_cbt)) == TRUE) | |
1913 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(other_cbt), FALSE); | |
1914 return; | |
1915 } | |
1916 | |
1917 static gboolean | |
1918 playlistwin_select_search_kp_cb(GtkWidget *entry, GdkEventKey *event, | |
1919 gpointer searchdlg_win) | |
1920 { | |
1921 switch (event->keyval) | |
1922 { | |
1923 case GDK_Return: | |
1924 if (gtk_im_context_filter_keypress (GTK_ENTRY (entry)->im_context, event)) { | |
1925 GTK_ENTRY (entry)->need_im_reset = TRUE; | |
1926 return TRUE; | |
1927 } else { | |
1928 gtk_dialog_response(GTK_DIALOG(searchdlg_win), GTK_RESPONSE_ACCEPT); | |
1929 return TRUE; | |
1930 } | |
1931 default: | |
1932 return FALSE; | |
1933 } | |
1934 } |