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