pidgin/gtkutils.c

branch
next.minor
changeset 25889
26d9ca30335c
parent 25888
d0fdd378a635
child 26572
1c3c4e6ee338
equal deleted inserted replaced
25888:d0fdd378a635 25889:26d9ca30335c
1925 g_free(data); 1925 g_free(data);
1926 } 1926 }
1927 #endif /* !NEW_STYLE_COMPLETION */ 1927 #endif /* !NEW_STYLE_COMPLETION */
1928 1928
1929 #ifdef NEW_STYLE_COMPLETION 1929 #ifdef NEW_STYLE_COMPLETION
1930 static gboolean screenname_completion_match_func(GtkEntryCompletion *completion, 1930 static gboolean buddyname_completion_match_func(GtkEntryCompletion *completion,
1931 const gchar *key, GtkTreeIter *iter, gpointer user_data) 1931 const gchar *key, GtkTreeIter *iter, gpointer user_data)
1932 { 1932 {
1933 GtkTreeModel *model; 1933 GtkTreeModel *model;
1934 GValue val1; 1934 GValue val1;
1935 GValue val2; 1935 GValue val2;
1958 g_value_unset(&val2); 1958 g_value_unset(&val2);
1959 1959
1960 return FALSE; 1960 return FALSE;
1961 } 1961 }
1962 1962
1963 static gboolean screenname_completion_match_selected_cb(GtkEntryCompletion *completion, 1963 static gboolean buddyname_completion_match_selected_cb(GtkEntryCompletion *completion,
1964 GtkTreeModel *model, GtkTreeIter *iter, PidginCompletionData *data) 1964 GtkTreeModel *model, GtkTreeIter *iter, PidginCompletionData *data)
1965 { 1965 {
1966 GValue val; 1966 GValue val;
1967 GtkWidget *optmenu = data->accountopt; 1967 GtkWidget *optmenu = data->accountopt;
1968 PurpleAccount *account; 1968 PurpleAccount *account;
1984 1984
1985 return TRUE; 1985 return TRUE;
1986 } 1986 }
1987 1987
1988 static void 1988 static void
1989 add_screenname_autocomplete_entry(GtkListStore *store, const char *buddy_alias, const char *contact_alias, 1989 add_buddyname_autocomplete_entry(GtkListStore *store, const char *buddy_alias, const char *contact_alias,
1990 const PurpleAccount *account, const char *screenname) 1990 const PurpleAccount *account, const char *buddyname)
1991 { 1991 {
1992 GtkTreeIter iter; 1992 GtkTreeIter iter;
1993 gboolean completion_added = FALSE; 1993 gboolean completion_added = FALSE;
1994 gchar *normalized_screenname; 1994 gchar *normalized_buddyname;
1995 gchar *tmp; 1995 gchar *tmp;
1996 1996
1997 tmp = g_utf8_normalize(screenname, -1, G_NORMALIZE_DEFAULT); 1997 tmp = g_utf8_normalize(buddyname, -1, G_NORMALIZE_DEFAULT);
1998 normalized_screenname = g_utf8_casefold(tmp, -1); 1998 normalized_buddyname = g_utf8_casefold(tmp, -1);
1999 g_free(tmp); 1999 g_free(tmp);
2000 2000
2001 /* There's no sense listing things like: 'xxx "xxx"' 2001 /* There's no sense listing things like: 'xxx "xxx"'
2002 when the screenname and buddy alias match. */ 2002 when the name and buddy alias match. */
2003 if (buddy_alias && strcmp(buddy_alias, screenname)) { 2003 if (buddy_alias && strcmp(buddy_alias, buddyname)) {
2004 char *completion_entry = g_strdup_printf("%s \"%s\"", screenname, buddy_alias); 2004 char *completion_entry = g_strdup_printf("%s \"%s\"", buddyname, buddy_alias);
2005 char *tmp2 = g_utf8_normalize(buddy_alias, -1, G_NORMALIZE_DEFAULT); 2005 char *tmp2 = g_utf8_normalize(buddy_alias, -1, G_NORMALIZE_DEFAULT);
2006 2006
2007 tmp = g_utf8_casefold(tmp2, -1); 2007 tmp = g_utf8_casefold(tmp2, -1);
2008 g_free(tmp2); 2008 g_free(tmp2);
2009 2009
2010 gtk_list_store_append(store, &iter); 2010 gtk_list_store_append(store, &iter);
2011 gtk_list_store_set(store, &iter, 2011 gtk_list_store_set(store, &iter,
2012 0, completion_entry, 2012 0, completion_entry,
2013 1, screenname, 2013 1, buddyname,
2014 2, normalized_screenname, 2014 2, normalized_buddyname,
2015 3, tmp, 2015 3, tmp,
2016 4, account, 2016 4, account,
2017 -1); 2017 -1);
2018 g_free(completion_entry); 2018 g_free(completion_entry);
2019 g_free(tmp); 2019 g_free(tmp);
2020 completion_added = TRUE; 2020 completion_added = TRUE;
2021 } 2021 }
2022 2022
2023 /* There's no sense listing things like: 'xxx "xxx"' 2023 /* There's no sense listing things like: 'xxx "xxx"'
2024 when the screenname and contact alias match. */ 2024 when the name and contact alias match. */
2025 if (contact_alias && strcmp(contact_alias, screenname)) { 2025 if (contact_alias && strcmp(contact_alias, buddyname)) {
2026 /* We don't want duplicates when the contact and buddy alias match. */ 2026 /* We don't want duplicates when the contact and buddy alias match. */
2027 if (!buddy_alias || strcmp(contact_alias, buddy_alias)) { 2027 if (!buddy_alias || strcmp(contact_alias, buddy_alias)) {
2028 char *completion_entry = g_strdup_printf("%s \"%s\"", 2028 char *completion_entry = g_strdup_printf("%s \"%s\"",
2029 screenname, contact_alias); 2029 buddyname, contact_alias);
2030 char *tmp2 = g_utf8_normalize(contact_alias, -1, G_NORMALIZE_DEFAULT); 2030 char *tmp2 = g_utf8_normalize(contact_alias, -1, G_NORMALIZE_DEFAULT);
2031 2031
2032 tmp = g_utf8_casefold(tmp2, -1); 2032 tmp = g_utf8_casefold(tmp2, -1);
2033 g_free(tmp2); 2033 g_free(tmp2);
2034 2034
2035 gtk_list_store_append(store, &iter); 2035 gtk_list_store_append(store, &iter);
2036 gtk_list_store_set(store, &iter, 2036 gtk_list_store_set(store, &iter,
2037 0, completion_entry, 2037 0, completion_entry,
2038 1, screenname, 2038 1, buddyname,
2039 2, normalized_screenname, 2039 2, normalized_buddyname,
2040 3, tmp, 2040 3, tmp,
2041 4, account, 2041 4, account,
2042 -1); 2042 -1);
2043 g_free(completion_entry); 2043 g_free(completion_entry);
2044 g_free(tmp); 2044 g_free(tmp);
2045 completion_added = TRUE; 2045 completion_added = TRUE;
2046 } 2046 }
2047 } 2047 }
2048 2048
2049 if (completion_added == FALSE) { 2049 if (completion_added == FALSE) {
2050 /* Add the buddy's screenname. */ 2050 /* Add the buddy's name. */
2051 gtk_list_store_append(store, &iter); 2051 gtk_list_store_append(store, &iter);
2052 gtk_list_store_set(store, &iter, 2052 gtk_list_store_set(store, &iter,
2053 0, screenname, 2053 0, buddyname,
2054 1, screenname, 2054 1, buddyname,
2055 2, normalized_screenname, 2055 2, normalized_buddyname,
2056 3, NULL, 2056 3, NULL,
2057 4, account, 2057 4, account,
2058 -1); 2058 -1);
2059 } 2059 }
2060 2060
2061 g_free(normalized_screenname); 2061 g_free(normalized_buddyname);
2062 } 2062 }
2063 #endif /* NEW_STYLE_COMPLETION */ 2063 #endif /* NEW_STYLE_COMPLETION */
2064 2064
2065 static void get_log_set_name(PurpleLogSet *set, gpointer value, PidginCompletionData *data) 2065 static void get_log_set_name(PurpleLogSet *set, gpointer value, PidginCompletionData *data)
2066 { 2066 {
2067 PidginFilterBuddyCompletionEntryFunc filter_func = data->filter_func; 2067 PidginFilterBuddyCompletionEntryFunc filter_func = data->filter_func;
2068 gpointer user_data = data->filter_func_user_data; 2068 gpointer user_data = data->filter_func_user_data;
2069 2069
2070 /* 1. Don't show buddies because we will have gotten them already. 2070 /* 1. Don't show buddies because we will have gotten them already.
2071 * 2. The boxes that use this autocomplete code handle only IMs. */ 2071 * 2. The boxes that use this autocomplete code handle only IMs. */
2072 if (!set->buddy && set->type == PURPLE_LOG_IM) { 2072 if (!set->buddy && set->type == PURPLE_LOG_IM) {
2073 PidginBuddyCompletionEntry entry; 2073 PidginBuddyCompletionEntry entry;
2074 entry.is_buddy = FALSE; 2074 entry.is_buddy = FALSE;
2075 entry.entry.logged_buddy = set; 2075 entry.entry.logged_buddy = set;
2076 2076
2077 if (filter_func(&entry, user_data)) { 2077 if (filter_func(&entry, user_data)) {
2078 #ifdef NEW_STYLE_COMPLETION 2078 #ifdef NEW_STYLE_COMPLETION
2079 add_screenname_autocomplete_entry(data->store, 2079 add_buddyname_autocomplete_entry(data->store,
2080 NULL, NULL, set->account, set->name); 2080 NULL, NULL, set->account, set->name);
2081 #else 2081 #else
2082 /* Steal the name for the GCompletion. */ 2082 /* Steal the name for the GCompletion. */
2083 data->log_items = g_list_append(data->log_items, set->name); 2083 data->log_items = g_list_append(data->log_items, set->name);
2084 set->name = set->normalized_name = NULL; 2084 set->name = set->normalized_name = NULL;
2120 entry.is_buddy = TRUE; 2120 entry.is_buddy = TRUE;
2121 entry.entry.buddy = (PurpleBuddy *) bnode; 2121 entry.entry.buddy = (PurpleBuddy *) bnode;
2122 2122
2123 if (filter_func(&entry, user_data)) { 2123 if (filter_func(&entry, user_data)) {
2124 #ifdef NEW_STYLE_COMPLETION 2124 #ifdef NEW_STYLE_COMPLETION
2125 add_screenname_autocomplete_entry(data->store, 2125 add_buddyname_autocomplete_entry(data->store,
2126 ((PurpleContact *)cnode)->alias, 2126 ((PurpleContact *)cnode)->alias,
2127 purple_buddy_get_contact_alias(entry.entry.buddy), 2127 purple_buddy_get_contact_alias(entry.entry.buddy),
2128 entry.entry.buddy->account, 2128 entry.entry.buddy->account,
2129 entry.entry.buddy->name 2129 entry.entry.buddy->name
2130 ); 2130 );
2151 g_list_free(data->log_items); 2151 g_list_free(data->log_items);
2152 #endif /* NEW_STYLE_COMPLETION */ 2152 #endif /* NEW_STYLE_COMPLETION */
2153 } 2153 }
2154 2154
2155 static void 2155 static void
2156 screenname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data) 2156 buddyname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
2157 { 2157 {
2158 g_free(data); 2158 g_free(data);
2159 purple_signals_disconnect_by_handle(widget); 2159 purple_signals_disconnect_by_handle(widget);
2160 } 2160 }
2161 2161
2163 repopulate_autocomplete(gpointer something, gpointer data) 2163 repopulate_autocomplete(gpointer something, gpointer data)
2164 { 2164 {
2165 add_completion_list(data); 2165 add_completion_list(data);
2166 } 2166 }
2167 2167
2168
2169 void 2168 void
2170 pidgin_setup_screenname_autocomplete_with_filter(GtkWidget *entry, GtkWidget *accountopt, PidginFilterBuddyCompletionEntryFunc filter_func, gpointer user_data) 2169 pidgin_setup_screenname_autocomplete_with_filter(GtkWidget *entry, GtkWidget *accountopt, PidginFilterBuddyCompletionEntryFunc filter_func, gpointer user_data)
2171 { 2170 {
2172 PidginCompletionData *data; 2171 PidginCompletionData *data;
2173 2172
2174 #ifdef NEW_STYLE_COMPLETION 2173 #ifdef NEW_STYLE_COMPLETION
2175 /* Store the displayed completion value, the screenname, the UTF-8 normalized & casefolded screenname, 2174 /*
2176 * the UTF-8 normalized & casefolded value for comparison, and the account. */ 2175 * Store the displayed completion value, the buddy name, the UTF-8
2176 * normalized & casefolded buddy name, the UTF-8 normalized &
2177 * casefolded value for comparison, and the account.
2178 */
2177 GtkListStore *store; 2179 GtkListStore *store;
2178 2180
2179 GtkEntryCompletion *completion; 2181 GtkEntryCompletion *completion;
2180 2182
2181 data = g_new0(PidginCompletionData, 1); 2183 data = g_new0(PidginCompletionData, 1);
2192 } 2194 }
2193 data->store = store; 2195 data->store = store;
2194 2196
2195 add_completion_list(data); 2197 add_completion_list(data);
2196 2198
2197 /* Sort the completion list by screenname. */ 2199 /* Sort the completion list by buddy name */
2198 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), 2200 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
2199 1, GTK_SORT_ASCENDING); 2201 1, GTK_SORT_ASCENDING);
2200 2202
2201 completion = gtk_entry_completion_new(); 2203 completion = gtk_entry_completion_new();
2202 gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL); 2204 gtk_entry_completion_set_match_func(completion, buddyname_completion_match_func, NULL, NULL);
2203 2205
2204 g_signal_connect(G_OBJECT(completion), "match-selected", 2206 g_signal_connect(G_OBJECT(completion), "match-selected",
2205 G_CALLBACK(screenname_completion_match_selected_cb), data); 2207 G_CALLBACK(buddyname_completion_match_selected_cb), data);
2206 2208
2207 gtk_entry_set_completion(GTK_ENTRY(entry), completion); 2209 gtk_entry_set_completion(GTK_ENTRY(entry), completion);
2208 g_object_unref(completion); 2210 g_object_unref(completion);
2209 2211
2210 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store)); 2212 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
2247 purple_signal_connect(purple_accounts_get_handle(), "account-added", entry, 2249 purple_signal_connect(purple_accounts_get_handle(), "account-added", entry,
2248 PURPLE_CALLBACK(repopulate_autocomplete), data); 2250 PURPLE_CALLBACK(repopulate_autocomplete), data);
2249 purple_signal_connect(purple_accounts_get_handle(), "account-removed", entry, 2251 purple_signal_connect(purple_accounts_get_handle(), "account-removed", entry,
2250 PURPLE_CALLBACK(repopulate_autocomplete), data); 2252 PURPLE_CALLBACK(repopulate_autocomplete), data);
2251 2253
2252 g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(screenname_autocomplete_destroyed_cb), data); 2254 g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(buddyname_autocomplete_destroyed_cb), data);
2253 } 2255 }
2254 2256
2255 gboolean 2257 gboolean
2256 pidgin_screenname_autocomplete_default_filter(const PidginBuddyCompletionEntry *completion_entry, gpointer all_accounts) { 2258 pidgin_screenname_autocomplete_default_filter(const PidginBuddyCompletionEntry *completion_entry, gpointer all_accounts) {
2257 gboolean all = GPOINTER_TO_INT(all_accounts); 2259 gboolean all = GPOINTER_TO_INT(all_accounts);

mercurial