changeset 1109:c73736fa0b7c

[gaim-migrate @ 1119] Auto-Away, courtesy BMiller. damn cool. i'm impressed. also minor touch-ups, mostly to indicate what all the FIXME's mean. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 20 Nov 2000 10:37:40 +0000
parents cb338aa38e78
children ad20ddc0391e
files src/away.c src/buddy.c src/buddy_chat.c src/dialogs.c src/gaim.h src/gaimrc.c src/idle.c src/multi.c src/prefs.c src/sound.c
diffstat 10 files changed, 247 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/away.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/away.c	Mon Nov 20 10:37:40 2000 +0000
@@ -40,6 +40,8 @@
 
 GtkWidget *awaymenu = NULL;
 struct away_message *awaymessage = NULL;
+int default_away;
+int auto_away;
 
 static void destroy_im_away()
 {
@@ -56,13 +58,14 @@
 	insert_applet_away();
 #endif /* USE_APPLET */
 	if (imaway) {
-		gtk_widget_destroy(imaway);
+		GtkWidget *tmp = imaway;
 		imaway=NULL;
+		gtk_widget_destroy(tmp);
+		plugin_event(event_back, 0, 0, 0, 0);
         }
 
         serv_set_away(NULL);
 	awaymessage = NULL;
-	plugin_event(event_back, 0, 0, 0, 0);
 }
 
 
@@ -194,6 +197,7 @@
 
 void rem_away_mess(GtkWidget *w, struct away_message *a)
 {
+	struct away_message *default_msg;
 #ifdef USE_APPLET
 	char *awayname;
 	awayname = g_malloc(sizeof (*awayname) * (6 + strlen(a->name)));
@@ -202,7 +206,11 @@
 	strcat(awayname, a->name);
 	applet_widget_unregister_callback(APPLET_WIDGET(applet), 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;
         g_free(a);
         do_away_menu();
         save_prefs();
@@ -254,61 +262,72 @@
                         gtk_list_select_item(GTK_LIST(prefs_away_list), 0);
 	}
 	
-	if (!awaymenu) return;
-	l = gtk_container_children(GTK_CONTAINER(awaymenu));
-	
-	while(l) {
-		gtk_widget_destroy(GTK_WIDGET(l->data));
-		l = l->next;
-	}
+	if (awaymenu) {
+		l = gtk_container_children(GTK_CONTAINER(awaymenu));
+		
+		while(l) {
+			gtk_widget_destroy(GTK_WIDGET(l->data));
+			l = l->next;
+		}
 
 
-	remmenu = gtk_menu_new();
-
-	menuitem = gtk_menu_item_new_with_label(_("New Away Message"));
-	gtk_menu_append(GTK_MENU(awaymenu), menuitem);
-	gtk_widget_show(menuitem);
-	gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL);
-
-	awy = away_messages;
-        while(awy) {
-                a = (struct away_message *)awy->data;
-
-		remitem = gtk_menu_item_new_with_label(a->name);
-		gtk_menu_append(GTK_MENU(remmenu), remitem);
-		gtk_widget_show(remitem);
-		gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a);
-
-		awy = g_slist_next(awy);
+		remmenu = gtk_menu_new();
 
-	}
-	
-	menuitem = gtk_menu_item_new_with_label(_("Remove Away Message"));
-	gtk_menu_append(GTK_MENU(awaymenu), menuitem);
-	gtk_widget_show(menuitem);
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu);
-	gtk_widget_show(remmenu);
-	
-	sep = gtk_hseparator_new();
-	menuitem = gtk_menu_item_new();
-	gtk_menu_append(GTK_MENU(awaymenu), menuitem);
-	gtk_container_add(GTK_CONTAINER(menuitem), sep);
-	gtk_widget_set_sensitive(menuitem, FALSE);
-	gtk_widget_show(menuitem);
-	gtk_widget_show(sep);
-
-	awy = away_messages;
-	
-	while(awy) {
-                a = (struct away_message *)awy->data;
-                
-		menuitem = gtk_menu_item_new_with_label(a->name);
+		menuitem = gtk_menu_item_new_with_label(_("New Away Message"));
+		gtk_menu_append(GTK_MENU(awaymenu), menuitem);
+		gtk_widget_show(menuitem);
+		gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(create_away_mess), NULL);
+		
+		awy = away_messages;
+		while(awy) {
+			a = (struct away_message *)awy->data;
+			
+			remitem = gtk_menu_item_new_with_label(a->name);
+			gtk_menu_append(GTK_MENU(remmenu), remitem);
+			gtk_widget_show(remitem);
+			gtk_signal_connect(GTK_OBJECT(remitem), "activate", GTK_SIGNAL_FUNC(rem_away_mess), a);
+			
+			awy = g_slist_next(awy);
+			
+		}
+		
+		menuitem = gtk_menu_item_new_with_label(_("Remove Away Message"));
 		gtk_menu_append(GTK_MENU(awaymenu), menuitem);
 		gtk_widget_show(menuitem);
