]> git.tdb.fi Git - r2c2.git/blob - mainpanel.cpp
62c9208848fd09a661faea327acf41eeb33a8f72
[r2c2.git] / mainpanel.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include "mainpanel.h"
9
10 using namespace std;
11 using namespace R2C2;
12
13 MainPanel::MainPanel(Remote &r, R2C2::Client &c):
14         remote(r),
15         client(c)
16 {
17         client.signal_power_changed.connect(sigc::mem_fun(this, &MainPanel::power_changed));
18         client.signal_halt_changed.connect(sigc::mem_fun(this, &MainPanel::halt_changed));
19         client.signal_emergency.connect(sigc::mem_fun(this, &MainPanel::emergency));
20
21         Gtk::HBox *hbox = new Gtk::HBox(false, 5);
22         pack_start(*manage(hbox), false, true);
23
24         hbox->pack_start(*manage(chk_power = new Gtk::CheckButton("Power")), false, true);
25         chk_power->signal_toggled().connect(sigc::mem_fun(this, &MainPanel::ui_power_changed));
26
27         hbox->pack_start(*manage(chk_halt = new Gtk::CheckButton("Halt")), false, true);
28         chk_halt->signal_toggled().connect(sigc::mem_fun(this, &MainPanel::ui_power_changed));
29
30         pack_start(*manage(lbl_status = new Gtk::Label), false, true);
31
32         show_all();
33 }
34
35 void MainPanel::power_changed(bool p)
36 {
37         chk_power->set_active(p);
38 }
39
40 void MainPanel::halt_changed(bool h)
41 {
42         chk_halt->set_active(h);
43         if(!h)
44                 lbl_status->set_text(string());
45 }
46
47 void MainPanel::emergency(const string &msg)
48 {
49         lbl_status->set_text(msg);
50 }
51
52 void MainPanel::ui_power_changed()
53 {
54         client.set_power(chk_power->get_active());
55 }
56
57 void MainPanel::ui_halt_changed()
58 {
59         client.set_halt(chk_halt->get_active());
60 }