Mercurial > audlegacy
annotate audacious/playlistwin.c @ 88:db2d1d193e56 trunk
[svn] Fix the missing separator in the playback menu. (oops)
author | nenolod |
---|---|
date | Tue, 01 Nov 2005 00:11:27 -0800 |
parents | 38ddde5b0f13 |
children | 2309d450ed2d |
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" | |
58 #include "images/bmp_playlist.xpm" | |
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 | |
117 static void plsort_menu_callback(gpointer cb_data, guint action, | |
118 GtkWidget * w); | |
119 static void playlistwin_sub_menu_callback(gpointer cb_data, guint action, | |
120 GtkWidget * w); | |
121 static void playlistwin_popup_menu_callback(gpointer cb_data, guint action, | |
122 GtkWidget * w); | |
123 | |
124 static GtkItemFactoryEntry playlistwin_popup_menu_entries[] = { | |
125 {N_("/View Track Details"), NULL, | |
126 playlistwin_popup_menu_callback, | |
127 MISC_FILEINFO, "<ImageItem>", my_pixbuf}, | |
128 | |
129 ITEM_SEPARATOR, | |
130 | |
131 {N_("/Remove Selected"), "Delete", | |
132 playlistwin_sub_menu_callback, | |
133 SUB_SELECTED, "<Item>", GTK_STOCK_DELETE}, | |
134 | |
135 {N_("/Remove Unselected"), NULL, | |
136 playlistwin_sub_menu_callback, | |
137 SUB_CROP, "<Item>", GTK_STOCK_CUT}, | |
138 | |
139 {N_("/Remove All"), NULL, | |
140 playlistwin_sub_menu_callback, | |
141 SUB_ALL, "<Item>", GTK_STOCK_DELETE}, | |
142 | |
143 ITEM_SEPARATOR, | |
144 | |
145 {N_("/Queue Toggle"), "q", | |
146 playlistwin_popup_menu_callback, | |
147 MISC_QUEUE, "<Item>", NULL}, | |
148 }; | |
149 | |
150 static GtkItemFactoryEntry pladd_menu_entries[] = { | |
151 {N_("/Add CD..."), "<shift>c", | |
152 mainwin_general_menu_callback, | |
153 MAINWIN_GENERAL_ADDCD, "<StockItem>", GTK_STOCK_CDROM}, | |
154 | |
155 {N_("/Add Internet Address..."), "<control>h", | |
156 mainwin_general_menu_callback, | |
157 MAINWIN_GENERAL_PLAYLOCATION, "<StockItem>", GTK_STOCK_NETWORK}, | |
158 | |
159 /* GtkFileChooser in SELECT_FOLDER mode is currently BROKEN! */ | |
160 #if 0 | |
161 {N_("/Add Folders..."), "d", | |
162 mainwin_general_menu_callback, | |
163 MAINWIN_GENERAL_PLAYDIRECTORY, "<StockItem>", GTK_STOCK_OPEN}, | |
164 #endif | |
165 | |
166 {N_("/Add Files..."), "f", | |
167 mainwin_general_menu_callback, | |
168 MAINWIN_GENERAL_PLAYFILE, "<StockItem>", GTK_STOCK_OPEN}, | |
169 }; | |
170 | |
171 static GtkItemFactoryEntry pldel_menu_entries[] = { | |
172 {N_("/Clear Queue"), "<shift>Q", | |
173 playlistwin_popup_menu_callback, | |
174 PLIST_CQUEUE, "<Item>"}, | |
175 | |
176 ITEM_SEPARATOR, | |
177 | |
178 {N_("/Remove Unavailable Files"), NULL, | |
179 playlistwin_sub_menu_callback, | |
180 PLAYLISTWIN_REMOVE_DEAD_FILES, "<Item>", GTK_STOCK_DELETE}, | |
181 | |
182 ITEM_SEPARATOR, | |
183 | |
184 {N_("/Remove All"), NULL, | |
185 playlistwin_sub_menu_callback, | |
186 SUB_ALL, "<Item>", GTK_STOCK_DELETE}, | |
187 | |
188 {N_("/Remove Unselected"), NULL, | |
189 playlistwin_sub_menu_callback, | |
190 SUB_CROP, "<Item>", GTK_STOCK_DELETE}, | |
191 | |
192 {N_("/Remove Selected"), "Delete", | |
193 playlistwin_sub_menu_callback, | |
194 SUB_SELECTED, "<Item>", GTK_STOCK_DELETE} | |
195 }; | |
196 | |
197 static GtkItemFactoryEntry pllist_menu_entries[] = { | |
198 {N_("/New List"), NULL, | |
199 playlistwin_sub_menu_callback, | |
200 PLIST_NEW, "<StockItem>", GTK_STOCK_NEW}, | |
201 | |
202 ITEM_SEPARATOR, | |
203 | |
204 {N_("/Load List"), "o", | |
205 playlistwin_sub_menu_callback, | |
206 PLIST_LOAD, "<StockItem>", GTK_STOCK_OPEN}, | |
207 | |
208 {N_("/Save List"), "s", | |
209 playlistwin_sub_menu_callback, | |
210 PLIST_SAVE, "<StockItem>", GTK_STOCK_SAVE}, | |
211 | |
212 ITEM_SEPARATOR, | |
213 | |
214 {N_("/Update View"), "F5", | |
215 playlistwin_sub_menu_callback, | |
216 PLAYLISTWIN_REFRESH, "<StockItem>", GTK_STOCK_REFRESH} | |
217 }; | |
218 | |
219 static GtkItemFactoryEntry plsel_menu_entries[] = { | |
220 {N_("/Invert Selection"), NULL, | |
221 playlistwin_sub_menu_callback, | |
222 SEL_INV, "<Item>", GTK_STOCK_NETWORK}, | |
223 | |
224 ITEM_SEPARATOR, | |
225 | |
226 {N_("/Select None"),"<Ctrl><Shift>A", | |
227 playlistwin_sub_menu_callback, | |
228 SEL_ZERO, "<Item>", GTK_STOCK_OPEN}, | |
229 | |
230 {N_("/Select All"), "<Ctrl>A", | |
231 playlistwin_sub_menu_callback, | |
232 SEL_ALL, "<Item>", GTK_STOCK_OPEN}, | |
233 }; | |
234 | |
235 static GtkItemFactoryEntry plsort_menu_entries[] = { | |
236 {N_("/Randomize List"), NULL, plsort_menu_callback, | |
237 PLAYLISTWIN_SORT_RANDOMIZE, "<Item>"}, | |
238 {N_("/Reverse List"), NULL, plsort_menu_callback, | |
239 PLAYLISTWIN_SORT_REVERSE, "<Item>"}, | |
240 ITEM_SEPARATOR, | |
241 {N_("/Sort List"), NULL, NULL, 0, "<Branch>"}, | |
242 {N_("/Sort List/By Title"), NULL, plsort_menu_callback, | |
243 PLAYLISTWIN_SORT_BYTITLE, "<Item>"}, | |
244 {N_("/Sort List/By Filename"), NULL, plsort_menu_callback, | |
245 PLAYLISTWIN_SORT_BYFILENAME, "<Item>"}, | |
246 {N_("/Sort List/By Path + Filename"), NULL, plsort_menu_callback, | |
247 PLAYLISTWIN_SORT_BYPATH, "<Item>"}, | |
248 {N_("/Sort List/By Date"), NULL, plsort_menu_callback, | |
249 PLAYLISTWIN_SORT_BYDATE, "<Item>"}, | |
250 {N_("/Sort Selection"), NULL, NULL, 0, "<Branch>"}, | |
251 {N_("/Sort Selection/By Title"), NULL, plsort_menu_callback, | |
252 PLAYLISTWIN_SORT_SEL_BYTITLE, "<Item>"}, | |
253 {N_("/Sort Selection/By Filename"), NULL, plsort_menu_callback, | |
254 PLAYLISTWIN_SORT_SEL_BYFILENAME, "<Item>"}, | |
255 {N_("/Sort Selection/By Path + Filename"), NULL, plsort_menu_callback, | |
256 PLAYLISTWIN_SORT_SEL_BYPATH, "<Item>"}, | |
257 {N_("/Sort Selection/By Date"), NULL, plsort_menu_callback, | |
258 PLAYLISTWIN_SORT_SEL_BYDATE, "<Item>"} | |
259 }; | |
260 | |
261 | |
262 static void playlistwin_draw_frame(void); | |
263 | |
264 | |
265 gboolean | |
266 playlistwin_is_shaded(void) | |
267 { | |
268 return cfg.playlist_shaded; | |
269 } | |
270 | |
271 gint | |
272 playlistwin_get_width(void) | |
273 { | |
274 return cfg.playlist_width; | |
275 } | |
276 | |
277 gint | |
278 playlistwin_get_height_unshaded(void) | |
279 { | |
280 gint height = cfg.playlist_height; | |
281 return height; | |
282 } | |
283 | |
284 gint | |
285 playlistwin_get_height_shaded(void) | |
286 { | |
287 return PLAYLISTWIN_SHADED_HEIGHT; | |
288 } | |
289 | |
290 gint | |
291 playlistwin_get_height(void) | |
292 { | |
293 if (playlistwin_is_shaded()) | |
294 return playlistwin_get_height_shaded(); | |
295 else | |
296 return playlistwin_get_height_unshaded(); | |
297 } | |
298 | |
299 void | |
300 playlistwin_get_size(gint * width, gint * height) | |
301 { | |
302 if (width) | |
303 *width = playlistwin_get_width(); | |
304 | |
305 if (height) | |
306 *height = playlistwin_get_height(); | |
307 } | |
308 | |
309 static void | |
310 playlistwin_update_info(void) | |
311 { | |
312 gchar *text, *sel_text, *tot_text; | |
313 gulong selection, total; | |
314 gboolean selection_more, total_more; | |
315 | |
316 playlist_get_total_time(&total, &selection, &total_more, &selection_more); | |
317 | |
318 if (selection > 0 || (selection == 0 && !selection_more)) { | |
319 if (selection > 3600) | |
320 sel_text = | |
321 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", selection / 3600, | |
322 (selection / 60) % 60, selection % 60, | |
323 (selection_more ? "+" : "")); | |
324 else | |
325 sel_text = | |
326 g_strdup_printf("%lu:%-2.2lu%s", selection / 60, | |
327 selection % 60, (selection_more ? "+" : "")); | |
328 } | |
329 else | |
330 sel_text = g_strdup("?"); | |
331 if (total > 0 || (total == 0 && !total_more)) { | |
332 if (total > 3600) | |
333 tot_text = | |
334 g_strdup_printf("%lu:%-2.2lu:%-2.2lu%s", total / 3600, | |
335 (total / 60) % 60, total % 60, | |
336 total_more ? "+" : ""); | |
337 else | |
338 tot_text = | |
339 g_strdup_printf("%lu:%-2.2lu%s", total / 60, total % 60, | |
340 total_more ? "+" : ""); | |
341 } | |
342 else | |
343 tot_text = g_strdup("?"); | |
344 text = g_strconcat(sel_text, "/", tot_text, NULL); | |
345 textbox_set_text(playlistwin_info, text); | |
346 g_free(text); | |
347 g_free(tot_text); | |
348 g_free(sel_text); | |
349 } | |
350 | |
351 static void | |
352 playlistwin_update_sinfo(void) | |
353 { | |
354 gchar *posstr, *timestr, *title, *info, *dots; | |
355 gint pos, time, max_len; | |
356 | |
357 pos = playlist_get_position(); | |
358 title = playlist_get_songtitle(pos); | |
359 time = playlist_get_songtime(pos); | |
360 | |
361 if (!title) { | |
362 textbox_set_text(playlistwin_sinfo, ""); | |
363 return; | |
364 } | |
365 | |
366 if (cfg.show_numbers_in_pl) | |
367 posstr = g_strdup_printf("%d. ", pos + 1); | |
368 else | |
369 posstr = g_strdup(""); | |
370 | |
371 max_len = (playlistwin_get_width() - 35) / 5 - strlen(posstr); | |
372 | |
373 if (time != -1) { | |
374 timestr = g_strdup_printf(" %d:%-2.2d", time / 60000, | |
375 (time / 1000) % 60); | |
376 max_len -= strlen(timestr); | |
377 } | |
378 else | |
379 timestr = g_strdup(""); | |
380 | |
381 convert_title_text(title); | |
382 | |
383 if (strlen(title) > max_len) { | |
384 max_len -= 3; | |
385 dots = "..."; | |
386 } | |
387 else | |
388 dots = ""; | |
389 | |
390 info = g_strdup_printf("%s%-*.*s%s%s", posstr, max_len, max_len, | |
391 title, dots, timestr); | |
392 g_free(posstr); | |
393 g_free(title); | |
394 g_free(timestr); | |
395 | |
396 textbox_set_text(playlistwin_sinfo, info); | |
397 g_free(info); | |
398 } | |
399 | |
400 gboolean | |
401 playlistwin_item_visible(gint index) | |
402 { | |
403 if (index >= playlistwin_list->pl_first | |
404 && index < | |
405 (playlistwin_list->pl_first + playlistwin_list->pl_num_visible)) | |
406 return TRUE; | |
407 return FALSE; | |
408 } | |
409 | |
410 gint | |
411 playlistwin_get_toprow(void) | |
412 { | |
413 if (playlistwin_list) | |
414 return (playlistwin_list->pl_first); | |
415 return (-1); | |
416 } | |
417 | |
418 void | |
419 playlistwin_set_toprow(gint toprow) | |
420 { | |
421 if (playlistwin_list) | |
422 playlistwin_list->pl_first = toprow; | |
423 playlistwin_update_list(); | |
424 } | |
425 | |
426 void | |
427 playlistwin_update_list(void) | |
428 { | |
429 g_return_if_fail(playlistwin_list != NULL); | |
430 | |
431 widget_draw(WIDGET(playlistwin_list)); | |
432 widget_draw(WIDGET(playlistwin_slider)); | |
433 playlistwin_update_info(); | |
434 playlistwin_update_sinfo(); | |
435 /* mainwin_update_jtf(); */ | |
436 } | |
437 | |
438 #if 0 | |
439 static void | |
440 playlistwin_redraw_list(void) | |
441 { | |
442 g_return_if_fail(playlistwin_list != NULL); | |
443 | |
444 draw_widget(playlistwin_list); | |
445 draw_widget(playlistwin_slider); | |
446 } | |
447 #endif | |
448 | |
449 static void | |
450 playlistwin_set_mask(void) | |
451 { | |
452 GdkGC *gc; | |
453 GdkColor pattern; | |
454 | |
455 if (playlistwin_mask) | |
456 g_object_unref(playlistwin_mask); | |
457 | |
458 playlistwin_mask = | |
459 gdk_pixmap_new(playlistwin->window, playlistwin_get_width(), | |
460 playlistwin_get_height(), 1); | |
461 gc = gdk_gc_new(playlistwin_mask); | |
462 pattern.pixel = 1; | |
463 gdk_gc_set_foreground(gc, &pattern); | |
464 gdk_draw_rectangle(playlistwin_mask, gc, TRUE, 0, 0, | |
465 playlistwin_get_width(), playlistwin_get_height()); | |
466 gdk_gc_destroy(gc); | |
467 | |
468 gtk_widget_shape_combine_mask(playlistwin, playlistwin_mask, 0, 0); | |
469 } | |
470 | |
471 static void | |
472 playlistwin_set_geometry_hints(gboolean shaded) | |
473 { | |
474 GdkGeometry geometry; | |
475 GdkWindowHints mask; | |
476 | |
477 geometry.min_width = PLAYLISTWIN_MIN_WIDTH; | |
478 geometry.max_width = G_MAXUINT16; | |
479 geometry.base_width = cfg.playlist_width; | |
480 | |
481 geometry.width_inc = PLAYLISTWIN_WIDTH_SNAP; | |
482 geometry.height_inc = PLAYLISTWIN_HEIGHT_SNAP; | |
483 | |
484 if (shaded) { | |
485 geometry.min_height = PLAYLISTWIN_SHADED_HEIGHT; | |
486 geometry.max_height = PLAYLISTWIN_SHADED_HEIGHT; | |
487 geometry.base_height = PLAYLISTWIN_SHADED_HEIGHT; | |
488 } | |
489 else { | |
490 geometry.min_height = PLAYLISTWIN_MIN_HEIGHT; | |
491 geometry.max_height = G_MAXUINT16; | |
492 geometry.base_height = cfg.playlist_height; | |
493 } | |
494 | |
495 mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_RESIZE_INC | | |
496 GDK_HINT_BASE_SIZE; | |
497 | |
498 gtk_window_set_geometry_hints(GTK_WINDOW(playlistwin), | |
499 playlistwin, &geometry, mask); | |
500 } | |
501 | |
502 void | |
503 playlistwin_set_shade(gboolean shaded) | |
504 { | |
505 if (cfg.playlist_shaded == shaded) | |
506 return; | |
507 | |
508 cfg.playlist_shaded = shaded; | |
509 | |
510 if (shaded) { | |
511 widget_show(WIDGET(playlistwin_sinfo)); | |
512 playlistwin_shade->pb_nx = 128; | |
513 playlistwin_shade->pb_ny = 45; | |
514 playlistwin_shade->pb_px = 150; | |
515 playlistwin_shade->pb_py = 42; | |
516 playlistwin_close->pb_nx = 138; | |
517 playlistwin_close->pb_ny = 45; | |
518 } | |
519 else { | |
520 widget_hide(WIDGET(playlistwin_sinfo)); | |
521 playlistwin_shade->pb_nx = 157; | |
522 playlistwin_shade->pb_ny = 3; | |
523 playlistwin_shade->pb_px = 62; | |
524 playlistwin_shade->pb_py = 42; | |
525 playlistwin_close->pb_nx = 167; | |
526 playlistwin_close->pb_ny = 3; | |
527 } | |
528 | |
529 dock_shade(dock_window_list, GTK_WINDOW(playlistwin), | |
530 playlistwin_get_height()); | |
531 | |
532 playlistwin_set_geometry_hints(cfg.playlist_shaded); | |
533 | |
534 gtk_window_resize(GTK_WINDOW(playlistwin), | |
535 cfg.playlist_width, | |
536 playlistwin_get_height()); | |
537 | |
79
38ddde5b0f13
[svn] Fix #129 by using playlistwin_set_mask() in playlistwin_set_shade()
msameer
parents:
0
diff
changeset
|
538 /* This is a fix for #129 */ |
38ddde5b0f13
[svn] Fix #129 by using playlistwin_set_mask() in playlistwin_set_shade()
msameer
parents:
0
diff
changeset
|
539 /* No idea, But it works! */ |
38ddde5b0f13
[svn] Fix #129 by using playlistwin_set_mask() in playlistwin_set_shade()
msameer
parents:
0
diff
changeset
|
540 playlistwin_set_mask(); |
38ddde5b0f13
[svn] Fix #129 by using playlistwin_set_mask() in playlistwin_set_shade()
msameer
parents:
0
diff
changeset
|
541 |
0 | 542 draw_playlist_window(TRUE); |
543 } | |
544 | |
545 static void | |
546 playlistwin_set_shade_menu(gboolean shaded) | |
547 { | |
548 GtkWidget *item; | |
549 | |
550 item = gtk_item_factory_get_widget(mainwin_view_menu, | |
551 "/Roll up Playlist Editor"); | |
552 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), shaded); | |
553 | |
554 playlistwin_set_shade(shaded); | |
555 } | |
556 | |
557 void | |
558 playlistwin_shade_toggle(void) | |
559 { | |
560 playlistwin_set_shade_menu(!cfg.playlist_shaded); | |
561 } | |
562 | |
563 static void | |
564 playlistwin_release(GtkWidget * widget, | |
565 GdkEventButton * event, | |
566 gpointer callback_data) | |
567 { | |
568 if (event->button == 3) | |
569 return; | |
570 | |
571 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
572 playlistwin_resizing = FALSE; | |
573 gdk_flush(); | |
574 | |
575 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
576 dock_move_release(GTK_WINDOW(playlistwin)); | |
577 #if 0 | |
578 if (cfg.playlist_transparent) | |
579 playlistwin_update_list(); | |
580 #endif | |
581 } | |
582 else { | |
583 handle_release_cb(playlistwin_wlist, widget, event); | |
584 playlist_popup_destroy(); | |
585 draw_playlist_window(FALSE); | |
586 } | |
587 } | |
588 | |
589 void | |
590 playlistwin_scroll(gint num) | |
591 { | |
592 playlistwin_list->pl_first += num; | |
593 playlistwin_update_list(); | |
594 } | |
595 | |
596 void | |
597 playlistwin_scroll_up_pushed(void) | |
598 { | |
599 playlistwin_list->pl_first -= 3; | |
600 playlistwin_update_list(); | |
601 } | |
602 | |
603 void | |
604 playlistwin_scroll_down_pushed(void) | |
605 { | |
606 playlistwin_list->pl_first += 3; | |
607 playlistwin_update_list(); | |
608 } | |
609 | |
610 static void | |
611 playlistwin_select_all(void) | |
612 { | |
613 playlist_select_all(TRUE); | |
614 playlistwin_list->pl_prev_selected = 0; | |
615 playlistwin_list->pl_prev_min = 0; | |
616 playlistwin_list->pl_prev_max = playlist_get_length() - 1; | |
617 playlistwin_update_list(); | |
618 } | |
619 | |
620 static void | |
621 playlistwin_select_none(void) | |
622 { | |
623 playlist_select_all(FALSE); | |
624 playlistwin_list->pl_prev_selected = -1; | |
625 playlistwin_list->pl_prev_min = -1; | |
626 playlistwin_update_list(); | |
627 } | |
628 | |
629 static void | |
630 playlistwin_inverse_selection(void) | |
631 { | |
632 playlist_select_invert_all(); | |
633 playlistwin_list->pl_prev_selected = -1; | |
634 playlistwin_list->pl_prev_min = -1; | |
635 playlistwin_update_list(); | |
636 } | |
637 | |
638 static void | |
639 playlistwin_resize(gint width, gint height) | |
640 { | |
641 gboolean redraw; | |
642 | |
643 g_return_if_fail(width > 0 && height > 0); | |
644 | |
645 cfg.playlist_width = width; | |
646 | |
647 if (!cfg.playlist_shaded) | |
648 cfg.playlist_height = height; | |
649 else | |
650 height = cfg.playlist_height; | |
651 | |
652 /* FIXME: why the fsck are we doing this manually? */ | |
653 /* adjust widget positions and sizes */ | |
654 | |
655 widget_resize(WIDGET(playlistwin_list), width - 31, height - 58); | |
656 | |
657 widget_move(WIDGET(playlistwin_slider), width - 15, 20); | |
658 widget_resize(WIDGET(playlistwin_slider), 8, height - 58); | |
659 | |
660 widget_resize(WIDGET(playlistwin_sinfo), width - 35, 14); | |
661 playlistwin_update_sinfo(); | |
662 | |
663 widget_move(WIDGET(playlistwin_shade), width - 21, 3); | |
664 widget_move(WIDGET(playlistwin_close), width - 11, 3); | |
665 widget_move(WIDGET(playlistwin_time_min), width - 82, height - 15); | |
666 widget_move(WIDGET(playlistwin_time_sec), width - 64, height - 15); | |
667 widget_move(WIDGET(playlistwin_info), width - 143, height - 28); | |
668 widget_move(WIDGET(playlistwin_srew), width - 144, height - 16); | |
669 widget_move(WIDGET(playlistwin_splay), width - 138, height - 16); | |
670 widget_move(WIDGET(playlistwin_spause), width - 128, height - 16); | |
671 widget_move(WIDGET(playlistwin_sstop), width - 118, height - 16); | |
672 widget_move(WIDGET(playlistwin_sfwd), width - 109, height - 16); | |
673 widget_move(WIDGET(playlistwin_seject), width - 100, height - 16); | |
674 widget_move(WIDGET(playlistwin_sscroll_up), width - 14, height - 35); | |
675 widget_move(WIDGET(playlistwin_sscroll_down), width - 14, height - 30); | |
676 | |
677 /* decide if we should show the mini visualizer */ | |
678 if (playlistwin_get_width() >= 350) { | |
679 widget_move(WIDGET(playlistwin_vis), width - 223, height - 26); | |
680 | |
681 if (playlistwin_vis_enabled) | |
682 widget_show(WIDGET(playlistwin_vis)); | |
683 } | |
684 else | |
685 widget_hide(WIDGET(playlistwin_vis)); | |
686 | |
687 g_object_unref(playlistwin_bg); | |
688 playlistwin_bg = gdk_pixmap_new(playlistwin->window, width, height, -1); | |
689 playlistwin_set_mask(); | |
690 | |
691 widget_list_lock(playlistwin_wlist); | |
692 | |
693 widget_list_change_pixmap(playlistwin_wlist, playlistwin_bg); | |
694 playlistwin_draw_frame(); | |
695 widget_list_draw(playlistwin_wlist, &redraw, TRUE); | |
696 widget_list_clear_redraw(playlistwin_wlist); | |
697 | |
698 widget_list_unlock(playlistwin_wlist); | |
699 | |
700 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
701 gdk_window_clear(playlistwin->window); | |
702 } | |
703 | |
704 | |
705 | |
706 static void | |
707 playlistwin_motion(GtkWidget * widget, | |
708 GdkEventMotion * event, | |
709 gpointer callback_data) | |
710 { | |
711 XEvent ev; | |
712 | |
713 if (dock_is_moving(GTK_WINDOW(playlistwin))) { | |
714 dock_move_motion(GTK_WINDOW(playlistwin), event); | |
715 } | |
716 else { | |
717 handle_motion_cb(playlistwin_wlist, widget, event); | |
718 draw_playlist_window(FALSE); | |
719 } | |
720 gdk_flush(); | |
721 while (XCheckMaskEvent(GDK_DISPLAY(), ButtonMotionMask, &ev)); | |
722 } | |
723 | |
724 static void | |
725 playlistwin_show_filebrowser(void) | |
726 { | |
727 util_run_filebrowser(NO_PLAY_BUTTON); | |
728 } | |
729 | |
730 #if 0 | |
731 static void | |
732 playlistwin_add_dir_handler(const gchar * dir) | |
733 { | |
734 g_free(cfg.filesel_path); | |
735 cfg.filesel_path = g_strdup(dir); | |
736 playlist_add_dir(dir); | |
737 } | |
738 #endif | |
739 | |
740 static void | |
741 playlistwin_fileinfo(void) | |
742 { | |
743 /* Show the first selected file, or the current file if nothing is | |
744 * selected */ | |
745 GList *list = playlist_get_selected(); | |
746 if (list) { | |
747 playlist_fileinfo(GPOINTER_TO_INT(list->data)); | |
748 g_list_free(list); | |
749 } | |
750 else | |
751 playlist_fileinfo_current(); | |
752 } | |
753 | |
754 static void | |
755 menu_set_item_sensitive(GtkItemFactory * item_factory, | |
756 const gchar * path, | |
757 gboolean sensitive) | |
758 { | |
759 GtkWidget *item = gtk_item_factory_get_widget(item_factory, path); | |
760 gtk_widget_set_sensitive(item, sensitive); | |
761 } | |
762 | |
763 /* FIXME: broken */ | |
764 static void | |
765 playlistwin_set_sensitive_sortmenu(void) | |
766 { | |
767 gboolean set = playlist_get_num_selected() > 1; | |
768 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Title", set); | |
769 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Filename", set); | |
770 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Path + Filename", set); | |
771 menu_set_item_sensitive(plsort_menu, "/Sort Selection/By Date", set); | |
772 } | |
773 | |
774 static void | |
775 show_playlist_save_error(GtkWindow * parent, | |
776 const gchar * filename) | |
777 { | |
778 GtkWidget *dialog; | |
779 | |
780 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
781 g_return_if_fail(filename != NULL); | |
782 | |
783 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
784 GTK_DIALOG_DESTROY_WITH_PARENT, | |
785 GTK_MESSAGE_ERROR, | |
786 GTK_BUTTONS_OK, | |
787 _("Error writing playlist \"%s\": %s"), | |
788 filename, strerror(errno)); | |
789 | |
790 gtk_dialog_run(GTK_DIALOG(dialog)); | |
791 gtk_widget_destroy(dialog); | |
792 } | |
793 | |
794 static gboolean | |
795 show_playlist_overwrite_prompt(GtkWindow * parent, | |
796 const gchar * filename) | |
797 { | |
798 GtkWidget *dialog; | |
799 gint result; | |
800 | |
801 g_return_val_if_fail(GTK_IS_WINDOW(parent), FALSE); | |
802 g_return_val_if_fail(filename != NULL, FALSE); | |
803 | |
804 dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
805 GTK_DIALOG_DESTROY_WITH_PARENT, | |
806 GTK_MESSAGE_QUESTION, | |
807 GTK_BUTTONS_YES_NO, | |
808 _("%s already exist. Continue?"), | |
809 filename); | |
810 | |
811 result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
812 gtk_widget_destroy(dialog); | |
813 | |
814 return (result == GTK_RESPONSE_YES); | |
815 } | |
816 | |
817 static void | |
818 show_playlist_save_format_error(GtkWindow * parent, | |
819 const gchar * filename) | |
820 { | |
821 const gchar *markup = | |
822 N_("<b><big>Unable to save playlist.</big></b>\n\n" | |
823 "Unknown file type for '%s'.\n"); | |
824 | |
825 GtkWidget *dialog; | |
826 | |
827 g_return_if_fail(GTK_IS_WINDOW(parent)); | |
828 g_return_if_fail(filename != NULL); | |
829 | |
830 dialog = | |
831 gtk_message_dialog_new_with_markup(GTK_WINDOW(parent), | |
832 GTK_DIALOG_DESTROY_WITH_PARENT, | |
833 GTK_MESSAGE_ERROR, | |
834 GTK_BUTTONS_OK, | |
835 _(markup), | |
836 filename); | |
837 gtk_dialog_run(GTK_DIALOG(dialog)); | |
838 gtk_widget_destroy(dialog); | |
839 } | |
840 | |
841 static void | |
842 playlistwin_save_playlist(const gchar * filename) | |
843 { | |
844 PlaylistFormat format; | |
845 | |
846 format = playlist_format_get_from_name(filename); | |
847 if (format == PLAYLIST_FORMAT_UNKNOWN) { | |
848 show_playlist_save_format_error(GTK_WINDOW(playlistwin), filename); | |
849 return; | |
850 } | |
851 | |
852 str_replace_in(&cfg.playlist_path, g_path_get_dirname(filename)); | |
853 | |
854 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
855 if (!show_playlist_overwrite_prompt(GTK_WINDOW(playlistwin), filename)) | |
856 return; | |
857 | |
858 if (!playlist_save(filename, format)) | |
859 show_playlist_save_error(GTK_WINDOW(playlistwin), filename); | |
860 } | |
861 | |
862 #if 0 | |
863 static void | |
864 playlistwin_save_current(void) | |
865 { | |
866 const gchar *filename; | |
867 | |
868 if (!(filename = playlist_get_current_name())) | |
869 return; | |
870 | |
871 playlistwin_save_playlist(filename); | |
872 } | |
873 #endif | |
874 | |
875 static void | |
876 playlistwin_load_playlist(const gchar * filename) | |
877 { | |
878 g_return_if_fail(filename != NULL); | |
879 | |
880 str_replace_in(&cfg.playlist_path, g_strdup(filename)); | |
881 | |
882 playlist_clear(); | |
883 mainwin_clear_song_info(); | |
884 mainwin_set_info_text(); | |
885 | |
886 playlist_load(filename); | |
887 playlist_set_current_name(filename); | |
888 } | |
889 | |
890 static gchar * | |
891 playlist_file_selection(const gchar * title, | |
892 gboolean save, | |
893 const gchar * default_filename) | |
894 { | |
895 GtkWidget *dialog, *button; | |
896 gchar *filename; | |
897 | |
898 g_return_val_if_fail(title != NULL, NULL); | |
899 | |
900 dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(mainwin), | |
901 save ? GTK_FILE_CHOOSER_ACTION_SAVE : | |
902 GTK_FILE_CHOOSER_ACTION_OPEN, NULL); | |
903 if (default_filename) | |
904 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
905 default_filename); | |
906 | |
907 button = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, | |
908 GTK_RESPONSE_REJECT); | |
909 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
910 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
911 | |
912 button = gtk_dialog_add_button(GTK_DIALOG(dialog), | |
913 save ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, | |
914 GTK_RESPONSE_ACCEPT); | |
915 gtk_button_set_use_stock(GTK_BUTTON(button), TRUE); | |
916 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
917 | |
918 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
919 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
920 else | |
921 filename = NULL; | |
922 | |
923 gtk_widget_destroy(dialog); | |
924 | |
925 return filename; | |
926 } | |
927 | |
928 void | |
929 playlistwin_select_playlist_to_load(const gchar * default_filename) | |
930 { | |
931 gchar *filename = | |
932 playlist_file_selection(_("Load Playlist"), FALSE, default_filename); | |
933 | |
934 if (filename) { | |
935 playlistwin_load_playlist(filename); | |
936 g_free(filename); | |
937 } | |
938 } | |
939 | |
940 static void | |
941 playlistwin_select_playlist_to_save(const gchar * default_filename) | |
942 { | |
943 gchar *filename = | |
944 playlist_file_selection(_("Save Playlist"), TRUE, default_filename); | |
945 | |
946 if (filename) { | |
947 /* Default to M3U if no filename has extension */ | |
948 | |
949 /* NOTE: This doesn't work correctly for hidden files | |
950 - descender */ | |
951 if (!strchr(filename, '.')) { | |
952 gchar *tmpstr = filename; | |
953 filename = g_strconcat(filename, ".m3u", NULL); | |
954 g_free(tmpstr); | |
955 } | |
956 | |
957 playlistwin_save_playlist(filename); | |
958 g_free(filename); | |
959 } | |
960 } | |
961 | |
962 static void | |
963 playlistwin_run_dirbrowser(void) | |
964 { | |
965 mainwin_run_dirbrowser(); | |
966 } | |
967 | |
968 static gboolean | |
969 inside_sensitive_widgets(gint x, gint y) | |
970 { | |
971 return (widget_contains(WIDGET(playlistwin_list), x, y) || | |
972 widget_contains(WIDGET(playlistwin_slider), x, y) || | |
973 widget_contains(WIDGET(playlistwin_close), x, y) || | |
974 widget_contains(WIDGET(playlistwin_shade), x, y) || | |
975 widget_contains(WIDGET(playlistwin_time_min), x, y) || | |
976 widget_contains(WIDGET(playlistwin_time_sec), x, y) || | |
977 widget_contains(WIDGET(playlistwin_info), x, y) || | |
978 widget_contains(WIDGET(playlistwin_vis), x, y) || | |
979 widget_contains(WIDGET(playlistwin_srew), x, y) || | |
980 widget_contains(WIDGET(playlistwin_splay), x, y) || | |
981 widget_contains(WIDGET(playlistwin_spause), x, y) || | |
982 widget_contains(WIDGET(playlistwin_sstop), x, y) || | |
983 widget_contains(WIDGET(playlistwin_sfwd), x, y) || | |
984 widget_contains(WIDGET(playlistwin_seject), x, y) || | |
985 widget_contains(WIDGET(playlistwin_sscroll_up), x, y) || | |
986 widget_contains(WIDGET(playlistwin_sscroll_down), x, y)); | |
987 } | |
988 | |
989 #define REGION_L(x1,x2,y1,y2) \ | |
990 (event->x >= (x1) && event->x < (x2) && \ | |
991 event->y >= cfg.playlist_height - (y1) && \ | |
992 event->y < cfg.playlist_height - (y2)) | |
993 | |
994 #define REGION_R(x1,x2,y1,y2) \ | |
995 (event->x >= playlistwin_get_width() - (x1) && \ | |
996 event->x < playlistwin_get_width() - (x2) && \ | |
997 event->y >= cfg.playlist_height - (y1) && \ | |
998 event->y < cfg.playlist_height - (y2)) | |
999 | |
1000 static void | |
1001 playlistwin_scrolled(GtkWidget * widget, | |
1002 GdkEventScroll * event, | |
1003 gpointer callback_data) | |
1004 { | |
1005 | |
1006 if (event->direction == GDK_SCROLL_DOWN) | |
1007 playlistwin_scroll(cfg.scroll_pl_by); | |
1008 | |
1009 if (event->direction == GDK_SCROLL_UP) | |
1010 playlistwin_scroll(-cfg.scroll_pl_by); | |
1011 | |
1012 } | |
1013 | |
1014 | |
1015 | |
1016 | |
1017 static gboolean | |
1018 playlistwin_press(GtkWidget * widget, | |
1019 GdkEventButton * event, | |
1020 gpointer callback_data) | |
1021 { | |
1022 gboolean grab = TRUE; | |
1023 gint xpos, ypos; | |
1024 GtkWidget *_menu; | |
1025 GtkRequisition req; | |
1026 | |
1027 gtk_window_get_position(GTK_WINDOW(playlistwin), &xpos, &ypos); | |
1028 | |
1029 if (event->button == 1 && !cfg.show_wm_decorations && | |
1030 ((!cfg.playlist_shaded && | |
1031 event->x > playlistwin_get_width() - 20 && | |
1032 event->y > cfg.playlist_height - 20) || | |
1033 (cfg.playlist_shaded && | |
1034 event->x >= playlistwin_get_width() - 31 && | |
1035 event->x < playlistwin_get_width() - 22))) { | |
1036 | |
1037 /* NOTE: Workaround for bug #214 */ | |
1038 if (event->type != GDK_2BUTTON_PRESS && | |
1039 event->type != GDK_3BUTTON_PRESS) { | |
1040 /* resize area */ | |
1041 playlistwin_resizing = TRUE; | |
1042 gtk_window_begin_resize_drag(GTK_WINDOW(widget), | |
1043 GDK_WINDOW_EDGE_SOUTH_EAST, | |
1044 event->button, | |
1045 event->x + xpos, event->y + ypos, | |
1046 event->time); | |
1047 } | |
1048 grab = FALSE; | |
1049 } | |
1050 else if (event->button == 1 && REGION_L(12, 37, 29, 11)) { | |
1051 /* ADD button menu */ | |
1052 | |
1053 _menu = GTK_WIDGET(pladd_menu->widget); | |
1054 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1055 gtk_widget_size_request(_menu, &req); | |
1056 gtk_item_factory_popup_with_data(pladd_menu, | |
1057 NULL, NULL, | |
1058 xpos+12, | |
1059 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1060 grab = FALSE; | |
1061 } | |
1062 else if (event->button == 1 && REGION_L(41, 66, 29, 11)) { | |
1063 /* SUB button menu */ | |
1064 _menu = GTK_WIDGET(pldel_menu->widget); | |
1065 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1066 gtk_widget_size_request(_menu, &req); | |
1067 gtk_item_factory_popup_with_data(pldel_menu, | |
1068 NULL, NULL, | |
1069 xpos+40, | |
1070 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1071 grab = FALSE; | |
1072 } | |
1073 else if (event->button == 1 && REGION_L(70, 95, 29, 11)) { | |
1074 /* SEL button menu */ | |
1075 _menu = GTK_WIDGET(plsel_menu->widget); | |
1076 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1077 gtk_widget_size_request(_menu, &req); | |
1078 gtk_item_factory_popup_with_data(plsel_menu, | |
1079 NULL, NULL, | |
1080 xpos+68, | |
1081 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1082 | |
1083 grab = FALSE; | |
1084 } | |
1085 else if (event->button == 1 && REGION_L(99, 124, 29, 11)) { | |
1086 /* MISC button menu */ | |
1087 _menu = GTK_WIDGET(plsort_menu->widget); | |
1088 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1089 gtk_widget_size_request(_menu, &req); | |
1090 gtk_item_factory_popup_with_data(plsort_menu, | |
1091 NULL, NULL, | |
1092 xpos+100, | |
1093 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1094 grab = FALSE; | |
1095 } | |
1096 else if (event->button == 1 && REGION_R(46, 23, 29, 11)) { | |
1097 /* LIST button menu */ | |
1098 _menu = GTK_WIDGET(pllist_menu->widget); | |
1099 if (!GTK_WIDGET_REALIZED(_menu)) gtk_widget_realize(_menu); | |
1100 gtk_widget_size_request(_menu, &req); | |
1101 gtk_item_factory_popup_with_data(pllist_menu, | |
1102 NULL, NULL, | |
1103 xpos + playlistwin_get_width() - req.width - 12, | |
1104 (ypos + playlistwin_get_height()) - 8 - req.height, 1, event->time); | |
1105 grab = FALSE; | |
1106 } | |
1107 else if (event->button == 1 && REGION_R(82, 54, 15, 9)) { | |
1108 if (cfg.timer_mode == TIMER_ELAPSED) | |
1109 cfg.timer_mode = TIMER_REMAINING; | |
1110 else | |
1111 cfg.timer_mode = TIMER_ELAPSED; | |
1112 } | |
1113 else if (event->button == 2 && (event->type == GDK_BUTTON_PRESS) && | |
1114 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1115 gtk_selection_convert(widget, GDK_SELECTION_PRIMARY, | |
1116 GDK_TARGET_STRING, event->time); | |
1117 } | |
1118 else if (playlistwin_get_width() >= 350 && REGION_R(223, 151, 26, 10)) { | |
1119 if (event->button == 1) { | |
1120 cfg.vis_type++; | |
1121 if (cfg.vis_type > VIS_OFF) | |
1122 cfg.vis_type = VIS_ANALYZER; | |
1123 mainwin_vis_set_type(cfg.vis_type); | |
1124 } | |
1125 else if (event->button == 3) { | |
1126 gint mx, my; | |
1127 GdkModifierType modmask; | |
1128 | |
1129 gdk_window_get_pointer(NULL, &mx, &my, &modmask); | |
1130 util_item_factory_popup(mainwin_vis_menu, mx, my, 3, event->time); | |
1131 grab = FALSE; | |
1132 } | |
1133 } | |
1134 else if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
1135 !inside_sensitive_widgets(event->x, event->y) && event->y < 14) { | |
1136 gdk_window_raise(playlistwin->window); | |
1137 dock_move_press(dock_window_list, GTK_WINDOW(playlistwin), event, | |
1138 FALSE); | |
1139 } | |
1140 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && | |
1141 !inside_sensitive_widgets(event->x, event->y) | |
1142 && event->y < 14) { | |
1143 /* double click on title bar */ | |
1144 playlistwin_shade_toggle(); | |
1145 if (dock_is_moving(GTK_WINDOW(playlistwin))) | |
1146 dock_move_release(GTK_WINDOW(playlistwin)); | |
1147 return TRUE; | |
1148 } | |
1149 else if (event->button == 3 && | |
1150 !(widget_contains(WIDGET(playlistwin_list), event->x, event->y) || | |
1151 (event->y >= cfg.playlist_height - 29 && | |
1152 event->y < cfg.playlist_height - 11 && | |
1153 ((event->x >= 12 && event->x < 37) || | |
1154 (event->x >= 41 && event->x < 66) || | |
1155 (event->x >= 70 && event->x < 95) || | |
1156 (event->x >= 99 && event->x < 124) || | |
1157 (event->x >= playlistwin_get_width() - 46 && | |
1158 event->x < playlistwin_get_width() - 23))))) { | |
1159 /* | |
1160 * Pop up the main menu a few pixels down to avoid | |
1161 * anything to be selected initially. | |
1162 */ | |
1163 util_item_factory_popup(mainwin_general_menu, event->x_root, | |
1164 event->y_root + 2, 3, event->time); | |
1165 grab = FALSE; | |
1166 } | |
1167 else if (event->button == 3 && | |
1168 widget_contains(WIDGET(playlistwin_list), event->x, event->y)) { | |
1169 /* popup menu */ | |
1170 playlistwin_set_sensitive_sortmenu(); | |
1171 gtk_item_factory_popup(playlistwin_popup_menu, | |
1172 event->x_root, event->y_root + 5, | |
1173 3, event->time); | |
1174 grab = FALSE; | |
1175 } | |
1176 else { | |
1177 handle_press_cb(playlistwin_wlist, widget, event); | |
1178 draw_playlist_window(FALSE); | |
1179 } | |
1180 | |
1181 if (grab) | |
1182 gdk_pointer_grab(playlistwin->window, FALSE, | |
1183 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | | |
1184 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
1185 GDK_BUTTON1_MOTION_MASK, NULL, NULL, | |
1186 GDK_CURRENT_TIME); | |
1187 | |
1188 return FALSE; | |
1189 } | |
1190 | |
1191 static gboolean | |
1192 playlistwin_focus_in(GtkWidget * widget, GdkEvent * event, gpointer data) | |
1193 { | |
1194 playlistwin_close->pb_allow_draw = TRUE; | |
1195 playlistwin_shade->pb_allow_draw = TRUE; | |
1196 draw_playlist_window(TRUE); | |
1197 return FALSE; | |
1198 } | |
1199 | |
1200 static gboolean | |
1201 playlistwin_focus_out(GtkWidget * widget, | |
1202 GdkEventButton * event, gpointer data) | |
1203 { | |
1204 playlistwin_close->pb_allow_draw = FALSE; | |
1205 playlistwin_shade->pb_allow_draw = FALSE; | |
1206 draw_playlist_window(TRUE); | |
1207 return FALSE; | |
1208 } | |
1209 | |
1210 static gboolean | |
1211 playlistwin_configure(GtkWidget * window, | |
1212 GdkEventConfigure * event, gpointer data) | |
1213 { | |
1214 if (!GTK_WIDGET_VISIBLE(window)) | |
1215 return FALSE; | |
1216 | |
1217 cfg.playlist_x = event->x; | |
1218 cfg.playlist_y = event->y; | |
1219 | |
1220 if (playlistwin_resizing) { | |
1221 if (event->width != playlistwin_get_width() || | |
1222 event->height != playlistwin_get_height()) | |
1223 playlistwin_resize(event->width, event->height); | |
1224 } | |
1225 return TRUE; | |
1226 } | |
1227 | |
1228 void | |
1229 playlistwin_set_back_pixmap(void) | |
1230 { | |
1231 gdk_window_set_back_pixmap(playlistwin->window, playlistwin_bg, 0); | |
1232 gdk_window_clear(playlistwin->window); | |
1233 } | |
1234 | |
1235 static gboolean | |
1236 playlistwin_delete(GtkWidget * w, gpointer data) | |
1237 { | |
1238 playlistwin_hide(); | |
1239 return TRUE; | |
1240 } | |
1241 | |
1242 static void | |
1243 playlistwin_keypress_up_down_handler(PlayList_List * pl, | |
1244 gboolean up, guint state) | |
1245 { | |
1246 if ((state & GDK_MOD1_MASK) && (state & GDK_SHIFT_MASK)) | |
1247 return; | |
1248 if (!(state & GDK_MOD1_MASK)) | |
1249 playlist_select_all(FALSE); | |
1250 | |
1251 if (pl->pl_prev_selected == -1 || | |
1252 (!playlistwin_item_visible(pl->pl_prev_selected) && | |
1253 !(state & GDK_SHIFT_MASK && pl->pl_prev_min != -1))) { | |
1254 pl->pl_prev_selected = pl->pl_first; | |
1255 } | |
1256 else if (state & GDK_SHIFT_MASK) { | |
1257 if (pl->pl_prev_min == -1) { | |
1258 pl->pl_prev_max = pl->pl_prev_selected; | |
1259 pl->pl_prev_min = pl->pl_prev_selected; | |
1260 } | |
1261 pl->pl_prev_max += (up ? -1 : 1); | |
1262 pl->pl_prev_max = | |
1263 CLAMP(pl->pl_prev_max, 0, playlist_get_length() - 1); | |
1264 | |
1265 pl->pl_first = MIN(pl->pl_first, pl->pl_prev_max); | |
1266 pl->pl_first = MAX(pl->pl_first, pl->pl_prev_max - | |
1267 pl->pl_num_visible + 1); | |
1268 playlist_select_range(pl->pl_prev_min, pl->pl_prev_max, TRUE); | |
1269 return; | |
1270 } | |
1271 else if (state & GDK_MOD1_MASK) { | |
1272 if (up) | |
1273 playlist_list_move_up(pl); | |
1274 else | |
1275 playlist_list_move_down(pl); | |
1276 if (pl->pl_prev_min < pl->pl_first) | |
1277 pl->pl_first = pl->pl_prev_min; | |
1278 else if (pl->pl_prev_max >= (pl->pl_first + pl->pl_num_visible)) | |
1279 pl->pl_first = pl->pl_prev_max - pl->pl_num_visible + 1; | |
1280 return; | |
1281 } | |
1282 else if (up) | |
1283 pl->pl_prev_selected--; | |
1284 else | |
1285 pl->pl_prev_selected++; | |
1286 | |
1287 pl->pl_prev_selected = | |
1288 CLAMP(pl->pl_prev_selected, 0, playlist_get_length() - 1); | |
1289 | |
1290 if (pl->pl_prev_selected < pl->pl_first) | |
1291 pl->pl_first--; | |
1292 else if (pl->pl_prev_selected >= (pl->pl_first + pl->pl_num_visible)) | |
1293 pl->pl_first++; | |
1294 | |
1295 playlist_select_range(pl->pl_prev_selected, pl->pl_prev_selected, TRUE); | |
1296 pl->pl_prev_min = -1; | |
1297 | |
1298 } | |
1299 | |
1300 /* FIXME: Handle the keys through menu */ | |
1301 | |
1302 static gboolean | |
1303 playlistwin_keypress(GtkWidget * w, GdkEventKey * event, gpointer data) | |
1304 { | |
1305 guint keyval; | |
1306 gboolean refresh = FALSE; | |
1307 | |
1308 if (cfg.playlist_shaded) | |
1309 return FALSE; | |
1310 | |
1311 switch (keyval = event->keyval) { | |
1312 case GDK_KP_Up: | |
1313 case GDK_KP_Down: | |
1314 case GDK_Up: | |
1315 case GDK_Down: | |
1316 playlistwin_keypress_up_down_handler(playlistwin_list, | |
1317 keyval == GDK_Up | |
1318 || keyval == GDK_KP_Up, | |
1319 event->state); | |
1320 refresh = TRUE; | |
1321 break; | |
1322 case GDK_Page_Up: | |
1323 playlistwin_scroll(-playlistwin_list->pl_num_visible); | |
1324 refresh = TRUE; | |
1325 break; | |
1326 case GDK_Page_Down: | |
1327 playlistwin_scroll(playlistwin_list->pl_num_visible); | |
1328 refresh = TRUE; | |
1329 break; | |
1330 case GDK_Home: | |
1331 playlistwin_list->pl_first = 0; | |
1332 refresh = TRUE; | |
1333 break; | |
1334 case GDK_End: | |
1335 playlistwin_list->pl_first = | |
1336 playlist_get_length() - playlistwin_list->pl_num_visible; | |
1337 refresh = TRUE; | |
1338 break; | |
1339 case GDK_Return: | |
1340 if (playlistwin_list->pl_prev_selected > -1 | |
1341 && playlistwin_item_visible(playlistwin_list->pl_prev_selected)) { | |
1342 playlist_set_position(playlistwin_list->pl_prev_selected); | |
1343 if (!bmp_playback_get_playing()) | |
1344 bmp_playback_initiate(); | |
1345 } | |
1346 break; | |
1347 case GDK_3: | |
1348 if (event->state & GDK_CONTROL_MASK) | |
1349 playlistwin_fileinfo(); | |
1350 break; | |
1351 case GDK_Delete: | |
1352 if (event->state & GDK_CONTROL_MASK) | |
1353 playlist_delete(TRUE); | |
1354 else | |
1355 playlist_delete(FALSE); | |
1356 break; | |
1357 case GDK_Insert: | |
1358 if (event->state & GDK_SHIFT_MASK) | |
1359 playlistwin_run_dirbrowser(); | |
1360 else if (event->state & GDK_MOD1_MASK) | |
1361 mainwin_show_add_url_window(); | |
1362 else | |
1363 playlistwin_show_filebrowser(); | |
1364 break; | |
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); | |
1679 gtk_window_set_title(GTK_WINDOW(playlistwin), _("BMP Playlist Editor")); | |
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 textbox_set_xfont(mainwin_info, TRUE, cfg.mainwin_font); | |
1941 break; | |
1942 } | |
1943 } | |
1944 | |
1945 static void | |
1946 playlistwin_popup_menu_callback(gpointer data, | |
1947 guint action, | |
1948 GtkWidget * widget) | |
1949 { | |
1950 switch (action) { | |
1951 case ADD_FILES: | |
1952 playlistwin_show_filebrowser(); | |
1953 break; | |
1954 case ADD_DIR: | |
1955 playlistwin_run_dirbrowser(); | |
1956 break; | |
1957 case CLOSE_PL_WINDOW: | |
1958 playlistwin_hide(); | |
1959 break; | |
1960 case MISC_FILEINFO: | |
1961 playlistwin_fileinfo(); | |
1962 break; | |
1963 case SEL_LOOKUP: | |
1964 playlist_read_info_selection(); | |
1965 break; | |
1966 case MISC_QUEUE: | |
1967 playlist_queue(); | |
1968 break; | |
1969 case PLIST_CQUEUE: | |
1970 playlist_clear_queue(); | |
1971 break; | |
1972 case PLIST_JTT: | |
1973 mainwin_jump_to_time(); | |
1974 break; | |
1975 case PLIST_JTF: | |
1976 mainwin_jump_to_file(); | |
1977 break; | |
1978 } | |
1979 } |