#!/usr/bin/perl

use warnings;
use strict;

use Gtk2 -init;

# Main Window
my $window=new Gtk2::Window("toplevel");
$window->signal_connect("destroy", sub { Gtk2->main_quit });

my $vbox=new Gtk2::VBox(0, 0);

my $main_list_window=Gtk2::ScrolledWindow->new(undef, undef);
my $list_store=new Gtk2::ListStore(qw/
                                   Glib::Int
                                   Glib::String
                                   Glib::String
                                   Glib::String
                                   Glib::String
                                   Glib::String
                                   Glib::String
                                   /);

my $tree_view=new Gtk2::TreeView($list_store);
my @column_names=(
                  'ID',
                  'Login',
                  'Status', 
                  'Result', 
                  'Date Scheduled', 
                  'Job ID', 
                  'Machine Status'
                  );
foreach my $i (0..$#column_names) {
    my $column_name=$column_names[$i];
    my $tree_column=new Gtk2::TreeViewColumn;
    $tree_column->set_title($column_name);
    
    my $renderer=new Gtk2::CellRendererText;
    $tree_column->pack_start($renderer, 0);
    
    $tree_column->add_attribute($renderer, text => $i);
    
    $tree_view->append_column($tree_column);
}

$tree_view->get_selection->set_mode('multiple');

$main_list_window->add($tree_view);

$main_list_window->set_size_request(-1, 350);
$main_list_window->set_policy('never','automatic');

$vbox->pack_start($main_list_window, 1, 1, 0);

my $button=new Gtk2::Button("Fill It");
$button->signal_connect('clicked' => \&check_new_steps, $tree_view);
$vbox->pack_start($button, 0, 0, 0);

$window->add($vbox);
$window->show_all;

Gtk2->main;
exit;


sub check_new_steps{
    my $tree_view=pop;
    my @datar=(
               [5176684, 'user111' , 'confirm'   , 'failed', '01-apr-2005 10:45', undef , '< None >'],
               [1488779, 'user1111', 'confirm'   , 'failed', '01-sep-2005 02:43', undef , '< None >'],
               [1645627, 'user11'  , 'confirm'   , 'failed', '05-sep-2005 05:06', undef , '< None >'],
               [1647143, 'user112' , 'confirm'   , 'failed', '05-sep-2005 07:35', undef , '< None >'],
               [1647262, 'user11'  , 'confirm'   , 'failed', '05-sep-2005 07:45', undef , '< None >'],
               [1647867, 'user11'  , 'confirm'   , 'failed', '05-sep-2005 08:07', undef , '< None >'],
               [1669614, 'user1112', 'confirm'   , 'failed', '06-sep-2005 11:13', undef , '< None >'],
               [1669740, 'user1112', 'confirm'   , 'failed', '06-sep-2005 11:21', undef , '< None >'],
               [1669982, 'user1112', 'confirm'   , 'failed', '06-sep-2005 11:43', undef , '< None >'],
               [1670307, 'user1112', 'confirm'   , 'failed', '06-sep-2005 12:21', undef , '< None >'],
               [1670935, 'user1112', 'confirm'   , 'failed', '06-sep-2005 01:19', undef , '< None >'],
               [1671474, 'user1112', 'confirm'   , 'failed', '06-sep-2005 02:13', undef , '< None >'],
               [1671964, 'user1112', 'confirm'   , 'failed', '06-sep-2005 02:33', undef , '< None >'],
               [1672494, 'user1113', 'confirm'   , 'failed', '06-sep-2005 03:23', undef , '< None >'],
               [1672811, 'user1113', 'confirm'   , 'failed', '06-sep-2005 03:49', undef , '< None >'],
               [1673539, 'user1113', 'confirm'   , 'failed', '06-sep-2005 04:29', undef , '< None >'],
               [1674687, 'user1113', 'confirm'   , 'failed', '06-sep-2005 06:23', undef , '< None >'],
               [1675425, 'user1113', 'confirm'   , 'failed', '06-sep-2005 07:25', undef , '< None >'],
               [1675593, 'user1113', 'confirm'   , 'failed', '06-sep-2005 07:37', undef , '< None >'],
               [1675597, 'user1113', 'confirm'   , 'failed', '06-sep-2005 07:37', undef , '< None >'],
               [1675615, 'user1113', 'confirm'   , 'failed', '06-sep-2005 07:40', undef , '< None >'],
               [1675626, 'user1113', 'confirm'   , 'failed', '06-sep-2005 07:40', undef , '< None >'],
               [1679560, 'user1113', 'confirm'   , 'failed', '07-sep-2005 04:36', undef , '< None >'],
               [1679910, 'user1113', 'confirm'   , 'failed', '07-sep-2005 05:03', undef , '< None >'],
               [2078295, 'user1112', 'confirm'   , 'failed', '23-sep-2005 06:13', undef , '< None >'],
               [2083074, 'user1112', 'confirm'   , 'failed', '23-sep-2005 08:49', undef , '< None >'],
               [2084547, 'user1112', 'confirm'   , 'failed', '23-sep-2005 09:21', undef , '< None >'],
               [2084701, 'user1112', 'confirm'   , 'failed', '23-sep-2005 09:26', undef , '< None >'],
               [2084754, 'user1113', 'confirm'   , 'failed', '23-sep-2005 09:29', undef , '< None >'],
               [2095551, 'user11'  , 'confirming', undef   , '23-sep-2005 02:01', 46407, '46407 RUN machine1234 login1 login1'],
               [2095642, 'user113' , 'scheduled' , undef   , '23-sep-2005 02:04', undef , '< None >'],

               );

    foreach my $row (@datar){
        my $list_store=$tree_view->get_model;
        my $temp=$list_store->append;
        my @data;
        $list_store->set($temp, 
                         map {($_ => $row->[$_])} (0..6));
    }
    
    1;
}

