#!/usr/bin/perl
#
# ClamTk, copyright (C) 2004-2011 Dave M
#
# 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".
#

use strict;
use warnings;
$| = 1;

use ClamTk::App;
use ClamTk::Device;
use ClamTk::GUI;
use ClamTk::Prefs;
use ClamTk::Results;
use ClamTk::Schedule;
use ClamTk::Submit;
use ClamTk::Update;

use encoding 'utf8';

use Locale::gettext;
use POSIX '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();

# See if the date in the submit file should be updated
ClamTk::Submit->test_date();

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

# I should probably just yank this...
# not sure it's ever been used.
sub zenity_error {
    my $text = shift;
    my @args = ( 'zenity', '--error', '--title', 'ClamTk', '--text' );
    system( @args, $text );
    return;
}
