3
* Copyright (C) 2001 J�rgen Scheibengruber
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
/*** the gui to gnomeradio */
25
#include <gconf/gconf-client.h>
33
#include "../pixmaps/digits.xpm"
34
#include "../pixmaps/signal.xpm"
35
#include "../pixmaps/stereo.xpm"
36
#include "../pixmaps/vol_up.xpm"
37
#include "../pixmaps/vol_down.xpm"
38
#include "../pixmaps/freq_up.xpm"
39
#include "../pixmaps/freq_down.xpm"
40
#include "../pixmaps/radio.xpm"
42
#define DIGIT_WIDTH 20
43
#define DIGIT_HEIGTH 30
44
#define SIGNAL_WIDTH 25
45
#define STEREO_WIDTH 35
48
#define TRANSLATORS "TRANSLATORS"
50
static GtkWidget *drawing_area;
51
static GdkPixmap *digits, *signal_s, *stereo;
52
static GtkWidget *preset_menu, *menu;
53
static GtkWidget *freq_scale, *vol_scale;
55
static int timeout_id, bp_timeout_id = -1, bp_timeout_steps = 0;
57
void start_radio(gboolean restart, GtkWidget *app)
62
if (!radio_init(settings.device))
66
dialog = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
67
_("Could not open device \"%s\" !\n\nCheck your Settings and make sure that no other\n"
68
"program is using %s.\nMake also sure that you have read-access to it."),
69
settings.device, settings.device);
70
gtk_dialog_run (GTK_DIALOG (dialog));
71
gtk_widget_destroy (dialog);
75
void start_mixer(gboolean restart, GtkWidget *app)
82
res = mixer_init(settings.mixer_dev, settings.mixer);
89
buffer = g_strdup_printf(_("Mixer source \"%s\" is not a valid source!"), settings.mixer);
91
buffer = g_strdup_printf(_("Could not open \"%s\"!"), settings.mixer_dev);
93
dialog = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, buffer);
94
gtk_dialog_run (GTK_DIALOG (dialog));
95
gtk_widget_destroy (dialog);
99
vol = mixer_get_volume();
102
gtk_adjustment_set_value(volume, (double)vol);
105
GList* get_mixer_recdev_list(void)
109
char *gconf_path = NULL, *sndcard_name = NULL;
110
GList *result = NULL;
111
GConfClient *client = NULL;
113
array = mixer_get_rec_devices();
117
if (!gconf_is_initialized())
120
client = gconf_client_get_default();
122
sndcard_name = mixer_get_sndcard_name();
125
g_strdelimit (sndcard_name, " ", '_');
126
gconf_path = g_strdup_printf("/apps/gnome-volume-control/OSS-%s-%d/%%s/title", sndcard_name, 1);
135
char *gconf_dev = NULL;
138
if (client && gconf_path)
140
char *path = g_strdup_printf(gconf_path, dev);
141
gconf_dev = gconf_client_get_string(client, path , NULL);
146
if (strcmp(gconf_dev, dev))
147
text = g_strdup_printf("%s (%s)", dev, gconf_dev);
149
text = g_strdup(dev);
154
text = g_strdup(dev);
155
result = g_list_append(result, text);
166
redraw_status_window(gboolean expose_event)
171
int win_width, win_height;
173
int freq[5], signal_strength, is_stereo, fl, rst, i;
174
static int old_signal_strength, old_is_stereo, old_freq[5], first = 1;
177
//g_print("Redrawing %s\n", expose_event ? "(expose event)" : "");
181
for (i=0; i<5; old_freq[i++] = -1)
183
old_signal_strength = -1;
187
val = rint(gtk_adjustment_get_value(adj));
189
fl = (int)(floor(val/STEPS));
190
dob = rint((double)(val*100/STEPS));
191
rst = (int)(dob)%100;
193
freq[0] = fl - fl%100;
194
freq[1] = (fl - freq[0]) - (fl - freq[0])%10;
195
freq[2] = fl - freq[0] - freq[1];
197
freq[3] = (rst - freq[4])/10;
202
signal_strength = radio_getsignal();
203
is_stereo = radio_getstereo();
205
if (signal_strength > 3)
207
if (signal_strength < 0)
210
window = drawing_area->window;
212
gdk_drawable_get_size(window, &win_width, &win_height);
214
gc = gdk_gc_new(window);
216
if (expose_event || first)
217
gdk_draw_rectangle(window, gc, TRUE, 0, 0, -1, -1);
223
if (freq[0] != old_freq[0])
226
gdk_draw_drawable(window, gc, digits, freq[0] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*6, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
228
gdk_draw_rectangle(window, gc, TRUE, win_width - DIGIT_WIDTH*6, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
230
if (freq[1] != old_freq[1])
231
gdk_draw_drawable(window, gc, digits, freq[1] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*5, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
232
if (freq[2] != old_freq[2])
233
gdk_draw_drawable(window, gc, digits, freq[2] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*4, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
235
gdk_draw_drawable(window, gc, digits, 10 * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*3, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
236
if (freq[3] != old_freq[3])
237
gdk_draw_drawable(window, gc, digits, freq[3] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*2, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
238
if (freq[4] != old_freq[4])
239
gdk_draw_drawable(window, gc, digits, freq[4] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*1, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
240
if (signal_strength != old_signal_strength)
241
gdk_draw_drawable(window, gc, signal_s, signal_strength * SIGNAL_WIDTH, 0, win_width - DIGIT_WIDTH*6-SIGNAL_WIDTH, 5, SIGNAL_WIDTH, DIGIT_HEIGTH);
242
if ((is_stereo != old_is_stereo) && (is_stereo > -1))
243
gdk_draw_drawable(window, gc, stereo, is_stereo * STEREO_WIDTH, 0, win_width - DIGIT_WIDTH*6-SIGNAL_WIDTH-STEREO_WIDTH, 5, STEREO_WIDTH, DIGIT_HEIGTH);
245
for (i=0; i<5; old_freq[i] = freq[i++])
247
old_signal_strength = signal_strength;
248
old_is_stereo = is_stereo;
255
expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
257
return redraw_status_window(TRUE);
260
void exit_gnome_radio(void)
262
if (settings.mute_on_exit)
272
static void adj_value_changed_cb(GtkAdjustment* data, gpointer window)
276
//expose_event_cb(NULL, NULL, NULL);
277
redraw_status_window(FALSE);
279
buffer = g_strdup_printf(_("Gnomeradio - %.2f MHz"), rint(adj->value)/STEPS);
280
gtk_window_set_title (GTK_WINDOW(window), buffer);
283
buffer = g_strdup_printf(_("Frequency: %.2f MHz"), rint(adj->value)/STEPS);
284
gtk_tooltips_set_tip(tooltips, freq_scale, buffer, NULL);
287
radio_setfreq(adj->value/STEPS);
290
static gboolean freq_scale_focus_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
293
preset_menu_set_item(mom_ps);
297
static void volume_value_changed_cb(GtkAdjustment* data, gpointer window)
301
mixer_set_volume((gint)volume->value);
303
text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
304
gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
310
static gboolean poll_volume_change(gpointer data)
313
if ((vol = mixer_get_volume()) < 0)
316
if (vol != (int)volume->value)
318
g_print("external volume change detected\n");
319
gtk_adjustment_set_value(volume, (double)vol);
327
change_frequency(gpointer data)
329
gboolean increase = (gboolean)data;
333
if (adj->value >= FREQ_MAX*STEPS)
334
gtk_adjustment_set_value(adj, FREQ_MIN*STEPS);
336
gtk_adjustment_set_value(adj, adj->value+1);
340
if (adj->value <= FREQ_MIN*STEPS)
341
gtk_adjustment_set_value(adj, FREQ_MAX*STEPS);
343
gtk_adjustment_set_value(adj, adj->value-1);
348
change_frequency_timeout(gpointer data)
350
change_frequency(data);
351
if (bp_timeout_steps < 10)
353
gtk_timeout_remove(bp_timeout_id);
354
//g_print("adding timeout with interval %d\n", 200 - 20*bp_timeout_steps);
355
bp_timeout_id = gtk_timeout_add(200 - 20*bp_timeout_steps,
356
(GtkFunction)change_frequency_timeout, data);
362
static void step_button_pressed_cb(GtkButton *button, gpointer data)
364
//change_frequency(data);
365
bp_timeout_id = gtk_timeout_add(500, (GtkFunction)change_frequency_timeout, data);
368
preset_menu_set_item(mom_ps);
371
static void step_button_clicked_cb(GtkButton *button, gpointer data)
373
change_frequency(data);
376
preset_menu_set_item(mom_ps);
379
static void step_button_released_cb(GtkButton *button, gpointer data)
381
if (bp_timeout_id > -1)
382
gtk_timeout_remove(bp_timeout_id);
384
bp_timeout_steps = 0;
388
static gboolean scan_freq(gpointer data)
390
static gint signal, a, b, c;
391
static gint start, mom, max;
392
gint dir = (gint)(data);
395
max = (FREQ_MAX - FREQ_MIN) * STEPS;
397
if ((a + b + c > 8) || (start > max))
399
start = mom = a = b = c = 0;
406
if (mom > FREQ_MAX*STEPS)
407
mom = FREQ_MIN*STEPS;
409
if (mom < FREQ_MIN*STEPS)
410
mom = FREQ_MAX*STEPS;
414
gtk_adjustment_set_value(adj, mom);
415
signal = radio_getsignal();
422
void scfw_button_clicked_cb(GtkButton *button, gpointer data)
427
timeout_id = gtk_timeout_add(1000/SCAN_SPEED, (GtkFunction)scan_freq, (gpointer)1);
429
preset_menu_set_item(mom_ps);
433
void scbw_button_clicked_cb(GtkButton *button, gpointer data)
438
timeout_id = gtk_timeout_add(1000/SCAN_SPEED, (GtkFunction)scan_freq, (gpointer)(-1));
440
preset_menu_set_item(mom_ps);
443
void preset_menu_set_item(gint i)
445
gtk_option_menu_set_history(GTK_OPTION_MENU(preset_menu), i+1);
448
static void pref_item_activate_cb(GtkWidget *item, gpointer data)
451
preset* ps = (preset*)g_list_nth_data(settings.presets,i);
453
gtk_adjustment_set_value(adj, ps->freq*STEPS);
456
static void update_preset_menu(void)
463
gtk_widget_destroy(menu);
464
menu = gtk_menu_new();
466
count = g_list_length(settings.presets);
468
item = gtk_menu_item_new_with_label(_("manual"));
469
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
471
for (i=0;i<count;i++)
473
ps = g_list_nth_data(settings.presets, i);
474
item = gtk_menu_item_new_with_label(ps->name);
475
g_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(pref_item_activate_cb), (gpointer)i);
476
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
478
gtk_widget_show_all(menu);
479
gtk_option_menu_set_menu(GTK_OPTION_MENU(preset_menu), menu);
483
change_preset(gboolean next)
486
int len = g_list_length(settings.presets);
491
mom_ps = (mom_ps + 1) % len;
493
mom_ps = (mom_ps - 1 + len) % len;
495
ps = g_list_nth_data(settings.presets, mom_ps);
496
gtk_adjustment_set_value(adj, ps->freq*STEPS);
497
preset_menu_set_item(mom_ps);
500
static void quit_button_clicked_cb(GtkButton *button, gpointer data)
505
static void prefs_button_clicked_cb(GtkButton *button, gpointer app)
512
dialog = prefs_window();
514
/* Michael Jochum <e9725005@stud3.tuwien.ac.at> proposed to not use gnome_dialog_set_parent()
515
but following instead. */
516
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(app));
517
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
519
/*gnome_dialog_set_parent(GNOME_DIALOG(dialog), GTK_WINDOW(app));*/
522
choise = GTK_RESPONSE_HELP;
523
while (choise == GTK_RESPONSE_HELP)
525
choise = gtk_dialog_run(GTK_DIALOG(dialog));
528
case GTK_RESPONSE_OK:
529
gtk_widget_destroy(dialog);
530
commit_settings(app);
531
update_preset_menu();
534
case GTK_RESPONSE_HELP:
535
display_help_cb("gnomeradio-settings");
538
gtk_widget_destroy(dialog);
545
start_recording(void)
547
GIOChannel *wavioc = NULL, *mp3ioc = NULL;
550
if (!mixer_set_rec_device())
553
dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
554
"Could not set \"%s\" as recording Source", settings.mixer);
555
gtk_dialog_run (GTK_DIALOG (dialog));
556
gtk_widget_destroy (dialog);
560
if (rec_settings.mp3)
561
record_as_mp3(&wavioc, &mp3ioc);
563
record_as_wave(&wavioc);
565
dialog = record_status_window();
567
run_status_window(wavioc, mp3ioc);
571
static void rec_button_clicked_cb(GtkButton *button, gpointer app)
574
gint choise, retval=0;
576
if (!check_sox_installation())
578
dialog = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
579
_("Sox could not be detected. Please ensure"
580
" that it is installed in your PATH."));
581
gtk_dialog_run (GTK_DIALOG (dialog));
582
gtk_widget_destroy (dialog);
586
dialog = record_prefs_window();
588
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(app));
589
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
591
//g_print("choise: %d\n", choise);
593
choise = GTK_RESPONSE_HELP;
594
while (choise == GTK_RESPONSE_HELP)
596
choise = gtk_dialog_run(GTK_DIALOG(dialog));
599
case GTK_RESPONSE_HELP:
600
display_help_cb("gnomeradio-recording");
603
case GTK_RESPONSE_OK:
608
if (g_file_test(rec_settings.filename, G_FILE_TEST_EXISTS ))
612
question = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_QUESTION,
614
_("File '%s' exists.\nOverwrite it?"), rec_settings.filename);
615
ch = gtk_dialog_run (GTK_DIALOG (question));
616
gtk_widget_destroy (question);
617
if (ch == GTK_RESPONSE_NO)
620
retval = check_filename(rec_settings.filename);
623
GtkWidget *errdialog;
624
errdialog = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
625
_("Error opening file '%s':\n%s"), rec_settings.filename, strerror(errno));
626
gtk_dialog_run (GTK_DIALOG (errdialog));
627
gtk_widget_destroy (errdialog);
633
gtk_widget_destroy(dialog);
637
choise = GTK_RESPONSE_HELP;
640
gtk_widget_destroy(dialog);
645
void mute_button_toggled_cb(GtkButton *button, gpointer data)
647
static gboolean muted = FALSE;
653
gtk_tooltips_set_tip(tooltips, mute_button, _("Mute"), NULL);
659
gtk_tooltips_set_tip(tooltips, mute_button, _("Unmute"), NULL);
663
static void about_button_clicked_cb(GtkButton *button, gpointer data)
666
static GtkWidget *about;
667
const char *authors[] = {"Jörgen Scheibengruber <mfcn@gmx.de>", NULL};
670
/* Feel free to put your names here translators :-) */
671
char *translators = _("TRANSLATORS");
675
gtk_window_present(GTK_WINDOW(about));
679
app_icon = gdk_pixbuf_new_from_xpm_data((const char**)radio_xpm);
682
text =_("Gnomeradio is a FM-Tuner application for the GNOME desktop. "
683
"It should work with all tuner hardware that is supported by the video4linux drivers.\n\n"
684
"This version has been compiled with LIRC support.");
686
text =_("Gnomeradio is a FM-Tuner application for the GNOME desktop. "
687
"It should work with all tuner hardware that is supported by the video4linux drivers.\n\n"
688
"This version has been compiled without LIRC support.");
691
about = gnome_about_new ("Gnomeradio", VERSION, "Copyright 2001 - 2003 Jörgen Scheibengruber",
692
text, (const char **) authors, NULL,
693
strcmp("TRANSLATORS", translators) ? translators : NULL,
696
gtk_widget_show(about);
697
g_object_add_weak_pointer(G_OBJECT(about), (gpointer*)&about);
701
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
707
void display_help_cb(char *topic)
709
GError *error = NULL;
711
gnome_help_display(PACKAGE, topic, &error);
715
dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
717
gtk_dialog_run (GTK_DIALOG (dialog));
718
gtk_widget_destroy (dialog);
719
g_error_free (error);
724
GtkWidget* gnome_radio_gui(void)
727
GtkWidget *prefs_button, *quit_button, *scfw_button, *scbw_button;
728
GtkWidget *stfw_button, *stbw_button, *about_button, *rec_button;
729
GtkWidget *prefs_pixmap, *quit_pixmap, *scfw_pixmap, *scbw_pixmap;
730
GtkWidget *stfw_pixmap, *stbw_pixmap, *about_pixmap, *mute_pixmap, *rec_pixmap;
731
GtkWidget *vol_up_pixmap, *vol_down_pixmap, *freq_up_pixmap, *freq_down_pixmap;
732
GdkPixbuf *vol_up_pixbuf, *vol_down_pixbuf, *freq_up_pixbuf, *freq_down_pixbuf;
733
GtkWidget *hbox1, *hbox2, *vbox, *menubox, *freq_vol_box;
734
GtkWidget *hseparator1, *hseparator2, *vseparator1, *vseparator2, *vseparator3, *vseparator4;
736
GtkWidget *frame1, *frame2;
739
app = gnome_app_new(PACKAGE, _("Gnomeradio"));
741
gtk_window_set_resizable(GTK_WINDOW(app), FALSE);
742
//gtk_window_set_policy(GTK_WINDOW(app), FALSE, FALSE, FALSE);
743
gtk_window_set_wmclass(GTK_WINDOW(app), "gnomeradio", "Gnomeradio");
745
frame1 = gtk_frame_new(NULL);
746
frame2 = gtk_frame_new(NULL);
748
/*quit_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_QUIT, GTK_ICON_SIZE_BUTTON);
749
prefs_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_PROPERTIES, GTK_ICON_SIZE_BUTTON);
750
scfw_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_LAST, GTK_ICON_SIZE_BUTTON);
751
scbw_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_FIRST, GTK_ICON_SIZE_BUTTON);
752
stfw_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_FORWARD, GTK_ICON_SIZE_BUTTON);
753
stbw_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_BACK, GTK_ICON_SIZE_BUTTON);
754
about_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_ABOUT, GTK_ICON_SIZE_BUTTON);
755
mute_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_VOLUME, GTK_ICON_SIZE_BUTTON);
756
rec_pixmap = gtk_image_new_from_stock(GNOME_STOCK_PIXMAP_MIC, GTK_ICON_SIZE_BUTTON);*/
758
quit_pixmap = gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_BUTTON);
759
prefs_pixmap = gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_BUTTON);
760
scfw_pixmap = gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON);
761
scbw_pixmap = gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON);
762
stfw_pixmap = gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON);
763
stbw_pixmap = gtk_image_new_from_stock(GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON);
764
about_pixmap = gtk_image_new_from_stock(GNOME_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
765
mute_pixmap = gtk_image_new_from_stock(GNOME_STOCK_VOLUME, GTK_ICON_SIZE_BUTTON);
766
rec_pixmap = gtk_image_new_from_stock(GNOME_STOCK_MIC, GTK_ICON_SIZE_BUTTON);
767
//help_pixmap = gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_BUTTON);
769
quit_button = gtk_button_new();
770
prefs_button = gtk_button_new();
771
scfw_button = gtk_button_new();
772
scbw_button = gtk_button_new();
773
stfw_button = gtk_button_new();
774
stbw_button = gtk_button_new();
775
about_button = gtk_button_new();
776
mute_button = gtk_toggle_button_new();
777
rec_button = gtk_button_new();
778
//help_button = gtk_button_new();
780
gtk_container_add(GTK_CONTAINER(quit_button), quit_pixmap);
781
gtk_container_add(GTK_CONTAINER(prefs_button), prefs_pixmap);
782
gtk_container_add(GTK_CONTAINER(scfw_button), scfw_pixmap);
783
gtk_container_add(GTK_CONTAINER(scbw_button), scbw_pixmap);
784
gtk_container_add(GTK_CONTAINER(stfw_button), stfw_pixmap);
785
gtk_container_add(GTK_CONTAINER(stbw_button), stbw_pixmap);
786
gtk_container_add(GTK_CONTAINER(about_button), about_pixmap);
787
gtk_container_add(GTK_CONTAINER(mute_button), mute_pixmap);
788
gtk_container_add(GTK_CONTAINER(rec_button), rec_pixmap);
789
//gtk_container_add(GTK_CONTAINER(help_button), help_pixmap);
791
/*gtk_widget_set_usize(quit_button, 30, 30);
792
gtk_widget_set_usize(prefs_button, 30, 30);
793
gtk_widget_set_usize(scfw_button, 30, 30);
794
gtk_widget_set_usize(scbw_button, 30, 30);
795
gtk_widget_set_usize(stfw_button, 30, 30);
796
gtk_widget_set_usize(stbw_button, 30, 30);
797
gtk_widget_set_usize(about_button, 30, 30);
798
gtk_widget_set_usize(mute_button, 30, 30);
799
gtk_widget_set_usize(rec_button, 30, 30);*/
801
vbox = gtk_vbox_new(FALSE, 0);
802
hbox1 = gtk_hbox_new(FALSE, 0);
803
hbox2 = gtk_hbox_new(FALSE, 0);
804
menubox = gtk_vbox_new(FALSE, 0);
805
freq_vol_box = gtk_hbox_new(FALSE, 0);
807
adj = GTK_ADJUSTMENT(gtk_adjustment_new(SUNSHINE*STEPS, FREQ_MIN*STEPS, FREQ_MAX*STEPS+1, 1, STEPS, 1));
808
volume = GTK_ADJUSTMENT(gtk_adjustment_new(100, 0, 101, 1, 10, 1));
811
preset_menu = gtk_option_menu_new();
812
//gtk_widget_set_usize(preset_menu, 10, 25);
813
gtk_widget_set_size_request(preset_menu, 10, -1);
814
label = gtk_label_new(_("Presets:"));
816
freq_scale = gtk_hscale_new(adj);
817
//gtk_range_set_update_policy(GTK_RANGE(freq_scale), GTK_UPDATE_DELAYED);
818
vol_scale = gtk_hscale_new(volume);
820
vol_up_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_up_xpm);
821
vol_down_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)vol_down_xpm);
822
freq_up_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)freq_up_xpm);
823
freq_down_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)freq_down_xpm);
825
vol_up_pixmap = gtk_image_new_from_pixbuf(vol_up_pixbuf);
826
vol_down_pixmap = gtk_image_new_from_pixbuf(vol_down_pixbuf);
827
freq_up_pixmap = gtk_image_new_from_pixbuf(freq_up_pixbuf);
828
freq_down_pixmap = gtk_image_new_from_pixbuf(freq_down_pixbuf);
830
//gtk_widget_set_usize(freq_scale, 160, 10);
831
gtk_widget_set_size_request(freq_scale, 160, -1);
833
gtk_widget_realize(app);
834
drawing_area = gtk_drawing_area_new();
835
digits = gdk_pixmap_create_from_xpm_d (app->window, NULL, NULL, digits_xpm);
836
signal_s = gdk_pixmap_create_from_xpm_d (app->window, NULL, NULL, signal_xpm);
837
stereo = gdk_pixmap_create_from_xpm_d (app->window, NULL, NULL, stereo_xpm);
839
hseparator1 = gtk_hseparator_new();
840
hseparator2 = gtk_hseparator_new();
841
vseparator1 = gtk_vseparator_new();
842
vseparator2 = gtk_vseparator_new();
843
vseparator3 = gtk_vseparator_new();
844
vseparator4 = gtk_vseparator_new();
846
gtk_scale_set_digits(GTK_SCALE(freq_scale), 0);
847
gtk_scale_set_draw_value(GTK_SCALE(freq_scale), FALSE);
848
gtk_scale_set_digits(GTK_SCALE(vol_scale), 0);
849
gtk_scale_set_draw_value(GTK_SCALE(vol_scale), FALSE);
851
//gtk_drawing_area_size(GTK_DRAWING_AREA(drawing_area), DIGIT_WIDTH*6+10+SIGNAL_WIDTH+STEREO_WIDTH, DIGIT_HEIGTH+10);
852
gtk_widget_set_size_request(drawing_area, DIGIT_WIDTH*6+10+SIGNAL_WIDTH+STEREO_WIDTH, DIGIT_HEIGTH+10);
853
//gtk_widget_set_usize(spinbutton, 60, 25);
855
gtk_container_add(GTK_CONTAINER(frame2), drawing_area);
857
gtk_box_pack_start(GTK_BOX(hbox2), scbw_button, FALSE, FALSE, 2);
858
gtk_box_pack_start(GTK_BOX(hbox2), stbw_button, FALSE, FALSE, 2);
859
gtk_box_pack_start(GTK_BOX(hbox2), stfw_button, FALSE, FALSE, 2);
860
gtk_box_pack_start(GTK_BOX(hbox2), scfw_button, FALSE, FALSE, 2);
861
gtk_box_pack_start(GTK_BOX(hbox2), vseparator1, FALSE, FALSE, 2);
862
gtk_box_pack_start(GTK_BOX(hbox2), mute_button, FALSE, FALSE, 2);
863
//gtk_box_pack_start(GTK_BOX(hbox2), vseparator2, TRUE, TRUE, 3);
864
gtk_box_pack_start(GTK_BOX(hbox2), rec_button, FALSE, FALSE, 2);
865
gtk_box_pack_start(GTK_BOX(hbox2), vseparator4, FALSE, FALSE, 2);
866
gtk_box_pack_start(GTK_BOX(hbox2), about_button, FALSE, FALSE, 2);
867
//gtk_box_pack_start(GTK_BOX(hbox2), help_button, FALSE, FALSE, 2);
868
gtk_box_pack_start(GTK_BOX(hbox2), prefs_button, FALSE, FALSE, 2);
869
gtk_box_pack_start(GTK_BOX(hbox2), quit_button, FALSE, FALSE, 2);
871
gtk_box_pack_start(GTK_BOX(hbox1), frame2, FALSE, FALSE, 3);
872
gtk_box_pack_start(GTK_BOX(hbox1), menubox, TRUE, TRUE, 3);
874
gtk_box_pack_start(GTK_BOX(menubox), label, TRUE, TRUE, 0);
875
gtk_box_pack_start(GTK_BOX(menubox), preset_menu, TRUE, TRUE, 0);
877
gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_down_pixmap, FALSE, FALSE, 2);
878
gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_scale, FALSE, FALSE, 0);
879
gtk_box_pack_start(GTK_BOX(freq_vol_box), freq_up_pixmap, FALSE, FALSE, 2);
880
gtk_box_pack_start(GTK_BOX(freq_vol_box), vseparator3, FALSE, FALSE, 2);
881
gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_down_pixmap, FALSE, FALSE, 2);
882
gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_scale, TRUE, TRUE, 0);
883
gtk_box_pack_start(GTK_BOX(freq_vol_box), vol_up_pixmap, FALSE, FALSE, 2);
885
gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 4);
886
gtk_box_pack_start(GTK_BOX(vbox), freq_vol_box, TRUE, TRUE, 2);
887
gtk_box_pack_start(GTK_BOX(vbox), hseparator1, FALSE, FALSE, 2);
888
gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 4);
889
//gtk_box_pack_start(GTK_BOX(vbox), hseparator2, FALSE, FALSE, 0);
891
gtk_container_add(GTK_CONTAINER(frame1), vbox);
893
gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_IN);
895
gtk_container_set_border_width(GTK_CONTAINER(frame1), 3);
896
gtk_container_set_border_width(GTK_CONTAINER(frame2), 2);
898
gnome_app_set_contents(GNOME_APP(app), frame1);
900
//status = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_NEVER);
902
//gnome_app_set_statusbar(GNOME_APP(app), status);
904
tooltips = gtk_tooltips_new();
906
g_signal_connect(GTK_OBJECT(app), "delete_event", GTK_SIGNAL_FUNC(delete_event_cb), NULL);
907
g_signal_connect(GTK_OBJECT(quit_button), "clicked", GTK_SIGNAL_FUNC(quit_button_clicked_cb), NULL);
908
g_signal_connect(GTK_OBJECT(adj), "value-changed", GTK_SIGNAL_FUNC(adj_value_changed_cb), (gpointer) app);
909
g_signal_connect(GTK_OBJECT(freq_scale), "button-release-event", GTK_SIGNAL_FUNC(freq_scale_focus_cb), NULL);
910
g_signal_connect(GTK_OBJECT(volume), "value-changed", GTK_SIGNAL_FUNC(volume_value_changed_cb), NULL);
911
g_signal_connect(GTK_OBJECT(stfw_button), "pressed", GTK_SIGNAL_FUNC(step_button_pressed_cb), (gpointer)TRUE);
912
g_signal_connect(GTK_OBJECT(stbw_button), "pressed", GTK_SIGNAL_FUNC(step_button_pressed_cb), (gpointer)FALSE);
913
g_signal_connect(GTK_OBJECT(stfw_button), "clicked", GTK_SIGNAL_FUNC(step_button_clicked_cb), (gpointer)TRUE);
914
g_signal_connect(GTK_OBJECT(stbw_button), "clicked", GTK_SIGNAL_FUNC(step_button_clicked_cb), (gpointer)FALSE);
915
g_signal_connect(GTK_OBJECT(stfw_button), "released", GTK_SIGNAL_FUNC(step_button_released_cb), NULL);
916
g_signal_connect(GTK_OBJECT(stbw_button), "released", GTK_SIGNAL_FUNC(step_button_released_cb), NULL);
917
g_signal_connect(GTK_OBJECT(scfw_button), "clicked", GTK_SIGNAL_FUNC(scfw_button_clicked_cb), NULL);
918
g_signal_connect(GTK_OBJECT(scbw_button), "clicked", GTK_SIGNAL_FUNC(scbw_button_clicked_cb), NULL);
919
g_signal_connect(GTK_OBJECT(about_button), "clicked", GTK_SIGNAL_FUNC(about_button_clicked_cb), NULL);
920
g_signal_connect(GTK_OBJECT(mute_button), "toggled", GTK_SIGNAL_FUNC(mute_button_toggled_cb), NULL);
921
g_signal_connect(GTK_OBJECT(rec_button), "clicked", GTK_SIGNAL_FUNC(rec_button_clicked_cb), (gpointer) app);
922
g_signal_connect(GTK_OBJECT(prefs_button), "clicked", GTK_SIGNAL_FUNC(prefs_button_clicked_cb), (gpointer) app);
923
g_signal_connect(GTK_OBJECT(drawing_area), "expose-event", GTK_SIGNAL_FUNC(expose_event_cb), NULL);
925
gtk_tooltips_set_tip(tooltips, scbw_button, _("Scan Backwards"), NULL);
926
gtk_tooltips_set_tip(tooltips, scfw_button, _("Scan Forwards"), NULL);
927
gtk_tooltips_set_tip(tooltips, stbw_button, _("0.05 MHz Backwards"), NULL);
928
gtk_tooltips_set_tip(tooltips, stfw_button, _("0.05 MHz Forwards"), NULL);
929
gtk_tooltips_set_tip(tooltips, about_button, _("About Gnomeradio"), NULL);
930
gtk_tooltips_set_tip(tooltips, rec_button, _("Record radio as Wave or MP3"), NULL);
931
gtk_tooltips_set_tip(tooltips, prefs_button, _("Edit your Preferences"), NULL);
932
gtk_tooltips_set_tip(tooltips, mute_button, _("Mute"), NULL);
933
gtk_tooltips_set_tip(tooltips, quit_button, _("Quit"), NULL);
934
text = g_strdup_printf(_("Frequency: %.2f MHz"), adj->value/STEPS);
935
gtk_tooltips_set_tip(tooltips, freq_scale, text, NULL);
937
text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
938
gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
945
session_die_cb(GnomeClient* client, gpointer client_data)
947
if (settings.mute_on_exit)
958
save_session_cb(GnomeClient *client, gint phase, GnomeSaveStyle save_style,
959
gint is_shutdown, GnomeInteractStyle interact_style,
960
gint is_fast, gpointer client_data)
966
gconf_error_handler(GConfClient *client, GError *error)
968
//gnome_error_dialog(error->message);
969
g_print("GConf error: %s\n", error->message);
973
key_press_event_cb(GtkWidget *app, GdkEventKey *event, gpointer data)
975
GtkToggleButton *tb = GTK_TOGGLE_BUTTON(mute_button);
976
gboolean state = gtk_toggle_button_get_active(tb);
977
//g_print("%s key pressed: %d\n", gdk_keyval_name(event->keyval), event->keyval);
979
switch (event->keyval)
981
case GDK_F1: display_help_cb(NULL);
984
gtk_toggle_button_set_active(tb, !state);
990
rec_button_clicked_cb(NULL, app);
993
scfw_button_clicked_cb(NULL, NULL);
996
scbw_button_clicked_cb(NULL, NULL);
1002
change_preset(FALSE);
1006
gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);
1009
case GDK_KP_Subtract:
1010
gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);
1016
int main(int argc, char* argv[])
1020
GdkPixbuf *app_icon;
1021
GnomeClient *client;
1023
int redraw_timeout_id;
1025
bindtextdomain(PACKAGE, GNOMELOCALEDIR);
1026
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
1027
textdomain(PACKAGE);
1029
gnome_program_init(PACKAGE, VERSION,
1030
LIBGNOMEUI_MODULE, argc, argv,
1031
GNOME_PROGRAM_STANDARD_PROPERTIES,
1034
app_icon = gdk_pixbuf_new_from_xpm_data((const char**)radio_xpm);
1035
icons = g_list_append(NULL, (gpointer)app_icon);
1036
gtk_window_set_default_icon_list(icons);
1038
/* Technical Stuff */
1042
app = gnome_radio_gui();
1044
gtk_widget_show_all(app);
1046
/* Initizialize Gconf */
1047
if (!gconf_init(argc, argv, &err))
1050
dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
1051
_("Failed to init GConf: %s\n"
1052
"Changes to the settings won't be saved\n"), err->message);
1053
gtk_dialog_run (GTK_DIALOG (dialog));
1054
gtk_widget_destroy (dialog);
1060
gconf_client_set_global_default_error_handler((GConfClientErrorHandlerFunc)gconf_error_handler);
1061
gconf_client_set_error_handling(gconf_client_get_default(), GCONF_CLIENT_HANDLE_ALL);
1065
update_preset_menu();
1066
//g_print("momps: %i\n", mom_ps);
1067
preset_menu_set_item(mom_ps);
1069
start_radio(FALSE, app);
1075
dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
1076
_("Could not start lirc"));
1077
gtk_dialog_run (GTK_DIALOG (dialog));
1078
gtk_widget_destroy (dialog);
1084
start_mixer(FALSE, app);
1085
adj_value_changed_cb(NULL, (gpointer) app);
1086
volume_value_changed_cb(NULL, NULL);
1088
/* Connect the Session Management signals
1090
client = gnome_master_client();
1091
g_signal_connect(GTK_OBJECT(client), "save_yourself",
1092
GTK_SIGNAL_FUNC(save_session_cb), NULL);
1093
g_signal_connect(GTK_OBJECT(client), "die",
1094
GTK_SIGNAL_FUNC(session_die_cb), NULL);
1095
g_signal_connect(GTK_OBJECT(app), "key-press-event",
1096
GTK_SIGNAL_FUNC(key_press_event_cb), NULL);
1098
/* Redraw the status window every 3 seconds
1099
* Necessary, because the mono/stereo reception
1100
* needs some time to be correctly detected
1102
redraw_timeout_id = gtk_timeout_add(3000, (GtkFunction)redraw_status_window, NULL);
1104
/* Checks if the volume has been changed by an
1107
//gtk_timeout_add(100, (GtkFunction)poll_volume_change, NULL);