~blackskad/gnomeradio/dev-vol-button

« back to all changes in this revision

Viewing changes to src/gui.c

  • Committer: mfcn
  • Date: 2003-01-08 17:19:21 UTC
  • Revision ID: svn-v3-trunk0:ba97a3d1-ec25-0410-b1c6-e06ad936ea6c:trunk:2
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gui.c
 
2
 *
 
3
 * Copyright (C) 2001 J�rgen Scheibengruber
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 * USA
 
19
 */
 
20
 
 
21
/*** the gui to gnomeradio */
 
22
 
 
23
#include <config.h>
 
24
#include <gnome.h>
 
25
#include <gconf/gconf-client.h>
 
26
#include <math.h>
 
27
#include "gui.h"
 
28
#include "tech.h"
 
29
#include "rec_tech.h"
 
30
#include "lirc.h"
 
31
#include "prefs.h"
 
32
#include "record.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"
 
41
 
 
42
#define DIGIT_WIDTH 20
 
43
#define DIGIT_HEIGTH 30
 
44
#define SIGNAL_WIDTH 25
 
45
#define STEREO_WIDTH 35
 
46
#define SCAN_SPEED 20
 
47
 
 
48
#define TRANSLATORS "TRANSLATORS"
 
49
 
 
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;
 
54
 
 
55
static int timeout_id, bp_timeout_id = -1, bp_timeout_steps = 0;
 
56
 
 
57
void start_radio(gboolean restart, GtkWidget *app)
 
58
{
 
59
        if (restart)
 
60
                radio_stop();
 
61
        
 
62
        if (!radio_init(settings.device)) 
 
63
        {
 
64
                GtkWidget *dialog;
 
65
                
 
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);
 
72
        }               
 
73
}
 
74
 
 
75
void start_mixer(gboolean restart, GtkWidget *app)
 
76
{
 
77
        gint res, vol;
 
78
        
 
79
        if (restart)
 
80
                mixer_close();
 
81
        
 
82
        res = mixer_init(settings.mixer_dev, settings.mixer);
 
83
        if (res <1) 
 
84
        {
 
85
                GtkWidget *dialog;
 
86
                char *buffer;
 
87
                
 
88
                if (res == -1)
 
89
                        buffer = g_strdup_printf(_("Mixer source \"%s\" is not a valid source!"), settings.mixer);
 
90
                else 
 
91
                        buffer = g_strdup_printf(_("Could not open \"%s\"!"), settings.mixer_dev);
 
92
 
 
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);
 
96
                
 
97
                g_free(buffer);
 
98
        }               
 
99
        vol = mixer_get_volume();
 
100
        
 
101
        if (vol >= 0)
 
102
                gtk_adjustment_set_value(volume, (double)vol);
 
103
}
 
104
 
 
105
GList* get_mixer_recdev_list(void)
 
106
{
 
107
        int i;
 
108
        char **array, *dev;
 
109
        char *gconf_path = NULL, *sndcard_name = NULL;
 
110
        GList *result = NULL;
 
111
        GConfClient *client = NULL;
 
112
        
 
113
        array = mixer_get_rec_devices();
 
114
        if (!array)
 
115
                return NULL;
 
116
 
 
117
        if (!gconf_is_initialized())
 
118
                return NULL;
 
119
        
 
120
        client = gconf_client_get_default();
 
121
        
 
122
        sndcard_name = mixer_get_sndcard_name();
 
123
        if (sndcard_name)
 
124
        {
 
125
                g_strdelimit (sndcard_name, " ", '_');
 
126
                gconf_path = g_strdup_printf("/apps/gnome-volume-control/OSS-%s-%d/%%s/title", sndcard_name, 1);
 
127
                //puts(gconf_path);
 
128
                free(sndcard_name);
 
129
        }
 
130
        
 
131
        i = 0;  
 
132
        dev = array[i];
 
133
        while (dev)
 
134
        {
 
135
                char *gconf_dev = NULL;
 
136
                char *text = NULL;
 
137
                
 
138
                if (client && gconf_path)
 
139
                {
 
140
                        char *path = g_strdup_printf(gconf_path, dev);
 
141
                        gconf_dev = gconf_client_get_string(client, path , NULL);
 
142
                        g_free(path);
 
143
                }
 
144
                if (gconf_dev)
 
145
                {
 
146
                        if (strcmp(gconf_dev, dev))
 
147
                                text = g_strdup_printf("%s (%s)", dev, gconf_dev);
 
148
                        else
 
149
                                text = g_strdup(dev);
 
150
                        g_free(gconf_dev);
 
151
                        gconf_dev = NULL;
 
152
                }
 
153
                else
 
154
                        text = g_strdup(dev);
 
155
                result = g_list_append(result, text);
 
156
                free(dev);
 
157
                dev = array[++i];
 
158
        }                       
 
159
        free(array);
 
160
        g_free(gconf_path);
 
161
        
 
162
        return result;
 
163
}
 
