view src/idle.c @ 1911:db3104dda736

[gaim-migrate @ 1921] Mike Heffner's redesigned UI. I changed around a lot of things from his patch, not because they weren't good or needed or anything like that; most of the changes I made just made the patch smaller. I moved functions back to where they originally where and renamed them back to what they originally were. Granted the names aren't as... good as the changes Mike made, but eh, it made my life a lot easier when I could see the meat of the changes without all the cosmetic details. The only thing I really changed about his patch was I made the list BROWSE instead of SINGLE so that there wouldn't be need for a deselect callback. Oh yeah, and update_show_plugins is called from different places (so that plugins can call load_plugin and have the window update properly). committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 29 May 2001 09:46:05 +0000
parents e65b9942f649
children 39df68320a82
line wrap: on
line source

/*
 * gaim
 *
 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <time.h>
#include <stdio.h>
#include <unistd.h>

#ifdef USE_SCREENSAVER
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/scrnsaver.h>
#endif /* USE_SCREENSAVER */

#include "multi.h"
#include "gaim.h"
#include "prpl.h"


gint check_idle(struct gaim_connection *gc)
{
	time_t t;
#ifdef USE_SCREENSAVER
	static XScreenSaverInfo *mit_info = NULL;
	static Display *d = NULL;
#endif
	time_t idle_time;

	/* Not idle, really...  :) */
	update_idle_times();

	plugin_event(event_blist_update, 0, 0, 0, 0);

	time(&t);


#ifdef USE_SCREENSAVER
	if (report_idle == IDLE_SCREENSAVER) {
		if (!d)
			d = XOpenDisplay((char *)NULL);
		if (mit_info == NULL) {
			mit_info = XScreenSaverAllocInfo();
		}
		XScreenSaverQueryInfo(d, DefaultRootWindow(d), mit_info);
		idle_time = (mit_info->idle) / 1000;
	} else
#endif /* USE_SCREENSAVER */
		idle_time = t - gc->lastsent;

	if ((general_options & OPT_GEN_AUTO_AWAY) && (idle_time > (60 * auto_away)) &&
			(!gc->is_auto_away) && (!gc->away)) {
		debug_printf("making %s away automatically\n", gc->username);
		set_default_away((GtkWidget*)NULL, (gpointer)g_slist_index(away_messages, default_away));
		if (!gc->away) {
			if (g_slist_length(connections) == 1)
				do_away_message(NULL, default_away);
			else if (default_away)
				serv_set_away(gc, GAIM_AWAY_CUSTOM, default_away->message);
			gc->is_auto_away = 1;
		} else
			gc->is_auto_away = 2;
	} else if (gc->is_auto_away && idle_time < 60 * auto_away) {
		if (gc->is_auto_away == 2) {
			gc->is_auto_away = 0;
			return TRUE;
		}
		gc->is_auto_away = 0;
		if (awaymessage == NULL) {
			debug_printf("removing auto-away message for %s\n", gc->username);
			serv_set_away(gc, GAIM_AWAY_CUSTOM, NULL);
		} else {
			if (g_slist_length(connections) == 1)
				do_im_back(0, 0);
			else {
				debug_printf("replacing auto-away with global for %s\n", gc->username);
				serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message);
			}
		}
	}


	/* 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 == IDLE_NONE) {
		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);
		gc->is_idle = 1;
		system_log(log_idle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON);
	} else if (idle_time < 600 && gc->is_idle) {
		debug_printf("setting %s unidle\n", gc->username);
		serv_touch_idle(gc);
		system_log(log_unidle, gc, NULL, OPT_LOG_BUDDY_IDLE | OPT_LOG_MY_SIGNON);
	}

	return TRUE;

}