2 # Contest UI for the MO Submitter
3 # (c) 2007 Martin Mares <mj@ucw.cz>
9 defined $ENV{"MO_ROOT"} or die "Please set MO_ROOT to the contest root directory first.\n";
11 use lib $ENV{"MO_ROOT"} . "/submit";
12 use lib $ENV{"MO_ROOT"} . "/submit/lib/perl5";
18 my $conn = new MO::Submit;
20 ### GUI INITIALIZATION ###
26 my $busy_cursor = Gtk2::Gdk::Cursor->new('watch');
29 my $window = Gtk2::Window->new('toplevel');
30 $window->signal_connect("delete-event" => sub { Gtk2->main_quit });
31 $window->set_title($conn->{"Contest"} . " Submitter");
32 $window->set_wmclass("submitter", "Submitter");
33 $window->set_default_size(320, 400);
36 my $title_lab = Gtk2::Label->new;
37 $title_lab->set_markup("<span size='x-large'>" . $conn->{"Contest"} . "</span>");
40 my $b_submit = Gtk2::Button->new('Submit');
41 $b_submit->signal_connect(clicked => sub { Gtk2->main_quit });
42 $b_submit->set_sensitive(0);
44 my $b_check = Gtk2::Button->new('Check');
45 $b_check->signal_connect(clicked => sub { Gtk2->main_quit });
46 $b_check->set_sensitive(0);
48 my $b_refresh = Gtk2::Button->new('Refresh');
49 $b_refresh->signal_connect(clicked => sub { refresh(0) });
51 my $button_box = Gtk2::HBox->new;
52 $button_box->pack_start_defaults($b_submit);
53 $button_box->pack_start_defaults($b_check);
54 $button_box->pack_start_defaults($b_refresh);
55 $button_box->set_border_width(5);
58 my $task_store = Gtk2::ListStore->new('Glib::String', 'Glib::String', 'Glib::String');
60 my $task_view = Gtk2::TreeView->new($task_store);
61 my $task_renderer = Gtk2::CellRendererText->new;
62 my $task_col1 = Gtk2::TreeViewColumn->new_with_attributes("Task", $task_renderer, "text", 0);
63 $task_view->append_column($task_col1);
64 my $task_col2 = Gtk2::TreeViewColumn->new_with_attributes("Part", $task_renderer, "text", 1);
65 $task_view->append_column($task_col2);
66 my $task_col3 = Gtk2::TreeViewColumn->new_with_attributes("Status", $task_renderer, "text", 2);
67 $task_view->append_column($task_col3);
68 $task_view->set_headers_visible(0);
70 my $task_scroll = Gtk2::ScrolledWindow->new;
71 $task_scroll->set_policy("automatic", "automatic");
72 $task_scroll->add($task_view);
73 $task_scroll->set_border_width(5);
75 my $task_frame = Gtk2::Frame->new("Tasks");
76 $task_frame->add($task_scroll);
79 my $task_sel = $task_view->get_selection;
80 $task_sel->set_mode('single');
81 $task_sel->signal_connect(changed => sub {
82 my $iter = $_[0]->get_selected;
84 $selected_task = $task_store->get($iter, 0);
85 print "Selected $selected_task\n";
86 $b_submit->set_sensitive(1);
87 $b_check->set_sensitive(1);
89 $selected_task = undef;
90 print "Deselected task\n";
91 $b_submit->set_sensitive(0);
92 $b_check->set_sensitive(0);
96 my $status_bar = Gtk2::Statusbar->new;
97 my $bar_ctx = $status_bar->get_context_id('xyzzy');
99 my $vbox = Gtk2::VBox->new;
100 $vbox->pack_start($title_lab, 0, 0, 10);
101 $vbox->pack_start($task_frame, 1, 1, 0);
102 $vbox->pack_start($button_box, 0, 0, 0);
103 $vbox->pack_start($status_bar, 0, 0, 0);
106 $window->signal_connect("expose-event" => sub { init_refresh(); return 0; });
109 Glib::Timeout->add(5000, \&timed_refresh);
118 print "GUI: ", $_[0], "\n" if $conn->{"Trace"};
119 defined $last_status_id and $status_bar->remove($bar_ctx, $last_status_id);
120 $last_status_id = $status_bar->push($bar_ctx, shift @_);
125 $window->window->set_cursor($busy_cursor);
126 $window->Gtk2::Gdk::flush;
131 $window->window->set_cursor(undef);
132 $window->Gtk2::Gdk::flush;
135 my $window_inited = 0;
138 if (!$window_inited) {
147 refresh(0); # FIXME: If-modified-since version?
148 return 1; # We wish to re-run the timer
151 my $task_status_object;
154 sub recalc_task_list() {
157 foreach my $t ($task_status_object->getarray("(T")) {
158 my $task = $t->get("T");
159 foreach my $p ($t->getarray("(P")) {
160 my $part = $p->get("P");
161 $task_parts->{$task}->{$part} = $p;
163 my $iter = $task_store->append;
164 $task_store->set($iter,
166 1, ($task eq $part ? "" : $part),
174 my $force = shift @_;
175 if (!$conn->is_connected || $force) {
176 busy("Connecting to server...");
177 if ($conn->connect) {
178 ready("Connected successfully");
180 ready($conn->{"error"});
183 if ($conn->is_connected) {
184 busy("Updating status...");
185 my $r = new Sherlock::Object("!" => "STATUS");
186 $r = $conn->request($r);
188 ready($conn->{"error"});
189 } elsif ($r->get("-")) {
192 $task_status_object = $r;
197 if (!$conn->is_connected && !$force) {
199 $conn->log("Retrying");