Mercurial > pidgin.yaz
comparison src/gtkutils.c @ 13364:3b7abce487f5
[gaim-migrate @ 15737]
A patch from Sadrul to update the screenname autocomplete list when accounts are added/deleted or sign on/sign off.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 01 Mar 2006 07:27:09 +0000 |
parents | 2e6dda9f9159 |
children | 143233089386 |
comparison
equal
deleted
inserted
replaced
13363:ef5287de40b5 | 13364:3b7abce487f5 |
---|---|
1733 } | 1733 } |
1734 gaim_menu_action_free(act); | 1734 gaim_menu_action_free(act); |
1735 } | 1735 } |
1736 } | 1736 } |
1737 | 1737 |
1738 | |
1739 #if GTK_CHECK_VERSION(2,3,0) | 1738 #if GTK_CHECK_VERSION(2,3,0) |
1740 # define NEW_STYLE_COMPLETION | 1739 # define NEW_STYLE_COMPLETION |
1741 #endif | 1740 #endif |
1742 | 1741 |
1743 #ifndef NEW_STYLE_COMPLETION | 1742 #ifndef NEW_STYLE_COMPLETION |
1744 typedef struct | 1743 typedef struct |
1745 { | 1744 { |
1746 GCompletion *completion; | 1745 GCompletion *completion; |
1747 | 1746 |
1748 gboolean completion_started; | 1747 gboolean completion_started; |
1748 gboolean all; | |
1749 | 1749 |
1750 } GaimGtkCompletionData; | 1750 } GaimGtkCompletionData; |
1751 #endif | 1751 #endif |
1752 | 1752 |
1753 #ifndef NEW_STYLE_COMPLETION | 1753 #ifndef NEW_STYLE_COMPLETION |
1998 set->name = set->normalized_name = NULL; | 1998 set->name = set->normalized_name = NULL; |
1999 #endif /* NEW_STYLE_COMPLETION */ | 1999 #endif /* NEW_STYLE_COMPLETION */ |
2000 } | 2000 } |
2001 } | 2001 } |
2002 | 2002 |
2003 void | |
2004 gaim_gtk_setup_screenname_autocomplete(GtkWidget *entry, GtkWidget *accountopt, gboolean all) | |
2005 { | |
2006 #ifdef NEW_STYLE_COMPLETION | 2003 #ifdef NEW_STYLE_COMPLETION |
2007 /* Store the displayed completion value, the screenname, the UTF-8 normalized & casefolded screenname, | 2004 static void |
2008 * the UTF-8 normalized & casefolded value for comparison, and the account. */ | 2005 add_completion_list(GtkListStore *store) |
2009 GtkListStore *store; | 2006 { |
2010 | |
2011 GaimBlistNode *gnode, *cnode, *bnode; | 2007 GaimBlistNode *gnode, *cnode, *bnode; |
2008 gboolean all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(store), "screenname-all")); | |
2012 GHashTable *sets; | 2009 GHashTable *sets; |
2013 gpointer set_hash_data[2]; | 2010 gpointer set_hash_data[] = {store, GINT_TO_POINTER(all)}; |
2014 GtkEntryCompletion *completion; | 2011 |
2015 gpointer *data; | 2012 gtk_list_store_clear(store); |
2016 | |
2017 g_return_if_fail(entry != NULL); | |
2018 | |
2019 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); | |
2020 set_hash_data[0] = store; | |
2021 set_hash_data[1] = GINT_TO_POINTER(all); | |
2022 | 2013 |
2023 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) | 2014 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) |
2024 { | 2015 { |
2025 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | 2016 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
2026 continue; | 2017 continue; |
2048 } | 2039 } |
2049 | 2040 |
2050 sets = gaim_log_get_log_sets(); | 2041 sets = gaim_log_get_log_sets(); |
2051 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data); | 2042 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data); |
2052 g_hash_table_destroy(sets); | 2043 g_hash_table_destroy(sets); |
2053 | 2044 } |
2045 #else | |
2046 static void | |
2047 add_completion_list(GaimGtkCompletionData *data) | |
2048 { | |
2049 GaimBlistNode *gnode, *cnode, *bnode; | |
2050 GCompletion *completion; | |
2051 GList *item = g_list_append(NULL, NULL); | |
2052 GHashTable *sets; | |
2053 gpointer set_hash_data[2]; | |
2054 | |
2055 completion = data->completion; | |
2056 | |
2057 g_list_foreach(completion->items, (GFunc)g_free, NULL); | |
2058 g_completion_clear_items(completion); | |
2059 | |
2060 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) | |
2061 { | |
2062 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
2063 continue; | |
2064 | |
2065 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) | |
2066 { | |
2067 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
2068 continue; | |
2069 | |
2070 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) | |
2071 { | |
2072 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
2073 | |
2074 if (!data->all && !gaim_account_is_connected(buddy->account)) | |
2075 continue; | |
2076 | |
2077 item->data = g_strdup(buddy->name); | |
2078 g_completion_add_items(data->completion, item); | |
2079 } | |
2080 } | |
2081 } | |
2082 g_list_free(item); | |
2083 | |
2084 sets = gaim_log_get_log_sets(); | |
2085 item = NULL; | |
2086 set_hash_data[0] = &item; | |
2087 set_hash_data[1] = GINT_TO_POINTER(data->all); | |
2088 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data); | |
2089 g_hash_table_destroy(sets); | |
2090 g_completion_add_items(data->completion, item); | |
2091 g_list_free(item); | |
2092 } | |
2093 #endif | |
2094 | |
2095 static void | |
2096 screenname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer null) | |
2097 { | |
2098 gaim_signals_disconnect_by_handle(widget); | |
2099 } | |
2100 | |
2101 static void | |
2102 repopulate_autocomplete(gpointer something, gpointer data) | |
2103 { | |
2104 add_completion_list(data); | |
2105 } | |
2106 | |
2107 void | |
2108 gaim_gtk_setup_screenname_autocomplete(GtkWidget *entry, GtkWidget *accountopt, gboolean all) | |
2109 { | |
2110 gpointer cb_data = NULL; | |
2111 | |
2112 #ifdef NEW_STYLE_COMPLETION | |
2113 /* Store the displayed completion value, the screenname, the UTF-8 normalized & casefolded screenname, | |
2114 * the UTF-8 normalized & casefolded value for comparison, and the account. */ | |
2115 GtkListStore *store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); | |
2116 | |
2117 GtkEntryCompletion *completion; | |
2118 gpointer *data; | |
2119 | |
2120 g_object_set_data(G_OBJECT(store), "screenname-all", GINT_TO_POINTER(all)); | |
2121 add_completion_list(store); | |
2122 | |
2123 cb_data = store; | |
2054 | 2124 |
2055 /* Sort the completion list by screenname. */ | 2125 /* Sort the completion list by screenname. */ |
2056 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), | 2126 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
2057 1, GTK_SORT_ASCENDING); | 2127 1, GTK_SORT_ASCENDING); |
2058 | 2128 |
2073 | 2143 |
2074 gtk_entry_completion_set_text_column(completion, 0); | 2144 gtk_entry_completion_set_text_column(completion, 0); |
2075 | 2145 |
2076 #else /* !NEW_STYLE_COMPLETION */ | 2146 #else /* !NEW_STYLE_COMPLETION */ |
2077 GaimGtkCompletionData *data; | 2147 GaimGtkCompletionData *data; |
2078 GaimBlistNode *gnode, *cnode, *bnode; | |
2079 GList *item = g_list_append(NULL, NULL); | |
2080 GHashTable *sets; | |
2081 gpointer set_hash_data[2]; | |
2082 | |
2083 g_return_if_fail(entry != NULL); | |
2084 | 2148 |
2085 data = g_new0(GaimGtkCompletionData, 1); | 2149 data = g_new0(GaimGtkCompletionData, 1); |
2086 | 2150 |
2087 data->completion = g_completion_new(NULL); | 2151 data->completion = g_completion_new(NULL); |
2152 data->all = all; | |
2088 | 2153 |
2089 g_completion_set_compare(data->completion, g_ascii_strncasecmp); | 2154 g_completion_set_compare(data->completion, g_ascii_strncasecmp); |
2090 | 2155 |
2091 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) | 2156 add_completion_list(data); |
2092 { | 2157 cb_data = data; |
2093 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
2094 continue; | |
2095 | |
2096 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) | |
2097 { | |
2098 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
2099 continue; | |
2100 | |
2101 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) | |
2102 { | |
2103 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
2104 | |
2105 if (!all && !gaim_account_is_connected(buddy->account)) | |
2106 continue; | |
2107 | |
2108 item->data = g_strdup(buddy->name); | |
2109 g_completion_add_items(data->completion, item); | |
2110 } | |
2111 } | |
2112 } | |
2113 g_list_free(item); | |
2114 | |
2115 sets = gaim_log_get_log_sets(); | |
2116 item = NULL; | |
2117 set_hash_data[0] = &item; | |
2118 set_hash_data[1] = GINT_TO_POINTER(all); | |
2119 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data); | |
2120 g_hash_table_destroy(sets); | |
2121 g_completion_add_items(data->completion, item); | |
2122 g_list_free(item); | |
2123 | 2158 |
2124 g_signal_connect(G_OBJECT(entry), "event", | 2159 g_signal_connect(G_OBJECT(entry), "event", |
2125 G_CALLBACK(completion_entry_event), data); | 2160 G_CALLBACK(completion_entry_event), data); |
2126 g_signal_connect(G_OBJECT(entry), "destroy", | 2161 g_signal_connect(G_OBJECT(entry), "destroy", |
2127 G_CALLBACK(destroy_completion_data), data); | 2162 G_CALLBACK(destroy_completion_data), data); |
2128 | 2163 |
2129 #endif /* !NEW_STYLE_COMPLETION */ | 2164 #endif /* !NEW_STYLE_COMPLETION */ |
2130 } | 2165 |
2131 | 2166 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", entry, |
2167 GAIM_CALLBACK(repopulate_autocomplete), cb_data); | |
2168 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", entry, | |
2169 GAIM_CALLBACK(repopulate_autocomplete), cb_data); | |
2170 gaim_signal_connect(gaim_accounts_get_handle(), "account-added", entry, | |
2171 GAIM_CALLBACK(repopulate_autocomplete), cb_data); | |
2172 gaim_signal_connect(gaim_accounts_get_handle(), "account-removed", entry, | |
2173 GAIM_CALLBACK(repopulate_autocomplete), cb_data); | |
2174 | |
2175 g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(screenname_autocomplete_destroyed_cb), NULL); | |
2176 } | |
2177 |