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