Mercurial > audlegacy
annotate audacious/playlistwin.c @ 276:28b73b5595d1 trunk
[svn] Raise MAX_CODED_SUPERFRAME_SIZE to 16384 in accordance with ffmpeg CVS.
author | chainsaw |
---|---|
date | Sat, 10 Dec 2005 08:42:49 -0800 |
parents | 32d7260f413e |
children | 763afa52f416 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include "playlistwin.h" | |
23 | |
24 #include <glib.h> | |
25 #include <glib/gi18n.h> | |
26 #include <gdk/gdk.h> | |
27 #include <gdk/gdkkeysyms.h> | |
28 #include <gtk/gtk.h> | |
29 #include <string.h> | |
30 | |
31 #include <gdk/gdkx.h> | |
32 | |
33 #include <X11/Xlib.h> | |
34 #include <unistd.h> | |
35 #include <errno.h> | |
36 | |
37 #include "libaudacious/util.h" | |
38 | |
39 #include "dnd.h" | |
40 #include "dock.h" | |
41 #include "equalizer.h" | |
42 #include "hints.h" | |
43 #include "input.h" | |
44 #include "main.h" | |
45 #include "mainwin.h" | |
46 #include "playback.h" | |
47 #include "playlist.h" | |
48 #include "playlist_list.h" | |
49 #include "playlist_slider.h" | |
50 #include "playlist_popup.h" | |
51 #include "pbutton.h" | |
52 #include "sbutton.h" | |
53 #include "skin.h" | |
54 #include "textbox.h" | |
55 #include "util.h" | |
56 | |
57 #include "pixmaps.h" | |
120 | 58 #include "images/audacious_playlist.xpm" |
0 | 59 |
60 | |
61 #define ITEM_SEPARATOR {"/-", NULL, NULL, 0, "<Separator>"} | |
62 | |
63 | |
64 enum { | |
65 ADD_URL, ADD_DIR, ADD_FILES, | |
66 SUB_MISC, SUB_ALL, SUB_CROP, SUB_SELECTED, | |
67 SEL_INV, SEL_ZERO, SEL_ALL, | |
68 MISC_SORT, MISC_FILEINFO, MISC_MISCOPTS, | |
69 PLIST_NEW, PLIST_SAVE_AS, PLIST_LOAD, | |
70 SEL_LOOKUP, CLOSE_PL_WINDOW, MOVE_UP, PLIST_SAVE, | |
71 MISC_QUEUE, PLIST_CQUEUE, PLIST_JTF, PLIST_JTT, | |
72 PLAYLISTWIN_REMOVE_DEAD_FILES, | |
73 PLAYLISTWIN_REFRESH | |
74 }; | |
75 | |
76 enum { | |
77 PLAYLISTWIN_SORT_BYTITLE, PLAYLISTWIN_SORT_BYFILENAME, | |
78 PLAYLISTWIN_SORT_BYPATH, PLAYLISTWIN_SORT_BYDATE, | |
79 PLAYLISTWIN_SORT_SEL_BYTITLE, PLAYLISTWIN_SORT_SEL_BYFILENAME, | |
80 PLAYLISTWIN_SORT_SEL_BYPATH, PLAYLISTWIN_SORT_SEL_BYDATE, | |
81 PLAYLISTWIN_SORT_RANDOMIZE, PLAYLISTWIN_SORT_REVERSE | |
82 }; | |
83 | |
84 GtkWidget *playlistwin; | |
85 | |
86 PlayList_List *playlistwin_list = NULL; | |
87 PButton *playlistwin_shade, *playlistwin_close; | |
88 Vis *playlistwin_vis; | |
89 | |
90 static gboolean playlistwin_resizing = FALSE; | |
91 | |
92 static GtkItemFactory *playlistwin_popup_menu; | |
93 static GtkItemFactory *pladd_menu, *pldel_menu; | |
94 static GtkItemFactory *plsel_menu, *plsort_menu; | |
95 static GtkItemFactory *pllist_menu; | |
96 | |
97 static GdkPixmap *playlistwin_bg; | |
98 static GdkBitmap *playlistwin_mask = NULL; | |
99 static GdkGC *playlistwin_gc; | |
100 | |
101 static GtkAccelGroup *playlistwin_accel; | |
102 | |
103 static gboolean playlistwin_hint_flag = FALSE; | |
104 | |
105 static PlaylistSlider *playlistwin_slider = NULL; | |
106 static TextBox *playlistwin_time_min, *playlistwin_time_sec; | |
107 static TextBox *playlistwin_info, *playlistwin_sinfo; | |
108 static SButton *playlistwin_srew, *playlistwin_splay; | |
109 static SButton *playlistwin_spause, *playlistwin_sstop; | |
110 static SButton *playlistwin_sfwd, *playlistwin_seject; | |
111 static SButton *playlistwin_sscroll_up, *playlistwin_sscroll_down; | |
112 | |
113 static GList *playlistwin_wlist = NULL; | |
114 static gboolean playlistwin_vis_enabled = FALSE; | |
115 | |
116 static void plsort_menu_callback(gpointer cb_data, guint action, | |
117 GtkWidget * w); | |
118 static void playlistwin_sub_menu_callback(gpointer cb_data, guint action, | |
119 GtkWidget * w); | |
120 static void playlistwin_popup_menu_callback(gpointer cb_data, guint action, | |
121 GtkWidget * w); | |
122 | |
123 static GtkItemFactoryEntry playlistwin_popup_menu_entries[] = { | |
124 {N_("/View Track Details"), NULL, | |
125 playlistwin_popup_menu_callback, | |
126 MISC_FILEINFO, "<ImageItem>", my_pixbuf}, | |
127 | |
128 ITEM_SEPARATOR, | |
129 | |
130 {N_("/Remove Selected"), "Delete", | |
131 playlistwin_sub_menu_callback, | |
132 SUB_SELECTED, "<Item>", GTK_STOCK_DELETE}, | |
133 | |
134 {N_("/Remove Unselected"), NULL, | |
135 playlistwin_sub_menu_callback, | |
136 SUB_CROP, "<Item>", GTK_STOCK_CUT}, | |
137 | |
138 {N_("/Remove All"), NULL, | |
139 playlistwin_sub_menu_callback, | |
140 SUB_ALL, "<Item>", GTK_STOCK_DELETE}, | |
141 | |
142 ITEM_SEPARATOR, | |
143 | |
144 {N_("/Queue Toggle"), "q", | |
145 playlistwin_popup_menu_callback, | |
146 MISC_QUEUE, "<Item>", NULL}, | |
147 }; | |
148 | |
149 static GtkItemFactoryEntry pladd_menu_entries[] = { | |
150 {N_("/Add CD..."), "<shift>c", | |
151 mainwin_general_menu_callback, | |
152 MAINWIN_GENERAL_ADDCD, "<StockItem>", GTK_STOCK_CDROM}, | |
153 | |
154 {N_("/Add Internet Address..."), "<control>h", | |
155 mainwin_general_menu_callback, | |
156 MAINWIN_GENERAL_PLAYLOCATION, "<StockItem>", GTK_STOCK_NETWORK}, | |
157 | |
158 /* GtkFileChooser in SELECT_FOLDER mode is currently BROKEN! */ | |
159 #if 0 | |
160 {N_("/Add Folders..."), "d", | |
161 mainwin_general_menu_callback, | |
162 MAINWIN_GENERAL_PLAYDIRECTORY, "<StockItem>", GTK_STOCK_OPEN}, | |
163 #endif | |
164 | |
165 {N_("/Add Files..."), "f", | |
166 mainwin_general_menu_callback, | |
167 MAINWIN_GENERAL_PLAYFILE, "<StockItem>", GTK_STOCK_OPEN}, | |
168 }; | |
169 | |
170 static GtkItemFactoryEntry pldel_menu_entries[] = { | |
171 {N_("/Clear Queue"), "<shift>Q", | |
172 playlistwin_popup_menu_callback, | |
173 PLIST_CQUEUE, "<Item>"}, | |
174 | |
175 ITEM_SEPARATOR, | |
176 | |
177 {N_("/Remove Unavailable Files"), NULL, | |
178 playlistwin_sub_menu_callback, | |
179 PLAYLISTWIN_REMOVE_DEAD_FILES, "<Item>", GTK_STOCK_DELETE}, | |
180 | |
181 ITEM_SEPARATOR, | |
182 | |
183 {N_("/Remove All"), NULL, | |
184 playlistwin_sub_menu_callback, | |
185 SUB_ALL, "<Item>", GTK_STOCK_DELETE}, | |
186 | |
187 {N_("/Remove Unselected"), NULL, | |
188 playlistwin_sub_menu_callback, | |
189 SUB_CROP, "<Item>", GTK_STOCK_DELETE}, | |
190 | |
191 {N_("/Remove Selected"), "Delete", | |
192 playlistwin_sub_menu_callback, | |
193 SUB_SELECTED, "<Item>", GTK_STOCK_DELETE} | |
194 }; | |
195 | |
196 static GtkItemFactoryEntry pllist_menu_entries[] = { | |
197 {N_("/New List"), NULL, | |
198 playlistwin_sub_menu_callback, | |
199 PLIST_NEW, "<StockItem>", GTK_STOCK_NEW}, | |
200 | |
201 ITEM_SEPARATOR, | |
202 | |
203 {N_("/Load List"), "o", | |
204 playlistwin_sub_menu_callback, | |
205 PLIST_LOAD, "<StockItem>", GTK_STOCK_OPEN}, | |
206 | |
207 {N_("/Save List"), "s", | |
208 playlistwin_sub_menu_callback, | |
209 PLIST_SAVE, "<StockItem>", GTK_STOCK_SAVE}, | |
210 | |
211 ITEM_SEPARATOR, | |
212 | |
213 {N_("/Update View"), "F5", | |
214 playlistwin_sub_menu_callback, | |
215 PLAYLISTWIN_REFRESH, "<StockItem>", GTK_STOCK_REFRESH} | |
216 }; | |
217 | |
218 static GtkItemFactoryEntry plsel_menu_entries[] = { | |
219 {N_("/Invert Selection"), NULL, | |
220 playlistwin_sub_menu_callback, | |
221 SEL_INV, "<Item>", GTK_STOCK_NETWORK}, | |
222 | |
223 ITEM_SEPARATOR, | |
224 | |
225 {N_("/Select None"),"<Ctrl><Shift>A", | |
226 playlistwin_sub_menu_callback, | |
227 SEL_ZERO, "<Item>", GTK_STOCK_OPEN}, | |
228 | |
229 {N_("/Select All"), "<Ctrl>A", | |
230 playlistwin_sub_menu_callback, | |
231 SEL_ALL, "<Item>", GTK_STOCK_OPEN}, | |
232 }; | |
233 | |
234 static GtkItemFactoryEntry plsort_menu_entries[] = { | |
235 {N_("/Randomize List"), NULL, plsort_menu_callback, | |
236 PLAYLISTWIN_SORT_RANDOMIZE, "<Item>"}, | |
237 {N_("/Reverse List"), NULL, plsort_menu_callback, | |
238 PLAYLISTWIN_SORT_REVERSE, "<Item>"}, | |
239 ITEM_SEPARATOR, | |
240 {N_("/Sort List"), NULL, NULL, 0, "<Branch>"}, | |
241 {N_("/Sort List/By Title"), NULL, plsort_menu_callback, | |
242 PLAYLISTWIN_SORT_BYTITLE, "<Item>"}, | |
243 {N_("/Sort List/By Filename"), NULL, plsort_menu_callback, | |
244 PLAYLISTWIN_SORT_BYFILENAME, "<Item>"}, | |
245 {N_("/Sort List/By Path + Filename"), NULL, plsort_menu_callback, | |
246 PLAYLISTWIN_SORT_BYPATH, "<Item>"}, | |
247 {N_("/Sort List/By Date"), NULL, plsort_menu_callback, | |
248 PLAYLISTWIN_SORT_BYDATE, "<Item>"}, | |
249 {N_("/Sort Selection"), NULL, NULL, 0, "<Branch>"}, | |
250 {N_("/Sort Selection/By Title"), NULL, plsort_menu_callback, | |
251 PLAYLISTWIN_SORT_SEL_BYTITLE, "<Item>"}, | |
252 {N_("/Sort Selection/By Filename"), NULL, plsort_menu_callback, | |
253 PLAYLISTWIN_SORT_SEL_BYFILENAME, "<Item>"}, | |
254 {N_("/Sort Selection/By Path + Filename"), NULL, plsort_menu_callback, | |
255 PLAYLISTWIN_SORT_SEL_BYPATH, "<Item>"}, | |
256 {N_("/Sort Selection/By Date"), NULL, plsort_menu_callback, | |
257 PLAYLISTWIN_SORT_SEL_BYDATE, "<Item>"} | |
258 }; | |
259 | |
260 | |
261 static void playlistwin_draw_frame(void); | |
262 | |
263 | |
264 gboolean | |
265 playlistwin_is_shaded(void) | |
266 { | |
267 return cfg.playlist_shaded; | |
268 } | |
269 | |
270 gint | |
271 playlistwin_get_width(void) | |
272 { | |
273 return cfg.playlist_width; | |
274 } | |
275 | |
276 gint | |
277 playlistwin_get_height_unshaded(void) | |
278 { | |
279 gint height = cfg.playlist_height; | |
280 return height; | |
281 } | |
282 | |
283 gint | |
284 playlistwin_get_height_shaded(void) | |
285 { | |
286 return PLAYLISTWIN_SHADED_HEIGHT; | |
287 } | |
288 | |
289 gint | |
290 playlistwin_get_height(void) | |
291 { | |
292 if (playlistwin_is_shaded()) | |
293 return playlistwin_get_height_shaded(); | |
294 else | |
295 return playlistwin_get_height_unshaded(); | |
296 } | |
297 | |
298 void | |
299 playlistwin_get_size(gint * width, gint * height) | |
300 { | |
301 if (width) | |
302 *width = playlistwin_get_width(); | |
303 | |
304 if (height) | |
305 *height = playlistwin_get_height(); | |
306 } | |
307 | |
308 static void | |
309 playlistwin_update_info(void) | |
310 { | |
311 gchar *text, *sel_text, *tot_text; | |
312 gulong selection, total; | |
313 gboolean selection_more, total_more; | |
314 | |
315 playlist_get_total_time(&total, &selection, &total_more, &selection_more); | |
316 | |
317 if (selection > 0 || (selection == 0 && !selection_more)) { | |
318 if (selection > 3600) | |
319 sel_text = | |
320 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", selection / 3600, | |
321 (selection / 60) % 60, selection % 60, | |
322 (selection_more ? "+" : "")); | |
323 else | |
324 sel_text = | |
325 g_strdup_printf("%lu:%-2.2lu%s", selection / 60, | |
326 selection % 60, (selection_more ? "+" : "")); | |
327 } | |
328 else | |
329 sel_text = g_strdup("?"); | |
330 if (total > 0 || (total == 0 && !total_more)) { | |
331 if (total > 3600) | |
332 tot_text = | |
333 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", total / 3600, | |
334 (total / 60) % 60, total % 60, | |
335 total_more ? "+" : ""); | |
336 else | |
337 tot_text = | |
338 g_strdup_printf("%lu:%-2.2lu%s", total / 60, total % 60, | |
339 total_more ? "+" : ""); | |
340 } | |
341 else | |
342 tot_text = g_strdup("?"); | |
343 text = g_strconcat(sel_text, "/", tot_text, NULL); | |
344 textbox_set_text(playlistwin_info, text); | |
345 g_free(text); | |
346 g_free(tot_text); | |
347 g_free(sel_text); | |
348 } | |
349 | |
350 static void | |
351 playlistwin_update_sinfo(void) | |
352 { | |
353 gchar *posstr, *timestr, *title, *info, *dots; | |
354 gint pos, time, max_len; | |
355 | |
356 pos = playlist_get_position(); | |
357 title = playlist_get_songtitle(pos); | |
358 time = playlist_get_songtime(pos); | |
359 | |
360 if (!title) { | |
361 textbox_set_text(playlistwin_sinfo, ""); | |
362 return; | |
363 } | |
364 | |
365 if (cfg.show_numbers_in_pl) | |
366 posstr = g_strdup_printf("%d. ", pos + 1); | |
367 else | |
368 posstr = g_strdup(""); | |
369 | |
370 max_len = (playlistwin_get_width() - 35) / 5 - strlen(posstr); | |
371 | |
372 if (time != -1) { | |
373 timestr = g_strdup_printf(" %d:%-2.2d", time / 60000, | |
374 (time / 1000) % 60); | |
375 max_len -= strlen(timestr); | |
376 } | |
377 else | |
378 timestr = g_strdup(""); | |
379 | |
380 convert_title_text(title); | |
381 | |
382 if (strlen(title) > max_len) { | |
383 max_len -= 3; | |
384 dots = "..."; | |
385 } | |
386 else | |
387 dots = ""; | |
388 | |
389 info = g_strdup_printf("%s%-*.*s%s%s", posstr, max_len, max_len, | |
390 title, dots, timestr); | |
391 g_free(posstr); | |
392 g_free(title); | |
393 g_free(timestr); | |
394 | |
395 textbox_set_text(playlistwin_sinfo, info); | |
396 g_free(info); | |
397 } | |
398 | |
399 gboolean | |
400 playlistwin_item_visible(gint index) | |
401 { | |
402 if (index >= playlistwin_list->pl_first | |
403 && index < | |
404 (playlistwin_list->pl_first + playlistwin_list->pl_num_visible)) | |
405 return TRUE; | |
406 return FALSE; | |
407 } | |
408 | |
409 gint | |
410 playlistwin_get_toprow(void) | |
411 { | |
412 if (playlistwin_list) | |
413 return (playlistwin_list->pl_first); | |
414 return (-1); | |
415 } | |
416 | |
417 void | |
418 playlistwin_set_toprow(gint toprow) | |
419 { | |
420 if (playlistwin_list) | |
421 playlistwin_list->pl_first = toprow; | |
422 playlistwin_update_list(); | |
423 } | |
424 | |
425 void | |
426 playlistwin_update_list(void) | |
427 { | |
428 g_return_if_fail(playlistwin_list != NULL); | |
429 | |
239
ac4c3da7c263
[svn] Don't use widget_draw_quick() in playlistwin_update_list().
nenolod
parents:
238
diff
changeset
|
430 widget_draw(WIDGET(playlistwin_list)); |
ac4c3da7c263
[svn] Don't use widget_draw_quick() in playlistwin_update_list().
nenolod
parents:
238
diff
changeset
|
431 widget_draw(WIDGET(playlistwin_slider)); |
0 | 432 playlistwin_update_info(); |
433 playlistwin_update_sinfo(); | |
434 /* mainwin_update_jtf(); */ | |
435 } | |
436 | |
437 #if 0 | |
438 static void | |
439 playlistwin_redraw_list(void) | |
440 { | |
441 g_return_if_fail(playlistwin_list != NULL); | |
442 | |
443 draw_widget(playlistwin_list); | |
444 draw_widget(playlistwin_slider); | |
445 } | |
446 #endif | |
447 | |
448 static void | |
449 playlistwin_set_mask(void) | |
450 { | |
451 GdkGC *gc; | |
452 GdkColor pattern; | |
453 | |
454 if (playlistwin_mask) | |
455 g_object_unref(playlistwin_mask); | |
456 | |
457 playlistwin_mask = | |
458 gdk_pixmap_new(playlistwin->window, playlistwin_get_width(), | |
459 playlistwin_get_height(), 1); | |
460 gc = gdk_gc_new(playlistwin_mask); | |
461 pattern.pixel = 1; | |
462 gdk_gc_set_foreground(gc, &pattern); | |
463 gdk_draw_rectangle(playlistwin_mask, gc, TRUE, 0, 0, | |
464 playlistwin_get_width(), playlistwin_get_height()); | |
465 gdk_gc_destroy(gc); | |
466 | |
467 gtk_widget_shape_combine_mask(playlistwin, playlistwin_mask, 0, 0); | |
468 } | |
469 | |
470 static void | |
471 playlistwin_set_geometry_hints(gboolean shaded) | |
472 { | |
473 GdkGeometry geometry; | |
474 GdkWindowHints mask; | |
475 | |
476 geometry.min_width = PLAYLISTWIN_MIN_WIDTH; | |
477 geometry.max_width = G_MAXUINT16; | |
478 geometry.base_width = cfg.playlist_width; | |
479 | |
480 geometry.width_inc = PLAYLISTWIN_WIDTH_SNAP; | |
481 geometry.height_inc = PLAYLISTWIN_HEIGHT_SNAP; | |
482 | |
483 if (shaded) { | |
484 geometry.min_height = PLAYLISTWIN_SHADED_HEIGHT; | |
485 geometry.max_height = PLAYLISTWIN_SHADED_HEIGHT; | |
486 geometry.base_height = PLAYLISTWIN_SHADED_HEIGHT; | |
487 } | |
488 else { | |
489 geometry.min_height = PLAYLISTWIN_MIN_HEIGHT; | |
490 geometry.max_height = G_MAXUINT16; | |
491 geometry.base_height = cfg.playlist_height; | |
492 } | |
493 | |
494 mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_RESIZE_INC | | |
495 GDK_HINT_BASE_SIZE; | |
496 | |
497 gtk_window_set_geometry_hints(GTK_WINDOW(playlistwin), | |
498 playlistwin, &geometry, mask); | |
499 } | |
500 | |
501 void | |
502 playlistwin_set_shade(gboolean shaded) | |
503 { | |
504 cfg.playlist_shaded = shaded; | |
505 | |
506 if (shaded) { | |
507 widget_show(WIDGET(playlistwin_sinfo)); | |
508 playlistwin_shade->pb_nx = 128; | |
509 playlistwin_shade->pb_ny = 45; | |
510 playlistwin_shade->pb_px = 150; | |
511 playlistwin_shade->pb_py = 42; | |
512 playlistwin_close->pb_nx = 138; | |
513 playlistwin_close->pb_ny = 45; | |
514 } | |
515 else { | |
516 widget_hide(WIDGET(playlistwin_sinfo)); | |
517 playlistwin_shade->pb_nx = 157; | |
518 playlistwin_shade->pb_ny = 3; | |
519 playlistwin_shade->pb_px = 62; | |
520 playlistwin_shade->pb_py = 42; | |
521 playlistwin_close->pb_nx = 167; | |
522 playlistwin_close->pb_ny = 3; | |
523 } | |
524 | |
525 dock_shade(dock_window_list, GTK_WINDOW(playlistwin), | |
526 playlistwin_get_height()); | |
527 | |
528 playlistwin_set_geometry_hints(cfg.playlist_shaded); | |
529 | |
530 gtk_window_resize(GTK_WINDOW(playlistwin), | |
531 cfg.playlist_width, | |
532 playlistwin_get_height()); | |
533 | |
79
38ddde5b0f13
[svn] Fix #129 by using playlistwin_set_mask() in playlistwin_set_shade()
msameer
parents:
0
diff
changeset
|
534 playlistwin_set_mask(); |
237
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
236
diff
changeset
|
535 |
242 | 536 widget_draw(WIDGET(playlistwin_list)); |
537 widget_draw(WIDGET(playlistwin_slider)); | |
538 | |
0 | 539 draw_playlist_window(TRUE); |
540 } | |
541 | |
542 static void | |
543 playlistwin_set_shade_menu(gboolean shaded) | |
544 { | |
545 GtkWidget *item; | |
546 | |
547 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
548 "/Roll up Playlist Editor"); | |
549 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), shaded); | |
550 | |
551 playlistwin_set_shade(shaded); | |
552 } | |
553 | |
554 void | |
555 playlistwin_shade_toggle(void) | |
556 { | |
557 playlistwin_set_shade_menu(!cfg.playlist_shaded); | |
558 } | |
559 | |
560 static void | |
561 playlistwin_release(GtkWidget * widget, | |
562 GdkEventButton * event, | |
563 gpointer callback_data) | |
564 { | |
565 if (event->button == 3) | |
566 return; | |
567 | |
568 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
569 playlistwin_resizing = FALSE; | |
570 gdk_flush(); | |
571 | |
572 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
573 dock_move_release(GTK_WINDOW(playlistwin)); | |
574 #if 0 | |
575 if (cfg.playlist_transparent) | |
576 playlistwin_update_list(); | |
577 #endif | |
578 } | |
579 else { | |
580 handle_release_cb(playlistwin_wlist, widget, event); | |
581 playlist_popup_destroy(); | |
582 draw_playlist_window(FALSE); | |
583 } | |
584 } | |
585 | |
586 void | |
587 playlistwin_scroll(gint num) | |
588 { | |
589 playlistwin_list->pl_first += num; | |
590 playlistwin_update_list(); | |
591 } | |
592 | |
593 void | |
594 playlistwin_scroll_up_pushed(void) | |
595 { | |
596 playlistwin_list->pl_first -= 3; | |
597 playlistwin_update_list(); | |
598 } | |
599 | |
600 void | |
601 playlistwin_scroll_down_pushed(void) | |
602 { | |
603 playlistwin_list->pl_first += 3; | |
604 playlistwin_update_list(); | |
605 } | |
606 | |
607 static void | |
608 playlistwin_select_all(void) | |
609 { | |
610 playlist_select_all(TRUE); | |
611 playlistwin_list->pl_prev_selected = 0; | |
612 playlistwin_list->pl_prev_min = 0; | |
613 playlistwin_list->pl_prev_max = playlist_get_length() - 1; | |
614 playlistwin_update_list(); | |
615 } | |
616 | |
617 static void | |
618 playlistwin_select_none(void) | |
619 { | |
620 playlist_select_all(FALSE); | |
621 playlistwin_list->pl_prev_selected = -1; | |
622 playlistwin_list->pl_prev_min = -1; | |
623 playlistwin_update_list(); | |
624 } | |
625 | |
626 static void | |
627 playlistwin_inverse_selection(void) | |
628 { | |
629 playlist_select_invert_all(); | |
630 playlistwin_list->pl_prev_selected = -1; | |
631 playlistwin_list->pl_prev_min = -1; | |
632 playlistwin_update_list(); | |
633 } | |
634 | |
635 static void | |
636 playlistwin_resize(gint width, gint height) | |
637 { | |
638 gboolean redraw; | |
639 | |
640 g_return_if_fail(width > 0 && height > 0); | |
641 | |
642 cfg.playlist_width = width; | |
643 | |
644 if (!cfg.playlist_shaded) | |
645 cfg.playlist_height = height; | |
646 else | |
647 height = cfg.playlist_height; | |
648 | |
649 /* FIXME: why the fsck are we doing this manually? */ | |
650 /* adjust widget positions and sizes */ | |
651 | |
652 widget_resize(WIDGET(playlistwin_list), width - 31, height - 58); | |
653 | |
654 widget_move(WIDGET(playlistwin_slider), width - 15, 20); | |
655 widget_resize(WIDGET(playlistwin_slider), 8, height - 58); | |
656 | |
657 widget_resize(WIDGET(playlistwin_sinfo), width - 35, 14); | |
658 playlistwin_update_sinfo(); | |
659 | |
660 widget_move(WIDGET(playlistwin_shade), width - 21, 3); | |
661 widget_move(WIDGET(playlistwin_close), width - 11, 3); | |
662 widget_move(WIDGET(playlistwin_time_min), width - 82, height - 15); | |
663 widget_move(WIDGET(playlistwin_time_sec), width - 64, height - 15); | |
664 widget_move(WIDGET(playlistwin_info), width - 143, height - 28); | |
665 widget_move(WIDGET(playlistwin_srew), width - 144, height - 16); | |
666 widget_move(WIDGET(playlistwin_splay), width - 138, height - 16); | |
667 widget_move(WIDGET(playlistwin_spause), width - 128, height - 16); | |
668 widget_move(WIDGET(playlistwin_sstop), width - 118, height - 16); | |
669 widget_move(WIDGET(playlistwin_sfwd), width - 109, height - 16); | |
670 widget_move(WIDGET(playlistwin_seject), width - 100, height - 16); | |
671 widget_move(WIDGET(playlistwin_sscroll_up), width - 14, height - 35); | |
672 widget_move(WIDGET(playlistwin_sscroll_down), width - 14, height - 30); | |
673 | |
674 /* decide if we should show the mini visualizer */ | |
675 if (playlistwin_get_width() >= 350) { | |
676 widget_move(WIDGET(playlistwin_vis), width - 223, height - 26); | |
677 | |
678 if (playlistwin_vis_enabled) | |
679 widget_show(WIDGET(playlistwin_vis)); | |
680 } | |
681 else | |
682 widget_hide(WIDGET(playlistwin_vis)); | |
683 | |
684 g_object_unref(playlistwin_bg); | |
685 playlistwin_bg = gdk_pixmap_new(playlistwin->window, width, height, -1); | |
686 playlistwin_set_mask(); | |
687 | |
688 widget_list_lock(playlistwin_wlist); | |
689 | |
690 widget_list_change_pixmap(playlistwin_wlist, playlistwin_bg); | |
691 playlistwin_draw_frame(); | |
692 widget_list_draw(playlistwin_wlist, &redraw, TRUE); | |
693 widget_list_clear_redraw(playlistwin_wlist); | |
694 | |
695 widget_list_unlock(playlistwin_wlist); | |
696 | |
697 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
698 gdk_window_clear(playlistwin->window); | |
699 } | |
700 | |
701 | |
702 | |
703 static void | |
704 playlistwin_motion(GtkWidget * widget, | |
705 GdkEventMotion * event, | |
706 gpointer callback_data) | |
707 { | |
708 XEvent ev; | |
709 | |
710 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
711 dock_move_motion(GTK_WINDOW(playlistwin), event); | |
712 } | |
713 else { | |
714 handle_motion_cb(playlistwin_wlist, widget, event); | |
715 draw_playlist_window(FALSE); | |
716 } | |
717 gdk_flush(); | |
718 while (XCheckMaskEvent(GDK_DISPLAY(), ButtonMotionMask, &ev)); | |
719 } | |
720 | |
721 static void | |
722 playlistwin_show_filebrowser(void) | |
723 { | |
724 util_run_filebrowser(NO_PLAY_BUTTON); | |
725 } | |
726 | |
727 #if 0 | |
728 static void | |
729 playlistwin_add_dir_handler(const gchar * dir) | |
730 { | |
731 g_free(cfg.filesel_path); | |
732 cfg.filesel_path = g_strdup(dir); | |
733 playlist_add_dir(dir); | |
734 } | |
735 #endif | |
736 | |
737 static void | |
738 playlistwin_fileinfo(void) | |
739 { | |
740 /* Show the first selected file, or the current file if nothing is | |
741 * selected */ | |
742 GList *list = playlist_get_selected(); | |
743 if (list) { | |
744 playlist_fileinfo(GPOINTER_TO_INT(list->data)); | |
745 g_list_free(list); | |
746 } | |
747 else | |
748 playlist_fileinfo_current(); | |
749 } | |
750 | |
751 static void | |
752 menu_set_item_sensitive(GtkItemFactory * item_factory, | |
753 const gchar * path, | |
754 gboolean sensitive) | |
755 { | |
756 GtkWidget *item = gtk_item_factory_get_widget(item_factory, path); | |
757 gtk_widget_set_sensitive(item, sensitive); | |
758 } | |
759 | |
760 /* FIXME: broken */ | |
761 static void | |
762 playlistwin_set_sensitive_sortmenu(void) | |
763 { | |
764 gboolean set = playlist_get_num_selected() > 1; | |
765 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Title", set); | |
766 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Filename", set); | |
767 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Path + Filename", set); | |
768 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Date", set); | |
769 } | |
770 | |
771 static void | |
772 show_playlist_save_error(GtkWindow * parent, | |
773 const gchar * filename) | |
774 { | |
775 GtkWidget *dialog; | |
776 | |
777 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
778 g_return_if_fail(filename != NULL); | |
779 | |
780 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
781 GTK_DIALOG_DESTROY_WITH_PARENT, | |
782 GTK_MESSAGE_ERROR, | |
783 GTK_BUTTONS_OK, | |
784 _("Error writing playlist \"%s\": %s"), | |
785 filename, strerror(errno)); | |
786 | |
787 gtk_dialog_run(GTK_DIALOG(dialog)); | |
788 gtk_widget_destroy(dialog); | |
789 } | |
790 | |
791 static gboolean | |
792 show_playlist_overwrite_prompt(GtkWindow * parent, | |
793 const gchar * filename) | |
794 { | |
795 GtkWidget *dialog; | |
796 gint result; | |
797 | |
798 g_return_val_if_fail(GTK_IS_WINDOW(parent), FALSE); | |
799 g_return_val_if_fail(filename != NULL, FALSE); | |
800 | |
801 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
802 GTK_DIALOG_DESTROY_WITH_PARENT, | |
803 GTK_MESSAGE_QUESTION, | |
804 GTK_BUTTONS_YES_NO, | |
805 _("%s already exist. Continue?"), | |
806 filename); | |
807 | |
808 result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
809 gtk_widget_destroy(dialog); | |
810 | |
811 return (result == GTK_RESPONSE_YES); | |
812 } | |
813 | |
814 static void | |
815 show_playlist_save_format_error(GtkWindow * parent, | |
816 const gchar * filename) | |
817 { | |
818 const gchar *markup = | |
819 N_("<b><big>Unable to save playlist.</big></b>\n\n" | |
820 "Unknown file type for '%s'.\n"); | |
821 | |
822 GtkWidget *dialog; | |
823 | |
824 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
825 g_return_if_fail(filename != NULL); | |
826 | |
827 dialog = | |
828 gtk_message_dialog_new_with_markup(GTK_WINDOW(parent), | |
829 GTK_DIALOG_DESTROY_WITH_PARENT, | |
830 GTK_MESSAGE_ERROR, | |
831 GTK_BUTTONS_OK, | |
832 _(markup), | |
833 filename); | |
834 gtk_dialog_run(GTK_DIALOG(dialog)); | |
835 gtk_widget_destroy(dialog); | |
836 } | |
837 | |
838 static void | |
839 playlistwin_save_playlist(const gchar * filename) | |
840 { | |
841 PlaylistFormat format; | |
842 | |
843 format = playlist_format_get_from_name(filename); | |
844 if (format == PLAYLIST_FORMAT_UNKNOWN) { | |
845 show_playlist_save_format_error(GTK_WINDOW(playlistwin), filename); | |
846 return; | |
847 } | |
848 | |
849 str_replace_in(&cfg.playlist_path, g_path_get_dirname(filename)); | |
850 | |
851 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
852 if (!show_playlist_overwrite_prompt(GTK_WINDOW(playlistwin), filename)) | |
853 return; | |
854 | |
855 if (!playlist_save(filename, format)) | |
856 show_playlist_save_error(GTK_WINDOW(playlistwin), filename); | |
857 } | |
858 | |
859 #if 0 | |
860 static void | |
861 playlistwin_save_current(void) | |
862 { | |
863 const gchar *filename; | |
864 | |
865 if (!(filename = playlist_get_current_name())) | |
866 return; | |
867 | |
868 playlistwin_save_playlist(filename); | |
869 } | |
870 #endif | |
871 | |
872 static void | |
873 playlistwin_load_playlist(const gchar * filename) | |
874 { | |
875 g_return_if_fail(filename != NULL); | |
876 | |
877 str_replace_in(&cfg.playlist_path, g_strdup(filename)); | |
878 | |
879 playlist_clear(); | |
880 mainwin_clear_song_info(); | |
881 mainwin_set_info_text(); | |
882 | |
883 playlist_load(filename); | |
884 playlist_set_current_name(filename); | |
885 } | |
886 | |
887 static gchar * | |
888 playlist_file_selection(const gchar * title, | |
889 gboolean save, | |
890 const gchar * default_filename) | |
891 { | |
892 GtkWidget *dialog, *button; | |
893 gchar *filename; | |
894 | |
895 g_return_val_if_fail(title != NULL, NULL); | |
896 | |
897 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
898 save ? GTK_FILE_CHOOSER_ACTION_SAVE : | |
899 GTK_FILE_CHOOSER_ACTION_OPEN, NULL); | |
900 if (default_filename) | |
901 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
902 default_filename); | |
903 | |
904 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
905 GTK_RESPONSE_REJECT); | |
906 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
907 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
908 | |
909 button = gtk_dialog_add_button(GTK_DIALOG(dialog), | |
910 save ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
911 GTK_RESPONSE_ACCEPT); | |
912 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
913 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
914 | |
915 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
916 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
917 else | |
918 filename = NULL; | |
919 | |
920 gtk_widget_destroy(dialog); | |
921 | |
922 return filename; | |
923 } | |
924 | |
925 void | |
926 playlistwin_select_playlist_to_load(const gchar * default_filename) | |
927 { | |
928 gchar *filename = | |
929 playlist_file_selection(_("Load Playlist"), FALSE, default_filename); | |
930 | |
931 if (filename) { | |
932 playlistwin_load_playlist(filename); | |
933 g_free(filename); | |
934 } | |
935 } | |
936 | |
937 static void | |
938 playlistwin_select_playlist_to_save(const gchar * default_filename) | |
939 { | |
940 gchar *filename = | |
941 playlist_file_selection(_("Save Playlist"), TRUE, default_filename); | |
942 | |
943 if (filename) { | |
944 /* Default to M3U if no filename has extension */ | |
945 | |
946 /* NOTE: This doesn't work correctly for hidden files | |
947 - descender */ | |
948 if (!strchr(filename, '.')) { | |
949 gchar *tmpstr = filename; | |
950 filename = g_strconcat(filename, ".m3u", NULL); | |
951 g_free(tmpstr); | |
952 } | |
953 | |
954 playlistwin_save_playlist(filename); | |
955 g_free(filename); | |
956 } | |
957 } | |
958 | |
959 static void | |
960 playlistwin_run_dirbrowser(void) | |
961 { | |
962 mainwin_run_dirbrowser(); | |
963 } | |
964 | |
965 static gboolean | |
966 inside_sensitive_widgets(gint x, gint y) | |
967 { | |
968 return (widget_contains(WIDGET(playlistwin_list), x, y) || | |
969 widget_contains(WIDGET(playlistwin_slider), x, y) || | |
970 widget_contains(WIDGET(playlistwin_close), x, y) || | |
971 widget_contains(WIDGET(playlistwin_shade), x, y) || | |
972 widget_contains(WIDGET(playlistwin_time_min), x, y) || | |
973 widget_contains(WIDGET(playlistwin_time_sec), x, y) || | |
974 widget_contains(WIDGET(playlistwin_info), x, y) || | |
975 widget_contains(WIDGET(playlistwin_vis), x, y) || | |
976 widget_contains(WIDGET(playlistwin_srew), x, y) || | |
977 widget_contains(WIDGET(playlistwin_splay), x, y) || | |
978 widget_contains(WIDGET(playlistwin_spause), x, y) || | |
979 widget_contains(WIDGET(playlistwin_sstop), x, y) || | |
980 widget_contains(WIDGET(playlistwin_sfwd), x, y) || | |
981 widget_contains(WIDGET(playlistwin_seject), x, y) || | |
982 widget_contains(WIDGET(playlistwin_sscroll_up), x, y) || | |
983 widget_contains(WIDGET(playlistwin_sscroll_down), x, y)); | |
984 } | |
985 | |
986 #define REGION_L(x1,x2,y1,y2) \ | |
987 (event->x >= (x1) && event->x < (x2) && \ | |
988 event->y >= cfg.playlist_height - (y1) && \ | |
989 event->y < cfg.playlist_height - (y2)) | |
990 | |
991 #define REGION_R(x1,x2,y1,y2) \ | |
992 (event->x >= playlistwin_get_width() - (x1) && \ | |
993 event->x < playlistwin_get_width() - (x2) && \ | |
994 event->y >= cfg.playlist_height - (y1) && \ | |
995 event->y < cfg.playlist_height - (y2)) | |
996 | |
997 static void | |
998 playlistwin_scrolled(GtkWidget * widget, | |
999 GdkEventScroll * event, | |
1000 gpointer callback_data) | |
1001 { | |
1002 | |
1003 if (event->direction == GDK_SCROLL_DOWN) | |
1004 playlistwin_scroll(cfg.scroll_pl_by); | |
1005 | |
1006 if (event->direction == GDK_SCROLL_UP) | |
1007 playlistwin_scroll(-cfg.scroll_pl_by); | |
1008 | |
1009 } | |
1010 | |
1011 | |
1012 | |
1013 | |
1014 static gboolean | |
1015 playlistwin_press(GtkWidget * widget, | |
1016 GdkEventButton * event, | |
1017 gpointer callback_data) | |
1018 { | |
1019 gboolean grab = TRUE; | |
1020 gint xpos, ypos; | |
1021 GtkWidget *_menu; | |
1022 GtkRequisition req; | |
1023 | |
1024 gtk_window_get_position(GTK_WINDOW(playlistwin), &xpos, &ypos); | |
1025 | |
1026 if (event->button == 1 && !cfg.show_wm_decorations && | |
1027 ((!cfg.playlist_shaded && | |
1028 event->x > playlistwin_get_width() - 20 && | |
1029 event->y > cfg.playlist_height - 20) || | |
1030 (cfg.playlist_shaded && | |
1031 event->x >= playlistwin_get_width() - 31 && | |
1032 event->x < playlistwin_get_width() - 22))) { | |
1033 | |
1034 /* NOTE: Workaround for bug #214 */ | |
1035 if (event->type != GDK_2BUTTON_PRESS && | |
1036 event->type != GDK_3BUTTON_PRESS) { | |
1037 /* resize area */ | |
1038 playlistwin_resizing = TRUE; | |
1039 gtk_window_begin_resize_drag(GTK_WINDOW(widget), | |
1040 GDK_WINDOW_EDGE_SOUTH_EAST, | |
1041 event->button, | |
1042 event->x + xpos, event->y + ypos, | |
1043 event->time); | |
1044 } | |
1045 grab = FALSE; | |
1046 } | |
1047 else if (event->button == 1 && REGION_L(12, 37, 29, 11)) { | |
1048 /* ADD button menu */ | |
1049 | |
1050 _menu = GTK_WIDGET(pladd_menu->widget); | |
1051 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1052 gtk_widget_size_request(_menu, &req); | |
1053 gtk_item_factory_popup_with_data(pladd_menu, | |
1054 NULL, NULL, | |
1055 xpos+12, | |
1056 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1057 grab = FALSE; | |
1058 } | |
1059 else if (event->button == 1 && REGION_L(41, 66, 29, 11)) { | |
1060 /* SUB button menu */ | |
1061 _menu = GTK_WIDGET(pldel_menu->widget); | |
1062 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1063 gtk_widget_size_request(_menu, &req); | |
1064 gtk_item_factory_popup_with_data(pldel_menu, | |
1065 NULL, NULL, | |
1066 xpos+40, | |
1067 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1068 grab = FALSE; | |
1069 } | |
1070 else if (event->button == 1 && REGION_L(70, 95, 29, 11)) { | |
1071 /* SEL button menu */ | |
1072 _menu = GTK_WIDGET(plsel_menu->widget); | |
1073 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1074 gtk_widget_size_request(_menu, &req); | |
1075 gtk_item_factory_popup_with_data(plsel_menu, | |
1076 NULL, NULL, | |
1077 xpos+68, | |
1078 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1079 | |
1080 grab = FALSE; | |
1081 } | |
1082 else if (event->button == 1 && REGION_L(99, 124, 29, 11)) { | |
1083 /* MISC button menu */ | |
1084 _menu = GTK_WIDGET(plsort_menu->widget); | |
1085 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1086 gtk_widget_size_request(_menu, &req); | |
1087 gtk_item_factory_popup_with_data(plsort_menu, | |
1088 NULL, NULL, | |
1089 xpos+100, | |
1090 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1091 grab = FALSE; | |
1092 } | |
1093 else if (event->button == 1 && REGION_R(46, 23, 29, 11)) { | |
1094 /* LIST button menu */ | |
1095 _menu = GTK_WIDGET(pllist_menu->widget); | |
1096 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1097 gtk_widget_size_request(_menu, &req); | |
1098 gtk_item_factory_popup_with_data(pllist_menu, | |
1099 NULL, NULL, | |
1100 xpos + playlistwin_get_width() - req.width - 12, | |
1101 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1102 grab = FALSE; | |
1103 } | |
1104 else if (event->button == 1 && REGION_R(82, 54, 15, 9)) { | |
1105 if (cfg.timer_mode == TIMER_ELAPSED) | |
1106 cfg.timer_mode = TIMER_REMAINING; | |
1107 else | |
1108 cfg.timer_mode = TIMER_ELAPSED; | |
1109 } | |
1110 else if (event->button == 2 && (event->type == GDK_BUTTON_PRESS) && | |
1111 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1112 gtk_selection_convert(widget, GDK_SELECTION_PRIMARY, | |
1113 GDK_TARGET_STRING, event->time); | |
1114 } | |
1115 else if (playlistwin_get_width() >= 350 && REGION_R(223, 151, 26, 10)) { | |
1116 if (event->button == 1) { | |
1117 cfg.vis_type++; | |
1118 if (cfg.vis_type > VIS_OFF) | |
1119 cfg.vis_type = VIS_ANALYZER; | |
1120 mainwin_vis_set_type(cfg.vis_type); | |
1121 } | |
1122 else if (event->button == 3) { | |
1123 gint mx, my; | |
1124 GdkModifierType modmask; | |
1125 | |
1126 gdk_window_get_pointer(NULL, &mx, &my, &modmask); | |
1127 util_item_factory_popup(mainwin_vis_menu, mx, my, 3, event->time); | |
1128 grab = FALSE; | |
1129 } | |
1130 } | |
1131 else if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
1132 !inside_sensitive_widgets(event->x, event->y) && event->y < 14) { | |
1133 gdk_window_raise(playlistwin->window); | |
1134 dock_move_press(dock_window_list, GTK_WINDOW(playlistwin), event, | |
1135 FALSE); | |
1136 } | |
1137 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && | |
1138 !inside_sensitive_widgets(event->x, event->y) | |
1139 && event->y < 14) { | |
1140 /* double click on title bar */ | |
1141 playlistwin_shade_toggle(); | |
1142 if (dock_is_moving(GTK_WINDOW(playlistwin))) | |
1143 dock_move_release(GTK_WINDOW(playlistwin)); | |
1144 return TRUE; | |
1145 } | |
1146 else if (event->button == 3 && | |
1147 !(widget_contains(WIDGET(playlistwin_list), event->x, event->y) || | |
1148 (event->y >= cfg.playlist_height - 29 && | |
1149 event->y < cfg.playlist_height - 11 && | |
1150 ((event->x >= 12 && event->x < 37) || | |
1151 (event->x >= 41 && event->x < 66) || | |
1152 (event->x >= 70 && event->x < 95) || | |
1153 (event->x >= 99 && event->x < 124) || | |
1154 (event->x >= playlistwin_get_width() - 46 && | |
1155 event->x < playlistwin_get_width() - 23))))) { | |
1156 /* | |
1157 * Pop up the main menu a few pixels down to avoid | |
1158 * anything to be selected initially. | |
1159 */ | |
1160 util_item_factory_popup(mainwin_general_menu, event->x_root, | |
1161 event->y_root + 2, 3, event->time); | |
1162 grab = FALSE; | |
1163 } | |
1164 else if (event->button == 3 && | |
1165 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1166 /* popup menu */ | |
1167 playlistwin_set_sensitive_sortmenu(); | |
1168 gtk_item_factory_popup(playlistwin_popup_menu, | |
1169 event->x_root, event->y_root + 5, | |
1170 3, event->time); | |
1171 grab = FALSE; | |
1172 } | |
1173 else { | |
1174 handle_press_cb(playlistwin_wlist, widget, event); | |
1175 draw_playlist_window(FALSE); | |
1176 } | |
1177 | |
1178 if (grab) | |
1179 gdk_pointer_grab(playlistwin->window, FALSE, | |
1180 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | | |
1181 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1182 GDK_BUTTON1_MOTION_MASK, NULL, NULL, | |
1183 GDK_CURRENT_TIME); | |
1184 | |
1185 return FALSE; | |
1186 } | |
1187 | |
1188 static gboolean | |
1189 playlistwin_focus_in(GtkWidget * widget, GdkEvent * event, gpointer data) | |
1190 { | |
1191 playlistwin_close->pb_allow_draw = TRUE; | |
1192 playlistwin_shade->pb_allow_draw = TRUE; | |
1193 draw_playlist_window(TRUE); | |
1194 return FALSE; | |
1195 } | |
1196 | |
1197 static gboolean | |
1198 playlistwin_focus_out(GtkWidget * widget, | |
1199 GdkEventButton * event, gpointer data) | |
1200 { | |
1201 playlistwin_close->pb_allow_draw = FALSE; | |
1202 playlistwin_shade->pb_allow_draw = FALSE; | |
1203 draw_playlist_window(TRUE); | |
1204 return FALSE; | |
1205 } | |
1206 | |
1207 static gboolean | |
1208 playlistwin_configure(GtkWidget * window, | |
1209 GdkEventConfigure * event, gpointer data) | |
1210 { | |
1211 if (!GTK_WIDGET_VISIBLE(window)) | |
1212 return FALSE; | |
1213 | |
1214 cfg.playlist_x = event->x; | |
1215 cfg.playlist_y = event->y; | |
1216 | |
1217 if (playlistwin_resizing) { | |
1218 if (event->width != playlistwin_get_width() || | |
1219 event->height != playlistwin_get_height()) | |
1220 playlistwin_resize(event->width, event->height); | |
1221 } | |
1222 return TRUE; | |
1223 } | |
1224 | |
1225 void | |
1226 playlistwin_set_back_pixmap(void) | |
1227 { | |
1228 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
1229 gdk_window_clear(playlistwin->window); | |
1230 } | |
1231 | |
1232 static gboolean | |
1233 playlistwin_delete(GtkWidget * w, gpointer data) | |
1234 { | |
1235 playlistwin_hide(); | |
1236 return TRUE; | |
1237 } | |
1238 | |
1239 static void | |
1240 playlistwin_keypress_up_down_handler(PlayList_List * pl, | |
1241 gboolean up, guint state) | |
1242 { | |
1243 if ((state & GDK_MOD1_MASK) && (state & GDK_SHIFT_MASK)) | |
1244 return; | |
1245 if (!(state & GDK_MOD1_MASK)) | |
1246 playlist_select_all(FALSE); | |
1247 | |
1248 if (pl->pl_prev_selected == -1 || | |
1249 (!playlistwin_item_visible(pl->pl_prev_selected) && | |
1250 !(state & GDK_SHIFT_MASK && pl->pl_prev_min != -1))) { | |
1251 pl->pl_prev_selected = pl->pl_first; | |
1252 } | |
1253 else if (state & GDK_SHIFT_MASK) { | |
1254 if (pl->pl_prev_min == -1) { | |
1255 pl->pl_prev_max = pl->pl_prev_selected; | |
1256 pl->pl_prev_min = pl->pl_prev_selected; | |
1257 } | |
1258 pl->pl_prev_max += (up ? -1 : 1); | |
1259 pl->pl_prev_max = | |
1260 CLAMP(pl->pl_prev_max, 0, playlist_get_length() - 1); | |
1261 | |
1262 pl->pl_first = MIN(pl->pl_first, pl->pl_prev_max); | |
1263 pl->pl_first = MAX(pl->pl_first, pl->pl_prev_max - | |
1264 pl->pl_num_visible + 1); | |
1265 playlist_select_range(pl->pl_prev_min, pl->pl_prev_max, TRUE); | |
1266 return; | |
1267 } | |
1268 else if (state & GDK_MOD1_MASK) { | |
1269 if (up) | |
1270 playlist_list_move_up(pl); | |
1271 else | |
1272 playlist_list_move_down(pl); | |
1273 if (pl->pl_prev_min < pl->pl_first) | |
1274 pl->pl_first = pl->pl_prev_min; | |
1275 else if (pl->pl_prev_max >= (pl->pl_first + pl->pl_num_visible)) | |
1276 pl->pl_first = pl->pl_prev_max - pl->pl_num_visible + 1; | |
1277 return; | |
1278 } | |
1279 else if (up) | |
1280 pl->pl_prev_selected--; | |
1281 else | |
1282 pl->pl_prev_selected++; | |
1283 | |
1284 pl->pl_prev_selected = | |
1285 CLAMP(pl->pl_prev_selected, 0, playlist_get_length() - 1); | |
1286 | |
1287 if (pl->pl_prev_selected < pl->pl_first) | |
1288 pl->pl_first--; | |
1289 else if (pl->pl_prev_selected >= (pl->pl_first + pl->pl_num_visible)) | |
1290 pl->pl_first++; | |
1291 | |
1292 playlist_select_range(pl->pl_prev_selected, pl->pl_prev_selected, TRUE); | |
1293 pl->pl_prev_min = -1; | |
1294 | |
1295 } | |
1296 | |
1297 /* FIXME: Handle the keys through menu */ | |
1298 | |
1299 static gboolean | |
1300 playlistwin_keypress(GtkWidget * w, GdkEventKey * event, gpointer data) | |
1301 { | |
1302 guint keyval; | |
1303 gboolean refresh = FALSE; | |
1304 | |
1305 if (cfg.playlist_shaded) | |
1306 return FALSE; | |
1307 | |
1308 switch (keyval = event->keyval) { | |
1309 case GDK_KP_Up: | |
1310 case GDK_KP_Down: | |
1311 case GDK_Up: | |
1312 case GDK_Down: | |
1313 playlistwin_keypress_up_down_handler(playlistwin_list, | |
1314 keyval == GDK_Up | |
1315 || keyval == GDK_KP_Up, | |
1316 event->state); | |
1317 refresh = TRUE; | |
1318 break; | |
1319 case GDK_Page_Up: | |
1320 playlistwin_scroll(-playlistwin_list->pl_num_visible); | |
1321 refresh = TRUE; | |
1322 break; | |
1323 case GDK_Page_Down: | |
1324 playlistwin_scroll(playlistwin_list->pl_num_visible); | |
1325 refresh = TRUE; | |
1326 break; | |
1327 case GDK_Home: | |
1328 playlistwin_list->pl_first = 0; | |
1329 refresh = TRUE; | |
1330 break; | |
1331 case GDK_End: | |
1332 playlistwin_list->pl_first = | |
1333 playlist_get_length() - playlistwin_list->pl_num_visible; | |
1334 refresh = TRUE; | |
1335 break; | |
1336 case GDK_Return: | |
1337 if (playlistwin_list->pl_prev_selected > -1 | |
1338 && playlistwin_item_visible(playlistwin_list->pl_prev_selected)) { | |
1339 playlist_set_position(playlistwin_list->pl_prev_selected); | |
1340 if (!bmp_playback_get_playing()) | |
1341 bmp_playback_initiate(); | |
1342 } | |
1343 break; | |
1344 case GDK_3: | |
1345 if (event->state & GDK_CONTROL_MASK) | |
1346 playlistwin_fileinfo(); | |
1347 break; | |
1348 case GDK_Delete: | |
1349 if (event->state & GDK_CONTROL_MASK) | |
1350 playlist_delete(TRUE); | |
1351 else | |
1352 playlist_delete(FALSE); | |
1353 break; | |
1354 case GDK_Insert: | |
1355 if (event->state & GDK_SHIFT_MASK) | |
1356 playlistwin_run_dirbrowser(); | |
1357 else if (event->state & GDK_MOD1_MASK) | |
1358 mainwin_show_add_url_window(); | |
1359 else | |
1360 playlistwin_show_filebrowser(); | |
1361 break; | |
226
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1362 case GDK_Left: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1363 case GDK_KP_Left: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1364 case GDK_KP_7: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1365 if (playlist_get_current_length() != -1) |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1366 bmp_playback_seek(CLAMP |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1367 (bmp_playback_get_time() - 5000, 0, |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1368 playlist_get_current_length()) / 1000); |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1369 break; |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1370 case GDK_Right: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1371 case GDK_KP_Right: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1372 case GDK_KP_9: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1373 if (playlist_get_current_length() != -1) |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1374 bmp_playback_seek(CLAMP |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1375 (bmp_playback_get_time() + 5000, 0, |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1376 playlist_get_current_length()) / 1000); |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1377 break; |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1378 |
0 | 1379 case GDK_Escape: |
1380 mainwin_minimize_cb(); | |
1381 break; | |
1382 default: | |
1383 return FALSE; | |
1384 } | |
1385 | |
1386 if (refresh) | |
1387 playlistwin_update_list(); | |
1388 | |
1389 return TRUE; | |
1390 } | |
1391 | |
1392 static void | |
1393 playlistwin_draw_frame(void) | |
1394 { | |
1395 gboolean focus = | |
1396 gtk_window_has_toplevel_focus(GTK_WINDOW(playlistwin)) || | |
1397 !cfg.dim_titlebar; | |
1398 | |
1399 if (cfg.playlist_shaded) { | |
1400 skin_draw_playlistwin_shaded(bmp_active_skin, | |
1401 playlistwin_bg, playlistwin_gc, | |
1402 playlistwin_get_width(), focus); | |
1403 } | |
1404 else { | |
1405 skin_draw_playlistwin_frame(bmp_active_skin, | |
1406 playlistwin_bg, playlistwin_gc, | |
1407 playlistwin_get_width(), | |
1408 cfg.playlist_height, focus); | |
1409 } | |
1410 } | |
1411 | |
1412 void | |
1413 draw_playlist_window(gboolean force) | |
1414 { | |
1415 gboolean redraw; | |
1416 GList *wl; | |
1417 Widget *w; | |
1418 | |
1419 if (force) | |
1420 playlistwin_draw_frame(); | |
1421 | |
1422 widget_list_lock(playlistwin_wlist); | |
1423 widget_list_draw(playlistwin_wlist, &redraw, force); | |
1424 | |
1425 if (redraw || force) { | |
1426 if (force) { | |
1427 gdk_window_clear(playlistwin->window); | |
1428 } | |
1429 else { | |
1430 for (wl = playlistwin_wlist; wl; wl = g_list_next(wl)) { | |
1431 w = WIDGET(wl->data); | |
1432 if (w->redraw && w->visible) { | |
1433 gdk_window_clear_area(playlistwin->window, w->x, w->y, | |
1434 w->width, w->height); | |
1435 w->redraw = FALSE; | |
1436 } | |
1437 } | |
1438 } | |
1439 | |
1440 gdk_flush(); | |
1441 } | |
1442 | |
1443 widget_list_unlock(playlistwin_wlist); | |
1444 } | |
1445 | |
1446 | |
1447 void | |
1448 playlistwin_hide_timer(void) | |
1449 { | |
1450 textbox_set_text(playlistwin_time_min, " "); | |
1451 textbox_set_text(playlistwin_time_sec, " "); | |
1452 } | |
1453 | |
1454 void | |
1455 playlistwin_vis_enable(void) | |
1456 { | |
1457 playlistwin_vis_enabled = TRUE; | |
1458 | |
1459 if (playlistwin_get_width() >= 350) | |
1460 widget_show(WIDGET(playlistwin_vis)); | |
1461 } | |
1462 | |
1463 void | |
1464 playlistwin_vis_disable(void) | |
1465 { | |
1466 playlistwin_vis_enabled = FALSE; | |
1467 widget_hide(WIDGET(playlistwin_vis)); | |
1468 draw_playlist_window(TRUE); | |
1469 } | |
1470 | |
1471 void | |
1472 playlistwin_set_time(gint time, gint length, TimerMode mode) | |
1473 { | |
1474 gchar *text, sign; | |
1475 | |
1476 if (mode == TIMER_REMAINING && length != -1) { | |
1477 time = length - time; | |
1478 sign = '-'; | |
1479 } | |
1480 else | |
1481 sign = ' '; | |
1482 | |
1483 time /= 1000; | |
1484 | |
1485 if (time < 0) | |
1486 time = 0; | |
1487 if (time > 99 * 60) | |
1488 time /= 60; | |
1489 | |
1490 text = g_strdup_printf("%c%-2.2d", sign, time / 60); | |
1491 textbox_set_text(playlistwin_time_min, text); | |
1492 g_free(text); | |
1493 | |
1494 text = g_strdup_printf("%-2.2d", time % 60); | |
1495 textbox_set_text(playlistwin_time_sec, text); | |
1496 g_free(text); | |
1497 } | |
1498 | |
1499 static void | |
1500 playlistwin_drag_motion(GtkWidget * widget, | |
1501 GdkDragContext * context, | |
1502 gint x, gint y, | |
1503 GtkSelectionData * selection_data, | |
1504 guint info, guint time, gpointer user_data) | |
1505 { | |
1506 playlistwin_list->pl_drag_motion = TRUE; | |
1507 playlistwin_list->drag_motion_x = x; | |
1508 playlistwin_list->drag_motion_y = y; | |
1509 playlistwin_update_list(); | |
1510 playlistwin_hint_flag = TRUE; | |
1511 } | |
1512 | |
1513 static void | |
1514 playlistwin_drag_end(GtkWidget * widget, | |
1515 GdkDragContext * context, gpointer user_data) | |
1516 { | |
1517 playlistwin_list->pl_drag_motion = FALSE; | |
1518 playlistwin_hint_flag = FALSE; | |
1519 playlistwin_update_list(); | |
1520 } | |
1521 | |
1522 static void | |
1523 playlistwin_drag_data_received(GtkWidget * widget, | |
1524 GdkDragContext * context, | |
1525 gint x, gint y, | |
1526 GtkSelectionData * | |
1527 selection_data, guint info, | |
1528 guint time, gpointer user_data) | |
1529 { | |
1530 guint pos; | |
1531 | |
1532 g_return_if_fail(selection_data != NULL); | |
1533 | |
1534 if (!selection_data->data) { | |
1535 g_message("Received no DND data!"); | |
1536 return; | |
1537 } | |
1538 | |
1539 if (widget_contains(WIDGET(playlistwin_list), x, y)) { | |
1540 pos = (y - WIDGET(playlistwin_list)->y) / | |
1541 playlistwin_list->pl_fheight + playlistwin_list->pl_first; | |
1542 | |
1543 pos = MIN(pos, playlist_get_length()); | |
1544 playlist_ins_url((gchar *) selection_data->data, pos); | |
1545 } | |
1546 else | |
1547 playlist_add_url((gchar *) selection_data->data); | |
1548 } | |
1549 | |
1550 static void | |
1551 playlistwin_create_widgets(void) | |
1552 { | |
1553 /* This function creates the custom widgets used by the playlist editor */ | |
1554 | |
1555 /* text box for displaying song title in shaded mode */ | |
1556 playlistwin_sinfo = | |
1557 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1558 4, 4, playlistwin_get_width() - 35, FALSE, SKIN_TEXT); | |
1559 | |
1560 if (!cfg.playlist_shaded) | |
1561 widget_hide(WIDGET(playlistwin_sinfo)); | |
1562 | |
1563 /* shade/unshade window push button */ | |
1564 if (cfg.playlist_shaded) | |
1565 playlistwin_shade = | |
1566 create_pbutton(&playlistwin_wlist, playlistwin_bg, | |
1567 playlistwin_gc, playlistwin_get_width() - 21, 3, | |
1568 9, 9, 128, 45, 150, 42, | |
1569 playlistwin_shade_toggle, SKIN_PLEDIT); | |
1570 else | |
1571 playlistwin_shade = | |
1572 create_pbutton(&playlistwin_wlist, playlistwin_bg, | |
1573 playlistwin_gc, playlistwin_get_width() - 21, 3, | |
1574 9, 9, 157, 3, 62, 42, playlistwin_shade_toggle, | |
1575 SKIN_PLEDIT); | |
1576 | |
1577 playlistwin_shade->pb_allow_draw = FALSE; | |
1578 | |
1579 /* close window push button */ | |
1580 playlistwin_close = | |
1581 create_pbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1582 playlistwin_get_width() - 11, 3, 9, 9, | |
1583 cfg.playlist_shaded ? 138 : 167, | |
1584 cfg.playlist_shaded ? 45 : 3, 52, 42, | |
1585 playlistwin_hide, SKIN_PLEDIT); | |
1586 playlistwin_close->pb_allow_draw = FALSE; | |
1587 | |
1588 /* playlist list box */ | |
1589 playlistwin_list = | |
1590 create_playlist_list(&playlistwin_wlist, playlistwin_bg, | |
1591 playlistwin_gc, 12, 20, | |
1592 playlistwin_get_width() - 31, | |
1593 cfg.playlist_height - 58); | |
1594 playlist_list_set_font(cfg.playlist_font); | |
1595 | |
1596 /* playlist list box slider */ | |
1597 playlistwin_slider = | |
1598 create_playlistslider(&playlistwin_wlist, playlistwin_bg, | |
1599 playlistwin_gc, playlistwin_get_width() - 15, | |
1600 20, cfg.playlist_height - 58, playlistwin_list); | |
1601 /* track time (minute) */ | |
1602 playlistwin_time_min = | |
1603 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1604 playlistwin_get_width() - 82, | |
1605 cfg.playlist_height - 15, 15, FALSE, SKIN_TEXT); | |
1606 | |
1607 /* track time (second) */ | |
1608 playlistwin_time_sec = | |
1609 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1610 playlistwin_get_width() - 64, | |
1611 cfg.playlist_height - 15, 10, FALSE, SKIN_TEXT); | |
1612 | |
1613 /* playlist information (current track length / total track length) */ | |
1614 playlistwin_info = | |
1615 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1616 playlistwin_get_width() - 143, | |
1617 cfg.playlist_height - 28, 85, FALSE, SKIN_TEXT); | |
1618 | |
1619 /* mini visualizer */ | |
1620 playlistwin_vis = | |
1621 create_vis(&playlistwin_wlist, playlistwin_bg, playlistwin->window, | |
1622 playlistwin_gc, playlistwin_get_width() - 223, | |
1623 cfg.playlist_height - 26, 72); | |
1624 widget_hide(WIDGET(playlistwin_vis)); | |
1625 | |
1626 /* mini play control buttons at right bottom corner */ | |
1627 | |
1628 /* rewind button */ | |
1629 playlistwin_srew = | |
1630 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1631 playlistwin_get_width() - 144, | |
1632 cfg.playlist_height - 16, 8, 7, playlist_prev); | |
1633 | |
1634 /* play button */ | |
1635 playlistwin_splay = | |
1636 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1637 playlistwin_get_width() - 138, | |
1638 cfg.playlist_height - 16, 10, 7, mainwin_play_pushed); | |
1639 | |
1640 /* pause button */ | |
1641 playlistwin_spause = | |
1642 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1643 playlistwin_get_width() - 128, | |
1644 cfg.playlist_height - 16, 10, 7, bmp_playback_pause); | |
1645 | |
1646 /* stop button */ | |
1647 playlistwin_sstop = | |
1648 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1649 playlistwin_get_width() - 118, | |
1650 cfg.playlist_height - 16, 9, 7, mainwin_stop_pushed); | |
1651 | |
1652 /* forward button */ | |
1653 playlistwin_sfwd = | |
1654 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1655 playlistwin_get_width() - 109, | |
1656 cfg.playlist_height - 16, 8, 7, playlist_next); | |
1657 | |
1658 /* eject button */ | |
1659 playlistwin_seject = | |
1660 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1661 playlistwin_get_width() - 100, | |
1662 cfg.playlist_height - 16, 9, 7, mainwin_eject_pushed); | |
1663 | |
1664 | |
1665 playlistwin_sscroll_up = | |
1666 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1667 playlistwin_get_width() - 14, | |
1668 cfg.playlist_height - 35, 8, 5, | |
1669 playlistwin_scroll_up_pushed); | |
1670 playlistwin_sscroll_down = | |
1671 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1672 playlistwin_get_width() - 14, | |
1673 cfg.playlist_height - 30, 8, 5, | |
1674 playlistwin_scroll_down_pushed); | |
1675 | |
1676 } | |
1677 | |
1678 static void | |
1679 selection_received(GtkWidget * widget, | |
1680 GtkSelectionData * selection_data, gpointer data) | |
1681 { | |
1682 if (selection_data->type == GDK_SELECTION_TYPE_STRING && | |
1683 selection_data->length > 0) | |
1684 playlist_add_url((gchar *) selection_data->data); | |
1685 } | |
1686 | |
1687 static void | |
1688 playlistwin_create_window(void) | |
1689 { | |
1690 GdkPixbuf *icon; | |
1691 | |
1692 playlistwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
187 | 1693 gtk_window_set_title(GTK_WINDOW(playlistwin), _("Audacious Playlist Editor")); |
0 | 1694 gtk_window_set_role(GTK_WINDOW(playlistwin), "playlist"); |
1695 gtk_window_set_default_size(GTK_WINDOW(playlistwin), | |
1696 playlistwin_get_width(), | |
1697 playlistwin_get_height()); | |
1698 gtk_window_set_resizable(GTK_WINDOW(playlistwin), TRUE); | |
1699 playlistwin_set_geometry_hints(cfg.playlist_shaded); | |
1700 dock_window_list = dock_window_set_decorated(dock_window_list, | |
1701 GTK_WINDOW(playlistwin), | |
1702 cfg.show_wm_decorations); | |
1703 | |
1704 gtk_window_set_transient_for(GTK_WINDOW(playlistwin), | |
1705 GTK_WINDOW(mainwin)); | |
1706 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(playlistwin), TRUE); | |
1707 | |
1708 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) bmp_playlist_icon); | |
1709 gtk_window_set_icon(GTK_WINDOW(playlistwin), icon); | |
1710 g_object_unref(icon); | |
1711 | |
1712 gtk_widget_set_app_paintable(playlistwin, TRUE); | |
1713 | |
1714 if (cfg.playlist_x != -1 && cfg.save_window_position) | |
1715 gtk_window_move(GTK_WINDOW(playlistwin), | |
1716 cfg.playlist_x, cfg.playlist_y); | |
1717 | |
1718 gtk_widget_add_events(playlistwin, | |
1719 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
1720 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1721 GDK_SCROLL_MASK | GDK_VISIBILITY_NOTIFY_MASK); | |
1722 gtk_widget_realize(playlistwin); | |
1723 | |
1724 util_set_cursor(playlistwin); | |
1725 | |
1726 g_signal_connect(playlistwin, "delete_event", | |
1727 G_CALLBACK(playlistwin_delete), NULL); | |
1728 g_signal_connect(playlistwin, "button_press_event", | |
1729 G_CALLBACK(playlistwin_press), NULL); | |
1730 g_signal_connect(playlistwin, "button_release_event", | |
1731 G_CALLBACK(playlistwin_release), NULL); | |
1732 g_signal_connect(playlistwin, "scroll_event", | |
1733 G_CALLBACK(playlistwin_scrolled), NULL); | |
1734 g_signal_connect(playlistwin, "motion_notify_event", | |
1735 G_CALLBACK(playlistwin_motion), NULL); | |
1736 g_signal_connect_after(playlistwin, "focus_in_event", | |
1737 G_CALLBACK(playlistwin_focus_in), NULL); | |
1738 g_signal_connect_after(playlistwin, "focus_out_event", | |
1739 G_CALLBACK(playlistwin_focus_out), NULL); | |
1740 g_signal_connect(playlistwin, "configure_event", | |
1741 G_CALLBACK(playlistwin_configure), NULL); | |
1742 g_signal_connect(playlistwin, "style_set", | |
1743 G_CALLBACK(playlistwin_set_back_pixmap), NULL); | |
1744 | |
1745 bmp_drag_dest_set(playlistwin); | |
1746 | |
1747 /* DnD stuff */ | |
1748 g_signal_connect(playlistwin, "drag-leave", | |
1749 G_CALLBACK(playlistwin_drag_end), NULL); | |
1750 g_signal_connect(playlistwin, "drag-data-delete", | |
1751 G_CALLBACK(playlistwin_drag_end), NULL); | |
1752 g_signal_connect(playlistwin, "drag-end", | |
1753 G_CALLBACK(playlistwin_drag_end), NULL); | |
1754 g_signal_connect(playlistwin, "drag-drop", | |
1755 G_CALLBACK(playlistwin_drag_end), NULL); | |
1756 g_signal_connect(playlistwin, "drag-data-received", | |
1757 G_CALLBACK(playlistwin_drag_data_received), NULL); | |
1758 g_signal_connect(playlistwin, "drag-motion", | |
1759 G_CALLBACK(playlistwin_drag_motion), NULL); | |
1760 | |
1761 g_signal_connect(playlistwin, "key_press_event", | |
1762 G_CALLBACK(playlistwin_keypress), NULL); | |
1763 g_signal_connect(playlistwin, "selection_received", | |
1764 G_CALLBACK(selection_received), NULL); | |
1765 | |
1766 playlistwin_set_mask(); | |
1767 } | |
1768 | |
1769 void | |
1770 playlistwin_create_popup_menus(void) | |
1771 { | |
1772 playlistwin_accel = gtk_accel_group_new(); | |
1773 | |
1774 /* playlist window popup menu */ | |
1775 playlistwin_popup_menu = create_menu(playlistwin_popup_menu_entries, | |
1776 G_N_ELEMENTS(playlistwin_popup_menu_entries), | |
1777 playlistwin_accel); | |
1778 | |
1779 pladd_menu = create_menu(pladd_menu_entries, G_N_ELEMENTS(pladd_menu_entries), | |
1780 playlistwin_accel); | |
1781 pldel_menu = create_menu(pldel_menu_entries, G_N_ELEMENTS(pldel_menu_entries), | |
1782 playlistwin_accel); | |
1783 plsel_menu = create_menu(plsel_menu_entries, G_N_ELEMENTS(plsel_menu_entries), | |
1784 playlistwin_accel); | |
1785 plsort_menu = create_menu(plsort_menu_entries, | |
1786 G_N_ELEMENTS(plsort_menu_entries), | |
1787 playlistwin_accel); | |
1788 pllist_menu = create_menu(pllist_menu_entries, G_N_ELEMENTS(pllist_menu_entries), | |
1789 playlistwin_accel); | |
1790 | |
1791 #if 0 | |
1792 make_submenu(playlistwin_popup_menu, "/Playlist", | |
1793 playlistwin_playlist_menu); | |
1794 make_submenu(playlistwin_popup_menu, "/Playback", | |
1795 playlistwin_playback_menu); | |
1796 make_submenu(playlistwin_popup_menu, "/Add", | |
1797 pladd_menu); | |
1798 #endif | |
1799 } | |
1800 | |
1801 void | |
1802 playlistwin_create(void) | |
1803 { | |
1804 playlistwin_create_window(); | |
1805 playlistwin_create_popup_menus(); | |
1806 | |
1807 /* create GC and back pixmap for custom widget to draw on */ | |
1808 playlistwin_gc = gdk_gc_new(playlistwin->window); | |
1809 playlistwin_bg = gdk_pixmap_new(playlistwin->window, | |
1810 playlistwin_get_width(), | |
1811 playlistwin_get_height_unshaded(), -1); | |
1812 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
1813 | |
1814 playlistwin_create_widgets(); | |
1815 playlistwin_update_info(); | |
1816 | |
1817 gtk_window_add_accel_group(GTK_WINDOW(playlistwin), playlistwin_accel); | |
1818 gtk_window_add_accel_group(GTK_WINDOW(playlistwin), mainwin_accel); | |
1819 } | |
1820 | |
1821 | |
1822 void | |
1823 playlistwin_show(void) | |
1824 { | |
1825 GtkWidget *item; | |
1826 | |
1827 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
1828 "/Show Playlist Editor"); | |
1829 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); | |
1830 | |
1831 tbutton_set_toggled(mainwin_pl, TRUE); | |
1832 cfg.playlist_visible = TRUE; | |
1833 | |
1834 playlistwin_set_toprow(0); | |
1835 playlist_check_pos_current(); | |
1836 | |
1837 gtk_widget_show(playlistwin); | |
1838 } | |
1839 | |
1840 void | |
1841 playlistwin_hide(void) | |
1842 { | |
1843 GtkWidget *item; | |
1844 | |
1845 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
1846 "/Show Playlist Editor"); | |
1847 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE); | |
1848 | |
1849 gtk_widget_hide(playlistwin); | |
1850 tbutton_set_toggled(mainwin_pl, FALSE); | |
1851 cfg.playlist_visible = FALSE; | |
1852 | |
1853 gtk_window_present(GTK_WINDOW(mainwin)); | |
1854 gtk_widget_grab_focus(mainwin); | |
1855 } | |
1856 | |
1857 | |
1858 static void | |
1859 plsort_menu_callback(gpointer data, | |
1860 guint action, | |
1861 GtkWidget * widget) | |
1862 { | |
1863 switch (action) { | |
1864 case PLAYLISTWIN_SORT_BYTITLE: | |
1865 playlist_sort(PLAYLIST_SORT_TITLE); | |
1866 playlistwin_update_list(); | |
1867 break; | |
1868 case PLAYLISTWIN_SORT_BYPATH: | |
1869 playlist_sort(PLAYLIST_SORT_PATH); | |
1870 playlistwin_update_list(); | |
1871 break; | |
1872 case PLAYLISTWIN_SORT_BYDATE: | |
1873 playlist_sort(PLAYLIST_SORT_DATE); | |
1874 playlistwin_update_list(); | |
1875 break; | |
1876 case PLAYLISTWIN_SORT_BYFILENAME: | |
1877 playlist_sort(PLAYLIST_SORT_FILENAME); | |
1878 playlistwin_update_list(); | |
1879 break; | |
1880 case PLAYLISTWIN_SORT_SEL_BYTITLE: | |
1881 playlist_sort_selected(PLAYLIST_SORT_TITLE); | |
1882 playlistwin_update_list(); | |
1883 break; | |
1884 case PLAYLISTWIN_SORT_SEL_BYFILENAME: | |
1885 playlist_sort_selected(PLAYLIST_SORT_FILENAME); | |
1886 playlistwin_update_list(); | |
1887 break; | |
1888 case PLAYLISTWIN_SORT_SEL_BYPATH: | |
1889 playlist_sort_selected(PLAYLIST_SORT_PATH); | |
1890 playlistwin_update_list(); | |
1891 break; | |
1892 case PLAYLISTWIN_SORT_SEL_BYDATE: | |
1893 playlist_sort_selected(PLAYLIST_SORT_DATE); | |
1894 playlistwin_update_list(); | |
1895 break; | |
1896 case PLAYLISTWIN_SORT_REVERSE: | |
1897 playlist_reverse(); | |
1898 playlistwin_update_list(); | |
1899 break; | |
1900 case PLAYLISTWIN_SORT_RANDOMIZE: | |
1901 playlist_random(); | |
1902 playlistwin_update_list(); | |
1903 break; | |
1904 } | |
1905 } | |
1906 | |
1907 static void | |
1908 playlistwin_sub_menu_callback(gpointer data, | |
1909 guint action, | |
1910 GtkWidget * widget) | |
1911 { | |
1912 switch (action) { | |
1913 case PLIST_NEW: | |
1914 playlist_set_current_name(NULL); | |
1915 playlist_clear(); | |
1916 mainwin_clear_song_info(); | |
1917 mainwin_set_info_text(); | |
1918 break; | |
1919 case PLIST_SAVE: | |
1920 playlistwin_select_playlist_to_save(playlist_get_current_name()); | |
1921 break; | |
1922 case PLIST_SAVE_AS: | |
1923 playlistwin_select_playlist_to_save(playlist_get_current_name()); | |
1924 break; | |
1925 case PLIST_LOAD: | |
1926 playlistwin_select_playlist_to_load(playlist_get_current_name()); | |
1927 break; | |
1928 case SEL_INV: | |
1929 playlistwin_inverse_selection(); | |
1930 break; | |
1931 case SEL_ZERO: | |
1932 playlistwin_select_none(); | |
1933 break; | |
1934 case SEL_ALL: | |
1935 playlistwin_select_all(); | |
1936 break; | |
1937 case SUB_ALL: | |
1938 playlist_clear(); | |
1939 mainwin_clear_song_info(); | |
1940 mainwin_set_info_text(); | |
1941 break; | |
1942 case SUB_CROP: | |
1943 playlist_delete(TRUE); | |
1944 break; | |
1945 case SUB_SELECTED: | |
1946 playlist_delete(FALSE); | |
1947 break; | |
1948 case PLAYLISTWIN_REMOVE_DEAD_FILES: | |
1949 playlist_remove_dead_files(); | |
1950 break; | |
1951 case PLAYLISTWIN_REFRESH: | |
1952 playlist_read_info_selection(); | |
1953 playlistwin_update_list(); | |
1954 break; | |
1955 } | |
1956 } | |
1957 | |
1958 static void | |
1959 playlistwin_popup_menu_callback(gpointer data, | |
1960 guint action, | |
1961 GtkWidget * widget) | |
1962 { | |
1963 switch (action) { | |
1964 case ADD_FILES: | |
1965 playlistwin_show_filebrowser(); | |
1966 break; | |
1967 case ADD_DIR: | |
1968 playlistwin_run_dirbrowser(); | |
1969 break; | |
1970 case CLOSE_PL_WINDOW: | |
1971 playlistwin_hide(); | |
1972 break; | |
1973 case MISC_FILEINFO: | |
1974 playlistwin_fileinfo(); | |
1975 break; | |
1976 case SEL_LOOKUP: | |
1977 playlist_read_info_selection(); | |
1978 break; | |
1979 case MISC_QUEUE: | |
1980 playlist_queue(); | |
1981 break; | |
1982 case PLIST_CQUEUE: | |
1983 playlist_clear_queue(); | |
1984 break; | |
1985 case PLIST_JTT: | |
1986 mainwin_jump_to_time(); | |
1987 break; | |
1988 case PLIST_JTF: | |
1989 mainwin_jump_to_file(); | |
1990 break; | |
1991 } | |
1992 } |