View | Details | Raw Unified | Return to bug 29
Collapse All | Expand All

(-)src/callbacks.c (-2 / +10 lines)
Lines 187-193 Link Here
187
    trim_whitespace(text);
187
    trim_whitespace(text);
188
    
188
    
189
    if(text[0] == '\0')
189
    if(text[0] == '\0')
190
        gtk_entry_set_text(GTK_ENTRY(widget), "Unknown");
190
        gtk_entry_set_text(GTK_ENTRY(widget), EMPTY_GENRE_SHOWN);
191
    else
191
    else
192
        gtk_entry_set_text(GTK_ENTRY(widget), text);
192
        gtk_entry_set_text(GTK_ENTRY(widget), text);
193
    
193
    
Lines 410-418 Link Here
410
        if (!prefs_are_valid())
410
        if (!prefs_are_valid())
411
            return;
411
            return;
412
        
412
        
413
        get_prefs_from_widgets(global_prefs);
413
        // ensure that global_prefs always points to a valid struct
414
        // - a thread safe solution needs a gmutex to protect each access of global_prefs,
415
        //   but this is a lot of work to implement, so for now this may suffice ...
416
        prefs * old_prefs = global_prefs;
417
        global_prefs = get_prefs_from_widgets(); // points to new struct
418
414
        save_prefs(global_prefs);
419
        save_prefs(global_prefs);
415
        toggle_allow_tracknum();
420
        toggle_allow_tracknum();
421
        upload_toggle_enable();
422
423
        delete_prefs(old_prefs); // can safely removed now
416
    }
424
    }
417
    
425
    
418
    gtk_widget_destroy(GTK_WIDGET(dialog));    
426
    gtk_widget_destroy(GTK_WIDGET(dialog));    
(-)src/interface.c (-48 / +14 lines)
Lines 272-307 Link Here
272
272
273
273
274
    /* the CDDB Upload button */
274
    /* the CDDB Upload button */
275
    GtkWidget* hbox_ub1 = gtk_hbox_new(FALSE, 5);
275
    GtkWidget* hbox_ub1 = get_cddb_upload_button_widget(main_win);
276
    gtk_box_pack_start(GTK_BOX (hbox_buttons), hbox_ub1, FALSE, TRUE, 5);
276
    gtk_box_pack_start(GTK_BOX (hbox_buttons), hbox_ub1, FALSE, TRUE, 5);
277
    gtk_widget_show(hbox_ub1);
278
277
279
    GtkWidget* statusLbl_ub = gtk_label_new("");
280
    gtk_label_set_use_markup(GTK_LABEL(statusLbl_ub), TRUE);
281
    gtk_misc_set_alignment(GTK_MISC(statusLbl_ub), 0.5, 0);
282
    gtk_box_pack_start(GTK_BOX (hbox_ub1), statusLbl_ub, TRUE, TRUE, 0);
283
    gtk_widget_show(statusLbl_ub);
284
285
    GtkWidget* fillerBox_ub = gtk_hbox_new(FALSE, 0);
286
    gtk_box_pack_start(GTK_BOX (hbox_ub1), fillerBox_ub, TRUE, TRUE, 0);
287
    gtk_widget_show(hbox_ub1);
288
289
    GtkWidget* upload_button = gtk_button_new ();
290
    gtk_widget_show(upload_button);
291
    gtk_box_pack_start(GTK_BOX (hbox_ub1), upload_button, FALSE, FALSE, 5);
292
293
    GtkWidget* alignment_ub = gtk_alignment_new (0.5, 0.5, 0, 0);
294
    gtk_widget_show (alignment_ub);
295
    gtk_container_add (GTK_CONTAINER (upload_button), alignment_ub);
296
297
    GtkWidget* hbox_ub2 = gtk_hbox_new (FALSE, 2);
298
    gtk_widget_show (hbox_ub2);
299
    gtk_container_add (GTK_CONTAINER (alignment_ub), hbox_ub2);
300
301
    GtkWidget* label_ub = gtk_label_new_with_mnemonic (_("Upload to CDDB"));
302
    gtk_widget_show (label_ub);
303
    gtk_box_pack_start (GTK_BOX (hbox_ub2), label_ub, FALSE, FALSE, 0);
304
305
    /* a fill field */
278
    /* a fill field */
306
    GtkWidget* button_fill = gtk_hbox_new(FALSE, 0);
279
    GtkWidget* button_fill = gtk_hbox_new(FALSE, 0);
307
    gtk_box_pack_start(GTK_BOX (hbox_buttons), button_fill, TRUE, TRUE, 0);
280
    gtk_box_pack_start(GTK_BOX (hbox_buttons), button_fill, TRUE, TRUE, 0);
Lines 375-383 Link Here
375
    g_signal_connect ((gpointer) single_artist, "toggled",
348
    g_signal_connect ((gpointer) single_artist, "toggled",
376
                                        G_CALLBACK (on_single_artist_toggled),
349
                                        G_CALLBACK (on_single_artist_toggled),
377
                                        NULL);
350
                                        NULL);
378
    g_signal_connect ((gpointer) upload_button, "clicked",
379
                                        G_CALLBACK (on_upload_button_clicked),
380
                                        NULL);
381
    g_signal_connect ((gpointer) rip_button, "clicked",
351
    g_signal_connect ((gpointer) rip_button, "clicked",
382
                                        G_CALLBACK (on_rip_button_clicked),
352
                                        G_CALLBACK (on_rip_button_clicked),
383
                                        NULL);
353
                                        NULL);
