view plugins/perl/scripts/count_down.pl @ 11249:b4b1be482b4e

[gaim-migrate @ 13418] sf patch #1235519, from Sadrul Habib Chowdhury This is a pretty big patch that makes Gaim correctly save and restore the current status (away/available, away message, available message, invisible, etc). The GaimGtkStatusBoxWidget thing I think defaults to "Available" every time its created, which overrides the setting that was saved to the XML file. So that still needs to be fixed before this will really work. Anyway, mad props to Sadrul for putting up with my requests on this patch committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 13 Aug 2005 05:22:09 +0000
parents 0e9e2b923d09
children 6fd82071a7b8
line wrap: on
line source

use Gaim;

%PLUGIN_INFO = ( 
	perl_api_version => 2, 
	name => "Countdown Info Timer", 
	version => "0.1", 
	summary => "Makes a countdown in days from today.", 
	description => "Long description coming....", 
	author => "John H. Kelm <johnhkelm\@gmail.com>", 
	url => "http://gaim.sourceforge.net/", 
	
	load => "plugin_load", 
	unload => "plugin_unload" 
); 

	$GLOBAL_TEST_VAR = "STUFF!";

sub plugin_unload { 
	my $plugin = shift; 
}

sub plugin_init { 
	return %PLUGIN_INFO; 
} 


sub plugin_load { 
	my $plugin = shift; 
	
	# Retrieve all the accounts
	@accounts = Gaim::Accounts::get_all();
	
	print "NUM OF ACCS: " . $accounts . "\n";
	# Search each account's user info for our tag
	foreach $acc (@accounts) {
		print "IN ACCOUNTS\n";
		$user_info = Gaim::Account::get_user_info($acc);
		print "USER INFO 1: " . $user_info . "\n";
		# Find <countdown> and replace
		$user_info =~ /countdown([0-9]+).([0-9]+).([0-9]+)/;
		print "Found: " .$1 . " " . $2 . " " . $3 . "\n";
		$days = count_days($1, $2, $3);
		$user_info =~ s/countdown(\d\d\d\d).(\d\d).(\d\d)/$days/;
		print "USER INFO 2: " . $user_info . "\n";
	#	Gaim::Account::set_user_info($acc, $user_info);
	
	}
	
	eval '
		use Gtk2 \'-init\';
		use Glib;
		$window = Gtk2::Window->new(\'toplevel\');
		$window->set_border_width(10);
		$button = Gtk2::Button->new("Hello World");
		$button->signal_connect(clicked => \&hello, $window);
		
		$window->add($button);
		$button->show;
		$window->show;
	#	Gtk2->main;
		
		0;
		
	'; warn $@ if $@;
}

sub hello {
	my ($widget, $window) = @_;
	print "Called from sub hello!\n ";
	print "Test var: " . $GLOBAL_TEST_VAR . " \n";
	@accounts = Gaim::Accounts::get_all();
	$acc = $accounts[0];
	$user_info = Gaim::Account::get_user_info($acc);
	print "USER INFO from sub hello: " . $user_info . "\n";
	$window->destroy;
}

sub count_days {
	($year, $month, $day) = @_;
	
	
	eval '
		use Time::Local;
		$future = timelocal(0,0,0,$day,$month-1,$year); 
	'; warn $@ if $@;
	$today = time();
	$days = int(($future - $today)/(60*60*24));
	return $days;
}