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