comparison src/bar_info.c @ 595:15766932414c

Allow the user to append or replace comments for a group of selected files. Two buttons were added to the Keywords panel.
author zas_
date Tue, 06 May 2008 17:00:55 +0000
parents 4cfce4ed35e0
children 0b203af63dbf
comparison
equal deleted inserted replaced
594:4cfce4ed35e0 595:15766932414c
490 490
491 list = list->next; 491 list = list->next;
492 } 492 }
493 } 493 }
494 494
495 static void metadata_set_keywords(FileData *fd, GList *list, gint add) 495 static void metadata_set_keywords(FileData *fd, GList *keywords_to_use, gchar *comment_to_use, gint add)
496 { 496 {
497 gchar *comment = NULL; 497 gchar *comment = NULL;
498 GList *keywords = NULL; 498 GList *keywords = NULL;
499 GList *save_list = NULL; 499 GList *save_list = NULL;
500 500
501 comment_read(fd, &keywords, &comment); 501 comment_read(fd, &keywords, &comment);
502 502
503 if (add) 503 if (comment_to_use)
504 { 504 {
505 GList *work; 505 if (add && comment && *comment)
506 506 {
507 work = list; 507 gchar *tmp = comment;
508 while (work) 508
509 { 509 comment = g_strconcat(tmp, comment_to_use, NULL);
510 gchar *key; 510 g_free(tmp);
511 GList *p; 511 }
512 512 else
513 key = work->data; 513 {
514 work = work->next; 514 g_free(comment);
515 515 comment = g_strdup(comment_to_use);
516 p = keywords; 516 }
517 while (p && key) 517 }
518
519 if (keywords_to_use)
520 {
521 if (add && keywords && g_list_length(keywords) > 0)
522 {
523 GList *work;
524
525 work = keywords_to_use;
526 while (work)
518 { 527 {
519 gchar *needle = p->data; 528 gchar *key;
520 p = p->next; 529 GList *p;
521 530
522 if (strcmp(needle, key) == 0) key = NULL; 531 key = work->data;
532 work = work->next;
533
534 p = keywords;
535 while (p && key)
536 {
537 gchar *needle = p->data;
538 p = p->next;
539
540 if (strcmp(needle, key) == 0) key = NULL;
541 }
542
543 if (key) keywords = g_list_append(keywords, g_strdup(key));
523 } 544 }
524 545 save_list = keywords;
525 if (key) keywords = g_list_append(keywords, g_strdup(key)); 546 }
526 } 547 else
527 save_list = keywords; 548 {
528 } 549 save_list = keywords_to_use;
529 else 550 }
530 { 551 }
531 save_list = list; 552
532 }
533
534 comment_write(fd, save_list, comment); 553 comment_write(fd, save_list, comment);
535 554
536 string_list_free(keywords); 555 string_list_free(keywords);
537 g_free(comment); 556 g_free(comment);
538 } 557 }
805 GtkWidget *keyword_treeview; 824 GtkWidget *keyword_treeview;
806 825
807 GtkWidget *comment_view; 826 GtkWidget *comment_view;
808 827
809 GtkWidget *button_save; 828 GtkWidget *button_save;
810 GtkWidget *button_set_add; 829 GtkWidget *button_set_keywords_add;
811 GtkWidget *button_set_replace; 830 GtkWidget *button_set_keywords_replace;
831 GtkWidget *button_set_comment_add;
832 GtkWidget *button_set_comment_replace;
812 833
813 FileData *fd; 834 FileData *fd;
814 835
815 gint changed; 836 gint changed;
816 gint save_timeout_id; 837 gint save_timeout_id;
1077 1098
1078 bar_info_save_update(bd, FALSE); 1099 bar_info_save_update(bd, FALSE);
1079 bar_info_write(bd); 1100 bar_info_write(bd);
1080 } 1101 }
1081 1102
1082 static void bar_info_set_selection(BarInfoData *bd, gint add) 1103 static void bar_info_set_selection(BarInfoData *bd, gint set_keywords, gint set_comment, gint add)
1083 { 1104 {
1084 GList *keywords; 1105 GList *keywords = NULL;
1085 GList *list = NULL; 1106 GList *list = NULL;
1086 GList *work; 1107 GList *work;
1108 gchar *comment = NULL;
1087 1109
1088 if (!bd->list_func) return; 1110 if (!bd->list_func) return;
1089 1111
1090 keywords = keyword_list_pull(bd->keyword_view); 1112 if (set_keywords)
1091 if (!keywords && add) return; 1113 {
1114 keywords = keyword_list_pull(bd->keyword_view);
1115 }
1116
1117 if (set_comment)
1118 {
1119 comment = comment_pull(bd->comment_view);
1120 }
1121
1122 if (add && !keywords && !comment) return;
1092 1123
1093 list = bd->list_func(bd->list_data); 1124 list = bd->list_func(bd->list_data);
1094 work = list; 1125 work = list;
1095 while (work) 1126 while (work)
1096 { 1127 {
1097 FileData *fd = work->data; 1128 FileData *fd = work->data;
1098 work = work->next; 1129 work = work->next;
1099 1130
1100 metadata_set_keywords(fd, keywords, add); 1131 metadata_set_keywords(fd, keywords, comment, add);
1101 } 1132 }
1102 1133
1103 filelist_free(list); 1134 filelist_free(list);
1104 string_list_free(keywords); 1135 string_list_free(keywords);
1105 } 1136 g_free(comment);
1106 1137 }
1107 static void bar_info_set_add(GtkWidget *button, gpointer data) 1138
1139 static void bar_info_set_keywords_add(GtkWidget *button, gpointer data)
1108 { 1140 {
1109 BarInfoData *bd = data; 1141 BarInfoData *bd = data;
1110 1142
1111 bar_info_set_selection(bd, TRUE); 1143 bar_info_set_selection(bd, TRUE, FALSE, TRUE);
1112 } 1144 }
1113 1145
1114 static void bar_info_set_replace(GtkWidget *button, gpointer data) 1146 static void bar_info_set_keywords_replace(GtkWidget *button, gpointer data)
1115 { 1147 {
1116 BarInfoData *bd = data; 1148 BarInfoData *bd = data;
1117 1149
1118 bar_info_set_selection(bd, FALSE); 1150 bar_info_set_selection(bd, TRUE, FALSE, FALSE);
1151 }
1152
1153 static void bar_info_set_comment_add(GtkWidget *button, gpointer data)
1154 {
1155 BarInfoData *bd = data;
1156
1157 bar_info_set_selection(bd, FALSE, TRUE, TRUE);
1158 }
1159
1160 static void bar_info_set_comment_replace(GtkWidget *button, gpointer data)
1161 {
1162 BarInfoData *bd = data;
1163
1164 bar_info_set_selection(bd, FALSE, TRUE, FALSE);
1119 } 1165 }
1120 1166
1121 static void bar_info_changed(GtkTextBuffer *buffer, gpointer data) 1167 static void bar_info_changed(GtkTextBuffer *buffer, gpointer data)
1122 { 1168 {
1123 BarInfoData *bd = data; 1169 BarInfoData *bd = data;
1312 1358
1313 pref_toolbar_button(tbar, GTK_STOCK_INDEX, NULL, FALSE, 1359 pref_toolbar_button(tbar, GTK_STOCK_INDEX, NULL, FALSE,
1314 _("Edit favorite keywords list."), 1360 _("Edit favorite keywords list."),
1315 G_CALLBACK(bar_keyword_edit_cb), bd); 1361 G_CALLBACK(bar_keyword_edit_cb), bd);
1316 pref_toolbar_spacer(tbar); 1362 pref_toolbar_spacer(tbar);
1317 bd->button_set_add = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE, 1363 bd->button_set_keywords_add = pref_toolbar_button(tbar, GTK_STOCK_ADD, NULL, FALSE,
1318 _("Add keywords to selected files"), 1364 _("Add keywords to selected files"),
1319 G_CALLBACK(bar_info_set_add), bd); 1365 G_CALLBACK(bar_info_set_keywords_add), bd);
1320 bd->button_set_replace = pref_toolbar_button(tbar, GTK_STOCK_CONVERT, NULL, FALSE, 1366 bd->button_set_keywords_replace = pref_toolbar_button(tbar, GTK_STOCK_CONVERT, NULL, FALSE,
1321 _("Add keywords to selected files, replacing the existing ones."), 1367 _("Add keywords to selected files, replacing existing ones"),
1322 G_CALLBACK(bar_info_set_replace), bd); 1368 G_CALLBACK(bar_info_set_keywords_replace), bd);
1369 bd->button_set_comment_add = pref_toolbar_button(tbar, GTK_STOCK_DND_MULTIPLE, NULL, FALSE,
1370 _("Add comment to selected files"),
1371 G_CALLBACK(bar_info_set_comment_add), bd);
1372 bd->button_set_comment_replace = pref_toolbar_button(tbar, GTK_STOCK_DND, NULL, FALSE,
1373 _("Add comment to selected files, replacing existing one"),
1374 G_CALLBACK(bar_info_set_comment_replace), bd);
1375
1323 pref_toolbar_spacer(tbar); 1376 pref_toolbar_spacer(tbar);
1324 bd->button_save = pref_toolbar_button(tbar, GTK_STOCK_SAVE, NULL, FALSE, 1377 bd->button_save = pref_toolbar_button(tbar, GTK_STOCK_SAVE, NULL, FALSE,
1325 _("Save comment now"), 1378 _("Save comment now"),
1326 G_CALLBACK(bar_info_save), bd); 1379 G_CALLBACK(bar_info_save), bd);
1327 1380
1356 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data"); 1409 bd = g_object_get_data(G_OBJECT(bar), "bar_info_data");
1357 if (!bd) return; 1410 if (!bd) return;
1358 1411
1359 enable = (count > 0 && bd->list_func != NULL); 1412 enable = (count > 0 && bd->list_func != NULL);
1360 1413
1361 gtk_widget_set_sensitive(bd->button_set_add, enable); 1414 gtk_widget_set_sensitive(bd->button_set_keywords_add, enable);
1362 gtk_widget_set_sensitive(bd->button_set_replace, enable); 1415 gtk_widget_set_sensitive(bd->button_set_keywords_replace, enable);
1363 } 1416 gtk_widget_set_sensitive(bd->button_set_comment_add, enable);
1417 gtk_widget_set_sensitive(bd->button_set_comment_replace, enable);
1418
1419 }