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