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 |
}); |
116 |
|
117 |
$self->{view2}->signal_connect(row_activated => sub { |
118 |
my ($widget, $path, $column) = @_; |
119 |
my $game = $self->{model2}->get ($self->{model2}->get_iter ($path), 0); |
120 |
($self->{game}{$game->{channel}} ||= new game %$game, conn => $self->{conn}) |
121 |
->join; |
122 |
}); |
123 |
|
124 |
$self; |
125 |
} |
126 |
|
127 |
sub update { |
128 |
my ($self, $room) = @_; |
129 |
|
130 |
$self->{games}{$room->{name}} = $room->{games}; |
131 |
|
132 |
$self->{event_update} ||= add Glib::Timeout 300, sub { |
133 |
my $m1 = $self->{model1}; |
134 |
my $m2 = $self->{model2}; |
135 |
|
136 |
$m1->clear; |
137 |
$m2->clear; |
138 |
|
139 |
while (my ($room, $games) = each %{$self->{games}}) { |
140 |
for (values %$games) { |
141 |
my $owner = $_->owner; |
142 |
if (exists $_->{notes}) { |
143 |
$m1->set ($m1->append, |
144 |
0, $_, |
145 |
1, $room, |
146 |
2, $_->type, |
147 |
3, $owner->{name}, |
148 |
4, $owner->rank_string, |
149 |
5, $owner->rank, |
150 |
6, "info", |
151 |
7, $_->{notes}, |
152 |
); |
153 |
} else { |
154 |
$m2->set ($m2->append, |
155 |
0, $_, |
156 |
1, $room, |
157 |
2, $_->type, |
158 |
3, $owner->{name}, |
159 |
4, $owner->rank_string, |
160 |
5, $owner->rank, |
161 |
6, $_->opponent_string, |
162 |
7, $_->{user1}->rank_string, |
163 |
8, $_->{user1}->rank, |
164 |
9, $_->moves, |
165 |
10, $_->{observers}, |
166 |
11, "info", |
167 |
); |
168 |
} |
169 |
} |
170 |
} |
171 |
|
172 |
delete $self->{event_update}; |
173 |
0; |
174 |
}; |
175 |
} |
176 |
|
177 |
1; |
178 |
|