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