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 ("Type", $gtk::text_renderer, text => 2); |
41 |
$column->set_sort_column_id(2); |
42 |
$column->set(resizable => 1); |
43 |
$column->set(sizing => 'fixed'); |
44 |
gtk::state $column, "gamelist::model::Type", undef, column_size => 20; |
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(resizable => 1); |
59 |
$column->set(sizing => 'fixed'); |
60 |
gtk::state $column, "gamelist::model::Rk", undef, column_size => 20; |
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 => 'fixed'); |
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 => 'fixed'); |
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(resizable => 1); |
91 |
$column->set(sizing => 'fixed'); |
92 |
gtk::state $column, "gamelist::model::Rk", undef, column_size => 20; |
93 |
$self->{view2}->append_column ($column); |
94 |
|
95 |
push @{$self->{rlcolumns}}, my $column = |
96 |
Gtk2::TreeViewColumn->new_with_attributes ("Mv", $gtk::int_renderer, text => 9); |
97 |
$column->set_sort_column_id(7); |
98 |
$column->set(resizable => 1); |
99 |
$column->set(sizing => 'fixed'); |
100 |
gtk::state $column, "gamelist::model::Mv", undef, column_size => 40; |
101 |
$self->{view2}->append_column ($column); |
102 |
|
103 |
push @{$self->{rlcolumns}}, my $column = |
104 |
Gtk2::TreeViewColumn->new_with_attributes ("Ob", $gtk::int_renderer, text => 10); |
105 |
$column->set_sort_column_id(8); |
106 |
$column->set(resizable => 1); |
107 |
$column->set(sizing => 'fixed'); |
108 |
gtk::state $column, "gamelist::model::Ob", undef, column_size => 40; |
109 |
$self->{view2}->append_column ($column); |
110 |
|
111 |
push @{$self->{rlcolumns}}, my $column = |
112 |
Gtk2::TreeViewColumn->new_with_attributes ("Info", $gtk::text_renderer, text => 11); |
113 |
$column->set(resizable => 1); |
114 |
$column->set(sizing => 'fixed'); |
115 |
gtk::state $column, "gamelist::model::Info", undef, column_size => 120; |
116 |
$self->{view2}->append_column ($column); |
117 |
|
118 |
########### |
119 |
|
120 |
$self->{view1}->signal_connect(row_activated => sub { |
121 |
my ($widget, $path, $column) = @_; |
122 |
my $game = $self->{model1}->get ($self->{model1}->get_iter ($path), 0); |
123 |
($self->{game}{$game->{channel}} ||= new game %$game, conn => $self->{conn}) |
124 |
->join; |
125 |
}); |
126 |
|
127 |
$self->{view2}->signal_connect(row_activated => sub { |
128 |
my ($widget, $path, $column) = @_; |
129 |
my $game = $self->{model2}->get ($self->{model2}->get_iter ($path), 0); |
130 |
($self->{game}{$game->{channel}} ||= new game %$game, conn => $self->{conn}) |
131 |
->join; |
132 |
}); |
133 |
|
134 |
$self; |
135 |
} |
136 |
|
137 |
sub update { |
138 |
my ($self, $room) = @_; |
139 |
|
140 |
$self->{games}{$room->{name}} = $room->{games}; |
141 |
|
142 |
$self->{event_update} ||= add Glib::Timeout 300, sub { |
143 |
my $m1 = $self->{model1}; |
144 |
my $m2 = $self->{model2}; |
145 |
|
146 |
$m1->clear; |
147 |
$m2->clear; |
148 |
|
149 |
while (my ($room, $games) = each %{$self->{games}}) { |
150 |
for (values %$games) { |
151 |
my $owner = $_->owner; |
152 |
if (exists $_->{notes}) { |
153 |
$m1->set ($m1->append, |
154 |
0, $_, |
155 |
1, $room, |
156 |
2, $_->type, |
157 |
3, $owner->{name}, |
158 |
4, $owner->rank_string, |
159 |
5, $owner->rank, |
160 |
6, "info", |
161 |
7, $_->{notes}, |
162 |
); |
163 |
} else { |
164 |
$m2->set ($m2->append, |
165 |
0, $_, |
166 |
1, $room, |
167 |
2, $_->type, |
168 |
3, $owner->{name}, |
169 |
4, $owner->rank_string, |
170 |
5, $owner->rank, |
171 |
6, $_->{user1}->{name}, |
172 |
7, $_->{user1}->rank_string, |
173 |
8, $_->{user1}->rank, |
174 |
9, $_->moves, |
175 |
10, $_->{observers}, |
176 |
11, "info", |
177 |
); |
178 |
} |
179 |
} |
180 |
} |
181 |
|
182 |
delete $self->{event_update}; |
183 |
0; |
184 |
}; |
185 |
} |
186 |
|
187 |
1; |
188 |
|