#!/usr/bin/perl
# 
#  Download.pm - Perlmodule which computes the Download part of Oroborus.org
# 
#  Copyright (C) 2002 Stefan Pfetzing and Martin Helas
# 
#  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, 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.  
# 

# define the Package name
package Oroborus::Download;

#use Apache::Reload;
use strict;
our ($q);

# constructor needs one argument, a reference to a CGI object
sub new($) {
	my $proto = shift();
	$q = shift();
	my $class = ref($proto) || $proto;
	my $self  = {};
	bless ($self, $class);
	return $self;
}

# destructor
sub DESTROY() {
};

sub getContent() {
	my $self = shift();
	return $q->table({-width=>"100%",
		-cellpadding=>"0",
		-cellspacing=>"0"},
		$q->Tr(
			$q->td(
				$q->h2("Download Section")
			)
		),
		$q->Tr(
			$q->td(
				$q->br(),
				$q->table({-width=>"100%",
					-cellpadding=>"0",
					-cellspacing=>"0"},
					$q->Tr(
						$q->td("Source"),
						$q->td("CVS")
					),
					$q->Tr(
						$q->td({-valign=>"top"},
							$q->ul($q->li($self->getModules()))
						),
						$q->td({-valign=>"top"},
							$q->ul(
								$q->li([
									$q->a({-href=>"http://savannah.nongnu.org/cvs/?group=oroborus"},
										"Savannah info page for CVS"),
									$q->a({-href=>"http://savannah.nongnu.org/cgi-bin/viewcvs/oroborus/"},
										"Webcvs tree of Oroborus (Source)"),
									$q->a({-href=>"http://savannah.nongnu.org/cgi-bin/viewcvs//non-gnu//oroborus/?cvsroot=www.gnu.org"},
										"Webcvs tree of Oroborus (Website)")
									]
								)
							)
						)
					)
				),
				$q->p(
					"If you are using Debian, you can download Oroborus and its tools either from the Sid (Unstable) Debian archive, or by putting ",
					"the following line in your /etc/apt/sources.list:"
				),
				$q->code("deb http://www.oroborus.org/debian sid main"),
				$q->p(
					"These versions are compiled for Debian Sid, but the sources are also availible, simply put the follwing in your /etc/apt/sources.list:"
				),
				$q->code("deb-src http://www.oroborus.org/debian sid main"),
			)
		)
	);
}

sub getModules() {
	my $self = shift();
	my $ret = [];
	my @modulesList = (["Oroborus", "oroborus"], ["KeyLaunch", "keylaunch"], ["DeskMenu", "deskmenu"], ["DeskLaunch", "desklaunch"]);

	foreach my $module (@modulesList) {
		push @$module, $self->getVersion($module->[1]);
		push @$ret, $module->[0].": ".$q->a({-href=>("/debian/dists/sid/main/source/x11/".$module->[1]."_".$module->[2].".tar.gz")}, $module->[2] . " tar.gz");
	}
	return $ret;
}

# get the current version of a module (Oroborus, keylaunch etc...)
sub getVersion($) {
	my $self = shift();
	my $module = shift();
	my $qst = $module . "_";
	opendir ( FILES, "debian/dists/sid/main/source/x11" );
	foreach my $file (readdir(FILES)) {
		if ($file =~ /$qst/) {
			$file =~ s/^$qst//;
			$file =~ s/\.dsc$//;
			$file =~ s/\.tar\.gz$//;
			$file =~ s/_source\.changes$//;
			$file =~ s/\.diff\.gz$//;
			closedir FILES;
			return $file;
		}
	}
	closedir FILES;
	return "";
}

# return a true value
1;
__END__


