# HG changeset patch # User Sadrul Habib Chowdhury # Date 1156659252 0 # Node ID 1bd09d355f9e371434da8b93f253181abb980174 # Parent eec3ce357b7044dc8974e22e534a83d983c96df7 [gaim-migrate @ 17054] Allow adding chats in the buddylist. And fix a few bugs along the way. committer: Tailor Script diff -r eec3ce357b70 -r 1bd09d355f9e console/gntblist.c --- a/console/gntblist.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/gntblist.c Sun Aug 27 06:14:12 2006 +0000 @@ -210,6 +210,72 @@ } static void +add_chat_cb(void *data, GaimRequestFields *allfields) +{ + GaimAccount *account; + const char *alias, *name, *group; + GaimChat *chat; + GaimGroup *grp; + GHashTable *hash = NULL; + GaimConnection *gc; + + account = gaim_request_fields_get_account(allfields, "account"); + name = gaim_request_fields_get_string(allfields, "name"); + alias = gaim_request_fields_get_string(allfields, "alias"); + group = gaim_request_fields_get_string(allfields, "group"); + + if (!gaim_account_is_connected(account) || !name || !*name) + return; + + if (!group || !*group) + group = _("Chats"); + + gc = gaim_account_get_connection(account); + + if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) + hash = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name); + + chat = gaim_chat_new(account, name, hash); + + if (chat != NULL) { + if ((grp = gaim_find_group(group)) == NULL) { + grp = gaim_group_new(group); + gaim_blist_add_group(grp, NULL); + } + gaim_blist_add_chat(chat, grp, NULL); + } +} + +static void +gg_request_add_chat(GaimAccount *account, GaimGroup *grp, const char *alias, const char *name) +{ + GaimRequestFields *fields = gaim_request_fields_new(); + GaimRequestFieldGroup *group = gaim_request_field_group_new(NULL); + GaimRequestField *field; + + gaim_request_fields_add_group(fields, group); + + field = gaim_request_field_account_new("account", _("Account"), NULL); + gaim_request_field_account_set_show_all(field, FALSE); + if (account) + gaim_request_field_account_set_value(field, account); + gaim_request_field_group_add_field(group, field); + + field = gaim_request_field_string_new("name", _("Name"), name, FALSE); + gaim_request_field_group_add_field(group, field); + + field = gaim_request_field_string_new("alias", _("Alias"), alias, FALSE); + gaim_request_field_group_add_field(group, field); + + field = gaim_request_field_string_new("group", _("Group"), grp->name, FALSE); + gaim_request_field_group_add_field(group, field); + + gaim_request_fields(NULL, _("Add Chat"), NULL, + _("You can edit more information from the context menu later."), + fields, _("Add"), G_CALLBACK(add_chat_cb), _("Cancel"), NULL, NULL); +} + +static void add_group_cb(gpointer null, const char *group) { GaimGroup *grp; @@ -252,7 +318,7 @@ NULL, NULL, .request_add_buddy = gg_request_add_buddy, - NULL, + .request_add_chat = gg_request_add_chat, .request_add_group = gg_request_add_group }; @@ -466,15 +532,77 @@ } static void +chat_components_edit_ok(GaimChat *chat, GaimRequestFields *allfields) +{ + GList *groups, *fields; + + for (groups = gaim_request_fields_get_groups(allfields); groups; groups = groups->next) { + fields = gaim_request_field_group_get_fields(groups->data); + for (; fields; fields = fields->next) { + GaimRequestField *field = fields->data; + const char *id; + char *val; + + id = gaim_request_field_get_id(field); + if (gaim_request_field_get_type(field) == GAIM_REQUEST_FIELD_INTEGER) + val = g_strdup_printf("%d", gaim_request_field_int_get_value(field)); + else + val = g_strdup(gaim_request_field_string_get_value(field)); + + g_hash_table_replace(chat->components, g_strdup(id), val); /* val should not be free'd */ + } + } +} + +static void +chat_components_edit(GaimChat *chat, GaimBlistNode *null) +{ + GaimRequestFields *fields = gaim_request_fields_new(); + GaimRequestFieldGroup *group = gaim_request_field_group_new(NULL); + GaimRequestField *field; + GList *parts, *iter; + struct proto_chat_entry *pce; + + gaim_request_fields_add_group(fields, group); + + parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); + + for (iter = parts; iter; iter = iter->next) { + pce = iter->data; + if (pce->is_int) { + int val; + const char *str = g_hash_table_lookup(chat->components, pce->identifier); + if (!str || sscanf(str, "%d", &val) != 1) + val = pce->min; + field = gaim_request_field_int_new(pce->identifier, pce->label, val); + } else { + field = gaim_request_field_string_new(pce->identifier, pce->label, + g_hash_table_lookup(chat->components, pce->identifier), FALSE); + } + + gaim_request_field_group_add_field(group, field); + g_free(pce); + } + + g_list_free(parts); + + gaim_request_fields(NULL, _("Edit Chat"), NULL, _("Please Update the necessary fields."), + fields, _("Edit"), G_CALLBACK(chat_components_edit_ok), _("Cancel"), NULL, chat); +} + +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); + + add_custom_action(tree, _("Edit Settings"), (GaimCallback)chat_components_edit, chat); + g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(context_menu_toggle), NULL); } @@ -491,10 +619,18 @@ } static void +gg_add_chat(GaimGroup *grp, GaimBlistNode *node) +{ + gaim_blist_request_add_chat(NULL, grp, NULL, NULL); +} + +static void create_group_menu(GntTree *tree, GaimGroup *group) { add_custom_action(tree, _("Add Buddy"), GAIM_CALLBACK(gg_add_buddy), group); + add_custom_action(tree, _("Add Chat"), + GAIM_CALLBACK(gg_add_chat), group); add_custom_action(tree, _("Add Group"), GAIM_CALLBACK(gg_add_group), group); } @@ -1005,7 +1141,8 @@ node = gaim_blist_node_next(node, TRUE); } - remove_typing_cb(NULL); + if (ggblist->typing) + g_source_remove(ggblist->typing); remove_peripherals(ggblist); g_free(ggblist); ggblist = NULL; @@ -1359,9 +1496,12 @@ ggblist = NULL; } -void gg_blist_get_position(int *x, int *y) +gboolean gg_blist_get_position(int *x, int *y) { + if (!ggblist || !ggblist->window) + return FALSE; gnt_widget_get_position(ggblist->window, x, y); + return TRUE; } void gg_blist_set_position(int x, int y) @@ -1369,9 +1509,12 @@ gnt_widget_set_position(ggblist->window, x, y); } -void gg_blist_get_size(int *width, int *height) +gboolean gg_blist_get_size(int *width, int *height) { + if (!ggblist || !ggblist->window) + return FALSE; gnt_widget_get_size(ggblist->window, width, height); + return TRUE; } void gg_blist_set_size(int width, int height) diff -r eec3ce357b70 -r 1bd09d355f9e console/gntblist.h --- a/console/gntblist.h Sun Aug 27 02:44:52 2006 +0000 +++ b/console/gntblist.h Sun Aug 27 06:14:12 2006 +0000 @@ -11,11 +11,11 @@ void gg_blist_show(void); -void gg_blist_get_position(int *x, int *y); +gboolean gg_blist_get_position(int *x, int *y); void gg_blist_set_position(int x, int y); -void gg_blist_get_size(int *width, int *height); +gboolean gg_blist_get_size(int *width, int *height); void gg_blist_set_size(int width, int height); diff -r eec3ce357b70 -r 1bd09d355f9e console/gntconv.c --- a/console/gntconv.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/gntconv.c Sun Aug 27 06:14:12 2006 +0000 @@ -191,7 +191,7 @@ gnt_box_set_title(GNT_BOX(ggc->window), title); gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); gnt_box_set_pad(GNT_BOX(ggc->window), 0); - gnt_widget_set_name(ggc->window, title); + gnt_widget_set_name(ggc->window, "conversation-window"); ggc->tv = gnt_text_view_new(); gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv); diff -r eec3ce357b70 -r 1bd09d355f9e console/gntgaim.c --- a/console/gntgaim.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/gntgaim.c Sun Aug 27 06:14:12 2006 +0000 @@ -224,7 +224,7 @@ } /* show version message */ if (opt_version) { - printf("Gaim %s\n", VERSION); + printf("gntgaim %s\n", VERSION); return 0; } diff -r eec3ce357b70 -r 1bd09d355f9e console/gntrequest.c --- a/console/gntrequest.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/gntrequest.c Sun Aug 27 06:14:12 2006 +0000 @@ -361,8 +361,12 @@ } else if (type == GAIM_REQUEST_FIELD_INTEGER) { - GntWidget *entry = gnt_entry_new( - gaim_request_field_string_get_default_value(field)); + char str[256]; + int val = gaim_request_field_int_get_default_value(field); + GntWidget *entry; + + snprintf(str, sizeof(str), "%d", val); + entry = gnt_entry_new(str); gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); gnt_box_add_widget(GNT_BOX(hbox), entry); field->ui_data = entry; diff -r eec3ce357b70 -r 1bd09d355f9e console/libgnt/gntentry.c --- a/console/libgnt/gntentry.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/libgnt/gntentry.c Sun Aug 27 06:14:12 2006 +0000 @@ -349,7 +349,7 @@ { const char *str, *next; - for (str = text; *str;) + for (str = text; *str; str = next) { int len; next = g_utf8_find_next_char(str, NULL); diff -r eec3ce357b70 -r 1bd09d355f9e console/libgnt/gnttree.c --- a/console/libgnt/gnttree.c Sun Aug 27 02:44:52 2006 +0000 +++ b/console/libgnt/gnttree.c Sun Aug 27 06:14:12 2006 +0000 @@ -633,10 +633,14 @@ tree->current = row; redraw_tree(tree); tree_selection_changed(tree, old, tree->current); - } else if (row == tree->current && row->choice) { - row->isselected = !row->isselected; - g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); - redraw_tree(tree); + } else if (row && row == tree->current) { + if (row->choice) { + row->isselected = !row->isselected; + g_signal_emit(tree, signals[SIG_TOGGLED], 0, row->key); + redraw_tree(tree); + } else { + gnt_widget_activate(widget); + } } } else { return FALSE;