Lines 441-447 Link Here
441
    GLADE_HOOKUP_OBJECT (main_win, scrolledwindow1, "scrolledwindow1");
411
    GLADE_HOOKUP_OBJECT (main_win, scrolledwindow1, "scrolledwindow1");
442
    GLADE_HOOKUP_OBJECT (main_win, tracklist, "tracklist");
412
    GLADE_HOOKUP_OBJECT (main_win, tracklist, "tracklist");
443
    GLADE_HOOKUP_OBJECT (main_win, rip_button, "rip_button");
413
    GLADE_HOOKUP_OBJECT (main_win, rip_button, "rip_button");
444
    GLADE_HOOKUP_OBJECT (main_win, upload_button, UPLOAD_BUTTON);
445
    GLADE_HOOKUP_OBJECT (main_win, alignment3, "alignment3");
414
    GLADE_HOOKUP_OBJECT (main_win, alignment3, "alignment3");
446
    GLADE_HOOKUP_OBJECT (main_win, hbox4, "hbox4");
415
    GLADE_HOOKUP_OBJECT (main_win, hbox4, "hbox4");
447
    GLADE_HOOKUP_OBJECT (main_win, image1, "image1");
416
    GLADE_HOOKUP_OBJECT (main_win, image1, "image1");
Lines 1165-1171 Link Here
1165
    GtkWidget* hbox;
1134
    GtkWidget* hbox;
1166
    GtkWidget* cddbServerName;
1135
    GtkWidget* cddbServerName;
1167
    GtkWidget* cddbPortNum;
1136
    GtkWidget* cddbPortNum;
1168
    GtkWidget* cddbEmailAddress;
1169
    GtkWidget* useProxy;
1137
    GtkWidget* useProxy;
1170
    GtkWidget* serverName;
1138
    GtkWidget* serverName;
1171
    GtkWidget* portNum;
1139
    GtkWidget* portNum;
Lines 1229-1252 Link Here
1229
    tooltips = gtk_tooltips_new ();
1197
    tooltips = gtk_tooltips_new ();
1230
    gtk_tooltips_set_tip (tooltips, cddbPortNum, _("The CDDB server port (default is 8880)"), NULL);
1198
    gtk_tooltips_set_tip (tooltips, cddbPortNum, _("The CDDB server port (default is 8880)"), NULL);
1231
    
1199
    
1200
    /* enable CDDB upload: */
1201
    GtkWidget* enable_cddb_upload = get_enable_cddb_upload_togglebutton(prefs);
1202
    gtk_box_pack_start (GTK_BOX (frameVbox), enable_cddb_upload, FALSE, FALSE, 0);
1203
1232
    /* CDDB email address: */
1204
    /* CDDB email address: */
1233
    hbox = gtk_hbox_new (FALSE, 0);
1205
    hbox = get_cddb_email_address_widget(prefs);
1234
    gtk_widget_show (hbox);
1235
    gtk_box_pack_start (GTK_BOX (frameVbox), hbox, FALSE, FALSE, 1);
1206
    gtk_box_pack_start (GTK_BOX (frameVbox), hbox, FALSE, FALSE, 1);
1236
1207
1237
    label = gtk_label_new (_("E-Mail: "));
1238
    gtk_widget_show (label);
1239
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 5);
1240
1241
    cddbEmailAddress = gtk_entry_new ();
1242
    gtk_widget_show (cddbEmailAddress);
1243
    gtk_box_pack_start (GTK_BOX (hbox), cddbEmailAddress, TRUE, TRUE, 5);
1244
    GLADE_HOOKUP_OBJECT (prefs, cddbEmailAddress, "cddb_email_address");
1245
1246
    tooltips = gtk_tooltips_new ();
1247
    gtk_tooltips_set_tip (tooltips, cddbEmailAddress, _("Enter a valid email if you want to update disc info into gnudb"), NULL);
1248
1249
1250
    frame = gtk_frame_new (NULL);
1208
    frame = gtk_frame_new (NULL);
1251
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
1209
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
1252
    gtk_widget_show (frame);
1210
    gtk_widget_show (frame);
Lines 1488-1494 Link Here
1488
    gtk_widget_set_sensitive(lookup_widget(win_main, "title_label"), FALSE);
1446
    gtk_widget_set_sensitive(lookup_widget(win_main, "title_label"), FALSE);
1489
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_title"), FALSE);
1447
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_title"), FALSE);
1490
    gtk_widget_set_sensitive(lookup_widget(win_main, SINGLE_ARTIST_BUTTON), FALSE);
1448
    gtk_widget_set_sensitive(lookup_widget(win_main, SINGLE_ARTIST_BUTTON), FALSE);
1449
    gtk_widget_set_sensitive(lookup_widget(win_main, ALBUM_CATEGORY_COMBO_BOX), FALSE);
1491
    gtk_widget_set_sensitive(glb_tracklist, FALSE);
1450
    gtk_widget_set_sensitive(glb_tracklist, FALSE);
1451
    gtk_widget_set_sensitive(glb_upload_button, FALSE);
1492
    gtk_widget_set_sensitive(lookup_widget(win_main, "rip_button"), FALSE);
1452
    gtk_widget_set_sensitive(lookup_widget(win_main, "rip_button"), FALSE);
