# HG changeset patch # User Mark Doliner # Date 1111867723 0 # Node ID 55af3fa46329005844a5e25e8f86c08654d80b45 # Parent b7f0bc4361796db9b010c3045252fb3b2bbe5d95 [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 diff -r b7f0bc436179 -r 55af3fa46329 plugins/autorecon.c --- a/plugins/autorecon.c Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/autorecon.c Sat Mar 26 20:08:43 2005 +0000 @@ -140,8 +140,7 @@ info->timeout = 0; gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); - /* XXX: make this remember the status from disconnect */ - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); return FALSE; diff -r b7f0bc436179 -r 55af3fa46329 plugins/docklet/docklet.c --- a/plugins/docklet/docklet.c Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/docklet/docklet.c Sat Mar 26 20:08:43 2005 +0000 @@ -82,12 +82,6 @@ gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); } -static void -docklet_auto_login() -{ - gaim_accounts_auto_login(GAIM_GTK_UI); -} - #ifdef _WIN32 #if 0 /* XXX NEW STATUS */ /* This is workaround for a bug in windows GTK+. Clicking outside of the @@ -137,7 +131,7 @@ switch (status) { case offline: case offline_connecting: - gaim_new_item_from_stock(menu, _("Auto-login"), GAIM_STOCK_SIGN_ON, G_CALLBACK(docklet_auto_login), NULL, 0, 0, NULL); + /* No special menu items right now */ break; default: gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(gaim_gtkdialogs_im), NULL, 0, 0, NULL); @@ -356,14 +350,7 @@ #endif break; case 2: - switch (status) { - case offline: - case offline_connecting: - docklet_auto_login(); - break; - default: - break; - } + /* Don't do anything for middle click */ break; case 3: docklet_menu(); diff -r b7f0bc436179 -r 55af3fa46329 plugins/filectl.c --- a/plugins/filectl.c Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/filectl.c Sat Mar 26 20:08:43 2005 +0000 @@ -79,9 +79,7 @@ account = gaim_accounts_find(arg1, arg2); if (account != NULL) { - gc = gaim_account_get_connection(account); - if (gc != NULL) - gaim_connection_disconnect(gc); + gaim_account_disconnect(account); } else if (arg1 == NULL) gaim_connections_disconnect_all(); diff -r b7f0bc436179 -r 55af3fa46329 plugins/gaim-remote/remote.c --- a/plugins/gaim-remote/remote.c Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/gaim-remote/remote.c Sat Mar 26 20:08:43 2005 +0000 @@ -392,8 +392,7 @@ memcpy(&id, data, sizeof(id)); account = g_list_nth_data(gaim_accounts_get_all(), id); if (account) - /* XXX: someone might want to extend this to allow connecting with a different status */ - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); /* don't need to do anything here because the UI will get updates from other handlers */ break; diff -r b7f0bc436179 -r 55af3fa46329 plugins/perl/common/Account.xs --- a/plugins/perl/common/Account.xs Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/perl/common/Account.xs Sat Mar 26 20:08:43 2005 +0000 @@ -7,8 +7,7 @@ gaim_account_connect(account) Gaim::Account account CODE: - RETVAL = gaim_account_connect(account, - gaim_account_get_status(account, "online")); + RETVAL = gaim_account_connect(account); OUTPUT: RETVAL diff -r b7f0bc436179 -r 55af3fa46329 plugins/tcl/tcl_cmds.c --- a/plugins/tcl/tcl_cmds.c Sat Mar 26 19:19:33 2005 +0000 +++ b/plugins/tcl/tcl_cmds.c Sat Mar 26 20:08:43 2005 +0000 @@ -122,9 +122,7 @@ if (gaim_account_is_connected(account)) Tcl_SetIntObj(result, (int)gaim_account_get_connection(account)); else -#warning Someone who knows TCL (Ethan!) fix this so TCL plugins can specify the status - Tcl_SetIntObj(result, (int)gaim_account_connect(account, - gaim_account_get_status(account, "online"))); + Tcl_SetIntObj(result, (int)gaim_account_connect(account)); break; case CMD_ACCOUNT_CONNECTION: if (objc != 3) { diff -r b7f0bc436179 -r 55af3fa46329 src/account.c --- a/src/account.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/account.c Sat Mar 26 20:08:43 2005 +0000 @@ -116,6 +116,40 @@ } static xmlnode * +status_to_xmlnode(const GaimStatus *status) +{ + xmlnode *node; + + node = xmlnode_new("status"); + xmlnode_set_attrib(node, "type", gaim_status_get_id(status)); + if (gaim_status_get_name(status) != NULL) + xmlnode_set_attrib(node, "name", gaim_status_get_name(status)); + xmlnode_set_attrib(node, "active", gaim_status_is_active(status) ? "true" : "false"); + + /* QQQ: Need to save status->attr_values */ + + return node; +} + +static xmlnode * +statuses_to_xmlnode(const GaimPresence *presence) +{ + xmlnode *node, *child; + const GList *statuses, *status; + + node = xmlnode_new("statuses"); + + statuses = gaim_presence_get_statuses(presence); + for (status = statuses; status != NULL; status = status->next) + { + child = status_to_xmlnode((GaimStatus *)status->data); + xmlnode_insert_child(node, child); + } + + return node; +} + +static xmlnode * proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info) { xmlnode *node, *child; @@ -175,6 +209,7 @@ { xmlnode *node, *child; const char *tmp; + GaimPresence *presence; GaimProxyInfo *proxy_info; node = xmlnode_new("account"); @@ -198,6 +233,12 @@ xmlnode_insert_data(child, tmp, -1); } + if ((presence = gaim_account_get_presence(account)) != NULL) + { + child = statuses_to_xmlnode(presence); + xmlnode_insert_child(node, child); + } + if ((tmp = gaim_account_get_user_info(account)) != NULL) { /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */ @@ -355,6 +396,56 @@ } static void +parse_status(xmlnode *node, GaimAccount *account) +{ + gboolean active = FALSE; + const char *data; + const char *type; + xmlnode *child; + + /* Get the active/inactive state */ + child = xmlnode_get_child(node, "active"); + if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) + { + if (strcasecmp(data, "true") == 0) + active = TRUE; + else if (strcasecmp(data, "false") == 0) + active = FALSE; + else + return; + } + else + return; + + /* Get the type of the status */ + child = xmlnode_get_child(node, "type"); + if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) + { + type = data; + } + else + return; + + /* QQQ: Need to read attributes into a vargs */ + + /* QQQ: This needs to do a better job of adding attributes and stuff */ + /* Use gaim_account_set_status_vargs(); */ + gaim_account_set_status(account, type, active); +} + +static void +parse_statuses(xmlnode *node, GaimAccount *account) +{ + xmlnode *child; + + for (child = xmlnode_get_child(node, "status"); child != NULL; + child = xmlnode_get_next_twin(child)) + { + parse_status(child, account); + } +} + +static void parse_proxy_info(xmlnode *node, GaimAccount *account) { GaimProxyInfo *proxy_info; @@ -489,6 +580,13 @@ g_free(data); } + /* Read the statuses */ + child = xmlnode_get_child(node, "statuses"); + if (child != NULL) + { + parse_statuses(child, ret); + } + /* Read the userinfo */ child = xmlnode_get_child(node, "userinfo"); if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) @@ -592,8 +690,9 @@ if (prpl == NULL) return account; + /* TODO: Should maybe use gaim_prpl_get_statuses()? */ prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); - if (prpl_info != NULL && prpl_info->status_types != NULL ) + if (prpl_info != NULL && prpl_info->status_types != NULL) gaim_account_set_status_types(account, prpl_info->status_types(account)); gaim_presence_set_status_active(account->presence, "offline", TRUE); @@ -663,7 +762,7 @@ } GaimConnection * -gaim_account_connect(GaimAccount *account, GaimStatus *status) +gaim_account_connect(GaimAccount *account) { GaimConnection *gc; @@ -677,7 +776,7 @@ gaim_debug_info("account", "Connecting to account %p. gc = %p\n", account, gc); - gaim_connection_connect(gc, status); + gaim_connection_connect(gc); return gc; } @@ -990,9 +1089,19 @@ gaim_account_set_status(GaimAccount *account, const char *status_id, gboolean active, ...) { + va_list args; + + va_start(args, active); + gaim_account_set_status_vargs(account, status_id, active, args); + va_end(args); +} + +void +gaim_account_set_status_vargs(GaimAccount *account, const char *status_id, + gboolean active, va_list args) +{ GaimStatus *status; GaimStatusType *status_type; - va_list args; g_return_if_fail(account != NULL); g_return_if_fail(status_id != NULL); @@ -1023,9 +1132,8 @@ /* TODO: Record the status in accounts.xml? */ - va_start(args, active); gaim_status_set_active_with_attrs(status, active, args); - va_end(args); + gaim_presence_set_status_active(gaim_account_get_presence(account), status_id, active); /* * If this account should be connected, but is not, then connect. @@ -1034,7 +1142,7 @@ (gaim_status_type_get_primitive(status_type) != GAIM_STATUS_OFFLINE) && !gaim_account_is_connected(account)) { - gaim_account_connect(account, status); + gaim_account_connect(account); } } @@ -1308,6 +1416,14 @@ } GaimStatus * +gaim_account_get_active_status(const GaimAccount *account) +{ + g_return_val_if_fail(account != NULL, NULL); + + return gaim_presence_get_active_status(account->presence); +} + +GaimStatus * gaim_account_get_status(const GaimAccount *account, const char *status_id) { g_return_val_if_fail(account != NULL, NULL); @@ -1588,23 +1704,6 @@ } void -gaim_accounts_auto_login(const char *ui) -{ - GaimAccount *account; - GList *l; - - g_return_if_fail(ui != NULL); - - for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { - account = l->data; - - /* TODO: Shouldn't be be using some sort of saved status here? */ - if (gaim_account_get_enabled(account, ui)) - gaim_account_connect(account, gaim_account_get_status(account, "online")); - } -} - -void gaim_accounts_reorder(GaimAccount *account, size_t new_index) { size_t index; diff -r b7f0bc436179 -r 55af3fa46329 src/account.h --- a/src/account.h Sat Mar 26 19:19:33 2005 +0000 +++ b/src/account.h Sat Mar 26 20:08:43 2005 +0000 @@ -117,7 +117,7 @@ * * @return The gaim connection. */ -GaimConnection *gaim_account_connect(GaimAccount *account, GaimStatus *status); +GaimConnection *gaim_account_connect(GaimAccount *account); /** * Registers an account. @@ -276,7 +276,8 @@ void gaim_account_set_presence(GaimAccount *account, GaimPresence *presence); /** - * Activates or deactivates a status. + * Activates or deactivates a status. All changes to the statuses of + * an account go through this function or gaim_account_set_status_vargs. * * Only independent statuses can be deactivated with this. To deactivate * an exclusive status, activate a different (and exclusive?) status. @@ -290,6 +291,23 @@ void gaim_account_set_status(GaimAccount *account, const char *status_id, gboolean active, ...); + +/** + * Activates or deactivates a status. All changes to the statuses of + * an account go through this function or gaim_account_set_status. + * + * Only independent statuses can be deactivated with this. To deactivate + * an exclusive status, activate a different (and exclusive?) status. + * + * @param account The account. + * @param status_id The ID of the status. + * @param active The active state. + * @param vargs The va_list of attributes. + */ +void gaim_account_set_status_vargs(GaimAccount *account, + const char *status_id, + gboolean active, va_list args); + /** * Clears all protocol-specific settings on an account. * @@ -480,6 +498,18 @@ GaimProxyInfo *gaim_account_get_proxy_info(const GaimAccount *account); /** + * Returns the active status for this account. This looks through + * the GaimPresence associated with this account and returns the + * GaimStatus that has its active flag set to "TRUE." There can be + * only one active GaimStatus in a GaimPresence. + * + * @param account The account. + * + * @return The active status. + */ +GaimStatus *gaim_account_get_active_status(const GaimAccount *account); + +/** * Returns the account status with the specified ID. * * Note that this works differently than gaim_buddy_get_status() in that @@ -669,13 +699,6 @@ void gaim_accounts_delete(GaimAccount *account); /** - * Auto-logins to all accounts set to auto-login under the specified UI. - * - * @param ui The UI. - */ -void gaim_accounts_auto_login(const char *ui); - -/** * Reorders an account. * * @param account The account to reorder. diff -r b7f0bc436179 -r 55af3fa46329 src/connection.c --- a/src/connection.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/connection.c Sat Mar 26 20:08:43 2005 +0000 @@ -89,8 +89,7 @@ { gaim_account_set_password(account, (*entry != '\0') ? entry : NULL); - /* XXX - connect with correct status */ - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); } void @@ -144,10 +143,11 @@ void -gaim_connection_connect(GaimConnection *gc, GaimStatus *status) +gaim_connection_connect(GaimConnection *gc) { GaimAccount *account; GaimPluginProtocolInfo *prpl_info = NULL; + GaimStatus *status; g_return_if_fail(gc != NULL); @@ -200,6 +200,7 @@ gaim_debug_info("connection", "Calling serv_login\n"); + status = gaim_account_get_active_status(account); serv_login(account, status); } @@ -265,13 +266,8 @@ gaim_connection_disconnect_cb(gpointer data) { GaimAccount *account = data; - GaimConnection *gc = gaim_account_get_connection(account); - if (!gaim_account_get_remember_password(account)) - gaim_account_set_password(account,NULL); - - if (gc != NULL) - gaim_connection_disconnect(gc); + gaim_account_disconnect(account); return FALSE; } diff -r b7f0bc436179 -r 55af3fa46329 src/connection.h --- a/src/connection.h Sat Mar 26 19:19:33 2005 +0000 +++ b/src/connection.h Sat Mar 26 20:08:43 2005 +0000 @@ -129,14 +129,21 @@ void gaim_connection_destroy(GaimConnection *gc); /** - * Logs in to this connection. + * This function should only be called by gaim_connection_connect() + * in account.c. If you're trying to sign on an account, use that + * function instead. + * + * Logs in to this connection. The connection uses the current + * active status in the account as the initial status. So if + * you want to sign on as "away," for example, you need to + * have called gaim_account_set_status(account, "away"). + * (And generally this has the effect of also signin on). * * @param gc The connection to log in. - * @param status The status to login to. * * @see gaim_connection_disconnect() */ -void gaim_connection_connect(GaimConnection *gc, GaimStatus *status); +void gaim_connection_connect(GaimConnection *gc); /** * Registers a connection. @@ -146,6 +153,10 @@ void gaim_connection_register(GaimConnection *gc); /** + * This function should only be called by gaim_connection_disconnect() + * in account.c. If you're trying to sign out an account, use that + * function instead. + * * Logs out of this connection. * * @param gc The connection to log out. diff -r b7f0bc436179 -r 55af3fa46329 src/gtkblist.c --- a/src/gtkblist.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/gtkblist.c Sat Mar 26 20:08:43 2005 +0000 @@ -4344,7 +4344,6 @@ gtk_table_attach_defaults(GTK_TABLE(table), data->account_box, 1, 2, 3, 4); gaim_set_accessible_label (data->account_box, label); - /* End of account box */ g_signal_connect(G_OBJECT(data->window), "response", diff -r b7f0bc436179 -r 55af3fa46329 src/gtkconn.c --- a/src/gtkconn.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/gtkconn.c Sat Mar 26 20:08:43 2005 +0000 @@ -222,7 +222,7 @@ l_accts_iter = l_accts; while (l_accts_iter != NULL) { account = l_accts_iter->data; - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); l_accts_iter = l_accts_iter->next; } g_list_free(l_accts); @@ -279,7 +279,7 @@ g_list_free(l_del); } - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); disconnect_window_update_buttons(model); break; diff -r b7f0bc436179 -r 55af3fa46329 src/gtkmain.c --- a/src/gtkmain.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/gtkmain.c Sat Mar 26 20:08:43 2005 +0000 @@ -114,14 +114,14 @@ account = gaim_accounts_find(names[i], NULL); if (account != NULL) { /* found a user */ ret = 0; - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); } } g_strfreev(names); } else { /* no name given, use the first account */ account = (GaimAccount *)gaim_accounts_get_all()->data; ret = 0; - gaim_account_connect(account, gaim_account_get_status(account, "online")); + gaim_account_connect(account); } return ret; @@ -456,7 +456,6 @@ int opt; gboolean gui_check; gboolean debug_enabled; - gchar *gaimrc, *accountsxml; #if HAVE_SIGNAL_H char errmsg[BUFSIZ]; #endif @@ -624,21 +623,6 @@ abort(); } - /* TODO: Remove this check. Maybe in 2005. --KingAnt, 25 Jul 2004 */ - gaimrc = g_build_filename(gaim_home_dir(), ".gaimrc", NULL); - accountsxml = g_build_filename(gaim_user_dir(), "accounts.xml", NULL); - if (g_file_test(gaimrc, G_FILE_TEST_EXISTS) && - !g_file_test(accountsxml, G_FILE_TEST_EXISTS)) - { - gaim_notify_error(NULL, NULL, _("Unable to load preferences"), - _("Gaim was not able to load your preferences " - "because they are stored in an old format " - "that is no longer used. Please reconfigure " - "your settings using the Preferences window.")); - } - g_free(gaimrc); - g_free(accountsxml); - /* TODO: Move blist loading into gaim_blist_init() */ gaim_set_blist(gaim_blist_new()); gaim_blist_load(); @@ -681,8 +665,10 @@ } } - if (!opt_acct && !opt_nologin) - gaim_accounts_auto_login(GAIM_GTK_UI); + if (!opt_acct && opt_nologin) + { + /* TODO: Need to disable all accounts or set them all to offline */ + } if (opt_acct || (gaim_accounts_get_all() == NULL)) { gaim_gtk_accounts_window_show(); diff -r b7f0bc436179 -r 55af3fa46329 src/protocols/irc/irc.c --- a/src/protocols/irc/irc.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/protocols/irc/irc.c Sat Mar 26 20:08:43 2005 +0000 @@ -447,7 +447,7 @@ args[0] = NULL; if (strcmp(status_id, "offline") && !gc) { - gaim_account_connect(account, status); + gaim_account_connect(account); } else if (!strcmp(status_id, "away")) { args[0] = gaim_status_get_attr_string(status, "message"); irc_cmd_away(irc, "away", NULL, args); diff -r b7f0bc436179 -r 55af3fa46329 src/protocols/jabber/presence.c --- a/src/protocols/jabber/presence.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/protocols/jabber/presence.c Sat Mar 26 20:08:43 2005 +0000 @@ -104,7 +104,7 @@ gc = account->gc; if (!gc && strcmp(gaim_status_get_id(status), "offline")) - gaim_account_connect(account, status); + gaim_account_connect(account); if(!gc) return; js= gc->proto_data; diff -r b7f0bc436179 -r 55af3fa46329 src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/protocols/msn/msn.c Sat Mar 26 20:08:43 2005 +0000 @@ -831,7 +831,7 @@ gaim_debug_info("msn", "Set status to %s\n", gaim_status_get_name(status)); if (strcmp(state, "offline") && !gc) { - gaim_account_connect(account, status); + gaim_account_connect(account); return; } else if (!strcmp(state, "away")) diff -r b7f0bc436179 -r 55af3fa46329 src/protocols/oscar/oscar.c --- a/src/protocols/oscar/oscar.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/protocols/oscar/oscar.c Sat Mar 26 20:08:43 2005 +0000 @@ -5856,7 +5856,7 @@ return; if (primitive == !GAIM_STATUS_OFFLINE && !gc) { - gaim_account_connect(account, status); + gaim_account_connect(account); } else if (primitive == GAIM_STATUS_OFFLINE && gc) { gaim_account_disconnect(account); } else { diff -r b7f0bc436179 -r 55af3fa46329 src/protocols/yahoo/yahoo.c --- a/src/protocols/yahoo/yahoo.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/protocols/yahoo/yahoo.c Sat Mar 26 20:08:43 2005 +0000 @@ -2772,7 +2772,7 @@ if (!gaim_status_is_active(status)) return; if (strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && !gc) { - gaim_account_connect(account, status); + gaim_account_connect(account); return; } else if (!strcmp(id, YAHOO_STATUS_TYPE_OFFLINE) && gc) { gaim_account_disconnect(account); diff -r b7f0bc436179 -r 55af3fa46329 src/savedstatuses.c --- a/src/savedstatuses.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/savedstatuses.c Sat Mar 26 20:08:43 2005 +0000 @@ -41,6 +41,8 @@ * The changes to status.xml caused by the new status API * are fully backward compatible. The new status API just * adds the optional sub-statuses to the XML file. + * + * TODO: This should probably just use a GaimStatus... */ struct _GaimSavedStatus { diff -r b7f0bc436179 -r 55af3fa46329 src/status.c --- a/src/status.c Sat Mar 26 19:19:33 2005 +0000 +++ b/src/status.c Sat Mar 26 20:08:43 2005 +0000 @@ -786,7 +786,9 @@ } if (status->active != active) + { changed = TRUE; + } status->active = active; @@ -1272,17 +1274,15 @@ "(%s) inactive. Only independent statuses " "can be specifically marked inactive.", status_id); - return; } - } else if (presence->active_status != NULL) { - gaim_status_set_active(presence->active_status, FALSE); - + if (presence->active_status != NULL) + gaim_status_set_active(presence->active_status, FALSE); + presence->active_status = status; } gaim_status_set_active(status, active); - presence->active_status = status; } void