Mercurial > pidgin.yaz
changeset 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 | a1d5f154585b |
children | bfd7b9e3c705 |
files | src/gtksavedstatuses.c |
diffstat | 1 files changed, 111 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtksavedstatuses.c Tue Feb 07 01:43:27 2006 +0000 +++ b/src/gtksavedstatuses.c Tue Feb 07 01:56:50 2006 +0000 @@ -55,6 +55,8 @@ STATUS_WINDOW_COLUMN_TITLE, STATUS_WINDOW_COLUMN_TYPE, STATUS_WINDOW_COLUMN_MESSAGE, + /** pointer to open window for this saved status */ + STATUS_WINDOW_COLUMN_WINDOW, STATUS_WINDOW_NUM_COLUMNS }; @@ -67,6 +69,8 @@ { /** A hidden column containing a pointer to the GaimAccount */ STATUS_EDITOR_COLUMN_ACCOUNT, + /** A hidden column containing a pointer to the substatus dialog */ + STATUS_EDITOR_COLUMN_WINDOW, STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, STATUS_EDITOR_COLUMN_ICON, STATUS_EDITOR_COLUMN_SCREENNAME, @@ -139,9 +143,14 @@ static gboolean status_window_find_savedstatus(GtkTreeIter *iter, const char *title) { - GtkTreeModel *model = GTK_TREE_MODEL(status_window->model); + GtkTreeModel *model; char *cur; + if (status_window == NULL) + return FALSE; + + model = GTK_TREE_MODEL(status_window->model); + if (!gtk_tree_model_get_iter_first(model, iter)) return FALSE; @@ -414,7 +423,8 @@ dialog->model = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_STRING, + G_TYPE_POINTER); /* Create the treeview */ treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); @@ -616,11 +626,25 @@ * Status editor **************************************************************************/ +static void +status_editor_remove_dialog(StatusEditor *dialog) +{ + GtkTreeIter iter; + if (status_window_find_savedstatus(&iter, dialog->original_title)) { + gtk_list_store_set(status_window->model, &iter, + STATUS_WINDOW_COLUMN_WINDOW, NULL, + -1); + } +} + + static gboolean status_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) { StatusEditor *dialog = user_data; + status_editor_remove_dialog(dialog); + g_free(dialog->original_title); g_free(dialog); @@ -632,6 +656,8 @@ { StatusEditor *dialog = user_data; + status_editor_remove_dialog(dialog); + gtk_widget_destroy(dialog->window); g_free(dialog->original_title); @@ -709,30 +735,14 @@ /* Set any substatuses */ model = GTK_TREE_MODEL(dialog->model); - if (gtk_tree_model_get_iter_first(model, &iter)) - { - GaimAccount *account; - gboolean enabled; - char *id; - char *message; - GaimStatusType *type; + if (gtk_tree_model_get_iter_first(model, &iter)) { + do { + GaimAccount *account; + gboolean enabled; + char *id; + char *message; + GaimStatusType *type; - gtk_tree_model_get(model, &iter, - STATUS_EDITOR_COLUMN_ACCOUNT, &account, - STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, - STATUS_EDITOR_COLUMN_STATUS_ID, &id, - STATUS_EDITOR_COLUMN_STATUS_MESSAGE, &message, - -1); - if (enabled) - { - type = gaim_account_get_status_type(account, id); - gaim_savedstatus_set_substatus(saved_status, account, type, message); - } - g_free(id); - g_free(message); - - while (gtk_tree_model_iter_next(model, &iter)) - { gtk_tree_model_get(model, &iter, STATUS_EDITOR_COLUMN_ACCOUNT, &account, STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, &enabled, @@ -746,7 +756,7 @@ } g_free(id); g_free(message); - } + } while (gtk_tree_model_iter_next(model, &iter)); } g_free(message); @@ -989,6 +999,7 @@ void gaim_gtk_status_editor_show(GaimSavedStatus *saved_status) { + GtkTreeIter iter; StatusEditor *dialog; GtkSizeGroup *sg; GtkWidget *bbox; @@ -1007,7 +1018,23 @@ GtkWidget *win; GList *focus_chain = NULL; + /* Find a possible window for this saved status and present it */ + if (status_window) { + status_window_find_savedstatus(&iter, gaim_savedstatus_get_title(saved_status)); + gtk_tree_model_get(GTK_TREE_MODEL(status_window->model), &iter, + STATUS_WINDOW_COLUMN_WINDOW, &dialog, + -1); + if (dialog) { + gtk_window_present(GTK_WINDOW(dialog->window)); + return; + } + } + dialog = g_new0(StatusEditor, 1); + if (status_window) + gtk_list_store_set(status_window->model, &iter, + STATUS_WINDOW_COLUMN_WINDOW, dialog, + -1); if (saved_status != NULL) dialog->original_title = g_strdup(gaim_savedstatus_get_title(saved_status)); @@ -1111,6 +1138,7 @@ /* Create the list model */ dialog->model = gtk_list_store_new(STATUS_EDITOR_NUM_COLUMNS, G_TYPE_POINTER, + G_TYPE_POINTER, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_STRING, @@ -1217,26 +1245,6 @@ } static gboolean -substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) -{ - SubStatusEditor *dialog = user_data; - - g_free(dialog); - - return FALSE; -} - -static void -substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) -{ - SubStatusEditor *dialog = user_data; - - gtk_widget_destroy(dialog->window); - - g_free(dialog); -} - -static gboolean status_editor_find_account_in_treemodel(GtkTreeIter *iter, StatusEditor *status_editor, GaimAccount *account) @@ -1267,6 +1275,48 @@ } static void +substatus_editor_remove_dialog(SubStatusEditor *dialog) +{ + GtkTreeIter iter; + GaimAccount *account; + + gtk_combo_box_get_active_iter(dialog->box, &iter); + + gtk_tree_model_get(GTK_TREE_MODEL(dialog->model), &iter, + SUBSTATUS_COLUMN_ACCOUNT, &account, + -1); + + if (status_editor_find_account_in_treemodel(&iter, dialog->status_editor, account)) { + gtk_list_store_set(dialog->status_editor->model, &iter, + STATUS_EDITOR_COLUMN_WINDOW, NULL, + -1); + } +} + +static gboolean +substatus_editor_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + SubStatusEditor *dialog = user_data; + substatus_editor_remove_dialog(dialog); + + g_free(dialog); + + return FALSE; +} + +static void +substatus_editor_cancel_cb(GtkButton *button, gpointer user_data) +{ + SubStatusEditor *dialog = user_data; + substatus_editor_remove_dialog(dialog); + + gtk_widget_destroy(dialog->window); + + g_free(dialog); +} + + +static void substatus_editor_ok_cb(GtkButton *button, gpointer user_data) { SubStatusEditor *dialog = user_data; @@ -1302,6 +1352,7 @@ STATUS_EDITOR_COLUMN_STATUS_ID, id, STATUS_EDITOR_COLUMN_STATUS_NAME, name, STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, + STATUS_EDITOR_COLUMN_WINDOW, NULL, -1); } @@ -1336,7 +1387,19 @@ g_return_if_fail(status_editor != NULL); g_return_if_fail(account != NULL); + status_editor_find_account_in_treemodel(&iter, status_editor, account); + gtk_tree_model_get(GTK_TREE_MODEL(status_editor->model), &iter, + STATUS_EDITOR_COLUMN_WINDOW, &dialog, + -1); + if (dialog) { + gtk_window_present(GTK_WINDOW(dialog->window)); + return; + } + dialog = g_new0(SubStatusEditor, 1); + gtk_list_store_set(status_editor->model, &iter, + STATUS_EDITOR_COLUMN_WINDOW, dialog, + -1); dialog->status_editor = status_editor; dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -1349,6 +1412,8 @@ g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(substatus_editor_destroy_cb), dialog); + g_signal_connect(G_OBJECT(status_editor->window), "destroy", + G_CALLBACK(substatus_editor_cancel_cb), dialog); /* Setup the vbox */ vbox = gtk_vbox_new(FALSE, GAIM_HIG_BORDER);