-
Notifications
You must be signed in to change notification settings - Fork 6
/
view.cpp
91 lines (69 loc) · 2.86 KB
/
view.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "view.h"
#include <Wt/WLength>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WPanel>
#include <Wt/WTextEdit>
#include <Wt/WLabel>
#include <Wt/WMessageBox>
#include <Wt/WApplication>
#include <Wt/WOverlayLoadingIndicator>
#include "util.h"
View::View(const Wt::WEnvironment& env, std::shared_ptr<Wt::WServer> /*server*/, std::shared_ptr<AbstractRPM> rpm) :
Wt::WApplication(env), rpm(rpm)
{
Wt::WString welcomeMsg = "Welcome to the Remote Power Manager (RPM)";
this->enableUpdates(true);
this->setLoadingIndicator(new Wt::WOverlayLoadingIndicator());
this->styleSheet().addRule("body", "background-color: #eeeeee;");
this->styleSheet().addRule(".computer", "background-color: #e0e0e0; border-style:solid; border-width: 2px; -moz-border-radius: 15px; border-radius: 15px;");
/* Application root fixup */
std::cerr << "Application root = '" << Wt::WApplication::appRoot()
<< "' and doc root = '" << Wt::WApplication::docRoot()
<< "'" << std::endl;
/* Set the title */
setTitle(welcomeMsg);
Wt::WContainerWidget *w = new Wt::WContainerWidget(root());
Wt::WBoxLayout *verticalLayout = new Wt::WBoxLayout(Wt::WBoxLayout::TopToBottom);
Wt::WText *title = new Wt::WText(welcomeMsg);
title->setStyleClass("WelcomeMsg");
this->styleSheet().addRule(".WelcomeMsg", "font-size: 36px; text-transform: capitalize;");
verticalLayout->addWidget(title, 0, Wt::AlignCenter);
verticalLayout->addSpacing(50);
_horizontalLayout = new Wt::WBoxLayout(Wt::WBoxLayout::LeftToRight);
verticalLayout->addLayout(_horizontalLayout, 0, Wt::AlignCenter);
verticalLayout->addSpacing(50);
Wt::WLabel *label = new Wt::WLabel("Copyrights 2013 - mupuf.org - This website has been created by mupuf.org developers and is released under a permissive license.");
verticalLayout->addWidget(label, 0, Wt::AlignCenter);
w->setLayout(verticalLayout);
}
void View::addComputer(const Wt::WString &computerName, std::shared_ptr<ComputerView> view)
{
_computers[computerName] = view;
view->setStyleClass("computer");
view->setMinimumSize(500, 150);
view->powerLedStatusChanged(rpm->powerLedState(computerName));
_horizontalLayout->addWidget(view.get());
}
std::shared_ptr<ComputerView> View::getComputer(const Wt::WString &computerName)
{
return _computers[computerName];
}
void View::powerLedStatusChanged(const Wt::WString &computerName, bool status)
{
std::shared_ptr<ComputerView> cview = getComputer(computerName);
cview->powerLedStatusChanged(status);
}
void View::consoleDataAdded(const Wt::WString &computerName, const Wt::WString &data)
{
std::shared_ptr<ComputerView> cview = getComputer(computerName);
cview->consoleDataAdded(data);
}
void View::setPingDelay(const Wt::WString &computerName, double delay)
{
std::shared_ptr<ComputerView> cview = getComputer(computerName);
cview->setPingDelay(delay);
}