changeset 4966:54cd43869333

[gaim-migrate @ 5300] fun stuff this makes the modify account dialog make a little more sense for jabber, and makes irc accounts distinguishable in the assorted dropdowns. however, there is a slight catch. IRC accounts now take the form of nick@server. The first time you log on with an IRC account, it will change it for you. However, if you try to edit the account before it gets signed on, the server will revert to the default (irc.freenode.net). So go log in with all of your IRC accounts before you go editing them ;-) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Thu, 03 Apr 2003 02:34:48 +0000
parents 6e7082cf0892
children a65297090ce8
files src/multi.c src/multi.h src/protocols/irc/irc.c src/protocols/jabber/jabber.c src/protocols/msn/msn.c src/prpl.c src/prpl.h
diffstat 7 files changed, 222 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/src/multi.c	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/multi.c	Thu Apr 03 02:34:48 2003 +0000
@@ -59,6 +59,9 @@
 	struct gaim_account *account;
 
 	/* these are temporary */
+	char username[64];
+	char show[400];
+	char password[32];
 	int options;
 	int protocol;
 	char proto_opt[7][256];
@@ -71,9 +74,11 @@
 	GtkWidget *pwdbox;
 	GtkWidget *pass;
 	GtkWidget *rempass;
+	GtkWidget *login_frame;
 	GtkWidget *user_frame;
 	GtkWidget *proto_frame;
 	GtkSizeGroup *sg;
+	GList *user_split_entries;
 	GList *opt_entries;
 
 	/* stuff for icon selection */
@@ -121,8 +126,6 @@
 	return NULL;
 }
 
-static void generate_protocol_options(struct mod_account *, GtkWidget *);
-
 
 struct gaim_connection *new_gaim_conn(struct gaim_account *account)
 {
@@ -361,12 +364,46 @@
 	return button;
 }
 
