changeset 1254:9da444224f0e

[gaim-migrate @ 1264] bmiller's away-on-signon patch. does --away=mesg use "mesg" or the away message titled "mesg"? i didn't look hehe. but if it uses "mesg" instead of the away message titled "mesg" then i'm not sure it works.... i figured someone would report a bug if it didn't work committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 14 Dec 2000 00:11:59 +0000
parents 8342d3aab1f1
children 992a246595d2
files src/aim.c src/away.c src/gaim.h src/gaimrc.c src/idle.c src/multi.c src/prefs.c src/util.c
diffstat 8 files changed, 112 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/aim.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/aim.c	Thu Dec 14 00:11:59 2000 +0000
@@ -71,6 +71,9 @@
 
 GtkWidget *mainwindow = NULL;
 
+int opt_away = 0;
+char *opt_away_arg = NULL;
+
 void BuddyTickerCreateWindow(void);
 
 void cancel_logon(void)
@@ -429,6 +432,8 @@
 	struct poptOption popt_options[] = {
 		{"acct", 'a', POPT_ARG_NONE, &opt_acct, 'a',
 		 "Display account editor window", NULL},
+		{"away", 'w', POPT_ARG_STRING, NULL, 'w',
+		 "Make away on signon (optional argument MESG specifies name of away message to use)", "[MESG]"},
 		{"login", 'l', POPT_ARG_STRING, NULL, 'l',
 		 "Automatically login (optional argument NAME specifies account(s) to use)", "[NAME]"},
 		{"user", 'u', POPT_ARG_STRING, &opt_user_arg, 'u',
@@ -438,6 +443,7 @@
 #else
 	struct option long_options[] = {
 		{"acct", no_argument, NULL, 'a'},
+		{"away", optional_argument, NULL, 'w'},
 		{"help", no_argument, NULL, 'h'},
 		{"login", optional_argument, NULL, 'l'},
 		{"user", required_argument, NULL, 'u'},
@@ -489,6 +495,33 @@
 			}
 			strcpy(argv[i], " ");
 		}
+		/* --away option */
+		else if (strstr (argv[i], "--aw") == argv[i]) {
+			char *equals;
+			opt_away = 1;
+			if ((equals = strchr(argv[i], '=')) != NULL) {
+				/* --away=MESG */
+				opt_away_arg = g_strdup (equals+1);
+			} else if (i+1 < argc && argv[i+1][0] != '-') {
+				/* --away MESG */
+				opt_away_arg = g_strdup (argv[i+1]);
+				strcpy (argv[i+1], " ");
+			}
+			strcpy (argv[i], " ");
+		}
+		/* -w option */
+		else if (strstr (argv[i], "-w") == argv[i]) {
+			opt_away = 1;
+			if (strlen (argv[i]) > 2) {
+				/* -wMESG */
+				opt_away_arg = g_strdup (argv[i]+2);
+			} else if (i+1 < argc && argv[i+1][0] != '-') {
+				/* -w MESG */
+				opt_away_arg = g_strdup (argv[i+1]);
+				strcpy (argv[i+1], " ");
+			}
+			strcpy(argv[i], " ");
+		}
 	}
 
 	gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, popt_options, 0, NULL);
@@ -497,7 +530,7 @@
 
 	/* scan command-line options */
 	opterr = 1;
