]> git.tdb.fi Git - r2c2.git/blob - source/remote/remote.cpp
57080c1fd0897ea86ea0527cf974a42f8b836d5d
[r2c2.git] / source / remote / remote.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/net/resolve.h>
9 #include <msp/time/units.h>
10 #include "remote.h"
11 #include "trainpanel.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 Application::RegApp<Remote> Remote::reg;
17
18 Remote::Remote(int argc, char **argv):
19         client(catalogue),
20         gtk(argc, argv)
21 {
22         if(argc<2)
23                 throw UsageError("No address given");
24
25         DataFile::load(catalogue, "locos.dat");
26
27         client.use_event_dispatcher(event_disp);
28         client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added));
29         string addr_str = argv[1];
30         if(addr_str.find(':')==string::npos)
31                 addr_str += ":8315";
32         Net::SockAddr *addr = Net::resolve(addr_str);
33         client.connect(*addr);
34         delete addr;
35
36         window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0));
37         window.set_border_width(5);
38         train_box = new Gtk::VBox(false, 5);
39         window.add(*manage(train_box));
40         window.show_all();
41 }
42
43 void Remote::tick()
44 {
45         event_disp.tick(Time::zero);
46         gtk.iteration(false);
47 }
48
49 void Remote::train_added(Marklin::NetTrain &t)
50 {
51         TrainPanel *panel = new TrainPanel(t);
52         train_box->add(*manage(panel));
53 }