~blackskad/gnomeradio/dev-vol-button

« back to all changes in this revision

Viewing changes to src/prefs.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
/*
 
2
 *  This program is free software; you can redistribute it and/or modify
 
3
 *  it under the terms of the GNU General Public License as published by
 
4
 *  the Free Software Foundation; either version 2 of the License, or
 
5
 *  (at your option) any later version.
 
6
 *
 
7
 *  This program is distributed in the hope that it will be useful,
 
8
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *  GNU Library General Public License for more details.
 
11
 *
 
12
 *  You should have received a copy of the GNU General Public License
 
13
 *  along with this program; if not, write to the Free Software
 
14
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 */
 
16
 
 
17
#include <gconf/gconf-client.h>
 
18
#include <string.h>
 
19
#include "config.h"
 
20
#include "prefs.h"
 
21
#include "gui.h"
 
22
#include "rec_tech.h"
 
23
 
 
24
#define UN_NAMED "unnamed"
 
25
 
 
26
static GtkWidget *name_entry, *device_entry, *freq_spin;
 
27
static GtkWidget *mixer_combo;
 
28
static GtkWidget *mute_on_exit_cb;
 
29
//static GtkWidget *clist;
 
30
static GtkWidget *list_view;
 
31
static GtkListStore *list_store;
 
32
static GtkTreeSelection *selection;
 
33
static GtkAdjustment *spin;
 
34
static gint selected_row = -1;
 
35
 
 
36
static gnomeradio_settings tmp_settings;
 
37
 
 
38
gboolean save_settings(void)
 
39
{
 
40
        gint i, count;
 
41
        gchar *buffer;
 
42
        preset *ps;
 
43
        GConfClient* client = NULL;
 
44
        
 
45
        if (!gconf_is_initialized())
 
46
                return FALSE;
 
47
 
 
48
        client = gconf_client_get_default();
 
49
        if (!client)
 
50
                return FALSE;
 
51
        
 
52
        /* Store general settings */
 
53
        gconf_client_set_string(client, "/apps/gnomeradio/device", settings.device, NULL);
 
54
        gconf_client_set_string(client, "/apps/gnomeradio/mixer", settings.mixer, NULL);
 
55
        gconf_client_set_string(client, "/apps/gnomeradio/mixer-device", settings.mixer_dev, NULL);
 
56
        gconf_client_set_bool(client, "/apps/gnomeradio/mute-on-exit", settings.mute_on_exit, NULL);
 
57
        //gconf_client_set_float(client, "/apps/gnomeradio/volume", volume->value, NULL);
 
58
        gconf_client_set_float(client, "/apps/gnomeradio/last-freq", adj->value/STEPS, NULL);
 
59
 
 
60
        /* Store recording settings */
 
61
        gconf_client_set_string(client, "/apps/gnomeradio/recording/audiodevice", rec_settings.audiodevice, NULL);
 
62
        gconf_client_set_string(client, "/apps/gnomeradio/recording/last-filename", rec_settings.filename, NULL);
 
63
        gconf_client_set_bool(client, "/apps/gnomeradio/recording/record-as-mp3", rec_settings.mp3, NULL);
 
64
        gconf_client_set_string(client, "/apps/gnomeradio/recording/sample-rate", rec_settings.rate, NULL);
 
65
        gconf_client_set_string(client, "/apps/gnomeradio/recording/sample-format", rec_settings.sample, NULL);
 
66
        gconf_client_set_bool(client, "/apps/gnomeradio/recording/record-in-stereo", rec_settings.stereo, NULL);
 
67
        gconf_client_set_string(client, "/apps/gnomeradio/recording/encoder", rec_settings.encoder, NULL);
 
68
        gconf_client_set_string(client, "/apps/gnomeradio/recording/bitrate", rec_settings.bitrate, NULL);
 
69
 
 
70
        /* Store the presets */
 
71
        count = g_list_length(settings.presets);
 
72
        gconf_client_set_int(client, "/apps/gnomeradio/presets/presets", count, NULL);
 
73
        for (i=0;i<count;i++)
 
74
        {
 
75
                ps = g_list_nth_data(settings.presets, i);
 
76
                buffer = g_strdup_printf("/apps/gnomeradio/presets/%d/name", i);
 
77
                gconf_client_set_string(client, buffer, ps->name, NULL); 
 
78
                g_free(buffer);
 
79
                buffer = g_strdup_printf("/apps/gnomeradio/presets/%d/freqency", i);
 
80
                gconf_client_set_float(client, buffer, ps->freq, NULL); 
 
81
                g_free(buffer);
 
82
        }       
 
83
        gconf_client_set_int(client, "/apps/gnomeradio/presets/last", mom_ps, NULL);
 
84
        g_print("Storing Settings in GConf database\n");
 
85
        
 
86
        return TRUE;
 
87
}                       
 
