# Wait_List_Window.pm
# Wait list window for crashman3
# $Id$
package Wait_List_Window;

use strict;
use CSL::Gnome2;
use Gnome2;
use Gtk2::GladeXML;
use Crashbackend;

use fields qw(list_store xml);

sub new
{
    my Wait_List_Window $self = shift;
    $self = fields::new($self) unless ref($self);

    my $GLADEDIR = $main::GLADEDIR || ".";
    $self->{xml} = Gtk2::GladeXML->new("$GLADEDIR/crashman3.glade",
                                       'wait_list_window')
                                 or die "Error Opening Glade File";
    $self->{xml}->signal_autoconnect_from_package($self);

    return $self;
}

sub run
{
    my ($class) = @_;

    Gnome2::Program->init("crashman", "3");

    my $self = $class->new;

    # Set up the list store
    my $list_store;
    $list_store = Gtk2::ListStore->new('Glib::String',  # User name
                                       'Glib::String',  # Date
                                       'Glib::String',  # Comment
                                       'Glib::Scalar'); # Data
    # Set up the list view
    my $list_view;
    $list_view = $self->wgt('wait_list_view');

    $list_view->set_model($list_store);
    $list_view->get_selection->set_mode('single');
    my @columns = ("User Name", "Date", "Comment");
    for (my $i = 0; $i <= $#columns; $i++)
    {
        $list_view->insert_column_with_attributes(-1, $columns[$i],
                                                  Gtk2::CellRendererText->new,
                                                  "text", $i);
    }
        
    # Populate the list store
    my @waitlist_entries = Crashbackend::get_wait_list;
    my %waitlist;
    foreach my $row (@waitlist_entries) {
        $waitlist{$row->{user_name}} = $row;
        $row->{date} =~ s/(\d+)-0*(\d+)-0*(\d+)/$2\/$3\/$1/;
        $row->{date} =~ s/\..*//;
        $list_store->set($list_store->append,
                         0, $row->{user_name},
                         1, $row->{date},
                         2, $row->{comment},
                         3, $row);
    }
    $self->{list_store} = $list_store;
}

sub on_ok_button_clicked
{
    my ($self) = @_;
    
    $self->wgt("wait_list_window")->destroy;
}

sub wgt { return $_[0]->{xml}->get_widget($_[1]); }

1;

