]> git.tdb.fi Git - r2c2.git/blob - remote.cpp
e5384777bf49ffaf5f52b21196483361e5088186
[r2c2.git] / remote.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2009-2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <gtkmm/scrolledwindow.h>
9 #include <gtkmm/separator.h>
10 #include <msp/net/resolve.h>
11 #include <msp/time/units.h>
12 #include "mainpanel.h"
13 #include "remote.h"
14 #include "trainpanel.h"
15
16 using namespace std;
17 using namespace Msp;
18
19 Application::RegApp<Remote> Remote::reg;
20
21 Remote::Remote(int argc, char **argv):
22         client(catalogue),
23         gtk(argc, argv)
24 {
25         if(argc<2)
26                 throw UsageError("No address given");
27
28         DataFile::load(catalogue, "locos.dat");
29
30         client.use_event_dispatcher(event_disp);
31         client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added));
32         string addr_str = argv[1];
33         if(addr_str.find(':')==string::npos)
34                 addr_str += ":8315";
35         Net::SockAddr *addr = Net::resolve(addr_str);
36         client.connect(*addr);
37         delete addr;
38
39         window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0));
40         window.set_default_size(300, 200);
41         window.set_border_width(5);
42
43         Gtk::ScrolledWindow *scroll = new Gtk::ScrolledWindow;
44         window.add(*manage(scroll));
45         scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
46
47         panel_box = new Gtk::VBox(false, 5);
48         scroll->add(*manage(panel_box));
49
50         main_panel = new MainPanel(*this, client);
51         panel_box->pack_start(*manage(main_panel), false, true);
52
53         window.show_all();
54 }
55
56 void Remote::tick()
57 {
58         event_disp.tick(Time::zero);
59         gtk.iteration(false);
60 }
61
62 void Remote::train_added(R2C2::NetTrain &t)
63 {
64         Gtk::HSeparator *sep = new Gtk::HSeparator;
65         panel_box->pack_start(*manage(sep), false, true);
66         sep->show();
67
68         TrainPanel *panel = new TrainPanel(*this, client, t);
69         panel_box->pack_start(*manage(panel), false, true);
70         train_panels.push_back(panel);
71 }