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