1 |
package gamelist; |
2 |
|
3 |
use KGS::Constants; |
4 |
|
5 |
use base gtk::widget; |
6 |
|
7 |
sub new { |
8 |
my $class = shift; |
9 |
my $self = $class->SUPER::new(@_); |
10 |
|
11 |
$self->{widget} = new Gtk2::VPaned; |
12 |
$self->{widget}->set(position_set => 1); |
13 |
gtk::state $self->{widget}, "gamelist::vpane", undef, position => 60; |
14 |
|
15 |
$self->{model1} = new Gtk2::ListStore Glib::Scalar, |
16 |
Glib::String, Glib::String, Glib::String, Glib::String, Glib::Int, Glib::String, Glib::String; |
17 |
gtk::state $self->{model1}, "gamelist::model1", undef, modelsortorder => [4, 'descending']; |
18 |
|
19 |
$self->{widget}->add(my $sw = new Gtk2::ScrolledWindow); |
20 |
$sw->set_policy("never", "always"); |
21 |
$sw->add($self->{view1} = new Gtk2::TreeView $self->{model1}); |
22 |
$self->{view1}->set_search_column(1); |
23 |
|
24 |
$self->{model2} = new Gtk2::ListStore Glib::Scalar, |
25 |
Glib::String, Glib::String, Glib::String, Glib::String, Glib::Int, |
26 |
Glib::String, Glib::String, Glib::Int, Glib::Int, Glib::Int, Glib::String; |
27 |
gtk::state $self->{model2}, "gamelist::model1", undef, modelsortorder => [4, 'descending']; |
28 |
|
29 |
$self->{widget}->add(my $sw = new Gtk2::ScrolledWindow); |
30 |
$sw->set_policy("never", "always"); |
31 |
$sw->add($self->{view2} = new Gtk2::TreeView $self->{model2}); |
32 |
$self->{view2}->set_search_column(1); |
33 |
|
34 |
for my $view ($self->{view1}, $self->{view2}) { |
35 |
push @{$self->{rlcolumns}}, my $column = |
36 |
Gtk2::TreeViewColumn->new_with_attributes ("Room", $gtk::text_renderer, text => 1); |
37 |
$column->set_sort_column_id(1); |
38 |
$column->set(resizable => 1); |
39 |
$column->set(sizing => 'fixed'); |
40 |
gtk::state $column, "gamelist::model::Room", undef, column_size => 80; |
41 |
$view->append_column ($column); |
42 |
|
43 |
push @{$self->{rlcolumns}}, my $column = |
44 |
Gtk2::TreeViewColumn->new_with_attributes ("T", $gtk::text_renderer, text => 2); |
45 |
$column->set_sort_column_id(2); |
46 |
$column->set(sizing => 'grow-only'); |
47 |
$view->append_column ($column); |
48 |
|
49 |
push @{$self->{rlcolumns}}, my $column = |
50 |
Gtk2::TreeViewColumn->new_with_attributes ("Owner", $gtk::text_renderer, text => 3); |
51 |
$column->set_sort_column_id(3); |
52 |
$column->set(resizable => 1); |
53 |
$column->set(sizing => 'fixed'); |
54 |
gtk::state $column, "gamelist::model::Owner", undef, column_size => 100; |
55 |
$view->append_column ($column); |
56 |
|
57 |
push @{$self->{rlcolumns}}, my $column = |
58 |
Gtk2::TreeViewColumn->new_with_attributes ("Rk", $gtk::text_renderer, text => 4); |
59 |
$column->set_sort_column_id(5); |
60 |
$column->set(sizing => 'grow-only'); |
61 |
$view->append_column ($column); |
62 |
} |
63 |
|
64 |
push @{$self->{rlcolumns}}, my $column = |
65 |
Gtk2::TreeViewColumn->new_with_attributes ("Info", $gtk::text_renderer, text => 6); |
66 |
$column->set(resizable => 1); |
67 |
$column->set(sizing => 'autosize'); |
68 |
gtk::state $column, "gamelist::model::Info", undef, column_size => 80; |
69 |
$self->{view1}->append_column ($column); |
70 |
|
71 |
push @{$self->{rlcolumns}}, my $column = |
72 |
Gtk2::TreeViewColumn->new_with_attributes ("Notes", $gtk::text_renderer, text => 7); |
73 |
$column->set(resizable => 1); |
74 |
$column->set(sizing => 'autosize'); |
75 |
gtk::state $column, "gamelist::model::Notes", undef, column_size => 200; |
76 |
$self->{view1}->append_column ($column); |
77 |
|
78 |
########### |
79 |
|
80 |
push @{$self->{rlcolumns}}, my $column = |
81 |
Gtk2::TreeViewColumn->new_with_attributes ("Opponent", $gtk::text_renderer, text => 6); |
82 |
$column->set(resizable => 1); |
83 |
$column->set(sizing => 'fixed'); |
84 |
gtk::state $column, "gamelist::model::Opponent", undef, column_size => 120; |
85 |
$self->{view2}->append_column ($column); |
86 |
|
87 |
push @{$self->{rlcolumns}}, my $column = |
88 |
Gtk2::TreeViewColumn->new_with_attributes ("Rk", $gtk::text_renderer, text => 7); |
89 |
$column->set_sort_column_id(8); |
90 |
$column->set(sizing => 'grow-only'); |
91 |
$self->{view2}->append_column ($column); |
92 |
|
93 |
push @{$self->{rlcolumns}}, my $column = |
94 |
Gtk2::TreeViewColumn->new_with_attributes ("Mv", $gtk::int_renderer, text => 9); |
95 |
$column->set_sort_column_id(9); |
96 |
$column->set(sizing => 'grow-only'); |
97 |
$self->{view2}->append_column ($column); |
98 |
|
99 |
push @{$self->{rlcolumns}}, my $column = |
100 |
Gtk2::TreeViewColumn->new_with_attributes ("Ob", $gtk::int_renderer, text => 10); |
101 |
$column->set_sort_column_id(10); |
102 |
$column->set(sizing => 'grow-only'); |
103 |
$self->{view2}->append_column ($column); |
104 |
|
105 |
push @{$self->{rlcolumns}}, my $column = |
106 |
Gtk2::TreeViewColumn->new_with_attributes ("Info", $gtk::text_renderer, text => 11); |
107 |
$column->set(resizable => 1); |
108 |
$column->set(sizing => 'autosize'); |
109 |
gtk::state $column, "gamelist::model::Info", undef, column_size => 120; |
110 |
$self->{view2}->append_column ($column); |
111 |
|
112 |
########### |
113 |
|
114 |
$self->{view1}->signal_connect(row_activated => sub { |
115 |
my ($widget, $path, $column) = @_; |
116 |
my $game = $self->{model1}->get ($self->{model1}->get_iter ($path), 0); |
117 |
($self->{game}{$game->{channel}} ||= new game %$game, conn => $self->{conn}) |
118 |
->join; |
119 |
1; |
120 |
}); |
121 |
|
122 |
$self->{view2}->signal_connect(row_activated => sub { |
123 |
my ($widget, $path, $column) = @_; |
124 |
my $game = $self->{model2}->get ($self->{model2}->get_iter ($path), 0); |
125 |
($self->{game}{$game->{channel}} ||= new game %$game, conn => $self->{conn}) |
126 |
->join; |
127 |
1; |
128 |
}); |
129 |
|
130 |
$self; |
131 |
} |
132 |
|
133 |
sub update { |
134 |
my ($self, $room, $add, $update, $remove) = @_; |
135 |
|
136 |
$self->{games}{$room->{name}} = $room->{games}; |
137 |
|
138 |
my $m1 = $self->{model1}; |
139 |
my $m2 = $self->{model2}; |
140 |
|
141 |
for (@$remove) { |
142 |
(delete $_->{model})->remove (delete $_->{iter}) if $_->{model}; |
143 |
} |
144 |
|
145 |
for (@$add, @$update) { |
146 |
my $owner = $_->owner; |
147 |
if ($_->is_valid) { |
148 |
(delete $_->{model})->remove (delete $_->{iter}) if $_->{model} && $_->{model} != $m2; |
149 |
$_->{model} = $m2; |
150 |
$m2->set ($_->{iter} ||= $m2->append, |
151 |
0, $_, |
152 |
1, $room->{name}, |
153 |
2, (uc substr $gametype{$_->type}, 0, 1),#d# should use ->gametype_char, which also does P, S |
154 |
3, $owner->{name}, |
155 |
4, $owner->rank_string, |
156 |
5, $owner->rank, |
157 |
6, $_->opponent_string, |
158 |
7, $_->{user1}->rank_string, |
159 |
8, $_->{user1}->rank, |
160 |
9, $_->moves, |
161 |
10, $_->{observers}, |
162 |
11, $_->rules, |
163 |
); |
164 |
} else { |
165 |
(delete $_->{model})->remove (delete $_->{iter}) if $_->{model} && $_->{model} != $m1; |
166 |
$_->{model} = $m1; |
167 |
$m1->set ($_->{iter} ||= $m1->append, |
168 |
0, $_, |
169 |
1, $room->{name}, |
170 |
2, (uc substr $gametype{$_->type}, 0, 1),#d# should use ->gametype_char, which also does P, S |
171 |
3, $owner->{name}, |
172 |
4, $owner->rank_string, |
173 |
5, $owner->rank, |
174 |
6, $_->rules, |
175 |
7, $_->{notes}, |
176 |
); |
177 |
} |
178 |
} |
179 |
} |
180 |
|
181 |
1; |
182 |
|