~ubuntu-branches/ubuntu/saucy/ricochet/saucy

« back to all changes in this revision

Viewing changes to ricochet-0.2/debian/ricochet/usr/share/ricochet/client-host.5c

  • Committer: Package Import Robot
  • Author(s): Keith Packard
  • Date: 2012-06-11 13:37:57 UTC
  • Revision ID: package-import@ubuntu.com-20120611133757-zn0ukd22vz56ymto
Tags: 0.3
* Improve appearance of board
* Fix user list when removing/adding same user

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 Keith Packard <keithp@keithp.com>
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; version 2 of the License.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16
 
 */
17
 
 
18
 
autoload Client;
19
 
autoload Client::Window;
20
 
autoload Client::Link;
21
 
autoload Client::Update;
22
 
autoload Client::Userlist;
23
 
autoload Client::Messages;
24
 
autoload Client::Games;
25
 
autoload ParseArgs;
26
 
autoload RR;
27
 
autoload Cairo;
28
 
autoload Nichrome;
29
 
autoload Nichrome::Button;
30
 
autoload Nichrome::Box;
31
 
autoload Nichrome::Label;
32
 
autoload Nichrome::Toggle;
33
 
autoload Nichrome::Textline;
34
 
autoload Nichrome::RRboard;
35
 
autoload Nichrome::Solid;
36
 
autoload Mutex;
37
 
autoload Process;
38
 
 
39
 
extend namespace Client {
40
 
        public namespace Host {
41
 
                import Nichrome;
42
 
                import Util;
43
 
                import Box;
44
 
 
45
 
                public string   host;
46
 
                public string   rrserve_path = "rrserve";
47
 
 
48
 
                *Nichrome::nichrome_t   ui;
49
 
                *Label::label_t         title;
50
 
                *Label::label_t         master_label;
51
 
                *Label::label_t         master;
52
 
                *Button::button_t       master_connect;
53
 
                *Label::label_t         remote_label;
54
 
                *Textline::textline_t   hostname;
55
 
                *Button::button_t       remote_connect;
56
 
                *Label::label_t         local_label;
57
 
                *Button::button_t       local;
58
 
                *Button::button_t       local_connect;
59
 
                *Button::button_t       cancel;
60
 
 
61
 
                bool    ret;
62
 
 
63
 
                void stop (bool val) {
64
 
                        ret = val;
65
 
                        Nichrome::destroy(ui);
66
 
                }
67
 
 
68
 
                void do_ok(*widget_t w, bool state) {
69
 
                        if (state) {
70
 
                                host = hostname->text;
71
 
                                stop(true);
72
 
                        }
73
 
                }
74
 
 
75
 
                void do_cancel(*widget_t w, bool state) {
76
 
                        if (state) {
77
 
                                if (is_uninit(&host))
78
 
                                        exit(0);
79
 
                                stop(false);
80
 
                        }
81
 
                }
82
 
 
83
 
                bool key_callback(*Textline::textline_t widget, string key) {
84
 
                        switch (key) {
85
 
                        case "Return": do_ok(widget, true); return true;
86
 
                        default:
87
 
                        }
88
 
                        return false;
89
 
                }
90
 
                
91
 
                string master_host = "rr.nickle.org";
92
 
 
93
 
                void do_master(*Button::button_t w, bool state) {
94
 
                        if (state) {
95
 
                                host = master_host;
96
 
                                stop(true);
97
 
                        }
98
 
                }
99
 
 
100
 
                void do_remote(*Button::button_t w, bool state) {
101
 
                        if (state) {
102
 
                                host = hostname->text;
103
 
                                stop(true);
104
 
                        }
105
 
                }
106
 
 
107
 
 
108
 
                void do_local(*Button::button_t w, bool state) {
109
 
                        if (state) {
110
 
                                host = "localhost";
111
 
                                stop(true);
112
 
                        }
113
 
                }
114
 
 
115
 
                void do_start_local(*Button::button_t w, bool state) {
116
 
                        if (state) {
117
 
                                Process::system(rrserve_path, "rrserve");
118
 
                        }
119
 
                }
120
 
 
121
 
                public bool select() {
122
 
                        ui = new("Ricochet Robots Servers", 100, 100);
123
 
                        title = new_bold(ui, "Select Server", Label::justify_t.center);
124
 
 
125
 
                        master_label = new_left (ui, "Master server:");
126
 
                        master = new_left(ui, master_host);
127
 
                        master_connect = Button::new(ui, "Connect", do_master);
128
 
 
129
 
                        remote_label = new_left (ui, "Another server:");
130
 
                        hostname = Textline::new(ui, 40);
131
 
                        hostname->callback = key_callback;
132
 
                        if (!is_uninit(&host))
133
 
                                Textline::set_text(hostname, host);
134
 
                        remote_connect = Button::new(ui, "Connect", do_remote);
135
 
 
136
 
                        local_label = new_left (ui, "Local server:");
137
 
                        local = Button::new(ui, "Start", do_start_local);
138
 
                        local_connect = Button::new(ui, "Connect", do_local);
139
 
 
140
 
                        cancel = Button::new(ui, "Cancel", do_cancel);
141
 
                        *Box::box_t     box = Box::new_empty();
142
 
                        int row = 0;
143
 
                        Box::add_row(box, 0, row++,
144
 
                                     Box::widget_span_item(title, 4, 1, 1, 0));
145
 
                        Box::add_row(box, 0, row++,
146
 
                                     Box::widget_item(master_label, 0, 1),
147
 
                                     Box::glue_item(1),
148
 
                                     Box::widget_item(master, 1, 1),
149
 
                                     Box::widget_item(master_connect, 1, 0));
150
 
                        Box::add_row(box, 0, row++,
151
 
                                     Box::widget_item(remote_label, 0, 1),
152
 
                                     Box::glue_item(1),
153
 
                                     Box::widget_item(hostname, 1, 1),
154
 
                                     Box::widget_item(remote_connect, 1, 0));
155
 
                        Box::add_row(box, 0, row++,
156
 
                                     Box::widget_item(local_label, 0, 1),
157
 
                                     Box::glue_item(1),
158
 
                                     Box::widget_item(local, 1, 1),
159
 
                                     Box::widget_item(local_connect, 1, 0));
160
 
                        Box::add_row(box, 0, row++,
161
 
                                     Box::widget_item(cancel, 1, 0));
162
 
                        Nichrome::set_box(ui, box);
163
 
                        set_key_focus(ui, hostname);
164
 
                        Nichrome::main_loop(ui);
165
 
                        return ret;
166
 
                }
167
 
        }
168
 
}