comparison src/account.c @ 9944:e4a27c9aec4c

[gaim-migrate @ 10838] with much rejoicing, and massive thanks to the efforts of Christian, and all who have helped him, I present to you the incomplete status rewrite! committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 03 Sep 2004 21:35:52 +0000
parents 78da12f2982d
children ab5db2c5da79
comparison
equal deleted inserted replaced
9943:f8e395a054e2 9944:e4a27c9aec4c
28 #include "notify.h" 28 #include "notify.h"
29 #include "pounce.h" 29 #include "pounce.h"
30 #include "prefs.h" 30 #include "prefs.h"
31 #include "prpl.h" 31 #include "prpl.h"
32 #include "request.h" 32 #include "request.h"
33 #include "server.h"
33 #include "signals.h" 34 #include "signals.h"
34 #include "server.h" 35 #include "status.h"
35 #include "util.h" 36 #include "util.h"
36 37
37 typedef enum 38 typedef enum
38 { 39 {
39 TAG_NONE = 0, 40 TAG_NONE = 0,
124 GaimAccount * 125 GaimAccount *
125 gaim_account_new(const char *username, const char *protocol_id) 126 gaim_account_new(const char *username, const char *protocol_id)
126 { 127 {
127 GaimAccount *account = NULL; 128 GaimAccount *account = NULL;
128 129
129 g_return_val_if_fail(username != NULL, NULL); 130 g_return_val_if_fail(username != NULL, NULL);
130 131
131 if(protocol_id) 132 if (protocol_id != NULL)
132 account = gaim_accounts_find(username, protocol_id); 133 account = gaim_accounts_find(username, protocol_id);
133 134
134 if (account != NULL) 135 if (account != NULL)
135 return account; 136 return account;
136 137
137 account = g_new0(GaimAccount, 1); 138 account = g_new0(GaimAccount, 1);
138 139
139 gaim_account_set_username(account, username); 140 gaim_account_set_username(account, username);
140 141
141 gaim_account_set_protocol_id(account, protocol_id ? protocol_id : GAIM_PROTO_DEFAULT); 142 gaim_account_set_protocol_id(account,
143 (protocol_id ? protocol_id : GAIM_PROTO_DEFAULT));
142 144
143 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, 145 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
144 g_free, delete_setting); 146 g_free, delete_setting);
145 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, 147 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
146 g_free, (GDestroyNotify)g_hash_table_destroy); 148 g_free, (GDestroyNotify)g_hash_table_destroy);
147 account->system_log = NULL; 149 account->system_log = NULL;
148 150
151 account->presence = gaim_presence_new_for_account(account);
152
149 return account; 153 return account;
150 } 154 }
151 155
152 void 156 void
153 gaim_account_destroy(GaimAccount *account) 157 gaim_account_destroy(GaimAccount *account)
154 { 158 {
155 GList *l; 159 GList *l;
156 160
157 g_return_if_fail(account != NULL); 161 g_return_if_fail(account != NULL);
158 162
159 gaim_debug(GAIM_DEBUG_INFO, "account", 163 gaim_debug_info("account", "Destroying account %p\n", account);
160 "Destroying account %p\n", account);
161 164
162 if (account->gc != NULL) 165 if (account->gc != NULL)
163 gaim_connection_destroy(account->gc); 166 gaim_connection_destroy(account->gc);
164 167
165 gaim_debug(GAIM_DEBUG_INFO, "account", 168 gaim_debug_info("account", "Continuing to destroy account %p\n", account);
166 "Continuing to destroy account %p\n", account);
167 169
168 for (l = gaim_get_conversations(); l != NULL; l = l->next) 170 for (l = gaim_get_conversations(); l != NULL; l = l->next)
169 { 171 {
170 GaimConversation *conv = (GaimConversation *)l->data; 172 GaimConversation *conv = (GaimConversation *)l->data;
171 173
180 if (account->protocol_id != NULL) g_free(account->protocol_id); 182 if (account->protocol_id != NULL) g_free(account->protocol_id);
181 183
182 g_hash_table_destroy(account->settings); 184 g_hash_table_destroy(account->settings);
183 g_hash_table_destroy(account->ui_settings); 185 g_hash_table_destroy(account->ui_settings);
184 186
187 gaim_account_set_status_types(account, NULL);
188
189 gaim_presence_destroy(account->presence);
190
185 if(account->system_log) 191 if(account->system_log)
186 gaim_log_free(account->system_log); 192 gaim_log_free(account->system_log);
187 193
188 g_free(account); 194 g_free(account);
189 } 195 }
198 if (gaim_account_get_connection(account) != NULL) 204 if (gaim_account_get_connection(account) != NULL)
199 return NULL; 205 return NULL;
200 206
201 gc = gaim_connection_new(account); 207 gc = gaim_connection_new(account);
202 208
203 gaim_debug(GAIM_DEBUG_INFO, "account", 209 gaim_debug_info("account", "Registering account %p. gc = %p\n",
204 "Registering account %p. gc = %p\n", account, gc); 210 account, gc);
205 211
206 gaim_connection_register(gc); 212 gaim_connection_register(gc);
207 213
208 return gc; 214 return gc;
209 } 215 }
218 if (gaim_account_get_connection(account) != NULL) 224 if (gaim_account_get_connection(account) != NULL)
219 return NULL; 225 return NULL;
220 226
221 gc = gaim_connection_new(account); 227 gc = gaim_connection_new(account);
222 228
223 gaim_debug(GAIM_DEBUG_INFO, "account", 229 gaim_debug_info("account", "Connecting to account %p. gc = %p\n",
224 "Connecting to account %p. gc = %p\n", account, gc); 230 account, gc);
225 231
226 gaim_connection_connect(gc); 232 gaim_connection_connect(gc);
227 233
228 return gc; 234 return gc;
229 } 235 }
234 GaimConnection *gc; 240 GaimConnection *gc;
235 241
236 g_return_if_fail(account != NULL); 242 g_return_if_fail(account != NULL);
237 g_return_if_fail(gaim_account_is_connected(account)); 243 g_return_if_fail(gaim_account_is_connected(account));
238 244
239 gaim_debug(GAIM_DEBUG_INFO, "account", 245 gaim_debug_info("account", "Disconnecting account %p\n", account);
240 "Disconnecting account %p\n", account);
241 246
242 gc = gaim_account_get_connection(account); 247 gc = gaim_account_get_connection(account);
243 248
244 gaim_account_set_connection(account, NULL); 249 gaim_account_set_connection(account, NULL);
245 250
510 515
511 schedule_accounts_save(); 516 schedule_accounts_save();
512 } 517 }
513 518
514 void 519 void
520 gaim_account_set_status_types(GaimAccount *account, GList *status_types)
521 {
522 g_return_if_fail(account != NULL);
523
524 if (account->status_types != NULL)
525 {
526 GList *l;
527
528 for (l = account->status_types; l != NULL; l = l->next)
529 gaim_status_type_destroy((GaimStatusType *)l->data);
530
531 g_list_free(account->status_types);
532 }
533
534 account->status_types = status_types;
535 }
536
537 void
538 gaim_account_set_status(GaimAccount *account, const char *status_id,
539 gboolean active, ...)
540 {
541 GaimStatus *status;
542
543 g_return_if_fail(account != NULL);
544 g_return_if_fail(status_id != NULL);
545
546 status = gaim_account_get_status(account, status_id);
547
548 if (status == NULL)
549 {
550 gaim_debug(GAIM_DEBUG_ERROR, "accounts",
551 "Invalid status ID %s for account %s (%s)\n",
552 status_id, gaim_account_get_username(account),
553 gaim_account_get_protocol_id(account));
554 return;
555 }
556
557 if (!active && gaim_status_is_independent(status))
558 {
559 gaim_debug(GAIM_DEBUG_ERROR, "accounts",
560 "Cannot deactivate an exclusive status.\n");
561 return;
562 }
563
564 if (gaim_status_is_active(status) == active)
565 return;
566
567 gaim_status_set_active(status, active);
568 }
569
570 void
515 gaim_account_clear_settings(GaimAccount *account) 571 gaim_account_clear_settings(GaimAccount *account)
516 { 572 {
517 g_return_if_fail(account != NULL); 573 g_return_if_fail(account != NULL);
518 574
519 g_hash_table_destroy(account->settings); 575 g_hash_table_destroy(account->settings);
776 gaim_account_get_proxy_info(const GaimAccount *account) 832 gaim_account_get_proxy_info(const GaimAccount *account)
777 { 833 {
778 g_return_val_if_fail(account != NULL, NULL); 834 g_return_val_if_fail(account != NULL, NULL);
779 835
780 return account->proxy_info; 836 return account->proxy_info;
837 }
838
839 GaimStatus *
840 gaim_account_get_status(const GaimAccount *account, const char *status_id)
841 {
842 g_return_val_if_fail(account != NULL, NULL);
843 g_return_val_if_fail(status_id != NULL, NULL);
844
845 return gaim_presence_get_status(account->presence, status_id);
846 }
847
848 GaimStatusType *
849 gaim_account_get_status_type(const GaimAccount *account, const char *id)
850 {
851 const GList *l;
852
853 g_return_val_if_fail(account != NULL, NULL);
854 g_return_val_if_fail(id != NULL, NULL);
855
856 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next)
857 {
858 GaimStatusType *status_type = (GaimStatusType *)l->data;
859
860 if (!strcmp(gaim_status_type_get_id(status_type), id))
861 return status_type;
862 }
863
864 return NULL;
865 }
866
867 GaimPresence *
868 gaim_account_get_presence(const GaimAccount *account)
869 {
870 g_return_val_if_fail(account != NULL, NULL);
871
872 return account->presence;
873 }
874
875 gboolean
876 gaim_account_is_status_active(const GaimAccount *account,
877 const char *status_id)
878 {
879 g_return_val_if_fail(account != NULL, FALSE);
880 g_return_val_if_fail(status_id != NULL, FALSE);
881
882 return gaim_presence_is_status_active(account->presence, status_id);
883 }
884
885 const GList *
886 gaim_account_get_status_types(const GaimAccount *account)
887 {
888 g_return_val_if_fail(account != NULL, NULL);
889
890 return account->status_types;
781 } 891 }
782 892
783 int 893 int
784 gaim_account_get_int(const GaimAccount *account, const char *name, 894 gaim_account_get_int(const GaimAccount *account, const char *name,
785 int default_value) 895 int default_value)