88
 
 
89
gboolean load_settings(void)
 
90
{
 
91
        gint i, count;
 
92
        gchar *buffer;
 
93
        preset *ps;
 
94
        GConfClient *client = NULL;
 
95
        double freq;
 
96
        
 
97
        settings.presets = NULL;
 
98
                
 
99
        if (!gconf_is_initialized())
 
100
                return FALSE;
 
101
        
 
102
        client = gconf_client_get_default();
 
103
        if (!client)
 
104
                return FALSE;
 
105
 
 
106
        /* Load general settings */
 
107
        settings.device = gconf_client_get_string(client, "/apps/gnomeradio/device" , NULL);
 
108
        if (!settings.device)
 
109
                settings.device = g_strdup("/dev/radio");
 
110
        settings.mixer = gconf_client_get_string(client, "/apps/gnomeradio/mixer", NULL);
 
111
        if (!settings.mixer)
 
112
                settings.mixer = g_strdup("line");
 
113
        settings.mixer_dev = gconf_client_get_string(client, "/apps/gnomeradio/mixer-device", NULL);
 
114
        if (!settings.mixer_dev)
 
115
                settings.mixer_dev = g_strdup("/dev/mixer");
 
116
        settings.mute_on_exit = gconf_client_get_bool(client, "/apps/gnomeradio/mute-on-exit", NULL);
 
117
        //volume->value = gconf_client_get_float(client, "/apps/gnomeradio/volume", NULL);
 
118
        freq = gconf_client_get_float(client, "/apps/gnomeradio/last-freq", NULL);
 
119
        if ((freq < FREQ_MIN) || (freq > FREQ_MAX))
 
120
                adj->value = FREQ_MIN * STEPS;
 
121
        else
 
122
                adj->value = freq * STEPS;
 
123
        
 
124
        /* Load recording settings */
 
125
        rec_settings.audiodevice = gconf_client_get_string(client, "/apps/gnomeradio/recording/audiodevice", NULL);
 
126
        if (!rec_settings.audiodevice)
 
127
                rec_settings.audiodevice = g_strdup("/dev/audio");
 
128
        rec_settings.filename = gconf_client_get_string(client, "/apps/gnomeradio/recording/last-filename", NULL);
 
129
        if (!rec_settings.filename)
 
130
                rec_settings.filename = g_strdup("/");
 
131
        rec_settings.mp3 = gconf_client_get_bool(client, "/apps/gnomeradio/recording/record-as-mp3", NULL);
 
132
        rec_settings.rate = gconf_client_get_string(client, "/apps/gnomeradio/recording/sample-rate", NULL);
 
133
        if (!rec_settings.rate)
 
134
                rec_settings.rate = g_strdup("44100");
 
135
        rec_settings.sample = gconf_client_get_string(client, "/apps/gnomeradio/recording/sample-format", NULL);
 
136
        if (!rec_settings.sample)
 
137
                rec_settings.sample = g_strdup("16");
 
138
        rec_settings.stereo = gconf_client_get_bool(client, "/apps/gnomeradio/recording/record-in-stereo", NULL);
 
139
        rec_settings.encoder = gconf_client_get_string(client, "/apps/gnomeradio/recording/encoder", NULL);
 
140
        if (!rec_settings.encoder)
 
141
                rec_settings.encoder = g_strdup("lame");
 
142
        rec_settings.bitrate = gconf_client_get_string(client, "/apps/gnomeradio/recording/bitrate", NULL);
 
143
        if (!rec_settings.bitrate)
 
144
                rec_settings.bitrate = g_strdup("128");
 
145
        
 
146
        /* Load the presets */
 
147
        count = gconf_client_get_int(client, "/apps/gnomeradio/presets/presets", NULL);
 
148
        for (i=0;i<count;i++)
 
149
        {
 
150
                char *tmp;
 
151
                ps = malloc(sizeof(preset));
 
152
                buffer = g_strdup_printf("/apps/gnomeradio/presets/%d/name", i);
 
153
                tmp = gconf_client_get_string(client, buffer, NULL); 
 
154
                if (!tmp)
 
155
                        tmp = "unnamed";
 
156
                strncpy(ps->name, tmp, 20);
 
157
                ps->name[20] = '\0';
 
158
                g_free(buffer);
 
159
                buffer = g_strdup_printf("/apps/gnomeradio/presets/%d/freqency", i);
 
160
                freq = gconf_client_get_float(client, buffer, NULL); 
 
161
                if ((freq < FREQ_MIN) || (freq > FREQ_MAX))
 
162
                        ps->freq = FREQ_MIN;
 
163
                else
 
164
                        ps->freq = freq;
 
165
                g_free(buffer);
 
166
                settings.presets = g_list_append(settings.presets, (gpointer)ps);       
 
167
        }       
 
168
        mom_ps = gconf_client_get_int(client, "/apps/gnomeradio/presets/last", NULL);
 
169
        if (mom_ps >= count)
 
170
                mom_ps = -1;
 
171
 
 
172
        return TRUE;
 
173
}                       
 
