changeset 6216:dc42b27101c0

[gaim-migrate @ 6702] fix the saving and importing of the default away message committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 18 Jul 2003 14:34:08 +0000
parents 643c7d3a18c2
children d4d2f0673852
files src/away.c src/gaimrc.c src/gtkconn.c src/gtkprefs.c src/idle.c src/prefs.c src/status.c src/ui.h
diffstat 8 files changed, 78 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/away.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/away.c	Fri Jul 18 14:34:08 2003 +0000
@@ -44,7 +44,6 @@
 GtkWidget *awayqueuesw;
 
 struct away_message *awaymessage = NULL;
-struct away_message *default_away;
 int auto_away;
 
 static void destroy_im_away()
@@ -305,14 +304,22 @@
 
 void rem_away_mess(GtkWidget *w, struct away_message *a)
 {
-	int default_index;
-	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;
+	struct away_message *default_away = NULL;
+	const char *default_away_name;
+	GSList *l;
+
+	default_away_name = gaim_prefs_get_string("/core/away/default_message");
+
+	for(l = away_messages; l; l = l->next) {
+		if(!strcmp(default_away_name, ((struct away_message *)l->data)->name)) {
+			default_away = l->data;
+			break;
+		}
 	}
+
+	if(!default_away && away_messages)
+		default_away = away_messages->data;
+
 	away_messages = g_slist_remove(away_messages, a);
 	g_free(a);
 	do_away_menu();
--- a/src/gaimrc.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/gaimrc.c	Fri Jul 18 14:34:08 2003 +0000
@@ -354,9 +354,12 @@
 		}
 		/* auto { time } { default message } */
 		else if (!strcmp(p->option, "auto")) {
+			struct away_message *default_away;
 			gaim_prefs_set_int("/core/away/mins_before_away",
 					atoi(p->value[0]));
 			default_away = g_slist_nth_data(away_messages, atoi(p->value[1]));
+			gaim_prefs_set_string("/core/away/default_message",
+					default_away->name);
 		}
 	}
 	if (!away_messages) {
--- a/src/gtkconn.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/gtkconn.c	Fri Jul 18 14:34:08 2003 +0000
@@ -22,6 +22,7 @@
 
 #include "account.h"
 #include "debug.h"
+#include "prefs.h"
 #include "util.h"
 
 #include "gtkblist.h"
@@ -282,7 +283,7 @@
 }
 
 
-void away_on_login(char *mesg)
+void away_on_login(const char *mesg)
 {
 	GSList *awy = away_messages;
 	struct away_message *a, *message = NULL;
@@ -294,22 +295,20 @@
 		return;
 	}
 
-	if (mesg == NULL) {
-		/* Use default message */
-		do_away_message(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 (mesg == NULL)
+		mesg = gaim_prefs_get_string("/core/away/default_message");
+	while (awy) {
+		a = (struct away_message *)awy->data;
+		if (strcmp(a->name, mesg) == 0) {
+			message = a;
+			break;
 		}
-		if (message == NULL)
-			message = default_away;
-		do_away_message(NULL, message);
+		awy = awy->next;
 	}
-	return;
+	if (message == NULL) {
+		if(!away_messages)
+			return;
+		message = away_messages->data;
+	}
+	do_away_message(NULL, message);
 }
--- a/src/gtkprefs.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/gtkprefs.c	Fri Jul 18 14:34:08 2003 +0000
@@ -2529,12 +2529,15 @@
 void default_away_menu_init(GtkWidget *omenu)
 {
 	GtkWidget *menu, *opt;
-	int index = 0;
+	int index = 0, default_index = 0;
 	GSList *awy = away_messages;
 	struct away_message *a;
+	const char *default_name;
 
 	menu = gtk_menu_new();
 
+	default_name = gaim_prefs_get_string("/core/away/default_message");
+
 	while (awy) {
 		a = (struct away_message *)awy->data;
 		opt = gtk_menu_item_new_with_label(a->name);
@@ -2543,13 +2546,16 @@
 		gtk_widget_show(opt);
 		gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
 
+		if(!strcmp(default_name, a->name))
+			default_index = index;
+
 		awy = awy->next;
 		index++;
 	}
 
 	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), g_slist_index(away_messages, default_away));
+	gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), default_index);
 }
 
 GtkWidget *pref_fg_picture = NULL;