-		gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a);
-
-		awy = g_slist_next(awy);
-
+		gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), remmenu);
+		gtk_widget_show(remmenu);
+		
+		sep = gtk_hseparator_new();
+		menuitem = gtk_menu_item_new();
+		gtk_menu_append(GTK_MENU(awaymenu), menuitem);
+		gtk_container_add(GTK_CONTAINER(menuitem), sep);
+		gtk_widget_set_sensitive(menuitem, FALSE);
+		gtk_widget_show(menuitem);
+		gtk_widget_show(sep);
+		
+		awy = away_messages;
+		
+		while(awy) {
+			a = (struct away_message *)awy->data;
+			
+			menuitem = gtk_menu_item_new_with_label(a->name);
+			gtk_menu_append(GTK_MENU(awaymenu), menuitem);
+			gtk_widget_show(menuitem);
+			gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(do_away_message), a);
+			
+			awy = g_slist_next(awy);
+			
+		}
+	}
+	if (prefs_away_menu) {
+		l = gtk_container_children(GTK_CONTAINER(prefs_away_menu));
+		while(l) {
+			gtk_widget_destroy(GTK_WIDGET(l->data));
+			l = l->next;
+		}
+		gtk_widget_hide(GTK_WIDGET(prefs_away_menu));
+		default_away_menu_init(GTK_WIDGET(prefs_away_menu));
+		gtk_widget_show(prefs_away_menu);
 	}
 
 }
--- a/src/buddy.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/buddy.c	Mon Nov 20 10:37:40 2000 +0000
@@ -1750,7 +1750,8 @@
 		g_free(sotime);
 		g_free(itime);
 	} else {
-		/* FIXME */
+		/* FIXME : how do we do tooltips and idletime if 2 connections report a buddy?
+		 * keep in mind that we can't assume both connections are the same protocol */
 	}
 }
 
--- a/src/buddy_chat.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/buddy_chat.c	Mon Nov 20 10:37:40 2000 +0000
@@ -723,7 +723,7 @@
 void handle_click_chat(GtkWidget *widget, GdkEventButton *event, struct chat_room *cr)
 {
         if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
-		/* FIXME */
+		/* FIXME : double click on chat in buddy list */
                 serv_join_chat(connections->data, cr->exchange, cr->name);
         }
 }
--- a/src/dialogs.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/dialogs.c	Mon Nov 20 10:37:40 2000 +0000
@@ -1180,7 +1180,7 @@
 	char *country = gtk_entry_get_text(GTK_ENTRY(b->country));
 
 
-	/* FIXME */
+	/* FIXME : set dir. not important */
         if (connections)
 		serv_set_dir(connections->data, first, middle, last, maiden, city, state, country, web);
 
@@ -1941,7 +1941,7 @@
 	state = gtk_entry_get_text(GTK_ENTRY(b->stateentry)); 
 	country = gtk_entry_get_text(GTK_ENTRY(b->countryentry)); 
 
-	/* FIXME */
+	/* FIXME : dir search. not sure if even works; not important */
 	if (connections)
 		serv_dir_search(connections->data, first, middle, last, maiden, city, state, country, "");
         destroy_dialog(NULL, b->window);