164
 
 
165
static gboolean
 
166
redraw_status_window(gboolean expose_event)
 
167
{
 
168
 
 
169
        GdkWindow *window;
 
170
        static GdkGC *gc;
 
171
        int win_width, win_height;
 
172
        //int a, b, c, d, e;
 
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;
 
175
        double dob, val;
 
176
        
 
177
        //g_print("Redrawing %s\n", expose_event ? "(expose event)" : "");
 
178
        
 
179
        if (expose_event)
 
180
        {
 
181
                for (i=0; i<5; old_freq[i++] = -1)
 
182
                        ;
 
183
                old_signal_strength = -1;
 
184
                old_is_stereo = -1;
 
185
        }
 
186
        
 
187
        val = rint(gtk_adjustment_get_value(adj));
 
188
 
 
189
        fl = (int)(floor(val/STEPS));
 
190
        dob = rint((double)(val*100/STEPS));
 
191
        rst = (int)(dob)%100;
 
192
                
 
193
        freq[0] = fl - fl%100;
 
194
        freq[1] = (fl - freq[0]) - (fl - freq[0])%10;
 
195
        freq[2] = fl - freq[0] - freq[1]; 
 
196
        freq[4] = rst%10;
 
197
        freq[3] = (rst - freq[4])/10;
 
198
 
 
199
        freq[0] /= 100;
 
200
        freq[1] /= 10;
 
201
 
 
202
        signal_strength = radio_getsignal();
 
203
        is_stereo = radio_getstereo();
 
204
        
 
205
        if (signal_strength > 3)
 
206
                signal_strength = 3;
 
207
        if (signal_strength < 0)
 
208
                signal_strength = 0;
 
209
        
 
210
        window = drawing_area->window;
 
211
 
 
212
        gdk_drawable_get_size(window, &win_width, &win_height);
 
213
        if (!gc)
 
214
                gc = gdk_gc_new(window);
 
215
        
 
216
        if (expose_event || first)
 
217
                gdk_draw_rectangle(window, gc, TRUE, 0, 0, -1, -1);
 
218
        if (first)
 
219
                first = 0;
 
220
        
 
221
        win_width -= 5;
 
222
        
 
223
        if (freq[0] != old_freq[0])
 
224
        {
 
225
                if (freq[0])
 
226
                        gdk_draw_drawable(window, gc, digits, freq[0] * DIGIT_WIDTH, 0, win_width - DIGIT_WIDTH*6, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
 
227
                else
 
228
                        gdk_draw_rectangle(window, gc, TRUE, win_width - DIGIT_WIDTH*6, 5, DIGIT_WIDTH, DIGIT_HEIGTH);
 
229
        }
 
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);
 
234
        if (expose_event)
 
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);
 
244
 
 
245
        for (i=0; i<5; old_freq[i] = freq[i++])
 
246
                        ;
 
247
        old_signal_strength = signal_strength;
 
