Mercurial > pidgin.yaz
comparison src/gtksavedstatuses.c @ 13144:e90e8655290d
[gaim-migrate @ 15507]
SF Patch #1414303 from Richard Nelson (wabz)
"The updated attached patch
- prevents duplicate saved status windows appearing (from
the saved status window)
- prevents duplicate sub (per-account) status windows
- destroys sub (per-account) status windows if that status
window is closed/destroyed
- removes some trivial duplicated code"
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 07 Feb 2006 01:56:50 +0000 |
parents | 39e7014cb687 |
children | 12d960995cdc |
comparison
equal
deleted
inserted
replaced
13143:a1d5f154585b | 13144:e90e8655290d |
---|---|
53 enum | 53 enum |
54 { | 54 { |
55 STATUS_WINDOW_COLUMN_TITLE, | 55 STATUS_WINDOW_COLUMN_TITLE, |
56 STATUS_WINDOW_COLUMN_TYPE, | 56 STATUS_WINDOW_COLUMN_TYPE, |
57 STATUS_WINDOW_COLUMN_MESSAGE, | 57 STATUS_WINDOW_COLUMN_MESSAGE, |
58 /** pointer to open window for this saved status */ | |
59 STATUS_WINDOW_COLUMN_WINDOW, | |
58 STATUS_WINDOW_NUM_COLUMNS | 60 STATUS_WINDOW_NUM_COLUMNS |
59 }; | 61 }; |
60 | 62 |
61 /** | 63 /** |
62 * These is used for the GtkTreeView containing the list of accounts | 64 * These is used for the GtkTreeView containing the list of accounts |
65 */ | 67 */ |
66 enum | 68 enum |
67 { | 69 { |
68 /** A hidden column containing a pointer to the GaimAccount */ | 70 /** A hidden column containing a pointer to the GaimAccount */ |
69 STATUS_EDITOR_COLUMN_ACCOUNT, | 71 STATUS_EDITOR_COLUMN_ACCOUNT, |
72 /** A hidden column containing a pointer to the substatus dialog */ | |
73 STATUS_EDITOR_COLUMN_WINDOW, | |
70 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, | 74 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, |
71 STATUS_EDITOR_COLUMN_ICON, | 75 STATUS_EDITOR_COLUMN_ICON, |
72 STATUS_EDITOR_COLUMN_SCREENNAME, | 76 STATUS_EDITOR_COLUMN_SCREENNAME, |
73 /** A hidden column containing the ID of this GaimStatusType. */ | 77 /** A hidden column containing the ID of this GaimStatusType. */ |
74 STATUS_EDITOR_COLUMN_STATUS_ID, | 78 STATUS_EDITOR_COLUMN_STATUS_ID, |
137 **************************************************************************/ | 141 **************************************************************************/ |
138 | 142 |
139 static gboolean | 143 static gboolean |
140 status_window_find_savedstatus(GtkTreeIter *iter, const char *title) | 144 status_window_find_savedstatus(GtkTreeIter *iter, const char *title) |
141 { | 145 { |
142 GtkTreeModel *model = GTK_TREE_MODEL(status_window->model); | 146 GtkTreeModel *model; |
143 char *cur; | 147 char *cur; |
148 | |
149 if (status_window == NULL) | |
150 return FALSE; | |
151 | |
152 model = GTK_TREE_MODEL(status_window->model); | |
144 | 153 |
145 if (!gtk_tree_model_get_iter_first(model, iter)) | 154 if (!gtk_tree_model_get_iter_first(model, iter)) |
146 return FALSE; | 155 return FALSE; |
147 | 156 |
148 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); | 157 gtk_tree_model_get(model, iter, STATUS_WINDOW_COLUMN_TITLE, &cur, -1); |
412 | 421 |
413 /* Create the list model */ | 422 /* Create the list model */ |
414 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, | 423 dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, |
415 G_TYPE_STRING, | 424 G_TYPE_STRING, |
416 G_TYPE_STRING, | 425 G_TYPE_STRING, |
417 G_TYPE_STRING); | 426 G_TYPE_STRING, |
427 G_TYPE_POINTER); | |
418 | 428 |
419 /* Create the treeview */ | 429 /* Create the treeview */ |
420 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | 430 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); |
421 dialog->treeview = treeview; | 431 dialog->treeview = treeview; |
422 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | 432 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); |
614 | 624 |
615 /************************************************************************** | 625 /************************************************************************** |
616 * Status editor | 626 * Status editor |
617 **************************************************************************/ | 627 **************************************************************************/ |
618 | 628 |
629 static void | |
630 status_editor_remove_dialog(StatusEditor *dialog) | |
631 { | |
632 GtkTreeIter iter; | |
633 if (status_window_find_savedstatus(&iter, dialog->original_title)) { | |
634 gtk_list_store_set(status_window->model, &iter, | |
635 STATUS_WINDOW_COLUMN_WINDOW, NULL, | |
636 -1); | |
637 } | |
638 } | |
639 | |
640 | |
619 static gboolean | 641 static gboolean |
620 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | 642 status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
621 { | 643 { |
622 StatusEditor *dialog = user_data; | 644 StatusEditor *dialog = user_data; |
623 | 645 |
646 status_editor_remove_dialog(dialog); | |
647 | |
624 g_free(dialog->original_title); | 648 g_free(dialog->original_title); |
625 g_free(dialog); | 649 g_free(dialog); |
626 | 650 |
627 return FALSE; | 651 return FALSE; |
628 } | 652 } |
629 | 653 |
630 static void | 654 static void |
631 status_editor_cancel_cb(GtkButton *button, gpointer user_data) | 655 status_editor_cancel_cb(GtkButton *button, gpointer user_data) |
632 { | 656 { |
633 StatusEditor *dialog = user_data; | 657 StatusEditor *dialog = user_data; |
658 | |
659 status_editor_remove_dialog(dialog); | |
634 | 660 |
635 gtk_widget_destroy(dialog->window); | 661 gtk_widget_destroy(dialog->window); |
636 | 662 |
637 g_free(dialog->original_title); | 663 g_free(dialog->original_title); |
638 g_free(dialog); | 664 g_free(dialog); |
707 else | 733 else |
708 gaim_savedstatus_set_message(saved_status, message); | 734 gaim_savedstatus_set_message(saved_status, message); |
709 | 735 |
710 /* Set any substatuses */ | 736 /* Set any substatuses */ |
711 model = GTK_TREE_MODEL(dialog->model); | 737 model = GTK_TREE_MODEL(dialog->model); |
712 if (gtk_tree_model_get_iter_first(model, &iter)) | 738 if (gtk_tree_model_get_iter_first(model, &iter)) { |
713 { | 739 do { |
714 GaimAccount *account; | 740 GaimAccount *account; |
715 gboolean enabled; | 741 gboolean enabled; |
716 char *id; | 742 char *id; |
717 char *message; | 743 char *message; |
718 GaimStatusType *type; | 744 GaimStatusType *type; |
719 | 745 |
720 gtk_tree_model_get(model, &iter, | |
721 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | |
722 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | |
723 STATUS_EDITOR_COLUMN_STATUS_ID, &id, | |
724 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, | |
725 -1); | |
726 if (enabled) | |
727 { | |
728 type = gaim_account_get_status_type(account, id); | |
729 gaim_savedstatus_set_substatus(saved_status, account, type, message); | |
730 } | |
731 g_free(id); | |
732 g_free(message); | |
733 | |
734 while (gtk_tree_model_iter_next(model, &iter)) | |
735 { | |
736 gtk_tree_model_get(model, &iter, | 746 gtk_tree_model_get(model, &iter, |
737 STATUS_EDITOR_COLUMN_ACCOUNT, &account, | 747 STATUS_EDITOR_COLUMN_ACCOUNT, &account, |
738 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, | 748 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, |
739 STATUS_EDITOR_COLUMN_STATUS_ID, &id, | 749 STATUS_EDITOR_COLUMN_STATUS_ID, &id, |
740 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, | 750 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, |
744 type = gaim_account_get_status_type(account, id); | 754 type = gaim_account_get_status_type(account, id); |
745 gaim_savedstatus_set_substatus(saved_status, account, type, message); | 755 gaim_savedstatus_set_substatus(saved_status, account, type, message); |
746 } | 756 } |
747 g_free(id); | 757 g_free(id); |
748 g_free(message); | 758 g_free(message); |
749 } | 759 } while (gtk_tree_model_iter_next(model, &iter)); |
750 } | 760 } |
751 | 761 |
752 g_free(message); | 762 g_free(message); |
753 g_free(unformatted); | 763 g_free(unformatted); |
754 | 764 |
987 } | 997 } |
988 | 998 |
989 void | 999 void |
990 gaim_gtk_status_editor_show(GaimSavedStatus *saved_status) | 1000 gaim_gtk_status_editor_show(GaimSavedStatus *saved_status) |
991 { | 1001 { |
1002 GtkTreeIter iter; | |
992 StatusEditor *dialog; | 1003 StatusEditor *dialog; |
993 GtkSizeGroup *sg; | 1004 GtkSizeGroup *sg; |
994 GtkWidget *bbox; | 1005 GtkWidget *bbox; |
995 GtkWidget *button; | 1006 GtkWidget *button; |
996 GtkWidget *dbox; | 1007 GtkWidget *dbox; |
1005 GtkWidget *toolbar; | 1016 GtkWidget *toolbar; |
1006 GtkWidget *vbox; | 1017 GtkWidget *vbox; |
1007 GtkWidget *win; | 1018 GtkWidget *win; |
1008 GList *focus_chain = NULL; | 1019 GList *focus_chain = NULL; |
1009 | 1020 |
1021 /* Find a possible window for this saved status and present it */ | |
1022 if (status_window) { | |
1023 status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status)); | |
1024 gtk_tree_model_get(GTK_TREE_MODEL(status_window->model), &iter, | |
1025 STATUS_WINDOW_COLUMN_WINDOW, &dialog, | |
1026 -1); | |
1027 if (dialog) { | |
1028 gtk_window_present(GTK_WINDOW(dialog->window)); | |
1029 return; | |
1030 } | |
1031 } | |
1032 | |
1010 dialog = g_new0(StatusEditor, 1); | 1033 dialog = g_new0(StatusEditor, 1); |
1034 if (status_window) | |
1035 gtk_list_store_set(status_window->model, &iter, | |
1036 STATUS_WINDOW_COLUMN_WINDOW, dialog, | |
1037 -1); | |
1011 | 1038 |
1012 if (saved_status != NULL) | 1039 if (saved_status != NULL) |
1013 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); | 1040 dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); |
1014 | 1041 |
1015 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 1042 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1109 gtk_widget_show(sw); | 1136 gtk_widget_show(sw); |
1110 | 1137 |
1111 /* Create the list model */ | 1138 /* Create the list model */ |
1112 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, | 1139 dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, |
1113 G_TYPE_POINTER, | 1140 G_TYPE_POINTER, |
1141 G_TYPE_POINTER, | |
1114 G_TYPE_BOOLEAN, | 1142 G_TYPE_BOOLEAN, |
1115 GDK_TYPE_PIXBUF, | 1143 GDK_TYPE_PIXBUF, |
1116 G_TYPE_STRING, | 1144 G_TYPE_STRING, |
1117 G_TYPE_STRING, | 1145 G_TYPE_STRING, |
1118 G_TYPE_STRING, | 1146 G_TYPE_STRING, |
1215 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); | 1243 gtk_widget_set_sensitive(GTK_WIDGET(select->toolbar), TRUE); |
1216 } | 1244 } |
1217 } | 1245 } |
1218 | 1246 |
1219 static gboolean | 1247 static gboolean |
1220 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
1221 { | |
1222 SubStatusEditor *dialog = user_data; | |
1223 | |
1224 g_free(dialog); | |
1225 | |
1226 return FALSE; | |
1227 } | |
1228 | |
1229 static void | |
1230 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
1231 { | |
1232 SubStatusEditor *dialog = user_data; | |
1233 | |
1234 gtk_widget_destroy(dialog->window); | |
1235 | |
1236 g_free(dialog); | |
1237 } | |
1238 | |
1239 static gboolean | |
1240 status_editor_find_account_in_treemodel(GtkTreeIter *iter, | 1248 status_editor_find_account_in_treemodel(GtkTreeIter *iter, |
1241 StatusEditor *status_editor, | 1249 StatusEditor *status_editor, |
1242 GaimAccount *account) | 1250 GaimAccount *account) |
1243 { | 1251 { |
1244 GtkTreeModel *model; | 1252 GtkTreeModel *model; |
1263 return TRUE; | 1271 return TRUE; |
1264 } | 1272 } |
1265 | 1273 |
1266 return FALSE; | 1274 return FALSE; |
1267 } | 1275 } |
1276 | |
1277 static void | |
1278 substatus_editor_remove_dialog(SubStatusEditor *dialog) | |
1279 { | |
1280 GtkTreeIter iter; | |
1281 GaimAccount *account; | |
1282 | |
1283 gtk_combo_box_get_active_iter(dialog->box, &iter); | |
1284 | |
1285 gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, | |
1286 SUBSTATUS_COLUMN_ACCOUNT, &account, | |
1287 -1); | |
1288 | |
1289 if (status_editor_find_account_in_treemodel(&iter, dialog->status_editor, account)) { | |
1290 gtk_list_store_set(dialog->status_editor->model, &iter, | |
1291 STATUS_EDITOR_COLUMN_WINDOW, NULL, | |
1292 -1); | |
1293 } | |
1294 } | |
1295 | |
1296 static gboolean | |
1297 substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) | |
1298 { | |
1299 SubStatusEditor *dialog = user_data; | |
1300 substatus_editor_remove_dialog(dialog); | |
1301 | |
1302 g_free(dialog); | |
1303 | |
1304 return FALSE; | |
1305 } | |
1306 | |
1307 static void | |
1308 substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) | |
1309 { | |
1310 SubStatusEditor *dialog = user_data; | |
1311 substatus_editor_remove_dialog(dialog); | |
1312 | |
1313 gtk_widget_destroy(dialog->window); | |
1314 | |
1315 g_free(dialog); | |
1316 } | |
1317 | |
1268 | 1318 |
1269 static void | 1319 static void |
1270 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) | 1320 substatus_editor_ok_cb(GtkButton *button, gpointer user_data) |
1271 { | 1321 { |
1272 SubStatusEditor *dialog = user_data; | 1322 SubStatusEditor *dialog = user_data; |
1300 gtk_list_store_set(status_editor->model, &iter, | 1350 gtk_list_store_set(status_editor->model, &iter, |
1301 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, | 1351 STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, TRUE, |
1302 STATUS_EDITOR_COLUMN_STATUS_ID, id, | 1352 STATUS_EDITOR_COLUMN_STATUS_ID, id, |
1303 STATUS_EDITOR_COLUMN_STATUS_NAME, name, | 1353 STATUS_EDITOR_COLUMN_STATUS_NAME, name, |
1304 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, | 1354 STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, |
1355 STATUS_EDITOR_COLUMN_WINDOW, NULL, | |
1305 -1); | 1356 -1); |
1306 } | 1357 } |
1307 | 1358 |
1308 gtk_widget_destroy(dialog->window); | 1359 gtk_widget_destroy(dialog->window); |
1309 g_free(id); | 1360 g_free(id); |
1334 gboolean select = FALSE; | 1385 gboolean select = FALSE; |
1335 | 1386 |
1336 g_return_if_fail(status_editor != NULL); | 1387 g_return_if_fail(status_editor != NULL); |
1337 g_return_if_fail(account != NULL); | 1388 g_return_if_fail(account != NULL); |
1338 | 1389 |
1390 status_editor_find_account_in_treemodel(&iter, status_editor, account); | |
1391 gtk_tree_model_get(GTK_TREE_MODEL(status_editor->model), &iter, | |
1392 STATUS_EDITOR_COLUMN_WINDOW, &dialog, | |
1393 -1); | |
1394 if (dialog) { | |
1395 gtk_window_present(GTK_WINDOW(dialog->window)); | |
1396 return; | |
1397 } | |
1398 | |
1339 dialog = g_new0(SubStatusEditor, 1); | 1399 dialog = g_new0(SubStatusEditor, 1); |
1400 gtk_list_store_set(status_editor->model, &iter, | |
1401 STATUS_EDITOR_COLUMN_WINDOW, dialog, | |
1402 -1); | |
1340 dialog->status_editor = status_editor; | 1403 dialog->status_editor = status_editor; |
1341 | 1404 |
1342 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 1405 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1343 gtk_window_set_role(GTK_WINDOW(win), "substatus"); | 1406 gtk_window_set_role(GTK_WINDOW(win), "substatus"); |
1344 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); | 1407 tmp = g_strdup_printf(_("Status for %s"), gaim_account_get_username(account)); |
1347 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); | 1410 gtk_window_set_resizable(GTK_WINDOW(win), FALSE); |
1348 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); | 1411 gtk_container_set_border_width(GTK_CONTAINER(win), GAIM_HIG_BORDER); |
1349 | 1412 |
1350 g_signal_connect(G_OBJECT(win), "delete_event", | 1413 g_signal_connect(G_OBJECT(win), "delete_event", |
1351 G_CALLBACK(substatus_editor_destroy_cb), dialog); | 1414 G_CALLBACK(substatus_editor_destroy_cb), dialog); |
1415 g_signal_connect(G_OBJECT(status_editor->window), "destroy", | |
1416 G_CALLBACK(substatus_editor_cancel_cb), dialog); | |
1352 | 1417 |
1353 /* Setup the vbox */ | 1418 /* Setup the vbox */ |
1354 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); | 1419 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER); |
1355 gtk_container_add(GTK_CONTAINER(win), vbox); | 1420 gtk_container_add(GTK_CONTAINER(win), vbox); |
1356 gtk_widget_show(vbox); | 1421 gtk_widget_show(vbox); |