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