248
        old_is_stereo = is_stereo;
 
249
        
 
250
        return TRUE;    
 
251
}
 
252
        
 
253
 
 
254
static gboolean
 
255
expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
 
256
{
 
257
        return redraw_status_window(TRUE);
 
258
}       
 
259
 
 
260
void exit_gnome_radio(void)
 
261
{
 
262
        if (settings.mute_on_exit)
 
263
        {
 
264
                radio_mute();
 
265
                radio_stop();
 
266
        }
 
267
        mixer_close();
 
268
        save_settings();
 
269
        gtk_main_quit();
 
270
}
 
271
 
 
272
static void adj_value_changed_cb(GtkAdjustment* data, gpointer window)
 
273
{
 
274
        gchar *buffer;
 
275
 
 
276
        //expose_event_cb(NULL, NULL, NULL);
 
277
        redraw_status_window(FALSE);
 
278
        
 
279
        buffer = g_strdup_printf(_("Gnomeradio - %.2f MHz"), rint(adj->value)/STEPS);
 
280
        gtk_window_set_title (GTK_WINDOW(window), buffer);
 
281
        g_free(buffer);
 
282
        
 
283
        buffer = g_strdup_printf(_("Frequency: %.2f MHz"), rint(adj->value)/STEPS);
 
284
        gtk_tooltips_set_tip(tooltips, freq_scale, buffer, NULL);
 
285
        g_free(buffer);
 
286
 
 
287
        radio_setfreq(adj->value/STEPS);
 
288
}
 
289
 
 
290
static gboolean freq_scale_focus_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
 
291
{
 
292
        mom_ps = -1;
 
293
        preset_menu_set_item(mom_ps);
 
294
        return FALSE;
 
295
}
 
296
 
 
297
static void volume_value_changed_cb(GtkAdjustment* data, gpointer window)
 
298
{
 
299
        char *text;
 
300
        
 
301
        mixer_set_volume((gint)volume->value);
 
302
        
 
303
        text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
 
304
        gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
 
305
        g_free(text);
 
306
 
 
307
}
 
308
 
 
309
#if 0
 
310
static gboolean poll_volume_change(gpointer data)
 
311
{
 
312
        int vol;
 
313
        if ((vol = mixer_get_volume()) < 0)
 
314
                return FALSE;
 
315
        
 
316
        if (vol != (int)volume->value)
 
317
        {
 
318
                g_print("external volume change detected\n");
 
319
                gtk_adjustment_set_value(volume, (double)vol);
 
320
        }
 
321
        
 
322
        return TRUE;
 
323
}
 
324
#endif
 
325
 
 
326
static void
 
327
change_frequency(gpointer data)
 
328
{
 
329
        gboolean increase = (gboolean)data;
 
330
        
 
331
        if (increase)
 
332
        {
 
333
                if (adj->value >= FREQ_MAX*STEPS)
 
334
                        gtk_adjustment_set_value(adj, FREQ_MIN*STEPS);
 
335
                else
 
336
                        gtk_adjustment_set_value(adj, adj->value+1);
 
337
        }
 
338
        else
 
339
        {
 
340
                if (adj->value <= FREQ_MIN*STEPS)
 
341
                        gtk_adjustment_set_value(adj, FREQ_MAX*STEPS);
 
342
                else
 
343
                        gtk_adjustment_set_value(adj, adj->value-1);
 
344
        }
 
345
}
 
346
 
 
347
static gboolean
 
348
change_frequency_timeout(gpointer data)
 
349
{
 
350
        change_frequency(data);
 
351
        if (bp_timeout_steps < 10)
 
352
        {
 
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);
 
357
                bp_timeout_steps++; 
 
358
        }
 
359
        return TRUE;
 
360
}       
 
361
 
 
362
static void step_button_pressed_cb(GtkButton *button, gpointer data)
 
