#!/usr/bin/perl -w
#
#     G-Tablix, graphical user interface for Tablix
#     Copyright (C) 2004,2005 Bostjan Spetic
# 
#     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
#
# 		author: Bostjan Spetic, igzebedze@cyberpipe.org
# 		contributions: Tomaz Solc
# 		19.12.2004, 30.1.2005, 27.2.2005

use strict;

# --------- check these for your system...
my $version = "0.0.9-13";
my $debug = 0;

use lib "/usr/lib";
use lib "./modules";

# -----------------------------------

use POSIX qw(setlocale LC_MESSAGES LC_ALL LC_CTYPE);
use Locale::gettext;
use encoding 'utf8';
use FindBin qw($Bin);
use Getopt::Std;
use I18N::Langinfo qw(langinfo DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7 
			MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12);

use Glib qw(TRUE FALSE);
use Gtk2 '-init';    
use Gtk2::GladeXML;
use Gtk2::SimpleList; 
use Gtk2::Gdk::Keysyms;
use XML::LibXML;
#use XML::Simple;
use File::Temp qw/ tempfile tempdir /;

# then we load other modules
use gtablix::settings;
use gtablix::gui;
use gtablix::check;
use gtablix::xml;
use gtablix::modinfo;
use gtablix::helpers;
use gtablix::lists_handlers;
use gtablix::plot;
use gtablix::ttview;
use gtablix::wizard;
use gtablix::ttedit;	
use gtablix::init;
use gtablix::input_fet;
use gtablix::import_tablix1;
use gtablix::import_tablix2;
use gtablix::export_tablix1;
use gtablix::export_tablix2;
#use gtablix::debug;

# settings 
	our($opt_h, $opt_d,$opt_l);
	&getopts('hdl:');
	if ($opt_h) { &print_help; exit 1; }
	if ($opt_d) { $debug = 1; }

my $libdir = $Bin;
if ($libdir eq '/usr/bin') { $libdir = '/usr/lib'; }
my $docdir;
my $picdir;
my $tempdir = tempdir("gtablix-XXXX", TMPDIR => 1);
if ($libdir eq '/usr/lib') {
	$picdir = '/usr/share/gtablix';
	$docdir = '/usr/share/doc/gtablix';
} else {
	$picdir = $libdir.'/modules/pixmaps';
	$docdir = $libdir.'/doc';
	&check_locale_dirs;	
	bindtextdomain('gtablix',$libdir.'/po');
	$libdir = $libdir.'/modules';
}

&init_stuff;

# other settings
my %defined_tt_entries; my %uid_tt_entries;
my $helpfile = "$docdir/".gettext("help.html");
my $wizardfile = "$docdir/".gettext("wizard.help");
my $faqfile = "$docdir/".gettext("faq.txt");

#------------------------

Gtk2->main;

system ("rm -rf $tempdir");
&save_settings;
exit 0;

# ------------------------------------------------------------------------

# then we setup variables callback
sub get_version { return $version; }
sub get_doc { return $docdir; }
sub get_picdir { return $picdir; }
sub get_vars { return (&get_form,undef,\%defined_tt_entries,\%uid_tt_entries); }
sub get_help { return ($helpfile,$wizardfile,$faqfile); }
sub get_libs { return $libdir; }
sub get_temp {	return $tempdir; }
sub get_debug { return $debug; }
sub set_debug { $debug = $_[0]; }
sub get_optl { return $opt_l; }

# ---------------------- drugo -------------------------------
sub get_when {
	my ($who) = @_;
	while ((my $key, my $value) = each %defined_tt_entries) {
		if ($value eq $who) {
			delete $defined_tt_entries{$key};
			return $key;
		}
	}
	return 0;
}
sub debug {
	print $_[0] if $debug;
}
sub print_help {
	print gettext("Usage: \n\tgtablix [-options] [file]\n\nOptions:\n\t-h - display this help\n\t-d - debug mode\n\t-l CODE - run in different language\n\n");
}
