#include #include #include #include #include #include #include using namespace std; using namespace Wt; class WorkingClass : public Wt::WResource { public: WorkingClass() : workDialog(nullptr), customMessage(nullptr), workingTimer(nullptr) { if (!workDialog) { workDialog = make_unique("Working dialog ..."); customMessage = workDialog->contents()->addWidget(make_unique()); customMessage->setMargin(30, Side::Top | Side::Left); customMessage->setText(""); workDialog->setTitleBarEnabled(true); workDialog->setModal(true); workDialog->setResizable(false); workDialog->setClosable(false); workDialog->setHidden(true); } workingTimer = make_unique(); workingTimer->timeout().connect(this, &WorkingClass::workFinished); workingTimer->setInterval(chrono::seconds(5)); } Signal<> doneSignal; void ShowDialog(std::string const& msg) { if (workDialog) { customMessage->setText(msg); workDialog->setHidden(false); } } void CloseDialog(void) { if (workDialog) workDialog->setHidden(true); } void DoingWork(void) { workingTimer->start(); } void handleRequest(Wt::Http::Request const &request, Wt::Http::Response &response) { } private: unique_ptr workDialog; unique_ptr workingTimer; WText* customMessage; void workFinished(void) { doneSignal.emit(); } }; class TestApplication : public WApplication { public: TestApplication(const WEnvironment& env) : WApplication(env), workingObject(nullptr), someText(nullptr) { setTheme(std::make_shared()); root()->addNew(); root()->addNew(); someText = root()->addNew("Push the button to get the working class working..."); someText->setMargin(30, Side::Top | Side::Left); root()->addNew(); root()->addNew(); auto workBtn = root()->addNew("Push me for work."); workBtn->setMargin(60, Side::Left); workBtn->clicked().connect(this, &TestApplication::performWork); } private: unique_ptr workingObject; WText* someText; void performWork() { if (!workingObject) { workingObject = make_unique(); workingObject->doneSignal.connect(this, &TestApplication::doneWork); } workingObject->ShowDialog("my message for working time"); someText->setText("now performing the hard work..."); workingObject->DoingWork(); } void doneWork() { someText->setText("hard work finished. Push the button again to get the working class working..."); if (workingObject) workingObject->CloseDialog(); } }; int main(int argc, char **argv) { return WRun(argc, argv, [](const WEnvironment& env) { return make_unique(env); }); }