@@ -1953,7 +1953,7 @@
 
 	email = gtk_entry_get_text(GTK_ENTRY(b->emailentry));
 	
-	/* FIXME */
+	/* FIXME : email search. not sure if even works; not important */
 	if (connections)
 		serv_dir_search(connections->data, "","","","","","","", email);
  
@@ -2799,7 +2799,7 @@
 			g_free (first);
 			return;
 		}
-		/* FIXME */
+		/* FIXME : import buddy list file. moderately important */
 		gc = connections->data;
         }
         else {
--- a/src/gaim.h	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/gaim.h	Mon Nov 20 10:37:40 2000 +0000
@@ -396,6 +396,8 @@
 
 /* Globals in away.c */
 extern struct away_message *awaymessage;
+extern int default_away;
+extern int auto_away;
 extern GtkWidget *awaymenu;
 
 /* Globals in buddy.c */
@@ -426,6 +428,7 @@
 #define OPT_GEN_TIK_HACK          0x00100000
 #define OPT_GEN_CTL_SMILEYS       0x00200000
 /* #define OPT_GEN_KEEPALIVE         0x00400000 now OPT_USR_KEEPALV */
+#define OPT_GEN_AUTO_AWAY	  0x00800000
 
 extern int display_options;
 #define OPT_DISP_SHOW_TIME        0x00000001
@@ -693,7 +696,10 @@
 extern void show_prefs();
 extern void show_debug(GtkObject *);
 extern void update_color(GtkWidget *, GtkWidget *);
+extern void set_default_away(GtkWidget *, gpointer);
+extern void default_away_menu_init(GtkWidget *);
 extern GtkWidget *prefs_away_list;
+extern GtkWidget *prefs_away_menu;
 extern GtkWidget *pref_fg_picture;
 extern GtkWidget *pref_bg_picture;
 
--- a/src/gaimrc.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/gaimrc.c	Mon Nov 20 10:37:40 2000 +0000
@@ -206,6 +206,12 @@
 			filter_break(a->message);
 			away_messages = g_slist_append(away_messages, a);
 		}
+		/* auto { time } { default message } */
+		else if (!strcmp(p->option, "auto"))
+		{
+			auto_away = atoi(p->value[0]);
+			default_away = atoi(p->value[1]);
+		}
 	}
 }
 
@@ -234,9 +240,13 @@
 	
 			awy = g_slist_next(awy);
 		}
+		fprintf(f, "\tauto { %d } { %d }\n", auto_away, default_away);
 	}
 	else
+	{
 		fprintf(f, "\tmessage { boring default } { %s }\n", BORING_DEFAULT_AWAY_MSG);
+		fprintf(f, "\tauto { 0 } { 0 }\n");
+	}
 
 	fprintf(f, "}\n");
 }
@@ -757,6 +767,8 @@
         	sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON;
         	report_idle = IDLE_SCREENSAVER;
         	web_browser = BROWSER_NETSCAPE;
+		auto_away = 10;
+		default_away = 0;
         
         	g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s");
         	blist_pos.width = 0;
--- a/src/idle.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/idle.c	Mon Nov 20 10:37:40 2000 +0000
@@ -36,6 +36,9 @@
 #include "gaim.h"
 
 
