changeset 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 e0146fcc4718
children 3a9b54f260e3
files src/account.c src/account.h src/away.c src/blist.c src/core.c src/gaim.h src/gaimrc.c src/gtkpounce.c src/main.c src/protocols/oscar/oscar.c src/proxy.c src/util.c
diffstat 12 files changed, 122 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/account.c	Sat May 31 02:27:03 2003 +0000
@@ -36,6 +36,7 @@
 
 typedef enum
 {
+	TAG_NONE = 0,
 	TAG_PROTOCOL,
 	TAG_NAME,
 	TAG_PASSWORD,
@@ -585,6 +586,8 @@
 		data->setting_name = NULL;
 	}
 
+	data->tag = TAG_NONE;
+
 	g_free(buffer);
 }
 
@@ -793,6 +796,37 @@
 	g_free(filename_real);
 }
 
+void
+gaim_accounts_reorder(GaimAccount *account, size_t new_index)
+{
+	size_t index;
+	GList *l;
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(new_index > 0 && new_index < g_list_length(accounts));
+
+	index = g_list_index(accounts, account);
+
+	if (index == -1) {
+		gaim_debug(GAIM_DEBUG_ERROR, "accounts",
+				   "Unregistered account (%s) discovered during reorder!\n",
+				   gaim_account_get_username(account));
+		return;
+	}
+
+	l = g_list_nth(accounts, index);
+
+	if (new_index > index)
+		new_index--;
+
+	/* Remove the old one. */
+	accounts = g_list_delete_link(accounts, l);
+
+	/* Insert it where it should go. */
+	accounts = g_list_insert(accounts, account, new_index);
+
+	schedule_accounts_save();
+}
 
 GList *
 gaim_accounts_get_all(void)