1493
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_genre"), FALSE);	// lnr
1453
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_genre"), FALSE);	// lnr
1494
    gtk_widget_set_sensitive(lookup_widget(win_main, "genre_label"), FALSE);	// lnr
1454
    gtk_widget_set_sensitive(lookup_widget(win_main, "genre_label"), FALSE);	// lnr
Lines 1511-1516 Link Here
1511
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_genre"), TRUE);		// lnr
1471
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_genre"), TRUE);		// lnr
1512
    gtk_widget_set_sensitive(lookup_widget(win_main, "genre_label"), TRUE);		// lnr
1472
    gtk_widget_set_sensitive(lookup_widget(win_main, "genre_label"), TRUE);		// lnr
1513
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_year"), TRUE);
1473
    gtk_widget_set_sensitive(lookup_widget(win_main, "album_year"), TRUE);
1474
1475
    if (upload_is_enabled())
1476
    {
1477
        gtk_widget_set_sensitive(lookup_widget(win_main, ALBUM_CATEGORY_COMBO_BOX), TRUE);
1478
        gtk_widget_set_sensitive(glb_upload_button, TRUE);
1479
    }
1514
}
1480
}
1515
1481
1516
void disable_mp3_widgets(void)
1482
void disable_mp3_widgets(void)
(-)src/main.c (-8 / +10 lines)
Lines 198-205 Link Here
198
                                                    "text", 1,
198
                                                    "text", 1,
199
                                                    NULL);
199
                                                    NULL);
200
	
200
	
201
    // disable the "rip" button
201
    // disable the category box and the "Upload" and "rip" buttons
202
    // it will be enabled when check_disc() finds a disc in the drive
202
    // they will be enabled when check_disc() finds a disc in the drive
203
    gtk_widget_set_sensitive(lookup_widget(win_main, ALBUM_CATEGORY_COMBO_BOX), FALSE);
204
    gtk_widget_set_sensitive(glb_upload_button, FALSE);
203
    gtk_widget_set_sensitive(lookup_widget(win_main, "rip_button"), FALSE);
205
    gtk_widget_set_sensitive(lookup_widget(win_main, "rip_button"), FALSE);
204
    
206
    
205
    win_ripping = create_ripping();
207
    win_ripping = create_ripping();