174
        
 
175
gint backup_settings(void)
 
176
{
 
177
        preset *ps, *tmp;
 
178
        gint i;
 
179
        
 
180
        //g_print("Making a backup of settings\n");
 
181
                
 
182
        tmp_settings.device = g_strdup(settings.device);
 
183
        tmp_settings.mixer = g_strdup(settings.mixer);
 
184
        tmp_settings.mute_on_exit = settings.mute_on_exit;
 
185
        tmp_settings.presets = NULL;
 
186
        for (i=0;i<g_list_length(settings.presets);i++)
 
187
        {
 
188
                ps = malloc(sizeof(preset));
 
189
                tmp = g_list_nth_data(settings.presets, i);
 
190
                strcpy(ps->name, tmp->name);
 
191
                ps->freq = tmp->freq;
 
192
                tmp_settings.presets = g_list_append(tmp_settings.presets, (gpointer) ps);
 
193
        }
 
194
        return 1;
 
195
}
 
196
 
 
197
gint commit_settings(gpointer app)
 
198
{
 
199
        preset  *tmp;
 
200
        gint i;
 
201
        gchar* ptr;
 
202
        
 
203
        //g_print("Committing Settings\n");
 
204
        
 
205
        ptr = settings.device;
 
206
        settings.device = tmp_settings.device;
 
207
        if (strcmp(ptr, tmp_settings.device))
 
208
                start_radio(TRUE, app);
 
209
        g_free(ptr);
 
210
        tmp_settings.device = NULL;
 
211
        ptr = settings.mixer;
 
212
        settings.mixer = tmp_settings.mixer;
 
213
        if (strcmp(ptr, tmp_settings.mixer))
 
214
                start_mixer(TRUE, app);
 
215
        g_free(ptr);
 
216
        tmp_settings.mixer = NULL;
 
217
        settings.mute_on_exit = tmp_settings.mute_on_exit;
 
218
        for (i=0;i<g_list_length(settings.presets);i++)
 
219
        {
 
220
                tmp = g_list_nth_data(settings.presets, i);
 
221
                g_free(tmp);
 
222
        }
 
223
        g_list_free(settings.presets);
 
224
        settings.presets = tmp_settings.presets;
 
225
        tmp_settings.presets = NULL;
 
226
        
 
227
        selected_row = -1;      
 
228
        return 1;
 
229
}
 
230
 
 
231
gint rollback_settings(void)
 
232
{
 
233
        preset *tmp;
 
234
        gint i;
 
235
        
 
236
        //g_print("Undo Changes\n");
 
237
        
 
238
        g_free(tmp_settings.device);
 
239
        g_free(tmp_settings.mixer);
 
240
        for (i=0;i<g_list_length(tmp_settings.presets);i++)
 
241
        {
 
242
                tmp = g_list_nth_data(tmp_settings.presets, i);
 
243
                g_free(tmp);
 
244
        }
 
245
        g_list_free(tmp_settings.presets);
 
246
        tmp_settings.presets = NULL;
 
247
        
 
248
        selected_row = -1;      
 
249
        return 1;
 
250
}
 
251
        
 
252
static void mute_on_exit_toggled_cb(GtkWidget* widget, gpointer data)
 
253
{
 
254
        tmp_settings.mute_on_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mute_on_exit_cb));
 
255
}       
 
256
 
 
257
static gboolean device_entry_focus_out_event_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
 
258
{
 
259
        if (tmp_settings.device)
 
260
                g_free(tmp_settings.device);
 
261
        tmp_settings.device = g_strdup(gtk_entry_get_text(GTK_ENTRY(device_entry)));
 
262
        return FALSE;
 
263
}
 
264
 
 
265
static gboolean mixer_entry_focus_out_event_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
 
266
{
 
267
        char *tmp;
 
268
        if (tmp_settings.mixer)
 
269
                g_free(tmp_settings.mixer);
 
270
        tmp_settings.mixer = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(mixer_combo)->entry)));
 
271
        
 
272
        if ((tmp = strstr(tmp_settings.mixer, " (")))
 
273
                tmp[0] = '\0';
 
274
        
 
275
        return FALSE;
 
276
}
 
277
 
 
278
static void add_button_clicked_cb(GtkWidget *widget, gpointer data)
 
