comparison pidgin/gtksavedstatuses.c @ 30229:6d3a90b49dba

propagate from branch 'im.pidgin.pidgin' (head 8587687655d4e11f0965358e8a4378cfa3d1e4e7) to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head 14eca8a36cf4d5e66226c1d94d6d44b5219b1476)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 28 Feb 2010 04:07:39 +0000
parents 551253814063
children 917c597beb97
comparison
equal deleted inserted replaced
30228:221cebbc35d8 30229:6d3a90b49dba
83 STATUS_EDITOR_COLUMN_STATUS_ICON, 83 STATUS_EDITOR_COLUMN_STATUS_ICON,
84 STATUS_EDITOR_NUM_COLUMNS 84 STATUS_EDITOR_NUM_COLUMNS
85 }; 85 };
86 86
87 /** 87 /**
88 * These are used in the GtkComboBox to select the specific 88 * These are used in the GtkComboBox to select the specific PurpleStatusType
89 * PurpleStatusType when setting a substatus for a particular saved 89 * when setting a (sub)status for a particular saved status.
90 * status.
91 */ 90 */
92 enum 91 enum
93 { 92 {
94 SUBSTATUS_COLUMN_ICON, 93 STATUS_COLUMN_ICON,
95 /** A hidden column containing the ID of this PurpleStatusType. */ 94 /** A hidden column containing the ID of this PurpleStatusType. */
96 SUBSTATUS_COLUMN_STATUS_ID, 95 STATUS_COLUMN_STATUS_ID,
97 SUBSTATUS_COLUMN_STATUS_NAME, 96 STATUS_COLUMN_STATUS_NAME,
98 SUBSTATUS_NUM_COLUMNS 97 STATUS_NUM_COLUMNS
99 }; 98 };
100 99
101 typedef struct 100 typedef struct
102 { 101 {
103 GtkWidget *window; 102 GtkWidget *window;
116 GtkButton *saveanduse_button; 115 GtkButton *saveanduse_button;
117 GtkButton *save_button; 116 GtkButton *save_button;
118 117
119 gchar *original_title; 118 gchar *original_title;
120 GtkEntry *title; 119 GtkEntry *title;
121 GtkOptionMenu *type; 120 GtkComboBox *type;
122 GtkIMHtml *message; 121 GtkIMHtml *message;
123 } StatusEditor; 122 } StatusEditor;
124 123
125 typedef struct 124 typedef struct
126 { 125 {
740 purple_notify_error(status_window, NULL, _("Title already in use. You must " 739 purple_notify_error(status_window, NULL, _("Title already in use. You must "
741 "choose a unique title."), NULL); 740 "choose a unique title."), NULL);
742 return; 741 return;
743 } 742 }
744 743
745 type = gtk_option_menu_get_history(dialog->type) + (PURPLE_STATUS_UNSET + 1); 744 type = gtk_combo_box_get_active(dialog->type) + (PURPLE_STATUS_UNSET + 1);
746 message = gtk_imhtml_get_markup(dialog->message); 745 message = gtk_imhtml_get_markup(dialog->message);
747 unformatted = purple_markup_strip_html(message); 746 unformatted = purple_markup_strip_html(message);
748 747
749 /* 748 /*
750 * If we're editing an old status, then lookup the old status. 749 * If we're editing an old status, then lookup the old status.
835 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0')); 834 gtk_widget_set_sensitive(GTK_WIDGET(dialog->saveanduse_button), (*text != '\0'));
836 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0')); 835 gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0'));
837 } 836 }
838 837
839 static GtkWidget * 838 static GtkWidget *
840 create_stock_item(const gchar *str, const gchar *icon)
841 {
842 GtkWidget *menuitem = gtk_menu_item_new();
843 GtkWidget *label = gtk_label_new_with_mnemonic(str);
844 GtkWidget *hbox = gtk_hbox_new(FALSE, 4);
845 GtkIconSize icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
846 GtkWidget *image = gtk_image_new_from_stock(icon, icon_size);;
847
848 gtk_widget_show(label);
849 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
850 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
851 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
852 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
853
854 gtk_container_add(GTK_CONTAINER(menuitem), hbox);
855
856 return menuitem;
857 }
858
859 static GtkWidget *
860 create_status_type_menu(PurpleStatusPrimitive type) 839 create_status_type_menu(PurpleStatusPrimitive type)
861 { 840 {
862 int i; 841 int i;
863 GtkWidget *dropdown; 842 GtkWidget *dropdown;
864 GtkWidget *menu; 843 GtkListStore *store;
865 GtkWidget *item; 844 GtkTreeIter iter;
866 845 GtkCellRenderer *renderer;
867 dropdown = gtk_option_menu_new(); 846
868 menu = gtk_menu_new(); 847 store = gtk_list_store_new(STATUS_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
869 848
870 for (i = PURPLE_STATUS_UNSET + 1; i < PURPLE_STATUS_NUM_PRIMITIVES; i++) 849 for (i = PURPLE_STATUS_UNSET + 1; i < PURPLE_STATUS_NUM_PRIMITIVES; i++)
871 { 850 {
872 if (i == PURPLE_STATUS_MOBILE || i == PURPLE_STATUS_TUNE) 851 /* Someone should fix this for 3.0.0. The independent boolean
852 * should probably be set on the status type, not the status.
853 * I guess that would prevent third party plugins from creating
854 * independent statuses?
855 */
856 if (i == PURPLE_STATUS_MOBILE ||
857 i == PURPLE_STATUS_MOOD ||
858 i == PURPLE_STATUS_TUNE)
873 /* 859 /*
874 * Special-case these. They're intended to be independent 860 * Special-case these. They're intended to be independent
875 * status types, so don't show them in the list. 861 * status types, so don't show them in the list.
876 */ 862 */
877 continue; 863 continue;
878 864
879 item = create_stock_item(purple_primitive_get_name_from_type(i), 865 gtk_list_store_append(store, &iter);
880 get_stock_icon_from_primitive(i)); 866 gtk_list_store_set(store, &iter,
881 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); 867 STATUS_COLUMN_ICON, get_stock_icon_from_primitive(i),
882 } 868 STATUS_COLUMN_STATUS_ID, purple_primitive_get_id_from_type(i),
883 869 STATUS_COLUMN_STATUS_NAME, purple_primitive_get_name_from_type(i),
884 gtk_menu_set_active(GTK_MENU(menu), type - (PURPLE_STATUS_UNSET + 1)); 870 -1);
885 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); 871 }
886 gtk_widget_show_all(menu); 872
873 dropdown = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
874
875 renderer = gtk_cell_renderer_pixbuf_new();
876 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, FALSE);
877 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
878 "stock-id", STATUS_COLUMN_ICON,
879 NULL);
880
881 renderer = gtk_cell_renderer_text_new();
882 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, TRUE);
883 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
884 "text", STATUS_COLUMN_STATUS_NAME,
885 NULL);
886
887 gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown),
888 type - (PURPLE_STATUS_UNSET + 1));
887 889
888 return dropdown; 890 return dropdown;
889 } 891 }
890 892
891 static void edit_substatus(StatusEditor *status_editor, PurpleAccount *account); 893 static void edit_substatus(StatusEditor *status_editor, PurpleAccount *account);
1151 /* Status type */ 1153 /* Status type */
1152 if (saved_status != NULL) 1154 if (saved_status != NULL)
1153 dropdown = create_status_type_menu(purple_savedstatus_get_type(saved_status)); 1155 dropdown = create_status_type_menu(purple_savedstatus_get_type(saved_status));
1154 else 1156 else
1155 dropdown = create_status_type_menu(PURPLE_STATUS_AWAY); 1157 dropdown = create_status_type_menu(PURPLE_STATUS_AWAY);
1156 dialog->type = GTK_OPTION_MENU(dropdown); 1158 dialog->type = GTK_COMBO_BOX(dropdown);
1157 pidgin_add_widget_to_vbox(GTK_BOX(vbox), _("_Status:"), sg, dropdown, TRUE, NULL); 1159 pidgin_add_widget_to_vbox(GTK_BOX(vbox), _("_Status:"), sg, dropdown, TRUE, NULL);
1158 1160
1159 /* Status message */ 1161 /* Status message */
1160 frame = pidgin_create_imhtml(TRUE, &text, &toolbar, NULL); 1162 frame = pidgin_create_imhtml(TRUE, &text, &toolbar, NULL);
1161 dialog->message = GTK_IMHTML(text); 1163 dialog->message = GTK_IMHTML(text);
1266 PurpleStatusType *type; 1268 PurpleStatusType *type;
1267 1269
1268 if (!gtk_combo_box_get_active_iter(box, &iter)) 1270 if (!gtk_combo_box_get_active_iter(box, &iter))
1269 return; 1271 return;
1270 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter, 1272 gtk_tree_model_get(GTK_TREE_MODEL(select->model), &iter,
1271 SUBSTATUS_COLUMN_STATUS_ID, &id, 1273 STATUS_COLUMN_STATUS_ID, &id,
1272 -1); 1274 -1);
1273 type = purple_account_get_status_type(select->account, id); 1275 type = purple_account_get_status_type(select->account, id);
1274 g_free(id); 1276 g_free(id);
1275 1277
1276 if (purple_status_type_get_attr(type, "message") == NULL) 1278 if (purple_status_type_get_attr(type, "message") == NULL)
1357 gtk_widget_destroy(dialog->window); 1359 gtk_widget_destroy(dialog->window);
1358 return; 1360 return;
1359 } 1361 }
1360 1362
1361 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, 1363 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter,
1362 SUBSTATUS_COLUMN_STATUS_ID, &id, 1364 STATUS_COLUMN_STATUS_ID, &id,
1363 -1); 1365 -1);
1364 type = purple_account_get_status_type(dialog->account, id); 1366 type = purple_account_get_status_type(dialog->account, id);
1365 if (purple_status_type_get_attr(type, "message") != NULL) 1367 if (purple_status_type_get_attr(type, "message") != NULL)
1366 message = gtk_imhtml_get_markup(GTK_IMHTML(dialog->message)); 1368 message = gtk_imhtml_get_markup(GTK_IMHTML(dialog->message));
1367 name = purple_status_type_get_name(type); 1369 name = purple_status_type_get_name(type);
1447 label = gtk_label_new_with_mnemonic(_("_Status:")); 1449 label = gtk_label_new_with_mnemonic(_("_Status:"));
1448 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 1450 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1449 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 1451 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1450 gtk_size_group_add_widget(sg, label); 1452 gtk_size_group_add_widget(sg, label);
1451 1453
1452 dialog->model = gtk_list_store_new(SUBSTATUS_NUM_COLUMNS, 1454 dialog->model = gtk_list_store_new(STATUS_NUM_COLUMNS,
1453 G_TYPE_STRING, 1455 G_TYPE_STRING,
1454 G_TYPE_STRING, 1456 G_TYPE_STRING,
1455 G_TYPE_STRING); 1457 G_TYPE_STRING);
1456 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model)); 1458 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dialog->model));
1457 dialog->box = GTK_COMBO_BOX(combo); 1459 dialog->box = GTK_COMBO_BOX(combo);
1460 g_object_set(G_OBJECT(rend), 1462 g_object_set(G_OBJECT(rend),
1461 "stock-size", gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), 1463 "stock-size", gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL),
1462 NULL); 1464 NULL);
1463 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE); 1465 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, FALSE);
1464 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, 1466 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend,
1465 "stock-id", SUBSTATUS_COLUMN_ICON, NULL); 1467 "stock-id", STATUS_COLUMN_ICON, NULL);
1466 1468
1467 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); 1469 rend = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1468 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE); 1470 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), rend, TRUE);
1469 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend, 1471 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), rend,
1470 "text", SUBSTATUS_COLUMN_STATUS_NAME, NULL); 1472 "text", STATUS_COLUMN_STATUS_NAME, NULL);
1471 1473
1472 g_signal_connect(G_OBJECT(combo), "changed", 1474 g_signal_connect(G_OBJECT(combo), "changed",
1473 G_CALLBACK(substatus_selection_changed_cb), dialog); 1475 G_CALLBACK(substatus_selection_changed_cb), dialog);
1474 1476
1475 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); 1477 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
1541 prim = purple_status_type_get_primitive(status_type); 1543 prim = purple_status_type_get_primitive(status_type);
1542 name = purple_status_type_get_name(status_type); 1544 name = purple_status_type_get_name(status_type);
1543 1545
1544 gtk_list_store_append(dialog->model, &iter); 1546 gtk_list_store_append(dialog->model, &iter);
1545 gtk_list_store_set(dialog->model, &iter, 1547 gtk_list_store_set(dialog->model, &iter,
1546 SUBSTATUS_COLUMN_ICON, pidgin_stock_id_from_status_primitive(prim), 1548 STATUS_COLUMN_ICON, pidgin_stock_id_from_status_primitive(prim),
1547 SUBSTATUS_COLUMN_STATUS_ID, id, 1549 STATUS_COLUMN_STATUS_ID, id,
1548 SUBSTATUS_COLUMN_STATUS_NAME, name, 1550 STATUS_COLUMN_STATUS_NAME, name,
1549 -1); 1551 -1);
1550 if ((status_id != NULL) && !strcmp(status_id, id)) 1552 if ((status_id != NULL) && !strcmp(status_id, id))
1551 { 1553 {
1552 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter); 1554 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
1553 select = TRUE; 1555 select = TRUE;