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

« back to all changes in this revision

Viewing changes to ricochet-0.1/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;
51
 
                *Button::button_t       master_connect;
52
 
                *Textline::textline_t   hostname;
53
 
                *Button::button_t       remote_connect;
54
 
                *Button::button_t       local;
55
 
                *Button::button_t       local_connect;
56
 
                *Button::button_t       cancel;
57
 
 
58
 
                bool    ret;
59
 
 
60
 
                void stop (bool val) {
61
 
                        ret = val;
62
 
                        Nichrome::destroy(ui);
63
 
                }
64
 
 
65
 
                void do_ok(*widget_t w, bool state) {
66
 
                        if (state) {
67
 
                                host = hostname->text;
68
 
                                stop(true);
69
 
                        }
70
 
                }
71
 
 
72
 
                void do_cancel(*widget_t w, bool state) {
73
 
                        if (state) {
74
 
                                if (is_uninit(&host))
75
 
                                        exit(0);
76
 
                                stop(false);
77
 
                        }
78
 
                }
79
 
 
80
 
                bool key_callback(*Textline::textline_t widget, string key) {
81
 
                        switch (key) {
82
 
                        case "Return": do_ok(widget, true); return true;
83
 
                        default:
84
 
                        }
85
 
                        return false;
86
 
                }
87
 
                
88
 
                string master_host = "rr.nickle.org";
89
 
 
90
 
                void do_master(*Button::button_t w, bool state) {
91
 
                        if (state) {
92
 
                                host = master_host;
93
 
                                stop(true);
94
 
                        }
95
 
                }
96
 
 
97
 
                void do_remote(*Button::button_t w, bool state) {
98
 
                        if (state) {
99
 
                                host = hostname->text;
100
 
                                stop(true);
101
 
                        }
102
 
                }
103
 
 
104
 
 
105
 
                void do_local(*Button::button_t w, bool state) {
106
 
                        if (state) {
107
 
                                host = "localhost";
108
 
                                stop(true);
109
 
                        }
110
 
                }
111
 
 
112
 
                void do_start_local(*Button::button_t w, bool state) {
113
 
                        if (state) {
114
 
                                Process::system(rrserve_path, "rrserve");
115
 
                        }
116
 
                }
117
 
 
118
 
                public bool select() {
119
 
                        ui = new("Ricochet Robots Servers", 100, 100);
120
 
                        title = new_bold(ui, "Select Server", Label::justify_t.center);
121
 
 
122
 
                        master = new_left(ui, master_host);
123
 
                        master_connect = Button::new(ui, "Connect", do_master);
124
 
 
125
 
                        hostname = Textline::new(ui, 40);
126
 
                        hostname->callback = key_callback;
127
 
                        if (!is_uninit(&host))
128
 
                                Textline::set_text(hostname, host);
129
 
                        remote_connect = Button::new(ui, "Connect", do_remote);
130
 
 
131
 
                        local = Button::new(ui, "Start local server", do_start_local);
132
 
                        local_connect = Button::new(ui, "Connect", do_local);
133
 
 
134
 
                        cancel = Button::new(ui, "Cancel", do_cancel);
135
 
                        *Box::box_t     box = Box::new(Box::dir_t.vertical,
136
 
                                                       Box::widget_item(title, 1, 0),
137
 
                                                       Box::box_item(Box::new(Box::dir_t.horizontal,
138
 
                                                                              Box::widget_item(master, 1, 0),
139
 
                                                                              Box::widget_item(master_connect))),
140
 
                                                       Box::box_item(Box::new(Box::dir_t.horizontal,
141
 
                                                                              Box::widget_item(hostname, 1, 0),
142
 
                                                                              Box::widget_item(remote_connect))),
143
 
                                                       Box::box_item(Box::new(Box::dir_t.horizontal,
144
 
                                                                              Box::widget_item(local, 1, 0),
145
 
                                                                              Box::widget_item(local_connect))),
146
 
                                                       Box::box_item(Box::new(Box::dir_t.horizontal,
147
 
                                                                              Box::glue_item(1),
148
 
                                                                              Box::widget_item(cancel, 0, 0),
149
 
                                                                              Box::glue_item(1))),
150
 
                                                       Box::glue_item(1));
151
 
                        Nichrome::set_box(ui, box);
152
 
                        set_key_focus(ui, hostname);
153
 
                        Nichrome::main_loop(ui);
154
 
                        return ret;
155
 
                }
156
 
        }
157
 
}