-	while ((opt = getopt_long(argc, argv, /*"ahl::u:v" */ "ahl::u:v",
+	while ((opt = getopt_long(argc, argv, "ahl::w::u:v",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'u':	/* set user */
@@ -508,6 +541,10 @@
 			opt_login = 1;
 			opt_login_arg = g_strdup(optarg);
 			break;
+		case 'w':
+			opt_away = 1;
+			opt_away_arg = g_strdup (optarg);
+			break;
 		case 'a':	/* account editor */
 			opt_acct = 1;
 			break;
--- a/src/away.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/away.c	Thu Dec 14 00:11:59 2000 +0000
@@ -40,7 +40,7 @@
 
 GtkWidget *awaymenu = NULL;
 struct away_message *awaymessage = NULL;
-int default_away;
+struct away_message *default_away;
 int auto_away;
 
 static void destroy_im_away()
@@ -103,6 +103,9 @@
 	if (!blist)
 		return;
 
+	if (!a)
+		return;
+
 #ifdef USE_APPLET
 	remove_applet_away();
 	applet_widget_register_callback(APPLET_WIDGET(applet),
@@ -181,7 +184,7 @@
 
 void rem_away_mess(GtkWidget *w, struct away_message *a)
 {
-	struct away_message *default_msg;
+	int default_index;
 #ifdef USE_APPLET
 	char *awayname;
 	awayname = g_malloc(sizeof(*awayname) * (6 + strlen(a->name)));
@@ -191,11 +194,13 @@
 	applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname);
 	g_free(awayname);
 #endif
-	default_msg = g_slist_nth_data(away_messages, default_away);
-	away_messages = g_slist_remove(away_messages, a);
-	default_away = g_slist_index(away_messages, default_msg);
-	if (default_away == -1)
-		default_away = 0;
+	default_index = g_slist_index(away_messages, default_away);
+	if (default_index == -1) {
+		if (away_messages != NULL)
+			default_away = away_messages->data;
+		else
+			default_away = NULL;
+	}
 	g_free(a);
 	do_away_menu();
 	save_prefs();
--- a/src/gaim.h	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/gaim.h	Thu Dec 14 00:11:59 2000 +0000
@@ -409,10 +409,13 @@
 extern GList *conversations;
 extern GList *chat_rooms;
 extern GtkWidget *mainwindow;
+int opt_away;
+char *opt_away_arg;
+
 
 /* Globals in away.c */
 extern struct away_message *awaymessage;
-extern int default_away;
+extern struct away_message *default_away;
 extern int auto_away;
 extern GtkWidget *awaymenu;
 
@@ -563,6 +566,7 @@
 extern int file_is_dir (char *, GtkWidget *);
 extern char *gaim_user_dir();
 extern void strncpy_withhtml(gchar *, const gchar *, size_t);
+extern void away_on_login(char *);
 
 /* Functions in server.c */
 /* input to serv */
--- a/src/gaimrc.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/gaimrc.c	Thu Dec 14 00:11:59 2000 +0000
@@ -211,7 +211,8 @@
 		/* auto { time } { default message } */
 		else if (!strcmp(p->option, "auto")) {
 			auto_away = atoi(p->value[0]);
-			default_away = atoi(p->value[1]);
+			default_away = g_slist_nth_data(away_messages,
+							atoi(p->value[1]));
 		}
 	}
 }
@@ -240,7 +241,8 @@
 
 			awy = g_slist_next(awy);
 		}
-		fprintf(f, "\tauto { %d } { %d }\n", auto_away, default_away);
+		fprintf(f, "\tauto { %d } { %d }\n", auto_away, 
+			g_slist_index(away_messages, default_away));
 	} else {
 		fprintf(f, "\tmessage { boring default } { %s }\n", BORING_DEFAULT_AWAY_MSG);
 		fprintf(f, "\tauto { 0 } { 0 }\n");
@@ -771,7 +773,7 @@
 		report_idle = IDLE_SCREENSAVER;
 		web_browser = BROWSER_NETSCAPE;
 		auto_away = 10;
-		default_away = 0;
+		default_away = NULL;
 
 		g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s");
 		blist_pos.width = 0;
--- a/src/idle.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/idle.c	Thu Dec 14 00:11:59 2000 +0000
@@ -71,10 +71,10 @@
 
 	if ((general_options & OPT_GEN_AUTO_AWAY) &&
 	    (idle_time > (60 * auto_away)) && (awaymessage == NULL) && (auto_is_away == 0)) {
-		struct away_message *a;
-		set_default_away((GtkWidget *)NULL, (gpointer)default_away);
-		a = g_slist_nth_data(away_messages, default_away);
-		do_away_message((GtkWidget *)NULL, a);
+		set_default_away((GtkWidget*)NULL, 
+				 (gpointer)g_slist_index(away_messages,
+							 default_away));
+		do_away_message((GtkWidget*)NULL, default_away);
 		auto_is_away = 1;
 	} else if (auto_is_away == 1 && idle_time < 60 * auto_away) {
 		auto_is_away = 0;
--- a/src/multi.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/multi.c	Thu Dec 14 00:11:59 2000 +0000
@@ -719,6 +719,17 @@
 
 	plugin_event(event_signon, gc, 0, 0, 0);
 
+	/* away option given? */
+	if (opt_away) {
+		away_on_login(opt_away_arg);
+		/* don't do it again */
+		opt_away = 0;
+	}
+	if (opt_away_arg != NULL) {
+		g_free (opt_away_arg);
+		opt_away_arg = NULL;
+	}
+
 	/* everything for the account editor */
 	if (!acctedit)
 		return;
--- a/src/prefs.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/prefs.c	Thu Dec 14 00:11:59 2000 +0000
@@ -325,7 +325,7 @@
 	gtk_widget_show(opt);
 	gtk_menu_append(GTK_MENU(menu), opt);
 
-	set_default_away(menu, (gpointer)default_away);
+	set_default_away(menu, (gpointer)g_slist_index(away_messages, default_away));
 
 	gtk_option_menu_remove_menu(GTK_OPTION_MENU(omenu));
 	gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);
@@ -1184,11 +1184,11 @@
 	int length = g_slist_length(away_messages);
 
 	if (away_messages == NULL)
-		default_away = 0;
+		default_away = NULL;
 	else if ((int)i >= length)
-		default_away = length - 1;
+		default_away = g_slist_nth_data(away_messages, length - 1);
 	else
-		default_away = (int)i;
+		default_away = g_slist_nth_data(away_messages, (int)i);
 }
 
 void default_away_menu_init(GtkWidget *omenu)
@@ -1214,7 +1214,7 @@
 
 	gtk_option_menu_remove_menu(GTK_OPTION_MENU(omenu));
 	gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);
-	gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), default_away);
+	gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), g_slist_index(away_messages, default_away));
 }
 
 
