71
73
* +-> track -> track -> ... -> NULL
73
75
static GSList *playlistlist = NULL;
77
* This is a file list with folder information, filtered
78
* to present a folder view
80
static GSList *datafilelist = NULL;
76
83
/***********************************************************************************/
77
84
/* Public and private functions */
78
85
/***********************************************************************************/
87
static void display_njberror(njb_t *njb, gchar *template)
89
gboolean found_njb_error = FALSE;
91
GString *error_string = g_string_new(template);
94
NJB_Error_Reset_Geterror(njb);
95
while ((sp = NJB_Error_Geterror(njb)) != NULL) {
96
found_njb_error = TRUE;
97
g_string_append_printf(error_string, "%s\n", sp);
100
found_njb_error = TRUE;
101
g_string_append_printf(error_string, _("Could not open the device on the USB bus"));
104
if (!found_njb_error)
105
g_string_append_printf(error_string, _("(unknown cause)"));
107
create_error_dialog(error_string->str);
108
g_string_free(error_string, TRUE);
80
111
static void refresh_id(void)
82
113
if (njb != NULL) {
87
njbid = NJB_Ping(njb);
91
118
/* Returns the unique jukebox ID */
92
gchar *jukebox_get_idstring(void)
119
static gchar *jukebox_get_idstring(void)
94
121
if (njb != NULL) {
95
return (gchar *) njb->idstring;
125
if (NJB_Get_SDMI_ID(njb, (u_int8_t *) &sdmiid) == 0) {
126
return g_strdup_printf("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
127
sdmiid[0], sdmiid[1], sdmiid[2], sdmiid[3], sdmiid[4],
128
sdmiid[5], sdmiid[6], sdmiid[7], sdmiid[8], sdmiid[9],
129
sdmiid[10], sdmiid[11], sdmiid[12], sdmiid[13], sdmiid[14],
101
139
/* Returns a string representing the firmware revision */
102
gchar *jukebox_get_firmware(void)
140
static gchar *jukebox_get_firmware(void)
104
if (jukebox_firmware != NULL) {
105
g_free(jukebox_firmware);
106
jukebox_firmware = NULL;
110
/* if (njb->device_type == NJB_DEVICE_NJB1) */
112
g_strdup_printf("%u.%u", njbid->fwMajor, njbid->fwMinor);
113
/* else g_strdup_printf("%u.%u.%u", njbid->fwMajor, njbid->fwMinor, njbid->fwRel); */
143
if (jukebox_firmware == NULL) {
144
u_int8_t major, minor, release;
146
if (NJB_Get_Firmware_Revision(njb, &major, &minor, &release) == -1) {
149
if (njb->device_type == NJB_DEVICE_NJB1) {
150
jukebox_firmware = g_strdup_printf("%u.%u", major, minor);
152
jukebox_firmware = g_strdup_printf("%u.%u.%u", major, minor, release);
114
155
return jukebox_firmware;
161
/* Returns a string representing the hardware revision */
162
static gchar *jukebox_get_hardware(void)
165
if (jukebox_hardware == NULL) {
166
u_int8_t major, minor, release;
168
if (NJB_Get_Hardware_Revision(njb, &major, &minor, &release) == -1) {
171
jukebox_hardware = g_strdup_printf("%u.%u.%u", major, minor, release);
173
return jukebox_hardware;
120
179
/* Returns the product name */
121
gchar *jukebox_get_prodname(void)
125
return (gchar *) njbid->productName;
131
/* Returns data about if the power cord is connected */
132
gboolean jukebox_get_power(void)
136
return (njbid->power > 0) ? TRUE : FALSE;
180
static gchar *jukebox_get_prodname(void)
183
return (gchar *) NJB_Get_Device_Name(njb, 1);
189
/* Returns data about if the power cord is connected */
190
static gboolean jukebox_get_power(void)
193
int powerstat = NJB_Get_Auxpower(njb);
194
if (powerstat == 1) {
204
/* Returns data about if the power cord is connected */
205
static gboolean jukebox_get_charging(void)
208
int chargestat = NJB_Get_Battery_Charging(njb);
209
if (chargestat == 1) {
219
/* Returns the battery level in percent */
220
static guint jukebox_get_battery_level(void)
223
return NJB_Get_Battery_Level(njb);
229
static void add_to_dialog(GtkWidget *dialog, GtkWidget *thing)
231
#if GTK_CHECK_VERSION(2,4,0)
232
gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), thing, TRUE, TRUE, 0);
234
gtk_box_pack_start (GTK_BOX(GNOME_DIALOG(dialog)->vbox), thing, TRUE, TRUE, 0);
238
/* This creates a device information dialog and returns it. */
239
GtkWidget *jukebox_get_deviceinfo_dialog(void)
241
GtkWidget *label, *button, *dialog, *hbox;
244
guint64 total, free, used;
245
guint songs, playlists, datafiles;
252
// Make sure our information is up-to-date
255
#if GTK_CHECK_VERSION(2,4,0)
256
dialog = gtk_message_dialog_new (GTK_WINDOW(main_window),
257
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
260
_("Jukebox information"));
261
// dialog = gtk_dialog_new();
262
gtk_window_set_title (GTK_WINDOW (dialog), (_("Jukebox information")));
263
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5);
264
gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE);
265
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
266
g_signal_connect_object(GTK_OBJECT(dialog),
268
G_CALLBACK(gtk_widget_destroy),
271
g_signal_connect_object(GTK_OBJECT(dialog),
273
G_CALLBACK(gtk_widget_destroy),
277
dialog = gnome_dialog_new(_("Jukebox information"),
278
GNOME_STOCK_BUTTON_OK,
280
gnome_dialog_button_connect_object(GNOME_DIALOG(dialog),
282
GTK_SIGNAL_FUNC(gtk_widget_destroy),
285
hbox = gtk_hbox_new(FALSE, 0);
286
label = gtk_label_new (_("Unique device ID:"));
287
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
288
gtk_widget_show (label);
289
add_empty_hbox (hbox);
290
label = gtk_label_new(jukebox_get_idstring());
291
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
292
gtk_widget_show(label);
293
add_to_dialog(dialog, hbox);
294
gtk_widget_show (hbox);
296
hbox = gtk_hbox_new(FALSE, 0);
297
label = gtk_label_new (_("Firmware revision:"));
298
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
299
gtk_widget_show (label);
300
add_empty_hbox (hbox);
301
label = gtk_label_new(jukebox_get_firmware());
302
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
303
gtk_widget_show(label);
304
add_to_dialog(dialog, hbox);
305
gtk_widget_show (hbox);
307
if (njb->device_type != NJB_DEVICE_NJB1) {
308
hbox = gtk_hbox_new(FALSE, 0);
309
label = gtk_label_new (_("Hardware revision:"));
310
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
311
gtk_widget_show (label);
312
add_empty_hbox (hbox);
313
label = gtk_label_new(jukebox_get_hardware());
314
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
315
gtk_widget_show(label);
316
add_to_dialog(dialog, hbox);
317
gtk_widget_show (hbox);
320
hbox = gtk_hbox_new(FALSE, 0);
321
label = gtk_label_new (_("Product name:"));
322
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
323
gtk_widget_show (label);
324
add_empty_hbox (hbox);
325
label = gtk_label_new(jukebox_get_prodname());
326
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
327
gtk_widget_show(label);
328
add_to_dialog(dialog, hbox);
329
gtk_widget_show (hbox);
331
hbox = gtk_hbox_new(FALSE, 0);
332
label = gtk_label_new (_("Auxilary power (AC or USB) connected:"));
333
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
334
gtk_widget_show (label);
335
add_empty_hbox (hbox);
336
label = gtk_label_new((jukebox_get_power()) ? _("Yes") : _("No"));
337
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
338
gtk_widget_show(label);
339
add_to_dialog(dialog, hbox);
340
gtk_widget_show (hbox);
342
hbox = gtk_hbox_new(FALSE, 0);
343
label = gtk_label_new (_("Battery is charging:"));
344
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
345
gtk_widget_show (label);
346
add_empty_hbox (hbox);
347
label = gtk_label_new((jukebox_get_charging()) ? _("Yes") : _("No"));
348
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
349
gtk_widget_show(label);
350
add_to_dialog(dialog, hbox);
351
gtk_widget_show (hbox);
353
if (njb->device_type != NJB_DEVICE_NJB1) {
354
hbox = gtk_hbox_new(FALSE, 0);
355
label = gtk_label_new (_("Battery level:"));
356
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
357
gtk_widget_show (label);
358
add_empty_hbox (hbox);
359
sprintf(tmp, "%d%%", jukebox_get_battery_level());
360
label = gtk_label_new(tmp);
361
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
362
gtk_widget_show(label);
363
add_to_dialog(dialog, hbox);
364
gtk_widget_show (hbox);
367
hbox = gtk_hbox_new(FALSE, 0);
368
label = gtk_label_new (_("Jukebox owner:"));
369
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
370
gtk_widget_show (label);
371
add_empty_hbox (hbox);
372
sprintf(tmp, "%s", jukebox_get_ownerstring());
373
label = gtk_label_new(tmp);
374
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
375
gtk_widget_show(label);
376
add_to_dialog(dialog, hbox);
377
gtk_widget_show (hbox);
379
hbox = gtk_hbox_new(FALSE, 0);
380
label = gtk_label_new (_("Time on jukebox:"));
381
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
382
gtk_widget_show (label);
383
add_empty_hbox (hbox);
384
label = gtk_label_new(jukebox_get_time());
385
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
386
gtk_widget_show(label);
387
add_to_dialog(dialog, hbox);
388
gtk_widget_show (hbox);
391
jukebox_getusage(&total, &free, &used, &songs, &playlists, &datafiles);
393
hbox = gtk_hbox_new(FALSE, 0);
394
label = gtk_label_new (_("Total bytes on disk:"));
395
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
396
gtk_widget_show (label);
397
add_empty_hbox (hbox);
398
sprintf(tmp, "%Lu (%Lu MB)",
399
total, (guint64) total/G_GINT64_CONSTANT(1048576));
400
label = gtk_label_new(tmp);
401
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
402
gtk_widget_show(label);
403
add_to_dialog(dialog, hbox);
404
gtk_widget_show (hbox);
406
hbox = gtk_hbox_new(FALSE, 0);
407
label = gtk_label_new (_("Total free bytes available:"));
408
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
409
gtk_widget_show (label);
410
add_empty_hbox (hbox);
411
sprintf(tmp, "%Lu (%Lu MB)",
412
free, (guint64) free/G_GINT64_CONSTANT(1048576));
413
label = gtk_label_new(tmp);
414
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
415
gtk_widget_show(label);
416
add_to_dialog(dialog, hbox);
417
gtk_widget_show (hbox);
419
hbox = gtk_hbox_new(FALSE, 0);
420
label = gtk_label_new (_("Total bytes used:"));
421
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
422
gtk_widget_show (label);
423
add_empty_hbox (hbox);
424
sprintf(tmp, "%Lu (%Lu MB)",
425
used, (guint64) used/G_GINT64_CONSTANT(1048576));
426
label = gtk_label_new(tmp);
427
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
428
gtk_widget_show(label);
429
add_to_dialog(dialog, hbox);
430
gtk_widget_show (hbox);
432
hbox = gtk_hbox_new(FALSE, 0);
433
label = gtk_label_new (_("Number of songs:"));
434
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
435
gtk_widget_show (label);
436
add_empty_hbox (hbox);
437
sprintf(tmp, "%lu", songs);
438
label = gtk_label_new(tmp);
439
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
440
gtk_widget_show(label);
441
add_to_dialog(dialog, hbox);
442
gtk_widget_show (hbox);
444
hbox = gtk_hbox_new(FALSE, 0);
445
label = gtk_label_new (_("Number of playlists:"));
446
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
447
gtk_widget_show (label);
448
add_empty_hbox (hbox);
449
sprintf(tmp, "%lu", playlists);
450
label = gtk_label_new(tmp);
451
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
452
gtk_widget_show(label);
453
add_to_dialog(dialog, hbox);
454
gtk_widget_show (hbox);
456
hbox = gtk_hbox_new(FALSE, 0);
457
label = gtk_label_new (_("Number of datafiles:"));
458
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
459
gtk_widget_show (label);
460
add_empty_hbox (hbox);
461
sprintf(tmp, "%lu", datafiles);
462
label = gtk_label_new(tmp);
463
gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
464
gtk_widget_show(label);
465
add_to_dialog(dialog, hbox);
466
gtk_widget_show (hbox);
142
471
gchar *jukebox_get_time(void)
576
914
/* Update the usage information */
577
915
static void flush_usage()
579
u_int64_t totalbytes;
917
u_int64_t totalbytes = 0;
918
u_int64_t freebytes = 0;
582
if (NJB_Get_Disk_Usage (njb, &totalbytes, &freebytes) == -1)
583
njb_error_dump(stderr);
920
if (NJB_Get_Disk_Usage (njb, &totalbytes, &freebytes) == -1) {
921
NJB_Error_Dump(njb, stderr);
585
925
jukebox_totalbytes = totalbytes;
586
926
jukebox_freebytes = freebytes;
587
927
jukebox_usedbytes = jukebox_totalbytes - jukebox_freebytes;
590
/***********************************************************************************/
591
/* Scanning thread - reads in the Jukebox track directory, the datafile directory */
592
/* and all playlists, along with some general information about the jukebox. */
593
/***********************************************************************************/
930
static void destroy_datafile_list()
932
GSList *tmplist = datafilelist;
934
while (tmplist != NULL) {
935
meta = (metadata_t *) tmplist->data;
936
destroy_metadata_t(meta);
937
tmplist = g_slist_next(tmplist);
939
g_slist_free(datafilelist);
943
static void remove_from_datafile_list(gchar *path)
945
GSList *tmplist1 = datafilelist;
946
GSList *tmplist2 = NULL;
949
while (tmplist1 != NULL) {
950
meta = (metadata_t *) tmplist1->data;
951
if (!strcmp(path, meta->path)) {
953
destroy_metadata_t(meta);
956
tmplist2 = g_slist_append(tmplist2, meta);
958
tmplist1 = g_slist_next(tmplist1);
960
g_slist_free(datafilelist);
961
datafilelist = tmplist2;
964
static GSList *filter_datafile_list(gchar *filter)
966
GSList *tmplist = datafilelist;
967
GSList *filterlist = NULL;
974
if (filter == NULL) {
977
/* Create a ".." directory */
978
meta = new_metadata_t();
979
meta->filename = g_strdup("..");
981
tmp = g_strsplit(filter, "\\", 0);
982
veclen = vectorlength(tmp);
985
gchar *newdir = NULL;
987
for (i = 0; i < veclen - 2; i++) {
988
newdir = stringcat(newdir, tmp[i]);
989
newdir = stringcat(newdir, "\\");
991
meta->folder = newdir;
993
meta->folder = g_strdup(filter);
997
filterlist = g_slist_append(filterlist, meta);
998
/* Then filter the list */
999
while (tmplist != NULL) {
1000
meta = (metadata_t *) tmplist->data;
1001
if (meta->folder != NULL) {
1002
if (!strcmp(meta->folder, filter)
1003
&& meta->size != 0) {
1004
/* First just add all regular files belonging to this directory */
1005
filterlist = g_slist_append(filterlist, meta);
1006
} else if (meta->size == 0) {
1007
/* Then add any subdirectories */
1008
gchar **tmp1 = g_strsplit(meta->folder, "\\", 0);
1009
gchar **tmp2 = g_strsplit(filter, "\\", 0);
1010
int veclen1 = vectorlength(tmp1);
1011
int veclen2 = vectorlength(tmp2);
1014
/* It must be exactly one more component in the folder than in the filter */
1015
if (veclen1 == veclen2+1) {
1016
gboolean match = TRUE;
1018
/* We don't match the last component of the filter, it's NULL, see. */
1019
for (i = 0; i < veclen2-1; i++) {
1020
if (tmp1[i] != NULL && tmp2[i] != NULL && strcmp(tmp1[i],tmp2[i])) {
1025
/* If it's matching up to the filter length, add it */
1026
filterlist = g_slist_append(filterlist, meta);
1032
} else if (!strcmp(filter, "\\")) {
1033
filterlist = g_slist_append(filterlist, meta);
1035
tmplist = g_slist_next(tmplist);
1040
void rebuild_datafile_list(gchar *filter) {
1042
* Add everything to the model by filtering out the root
1043
* directory files only from the datafile list.
1045
if (datafilelist != NULL) {
1048
/* Hack to get the datafile list store built in O(n) instead of O(n^2) */
1049
recreate_list_store(JBDATA_LIST);
1050
filtered = filter_datafile_list(filter);
1051
if (filtered != NULL) {
1052
GSList *tmplist = filtered;
1055
while (tmplist != NULL) {
1056
meta = (metadata_t *) tmplist->data;
1057
add_metadata_to_model(meta, JBDATA_LIST);
1058
tmplist = g_slist_next(tmplist);
1060
g_slist_free(tmplist);
1062
view_and_sort_list_store(JBDATA_LIST);
1067
* Scanning thread - reads in the Jukebox track directory, the datafile directory
1068
* and all playlists, along with some general information about the jukebox.
595
1070
gpointer scan_thread(gpointer thread_args)
1072
njb_songid_t *songtag;
1073
njb_datafile_t *datatag;
599
1074
gchar *scan_songs = _("Scanning songs...");
1075
gchar *slow_warning = _("Scanning songs:\nYou have selected extended metadata scan,\n so scanning will be very slow.");
600
1076
gchar *scan_playlists = _("Scanning playlists...");
601
1077
gchar *scan_datafiles = _("Scanning datafiles...");
602
1078
scan_thread_arg_t *args = (scan_thread_arg_t *) thread_args;
646
1123
gdk_threads_leave();
647
1124
g_free(scanstring);
649
songid_reset_getframe(songtag);
1126
NJB_Songid_Reset_Getframe(songtag);
650
1127
/* Create a structure to hold the data in the columns */
651
1128
meta = new_metadata_t();
652
1129
meta->path = g_strdup_printf("%lu", songtag->trid);
654
1131
/* Loop through the song tags */
655
while(frame = songid_getframe(songtag)){
1132
while(frame = NJB_Songid_Getframe(songtag)){
656
1133
// FIXME: add progress bar for scanning?
657
label = (gchar *) g_malloc (frame->labelsz + 1);
658
memcpy(label, frame->label, frame->labelsz);
659
/* Terminate string */
660
label[frame->labelsz] = '\0';
662
if (frame->type == ID_DATA_BIN) {
663
/* If it is not ASCII data */
664
if (!strcmp(label, FR_LENGTH)) {
665
data = seconds_to_mmss(songid_frame_data32(frame));
668
if (frame->datasz > 4) {
670
* There is no way to handle this right now, though
671
* it could easily be added to the libnjb if needed
673
g_print("Error: Found 64 bit data in songid tag frame. Ignoring.\n");
675
numdata = songid_frame_data32(frame);
677
} else if (frame->type == ID_DATA_ASCII) {
678
/* Strings that are actually integers are converted */
679
if (!strcmp(label, FR_YEAR) ||
680
!strcmp(label, FR_TRACK)) {
681
numdata = string_to_guint(frame->data);
683
/* If it is ASCII data */
685
data = g_strdup(frame->data);
687
data = g_strdup("<Unknown>");
691
if (!strcmp(label, FR_ARTIST))
693
else if (!strcmp(label, FR_TITLE))
695
else if (!strcmp(label, FR_ALBUM))
697
else if (!strcmp(label, FR_GENRE))
699
else if (!strcmp(label, FR_LENGTH))
701
else if (!strcmp(label, FR_SIZE))
702
meta->size = numdata;
703
else if (!strcmp(label, FR_CODEC))
705
else if (!strcmp(label, FR_TRACK))
706
meta->trackno = numdata;
707
else if (!strcmp(label, FR_YEAR))
708
meta->year = numdata;
709
else if (!strcmp(label, FR_FNAME))
710
meta->filename = data;
711
else if (!strcmp(label, FR_PROTECTED)) {
1135
if (!strcmp(frame->label, FR_ARTIST)) {
1136
meta->artist = g_strdup(frame->data.strval);
1137
} else if (!strcmp(frame->label, FR_TITLE)) {
1138
meta->title = g_strdup(frame->data.strval);
1139
} else if (!strcmp(frame->label, FR_ALBUM)) {
1140
meta->album = g_strdup(frame->data.strval);
1141
} else if (!strcmp(frame->label, FR_GENRE)) {
1142
meta->genre = g_strdup(frame->data.strval);
1143
} else if (!strcmp(frame->label, FR_LENGTH)) {
1144
meta->length = seconds_to_mmss((guint) frame->data.u_int16_val);
1145
} else if (!strcmp(frame->label, FR_SIZE)) {
1146
meta->size = frame->data.u_int32_val;
1147
} else if (!strcmp(frame->label, FR_CODEC)) {
1148
// Uppercaseify it. Work in all GTK+ >= 2.0?
1149
meta->codec = g_ascii_strup(frame->data.strval, -1);
1150
} else if (!strcmp(frame->label, FR_TRACK)) {
1151
meta->trackno = (guint) frame->data.u_int16_val;
1152
} else if (!strcmp(frame->label, FR_YEAR)) {
1153
meta->year = (guint) frame->data.u_int16_val;
1154
} else if (!strcmp(frame->label, FR_FNAME)) {
1155
meta->filename = g_strdup(frame->data.strval);
1156
} else if (!strcmp(frame->label, FR_FOLDER)) {
1157
meta->folder = g_strdup(frame->data.strval);
1158
} else if (!strcmp(frame->label, FR_PROTECTED)) {
712
1159
meta->protect = TRUE;
717
g_print("Discarded: %s -> %s\n", label, data);
1161
g_print("Unknown frame type %s\n", frame->label);
723
1164
/* Compensate for missing tag information */
724
1165
if (!meta->artist)
978
1431
gtk_progress_bar_update(GTK_PROGRESS_BAR(progress_bar), (gfloat) 0);
979
1432
gdk_threads_leave();
980
1433
length = mmss_to_seconds(hdmeta->length);
981
tmpyear = g_strdup_printf("%lu", hdmeta->year);
982
1434
protectint = hdmeta->protect ? 1 : 0;
1435
songid = NJB_Songid_New();
1436
frame = NJB_Songid_Frame_New_Codec(hdmeta->codec);
1437
NJB_Songid_Addframe(songid, frame);
1438
// libnjb will add this if not added by hand
1439
// frame = NJB_Songid_Frame_New_Filesize(filesize);
1440
// NJB_Songid_Addframe(songid, frame);
1441
frame = NJB_Songid_Frame_New_Title(hdmeta->title);
1442
NJB_Songid_Addframe(songid, frame);
1443
frame = NJB_Songid_Frame_New_Album(hdmeta->album);
1444
NJB_Songid_Addframe(songid, frame);
1445
frame = NJB_Songid_Frame_New_Artist(hdmeta->artist);
1446
NJB_Songid_Addframe(songid, frame);
1447
frame = NJB_Songid_Frame_New_Genre(hdmeta->genre);
1448
NJB_Songid_Addframe(songid, frame);
1449
frame = NJB_Songid_Frame_New_Year(hdmeta->year);
1450
NJB_Songid_Addframe(songid, frame);
1451
frame = NJB_Songid_Frame_New_Tracknum(hdmeta->trackno);
1452
NJB_Songid_Addframe(songid, frame);
1453
frame = NJB_Songid_Frame_New_Length(length);
1454
NJB_Songid_Addframe(songid, frame);
1455
frame = NJB_Songid_Frame_New_Filename(hdmeta->filename);
1456
NJB_Songid_Addframe(songid, frame);
1457
if (hdmeta->protect) {
1458
frame = NJB_Songid_Frame_New_Protected(1);
1459
NJB_Songid_Addframe(songid, frame);
983
1462
/* Optionally remove ID3 tag */
984
1463
if (get_prefs_id3remove() && !strcmp(hdmeta->codec, "MP3")) {
985
1464
gchar *tmpfname8;
988
1465
tmpfname8 = g_build_filename(tmpdirname, hdmeta->filename, NULL);
989
1466
tmpfname = filename_fromutf8(tmpfname8);
990
1468
/* Call the filesystem to clone the file and remove the tag */
991
1469
if (clone_and_strip_id3(hdmeta->path, tmpfname8)) {
992
1470
// g_print("Transferring track.\n");
993
if (NJB_Send_Track (njb,
1471
if (NJB_Send_Track (njb, tmpfname, songid,
1007
njb_error_dump(stderr);
1474
NJB_Error_Dump(njb, stderr);
1008
1475
goto hd2jb_cleanup;
1010
1477
/* Afterwards delete the tempfile */
1011
1478
unlink(tmpfname);
1012
1479
g_free(tmpfname8);
1017
1482
tmpfname = filename_fromutf8(hdmeta->path);
1018
if (NJB_Send_Track (njb,
1483
if (NJB_Send_Track (njb, tmpfname, songid,
1033
njb_error_dump(stderr);
1486
NJB_Error_Dump(njb, stderr);
1034
1487
goto hd2jb_cleanup;
1036
/* g_print("%s stored on jukebox with ID: %lu\n", file, id); */
1490
/* g_print("%s stored on jukebox with ID: %lu\n", file, id); */
1041
1493
/* Add to disk listbox and re-sort */
1042
1494
/* Add correct trackid in col 7, add the row */
1043
1495
jbmeta = clone_metadata_t(hdmeta);
1272
1724
/* Set metadata on the file with ID id */
1273
1725
u_int32_t id, length;
1274
1726
metadata_t *tmpmeta;
1727
njb_songid_t *songid;
1728
njb_songid_frame_t *frame;
1278
1730
id = string_to_guint(meta->path);
1279
1731
length = mmss_to_seconds(meta->length);
1280
tmpyear = g_strdup_printf("%lu", meta->year);
1281
protectint = meta->protect ? 1 : 0;
1283
if (NJB_Replace_Track_Tag (njb,
1295
protectint) == -1) {
1296
njb_error_dump(stderr);
1733
create_error_dialog(_("Track ID was zero! Illegal value!"));
1737
create_error_dialog(_("Song length must be greater than zero!"));
1741
songid = NJB_Songid_New();
1742
/* On NJB1 incremental update is not possible! */
1743
if (njb->device_type == NJB_DEVICE_NJB1) {
1744
// Sometimes it fails with old codec names.
1745
gchar *tmpcodec = g_ascii_strup(meta->codec, -1);
1747
frame = NJB_Songid_Frame_New_Codec(tmpcodec);
1749
NJB_Songid_Addframe(songid, frame);
1750
frame = NJB_Songid_Frame_New_Filesize(meta->size);
1751
NJB_Songid_Addframe(songid, frame);
1753
/* Ultimately only send altered fields to NJB series 3 */
1754
frame = NJB_Songid_Frame_New_Title(meta->title);
1755
NJB_Songid_Addframe(songid, frame);
1756
frame = NJB_Songid_Frame_New_Album(meta->album);
1757
NJB_Songid_Addframe(songid, frame);
1758
frame = NJB_Songid_Frame_New_Artist(meta->artist);
1759
NJB_Songid_Addframe(songid, frame);
1760
frame = NJB_Songid_Frame_New_Genre(meta->genre);
1761
NJB_Songid_Addframe(songid, frame);
1762
frame = NJB_Songid_Frame_New_Year(meta->year);
1763
NJB_Songid_Addframe(songid, frame);
1764
frame = NJB_Songid_Frame_New_Tracknum(meta->trackno);
1765
NJB_Songid_Addframe(songid, frame);
1766
frame = NJB_Songid_Frame_New_Length(length);
1767
NJB_Songid_Addframe(songid, frame);
1769
* These will only be set if the jukebox has retrieved
1770
* extended metadata so that the user has a chance of modifying
1771
* an existing tag, not just overwrite what is already there.
1773
if (get_prefs_extended_metadata()) {
1774
if (meta->filename != NULL) {
1775
frame = NJB_Songid_Frame_New_Filename(meta->filename);
1776
NJB_Songid_Addframe(songid, frame);
1778
if (meta->folder != NULL) {
1779
frame = NJB_Songid_Frame_New_Folder(meta->folder);
1780
NJB_Songid_Addframe(songid, frame);
1783
if (meta->protect) {
1784
frame = NJB_Songid_Frame_New_Protected(1);
1785
NJB_Songid_Addframe(songid, frame);
1788
if (NJB_Replace_Track_Tag(njb, id, songid) == -1) {
1789
NJB_Error_Dump(njb, stderr);
1299
1791
/* Replace the data in the hash table */
1300
1792
tmpmeta = (metadata_t *) g_hash_table_lookup(songhash,
1301
1793
GUINT_TO_POINTER(id));
1302
// Make sure we actually find it! Sometimes it is non-existant...
1794
/* Make sure we actually find it! Sometimes it is non-existant... */
1303
1795
if (tmpmeta != NULL) {
1304
1796
destroy_hash(NULL, tmpmeta, NULL);
1305
1797
g_hash_table_remove(songhash,
1925
/* Randomize file from playlist UNTHREADED */
1926
guint jukebox_randomize_playlist(guint plist, GtkTreeStore *pltreestore)
1928
guint new_plid = plist;
1931
njb_playlist_t *playlist;
1932
gboolean found = FALSE;
1934
jukebox_locked = TRUE;
1935
// g_print("randomizing playlist %lu\n", plist);
1936
NJB_Reset_Get_Playlist(njb);
1937
while (playlist = NJB_Get_Playlist(njb)) {
1938
// g_print("Is it %lu?\n", playlist->plid);
1939
if (playlist->plid == plist) {
1945
NJB_Playlist_Destroy(playlist);
1948
GPtrArray *contents = g_ptr_array_sized_new (playlist->ntracks);
1950
njb_playlist_track_t *current = playlist->first;
1951
njb_playlist_track_t *prev = NULL;
1952
GRand* randnum = g_rand_new();
1954
// g_print(" playlist size is %u\n", playlist->ntracks);
1956
if (playlist->ntracks > 1)
1958
//g_print("Old order\n");
1959
while(current != NULL)
1961
//g_print("%lu\n", current->trackid);
1962
g_ptr_array_add(contents, current);
1963
current = current->next;
1966
//For each item, swap with a randommly selected later item
1967
for (i = 0; i < playlist->ntracks; ++i)
1969
j = g_rand_int_range(randnum, i, playlist->ntracks);
1970
//g_print("Swapping %lu [%i] with %lu [%i]\n",((njb_playlist_track_t *)contents->pdata[i])->trackid,i,((njb_playlist_track_t *)contents->pdata[j])->trackid,j);
1971
temp = contents->pdata[i];
1972
contents->pdata[i] = contents->pdata[j];
1973
contents->pdata[j] = temp;
1976
// Repair the chaining
1977
// g_print("New order\n");
1978
for (i = 0; i < playlist->ntracks; ++i)
1980
current = (njb_playlist_track_t *)contents->pdata[i];
1981
//g_print("%lu\n", current->trackid);
1982
current->prev = prev;
1984
prev->next = current;
1985
current->next = NULL;
1989
playlist->first = contents->pdata[0];
1990
playlist->last = prev;
1993
playlist->_state = NJB_PL_CHTRACKS;
1994
if (NJB_Update_Playlist(njb, playlist) == -1)
1995
NJB_Error_Dump(njb, stderr);
1996
new_plid = playlist->plid;
1998
g_print("Playlist is too small to shuffle\n");
2001
NJB_Playlist_Destroy(playlist);
2002
g_ptr_array_free(contents, FALSE);
2003
g_rand_free(randnum);
2004
// Then rebuild the playlist list (necessary).
2005
build_playlist_tree(pltreestore, FALSE);
2008
jukebox_locked = FALSE;
2009
// g_print("Old playlist ID: %lu, new playlist ID: %lu\n", plist, new_plid);
1433
2013
/* Delete file from playlist UNTHREADED */
1434
guint jukebox_delete_track_from_playlist(guint trackid, guint plist)
2014
guint jukebox_delete_track_from_playlist(guint trackid, guint plist, GtkTreeStore *pltreestore)
1436
2016
guint new_plid = plist;
1438
2018
if (trackid != 0 && plist != 0) {
1439
playlist_t *playlist;
2019
njb_playlist_t *playlist;
1440
2020
gboolean found = FALSE;
1441
2022
jukebox_locked = TRUE;
1443
g_print("Removing track: %lu from playlist %lu\n",
2023
// g_print("Removing track: %lu from playlist %lu\n", trackid, plist);
1445
2024
NJB_Reset_Get_Playlist(njb);
1446
2025
while (playlist = NJB_Get_Playlist(njb)) {
1447
g_print("Is it in %lu?\n", playlist->plid);
2026
// g_print("Is it in %lu? ...", playlist->plid);
1448
2027
if (playlist->plid == plist) {
2028
// g_print("YES!\n");
1454
playlist_destroy(playlist);
2032
// g_print("NO.\n");
2033
NJB_Playlist_Destroy(playlist);
1456
2035
/* If the playlist was found, remove the track */
1458
playlist_track_t *track;
2037
njb_playlist_track_t *track;
1460
g_print("Found playlist %lu\n", playlist->plid);
1461
while (track = playlist_gettrack(playlist)) {
2039
// g_print("Found playlist %lu\n", playlist->plid);
2040
while (track = NJB_Playlist_Gettrack(playlist)) {
1462
2041
if (trackid == track->trackid) {
1463
2042
/* When the track is located in a playlist, remove it */
1464
g_print("Removing track: %lu from playlist %lu\n",
1465
track->trackid, playlist->plid);
2043
// g_print("Removing track: %lu from playlist %lu\n", track->trackid, playlist->plid);
1467
2045
if (track->prev != NULL)
1468
2046
track->prev->next = track->next;