Lines 539-545 Link Here
539
GList * lookup_disc(cddb_disc_t * disc)
541
GList * lookup_disc(cddb_disc_t * disc)
540
{
542
{
541
    // set up the connection to the cddb server
543
    // set up the connection to the cddb server
542
    cddb_conn_t * conn = get_cddb_connection(NULL); /* no email required for loookup */
544
    cddb_conn_t * conn = get_cddb_connection(""); /* no email required for loookup */
543
    
545
    
544
    // show cddb update window
546
    // show cddb update window
545
    gdk_threads_enter();
547
    gdk_threads_enter();
Lines 570-576 Link Here
570
    cddb_conn_t * conn = cddb_new();
572
    cddb_conn_t * conn = cddb_new();
571
    if (conn == NULL)
573
    if (conn == NULL)
572
    {
574
    {
573
    	if (useThisEmailAddress)
575
    	if (0 != strlen(useThisEmailAddress))
574
    	{
576
    	{
575
    		// cannot open for cddb Update
577
    		// cannot open for cddb Update
576
    		return NULL; // don't exit on error, since the rip may work
578
    		return NULL; // don't exit on error, since the rip may work
Lines 585-591 Link Here
585
    cddb_set_server_name(conn, global_prefs->cddb_server_name);
587
    cddb_set_server_name(conn, global_prefs->cddb_server_name);
586
    cddb_set_server_port(conn, global_prefs->cddb_port_number);
588
    cddb_set_server_port(conn, global_prefs->cddb_port_number);
587
	cddb_set_client(conn, PROGRAM_NAME, PROGRAM_VERSION);
589
	cddb_set_client(conn, PROGRAM_NAME, PROGRAM_VERSION);
588
    if (useThisEmailAddress)
590
    if (0 != strlen(useThisEmailAddress))
589
    {
591
    {
590
    	cddb_set_email_address(conn, useThisEmailAddress);
592
    	cddb_set_email_address(conn, useThisEmailAddress);
591
    }
593
    }
Lines 704-710 Link Here
704
                        fatalError("cddb_track_new() failed. Out of memory?");
706
                        fatalError("cddb_track_new() failed. Out of memory?");
705
                    
707
                    
706
                    cddb_track_set_frame_offset(track, ntohl(te.entry.addr.lba)+SECONDS_TO_FRAMES(2));
708
                    cddb_track_set_frame_offset(track, ntohl(te.entry.addr.lba)+SECONDS_TO_FRAMES(2));
707
                    snprintf(trackname, 9, "Track %d", i);
709
                    snprintf(trackname, 9, EMPTY_TRACK_SHOWN, i);
708
                    cddb_track_set_title(track, trackname);
710
                    cddb_track_set_title(track, trackname);
709
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
711
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
710
                    cddb_disc_add_track(disc, track);
712
                    cddb_disc_add_track(disc, track);
Lines 760-766 Link Here
760
                        fatalError("cddb_track_new() failed. Out of memory?");
762
                        fatalError("cddb_track_new() failed. Out of memory?");
761
                    
763
                    
762
                    cddb_track_set_frame_offset(track, te.data->addr.lba+SECONDS_TO_FRAMES(2));
764
                    cddb_track_set_frame_offset(track, te.data->addr.lba+SECONDS_TO_FRAMES(2));
763
                    snprintf(trackname, 9, "Track %d", i);
765
                    snprintf(trackname, 9, EMPTY_TRACK_SHOWN, i);
764
                    cddb_track_set_title(track, trackname);
766
                    cddb_track_set_title(track, trackname);
765
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
767
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
766
                    cddb_disc_add_track(disc, track);
768
                    cddb_disc_add_track(disc, track);
Lines 809-815 Link Here
809
                        fatalError("cddb_track_new() failed. Out of memory?");
811
                        fatalError("cddb_track_new() failed. Out of memory?");
810
812
811
                    cddb_track_set_frame_offset(track, te.cdte_addr.lba + SECONDS_TO_FRAMES(2));
813
                    cddb_track_set_frame_offset(track, te.cdte_addr.lba + SECONDS_TO_FRAMES(2));
812
                    snprintf(trackname, 9, "Track %d", i);
814
                    snprintf(trackname, 9, EMPTY_TRACK_SHOWN, i);
813
                    cddb_track_set_title(track, trackname);
815
                    cddb_track_set_title(track, trackname);
814
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
816
                    cddb_track_set_artist(track, EMPTY_ARTIST_SHOWN);
815
                    cddb_disc_add_track(disc, track);
817
                    cddb_disc_add_track(disc, track);
(-)src/main.h (+3 lines)
Lines 78-82 Link Here
78
#define EMPTY_YEAR_SHOWN	1900
78
#define EMPTY_YEAR_SHOWN	1900
79
#define EMPTY_ARTIST_SHOWN	"Unknown Artist"
79
#define EMPTY_ARTIST_SHOWN	"Unknown Artist"
80
#define EMPTY_ALBUM_SHOWN	"Unknown Album"
80
#define EMPTY_ALBUM_SHOWN	"Unknown Album"
81
#define EMPTY_GENRE_SHOWN	"Unknown"
82
#define EMPTY_TRACK_SHOWN   "Track %d"
81
83
84
82
//#define DEBUG
85
//#define DEBUG
(-)src/prefs.c (-3 / +21 lines)
Lines 26-32 Link Here
26
#include "util.h"
26
#include "util.h"
27
#include "support.h"
27
#include "support.h"
28
#include "interface.h"
28
#include "interface.h"
29
#include "upload.h"
29
30
31
30
#define CONFIG_FILENAME "asunder"
32
#define CONFIG_FILENAME "asunder"
31
33
32
prefs * global_prefs = NULL;
34
prefs * global_prefs = NULL;
Lines 176-181 Link Here
176
    p->concatenated_track_separator[0] = '/';
178
    p->concatenated_track_separator[0] = '/';
177
    p->concatenated_track_separator[1] = '\0';
179
    p->concatenated_track_separator[1] = '\0';
178
	
180
	
181
    p->cddb_upload_enabled = 0; // disabled
179
    p->cddb_email_address = heap_copy_of(""); /* fine as long as no one wants to update the cddb */
182
    p->cddb_email_address = heap_copy_of(""); /* fine as long as no one wants to update the cddb */
180
    
183
    
181
    return p;
184
    return p;
Lines 224-230 Link Here
224
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_server_name")), p->cddb_server_name);
227
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_server_name")), p->cddb_server_name);
225
    snprintf(tempStr, 10, "%d", p->cddb_port_number);
228
    snprintf(tempStr, 10, "%d", p->cddb_port_number);
226
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_port_number")), tempStr);
229
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_port_number")), tempStr);
230
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "enable_cddb_upload")), p->cddb_upload_enabled);
227
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_email_address")), p->cddb_email_address);
231
    gtk_entry_set_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_email_address")), p->cddb_email_address);
232
    gtk_widget_set_sensitive(lookup_widget(win_prefs, "cddb_email_address"), p->cddb_upload_enabled);
233
228
    if(global_prefs->more_formats_expanded)
234
    if(global_prefs->more_formats_expanded)
229
        gtk_expander_set_expanded (GTK_EXPANDER(lookup_widget(win_prefs, "more_formats_expander")), TRUE);
235
        gtk_expander_set_expanded (GTK_EXPANDER(lookup_widget(win_prefs, "more_formats_expander")), TRUE);
230
    //~ if(global_prefs->proprietary_formats_expanded)
236
    //~ if(global_prefs->proprietary_formats_expanded)
Lines 257-268 Link Here
257
}
263
}
258
264
259
// populates a prefs struct from the current state of the widgets
265
// populates a prefs struct from the current state of the widgets
260
void get_prefs_from_widgets(prefs * p)
266
prefs * get_prefs_from_widgets()
261
{
267
{
262
    gchar * tocopy = NULL;
268
    gchar * tocopy = NULL;
263
    const gchar * tocopyc = NULL;
269
    const gchar * tocopyc = NULL;
264
270
    prefs * p = get_default_prefs();
265
    clear_prefs(p);
266
    
271
    
267
    p->cdrom = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cdrom"))));
272
    p->cdrom = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cdrom"))));
268
    
273
    
Lines 308-313 Link Here
308
    
313
    
309
    p->cddb_server_name = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_server_name"))));
314
    p->cddb_server_name = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_server_name"))));
310
    p->cddb_port_number = atoi(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_port_number"))));
315
    p->cddb_port_number = atoi(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_port_number"))));
316
    p->cddb_upload_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "enable_cddb_upload")));
311
    p->cddb_email_address = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_email_address"))));
317
    p->cddb_email_address = heap_copy_of(gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_email_address"))));
312
318
313
    p->do_log = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "do_log")));
