#ifdef ANDROID #include #endif #include #include #include #include #include "controller.hxx" Controller::Controller(QObject* parent) : QObject{parent} { #ifdef ANDROID QFile file{"assets:/certs/ca-certificates.crt"}; file.copy(QDir{QStandardPaths::writableLocation (QStandardPaths::AppDataLocation)}.absolutePath() % "/ca-certificates.crt"); auto path = QDir{QStandardPaths::writableLocation (QStandardPaths::AppDataLocation)}.absolutePath() % "/ca-certificates.crt"; auto client = new RTClient::Client{"https://darapsa.co.id/rt" , path.toLatin1().constData()}; #else auto client = new RTClient::Client{"https://darapsa.co.id/rt"}; #endif client->moveToThread(&thread); connect(&thread, &QThread::finished, client, &QObject::deleteLater); auto engine = static_cast(parent); auto rootObjects = engine->rootObjects(); auto appWindow = rootObjects[0]; auto onboardingView = appWindow->findChild("onboarding"); using RTClient::User; auto typeId = qmlRegisterSingletonType("KelakonUser", 0, 1, "User" , [](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*))); connect(this, SIGNAL(checked(QString)) , client, SLOT(ticketSearch(QString))); connect(client, SIGNAL(ticketSearched(rtclient_ticketlist*)) , taskList, SLOT(update(rtclient_ticketlist*))); connect(taskList, SIGNAL(updated()), onboardingView, SLOT(pushHome())); connect(onboardingView, SIGNAL(ticketNew(QString, QString)) , client, SLOT(ticketNew(QString, QString))); thread.start(); } void Controller::check(rtclient_user* user) { if (user) { emit checked(QString{user->name}); emit checked(user); } } Controller::~Controller() { thread.quit(); thread.wait(); delete taskList; }