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