319
    p->do_log = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "do_log")));
Lines 322-327 Link Here
322
    p->allow_first_track_num_change = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "allow_tracknum")));
328
    p->allow_first_track_num_change = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "allow_tracknum")));
323
    p->first_track_num_offset = atoi(gtk_entry_get_text(GTK_ENTRY (lookup_widget(win_main, "tn_first")))) - 1;
329
    p->first_track_num_offset = atoi(gtk_entry_get_text(GTK_ENTRY (lookup_widget(win_main, "tn_first")))) - 1;
324
    p->track_num_width = gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(win_main, "tn_width"))) + 1;
330
    p->track_num_width = gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(win_main, "tn_width"))) + 1;
331
332
    return p;
325
}
333
}
326
334
327
// get a config file path to load from, using XDG_CONFIG_HOME if available
335
// get a config file path to load from, using XDG_CONFIG_HOME if available
Lines 454-459 Link Here
454
        fprintf(config, "%d\n", p->rip_fdkaac);
462
        fprintf(config, "%d\n", p->rip_fdkaac);
455
        fprintf(config, "%d\n", p->fdkaac_bitrate);
463
        fprintf(config, "%d\n", p->fdkaac_bitrate);
456
        fprintf(config, "%s\n", p->concatenated_track_separator);
464
        fprintf(config, "%s\n", p->concatenated_track_separator);
465
        fprintf(config, "%d\n", p->cddb_upload_enabled);
457
        fprintf(config, "%s\n", (p->cddb_email_address ? p->cddb_email_address : "NotSet"));
466
        fprintf(config, "%s\n", (p->cddb_email_address ? p->cddb_email_address : "NotSet"));
458
        
467
        
459
        fclose(config);
468
        fclose(config);
Lines 674-679 Link Here
674
            p->concatenated_track_separator[0] = aCharPtr[0];
683
            p->concatenated_track_separator[0] = aCharPtr[0];
675
        }
684
        }
676
		
685
		
686
        // this one can be 0
687
        p->cddb_upload_enabled = read_line_num(fd);
688
677
        aCharPtr = read_line(fd);
689
        aCharPtr = read_line(fd);
678
        if (aCharPtr != NULL)
690
        if (aCharPtr != NULL)
679
        {
691
        {
Lines 816-821 Link Here
816
        somethingWrong = true;
828
        somethingWrong = true;
817
    }
829
    }
818
	
830
	
831
    // cddb mail address (only when cddb upload is enabled)
832
    if ( ! upload_email_address_is_valid())
833
    {
834
		somethingWrong = true;
835
    }
836
819
    if(somethingWrong)
837
    if(somethingWrong)
820
        return false;
838
        return false;
821
    else
839
    else
(-)src/prefs.h (-1 / +2 lines)
Lines 49-54 Link Here
49
    int rip_fdkaac;
49
    int rip_fdkaac;
50
    int fdkaac_bitrate;
50
    int fdkaac_bitrate;
51
    char concatenated_track_separator[2];
51
    char concatenated_track_separator[2];
52
    int cddb_upload_enabled;
52
    char* cddb_email_address;
53
    char* cddb_email_address;
53
    
54
    
