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