279
{
 
280
        preset *ps;
 
281
        GtkTreeIter iter = {0};
 
282
        char *text, *buffer;
 
283
        GtkAdjustment *v_scb;
 
284
        
 
285
        text = (char*)gtk_entry_get_text(GTK_ENTRY(name_entry));
 
286
        if (strlen(text)<1)
 
287
        {
 
288
                g_print("\a");
 
289
                return;
 
290
        }
 
291
        
 
292
        ps = malloc(sizeof(preset));
 
293
        strcpy(ps->name, text);
 
294
        ps->freq = spin->value;
 
295
        tmp_settings.presets = g_list_append(tmp_settings.presets, (gpointer) ps);
 
296
        buffer = g_strdup_printf("%.2f", spin->value);
 
297
 
 
298
        gtk_list_store_append(list_store, &iter);
 
299
        gtk_list_store_set(list_store, &iter, 0, text, 1, buffer, -1);
 
300
 
 
301
        gtk_entry_set_text(GTK_ENTRY(name_entry), "");
 
302
        
 
303
        g_free(buffer);
 
304
        gtk_tree_selection_unselect_all(selection);
 
305
        
 
306
        v_scb = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(list_view));
 
307
        gtk_adjustment_set_value(v_scb, v_scb->upper);
 
308
}
 
309
 
 
310
 
 
311
static void del_button_clicked_cb(GtkWidget *widget, gpointer data)
 
312
{
 
313
        GtkTreePath *path = NULL;
 
314
        GtkTreeViewColumn *focus_column = NULL;
 
315
        GtkTreeIter iter;
 
316
        preset *ps;
 
317
        int *row;
 
318
        
 
319
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
 
320
        
 
321
        if (!path)
 
322
        {
 
323
                g_print("\aNo row selected\n");
 
324
                return;
 
325
        }
 
326
        
 
327
        row = gtk_tree_path_get_indices(path);
 
328
        g_assert(row);
 
329
        g_assert(*row < g_list_length(tmp_settings.presets));
 
330
 
 
331
        //g_print("path: %s row %d\n", gtk_tree_path_to_string(path), *row);
 
332
        ps = g_list_nth_data(tmp_settings.presets, *row);
 
333
        g_assert(ps);   
 
334
        tmp_settings.presets = g_list_remove(tmp_settings.presets, (gpointer)ps);
 
335
        g_free(ps);
 
336
        
 
337
        gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
 
338
        gtk_list_store_remove(list_store, &iter);
 
339
        
 
340
        if (!gtk_tree_path_prev(path))
 
341
                return;
 
342
        gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view), path, NULL, FALSE);
 
343
                
 
344
}
 
345
 
 
346
static void update_button_clicked_cb(GtkWidget *widget, gpointer data)
 
347
{
 
348
        GtkTreePath *path = NULL;
 
349
        GtkTreeViewColumn *focus_column = NULL;
 
350
        GtkTreeIter iter;
 
351
        preset *ps;
 
352
        int *row;
 
353
        char *text, *buffer;
 
354
        
 
355
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
 
356
        
 
357
        if (!path)
 
358
        {
 
359
                g_print("\aNo row selected\n");
 
360
                return;
 
361
        }
 
362
        
 
363
        row = gtk_tree_path_get_indices(path);
 
364
        g_assert(row);
 
365
        g_assert(*row < g_list_length(tmp_settings.presets));
 
366
 
 
367
        text = (char*)gtk_entry_get_text(GTK_ENTRY(name_entry));
 
368
        if (strlen(text)<1)
 
369
        {
 
370
                g_print("\a");
 
371
                return;
 
372
        }
 
373
        ps = g_list_nth_data(tmp_settings.presets, *row);
 
374
        g_assert(ps);   
 
375
 
 
376
        strcpy(ps->name, text);
 
377
        ps->freq = spin->value;
 
378
        buffer = g_strdup_printf("%.2f", spin->value);
 
379
        
 
380
        gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
 
381
        gtk_list_store_set(list_store, &iter, 0, text, 1, buffer, -1);
 
382
 
 
383
        g_free(buffer);
 
384
}
 
385
 
 
386
static gboolean list_view_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
387
{
 
388
        if (event->keyval == GDK_Delete)
 
389
                del_button_clicked_cb(widget, user_data);
 
390
        
 
391
        return FALSE;
 
392
}               
 
393
 
 
394
#if 0
 
395
static void freq_spin_activate_cb(void)
 
396
{
 
397
        GtkTreePath *path = NULL;
 
398
        GtkTreeViewColumn *focus_column = NULL;
 
399
        
 
400
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
 
401
        
 
402
        if (!path)
 
403
                add_button_clicked_cb(NULL, NULL);
 
404
        else
 
405
                update_button_clicked_cb(NULL, NULL);
 
406
}       
 
