annotate src/account.c @ 5580:86456ec3ca25

[gaim-migrate @ 5984] More nifty stuff! Accounts now get converted, and other niceties. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 31 May 2003 02:27:03 +0000
parents a95e872e58dc
children 3a9b54f260e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5574
a95e872e58dc [gaim-migrate @ 5978]
Christian Hammond <chipx86@chipx86.com>
parents: 5573
diff changeset
1 /*
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file account.c Account API
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * (at your option) any later version.
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * GNU General Public License for more details.
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 */
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
23 #ifdef HAVE_CONFIG_H
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
24 #include <config.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
25 #endif
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
26
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
27 #include <string.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
28 #include <stdio.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
29 #include <stdlib.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
30 #include <sys/stat.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
31 #include <sys/types.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
32 #include <glib.h>
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
33
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 #include "account.h"
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 #include "prefs.h"
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
37 typedef enum
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
38 {
5580
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
39 TAG_NONE = 0,
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
40 TAG_PROTOCOL,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
41 TAG_NAME,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
42 TAG_PASSWORD,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
43 TAG_ALIAS,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
44 TAG_USERINFO,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
45 TAG_BUDDYICON,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
46 TAG_SETTING
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
47
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
48 } AccountParserTag;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
49
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 typedef struct
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 GaimPrefType type;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 union
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 int integer;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 char *string;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 gboolean bool;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 } value;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 } GaimAccountSetting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
64 typedef struct
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
65 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
66 AccountParserTag tag;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
67
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
68 GaimAccount *account;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
69 GaimProtocol protocol;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
70
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
71 GString *buffer;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
72
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
73 GaimPrefType setting_type;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
74 char *setting_name;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
75
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
76 } AccountParserData;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
77
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
78 static GList *accounts = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
79 static guint accounts_save_timer = 0;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
80 static gboolean accounts_loaded = FALSE;
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 static void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 __delete_setting(void *data)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 GaimAccountSetting *setting = (GaimAccountSetting *)data;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 if (setting->type == GAIM_PREF_STRING)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 g_free(setting->value.string);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 g_free(setting);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
93 static gboolean
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
94 __accounts_save_cb(gpointer unused)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
95 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
96 gaim_accounts_sync();
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
97 accounts_save_timer = 0;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
98
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
99 return FALSE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
100 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
101
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
102 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
103 schedule_accounts_save()
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
104 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
105 if (!accounts_save_timer)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
106 accounts_save_timer = g_timeout_add(5000, __accounts_save_cb, NULL);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
107 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
108
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 GaimAccount *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 gaim_account_new(const char *username, GaimProtocol protocol)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 GaimAccount *account;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114 g_return_val_if_fail(username != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
116 account = g_new0(GaimAccount, 1);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118 gaim_account_set_username(account, username);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 gaim_account_set_protocol(account, protocol);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122 g_free, __delete_setting);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
124 accounts = g_list_append(accounts, account);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126 return account;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 gaim_account_destroy(GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134 if (account->gc != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
135 gaim_connection_destroy(account->gc);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
136
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
137 if (account->username != NULL) g_free(account->username);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138 if (account->alias != NULL) g_free(account->alias);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 if (account->password != NULL) g_free(account->password);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140 if (account->user_info != NULL) g_free(account->user_info);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 g_hash_table_destroy(account->settings);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
143
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
144 accounts = g_list_remove(accounts, account);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146 g_free(account);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149 GaimConnection *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150 gaim_account_connect(GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152 GaimConnection *gc;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155 g_return_val_if_fail(!gaim_account_is_connected(account), NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 gc = gaim_connection_new(account);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159 gaim_connection_connect(gc);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 return gc;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
163
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
164 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
165 gaim_account_disconnect(GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
166 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
167 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 g_return_if_fail(gaim_account_is_connected(account));
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 gaim_connection_disconnect(account->gc);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 gaim_connection_destroy(account->gc);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173 account->gc = NULL;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 gaim_account_set_username(GaimAccount *account, const char *username)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 g_return_if_fail(username != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 if (account->username != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183 g_free(account->username);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185 account->username = (username == NULL ? NULL : g_strdup(username));
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
186
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
187 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 gaim_account_set_password(GaimAccount *account, const char *password)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
194 g_return_if_fail(password != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
195
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
196 if (account->password != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197 g_free(account->password);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
199 account->password = (password == NULL ? NULL : g_strdup(password));
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
200
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
201 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
202 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
203
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
204 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
205 gaim_account_set_alias(GaimAccount *account, const char *alias)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
206 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
207 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
208 g_return_if_fail(alias != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
209
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
210 if (account->alias != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
211 g_free(account->alias);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
212
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
213 account->alias = (alias == NULL ? NULL : g_strdup(alias));
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
214
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
215 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
216 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
217
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
218 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219 gaim_account_set_user_info(GaimAccount *account, const char *user_info)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
220 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 g_return_if_fail(user_info != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
223
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
224 if (account->user_info != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
225 g_free(account->user_info);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
226
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227 account->user_info = (user_info == NULL ? NULL : g_strdup(user_info));
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
228
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
229 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
232 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
233 gaim_account_set_buddy_icon(GaimAccount *account, const char *icon)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
234 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236 g_return_if_fail(icon != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 if (account->buddy_icon != NULL)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239 g_free(account->buddy_icon);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
240
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241 account->buddy_icon = (icon == NULL ? NULL : g_strdup(icon));
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
242
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
243 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
244 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
247 gaim_account_set_protocol(GaimAccount *account, GaimProtocol protocol)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
250
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
251 account->protocol = protocol;
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
252
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
253 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
255
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
257 gaim_account_set_connection(GaimAccount *account, GaimConnection *gc)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
258 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 g_return_if_fail(gc != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
262 account->gc = gc;
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
263
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
264 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
265 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268 gaim_account_set_remember_password(GaimAccount *account, gboolean value)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
271
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
272 account->remember_pass = value;
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
273
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
274 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 gaim_account_set_int(GaimAccount *account, const char *name, int value)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283 g_return_if_fail(name != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
284
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 setting = g_new0(GaimAccountSetting, 1);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287 setting->type = GAIM_PREF_INT;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288 setting->value.integer = value;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 g_hash_table_insert(account->settings, g_strdup(name), setting);
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
291
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
292 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
293 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296 gaim_account_set_string(GaimAccount *account, const char *name,
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297 const char *value)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
298 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302 g_return_if_fail(name != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 setting = g_new0(GaimAccountSetting, 1);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306 setting->type = GAIM_PREF_STRING;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 setting->value.string = g_strdup(value);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
308
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 g_hash_table_insert(account->settings, g_strdup(name), setting);
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
310
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
311 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
312 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
313
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
314 void
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 gaim_account_set_bool(GaimAccount *account, const char *name, gboolean value)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
319 g_return_if_fail(account != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
320 g_return_if_fail(name != NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
321
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
322 setting = g_new0(GaimAccountSetting, 1);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
323
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
324 setting->type = GAIM_PREF_BOOLEAN;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
325 setting->value.bool = value;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
326
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
327 g_hash_table_insert(account->settings, g_strdup(name), setting);
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
328
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
329 schedule_accounts_save();
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
330 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
331
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
332 gboolean
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
333 gaim_account_is_connected(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
334 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
335 g_return_val_if_fail(account != NULL, FALSE);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
336
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
337 return (account->gc != NULL &&
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
338 gaim_connection_get_state(account->gc) == GAIM_CONNECTED);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
339 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
340
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 const char *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
342 gaim_account_get_username(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
343 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
344 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
345
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
346 return account->username;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
347 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
348
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349 const char *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
350 gaim_account_get_password(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
352 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
353
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354 return account->password;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
355 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
356
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
357 const char *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
358 gaim_account_get_alias(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
359 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
360 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
361
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
362 return account->alias;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
363 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
364
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
365 const char *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
366 gaim_account_get_user_info(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
367 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
368 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
369
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
370 return account->user_info;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
371 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
372
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
373 const char *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
374 gaim_account_get_buddy_icon(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
375 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
376 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
377
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
378 return account->buddy_icon;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
379 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
380
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
381 GaimProtocol
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
382 gaim_account_get_protocol(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
383 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
384 g_return_val_if_fail(account != NULL, -1);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
385
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
386 return account->protocol;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
387 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
388
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
389 GaimConnection *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
390 gaim_account_get_connection(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
391 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
392 g_return_val_if_fail(account != NULL, NULL);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
393
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
394 return account->gc;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
395 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
396
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
397 gboolean
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
398 gaim_account_get_remember_password(const GaimAccount *account)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
399 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
400 g_return_val_if_fail(account != NULL, FALSE);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
401
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
402 return account->remember_pass;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
403 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
404
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
405 gboolean
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
406 gaim_account_get_check_mail(const GaimAccount *account)
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
407 {
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
408 g_return_val_if_fail(account != NULL, FALSE);
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
409
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
410 return account->check_mail;
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
411 }
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
412
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
413 int
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
414 gaim_account_get_int(const GaimAccount *account, const char *name,
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
415 int default_value)
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
416 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
417 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
418
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
419 g_return_val_if_fail(account != NULL, default_value);
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
420 g_return_val_if_fail(name != NULL, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
421
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
422 setting = g_hash_table_lookup(account->settings, name);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
423
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
424 if (setting == NULL)
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
425 return default_value;
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
426
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
427 g_return_val_if_fail(setting->type == GAIM_PREF_INT, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
428
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
429 return setting->value.integer;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
430 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
431
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
432 const char *
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
433 gaim_account_get_string(const GaimAccount *account, const char *name,
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
434 const char *default_value)
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
435 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
436 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
437
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
438 g_return_val_if_fail(account != NULL, default_value);
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
439 g_return_val_if_fail(name != NULL, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
440
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
441 setting = g_hash_table_lookup(account->settings, name);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
442
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
443 if (setting == NULL)
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
444 return default_value;
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
445
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
446 g_return_val_if_fail(setting->type == GAIM_PREF_STRING, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
447
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
448 return setting->value.string;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
449 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
450
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
451 gboolean
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
452 gaim_account_get_bool(const GaimAccount *account, const char *name,
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
453 gboolean default_value)
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
454 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
455 GaimAccountSetting *setting;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
456
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
457 g_return_val_if_fail(account != NULL, default_value);
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
458 g_return_val_if_fail(name != NULL, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
459
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
460 setting = g_hash_table_lookup(account->settings, name);
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
461
5564
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
462 if (setting == NULL)
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
463 return default_value;
187c740f2a4e [gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents: 5563
diff changeset
464
5565
c3c4aaf69f65 [gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents: 5564
diff changeset
465 g_return_val_if_fail(setting->type == GAIM_PREF_BOOLEAN, default_value);
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
466
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
467 return setting->value.bool;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
468 }
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
469
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
470 /* XML Stuff */
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
471 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
472 __free_parser_data(gpointer user_data)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
473 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
474 AccountParserData *data = user_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
475
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
476 if (data->buffer != NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
477 g_free(data->buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
478
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
479 if (data->setting_name != NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
480 g_free(data->setting_name);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
481
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
482 g_free(data);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
483 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
484
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
485 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
486 __start_element_handler(GMarkupParseContext *context,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
487 const gchar *element_name,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
488 const gchar **attribute_names,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
489 const gchar **attribute_values,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
490 gpointer user_data, GError **error)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
491 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
492 AccountParserData *data = user_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
493 int i;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
494
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
495 if (data->buffer != NULL) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
496 g_string_free(data->buffer, TRUE);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
497 data->buffer = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
498 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
499
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
500 if (!strcmp(element_name, "protocol"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
501 data->tag = TAG_PROTOCOL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
502 else if (!strcmp(element_name, "name"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
503 data->tag = TAG_NAME;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
504 else if (!strcmp(element_name, "password"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
505 data->tag = TAG_PASSWORD;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
506 else if (!strcmp(element_name, "alias"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
507 data->tag = TAG_ALIAS;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
508 else if (!strcmp(element_name, "userinfo"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
509 data->tag = TAG_USERINFO;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
510 else if (!strcmp(element_name, "buddyicon"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
511 data->tag = TAG_BUDDYICON;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
512 else if (!strcmp(element_name, "setting")) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
513 data->tag = TAG_SETTING;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
514
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
515 for (i = 0; attribute_names[i] != NULL; i++) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
516
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
517 if (!strcmp(attribute_names[i], "name"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
518 data->setting_name = g_strdup(attribute_values[i]);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
519 else if (!strcmp(attribute_names[i], "type")) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
520
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
521 if (!strcmp(attribute_values[i], "string"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
522 data->setting_type = GAIM_PREF_STRING;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
523 else if (!strcmp(attribute_values[i], "int"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
524 data->setting_type = GAIM_PREF_INT;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
525 else if (!strcmp(attribute_values[i], "bool"))
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
526 data->setting_type = GAIM_PREF_BOOLEAN;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
527 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
528 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
529 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
530 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
531
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
532 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
533 __end_element_handler(GMarkupParseContext *context, const gchar *element_name,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
534 gpointer user_data, GError **error)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
535 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
536 AccountParserData *data = user_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
537 gchar *buffer;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
538
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
539 if (data->buffer == NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
540 return;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
541
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
542 buffer = g_string_free(data->buffer, FALSE);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
543 data->buffer = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
544
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
545 if (data->tag == TAG_PROTOCOL) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
546 GList *l;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
547 GaimPlugin *plugin;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
548
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
549 data->protocol = -1;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
550
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
551 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
552 plugin = (GaimPlugin *)l->data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
553
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
554 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
555 if (!strcmp(plugin->info->name, buffer)) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
556 data->protocol =
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
557 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
558
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
559 break;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
560 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
561 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
562 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
563 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
564 else if (data->tag == TAG_NAME)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
565 data->account = gaim_account_new(buffer, data->protocol);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
566 else if (data->tag == TAG_PASSWORD)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
567 gaim_account_set_password(data->account, buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
568 else if (data->tag == TAG_ALIAS)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
569 gaim_account_set_alias(data->account, buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
570 else if (data->tag == TAG_USERINFO)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
571 gaim_account_set_user_info(data->account, buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
572 else if (data->tag == TAG_BUDDYICON)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
573 gaim_account_set_buddy_icon(data->account, buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
574 else if (data->tag == TAG_SETTING) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
575 if (data->setting_type == GAIM_PREF_STRING)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
576 gaim_account_set_string(data->account, data->setting_name,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
577 buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
578 else if (data->setting_type == GAIM_PREF_INT)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
579 gaim_account_set_int(data->account, data->setting_name,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
580 atoi(buffer));
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
581 else if (data->setting_type == GAIM_PREF_BOOLEAN)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
582 gaim_account_set_bool(data->account, data->setting_name,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
583 (*buffer == '0' ? FALSE : TRUE));
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
584
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
585 g_free(data->setting_name);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
586 data->setting_name = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
587 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
588
5580
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
589 data->tag = TAG_NONE;
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
590
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
591 g_free(buffer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
592 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
593
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
594 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
595 __text_handler(GMarkupParseContext *context, const gchar *text,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
596 gsize text_len, gpointer user_data, GError **error)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
597 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
598 AccountParserData *data = user_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
599
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
600 if (data->buffer == NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
601 data->buffer = g_string_new_len(text, text_len);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
602 else
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
603 g_string_append_len(data->buffer, text, text_len);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
604 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
605
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
606 static GMarkupParser accounts_parser =
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
607 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
608 __start_element_handler,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
609 __end_element_handler,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
610 __text_handler,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
611 NULL,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
612 NULL
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
613 };
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
614
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
615 gboolean
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
616 gaim_accounts_load()
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
617 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
618 gchar *filename = g_build_filename(gaim_user_dir(), "accounts.xml", NULL);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
619 gchar *contents = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
620 gsize length;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
621 GMarkupParseContext *context;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
622 GError *error = NULL;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
623 AccountParserData *parser_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
624
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
625 if (filename == NULL) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
626 accounts_loaded = TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
627 return FALSE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
628 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
629
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
630 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Reading %s\n", filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
631
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
632 if (!g_file_get_contents(filename, &contents, &length, &error)) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
633 gaim_debug(GAIM_DEBUG_ERROR, "accounts",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
634 "Error reading accounts: %s\n", error->message);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
635
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
636 g_error_free(error);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
637
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
638 accounts_loaded = TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
639 return FALSE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
640 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
641
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
642 parser_data = g_new0(AccountParserData, 1);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
643
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
644 context = g_markup_parse_context_new(&accounts_parser, 0,
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
645 parser_data, __free_parser_data);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
646
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
647 if (!g_markup_parse_context_parse(context, contents, length, NULL)) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
648 g_markup_parse_context_free(context);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
649 g_free(contents);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
650
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
651 accounts_loaded = TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
652
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
653 return FALSE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
654 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
655
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
656 if (!g_markup_parse_context_end_parse(context, NULL)) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
657 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Error parsing %s\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
658 filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
659
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
660 g_markup_parse_context_free(context);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
661 g_free(contents);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
662 accounts_loaded = TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
663
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
664 return FALSE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
665 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
666
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
667 g_markup_parse_context_free(context);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
668 g_free(contents);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
669
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
670 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Finished reading %s\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
671 filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
672 g_free(filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
673
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
674 accounts_loaded = TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
675
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
676 return TRUE;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
677 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
678
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
679 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
680 __write_setting(gpointer key, gpointer value, gpointer user_data)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
681 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
682 GaimAccountSetting *setting;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
683 const char *name;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
684 FILE *fp;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
685
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
686 setting = (GaimAccountSetting *)value;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
687 name = (const char *)key;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
688 fp = (FILE *)user_data;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
689
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
690 if (setting->type == GAIM_PREF_INT) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
691 fprintf(fp, " <setting name='%s' type='int'>%d</setting>\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
692 name, setting->value.integer);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
693 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
694 else if (setting->type == GAIM_PREF_STRING) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
695 fprintf(fp, " <setting name='%s' type='string'>%s</setting>\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
696 name, setting->value.string);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
697 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
698 else if (setting->type == GAIM_PREF_BOOLEAN) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
699 fprintf(fp, " <setting name='%s' type='bool'>%d</setting>\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
700 name, setting->value.bool);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
701 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
702 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
703
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
704 static void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
705 gaim_accounts_write(FILE *fp, GaimAccount *account)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
706 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
707 GaimPlugin *plugin;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
708 const char *password, *alias, *user_info, *buddy_icon;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
709
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
710 plugin = gaim_find_prpl(gaim_account_get_protocol(account));
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
711
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
712 fprintf(fp, " <account>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
713 fprintf(fp, " <protocol>%s</protocol>\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
714 (plugin != NULL && plugin->info != NULL && plugin->info->id != NULL
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
715 ? plugin->info->id : "unknown"));
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
716 fprintf(fp, " <name>%s</name>\n", gaim_account_get_username(account));
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
717
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
718 if (gaim_account_get_remember_password(account) &&
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
719 (password = gaim_account_get_password(account)) != NULL) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
720
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
721 fprintf(fp, " <password>%s</password>\n", password);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
722 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
723
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
724 if ((alias = gaim_account_get_alias(account)) != NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
725 fprintf(fp, " <alias>%s</alias>\n", alias);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
726
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
727 if ((user_info = gaim_account_get_user_info(account)) != NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
728 fprintf(fp, " <userinfo>%s</userinfo>\n", user_info);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
729
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
730 if ((buddy_icon = gaim_account_get_buddy_icon(account)) != NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
731 fprintf(fp, " <buddyicon>%s</buddyicon>\n", buddy_icon);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
732
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
733 fprintf(fp, " <settings>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
734 g_hash_table_foreach(account->settings, __write_setting, fp);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
735 fprintf(fp, " </settings>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
736
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
737 fprintf(fp, " </account>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
738 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
739
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
740 void
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
741 gaim_accounts_sync(void)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
742 {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
743 FILE *fp;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
744 const char *user_dir = gaim_user_dir();
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
745 char *filename;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
746 char *filename_real;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
747
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
748 if (!accounts_loaded) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
749 gaim_debug(GAIM_DEBUG_WARNING, "accounts",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
750 "Writing accounts to disk.\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
751 schedule_accounts_save();
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
752 return;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
753 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
754
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
755 if (user_dir == NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
756 return;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
757
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
758 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Writing accounts to disk.\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
759
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
760 fp = fopen(user_dir, "r");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
761
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
762 if (fp == NULL)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
763 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
764 else
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
765 fclose(fp);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
766
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
767 filename = g_build_filename(user_dir, "accounts.xml.save", NULL);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
768
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
769 if ((fp = fopen(filename, "w")) != NULL) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
770 GList *l;
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
771
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
772 fprintf(fp, "<?xml version='1.0' encoding='UTF-8' ?>\n\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
773 fprintf(fp, "<accounts>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
774
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
775 for (l = gaim_accounts_get_all(); l != NULL; l = l->next)
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
776 gaim_accounts_write(fp, l->data);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
777
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
778 fprintf(fp, "</accounts>\n");
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
779
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
780 fclose(fp);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
781 chmod(filename, S_IRUSR | S_IWUSR);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
782 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
783 else {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
784 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Unable to write %s\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
785 filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
786 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
787
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
788 filename_real = g_build_filename(user_dir, "accounts.xml", NULL);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
789
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
790 if (rename(filename, filename_real) < 0) {
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
791 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Error renaming %s to %s\n",
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
792 filename, filename_real);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
793 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
794
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
795 g_free(filename);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
796 g_free(filename_real);
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
797 }
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
798
5580
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
799 void
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
800 gaim_accounts_reorder(GaimAccount *account, size_t new_index)
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
801 {
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
802 size_t index;
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
803 GList *l;
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
804
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
805 g_return_if_fail(account != NULL);
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
806 g_return_if_fail(new_index > 0 && new_index < g_list_length(accounts));
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
807
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
808 index = g_list_index(accounts, account);
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
809
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
810 if (index == -1) {
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
811 gaim_debug(GAIM_DEBUG_ERROR, "accounts",
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
812 "Unregistered account (%s) discovered during reorder!\n",
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
813 gaim_account_get_username(account));
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
814 return;
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
815 }
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
816
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
817 l = g_list_nth(accounts, index);
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
818
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
819 if (new_index > index)
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
820 new_index--;
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
821
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
822 /* Remove the old one. */
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
823 accounts = g_list_delete_link(accounts, l);
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
824
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
825 /* Insert it where it should go. */
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
826 accounts = g_list_insert(accounts, account, new_index);
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
827
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
828 schedule_accounts_save();
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5574
diff changeset
829 }
5573
5e7de337a053 [gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents: 5565
diff changeset
830
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
831 GList *
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
832 gaim_accounts_get_all(void)
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
833 {
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
834 return accounts;
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
835 }