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