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