comparison src/audacious/ui_main.c @ 2313:3149d4b1a9a9 trunk

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