363
{
 
364
        //change_frequency(data);
 
365
        bp_timeout_id = gtk_timeout_add(500, (GtkFunction)change_frequency_timeout, data);
 
366
        
 
367
        mom_ps = -1;
 
368
        preset_menu_set_item(mom_ps);
 
369
}
 
370
 
 
371
static void step_button_clicked_cb(GtkButton *button, gpointer data)
 
372
{
 
373
        change_frequency(data);
 
374
 
 
375
        mom_ps = -1;
 
376
        preset_menu_set_item(mom_ps);
 
377
}
 
378
 
 
379
static void step_button_released_cb(GtkButton *button, gpointer data)
 
380
{
 
381
        if (bp_timeout_id > -1)
 
382
                gtk_timeout_remove(bp_timeout_id);
 
383
        bp_timeout_id = -1;
 
384
        bp_timeout_steps = 0;
 
385
}
 
386
 
 
387
 
 
388
static gboolean scan_freq(gpointer data)
 
389
{
 
390
        static gint signal, a, b, c;    
 
391
        static gint start, mom, max;
 
392
        gint dir = (gint)(data);
 
393
        
 
394
        if (!max)
 
395
                max = (FREQ_MAX - FREQ_MIN) * STEPS;
 
396
 
 
397
        if ((a + b + c > 8) || (start > max))   
 
398
        {
 
399
                start = mom = a = b = c = 0;
 
400
                radio_unmute();
 
401
                timeout_id = 0;
 
402
                return FALSE;
 
403
        }
 
404
        if (!mom)
 
405
        mom= adj->value;
 
406
        if (mom > FREQ_MAX*STEPS) 
 
407
                mom = FREQ_MIN*STEPS;
 
408
        else
 
409
        if (mom < FREQ_MIN*STEPS)
 
410
                mom = FREQ_MAX*STEPS;
 
411
        else    
 
412
                mom = mom + dir;
 
413
        start += 1;
 
414
        gtk_adjustment_set_value(adj, mom);
 
415
        signal = radio_getsignal();
 
416
        a = b;
 
417
        b = c;
 
418
        c = signal;
 
419
        return TRUE;
 
420
}
 
421
 
 
422
void scfw_button_clicked_cb(GtkButton *button, gpointer data)
 
423
{
 
424
        if (timeout_id)
 
425
                return;
 
426
        radio_mute();
 
427
        timeout_id = gtk_timeout_add(1000/SCAN_SPEED, (GtkFunction)scan_freq, (gpointer)1);     
 
428
        mom_ps = -1;
 
429
        preset_menu_set_item(mom_ps);
 
430
 
 
431
}
 
432
 
 
433
void scbw_button_clicked_cb(GtkButton *button, gpointer data)
 
434
{
 
435
        if (timeout_id)
 
436
                return;
 
437
        radio_mute();
 
438
        timeout_id = gtk_timeout_add(1000/SCAN_SPEED, (GtkFunction)scan_freq, (gpointer)(-1));  
 
439
        mom_ps = -1;
 
440
        preset_menu_set_item(mom_ps);
 
441
}
 
442
 
 
443
void preset_menu_set_item(gint i)
 
444
{
 
445
        gtk_option_menu_set_history(GTK_OPTION_MENU(preset_menu), i+1);
 
446
}
 
447
 
 
448
static void pref_item_activate_cb(GtkWidget *item, gpointer data)
 
449
{
 
450
        gint i = (gint)data;
 
451
        preset* ps = (preset*)g_list_nth_data(settings.presets,i);
 
452
        mom_ps = i;
 
453
        gtk_adjustment_set_value(adj, ps->freq*STEPS);
 
454
}
 
455
 
 
456
static void update_preset_menu(void)
 
457
{
 
458
        gint i, count;
 
459
        GtkWidget *item;
 
460
        preset *ps;
 
461
        
 
462
        if (menu)
 
463
                gtk_widget_destroy(menu);
 
464
        menu = gtk_menu_new();
 
465
        
 
466
        count = g_list_length(settings.presets);
 
467
        
 
468
        item = gtk_menu_item_new_with_label(_("manual"));
 
469
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
470
        
 
471
        for (i=0;i<count;i++)
 
472
        {
 
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);
 
477
        }
 
