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