407
 
 
408
static gboolean enter_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
409
{
 
410
        //g_print("keyval = %d\n", event->keyval);
 
411
        if (event->keyval == GDK_Return)
 
412
                freq_spin_activate_cb();
 
413
 
 
414
        return FALSE;
 
415
}               
 
416
#endif
 
417
 
 
418
/*static gboolean
 
419
list_view_select_cb(GtkTreeSelection *selection, GtkTreeModel *model, 
 
420
                                GtkTreePath *path, gboolean path_currently_selected, gpointer data)
 
421
{
 
422
        gchar* text;
 
423
        preset *ps;
 
424
        int *row;
 
425
        
 
426
        row = gtk_tree_path_get_indices(path);
 
427
        g_assert(row);
 
428
        g_assert(*row < g_list_length(tmp_settings.presets));
 
429
        g_print("row: %d %d\n", *row, path_currently_selected);
 
430
        if (!path_currently_selected)
 
431
        {
 
432
                return TRUE;
 
433
        }
 
434
        ps = (preset*)g_list_nth_data(tmp_settings.presets, *row);
 
435
        text = ps->name;
 
436
        gtk_entry_set_text(GTK_ENTRY(name_entry), text);
 
437
        gtk_adjustment_set_value(spin, ps->freq);
 
438
        return TRUE;
 
439
}*/
 
440
 
 
441
static void
 
442
list_view_cursor_changed_cb(GtkWidget *widget, gpointer data)
 
443
{
 
444
        gchar* text;
 
445
        preset *ps;
 
446
        int *row;
 
447
        GtkTreePath *path = NULL;
 
448
        GtkTreeViewColumn *focus_column = NULL;
 
449
        
 
450
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(list_view), &path, &focus_column);
 
451
        
 
452
        if (!path)
 
453
        {
 
454
                return;
 
455
        }
 
456
 
 
457
        row = gtk_tree_path_get_indices(path);
 
458
        g_assert(row);
 
459
        g_assert(*row < g_list_length(tmp_settings.presets));
 
460
 
 
461
        ps = (preset*)g_list_nth_data(tmp_settings.presets, *row);
 
462
        text = ps->name;
 
463
        gtk_entry_set_text(GTK_ENTRY(name_entry), text);
 
464
        gtk_adjustment_set_value(spin, ps->freq);
 
465
        return;
 
466
}
 
467
 
 
468
/*
 
469
static void clist_select_row_cb(GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer user_data)
 
470
{
 
471
        gchar* text;
 
472
        preset *ps;
 
473
 
 
474
        g_assert(row < g_list_length(tmp_settings.presets));
 
475
 
 
476
        selected_row = row;
 
477
        ps = (preset*)g_list_nth_data(tmp_settings.presets, row);
 
478
        text = ps->name;
 
479
        gtk_entry_set_text(GTK_ENTRY(name_entry), text);
 
480
        //freq_entry_set_value(ps->freq);
 
481
        //freq_entry_activate_cb(NULL, NULL);   
 
482
        gtk_adjustment_set_value(spin, ps->freq);
 
483
}       
 
484
 
 
485
static void clist_unselect_row_cb(GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer user_data)
 
486
{
 
487
        selected_row = -1;
 
488
}*/     
 
489
 
 
490
static void spin_value_changed_cb(GtkWidget *widget, gpointer data)
 
491
{
 
492
        double value;
 
493
 
 
494
        value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(freq_spin));
 
495
        gtk_adjustment_set_value(adj, value*STEPS);
 
496
        mom_ps = -1;
 
497
        preset_menu_set_item(mom_ps);
 
498
}
 
499
 
 
500
GtkWidget* prefs_window(void)
 
501
{
 
502
        GtkWidget *dialog;
 
503
        GtkWidget *frame1, *frame2;
 
504
        GtkWidget *misc_box, *preset_box, *hbox;
 
505
        GtkWidget *device_label, *device_box;
 
506
        GtkWidget *mixer_label, *mixer_box;
 
507
        GtkWidget *name_label, *freq_label;
 
508
        GtkWidget *button_box, *entry_box, *freq_box;
 
509
        GtkWidget *add_button, *del_button, *update_button;
 
510
        GtkWidget *add_pixmap, *del_pixmap, *update_pixmap;
 
511
        GtkWidget *scrolled_window;
 
512
        GtkWidget *separator;
 
513
        GtkCellRenderer *cellrenderer;
 
514
        GtkTreeViewColumn *list_column;
 
515
        GList *mixer_devs;
 
516
        gint i;
 
517
        preset* ps;
 
518
        
 
519
        dialog = gtk_dialog_new_with_buttons(_("Gnomeradio Settings"), NULL, 
 
520
                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
 
521
                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
 
522
                        GTK_STOCK_OK, GTK_RESPONSE_OK, 
 
523
                        GTK_STOCK_HELP, GTK_RESPONSE_HELP,
 
524
                        NULL);
 
525
        
 
526
        frame1 = gtk_frame_new(_("Misc Settings"));
 
527
        frame2 = gtk_frame_new(_("Presets"));
 
528
        gtk_container_set_border_width(GTK_CONTAINER(frame1), 5);
 
529
        gtk_container_set_border_width(GTK_CONTAINER(frame2), 5);
 
530
 
 
531
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame1, TRUE, TRUE, 0);
 