54
} prefs;
55
} prefs;
Lines 77-83 Link Here
77
// match the given prefs struct
78
// match the given prefs struct
78
void set_widgets_from_prefs(prefs * p);
79
void set_widgets_from_prefs(prefs * p);
79
80
80
void get_prefs_from_widgets(prefs * p);
81
prefs * get_prefs_from_widgets();
81
82
82
// store the given prefs struct to the config file
83
// store the given prefs struct to the config file
83
void save_prefs(prefs * p);
84
void save_prefs(prefs * p);
(-)src/upload.c (-16 / +244 lines)
Lines 24-33 Link Here
24
#include "support.h"
24
#include "support.h"
25
#include "util.h"
25
#include "util.h"
26
26
27
#define HAS_POSIX_REGEX 1
28
#if HAS_POSIX_REGEX
29
#   include <regex.h>
30
#endif
27
31
28
#define TEST_UPLOAD 1	// set to 1 to enable test mode.
32
#define TEST_UPLOAD 1	// set to 1 to enable test mode.
29
33
34
#define GLADE_HOOKUP_OBJECT(component,widget,name) \
35
    g_object_set_data_full (G_OBJECT (component), name, \
36
        gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
30
37
38
#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
39
    g_object_set_data (G_OBJECT (component), name, widget)
40
41
static void on_upload_button_clicked(GtkButton* button, gpointer user_data);
42
static void on_enable_cddb_upload_toggled(GtkToggleButton *togglebutton, gpointer user_data);
31
static int set_disc_from_GUI(cddb_disc_t * disc);
43
static int set_disc_from_GUI(cddb_disc_t * disc);
32
static int is_different(const char* orig, const char* fromGui);
44
static int is_different(const char* orig, const char* fromGui);
33
static GtkWidget* create_upload_check (cddb_disc_t* disc);
45
static GtkWidget* create_upload_check (cddb_disc_t* disc);
Lines 37-48 Link Here
37
static void show_cddb_connection_error(cddb_conn_t * conn, const char* failed_task, const char* possible_cause);
49
static void show_cddb_connection_error(cddb_conn_t * conn, const char* failed_task, const char* possible_cause);
38
static void disable_update_button(void);
50
static void disable_update_button(void);
39
static void enable_update_button(void);
51
static void enable_update_button(void);
52
static bool is_valid_email_address(const char* email_address);
40
53
41
54
42
/*** public functions ***/
55
/*** public functions ***/
43
56
57
GtkWidget * get_cddb_upload_button_widget(GtkWidget *main_win)
58
{
59
    GtkWidget* hbox_ub1 = gtk_hbox_new(FALSE, 5);
60
    gtk_widget_show(hbox_ub1);
61
62
    GtkWidget* upload_button = gtk_button_new ();
63
    if (upload_is_enabled())
64
    {
65
    	gtk_widget_show(upload_button);
66
    }
67
    gtk_box_pack_start(GTK_BOX (hbox_ub1), upload_button, FALSE, FALSE, 5);
68
69
    GtkWidget* alignment_ub = gtk_alignment_new (0.5, 0.5, 0, 0);
70
    gtk_widget_show (alignment_ub);
71
    gtk_container_add (GTK_CONTAINER (upload_button), alignment_ub);
72
73
    GtkWidget* hbox_ub2 = gtk_hbox_new (FALSE, 2);
74
    gtk_widget_show (hbox_ub2);
75
    gtk_container_add (GTK_CONTAINER (alignment_ub), hbox_ub2);
76
77
    GtkWidget* label_ub = gtk_label_new_with_mnemonic (_("Upload to CDDB"));
78
    gtk_widget_show (label_ub);
79
    gtk_box_pack_start (GTK_BOX (hbox_ub2), label_ub, FALSE, FALSE, 0);
80
81
    GLADE_HOOKUP_OBJECT (main_win, upload_button, UPLOAD_BUTTON);
82
    g_signal_connect ((gpointer) upload_button, "clicked", G_CALLBACK (on_upload_button_clicked), NULL);
83
84
    return hbox_ub1;
85
}
86
87
88
GtkWidget * get_enable_cddb_upload_togglebutton(GtkWidget *prefs)
89
{
90
    /* enable CDDB upload: */
91
    GtkWidget* enable_cddb_upload = gtk_check_button_new_with_mnemonic (_("Enable CDDB upload"));
92
    gtk_widget_show (enable_cddb_upload);
93
94
    GLADE_HOOKUP_OBJECT (prefs, enable_cddb_upload, "enable_cddb_upload");
95
    g_signal_connect ((gpointer) enable_cddb_upload, "toggled", G_CALLBACK (on_enable_cddb_upload_toggled), NULL);
96
97
    return enable_cddb_upload;
98
}
99
100
101
GtkWidget * get_cddb_email_address_widget(GtkWidget *prefs)
102
{
103
	GtkWidget * hbox = gtk_hbox_new (FALSE, 0);
104
    gtk_widget_show (hbox);
105
106
    GtkWidget * label = gtk_label_new (_("E-Mail: "));
107
    gtk_widget_show (label);
108
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 5);
109
110
    GtkWidget * cddbEmailAddress = gtk_entry_new ();
111
    gtk_widget_show (cddbEmailAddress);
112
    gtk_box_pack_start (GTK_BOX (hbox), cddbEmailAddress, TRUE, TRUE, 5);
113
    GLADE_HOOKUP_OBJECT (prefs, cddbEmailAddress, "cddb_email_address");
114
115
    GtkTooltips * tooltips = gtk_tooltips_new ();
116
    gtk_tooltips_set_tip (tooltips, cddbEmailAddress, _("Enter a valid email if you want to update disc info into gnudb"), NULL);
117
118
    return hbox;
119
}
120
121
122
int upload_is_enabled()
123
{
124
    if (global_prefs->cddb_upload_enabled && (0 < strlen(global_prefs->cddb_email_address)))
125
    {
126
    	return 1;
127
    }
128
    return 0;
129
}
130
131
void
132
upload_toggle_enable(void)
133
{
134
    if (upload_is_enabled())
135
    {
136
    	gtk_widget_show(glb_upload_button);
137
        gtk_widget_set_sensitive(lookup_widget(win_main, ALBUM_CATEGORY_COMBO_BOX), TRUE);
138
    }
139
    else
140
    {
141
    	gtk_widget_hide(glb_upload_button);
142
        gtk_widget_set_sensitive(lookup_widget(win_main, ALBUM_CATEGORY_COMBO_BOX), FALSE);
143
    }
144
}
145
146
int upload_email_address_is_valid()
147
{
148
    // cddb mail address (only when cddb upload is enabled)
149
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(win_prefs, "enable_cddb_upload"))))
150
    {
151
    	const char* email_address = gtk_entry_get_text(GTK_ENTRY(lookup_widget(win_prefs, "cddb_email_address")));
152
    	if ( ! email_address || (0 == strlen(email_address)))
153
    	{
154
    		show_simple_dialog_message("CDDB upload requires a valid email address");
155
    		return 0;
156
    	}
157
    	if ( ! is_valid_email_address(email_address))
158
    	{
159
    		show_simple_dialog_message("Invalid email address");
160
    		return 0;
161
    	}
162
    }
163
    return 1;
