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