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