]> git.tdb.fi Git - r2c2.git/blob - source/remote/remote.cpp
Some other minor UI tweaks
[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 Remote::Remote(int argc, char **argv):
14         client(catalogue),
15         gtk(argc, argv)
16 {
17         if(argc<2)
18                 throw usage_error("No address given");
19
20         DataFile::load(catalogue, "locos.dat");
21
22         client.use_event_dispatcher(event_disp);
23         client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added));
24         string addr_str = argv[1];
25         if(addr_str.find(':')==string::npos)
26                 addr_str += ":8315";
27         Net::SockAddr *addr = Net::resolve(addr_str);
28         client.connect(*addr);
29         delete addr;
30
31         window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0));
32         window.set_default_size(300, 200);
33         window.set_border_width(5);
34
35         Gtk::ScrolledWindow *scroll = new Gtk::ScrolledWindow;
36         window.add(*manage(scroll));
37         scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
38
39         panel_box = new Gtk::VBox(false, 5);
40         scroll->add(*manage(panel_box));
41
42         main_panel = new MainPanel(*this, client);
43         panel_box->pack_start(*manage(main_panel), false, true);
44
45         window.show_all();
46 }
47
48 void Remote::tick()
49 {
50         event_disp.tick(Time::zero);
51         gtk.iteration(false);
52 }
53
54 void Remote::train_added(R2C2::NetTrain &t)
55 {
56         Gtk::HSeparator *sep = new Gtk::HSeparator;
57         panel_box->pack_start(*manage(sep), false, true);
58         sep->show();
59
60         TrainPanel *panel = new TrainPanel(*this, client, t);
61         panel_box->pack_start(*manage(panel), false, true);
62         train_panels.push_back(panel);
63 }