Mercurial > pidgin
changeset 14105:eaf7f35635bc
[gaim-migrate @ 16739]
Allow autojoining chat rooms.
Sort the buddies in the buddylist, and the plugins in the plugin list.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 13 Aug 2006 23:30:19 +0000 |
parents | b0566d50291f |
children | a82d407d38fa |
files | console/gntblist.c console/gntnotify.c console/gntplugin.c console/libgnt/gntcombobox.c console/libgnt/gntentry.c console/libgnt/gnttree.c console/libgnt/gnttree.h console/libgnt/test/focus.c console/libgnt/test/tv.c |
diffstat | 9 files changed, 183 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/console/gntblist.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/gntblist.c Sun Aug 13 23:30:19 2006 +0000 @@ -337,6 +337,9 @@ node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat, gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), group, NULL); + + if (gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin")) + serv_join_chat(gaim_account_get_connection(chat->account), chat->components); } static void @@ -452,8 +455,23 @@ } static void +context_menu_toggle(GntTree *tree, GaimMenuAction *action, gpointer null) +{ + gboolean sel = gnt_tree_get_choice(tree, action); + gaim_blist_node_set_bool(action->data, "gnt-autojoin", sel); +} + +static void create_chat_menu(GntTree *tree, GaimChat *chat) { + GaimMenuAction *action = gaim_menu_action_new(_("Auto-join"), NULL, chat, NULL); + + gnt_tree_add_choice(tree, action, gnt_tree_create_row(tree, action->label), NULL, NULL); + gnt_tree_set_choice(tree, action, gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin")); + + g_signal_connect_swapped(G_OBJECT(tree), "destroy", + G_CALLBACK(gaim_menu_action_free), action); + g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(context_menu_toggle), NULL); } static void @@ -1182,6 +1200,42 @@ 0, 0, NULL, status_text_changed, NULL); } +static int +blist_node_compare(GaimBlistNode *n1, GaimBlistNode *n2) +{ + const char *s1, *s2; + char *us1, *us2; + int ret; + + g_return_val_if_fail(n1->type == n2->type, -1); + + switch (n1->type) + { + case GAIM_BLIST_GROUP_NODE: + s1 = ((GaimGroup*)n1)->name; + s2 = ((GaimGroup*)n2)->name; + break; + case GAIM_BLIST_CHAT_NODE: + s1 = gaim_chat_get_name((GaimChat*)n1); + s2 = gaim_chat_get_name((GaimChat*)n2); + break; + case GAIM_BLIST_BUDDY_NODE: + s1 = gaim_buddy_get_alias((GaimBuddy*)n1); + s2 = gaim_buddy_get_alias((GaimBuddy*)n2); + break; + default: + return -1; + } + + us1 = g_utf8_strup(s1, -1); + us2 = g_utf8_strup(s2, -1); + ret = g_utf8_collate(us1, us2); + g_free(us1); + g_free(us2); + + return ret; +} + void gg_blist_show() { if (ggblist) @@ -1198,6 +1252,7 @@ gnt_box_set_pad(GNT_BOX(ggblist->window), 0); ggblist->tree = gnt_tree_new(); + gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), (GCompareFunc)blist_node_compare); GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, 25); gnt_widget_set_size(ggblist->tree, gaim_prefs_get_int(PREF_ROOT "/size/width"),
--- a/console/gntnotify.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/gntnotify.c Sun Aug 13 23:30:19 2006 +0000 @@ -163,14 +163,18 @@ } else { + char *to; + setup_email_dialog(); + to = g_strdup_printf("%s (%s)", tos ? *tos : gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), - gnt_tree_create_row(GNT_TREE(emaildialog.tree), - tos ? *tos : gaim_account_get_username(account), /* XXX: Perhaps add the prpl-name */ + gnt_tree_create_row(GNT_TREE(emaildialog.tree), to, froms ? *froms : "[Unknown sender]", *subjects), NULL, NULL); + g_free(to); gnt_widget_show(emaildialog.window); return NULL; }
--- a/console/gntplugin.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/gntplugin.c Sun Aug 13 23:30:19 2006 +0000 @@ -68,6 +68,7 @@ gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot), text, GNT_TEXT_FLAG_NORMAL); gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0); + g_free(text); } static void @@ -78,6 +79,17 @@ plugins.aboot = NULL; } +static int +plugin_compare(GaimPlugin *p1, GaimPlugin *p2) +{ + char *s1 = g_utf8_strup(p1->info->name, -1); + char *s2 = g_utf8_strup(p2->info->name, -1); + int ret = g_utf8_collate(s1, s2); + g_free(s1); + g_free(s2); + return ret; +} + void gg_plugins_show_all() { GntWidget *window, *tree, *box, *aboot; @@ -102,6 +114,7 @@ gnt_box_set_pad(GNT_BOX(box), 0); plugins.tree = tree = gnt_tree_new(); + gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)plugin_compare); GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); gnt_box_add_widget(GNT_BOX(box), tree); gnt_box_add_widget(GNT_BOX(box), gnt_vline_new()); @@ -128,8 +141,6 @@ g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(reset_plugin_window), NULL); - gnt_tree_set_selected(GNT_TREE(tree), gaim_plugins_get_all()->data); - gnt_widget_show(window); }
--- a/console/libgnt/gntcombobox.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/gntcombobox.c Sun Aug 13 23:30:19 2006 +0000 @@ -244,8 +244,8 @@ void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) { - gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, - gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL, NULL); + gnt_tree_add_row_last(GNT_TREE(box->dropdown), key, + gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL); if (box->selected == NULL) set_selection(box, key); }
--- a/console/libgnt/gntentry.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/gntentry.c Sun Aug 13 23:30:19 2006 +0000 @@ -61,6 +61,7 @@ { GntWidget *box = gnt_vbox_new(FALSE); entry->ddown = gnt_tree_new(); + gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate); gnt_box_add_widget(GNT_BOX(box), entry->ddown); GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT);
--- a/console/libgnt/gnttree.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/gnttree.c Sun Aug 13 23:30:19 2006 +0000 @@ -249,7 +249,10 @@ int start; GntWidget *widget = GNT_WIDGET(tree); GntTreeRow *row; - int pos; + int pos, up, down, nr; + + if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) + return; if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) pos = 0; @@ -288,6 +291,21 @@ start = 2; } + nr = widget->priv.height - pos * 2 - start - 1; + tree->bottom = get_next_n_opt(tree->top, nr, &down); + if (down < nr) + { + tree->top = get_prev_n(tree->bottom, nr); + if (tree->top == NULL) + tree->top = tree->root; + } + + up = get_distance(tree->top, tree->current); + if (up < 0) + tree->top = tree->current; + else if (up >= widget->priv.height - pos) + tree->top = get_prev_n(tree->current, nr); + row = tree->top; for (start = start + pos; row && start < widget->priv.height - pos; start++, row = get_next(row)) @@ -379,8 +397,13 @@ static void gnt_tree_map(GntWidget *widget) { + GntTree *tree = GNT_TREE(widget); if (widget->priv.width == 0 || widget->priv.height == 0) + { gnt_widget_size_request(widget); + } + tree->top = tree->root; + tree->current = tree->root; DEBUG; } @@ -616,12 +639,48 @@ g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); } +static gpointer +find_position(GntTree *tree, gpointer key, gpointer parent) +{ + GntTreeRow *row; + + if (tree->compare == NULL) + return NULL; + + if (parent == NULL) + row = tree->root; + else + row = g_hash_table_lookup(tree->hash, parent); + + if (!row) + return NULL; + + if (parent) + row = row->child; + + while (row) + { + if (tree->compare(key, row->key) < 0) + return (row->prev ? row->prev->key : NULL); + if (row->next) + row = row->next; + else + return row->key; + } + return NULL; +} + GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) { GntTreeRow *pr = NULL; g_hash_table_replace(tree->hash, key, row); + if (bigbro == NULL && tree->compare) + { + bigbro = find_position(tree, key, parent); + } + if (tree->root == NULL) { tree->root = row; @@ -663,12 +722,10 @@ if (pr == NULL) { GntTreeRow *r = tree->root; - while (r->next) - r = r->next; - r->next = row; - row->prev = r; - - tree->list = g_list_append(tree->list, key); + row->next = r; + if (r) r->prev = row; + tree->root = row; + tree->list = g_list_prepend(tree->list, key); } else { @@ -679,12 +736,32 @@ row->key = key; row->data = NULL; - if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) - redraw_tree(tree); + redraw_tree(tree); return row; } +GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent) +{ + GntTreeRow *pr = NULL, *br = NULL; + + if (parent) + pr = g_hash_table_lookup(tree->hash, parent); + + if (pr) + br = pr->child; + else + br = tree->root; + + if (br) + { + while (br->next) + br = br->next; + } + + return gnt_tree_add_row_after(tree, key, row, parent, br ? br->key : NULL); +} + gpointer gnt_tree_get_selection_data(GntTree *tree) { if (tree->current) @@ -954,3 +1031,8 @@ tree->show_title = set; } +void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) +{ + tree->compare = func; +} +
--- a/console/libgnt/gnttree.h Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/gnttree.h Sun Aug 13 23:30:19 2006 +0000 @@ -46,6 +46,8 @@ char *title; } *columns; /* Would a GList be better? */ gboolean show_title; + + GCompareFunc compare; }; struct _GnTreeClass @@ -76,6 +78,8 @@ GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro); +GntTreeRow *gnt_tree_add_row_last(GntTree *tree, void *key, GntTreeRow *row, void *parent); + gpointer gnt_tree_get_selection_data(GntTree *tree); /* Returned string needs to be freed */ @@ -112,6 +116,8 @@ void gnt_tree_set_show_title(GntTree *tree, gboolean set); +void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func); + G_END_DECLS #endif /* GNT_TREE_H */
--- a/console/libgnt/test/focus.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/test/focus.c Sun Aug 13 23:30:19 2006 +0000 @@ -44,13 +44,19 @@ box = gnt_box_new(FALSE, FALSE); tree = gnt_tree_new(); + gnt_tree_set_compare_func(GNT_TREE(tree), g_utf8_collate); gnt_widget_set_name(tree, "tree"); gnt_box_add_widget(GNT_BOX(box), tree); gnt_box_add_widget(GNT_BOX(hbox), box); + gnt_tree_add_row_after(GNT_TREE(tree), "c", gnt_tree_create_row(GNT_TREE(tree), "c"), NULL, NULL); gnt_tree_add_row_after(GNT_TREE(tree), "a", gnt_tree_create_row(GNT_TREE(tree), "a"), NULL, NULL); - gnt_tree_add_row_after(GNT_TREE(tree), "c", gnt_tree_create_row(GNT_TREE(tree), "c"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "z", gnt_tree_create_row(GNT_TREE(tree), "z"), "a", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "y", gnt_tree_create_row(GNT_TREE(tree), "y"), "a", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "g", gnt_tree_create_row(GNT_TREE(tree), "g"), "a", NULL); gnt_tree_add_row_after(GNT_TREE(tree), "d", gnt_tree_create_row(GNT_TREE(tree), "d"), NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "x", gnt_tree_create_row(GNT_TREE(tree), "x"), "a", NULL); + gnt_tree_add_row_after(GNT_TREE(tree), "k", gnt_tree_create_row(GNT_TREE(tree), "k"), "a", NULL); gnt_tree_add_row_after(GNT_TREE(tree), "e", gnt_tree_create_row(GNT_TREE(tree), "e"), "a", NULL); gnt_tree_add_choice(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL);
--- a/console/libgnt/test/tv.c Sun Aug 13 08:41:07 2006 +0000 +++ b/console/libgnt/test/tv.c Sun Aug 13 23:30:19 2006 +0000 @@ -62,9 +62,10 @@ gnt_entry_set_always_suggest(GNT_ENTRY(entry), FALSE); gnt_entry_add_suggest(GNT_ENTRY(entry), "a"); gnt_entry_add_suggest(GNT_ENTRY(entry), "ab"); + gnt_entry_add_suggest(GNT_ENTRY(entry), "abe"); gnt_entry_add_suggest(GNT_ENTRY(entry), "abc"); + gnt_entry_add_suggest(GNT_ENTRY(entry), "abcde"); gnt_entry_add_suggest(GNT_ENTRY(entry), "abcd"); - gnt_entry_add_suggest(GNT_ENTRY(entry), "abcde"); gnt_entry_add_suggest(GNT_ENTRY(entry), "acb"); view = gnt_text_view_new();