comparison console/gntblist.c @ 14351:1bd09d355f9e

[gaim-migrate @ 17054] Allow adding chats in the buddylist. And fix a few bugs along the way. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 27 Aug 2006 06:14:12 +0000
parents c509b8b8a646
children a7e29c0b51f4
comparison
equal deleted inserted replaced
14350:eec3ce357b70 14351:1bd09d355f9e
208 gaim_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."), 208 gaim_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."),
209 fields, _("Add"), G_CALLBACK(add_buddy_cb), _("Cancel"), NULL, NULL); 209 fields, _("Add"), G_CALLBACK(add_buddy_cb), _("Cancel"), NULL, NULL);
210 } 210 }
211 211
212 static void 212 static void
213 add_chat_cb(void *data, GaimRequestFields *allfields)
214 {
215 GaimAccount *account;
216 const char *alias, *name, *group;
217 GaimChat *chat;
218 GaimGroup *grp;
219 GHashTable *hash = NULL;
220 GaimConnection *gc;
221
222 account = gaim_request_fields_get_account(allfields, "account");
223 name = gaim_request_fields_get_string(allfields, "name");
224 alias = gaim_request_fields_get_string(allfields, "alias");
225 group = gaim_request_fields_get_string(allfields, "group");
226
227 if (!gaim_account_is_connected(account) || !name || !*name)
228 return;
229
230 if (!group || !*group)
231 group = _("Chats");
232
233 gc = gaim_account_get_connection(account);
234
235 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
236 hash = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name);
237
238 chat = gaim_chat_new(account, name, hash);
239
240 if (chat != NULL) {
241 if ((grp = gaim_find_group(group)) == NULL) {
242 grp = gaim_group_new(group);
243 gaim_blist_add_group(grp, NULL);
244 }
245 gaim_blist_add_chat(chat, grp, NULL);
246 }
247 }
248
249 static void
250 gg_request_add_chat(GaimAccount *account, GaimGroup *grp, const char *alias, const char *name)
251 {
252 GaimRequestFields *fields = gaim_request_fields_new();
253 GaimRequestFieldGroup *group = gaim_request_field_group_new(NULL);
254 GaimRequestField *field;
255
256 gaim_request_fields_add_group(fields, group);
257
258 field = gaim_request_field_account_new("account", _("Account"), NULL);
259 gaim_request_field_account_set_show_all(field, FALSE);
260 if (account)
261 gaim_request_field_account_set_value(field, account);
262 gaim_request_field_group_add_field(group, field);
263
264 field = gaim_request_field_string_new("name", _("Name"), name, FALSE);
265 gaim_request_field_group_add_field(group, field);
266
267 field = gaim_request_field_string_new("alias", _("Alias"), alias, FALSE);
268 gaim_request_field_group_add_field(group, field);
269
270 field = gaim_request_field_string_new("group", _("Group"), grp->name, FALSE);
271 gaim_request_field_group_add_field(group, field);
272
273 gaim_request_fields(NULL, _("Add Chat"), NULL,
274 _("You can edit more information from the context menu later."),
275 fields, _("Add"), G_CALLBACK(add_chat_cb), _("Cancel"), NULL, NULL);
276 }
277
278 static void
213 add_group_cb(gpointer null, const char *group) 279 add_group_cb(gpointer null, const char *group)
214 { 280 {
215 GaimGroup *grp; 281 GaimGroup *grp;
216 282
217 if (!group || !*group) 283 if (!group || !*group)
250 node_update, /* This doesn't do crap */ 316 node_update, /* This doesn't do crap */
251 node_remove, 317 node_remove,
252 NULL, 318 NULL,
253 NULL, 319 NULL,
254 .request_add_buddy = gg_request_add_buddy, 320 .request_add_buddy = gg_request_add_buddy,
255 NULL, 321 .request_add_chat = gg_request_add_chat,
256 .request_add_group = gg_request_add_group 322 .request_add_group = gg_request_add_group
257 }; 323 };
258 324
259 static gpointer 325 static gpointer
260 gg_blist_get_handle() 326 gg_blist_get_handle()
464 gboolean sel = gnt_tree_get_choice(tree, action); 530 gboolean sel = gnt_tree_get_choice(tree, action);
465 gaim_blist_node_set_bool(action->data, "gnt-autojoin", sel); 531 gaim_blist_node_set_bool(action->data, "gnt-autojoin", sel);
466 } 532 }
467 533
468 static void 534 static void
535 chat_components_edit_ok(GaimChat *chat, GaimRequestFields *allfields)
536 {
537 GList *groups, *fields;
538
539 for (groups = gaim_request_fields_get_groups(allfields); groups; groups = groups->next) {
540 fields = gaim_request_field_group_get_fields(groups->data);
541 for (; fields; fields = fields->next) {
542 GaimRequestField *field = fields->data;
543 const char *id;
544 char *val;
545
546 id = gaim_request_field_get_id(field);
547 if (gaim_request_field_get_type(field) == GAIM_REQUEST_FIELD_INTEGER)
548 val = g_strdup_printf("%d", gaim_request_field_int_get_value(field));
549 else
550 val = g_strdup(gaim_request_field_string_get_value(field));
551
552 g_hash_table_replace(chat->components, g_strdup(id), val); /* val should not be free'd */
553 }
554 }
555 }
556
557 static void
558 chat_components_edit(GaimChat *chat, GaimBlistNode *null)
559 {
560 GaimRequestFields *fields = gaim_request_fields_new();
561 GaimRequestFieldGroup *group = gaim_request_field_group_new(NULL);
562 GaimRequestField *field;
563 GList *parts, *iter;
564 struct proto_chat_entry *pce;
565
566 gaim_request_fields_add_group(fields, group);
567
568 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc);
569
570 for (iter = parts; iter; iter = iter->next) {
571 pce = iter->data;
572 if (pce->is_int) {
573 int val;
574 const char *str = g_hash_table_lookup(chat->components, pce->identifier);
575 if (!str || sscanf(str, "%d", &val) != 1)
576 val = pce->min;
577 field = gaim_request_field_int_new(pce->identifier, pce->label, val);
578 } else {
579 field = gaim_request_field_string_new(pce->identifier, pce->label,
580 g_hash_table_lookup(chat->components, pce->identifier), FALSE);
581 }
582
583 gaim_request_field_group_add_field(group, field);
584 g_free(pce);
585 }
586
587 g_list_free(parts);
588
589 gaim_request_fields(NULL, _("Edit Chat"), NULL, _("Please Update the necessary fields."),
590 fields, _("Edit"), G_CALLBACK(chat_components_edit_ok), _("Cancel"), NULL, chat);
591 }
592
593 static void
469 create_chat_menu(GntTree *tree, GaimChat *chat) 594 create_chat_menu(GntTree *tree, GaimChat *chat)
470 { 595 {
471 GaimMenuAction *action = gaim_menu_action_new(_("Auto-join"), NULL, chat, NULL); 596 GaimMenuAction *action = gaim_menu_action_new(_("Auto-join"), NULL, chat, NULL);
472 597
473 gnt_tree_add_choice(tree, action, gnt_tree_create_row(tree, action->label), NULL, NULL); 598 gnt_tree_add_choice(tree, action, gnt_tree_create_row(tree, action->label), NULL, NULL);
474 gnt_tree_set_choice(tree, action, gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin")); 599 gnt_tree_set_choice(tree, action, gaim_blist_node_get_bool((GaimBlistNode*)chat, "gnt-autojoin"));
475 600
476 g_signal_connect_swapped(G_OBJECT(tree), "destroy", 601 g_signal_connect_swapped(G_OBJECT(tree), "destroy",
477 G_CALLBACK(gaim_menu_action_free), action); 602 G_CALLBACK(gaim_menu_action_free), action);
603
604 add_custom_action(tree, _("Edit Settings"), (GaimCallback)chat_components_edit, chat);
605
478 g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(context_menu_toggle), NULL); 606 g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(context_menu_toggle), NULL);
479 } 607 }
480 608
481 static void 609 static void
482 gg_add_buddy(GaimGroup *grp, GaimBlistNode *node) 610 gg_add_buddy(GaimGroup *grp, GaimBlistNode *node)
486 614
487 static void 615 static void
488 gg_add_group(GaimGroup *grp, GaimBlistNode *node) 616 gg_add_group(GaimGroup *grp, GaimBlistNode *node)
489 { 617 {
490 gaim_blist_request_add_group(); 618 gaim_blist_request_add_group();
619 }
620
621 static void
622 gg_add_chat(GaimGroup *grp, GaimBlistNode *node)
623 {
624 gaim_blist_request_add_chat(NULL, grp, NULL, NULL);
491 } 625 }
492 626
493 static void 627 static void
494 create_group_menu(GntTree *tree, GaimGroup *group) 628 create_group_menu(GntTree *tree, GaimGroup *group)
495 { 629 {
496 add_custom_action(tree, _("Add Buddy"), 630 add_custom_action(tree, _("Add Buddy"),
497 GAIM_CALLBACK(gg_add_buddy), group); 631 GAIM_CALLBACK(gg_add_buddy), group);
632 add_custom_action(tree, _("Add Chat"),
633 GAIM_CALLBACK(gg_add_chat), group);
498 add_custom_action(tree, _("Add Group"), 634 add_custom_action(tree, _("Add Group"),
499 GAIM_CALLBACK(gg_add_group), group); 635 GAIM_CALLBACK(gg_add_group), group);
500 } 636 }
501 637
502 static void 638 static void
1003 { 1139 {
1004 node->ui_data = NULL; 1140 node->ui_data = NULL;
1005 node = gaim_blist_node_next(node, TRUE); 1141 node = gaim_blist_node_next(node, TRUE);
1006 } 1142 }
1007 1143
1008 remove_typing_cb(NULL); 1144 if (ggblist->typing)
1145 g_source_remove(ggblist->typing);
1009 remove_peripherals(ggblist); 1146 remove_peripherals(ggblist);
1010 g_free(ggblist); 1147 g_free(ggblist);
1011 ggblist = NULL; 1148 ggblist = NULL;
1012 } 1149 }
1013 1150
1357 gnt_widget_destroy(ggblist->window); 1494 gnt_widget_destroy(ggblist->window);
1358 g_free(ggblist); 1495 g_free(ggblist);
1359 ggblist = NULL; 1496 ggblist = NULL;
1360 } 1497 }
1361 1498
1362 void gg_blist_get_position(int *x, int *y) 1499 gboolean gg_blist_get_position(int *x, int *y)
1363 { 1500 {
1501 if (!ggblist || !ggblist->window)
1502 return FALSE;
1364 gnt_widget_get_position(ggblist->window, x, y); 1503 gnt_widget_get_position(ggblist->window, x, y);
1504 return TRUE;
1365 } 1505 }
1366 1506
1367 void gg_blist_set_position(int x, int y) 1507 void gg_blist_set_position(int x, int y)
1368 { 1508 {
1369 gnt_widget_set_position(ggblist->window, x, y); 1509 gnt_widget_set_position(ggblist->window, x, y);
1370 } 1510 }
1371 1511
1372 void gg_blist_get_size(int *width, int *height) 1512 gboolean gg_blist_get_size(int *width, int *height)
1373 { 1513 {
1514 if (!ggblist || !ggblist->window)
1515 return FALSE;
1374 gnt_widget_get_size(ggblist->window, width, height); 1516 gnt_widget_get_size(ggblist->window, width, height);
1517 return TRUE;
1375 } 1518 }
1376 1519
1377 void gg_blist_set_size(int width, int height) 1520 void gg_blist_set_size(int width, int height)
1378 { 1521 {
1379 gnt_widget_set_size(ggblist->window, width, height); 1522 gnt_widget_set_size(ggblist->window, width, height);