+int auto_is_away = 0;
+
+
 gint check_idle(struct gaim_connection *gc)
 {
 	time_t t;
@@ -52,8 +55,6 @@
         
 	time(&t);
 
-	if (report_idle == 0)
-                return TRUE;
 
 #ifdef USE_SCREENSAVER
 	if (report_idle == IDLE_SCREENSAVER) {
@@ -68,6 +69,31 @@
 #endif /* USE_SCREENSAVER */
 		idle_time = t - gc->lastsent;
 
+	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);
+		auto_is_away = 1;
+	} else if (auto_is_away == 1 && awaymessage != NULL &&
+		   idle_time < 60*auto_away) {
+		do_im_back((GtkWidget*)NULL, (GtkWidget*)NULL);
+		auto_is_away = 0;
+	}
+	if (auto_is_away == 1 && awaymessage == NULL)
+		auto_is_away = 0;
+
+
+	/* If we're not reporting idle times to the server, still use Gaim
+	   usage for auto-away, but quit here so we don't report to the 
+	   server */
+	if (report_idle == 0) {
+		return TRUE;
+	}
+
 	if (idle_time > 600 && !gc->is_idle) { /* 10 minutes! */
 		debug_printf("setting %s idle %d seconds\n", gc->username, idle_time);
 		serv_set_idle(gc, idle_time);
--- a/src/multi.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/multi.c	Mon Nov 20 10:37:40 2000 +0000
@@ -90,8 +90,10 @@
 	}
 	g_free(gc);
 	redo_convo_menus();
+#ifndef USE_APPLET
 	if (!connections && mainwindow)
 		gtk_widget_show(mainwindow);
+#endif
 }
 
 struct gaim_connection *find_gaim_conn_by_name(char *name) {
--- a/src/prefs.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/prefs.c	Mon Nov 20 10:37:40 2000 +0000
@@ -60,10 +60,12 @@
 static void prefs_build_browser(GtkWidget *);
 static gint handle_delete(GtkWidget *, GdkEvent *, void *);
 static void delete_prefs(GtkWidget *, void *);
+void set_default_away(GtkWidget *, gpointer);
 
 static GtkWidget *prefdialog = NULL;
 static GtkWidget *debugbutton = NULL;
 GtkWidget *prefs_away_list = NULL;
+GtkWidget *prefs_away_menu = NULL;
 
 static void destdeb(GtkWidget *m, gpointer n)
 {
@@ -330,6 +332,8 @@
 	gtk_widget_show(opt);
 	gtk_menu_append(GTK_MENU(menu), opt);
 
+	set_default_away(menu, (gpointer)default_away);
+
 	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), index);
@@ -1059,6 +1063,50 @@
 		do_away_message(NULL, gtk_object_get_user_data(GTK_OBJECT(i->data)));
 }
 
+static void set_auto_away(GtkWidget *w, GtkWidget *spin)
+{
+	auto_away = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+}
+
+void set_default_away(GtkWidget *w, gpointer i)
+{
+	int length = g_slist_length(away_messages);
+
+	if (away_messages == NULL)
+		default_away = 0;
+	else if ((int)i >= length)
+		default_away = length-1;
+	else
+		default_away = (int)i;
+}
+
+void default_away_menu_init(GtkWidget *omenu)
+{
+	GtkWidget *menu, *opt;
+	int index = 0;
+	GSList *awy = away_messages;
+	struct away_message *a;
+
+	menu = gtk_menu_new();
+
+	while (awy) {
+		a = (struct away_message *)awy->data;
+		opt = gtk_menu_item_new_with_label(a->name);
+		gtk_signal_connect(GTK_OBJECT(opt), "activate", GTK_SIGNAL_FUNC(set_default_away), (gpointer)index);
+		gtk_widget_show(opt);
+		gtk_menu_append(GTK_MENU(menu), opt);
+
+		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), default_away);
+}
+
+	
+
 static void away_page()
 {
 	GtkWidget *parent;
@@ -1072,6 +1120,8 @@
 	GtkWidget *label;
 	GtkWidget *list_item;
 	GtkWidget *sep;
+	GtkObject *adjust;
+	GtkWidget *spin;
 	GSList *awy = away_messages;
 	struct away_message *a;
 	char buffer[BUF_LONG];
@@ -1177,12 +1227,44 @@
 	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 0);
 	gtk_widget_show(sep);
 
-	hbox = gtk_hbox_new(TRUE, 0);
+	hbox = gtk_hbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+	gtk_widget_show(hbox);
+
+	gaim_button(_("Ignore new conversations when away   "), &general_options, OPT_GEN_DISCARD_WHEN_AWAY, hbox);
+	gaim_button(_("Sounds while away"), &sound_options, OPT_SOUND_WHEN_AWAY, hbox);
+
+	sep = gtk_hseparator_new();
+	gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 0);
+	gtk_widget_show(sep);
+
+	hbox = gtk_hbox_new(FALSE, 5);
 	gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
 	gtk_widget_show(hbox);
 
