-
Notifications
You must be signed in to change notification settings - Fork 1
/
laka_engine.C
executable file
·123 lines (96 loc) · 2.9 KB
/
laka_engine.C
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**************************************************************
Purpose : main app file of Laka Engine
Author : Gauravjeet Singh, Inderpreet Singh, Shaina Sabarwal
License : GNU GPL V3
***************************************************************/
#include "laka_engine.h"
#include "admin/setting_pannel.h"
#include "add_theme.h"
#include <Wt/WLink>
#include <Wt/WStackedWidget>
string mainTemplate;
LakaEngine::LakaEngine(const WEnvironment &env)
:WApplication(env)
{
useStyleSheet("themes/yanni/style.css");
applySettings();
cout<<"__________title_______"<<titleString<<endl;
cout<<"_________tagline______"<<taglineString<<endl;
if(titleString == "")
titleString = "Lakaness";
if(taglineString == "")
taglineString="Give a height to your thoughts";
setTitle(titleString);
useStyleSheet("resources/default.css");
clicked = false;
container = new WContainerWidget(root());
container->setStyleClass("container");
headerContainer = new WContainerWidget();
authForm = new AuthForm(headerContainer);
postLoop = new PostLoop(container);
headerPanel = new WPanel(root());
headerPanel->setTitle("Login/Sign up");
headerPanel->setCentralWidget(headerContainer);
headerPanel->setCollapsible(true);
headerPanel->setCollapsed(false);
WAnimation animation(WAnimation::SlideInFromTop, WAnimation::EaseOut, 100);
headerPanel->setAnimation(animation);
main = new WTemplate(root());
main->setTemplateText(mainTemplate);
main->bindString("tagline", taglineString);
main->bindString("title", titleString);
main->bindWidget("postloop", postLoop);
internalPathChanged().connect(this, &LakaEngine::handlePathChange);
handlePathChange();
}
void LakaEngine::applySettings()
{
try{
{
dbo::Transaction t(session_);
dbo::ptr<User> userPtr = session_.find<User>().where("name = ?").bind("admin");
titleString = userPtr->title;
taglineString=userPtr->tagline;
t.commit();
}
}
catch(exception& e)
{
cout<<"Register first";
}
}
void LakaEngine::handlePathChange()
{
std::string path = internalPath();
if(path == "/")
{
container->clear();
postLoop = new PostLoop(container);
main->bindWidget("postloop", postLoop);
}
else
{
postLoop->handlePath();
}
}
WApplication *createApplication(const WEnvironment &env)
{
return new LakaEngine(env);
}
int main(int argc, char **argv)
{
try{
Wt::WServer server(argv[0]);
server.setServerConfiguration(argc,argv, WTHTTP_CONFIGURATION);
server.addEntryPoint(Wt::Application, createApplication);
Session::configureAuth();
if(server.start()){
Wt::WServer::waitForShutdown();
server.stop();
}
} catch (Wt::WServer::Exception& e) {
std::cerr << e.what() << std::endl;
} catch (std::exception &e) {
std::cerr<< "exception" << e.what() <<std::endl;
}
}