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