-	gaim_button(_("Ignore new conversations when away"), &general_options, OPT_GEN_DISCARD_WHEN_AWAY, hbox);
-	gaim_button(_("Sounds while away"), &sound_options, OPT_SOUND_WHEN_AWAY, hbox);
+	button = gaim_button(_("Auto Away after"), &general_options, OPT_GEN_AUTO_AWAY, hbox);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), spin);
+
+	adjust = gtk_adjustment_new(auto_away, 1, 1440, 1, 10, 10);
+	spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
+	gtk_widget_set_usize(spin, 50, -1);
+	if (!(general_options & OPT_GEN_AUTO_AWAY))
+		gtk_widget_set_sensitive(GTK_WIDGET(spin), FALSE);
+	gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
+	gtk_signal_connect(GTK_OBJECT(adjust), "value-changed", GTK_SIGNAL_FUNC(set_auto_away), GTK_WIDGET(spin));
+	gtk_widget_show(spin);
+
+	label = gtk_label_new(_("minutes using"));
+	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+	gtk_widget_show(label);
+
+	prefs_away_menu = gtk_option_menu_new();
+	if (!(general_options & OPT_GEN_AUTO_AWAY))
+		gtk_widget_set_sensitive(GTK_WIDGET(prefs_away_menu), FALSE);
+	default_away_menu_init(prefs_away_menu);
+	gtk_box_pack_start(GTK_BOX(hbox), prefs_away_menu, FALSE, FALSE, 0);
+	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_sensitive), prefs_away_menu);
+	gtk_widget_show(prefs_away_menu);
 
 	gtk_widget_show(prefdialog);
 }
@@ -1477,6 +1559,7 @@
 	prefs = NULL;
 	prefdialog = NULL;
 	debugbutton = NULL;
+	prefs_away_menu = NULL;
 	
         return FALSE;
 }
@@ -1488,6 +1571,7 @@
 		gtk_widget_destroy(prefs);
 	}
 	prefs = NULL;
+	prefs_away_menu = NULL;
 }
       
 
--- a/src/sound.c	Mon Nov 20 08:35:25 2000 +0000
+++ b/src/sound.c	Mon Nov 20 10:37:40 2000 +0000
@@ -97,14 +97,18 @@
 		return;
 	}
 	fstat(fd, &info);
+	if (info.st_size < 24)
+		return;
 	buf = malloc(info.st_size + 1);
 	read(fd, buf, 24);
 	read(fd, buf, info.st_size - 24);
 	close(fd);
 
 	fd = open("/dev/audio", O_WRONLY | O_EXCL);
-	if (fd < 0)
+	if (fd < 0) {
+		free(buf);
 		return;
+	}
 	write(fd, buf, info.st_size - 24);
 	free(buf);
 	close(fd);
@@ -271,6 +275,31 @@
         return 0;
 }
 
+static int play_nas_file(char *file)
+{
+	struct stat stat_buf;
+	char *buf;
+	int ret;
+	int fd = open(file, O_RDONLY);
+	if (fd <= 0)
+		return 0;
+
+	if (!can_play_nas())
+		return 0;
+
+	if (stat(file, &stat_buf))
+		return 0;
+
+	if (!stat_buf.st_size)
+		return 0;
+
+	buf = malloc(stat_buf.st_size);
+	read(fd, buf, stat_buf.st_size);
+	ret = play_nas(buf, stat_buf.st_size);
+	free(buf);
+	return ret;
+}
+
 #endif
 
 void play_file(char *filename) {
@@ -296,7 +325,10 @@
 			_exit(0);
 #endif
 
-		/* FIXME : NAS (does anyone use this?) */
+#ifdef NAS_SOUND
+		if (play_nas_file(filenae))
+			_exit(0);
+#endif
 
 		if (can_play_audio()) {
 			play_audio_file(filename);