Mercurial > audlegacy
annotate audacious/playlistwin.c @ 236:be1be6f2aeeb trunk
[svn] Remove unneeded sanity check.
author | nenolod |
---|---|
date | Sat, 26 Nov 2005 17:44:16 -0800 |
parents | 1a8fcda55ac1 |
children | 02c17a5c99e3 |
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 | |
430 widget_draw(WIDGET(playlistwin_list)); | |
431 widget_draw(WIDGET(playlistwin_slider)); | |
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(); |
0 | 535 draw_playlist_window(TRUE); |
536 } | |
537 | |
538 static void | |
539 playlistwin_set_shade_menu(gboolean shaded) | |
540 { | |
541 GtkWidget *item; | |
542 | |
543 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
544 "/Roll up Playlist Editor"); | |
545 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), shaded); | |
546 | |
547 playlistwin_set_shade(shaded); | |
548 } | |
549 | |
550 void | |
551 playlistwin_shade_toggle(void) | |
552 { | |
553 playlistwin_set_shade_menu(!cfg.playlist_shaded); | |
554 } | |
555 | |
556 static void | |
557 playlistwin_release(GtkWidget * widget, | |
558 GdkEventButton * event, | |
559 gpointer callback_data) | |
560 { | |
561 if (event->button == 3) | |
562 return; | |
563 | |
564 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
565 playlistwin_resizing = FALSE; | |
566 gdk_flush(); | |
567 | |
568 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
569 dock_move_release(GTK_WINDOW(playlistwin)); | |
570 #if 0 | |
571 if (cfg.playlist_transparent) | |
572 playlistwin_update_list(); | |
573 #endif | |
574 } | |
575 else { | |
576 handle_release_cb(playlistwin_wlist, widget, event); | |
577 playlist_popup_destroy(); | |
578 draw_playlist_window(FALSE); | |
579 } | |
580 } | |
581 | |
582 void | |
583 playlistwin_scroll(gint num) | |
584 { | |
585 playlistwin_list->pl_first += num; | |
586 playlistwin_update_list(); | |
587 } | |
588 | |
589 void | |
590 playlistwin_scroll_up_pushed(void) | |
591 { | |
592 playlistwin_list->pl_first -= 3; | |
593 playlistwin_update_list(); | |
594 } | |
595 | |
596 void | |
597 playlistwin_scroll_down_pushed(void) | |
598 { | |
599 playlistwin_list->pl_first += 3; | |
600 playlistwin_update_list(); | |
601 } | |
602 | |
603 static void | |
604 playlistwin_select_all(void) | |
605 { | |
606 playlist_select_all(TRUE); | |
607 playlistwin_list->pl_prev_selected = 0; | |
608 playlistwin_list->pl_prev_min = 0; | |
609 playlistwin_list->pl_prev_max = playlist_get_length() - 1; | |
610 playlistwin_update_list(); | |
611 } | |
612 | |
613 static void | |
614 playlistwin_select_none(void) | |
615 { | |
616 playlist_select_all(FALSE); | |
617 playlistwin_list->pl_prev_selected = -1; | |
618 playlistwin_list->pl_prev_min = -1; | |
619 playlistwin_update_list(); | |
620 } | |
621 | |
622 static void | |
623 playlistwin_inverse_selection(void) | |
624 { | |
625 playlist_select_invert_all(); | |
626 playlistwin_list->pl_prev_selected = -1; | |
627 playlistwin_list->pl_prev_min = -1; | |
628 playlistwin_update_list(); | |
629 } | |
630 | |
631 static void | |
632 playlistwin_resize(gint width, gint height) | |
633 { | |
634 gboolean redraw; | |
635 | |
636 g_return_if_fail(width > 0 && height > 0); | |
637 | |
638 cfg.playlist_width = width; | |
639 | |
640 if (!cfg.playlist_shaded) | |
641 cfg.playlist_height = height; | |
642 else | |
643 height = cfg.playlist_height; | |
644 | |
645 /* FIXME: why the fsck are we doing this manually? */ | |
646 /* adjust widget positions and sizes */ | |
647 | |
648 widget_resize(WIDGET(playlistwin_list), width - 31, height - 58); | |
649 | |
650 widget_move(WIDGET(playlistwin_slider), width - 15, 20); | |
651 widget_resize(WIDGET(playlistwin_slider), 8, height - 58); | |
652 | |
653 widget_resize(WIDGET(playlistwin_sinfo), width - 35, 14); | |
654 playlistwin_update_sinfo(); | |
655 | |
656 widget_move(WIDGET(playlistwin_shade), width - 21, 3); | |
657 widget_move(WIDGET(playlistwin_close), width - 11, 3); | |
658 widget_move(WIDGET(playlistwin_time_min), width - 82, height - 15); | |
659 widget_move(WIDGET(playlistwin_time_sec), width - 64, height - 15); | |
660 widget_move(WIDGET(playlistwin_info), width - 143, height - 28); | |
661 widget_move(WIDGET(playlistwin_srew), width - 144, height - 16); | |
662 widget_move(WIDGET(playlistwin_splay), width - 138, height - 16); | |
663 widget_move(WIDGET(playlistwin_spause), width - 128, height - 16); | |
664 widget_move(WIDGET(playlistwin_sstop), width - 118, height - 16); | |
665 widget_move(WIDGET(playlistwin_sfwd), width - 109, height - 16); | |
666 widget_move(WIDGET(playlistwin_seject), width - 100, height - 16); | |
667 widget_move(WIDGET(playlistwin_sscroll_up), width - 14, height - 35); | |
668 widget_move(WIDGET(playlistwin_sscroll_down), width - 14, height - 30); | |
669 | |
670 /* decide if we should show the mini visualizer */ | |
671 if (playlistwin_get_width() >= 350) { | |
672 widget_move(WIDGET(playlistwin_vis), width - 223, height - 26); | |
673 | |
674 if (playlistwin_vis_enabled) | |
675 widget_show(WIDGET(playlistwin_vis)); | |
676 } | |
677 else | |
678 widget_hide(WIDGET(playlistwin_vis)); | |
679 | |
680 g_object_unref(playlistwin_bg); | |
681 playlistwin_bg = gdk_pixmap_new(playlistwin->window, width, height, -1); | |
682 playlistwin_set_mask(); | |
683 | |
684 widget_list_lock(playlistwin_wlist); | |
685 | |
686 widget_list_change_pixmap(playlistwin_wlist, playlistwin_bg); | |
687 playlistwin_draw_frame(); | |
688 widget_list_draw(playlistwin_wlist, &redraw, TRUE); | |
689 widget_list_clear_redraw(playlistwin_wlist); | |
690 | |
691 widget_list_unlock(playlistwin_wlist); | |
692 | |
693 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
694 gdk_window_clear(playlistwin->window); | |
695 } | |
696 | |
697 | |
698 | |
699 static void | |
700 playlistwin_motion(GtkWidget * widget, | |
701 GdkEventMotion * event, | |
702 gpointer callback_data) | |
703 { | |
704 XEvent ev; | |
705 | |
706 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
707 dock_move_motion(GTK_WINDOW(playlistwin), event); | |
708 } | |
709 else { | |
710 handle_motion_cb(playlistwin_wlist, widget, event); | |
711 draw_playlist_window(FALSE); | |
712 } | |
713 gdk_flush(); | |
714 while (XCheckMaskEvent(GDK_DISPLAY(), ButtonMotionMask, &ev)); | |
715 } | |
716 | |
717 static void | |
718 playlistwin_show_filebrowser(void) | |
719 { | |
720 util_run_filebrowser(NO_PLAY_BUTTON); | |
721 } | |
722 | |
723 #if 0 | |
724 static void | |
725 playlistwin_add_dir_handler(const gchar * dir) | |
726 { | |
727 g_free(cfg.filesel_path); | |
728 cfg.filesel_path = g_strdup(dir); | |
729 playlist_add_dir(dir); | |
730 } | |
731 #endif | |
732 | |
733 static void | |
734 playlistwin_fileinfo(void) | |
735 { | |
736 /* Show the first selected file, or the current file if nothing is | |
737 * selected */ | |
738 GList *list = playlist_get_selected(); | |
739 if (list) { | |
740 playlist_fileinfo(GPOINTER_TO_INT(list->data)); | |
741 g_list_free(list); | |
742 } | |
743 else | |
744 playlist_fileinfo_current(); | |
745 } | |
746 | |
747 static void | |
748 menu_set_item_sensitive(GtkItemFactory * item_factory, | |
749 const gchar * path, | |
750 gboolean sensitive) | |
751 { | |
752 GtkWidget *item = gtk_item_factory_get_widget(item_factory, path); | |
753 gtk_widget_set_sensitive(item, sensitive); | |
754 } | |
755 | |
756 /* FIXME: broken */ | |
757 static void | |
758 playlistwin_set_sensitive_sortmenu(void) | |
759 { | |
760 gboolean set = playlist_get_num_selected() > 1; | |
761 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Title", set); | |
762 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Filename", set); | |
763 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Path + Filename", set); | |
764 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Date", set); | |
765 } | |
766 | |
767 static void | |
768 show_playlist_save_error(GtkWindow * parent, | |
769 const gchar * filename) | |
770 { | |
771 GtkWidget *dialog; | |
772 | |
773 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
774 g_return_if_fail(filename != NULL); | |
775 | |
776 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
777 GTK_DIALOG_DESTROY_WITH_PARENT, | |
778 GTK_MESSAGE_ERROR, | |
779 GTK_BUTTONS_OK, | |
780 _("Error writing playlist \"%s\": %s"), | |
781 filename, strerror(errno)); | |
782 | |
783 gtk_dialog_run(GTK_DIALOG(dialog)); | |
784 gtk_widget_destroy(dialog); | |
785 } | |
786 | |
787 static gboolean | |
788 show_playlist_overwrite_prompt(GtkWindow * parent, | |
789 const gchar * filename) | |
790 { | |
791 GtkWidget *dialog; | |
792 gint result; | |
793 | |
794 g_return_val_if_fail(GTK_IS_WINDOW(parent), FALSE); | |
795 g_return_val_if_fail(filename != NULL, FALSE); | |
796 | |
797 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
798 GTK_DIALOG_DESTROY_WITH_PARENT, | |
799 GTK_MESSAGE_QUESTION, | |
800 GTK_BUTTONS_YES_NO, | |
801 _("%s already exist. Continue?"), | |
802 filename); | |
803 | |
804 result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
805 gtk_widget_destroy(dialog); | |
806 | |
807 return (result == GTK_RESPONSE_YES); | |
808 } | |
809 | |
810 static void | |
811 show_playlist_save_format_error(GtkWindow * parent, | |
812 const gchar * filename) | |
813 { | |
814 const gchar *markup = | |
815 N_("<b><big>Unable to save playlist.</big></b>\n\n" | |
816 "Unknown file type for '%s'.\n"); | |
817 | |
818 GtkWidget *dialog; | |
819 | |
820 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
821 g_return_if_fail(filename != NULL); | |
822 | |
823 dialog = | |
824 gtk_message_dialog_new_with_markup(GTK_WINDOW(parent), | |
825 GTK_DIALOG_DESTROY_WITH_PARENT, | |
826 GTK_MESSAGE_ERROR, | |
827 GTK_BUTTONS_OK, | |
828 _(markup), | |
829 filename); | |
830 gtk_dialog_run(GTK_DIALOG(dialog)); | |
831 gtk_widget_destroy(dialog); | |
832 } | |
833 | |
834 static void | |
835 playlistwin_save_playlist(const gchar * filename) | |
836 { | |
837 PlaylistFormat format; | |
838 | |
839 format = playlist_format_get_from_name(filename); | |
840 if (format == PLAYLIST_FORMAT_UNKNOWN) { | |
841 show_playlist_save_format_error(GTK_WINDOW(playlistwin), filename); | |
842 return; | |
843 } | |
844 | |
845 str_replace_in(&cfg.playlist_path, g_path_get_dirname(filename)); | |
846 | |
847 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
848 if (!show_playlist_overwrite_prompt(GTK_WINDOW(playlistwin), filename)) | |
849 return; | |
850 | |
851 if (!playlist_save(filename, format)) | |
852 show_playlist_save_error(GTK_WINDOW(playlistwin), filename); | |
853 } | |
854 | |
855 #if 0 | |
856 static void | |
857 playlistwin_save_current(void) | |
858 { | |
859 const gchar *filename; | |
860 | |
861 if (!(filename = playlist_get_current_name())) | |
862 return; | |
863 | |
864 playlistwin_save_playlist(filename); | |
865 } | |
866 #endif | |
867 | |
868 static void | |
869 playlistwin_load_playlist(const gchar * filename) | |
870 { | |
871 g_return_if_fail(filename != NULL); | |
872 | |
873 str_replace_in(&cfg.playlist_path, g_strdup(filename)); | |
874 | |
875 playlist_clear(); | |
876 mainwin_clear_song_info(); | |
877 mainwin_set_info_text(); | |
878 | |
879 playlist_load(filename); | |
880 playlist_set_current_name(filename); | |
881 } | |
882 | |
883 static gchar * | |
884 playlist_file_selection(const gchar * title, | |
885 gboolean save, | |
886 const gchar * default_filename) | |
887 { | |
888 GtkWidget *dialog, *button; | |
889 gchar *filename; | |
890 | |
891 g_return_val_if_fail(title != NULL, NULL); | |
892 | |
893 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
894 save ? GTK_FILE_CHOOSER_ACTION_SAVE : | |
895 GTK_FILE_CHOOSER_ACTION_OPEN, NULL); | |
896 if (default_filename) | |
897 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
898 default_filename); | |
899 | |
900 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
901 GTK_RESPONSE_REJECT); | |
902 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
903 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
904 | |
905 button = gtk_dialog_add_button(GTK_DIALOG(dialog), | |
906 save ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
907 GTK_RESPONSE_ACCEPT); | |
908 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
909 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
910 | |
911 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
912 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
913 else | |
914 filename = NULL; | |
915 | |
916 gtk_widget_destroy(dialog); | |
917 | |
918 return filename; | |
919 } | |
920 | |
921 void | |
922 playlistwin_select_playlist_to_load(const gchar * default_filename) | |
923 { | |
924 gchar *filename = | |
925 playlist_file_selection(_("Load Playlist"), FALSE, default_filename); | |
926 | |
927 if (filename) { | |
928 playlistwin_load_playlist(filename); | |
929 g_free(filename); | |
930 } | |
931 } | |
932 | |
933 static void | |
934 playlistwin_select_playlist_to_save(const gchar * default_filename) | |
935 { | |
936 gchar *filename = | |
937 playlist_file_selection(_("Save Playlist"), TRUE, default_filename); | |
938 | |
939 if (filename) { | |
940 /* Default to M3U if no filename has extension */ | |
941 | |
942 /* NOTE: This doesn't work correctly for hidden files | |
943 - descender */ | |
944 if (!strchr(filename, '.')) { | |
945 gchar *tmpstr = filename; | |
946 filename = g_strconcat(filename, ".m3u", NULL); | |
947 g_free(tmpstr); | |
948 } | |
949 | |
950 playlistwin_save_playlist(filename); | |
951 g_free(filename); | |
952 } | |
953 } | |
954 | |
955 static void | |
956 playlistwin_run_dirbrowser(void) | |
957 { | |
958 mainwin_run_dirbrowser(); | |
959 } | |
960 | |
961 static gboolean | |
962 inside_sensitive_widgets(gint x, gint y) | |
963 { | |
964 return (widget_contains(WIDGET(playlistwin_list), x, y) || | |
965 widget_contains(WIDGET(playlistwin_slider), x, y) || | |
966 widget_contains(WIDGET(playlistwin_close), x, y) || | |
967 widget_contains(WIDGET(playlistwin_shade), x, y) || | |
968 widget_contains(WIDGET(playlistwin_time_min), x, y) || | |
969 widget_contains(WIDGET(playlistwin_time_sec), x, y) || | |
970 widget_contains(WIDGET(playlistwin_info), x, y) || | |
971 widget_contains(WIDGET(playlistwin_vis), x, y) || | |
972 widget_contains(WIDGET(playlistwin_srew), x, y) || | |
973 widget_contains(WIDGET(playlistwin_splay), x, y) || | |
974 widget_contains(WIDGET(playlistwin_spause), x, y) || | |
975 widget_contains(WIDGET(playlistwin_sstop), x, y) || | |
976 widget_contains(WIDGET(playlistwin_sfwd), x, y) || | |
977 widget_contains(WIDGET(playlistwin_seject), x, y) || | |
978 widget_contains(WIDGET(playlistwin_sscroll_up), x, y) || | |
979 widget_contains(WIDGET(playlistwin_sscroll_down), x, y)); | |
980 } | |
981 | |
982 #define REGION_L(x1,x2,y1,y2) \ | |
983 (event->x >= (x1) && event->x < (x2) && \ | |
984 event->y >= cfg.playlist_height - (y1) && \ | |
985 event->y < cfg.playlist_height - (y2)) | |
986 | |
987 #define REGION_R(x1,x2,y1,y2) \ | |
988 (event->x >= playlistwin_get_width() - (x1) && \ | |
989 event->x < playlistwin_get_width() - (x2) && \ | |
990 event->y >= cfg.playlist_height - (y1) && \ | |
991 event->y < cfg.playlist_height - (y2)) | |
992 | |
993 static void | |
994 playlistwin_scrolled(GtkWidget * widget, | |
995 GdkEventScroll * event, | |
996 gpointer callback_data) | |
997 { | |
998 | |
999 if (event->direction == GDK_SCROLL_DOWN) | |
1000 playlistwin_scroll(cfg.scroll_pl_by); | |
1001 | |
1002 if (event->direction == GDK_SCROLL_UP) | |
1003 playlistwin_scroll(-cfg.scroll_pl_by); | |
1004 | |
1005 } | |
1006 | |
1007 | |
1008 | |
1009 | |
1010 static gboolean | |
1011 playlistwin_press(GtkWidget * widget, | |
1012 GdkEventButton * event, | |
1013 gpointer callback_data) | |
1014 { | |
1015 gboolean grab = TRUE; | |
1016 gint xpos, ypos; | |
1017 GtkWidget *_menu; | |
1018 GtkRequisition req; | |
1019 | |
1020 gtk_window_get_position(GTK_WINDOW(playlistwin), &xpos, &ypos); | |
1021 | |
1022 if (event->button == 1 && !cfg.show_wm_decorations && | |
1023 ((!cfg.playlist_shaded && | |
1024 event->x > playlistwin_get_width() - 20 && | |
1025 event->y > cfg.playlist_height - 20) || | |
1026 (cfg.playlist_shaded && | |
1027 event->x >= playlistwin_get_width() - 31 && | |
1028 event->x < playlistwin_get_width() - 22))) { | |
1029 | |
1030 /* NOTE: Workaround for bug #214 */ | |
1031 if (event->type != GDK_2BUTTON_PRESS && | |
1032 event->type != GDK_3BUTTON_PRESS) { | |
1033 /* resize area */ | |
1034 playlistwin_resizing = TRUE; | |
1035 gtk_window_begin_resize_drag(GTK_WINDOW(widget), | |
1036 GDK_WINDOW_EDGE_SOUTH_EAST, | |
1037 event->button, | |
1038 event->x + xpos, event->y + ypos, | |
1039 event->time); | |
1040 } | |
1041 grab = FALSE; | |
1042 } | |
1043 else if (event->button == 1 && REGION_L(12, 37, 29, 11)) { | |
1044 /* ADD button menu */ | |
1045 | |
1046 _menu = GTK_WIDGET(pladd_menu->widget); | |
1047 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1048 gtk_widget_size_request(_menu, &req); | |
1049 gtk_item_factory_popup_with_data(pladd_menu, | |
1050 NULL, NULL, | |
1051 xpos+12, | |
1052 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1053 grab = FALSE; | |
1054 } | |
1055 else if (event->button == 1 && REGION_L(41, 66, 29, 11)) { | |
1056 /* SUB button menu */ | |
1057 _menu = GTK_WIDGET(pldel_menu->widget); | |
1058 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1059 gtk_widget_size_request(_menu, &req); | |
1060 gtk_item_factory_popup_with_data(pldel_menu, | |
1061 NULL, NULL, | |
1062 xpos+40, | |
1063 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1064 grab = FALSE; | |
1065 } | |
1066 else if (event->button == 1 && REGION_L(70, 95, 29, 11)) { | |
1067 /* SEL button menu */ | |
1068 _menu = GTK_WIDGET(plsel_menu->widget); | |
1069 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1070 gtk_widget_size_request(_menu, &req); | |
1071 gtk_item_factory_popup_with_data(plsel_menu, | |
1072 NULL, NULL, | |
1073 xpos+68, | |
1074 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1075 | |
1076 grab = FALSE; | |
1077 } | |
1078 else if (event->button == 1 && REGION_L(99, 124, 29, 11)) { | |
1079 /* MISC button menu */ | |
1080 _menu = GTK_WIDGET(plsort_menu->widget); | |
1081 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1082 gtk_widget_size_request(_menu, &req); | |
1083 gtk_item_factory_popup_with_data(plsort_menu, | |
1084 NULL, NULL, | |
1085 xpos+100, | |
1086 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1087 grab = FALSE; | |
1088 } | |
1089 else if (event->button == 1 && REGION_R(46, 23, 29, 11)) { | |
1090 /* LIST button menu */ | |
1091 _menu = GTK_WIDGET(pllist_menu->widget); | |
1092 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1093 gtk_widget_size_request(_menu, &req); | |
1094 gtk_item_factory_popup_with_data(pllist_menu, | |
1095 NULL, NULL, | |
1096 xpos + playlistwin_get_width() - req.width - 12, | |
1097 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1098 grab = FALSE; | |
1099 } | |
1100 else if (event->button == 1 && REGION_R(82, 54, 15, 9)) { | |
1101 if (cfg.timer_mode == TIMER_ELAPSED) | |
1102 cfg.timer_mode = TIMER_REMAINING; | |
1103 else | |
1104 cfg.timer_mode = TIMER_ELAPSED; | |
1105 } | |
1106 else if (event->button == 2 && (event->type == GDK_BUTTON_PRESS) && | |
1107 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1108 gtk_selection_convert(widget, GDK_SELECTION_PRIMARY, | |
1109 GDK_TARGET_STRING, event->time); | |
1110 } | |
1111 else if (playlistwin_get_width() >= 350 && REGION_R(223, 151, 26, 10)) { | |
1112 if (event->button == 1) { | |
1113 cfg.vis_type++; | |
1114 if (cfg.vis_type > VIS_OFF) | |
1115 cfg.vis_type = VIS_ANALYZER; | |
1116 mainwin_vis_set_type(cfg.vis_type); | |
1117 } | |
1118 else if (event->button == 3) { | |
1119 gint mx, my; | |
1120 GdkModifierType modmask; | |
1121 | |
1122 gdk_window_get_pointer(NULL, &mx, &my, &modmask); | |
1123 util_item_factory_popup(mainwin_vis_menu, mx, my, 3, event->time); | |
1124 grab = FALSE; | |
1125 } | |
1126 } | |
1127 else if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
1128 !inside_sensitive_widgets(event->x, event->y) && event->y < 14) { | |
1129 gdk_window_raise(playlistwin->window); | |
1130 dock_move_press(dock_window_list, GTK_WINDOW(playlistwin), event, | |
1131 FALSE); | |
1132 } | |
1133 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && | |
1134 !inside_sensitive_widgets(event->x, event->y) | |
1135 && event->y < 14) { | |
1136 /* double click on title bar */ | |
1137 playlistwin_shade_toggle(); | |
1138 if (dock_is_moving(GTK_WINDOW(playlistwin))) | |
1139 dock_move_release(GTK_WINDOW(playlistwin)); | |
1140 return TRUE; | |
1141 } | |
1142 else if (event->button == 3 && | |
1143 !(widget_contains(WIDGET(playlistwin_list), event->x, event->y) || | |
1144 (event->y >= cfg.playlist_height - 29 && | |
1145 event->y < cfg.playlist_height - 11 && | |
1146 ((event->x >= 12 && event->x < 37) || | |
1147 (event->x >= 41 && event->x < 66) || | |
1148 (event->x >= 70 && event->x < 95) || | |
1149 (event->x >= 99 && event->x < 124) || | |
1150 (event->x >= playlistwin_get_width() - 46 && | |
1151 event->x < playlistwin_get_width() - 23))))) { | |
1152 /* | |
1153 * Pop up the main menu a few pixels down to avoid | |
1154 * anything to be selected initially. | |
1155 */ | |
1156 util_item_factory_popup(mainwin_general_menu, event->x_root, | |
1157 event->y_root + 2, 3, event->time); | |
1158 grab = FALSE; | |
1159 } | |
1160 else if (event->button == 3 && | |
1161 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1162 /* popup menu */ | |
1163 playlistwin_set_sensitive_sortmenu(); | |
1164 gtk_item_factory_popup(playlistwin_popup_menu, | |
1165 event->x_root, event->y_root + 5, | |
1166 3, event->time); | |
1167 grab = FALSE; | |
1168 } | |
1169 else { | |
1170 handle_press_cb(playlistwin_wlist, widget, event); | |
1171 draw_playlist_window(FALSE); | |
1172 } | |
1173 | |
1174 if (grab) | |
1175 gdk_pointer_grab(playlistwin->window, FALSE, | |
1176 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | | |
1177 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1178 GDK_BUTTON1_MOTION_MASK, NULL, NULL, | |
1179 GDK_CURRENT_TIME); | |
1180 | |
1181 return FALSE; | |
1182 } | |
1183 | |
1184 static gboolean | |
1185 playlistwin_focus_in(GtkWidget * widget, GdkEvent * event, gpointer data) | |
1186 { | |
1187 playlistwin_close->pb_allow_draw = TRUE; | |
1188 playlistwin_shade->pb_allow_draw = TRUE; | |
1189 draw_playlist_window(TRUE); | |
1190 return FALSE; | |
1191 } | |
1192 | |
1193 static gboolean | |
1194 playlistwin_focus_out(GtkWidget * widget, | |
1195 GdkEventButton * event, gpointer data) | |
1196 { | |
1197 playlistwin_close->pb_allow_draw = FALSE; | |
1198 playlistwin_shade->pb_allow_draw = FALSE; | |
1199 draw_playlist_window(TRUE); | |
1200 return FALSE; | |
1201 } | |
1202 | |
1203 static gboolean | |
1204 playlistwin_configure(GtkWidget * window, | |
1205 GdkEventConfigure * event, gpointer data) | |
1206 { | |
1207 if (!GTK_WIDGET_VISIBLE(window)) | |
1208 return FALSE; | |
1209 | |
1210 cfg.playlist_x = event->x; | |
1211 cfg.playlist_y = event->y; | |
1212 | |
1213 if (playlistwin_resizing) { | |
1214 if (event->width != playlistwin_get_width() || | |
1215 event->height != playlistwin_get_height()) | |
1216 playlistwin_resize(event->width, event->height); | |
1217 } | |
1218 return TRUE; | |
1219 } | |
1220 | |
1221 void | |
1222 playlistwin_set_back_pixmap(void) | |
1223 { | |
1224 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
1225 gdk_window_clear(playlistwin->window); | |
1226 } | |
1227 | |
1228 static gboolean | |
1229 playlistwin_delete(GtkWidget * w, gpointer data) | |
1230 { | |
1231 playlistwin_hide(); | |
1232 return TRUE; | |
1233 } | |
1234 | |
1235 static void | |
1236 playlistwin_keypress_up_down_handler(PlayList_List * pl, | |
1237 gboolean up, guint state) | |
1238 { | |
1239 if ((state & GDK_MOD1_MASK) && (state & GDK_SHIFT_MASK)) | |
1240 return; | |
1241 if (!(state & GDK_MOD1_MASK)) | |
1242 playlist_select_all(FALSE); | |
1243 | |
1244 if (pl->pl_prev_selected == -1 || | |
1245 (!playlistwin_item_visible(pl->pl_prev_selected) && | |
1246 !(state & GDK_SHIFT_MASK && pl->pl_prev_min != -1))) { | |
1247 pl->pl_prev_selected = pl->pl_first; | |
1248 } | |
1249 else if (state & GDK_SHIFT_MASK) { | |
1250 if (pl->pl_prev_min == -1) { | |
1251 pl->pl_prev_max = pl->pl_prev_selected; | |
1252 pl->pl_prev_min = pl->pl_prev_selected; | |
1253 } | |
1254 pl->pl_prev_max += (up ? -1 : 1); | |
1255 pl->pl_prev_max = | |
1256 CLAMP(pl->pl_prev_max, 0, playlist_get_length() - 1); | |
1257 | |
1258 pl->pl_first = MIN(pl->pl_first, pl->pl_prev_max); | |
1259 pl->pl_first = MAX(pl->pl_first, pl->pl_prev_max - | |
1260 pl->pl_num_visible + 1); | |
1261 playlist_select_range(pl->pl_prev_min, pl->pl_prev_max, TRUE); | |
1262 return; | |
1263 } | |
1264 else if (state & GDK_MOD1_MASK) { | |
1265 if (up) | |
1266 playlist_list_move_up(pl); | |
1267 else | |
1268 playlist_list_move_down(pl); | |
1269 if (pl->pl_prev_min < pl->pl_first) | |
1270 pl->pl_first = pl->pl_prev_min; | |
1271 else if (pl->pl_prev_max >= (pl->pl_first + pl->pl_num_visible)) | |
1272 pl->pl_first = pl->pl_prev_max - pl->pl_num_visible + 1; | |
1273 return; | |
1274 } | |
1275 else if (up) | |
1276 pl->pl_prev_selected--; | |
1277 else | |
1278 pl->pl_prev_selected++; | |
1279 | |
1280 pl->pl_prev_selected = | |
1281 CLAMP(pl->pl_prev_selected, 0, playlist_get_length() - 1); | |
1282 | |
1283 if (pl->pl_prev_selected < pl->pl_first) | |
1284 pl->pl_first--; | |
1285 else if (pl->pl_prev_selected >= (pl->pl_first + pl->pl_num_visible)) | |
1286 pl->pl_first++; | |
1287 | |
1288 playlist_select_range(pl->pl_prev_selected, pl->pl_prev_selected, TRUE); | |
1289 pl->pl_prev_min = -1; | |
1290 | |
1291 } | |
1292 | |
1293 /* FIXME: Handle the keys through menu */ | |
1294 | |
1295 static gboolean | |
1296 playlistwin_keypress(GtkWidget * w, GdkEventKey * event, gpointer data) | |
1297 { | |
1298 guint keyval; | |
1299 gboolean refresh = FALSE; | |
1300 | |
1301 if (cfg.playlist_shaded) | |
1302 return FALSE; | |
1303 | |
1304 switch (keyval = event->keyval) { | |
1305 case GDK_KP_Up: | |
1306 case GDK_KP_Down: | |
1307 case GDK_Up: | |
1308 case GDK_Down: | |
1309 playlistwin_keypress_up_down_handler(playlistwin_list, | |
1310 keyval == GDK_Up | |
1311 || keyval == GDK_KP_Up, | |
1312 event->state); | |
1313 refresh = TRUE; | |
1314 break; | |
1315 case GDK_Page_Up: | |
1316 playlistwin_scroll(-playlistwin_list->pl_num_visible); | |
1317 refresh = TRUE; | |
1318 break; | |
1319 case GDK_Page_Down: | |
1320 playlistwin_scroll(playlistwin_list->pl_num_visible); | |
1321 refresh = TRUE; | |
1322 break; | |
1323 case GDK_Home: | |
1324 playlistwin_list->pl_first = 0; | |
1325 refresh = TRUE; | |
1326 break; | |
1327 case GDK_End: | |
1328 playlistwin_list->pl_first = | |
1329 playlist_get_length() - playlistwin_list->pl_num_visible; | |
1330 refresh = TRUE; | |
1331 break; | |
1332 case GDK_Return: | |
1333 if (playlistwin_list->pl_prev_selected > -1 | |
1334 && playlistwin_item_visible(playlistwin_list->pl_prev_selected)) { | |
1335 playlist_set_position(playlistwin_list->pl_prev_selected); | |
1336 if (!bmp_playback_get_playing()) | |
1337 bmp_playback_initiate(); | |
1338 } | |
1339 break; | |
1340 case GDK_3: | |
1341 if (event->state & GDK_CONTROL_MASK) | |
1342 playlistwin_fileinfo(); | |
1343 break; | |
1344 case GDK_Delete: | |
1345 if (event->state & GDK_CONTROL_MASK) | |
1346 playlist_delete(TRUE); | |
1347 else | |
1348 playlist_delete(FALSE); | |
1349 break; | |
1350 case GDK_Insert: | |
1351 if (event->state & GDK_SHIFT_MASK) | |
1352 playlistwin_run_dirbrowser(); | |
1353 else if (event->state & GDK_MOD1_MASK) | |
1354 mainwin_show_add_url_window(); | |
1355 else | |
1356 playlistwin_show_filebrowser(); | |
1357 break; | |
226
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1358 case GDK_Left: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1359 case GDK_KP_Left: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1360 case GDK_KP_7: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1361 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
|
1362 bmp_playback_seek(CLAMP |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1363 (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
|
1364 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
|
1365 break; |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1366 case GDK_Right: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1367 case GDK_KP_Right: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1368 case GDK_KP_9: |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1369 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
|
1370 bmp_playback_seek(CLAMP |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1371 (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
|
1372 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
|
1373 break; |
f6ad670bb500
[svn] Make the left and right keys work when the playlist window has focus.
nenolod
parents:
224
diff
changeset
|
1374 |
0 | 1375 case GDK_Escape: |
1376 mainwin_minimize_cb(); | |
1377 break; | |
1378 default: | |
1379 return FALSE; | |
1380 } | |
1381 | |
1382 if (refresh) | |
1383 playlistwin_update_list(); | |
1384 | |
1385 return TRUE; | |
1386 } | |
1387 | |
1388 static void | |
1389 playlistwin_draw_frame(void) | |
1390 { | |
1391 gboolean focus = | |
1392 gtk_window_has_toplevel_focus(GTK_WINDOW(playlistwin)) || | |
1393 !cfg.dim_titlebar; | |
1394 | |
1395 if (cfg.playlist_shaded) { | |
1396 skin_draw_playlistwin_shaded(bmp_active_skin, | |
1397 playlistwin_bg, playlistwin_gc, | |
1398 playlistwin_get_width(), focus); | |
1399 } | |
1400 else { | |
1401 skin_draw_playlistwin_frame(bmp_active_skin, | |
1402 playlistwin_bg, playlistwin_gc, | |
1403 playlistwin_get_width(), | |
1404 cfg.playlist_height, focus); | |
1405 } | |
1406 } | |
1407 | |
1408 void | |
1409 draw_playlist_window(gboolean force) | |
1410 { | |
1411 gboolean redraw; | |
1412 GList *wl; | |
1413 Widget *w; | |
1414 | |
1415 if (force) | |
1416 playlistwin_draw_frame(); | |
1417 | |
1418 widget_list_lock(playlistwin_wlist); | |
1419 widget_list_draw(playlistwin_wlist, &redraw, force); | |
1420 | |
1421 if (redraw || force) { | |
1422 if (force) { | |
1423 gdk_window_clear(playlistwin->window); | |
1424 } | |
1425 else { | |
1426 for (wl = playlistwin_wlist; wl; wl = g_list_next(wl)) { | |
1427 w = WIDGET(wl->data); | |
1428 if (w->redraw && w->visible) { | |
1429 gdk_window_clear_area(playlistwin->window, w->x, w->y, | |
1430 w->width, w->height); | |
1431 w->redraw = FALSE; | |
1432 } | |
1433 } | |
1434 } | |
1435 | |
1436 gdk_flush(); | |
1437 } | |
1438 | |
1439 widget_list_unlock(playlistwin_wlist); | |
1440 } | |
1441 | |
1442 | |
1443 void | |
1444 playlistwin_hide_timer(void) | |
1445 { | |
1446 textbox_set_text(playlistwin_time_min, " "); | |
1447 textbox_set_text(playlistwin_time_sec, " "); | |
1448 } | |
1449 | |
1450 void | |
1451 playlistwin_vis_enable(void) | |
1452 { | |
1453 playlistwin_vis_enabled = TRUE; | |
1454 | |
1455 if (playlistwin_get_width() >= 350) | |
1456 widget_show(WIDGET(playlistwin_vis)); | |
1457 } | |
1458 | |
1459 void | |
1460 playlistwin_vis_disable(void) | |
1461 { | |
1462 playlistwin_vis_enabled = FALSE; | |
1463 widget_hide(WIDGET(playlistwin_vis)); | |
1464 draw_playlist_window(TRUE); | |
1465 } | |
1466 | |
1467 void | |
1468 playlistwin_set_time(gint time, gint length, TimerMode mode) | |
1469 { | |
1470 gchar *text, sign; | |
1471 | |
1472 if (mode == TIMER_REMAINING && length != -1) { | |
1473 time = length - time; | |
1474 sign = '-'; | |
1475 } | |
1476 else | |
1477 sign = ' '; | |
1478 | |
1479 time /= 1000; | |
1480 | |
1481 if (time < 0) | |
1482 time = 0; | |
1483 if (time > 99 * 60) | |
1484 time /= 60; | |
1485 | |
1486 text = g_strdup_printf("%c%-2.2d", sign, time / 60); | |
1487 textbox_set_text(playlistwin_time_min, text); | |
1488 g_free(text); | |
1489 | |
1490 text = g_strdup_printf("%-2.2d", time % 60); | |
1491 textbox_set_text(playlistwin_time_sec, text); | |
1492 g_free(text); | |
1493 } | |
1494 | |
1495 static void | |
1496 playlistwin_drag_motion(GtkWidget * widget, | |
1497 GdkDragContext * context, | |
1498 gint x, gint y, | |
1499 GtkSelectionData * selection_data, | |
1500 guint info, guint time, gpointer user_data) | |
1501 { | |
1502 playlistwin_list->pl_drag_motion = TRUE; | |
1503 playlistwin_list->drag_motion_x = x; | |
1504 playlistwin_list->drag_motion_y = y; | |
1505 playlistwin_update_list(); | |
1506 playlistwin_hint_flag = TRUE; | |
1507 } | |
1508 | |
1509 static void | |
1510 playlistwin_drag_end(GtkWidget * widget, | |
1511 GdkDragContext * context, gpointer user_data) | |
1512 { | |
1513 playlistwin_list->pl_drag_motion = FALSE; | |
1514 playlistwin_hint_flag = FALSE; | |
1515 playlistwin_update_list(); | |
1516 } | |
1517 | |
1518 static void | |
1519 playlistwin_drag_data_received(GtkWidget * widget, | |
1520 GdkDragContext * context, | |
1521 gint x, gint y, | |
1522 GtkSelectionData * | |
1523 selection_data, guint info, | |
1524 guint time, gpointer user_data) | |
1525 { | |
1526 guint pos; | |
1527 | |
1528 g_return_if_fail(selection_data != NULL); | |
1529 | |
1530 if (!selection_data->data) { | |
1531 g_message("Received no DND data!"); | |
1532 return; | |
1533 } | |
1534 | |
1535 if (widget_contains(WIDGET(playlistwin_list), x, y)) { | |
1536 pos = (y - WIDGET(playlistwin_list)->y) / | |
1537 playlistwin_list->pl_fheight + playlistwin_list->pl_first; | |
1538 | |
1539 pos = MIN(pos, playlist_get_length()); | |
1540 playlist_ins_url((gchar *) selection_data->data, pos); | |
1541 } | |
1542 else | |
1543 playlist_add_url((gchar *) selection_data->data); | |
1544 } | |
1545 | |
1546 static void | |
1547 playlistwin_create_widgets(void) | |
1548 { | |
1549 /* This function creates the custom widgets used by the playlist editor */ | |
1550 | |
1551 /* text box for displaying song title in shaded mode */ | |
1552 playlistwin_sinfo = | |
1553 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1554 4, 4, playlistwin_get_width() - 35, FALSE, SKIN_TEXT); | |
1555 | |
1556 if (!cfg.playlist_shaded) | |
1557 widget_hide(WIDGET(playlistwin_sinfo)); | |
1558 | |
1559 /* shade/unshade window push button */ | |
1560 if (cfg.playlist_shaded) | |
1561 playlistwin_shade = | |
1562 create_pbutton(&playlistwin_wlist, playlistwin_bg, | |
1563 playlistwin_gc, playlistwin_get_width() - 21, 3, | |
1564 9, 9, 128, 45, 150, 42, | |
1565 playlistwin_shade_toggle, SKIN_PLEDIT); | |
1566 else | |
1567 playlistwin_shade = | |
1568 create_pbutton(&playlistwin_wlist, playlistwin_bg, | |
1569 playlistwin_gc, playlistwin_get_width() - 21, 3, | |
1570 9, 9, 157, 3, 62, 42, playlistwin_shade_toggle, | |
1571 SKIN_PLEDIT); | |
1572 | |
1573 playlistwin_shade->pb_allow_draw = FALSE; | |
1574 | |
1575 /* close window push button */ | |
1576 playlistwin_close = | |
1577 create_pbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1578 playlistwin_get_width() - 11, 3, 9, 9, | |
1579 cfg.playlist_shaded ? 138 : 167, | |
1580 cfg.playlist_shaded ? 45 : 3, 52, 42, | |
1581 playlistwin_hide, SKIN_PLEDIT); | |
1582 playlistwin_close->pb_allow_draw = FALSE; | |
1583 | |
1584 /* playlist list box */ | |
1585 playlistwin_list = | |
1586 create_playlist_list(&playlistwin_wlist, playlistwin_bg, | |
1587 playlistwin_gc, 12, 20, | |
1588 playlistwin_get_width() - 31, | |
1589 cfg.playlist_height - 58); | |
1590 playlist_list_set_font(cfg.playlist_font); | |
1591 | |
1592 /* playlist list box slider */ | |
1593 playlistwin_slider = | |
1594 create_playlistslider(&playlistwin_wlist, playlistwin_bg, | |
1595 playlistwin_gc, playlistwin_get_width() - 15, | |
1596 20, cfg.playlist_height - 58, playlistwin_list); | |
1597 /* track time (minute) */ | |
1598 playlistwin_time_min = | |
1599 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1600 playlistwin_get_width() - 82, | |
1601 cfg.playlist_height - 15, 15, FALSE, SKIN_TEXT); | |
1602 | |
1603 /* track time (second) */ | |
1604 playlistwin_time_sec = | |
1605 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1606 playlistwin_get_width() - 64, | |
1607 cfg.playlist_height - 15, 10, FALSE, SKIN_TEXT); | |
1608 | |
1609 /* playlist information (current track length / total track length) */ | |
1610 playlistwin_info = | |
1611 create_textbox(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1612 playlistwin_get_width() - 143, | |
1613 cfg.playlist_height - 28, 85, FALSE, SKIN_TEXT); | |
1614 | |
1615 /* mini visualizer */ | |
1616 playlistwin_vis = | |
1617 create_vis(&playlistwin_wlist, playlistwin_bg, playlistwin->window, | |
1618 playlistwin_gc, playlistwin_get_width() - 223, | |
1619 cfg.playlist_height - 26, 72); | |
1620 widget_hide(WIDGET(playlistwin_vis)); | |
1621 | |
1622 /* mini play control buttons at right bottom corner */ | |
1623 | |
1624 /* rewind button */ | |
1625 playlistwin_srew = | |
1626 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1627 playlistwin_get_width() - 144, | |
1628 cfg.playlist_height - 16, 8, 7, playlist_prev); | |
1629 | |
1630 /* play button */ | |
1631 playlistwin_splay = | |
1632 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1633 playlistwin_get_width() - 138, | |
1634 cfg.playlist_height - 16, 10, 7, mainwin_play_pushed); | |
1635 | |
1636 /* pause button */ | |
1637 playlistwin_spause = | |
1638 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1639 playlistwin_get_width() - 128, | |
1640 cfg.playlist_height - 16, 10, 7, bmp_playback_pause); | |
1641 | |
1642 /* stop button */ | |
1643 playlistwin_sstop = | |
1644 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1645 playlistwin_get_width() - 118, | |
1646 cfg.playlist_height - 16, 9, 7, mainwin_stop_pushed); | |
1647 | |
1648 /* forward button */ | |
1649 playlistwin_sfwd = | |
1650 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1651 playlistwin_get_width() - 109, | |
1652 cfg.playlist_height - 16, 8, 7, playlist_next); | |
1653 | |
1654 /* eject button */ | |
1655 playlistwin_seject = | |
1656 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1657 playlistwin_get_width() - 100, | |
1658 cfg.playlist_height - 16, 9, 7, mainwin_eject_pushed); | |
1659 | |
1660 | |
1661 playlistwin_sscroll_up = | |
1662 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1663 playlistwin_get_width() - 14, | |
1664 cfg.playlist_height - 35, 8, 5, | |
1665 playlistwin_scroll_up_pushed); | |
1666 playlistwin_sscroll_down = | |
1667 create_sbutton(&playlistwin_wlist, playlistwin_bg, playlistwin_gc, | |
1668 playlistwin_get_width() - 14, | |
1669 cfg.playlist_height - 30, 8, 5, | |
1670 playlistwin_scroll_down_pushed); | |
1671 | |
1672 } | |
1673 | |
1674 static void | |
1675 selection_received(GtkWidget * widget, | |
1676 GtkSelectionData * selection_data, gpointer data) | |
1677 { | |
1678 if (selection_data->type == GDK_SELECTION_TYPE_STRING && | |
1679 selection_data->length > 0) | |
1680 playlist_add_url((gchar *) selection_data->data); | |
1681 } | |
1682 | |
1683 static void | |
1684 playlistwin_create_window(void) | |
1685 { | |
1686 GdkPixbuf *icon; | |
1687 | |
1688 playlistwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
187 | 1689 gtk_window_set_title(GTK_WINDOW(playlistwin), _("Audacious Playlist Editor")); |
0 | 1690 gtk_window_set_role(GTK_WINDOW(playlistwin), "playlist"); |
1691 gtk_window_set_default_size(GTK_WINDOW(playlistwin), | |
1692 playlistwin_get_width(), | |
1693 playlistwin_get_height()); | |
1694 gtk_window_set_resizable(GTK_WINDOW(playlistwin), TRUE); | |
1695 playlistwin_set_geometry_hints(cfg.playlist_shaded); | |
1696 dock_window_list = dock_window_set_decorated(dock_window_list, | |
1697 GTK_WINDOW(playlistwin), | |
1698 cfg.show_wm_decorations); | |
1699 | |
1700 gtk_window_set_transient_for(GTK_WINDOW(playlistwin), | |
1701 GTK_WINDOW(mainwin)); | |
1702 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(playlistwin), TRUE); | |
1703 | |
1704 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) bmp_playlist_icon); | |
1705 gtk_window_set_icon(GTK_WINDOW(playlistwin), icon); | |
1706 g_object_unref(icon); | |
1707 | |
1708 gtk_widget_set_app_paintable(playlistwin, TRUE); | |
1709 | |
1710 if (cfg.playlist_x != -1 && cfg.save_window_position) | |
1711 gtk_window_move(GTK_WINDOW(playlistwin), | |
1712 cfg.playlist_x, cfg.playlist_y); | |
1713 | |
1714 gtk_widget_add_events(playlistwin, | |
1715 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
1716 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1717 GDK_SCROLL_MASK | GDK_VISIBILITY_NOTIFY_MASK); | |
1718 gtk_widget_realize(playlistwin); | |
1719 | |
1720 util_set_cursor(playlistwin); | |
1721 | |
1722 g_signal_connect(playlistwin, "delete_event", | |
1723 G_CALLBACK(playlistwin_delete), NULL); | |
1724 g_signal_connect(playlistwin, "button_press_event", | |
1725 G_CALLBACK(playlistwin_press), NULL); | |
1726 g_signal_connect(playlistwin, "button_release_event", | |
1727 G_CALLBACK(playlistwin_release), NULL); | |
1728 g_signal_connect(playlistwin, "scroll_event", | |
1729 G_CALLBACK(playlistwin_scrolled), NULL); | |
1730 g_signal_connect(playlistwin, "motion_notify_event", | |
1731 G_CALLBACK(playlistwin_motion), NULL); | |
1732 g_signal_connect_after(playlistwin, "focus_in_event", | |
1733 G_CALLBACK(playlistwin_focus_in), NULL); | |
1734 g_signal_connect_after(playlistwin, "focus_out_event", | |
1735 G_CALLBACK(playlistwin_focus_out), NULL); | |
1736 g_signal_connect(playlistwin, "configure_event", | |
1737 G_CALLBACK(playlistwin_configure), NULL); | |
1738 g_signal_connect(playlistwin, "style_set", | |
1739 G_CALLBACK(playlistwin_set_back_pixmap), NULL); | |
1740 | |
1741 bmp_drag_dest_set(playlistwin); | |
1742 | |
1743 /* DnD stuff */ | |
1744 g_signal_connect(playlistwin, "drag-leave", | |
1745 G_CALLBACK(playlistwin_drag_end), NULL); | |
1746 g_signal_connect(playlistwin, "drag-data-delete", | |
1747 G_CALLBACK(playlistwin_drag_end), NULL); | |
1748 g_signal_connect(playlistwin, "drag-end", | |
1749 G_CALLBACK(playlistwin_drag_end), NULL); | |
1750 g_signal_connect(playlistwin, "drag-drop", | |
1751 G_CALLBACK(playlistwin_drag_end), NULL); | |
1752 g_signal_connect(playlistwin, "drag-data-received", | |
1753 G_CALLBACK(playlistwin_drag_data_received), NULL); | |
1754 g_signal_connect(playlistwin, "drag-motion", | |
1755 G_CALLBACK(playlistwin_drag_motion), NULL); | |
1756 | |
1757 g_signal_connect(playlistwin, "key_press_event", | |
1758 G_CALLBACK(playlistwin_keypress), NULL); | |
1759 g_signal_connect(playlistwin, "selection_received", | |
1760 G_CALLBACK(selection_received), NULL); | |
1761 | |
1762 playlistwin_set_mask(); | |
1763 } | |
1764 | |
1765 void | |
1766 playlistwin_create_popup_menus(void) | |
1767 { | |
1768 playlistwin_accel = gtk_accel_group_new(); | |
1769 | |
1770 /* playlist window popup menu */ | |
1771 playlistwin_popup_menu = create_menu(playlistwin_popup_menu_entries, | |
1772 G_N_ELEMENTS(playlistwin_popup_menu_entries), | |
1773 playlistwin_accel); | |
1774 | |
1775 pladd_menu = create_menu(pladd_menu_entries, G_N_ELEMENTS(pladd_menu_entries), | |
1776 playlistwin_accel); | |
1777 pldel_menu = create_menu(pldel_menu_entries, G_N_ELEMENTS(pldel_menu_entries), | |
1778 playlistwin_accel); | |
1779 plsel_menu = create_menu(plsel_menu_entries, G_N_ELEMENTS(plsel_menu_entries), | |
1780 playlistwin_accel); | |
1781 plsort_menu = create_menu(plsort_menu_entries, | |
1782 G_N_ELEMENTS(plsort_menu_entries), | |
1783 playlistwin_accel); | |
1784 pllist_menu = create_menu(pllist_menu_entries, G_N_ELEMENTS(pllist_menu_entries), | |
1785 playlistwin_accel); | |
1786 | |
1787 #if 0 | |
1788 make_submenu(playlistwin_popup_menu, "/Playlist", | |
1789 playlistwin_playlist_menu); | |
1790 make_submenu(playlistwin_popup_menu, "/Playback", | |
1791 playlistwin_playback_menu); | |
1792 make_submenu(playlistwin_popup_menu, "/Add", | |
1793 pladd_menu); | |
1794 #endif | |
1795 } | |
1796 | |
1797 void | |
1798 playlistwin_create(void) | |
1799 { | |
1800 playlistwin_create_window(); | |
1801 playlistwin_create_popup_menus(); | |
1802 | |
1803 /* create GC and back pixmap for custom widget to draw on */ | |
1804 playlistwin_gc = gdk_gc_new(playlistwin->window); | |
1805 playlistwin_bg = gdk_pixmap_new(playlistwin->window, | |
1806 playlistwin_get_width(), | |
1807 playlistwin_get_height_unshaded(), -1); | |
1808 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
1809 | |
1810 playlistwin_create_widgets(); | |
1811 playlistwin_update_info(); | |
1812 | |
1813 gtk_window_add_accel_group(GTK_WINDOW(playlistwin), playlistwin_accel); | |
1814 gtk_window_add_accel_group(GTK_WINDOW(playlistwin), mainwin_accel); | |
1815 } | |
1816 | |
1817 | |
1818 void | |
1819 playlistwin_show(void) | |
1820 { | |
1821 GtkWidget *item; | |
1822 | |
1823 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
1824 "/Show Playlist Editor"); | |
1825 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); | |
1826 | |
1827 tbutton_set_toggled(mainwin_pl, TRUE); | |
1828 cfg.playlist_visible = TRUE; | |
1829 | |
1830 playlistwin_set_toprow(0); | |
1831 playlist_check_pos_current(); | |
1832 | |
1833 gtk_widget_show(playlistwin); | |
1834 } | |
1835 | |
1836 void | |
1837 playlistwin_hide(void) | |
1838 { | |
1839 GtkWidget *item; | |
1840 | |
1841 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
1842 "/Show Playlist Editor"); | |
1843 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE); | |
1844 | |
1845 gtk_widget_hide(playlistwin); | |
1846 tbutton_set_toggled(mainwin_pl, FALSE); | |
1847 cfg.playlist_visible = FALSE; | |
1848 | |
1849 gtk_window_present(GTK_WINDOW(mainwin)); | |
1850 gtk_widget_grab_focus(mainwin); | |
1851 } | |
1852 | |
1853 | |
1854 static void | |
1855 plsort_menu_callback(gpointer data, | |
1856 guint action, | |
1857 GtkWidget * widget) | |
1858 { | |
1859 switch (action) { | |
1860 case PLAYLISTWIN_SORT_BYTITLE: | |
1861 playlist_sort(PLAYLIST_SORT_TITLE); | |
1862 playlistwin_update_list(); | |
1863 break; | |
1864 case PLAYLISTWIN_SORT_BYPATH: | |
1865 playlist_sort(PLAYLIST_SORT_PATH); | |
1866 playlistwin_update_list(); | |
1867 break; | |
1868 case PLAYLISTWIN_SORT_BYDATE: | |
1869 playlist_sort(PLAYLIST_SORT_DATE); | |
1870 playlistwin_update_list(); | |
1871 break; | |
1872 case PLAYLISTWIN_SORT_BYFILENAME: | |
1873 playlist_sort(PLAYLIST_SORT_FILENAME); | |
1874 playlistwin_update_list(); | |
1875 break; | |
1876 case PLAYLISTWIN_SORT_SEL_BYTITLE: | |
1877 playlist_sort_selected(PLAYLIST_SORT_TITLE); | |
1878 playlistwin_update_list(); | |
1879 break; | |
1880 case PLAYLISTWIN_SORT_SEL_BYFILENAME: | |
1881 playlist_sort_selected(PLAYLIST_SORT_FILENAME); | |
1882 playlistwin_update_list(); | |
1883 break; | |
1884 case PLAYLISTWIN_SORT_SEL_BYPATH: | |
1885 playlist_sort_selected(PLAYLIST_SORT_PATH); | |
1886 playlistwin_update_list(); | |
1887 break; | |
1888 case PLAYLISTWIN_SORT_SEL_BYDATE: | |
1889 playlist_sort_selected(PLAYLIST_SORT_DATE); | |
1890 playlistwin_update_list(); | |
1891 break; | |
1892 case PLAYLISTWIN_SORT_REVERSE: | |
1893 playlist_reverse(); | |
1894 playlistwin_update_list(); | |
1895 break; | |
1896 case PLAYLISTWIN_SORT_RANDOMIZE: | |
1897 playlist_random(); | |
1898 playlistwin_update_list(); | |
1899 break; | |
1900 } | |
1901 } | |
1902 | |
1903 static void | |
1904 playlistwin_sub_menu_callback(gpointer data, | |
1905 guint action, | |
1906 GtkWidget * widget) | |
1907 { | |
1908 switch (action) { | |
1909 case PLIST_NEW: | |
1910 playlist_set_current_name(NULL); | |
1911 playlist_clear(); | |
1912 mainwin_clear_song_info(); | |
1913 mainwin_set_info_text(); | |
1914 break; | |
1915 case PLIST_SAVE: | |
1916 playlistwin_select_playlist_to_save(playlist_get_current_name()); | |
1917 break; | |
1918 case PLIST_SAVE_AS: | |
1919 playlistwin_select_playlist_to_save(playlist_get_current_name()); | |
1920 break; | |
1921 case PLIST_LOAD: | |
1922 playlistwin_select_playlist_to_load(playlist_get_current_name()); | |
1923 break; | |
1924 case SEL_INV: | |
1925 playlistwin_inverse_selection(); | |
1926 break; | |
1927 case SEL_ZERO: | |
1928 playlistwin_select_none(); | |
1929 break; | |
1930 case SEL_ALL: | |
1931 playlistwin_select_all(); | |
1932 break; | |
1933 case SUB_ALL: | |
1934 playlist_clear(); | |
1935 mainwin_clear_song_info(); | |
1936 mainwin_set_info_text(); | |
1937 break; | |
1938 case SUB_CROP: | |
1939 playlist_delete(TRUE); | |
1940 break; | |
1941 case SUB_SELECTED: | |
1942 playlist_delete(FALSE); | |
1943 break; | |
1944 case PLAYLISTWIN_REMOVE_DEAD_FILES: | |
1945 playlist_remove_dead_files(); | |
1946 break; | |
1947 case PLAYLISTWIN_REFRESH: | |
1948 playlist_read_info_selection(); | |
1949 playlistwin_update_list(); | |
1950 break; | |
1951 } | |
1952 } | |
1953 | |
1954 static void | |
1955 playlistwin_popup_menu_callback(gpointer data, | |
1956 guint action, | |
1957 GtkWidget * widget) | |
1958 { | |
1959 switch (action) { | |
1960 case ADD_FILES: | |
1961 playlistwin_show_filebrowser(); | |
1962 break; | |
1963 case ADD_DIR: | |
1964 playlistwin_run_dirbrowser(); | |
1965 break; | |
1966 case CLOSE_PL_WINDOW: | |
1967 playlistwin_hide(); | |
1968 break; | |
1969 case MISC_FILEINFO: | |
1970 playlistwin_fileinfo(); | |
1971 break; | |
1972 case SEL_LOOKUP: | |
1973 playlist_read_info_selection(); | |
1974 break; | |
1975 case MISC_QUEUE: | |
1976 playlist_queue(); | |
1977 break; | |
1978 case PLIST_CQUEUE: | |
1979 playlist_clear_queue(); | |
1980 break; | |
1981 case PLIST_JTT: | |
1982 mainwin_jump_to_time(); | |
1983 break; | |
1984 case PLIST_JTF: | |
1985 mainwin_jump_to_file(); | |
1986 break; | |
1987 } | |
1988 } |