--- a/src/account.h	Sat May 31 02:20:09 2003 +0000
+++ b/src/account.h	Sat May 31 02:27:03 2003 +0000
@@ -326,6 +326,14 @@
 void gaim_accounts_sync();
 
 /**
+ * Reorders an account.
+ *
+ * @param account   The account to reorder.
+ * @param new_index The new index for the account.
+ */
+void gaim_accounts_reorder(GaimAccount *account, size_t new_index);
+
+/**
  * Returns a list of all accounts.
  *
  * @return A list of all accounts.
--- a/src/away.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/away.c	Sat May 31 02:27:03 2003 +0000
@@ -77,7 +77,7 @@
 			if (!gaim_utf8_strcasecmp(qm->name, name)) {
 				GaimAccount *account = NULL;
 
-				if (g_slist_index(gaim_accounts, qm->account) >= 0)
+				if (g_list_index(gaim_accounts_get_all(), qm->account) >= 0)
 					account = qm->account;
 
 				cnv = gaim_find_conversation(name);
@@ -117,7 +117,7 @@
 
 		account = NULL;
 
-		if (g_slist_index(gaim_accounts, qm->account) >= 0)
+		if (g_list_index(gaim_accounts_get_all(), qm->account) >= 0)
 			account = qm->account;
 
 		cnv = gaim_find_conversation(qm->name);
--- a/src/blist.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/blist.c	Sat May 31 02:27:03 2003 +0000
@@ -1562,7 +1562,7 @@
 }
 
 void gaim_blist_load() {
-	GSList *accts;
+	GList *accts;
 	char *user_dir = gaim_user_dir();
 	char *filename;
 	char *msg;
@@ -1581,7 +1581,7 @@
 			gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg);
 			g_free(msg);
 		}
-	} else if(g_slist_length(gaim_accounts)) {
+	} else if(g_list_length(gaim_accounts_get_all())) {
 		/* rob wants to inform the user that their buddy lists are
 		 * being converted */
 		msg = g_strdup_printf(_("Gaim is converting your old buddy lists "
@@ -1595,7 +1595,7 @@
 			gtk_main_iteration();
 
 		/* read in the old lists, then save to the new format */
-		for(accts = gaim_accounts; accts; accts = accts->next) {
+		for(accts = gaim_accounts_get_all(); accts; accts = accts->next) {
 			do_import(accts->data, NULL);
 		}
 		gaim_blist_save();
@@ -1659,7 +1659,8 @@
 }
 
 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) {
-	GSList *accounts, *buds;
+	GList *accounts;
+	GSList *buds;
 	GaimBlistNode *gnode,*bnode;
 	struct group *group;
 	struct buddy *bud;
@@ -1727,7 +1728,10 @@
 	fprintf(file, "\t</blist>\n");
 	fprintf(file, "\t<privacy>\n");
 
-	for(accounts = gaim_accounts; accounts; accounts = accounts->next) {
+	for(accounts = gaim_accounts_get_all();
+		accounts != NULL;
+		accounts = accounts->next) {
+
 		GaimAccount *account = accounts->data;
 		char *acct_name = g_markup_escape_text(account->username, -1);
 		if(!exp_acct || account == exp_acct) {
--- a/src/core.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/core.c	Sat May 31 02:27:03 2003 +0000
@@ -236,7 +236,7 @@
 		if (!data)
 			return;
 		memcpy(&id, data, sizeof(id));
-		account = g_slist_nth_data(gaim_accounts, id);
+		account = g_list_nth_data(gaim_accounts_get_all(), id);
 		if (account)
 			serv_login(account);
 		/* don't need to do anything here because the UI will get updates from other handlers */
--- a/src/gaim.h	Sat May 31 02:20:09 2003 +0000
+++ b/src/gaim.h	Sat May 31 02:27:03 2003 +0000
@@ -193,7 +193,6 @@
 extern char *opt_rcfile_arg;
 extern int opt_debug;
 
-extern GSList *gaim_accounts;
 extern GSList *message_queue;
 extern GSList *unread_message_queue;
 extern GSList *away_time_queue;
@@ -201,19 +200,6 @@
 /* Functions in main.c */
 extern void do_quit();
 
-/* Functions in gtkblist.c */
-extern void signoff(GaimConnection *);
-
-/* Functions in buddy_chat.c */
-#if 0
-extern void show_new_buddy_chat(struct gaim_conversation *);
-extern void chat_set_topic(struct gaim_conversation*, char*, char*);
-/*extern void add_chat_buddy(struct gaim_conversation *, char *);*/
-extern void add_chat_buddy(struct gaim_conversation *, char *, char *);
-extern void rename_chat_buddy(struct gaim_conversation *, char *, char *);
-extern void remove_chat_buddy(struct gaim_conversation *, char *, char *);
-#endif
-
 /* Functions in dialogs.c */
 extern void g_show_info_text(GaimConnection *, const char *, int, const char *, ...);
 extern void show_change_passwd(GaimConnection *);
--- a/src/gaimrc.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/gaimrc.c	Sat May 31 02:27:03 2003 +0000
@@ -157,7 +157,6 @@
 #define OPT_ACCT_REM_PASS	0x00000004
 #define OPT_ACCT_MAIL_CHECK      0x00000008
 
-GSList *gaim_accounts = NULL;
 static guint misc_options;
 static guint logging_options;
 static guint blist_options;
@@ -589,6 +588,36 @@
 	}
 #endif
 
+	/* I hate this part. We must convert the protocol options. */
+	switch (gaim_account_get_protocol(account)) {
+		case GAIM_PROTO_TOC:
+		case GAIM_PROTO_OSCAR:
+		case GAIM_PROTO_JABBER:
+			gaim_account_set_string(account, "server", p->value[0]);
+			gaim_account_set_int(account, "port", atoi(p->value[1]));
+			break;
+
+		case GAIM_PROTO_MSN:
+		case GAIM_PROTO_NAPSTER:
+		case GAIM_PROTO_YAHOO:
+			gaim_account_set_string(account, "server", p->value[3]);
+			gaim_account_set_int(account, "port", atoi(p->value[4]));
+			break;
+
+		case GAIM_PROTO_IRC:
+			gaim_account_set_string(account, "server", p->value[0]);
+			gaim_account_set_int(account, "port", atoi(p->value[1]));
+			gaim_account_set_string(account, "charset", p->value[2]);
+			break;
+
+		case GAIM_PROTO_GADUGADU:
+			gaim_account_set_string(account, "nick", p->value[0]);
+			break;
+
+		default:
+			break;
+	}
+
 	if (!fgets(buf, sizeof(buf), f))
 		return account;
 
@@ -663,9 +692,7 @@
 
 		if (strcmp(p->option, "user")==0 ||
 		    strcmp(p->option, "current_user")==0) {
-			if((account=gaimrc_read_user(f))!=NULL)
-				gaim_accounts = g_slist_append(gaim_accounts, account);
-			else {
+			if((account=gaimrc_read_user(f))==NULL) {
 				gaim_debug(GAIM_DEBUG_ERROR, "gaimrc",
 						   "Error reading in users from .gaimrc\n");
 				return;
--- a/src/gtkpounce.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/gtkpounce.c	Sat May 31 02:27:03 2003 +0000
@@ -281,14 +281,17 @@
 	GtkWidget *opt_menu;
 	GtkWidget *menu;
 	GtkWidget *item;
-	GSList *l;
+	GList *l;
 	char buf[2048];
 	int count, place = 0;
 
 	opt_menu = gtk_option_menu_new();
 	menu = gtk_menu_new();
 
-	for (l = gaim_accounts, count = 0; l != NULL; l = l->next, count++) {
+	for (l = gaim_accounts_get_all(), count = 0;
+		 l != NULL;
+		 l = l->next, count++) {
+
 		account = (GaimAccount *)l->data;
 
 		prpl = gaim_find_prpl(account->protocol);
@@ -480,7 +483,7 @@
 	}
 	else {
 		dialog->pounce  = NULL;
-		dialog->account = gaim_accounts->data;
+		dialog->account = gaim_accounts_get_all()->data;
 	}
 
 	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
--- a/src/main.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/main.c	Sat May 31 02:27:03 2003 +0000
@@ -232,7 +232,7 @@
 		}
 		g_strfreev(names);
 	} else {		/* no name given, use default */
-		account = (GaimAccount *)gaim_accounts->data;
+		account = (GaimAccount *)gaim_accounts_get_all()->data;
 
 		if (gaim_account_get_remember_password(account)) {
 			retval = 0;
@@ -273,7 +273,7 @@
 
 static GList *combo_user_names()
 {
-	GSList *accts = gaim_accounts;
+	GList *accts = gaim_accounts_get_all();
 	GList *tmp = NULL;
 	GaimAccount *account;
 
@@ -394,8 +394,8 @@
 	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
 
 	/* Now grab the focus that we need */
-	if (gaim_accounts) {
-		GaimAccount *account = gaim_accounts->data;
+	if (gaim_accounts_get_all()) {
+		GaimAccount *account = gaim_accounts_get_all()->data;
 
 		if (gaim_account_get_remember_password(account)) {
 			combo_changed(NULL, name);
@@ -589,16 +589,11 @@
 
 	account = gaim_account_find(name, -1);
 
-	if (!account) {		/* new user */
-		account = g_new0(GaimAccount, 1);
-		g_snprintf(account->username, sizeof(account->username), "%s", name);
-		account->protocol = GAIM_PROTO_DEFAULT;
-		gaim_accounts = g_slist_prepend(gaim_accounts, account);
-	} else {		/* user already exists */
-		gaim_accounts = g_slist_remove(gaim_accounts, account);
-		gaim_accounts = g_slist_prepend(gaim_accounts, account);
-	}
-	save_prefs();
+	if (account == NULL)   /* new user */
+		account = gaim_account_new(name, GAIM_PROTO_DEFAULT);
+
+	/* Place it as the first user. */
+	gaim_accounts_reorder(account, 0);
 }
 
 #ifdef _WIN32
@@ -893,8 +888,11 @@
 	gaim_gtk_prefs_init();
 	gaim_accounts_load();
 
-	if (!gaim_prefs_load())
+	if (!gaim_prefs_load()) {
 		load_prefs();
+		gaim_prefs_sync();
+		gaim_accounts_sync();
+	}
 
 	plugin_search_paths[0] = LIBDIR;
 	plugin_search_paths[1] = gaim_user_dir();
--- a/src/protocols/oscar/oscar.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/protocols/oscar/oscar.c	Sat May 31 02:27:03 2003 +0000
@@ -71,7 +71,6 @@
 static GaimPlugin *my_protocol = NULL;
 
 /* For win32 compatability */
-G_MODULE_IMPORT GSList *connections;
 G_MODULE_IMPORT int report_idle;
 
 static int caps_aim = AIM_CAPS_CHAT | AIM_CAPS_BUDDYICON | AIM_CAPS_IMIMAGE | AIM_CAPS_SENDFILE | AIM_CAPS_INTEROPERATE;
@@ -512,7 +511,7 @@
       
 	od = (struct oscar_data *)gc->proto_data;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		/* oh boy. this is probably bad. i guess the only thing we 
 		 * can really do is return? */
 		gaim_debug(GAIM_DEBUG_INFO, "oscar",
@@ -630,7 +629,7 @@
 	aim_session_t *sess;
 	aim_conn_t *conn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -780,7 +779,7 @@
 	aim_session_t *sess;
 	aim_conn_t *bosconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -1442,7 +1441,7 @@
 	aim_session_t *sess;
 	aim_conn_t *tstconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -1471,7 +1470,7 @@
 	aim_session_t *sess;
 	aim_conn_t *tstconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -1501,7 +1500,7 @@
 	aim_session_t *sess;
 	aim_conn_t *tstconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		g_free(ccon->show);
 		g_free(ccon->name);
@@ -1533,7 +1532,7 @@
 	aim_session_t *sess;
 	aim_conn_t *tstconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -1562,7 +1561,7 @@
 	aim_session_t *sess;
 	aim_conn_t *tstconn;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		close(source);
 		return;
 	}
@@ -1878,7 +1877,7 @@
 	struct sockaddr name;
 	socklen_t name_len = 1;
 	
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		g_free(dim);
 		return;
 	}
@@ -2092,7 +2091,7 @@
 	char *host; int port = 4443;
 	int i, rc;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		cancel_direct_im(d);
 		return;
 	}
@@ -2419,7 +2418,7 @@
 static void gaim_auth_request(struct name_data *data, char *msg) {
 	GaimConnection *gc = data->gc;
 
-	if (g_slist_find(connections, gc)) {
+	if (g_list_find(gaim_connections_get_all(), gc)) {
 		struct oscar_data *od = gc->proto_data;
 		struct buddy *buddy = gaim_find_buddy(gc->account, data->name);
 		struct group *group = gaim_find_buddys_group(buddy);
@@ -2445,7 +2444,7 @@
 static void gaim_auth_dontrequest(struct name_data *data) {
 	GaimConnection *gc = data->gc;
 
-	if (g_slist_find(connections, gc)) {
+	if (g_list_find(gaim_connections_get_all(), gc)) {
 		/* struct oscar_data *od = gc->proto_data; */
 		/* XXX - Take the buddy out of our buddy list */
 	}
@@ -2483,7 +2482,7 @@
 static void gaim_auth_grant(struct name_data *data) {
 	GaimConnection *gc = data->gc;
 
-	if (g_slist_find(connections, gc)) {
+	if (g_list_find(gaim_connections_get_all(), gc)) {
 		struct oscar_data *od = gc->proto_data;
 #ifdef NOSSI
 		struct buddy *buddy;
@@ -2504,7 +2503,7 @@
 static void gaim_auth_dontgrant(struct name_data *data, char *msg) {
 	GaimConnection *gc = data->gc;
 
-	if (g_slist_find(connections, gc)) {
+	if (g_list_find(gaim_connections_get_all(), gc)) {
 		struct oscar_data *od = gc->proto_data;
 #ifdef NOSSI
 		aim_im_sendch4(od->sess, data->name, AIM_ICQMSG_AUTHDENIED, msg ? msg : _("No reason given."));
@@ -2526,7 +2525,7 @@
 static void gaim_icq_contactadd(struct name_data *data) {
 	GaimConnection *gc = data->gc;
 
-	if (g_slist_find(connections, gc)) {
+	if (g_list_find(gaim_connections_get_all(), gc)) {
 		show_add_buddy(gc, data->name, NULL, data->nick);
 	}
 
@@ -5548,7 +5547,7 @@
 	struct oscar_data *od;
 	struct direct_im *dim;
 
-	if (!g_slist_find(connections, gc)) {
+	if (!g_list_find(gaim_connections_get_all(), gc)) {
 		g_free(data->who);
 		g_free(data);
 		return;
--- a/src/proxy.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/proxy.c	Sat May 31 02:27:03 2003 +0000
@@ -1243,7 +1243,7 @@
 int
 proxy_connect(GaimAccount *account, const char *host, int port, GaimInputFunction func, gpointer data)
 {
-	char *connecthost = host;
+	const char *connecthost = host;
 	int connectport = port;
 	struct PHB *phb = g_new0(struct PHB, 1);
 	if(!account || !account->gpi)
--- a/src/util.c	Sat May 31 02:20:09 2003 +0000
+++ b/src/util.c	Sat May 31 02:27:03 2003 +0000
@@ -571,7 +571,7 @@
 GaimAccount *gaim_account_find(const char *name, int protocol)
 {
 	char *who = g_strdup(normalize(name));
-	GSList *accts = gaim_accounts;
+	GList *accts = gaim_accounts_get_all();
 	GaimAccount *account;
 
 	while (accts) {