/
skunk_test.cpp
79 lines (59 loc) · 1.69 KB
/
skunk_test.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
#include "Skunk.hpp"
#include <string>
#include <vector>
/**
* @file skunk_test.cpp
* */
/**
* Klasa dziedziczaca po TextField, umozliwia odczytywanie i ustawianie nowej
* wartosci pola tesktowego
* */
class PoleTekstowe : public Skunk::TextField {
std::string wartosc_;
public:
PoleTekstowe(std::string w) : wartosc_(w) { }
virtual std::string getValue() { /// odczytuje wartosc pola tekstowego
return wartosc_;
}
virtual void setValue(std::string& neu) { /// nadaje nowa wartosc polu tekstowemu
wartosc_ = neu;
}
};
/**
* Klasa umozliwiajaca nadawanie polu typu radio nowych wartosci
* */
class PoleRadiowe : public Skunk::RadioButton {
public:
virtual void setValue(int neu) { /// nadaje nowa wartosc polu typu radio
index = neu;
}
};
/**
* Klasa naglowka
* */
class WielkiNapis : public Skunk::Widget {
virtual std::string GET() {
return "<h1><b>TIN HTTP APP</b></h1>";
}
virtual void POST(std::string&) { }
};
/**
* Main - tworzy nowy server z dostepnymi widgetami i uruchamia go
* */
int main(void) {
Skunk::Server *srv = new Skunk::Server();
srv->addWidget(new WielkiNapis());
srv->addWidget(new PoleTekstowe("text1"));
srv->addWidget(new PoleTekstowe("text2"));
PoleRadiowe *pr = new PoleRadiowe();
srv->addWidget(pr);
pr->setTitle("Preferencje");
pr->addChoice("Opcja1");
pr->addChoice("Opcja2");
pr->addChoice("Opcja3");
Skunk::SimpleAuth *auth = new Skunk::SimpleAuth();
auth->addUser("admin", "admin.8");
auth->addUser("user", "user.8");
srv->setAuth(auth);
srv->run();
}