#!/usr/bin/perl
require 5.000; use strict 'vars', 'refs', 'subs';

my $VERSION = "0.58";
use Glade::PerlGenerate;

my $glade_filename = shift;
my $verbosity = shift;

#===============================================================================
#==== Documentation
#===============================================================================
=pod

=head1 NAME

glade2perl - Builds Gtk-Perl sources from a Glade file

=head1 SYNOPSIS

 glade2perl MyProject.glade 2;

=head1 DESCRIPTION

This script will read a Glade file (first arg) and generate Gtk-Perl source
application files for the Glade project. 

This script is called when you click Glade's 'Build' button or you can 
call it directly.

If you do not specify a project file as the first arg, Glade-Perl will work
on the most recently used file (details kept in the user options file).

Diagnostics are produced if you specify a verbose level as second arg 
(default level is 0 ie. no messages logged). 

    'verbose'          => 0,   # Turn off diagnostics
    'verbose'          => 1,   # Errors only
    'verbose'          => 2,   # Warnings and some diagnostics
    'verbose'          => 4,   # More diagnostics (you get the idea :)
    'verbose'          => 10,  # All diagnostics (more than you want)

For a user, probably the most useful verbose level is 2.

To save the diagnostics to disk (default 0 is NO output), you can
edit the value in glade2perl to change the default verbosity (eg from Glade)
or you can specify a 2nd arg to glade2perl 
if you are calling the script directly.

=cut

$verbosity ||= 0;
#$verbosity ||= 02;

my $base;
my $log_file;
my $project_options_file;

# Tell Glade-Perl to use the default log file name
$log_file = 'True' if $verbosity;

if ($glade_filename) {
    $base = $glade_filename;

    # Strip off any suffix (if it exists)
    $base =~ s/(.+)\..*$/$1/;

    $project_options_file = "$base.glade2perl.xml";
    # Default $project_options_file is eg 'Example/BusForm.glade2perl.xml'

    $log_file = "$base.glade2perl.log" if $verbosity;
    # Default $log_file is eg 'Example/BusForm.glade2perl.log'

} else {
    $glade_filename eq $Glade::PerlRun::NOFILE;
}

Glade::PerlGenerate->Form_from_Glade_File( 
    'verbose'           => $verbosity,
    'log_file'          => $log_file,               # Save diagnostics to disk
    'write_source'      => 'True',                  # We DO want source
    'dont_show_UI'      => 'True',                  # We DON'T want to show UI
    'options_set'       => $0,                      # glade2perl set the options
    'project_options'   => $project_options_file,   # Read/write project_options file
    'glade_filename'    => $glade_filename 
) && 

exit 0; # to return a C or shell type success

1;      # else return a C or shell failure

=head1 SEE ALSO

Glade::PerlGenerate(3)

=head1 AUTHOR

Dermot Musgrove <dermot.musgrove\@virgin.net>

=cut
