comparison src/gtksavedstatuses.c @ 12329:a83644e2a2a8

[gaim-migrate @ 14633] Add a "Use" and a "Save & Use" button to the New Status window. This makes the window a lot more like the New Status window in 1.5.0. I really do think this is the ideal way to handle this. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 04 Dec 2005 22:49:56 +0000
parents b7a51e68d0b8
children 07d6cc1b5a98
comparison
equal deleted inserted replaced
12328:cdb0e57f4a76 12329:a83644e2a2a8
106 typedef struct 106 typedef struct
107 { 107 {
108 GtkWidget *window; 108 GtkWidget *window;
109 GtkListStore *model; 109 GtkListStore *model;
110 GtkWidget *treeview; 110 GtkWidget *treeview;
111 GtkWidget *save_button; 111 GtkButton *saveanduse_button;
112 GtkButton *save_button;
112 113
113 gchar *original_title; 114 gchar *original_title;
114 GtkEntry *title; 115 GtkEntry *title;
115 GtkOptionMenu *type; 116 GtkOptionMenu *type;
116 GtkIMHtml *message; 117 GtkIMHtml *message;
634 g_free(dialog->original_title); 635 g_free(dialog->original_title);
635 g_free(dialog); 636 g_free(dialog);
636 } 637 }
637 638
638 static void 639 static void
639 status_editor_save_cb(GtkButton *button, gpointer user_data) 640 status_editor_ok_cb(GtkButton *button, gpointer user_data)
640 { 641 {
641 StatusEditor *dialog = user_data; 642 StatusEditor *dialog = user_data;
642 const char *title; 643 const char *title;
643 GaimStatusPrimitive type; 644 GaimStatusPrimitive type;
644 char *message, *unformatted; 645 char *message, *unformatted;
647 GtkTreeIter iter; 648 GtkTreeIter iter;
648 649
649 title = gtk_entry_get_text(dialog->title); 650 title = gtk_entry_get_text(dialog->title);
650 651
651 /* 652 /*
652 * If the title is already taken then show an error dialog and 653 * If we're saving this status, and the title is already taken
653 * don't do anything. 654 * then show an error dialog and don't do anything.
654 */ 655 */
655 if ((gaim_savedstatus_find(title) != NULL) && 656 if (((button == dialog->saveanduse_button) || (button == dialog->save_button)) &&
657 (gaim_savedstatus_find(title) != NULL) &&
656 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title)))) 658 ((dialog->original_title == NULL) || (strcmp(title, dialog->original_title))))
657 { 659 {
658 gaim_notify_error(NULL, NULL, _("Title already in use. You must " 660 gaim_notify_error(NULL, NULL, _("Title already in use. You must "
659 "choose a unique title."), NULL); 661 "choose a unique title."), NULL);
660 return; 662 return;
682 } 684 }
683 685
684 if (saved_status == NULL) 686 if (saved_status == NULL)
685 { 687 {
686 /* This is a new status */ 688 /* This is a new status */
687 saved_status = gaim_savedstatus_new(title, type); 689 if ((button == dialog->saveanduse_button)
690 || (button == dialog->save_button))
691 saved_status = gaim_savedstatus_new(title, type);
692 else
693 saved_status = gaim_savedstatus_new(NULL, type);
688 } 694 }
689 else 695 else
690 { 696 {
691 /* Modify the old status */ 697 /* Modify the old status */
692 if (strcmp(title, dialog->original_title)) 698 if (strcmp(title, dialog->original_title))
746 g_free(dialog->original_title); 752 g_free(dialog->original_title);
747 g_free(dialog); 753 g_free(dialog);
748 754
749 if (status_window != NULL) 755 if (status_window != NULL)
750 add_status_to_saved_status_list(status_window->model, saved_status); 756 add_status_to_saved_status_list(status_window->model, saved_status);
757
758 if ((button == dialog->saveanduse_button)
759 || (button != dialog->save_button))
760 gaim_savedstatus_activate(saved_status);
751 } 761 }
752 762
753 static void 763 static void
754 editor_title_changed_cb(GtkWidget *widget, gpointer user_data) 764 editor_title_changed_cb(GtkWidget *widget, gpointer user_data)
755 { 765 {
756 StatusEditor *dialog = user_data; 766 StatusEditor *dialog = user_data;
757 const gchar *text; 767 const gchar *text;
758 768
759 text = gtk_entry_get_text(dialog->title); 769 text = gtk_entry_get_text(dialog->title);
760 770
761 gtk_widget_set_sensitive(dialog->save_button, (*text != '\0')); 771 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0'));
772 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0'));
762 } 773 }
763 774
764 static GtkWidget * 775 static GtkWidget *
765 create_status_type_menu(GaimStatusPrimitive type) 776 create_status_type_menu(GaimStatusPrimitive type)
766 { 777 {
1133 gtk_widget_show(button); 1144 gtk_widget_show(button);
1134 1145
1135 g_signal_connect(G_OBJECT(button), "clicked", 1146 g_signal_connect(G_OBJECT(button), "clicked",
1136 G_CALLBACK(status_editor_cancel_cb), dialog); 1147 G_CALLBACK(status_editor_cancel_cb), dialog);
1137 1148
1149 /* Use button */
1150 button = gaim_pixbuf_button_from_stock(_("_Use"), GTK_STOCK_EXECUTE,
1151 GAIM_BUTTON_HORIZONTAL);
1152 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
1153 gtk_widget_show(button);
1154
1155 g_signal_connect(G_OBJECT(button), "clicked",
1156 G_CALLBACK(status_editor_ok_cb), dialog);
1157
1158 /* Save & Use button */
1159 button = gaim_pixbuf_button_from_stock(_("Sa_ve & Use"), GTK_STOCK_OK,
1160 GAIM_BUTTON_HORIZONTAL);
1161 dialog->saveanduse_button = GTK_BUTTON(button);
1162 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
1163 if (dialog->original_title == NULL)
1164 gtk_widget_set_sensitive(button, FALSE);
1165 gtk_widget_show(button);
1166
1167 g_signal_connect(G_OBJECT(button), "clicked",
1168 G_CALLBACK(status_editor_ok_cb), dialog);
1169
1138 /* Save button */ 1170 /* Save button */
1139 button = gtk_button_new_from_stock(GTK_STOCK_SAVE); 1171 button = gtk_button_new_from_stock(GTK_STOCK_SAVE);
1140 dialog->save_button = button; 1172 dialog->save_button = GTK_BUTTON(button);
1141 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); 1173 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
1142 if (dialog->title == NULL) 1174 if (dialog->original_title == NULL)
1143 gtk_widget_set_sensitive(button, FALSE); 1175 gtk_widget_set_sensitive(button, FALSE);
1144 gtk_widget_show(button); 1176 gtk_widget_show(button);
1145 1177
1146 g_signal_connect(G_OBJECT(button), "clicked", 1178 g_signal_connect(G_OBJECT(button), "clicked",
1147 G_CALLBACK(status_editor_save_cb), dialog); 1179 G_CALLBACK(status_editor_ok_cb), dialog);
1148 1180
1149 gtk_widget_show(win); 1181 gtk_widget_show(win);
1150 } 1182 }
1151 1183
1152 1184
1446 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); 1478 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
1447 1479
1448 gtk_widget_show(win); 1480 gtk_widget_show(win);
1449 } 1481 }
1450 1482
1483
1451 /************************************************************************** 1484 /**************************************************************************
1452 * Utilities * 1485 * Utilities *
1453 **************************************************************************/ 1486 **************************************************************************/
1454 1487
1455 static void 1488 static void
1471 { 1504 {
1472 GtkWidget *combobox; 1505 GtkWidget *combobox;
1473 const GList *saved_statuses; 1506 const GList *saved_statuses;
1474 int i; 1507 int i;
1475 int index = -1; 1508 int index = -1;
1476 1509
1477 combobox = gtk_combo_box_new_text(); 1510 combobox = gtk_combo_box_new_text();
1478 1511
1479 for (saved_statuses = gaim_savedstatuses_get_all(), i = 0; 1512 for (saved_statuses = gaim_savedstatuses_get_all(), i = 0;
1480 saved_statuses != NULL; 1513 saved_statuses != NULL;
1481 saved_statuses = g_list_next(saved_statuses)) { 1514 saved_statuses = g_list_next(saved_statuses))
1515 {
1482 GaimSavedStatus *status = (GaimSavedStatus*)saved_statuses->data; 1516 GaimSavedStatus *status = (GaimSavedStatus*)saved_statuses->data;
1483 if (!gaim_savedstatus_is_transient(status)) { 1517 if (!gaim_savedstatus_is_transient(status)) {
1484 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), 1518 gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
1485 gaim_savedstatus_get_title(status)); 1519 gaim_savedstatus_get_title(status));
1486 if (status == current_status) 1520 if (status == current_status)
1487 index = i; 1521 index = i;
1488 i++; 1522 i++;
1489 } 1523 }
1490 } 1524 }
1491 1525
1492 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index); 1526 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index);
1493 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback); 1527 g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback);
1528
1494 return combobox; 1529 return combobox;
1495 } 1530 }
1496 1531
1497 1532
1498 /************************************************************************** 1533 /**************************************************************************