478
        gtk_widget_show_all(menu);
 
479
        gtk_option_menu_set_menu(GTK_OPTION_MENU(preset_menu), menu);
 
480
}
 
481
 
 
482
void
 
483
change_preset(gboolean next)
 
484
{
 
485
        preset *ps;
 
486
        int len = g_list_length(settings.presets);
 
487
        if (len < 1)
 
488
                return;
 
489
 
 
490
        if (next)
 
491
                mom_ps = (mom_ps + 1) % len;
 
492
        else
 
493
                mom_ps = (mom_ps - 1 + len) % len;
 
494
 
 
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);
 
498
}
 
499
 
 
500
static void quit_button_clicked_cb(GtkButton *button, gpointer data)
 
501
{
 
502
        exit_gnome_radio();
 
503
}
 
504
 
 
505
static void prefs_button_clicked_cb(GtkButton *button, gpointer app)
 
506
{
 
507
        GtkWidget* dialog;
 
508
        gint choise;
 
509
        
 
510
        backup_settings();
 
511
        
 
512
        dialog = prefs_window();
 
513
        
 
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);
 
518
        
 
519
        /*gnome_dialog_set_parent(GNOME_DIALOG(dialog), GTK_WINDOW(app));*/
 
520
        
 
521
        
 
522
        choise = GTK_RESPONSE_HELP;
 
523
        while (choise == GTK_RESPONSE_HELP)
 
524
        {
 
525
                choise = gtk_dialog_run(GTK_DIALOG(dialog)); 
 
526
                switch (choise)
 
527
                {
 
528
                        case GTK_RESPONSE_OK:
 
529
                                gtk_widget_destroy(dialog);
 
530
                                commit_settings(app);
 
531
                                update_preset_menu();
 
532
                                break;
 
533
                
 
534
                        case GTK_RESPONSE_HELP:
 
535
                                display_help_cb("gnomeradio-settings");
 
536
                        break;
 
537
                        default:
 
538
                                gtk_widget_destroy(dialog);
 
539
                                rollback_settings();
 
540
                }
 
541
        }
 
542
}
 
543
 
 
544
static int
 
545
start_recording(void)
 
546
{
 
547
        GIOChannel *wavioc = NULL, *mp3ioc = NULL;
 
548
        GtkWidget *dialog;
 
549
        
 
550
        if (!mixer_set_rec_device())
 
551
        {
 
552
                GtkWidget *dialog;
 
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);
 
557
                return -1;
 
558
        }
 
559
                
 
560
        if (rec_settings.mp3)
 
561
                record_as_mp3(&wavioc, &mp3ioc);
 
562
        else    
 
563
                record_as_wave(&wavioc);
 
564
 
 
565
        dialog = record_status_window();
 
566
        
 
567
        run_status_window(wavioc, mp3ioc);
 
568
        return 1;
 
569
}
 
570
 
 
571
static void rec_button_clicked_cb(GtkButton *button, gpointer app)
 
572
{
 
573
        GtkWidget *dialog;
 
574
        gint choise, retval=0;
 
575
        
 
576
        if (!check_sox_installation())
 
577
        {
 
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);
 
583
                return;
 
584
        }
 
585
        
 
586
        dialog = record_prefs_window();
 
587
        
 
588
        gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(app));
 
589
        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
 
590
        
 
591
        //g_print("choise: %d\n", choise);
 
592
        
 
593
        choise = GTK_RESPONSE_HELP;
 
594
        while (choise == GTK_RESPONSE_HELP)
 
