comparison src/account.c @ 10738:55af3fa46329

[gaim-migrate @ 12340] Lots of changes here. A lot of it stems from chaning gaim_account_connect() so that it DOES NOT have the GaimStatus parameter. It will attempt to use the GaimStatus of your account from the last time it was connected (which doesn't work quite right yet). My goal here was to save and load each account's GaimStatuses to accounts.xml, so if you were "away" when you signed off then you'll be "away" when you sign back on. Not quite there yet. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 26 Mar 2005 20:08:43 +0000
parents 0e017707532f
children 94cc67130789
comparison
equal deleted inserted replaced
10737:b7f0bc436179 10738:55af3fa46329
114 g_hash_table_foreach(table, setting_to_xmlnode, child); 114 g_hash_table_foreach(table, setting_to_xmlnode, child);
115 } 115 }
116 } 116 }
117 117
118 static xmlnode * 118 static xmlnode *
119 status_to_xmlnode(const GaimStatus *status)
120 {
121 xmlnode *node;
122
123 node = xmlnode_new("status");
124 xmlnode_set_attrib(node, "type", gaim_status_get_id(status));
125 if (gaim_status_get_name(status) != NULL)
126 xmlnode_set_attrib(node, "name", gaim_status_get_name(status));
127 xmlnode_set_attrib(node, "active", gaim_status_is_active(status) ? "true" : "false");
128
129 /* QQQ: Need to save status->attr_values */
130
131 return node;
132 }
133
134 static xmlnode *
135 statuses_to_xmlnode(const GaimPresence *presence)
136 {
137 xmlnode *node, *child;
138 const GList *statuses, *status;
139
140 node = xmlnode_new("statuses");
141
142 statuses = gaim_presence_get_statuses(presence);
143 for (status = statuses; status != NULL; status = status->next)
144 {
145 child = status_to_xmlnode((GaimStatus *)status->data);
146 xmlnode_insert_child(node, child);
147 }
148
149 return node;
150 }
151
152 static xmlnode *
119 proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info) 153 proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info)
120 { 154 {
121 xmlnode *node, *child; 155 xmlnode *node, *child;
122 GaimProxyType proxy_type; 156 GaimProxyType proxy_type;
123 const char *value; 157 const char *value;
173 static xmlnode * 207 static xmlnode *
174 account_to_xmlnode(GaimAccount *account) 208 account_to_xmlnode(GaimAccount *account)
175 { 209 {
176 xmlnode *node, *child; 210 xmlnode *node, *child;
177 const char *tmp; 211 const char *tmp;
212 GaimPresence *presence;
178 GaimProxyInfo *proxy_info; 213 GaimProxyInfo *proxy_info;
179 214
180 node = xmlnode_new("account"); 215 node = xmlnode_new("account");
181 216
182 child = xmlnode_new_child(node, "protocol"); 217 child = xmlnode_new_child(node, "protocol");
194 229
195 if ((tmp = gaim_account_get_alias(account)) != NULL) 230 if ((tmp = gaim_account_get_alias(account)) != NULL)
196 { 231 {
197 child = xmlnode_new_child(node, "alias"); 232 child = xmlnode_new_child(node, "alias");
198 xmlnode_insert_data(child, tmp, -1); 233 xmlnode_insert_data(child, tmp, -1);
234 }
235
236 if ((presence = gaim_account_get_presence(account)) != NULL)
237 {
238 child = statuses_to_xmlnode(presence);
239 xmlnode_insert_child(node, child);
199 } 240 }
200 241
201 if ((tmp = gaim_account_get_user_info(account)) != NULL) 242 if ((tmp = gaim_account_get_user_info(account)) != NULL)
202 { 243 {
203 /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */ 244 /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */
349 gaim_account_set_ui_bool(account, ui, name, 390 gaim_account_set_ui_bool(account, ui, name,
350 (*data == '0' ? FALSE : TRUE)); 391 (*data == '0' ? FALSE : TRUE));
351 } 392 }
352 393
353 g_free(data); 394 g_free(data);
395 }
396 }
397
398 static void
399 parse_status(xmlnode *node, GaimAccount *account)
400 {
401 gboolean active = FALSE;
402 const char *data;
403 const char *type;
404 xmlnode *child;
405
406 /* Get the active/inactive state */
407 child = xmlnode_get_child(node, "active");
408 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
409 {
410 if (strcasecmp(data, "true") == 0)
411 active = TRUE;
412 else if (strcasecmp(data, "false") == 0)
413 active = FALSE;
414 else
415 return;
416 }
417 else
418 return;
419
420 /* Get the type of the status */
421 child = xmlnode_get_child(node, "type");
422 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
423 {
424 type = data;
425 }
426 else
427 return;
428
429 /* QQQ: Need to read attributes into a vargs */
430
431 /* QQQ: This needs to do a better job of adding attributes and stuff */
432 /* Use gaim_account_set_status_vargs(); */
433 gaim_account_set_status(account, type, active);
434 }
435
436 static void
437 parse_statuses(xmlnode *node, GaimAccount *account)
438 {
439 xmlnode *child;
440
441 for (child = xmlnode_get_child(node, "status"); child != NULL;
442 child = xmlnode_get_next_twin(child))
443 {
444 parse_status(child, account);
354 } 445 }
355 } 446 }
356 447
357 static void 448 static void
358 parse_proxy_info(xmlnode *node, GaimAccount *account) 449 parse_proxy_info(xmlnode *node, GaimAccount *account)
487 { 578 {
488 gaim_account_set_alias(ret, data); 579 gaim_account_set_alias(ret, data);
489 g_free(data); 580 g_free(data);
490 } 581 }
491 582
583 /* Read the statuses */
584 child = xmlnode_get_child(node, "statuses");
585 if (child != NULL)
586 {
587 parse_statuses(child, ret);
588 }
589
492 /* Read the userinfo */ 590 /* Read the userinfo */
493 child = xmlnode_get_child(node, "userinfo"); 591 child = xmlnode_get_child(node, "userinfo");
494 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) 592 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
495 { 593 {
496 gaim_account_set_user_info(ret, data); 594 gaim_account_set_user_info(ret, data);
590 prpl = gaim_find_prpl(protocol_id); 688 prpl = gaim_find_prpl(protocol_id);
591 689
592 if (prpl == NULL) 690 if (prpl == NULL)
593 return account; 691 return account;
594 692
693 /* TODO: Should maybe use gaim_prpl_get_statuses()? */
595 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); 694 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
596 if (prpl_info != NULL && prpl_info->status_types != NULL ) 695 if (prpl_info != NULL && prpl_info->status_types != NULL)
597 gaim_account_set_status_types(account, prpl_info->status_types(account)); 696 gaim_account_set_status_types(account, prpl_info->status_types(account));
598 697
599 gaim_presence_set_status_active(account->presence, "offline", TRUE); 698 gaim_presence_set_status_active(account->presence, "offline", TRUE);
600 699
601 return account; 700 return account;
661 760
662 return gc; 761 return gc;
663 } 762 }
664 763
665 GaimConnection * 764 GaimConnection *
666 gaim_account_connect(GaimAccount *account, GaimStatus *status) 765 gaim_account_connect(GaimAccount *account)
667 { 766 {
668 GaimConnection *gc; 767 GaimConnection *gc;
669 768
670 g_return_val_if_fail(account != NULL, NULL); 769 g_return_val_if_fail(account != NULL, NULL);
671 770
675 gc = gaim_connection_new(account); 774 gc = gaim_connection_new(account);
676 775
677 gaim_debug_info("account", "Connecting to account %p. gc = %p\n", 776 gaim_debug_info("account", "Connecting to account %p. gc = %p\n",
678 account, gc); 777 account, gc);
679 778
680 gaim_connection_connect(gc, status); 779 gaim_connection_connect(gc);
681 780
682 return gc; 781 return gc;
683 } 782 }
684 783
685 void 784 void
988 1087
989 void 1088 void
990 gaim_account_set_status(GaimAccount *account, const char *status_id, 1089 gaim_account_set_status(GaimAccount *account, const char *status_id,
991 gboolean active, ...) 1090 gboolean active, ...)
992 { 1091 {
1092 va_list args;
1093
1094 va_start(args, active);
1095 gaim_account_set_status_vargs(account, status_id, active, args);
1096 va_end(args);
1097 }
1098
1099 void
1100 gaim_account_set_status_vargs(GaimAccount *account, const char *status_id,
1101 gboolean active, va_list args)
1102 {
993 GaimStatus *status; 1103 GaimStatus *status;
994 GaimStatusType *status_type; 1104 GaimStatusType *status_type;
995 va_list args;
996 1105
997 g_return_if_fail(account != NULL); 1106 g_return_if_fail(account != NULL);
998 g_return_if_fail(status_id != NULL); 1107 g_return_if_fail(status_id != NULL);
999 1108
1000 status = gaim_account_get_status(account, status_id); 1109 status = gaim_account_get_status(account, status_id);
1021 return; 1130 return;
1022 } 1131 }
1023 1132
1024 /* TODO: Record the status in accounts.xml? */ 1133 /* TODO: Record the status in accounts.xml? */
1025 1134
1026 va_start(args, active);
1027 gaim_status_set_active_with_attrs(status, active, args); 1135 gaim_status_set_active_with_attrs(status, active, args);
1028 va_end(args); 1136 gaim_presence_set_status_active(gaim_account_get_presence(account), status_id, active);
1029 1137
1030 /* 1138 /*
1031 * If this account should be connected, but is not, then connect. 1139 * If this account should be connected, but is not, then connect.
1032 */ 1140 */
1033 if (active && 1141 if (active &&
1034 (gaim_status_type_get_primitive(status_type) != GAIM_STATUS_OFFLINE) && 1142 (gaim_status_type_get_primitive(status_type) != GAIM_STATUS_OFFLINE) &&
1035 !gaim_account_is_connected(account)) 1143 !gaim_account_is_connected(account))
1036 { 1144 {
1037 gaim_account_connect(account, status); 1145 gaim_account_connect(account);
1038 } 1146 }
1039 } 1147 }
1040 1148
1041 void 1149 void
1042 gaim_account_clear_settings(GaimAccount *account) 1150 gaim_account_clear_settings(GaimAccount *account)
1303 gaim_account_get_proxy_info(const GaimAccount *account) 1411 gaim_account_get_proxy_info(const GaimAccount *account)
1304 { 1412 {
1305 g_return_val_if_fail(account != NULL, NULL); 1413 g_return_val_if_fail(account != NULL, NULL);
1306 1414
1307 return account->proxy_info; 1415 return account->proxy_info;
1416 }
1417
1418 GaimStatus *
1419 gaim_account_get_active_status(const GaimAccount *account)
1420 {
1421 g_return_val_if_fail(account != NULL, NULL);
1422
1423 return gaim_presence_get_active_status(account->presence);
1308 } 1424 }
1309 1425
1310 GaimStatus * 1426 GaimStatus *
1311 gaim_account_get_status(const GaimAccount *account, const char *status_id) 1427 gaim_account_get_status(const GaimAccount *account, const char *status_id)
1312 { 1428 {
1586 1702
1587 gaim_account_destroy(account); 1703 gaim_account_destroy(account);
1588 } 1704 }
1589 1705
1590 void 1706 void
1591 gaim_accounts_auto_login(const char *ui)
1592 {
1593 GaimAccount *account;
1594 GList *l;
1595
1596 g_return_if_fail(ui != NULL);
1597
1598 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
1599 account = l->data;
1600
1601 /* TODO: Shouldn't be be using some sort of saved status here? */
1602 if (gaim_account_get_enabled(account, ui))
1603 gaim_account_connect(account, gaim_account_get_status(account, "online"));
1604 }
1605 }
1606
1607 void
1608 gaim_accounts_reorder(GaimAccount *account, size_t new_index) 1707 gaim_accounts_reorder(GaimAccount *account, size_t new_index)
1609 { 1708 {
1610 size_t index; 1709 size_t index;
1611 GList *l; 1710 GList *l;
1612 1711