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