diff options
Diffstat (limited to 'homescreen/src')
-rw-r--r-- | homescreen/src/applicationlauncher.cpp | 1 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.cpp | 209 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.h | 39 | ||||
-rw-r--r-- | homescreen/src/main.cpp | 76 | ||||
-rw-r--r-- | homescreen/src/mastervolume.cpp | 100 | ||||
-rw-r--r-- | homescreen/src/mastervolume.h | 49 | ||||
-rw-r--r-- | homescreen/src/shortcutappmodel.cpp | 268 | ||||
-rw-r--r-- | homescreen/src/shortcutappmodel.h | 62 | ||||
-rw-r--r-- | homescreen/src/statusbarmodel.cpp | 11 | ||||
-rw-r--r-- | homescreen/src/toucharea.cpp | 7 |
10 files changed, 123 insertions, 699 deletions
diff --git a/homescreen/src/applicationlauncher.cpp b/homescreen/src/applicationlauncher.cpp index a72ea9f..5a1e2d6 100644 --- a/homescreen/src/applicationlauncher.cpp +++ b/homescreen/src/applicationlauncher.cpp @@ -81,6 +81,5 @@ void ApplicationLauncher::setCurrent(const QString ¤t) { if (m_current == current) return; m_current = current; - qDebug() << "setCurrent" << m_current; emit currentChanged(current); } diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp index cbf816a..251dbe9 100644 --- a/homescreen/src/homescreenhandler.cpp +++ b/homescreen/src/homescreenhandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, 2019 TOYOTA MOTOR CORPORATION + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,20 @@ * limitations under the License. */ -#include <QFileInfo> #include "homescreenhandler.h" #include <functional> +#include <QQmlApplicationEngine> +#include <QtQuick/QQuickWindow> #include <QProcess> -#include <dirent.h> -#include <stdio.h> #include "hmi-debug.h" -#define BUF_SIZE 1024 void* HomescreenHandler::myThis = 0; HomescreenHandler::HomescreenHandler(QObject *parent) : QObject(parent), - mp_qhs(NULL), - current_application("launcher") + mp_qhs(NULL), mp_wm(NULL), m_role() { + } HomescreenHandler::~HomescreenHandler() @@ -37,164 +35,88 @@ HomescreenHandler::~HomescreenHandler() if (mp_qhs != NULL) { delete mp_qhs; } + if (mp_wm != NULL) { + delete mp_wm; + } } -void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname) +void HomescreenHandler::init(const char* role, int port, const char *token) { + this->m_role = role; + + // LibWindowManager initialize + mp_wm = new LibWindowmanager(); + if(mp_wm->init(port,token) != 0){ + exit(EXIT_FAILURE); + } + + int surface = mp_wm->requestSurface(m_role.c_str()); + if (surface < 0) { + exit(EXIT_FAILURE); + } + std::string ivi_id = std::to_string(surface); + setenv("QT_IVI_SURFACE_ID", ivi_id.c_str(), true); + + // LibHomeScreen initialize mp_qhs = new QLibHomeScreen(); mp_qhs->init(port, token); myThis = this; - mp_qwm = qwm; - m_myname = myname; mp_qhs->registerCallback(nullptr, HomescreenHandler::onRep_static); - mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowWindow,[this](json_object *object){ - HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n"); - static bool first_start = true; - if (first_start) { - first_start = false; - mp_qwm->activateWindow(m_myname); - } - else { - emit showWindow(); - } - }); - mp_qhs->set_event_handler(QLibHomeScreen::Event_OnScreenMessage, [this](json_object *object){ const char *display_message = json_object_get_string( json_object_object_get(object, "display_message")); HMI_DEBUG("HomeScreen","set_event_handler Event_OnScreenMessage display_message = %s", display_message); }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowNotification,[this](json_object *object){ - json_object *p_obj = json_object_object_get(object, "parameter"); - const char *icon = json_object_get_string( - json_object_object_get(p_obj, "icon")); - const char *text = json_object_get_string( - json_object_object_get(p_obj, "text")); - const char *app_id = json_object_get_string( - json_object_object_get(p_obj, "caller")); - HMI_DEBUG("HomeScreen","Event_ShowNotification icon=%s, text=%s, caller=%s", icon, text, app_id); - QFileInfo icon_file(icon); - QString icon_path; - if (icon_file.isFile() && icon_file.exists()) { - icon_path = QString(QLatin1String(icon)); - } else { - icon_path = "./images/Utility_Logo_Grey-01.svg"; - } - - emit showNotification(QString(QLatin1String(app_id)), icon_path, QString(QLatin1String(text))); - }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowInformation,[this](json_object *object){ - json_object *p_obj = json_object_object_get(object, "parameter"); - const char *info = json_object_get_string( - json_object_object_get(p_obj, "info")); - - emit showInformation(QString(QLatin1String(info))); - }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_HideWindow, [this](json_object *object) { - emit hideWindow(); - HMI_DEBUG("HomeScreen","set_event_handler Event_HideWindow"); - }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_RegisterShortcut,[this](json_object *object){ - HMI_DEBUG("HomeScreen","set_event_handler Event_RegisterShortcut"); - json_object *p_obj = json_object_object_get(object, "parameter"); - const char *shortcut_id = json_object_get_string( - json_object_object_get(p_obj, "shortcut_id")); - const char *shortcut_name = json_object_get_string( - json_object_object_get(p_obj, "shortcut_name")); - const char *position = json_object_get_string( - json_object_object_get(p_obj, "position")); - HMI_DEBUG("HomeScreen", "Event_RegisterShortcut id==%s, name==%s, position ==%s", shortcut_id, shortcut_name, position); - emit shortcutChanged(QString(QLatin1String(shortcut_id)), QString(QLatin1String(shortcut_name)), QString(QLatin1String(position))); - }); } -void HomescreenHandler::tapShortcut(QString application_id, bool is_full) -{ - HMI_DEBUG("HomeScreen","tapShortcut %s", application_id.toStdString().c_str()); - struct json_object* j_json = json_object_new_object(); - struct json_object* value; - if(is_full) { - value = json_object_new_string("fullscreen"); - HMI_DEBUG("HomeScreen","fullscreen"); - } else { - value = json_object_new_string("normal.full"); - HMI_DEBUG("HomeScreen","normal"); - } - json_object_object_add(j_json, "area", value); - mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json); +void HomescreenHandler::setWMHandler(WMHandler& h) { + h.on_sync_draw = [&](const char* role, const char* area, Rect r) { + this->mp_wm->endDraw(this->m_role.c_str()); + }; + mp_wm->setEventHandler(h); } -void HomescreenHandler::updateShortcut(QString id, struct json_object* object) +void HomescreenHandler::disconnect_frame_swapped(void) { - mp_qhs->updateShortcut(id.toStdString().c_str(), object); + qDebug("Let's start homescreen"); + QObject::disconnect(this->loading); + mp_wm->activateWindow(m_role.c_str(), "fullscreen"); } - -void HomescreenHandler::setCurrentApplication(QString application_name) +void HomescreenHandler::attach(QQmlApplicationEngine* engine) { - HMI_DEBUG("HomeScreen","setCurrentApplication %s", application_name.toStdString().c_str()); - current_application = application_name; + QQuickWindow *window = qobject_cast<QQuickWindow *>(engine->rootObjects().first()); +// this->loading = QObject::connect(window, SIGNAL(frameSwapped()), this, SLOT(disconnect_frame_swapped())); + mp_qhs->setQuickWindow(window); } -QString HomescreenHandler::getCurrentApplication() +void HomescreenHandler::changeLayout(int pattern) { - HMI_DEBUG("HomeScreen","getCurrentApplication %s", current_application.toStdString().c_str()); - return current_application; -} - -int HomescreenHandler::getPidOfApplication(QString application_name) { - DIR *dir = NULL; - struct dirent *dir_ent_ptr = NULL; - FILE *fp = NULL; - char file_path[50] = {0}; - char cur_task_ame[50] = {0}; - char buf[BUF_SIZE] = {0}; - int pid = -1; - - dir = opendir("/proc"); - if (dir) { - while((dir_ent_ptr = readdir(dir)) != NULL) { - if ((strcmp(dir_ent_ptr->d_name, ".") == 0) || (strcmp(dir_ent_ptr->d_name, "..") == 0) - || (DT_DIR != dir_ent_ptr->d_type)) - continue; - sprintf(file_path, "/proc/%s/status", dir_ent_ptr->d_name); - fp = fopen(file_path, "r"); - if (fp) { - if (fgets(buf, BUF_SIZE - 1, fp) == NULL) { - fclose(fp); - continue; - } - sscanf(buf, "%*s %s", cur_task_ame); - if (0 == strcmp(application_name.toStdString().c_str(), cur_task_ame)) { - pid = atoi(dir_ent_ptr->d_name); - break; - } - } - } + HMI_NOTICE("HomeScreen", "Pressed %d, %s", pattern, + (pattern == P_LEFT_METER_RIGHT_MAP) ? "left:meter, right:map": "left:map, right:meter"); + ChangeAreaReq req; + std::unordered_map<std::string, Rect> map_list; + switch(pattern) { + case P_LEFT_METER_RIGHT_MAP: + map_list["split.main"] = Rect(0, 0, 1280, 720); + map_list["split.sub"] = Rect(1280, 0, 640, 720); + break; + case P_LEFT_MAP_RIGHT_METER: + map_list["split.main"] = Rect(640, 0, 1280, 720); + map_list["split.sub"] = Rect(0, 0, 640, 720); + break; + default: + break; + } + if(map_list.size() != 0) + { + req.setAreaReq(map_list); + HMI_NOTICE("Homescreen", "Change layout"); + mp_wm->changeAreaSize(req); } - - return pid; -} - -void HomescreenHandler::killRunningApplications() -{ - QProcess *proc = new QProcess; - QProcess *proc2 = new QProcess; -// int num = getPidOfApplication("afbd-video@0.1"); -// QString procNum = QString::number(num); - QString command = "/usr/bin/pkill videoplayer"; - QString command2 = "/usr/bin/pkill navigation"; - proc->start(command); - proc2->start(command2); - HMI_DEBUG("homescreen", command.toStdString().c_str()); - HMI_DEBUG("homescreen", command2.toStdString().c_str()); } void HomescreenHandler::reboot() @@ -203,6 +125,12 @@ void HomescreenHandler::reboot() QProcess::execute("reboot -f"); } +void HomescreenHandler::tapShortcut(QString application_name) +{ + HMI_DEBUG("HomeScreen","tapShortcut %s", application_name.toStdString().c_str()); + mp_qhs->tapShortcut(application_name.toStdString().c_str()); +} + void HomescreenHandler::onRep_static(struct json_object* reply_contents) { static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents); @@ -232,8 +160,3 @@ void HomescreenHandler::onEv(const string& event, struct json_object* event_cont HMI_DEBUG("HomeScreen","display_message = %s", display_message); } } - -void HomescreenHandler::setQuickWindow(QQuickWindow *qw) -{ - mp_qhs->setQuickWindow(qw); -} diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h index 4afbac4..69599de 100644 --- a/homescreen/src/homescreenhandler.h +++ b/homescreen/src/homescreenhandler.h @@ -18,28 +18,33 @@ #define HOMESCREENHANDLER_H #include <QObject> -#include <QQuickWindow> #include <qlibhomescreen.h> -#include <qlibwindowmanager.h> +#include <libwindowmanager.h> #include <string> using namespace std; +class QQmlApplicationEngine; + class HomescreenHandler : public QObject { Q_OBJECT public: + enum CHANGE_LAYOUT_PATTERN { + P_LEFT_METER_RIGHT_MAP = 0, + P_LEFT_MAP_RIGHT_METER + }; + Q_ENUMS(CHANGE_LAYOUT_PATTERN) explicit HomescreenHandler(QObject *parent = 0); ~HomescreenHandler(); - void init(int port, const char* token, QLibWindowmanager *qwm, QString myname); + void init(const char* role, int port, const char* token); + void attach(QQmlApplicationEngine* engine); + void setWMHandler(WMHandler &handler); - Q_INVOKABLE void tapShortcut(QString application_name, bool is_full); - Q_INVOKABLE QString getCurrentApplication(); - Q_INVOKABLE void killRunningApplications(); + Q_INVOKABLE void tapShortcut(QString application_name); + Q_INVOKABLE void changeLayout(int pattern); Q_INVOKABLE void reboot(); - void setCurrentApplication(QString application_name); - int getPidOfApplication(QString application_name); void onRep(struct json_object* reply_contents); void onEv(const string& event, struct json_object* event_contents); @@ -47,23 +52,19 @@ public: static void* myThis; static void onRep_static(struct json_object* reply_contents); static void onEv_static(const string& event, struct json_object* event_contents); - void setQuickWindow(QQuickWindow *qw); signals: - void showNotification(QString application_id, QString icon_path, QString text); - void showInformation(QString info); - void shortcutChanged(QString shortcut_id, QString shortcut_name, QString position); - void showWindow(); - void hideWindow(); + void notification(QString id, QString icon, QString text); + void information(QString text); -public slots: - void updateShortcut(QString id, struct json_object* object); +private Q_SLOTS: + void disconnect_frame_swapped(void); private: QLibHomeScreen *mp_qhs; - QLibWindowmanager *mp_qwm; - QString m_myname; - QString current_application; + LibWindowmanager *mp_wm; + std::string m_role; + QMetaObject::Connection loading; }; #endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 0c477fd..ba5d36a 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * Copyright (c) 2017, 2018 TOYOTA MOTOR CORPORATION + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,17 +24,15 @@ #include <QQuickWindow> #include <QThread> -#include <qlibwindowmanager.h> #include <weather.h> #include <bluetooth.h> #include "applicationlauncher.h" #include "statusbarmodel.h" #include "afm_user_daemon_proxy.h" -#include "mastervolume.h" #include "homescreenhandler.h" #include "toucharea.h" -#include "shortcutappmodel.h" #include "hmi-debug.h" +#include <QBitmap> // XXX: We want this DBus connection to be shared across the different // QML objects, is there another way to do this, a nice way, perhaps? @@ -58,6 +56,7 @@ void noOutput(QtMsgType, const QMessageLogContext &, const QString &) int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); + const char* graphic_role = "homescreen"; // use launch process QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user", @@ -81,7 +80,6 @@ int main(int argc, char *argv[]) int port = 1700; QString token = "wm"; - QString graphic_role = "homescreen"; // defined in layers.json in Window Manager if (positionalArguments.length() == 2) { port = positionalArguments.takeFirst().toInt(); @@ -93,22 +91,10 @@ int main(int argc, char *argv[]) // import C++ class to QML // qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher"); qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel"); - qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume"); - qmlRegisterType<ShortcutAppModel>("ShortcutAppModel", 1, 0, "ShortcutAppModel"); ApplicationLauncher *launcher = new ApplicationLauncher(); - QLibWindowmanager* layoutHandler = new QLibWindowmanager(); HomescreenHandler* homescreenHandler = new HomescreenHandler(); - ShortcutAppModel* shortcutAppModel = new ShortcutAppModel(); - if(layoutHandler->init(port,token) != 0){ - exit(EXIT_FAILURE); - } - - AGLScreenInfo screenInfo(layoutHandler->get_scale_factor()); - - if (layoutHandler->requestSurface(graphic_role) != 0) { - exit(EXIT_FAILURE); - } + homescreenHandler->init(graphic_role, port, token.toStdString().c_str()); QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); @@ -121,47 +107,46 @@ int main(int argc, char *argv[]) bindingAddress.setQuery(query); TouchArea* touchArea = new TouchArea(); - homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, graphic_role); // mail.qml loading QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty("bindingAddress", bindingAddress); - engine.rootContext()->setContextProperty("layoutHandler", layoutHandler); engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler); engine.rootContext()->setContextProperty("touchArea", touchArea); - engine.rootContext()->setContextProperty("shortcutAppModel", shortcutAppModel); engine.rootContext()->setContextProperty("launcher", launcher); engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress)); - engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress, engine.rootContext())); - engine.rootContext()->setContextProperty("screenInfo", &screenInfo); +// engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress)); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *root = engine.rootObjects().first(); - QQuickWindow *window = qobject_cast<QQuickWindow *>(root); - homescreenHandler->setQuickWindow(window); - - layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler, &graphic_role](json_object *object) { - layoutHandler->endDraw(graphic_role); - }); - layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher, homescreenHandler, root](json_object *object) { - json_object *jarray = json_object_object_get(object, "ids"); - HMI_DEBUG("HomeScreen","ids=%s", json_object_to_json_string(object)); - int arrLen = json_object_array_length(jarray); + WMHandler wmh; + wmh.on_screen_updated = [launcher, root](std::vector<std::string> list) { + for(const auto& i : list) { + HMI_DEBUG("HomeScreen", "ids=%s", i.c_str()); + } + int arrLen = list.size(); QString label = QString(""); for( int idx = 0; idx < arrLen; idx++) { - label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) )); - HMI_DEBUG("HomeScreen","Event_ScreenUpdated application11: %s.", label.toStdString().c_str()); - homescreenHandler->setCurrentApplication(label); + label = list[idx].c_str(); + HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str()); QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); + if(label == "launcher") { + QMetaObject::invokeMethod(root, "turnToNormal"); + } else { + QMetaObject::invokeMethod(root, "turnToFullscreen"); + } + if((arrLen == 1) && (QString("restriction") != label)) { + QMetaObject::invokeMethod(root, "disableSplitSwitchBtn"); + } else { + QMetaObject::invokeMethod(root, "enableSplitSwitchBtn"); + } } - if((arrLen == 1) && (QString("navigation") == label)){ - QMetaObject::invokeMethod(root, "changeSwitchState", Q_ARG(QVariant, true)); - }else{ - QMetaObject::invokeMethod(root, "changeSwitchState", Q_ARG(QVariant, false)); - } - }); + }; + homescreenHandler->setWMHandler(wmh); + homescreenHandler->attach(&engine); + + QQuickWindow *window = qobject_cast<QQuickWindow *>(root); touchArea->setWindow(window); QThread* thread = new QThread; @@ -174,10 +159,5 @@ int main(int argc, char *argv[]) StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar"); statusBar->init(bindingAddress, engine.rootContext()); - QObject::connect(homescreenHandler, SIGNAL(shortcutChanged(QString, QString, QString)), shortcutAppModel, SLOT(changeShortcut(QString, QString, QString))); - QObject::connect(shortcutAppModel, SIGNAL(shortcutUpdated(QString, struct json_object*)), homescreenHandler, SLOT(updateShortcut(QString, struct json_object*))); - - shortcutAppModel->screenUpdated(); - return a.exec(); } diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp deleted file mode 100644 index 35b47fc..0000000 --- a/homescreen/src/mastervolume.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2017 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mastervolume.h" -#include <QJsonObject> -#include <QTimer> -#include <QtDebug> - -MasterVolume::MasterVolume(QObject* parent) - : QObject(parent) - , m_volume{50} -{ - connect(&m_client, SIGNAL(connected()), this, SLOT(onClientConnected())); - connect(&m_client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected())); - connect(&m_client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onClientError(QAbstractSocket::SocketError))); - connect(&m_client, SIGNAL(eventReceived(QString, const QJsonValue&)), this, SLOT(onClientEventReceived(QString, const QJsonValue&))); -} - -void MasterVolume::open(const QUrl& url) -{ - m_url = url; - TryOpen(); -} - -qint32 MasterVolume::getVolume() const -{ - return m_volume; -} - -void MasterVolume::setVolume(qint32 volume) -{ - if (m_volume != volume) - { - m_volume = volume; - QJsonObject arg; - arg.insert("action", "volume"); - arg.insert("value", volume); - m_client.call("ahl-4a", "activerole", arg, [](bool, const QJsonValue&) { - // Nothing to do, events will update sliders - }); - } -} - -void MasterVolume::onClientConnected() -{ - // Subscribe to 4a events - m_client.call("ahl-4a", "subscribe", QJsonValue(), [this](bool r, const QJsonValue&) { - if (r) qDebug() << "MasterVolume::onClientConnected - subscribed to 4a events!"; - else qCritical () << "MasterVolume::onClientConnected - Failed to subscribe to 4a events!"; - }); -} - -void MasterVolume::onClientDisconnected() -{ - qDebug() << "MasterVolume::onClientDisconnected!"; - QTimer::singleShot(1000, this, SLOT(TryOpen())); -} - -void MasterVolume::onClientError(QAbstractSocket::SocketError se) -{ - qDebug() << "MasterVolume::onClientError: " << se; -} - -void MasterVolume::onClientEventReceived(QString name, const QJsonValue& data) -{ - qDebug() << "MasterVolume::onClientEventReceived[" << name << "]: " << data; - if (name == "ahl-4a/volume_changed") - { - QJsonObject arg = data.toObject(); - bool active = arg["active"].toBool(); - if (active) - { - // QString role = arg["role"].toString(); - int volume = arg["volume"].toInt(); - if (m_volume != volume) - { - m_volume = volume; - emit VolumeChanged(); - } - } - } -} - -void MasterVolume::TryOpen() -{ - m_client.open(m_url); -} diff --git a/homescreen/src/mastervolume.h b/homescreen/src/mastervolume.h deleted file mode 100644 index 6ae0aad..0000000 --- a/homescreen/src/mastervolume.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2017 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <QtCore/QObject> -#include <QQmlEngine> -#include "../qafbwebsocketclient.h" - -class MasterVolume - : public QObject -{ - Q_OBJECT - Q_PROPERTY (uint32_t volume READ getVolume WRITE setVolume NOTIFY VolumeChanged) - -private: - QAfbWebsocketClient m_client; - QUrl m_url; - qint32 m_volume; - -public: - MasterVolume(QObject* parent = nullptr); - ~MasterVolume() = default; - - Q_INVOKABLE void open(const QUrl& url); - Q_INVOKABLE qint32 getVolume() const; - Q_INVOKABLE void setVolume(qint32 val); - -private slots: - void onClientConnected(); - void onClientDisconnected(); - void onClientError(QAbstractSocket::SocketError se); - void onClientEventReceived(QString name, const QJsonValue& data); - void TryOpen(); - -signals: - void VolumeChanged(); -}; diff --git a/homescreen/src/shortcutappmodel.cpp b/homescreen/src/shortcutappmodel.cpp deleted file mode 100644 index 76078da..0000000 --- a/homescreen/src/shortcutappmodel.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2017 TOYOTA MOTOR CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "shortcutappmodel.h" -#include "hmi-debug.h" -#include <unistd.h> -#define SHORTCUTKEY_PATH "/var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json" - -class ShortcutAppModel::Private -{ -public: - Private(); - - QList<RegisterApp> data; -}; - -ShortcutAppModel::Private::Private() -{ -} - - -ShortcutAppModel::ShortcutAppModel(QObject *parent) - : QAbstractListModel(parent) - , d(new Private()) -{ - getAppQueue(); -} - -ShortcutAppModel::~ShortcutAppModel() -{ - delete this->d; -} - -int ShortcutAppModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - - return this->d->data.count(); -} - -QVariant ShortcutAppModel::data(const QModelIndex &index, int role) const -{ - QVariant ret; - if (!index.isValid()) - return ret; - - switch (role) { - case Qt::DecorationRole: - ret = this->d->data[index.row()].icon; - break; - case Qt::DisplayRole: - ret = this->d->data[index.row()].name; - break; - case Qt::UserRole: - ret = this->d->data[index.row()].id; - break; - default: - break; - } - - return ret; -} - -QHash<int, QByteArray> ShortcutAppModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[Qt::DecorationRole] = "icon"; - roles[Qt::DisplayRole] = "name"; - roles[Qt::UserRole] = "id"; - return roles; -} - -void ShortcutAppModel::changeShortcut(QString id, QString name, QString position) -{ - for(int i = 1; i < d->data.size(); i++) { - if(id == d->data.at(i).id) { - return; - } - } - d->data.removeAt(position.toInt() + 1); - - RegisterApp temp; - temp.id = id; - temp.name = name; - temp.icon = temp.icon = getIconPath(temp.id); - if (temp.icon == "") { - temp.isBlank = true; - } else { - temp.isBlank = false; - } - - d->data.insert(position.toInt() + 1, temp); - setAppQueue(); - emit updateShortcut(); - struct json_object* obj = makeAppListJson(); - emit shortcutUpdated(QString("launcher"), obj); -} - -struct json_object* ShortcutAppModel::makeAppListJson() -{ - struct json_object* obj = json_object_new_object(); - struct json_object* obj_array = json_object_new_array(); - for(int i = 1; i < d->data.size(); i++) - { - struct json_object* obj_shortcut = json_object_new_object(); - json_object_object_add(obj_shortcut, "shortcut_id", json_object_new_string(d->data.at(i).id.toStdString().c_str())); - json_object_object_add(obj_shortcut, "shortcut_name", json_object_new_string(d->data.at(i).name.toStdString().c_str())); - json_object_array_add(obj_array, obj_shortcut); - } - json_object_object_add(obj, "shortcut", obj_array); - HMI_DEBUG("Homescreen", "makeAppListJson id1=%s",json_object_new_string(d->data.at(1).name.toStdString().c_str())); - return obj; -} - -QString ShortcutAppModel::getId(int index) const -{ - return d->data.at(index).id; -} - -QString ShortcutAppModel::getName(int index) const -{ - return d->data.at(index).name; -} - -QString ShortcutAppModel::getIcon(int index) const -{ - return d->data.at(index).icon; -} - -bool ShortcutAppModel::isBlank(int index) const -{ - return d->data.at(index).isBlank; -} - -QString ShortcutAppModel::getIconPath(QString id) -{ - QString name = id.section('@', 0, 0); - QString version = id.section('@', 1, 1); - QString boardIconPath = "/var/local/lib/afm/applications/" + name + "/" + version + "/icon.svg"; - QString appIconPath = ":/images/Shortcut/" + name + ".svg"; - if (QFile::exists(boardIconPath)) { - return "file://" + boardIconPath; - } else if (QFile::exists(appIconPath)) { - return appIconPath.section('/', 1, -1); - } - return ""; -} - -void ShortcutAppModel::getAppQueue() -{ - QProcess *process = new QProcess(this); - if(checkAppFile()) { - process->start("cp /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.aaa.json /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json"); - } else { - process->start("cp /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json /var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.aaa.json"); - } - QThread::msleep(300); - - QFile file(SHORTCUTKEY_PATH); - if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QByteArray allData = file.readAll(); - QString str(allData); - if(str == "") { - file.close(); - - } - QJsonParseError json_error; - QJsonDocument jsonDoc(QJsonDocument::fromJson(allData, &json_error)); - - if(json_error.error != QJsonParseError::NoError) - { - HMI_ERROR("HomeScreen", "registeredApp.json error"); - return; - } - - QJsonObject rootObj = jsonDoc.object(); - - QJsonObject subObj = rootObj.value("1st shortcut key").toObject(); - setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); - subObj = rootObj.value("2nd shortcut key").toObject(); - setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); - subObj = rootObj.value("3rd shortcut key").toObject(); - setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); - subObj = rootObj.value("4th shortcut key").toObject(); - setAppQueuePoint(subObj["id"].toString(), subObj["name"].toString()); - } - file.close(); -} - -void ShortcutAppModel::setAppQueuePoint(QString id, QString name) -{ - app.id = id; - app.icon = getIconPath(app.id); - if (app.icon == "") { - app.isBlank = true; - } else { - app.isBlank = false; - } - app.name = name; - d->data.append(app); -} - -void ShortcutAppModel::screenUpdated() -{ - struct json_object* obj = makeAppListJson(); - emit shortcutUpdated(QString("launcher"), obj); -} - -void ShortcutAppModel::setAppQueue() -{ - QFile file(SHORTCUTKEY_PATH); - if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QJsonObject rootObj, subObj1, subObj2, subObj3, subObj4; - subObj1.insert("id", d->data.at(0).id); - subObj1.insert("name", d->data.at(0).name); - subObj2.insert("id", d->data.at(1).id); - subObj2.insert("name", d->data.at(1).name); - subObj3.insert("id", d->data.at(2).id); - subObj3.insert("name", d->data.at(2).name); - subObj4.insert("id", d->data.at(3).id); - subObj4.insert("name", d->data.at(3).name); - rootObj.insert("1st shortcut key", subObj1); - rootObj.insert("2nd shortcut key", subObj2); - rootObj.insert("3rd shortcut key", subObj3); - rootObj.insert("4th shortcut key", subObj4); - - QJsonDocument jsonDoc; - jsonDoc.setObject(rootObj); - - file.write(jsonDoc.toJson()); - } else { - HMI_ERROR("HomeScreen", "write to registeredApp.json file failed"); - } - file.flush(); - fsync(file.handle()); - file.close(); -} - -bool ShortcutAppModel::checkAppFile() -{ - bool fileError = false; - QFile file(SHORTCUTKEY_PATH); - if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QByteArray line = file.readLine(); - if(line == "\n" || line.isEmpty()) { - fileError = true; - } - } else { - fileError = true; - HMI_ERROR("HomeScreen", "registeredApp.json file open failed"); - } - file.close(); - return fileError; -} diff --git a/homescreen/src/shortcutappmodel.h b/homescreen/src/shortcutappmodel.h deleted file mode 100644 index f177a95..0000000 --- a/homescreen/src/shortcutappmodel.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef SHORTCUTAPPMODEL_H -#define SHORTCUTAPPMODEL_H - -#include <QtCore/QAbstractListModel> -#include <QXmlStreamReader> -#include <QXmlStreamWriter> -#include <QFile> -#include <QProcess> -#include <QThread> -#include <QJsonDocument> -#include <QJsonParseError> -#include <QJsonObject> -#include <json_object.h> - -struct RegisterApp { - QString id; - QString name; - QString icon; - bool isBlank; -}; - -class ShortcutAppModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit ShortcutAppModel(QObject *parent = nullptr); - ~ShortcutAppModel(); - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QHash<int, QByteArray> roleNames() const override; - - Q_INVOKABLE QString getId(int index) const; - Q_INVOKABLE QString getName(int index) const; - Q_INVOKABLE QString getIcon(int index) const; - Q_INVOKABLE bool isBlank(int index) const; - - void screenUpdated(); - -public slots: - void changeShortcut(QString id, QString name, QString position); - -signals: - void updateShortcut(); - void shortcutUpdated(QString id, struct json_object* object); - -private: - void getAppQueue(); - void setAppQueue(); - bool checkAppFile(); - void setAppQueuePoint(QString id, QString name); - QString getIconPath(QString id); - struct json_object* makeAppListJson(); - - class Private; - Private *d; - RegisterApp app; - -}; - -#endif // SHORTCUTAPPMODEL_H diff --git a/homescreen/src/statusbarmodel.cpp b/homescreen/src/statusbarmodel.cpp index 5e63b7d..c093ceb 100644 --- a/homescreen/src/statusbarmodel.cpp +++ b/homescreen/src/statusbarmodel.cpp @@ -1,6 +1,5 @@ /* * Copyright (C) 2016 The Qt Company Ltd. - * Copyright (C) 2017, 2018 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +16,14 @@ #include "statusbarmodel.h" #include "statusbarserver.h" +#include <QDebug> +#include "hmi-debug.h" #include <QtDBus/QDBusConnection> #include "network.h" + class StatusBarModel::Private { public: @@ -65,6 +67,7 @@ StatusBarModel::~StatusBarModel() void StatusBarModel::init(QUrl &url, QQmlContext *context) { + HMI_DEBUG("HomeScreen", "StatusBarModel::init"); d->network = new Network(url, context); context->setContextProperty("network", d->network); @@ -77,6 +80,7 @@ void StatusBarModel::init(QUrl &url, QQmlContext *context) void StatusBarModel::setWifiStatus(bool connected, bool enabled, int strength) { + HMI_DEBUG("HomeScreen", "StatusBarModel::setWifiStatus"); if (enabled && connected) if (strength < 30) d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png")); @@ -111,7 +115,6 @@ int StatusBarModel::rowCount(const QModelIndex &parent) const if (parent.isValid()) return 0; - // Delete bluetooth because use agl-service-bluetooth. return StatusBarServer::SupportedCount - 1; } @@ -123,9 +126,9 @@ QVariant StatusBarModel::data(const QModelIndex &index, int role) const switch (role) { case Qt::DisplayRole: - if (index.row() == 0){ + if (index.row() == 0) { ret = d->iconList[StatusBarServer::StatusWifi]; - }else if (index.row() == 1){ + } else if (index.row() == 1) { ret = d->iconList[StatusBarServer::StatusCellular]; } break; diff --git a/homescreen/src/toucharea.cpp b/homescreen/src/toucharea.cpp index 1cf4384..aad4b1b 100644 --- a/homescreen/src/toucharea.cpp +++ b/homescreen/src/toucharea.cpp @@ -1,5 +1,4 @@ #include "toucharea.h" -#include "hmi-debug.h" TouchArea::TouchArea() { @@ -17,8 +16,8 @@ void TouchArea::setWindow(QQuickWindow *window) void TouchArea::init() { - bitmapNormal = QPixmap(":/images/AGL_HMI_Normal_Background.png").createHeuristicMask(); - bitmapFullscreen = QPixmap(":/images/AGL_HMI_Full_Background.png").createHeuristicMask(); + bitmapNormal = QPixmap(":/images/menubar_normal_background.png").createHeuristicMask(); + bitmapFullscreen = QPixmap(":/images/menubar_full_background.png").createHeuristicMask(); myWindow->setMask(QRegion(bitmapNormal)); } @@ -26,9 +25,7 @@ void TouchArea::switchArea(int areaType) { if(areaType == NORMAL) { myWindow->setMask(QRegion(bitmapNormal)); - HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); } else if (areaType == FULLSCREEN) { - HMI_DEBUG("HomeScreen","TouchArea switchArea: %d.", areaType); myWindow->setMask(QRegion(bitmapFullscreen)); } } |