--- a/src/util.c	Wed Dec 13 23:59:46 2000 +0000
+++ b/src/util.c	Thu Dec 14 00:11:59 2000 +0000
@@ -1103,6 +1103,8 @@
 	case 0:		/* full help text */
 		printf("Usage: %s [OPTION]...\n\n"
 		       "  -a, --acct          display account editor window\n"
+		       "  -w, --away[=MESG]   make away on signon (optional argument MESG specifies\n"
+		       "                      name of away message to use)\n"
 		       "  -l, --login[=NAME]  automatically login (optional argument NAME specifies\n"
 		       "                      account(s) to use)\n"
 		       "  -u, --user=NAME     use account NAME\n"
@@ -1270,3 +1272,33 @@
 			*dest++ = *src++;
 	}
 }
+
+
+void away_on_login (char *mesg)
+{
+	GSList *awy = away_messages;
+	struct away_message *a, *message = NULL;
+	
+	if (!blist) {
+		return;
+	}
+
+	if (mesg == NULL) {
+		/* Use default message */
+		do_away_message((GtkWidget*)NULL, default_away);
+	} else {
+		/* Use argument */
+		while (awy) {
+			a = (struct away_message *)awy->data;
+			if (strcmp (a->name, mesg) == 0) {
+				message = a;
+				break;
+			}
+			awy = awy->next;
+		}
+		if (message == NULL)
+			message = default_away;
+		do_away_message((GtkWidget*)NULL, message);
+	}
+	return;
+}