| 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; |
| 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)); |