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