@@ -2604,7 +2610,7 @@
 
 void set_default_away(GtkWidget *w, gpointer i)
 {
-
+	struct away_message *default_away = NULL;
 	int length = g_slist_length(away_messages);
 
 	if (away_messages == NULL)
@@ -2613,6 +2619,11 @@
 		default_away = g_slist_nth_data(away_messages, length - 1);
 	else
 		default_away = g_slist_nth_data(away_messages, (int)i);
+
+	if(default_away)
+		gaim_prefs_set_string("/core/away/default_message", default_away->name);
+	else
+		gaim_prefs_set_string("/core/away/default_message", "");
 }
 
 static GtkWidget *show_color_pref(GtkWidget *box, gboolean fgc)
--- a/src/idle.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/idle.c	Fri Jul 18 14:34:08 2003 +0000
@@ -92,6 +92,22 @@
 		&& (!gc->is_auto_away)) {
 
 		if (!gc->away) {
+			struct away_message *default_away = NULL;
+			const char *default_name;
+			GSList *l;
+
+			default_name = gaim_prefs_get_string("/core/away/default_message");
+
+			for(l = away_messages; l; l = l->next) {
+				if(!strcmp(default_name, ((struct away_message *)l->data)->name)) {
+					default_away = l->data;
+					break;
+				}
+			}
+
+			if(!default_away && away_messages)
+				default_away = away_messages->data;
+
 			gaim_debug(GAIM_DEBUG_INFO, "idle",
 					   "Making %s away automatically\n",
 					   gaim_account_get_username(account));
@@ -100,7 +116,6 @@
 			else if (default_away)
 				serv_set_away(gc, GAIM_AWAY_CUSTOM, default_away->message);
 			gc->is_auto_away = 1;
-			set_default_away(NULL, (gpointer)g_slist_index(away_messages, default_away));
 		} else
 			gc->is_auto_away = 2;
 	} else if (gc->is_auto_away &&
--- a/src/prefs.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/prefs.c	Fri Jul 18 14:34:08 2003 +0000
@@ -29,6 +29,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <glib.h>
+#include "internal.h"
 #include "prefs.h"
 #include "debug.h"
 #include "util.h"
@@ -107,6 +108,9 @@
 	gaim_prefs_add_none("/core/away");
 	gaim_prefs_add_bool("/core/away/away_when_idle", TRUE);
 	gaim_prefs_add_int("/core/away/mins_before_away", 1);
+	/* XXX: internationalized string in prefs...evil */
+	gaim_prefs_add_string("/core/away/default_message",
+			_("Slightly less boring default"));
 
 	/* Away -> Auto Response */
 	gaim_prefs_add_none("/core/away/auto_response");
--- a/src/status.c	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/status.c	Fri Jul 18 14:34:08 2003 +0000
@@ -71,18 +71,18 @@
 static void gaim_status_write(FILE *fp, struct away_message *am)
 {
 	char *esc = NULL;
-	
+
 	esc = g_markup_escape_text(am->name, -1);
-	fprintf(fp, " <status name=\"%s\">\n", esc);
-	g_free(esc);
-	
-	fprintf(fp, "    <state>away</state>\n");
-	
-	esc = g_markup_escape_text(am->message, -1);
-	fprintf(fp, "    <message>%s</message>\n", esc);
+	fprintf(fp, "\t<status name=\"%s\">\n", esc);
 	g_free(esc);
 
-	fprintf(fp, " </status>\n");
+	fprintf(fp, "\t\t<state>away</state>\n");
+
+	esc = g_markup_escape_text(am->message, -1);
+	fprintf(fp, "\t\t<message>%s</message>\n", esc);
+	g_free(esc);
+
+	fprintf(fp, "\t</status>\n");
 }
 
 static gboolean
@@ -134,7 +134,7 @@
 		}
 	} else if (!strcmp(element_name, "message")) {
 		data->tag = TAG_MESSAGE;
-		
+
 	}
 
 	g_hash_table_destroy(atts);
--- a/src/ui.h	Fri Jul 18 14:30:22 2003 +0000
+++ b/src/ui.h	Fri Jul 18 14:34:08 2003 +0000
@@ -147,7 +147,6 @@
 
 /* Globals in away.c */
 extern struct away_message *awaymessage;
-extern struct away_message *default_away;
 extern GtkWidget *awaymenu;
 extern GtkWidget *awayqueue;
 extern GtkListStore *awayqueuestore;