595
        {
 
596
                choise = gtk_dialog_run(GTK_DIALOG(dialog));
 
597
                switch (choise)
 
598
                {
 
599
                        case GTK_RESPONSE_HELP:
 
600
                                display_help_cb("gnomeradio-recording");
 
601
                                break;
 
602
 
 
603
                        case GTK_RESPONSE_OK:
 
604
                
 
605
                                retval = 0;
 
606
                                while (!retval)
 
607
                                {
 
608
                                        if (g_file_test(rec_settings.filename, G_FILE_TEST_EXISTS ))
 
609
                                        {
 
610
                                                int ch;
 
611
                                                GtkWidget *question;
 
612
                                                question = gtk_message_dialog_new(GTK_WINDOW(app), DIALOG_FLAGS, GTK_MESSAGE_QUESTION, 
 
613
                                                                        GTK_BUTTONS_YES_NO, 
 
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)
 
618
                                                        break;
 
619
                                        }
 
620
                                        retval = check_filename(rec_settings.filename);
 
621
                                        if (!retval)
 
622
                                        {
 
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);
 
628
                                                break;
 
629
                                        }
 
630
                                }
 
631
                                if (retval > 0)
 
632
                                {
 
633
                                        gtk_widget_destroy(dialog);
 
634
                                        start_recording();
 
635
                                }
 
636
                                else
 
637
                                        choise = GTK_RESPONSE_HELP;
 
638
                                break;
 
639
                        default:
 
640
                                gtk_widget_destroy(dialog);
 
641
                }
 
642
        }
 
643
}
 
644
 
 
645
void mute_button_toggled_cb(GtkButton *button, gpointer data)
 
646
{
 
647
        static gboolean muted = FALSE;
 
648
        
 
649
        if (muted)
 
650
        {
 
651
                radio_unmute();
 
652
                muted = FALSE;
 
653
                gtk_tooltips_set_tip(tooltips, mute_button, _("Mute"), NULL);
 
654
        }
 
655
        else
 
656
        {
 
657
                radio_mute();
 
658
                muted = TRUE;
 
659
                gtk_tooltips_set_tip(tooltips, mute_button, _("Unmute"), NULL);
 
660
        }
 
661
}
 
662
 
 
663
static void about_button_clicked_cb(GtkButton *button, gpointer data)
 
664
{
 
665
        GdkPixbuf *app_icon;
 
666
        static GtkWidget *about;
 
667
        const char *authors[] = {"Jörgen Scheibengruber <mfcn@gmx.de>", NULL};
 
668
        char *text;
 
669
        
 
670
        /* Feel free to put your names here translators :-) */
 
671
        char *translators = _("TRANSLATORS");
 
672
 
 
673
        if (about)
 
674
        {
 
675
                gtk_window_present(GTK_WINDOW(about));
 
676
                return;
 
677
        }
 
678
 
 
679
        app_icon = gdk_pixbuf_new_from_xpm_data((const char**)radio_xpm);
 
680
 
 
681
#ifdef HAVE_LIRC        
 
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.");
 
685
#else
 
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.");
 
689
#endif
 
690
        
 
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, 
 
694
                                                        app_icon);
 
695
 
 
696
        gtk_widget_show(about);
 
697
        g_object_add_weak_pointer(G_OBJECT(about), (gpointer*)&about);
 
698
        
 
699
}
 
700
 
 
701
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
 
702
{
 
703
        exit_gnome_radio();
 
704
        return TRUE;
 
705
}
 
706
 
 
707
void display_help_cb(char *topic)
 
708
{
 
709
        GError *error = NULL;
 
710
 
 
711
        gnome_help_display(PACKAGE, topic, &error);
 
712
        if (error)
 
713
        {
 
714
                GtkWidget *dialog;
 
715
                dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
716
                                error->message);
 
717
                gtk_dialog_run (GTK_DIALOG (dialog));
 
718
                gtk_widget_destroy (dialog);
 
719
                g_error_free (error);
 
720
                error = NULL;
 
721
        }
 
722
}
 
723
 
 
724
GtkWidget* gnome_radio_gui(void)
 