532
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame2, TRUE, TRUE, 0);
 
533
 
 
534
        misc_box = gtk_vbox_new(FALSE, 6);
 
535
        gtk_container_set_border_width(GTK_CONTAINER(misc_box), 8);
 
536
        gtk_container_add(GTK_CONTAINER(frame1), misc_box);
 
537
        
 
538
        device_box = gtk_hbox_new(FALSE, 10);
 
539
        device_label = gtk_label_new(_("Radio Device:"));
 
540
        gtk_misc_set_alignment(GTK_MISC(device_label), 0.0f, 0.5f);
 
541
        device_entry = gtk_entry_new();
 
542
        gtk_entry_set_text(GTK_ENTRY(device_entry), tmp_settings.device);
 
543
        gtk_box_pack_start(GTK_BOX(device_box), device_label, TRUE, TRUE, 0);
 
544
        gtk_box_pack_start(GTK_BOX(device_box), device_entry, TRUE, TRUE, 0);
 
545
 
 
546
        mixer_box = gtk_hbox_new(FALSE, 10);
 
547
        mixer_label = gtk_label_new(_("Mixer Source:"));
 
548
        gtk_misc_set_alignment(GTK_MISC(mixer_label), 0.0f, 0.5f);
 
549
        mixer_combo = gtk_combo_new();
 
550
        mixer_devs = get_mixer_recdev_list();
 
551
        if (mixer_devs)
 
552
        {
 
553
                gtk_combo_set_popdown_strings(GTK_COMBO(mixer_combo), mixer_devs);
 
554
                g_list_foreach(mixer_devs, (GFunc)g_free, NULL);
 
555
                g_list_free(mixer_devs);
 
556
        }
 
557
        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(mixer_combo)->entry), tmp_settings.mixer);
 
558
        gtk_box_pack_start(GTK_BOX(mixer_box), mixer_label, TRUE, TRUE, 0);
 
559
        gtk_box_pack_start(GTK_BOX(mixer_box), mixer_combo, TRUE, TRUE, 0);
 
560
 
 
561
        mute_on_exit_cb = gtk_check_button_new_with_label(_("Mute on exit?"));
 
562
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_on_exit_cb), tmp_settings.mute_on_exit);
 
563
 
 
564
        gtk_box_pack_start(GTK_BOX(misc_box), device_box, FALSE, FALSE, 2);
 
565
        gtk_box_pack_start(GTK_BOX(misc_box), mixer_box, FALSE, FALSE, 2);
 
566
        gtk_box_pack_start(GTK_BOX(misc_box), mute_on_exit_cb, FALSE, FALSE, 2);
 
567
 
 
568
        preset_box = gtk_vbox_new(FALSE, 4);
 
569
        hbox = gtk_hbox_new(FALSE, 4);
 
570
        gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
 
571
        gtk_container_add(GTK_CONTAINER(frame2), hbox);
 
572
 
 
573
        /*scrolled_window = gtk_scrolled_window_new(NULL, NULL);
 
574
        clist = gtk_clist_new(2);
 
575
        gtk_container_add(GTK_CONTAINER(scrolled_window), clist);
 
576
        gtk_widget_set_usize(clist, 50, 80);
 
577
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
578
        gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_SINGLE);
 
579
        gtk_clist_set_column_width(GTK_CLIST(clist), 0, 120);
 
580
        //gtk_clist_set_column_width(GTK_CLIST(clist), 1, 40);*/
 
581
 
 
582
        scrolled_window = gtk_scrolled_window_new(NULL, NULL);
 
583
        list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
 
584
        list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store));
 
585
        gtk_container_add(GTK_CONTAINER(scrolled_window), list_view);
 
586
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
 
587
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
588
        //gtk_widget_set_usize(list_view, 130, 100);
 
589
        gtk_widget_set_size_request(list_view, 130, 100);
 
590
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list_view), FALSE);
 
591
        
 
592
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
 
593
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
 
