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