725
{
 
726
        GtkWidget *app;
 
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;
 
735
        GtkWidget *label;
 
736
        GtkWidget *frame1, *frame2;
 
737
        gchar *text;
 
738
 
 
739
        app = gnome_app_new(PACKAGE, _("Gnomeradio"));
 
740
 
 
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");
 
744
 
 
745
        frame1 = gtk_frame_new(NULL);
 
746
        frame2 = gtk_frame_new(NULL);
 
747
 
 
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);*/
 
757
        
 
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);
 
768
        
 
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();
 
779
 
 
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);
 
790
 
 
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);*/
 
800
 
 
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);
 
806
        
 
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));
 
809
        
 
810
        
 
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:"));
 
815
        
 
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);
 
819
        
 
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);
 
824
 
 
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);
 
829
 
 
830
        //gtk_widget_set_usize(freq_scale, 160, 10);
 
831
        gtk_widget_set_size_request(freq_scale, 160, -1);
 
832
 
 
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);
 
838
        
 
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();
 
845
        
 
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);
 
850
 
 
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);
 
854
 
 
855
        gtk_container_add(GTK_CONTAINER(frame2), drawing_area);
 
856
 
 
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);
 
870
 
 
871
        gtk_box_pack_start(GTK_BOX(hbox1), frame2, FALSE, FALSE, 3);
 
872
        gtk_box_pack_start(GTK_BOX(hbox1), menubox, TRUE, TRUE, 3);
 
873
        
 
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);
 
876
 
 
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);
 
884
 
 
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);
 
890
        
 
891
        gtk_container_add(GTK_CONTAINER(frame1), vbox);
 
892
        
 
893
        gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_IN);
 
894
 
 
895
        gtk_container_set_border_width(GTK_CONTAINER(frame1), 3);
 
896
        gtk_container_set_border_width(GTK_CONTAINER(frame2), 2);
 
897
 
 
898
        gnome_app_set_contents(GNOME_APP(app), frame1);
 
899
 
 
900
        //status = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_NEVER);
 
901
 
 
902
        //gnome_app_set_statusbar(GNOME_APP(app), status);
 
903
 
 
904
        tooltips = gtk_tooltips_new();
 
905
 
 
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);
 
924
 
 
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);
 
936
        g_free(text);
 
937
        text = g_strdup_printf(_("Volume: %d%%"), (gint)volume->value);
 
938
        gtk_tooltips_set_tip(tooltips, vol_scale, text, NULL);
 
939
        g_free(text);
 
940
        
 
941
        return app;
 
942
}
 
943
 
 
944
static void
 
945
session_die_cb(GnomeClient* client, gpointer client_data)
 
946
{
 
947
        if (settings.mute_on_exit)
 
948
        {
 
949
                radio_mute();
 
950
                radio_stop();
 
951
        }
 
952
        mixer_close();
 
953
        gtk_main_quit();
 
954
        exit (0);
 
955
}
 
956
 
 
957
static void 
 
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)
 
961
{
 
962
        save_settings();
 
963
}
 
964
 
 
965
static void
 
966
gconf_error_handler(GConfClient *client, GError *error)
 
967
{
 
968
        //gnome_error_dialog(error->message);
 
969
        g_print("GConf error: %s\n", error->message);
 
970
}
 
971
 
 
972
static gboolean
 
973
key_press_event_cb(GtkWidget *app, GdkEventKey *event, gpointer data)
 
974
{
 
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);
 
978
        
 
979
        switch (event->keyval)
 
