Mercurial > audlegacy
comparison audacious/mainwin.c @ 0:cb178e5ad177 trunk
[svn] Import audacious source.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 03:06:47 -0700 |
parents | |
children | 8c8a20f72ace |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb178e5ad177 |
---|---|
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 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 | |
27 #include <glib.h> | |
28 #include <glib/gi18n.h> | |
29 #include <glib/gprintf.h> | |
30 #include <gtk/gtk.h> | |
31 #include <gdk/gdkx.h> | |
32 #include <gdk/gdkkeysyms.h> | |
33 | |
34 #include <math.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 | |
38 #include <X11/Xlib.h> | |
39 | |
40 #include "textbox.h" | |
41 #include "mainwin.h" | |
42 #include "pixmaps.h" | |
43 | |
44 #include "main.h" | |
45 | |
46 #include "controlsocket.h" | |
47 #include "pluginenum.h" | |
48 | |
49 #include "about.h" | |
50 #include "dnd.h" | |
51 #include "dock.h" | |
52 #include "equalizer.h" | |
53 #include "hints.h" | |
54 #include "input.h" | |
55 #include "playlistwin.h" | |
56 #include "prefswin.h" | |
57 #include "skinwin.h" | |
58 | |
59 #include "hslider.h" | |
60 #include "menurow.h" | |
61 #include "monostereo.h" | |
62 #include "pbutton.h" | |
63 #include "playback.h" | |
64 #include "playlist.h" | |
65 #include "playlist_list.h" | |
66 #include "playstatus.h" | |
67 #include "sbutton.h" | |
68 #include "svis.h" | |
69 #include "textbox.h" | |
70 #include "urldecode.h" | |
71 #include "util.h" | |
72 #include "vis.h" | |
73 #include "visualization.h" | |
74 #include "libaudacious/configdb.h" | |
75 | |
76 | |
77 #define ITEM_SEPARATOR {"/-", NULL, NULL, 0, "<Separator>"} | |
78 | |
79 /* | |
80 * If you change the menu above change these defines also | |
81 */ | |
82 | |
83 #define MAINWIN_VIS_MENU_VIS_MODE 1 | |
84 #define MAINWIN_VIS_MENU_NUM_VIS_MODE 3 | |
85 #define MAINWIN_VIS_MENU_ANALYZER_MODE 5 | |
86 #define MAINWIN_VIS_MENU_NUM_ANALYZER_MODE 3 | |
87 #define MAINWIN_VIS_MENU_ANALYZER_TYPE 9 | |
88 #define MAINWIN_VIS_MENU_NUM_ANALYZER_TYPE 2 | |
89 #define MAINWIN_VIS_MENU_ANALYZER_PEAKS 12 | |
90 #define MAINWIN_VIS_MENU_SCOPE_MODE 14 | |
91 #define MAINWIN_VIS_MENU_NUM_SCOPE_MODE 3 | |
92 #define MAINWIN_VIS_MENU_WSHADEVU_MODE 18 | |
93 #define MAINWIN_VIS_MENU_NUM_WSHADEVU_MODE 2 | |
94 #define MAINWIN_VIS_MENU_REFRESH_RATE 21 | |
95 #define MAINWIN_VIS_MENU_NUM_REFRESH_RATE 4 | |
96 #define MAINWIN_VIS_MENU_AFALLOFF 26 | |
97 #define MAINWIN_VIS_MENU_NUM_AFALLOFF 5 | |
98 #define MAINWIN_VIS_MENU_PFALLOFF 32 | |
99 #define MAINWIN_VIS_MENU_NUM_PFALLOFF 5 | |
100 | |
101 #define VOLSET_DISP_TIMES 5 | |
102 | |
103 | |
104 enum { | |
105 MAINWIN_SONGNAME_FILEINFO, | |
106 MAINWIN_SONGNAME_JTF, | |
107 MAINWIN_SONGNAME_JTT, | |
108 MAINWIN_SONGNAME_SCROLL | |
109 }; | |
110 | |
111 enum { | |
112 MAINWIN_OPT_SKIN, MAINWIN_OPT_RELOADSKIN, | |
113 MAINWIN_OPT_REPEAT, MAINWIN_OPT_SHUFFLE, MAINWIN_OPT_NPA, | |
114 MAINWIN_OPT_TELAPSED, MAINWIN_OPT_TREMAINING, | |
115 MAINWIN_OPT_ALWAYS, | |
116 MAINWIN_OPT_STICKY, | |
117 MAINWIN_OPT_WS, | |
118 MAINWIN_OPT_PWS, | |
119 MAINWIN_OPT_EQWS | |
120 }; | |
121 | |
122 enum { | |
123 MAINWIN_VIS_ANALYZER, MAINWIN_VIS_SCOPE, MAINWIN_VIS_OFF, | |
124 MAINWIN_VIS_ANALYZER_NORMAL, MAINWIN_VIS_ANALYZER_FIRE, | |
125 MAINWIN_VIS_ANALYZER_VLINES, | |
126 MAINWIN_VIS_ANALYZER_LINES, MAINWIN_VIS_ANALYZER_BARS, | |
127 MAINWIN_VIS_ANALYZER_PEAKS, | |
128 MAINWIN_VIS_SCOPE_DOT, MAINWIN_VIS_SCOPE_LINE, MAINWIN_VIS_SCOPE_SOLID, | |
129 MAINWIN_VIS_VU_NORMAL, MAINWIN_VIS_VU_SMOOTH, | |
130 MAINWIN_VIS_REFRESH_FULL, MAINWIN_VIS_REFRESH_HALF, | |
131 MAINWIN_VIS_REFRESH_QUARTER, MAINWIN_VIS_REFRESH_EIGHTH, | |
132 MAINWIN_VIS_AFALLOFF_SLOWEST, MAINWIN_VIS_AFALLOFF_SLOW, | |
133 MAINWIN_VIS_AFALLOFF_MEDIUM, MAINWIN_VIS_AFALLOFF_FAST, | |
134 MAINWIN_VIS_AFALLOFF_FASTEST, | |
135 MAINWIN_VIS_PFALLOFF_SLOWEST, MAINWIN_VIS_PFALLOFF_SLOW, | |
136 MAINWIN_VIS_PFALLOFF_MEDIUM, MAINWIN_VIS_PFALLOFF_FAST, | |
137 MAINWIN_VIS_PFALLOFF_FASTEST, | |
138 MAINWIN_VIS_PLUGINS | |
139 }; | |
140 | |
141 enum { | |
142 MAINWIN_VIS_ACTIVE_MAINWIN, MAINWIN_VIS_ACTIVE_PLAYLISTWIN | |
143 }; | |
144 | |
145 | |
146 typedef struct _PlaybackInfo PlaybackInfo; | |
147 | |
148 struct _PlaybackInfo { | |
149 gchar *title; | |
150 gint bitrate; | |
151 gint frequency; | |
152 gint n_channels; | |
153 }; | |
154 | |
155 | |
156 GtkWidget *mainwin = NULL; | |
157 | |
158 static GdkBitmap *nullmask; | |
159 static gint balance; | |
160 | |
161 GtkWidget *mainwin_jtf = NULL; | |
162 static GtkWidget *mainwin_jtt = NULL; | |
163 | |
164 GtkItemFactory *mainwin_songname_menu, *mainwin_vis_menu; | |
165 GtkItemFactory *mainwin_general_menu, *mainwin_play_menu, *mainwin_add_menu; | |
166 GtkItemFactory *mainwin_view_menu; | |
167 | |
168 | |
169 GdkGC *mainwin_gc; | |
170 static GdkPixmap *mainwin_bg = NULL; | |
171 | |
172 GtkAccelGroup *mainwin_accel = NULL; | |
173 | |
174 static PButton *mainwin_menubtn; | |
175 static PButton *mainwin_minimize, *mainwin_shade, *mainwin_close; | |
176 | |
177 static PButton *mainwin_rew, *mainwin_fwd; | |
178 static PButton *mainwin_eject; | |
179 static PButton *mainwin_play, *mainwin_pause, *mainwin_stop; | |
180 | |
181 TButton *mainwin_shuffle, *mainwin_repeat, *mainwin_eq, *mainwin_pl; | |
182 TextBox *mainwin_info; | |
183 | |
184 static TextBox *mainwin_rate_text, *mainwin_freq_text; | |
185 static TextBox *mainwin_stime_min, *mainwin_stime_sec; | |
186 | |
187 PlayStatus *mainwin_playstatus; | |
188 | |
189 static Number *mainwin_minus_num, *mainwin_10min_num, *mainwin_min_num; | |
190 static Number *mainwin_10sec_num, *mainwin_sec_num; | |
191 | |
192 static gboolean setting_volume = FALSE; | |
193 | |
194 Vis *active_vis; | |
195 Vis *mainwin_vis; | |
196 SVis *mainwin_svis; | |
197 | |
198 static MenuRow *mainwin_menurow; | |
199 static HSlider *mainwin_volume, *mainwin_balance, *mainwin_position; | |
200 static HSlider *mainwin_sposition = NULL; | |
201 static MonoStereo *mainwin_monostereo; | |
202 static SButton *mainwin_srew, *mainwin_splay, *mainwin_spause; | |
203 static SButton *mainwin_sstop, *mainwin_sfwd, *mainwin_seject, *mainwin_about; | |
204 | |
205 static GList *mainwin_wlist = NULL; | |
206 | |
207 static gint mainwin_timeout_id; | |
208 | |
209 G_LOCK_DEFINE_STATIC(mainwin_title); | |
210 | |
211 static gboolean mainwin_force_redraw = FALSE; | |
212 static gchar *mainwin_title_text = NULL; | |
213 static gboolean mainwin_info_text_locked = FALSE; | |
214 | |
215 | |
216 static void mainwin_songname_menu_callback(gpointer user_data, | |
217 guint action, | |
218 GtkWidget * widget); | |
219 | |
220 static void mainwin_vis_menu_callback(gpointer user_data, | |
221 guint action, | |
222 GtkWidget * widget); | |
223 | |
224 static void mainwin_view_menu_callback(gpointer user_data, | |
225 guint action, | |
226 GtkWidget * widget); | |
227 | |
228 static void mainwin_play_menu_callback(gpointer user_data, | |
229 guint action, | |
230 GtkWidget * widget); | |
231 | |
232 /* Song name area menu */ | |
233 | |
234 static GtkItemFactoryEntry mainwin_songname_menu_entries[] = { | |
235 {N_("/View Track Details"), "<alt>i", mainwin_general_menu_callback, | |
236 MAINWIN_GENERAL_FILEINFO, "<ImageItem>", my_pixbuf}, | |
237 {"/-", NULL, NULL, 0, "<Separator>"}, | |
238 {N_("/Autoscroll Songname"), NULL, mainwin_songname_menu_callback, | |
239 MAINWIN_SONGNAME_SCROLL, "<ToggleItem>"}, | |
240 }; | |
241 | |
242 static gint mainwin_songname_menu_entries_num = | |
243 G_N_ELEMENTS(mainwin_songname_menu_entries); | |
244 | |
245 /* Mini-visualizer area menu */ | |
246 | |
247 static GtkItemFactoryEntry mainwin_vis_menu_entries[] = { | |
248 {N_("/Visualization Mode"), NULL, NULL, 0, "<Branch>"}, | |
249 {N_("/Visualization Mode/Analyzer"), NULL, mainwin_vis_menu_callback, | |
250 MAINWIN_VIS_ANALYZER, "<RadioItem>"}, | |
251 {N_("/Visualization Mode/Scope"), NULL, mainwin_vis_menu_callback, | |
252 MAINWIN_VIS_SCOPE, "/Visualization Mode/Analyzer"}, | |
253 {N_("/Visualization Mode/Off"), NULL, mainwin_vis_menu_callback, | |
254 MAINWIN_VIS_OFF, "/Visualization Mode/Analyzer"}, | |
255 {N_("/Analyzer Mode"), NULL, NULL, 0, "<Branch>"}, | |
256 {N_("/Analyzer Mode/Normal"), NULL, mainwin_vis_menu_callback, | |
257 MAINWIN_VIS_ANALYZER_NORMAL, "<RadioItem>"}, | |
258 {N_("/Analyzer Mode/Fire"), NULL, mainwin_vis_menu_callback, | |
259 MAINWIN_VIS_ANALYZER_FIRE, "/Analyzer Mode/Normal"}, | |
260 {N_("/Analyzer Mode/Vertical Lines"), NULL, mainwin_vis_menu_callback, | |
261 MAINWIN_VIS_ANALYZER_VLINES, "/Analyzer Mode/Normal"}, | |
262 {"/Analyzer Mode/-", NULL, NULL, 0, "<Separator>"}, | |
263 {N_("/Analyzer Mode/Lines"), NULL, mainwin_vis_menu_callback, | |
264 MAINWIN_VIS_ANALYZER_LINES, "<RadioItem>"}, | |
265 {N_("/Analyzer Mode/Bars"), NULL, mainwin_vis_menu_callback, | |
266 MAINWIN_VIS_ANALYZER_BARS, "/Analyzer Mode/Lines"}, | |
267 {"/Analyzer Mode/-", NULL, NULL, 0, "<Separator>"}, | |
268 {N_("/Analyzer Mode/Peaks"), NULL, mainwin_vis_menu_callback, | |
269 MAINWIN_VIS_ANALYZER_PEAKS, "<ToggleItem>"}, | |
270 {N_("/Scope Mode"), NULL, NULL, 0, "<Branch>"}, | |
271 {N_("/Scope Mode/Dot Scope"), NULL, mainwin_vis_menu_callback, | |
272 MAINWIN_VIS_SCOPE_DOT, "<RadioItem>"}, | |
273 {N_("/Scope Mode/Line Scope"), NULL, mainwin_vis_menu_callback, | |
274 MAINWIN_VIS_SCOPE_LINE, "/Scope Mode/Dot Scope"}, | |
275 {N_("/Scope Mode/Solid Scope"), NULL, mainwin_vis_menu_callback, | |
276 MAINWIN_VIS_SCOPE_SOLID, "/Scope Mode/Dot Scope"}, | |
277 {N_("/WindowShade VU Mode"), NULL, NULL, 0, "<Branch>"}, | |
278 {N_("/WindowShade VU Mode/Normal"), NULL, mainwin_vis_menu_callback, | |
279 MAINWIN_VIS_VU_NORMAL, "<RadioItem>"}, | |
280 {N_("/WindowShade VU Mode/Smooth"), NULL, mainwin_vis_menu_callback, | |
281 MAINWIN_VIS_VU_SMOOTH, "/WindowShade VU Mode/Normal"}, | |
282 {N_("/Refresh Rate"), NULL, NULL, 0, "<Branch>"}, | |
283 {N_("/Refresh Rate/Full (~50 fps)"), NULL, mainwin_vis_menu_callback, | |
284 MAINWIN_VIS_REFRESH_FULL, "<RadioItem>"}, | |
285 {N_("/Refresh Rate/Half (~25 fps)"), NULL, mainwin_vis_menu_callback, | |
286 MAINWIN_VIS_REFRESH_HALF, "/Refresh Rate/Full (~50 fps)"}, | |
287 {N_("/Refresh Rate/Quarter (~13 fps)"), NULL, mainwin_vis_menu_callback, | |
288 MAINWIN_VIS_REFRESH_QUARTER, "/Refresh Rate/Full (~50 fps)"}, | |
289 {N_("/Refresh Rate/Eighth (~6 fps)"), NULL, mainwin_vis_menu_callback, | |
290 MAINWIN_VIS_REFRESH_EIGHTH, "/Refresh Rate/Full (~50 fps)"}, | |
291 {N_("/Analyzer Falloff"), NULL, NULL, 0, "<Branch>"}, | |
292 {N_("/Analyzer Falloff/Slowest"), NULL, mainwin_vis_menu_callback, | |
293 MAINWIN_VIS_AFALLOFF_SLOWEST, "<RadioItem>"}, | |
294 {N_("/Analyzer Falloff/Slow"), NULL, mainwin_vis_menu_callback, | |
295 MAINWIN_VIS_AFALLOFF_SLOW, "/Analyzer Falloff/Slowest"}, | |
296 {N_("/Analyzer Falloff/Medium"), NULL, mainwin_vis_menu_callback, | |
297 MAINWIN_VIS_AFALLOFF_MEDIUM, "/Analyzer Falloff/Slowest"}, | |
298 {N_("/Analyzer Falloff/Fast"), NULL, mainwin_vis_menu_callback, | |
299 MAINWIN_VIS_AFALLOFF_FAST, "/Analyzer Falloff/Slowest"}, | |
300 {N_("/Analyzer Falloff/Fastest"), NULL, mainwin_vis_menu_callback, | |
301 MAINWIN_VIS_AFALLOFF_FASTEST, "/Analyzer Falloff/Slowest"}, | |
302 {N_("/Peaks Falloff"), NULL, NULL, 0, "<Branch>"}, | |
303 {N_("/Peaks Falloff/Slowest"), NULL, mainwin_vis_menu_callback, | |
304 MAINWIN_VIS_PFALLOFF_SLOWEST, "<RadioItem>"}, | |
305 {N_("/Peaks Falloff/Slow"), NULL, mainwin_vis_menu_callback, | |
306 MAINWIN_VIS_PFALLOFF_SLOW, "/Peaks Falloff/Slowest"}, | |
307 {N_("/Peaks Falloff/Medium"), NULL, mainwin_vis_menu_callback, | |
308 MAINWIN_VIS_PFALLOFF_MEDIUM, "/Peaks Falloff/Slowest"}, | |
309 {N_("/Peaks Falloff/Fast"), NULL, mainwin_vis_menu_callback, | |
310 MAINWIN_VIS_PFALLOFF_FAST, "/Peaks Falloff/Slowest"}, | |
311 {N_("/Peaks Falloff/Fastest"), NULL, mainwin_vis_menu_callback, | |
312 MAINWIN_VIS_PFALLOFF_FASTEST, "/Peaks Falloff/Slowest"} | |
313 }; | |
314 | |
315 static const gint mainwin_vis_menu_entries_num = | |
316 G_N_ELEMENTS(mainwin_vis_menu_entries); | |
317 | |
318 /* Playback menu (now used only for accelerators) */ | |
319 | |
320 static GtkItemFactoryEntry mainwin_playback_menu_entries[] = { | |
321 /* | |
322 {N_("/Play CD"), "<alt>C", mainwin_general_menu_callback, | |
323 MAINWIN_GENERAL_PLAYCD, "<StockItem>", GTK_STOCK_CDROM}, | |
324 {"/-", NULL, NULL, 0, "<Separator>"}, | |
325 */ | |
326 {N_("/Repeat"), "R", mainwin_play_menu_callback, | |
327 MAINWIN_OPT_REPEAT, "<ToggleItem>"}, | |
328 {N_("/Shuffle"), "S", mainwin_play_menu_callback, | |
329 MAINWIN_OPT_SHUFFLE, "<ToggleItem>"}, | |
330 /* | |
331 {N_("/No Playlist Advance"), "<control>N", mainwin_play_menu_callback, | |
332 MAINWIN_OPT_NPA, "<ToggleItem>"}, | |
333 */ | |
334 {"/-", NULL, NULL, 0, "<Separator>"}, | |
335 {N_("/Play"), "x", mainwin_general_menu_callback, | |
336 MAINWIN_GENERAL_PLAY, "<Item>"}, | |
337 {N_("/Pause"), "c", mainwin_general_menu_callback, | |
338 MAINWIN_GENERAL_PAUSE, "<Item>"}, | |
339 {N_("/Stop"), "v", mainwin_general_menu_callback, | |
340 MAINWIN_GENERAL_STOP, "<StockItem>", GTK_STOCK_STOP}, | |
341 {N_("/Previous"), "z", mainwin_general_menu_callback, | |
342 MAINWIN_GENERAL_PREV, "<StockItem>", GTK_STOCK_GO_BACK}, | |
343 {N_("/Next"), "b", mainwin_general_menu_callback, | |
344 MAINWIN_GENERAL_NEXT, "<StockItem>", GTK_STOCK_GO_FORWARD}, | |
345 {"/-", NULL, NULL, 0, "<Separator>"}, | |
346 {N_("/Jump to Playlist Start"), "<control>Z", mainwin_general_menu_callback, | |
347 MAINWIN_GENERAL_START, "<StockItem>", GTK_STOCK_GOTO_TOP}, | |
348 {"/-", NULL, NULL, 0, "<Separator>"}, | |
349 {N_("/Jump to File"), "J", mainwin_general_menu_callback, | |
350 MAINWIN_GENERAL_JTF, "<StockItem>", GTK_STOCK_JUMP_TO}, | |
351 {N_("/Jump to Time"), "<control>J", mainwin_general_menu_callback, | |
352 MAINWIN_GENERAL_JTT, "<StockItem>", GTK_STOCK_JUMP_TO}, | |
353 }; | |
354 | |
355 static const gint mainwin_playback_menu_entries_num = | |
356 G_N_ELEMENTS(mainwin_playback_menu_entries); | |
357 | |
358 /* Main menu */ | |
359 | |
360 static GtkItemFactoryEntry mainwin_general_menu_entries[] = { | |
361 { N_("/View Track Details"), "<alt>I", mainwin_general_menu_callback, | |
362 MAINWIN_GENERAL_FILEINFO, "<ImageItem>", my_pixbuf}, | |
363 {"/-", NULL, NULL, 0, "<Separator>"}, | |
364 {N_("/Preferences"), "<control>P", mainwin_general_menu_callback, | |
365 MAINWIN_GENERAL_PREFS, "<StockItem>", GTK_STOCK_PREFERENCES}, | |
366 {N_("/_View"), NULL, NULL, 0, "<Item>"}, | |
367 {"/-", NULL, NULL, 0, "<Separator>"}, | |
368 {N_("/About Audacious"), NULL, mainwin_general_menu_callback, | |
369 MAINWIN_GENERAL_ABOUT, "<StockItem>", GTK_STOCK_DIALOG_INFO}, | |
370 {N_("/_Quit"), NULL, mainwin_general_menu_callback, | |
371 MAINWIN_GENERAL_EXIT, "<StockItem>", GTK_STOCK_QUIT} | |
372 }; | |
373 | |
374 static const gint mainwin_general_menu_entries_num = | |
375 G_N_ELEMENTS(mainwin_general_menu_entries); | |
376 | |
377 /* Add submenu */ | |
378 | |
379 static GtkItemFactoryEntry mainwin_add_menu_entries[] = { | |
380 {N_("/Files..."), "f", mainwin_general_menu_callback, | |
381 MAINWIN_GENERAL_PLAYFILE, "<StockItem>", GTK_STOCK_OPEN}, | |
382 /* | |
383 {N_("/Folders..."), "d", | |
384 mainwin_general_menu_callback, | |
385 MAINWIN_GENERAL_PLAYDIRECTORY, "<StockItem>", GTK_STOCK_OPEN}, | |
386 */ | |
387 {N_("/Internet location..."), "<control>h", mainwin_general_menu_callback, | |
388 MAINWIN_GENERAL_PLAYLOCATION, "<StockItem>", GTK_STOCK_NETWORK}, | |
389 }; | |
390 | |
391 static const gint mainwin_add_menu_entries_num = | |
392 G_N_ELEMENTS(mainwin_add_menu_entries); | |
393 | |
394 | |
395 /* | |
396 */ | |
397 | |
398 /* View submenu */ | |
399 | |
400 static GtkItemFactoryEntry mainwin_view_menu_entries[] = { | |
401 {N_("/Show Playlist Editor"), "<alt>E", mainwin_general_menu_callback, | |
402 MAINWIN_GENERAL_SHOWPLWIN, "<ToggleItem>"}, | |
403 {N_("/Show Equalizer"), "<alt>G", mainwin_general_menu_callback, | |
404 MAINWIN_GENERAL_SHOWEQWIN, "<ToggleItem>"}, | |
405 {"/-", NULL, NULL, 0, "<Separator>"}, | |
406 {N_("/Time Elapsed"), "<control>E", mainwin_view_menu_callback, | |
407 MAINWIN_OPT_TELAPSED, "<RadioItem>"}, | |
408 {N_("/Time Remaining"), "<control>R", mainwin_view_menu_callback, | |
409 MAINWIN_OPT_TREMAINING, "/Time Elapsed"}, | |
410 {"/-", NULL, NULL, 0, "<Separator>"}, | |
411 {N_("/Always On Top"), "<control>o", mainwin_view_menu_callback, | |
412 MAINWIN_OPT_ALWAYS, "<ToggleItem>"}, | |
413 {N_("/Put on All Workspaces"), "<control>S", | |
414 mainwin_view_menu_callback, MAINWIN_OPT_STICKY, "<ToggleItem>"}, | |
415 {"/-", NULL, NULL, 0, "<Separator>"}, | |
416 {N_("/Roll up Player"), "<control>W", mainwin_view_menu_callback, | |
417 MAINWIN_OPT_WS, "<ToggleItem>"}, | |
418 {N_("/Roll up Playlist Editor"), "<control><shift>W", mainwin_view_menu_callback, | |
419 MAINWIN_OPT_PWS, "<ToggleItem>"}, | |
420 {N_("/Roll up Equalizer"), "<control><alt>W", mainwin_view_menu_callback, | |
421 MAINWIN_OPT_EQWS, "<ToggleItem>"} | |
422 }; | |
423 | |
424 static const gint mainwin_view_menu_entries_num = | |
425 G_N_ELEMENTS(mainwin_view_menu_entries); | |
426 | |
427 | |
428 static PlaybackInfo playback_info = { NULL, 0, 0, 0 }; | |
429 | |
430 | |
431 static gint mainwin_idle_func(gpointer data); | |
432 | |
433 static void set_timer_mode_menu_cb(TimerMode mode); | |
434 static void set_timer_mode(TimerMode mode); | |
435 | |
436 | |
437 /* FIXME: placed here for now */ | |
438 void | |
439 playback_get_sample_params(gint * bitrate, | |
440 gint * frequency, | |
441 gint * n_channels) | |
442 { | |
443 if (bitrate) | |
444 *bitrate = playback_info.bitrate; | |
445 | |
446 if (frequency) | |
447 *frequency = playback_info.frequency; | |
448 | |
449 if (n_channels) | |
450 *n_channels = playback_info.n_channels; | |
451 } | |
452 | |
453 static void | |
454 playback_set_sample_params(gint bitrate, | |
455 gint frequency, | |
456 gint n_channels) | |
457 { | |
458 if (bitrate >= 0) | |
459 playback_info.bitrate = bitrate; | |
460 | |
461 if (frequency >= 0) | |
462 playback_info.frequency = frequency; | |
463 | |
464 if (n_channels >= 0) | |
465 playback_info.n_channels = n_channels; | |
466 } | |
467 | |
468 static void | |
469 mainwin_set_title_scroll(gboolean scroll) | |
470 { | |
471 cfg.autoscroll = scroll; | |
472 textbox_set_scroll(mainwin_info, cfg.autoscroll); | |
473 } | |
474 | |
475 | |
476 void | |
477 mainwin_set_always_on_top(gboolean always) | |
478 { | |
479 GtkWidget *widget = gtk_item_factory_get_widget(mainwin_view_menu, | |
480 "/Always On Top"); | |
481 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), | |
482 mainwin_menurow->mr_always_selected); | |
483 } | |
484 | |
485 static void | |
486 mainwin_set_shape_mask(void) | |
487 { | |
488 GdkBitmap *mask; | |
489 | |
490 if (!cfg.player_visible) | |
491 return; | |
492 | |
493 mask = skin_get_mask(bmp_active_skin, SKIN_MASK_MAIN + cfg.player_shaded); | |
494 gtk_widget_shape_combine_mask(mainwin, mask, 0, 0); | |
495 } | |
496 | |
497 static void | |
498 mainwin_set_shade(gboolean shaded) | |
499 { | |
500 GtkWidget *widget; | |
501 widget = gtk_item_factory_get_widget(mainwin_view_menu, | |
502 "/Roll up Player"); | |
503 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), shaded); | |
504 } | |
505 | |
506 static void | |
507 mainwin_set_shade_menu_cb(gboolean shaded) | |
508 { | |
509 cfg.player_shaded = shaded; | |
510 | |
511 mainwin_set_shape_mask(); | |
512 | |
513 if (shaded) { | |
514 dock_shade(dock_window_list, GTK_WINDOW(mainwin), | |
515 MAINWIN_SHADED_HEIGHT); | |
516 | |
517 widget_show(WIDGET(mainwin_svis)); | |
518 vis_clear_data(mainwin_vis); | |
519 | |
520 widget_show(WIDGET(mainwin_srew)); | |
521 widget_show(WIDGET(mainwin_splay)); | |
522 widget_show(WIDGET(mainwin_spause)); | |
523 widget_show(WIDGET(mainwin_sstop)); | |
524 widget_show(WIDGET(mainwin_sfwd)); | |
525 widget_show(WIDGET(mainwin_seject)); | |
526 | |
527 widget_show(WIDGET(mainwin_stime_min)); | |
528 widget_show(WIDGET(mainwin_stime_sec)); | |
529 | |
530 textbox_set_scroll(mainwin_info, FALSE); | |
531 if (bmp_playback_get_playing() | |
532 && playlist_get_current_length() != -1) | |
533 widget_show(WIDGET(mainwin_sposition)); | |
534 | |
535 mainwin_shade->pb_ny = mainwin_shade->pb_py = 27; | |
536 } | |
537 else { | |
538 dock_shade(dock_window_list, GTK_WINDOW(mainwin), MAINWIN_HEIGHT); | |
539 | |
540 widget_hide(WIDGET(mainwin_svis)); | |
541 svis_clear_data(mainwin_svis); | |
542 | |
543 widget_hide(WIDGET(mainwin_srew)); | |
544 widget_hide(WIDGET(mainwin_splay)); | |
545 widget_hide(WIDGET(mainwin_spause)); | |
546 widget_hide(WIDGET(mainwin_sstop)); | |
547 widget_hide(WIDGET(mainwin_sfwd)); | |
548 widget_hide(WIDGET(mainwin_seject)); | |
549 | |
550 widget_hide(WIDGET(mainwin_stime_min)); | |
551 widget_hide(WIDGET(mainwin_stime_sec)); | |
552 widget_hide(WIDGET(mainwin_sposition)); | |
553 | |
554 textbox_set_scroll(mainwin_info, TRUE); | |
555 mainwin_shade->pb_ny = mainwin_shade->pb_py = 18; | |
556 } | |
557 | |
558 draw_main_window(TRUE); | |
559 } | |
560 | |
561 static void | |
562 mainwin_vis_set_active_vis(gint new_vis) | |
563 { | |
564 switch (new_vis) { | |
565 case MAINWIN_VIS_ACTIVE_MAINWIN: | |
566 playlistwin_vis_disable(); | |
567 active_vis = mainwin_vis; | |
568 break; | |
569 case MAINWIN_VIS_ACTIVE_PLAYLISTWIN: | |
570 playlistwin_vis_enable(); | |
571 active_vis = playlistwin_vis; | |
572 break; | |
573 } | |
574 } | |
575 | |
576 static void | |
577 mainwin_vis_set_refresh(RefreshRate rate) | |
578 { | |
579 cfg.vis_refresh = rate; | |
580 } | |
581 | |
582 static void | |
583 mainwin_vis_set_afalloff(FalloffSpeed speed) | |
584 { | |
585 cfg.analyzer_falloff = speed; | |
586 } | |
587 | |
588 static void | |
589 mainwin_vis_set_pfalloff(FalloffSpeed speed) | |
590 { | |
591 cfg.peaks_falloff = speed; | |
592 } | |
593 | |
594 static void | |
595 mainwin_vis_set_analyzer_mode(AnalyzerMode mode) | |
596 { | |
597 cfg.analyzer_mode = mode; | |
598 } | |
599 | |
600 static void | |
601 mainwin_vis_set_analyzer_type(AnalyzerType mode) | |
602 { | |
603 cfg.analyzer_type = mode; | |
604 } | |
605 | |
606 void | |
607 mainwin_vis_set_type(VisType mode) | |
608 { | |
609 gchar *path = | |
610 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_VIS_MODE + mode].path; | |
611 GtkWidget *widget = gtk_item_factory_get_widget(mainwin_vis_menu, path); | |
612 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); | |
613 } | |
614 | |
615 static void | |
616 mainwin_vis_set_type_menu_cb(VisType mode) | |
617 { | |
618 cfg.vis_type = mode; | |
619 | |
620 if (mode == VIS_OFF) { | |
621 if (cfg.player_shaded && cfg.player_visible) | |
622 svis_clear(mainwin_svis); | |
623 else | |
624 vis_clear(active_vis); | |
625 } | |
626 if (mode == VIS_ANALYZER) { | |
627 vis_clear_data(active_vis); | |
628 svis_clear_data(mainwin_svis); | |
629 } | |
630 } | |
631 | |
632 static void | |
633 mainwin_menubtn_cb(void) | |
634 { | |
635 gint x, y; | |
636 gtk_window_get_position(GTK_WINDOW(mainwin), &x, &y); | |
637 util_item_factory_popup(mainwin_general_menu, | |
638 x + 6, | |
639 y + MAINWIN_SHADED_HEIGHT, | |
640 1, GDK_CURRENT_TIME); | |
641 } | |
642 | |
643 void | |
644 mainwin_minimize_cb(void) | |
645 { | |
646 if (!mainwin) | |
647 return; | |
648 | |
649 gtk_window_iconify(GTK_WINDOW(mainwin)); | |
650 } | |
651 | |
652 static void | |
653 mainwin_shade_toggle(void) | |
654 { | |
655 mainwin_set_shade(!cfg.player_shaded); | |
656 } | |
657 | |
658 void | |
659 mainwin_quit_cb(void) | |
660 { | |
661 gtk_widget_hide(equalizerwin); | |
662 gtk_widget_hide(playlistwin); | |
663 gtk_widget_hide(mainwin); | |
664 gdk_flush(); | |
665 | |
666 g_source_remove(mainwin_timeout_id); | |
667 | |
668 util_set_cursor(NULL); | |
669 | |
670 bmp_config_save(); | |
671 gtk_accel_map_save(bmp_paths[BMP_PATH_ACCEL_FILE]); | |
672 | |
673 ctrlsocket_cleanup(); | |
674 | |
675 playlist_stop_get_info_thread(); | |
676 playlist_clear(); | |
677 | |
678 plugin_system_cleanup(); | |
679 | |
680 gtk_main_quit(); | |
681 } | |
682 | |
683 static void | |
684 mainwin_destroy(GtkWidget * widget, gpointer data) | |
685 { | |
686 mainwin_quit_cb(); | |
687 } | |
688 | |
689 static void | |
690 mainwin_draw_titlebar(gboolean focus) | |
691 { | |
692 skin_draw_mainwin_titlebar(bmp_active_skin, mainwin_bg, mainwin_gc, | |
693 cfg.player_shaded, focus || !cfg.dim_titlebar); | |
694 } | |
695 | |
696 void | |
697 draw_main_window(gboolean force) | |
698 { | |
699 GList *wl; | |
700 Widget *w; | |
701 gboolean redraw; | |
702 | |
703 if (!cfg.player_visible) | |
704 return; | |
705 | |
706 widget_list_lock(mainwin_wlist); | |
707 | |
708 if (force) { | |
709 if (!cfg.player_shaded) | |
710 skin_draw_pixmap(bmp_active_skin, mainwin_bg, mainwin_gc, | |
711 SKIN_MAIN, 0, 0, 0, 0, MAINWIN_WIDTH, | |
712 MAINWIN_HEIGHT); | |
713 mainwin_draw_titlebar(gtk_window_has_toplevel_focus | |
714 (GTK_WINDOW(mainwin))); | |
715 } | |
716 | |
717 widget_list_draw(mainwin_wlist, &redraw, force); | |
718 | |
719 if (redraw || force) { | |
720 if (force) { | |
721 gdk_window_clear(mainwin->window); | |
722 } | |
723 else { | |
724 for (wl = mainwin_wlist; wl; wl = g_list_next(wl)) { | |
725 w = WIDGET(wl->data); | |
726 | |
727 if (!w->redraw || !w->visible) | |
728 continue; | |
729 | |
730 gdk_window_clear_area(mainwin->window, w->x, w->y, | |
731 w->width, w->height); | |
732 w->redraw = FALSE; | |
733 } | |
734 } | |
735 | |
736 gdk_flush(); | |
737 } | |
738 | |
739 widget_list_unlock(mainwin_wlist); | |
740 } | |
741 | |
742 | |
743 void | |
744 mainwin_set_info_text(void) | |
745 { | |
746 gchar *text; | |
747 | |
748 if (mainwin_info_text_locked) | |
749 return; | |
750 | |
751 if ((text = input_get_info_text()) != NULL) { | |
752 textbox_set_text(mainwin_info, text); | |
753 g_free(text); | |
754 } | |
755 else if ((text = playlist_get_info_text()) != NULL) { | |
756 textbox_set_text(mainwin_info, text); | |
757 g_free(text); | |
758 } | |
759 } | |
760 | |
761 void | |
762 mainwin_lock_info_text(const gchar * text) | |
763 { | |
764 mainwin_info_text_locked = TRUE; | |
765 textbox_set_text(mainwin_info, text); | |
766 } | |
767 | |
768 void | |
769 mainwin_release_info_text(void) | |
770 { | |
771 mainwin_info_text_locked = FALSE; | |
772 mainwin_set_info_text(); | |
773 } | |
774 | |
775 | |
776 static gchar * | |
777 make_mainwin_title(const gchar * title) | |
778 { | |
779 if (title) | |
780 return g_strdup_printf(_("%s - Audacious"), title); | |
781 else | |
782 return g_strdup(_("Audacious")); | |
783 } | |
784 | |
785 void | |
786 mainwin_set_song_title(const gchar * title) | |
787 { | |
788 G_LOCK(mainwin_title); | |
789 g_free(mainwin_title_text); | |
790 mainwin_title_text = make_mainwin_title(title); | |
791 G_UNLOCK(mainwin_title); | |
792 } | |
793 | |
794 void | |
795 mainwin_set_song_info(gint bitrate, | |
796 gint frequency, | |
797 gint n_channels) | |
798 { | |
799 gchar text[10]; | |
800 gchar *title; | |
801 | |
802 playback_set_sample_params(bitrate, frequency, n_channels); | |
803 | |
804 if (bitrate != -1) { | |
805 bitrate /= 1000; | |
806 | |
807 if (bitrate < 1000) { | |
808 /* Show bitrate in 1000s */ | |
809 g_snprintf(text, sizeof(text), "%3d", bitrate); | |
810 textbox_set_text(mainwin_rate_text, text); | |
811 } | |
812 else { | |
813 /* Show bitrate in 100,000s */ | |
814 bitrate /= 100; | |
815 g_snprintf(text, sizeof(text), "%2dH", bitrate); | |
816 textbox_set_text(mainwin_rate_text, text); | |
817 } | |
818 } | |
819 else | |
820 textbox_set_text(mainwin_rate_text, _("VBR")); | |
821 | |
822 /* Show sampling frequency in kHz */ | |
823 g_snprintf(text, sizeof(text), "%2d", frequency / 1000); | |
824 textbox_set_text(mainwin_freq_text, text); | |
825 | |
826 monostereo_set_num_channels(mainwin_monostereo, n_channels); | |
827 | |
828 widget_show(WIDGET(mainwin_minus_num)); | |
829 widget_show(WIDGET(mainwin_10min_num)); | |
830 widget_show(WIDGET(mainwin_min_num)); | |
831 widget_show(WIDGET(mainwin_10sec_num)); | |
832 widget_show(WIDGET(mainwin_sec_num)); | |
833 | |
834 if (!bmp_playback_get_paused()) | |
835 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
836 | |
837 if (playlist_get_current_length() != -1) { | |
838 if (cfg.player_shaded) | |
839 widget_show(WIDGET(mainwin_sposition)); | |
840 widget_show(WIDGET(mainwin_position)); | |
841 } | |
842 else { | |
843 widget_hide(WIDGET(mainwin_position)); | |
844 widget_hide(WIDGET(mainwin_sposition)); | |
845 mainwin_force_redraw = TRUE; | |
846 } | |
847 | |
848 title = playlist_get_info_text(); | |
849 mainwin_set_song_title(title); | |
850 g_free(title); | |
851 } | |
852 | |
853 void | |
854 mainwin_clear_song_info(void) | |
855 { | |
856 /* clear title */ | |
857 G_LOCK(mainwin_title); | |
858 g_free(mainwin_title_text); | |
859 mainwin_title_text = NULL; | |
860 G_UNLOCK(mainwin_title); | |
861 | |
862 /* clear sampling parameters */ | |
863 playback_set_sample_params(0, 0, 0); | |
864 | |
865 mainwin_position->hs_pressed = FALSE; | |
866 mainwin_sposition->hs_pressed = FALSE; | |
867 | |
868 /* clear sampling parameter displays */ | |
869 textbox_set_text(mainwin_rate_text, " "); | |
870 textbox_set_text(mainwin_freq_text, " "); | |
871 monostereo_set_num_channels(mainwin_monostereo, 0); | |
872 | |
873 playstatus_set_status(mainwin_playstatus, STATUS_STOP); | |
874 | |
875 /* hide playback time */ | |
876 widget_hide(WIDGET(mainwin_minus_num)); | |
877 widget_hide(WIDGET(mainwin_10min_num)); | |
878 widget_hide(WIDGET(mainwin_min_num)); | |
879 widget_hide(WIDGET(mainwin_10sec_num)); | |
880 widget_hide(WIDGET(mainwin_sec_num)); | |
881 | |
882 textbox_set_text(mainwin_stime_min, " "); | |
883 textbox_set_text(mainwin_stime_sec, " "); | |
884 | |
885 widget_hide(WIDGET(mainwin_position)); | |
886 widget_hide(WIDGET(mainwin_sposition)); | |
887 | |
888 playlistwin_hide_timer(); | |
889 draw_main_window(TRUE); | |
890 | |
891 vis_clear(active_vis); | |
892 } | |
893 | |
894 void | |
895 mainwin_disable_seekbar(void) | |
896 { | |
897 /* | |
898 * We dont call draw_main_window() here so this will not | |
899 * remove them visually. It will only prevent us from sending | |
900 * any seek calls to the input plugin before the input plugin | |
901 * calls ->set_info(). | |
902 */ | |
903 widget_hide(WIDGET(mainwin_position)); | |
904 widget_hide(WIDGET(mainwin_sposition)); | |
905 } | |
906 | |
907 static gboolean | |
908 mainwin_mouse_button_release(GtkWidget * widget, | |
909 GdkEventButton * event, | |
910 gpointer callback_data) | |
911 { | |
912 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
913 | |
914 /* | |
915 * The gdk_flush() is just for making sure that the pointer really | |
916 * gets ungrabbed before calling any button callbacks | |
917 * | |
918 */ | |
919 | |
920 gdk_flush(); | |
921 | |
922 if (dock_is_moving(GTK_WINDOW(mainwin))) { | |
923 dock_move_release(GTK_WINDOW(mainwin)); | |
924 } | |
925 | |
926 if (mainwin_menurow->mr_doublesize_selected) { | |
927 event->x /= 2; | |
928 event->y /= 2; | |
929 } | |
930 | |
931 handle_release_cb(mainwin_wlist, widget, event); | |
932 | |
933 draw_main_window(FALSE); | |
934 | |
935 return FALSE; | |
936 } | |
937 | |
938 static gboolean | |
939 mainwin_motion(GtkWidget * widget, | |
940 GdkEventMotion * event, | |
941 gpointer callback_data) | |
942 { | |
943 XEvent ev; | |
944 gint i = 0; | |
945 | |
946 XSync(GDK_DISPLAY(), False); | |
947 | |
948 while (XCheckTypedEvent(GDK_DISPLAY(), MotionNotify, &ev)) { | |
949 event->x = ev.xmotion.x; | |
950 event->y = ev.xmotion.y; | |
951 i++; | |
952 } | |
953 | |
954 if (dock_is_moving(GTK_WINDOW(mainwin))) { | |
955 dock_move_motion(GTK_WINDOW(mainwin), event); | |
956 } | |
957 else { | |
958 handle_motion_cb(mainwin_wlist, widget, event); | |
959 draw_main_window(FALSE); | |
960 } | |
961 gdk_flush(); | |
962 | |
963 return FALSE; | |
964 } | |
965 | |
966 static gboolean | |
967 inside_sensitive_widgets(gint x, gint y) | |
968 { | |
969 return (widget_contains(WIDGET(mainwin_menubtn), x, y) | |
970 || widget_contains(WIDGET(mainwin_minimize), x, y) | |
971 || widget_contains(WIDGET(mainwin_shade), x, y) | |
972 || widget_contains(WIDGET(mainwin_close), x, y) | |
973 || widget_contains(WIDGET(mainwin_rew), x, y) | |
974 || widget_contains(WIDGET(mainwin_play), x, y) | |
975 || widget_contains(WIDGET(mainwin_pause), x, y) | |
976 || widget_contains(WIDGET(mainwin_stop), x, y) | |
977 || widget_contains(WIDGET(mainwin_fwd), x, y) | |
978 || widget_contains(WIDGET(mainwin_eject), x, y) | |
979 || widget_contains(WIDGET(mainwin_shuffle), x, y) | |
980 || widget_contains(WIDGET(mainwin_repeat), x, y) | |
981 || widget_contains(WIDGET(mainwin_pl), x, y) | |
982 || widget_contains(WIDGET(mainwin_eq), x, y) | |
983 || widget_contains(WIDGET(mainwin_info), x, y) | |
984 || widget_contains(WIDGET(mainwin_menurow), x, y) | |
985 || widget_contains(WIDGET(mainwin_volume), x, y) | |
986 || widget_contains(WIDGET(mainwin_balance), x, y) | |
987 || (widget_contains(WIDGET(mainwin_position), x, y) && | |
988 widget_is_visible(WIDGET(mainwin_position))) | |
989 || widget_contains(WIDGET(mainwin_minus_num), x, y) | |
990 || widget_contains(WIDGET(mainwin_10min_num), x, y) | |
991 || widget_contains(WIDGET(mainwin_min_num), x, y) | |
992 || widget_contains(WIDGET(mainwin_10sec_num), x, y) | |
993 || widget_contains(WIDGET(mainwin_sec_num), x, y) | |
994 || widget_contains(WIDGET(mainwin_vis), x, y) | |
995 || widget_contains(WIDGET(mainwin_minimize), x, y) | |
996 || widget_contains(WIDGET(mainwin_shade), x, y) | |
997 || widget_contains(WIDGET(mainwin_close), x, y) | |
998 || widget_contains(WIDGET(mainwin_menubtn), x, y) | |
999 || widget_contains(WIDGET(mainwin_sposition), x, y) | |
1000 || widget_contains(WIDGET(mainwin_stime_min), x, y) | |
1001 || widget_contains(WIDGET(mainwin_stime_sec), x, y) | |
1002 || widget_contains(WIDGET(mainwin_srew), x, y) | |
1003 || widget_contains(WIDGET(mainwin_splay), x, y) | |
1004 || widget_contains(WIDGET(mainwin_spause), x, y) | |
1005 || widget_contains(WIDGET(mainwin_sstop), x, y) | |
1006 || widget_contains(WIDGET(mainwin_sfwd), x, y) | |
1007 || widget_contains(WIDGET(mainwin_seject), x, y) | |
1008 || widget_contains(WIDGET(mainwin_svis), x, y) | |
1009 || widget_contains(WIDGET(mainwin_about), x, y)); | |
1010 } | |
1011 | |
1012 void | |
1013 mainwin_scrolled(GtkWidget * widget, | |
1014 GdkEventScroll * event, | |
1015 gpointer callback_data) | |
1016 { | |
1017 gint d = cfg.mouse_change; | |
1018 if (event->direction == GDK_SCROLL_DOWN) | |
1019 d *= -1; | |
1020 mainwin_set_volume_diff(d); | |
1021 } | |
1022 | |
1023 | |
1024 static gboolean | |
1025 mainwin_mouse_button_press(GtkWidget * widget, | |
1026 GdkEventButton * event, | |
1027 gpointer callback_data) | |
1028 { | |
1029 | |
1030 gboolean grab = TRUE; | |
1031 | |
1032 if (event->button == 1 && event->type == GDK_BUTTON_PRESS && | |
1033 !inside_sensitive_widgets(event->x, event->y) && event->y < 14) { | |
1034 if (0 && hint_move_resize_available()) { | |
1035 hint_move_resize(mainwin, event->x_root, event->y_root, TRUE); | |
1036 grab = FALSE; | |
1037 } | |
1038 else { | |
1039 gtk_window_present(GTK_WINDOW(mainwin)); | |
1040 dock_move_press(dock_window_list, GTK_WINDOW(mainwin), event, | |
1041 TRUE); | |
1042 } | |
1043 } | |
1044 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && | |
1045 event->y < 14 && !inside_sensitive_widgets(event->x, event->y)) { | |
1046 mainwin_set_shade(!cfg.player_shaded); | |
1047 if (dock_is_moving(GTK_WINDOW(mainwin))) | |
1048 dock_move_release(GTK_WINDOW(mainwin)); | |
1049 } | |
1050 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && | |
1051 widget_contains(WIDGET(mainwin_info), event->x, event->y)) { | |
1052 playlist_fileinfo_current(); | |
1053 } | |
1054 else { | |
1055 handle_press_cb(mainwin_wlist, widget, event); | |
1056 draw_main_window(FALSE); | |
1057 } | |
1058 | |
1059 if ((event->button == 1) && event->type != GDK_2BUTTON_PRESS && | |
1060 (widget_contains(WIDGET(mainwin_vis), event->x, event->y) || | |
1061 widget_contains(WIDGET(mainwin_svis), event->x, event->y))) { | |
1062 | |
1063 cfg.vis_type++; | |
1064 | |
1065 if (cfg.vis_type > VIS_OFF) | |
1066 cfg.vis_type = VIS_ANALYZER; | |
1067 | |
1068 mainwin_vis_set_type(cfg.vis_type); | |
1069 } | |
1070 | |
1071 if (event->button == 3) { | |
1072 if (widget_contains(WIDGET(mainwin_info), event->x, event->y)) { | |
1073 util_item_factory_popup(mainwin_songname_menu, | |
1074 event->x_root, event->y_root, | |
1075 3, event->time); | |
1076 grab = FALSE; | |
1077 } | |
1078 else if (widget_contains(WIDGET(mainwin_vis), event->x, event->y) || | |
1079 widget_contains(WIDGET(mainwin_svis), event->x, event->y)) { | |
1080 util_item_factory_popup(mainwin_vis_menu, event->x_root, | |
1081 event->y_root, 3, event->time); | |
1082 grab = FALSE; | |
1083 } | |
1084 else if ( (event->y > 70) && (event->x < 128) ) | |
1085 { | |
1086 | |
1087 util_item_factory_popup(mainwin_play_menu, | |
1088 event->x_root, | |
1089 event->y_root, 3, event->time); | |
1090 grab = FALSE; | |
1091 } else { | |
1092 /* | |
1093 * Pop up the main menu a few pixels down. | |
1094 * This will avoid that anything is selected | |
1095 * if one right-clicks to focus the window | |
1096 * without raising it. | |
1097 * | |
1098 ***MD I think the above is stupid, people don't expect this | |
1099 * | |
1100 */ | |
1101 util_item_factory_popup(mainwin_general_menu, | |
1102 event->x_root, | |
1103 event->y_root, 3, event->time); | |
1104 grab = FALSE; | |
1105 } | |
1106 } | |
1107 if (event->button == 1) { | |
1108 if ((event->x > 35 && event->x < 100 && | |
1109 event->y > 25 && event->y < 40) || | |
1110 widget_contains(WIDGET(mainwin_stime_min), event->x, event->y) || | |
1111 widget_contains(WIDGET(mainwin_stime_sec), event->x, event->y)) { | |
1112 | |
1113 if (cfg.timer_mode == TIMER_ELAPSED) | |
1114 set_timer_mode(TIMER_REMAINING); | |
1115 else | |
1116 set_timer_mode(TIMER_ELAPSED); | |
1117 } | |
1118 | |
1119 } | |
1120 | |
1121 if (grab) | |
1122 gdk_pointer_grab(mainwin->window, FALSE, | |
1123 GDK_BUTTON_MOTION_MASK | | |
1124 GDK_BUTTON_RELEASE_MASK, | |
1125 GDK_WINDOW(GDK_NONE), NULL, GDK_CURRENT_TIME); | |
1126 | |
1127 return FALSE; | |
1128 } | |
1129 | |
1130 static gboolean | |
1131 mainwin_focus_in(GtkWidget * window, | |
1132 GdkEventFocus * event, | |
1133 gpointer data) | |
1134 { | |
1135 mainwin_menubtn->pb_allow_draw = TRUE; | |
1136 mainwin_minimize->pb_allow_draw = TRUE; | |
1137 mainwin_shade->pb_allow_draw = TRUE; | |
1138 mainwin_close->pb_allow_draw = TRUE; | |
1139 draw_main_window(TRUE); | |
1140 | |
1141 return TRUE; | |
1142 } | |
1143 | |
1144 | |
1145 static gboolean | |
1146 mainwin_focus_out(GtkWidget * widget, | |
1147 GdkEventFocus * event, | |
1148 gpointer callback_data) | |
1149 { | |
1150 mainwin_menubtn->pb_allow_draw = FALSE; | |
1151 mainwin_minimize->pb_allow_draw = FALSE; | |
1152 mainwin_shade->pb_allow_draw = FALSE; | |
1153 mainwin_close->pb_allow_draw = FALSE; | |
1154 draw_main_window(TRUE); | |
1155 | |
1156 return TRUE; | |
1157 } | |
1158 | |
1159 static gboolean | |
1160 mainwin_keypress(GtkWidget * grab_widget, | |
1161 GdkEventKey * event, | |
1162 gpointer data) | |
1163 { | |
1164 | |
1165 switch (event->keyval) { | |
1166 | |
1167 case GDK_Up: | |
1168 case GDK_KP_Up: | |
1169 mainwin_set_volume_diff(2); | |
1170 break; | |
1171 case GDK_Down: | |
1172 case GDK_KP_Down: | |
1173 mainwin_set_volume_diff(-2); | |
1174 break; | |
1175 case GDK_Left: | |
1176 case GDK_KP_Left: | |
1177 if (playlist_get_current_length() != -1) | |
1178 bmp_playback_seek(CLAMP | |
1179 (bmp_playback_get_time() - 5000, 0, | |
1180 playlist_get_current_length()) / 1000); | |
1181 break; | |
1182 case GDK_Right: | |
1183 case GDK_KP_Right: | |
1184 if (playlist_get_current_length() != -1) | |
1185 bmp_playback_seek(CLAMP | |
1186 (bmp_playback_get_time() + 5000, 0, | |
1187 playlist_get_current_length()) / 1000); | |
1188 break; | |
1189 case GDK_Escape: | |
1190 mainwin_minimize_cb(); | |
1191 break; | |
1192 default: | |
1193 return FALSE; | |
1194 } | |
1195 | |
1196 return TRUE; | |
1197 } | |
1198 | |
1199 static void | |
1200 mainwin_jump_to_time_cb(GtkWidget * widget, | |
1201 GtkWidget * entry) | |
1202 { | |
1203 guint min = 0, sec = 0, params, time; | |
1204 | |
1205 params = sscanf(gtk_entry_get_text(GTK_ENTRY(entry)), "%u:%u", | |
1206 &min, &sec); | |
1207 if (params == 2) | |
1208 time = (min * 60) + sec; | |
1209 else if (params == 1) | |
1210 time = min; | |
1211 else | |
1212 return; | |
1213 | |
1214 if (playlist_get_current_length() > -1 && | |
1215 time <= (playlist_get_current_length() / 1000)) { | |
1216 bmp_playback_seek(time); | |
1217 gtk_widget_destroy(mainwin_jtt); | |
1218 } | |
1219 } | |
1220 | |
1221 | |
1222 void | |
1223 mainwin_jump_to_time(void) | |
1224 { | |
1225 GtkWidget *vbox, *hbox_new, *hbox_total; | |
1226 GtkWidget *time_entry, *label, *bbox, *jump, *cancel; | |
1227 guint tindex; | |
1228 gchar time_str[10]; | |
1229 | |
1230 if (!bmp_playback_get_playing()) { | |
1231 /* FIXME: pop an error dialog and/or disable menu option to | |
1232 indicate JTT can't be launched when no track is being | |
1233 played */ | |
1234 return; | |
1235 } | |
1236 | |
1237 if (mainwin_jtt) { | |
1238 gtk_window_present(GTK_WINDOW(mainwin_jtt)); | |
1239 return; | |
1240 } | |
1241 | |
1242 mainwin_jtt = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1243 gtk_window_set_type_hint(GTK_WINDOW(mainwin_jtt), | |
1244 GDK_WINDOW_TYPE_HINT_DIALOG); | |
1245 | |
1246 gtk_window_set_title(GTK_WINDOW(mainwin_jtt), _("Jump to Time")); | |
1247 gtk_window_set_position(GTK_WINDOW(mainwin_jtt), GTK_WIN_POS_CENTER); | |
1248 gtk_window_set_transient_for(GTK_WINDOW(mainwin_jtt), | |
1249 GTK_WINDOW(mainwin)); | |
1250 | |
1251 g_signal_connect(mainwin_jtt, "destroy", | |
1252 G_CALLBACK(gtk_widget_destroyed), &mainwin_jtt); | |
1253 gtk_container_border_width(GTK_CONTAINER(mainwin_jtt), 10); | |
1254 | |
1255 vbox = gtk_vbox_new(FALSE, 5); | |
1256 gtk_container_add(GTK_CONTAINER(mainwin_jtt), vbox); | |
1257 | |
1258 hbox_new = gtk_hbox_new(FALSE, 0); | |
1259 gtk_box_pack_start(GTK_BOX(vbox), hbox_new, TRUE, TRUE, 5); | |
1260 | |
1261 time_entry = gtk_entry_new(); | |
1262 gtk_box_pack_start(GTK_BOX(hbox_new), time_entry, FALSE, FALSE, 5); | |
1263 g_signal_connect(time_entry, "activate", | |
1264 G_CALLBACK(mainwin_jump_to_time_cb), time_entry); | |
1265 | |
1266 gtk_widget_set_size_request(time_entry, 70, -1); | |
1267 label = gtk_label_new(_("minutes:seconds")); | |
1268 gtk_box_pack_start(GTK_BOX(hbox_new), label, FALSE, FALSE, 5); | |
1269 | |
1270 hbox_total = gtk_hbox_new(FALSE, 0); | |
1271 gtk_box_pack_start(GTK_BOX(vbox), hbox_total, TRUE, TRUE, 5); | |
1272 gtk_widget_show(hbox_total); | |
1273 | |
1274 /* FIXME: Disable display of current track length. It's not | |
1275 updated when track changes */ | |
1276 #if 0 | |
1277 label = gtk_label_new(_("Track length:")); | |
1278 gtk_box_pack_start(GTK_BOX(hbox_total), label, FALSE, FALSE, 5); | |
1279 | |
1280 len = playlist_get_current_length() / 1000; | |
1281 g_snprintf(time_str, sizeof(time_str), "%u:%2.2u", len / 60, len % 60); | |
1282 label = gtk_label_new(time_str); | |
1283 | |
1284 gtk_box_pack_start(GTK_BOX(hbox_total), label, FALSE, FALSE, 10); | |
1285 #endif | |
1286 | |
1287 bbox = gtk_hbutton_box_new(); | |
1288 gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 0); | |
1289 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1290 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1291 | |
1292 cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1293 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
1294 gtk_container_add(GTK_CONTAINER(bbox), cancel); | |
1295 g_signal_connect_swapped(cancel, "clicked", | |
1296 G_CALLBACK(gtk_widget_destroy), mainwin_jtt); | |
1297 | |
1298 jump = gtk_button_new_from_stock(GTK_STOCK_JUMP_TO); | |
1299 GTK_WIDGET_SET_FLAGS(jump, GTK_CAN_DEFAULT); | |
1300 gtk_container_add(GTK_CONTAINER(bbox), jump); | |
1301 g_signal_connect(jump, "clicked", | |
1302 G_CALLBACK(mainwin_jump_to_time_cb), time_entry); | |
1303 | |
1304 tindex = bmp_playback_get_time() / 1000; | |
1305 g_snprintf(time_str, sizeof(time_str), "%u:%2.2u", tindex / 60, | |
1306 tindex % 60); | |
1307 gtk_entry_set_text(GTK_ENTRY(time_entry), time_str); | |
1308 | |
1309 gtk_entry_select_region(GTK_ENTRY(time_entry), 0, strlen(time_str)); | |
1310 | |
1311 gtk_widget_show_all(mainwin_jtt); | |
1312 | |
1313 gtk_widget_grab_focus(time_entry); | |
1314 gtk_widget_grab_default(jump); | |
1315 } | |
1316 | |
1317 static void | |
1318 change_song(guint pos) | |
1319 { | |
1320 if (bmp_playback_get_playing()) | |
1321 bmp_playback_stop(); | |
1322 | |
1323 playlist_set_position(pos); | |
1324 bmp_playback_initiate(); | |
1325 } | |
1326 | |
1327 static void | |
1328 mainwin_jump_to_file_jump(GtkTreeView * treeview) | |
1329 { | |
1330 GtkTreeModel *model; | |
1331 GtkTreeSelection *selection; | |
1332 GtkTreeIter iter; | |
1333 gchar *pos_str; | |
1334 guint pos; | |
1335 | |
1336 model = gtk_tree_view_get_model(treeview); | |
1337 selection = gtk_tree_view_get_selection(treeview); | |
1338 | |
1339 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) | |
1340 return; | |
1341 | |
1342 gtk_tree_model_get(model, &iter, 0, &pos_str, -1); | |
1343 pos = g_ascii_strtoull(pos_str, NULL, 10) - 1; | |
1344 | |
1345 change_song(pos); | |
1346 | |
1347 /* FIXME: should only hide window */ | |
1348 gtk_widget_destroy(mainwin_jtf); | |
1349 mainwin_jtf = NULL; | |
1350 } | |
1351 | |
1352 static void | |
1353 mainwin_jump_to_file_jump_cb(GtkTreeView * treeview, | |
1354 gpointer data) | |
1355 { | |
1356 mainwin_jump_to_file_jump(treeview); | |
1357 } | |
1358 | |
1359 static void | |
1360 mainwin_jump_to_file_set_queue_button_label(GtkButton * button, | |
1361 guint pos) | |
1362 { | |
1363 if (playlist_is_position_queued(pos)) | |
1364 gtk_button_set_label(button, _("Un_queue")); | |
1365 else | |
1366 gtk_button_set_label(button, _("_Queue")); | |
1367 } | |
1368 | |
1369 static void | |
1370 mainwin_jump_to_file_queue_cb(GtkButton * button, | |
1371 gpointer data) | |
1372 { | |
1373 GtkTreeView *treeview; | |
1374 GtkTreeModel *model; | |
1375 GtkTreeSelection *selection; | |
1376 GtkTreeIter iter; | |
1377 gchar *pos_str; | |
1378 guint pos; | |
1379 | |
1380 treeview = GTK_TREE_VIEW(data); | |
1381 model = gtk_tree_view_get_model(treeview); | |
1382 selection = gtk_tree_view_get_selection(treeview); | |
1383 | |
1384 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) | |
1385 return; | |
1386 | |
1387 gtk_tree_model_get(model, &iter, 0, &pos_str, -1); | |
1388 pos = g_ascii_strtoull(pos_str, NULL, 10) - 1; | |
1389 | |
1390 playlist_queue_position(pos); | |
1391 | |
1392 mainwin_jump_to_file_set_queue_button_label(button, pos); | |
1393 } | |
1394 | |
1395 static void | |
1396 mainwin_jump_to_file_selection_changed_cb(GtkTreeSelection *treesel, | |
1397 gpointer data) | |
1398 { | |
1399 GtkTreeView *treeview; | |
1400 GtkTreeModel *model; | |
1401 GtkTreeSelection *selection; | |
1402 GtkTreeIter iter; | |
1403 gchar *pos_str; | |
1404 guint pos; | |
1405 | |
1406 treeview = gtk_tree_selection_get_tree_view(treesel); | |
1407 model = gtk_tree_view_get_model(treeview); | |
1408 selection = gtk_tree_view_get_selection(treeview); | |
1409 | |
1410 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) | |
1411 return; | |
1412 | |
1413 gtk_tree_model_get(model, &iter, 0, &pos_str, -1); | |
1414 pos = g_ascii_strtoull(pos_str, NULL, 10) - 1; | |
1415 | |
1416 mainwin_jump_to_file_set_queue_button_label(GTK_BUTTON(data), pos); | |
1417 } | |
1418 | |
1419 static gboolean | |
1420 mainwin_jump_to_file_keypress_cb(GtkWidget * object, | |
1421 GdkEventKey * event, | |
1422 gpointer data) | |
1423 { | |
1424 switch (event->keyval) { | |
1425 case GDK_Escape: | |
1426 /* FIXME: show only hide window */ | |
1427 gtk_widget_destroy(mainwin_jtf); | |
1428 mainwin_jtf = NULL; | |
1429 return TRUE; | |
1430 case GDK_Return: | |
1431 mainwin_jump_to_file_jump(GTK_TREE_VIEW(data)); | |
1432 return TRUE; | |
1433 default: | |
1434 return FALSE; | |
1435 }; | |
1436 } | |
1437 | |
1438 static gboolean | |
1439 mainwin_jump_to_file_match(const gchar * song, gchar ** keys) | |
1440 { | |
1441 gint i = 0; | |
1442 gchar *key; | |
1443 gchar *song_lc; | |
1444 | |
1445 song_lc = g_ascii_strdown(song, -1); | |
1446 | |
1447 while (keys[i]) { | |
1448 key = g_ascii_strdown(keys[i], -1); | |
1449 if (!g_strrstr(song_lc, key)) { | |
1450 g_free(key); | |
1451 g_free(song_lc); | |
1452 return FALSE; | |
1453 } | |
1454 | |
1455 g_free(key); | |
1456 i++; | |
1457 } | |
1458 | |
1459 g_free(song_lc); | |
1460 | |
1461 return TRUE; | |
1462 } | |
1463 | |
1464 /* FIXME: Clear the entry when the list gets updated */ | |
1465 static void | |
1466 mainwin_update_jtf(GtkWidget * widget, gpointer user_data) | |
1467 { | |
1468 /* FIXME: Is not in sync with playlist due to delayed extinfo | |
1469 * reading */ | |
1470 gint row; | |
1471 GList *playlist; | |
1472 gchar *desc_buf; | |
1473 gchar *row_str; | |
1474 GtkTreeIter iter; | |
1475 GtkTreeSelection *selection; | |
1476 | |
1477 GtkTreeModel *store; | |
1478 | |
1479 if (!mainwin_jtf) | |
1480 return; | |
1481 | |
1482 store = gtk_tree_view_get_model(GTK_TREE_VIEW(user_data)); | |
1483 gtk_list_store_clear(GTK_LIST_STORE(store)); | |
1484 | |
1485 row = 1; | |
1486 for (playlist = playlist_get(); playlist; | |
1487 playlist = g_list_next(playlist)) { | |
1488 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist->data); | |
1489 | |
1490 if (entry->title) | |
1491 desc_buf = entry->title; | |
1492 else if (strchr(entry->filename, '/')) | |
1493 desc_buf = strrchr(entry->filename, '/') + 1; | |
1494 else | |
1495 desc_buf = entry->filename; | |
1496 | |
1497 row_str = g_strdup_printf("%d", row++); | |
1498 | |
1499 gtk_list_store_append(GTK_LIST_STORE(store), &iter); | |
1500 gtk_list_store_set(GTK_LIST_STORE(store), &iter, | |
1501 0, row_str, 1, desc_buf, -1); | |
1502 | |
1503 g_free(row_str); | |
1504 } | |
1505 | |
1506 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); | |
1507 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(user_data)); | |
1508 gtk_tree_selection_select_iter(selection, &iter); | |
1509 } | |
1510 | |
1511 static void | |
1512 mainwin_jump_to_file_edit_cb(GtkEntry * entry, gpointer user_data) | |
1513 { | |
1514 GtkTreeView *treeview = GTK_TREE_VIEW(user_data); | |
1515 GtkTreeSelection *selection; | |
1516 GtkTreeIter iter; | |
1517 | |
1518 GtkListStore *store; | |
1519 | |
1520 gint song_index = 0; | |
1521 gchar **words; | |
1522 GList *playlist; | |
1523 | |
1524 gboolean match = FALSE; | |
1525 | |
1526 /* Chop the key string into ' '-separated key words */ | |
1527 words = g_strsplit(gtk_entry_get_text(entry), " ", 0); | |
1528 | |
1529 /* FIXME: Remove the connected signals before clearing | |
1530 * (row-selected will still eventually arrive once) */ | |
1531 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); | |
1532 gtk_list_store_clear(store); | |
1533 | |
1534 PLAYLIST_LOCK(); | |
1535 | |
1536 for (playlist = playlist_get(); playlist; | |
1537 playlist = g_list_next(playlist)) { | |
1538 | |
1539 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist->data); | |
1540 const gchar *title, *filename; | |
1541 | |
1542 title = entry->title; | |
1543 if (!title) { | |
1544 filename = entry->filename; | |
1545 | |
1546 if (strchr(filename, '/')) | |
1547 title = strrchr(filename, '/') + 1; | |
1548 else | |
1549 title = filename; | |
1550 } | |
1551 | |
1552 /* Compare the key words to the string - if all the words | |
1553 match, add to the ListStore */ | |
1554 | |
1555 /* | |
1556 * FIXME: The search string should be adapted to the | |
1557 * current display setting, e.g. if the user has set it to | |
1558 * "%p - %t" then build the match string like that too, or | |
1559 * even better, search for each of the tags seperatly. | |
1560 * | |
1561 * In any case the string to match should _never_ contain | |
1562 * something the user can't actually see in the playlist. | |
1563 */ | |
1564 if (words[0]) | |
1565 match = mainwin_jump_to_file_match(title, words); | |
1566 else | |
1567 match = TRUE; | |
1568 | |
1569 if (match) { | |
1570 gchar *song_index_str = g_strdup_printf("%d", song_index + 1); | |
1571 gtk_list_store_append(store, &iter); | |
1572 gtk_list_store_set(store, &iter, 0, song_index_str, 1, title, -1); | |
1573 g_free(song_index_str); | |
1574 } | |
1575 | |
1576 song_index++; | |
1577 } | |
1578 | |
1579 PLAYLIST_UNLOCK(); | |
1580 | |
1581 g_strfreev(words); | |
1582 | |
1583 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) { | |
1584 selection = gtk_tree_view_get_selection(treeview); | |
1585 gtk_tree_selection_select_iter(selection, &iter); | |
1586 } | |
1587 } | |
1588 | |
1589 void | |
1590 mainwin_jump_to_file(void) | |
1591 { | |
1592 GtkWidget *scrollwin; | |
1593 GtkWidget *vbox, *bbox, *sep; | |
1594 GtkWidget *jump, *queue, *cancel; | |
1595 GtkWidget *rescan, *edit; | |
1596 GtkWidget *search_label, *hbox; | |
1597 GList *playlist; | |
1598 gchar *desc_buf; | |
1599 gchar *row_str; | |
1600 gint row; | |
1601 | |
1602 GtkWidget *treeview; | |
1603 GtkListStore *jtf_store; | |
1604 | |
1605 GtkTreeIter iter; | |
1606 GtkCellRenderer *renderer; | |
1607 GtkTreeViewColumn *column; | |
1608 | |
1609 if (mainwin_jtf) { | |
1610 gtk_window_present(GTK_WINDOW(mainwin_jtf)); | |
1611 return; | |
1612 } | |
1613 | |
1614 mainwin_jtf = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1615 gtk_window_set_type_hint(GTK_WINDOW(mainwin_jtf), | |
1616 GDK_WINDOW_TYPE_HINT_DIALOG); | |
1617 | |
1618 gtk_window_set_title(GTK_WINDOW(mainwin_jtf), _("Jump to Track")); | |
1619 | |
1620 gtk_window_set_position(GTK_WINDOW(mainwin_jtf), GTK_WIN_POS_CENTER); | |
1621 g_signal_connect(mainwin_jtf, "destroy", | |
1622 G_CALLBACK(gtk_widget_destroyed), &mainwin_jtf); | |
1623 | |
1624 gtk_container_border_width(GTK_CONTAINER(mainwin_jtf), 10); | |
1625 gtk_window_set_default_size(GTK_WINDOW(mainwin_jtf), 550, 350); | |
1626 | |
1627 vbox = gtk_vbox_new(FALSE, 5); | |
1628 gtk_container_add(GTK_CONTAINER(mainwin_jtf), vbox); | |
1629 | |
1630 jtf_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); | |
1631 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(jtf_store)); | |
1632 g_object_unref(jtf_store); | |
1633 | |
1634 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
1635 | |
1636 column = gtk_tree_view_column_new(); | |
1637 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
1638 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1639 | |
1640 renderer = gtk_cell_renderer_text_new(); | |
1641 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1642 gtk_tree_view_column_set_attributes(column, renderer, "text", 0, NULL); | |
1643 gtk_tree_view_column_set_spacing(column, 4); | |
1644 | |
1645 renderer = gtk_cell_renderer_text_new(); | |
1646 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1647 gtk_tree_view_column_set_attributes(column, renderer, "text", 1, NULL); | |
1648 gtk_tree_view_column_set_spacing(column, 4); | |
1649 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
1650 | |
1651 g_signal_connect(treeview, "row-activated", | |
1652 G_CALLBACK(mainwin_jump_to_file_jump), NULL); | |
1653 | |
1654 hbox = gtk_hbox_new(FALSE, 3); | |
1655 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3); | |
1656 | |
1657 search_label = gtk_label_new(_("Filter: ")); | |
1658 gtk_label_set_markup_with_mnemonic(GTK_LABEL(search_label), "_Filter:"); | |
1659 gtk_box_pack_start(GTK_BOX(hbox), search_label, FALSE, FALSE, 0); | |
1660 | |
1661 edit = gtk_entry_new(); | |
1662 gtk_entry_set_editable(GTK_ENTRY(edit), TRUE); | |
1663 gtk_label_set_mnemonic_widget(GTK_LABEL(search_label), edit); | |
1664 g_signal_connect(edit, "changed", | |
1665 G_CALLBACK(mainwin_jump_to_file_edit_cb), treeview); | |
1666 | |
1667 g_signal_connect(mainwin_jtf, "key_press_event", | |
1668 G_CALLBACK(mainwin_jump_to_file_keypress_cb), treeview); | |
1669 | |
1670 gtk_box_pack_start(GTK_BOX(hbox), edit, TRUE, TRUE, 3); | |
1671 | |
1672 scrollwin = gtk_scrolled_window_new(NULL, NULL); | |
1673 gtk_container_add(GTK_CONTAINER(scrollwin), treeview); | |
1674 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), | |
1675 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1676 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin), | |
1677 GTK_SHADOW_IN); | |
1678 gtk_box_pack_start(GTK_BOX(vbox), scrollwin, TRUE, TRUE, 0); | |
1679 | |
1680 sep = gtk_hseparator_new(); | |
1681 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
1682 | |
1683 bbox = gtk_hbutton_box_new(); | |
1684 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1685 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1686 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1687 | |
1688 queue = gtk_button_new_with_mnemonic(_("_Queue")); | |
1689 gtk_box_pack_start(GTK_BOX(bbox), queue, FALSE, FALSE, 0); | |
1690 GTK_WIDGET_SET_FLAGS(queue, GTK_CAN_DEFAULT); | |
1691 g_signal_connect(queue, "clicked", | |
1692 G_CALLBACK(mainwin_jump_to_file_queue_cb), | |
1693 treeview); | |
1694 g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), "changed", | |
1695 G_CALLBACK(mainwin_jump_to_file_selection_changed_cb), | |
1696 queue); | |
1697 | |
1698 rescan = gtk_button_new_from_stock(GTK_STOCK_REFRESH); | |
1699 gtk_box_pack_start(GTK_BOX(bbox), rescan, FALSE, FALSE, 0); | |
1700 g_signal_connect(rescan, "clicked", | |
1701 G_CALLBACK(mainwin_update_jtf), treeview); | |
1702 GTK_WIDGET_SET_FLAGS(rescan, GTK_CAN_DEFAULT); | |
1703 gtk_widget_grab_default(rescan); | |
1704 | |
1705 jump = gtk_button_new_from_stock(GTK_STOCK_JUMP_TO); | |
1706 gtk_box_pack_start(GTK_BOX(bbox), jump, FALSE, FALSE, 0); | |
1707 | |
1708 g_signal_connect_swapped(jump, "clicked", | |
1709 G_CALLBACK(mainwin_jump_to_file_jump_cb), | |
1710 treeview); | |
1711 | |
1712 GTK_WIDGET_SET_FLAGS(jump, GTK_CAN_DEFAULT); | |
1713 gtk_widget_grab_default(jump); | |
1714 | |
1715 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
1716 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); | |
1717 g_signal_connect_swapped(cancel, "clicked", | |
1718 G_CALLBACK(gtk_widget_destroy), | |
1719 mainwin_jtf); | |
1720 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
1721 | |
1722 gtk_list_store_clear(jtf_store); | |
1723 | |
1724 row = 1; | |
1725 | |
1726 PLAYLIST_LOCK(); | |
1727 | |
1728 for (playlist = playlist_get(); playlist; | |
1729 playlist = g_list_next(playlist)) { | |
1730 | |
1731 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist->data); | |
1732 | |
1733 if (entry->title) | |
1734 desc_buf = entry->title; | |
1735 else if (strchr(entry->filename, '/')) | |
1736 desc_buf = strrchr(entry->filename, '/') + 1; | |
1737 else | |
1738 desc_buf = entry->filename; | |
1739 | |
1740 row_str = g_strdup_printf("%d", row++); | |
1741 | |
1742 gtk_list_store_append(GTK_LIST_STORE(jtf_store), &iter); | |
1743 gtk_list_store_set(GTK_LIST_STORE(jtf_store), &iter, | |
1744 0, row_str, 1, desc_buf, -1); | |
1745 | |
1746 g_free(row_str); | |
1747 } | |
1748 | |
1749 PLAYLIST_UNLOCK(); | |
1750 | |
1751 gtk_widget_show_all(mainwin_jtf); | |
1752 } | |
1753 | |
1754 static gboolean | |
1755 mainwin_configure(GtkWidget * window, | |
1756 GdkEventConfigure * event, | |
1757 gpointer data) | |
1758 { | |
1759 if (!GTK_WIDGET_VISIBLE(window)) | |
1760 return FALSE; | |
1761 | |
1762 if (cfg.show_wm_decorations) | |
1763 gdk_window_get_root_origin(window->window, | |
1764 &cfg.player_x, &cfg.player_y); | |
1765 else | |
1766 gdk_window_get_deskrelative_origin(window->window, | |
1767 &cfg.player_x, &cfg.player_y); | |
1768 return FALSE; | |
1769 } | |
1770 | |
1771 void | |
1772 mainwin_set_back_pixmap(void) | |
1773 { | |
1774 gdk_window_set_back_pixmap(mainwin->window, mainwin_bg, 0); | |
1775 gdk_window_clear(mainwin->window); | |
1776 } | |
1777 | |
1778 void | |
1779 mainwin_drag_data_received(GtkWidget * widget, | |
1780 GdkDragContext * context, | |
1781 gint x, | |
1782 gint y, | |
1783 GtkSelectionData * selection_data, | |
1784 guint info, | |
1785 guint time, | |
1786 gpointer user_data) | |
1787 { | |
1788 ConfigDb *db; | |
1789 gchar *path, *decoded; | |
1790 | |
1791 if (!selection_data->data) { | |
1792 g_warning("DND data string is NULL"); | |
1793 return; | |
1794 } | |
1795 | |
1796 path = (gchar *) selection_data->data; | |
1797 | |
1798 g_message(path); | |
1799 | |
1800 /* FIXME: use a real URL validator/parser */ | |
1801 | |
1802 if (str_has_prefix_nocase(path, "fonts:///")) { | |
1803 path[strlen(path) - 2] = 0; /* Why the hell a CR&LF? */ | |
1804 path += 8; | |
1805 | |
1806 /* plain, since we already stripped the first URI part */ | |
1807 decoded = xmms_urldecode_plain(path); | |
1808 | |
1809 /* Get the old font's size, and add it to the dropped | |
1810 * font's name */ | |
1811 cfg.playlist_font = g_strconcat(decoded + 1, | |
1812 strrchr(cfg.playlist_font, ' '), | |
1813 NULL); | |
1814 playlist_list_set_font(cfg.playlist_font); | |
1815 playlistwin_update_list(); | |
1816 | |
1817 g_free(decoded); | |
1818 return; | |
1819 } | |
1820 | |
1821 if (str_has_prefix_nocase(path, "file:///")) { | |
1822 path[strlen(path) - 2] = 0; /* Why the hell a CR&LF? */ | |
1823 path += 7; | |
1824 } | |
1825 else if (str_has_prefix_nocase(path, "file:")) { | |
1826 path += 5; | |
1827 } | |
1828 | |
1829 if (file_is_archive(path)) { | |
1830 bmp_active_skin_load(path); | |
1831 skin_install_skin(path); /* ...and install the skin */ | |
1832 skin_view_update(user_data); | |
1833 /* Change skin name in the config file */ | |
1834 db = bmp_cfg_db_open(); | |
1835 bmp_cfg_db_set_string(db, NULL, "skin", path); | |
1836 bmp_cfg_db_close(db); | |
1837 } | |
1838 else { | |
1839 if (input_check_file((gchar *) selection_data->data, FALSE)) { | |
1840 playlist_clear(); | |
1841 playlist_add_url((gchar *) selection_data->data); | |
1842 bmp_playback_initiate(); | |
1843 } | |
1844 } | |
1845 } | |
1846 | |
1847 static void | |
1848 dirbrowser_add_dir(const gchar * dir) | |
1849 { | |
1850 g_free(cfg.filesel_path); | |
1851 cfg.filesel_path = g_strdup(dir); | |
1852 playlist_add_dir(dir); | |
1853 } | |
1854 | |
1855 static void | |
1856 dirbrowser_on_response(GtkFileChooserDialog * dialog, | |
1857 gint result, | |
1858 gpointer data) | |
1859 { | |
1860 | |
1861 gchar *pathname; | |
1862 | |
1863 // gtk_widget_hide(GTK_WIDGET(dialog)); | |
1864 | |
1865 switch (result) { | |
1866 case GTK_RESPONSE_ACCEPT: | |
1867 pathname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
1868 dirbrowser_add_dir(pathname); | |
1869 g_free(pathname); | |
1870 break; | |
1871 | |
1872 case GTK_RESPONSE_CLOSE: | |
1873 break; | |
1874 } | |
1875 | |
1876 } | |
1877 | |
1878 | |
1879 static GtkWidget * | |
1880 dirbrowser_new(const gchar * path) | |
1881 { | |
1882 GtkWidget *dialog; | |
1883 | |
1884 dialog = gtk_file_chooser_dialog_new(_("Add Folders"), | |
1885 GTK_WINDOW(mainwin), | |
1886 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, | |
1887 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
1888 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | |
1889 NULL); | |
1890 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | |
1891 | |
1892 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | |
1893 path); | |
1894 g_signal_connect(dialog, "response", | |
1895 G_CALLBACK(dirbrowser_on_response), | |
1896 NULL); | |
1897 | |
1898 return dialog; | |
1899 } | |
1900 | |
1901 void | |
1902 mainwin_run_dirbrowser(void) | |
1903 { | |
1904 static GtkWidget *browser = NULL; | |
1905 | |
1906 if (!browser) { | |
1907 browser = dirbrowser_new(cfg.filesel_path); | |
1908 | |
1909 g_signal_connect(browser, "destroy", | |
1910 G_CALLBACK(gtk_widget_destroyed), | |
1911 &browser); | |
1912 | |
1913 gtk_widget_show(GTK_WIDGET(browser)); | |
1914 } | |
1915 | |
1916 gtk_window_present(GTK_WINDOW(browser)); | |
1917 } | |
1918 | |
1919 static void | |
1920 on_add_url_add_clicked(GtkWidget * widget, | |
1921 GtkWidget * entry) | |
1922 { | |
1923 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry)); | |
1924 if (text && *text) | |
1925 playlist_add_url(text); | |
1926 } | |
1927 | |
1928 void | |
1929 mainwin_show_add_url_window(void) | |
1930 { | |
1931 static GtkWidget *url_window = NULL; | |
1932 | |
1933 if (!url_window) { | |
1934 url_window = | |
1935 util_add_url_dialog_new(_("Add Internet Address"), | |
1936 G_CALLBACK(on_add_url_add_clicked)); | |
1937 gtk_window_set_transient_for(GTK_WINDOW(url_window), | |
1938 GTK_WINDOW(mainwin)); | |
1939 g_signal_connect(url_window, "destroy", | |
1940 G_CALLBACK(gtk_widget_destroyed), | |
1941 &url_window); | |
1942 } | |
1943 | |
1944 gtk_window_present(GTK_WINDOW(url_window)); | |
1945 } | |
1946 | |
1947 static void | |
1948 check_set(GtkItemFactory * factory, | |
1949 const gchar * path, | |
1950 gboolean active) | |
1951 { | |
1952 GtkWidget *item = gtk_item_factory_get_widget(factory, path); | |
1953 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active); | |
1954 } | |
1955 | |
1956 void | |
1957 mainwin_eject_pushed(void) | |
1958 { | |
1959 util_run_filebrowser(PLAY_BUTTON); | |
1960 } | |
1961 | |
1962 void | |
1963 mainwin_play_pushed(void) | |
1964 { | |
1965 if (bmp_playback_get_paused()) { | |
1966 bmp_playback_pause(); | |
1967 return; | |
1968 } | |
1969 | |
1970 if (playlist_get_length()) | |
1971 bmp_playback_initiate(); | |
1972 else | |
1973 mainwin_eject_pushed(); | |
1974 } | |
1975 | |
1976 void | |
1977 mainwin_stop_pushed(void) | |
1978 { | |
1979 mainwin_clear_song_info(); | |
1980 bmp_playback_stop(); | |
1981 } | |
1982 | |
1983 void | |
1984 mainwin_shuffle_pushed(gboolean toggled) | |
1985 { | |
1986 check_set(mainwin_play_menu, "/Shuffle", toggled); | |
1987 } | |
1988 | |
1989 void | |
1990 mainwin_repeat_pushed(gboolean toggled) | |
1991 { | |
1992 check_set(mainwin_play_menu, "/Repeat", toggled); | |
1993 } | |
1994 | |
1995 void | |
1996 mainwin_pl_pushed(gboolean toggled) | |
1997 { | |
1998 if (toggled) | |
1999 playlistwin_show(); | |
2000 else | |
2001 playlistwin_hide(); | |
2002 } | |
2003 | |
2004 gint | |
2005 mainwin_spos_frame_cb(gint pos) | |
2006 { | |
2007 if (mainwin_sposition) { | |
2008 if (pos < 6) | |
2009 mainwin_sposition->hs_knob_nx = mainwin_sposition->hs_knob_px = | |
2010 17; | |
2011 else if (pos < 9) | |
2012 mainwin_sposition->hs_knob_nx = mainwin_sposition->hs_knob_px = | |
2013 20; | |
2014 else | |
2015 mainwin_sposition->hs_knob_nx = mainwin_sposition->hs_knob_px = | |
2016 23; | |
2017 } | |
2018 return 1; | |
2019 } | |
2020 | |
2021 void | |
2022 mainwin_spos_motion_cb(gint pos) | |
2023 { | |
2024 gint time; | |
2025 gchar *time_msg; | |
2026 | |
2027 pos--; | |
2028 | |
2029 time = ((playlist_get_current_length() / 1000) * pos) / 12; | |
2030 | |
2031 if (cfg.timer_mode == TIMER_REMAINING) { | |
2032 time = (playlist_get_current_length() / 1000) - time; | |
2033 time_msg = g_strdup_printf("-%2.2d", time / 60); | |
2034 textbox_set_text(mainwin_stime_min, time_msg); | |
2035 g_free(time_msg); | |
2036 } | |
2037 else { | |
2038 time_msg = g_strdup_printf(" %2.2d", time / 60); | |
2039 textbox_set_text(mainwin_stime_min, time_msg); | |
2040 g_free(time_msg); | |
2041 } | |
2042 | |
2043 time_msg = g_strdup_printf("%2.2d", time % 60); | |
2044 textbox_set_text(mainwin_stime_sec, time_msg); | |
2045 g_free(time_msg); | |
2046 } | |
2047 | |
2048 void | |
2049 mainwin_spos_release_cb(gint pos) | |
2050 { | |
2051 bmp_playback_seek(((playlist_get_current_length() / 1000) * | |
2052 (pos - 1)) / 12); | |
2053 } | |
2054 | |
2055 void | |
2056 mainwin_position_motion_cb(gint pos) | |
2057 { | |
2058 gint length, time; | |
2059 gchar *seek_msg; | |
2060 | |
2061 length = playlist_get_current_length() / 1000; | |
2062 time = (length * pos) / 219; | |
2063 seek_msg = g_strdup_printf(_("SEEK TO: %d:%-2.2d/%d:%-2.2d (%d%%)"), | |
2064 time / 60, time % 60, | |
2065 length / 60, length % 60, | |
2066 (length != 0) ? (time * 100) / length : 0); | |
2067 mainwin_lock_info_text(seek_msg); | |
2068 g_free(seek_msg); | |
2069 } | |
2070 | |
2071 void | |
2072 mainwin_position_release_cb(gint pos) | |
2073 { | |
2074 gint length, time; | |
2075 | |
2076 length = playlist_get_current_length() / 1000; | |
2077 time = (length * pos) / 219; | |
2078 bmp_playback_seek(time); | |
2079 mainwin_release_info_text(); | |
2080 } | |
2081 | |
2082 gint | |
2083 mainwin_volume_frame_cb(gint pos) | |
2084 { | |
2085 return (gint) rint((pos / 52.0) * 28); | |
2086 } | |
2087 | |
2088 void | |
2089 mainwin_adjust_volume_motion(gint v) | |
2090 { | |
2091 gchar *volume_msg; | |
2092 | |
2093 setting_volume = TRUE; | |
2094 | |
2095 volume_msg = g_strdup_printf(_("VOLUME: %d%%"), v); | |
2096 mainwin_lock_info_text(volume_msg); | |
2097 g_free(volume_msg); | |
2098 | |
2099 if (balance < 0) | |
2100 input_set_volume(v, (v * (100 - abs(balance))) / 100); | |
2101 else if (balance > 0) | |
2102 input_set_volume((v * (100 - abs(balance))) / 100, v); | |
2103 else | |
2104 input_set_volume(v, v); | |
2105 } | |
2106 | |
2107 void | |
2108 mainwin_adjust_volume_release(void) | |
2109 { | |
2110 mainwin_release_info_text(); | |
2111 setting_volume = FALSE; | |
2112 read_volume(VOLUME_ADJUSTED); | |
2113 } | |
2114 | |
2115 void | |
2116 mainwin_adjust_balance_motion(gint b) | |
2117 { | |
2118 gchar *balance_msg; | |
2119 gint v, pvl, pvr; | |
2120 | |
2121 setting_volume = TRUE; | |
2122 balance = b; | |
2123 input_get_volume(&pvl, &pvr); | |
2124 v = MAX(pvl, pvr); | |
2125 if (b < 0) { | |
2126 balance_msg = g_strdup_printf(_("BALANCE: %d%% LEFT"), -b); | |
2127 input_set_volume(v, (gint) rint(((100 + b) / 100.0) * v)); | |
2128 } | |
2129 else if (b == 0) { | |
2130 balance_msg = g_strdup_printf(_("BALANCE: CENTER")); | |
2131 input_set_volume(v, v); | |
2132 } | |
2133 else { /* b > 0 */ | |
2134 balance_msg = g_strdup_printf(_("BALANCE: %d%% RIGHT"), b); | |
2135 input_set_volume((gint) rint(((100 - b) / 100.0) * v), v); | |
2136 } | |
2137 mainwin_lock_info_text(balance_msg); | |
2138 g_free(balance_msg); | |
2139 } | |
2140 | |
2141 void | |
2142 mainwin_adjust_balance_release(void) | |
2143 { | |
2144 mainwin_release_info_text(); | |
2145 setting_volume = FALSE; | |
2146 read_volume(VOLUME_ADJUSTED); | |
2147 } | |
2148 | |
2149 void | |
2150 mainwin_set_volume_slider(gint percent) | |
2151 { | |
2152 hslider_set_position(mainwin_volume, (gint) rint((percent * 51) / 100.0)); | |
2153 } | |
2154 | |
2155 void | |
2156 mainwin_set_balance_slider(gint percent) | |
2157 { | |
2158 hslider_set_position(mainwin_balance, | |
2159 (gint) rint(((percent * 12) / 100.0) + 12)); | |
2160 } | |
2161 | |
2162 void | |
2163 mainwin_volume_motion_cb(gint pos) | |
2164 { | |
2165 gint vol = (pos * 100) / 51; | |
2166 mainwin_adjust_volume_motion(vol); | |
2167 equalizerwin_set_volume_slider(vol); | |
2168 } | |
2169 | |
2170 void | |
2171 mainwin_volume_release_cb(gint pos) | |
2172 { | |
2173 mainwin_adjust_volume_release(); | |
2174 } | |
2175 | |
2176 gint | |
2177 mainwin_balance_frame_cb(gint pos) | |
2178 { | |
2179 return ((abs(pos - 12) * 28) / 13); | |
2180 } | |
2181 | |
2182 void | |
2183 mainwin_balance_motion_cb(gint pos) | |
2184 { | |
2185 gint bal = ((pos - 12) * 100) / 12; | |
2186 mainwin_adjust_balance_motion(bal); | |
2187 equalizerwin_set_balance_slider(bal); | |
2188 } | |
2189 | |
2190 void | |
2191 mainwin_balance_release_cb(gint pos) | |
2192 { | |
2193 mainwin_adjust_volume_release(); | |
2194 } | |
2195 | |
2196 void | |
2197 mainwin_set_volume_diff(gint diff) | |
2198 { | |
2199 gint vl, vr, vol; | |
2200 | |
2201 input_get_volume(&vl, &vr); | |
2202 vol = MAX(vl, vr); | |
2203 vol = CLAMP(vol + diff, 0, 100); | |
2204 | |
2205 mainwin_adjust_volume_motion(vol); | |
2206 setting_volume = FALSE; | |
2207 mainwin_set_volume_slider(vol); | |
2208 equalizerwin_set_volume_slider(vol); | |
2209 read_volume(VOLUME_SET); | |
2210 } | |
2211 | |
2212 void | |
2213 mainwin_set_balance_diff(gint diff) | |
2214 { | |
2215 gint b; | |
2216 b = CLAMP(balance + diff, -100, 100); | |
2217 mainwin_adjust_balance_motion(b); | |
2218 setting_volume = FALSE; | |
2219 mainwin_set_balance_slider(b); | |
2220 equalizerwin_set_balance_slider(b); | |
2221 read_volume(VOLUME_SET); | |
2222 } | |
2223 | |
2224 void | |
2225 mainwin_show(gboolean show) | |
2226 { | |
2227 if (show) | |
2228 mainwin_real_show(); | |
2229 else | |
2230 mainwin_real_hide(); | |
2231 } | |
2232 | |
2233 void | |
2234 mainwin_real_show(void) | |
2235 { | |
2236 cfg.player_visible = TRUE; | |
2237 | |
2238 if (cfg.player_shaded) | |
2239 vis_clear_data(active_vis); | |
2240 | |
2241 mainwin_vis_set_active_vis(MAINWIN_VIS_ACTIVE_MAINWIN); | |
2242 mainwin_set_shape_mask(); | |
2243 | |
2244 if (cfg.show_wm_decorations) { | |
2245 if (!pposition_broken && cfg.player_x != -1 | |
2246 && cfg.save_window_position) | |
2247 gtk_window_move(GTK_WINDOW(mainwin), cfg.player_x, cfg.player_y); | |
2248 | |
2249 gtk_widget_show(mainwin); | |
2250 | |
2251 if (pposition_broken && cfg.player_x != -1 | |
2252 && cfg.save_window_position) | |
2253 gtk_window_move(GTK_WINDOW(mainwin), cfg.player_x, cfg.player_y); | |
2254 | |
2255 return; | |
2256 } | |
2257 | |
2258 gtk_widget_show_all(mainwin); | |
2259 | |
2260 if (!nullmask) | |
2261 return; | |
2262 | |
2263 g_object_unref(nullmask); | |
2264 nullmask = NULL; | |
2265 | |
2266 gdk_window_set_hints(mainwin->window, 0, 0, | |
2267 PLAYER_WIDTH, PLAYER_HEIGHT, | |
2268 PLAYER_WIDTH, PLAYER_HEIGHT, | |
2269 GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); | |
2270 gtk_window_resize(GTK_WINDOW(mainwin), PLAYER_WIDTH, PLAYER_HEIGHT); | |
2271 | |
2272 if (cfg.player_x != -1 && cfg.player_y != -1) | |
2273 gtk_window_move(GTK_WINDOW(mainwin), cfg.player_x, cfg.player_y); | |
2274 | |
2275 draw_main_window(TRUE); | |
2276 | |
2277 gtk_window_present(GTK_WINDOW(mainwin)); | |
2278 } | |
2279 | |
2280 void | |
2281 mainwin_real_hide(void) | |
2282 { | |
2283 GdkGC *gc; | |
2284 GdkColor pattern; | |
2285 | |
2286 if (cfg.player_shaded) { | |
2287 svis_clear_data(mainwin_svis); | |
2288 vis_clear_data(playlistwin_vis); | |
2289 } | |
2290 | |
2291 if (!cfg.show_wm_decorations) { | |
2292 nullmask = gdk_pixmap_new(mainwin->window, 20, 20, 1); | |
2293 gc = gdk_gc_new(nullmask); | |
2294 pattern.pixel = 0; | |
2295 gdk_gc_set_foreground(gc, &pattern); | |
2296 gdk_draw_rectangle(nullmask, gc, TRUE, 0, 0, 20, 20); | |
2297 gdk_gc_destroy(gc); | |
2298 gtk_widget_shape_combine_mask(mainwin, nullmask, 0, 0); | |
2299 | |
2300 gdk_window_set_hints(mainwin->window, 0, 0, 0, 0, 0, 0, | |
2301 GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); | |
2302 gdk_window_resize(mainwin->window, 0, 0); | |
2303 } | |
2304 | |
2305 gtk_widget_hide(mainwin); | |
2306 | |
2307 mainwin_vis_set_active_vis(MAINWIN_VIS_ACTIVE_PLAYLISTWIN); | |
2308 cfg.player_visible = FALSE; | |
2309 } | |
2310 | |
2311 static void | |
2312 mainwin_songname_menu_callback(gpointer data, | |
2313 guint action, | |
2314 GtkWidget * item) | |
2315 { | |
2316 GtkCheckMenuItem *check; | |
2317 | |
2318 switch (action) { | |
2319 case MAINWIN_SONGNAME_FILEINFO: | |
2320 playlist_fileinfo_current(); | |
2321 break; | |
2322 case MAINWIN_SONGNAME_JTF: | |
2323 mainwin_jump_to_file(); | |
2324 break; | |
2325 case MAINWIN_SONGNAME_JTT: | |
2326 mainwin_jump_to_time(); | |
2327 break; | |
2328 case MAINWIN_SONGNAME_SCROLL: | |
2329 check = GTK_CHECK_MENU_ITEM(item); | |
2330 mainwin_set_title_scroll(gtk_check_menu_item_get_active(check)); | |
2331 break; | |
2332 } | |
2333 } | |
2334 | |
2335 static void | |
2336 mainwin_play_menu_callback(gpointer data, | |
2337 guint action, | |
2338 GtkWidget * item) | |
2339 { | |
2340 GtkCheckMenuItem *check; | |
2341 | |
2342 switch (action) { | |
2343 case MAINWIN_OPT_SHUFFLE: | |
2344 check = GTK_CHECK_MENU_ITEM(item); | |
2345 cfg.shuffle = gtk_check_menu_item_get_active(check); | |
2346 playlist_set_shuffle(cfg.shuffle); | |
2347 tbutton_set_toggled(mainwin_shuffle, cfg.shuffle); | |
2348 break; | |
2349 case MAINWIN_OPT_REPEAT: | |
2350 check = GTK_CHECK_MENU_ITEM(item); | |
2351 cfg.repeat = gtk_check_menu_item_get_active(check); | |
2352 tbutton_set_toggled(mainwin_repeat, cfg.repeat); | |
2353 break; | |
2354 case MAINWIN_OPT_NPA: | |
2355 check = GTK_CHECK_MENU_ITEM(item); | |
2356 cfg.no_playlist_advance = gtk_check_menu_item_get_active(check); | |
2357 break; | |
2358 } | |
2359 } | |
2360 | |
2361 | |
2362 static void | |
2363 mainwin_view_menu_callback(gpointer data, | |
2364 guint action, | |
2365 GtkWidget * item) | |
2366 { | |
2367 switch (action) { | |
2368 case MAINWIN_OPT_TELAPSED: | |
2369 set_timer_mode_menu_cb(TIMER_ELAPSED); | |
2370 break; | |
2371 case MAINWIN_OPT_TREMAINING: | |
2372 set_timer_mode_menu_cb(TIMER_REMAINING); | |
2373 break; | |
2374 case MAINWIN_OPT_ALWAYS: | |
2375 mainwin_menurow->mr_always_selected = GTK_CHECK_MENU_ITEM(item)->active; | |
2376 cfg.always_on_top = mainwin_menurow->mr_always_selected; | |
2377 widget_draw(WIDGET(mainwin_menurow)); | |
2378 hint_set_always(cfg.always_on_top); | |
2379 break; | |
2380 case MAINWIN_OPT_STICKY: | |
2381 cfg.sticky = GTK_CHECK_MENU_ITEM(item)->active; | |
2382 hint_set_sticky(cfg.sticky); | |
2383 break; | |
2384 case MAINWIN_OPT_WS: | |
2385 mainwin_set_shade_menu_cb(GTK_CHECK_MENU_ITEM(item)->active); | |
2386 break; | |
2387 case MAINWIN_OPT_PWS: | |
2388 playlistwin_set_shade(GTK_CHECK_MENU_ITEM(item)->active); | |
2389 break; | |
2390 case MAINWIN_OPT_EQWS: | |
2391 equalizerwin_set_shade_menu_cb(GTK_CHECK_MENU_ITEM(item)->active); | |
2392 break; | |
2393 } | |
2394 } | |
2395 | |
2396 void | |
2397 mainwin_vis_menu_callback(gpointer data, | |
2398 guint action, | |
2399 GtkWidget * item) | |
2400 { | |
2401 switch (action) { | |
2402 case MAINWIN_VIS_ANALYZER: | |
2403 case MAINWIN_VIS_SCOPE: | |
2404 case MAINWIN_VIS_OFF: | |
2405 mainwin_vis_set_type_menu_cb(action - MAINWIN_VIS_ANALYZER); | |
2406 break; | |
2407 case MAINWIN_VIS_ANALYZER_NORMAL: | |
2408 case MAINWIN_VIS_ANALYZER_FIRE: | |
2409 case MAINWIN_VIS_ANALYZER_VLINES: | |
2410 mainwin_vis_set_analyzer_mode(action - MAINWIN_VIS_ANALYZER_NORMAL); | |
2411 break; | |
2412 case MAINWIN_VIS_ANALYZER_LINES: | |
2413 case MAINWIN_VIS_ANALYZER_BARS: | |
2414 mainwin_vis_set_analyzer_type(action - MAINWIN_VIS_ANALYZER_LINES); | |
2415 break; | |
2416 case MAINWIN_VIS_ANALYZER_PEAKS: | |
2417 cfg.analyzer_peaks = GTK_CHECK_MENU_ITEM(item)->active; | |
2418 break; | |
2419 case MAINWIN_VIS_SCOPE_DOT: | |
2420 case MAINWIN_VIS_SCOPE_LINE: | |
2421 case MAINWIN_VIS_SCOPE_SOLID: | |
2422 cfg.scope_mode = action - MAINWIN_VIS_SCOPE_DOT; | |
2423 break; | |
2424 case MAINWIN_VIS_VU_NORMAL: | |
2425 case MAINWIN_VIS_VU_SMOOTH: | |
2426 cfg.vu_mode = action - MAINWIN_VIS_VU_NORMAL; | |
2427 break; | |
2428 case MAINWIN_VIS_REFRESH_FULL: | |
2429 case MAINWIN_VIS_REFRESH_HALF: | |
2430 case MAINWIN_VIS_REFRESH_QUARTER: | |
2431 case MAINWIN_VIS_REFRESH_EIGHTH: | |
2432 mainwin_vis_set_refresh(action - MAINWIN_VIS_REFRESH_FULL); | |
2433 break; | |
2434 case MAINWIN_VIS_AFALLOFF_SLOWEST: | |
2435 case MAINWIN_VIS_AFALLOFF_SLOW: | |
2436 case MAINWIN_VIS_AFALLOFF_MEDIUM: | |
2437 case MAINWIN_VIS_AFALLOFF_FAST: | |
2438 case MAINWIN_VIS_AFALLOFF_FASTEST: | |
2439 mainwin_vis_set_afalloff(action - MAINWIN_VIS_AFALLOFF_SLOWEST); | |
2440 break; | |
2441 case MAINWIN_VIS_PFALLOFF_SLOWEST: | |
2442 case MAINWIN_VIS_PFALLOFF_SLOW: | |
2443 case MAINWIN_VIS_PFALLOFF_MEDIUM: | |
2444 case MAINWIN_VIS_PFALLOFF_FAST: | |
2445 case MAINWIN_VIS_PFALLOFF_FASTEST: | |
2446 mainwin_vis_set_pfalloff(action - MAINWIN_VIS_PFALLOFF_SLOWEST); | |
2447 break; | |
2448 } | |
2449 } | |
2450 | |
2451 void | |
2452 mainwin_general_menu_callback(gpointer data, | |
2453 guint action, | |
2454 GtkWidget * item) | |
2455 { | |
2456 switch (action) { | |
2457 case MAINWIN_GENERAL_PREFS: | |
2458 show_prefs_window(); | |
2459 break; | |
2460 case MAINWIN_GENERAL_ABOUT: | |
2461 show_about_window(); | |
2462 break; | |
2463 case MAINWIN_GENERAL_PLAYFILE: | |
2464 util_run_filebrowser(NO_PLAY_BUTTON); | |
2465 break; | |
2466 case MAINWIN_GENERAL_PLAYDIRECTORY: | |
2467 mainwin_run_dirbrowser(); | |
2468 break; | |
2469 case MAINWIN_GENERAL_PLAYCD: | |
2470 play_medium(); | |
2471 break; | |
2472 case MAINWIN_GENERAL_ADDCD: | |
2473 add_medium(); | |
2474 break; | |
2475 case MAINWIN_GENERAL_PLAYLOCATION: | |
2476 mainwin_show_add_url_window(); | |
2477 break; | |
2478 case MAINWIN_GENERAL_FILEINFO: | |
2479 playlist_fileinfo_current(); | |
2480 break; | |
2481 case MAINWIN_GENERAL_FOCUSPLWIN: | |
2482 gtk_window_present(GTK_WINDOW(playlistwin)); | |
2483 break; | |
2484 case MAINWIN_GENERAL_SHOWPLWIN: | |
2485 if (GTK_CHECK_MENU_ITEM(item)->active) | |
2486 playlistwin_show(); | |
2487 else | |
2488 playlistwin_hide(); | |
2489 break; | |
2490 case MAINWIN_GENERAL_SHOWEQWIN: | |
2491 if (GTK_CHECK_MENU_ITEM(item)->active) | |
2492 equalizerwin_real_show(); | |
2493 else | |
2494 equalizerwin_real_hide(); | |
2495 break; | |
2496 case MAINWIN_GENERAL_PREV: | |
2497 playlist_prev(); | |
2498 break; | |
2499 case MAINWIN_GENERAL_PLAY: | |
2500 mainwin_play_pushed(); | |
2501 break; | |
2502 case MAINWIN_GENERAL_PAUSE: | |
2503 bmp_playback_pause(); | |
2504 break; | |
2505 case MAINWIN_GENERAL_STOP: | |
2506 mainwin_stop_pushed(); | |
2507 break; | |
2508 case MAINWIN_GENERAL_NEXT: | |
2509 playlist_next(); | |
2510 break; | |
2511 case MAINWIN_GENERAL_BACK5SEC: | |
2512 if (bmp_playback_get_playing() | |
2513 && playlist_get_current_length() != -1) | |
2514 bmp_playback_seek_relative(-5); | |
2515 break; | |
2516 case MAINWIN_GENERAL_FWD5SEC: | |
2517 if (bmp_playback_get_playing() | |
2518 && playlist_get_current_length() != -1) | |
2519 bmp_playback_seek_relative(5); | |
2520 break; | |
2521 case MAINWIN_GENERAL_START: | |
2522 playlist_set_position(0); | |
2523 break; | |
2524 case MAINWIN_GENERAL_JTT: | |
2525 mainwin_jump_to_time(); | |
2526 break; | |
2527 case MAINWIN_GENERAL_JTF: | |
2528 mainwin_jump_to_file(); | |
2529 break; | |
2530 case MAINWIN_GENERAL_EXIT: | |
2531 mainwin_quit_cb(); | |
2532 break; | |
2533 } | |
2534 } | |
2535 | |
2536 static void | |
2537 mainwin_mr_change(MenuRowItem i) | |
2538 { | |
2539 switch (i) { | |
2540 case MENUROW_NONE: | |
2541 mainwin_set_info_text(); | |
2542 break; | |
2543 case MENUROW_OPTIONS: | |
2544 mainwin_lock_info_text(_("OPTIONS MENU")); | |
2545 break; | |
2546 case MENUROW_ALWAYS: | |
2547 if (!hint_always_on_top_available()) { | |
2548 if (mainwin_menurow->mr_always_selected) | |
2549 mainwin_lock_info_text(_("DISABLE ALWAYS ON TOP (N/A)")); | |
2550 else | |
2551 mainwin_lock_info_text(_("ENABLE ALWAYS ON TOP (N/A)")); | |
2552 } | |
2553 else if (mainwin_menurow->mr_doublesize_selected) | |
2554 mainwin_lock_info_text(_("DISABLE ALWAYS ON TOP")); | |
2555 else | |
2556 mainwin_lock_info_text(_("ENABLE ALWAYS ON TOP")); | |
2557 break; | |
2558 case MENUROW_FILEINFOBOX: | |
2559 mainwin_lock_info_text(_("FILE INFO BOX")); | |
2560 break; | |
2561 case MENUROW_DOUBLESIZE: | |
2562 mainwin_lock_info_text(_("** DOUBLESIZE HAS BEEN REMOVED **")); | |
2563 break; | |
2564 case MENUROW_VISUALIZATION: | |
2565 mainwin_lock_info_text(_("VISUALIZATION MENU")); | |
2566 break; | |
2567 } | |
2568 } | |
2569 | |
2570 static void | |
2571 mainwin_mr_release(MenuRowItem i) | |
2572 { | |
2573 GdkModifierType modmask; | |
2574 GtkWidget *widget; | |
2575 gint x, y; | |
2576 | |
2577 switch (i) { | |
2578 case MENUROW_OPTIONS: | |
2579 gdk_window_get_pointer(NULL, &x, &y, &modmask); | |
2580 util_item_factory_popup(mainwin_view_menu, x, y, 1, | |
2581 GDK_CURRENT_TIME); | |
2582 break; | |
2583 case MENUROW_ALWAYS: | |
2584 widget = | |
2585 gtk_item_factory_get_widget(mainwin_view_menu, | |
2586 "/Always On Top"); | |
2587 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), | |
2588 mainwin_menurow->mr_always_selected); | |
2589 break; | |
2590 case MENUROW_FILEINFOBOX: | |
2591 playlist_fileinfo_current(); | |
2592 break; | |
2593 case MENUROW_DOUBLESIZE: | |
2594 /* double size removed, do nothing */ | |
2595 break; | |
2596 case MENUROW_VISUALIZATION: | |
2597 gdk_window_get_pointer(NULL, &x, &y, &modmask); | |
2598 util_item_factory_popup(mainwin_vis_menu, x, y, 1, GDK_CURRENT_TIME); | |
2599 break; | |
2600 case MENUROW_NONE: | |
2601 break; | |
2602 } | |
2603 mainwin_release_info_text(); | |
2604 } | |
2605 | |
2606 static void | |
2607 run_no_audiocd_dialog(void) | |
2608 { | |
2609 const gchar *markup = | |
2610 N_("<b><big>No playable CD found.</big></b>\n\n" | |
2611 "No CD inserted, or inserted CD is not an audio CD.\n"); | |
2612 | |
2613 GtkWidget *dialog = | |
2614 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
2615 GTK_DIALOG_DESTROY_WITH_PARENT, | |
2616 GTK_MESSAGE_ERROR, | |
2617 GTK_BUTTONS_OK, | |
2618 _(markup)); | |
2619 gtk_dialog_run(GTK_DIALOG(dialog)); | |
2620 gtk_widget_destroy(dialog); | |
2621 } | |
2622 | |
2623 static void | |
2624 run_no_output_device_dialog(void) | |
2625 { | |
2626 const gchar *markup = | |
2627 N_("<b><big>Couldn't open audio.</big></b>\n\n" | |
2628 "Please check that:\n" | |
2629 "1. You have the correct output plugin selected.\n" | |
2630 "2. No other programs is blocking the soundcard.\n" | |
2631 "3. Your soundcard is configured properly.\n"); | |
2632 | |
2633 GtkWidget *dialog = | |
2634 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
2635 GTK_DIALOG_DESTROY_WITH_PARENT, | |
2636 GTK_MESSAGE_ERROR, | |
2637 GTK_BUTTONS_OK, | |
2638 _(markup)); | |
2639 gtk_dialog_run(GTK_DIALOG(dialog)); | |
2640 gtk_widget_destroy(dialog); | |
2641 } | |
2642 | |
2643 | |
2644 void | |
2645 add_medium(void) | |
2646 { | |
2647 GList *list, *node; | |
2648 gchar *filename; | |
2649 gchar *path; | |
2650 ConfigDb *db; | |
2651 | |
2652 db = bmp_cfg_db_open(); | |
2653 | |
2654 bmp_cfg_db_get_string(db, "CDDA", "directory", &path); | |
2655 bmp_cfg_db_close(db); | |
2656 | |
2657 if (!(list = input_scan_dir(path))) { | |
2658 run_no_audiocd_dialog(); | |
2659 return; | |
2660 } | |
2661 | |
2662 for (node = list; node; node = g_list_next(node)) { | |
2663 filename = g_build_filename(path, node->data, NULL); | |
2664 playlist_add(filename); | |
2665 g_free(filename); | |
2666 g_free(node->data); | |
2667 } | |
2668 | |
2669 g_free(path); | |
2670 g_list_free(list); | |
2671 | |
2672 } | |
2673 | |
2674 void | |
2675 play_medium(void) | |
2676 { | |
2677 GList *list, *node; | |
2678 gchar *filename; | |
2679 gchar *path; | |
2680 ConfigDb *db; | |
2681 | |
2682 db = bmp_cfg_db_open(); | |
2683 bmp_cfg_db_get_string(db, "CDDA", "directory", &path); | |
2684 bmp_cfg_db_close(db); | |
2685 | |
2686 if (!(list = input_scan_dir(path))) { | |
2687 run_no_audiocd_dialog(); | |
2688 return; | |
2689 } | |
2690 | |
2691 playlist_clear(); | |
2692 | |
2693 for (node = list; node; node = g_list_next(node)) { | |
2694 filename = g_build_filename(path, node->data, NULL); | |
2695 playlist_add(filename); | |
2696 g_free(filename); | |
2697 g_free(node->data); | |
2698 } | |
2699 | |
2700 g_free(path); | |
2701 g_list_free(list); | |
2702 | |
2703 playlist_set_position(0); | |
2704 bmp_playback_initiate(); | |
2705 } | |
2706 | |
2707 void | |
2708 read_volume(gint when) | |
2709 { | |
2710 static gint pvl = 0, pvr = 0; | |
2711 static gint times = VOLSET_DISP_TIMES; | |
2712 static gboolean changing = FALSE; | |
2713 | |
2714 gint vl, vr, b, v; | |
2715 | |
2716 input_get_volume(&vl, &vr); | |
2717 | |
2718 switch (when) { | |
2719 case VOLSET_STARTUP: | |
2720 vl = CLAMP(vl, 0, 100); | |
2721 vr = CLAMP(vr, 0, 100); | |
2722 pvl = vl; | |
2723 pvr = vr; | |
2724 v = MAX(vl, vr); | |
2725 if (vl > vr) | |
2726 b = (gint) rint(((gdouble) vr / vl) * 100) - 100; | |
2727 else if (vl < vr) | |
2728 b = 100 - (gint) rint(((gdouble) vl / vr) * 100); | |
2729 else | |
2730 b = 0; | |
2731 | |
2732 balance = b; | |
2733 mainwin_set_volume_slider(v); | |
2734 equalizerwin_set_volume_slider(v); | |
2735 mainwin_set_balance_slider(b); | |
2736 equalizerwin_set_balance_slider(b); | |
2737 return; | |
2738 | |
2739 case VOLSET_UPDATE: | |
2740 if (vl == -1 || vr == -1) | |
2741 return; | |
2742 | |
2743 if (setting_volume) { | |
2744 pvl = vl; | |
2745 pvr = vr; | |
2746 return; | |
2747 } | |
2748 | |
2749 if (pvr == vr && pvl == vl && changing) { | |
2750 if (times < VOLSET_DISP_TIMES) | |
2751 times++; | |
2752 else { | |
2753 mainwin_release_info_text(); | |
2754 changing = FALSE; | |
2755 } | |
2756 } | |
2757 else if (pvr != vr || pvl != vl) { | |
2758 gchar *tmp; | |
2759 | |
2760 v = MAX(vl, vr); | |
2761 if (vl > vr) | |
2762 b = (gint) rint(((gdouble) vr / vl) * 100) - 100; | |
2763 else if (vl < vr) | |
2764 b = 100 - (gint) rint(((gdouble) vl / vr) * 100); | |
2765 else | |
2766 b = 0; | |
2767 | |
2768 if (MAX(vl, vr) != MAX(pvl, pvr)) | |
2769 tmp = g_strdup_printf(_("VOLUME: %d%%"), v); | |
2770 else { | |
2771 if (vl > vr) { | |
2772 tmp = g_strdup_printf(_("BALANCE: %d%% LEFT"), -b); | |
2773 } | |
2774 else if (vr == vl) | |
2775 tmp = g_strdup_printf(_("BALANCE: CENTER")); | |
2776 else { /* (vl < vr) */ | |
2777 tmp = g_strdup_printf(_("BALANCE: %d%% RIGHT"), b); | |
2778 } | |
2779 } | |
2780 mainwin_lock_info_text(tmp); | |
2781 g_free(tmp); | |
2782 | |
2783 pvr = vr; | |
2784 pvl = vl; | |
2785 times = 0; | |
2786 changing = TRUE; | |
2787 mainwin_set_volume_slider(v); | |
2788 equalizerwin_set_volume_slider(v); | |
2789 | |
2790 /* Don't change the balance slider if the volume has been | |
2791 * set to zero. The balance can be anything, and our best | |
2792 * guess is what is was before. */ | |
2793 if (v > 0) { | |
2794 balance = b; | |
2795 mainwin_set_balance_slider(b); | |
2796 equalizerwin_set_balance_slider(b); | |
2797 } | |
2798 } | |
2799 break; | |
2800 | |
2801 case VOLUME_ADJUSTED: | |
2802 pvl = vl; | |
2803 pvr = vr; | |
2804 break; | |
2805 | |
2806 case VOLUME_SET: | |
2807 times = 0; | |
2808 changing = TRUE; | |
2809 pvl = vl; | |
2810 pvr = vr; | |
2811 break; | |
2812 } | |
2813 } | |
2814 | |
2815 | |
2816 /* TODO: HAL! */ | |
2817 gboolean | |
2818 can_play_cd(void) | |
2819 { | |
2820 GList *ilist; | |
2821 | |
2822 for (ilist = get_input_list(); ilist; ilist = g_list_next(ilist)) { | |
2823 InputPlugin *ip = INPUT_PLUGIN(ilist->data); | |
2824 | |
2825 if (!g_ascii_strcasecmp(g_basename(ip->filename), | |
2826 PLUGIN_FILENAME("cdaudio"))) { | |
2827 return TRUE; | |
2828 } | |
2829 } | |
2830 | |
2831 return FALSE; | |
2832 } | |
2833 | |
2834 | |
2835 static void | |
2836 set_timer_mode(TimerMode mode) | |
2837 { | |
2838 if (mode == TIMER_ELAPSED) | |
2839 check_set(mainwin_view_menu, "/Time Elapsed", TRUE); | |
2840 else | |
2841 check_set(mainwin_view_menu, "/Time Remaining", TRUE); | |
2842 } | |
2843 | |
2844 static void | |
2845 set_timer_mode_menu_cb(TimerMode mode) | |
2846 { | |
2847 cfg.timer_mode = mode; | |
2848 } | |
2849 | |
2850 | |
2851 void | |
2852 mainwin_setup_menus(void) | |
2853 { | |
2854 set_timer_mode(cfg.timer_mode); | |
2855 | |
2856 /* View menu */ | |
2857 | |
2858 check_set(mainwin_view_menu, "/Always On Top", cfg.always_on_top); | |
2859 check_set(mainwin_view_menu, "/Put on All Workspaces", cfg.sticky); | |
2860 check_set(mainwin_view_menu, "/Roll up Player", cfg.player_shaded); | |
2861 check_set(mainwin_view_menu, "/Roll up Playlist Editor", cfg.playlist_shaded); | |
2862 check_set(mainwin_view_menu, "/Roll up Equalizer", cfg.equalizer_shaded); | |
2863 | |
2864 /* Songname menu */ | |
2865 | |
2866 check_set(mainwin_songname_menu, "/Autoscroll Songname", cfg.autoscroll); | |
2867 | |
2868 /* Playback menu */ | |
2869 | |
2870 check_set(mainwin_play_menu, "/Repeat", cfg.repeat); | |
2871 check_set(mainwin_play_menu, "/Shuffle", cfg.shuffle); | |
2872 | |
2873 /* Visualization menu */ | |
2874 | |
2875 check_set(mainwin_vis_menu, | |
2876 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_VIS_MODE + | |
2877 cfg.vis_type].path, TRUE); | |
2878 check_set(mainwin_vis_menu, | |
2879 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_ANALYZER_MODE + | |
2880 cfg.analyzer_mode].path, TRUE); | |
2881 check_set(mainwin_vis_menu, | |
2882 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_ANALYZER_TYPE + | |
2883 cfg.analyzer_type].path, TRUE); | |
2884 check_set(mainwin_vis_menu, | |
2885 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_ANALYZER_PEAKS]. | |
2886 path, cfg.analyzer_peaks); | |
2887 check_set(mainwin_vis_menu, | |
2888 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_SCOPE_MODE + | |
2889 cfg.scope_mode].path, TRUE); | |
2890 check_set(mainwin_vis_menu, | |
2891 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_WSHADEVU_MODE + | |
2892 cfg.vu_mode].path, TRUE); | |
2893 check_set(mainwin_vis_menu, | |
2894 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_REFRESH_RATE + | |
2895 cfg.vis_refresh].path, TRUE); | |
2896 check_set(mainwin_vis_menu, | |
2897 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_AFALLOFF + | |
2898 cfg.analyzer_falloff].path, TRUE); | |
2899 check_set(mainwin_vis_menu, | |
2900 mainwin_vis_menu_entries[MAINWIN_VIS_MENU_PFALLOFF + | |
2901 cfg.peaks_falloff].path, TRUE); | |
2902 } | |
2903 | |
2904 static void | |
2905 mainwin_create_widgets(void) | |
2906 { | |
2907 mainwin_menubtn = | |
2908 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 6, 3, 9, 9, | |
2909 0, 0, 0, 9, mainwin_menubtn_cb, SKIN_TITLEBAR); | |
2910 mainwin_menubtn->pb_allow_draw = FALSE; | |
2911 mainwin_minimize = | |
2912 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 244, 3, 9, | |
2913 9, 9, 0, 9, 9, mainwin_minimize_cb, SKIN_TITLEBAR); | |
2914 mainwin_minimize->pb_allow_draw = FALSE; | |
2915 mainwin_shade = | |
2916 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 254, 3, 9, | |
2917 9, 0, cfg.player_shaded ? 27 : 18, 9, | |
2918 cfg.player_shaded ? 27 : 18, mainwin_shade_toggle, | |
2919 SKIN_TITLEBAR); | |
2920 mainwin_shade->pb_allow_draw = FALSE; | |
2921 mainwin_close = | |
2922 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 264, 3, 9, | |
2923 9, 18, 0, 18, 9, mainwin_quit_cb, SKIN_TITLEBAR); | |
2924 mainwin_close->pb_allow_draw = FALSE; | |
2925 | |
2926 mainwin_rew = | |
2927 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 16, 88, 23, | |
2928 18, 0, 0, 0, 18, playlist_prev, SKIN_CBUTTONS); | |
2929 mainwin_play = | |
2930 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 39, 88, 23, | |
2931 18, 23, 0, 23, 18, mainwin_play_pushed, SKIN_CBUTTONS); | |
2932 mainwin_pause = | |
2933 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 62, 88, 23, | |
2934 18, 46, 0, 46, 18, bmp_playback_pause, SKIN_CBUTTONS); | |
2935 mainwin_stop = | |
2936 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 85, 88, 23, | |
2937 18, 69, 0, 69, 18, mainwin_stop_pushed, SKIN_CBUTTONS); | |
2938 mainwin_fwd = | |
2939 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 108, 88, 22, | |
2940 18, 92, 0, 92, 18, playlist_next, SKIN_CBUTTONS); | |
2941 mainwin_eject = | |
2942 create_pbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 136, 89, 22, | |
2943 16, 114, 0, 114, 16, mainwin_eject_pushed, | |
2944 SKIN_CBUTTONS); | |
2945 | |
2946 mainwin_srew = | |
2947 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 169, 4, 8, | |
2948 7, playlist_prev); | |
2949 mainwin_splay = | |
2950 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 177, 4, 10, | |
2951 7, mainwin_play_pushed); | |
2952 mainwin_spause = | |
2953 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 187, 4, 10, | |
2954 7, bmp_playback_pause); | |
2955 mainwin_sstop = | |
2956 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 197, 4, 9, | |
2957 7, mainwin_stop_pushed); | |
2958 mainwin_sfwd = | |
2959 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 206, 4, 8, | |
2960 7, playlist_next); | |
2961 mainwin_seject = | |
2962 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 216, 4, 9, | |
2963 7, mainwin_eject_pushed); | |
2964 | |
2965 mainwin_shuffle = | |
2966 create_tbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 164, 89, 46, | |
2967 15, 28, 0, 28, 15, 28, 30, 28, 45, | |
2968 mainwin_shuffle_pushed, SKIN_SHUFREP); | |
2969 | |
2970 mainwin_repeat = | |
2971 create_tbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 210, 89, 28, | |
2972 15, 0, 0, 0, 15, 0, 30, 0, 45, | |
2973 mainwin_repeat_pushed, SKIN_SHUFREP); | |
2974 | |
2975 mainwin_eq = | |
2976 create_tbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 219, 58, 23, | |
2977 12, 0, 61, 46, 61, 0, 73, 46, 73, equalizerwin_show, | |
2978 SKIN_SHUFREP); | |
2979 tbutton_set_toggled(mainwin_eq, cfg.equalizer_visible); | |
2980 mainwin_pl = | |
2981 create_tbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 242, 58, 23, | |
2982 12, 23, 61, 69, 61, 23, 73, 69, 73, | |
2983 mainwin_pl_pushed, SKIN_SHUFREP); | |
2984 tbutton_set_toggled(mainwin_pl, cfg.playlist_visible); | |
2985 | |
2986 mainwin_info = | |
2987 create_textbox(&mainwin_wlist, mainwin_bg, mainwin_gc, 112, 27, | |
2988 153, 1, SKIN_TEXT); | |
2989 textbox_set_scroll(mainwin_info, cfg.autoscroll); | |
2990 textbox_set_xfont(mainwin_info, TRUE, cfg.mainwin_font); | |
2991 mainwin_rate_text = | |
2992 create_textbox(&mainwin_wlist, mainwin_bg, mainwin_gc, 111, 43, 15, | |
2993 0, SKIN_TEXT); | |
2994 mainwin_freq_text = | |
2995 create_textbox(&mainwin_wlist, mainwin_bg, mainwin_gc, 156, 43, 10, | |
2996 0, SKIN_TEXT); | |
2997 | |
2998 mainwin_menurow = | |
2999 create_menurow(&mainwin_wlist, mainwin_bg, mainwin_gc, 10, 22, 304, | |
3000 0, 304, 44, mainwin_mr_change, mainwin_mr_release, | |
3001 SKIN_TITLEBAR); | |
3002 mainwin_menurow->mr_doublesize_selected = FALSE; | |
3003 mainwin_menurow->mr_always_selected = cfg.always_on_top; | |
3004 | |
3005 mainwin_volume = | |
3006 create_hslider(&mainwin_wlist, mainwin_bg, mainwin_gc, 107, 57, 68, | |
3007 13, 15, 422, 0, 422, 14, 11, 15, 0, 0, 51, | |
3008 mainwin_volume_frame_cb, mainwin_volume_motion_cb, | |
3009 mainwin_volume_release_cb, SKIN_VOLUME); | |
3010 mainwin_balance = | |
3011 create_hslider(&mainwin_wlist, mainwin_bg, mainwin_gc, 177, 57, 38, | |
3012 13, 15, 422, 0, 422, 14, 11, 15, 9, 0, 24, | |
3013 mainwin_balance_frame_cb, mainwin_balance_motion_cb, | |
3014 mainwin_balance_release_cb, SKIN_BALANCE); | |
3015 | |
3016 mainwin_monostereo = | |
3017 create_monostereo(&mainwin_wlist, mainwin_bg, mainwin_gc, 212, 41, | |
3018 SKIN_MONOSTEREO); | |
3019 | |
3020 mainwin_playstatus = | |
3021 create_playstatus(&mainwin_wlist, mainwin_bg, mainwin_gc, 24, 28); | |
3022 | |
3023 mainwin_minus_num = | |
3024 create_number(&mainwin_wlist, mainwin_bg, mainwin_gc, 36, 26, | |
3025 SKIN_NUMBERS); | |
3026 widget_hide(WIDGET(mainwin_minus_num)); | |
3027 mainwin_10min_num = | |
3028 create_number(&mainwin_wlist, mainwin_bg, mainwin_gc, 48, 26, | |
3029 SKIN_NUMBERS); | |
3030 widget_hide(WIDGET(mainwin_10min_num)); | |
3031 | |
3032 mainwin_min_num = | |
3033 create_number(&mainwin_wlist, mainwin_bg, mainwin_gc, 60, 26, | |
3034 SKIN_NUMBERS); | |
3035 widget_hide(WIDGET(mainwin_min_num)); | |
3036 | |
3037 mainwin_10sec_num = | |
3038 create_number(&mainwin_wlist, mainwin_bg, mainwin_gc, 78, 26, | |
3039 SKIN_NUMBERS); | |
3040 widget_hide(WIDGET(mainwin_10sec_num)); | |
3041 | |
3042 mainwin_sec_num = | |
3043 create_number(&mainwin_wlist, mainwin_bg, mainwin_gc, 90, 26, | |
3044 SKIN_NUMBERS); | |
3045 widget_hide(WIDGET(mainwin_sec_num)); | |
3046 | |
3047 mainwin_about = | |
3048 create_sbutton(&mainwin_wlist, mainwin_bg, mainwin_gc, 247, 83, 20, | |
3049 25, show_about_window); | |
3050 | |
3051 mainwin_vis = | |
3052 create_vis(&mainwin_wlist, mainwin_bg, mainwin->window, mainwin_gc, | |
3053 24, 43, 76); | |
3054 mainwin_svis = create_svis(&mainwin_wlist, mainwin_bg, mainwin_gc, 79, 5); | |
3055 active_vis = mainwin_vis; | |
3056 | |
3057 mainwin_position = | |
3058 create_hslider(&mainwin_wlist, mainwin_bg, mainwin_gc, 16, 72, 248, | |
3059 10, 248, 0, 278, 0, 29, 10, 10, 0, 0, 219, NULL, | |
3060 mainwin_position_motion_cb, | |
3061 mainwin_position_release_cb, SKIN_POSBAR); | |
3062 widget_hide(WIDGET(mainwin_position)); | |
3063 | |
3064 mainwin_sposition = | |
3065 create_hslider(&mainwin_wlist, mainwin_bg, mainwin_gc, 226, 4, 17, | |
3066 7, 17, 36, 17, 36, 3, 7, 36, 0, 1, 13, | |
3067 mainwin_spos_frame_cb, mainwin_spos_motion_cb, | |
3068 mainwin_spos_release_cb, SKIN_TITLEBAR); | |
3069 widget_hide(WIDGET(mainwin_sposition)); | |
3070 | |
3071 mainwin_stime_min = | |
3072 create_textbox(&mainwin_wlist, mainwin_bg, mainwin_gc, 130, 4, 15, | |
3073 FALSE, SKIN_TEXT); | |
3074 mainwin_stime_sec = | |
3075 create_textbox(&mainwin_wlist, mainwin_bg, mainwin_gc, 147, 4, 10, | |
3076 FALSE, SKIN_TEXT); | |
3077 | |
3078 if (!cfg.player_shaded) { | |
3079 widget_hide(WIDGET(mainwin_svis)); | |
3080 widget_hide(WIDGET(mainwin_srew)); | |
3081 widget_hide(WIDGET(mainwin_splay)); | |
3082 widget_hide(WIDGET(mainwin_spause)); | |
3083 widget_hide(WIDGET(mainwin_sstop)); | |
3084 widget_hide(WIDGET(mainwin_sfwd)); | |
3085 widget_hide(WIDGET(mainwin_seject)); | |
3086 widget_hide(WIDGET(mainwin_stime_min)); | |
3087 widget_hide(WIDGET(mainwin_stime_sec)); | |
3088 } | |
3089 | |
3090 } | |
3091 | |
3092 static void | |
3093 mainwin_create_window(void) | |
3094 { | |
3095 gint width, height; | |
3096 | |
3097 mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3098 gtk_window_set_title(GTK_WINDOW(mainwin), _("Audacious")); | |
3099 gtk_window_set_role(GTK_WINDOW(mainwin), "player"); | |
3100 gtk_window_set_resizable(GTK_WINDOW(mainwin), FALSE); | |
3101 | |
3102 width = MAINWIN_WIDTH; | |
3103 height = cfg.player_shaded ? MAINWIN_SHADED_HEIGHT : MAINWIN_HEIGHT; | |
3104 | |
3105 gtk_widget_set_size_request(mainwin, width, height); | |
3106 gtk_widget_set_app_paintable(mainwin, TRUE); | |
3107 | |
3108 dock_window_list = dock_window_set_decorated(dock_window_list, | |
3109 GTK_WINDOW(mainwin), | |
3110 cfg.show_wm_decorations); | |
3111 | |
3112 if (cfg.player_x != -1 && cfg.save_window_position) | |
3113 gtk_window_move(GTK_WINDOW(mainwin), cfg.player_x, cfg.player_y); | |
3114 | |
3115 gtk_widget_add_events(mainwin, | |
3116 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
3117 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
3118 GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK | | |
3119 GDK_VISIBILITY_NOTIFY_MASK); | |
3120 gtk_widget_realize(mainwin); | |
3121 | |
3122 util_set_cursor(mainwin); | |
3123 | |
3124 g_signal_connect(mainwin, "destroy", G_CALLBACK(mainwin_destroy), NULL); | |
3125 g_signal_connect(mainwin, "button_press_event", | |
3126 G_CALLBACK(mainwin_mouse_button_press), NULL); | |
3127 g_signal_connect(mainwin, "scroll_event", | |
3128 G_CALLBACK(mainwin_scrolled), NULL); | |
3129 g_signal_connect(mainwin, "button_release_event", | |
3130 G_CALLBACK(mainwin_mouse_button_release), NULL); | |
3131 g_signal_connect(mainwin, "motion_notify_event", | |
3132 G_CALLBACK(mainwin_motion), NULL); | |
3133 g_signal_connect_after(mainwin, "focus_in_event", | |
3134 G_CALLBACK(mainwin_focus_in), NULL); | |
3135 g_signal_connect_after(mainwin, "focus_out_event", | |
3136 G_CALLBACK(mainwin_focus_out), NULL); | |
3137 g_signal_connect(mainwin, "configure_event", | |
3138 G_CALLBACK(mainwin_configure), NULL); | |
3139 g_signal_connect(mainwin, "style_set", | |
3140 G_CALLBACK(mainwin_set_back_pixmap), NULL); | |
3141 | |
3142 bmp_drag_dest_set(mainwin); | |
3143 | |
3144 g_signal_connect(mainwin, "key_press_event", | |
3145 G_CALLBACK(mainwin_keypress), NULL); | |
3146 } | |
3147 | |
3148 static void | |
3149 mainwin_create_menus(void) | |
3150 { | |
3151 mainwin_general_menu = create_menu(mainwin_general_menu_entries, | |
3152 mainwin_general_menu_entries_num, | |
3153 mainwin_accel); | |
3154 | |
3155 mainwin_play_menu = create_menu(mainwin_playback_menu_entries, | |
3156 mainwin_playback_menu_entries_num, | |
3157 mainwin_accel); | |
3158 | |
3159 mainwin_view_menu = create_menu(mainwin_view_menu_entries, | |
3160 mainwin_view_menu_entries_num, | |
3161 mainwin_accel); | |
3162 | |
3163 mainwin_songname_menu = create_menu(mainwin_songname_menu_entries, | |
3164 mainwin_songname_menu_entries_num, | |
3165 mainwin_accel); | |
3166 | |
3167 mainwin_add_menu = create_menu(mainwin_add_menu_entries, | |
3168 mainwin_add_menu_entries_num, | |
3169 mainwin_accel); | |
3170 | |
3171 mainwin_vis_menu = create_menu(mainwin_vis_menu_entries, | |
3172 mainwin_vis_menu_entries_num, | |
3173 mainwin_accel); | |
3174 | |
3175 make_submenu(mainwin_general_menu, "/View", mainwin_view_menu); | |
3176 | |
3177 gtk_window_add_accel_group(GTK_WINDOW(mainwin), mainwin_accel); | |
3178 } | |
3179 | |
3180 void | |
3181 mainwin_create(void) | |
3182 { | |
3183 mainwin_create_window(); | |
3184 | |
3185 mainwin_accel = gtk_accel_group_new(); | |
3186 mainwin_create_menus(); | |
3187 | |
3188 mainwin_gc = gdk_gc_new(mainwin->window); | |
3189 mainwin_bg = gdk_pixmap_new(mainwin->window, | |
3190 MAINWIN_WIDTH, MAINWIN_HEIGHT, -1); | |
3191 mainwin_set_back_pixmap(); | |
3192 mainwin_create_widgets(); | |
3193 | |
3194 vis_set_window(mainwin_vis, mainwin->window); | |
3195 } | |
3196 | |
3197 void | |
3198 mainwin_attach_idle_func(void) | |
3199 { | |
3200 mainwin_timeout_id = g_timeout_add(MAINWIN_UPDATE_INTERVAL, | |
3201 mainwin_idle_func, NULL); | |
3202 } | |
3203 | |
3204 static gboolean | |
3205 idle_func_change_song(gboolean waiting) | |
3206 { | |
3207 static GTimer *pause_timer = NULL; | |
3208 | |
3209 if (!pause_timer) | |
3210 pause_timer = g_timer_new(); | |
3211 | |
3212 if (cfg.pause_between_songs) { | |
3213 gint timeleft; | |
3214 | |
3215 if (!waiting) { | |
3216 g_timer_start(pause_timer); | |
3217 waiting = TRUE; | |
3218 } | |
3219 | |
3220 timeleft = cfg.pause_between_songs_time - | |
3221 (gint) g_timer_elapsed(pause_timer, NULL); | |
3222 | |
3223 number_set_number(mainwin_10min_num, timeleft / 600); | |
3224 number_set_number(mainwin_min_num, (timeleft / 60) % 10); | |
3225 number_set_number(mainwin_10sec_num, (timeleft / 10) % 6); | |
3226 number_set_number(mainwin_sec_num, timeleft % 10); | |
3227 | |
3228 if (!mainwin_sposition->hs_pressed) { | |
3229 gchar time_str[5]; | |
3230 | |
3231 g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft / 60); | |
3232 textbox_set_text(mainwin_stime_min, time_str); | |
3233 | |
3234 g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft % 60); | |
3235 textbox_set_text(mainwin_stime_sec, time_str); | |
3236 } | |
3237 | |
3238 playlistwin_set_time(timeleft * 1000, 0, TIMER_ELAPSED); | |
3239 } | |
3240 | |
3241 if (!cfg.pause_between_songs || | |
3242 g_timer_elapsed(pause_timer, NULL) >= cfg.pause_between_songs_time) { | |
3243 | |
3244 GDK_THREADS_ENTER(); | |
3245 playlist_eof_reached(); | |
3246 GDK_THREADS_LEAVE(); | |
3247 | |
3248 waiting = FALSE; | |
3249 } | |
3250 | |
3251 return waiting; | |
3252 } | |
3253 | |
3254 static void | |
3255 idle_func_update_song_info(gint time) | |
3256 { | |
3257 gint length, t; | |
3258 gchar stime_prefix; | |
3259 | |
3260 length = playlist_get_current_length(); | |
3261 playlistwin_set_time(time, length, cfg.timer_mode); | |
3262 input_update_vis(time); | |
3263 | |
3264 if (cfg.timer_mode == TIMER_REMAINING) { | |
3265 if (length != -1) { | |
3266 number_set_number(mainwin_minus_num, 11); | |
3267 t = length - time; | |
3268 stime_prefix = '-'; | |
3269 } | |
3270 else { | |
3271 number_set_number(mainwin_minus_num, 10); | |
3272 t = time; | |
3273 stime_prefix = ' '; | |
3274 } | |
3275 } | |
3276 else { | |
3277 number_set_number(mainwin_minus_num, 10); | |
3278 t = time; | |
3279 stime_prefix = ' '; | |
3280 } | |
3281 t /= 1000; | |
3282 | |
3283 /* Show the time in the format HH:MM when we have more than 100 | |
3284 * minutes. */ | |
3285 if (t >= 100 * 60) | |
3286 t /= 60; | |
3287 number_set_number(mainwin_10min_num, t / 600); | |
3288 number_set_number(mainwin_min_num, (t / 60) % 10); | |
3289 number_set_number(mainwin_10sec_num, (t / 10) % 6); | |
3290 number_set_number(mainwin_sec_num, t % 10); | |
3291 | |
3292 if (!mainwin_sposition->hs_pressed) { | |
3293 gchar *time_str; | |
3294 | |
3295 time_str = g_strdup_printf("%c%2.2d", stime_prefix, t / 60); | |
3296 textbox_set_text(mainwin_stime_min, time_str); | |
3297 g_free(time_str); | |
3298 | |
3299 time_str = g_strdup_printf("%2.2d", t % 60); | |
3300 textbox_set_text(mainwin_stime_sec, time_str); | |
3301 g_free(time_str); | |
3302 } | |
3303 | |
3304 time /= 1000; | |
3305 length /= 1000; | |
3306 if (length > 0) { | |
3307 if (time > length) { | |
3308 hslider_set_position(mainwin_position, 219); | |
3309 hslider_set_position(mainwin_sposition, 13); | |
3310 } | |
3311 else { | |
3312 hslider_set_position(mainwin_position, (time * 219) / length); | |
3313 hslider_set_position(mainwin_sposition, | |
3314 ((time * 12) / length) + 1); | |
3315 } | |
3316 } | |
3317 else { | |
3318 hslider_set_position(mainwin_position, 0); | |
3319 hslider_set_position(mainwin_sposition, 1); | |
3320 } | |
3321 } | |
3322 | |
3323 | |
3324 static gboolean | |
3325 mainwin_idle_func(gpointer data) | |
3326 { | |
3327 static gboolean waiting = FALSE; | |
3328 static gint count = 0; | |
3329 | |
3330 gint time; | |
3331 | |
3332 if (bmp_playback_get_playing()) { | |
3333 GDK_THREADS_ENTER(); | |
3334 vis_playback_start(); | |
3335 GDK_THREADS_LEAVE(); | |
3336 | |
3337 time = bmp_playback_get_time(); | |
3338 | |
3339 switch (time) { | |
3340 case -1: | |
3341 /* no song playing */ | |
3342 waiting = idle_func_change_song(waiting); | |
3343 break; | |
3344 | |
3345 case -2: | |
3346 /* no usable output device */ | |
3347 GDK_THREADS_ENTER(); | |
3348 run_no_output_device_dialog(); | |
3349 mainwin_stop_pushed(); | |
3350 GDK_THREADS_LEAVE(); | |
3351 waiting = FALSE; | |
3352 break; | |
3353 | |
3354 default: | |
3355 /* song playing, all's well */ | |
3356 idle_func_update_song_info(time); | |
3357 waiting = FALSE; | |
3358 } | |
3359 } | |
3360 else { | |
3361 GDK_THREADS_ENTER(); | |
3362 vis_playback_stop(); | |
3363 GDK_THREADS_LEAVE(); | |
3364 } | |
3365 | |
3366 GDK_THREADS_ENTER(); | |
3367 | |
3368 ctrlsocket_check(); | |
3369 | |
3370 draw_main_window(mainwin_force_redraw); | |
3371 | |
3372 if (!count) { | |
3373 read_volume(VOLSET_UPDATE); | |
3374 count = 10; | |
3375 } | |
3376 else | |
3377 count--; | |
3378 | |
3379 mainwin_force_redraw = FALSE; | |
3380 draw_playlist_window(FALSE); | |
3381 draw_equalizer_window(FALSE); | |
3382 | |
3383 if (mainwin_title_text) { | |
3384 G_LOCK(mainwin_title); | |
3385 gtk_window_set_title(GTK_WINDOW(mainwin), mainwin_title_text); | |
3386 g_free(mainwin_title_text); | |
3387 mainwin_title_text = NULL; | |
3388 G_UNLOCK(mainwin_title); | |
3389 | |
3390 mainwin_set_info_text(); | |
3391 playlistwin_update_list(); | |
3392 } | |
3393 | |
3394 GDK_THREADS_LEAVE(); | |
3395 | |
3396 return TRUE; | |
3397 } |