594
        /*gtk_tree_selection_select_path(selection, gtk_tree_path_new_from_string("0"));
 
595
        gtk_tree_selection_set_select_function(selection, (GtkTreeSelectionFunc)list_view_select_cb, NULL, NULL);*/
 
596
        
 
597
        cellrenderer = gtk_cell_renderer_text_new();
 
598
        list_column = gtk_tree_view_column_new_with_attributes(NULL, cellrenderer, "text", 0, NULL);
 
599
        gtk_tree_view_column_set_min_width(list_column, 130);
 
600
        gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), list_column);
 
601
        cellrenderer = gtk_cell_renderer_text_new();
 
602
        list_column = gtk_tree_view_column_new_with_attributes(NULL, cellrenderer, "text", 1, NULL);
 
603
        //gtk_tree_view_column_set_min_width(list_column, 30);
 
604
        gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), list_column);
 
605
 
 
606
        entry_box = gtk_hbox_new(FALSE, 10);
 
607
        button_box = gtk_vbox_new(TRUE, 3);
 
608
 
 
609
        name_label = gtk_label_new(_("Name:")); 
 
610
        gtk_misc_set_alignment(GTK_MISC(name_label), 0.0f, 0.5f);
 
611
        name_entry = gtk_entry_new();
 
612
        gtk_entry_set_max_length(GTK_ENTRY(name_entry), 20);
 
613
        //gtk_entry_set_text(GTK_ENTRY(name_entry), UN_NAMED);
 
614
        gtk_editable_set_editable(GTK_EDITABLE(name_entry), TRUE);
 
615
        
 
616
        gtk_box_pack_start(GTK_BOX(entry_box), name_label, TRUE, TRUE, 0);
 
617
        gtk_box_pack_start(GTK_BOX(entry_box), name_entry, TRUE, TRUE, 0);
 
618
 
 
619
        add_pixmap = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
 
620
        del_pixmap = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON);
 
621
        update_pixmap = gtk_image_new_from_stock(GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
 
622
        
 
623
        add_button = gtk_button_new();
 
624
        del_button = gtk_button_new();
 
625
        update_button = gtk_button_new();
 
626
 
 
627
        /*add_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
 
628
        del_button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
 
629
        update_button = gtk_button_new_from_stock(GTK_STOCK_REFRESH);*/
 
630
 
 
631
 
 
632
        separator = gtk_hseparator_new();
 
633
        
 
634
        gtk_container_add(GTK_CONTAINER(add_button), add_pixmap);
 
635
        gtk_container_add(GTK_CONTAINER(del_button), del_pixmap);
 
636
        gtk_container_add(GTK_CONTAINER(update_button), update_pixmap);
 
637
 
 
638
        gtk_box_pack_start(GTK_BOX(button_box), add_button, FALSE, FALSE, 0);
 
639
        gtk_box_pack_start(GTK_BOX(button_box), del_button, FALSE, FALSE, 0);
 
640
        gtk_box_pack_start(GTK_BOX(button_box), update_button, FALSE, FALSE, 0);
 
641
        
 
642
        freq_box = gtk_hbox_new(FALSE, 4);
 
643
        freq_label = gtk_label_new(_("Frequency:"));
 
644
        gtk_misc_set_alignment(GTK_MISC(freq_label), 0.0f, 0.5f);
 
645
        /*freq_entry = gtk_entry_new_with_max_length(6);
 
646
        freq_entry_set_value(adj->value/STEPS);
 
647
        gtk_widget_set_usize(freq_entry, 50, 23);
 
648
        freq_spin = my_spin();*/
 
649
        
 
650
        spin = GTK_ADJUSTMENT(gtk_adjustment_new(adj->value/STEPS, FREQ_MIN, FREQ_MAX, 0.05, 1, 1));
 
651
        freq_spin = gtk_spin_button_new(spin, 0.05, 2);
 
652
        gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(freq_spin), TRUE);
 
653
        gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(freq_spin), TRUE);
 
654
        //gtk_widget_set_usize(fgtk_spin_button_get_snap_to_ticksreq_spin, 120, 23);
 
655
        
 
656
        gtk_box_pack_start(GTK_BOX(freq_box), freq_label, TRUE, TRUE, 0);
 
657
        //gtk_box_pack_start(GTK_BOX(freq_box), freq_entry, TRUE, TRUE, 0);
 
658
        gtk_box_pack_start(GTK_BOX(freq_box), freq_spin, TRUE, TRUE, 0);
 
659
 
 
660
        gtk_box_pack_start(GTK_BOX(preset_box), scrolled_window, TRUE, TRUE, 2);
 
661
        gtk_box_pack_start(GTK_BOX(preset_box), separator, TRUE, TRUE, 0);
 
