# Copyright (c) 2006 Torbjörn Svensson <azoff@se.linux.org>.
#
# 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

use Irssi;
use vars qw($VERSION %IRSSI); 
$VERSION = "0.1";
%IRSSI = (
	authors			=> "Torbjörn Svensson",
	contact         => "azoff\@se.linux.org",
	name            => "channellist",
	description     => "Show channelnames and numbers in the statusbar",
	license         => "GNU GPLv2",
	changed         => "Fri, 07 Apr 2006 14:23:29 +0200",
						
);
my $refreshtag;

# do the actual drawing..
sub chanlist {
	my ($item, $get_size_only) = @_;
	
	my $str;
	for my $refnum (1 .. Irssi::windows_refnum_last()) {
		$str .= sprintf( "[%d: %s] ", $refnum, Irssi::window_find_refnum($refnum)->{active}->{name} );
	}
	

	$item->default_handler($get_size_only, undef, $str);
}

# callback function
sub refresh_chanlist {
    Irssi::statusbar_items_redraw('chanlist');
}

# register the sb-item
Irssi::statusbar_item_register('chanlist', '{sb $0-}', 'chanlist');
Irssi::statusbars_recreate_items();

Irssi::timeout_remove($refresh_tag) if $refresh_tag;
$refresh_tag = Irssi::timeout_add(1000, 'refresh_chanlist', undef);

