#!/usr/bin/perl
#
# This file is part of ClamTk.
#
# ClamTk is free software; you can redistribute it and/or modify it
# under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
# Foundation; either version 1, or (at your option) any later version, or
#
# b) the "Artistic License".
#
# ClamTk, copyright (C) 2004-2010 Dave M

use strict;
use warnings;
$|++;

use ClamTk::Prefs qw/structure restore_file_fix/;
use ClamTk::GUI qw/start_gui/;

use encoding 'utf8';

use Locale::gettext;
use POSIX qw/locale_h/;
textdomain('clamtk');
setlocale( LC_MESSAGES, '' );
bind_textdomain_codeset( 'clamtk', 'UTF-8' );

# Ensure all the normal directories are created
ClamTk::Prefs->structure() or do {
    zenity_error( gettext('Unable to create startup directories!') );
};

# Ensure the preferences are normalized
# Create defaults if they do not exist
ClamTk::Prefs->custom_prefs();

# Patches?
ClamTk::Prefs->restore_file_fix();

# Launch!
ClamTk::GUI->start_gui() or do {
    zenity_error( ('Unable to create graphical interface!') );
    exit(1);
};

sub zenity_error {
    my $text = shift;
    my @args = ( 'zenity', '--error', '--title', 'ClamTk', '--text' );
    system( @args, $text );
    return;
}