662
        gtk_box_pack_start(GTK_BOX(preset_box), entry_box, TRUE, TRUE, 2);
 
663
        gtk_box_pack_start(GTK_BOX(preset_box), freq_box, TRUE, TRUE, 2);
 
664
        //gtk_box_pack_start(GTK_BOX(preset_box), button_box, TRUE, TRUE, 2);
 
665
 
 
666
        gtk_box_pack_start(GTK_BOX(hbox), preset_box, TRUE, TRUE, 2);
 
667
        gtk_box_pack_start(GTK_BOX(hbox), button_box, TRUE, FALSE, 10);
 
668
 
 
669
        //g_signal_connect(GTK_OBJECT(freq_spin), "button-press-event", GTK_SIGNAL_FUNC(freq_spin_button_press_event_cb), NULL);
 
670
        g_signal_connect(GTK_OBJECT(device_entry), "focus-out-event", GTK_SIGNAL_FUNC(device_entry_focus_out_event_cb), NULL);
 
671
        g_signal_connect(GTK_OBJECT(GTK_COMBO(mixer_combo)->entry), "focus-out-event", GTK_SIGNAL_FUNC(mixer_entry_focus_out_event_cb), NULL);
 
672
        g_signal_connect(GTK_OBJECT(mute_on_exit_cb), "toggled", GTK_SIGNAL_FUNC(mute_on_exit_toggled_cb), NULL);
 
673
        g_signal_connect(GTK_OBJECT(add_button), "clicked", GTK_SIGNAL_FUNC(add_button_clicked_cb), NULL);
 
674
        g_signal_connect(GTK_OBJECT(del_button), "clicked", GTK_SIGNAL_FUNC(del_button_clicked_cb), NULL);
 
675
        g_signal_connect(GTK_OBJECT(update_button), "clicked", GTK_SIGNAL_FUNC(update_button_clicked_cb), NULL);
 
676
        //g_signal_connect(GTK_OBJECT(clist), "select-row", GTK_SIGNAL_FUNC(clist_select_row_cb), NULL);
 
677
        //g_signal_connect(GTK_OBJECT(clist), "unselect-row", GTK_SIGNAL_FUNC(clist_unselect_row_cb), NULL);
 
678
        g_signal_connect(GTK_OBJECT(list_view), "key-press-event", GTK_SIGNAL_FUNC(list_view_key_press_event_cb), NULL);
 
679
        /* FIXME: Does not really work :-( */
 
680
        /*g_signal_connect_after(GTK_OBJECT(freq_spin), "activate", GTK_SIGNAL_FUNC(freq_spin_activate_cb), NULL);
 
681
        g_signal_connect(GTK_OBJECT(name_entry), "key-press-event", GTK_SIGNAL_FUNC(enter_key_press_event_cb), NULL);*/
 
682
        g_signal_connect(GTK_OBJECT(spin), "value-changed", GTK_SIGNAL_FUNC(spin_value_changed_cb), NULL);
 
683
        g_signal_connect(GTK_OBJECT(list_view), "cursor-changed", GTK_SIGNAL_FUNC(list_view_cursor_changed_cb), NULL);
 
684
 
 
685
 
 
686
        for (i=0;i<g_list_length(tmp_settings.presets);i++)
 
687
        {
 
688
                GtkTreeIter iter = {0};
 
689
                char *buffer;
 
690
                ps = g_list_nth_data(tmp_settings.presets, i);
 
691
                buffer = g_strdup_printf("%0.2f", ps->freq);
 
692
                gtk_list_store_append(list_store, &iter);
 
693
                gtk_list_store_set(list_store, &iter, 0, ps->name, 1, buffer, -1);
 
694
                g_free(buffer);
 
695
        }
 
696
 
 
697
        gtk_tooltips_set_tip(tooltips, device_entry, _("Specify the radio-device (in most cases /dev/radio)"), NULL);
 
698
        gtk_tooltips_set_tip(tooltips, GTK_COMBO(mixer_combo)->entry, 
 
699
        _("Choose the mixer source (line, line1, etc.) that is able to control the volume of your radio"), NULL);
 
700
        gtk_tooltips_set_tip(tooltips, mute_on_exit_cb, _("If unchecked, gnomeradio won't mute after exiting"), NULL);
 
701
        gtk_tooltips_set_tip(tooltips, add_button, _("Add a new preset"), NULL);
 
702
        gtk_tooltips_set_tip(tooltips, del_button, _("Remove preset from List"), NULL);
 
703
        gtk_tooltips_set_tip(tooltips, update_button, _("Update the preset in the List"), NULL);
 
704
 
 
705
        gtk_widget_show_all(dialog);
 
706
 
 
707
        return dialog;
 
708
}       
 
709