164
}
165
166
static void on_enable_cddb_upload_toggled(GtkToggleButton *togglebutton, gpointer user_data)
167
{
168
	GtkWidget* email_address_w = lookup_widget(win_prefs, "cddb_email_address");
169
    if (gtk_toggle_button_get_active(togglebutton))
170
    {
171
    	gtk_widget_set_sensitive(email_address_w, 1);
172
    }
173
    else
174
    {
175
    	gtk_widget_set_sensitive(email_address_w, 0);
176
    }
177
}
178
179
44
// open dialog to show disc data to be uploaded to CDDB
180
// open dialog to show disc data to be uploaded to CDDB
45
void on_upload_button_clicked(GtkButton* button, gpointer user_data)
181
static void on_upload_button_clicked(GtkButton* button, gpointer user_data)
46
{
182
{
47
	// check if CD is inserted:
183
	// check if CD is inserted:
48
	GtkListStore * store = glb_get_tracklist_store();
184
	GtkListStore * store = glb_get_tracklist_store();
Lines 51-57 Link Here
51
    	show_simple_dialog_message("No CD is inserted. Please insert a CD into the CD-ROM drive.");
187
    	show_simple_dialog_message("No CD is inserted. Please insert a CD into the CD-ROM drive.");
52
        return;
188
        return;
53
    }
189
    }
54
	if ( ! global_prefs->cddb_email_address)
190
	if ( ! upload_is_enabled())
