From 66136b7dfa06a150089fdddd0705aef60aeada4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sat, 21 Sep 2019 07:56:19 +0800 Subject: User show slot result gets checked first by controller and only if the result is not null, implying the login is successful, then it will do a ticket search based on the logged in user's name. --- LoginPassword.qml | 9 ++------- Onboarding.qml | 1 - controller.cxx | 43 +++++++++++++++++++++++++++++-------------- controller.hxx | 9 +++++++++ qrtclient | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/LoginPassword.qml b/LoginPassword.qml index 8b65a11..d2e8064 100644 --- a/LoginPassword.qml +++ b/LoginPassword.qml @@ -4,20 +4,15 @@ import "larva/features" LoginPasswordForm { emailTextLabel.text: User.name - - passwordTextField.onTextChanged: { + passwordTextField.onTextChanged: if (!passwordTextField.text || !continueButton.enabled) continueButton.enabled = !continueButton.enabled - } continueButton { icon.source: "assets/arrow-forward-24px.svg" onClicked: { User.password = passwordTextField.text - onClicked: { - onboarding.logIn(User.name, User.password) - onboarding.ticketSearch(User.name) - } + onboarding.logIn(User.name, User.password) } } } diff --git a/Onboarding.qml b/Onboarding.qml index f66f491..9e54625 100644 --- a/Onboarding.qml +++ b/Onboarding.qml @@ -4,7 +4,6 @@ import "larva/features" OnboardingForm { signal logIn(string name, string password) signal ticketNew(string queue, string requestor) - signal ticketSearch(string name) function pushHome() { pageView.push("Home.qml") } diff --git a/controller.cxx b/controller.cxx index 8e832b7..5ffe31f 100644 --- a/controller.cxx +++ b/controller.cxx @@ -13,38 +13,53 @@ Controller::Controller(QObject* parent) : QObject{parent} auto engine = static_cast(parent); auto rootObjects = engine->rootObjects(); auto appWindow = rootObjects[0]; - auto onboardingView = appWindow->findChild("onboarding"); - connect(onboardingView, SIGNAL(logIn(QString, QString)) - , client, SLOT(logIn(QString, QString))); - connect(client, SIGNAL(loggedIn(QString)) - , client, SLOT(userShow(QString))); - connect(onboardingView, SIGNAL(ticketNew(QString, QString)) - , client, SLOT(ticketNew(QString, QString))); - connect(onboardingView, SIGNAL(ticketSearch(QString)) - , client, SLOT(ticketSearch(QString))); - using RTClient::User; auto typeId = qmlRegisterSingletonType("KelakonUser", 0, 1, "User" - , [](QQmlEngine *engine, - QJSEngine *scriptEngine) -> QObject* { + , [](QQmlEngine *engine + , QJSEngine *scriptEngine) -> QObject* { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new User; }); auto user = engine->singletonInstance(typeId); + taskList = new RTClient::TicketList; + engine->rootContext()->setContextProperty("taskList", taskList); + + connect(onboardingView, SIGNAL(logIn(QString, QString)) + , client, SLOT(logIn(QString, QString))); + + connect(client, SIGNAL(loggedIn(QString)) + , client, SLOT(userShow(QString))); + connect(client, SIGNAL(userShown(rtclient_user*)) + , this, SLOT(check(rtclient_user*))); + + connect(this, SIGNAL(checked(rtclient_user*)) , user, SLOT(update(rtclient_user*))); - taskList = new RTClient::TicketList; - engine->rootContext()->setContextProperty("taskList", taskList); + connect(this, SIGNAL(checked(QString)) + , client, SLOT(ticketSearch(QString))); + connect(client, SIGNAL(ticketSearched(rtclient_ticketlist*)) , taskList, SLOT(update(rtclient_ticketlist*))); + + connect(onboardingView, SIGNAL(ticketNew(QString, QString)) + , client, SLOT(ticketNew(QString, QString))); + connect(taskList, SIGNAL(updated()), onboardingView, SLOT(pushHome())); thread.start(); } +void Controller::check(rtclient_user* user) +{ + if (user) { + emit checked(QString{user->name}); + emit checked(user); + } +} + Controller::~Controller() { thread.quit(); diff --git a/controller.hxx b/controller.hxx index dcfdb7c..8eb4017 100644 --- a/controller.hxx +++ b/controller.hxx @@ -4,6 +4,8 @@ #include #include +struct rtclient_user; + class Controller : public QObject { Q_OBJECT @@ -12,6 +14,13 @@ class Controller : public QObject Controller(QObject* parent = nullptr); ~Controller(); + signals: + void checked(rtclient_user* user); + void checked(QString const& name); + + private slots: + void check(rtclient_user* user); + private: QThread thread; RTClient::TicketList* taskList; diff --git a/qrtclient b/qrtclient index c45c7b8..6aba477 160000 --- a/qrtclient +++ b/qrtclient @@ -1 +1 @@ -Subproject commit c45c7b8eae9ade41b6c9bfa02a4b7d6ff329e860 +Subproject commit 6aba4774d836194e913e56c0c85fa30407d0e5cb -- cgit v1.2.3