980
        {
 
981
                case GDK_F1: display_help_cb(NULL);
 
982
                                break;
 
983
                case GDK_m: 
 
984
                                gtk_toggle_button_set_active(tb, !state);
 
985
                                break;
 
986
                case GDK_q: 
 
987
                                exit_gnome_radio();
 
988
                                break;
 
989
                case GDK_r: 
 
990
                                rec_button_clicked_cb(NULL, app);
 
991
                                break;
 
992
                case GDK_f: 
 
993
                                scfw_button_clicked_cb(NULL, NULL);
 
994
                                break;
 
995
                case GDK_b: 
 
996
                                scbw_button_clicked_cb(NULL, NULL);
 
997
                                break;
 
998
                case GDK_n: 
 
999
                                change_preset(TRUE);
 
1000
                                break;
 
1001
                case GDK_p: 
 
1002
                                change_preset(FALSE);
 
1003
                                break;
 
1004
                case GDK_KP_Add:
 
1005
                case GDK_plus:  
 
1006
                                gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);
 
1007
                                break;
 
1008
                case GDK_minus:
 
1009
                case GDK_KP_Subtract: 
 
1010
                                gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);
 
1011
                                break;
 
1012
        }
 
1013
        return FALSE;
 
1014
}
 
1015
 
 
1016
int main(int argc, char* argv[])
 
1017
{
 
1018
        GtkWidget* app;
 
1019
        GList *icons;
 
1020
        GdkPixbuf *app_icon;
 
1021
        GnomeClient *client;
 
1022
        GError *err = NULL;
 
1023
        int redraw_timeout_id;
 
1024
        
 
1025
        bindtextdomain(PACKAGE, GNOMELOCALEDIR);  
 
1026
        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 
1027
        textdomain(PACKAGE);
 
1028
 
 
1029
        gnome_program_init(PACKAGE, VERSION, 
 
1030
                                        LIBGNOMEUI_MODULE, argc, argv, 
 
1031
                                        GNOME_PROGRAM_STANDARD_PROPERTIES, 
 
1032
                                        NULL);
 
1033
                
 
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);
 
1037
 
 
1038
        /* Technical Stuff */
 
1039
        
 
1040
        /* Main app */
 
1041
 
 
1042
        app = gnome_radio_gui();
 
1043
 
 
1044
        gtk_widget_show_all(app);
 
1045
 
 
1046
        /* Initizialize Gconf */
 
1047
        if (!gconf_init(argc, argv, &err))
 
1048
        {
 
1049
                GtkWidget *dialog;
 
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);
 
1055
                g_error_free(err); 
 
1056
                err = NULL;
 
1057
        }
 
1058
        else
 
1059
        {
 
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);
 
1062
        }
 
1063
                
 
1064
        load_settings();
 
1065
        update_preset_menu();
 
1066
        //g_print("momps: %i\n", mom_ps);
 
1067
        preset_menu_set_item(mom_ps);
 
1068
 
 
1069
        start_radio(FALSE, app);
 
1070
        
 
1071
#ifdef HAVE_LIRC
 
1072
        if(!my_lirc_init())
 
1073
        {
 
1074
                GtkWidget *dialog;
 
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);
 
1079
        }
 
1080
        else
 
1081
                start_lirc();
 
1082
#endif
 
1083
 
 
1084
        start_mixer(FALSE, app);
 
1085
        adj_value_changed_cb(NULL, (gpointer) app);
 
1086
        volume_value_changed_cb(NULL, NULL);
 
1087
        
 
1088
/* Connect the Session Management signals
 
1089
 */
 
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);
 
1097
 
 
1098
        /* Redraw the status window every 3 seconds
 
1099
         * Necessary, because the mono/stereo reception
 
1100
         * needs some time to be correctly detected
 
1101
         */
 
1102
        redraw_timeout_id = gtk_timeout_add(3000, (GtkFunction)redraw_status_window, NULL);     
 
1103
 
 
1104
        /* Checks if the volume has been changed by an 
 
1105
         * external app
 
1106
         */
 
1107
        //gtk_timeout_add(100, (GtkFunction)poll_volume_change, NULL);
 
1108
 
 
1109
        gtk_main();
 
1110
                
 
1111
#ifdef HAVE_LIRC        
 
1112
        my_lirc_deinit();
 
1113
#endif
 
1114
 
 
1115
        return 0;
 
1116
}
 
1117