55
	{
191
	{
56
		show_simple_dialog_message(
192
		show_simple_dialog_message(
57
				"CDDB upload is not possible without a valid email address.\n"
193
				"CDDB upload is not possible without a valid email address.\n"
Lines 115-127 Link Here
115
251
116
	/* set the artist */
252
	/* set the artist */
117
	const char* new_album_artist = gtk_entry_get_text(glb_album_artist);
253
	const char* new_album_artist = gtk_entry_get_text(glb_album_artist);
118
	num_changes += is_different(orig_album_artist, new_album_artist);
254
	if (0 != strcmp(new_album_artist, EMPTY_ARTIST_SHOWN))
119
    cddb_disc_set_artist (disc, new_album_artist);
255
	{
256
		num_changes += is_different(orig_album_artist, new_album_artist);
257
		cddb_disc_set_artist (disc, new_album_artist);
258
	}
120
259
121
    /* set the title */
260
	/* set the title */
122
    const char* new_album_title = gtk_entry_get_text(glb_album_title);
261
    const char* new_album_title = gtk_entry_get_text(glb_album_title);
123
	num_changes += is_different(orig_album_title, new_album_title);
262
	if (0 != strcmp(new_album_title, EMPTY_ALBUM_SHOWN))
124
    cddb_disc_set_title (disc, new_album_title);
263
	{
264
		num_changes += is_different(orig_album_title, new_album_title);
265
		cddb_disc_set_title (disc, new_album_title);
266
	}
125
267
126
    /* set the category */
268
    /* set the category */
127
    cddb_cat_t orig_album_category = cddb_disc_get_category(disc);
269
    cddb_cat_t orig_album_category = cddb_disc_get_category(disc);
Lines 130-141 Link Here
130
    cddb_disc_set_category(disc, new_album_category);
272
    cddb_disc_set_category(disc, new_album_category);
131
273
132
    /* set the genre */
274
    /* set the genre */
133
    const char* orig_album_genre = cddb_disc_get_genre(disc);
134
    const char* new_album_genre = gtk_entry_get_text(glb_album_genre);
275
    const char* new_album_genre = gtk_entry_get_text(glb_album_genre);
135
	num_changes += is_different(orig_album_genre, new_album_genre);
276
	if (0 != strcmp(new_album_genre, EMPTY_GENRE_SHOWN))
136
    cddb_disc_set_genre (disc, new_album_genre);
277
	{
278
	    const char* orig_album_genre = cddb_disc_get_genre(disc);
279
		num_changes += is_different(orig_album_genre, new_album_genre);
280
		cddb_disc_set_genre (disc, new_album_genre);
281
	}
137
282
138
    /* set the year */
283
	/* set the year */
139
    int orig_album_year = cddb_disc_get_year(disc);
284
    int orig_album_year = cddb_disc_get_year(disc);
140
    int new_album_year = atoi(gtk_entry_get_text(glb_album_year));
285
    int new_album_year = atoi(gtk_entry_get_text(glb_album_year));
141
    if (new_album_year == EMPTY_YEAR_SHOWN)
286
    if (new_album_year == EMPTY_YEAR_SHOWN)
Lines 161-169 Link Here
161
    	/* get track artist and title */
306
    	/* get track artist and title */
162
        char* new_track_artist = NULL;
307
        char* new_track_artist = NULL;
163
        char* new_track_title = NULL;
308
        char* new_track_title = NULL;
309
        int track_num = 0;
164
        gtk_tree_model_get(store_model, &iter,
310
        gtk_tree_model_get(store_model, &iter,
165
            COL_TRACKARTIST, &new_track_artist,
311
            COL_TRACKARTIST, &new_track_artist,
166
			COL_TRACKTITLE,  &new_track_title,
312
			COL_TRACKTITLE,  &new_track_title,
313
			COL_TRACKNUM,    &track_num,
167
            -1);
314
            -1);
168
        const char* real_new_track_artist = new_track_artist;
315
        const char* real_new_track_artist = new_track_artist;
169
        if (is_single_artist || (0 == strcmp(real_new_track_artist, EMPTY_ARTIST_SHOWN)))
316
        if (is_single_artist || (0 == strcmp(real_new_track_artist, EMPTY_ARTIST_SHOWN)))
Lines 174-187 Link Here
174
321
175
    	/* set track artist */
322
    	/* set track artist */
176
    	const char* orig_track_artist = cddb_track_get_artist(track);
323
    	const char* orig_track_artist = cddb_track_get_artist(track);
177
    	num_changes += is_different(orig_track_artist, real_new_track_artist);
324
    	if (0 != strcmp(real_new_track_artist, EMPTY_ARTIST_SHOWN))
178
        cddb_track_set_artist(track, real_new_track_artist);
325
    	{
326
    		num_changes += is_different(orig_track_artist, real_new_track_artist);
327
    		cddb_track_set_artist(track, real_new_track_artist);
328
    	}
179
        free(new_track_artist);
329
        free(new_track_artist);
180
330
181
    	/* set track title */
331
    	/* set track title */
182
        const char* orig_track_title = cddb_track_get_title(track);
332
        char empty_track_title[16];
183
    	num_changes += is_different(orig_track_title, new_track_title);
333
        snprintf(empty_track_title, sizeof(empty_track_title) - 1, EMPTY_TRACK_SHOWN, track_num);
184
        cddb_track_set_title(track, new_track_title);
334
        if (0 != strcmp(new_track_title, empty_track_title))
335
        {
336
        	const char* orig_track_title = cddb_track_get_title(track);
337
        	num_changes += is_different(orig_track_title, new_track_title);
338
        	cddb_track_set_title(track, new_track_title);
339
        }
185
        free(new_track_title);
340
        free(new_track_title);
186
    }
341
    }
187
342
Lines 420-427 Link Here
420
    gtk_widget_set_sensitive(glb_upload_button, FALSE);
575
    gtk_widget_set_sensitive(glb_upload_button, FALSE);
421
}
576
}
422
577
578
423
static void enable_update_button(void)
579
static void enable_update_button(void)
424
{
580
{
425
    gtk_widget_set_sensitive(glb_upload_button, TRUE);
581
    gtk_widget_set_sensitive(glb_upload_button, TRUE);
426
}
582
}
427
583
584
585
static bool is_valid_email_address(const char* email_address)
586
{
587
#if HAS_POSIX_REGEX
588
	regex_t regex;
589
	int bad_regular_expression = regcomp(
590
			&regex,
591
			"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$",
592
			REG_EXTENDED | REG_NEWLINE);
593
	if ( ! bad_regular_expression)
594
	{
595
        size_t nmatch = 1;
596
        regmatch_t pmatch[1];
597
598
        int nomatch = regexec(&regex, email_address, nmatch, pmatch, 0);
599
        regfree(&regex);
600
        if (nomatch)
601
        {
602
        	return 0;
603
        }
604
		return 1;
605
	}
606
	regfree(&regex);
607
	// in case of bad expression use the simple algorithm below
608
#endif
609
610
	// a better way would be to call regcomp(POSIX)
611
612
	int num_at = 0;				// number of '@' characters
613
	int pos_of_at = -1;			// position of last '@' character
614
	int num_dots = 0;			// number of '.' characters
615
	int pos_of_dot = -1;	// position of last '.' character
616
617
	int len = strlen(email_address);
618
	int i;
619
	for (i = 0; i < len; ++i)
620
	{
621
		char c = email_address[i];
622
		switch (c)
623
		{
624
		case '@':
625
			++ num_at;
626
			pos_of_at = i;
627
			break;
628
629
		case '.':
630
			++num_dots;
631
			pos_of_dot = i;
632
			break;
633
634
		case ' ':
635
		case '\t':
636
			return 0;	// illegal character
637
638
		default:
639
			break;
640
		}
641
	}
642
	if (num_at > 1)
643
	{
644
		return 0;	// too many '@' characters
645
	}
646
	if (num_dots == 0)
647
	{
648
		return 0;	// missing '.' character
649
	}
650
	if (pos_of_dot < pos_of_at)
651
	{
652
		return 0;	// missing '.' after '@'
653
	}
654
	return 1;
655
}
(-)src/upload.h (-1 / +17 lines)
Lines 11-16 Link Here
11
11
12
#include <gtk/gtk.h>
12
#include <gtk/gtk.h>
13
13
14
// return the widget which contains the button to start the CDDB upload (for the main window)
15
GtkWidget * get_cddb_upload_button_widget(GtkWidget *main_win);
14
16
15
void on_upload_button_clicked(GtkButton* button, gpointer user_data);
17
// return the widget which contains the toggle button to enable/disable CDDB upload (for the Preferences dialog)
18
GtkWidget * get_enable_cddb_upload_togglebutton(GtkWidget *prefs);
16
19
20
// return the widget which contains label and textfield to enter the email address (for the Preferences dialog)
21
GtkWidget * get_cddb_email_address_widget(GtkWidget *prefs);
22
23
// return 1 if CDDB upload is enabled, and 0 otherwise
24
int upload_is_enabled();
25
26
// return 1 if the email address in the Preference dialog is valid, and 0 otherwise
27
int upload_email_address_is_valid();
28
29
// shows/hides the upload button and the category box
30
void upload_toggle_enable(void);
31
32

Return to bug 29