+static void process_login_opts(struct mod_account *ma) {
+	struct prpl *p = find_prpl(ma->protocol);
+	const char *entry_text;
+	char *username = g_strdup(gtk_entry_get_text(GTK_ENTRY(ma->name)));
+	char *tmp;
+	GList *entries = ma->user_split_entries;
+	GList *user_splits = NULL;
+	if(p)
+		user_splits = p->user_splits;
+	while(user_splits) {
+		GtkWidget *entry = entries->data;
+		struct proto_user_split *pus = user_splits->data;
+		char tmp_sep[2] = " ";
+		entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
+
+		tmp_sep[0] = pus->sep;
+		tmp = g_strconcat(username, tmp_sep, *entry_text ? entry_text : pus->def, NULL);
+		g_free(username);
+		username = tmp;
+
+		entries = entries->next;
+		user_splits = user_splits->next;
+	}
+
+	g_snprintf(ma->username, sizeof(ma->username), "%s", username);
+	g_free(username);
+
+	entry_text = gtk_entry_get_text(GTK_ENTRY(ma->pass));
+	g_snprintf(ma->password, sizeof(ma->password), "%s", entry_text);
+
+	entry_text = gtk_entry_get_text(GTK_ENTRY(ma->alias));
+	g_snprintf(ma->show, sizeof(ma->show), "%s", entry_text);
+}
+
 static void ok_mod(GtkWidget *w, struct mod_account *ma)
 {
 	GList *tmp;
 	const char *txt;
 	struct gaim_account *a;
-	struct prpl *p;
+	struct prpl *p = find_prpl(ma->protocol);
 	GtkTreeIter iter;
 	int proxytype;
 
@@ -378,13 +415,13 @@
 
 	a->options = ma->options;
 	a->protocol = ma->protocol;
-	txt = gtk_entry_get_text(GTK_ENTRY(ma->name));
-	g_snprintf(a->username, sizeof(a->username), "%s", txt);
-	txt = gtk_entry_get_text(GTK_ENTRY(ma->alias));
-	g_snprintf(a->alias, sizeof(a->alias), "%s", txt);
-	txt = gtk_entry_get_text(GTK_ENTRY(ma->pass));
+
+	process_login_opts(ma);
+	g_snprintf(a->username, sizeof(a->username), "%s", ma->username);
+	g_snprintf(a->alias, sizeof(a->alias), "%s", ma->show);
+
 	if (a->options & OPT_ACCT_REM_PASS)
-		g_snprintf(a->password, sizeof(a->password), "%s", txt);
+		g_snprintf(a->password, sizeof(a->password), "%s", ma->password);
 	else
 		a->password[0] = '\0';
 
@@ -443,7 +480,7 @@
 	/*
 	 * See if user registration is supported/required
 	 */
-	if((p = find_prpl(ma->protocol)) == NULL) {
+	if(!p) {
 		/* TBD: error dialog here! (This should never happen, you know...) */
 		fprintf(stderr, "dbg: couldn't find protocol for protocol number %d!\n", ma->protocol);
 		fflush(stderr);
@@ -474,42 +511,31 @@
 	gtk_widget_destroy(ma->mod);
 }
 
+static void generate_login_options(struct mod_account *ma, GtkWidget *box);
+static void generate_user_options(struct mod_account *ma, GtkWidget *box);
+static void generate_protocol_options(struct mod_account *ma, GtkWidget *box);
+
 static void set_prot(GtkWidget *opt, int proto)
 {
 	struct mod_account *ma = g_object_get_data(G_OBJECT(opt), "mod_account");
-	struct prpl *p, *q;
-	q = find_prpl(proto);
+	struct prpl *p;
 	if (ma->protocol != proto) {
 		int i;
+
 		for (i = 0; i < 7; i++)
 			ma->proto_opt[i][0] = '\0';
 		p = find_prpl(ma->protocol);
 
-		if (!(p->options & OPT_PROTO_NO_PASSWORD) && (q->options & OPT_PROTO_NO_PASSWORD)) {
-			gtk_widget_hide(ma->pwdbox);
-			gtk_widget_hide(ma->rempass);
-		} else if ((p->options & OPT_PROTO_NO_PASSWORD) && !(q->options & OPT_PROTO_NO_PASSWORD)) {
-			gtk_widget_show(ma->pwdbox);
-			gtk_widget_show(ma->rempass);
-		}
-		if (!(p->options & OPT_PROTO_MAIL_CHECK) && (q->options & OPT_PROTO_MAIL_CHECK)) {
-			gtk_widget_show(ma->checkmail);
-		} else if ((p->options & OPT_PROTO_MAIL_CHECK) && !(q->options & OPT_PROTO_MAIL_CHECK)) {
-			gtk_widget_hide(ma->checkmail);
-		}
-
-		if (!(p->options & OPT_PROTO_BUDDY_ICON) && (q->options & OPT_PROTO_BUDDY_ICON)) {
-			gtk_widget_show(ma->iconsel);
-		} else if ((p->options & OPT_PROTO_BUDDY_ICON) && !(q->options & OPT_PROTO_BUDDY_ICON)) {
-			gtk_widget_hide(ma->iconsel);
-		}
-
-		if ((q->options & OPT_PROTO_BUDDY_ICON) || (q->options & OPT_PROTO_MAIL_CHECK))
-			gtk_widget_show(ma->user_frame);
-		else
-			gtk_widget_hide(ma->user_frame);
+		process_login_opts(ma);
 
 		ma->protocol = proto;
+
+		if(!ma->account)
+			g_snprintf(ma->username, sizeof(ma->username), "%s",
+					gtk_entry_get_text(GTK_ENTRY(ma->name)));
+
+		generate_login_options(ma, ma->main);
+		generate_user_options(ma, ma->main);
 		generate_protocol_options(ma, ma->main);
 	}
 }
@@ -659,15 +685,24 @@
 
 static void generate_login_options(struct mod_account *ma, GtkWidget *box)
 {
-	GtkWidget *frame, *frame_parent;
+	GtkWidget *frame;
 	GtkWidget *vbox;
 	GtkWidget *hbox;
 	GtkWidget *label;
+	GList *user_splits = NULL;
+	GList *split_entries;
 
 	struct prpl *p;
 
+	char *username = NULL;
+	char *start;
+
+	if(ma->login_frame)
+		gtk_widget_destroy(ma->login_frame);
+	ma->login_frame = NULL;
+
 	frame = make_frame(box, _("Login Options"));
-	frame_parent = gtk_widget_get_parent(gtk_widget_get_parent(frame));
+	ma->login_frame = gtk_widget_get_parent(gtk_widget_get_parent(frame));
 
 	vbox = gtk_vbox_new(FALSE, 5);
 	gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
@@ -675,6 +710,21 @@
 
 	hbox = gtk_hbox_new(FALSE, 5);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	label = gtk_label_new(_("Protocol:"));
+	gtk_size_group_add_widget(ma->sg, label);
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+	make_protocol_menu(hbox, ma);
+
+	hbox = gtk_hbox_new(FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+	p = find_prpl(ma->protocol);
+	if(p)
+		user_splits = p->user_splits;
 
 	label = gtk_label_new(_("Screenname:"));
 	gtk_size_group_add_widget(ma->sg, label);
@@ -684,6 +734,30 @@
 	ma->name = gtk_entry_new();
 	gtk_box_pack_start(GTK_BOX(hbox), ma->name, TRUE, TRUE, 0);
 
+	if(ma->user_split_entries) {
+		g_list_free(ma->user_split_entries);
+		ma->user_split_entries = NULL;
+	}
+
+	while(user_splits) {
+		struct proto_user_split *pus = user_splits->data;
+		GtkWidget *entry;
+
+		hbox = gtk_hbox_new(FALSE, 5);
+		gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+		label = gtk_label_new(pus->label);
+		gtk_size_group_add_widget(ma->sg, label);
+		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+		gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+		user_splits = user_splits->next;
+
+		entry = gtk_entry_new();
+		gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
+
+		ma->user_split_entries = g_list_append(ma->user_split_entries, entry);
+	}
+
 	ma->pwdbox = gtk_hbox_new(FALSE, 5);
 	gtk_box_pack_start(GTK_BOX(vbox), ma->pwdbox, FALSE, FALSE, 0);
 
@@ -707,29 +781,37 @@
 	ma->alias = gtk_entry_new();
 	gtk_box_pack_start(GTK_BOX(hbox), ma->alias, TRUE, TRUE, 0);
 
-	hbox = gtk_hbox_new(FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-	gtk_widget_show(hbox);
-
-	label = gtk_label_new(_("Protocol:"));
-	gtk_size_group_add_widget(ma->sg, label);
-	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
-	make_protocol_menu(hbox, ma);
-
 	ma->rempass = acct_button(_("Remember Password"), ma, OPT_ACCT_REM_PASS, vbox);
 	acct_button(_("Auto-Login"), ma, OPT_ACCT_AUTO, vbox);
 
-	gtk_widget_show_all(frame_parent);
+	gtk_widget_show_all(ma->login_frame);
+
+	if(p)
+		user_splits = g_list_last(p->user_splits);
+
+	username = g_strdup(ma->username);
+	split_entries = g_list_last(ma->user_split_entries);
 
-	if (ma->account) {
-		gtk_entry_set_text(GTK_ENTRY(ma->name), ma->account->username);
-		gtk_entry_set_text(GTK_ENTRY(ma->alias), ma->account->alias);
-		gtk_entry_set_text(GTK_ENTRY(ma->pass), ma->account->password);
+	while(user_splits) {
+		struct proto_user_split *pus = user_splits->data;
+		GtkWidget *entry = split_entries->data;
+		start = strrchr(username, pus->sep);
+		if(start) {
+			*start = '\0';
+			start++;
+			gtk_entry_set_text(GTK_ENTRY(entry), start);
+		} else {
+			gtk_entry_set_text(GTK_ENTRY(entry), pus->def);
+		}
+		user_splits = user_splits->prev;
+		split_entries = split_entries->prev;
 	}
 
-	p = find_prpl(ma->protocol);
+	gtk_entry_set_text(GTK_ENTRY(ma->name), username);
+	gtk_entry_set_text(GTK_ENTRY(ma->alias), ma->show);
+	gtk_entry_set_text(GTK_ENTRY(ma->pass), ma->password);
+	g_free(username);
+
 	if (p && (p->options & OPT_PROTO_NO_PASSWORD)) {
 		gtk_widget_hide(ma->pwdbox);
 		gtk_widget_hide(ma->rempass);
@@ -752,6 +834,10 @@
 
 	struct prpl *p = find_prpl(ma->protocol);
 
+	if(ma->user_frame)
+		gtk_widget_destroy(ma->user_frame);
+	ma->user_frame = NULL;
+
 	frame = make_frame(box, _("User Options"));
 	ma->user_frame = gtk_widget_get_parent(gtk_widget_get_parent(frame));
 	gtk_widget_show_all(ma->user_frame);
@@ -1071,6 +1157,10 @@
 			else
 				ma->protocol = -1;
 			g_snprintf(ma->iconfile, sizeof(ma->iconfile), "%s", a->iconfile);
+			g_snprintf(ma->username, sizeof(ma->username), "%s", a->username);
+			g_snprintf(ma->show, sizeof(ma->show), "%s", a->alias);
+			g_snprintf(ma->password, sizeof(ma->password), "%s", a->password);
+
 			for (i = 0; i < 7; i++)
 				g_snprintf(ma->proto_opt[i], sizeof(ma->proto_opt[i]), "%s",
 						a->proto_opt[i]);
--- a/src/multi.h	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/multi.h	Thu Apr 03 02:34:48 2003 +0000
@@ -74,6 +74,12 @@
 /* set this flag on a gc if you want serv_got_im to autoreply when away */
 #define OPT_CONN_AUTO_RESP	0x00000002
 
+struct proto_user_split {
+	char sep;
+	char *label;
+	char *def;
+};
+
 struct proto_user_opt {
 	char *label;
 	char *def;
--- a/src/protocols/irc/irc.c	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/protocols/irc/irc.c	Thu Apr 03 02:34:48 2003 +0000
@@ -57,6 +57,8 @@
 #define USEROPT_PORT      1
 #define USEROPT_CHARSET   2
 
+#define DEFAULT_SERVER "irc.freenode.net"
+
 static struct prpl *my_protocol = NULL;
 
 /* for win32 compatability */
@@ -90,6 +92,8 @@
 	gboolean online;
 	guint32 timer;
 
+	char *server;
+
 	char *rxqueue;
 	int rxlen;
 
@@ -1791,16 +1795,16 @@
 	}
 
 	g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n",
-		   g_get_user_name(), hostname, 
-		   gc->account->proto_opt[USEROPT_SERV], 
-		   gc->account->alias && strlen(gc->account->alias) ? gc->account->alias : "gaim");
+		   g_get_user_name(), hostname,
+		   idata->server,
+		   *gc->account->alias ? gc->account->alias : "gaim");
 	if (irc_write(idata->fd, buf, strlen(buf)) < 0) {
 		hide_login_progress(gc, "Write error");
 		signoff(gc);
 		return;
 	}
 
-	g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->username);
+	g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->displayname);
 	if (irc_write(idata->fd, buf, strlen(buf)) < 0) {
 		hide_login_progress(gc, "Write error");
 		signoff(gc);
@@ -1816,10 +1820,26 @@
 	char buf[IRC_BUF_LEN];
 	int rc;
 
-	struct gaim_connection *gc = new_gaim_conn(account);
-	struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1);
+	struct gaim_connection *gc;
+	struct irc_data *idata;
+	char **parts;
+	if(!strrchr(account->username, '@')) {
+		char *username = g_strdup(account->username);
+		g_snprintf(account->username, sizeof(account->username), "%s@%s",
+				username, *account->proto_opt[USEROPT_SERV] ?
+				account->proto_opt[USEROPT_SERV] : DEFAULT_SERVER);
+		g_free(username);
+		strcpy(account->proto_opt[USEROPT_SERV], "");
+		save_prefs();
+	}
 
-	g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", gc->username);
+	gc = new_gaim_conn(account);
+	idata = gc->proto_data = g_new0(struct irc_data, 1);
+
+	parts = g_strsplit(gc->username, "@", 2);
+	g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", parts[0]);
+	idata->server = g_strdup(parts[1]);
+	g_strfreev(parts);
 
 	g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username);
 	set_login_progress(gc, 2, buf);
@@ -1830,7 +1850,7 @@
 	idata->str = g_string_new("");
 	idata->fd = -1;
 
-	rc = proxy_connect(account, account->proto_opt[USEROPT_SERV],
+	rc = proxy_connect(account, idata->server,
 				  account->proto_opt[USEROPT_PORT][0] ?
 				  atoi(account->proto_opt[USEROPT_PORT]) : 6667,
 				  irc_login_callback, gc);
@@ -2813,6 +2833,7 @@
 G_MODULE_EXPORT void 
 irc_init(struct prpl *ret)
 {
+	struct proto_user_split *pus;
 	struct proto_user_opt *puo;
 	ret->protocol = PROTO_IRC;
 	ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL;
@@ -2842,11 +2863,11 @@
 	ret->file_transfer_cancel =irc_file_transfer_cancel;
 #endif
 
-	puo = g_new0(struct proto_user_opt, 1);
-	puo->label = g_strdup(_("Server:"));
-	puo->def = g_strdup("irc.freenode.net");
-	puo->pos = USEROPT_SERV;
-	ret->user_opts = g_list_append(ret->user_opts, puo);
+	pus = g_new0(struct proto_user_split, 1);
+	pus->sep = '@';
+	pus->label = g_strdup(_("Server:"));
+	pus->def = g_strdup(DEFAULT_SERVER);
+	ret->user_splits = g_list_append(ret->user_splits, pus);
 
 	puo = g_new0(struct proto_user_opt, 1);
 	puo->label = g_strdup(_("Port:"));
@@ -2859,7 +2880,7 @@
 	puo->def = g_strdup("ISO-8859-1");
 	puo->pos = USEROPT_CHARSET;
 	ret->user_opts = g_list_append(ret->user_opts, puo);
-	
+
 	my_protocol = ret;
 }
 
--- a/src/protocols/jabber/jabber.c	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Thu Apr 03 02:34:48 2003 +0000
@@ -4207,6 +4207,7 @@
 G_MODULE_EXPORT void jabber_init(struct prpl *ret)
 {
 	/* the NULL's aren't required but they're nice to have */
+	struct proto_user_split *pus;
 	struct proto_user_opt *puo;
 	ret->protocol = PROTO_JABBER;
 	ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC;
@@ -4255,6 +4256,18 @@
 	ret->convo_closed = jabber_convo_closed;
 	ret->rename_group = jabber_rename_group;
 
+	pus = g_new0(struct proto_user_split, 1);
+	pus->sep = '@';
+	pus->label = g_strdup(_("Server:"));
+	pus->def = g_strdup("jabber.org");
+	ret->user_splits = g_list_append(ret->user_splits, pus);
+
+	pus = g_new0(struct proto_user_split, 1);
+	pus->sep = '/';
+	pus->label = g_strdup(_("Resource:"));
+	pus->def = g_strdup("Gaim");
+	ret->user_splits = g_list_append(ret->user_splits, pus);
+
 	puo = g_new0(struct proto_user_opt, 1);
 	puo->label = g_strdup(_("Port:"));
 	puo->def = g_strdup_printf("%d", DEFAULT_PORT);
--- a/src/protocols/msn/msn.c	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/protocols/msn/msn.c	Thu Apr 03 02:34:48 2003 +0000
@@ -1999,6 +1999,7 @@
 
 G_MODULE_EXPORT void msn_init(struct prpl *ret)
 {
+	struct proto_user_split *pus;
 	struct proto_user_opt *puo;
 	ret->protocol = PROTO_MSN;
 	ret->options = OPT_PROTO_MAIL_CHECK;
@@ -2039,8 +2040,15 @@
 	ret->file_transfer_read = msn_file_transfer_read;
 #endif
 
+	pus = g_new0(struct proto_user_split, 1);
+	pus->sep = '@';
+	pus->label = g_strdup(_("Server:"));
+	pus->def = g_strdup("hotmail.com");
+	ret->user_splits = g_list_append(ret->user_splits, pus);
+
+
 	puo = g_new0(struct proto_user_opt, 1);
-	puo->label = g_strdup(_("Server:"));
+	puo->label = g_strdup(_("Login Server:"));
 	puo->def = g_strdup(MSN_SERVER);
 	puo->pos = USEROPT_MSNSERVER;
 	ret->user_opts = g_list_append(ret->user_opts, puo);
--- a/src/prpl.c	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/prpl.c	Thu Apr 03 02:34:48 2003 +0000
@@ -114,9 +114,22 @@
 void unload_protocol(struct prpl *p)
 {
 	GList *c;
+	struct proto_user_split *pus;
 	struct proto_user_opt *puo;
 	if (p->name)
 		g_free(p->name);
+
+	c = p->user_splits;
+	while (c) {
+		pus = c->data;
+		g_free(pus->label);
+		g_free(pus->def);
+		g_free(pus);
+		c = c->next;
+	}
+	g_list_free(p->user_splits);
+	p->user_splits = NULL;
+
 	c = p->user_opts;
 	while (c) {
 		puo = c->data;
--- a/src/prpl.h	Thu Apr 03 02:32:17 2003 +0000
+++ b/src/prpl.h	Thu Apr 03 02:34:48 2003 +0000
@@ -204,6 +204,8 @@
 	
 	GList *(* away_states)(struct gaim_connection *gc);
 	GList *(* actions)(struct gaim_connection *gc);
+	/* user_splits is a GList of g_malloc'd struct proto_user_split */
+	GList *user_splits;
 	/* user_opts is a GList* of g_malloc'd struct proto_user_opts */
 	GList *user_opts;
 	GList *(* buddy_menu)(struct gaim_connection *, char *);