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