Mercurial > pidgin.yaz
changeset 14062:fa8f65cd912c
[gaim-migrate @ 16681]
You can now add buddies or groups in the buddylist from the context-menu
for a group. Adding chats is not yet possible.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 09 Aug 2006 17:22:55 +0000 |
parents | eb58c6169e6c |
children | ccbd43daa1a3 |
files | console/gntblist.c console/gntrequest.c console/libgnt/gntcombobox.c |
diffstat | 3 files changed, 176 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/console/gntblist.c Wed Aug 09 14:47:37 2006 +0000 +++ b/console/gntblist.c Wed Aug 09 17:22:55 2006 +0000 @@ -1,5 +1,6 @@ #include <account.h> #include <blist.h> +#include <notify.h> #include <request.h> #include <savedstatuses.h> #include <server.h> @@ -141,6 +142,103 @@ { } +static void +add_buddy_cb(void *data, GaimRequestFields *allfields) +{ + const char *username = gaim_request_fields_get_string(allfields, "screenname"); + const char *alias = gaim_request_fields_get_string(allfields, "alias"); + const char *group = gaim_request_fields_get_string(allfields, "group"); + GaimAccount *account = gaim_request_fields_get_account(allfields, "account"); + const char *error = NULL; + GaimGroup *grp; + GaimBuddy *buddy; + + if (!username) + error = _("You must provide a screename for the buddy."); + else if (!group) + error = _("You must provide a group."); + else if (!account) + error = _("You must select an account."); + + if (error) + { + gaim_notify_error(NULL, _("Error"), _("Error adding buddy"), error); + return; + } + + grp = gaim_find_group(group); + if (!grp) + { + grp = gaim_group_new(group); + gaim_blist_add_group(grp, NULL); + } + + buddy = gaim_buddy_new(account, username, alias); + gaim_blist_add_buddy(buddy, NULL, grp, NULL); + gaim_account_add_buddy(account, buddy); +} + +static void +gg_request_add_buddy(GaimAccount *account, const char *username, const char *grp, const char *alias) +{ + 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_string_new("screenname", _("Screen Name"), username, 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, FALSE); + gaim_request_field_group_add_field(group, field); + + 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); + + gaim_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."), + fields, _("Add"), G_CALLBACK(add_buddy_cb), _("Cancel"), NULL, NULL); +} + +static void +add_group_cb(gpointer null, const char *group) +{ + GaimGroup *grp; + + if (!group || !*group) + { + gaim_notify_error(NULL, _("Error"), _("Error adding group"), + _("You must give a name for the group to add.")); + return; + } + + grp = gaim_find_group(group); + if (!grp) + { + grp = gaim_group_new(group); + gaim_blist_add_group(grp, NULL); + } + else + { + gaim_notify_error(NULL, _("Error"), _("Error adding group"), + _("A group with the name already exists.")); + } +} + +static void +gg_request_add_group() +{ + gaim_request_input(NULL, _("Add Group"), NULL, _("Enter the name of the group"), + NULL, FALSE, FALSE, NULL, + _("Add"), G_CALLBACK(add_group_cb), _("Cancel"), NULL, NULL); +} + static GaimBlistUiOps blist_ui_ops = { new_list, @@ -150,9 +248,9 @@ node_remove, NULL, NULL, - NULL, + .request_add_buddy = gg_request_add_buddy, NULL, - NULL + .request_add_group = gg_request_add_group }; static gpointer @@ -360,8 +458,24 @@ } static void +gg_add_buddy(GaimGroup *grp, GaimBlistNode *node) +{ + gaim_blist_request_add_buddy(NULL, NULL, grp->name, NULL); +} + +static void +gg_add_group(GaimGroup *grp, GaimBlistNode *node) +{ + gaim_blist_request_add_group(); +} + +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 Group"), + GAIM_CALLBACK(gg_add_group), group); } static void @@ -555,6 +669,7 @@ GAIM_CALLBACK(gg_blist_remove_node_cb), node); window = gnt_vbox_new(FALSE); + GNT_WIDGET_SET_FLAGS(window, GNT_WIDGET_TRANSIENT); gnt_box_set_toplevel(GNT_BOX(window), TRUE); gnt_box_set_title(GNT_BOX(window), title);
--- a/console/gntrequest.c Wed Aug 09 14:47:37 2006 +0000 +++ b/console/gntrequest.c Wed Aug 09 17:22:55 2006 +0000 @@ -278,6 +278,9 @@ } else if (type == GAIM_REQUEST_FIELD_ACCOUNT) { + GntWidget *combo = field->ui_data; + GaimAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); + gaim_request_field_account_set_value(field, acc); } } } @@ -293,13 +296,13 @@ static void * gg_request_fields(const char *title, const char *primary, - const char *secondary, GaimRequestFields *fields, + const char *secondary, GaimRequestFields *allfields, const char *ok, GCallback ok_cb, const char *cancel, GCallback cancel_cb, void *userdata) { GntWidget *window, *box; - GList *list; + GList *grlist; window = setup_request_window(title, primary, secondary, GAIM_REQUEST_FIELDS); @@ -309,27 +312,28 @@ box = gnt_vbox_new(FALSE); gnt_box_set_pad(GNT_BOX(box), 0); gnt_box_set_fill(GNT_BOX(box), TRUE); - for (list = gaim_request_fields_get_groups(fields); list; list = list->next) + for (grlist = gaim_request_fields_get_groups(allfields); grlist; grlist = grlist->next) { - GaimRequestFieldGroup *group = list->data; + GaimRequestFieldGroup *group = grlist->data; GList *fields = gaim_request_field_group_get_fields(group); GntWidget *hbox; - - gnt_box_add_widget(GNT_BOX(box), - gnt_label_new_with_format(gaim_request_field_group_get_title(group), - GNT_TEXT_FLAG_BOLD)); + const char *title = gaim_request_field_group_get_title(group); + + if (title) + gnt_box_add_widget(GNT_BOX(box), + gnt_label_new_with_format(title, GNT_TEXT_FLAG_BOLD)); for (; fields ; fields = fields->next) { + /* XXX: Break each of the fields into a separate function? */ GaimRequestField *field = fields->data; GaimRequestFieldType type = gaim_request_field_get_type(field); const char *label = gaim_request_field_get_label(field); - hbox = gnt_hbox_new(FALSE); - gnt_box_set_pad(GNT_BOX(hbox), 0); + hbox = gnt_hbox_new(TRUE); /* hrm */ gnt_box_add_widget(GNT_BOX(box), hbox); - if (type != GAIM_REQUEST_FIELD_BOOLEAN) + if (type != GAIM_REQUEST_FIELD_BOOLEAN && label) { GntWidget *l = gnt_label_new(label); gnt_widget_set_size(l, 0, 1); @@ -417,12 +421,44 @@ } } } -#if 0 else if (type == GAIM_REQUEST_FIELD_ACCOUNT) { - /* XXX: remember to set the field->ui_data */ + gboolean all; + GaimAccount *def; + GList *list; + GntWidget *combo = gnt_combo_box_new(); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); + gnt_box_add_widget(GNT_BOX(hbox), combo); + field->ui_data = combo; + + all = gaim_request_field_account_get_show_all(field); + def = gaim_request_field_account_get_default_value(field); + + if (all) + list = gaim_accounts_get_all(); + else + list = gaim_connections_get_all(); + + for (; list; list = list->next) + { + GaimAccount *account; + char *text; + + if (all) + account = list->data; + else + account = gaim_connection_get_account(list->data); + + text = g_strdup_printf("%s (%s)", + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); + gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text); + g_free(text); + if (account == def) + gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account); + } + gnt_widget_set_size(combo, 20, 3); /* ew */ } -#endif else { gnt_box_add_widget(GNT_BOX(hbox), @@ -430,12 +466,12 @@ GNT_TEXT_FLAG_BOLD)); } } - if (list->next) + if (grlist->next) gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); } gnt_box_add_widget(GNT_BOX(window), box); - box = setup_button_box(userdata, request_fields_cb, fields, + box = setup_button_box(userdata, request_fields_cb, allfields, ok, ok_cb, cancel, cancel_cb, NULL); gnt_box_add_widget(GNT_BOX(window), box);
--- a/console/libgnt/gntcombobox.c Wed Aug 09 14:47:37 2006 +0000 +++ b/console/libgnt/gntcombobox.c Wed Aug 09 17:22:55 2006 +0000 @@ -74,8 +74,13 @@ static void gnt_combo_box_size_request(GntWidget *widget) { - widget->priv.height = 3; /* For now, a combobox will have border */ - widget->priv.width = 15; + if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) + { + GntWidget *dd = GNT_COMBO_BOX(widget)->dropdown; + gnt_widget_size_request(dd); + widget->priv.height = 3; /* For now, a combobox will have border */ + widget->priv.width = MIN(10, dd->priv.width); + } } static void