void Application::homeLoaded(QVariantMap &homeData) { homeModel->load(homeData); audioModel->load(homeData); favHomeModel->load(homeData); cameraModel->load(homeData); update_applicationStatus(Common::LoggedIn); favModel->load(favoritesList); saveSettings(); }
void Application::loginFailed() { if (m_applicationStatus == Common::NotConnected) return; qDebug() << "loginFailed called"; update_applicationStatus(Common::NotConnected); HardwareUtils::Instance()->showAlertMessage(tr("Login failed"), tr("Connection failed, please check your credentials."), tr("Close")); }
void Application::homeLoaded(const QVariantMap &homeData) { homeModel->load(homeData); audioModel->load(homeData); favHomeModel->load(homeData); cameraModel->load(homeData); update_applicationStatus(Common::LoggedIn); favModel->load(favoritesList); saveSettings(); if (!startedWithOptHandled) { qDebug() << "handling start options if any"; startedWithOptHandled = true; if (HardwareUtils::Instance()->hasStartedWithOption()) { //If app has been started with option, it should be a scenario (only supported action for now) QString io = HardwareUtils::Instance()->getStartOption("scenario"); qDebug() << "Start option: activate scenario: " << io; IOBase *iosc = IOCache::Instance().searchInput(io); if (!iosc) qDebug() << "Unable to start scenario " << io << " reason: not found"; else iosc->sendTrue(); //Start scenario } } //Export 4 first scenarios to hardware (for QuickLinks on iOS) //This allows iOS with 3D touch to quick start a scenario on home screen QVariantList scenariosLinks; for (int i = 0;i < scenarioSortModel->rowCount() && i < 4;i++) { IOBase *io = dynamic_cast<IOBase *>(scenarioSortModel->getItemModel(i)); QVariantMap sc = {{ "id", io->get_ioId() }, { "name", io->get_ioName() }}; scenariosLinks.append(sc); } HardwareUtils::Instance()->setQuickLinks(scenariosLinks); }
void Application::login(QString user, QString pass, QString host) { if (HardwareUtils::Instance()->getNetworkStatus() == HardwareUtils::NotConnected) { HardwareUtils::Instance()->showAlertMessage(tr("Network error"), tr("No network connection found, " "this application requires a " "network connection to work."), tr("Close")); return; } if (get_applicationStatus() != Common::NotConnected) return; update_username(user); update_password(pass); update_hostname(host); update_applicationStatus(Common::Loading); calaosConnect->login(user, pass, host); }
void Application::loginFailed() { if (m_applicationStatus == Common::NotConnected) return; qDebug() << "loginFailed called"; update_applicationStatus(Common::NotConnected); HardwareUtils::Instance()->showAlertMessage(tr("Login failed"), tr("Connection failed, please check your credentials."), tr("Close")); #ifdef CALAOS_DESKTOP //restart autologin, only on desktop to continually try to connect QTimer::singleShot(1000, [=]() { //reload settings in case it was changed loadSettings(); login(get_username(), get_password(), get_hostname()); }); #endif }
void Application::logout() { calaosConnect->logout(); update_applicationStatus(Common::NotConnected); }
Application::Application(int & argc, char ** argv) : QAPP(argc, argv) { HardwareUtils::Instance()->setParent(this); connect(HardwareUtils::Instance(), SIGNAL(networkStatusChanged()), this, SLOT(networkStatusChanged())); connect(HardwareUtils::Instance(), &HardwareUtils::applicationWillResignActive, [=]() { qDebug() << "Application is in background, logout"; startedWithOptHandled = false; logout(); }); connect(HardwareUtils::Instance(), &HardwareUtils::applicationBecomeActive, [=]() { qDebug() << "Application is in foreground, login again"; QTimer::singleShot(0, [=]() { login(get_username(), get_password(), get_hostname()); }); }); QCoreApplication::setOrganizationName("Calaos"); QCoreApplication::setOrganizationDomain("calaos.fr"); QCoreApplication::setApplicationName("CalaosHome"); Common::registerQml(); #ifdef Q_OS_ANDROID QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); QAndroidJniObject resource = activity.callObjectMethod("getResources","()Landroid/content/res/Resources;"); QAndroidJniObject metrics = resource.callObjectMethod("getDisplayMetrics","()Landroid/util/DisplayMetrics;"); update_density(metrics.getField<float>("density")); update_needBackButton(false); // Need to fix a bug on Android where text is scratched at runtime on some devices qputenv("QML_USE_GLYPHCACHE_WORKAROUND", QByteArray("1")); update_isAndroid(true); update_isIOS(false); update_isDesktop(false); #else if (arguments().contains("--force-hdpi")) update_density(2.0); else update_density(1.0); update_needBackButton(true); #ifdef Q_OS_IOS update_isAndroid(false); update_isIOS(true); update_isDesktop(false); #else update_isAndroid(false); update_isIOS(false); update_isDesktop(true); #endif #endif loadSettings(); update_applicationStatus(Common::NotConnected); calaosConnect = new CalaosConnection(this); connect(calaosConnect, SIGNAL(homeLoaded(QVariantMap)), this, SLOT(homeLoaded(QVariantMap))); connect(calaosConnect, SIGNAL(loginFailed()), this, SLOT(loginFailed())); connect(calaosConnect, &CalaosConnection::disconnected, [=]() { update_applicationStatus(Common::NotConnected); }); scenarioModel = new ScenarioModel(&engine, calaosConnect, this); scenarioSortModel = new ScenarioSortModel(&engine, this); scenarioSortModel->setSourceModel(scenarioModel); engine.rootContext()->setContextProperty("scenarioModel", scenarioSortModel); lightOnModel = new LightOnModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("lightOnModel", lightOnModel); homeModel = new HomeModel(&engine, calaosConnect, scenarioModel, lightOnModel, this); engine.rootContext()->setContextProperty("homeModel", homeModel); audioModel = new AudioModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("audioModel", audioModel); favModel = new FavoritesModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("favoritesModel", favModel); favHomeModel = new HomeFavModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("favoritesHomeModel", favHomeModel); cameraModel = new CameraModel(&engine, calaosConnect); engine.rootContext()->setContextProperty("cameraModel", cameraModel); engine.rootContext()->setContextProperty("calaosApp", this); engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); //Start autologin QTimer::singleShot(100, [=]() { login(get_username(), get_password(), get_hostname()); }); }
void Application::createQmlApp() { loadSettings(); engine.addImportPath("qrc:/qml/"); connect(HardwareUtils::Instance(), SIGNAL(networkStatusChanged()), this, SLOT(networkStatusChanged())); connect(HardwareUtils::Instance(), SIGNAL(calaosServerDetected()), this, SLOT(calaosServerDetected())); connect(HardwareUtils::Instance(), &HardwareUtils::applicationWillResignActive, [=]() { qDebug() << "Application is in background, logout"; startedWithOptHandled = false; logout(); }); connect(HardwareUtils::Instance(), &HardwareUtils::applicationBecomeActive, [=]() { qDebug() << "Application is in foreground, login again"; QTimer::singleShot(0, [=]() { login(get_username(), get_password(), get_hostname()); }); }); Common::registerQml(); #ifdef Q_OS_ANDROID QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); QAndroidJniObject resource = activity.callObjectMethod("getResources","()Landroid/content/res/Resources;"); QAndroidJniObject metrics = resource.callObjectMethod("getDisplayMetrics","()Landroid/util/DisplayMetrics;"); update_density(metrics.getField<float>("density")); update_needBackButton(false); // Need to fix a bug on Android where text is scratched at runtime on some devices qputenv("QML_USE_GLYPHCACHE_WORKAROUND", QByteArray("1")); update_isAndroid(true); update_isIOS(false); update_isDesktop(false); #else if (arguments().contains("--force-hdpi")) update_density(2.0); else update_density(1.0); update_needBackButton(true); #ifdef Q_OS_IOS update_isAndroid(false); update_isIOS(true); update_isDesktop(false); #else update_isAndroid(false); update_isIOS(false); update_isDesktop(true); #endif #endif update_applicationStatus(Common::NotConnected); calaosConnect = new CalaosConnection(this); connect(calaosConnect, SIGNAL(homeLoaded(QVariantMap)), this, SLOT(homeLoaded(QVariantMap))); connect(calaosConnect, SIGNAL(loginFailed()), this, SLOT(loginFailed())); connect(calaosConnect, &CalaosConnection::disconnected, [=]() { update_applicationStatus(Common::NotConnected); #ifdef CALAOS_DESKTOP HardwareUtils::Instance()->showAlertMessage(tr("Network error"), tr("The connection to calaos_server was lost." "It will reconnect automatically when calaos_server" "is available again."), tr("Close")); //restart autologin, only on desktop to continually try to connect QTimer::singleShot(1000, [=]() { //reload settings in case it was changed loadSettings(); login(get_username(), get_password(), get_hostname()); }); #endif }); scenarioModel = new ScenarioModel(&engine, calaosConnect, this); scenarioSortModel = new ScenarioSortModel(&engine, this); scenarioSortModel->setSourceModel(scenarioModel); engine.rootContext()->setContextProperty("scenarioModel", scenarioSortModel); lightOnModel = new LightOnModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("lightOnModel", lightOnModel); homeModel = new HomeModel(&engine, calaosConnect, scenarioModel, lightOnModel, this); engine.rootContext()->setContextProperty("homeModel", homeModel); audioModel = new AudioModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("audioModel", audioModel); favModel = new FavoritesModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("favoritesModel", favModel); favHomeModel = new HomeFavModel(&engine, calaosConnect, this); engine.rootContext()->setContextProperty("favoritesHomeModel", favHomeModel); cameraModel = new CameraModel(&engine, calaosConnect); engine.rootContext()->setContextProperty("cameraModel", cameraModel); #ifdef CALAOS_DESKTOP CalaosWidgetModel::Instance()->loadFromDisk(); engine.rootContext()->setContextProperty("widgetsModel", CalaosWidgetModel::Instance()); #endif engine.rootContext()->setContextProperty("calaosApp", this); //Register Units singleton //qmlRegisterSingletonType(QUrl("qrc:/qml/Units.qml"), "Units", 1, 0, "Units"); qmlRegisterType<RoomFilterModel>("Calaos", 1, 0, "RoomFilterModel"); #if defined(CALAOS_MOBILE) engine.load(QUrl(QStringLiteral("qrc:///qml/mobile/main.qml"))); #elif defined(CALAOS_DESKTOP) engine.load(QUrl(QStringLiteral("qrc:///qml/desktop/main.qml"))); #else #error "Unknown UI type!" #endif #ifndef CALAOS_DESKTOP //Start autologin, only on mobile. On desktop we wait for calaos_server detection QTimer::singleShot(100, [=]() { login(get_username(), get_password(), get_hostname()); }); #endif }