diff options
Diffstat (limited to 'homescreen/src')
-rw-r--r-- | homescreen/src/applicationlauncher.cpp | 85 | ||||
-rw-r--r-- | homescreen/src/applicationlauncher.h | 55 | ||||
-rw-r--r-- | homescreen/src/hmi-debug.h | 70 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.cpp | 121 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.h | 51 | ||||
-rw-r--r-- | homescreen/src/main.cpp | 155 | ||||
-rw-r--r-- | homescreen/src/mastervolume.cpp | 110 | ||||
-rw-r--r-- | homescreen/src/mastervolume.h | 49 | ||||
-rw-r--r-- | homescreen/src/statusbarmodel.cpp | 150 | ||||
-rw-r--r-- | homescreen/src/statusbarmodel.h | 47 | ||||
-rw-r--r-- | homescreen/src/statusbarserver.cpp | 91 | ||||
-rw-r--r-- | homescreen/src/statusbarserver.h | 52 |
12 files changed, 0 insertions, 1036 deletions
diff --git a/homescreen/src/applicationlauncher.cpp b/homescreen/src/applicationlauncher.cpp deleted file mode 100644 index 5a1e2d6..0000000 --- a/homescreen/src/applicationlauncher.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * 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 "applicationlauncher.h" - -#include "afm_user_daemon_proxy.h" - -#include "hmi-debug.h" - -extern org::AGL::afm::user *afm_user_daemon_proxy; - -ApplicationLauncher::ApplicationLauncher(QObject *parent) - : QObject(parent) - , m_launching(false) - , m_timeout(new QTimer(this)) -{ - m_timeout->setInterval(3000); - m_timeout->setSingleShot(true); - connect(m_timeout, &QTimer::timeout, [&]() { - setLaunching(false); - }); - connect(this, &ApplicationLauncher::launchingChanged, [&](bool launching) { - if (launching) - m_timeout->start(); - else - m_timeout->stop(); - }); - connect(this, &ApplicationLauncher::currentChanged, [&]() { - setLaunching(false); - }); -} - -int ApplicationLauncher::launch(const QString &application) -{ - int result = -1; - HMI_DEBUG("HomeScreen","ApplicationLauncher launch %s.", application.toStdString().c_str()); - - result = afm_user_daemon_proxy->start(application).value().toInt(); - HMI_DEBUG("HomeScreen","ApplicationLauncher pid: %d.", result); - - if (result > 1) { - setLaunching(true); - } - - return result; -} - -bool ApplicationLauncher::isLaunching() const -{ - return m_launching; -} - -void ApplicationLauncher::setLaunching(bool launching) -{ - if (m_launching == launching) return; - m_launching = launching; - launchingChanged(launching); -} - -QString ApplicationLauncher::current() const -{ - return m_current; -} - -void ApplicationLauncher::setCurrent(const QString ¤t) -{ - if (m_current == current) return; - m_current = current; - emit currentChanged(current); -} diff --git a/homescreen/src/applicationlauncher.h b/homescreen/src/applicationlauncher.h deleted file mode 100644 index dfa5846..0000000 --- a/homescreen/src/applicationlauncher.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * 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. - */ - -#ifndef APPLICATIONLAUNCHER_H -#define APPLICATIONLAUNCHER_H - -#include <QtCore/QObject> - -class QTimer; - -class ApplicationLauncher : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool launching READ isLaunching NOTIFY launchingChanged) - Q_PROPERTY(QString current READ current WRITE setCurrent NOTIFY currentChanged) -public: - explicit ApplicationLauncher(QObject *parent = NULL); - - bool isLaunching() const; - QString current() const; - -signals: - void newAppRequestsToBeVisible(int pid); - void launchingChanged(bool launching); - void currentChanged(const QString ¤t); - -public slots: - int launch(const QString &application); - void setCurrent(const QString ¤t); - -private: - void setLaunching(bool launching); - -private: - bool m_launching; - QString m_current; - QTimer *m_timeout; -}; - -#endif // APPLICATIONLAUNCHER_H diff --git a/homescreen/src/hmi-debug.h b/homescreen/src/hmi-debug.h deleted file mode 100644 index 28705f5..0000000 --- a/homescreen/src/hmi-debug.h +++ /dev/null @@ -1,70 +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. - */ - -#ifndef __HMI_DEBUG_H__ -#define __HMI_DEBUG_H__ - -#include <time.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> -#include <stdlib.h> - -enum LOG_LEVEL{ - LOG_LEVEL_NONE = 0, - LOG_LEVEL_ERROR, - LOG_LEVEL_WARNING, - LOG_LEVEL_NOTICE, - LOG_LEVEL_INFO, - LOG_LEVEL_DEBUG, - LOG_LEVEL_MAX = LOG_LEVEL_DEBUG -}; - -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - -#define HMI_ERROR(prefix, args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, prefix, args, ##__VA_ARGS__) -#define HMI_WARNING(prefix, args,...) _HMI_LOG(LOG_LEVEL_WARNING, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) -#define HMI_NOTICE(prefix, args,...) _HMI_LOG(LOG_LEVEL_NOTICE, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) -#define HMI_INFO(prefix, args,...) _HMI_LOG(LOG_LEVEL_INFO, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) -#define HMI_DEBUG(prefix, args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) - -static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"}; - -static void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...) -{ - const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG")); - if(log_level < level) - { - return; - } - - char *message; - struct timespec tp; - unsigned int time; - - clock_gettime(CLOCK_REALTIME, &tp); - time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); - - va_list args; - va_start(args, log); - if (log == NULL || vasprintf(&message, log, args) < 0) - message = NULL; - fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message); - va_end(args); - free(message); -} - -#endif //__HMI_DEBUG_H__ diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp deleted file mode 100644 index 4db60fb..0000000 --- a/homescreen/src/homescreenhandler.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017, 2018, 2019 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 <QFileInfo> -#include "homescreenhandler.h" -#include <functional> -#include "hmi-debug.h" - -void* HomescreenHandler::myThis = 0; - -HomescreenHandler::HomescreenHandler(QObject *parent) : - QObject(parent), - mp_hs(NULL) -{ - -} - -HomescreenHandler::~HomescreenHandler() -{ - if (mp_hs != NULL) { - delete mp_hs; - } -} - -void HomescreenHandler::init(int port, const char *token) -{ - mp_hs = new LibHomeScreen(); - mp_hs->init(port, token); - - myThis = this; - - mp_hs->registerCallback(nullptr, HomescreenHandler::onRep_static); - - mp_hs->set_event_handler(LibHomeScreen::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_hs->set_event_handler(LibHomeScreen::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_hs->set_event_handler(LibHomeScreen::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))); - }); -} - -void HomescreenHandler::tapShortcut(QString application_id) -{ - HMI_DEBUG("HomeScreen","tapShortcut %s", application_id.toStdString().c_str()); - struct json_object* j_json = json_object_new_object(); - struct json_object* value; - value = json_object_new_string("normal.full"); - json_object_object_add(j_json, "area", value); - - mp_hs->showWindow(application_id.toStdString().c_str(), j_json); -} - -void HomescreenHandler::onRep_static(struct json_object* reply_contents) -{ - static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents); -} - -void HomescreenHandler::onEv_static(const string& event, struct json_object* event_contents) -{ - static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onEv(event, event_contents); -} - -void HomescreenHandler::onRep(struct json_object* reply_contents) -{ - const char* str = json_object_to_json_string(reply_contents); - HMI_DEBUG("HomeScreen","HomeScreen onReply %s", str); -} - -void HomescreenHandler::onEv(const string& event, struct json_object* event_contents) -{ - const char* str = json_object_to_json_string(event_contents); - HMI_DEBUG("HomeScreen","HomeScreen onEv %s, contents: %s", event.c_str(), str); - - if (event.compare("homescreen/on_screen_message") == 0) { - struct json_object *json_data = json_object_object_get(event_contents, "data"); - struct json_object *json_display_message = json_object_object_get(json_data, "display_message"); - const char* display_message = json_object_get_string(json_display_message); - - HMI_DEBUG("HomeScreen","display_message = %s", display_message); - } -} diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h deleted file mode 100644 index 5dfe041..0000000 --- a/homescreen/src/homescreenhandler.h +++ /dev/null @@ -1,51 +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. - */ - -#ifndef HOMESCREENHANDLER_H -#define HOMESCREENHANDLER_H - -#include <QObject> -#include <libhomescreen.hpp> -#include <string> - -using namespace std; - -class HomescreenHandler : public QObject -{ - Q_OBJECT -public: - explicit HomescreenHandler(QObject *parent = 0); - ~HomescreenHandler(); - - void init(int port, const char* token); - - Q_INVOKABLE void tapShortcut(QString application_id); - - void onRep(struct json_object* reply_contents); - void onEv(const string& event, struct json_object* event_contents); - - static void* myThis; - static void onRep_static(struct json_object* reply_contents); - static void onEv_static(const string& event, struct json_object* event_contents); - -signals: - void showNotification(QString application_id, QString icon_path, QString text); - void showInformation(QString info); -private: - LibHomeScreen *mp_hs; -}; - -#endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp deleted file mode 100644 index 5f283fb..0000000 --- a/homescreen/src/main.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * 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. - * 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 <QGuiApplication> -#include <QCommandLineParser> -#include <QtGui/QGuiApplication> -#include <QtQml/QQmlApplicationEngine> -#include <QtQml/QQmlContext> -#include <QtQml/qqml.h> -#include <QQuickWindow> - -#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 "hmi-debug.h" - -// 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? -org::AGL::afm::user *afm_user_daemon_proxy; - -namespace { - -struct Cleanup { - static inline void cleanup(org::AGL::afm::user *p) { - delete p; - afm_user_daemon_proxy = Q_NULLPTR; - } -}; - -void noOutput(QtMsgType, const QMessageLogContext &, const QString &) -{ -} - -} - -int main(int argc, char *argv[]) -{ - QGuiApplication a(argc, argv); - - // use launch process - QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user", - "/org/AGL/afm/user", - QDBusConnection::sessionBus(), - 0)); - ::afm_user_daemon_proxy = afm_user_daemon_proxy.data(); - - QCoreApplication::setOrganizationDomain("LinuxFoundation"); - QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); - QCoreApplication::setApplicationName("HomeScreen"); - QCoreApplication::setApplicationVersion("0.7.0"); - - QCommandLineParser parser; - parser.addPositionalArgument("port", a.translate("main", "port for binding")); - parser.addPositionalArgument("secret", a.translate("main", "secret for binding")); - parser.addHelpOption(); - parser.addVersionOption(); - parser.process(a); - QStringList positionalArguments = parser.positionalArguments(); - - 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(); - token = positionalArguments.takeFirst(); - } - - HMI_DEBUG("HomeScreen","port = %d, token = %s", port, token.toStdString().c_str()); - - // import C++ class to QML - // qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher"); - qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel"); - qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume"); - - ApplicationLauncher *launcher = new ApplicationLauncher(); - QLibWindowmanager* layoutHandler = new QLibWindowmanager(); - if(layoutHandler->init(port,token) != 0){ - exit(EXIT_FAILURE); - } - - AGLScreenInfo screenInfo(layoutHandler->get_scale_factor()); - - if (layoutHandler->requestSurface(graphic_role) != 0) { - exit(EXIT_FAILURE); - } - - 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](json_object *object) { - json_object *jarray = json_object_object_get(object, "ids"); - int arrLen = json_object_array_length(jarray); - for( int idx = 0; idx < arrLen; idx++) - { - QString label = QString(json_object_get_string( json_object_array_get_idx(jarray, idx) )); - HMI_DEBUG("HomeScreen","Event_ScreenUpdated application: %s.", label.toStdString().c_str()); - QMetaObject::invokeMethod(launcher, "setCurrent", Qt::QueuedConnection, Q_ARG(QString, label)); - } - }); - - HomescreenHandler* homescreenHandler = new HomescreenHandler(); - homescreenHandler->init(port, token.toStdString().c_str()); - - QUrl bindingAddress; - bindingAddress.setScheme(QStringLiteral("ws")); - bindingAddress.setHost(QStringLiteral("localhost")); - bindingAddress.setPort(port); - bindingAddress.setPath(QStringLiteral("/api")); - - QUrlQuery query; - query.addQueryItem(QStringLiteral("token"), token); - bindingAddress.setQuery(query); - - // mail.qml loading - QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty("bindingAddress", bindingAddress); - engine.rootContext()->setContextProperty("layoutHandler", layoutHandler); - engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler); - 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.load(QUrl(QStringLiteral("qrc:/main.qml"))); - - QObject *root = engine.rootObjects().first(); - QQuickWindow *window = qobject_cast<QQuickWindow *>(root); - QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface())); - - QList<QObject *> sobjs = engine.rootObjects(); - StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar"); - statusBar->init(bindingAddress, engine.rootContext()); - - return a.exec(); -} diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp deleted file mode 100644 index 5a6dc9a..0000000 --- a/homescreen/src/mastervolume.cpp +++ /dev/null @@ -1,110 +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("control", "Master"); - arg.insert("value", volume); - m_client.call("audiomixer", "volume", arg); - } -} - -void MasterVolume::onClientConnected() -{ - QJsonObject arg; - arg.insert("control", "Master"); - m_client.call("audiomixer", "volume", arg, [this](bool r, const QJsonValue& v) { - if (r && v.isObject()) { - int volume = v.toObject()["response"].toObject()["volume"].toDouble() * 100; - volume = qBound(0, volume, 100); - if (m_volume != volume) - { - m_volume = volume; - emit VolumeChanged(); - } - } - - QJsonObject arg; - arg.insert("event", "volume_changed"); - m_client.call("audiomixer", "subscribe", arg); - }); -} - -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 == "audiomixer/volume_changed") - { - QString ctlName = data.toObject()["control"].toString(); - - if (ctlName != "Master") - return; - - int volume = data.toObject()["value"].toDouble() * 100; - volume = qBound(0, volume, 100); - 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/statusbarmodel.cpp b/homescreen/src/statusbarmodel.cpp deleted file mode 100644 index f54a5f4..0000000 --- a/homescreen/src/statusbarmodel.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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. - * 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 "statusbarmodel.h" -#include "statusbarserver.h" - -#include <QtDBus/QDBusConnection> - -#include "network.h" - -class StatusBarModel::Private -{ -public: - Private(StatusBarModel *parent); - -private: - StatusBarModel *q; -public: - StatusBarServer server; - QString iconList[StatusBarServer::SupportedCount]; - Network *network; - WifiAdapter *wifi_a; -}; - -StatusBarModel::Private::Private(StatusBarModel *parent) - : q(parent) -{ - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/StatusBar", &server); - dbus.registerService("org.agl.homescreen"); - connect(&server, &StatusBarServer::statusIconChanged, [&](int placeholderIndex, const QString &icon) { - if (placeholderIndex < 0 || StatusBarServer::SupportedCount <= placeholderIndex) return; - if (iconList[placeholderIndex] == icon) return; - iconList[placeholderIndex] = icon; - emit q->dataChanged(q->index(placeholderIndex), q->index(placeholderIndex)); - }); - for (int i = 0; i < StatusBarServer::SupportedCount; i++) { - iconList[i] = server.getStatusIcon(i); - } -} - -StatusBarModel::StatusBarModel(QObject *parent) - : QAbstractListModel(parent) - , d(new Private(this)) -{ -} - -StatusBarModel::~StatusBarModel() -{ - delete d; -} - -void StatusBarModel::init(QUrl &url, QQmlContext *context) -{ - d->network = new Network(url, context); - context->setContextProperty("network", d->network); - d->wifi_a = static_cast<WifiAdapter*>(d->network->findAdapter("wifi")); - Q_CHECK_PTR(d->wifi_a); - - QObject::connect(d->wifi_a, &WifiAdapter::wifiConnectedChanged, - this, &StatusBarModel::onWifiConnectedChanged); - QObject::connect(d->wifi_a, &WifiAdapter::wifiEnabledChanged, - this, &StatusBarModel::onWifiEnabledChanged); - QObject::connect(d->wifi_a, &WifiAdapter::wifiStrengthChanged, - this, &StatusBarModel::onWifiStrengthChanged); - - setWifiStatus(d->wifi_a->wifiConnected(), d->wifi_a->wifiEnabled(), d->wifi_a->wifiStrength()); -} - -void StatusBarModel::setWifiStatus(bool connected, bool enabled, int strength) -{ - if (enabled && connected) - if (strength < 30) - d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png")); - else if (strength < 50) - d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_2Bars-01.png")); - else if (strength < 70) - d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_3Bars-01.png")); - else - d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_Full-01.png")); - else - d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png")); -} - -void StatusBarModel::onWifiConnectedChanged(bool connected) -{ - setWifiStatus(connected, d->wifi_a->wifiEnabled(), d->wifi_a->wifiStrength()); -} - -void StatusBarModel::onWifiEnabledChanged(bool enabled) -{ - setWifiStatus(d->wifi_a->wifiConnected(), enabled, d->wifi_a->wifiStrength()); -} - -void StatusBarModel::onWifiStrengthChanged(int strength) -{ - qInfo() << "Strength changed: " << strength; - setWifiStatus(d->wifi_a->wifiConnected(), d->wifi_a->wifiEnabled(), strength); -} - -int StatusBarModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - - // Delete bluetooth because use agl-service-bluetooth. - return StatusBarServer::SupportedCount - 1; -} - -QVariant StatusBarModel::data(const QModelIndex &index, int role) const -{ - QVariant ret; - if (!index.isValid()) - return ret; - - switch (role) { - case Qt::DisplayRole: - if (index.row() == 0){ - ret = d->iconList[StatusBarServer::StatusWifi]; - }else if (index.row() == 1){ - ret = d->iconList[StatusBarServer::StatusCellular]; - } - break; - default: - break; - } - - return ret; -} - -QHash<int, QByteArray> StatusBarModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[Qt::DisplayRole] = "icon"; - return roles; -} diff --git a/homescreen/src/statusbarmodel.h b/homescreen/src/statusbarmodel.h deleted file mode 100644 index 4e31f19..0000000 --- a/homescreen/src/statusbarmodel.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * - * 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. - */ - -#ifndef STATUSBARMODEL_H -#define STATUSBARMODEL_H - -#include <QtCore/QAbstractListModel> -#include <QtQml/QQmlContext> - -class StatusBarModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit StatusBarModel(QObject *parent = NULL); - ~StatusBarModel(); - - void init(QUrl &url, QQmlContext *context); - 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; - - // slots - void onWifiConnectedChanged(bool connected); - void onWifiEnabledChanged(bool enabled); - void onWifiStrengthChanged(int strength); - -private: - class Private; - Private *d; - void setWifiStatus(bool connected, bool enabled, int strength); -}; - -#endif // STATUSBARMODEL_H diff --git a/homescreen/src/statusbarserver.cpp b/homescreen/src/statusbarserver.cpp deleted file mode 100644 index 805c582..0000000 --- a/homescreen/src/statusbarserver.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * - * 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 "statusbarserver.h" -#include "statusbar_adaptor.h" - -class StatusBarServer::Private -{ -public: - Private(StatusBarServer *parent); - QString texts[SupportedCount]; - QString icons[SupportedCount]; - StatusbarAdaptor adaptor; -}; - -StatusBarServer::Private::Private(StatusBarServer *parent) - : adaptor(parent) -{ - icons[0] = QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png"); - icons[1] = QStringLiteral("qrc:/images/Status/HMI_Status_Bluetooth_Inactive-01.png"); - icons[2] = QStringLiteral("qrc:/images/Status/HMI_Status_Signal_NoBars-01.png"); -} - -StatusBarServer::StatusBarServer(QObject *parent) - : QObject(parent) - , d(new Private(this)) -{ -} - -StatusBarServer::~StatusBarServer() -{ - delete d; -} - -QList<int> StatusBarServer::getAvailablePlaceholders() const -{ - QList<int> ret; - for (int i = 0; i < SupportedCount; ++i) { - ret.append(i); - } - return ret; -} - -QString StatusBarServer::getStatusIcon(int placeholderIndex) const -{ - QString ret; - if (-1 < placeholderIndex && placeholderIndex < SupportedCount) - ret = d->icons[placeholderIndex]; - return ret; -} - -void StatusBarServer::setStatusIcon(int placeholderIndex, const QString &icon) -{ - if (-1 < placeholderIndex && placeholderIndex < SupportedCount) { - if (d->icons[placeholderIndex] == icon) return; - d->icons[placeholderIndex] = icon; - emit statusIconChanged(placeholderIndex, icon); - } -} - -QString StatusBarServer::getStatusText(int placeholderIndex) const -{ - QString ret; - if (-1 < placeholderIndex && placeholderIndex < SupportedCount) { - ret = d->texts[placeholderIndex]; - } - return ret; -} - -void StatusBarServer::setStatusText(int placeholderIndex, const QString &text) -{ - if (-1 < placeholderIndex && placeholderIndex < SupportedCount) { - if (d->texts[placeholderIndex] == text) return; - d->texts[placeholderIndex] = text; - emit statusTextChanged(placeholderIndex, text); - } -} diff --git a/homescreen/src/statusbarserver.h b/homescreen/src/statusbarserver.h deleted file mode 100644 index dabf6d3..0000000 --- a/homescreen/src/statusbarserver.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2016 The Qt Company Ltd. - * - * 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. - */ - -#ifndef STATUSBARSERVER_H -#define STATUSBARSERVER_H - -#include <QtCore/QObject> - -class StatusBarServer : public QObject -{ - Q_OBJECT -public: - enum { - StatusWifi = 0, - StatusBluetooth = 1, - StatusCellular = 2, - SupportedCount = 3, - }; - explicit StatusBarServer(QObject *parent = NULL); - ~StatusBarServer(); - - Q_INVOKABLE QList<int> getAvailablePlaceholders() const; - Q_INVOKABLE QString getStatusIcon(int placeholderIndex) const; - Q_INVOKABLE QString getStatusText(int placeholderIndex) const; - -public slots: - void setStatusIcon(int placeholderIndex, const QString &icon); - void setStatusText(int placeholderIndex, const QString &text); - -signals: - void statusIconChanged(int placeholderIndex, const QString &icon); - void statusTextChanged(int placeholderIndex, const QString &text); - -private: - class Private; - Private *d; -}; - -#endif // STATUSBARSERVER_H |