From 381755e4686a08e766316aaf40e8fdfa202d48d4 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Fri, 29 Sep 2017 21:00:25 +0900 Subject: Add homescreen-2017 Add new homescreen-2017 with agl-service-windowmanaeger-2017 and agl-service-homescreen-2017. About this information see JIRA SPEC-871. [PatchSet2] Use aglwgt make package. Delete homescreensimulator and sampleapptimedate beacuse not use them. Change-Id: I402134d0386e76b2127ca95b9b0b48c1721b4086 Signed-off-by: zheng_wenlong --- homescreen/src/appinfo.cpp | 176 ++++++++++++++++++++++++++ homescreen/src/appinfo.h | 68 ++++++++++ homescreen/src/applicationlauncher.cpp | 56 ++++++++ homescreen/src/applicationlauncher.h | 44 +++++++ homescreen/src/applicationmodel.cpp | 155 +++++++++++++++++++++++ homescreen/src/applicationmodel.h | 42 ++++++ homescreen/src/homescreencontrolinterface.cpp | 86 +++++++++++++ homescreen/src/homescreencontrolinterface.h | 52 ++++++++ homescreen/src/homescreenhandler.cpp | 79 ++++++++++++ homescreen/src/homescreenhandler.h | 34 +++++ homescreen/src/layouthandler.cpp | 92 ++++++++++++++ homescreen/src/layouthandler.h | 44 +++++++ homescreen/src/main.cpp | 133 +++++++++++++++++++ homescreen/src/mastervolume.cpp | 33 +++++ homescreen/src/mastervolume.h | 49 +++++++ homescreen/src/popupwidget.cpp | 92 ++++++++++++++ homescreen/src/popupwidget.h | 58 +++++++++ homescreen/src/settingswidget.cpp | 103 +++++++++++++++ homescreen/src/settingswidget.h | 53 ++++++++ homescreen/src/statusbarmodel.cpp | 92 ++++++++++++++ homescreen/src/statusbarmodel.h | 39 ++++++ homescreen/src/statusbarserver.cpp | 91 +++++++++++++ homescreen/src/statusbarserver.h | 49 +++++++ 23 files changed, 1720 insertions(+) create mode 100644 homescreen/src/appinfo.cpp create mode 100644 homescreen/src/appinfo.h create mode 100644 homescreen/src/applicationlauncher.cpp create mode 100644 homescreen/src/applicationlauncher.h create mode 100644 homescreen/src/applicationmodel.cpp create mode 100644 homescreen/src/applicationmodel.h create mode 100644 homescreen/src/homescreencontrolinterface.cpp create mode 100644 homescreen/src/homescreencontrolinterface.h create mode 100644 homescreen/src/homescreenhandler.cpp create mode 100644 homescreen/src/homescreenhandler.h create mode 100644 homescreen/src/layouthandler.cpp create mode 100644 homescreen/src/layouthandler.h create mode 100644 homescreen/src/main.cpp create mode 100644 homescreen/src/mastervolume.cpp create mode 100644 homescreen/src/mastervolume.h create mode 100644 homescreen/src/popupwidget.cpp create mode 100644 homescreen/src/popupwidget.h create mode 100644 homescreen/src/settingswidget.cpp create mode 100644 homescreen/src/settingswidget.h create mode 100644 homescreen/src/statusbarmodel.cpp create mode 100644 homescreen/src/statusbarmodel.h create mode 100644 homescreen/src/statusbarserver.cpp create mode 100644 homescreen/src/statusbarserver.h (limited to 'homescreen/src') diff --git a/homescreen/src/appinfo.cpp b/homescreen/src/appinfo.cpp new file mode 100644 index 0000000..fd9a585 --- /dev/null +++ b/homescreen/src/appinfo.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH + * 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. + */ + +#include "appinfo.h" + +#include + +class AppInfo::Private : public QSharedData +{ +public: + Private(); + Private(const Private &other); + + QString id; + QString version; + int width; + int height; + QString name; + QString description; + QString shortname; + QString author; + QString iconPath; +}; + +AppInfo::Private::Private() + : width(-1) + , height(-1) +{ +} + +AppInfo::Private::Private(const Private &other) + : QSharedData(other) + , id(other.id) + , version(other.version) + , width(other.width) + , height(other.height) + , name(other.name) + , description(other.description) + , shortname(other.shortname) + , author(other.author) + , iconPath(other.iconPath) +{ +} + +AppInfo::AppInfo() + : d(new Private) +{ +} + +AppInfo::AppInfo(const QString &icon, const QString &name, const QString &id) + : d(new Private) +{ + d->iconPath = icon; + d->name = name; + d->id = id; +} + +AppInfo::AppInfo(const AppInfo &other) + : d(other.d) +{ +} + +AppInfo::~AppInfo() +{ +} + +AppInfo &AppInfo::operator =(const AppInfo &other) +{ + d = other.d; + return *this; +} + +QString AppInfo::id() const +{ + return d->id; +} + +QString AppInfo::version() const +{ + return d->version; +} + +int AppInfo::width() const +{ + return d->width; +} + +int AppInfo::height() const +{ + return d->height; +} + +QString AppInfo::name() const +{ + return d->name; +} + +QString AppInfo::description() const +{ + return d->description; +} + +QString AppInfo::shortname() const +{ + return d->shortname; +} + +QString AppInfo::author() const +{ + return d->author; +} + +QString AppInfo::iconPath() const +{ + return d->iconPath; +} + +void AppInfo::read(const QJsonObject &json) +{ + d->id = json["id"].toString(); + d->version = json["version"].toString(); + d->width = json["width"].toInt(); + d->height = json["height"].toInt(); + d->name = json["name"].toString(); + d->description = json["description"].toString(); + d->shortname = json["shortname"].toString(); + d->author = json["author"].toString(); + d->iconPath = json["iconPath"].toString(); +} + +QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo) +{ + argument.beginStructure(); + argument << appInfo.d->id; + argument << appInfo.d->version; + argument << appInfo.d->width; + argument << appInfo.d->height; + argument << appInfo.d->name; + argument << appInfo.d->description; + argument << appInfo.d->shortname; + argument << appInfo.d->author; + argument << appInfo.d->iconPath; + argument.endStructure(); + + return argument; +} + +const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo) +{ + argument.beginStructure(); + argument >> appInfo.d->id; + argument >> appInfo.d->version; + argument >> appInfo.d->width; + argument >> appInfo.d->height; + argument >> appInfo.d->name; + argument >> appInfo.d->description; + argument >> appInfo.d->shortname; + argument >> appInfo.d->author; + argument >> appInfo.d->iconPath; + argument.endStructure(); + return argument; +} diff --git a/homescreen/src/appinfo.h b/homescreen/src/appinfo.h new file mode 100644 index 0000000..0d98b10 --- /dev/null +++ b/homescreen/src/appinfo.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH + * 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 APPINFO_H +#define APPINFO_H + +#include +#include + +class AppInfo +{ + Q_GADGET + Q_PROPERTY(QString id READ id) + Q_PROPERTY(QString version READ version) + Q_PROPERTY(int width READ width) + Q_PROPERTY(int height READ height) + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString description READ description) + Q_PROPERTY(QString shortname READ shortname) + Q_PROPERTY(QString author READ author) + Q_PROPERTY(QString iconPath READ iconPath) +public: + AppInfo(); + AppInfo(const QString &icon, const QString &name, const QString &id); + AppInfo(const AppInfo &other); + virtual ~AppInfo(); + AppInfo &operator =(const AppInfo &other); + void swap(AppInfo &other) { qSwap(d, other.d); } + + QString id() const; + QString version() const; + int width() const; + int height() const; + QString name() const; + QString description() const; + QString shortname() const; + QString author() const; + QString iconPath() const; + + void read(const QJsonObject &json); + + friend QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo); + friend const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo); + +private: + class Private; + QSharedDataPointer d; +}; + +Q_DECLARE_SHARED(AppInfo) +Q_DECLARE_METATYPE(AppInfo) +Q_DECLARE_METATYPE(QList) + +#endif // APPINFO_H diff --git a/homescreen/src/applicationlauncher.cpp b/homescreen/src/applicationlauncher.cpp new file mode 100644 index 0000000..8358107 --- /dev/null +++ b/homescreen/src/applicationlauncher.cpp @@ -0,0 +1,56 @@ +/* + * 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 "applicationlauncher.h" + +#include "afm_user_daemon_proxy.h" + +#include + +extern org::AGL::afm::user *afm_user_daemon_proxy; + +ApplicationLauncher::ApplicationLauncher(QObject *parent) + : QObject(parent) +{ +} + +int ApplicationLauncher::launch(const QString &application) +{ + int result = -1; + qDebug() << "ApplicationLauncher launch" << application; + + result = afm_user_daemon_proxy->start(application).value().toInt(); + qDebug() << "ApplicationLauncher pid:" << result; + + if (result > 1) { + setCurrent(application); + } + + return result; +} + +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 new file mode 100644 index 0000000..a31e663 --- /dev/null +++ b/homescreen/src/applicationlauncher.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef APPLICATIONLAUNCHER_H +#define APPLICATIONLAUNCHER_H + +#include + +class ApplicationLauncher : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString current READ current WRITE setCurrent NOTIFY currentChanged) +public: + explicit ApplicationLauncher(QObject *parent = NULL); + + QString current() const; + +signals: + void newAppRequestsToBeVisible(int pid); + void currentChanged(const QString ¤t); + +public slots: + int launch(const QString &application); + void setCurrent(const QString ¤t); + +private: + QString m_current; +}; + +#endif // APPLICATIONLAUNCHER_H diff --git a/homescreen/src/applicationmodel.cpp b/homescreen/src/applicationmodel.cpp new file mode 100644 index 0000000..2c51b98 --- /dev/null +++ b/homescreen/src/applicationmodel.cpp @@ -0,0 +1,155 @@ +/* + * 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 "applicationmodel.h" +#include "appinfo.h" + +#include + +#include +#include + +#include "afm_user_daemon_proxy.h" + +extern org::AGL::afm::user *afm_user_daemon_proxy; + +class ApplicationModel::Private +{ +public: + Private(); + + QList data; +}; + +namespace { + QString get_icon_name(QJsonObject const &i) + { + QString icon = i["id"].toString().split("@").front(); + if (icon == "hvac" || icon == "poi") { + icon = icon.toUpper(); + } else if (icon == "mediaplayer") { +// icon = "Multimedia"; + icon = "MediaPlayer"; + } else { + icon[0] = icon[0].toUpper(); + } + return icon; + } +} + +ApplicationModel::Private::Private() +{ + QString apps = afm_user_daemon_proxy->runnables(QStringLiteral("")); + QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8()); + for (auto const &app : japps.array()) { + QJsonObject const &jso = app.toObject(); + auto const name = jso["name"].toString(); + auto const id = jso["id"].toString(); + auto const icon = get_icon_name(jso); + + // HomeScreenは除外する + if (name != "homescreen-2017") { + this->data.append(AppInfo(icon, name, id)); + } + + qDebug() << "name:" << name << "icon:" << icon << "id:" << id; + } +} + +ApplicationModel::ApplicationModel(QObject *parent) + : QAbstractListModel(parent) + , d(new Private()) +{ +} + +ApplicationModel::~ApplicationModel() +{ + delete this->d; +} + +int ApplicationModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return this->d->data.count(); +} + +QVariant ApplicationModel::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()].iconPath(); + 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 ApplicationModel::roleNames() const +{ + QHash roles; + roles[Qt::DecorationRole] = "icon"; + roles[Qt::DisplayRole] = "name"; + roles[Qt::UserRole] = "id"; + return roles; +} + +QString ApplicationModel::id(int i) const +{ + return data(index(i), Qt::UserRole).toString(); +} + +QString ApplicationModel::name(int i) const +{ + return data(index(i), Qt::DisplayRole).toString(); +} + +void ApplicationModel::move(int from, int to) +{ + QModelIndex parent; + if (to < 0 || to > rowCount()) return; + if (from < to) { + if (!beginMoveRows(parent, from, from, parent, to + 1)) { + qDebug() << from << to << false; + return; + } + d->data.move(from, to); + endMoveRows(); + } else if (from > to) { + if (!beginMoveRows(parent, from, from, parent, to)) { + qDebug() << from << to << false; + return; + } + d->data.move(from, to); + endMoveRows(); + } else { + qDebug() << from << to << false; + } +} diff --git a/homescreen/src/applicationmodel.h b/homescreen/src/applicationmodel.h new file mode 100644 index 0000000..64f9c53 --- /dev/null +++ b/homescreen/src/applicationmodel.h @@ -0,0 +1,42 @@ +/* + * 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 APPLICATIONMODEL_H +#define APPLICATIONMODEL_H + +#include + +class ApplicationModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ApplicationModel(QObject *parent = nullptr); + ~ApplicationModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + Q_INVOKABLE QString id(int index) const; + Q_INVOKABLE QString name(int index) const; + Q_INVOKABLE void move(int from, int to); + +private: + class Private; + Private *d; +}; + +#endif // APPLICATIONMODEL_H diff --git a/homescreen/src/homescreencontrolinterface.cpp b/homescreen/src/homescreencontrolinterface.cpp new file mode 100644 index 0000000..ecbe8e4 --- /dev/null +++ b/homescreen/src/homescreencontrolinterface.cpp @@ -0,0 +1,86 @@ +/* + * 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 "afm_user_daemon_proxy.h" +#include "homescreencontrolinterface.h" + +extern org::AGL::afm::user *afm_user_daemon_proxy; + +HomeScreenControlInterface::HomeScreenControlInterface(QObject *parent) : + QObject(parent), + mp_homeScreenAdaptor(0) +{ + // publish dbus homescreen interface + mp_homeScreenAdaptor = new HomescreenAdaptor((QObject*)this); + + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/HomeScreen", this); + dbus.registerService("org.agl.homescreen"); +} + +QList HomeScreenControlInterface::getAllSurfacesOfProcess(int pid) +{ + qDebug("getAllSurfacesOfProcess %d", pid); + return newRequestGetAllSurfacesOfProcess(pid); +} + +int HomeScreenControlInterface::getSurfaceStatus(int surfaceId) +{ + qDebug("getSurfaceStatus %d", surfaceId); + return newRequestGetSurfaceStatus(surfaceId); +} + +void HomeScreenControlInterface::hardKeyPressed(int key) +{ + int pid = -1; + + switch (key) + { + case InputEvent::HARDKEY_NAV: + qDebug("hardKeyPressed NAV key pressed!"); + pid = afm_user_daemon_proxy->start("navigation@0.1").value().toInt(); + qDebug("pid: %d", pid); + emit newRequestsToBeVisibleApp(pid); + break; + case InputEvent::HARDKEY_MEDIA: + qDebug("hardKeyPressed MEDIA key pressed!"); + pid = afm_user_daemon_proxy->start("media@0.1").value().toInt(); + qDebug("pid: %d", pid); + emit newRequestsToBeVisibleApp(pid); + break; + default: + qDebug("hardKeyPressed %d", key); + break; + } +} + +void HomeScreenControlInterface::renderSurfaceToArea(int surfaceId, int layoutArea) +{ + qDebug("renderSurfaceToArea %d %d", surfaceId, layoutArea); + emit newRequestRenderSurfaceToArea(surfaceId, layoutArea); +} + +bool HomeScreenControlInterface::renderAppToAreaAllowed(int appCategory, int layoutArea) +{ + qDebug("renderAppToAreaAllowed %d %d", appCategory, layoutArea); + return true; //TODO: ask policy manager +} + +void HomeScreenControlInterface::requestSurfaceIdToFullScreen(int surfaceId) +{ + qDebug("requestSurfaceIdToFullScreen %d", surfaceId); + emit newRequestSurfaceIdToFullScreen(surfaceId); +} diff --git a/homescreen/src/homescreencontrolinterface.h b/homescreen/src/homescreencontrolinterface.h new file mode 100644 index 0000000..b68a2b2 --- /dev/null +++ b/homescreen/src/homescreencontrolinterface.h @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef HOMESCREENCONTROLINTERFACE_H +#define HOMESCREENCONTROLINTERFACE_H + +#include +#include "include/homescreen.hpp" +#include "homescreen_adaptor.h" + +class HomeScreenControlInterface : public QObject +{ + Q_OBJECT +public: + explicit HomeScreenControlInterface(QObject *parent = 0); + +signals: + void newRequestsToBeVisibleApp(int pid); + + QList newRequestGetAllSurfacesOfProcess(int pid); + int newRequestGetSurfaceStatus(int surfaceId); + void newRequestRenderSurfaceToArea(int surfaceId, int layoutArea); + bool newRequestRenderSurfaceToAreaAllowed(int surfaceId, int layoutArea); + void newRequestSurfaceIdToFullScreen(int surfaceId); + +//from homescreen_adaptor.h +public Q_SLOTS: // METHODS + QList getAllSurfacesOfProcess(int pid); + int getSurfaceStatus(int surfaceId); + void hardKeyPressed(int key); + void renderSurfaceToArea(int surfaceId, int layoutArea); + bool renderAppToAreaAllowed(int appCategory, int layoutArea); + void requestSurfaceIdToFullScreen(int surfaceId); + +private: + HomescreenAdaptor *mp_homeScreenAdaptor; +}; + +#endif // HOMESCREENCONTROLINTERFACE_H diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp new file mode 100644 index 0000000..2a69034 --- /dev/null +++ b/homescreen/src/homescreenhandler.cpp @@ -0,0 +1,79 @@ +#include "homescreenhandler.h" +#include + +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(HomescreenHandler::onEv_static, HomescreenHandler::onRep_static); +// mp_hs->subscribe(LibHomeScreen::event_list[0]); +// mp_hs->subscribe(LibHomeScreen::event_list[1]); + + mp_hs->registerCallback(nullptr, HomescreenHandler::onRep_static); + + mp_hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [this](const char* display_message){ + qDebug("set_event_handler Event_OnScreenMessage display_message = %s", display_message); + }); + + mp_hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [this](const char* application_name){ + if(strcmp(application_name, "Home") == 0){ + emit this->homeButton(); + } + }); + +} + +void HomescreenHandler::tapShortcut(QString application_name) +{ + qDebug("tapShortcut %s", qPrintable(application_name)); + mp_hs->tapShortcut(application_name.toStdString().c_str()); +} + +void HomescreenHandler::onRep_static(struct json_object* reply_contents) +{ + static_cast(HomescreenHandler::myThis)->onRep(reply_contents); +} + +void HomescreenHandler::onEv_static(const string& event, struct json_object* event_contents) +{ + static_cast(HomescreenHandler::myThis)->onEv(event, event_contents); +} + +void HomescreenHandler::onRep(struct json_object* reply_contents) +{ + const char* str = json_object_to_json_string(reply_contents); + qDebug("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); + qDebug("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); + + qDebug("display_message = %s", display_message); + } +} diff --git a/homescreen/src/homescreenhandler.h b/homescreen/src/homescreenhandler.h new file mode 100644 index 0000000..55d14fd --- /dev/null +++ b/homescreen/src/homescreenhandler.h @@ -0,0 +1,34 @@ +#ifndef HOMESCREENHANDLER_H +#define HOMESCREENHANDLER_H + +#include +#include +#include + +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_name); + + 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 homeButton(); + +private: + LibHomeScreen *mp_hs; +}; + +#endif // HOMESCREENHANDLER_H diff --git a/homescreen/src/layouthandler.cpp b/homescreen/src/layouthandler.cpp new file mode 100644 index 0000000..d16b5e7 --- /dev/null +++ b/homescreen/src/layouthandler.cpp @@ -0,0 +1,92 @@ +/* + * 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 +#include "layouthandler.h" + +#define HOMESCREEN "HomeScreen" + +LayoutHandler::LayoutHandler(QObject *parent) : + QObject(parent), + mp_wm(NULL) +{ + isActived = false; +} + +LayoutHandler::~LayoutHandler() +{ +} + +void LayoutHandler::init(int port, const char* token) +{ + if (mp_wm != NULL) exit(EXIT_FAILURE); + + mp_wm = new LibWindowmanager(); + + if (mp_wm->init(port, token) != 0) { + exit(EXIT_FAILURE); + } + + mp_wm->requestSurface(HOMESCREEN); + + mp_wm->set_event_handler(LibWindowmanager::Event_Active, [this](const char* label) { + this->isActived = true; + qDebug("Surface %s got activated!", label); + }); + + mp_wm->set_event_handler(LibWindowmanager::Event_Inactive, [this](const char* label) { + this->isActived = false; + qDebug("Surface %s got deactivated!", label); + }); + + mp_wm->set_event_handler(LibWindowmanager::Event_Visible, [](char const *label) { + qDebug("Surface %s got visibled!", label); + }); + + mp_wm->set_event_handler(LibWindowmanager::Event_Invisible, [](char const *label) { + qDebug("Surface %s got invisibled!", label); + }); + + mp_wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [this](const char* label) { + qDebug("Surface %s got syncDraw!", label); + qDebug("Try to endDraw Surface %s Start!", label); + this->mp_wm->endDraw(HOMESCREEN); + qDebug("Try to endDraw Surface %s End!", label); + }); + + mp_wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [](char const *label) { + qDebug("Surface %s got flushDraw!", label); + }); +} + +void LayoutHandler::activateSurface() +{ + mp_wm->activateSurface(HOMESCREEN); +} + +void LayoutHandler::slotActivateSurface() +{ + if(isActived) + return; + qDebug(__FUNCTION__); + this->activateSurface(); +} + +void LayoutHandler::slotHomeButton() +{ + qDebug(__FUNCTION__); + this->activateSurface(); +} diff --git a/homescreen/src/layouthandler.h b/homescreen/src/layouthandler.h new file mode 100644 index 0000000..4b9e510 --- /dev/null +++ b/homescreen/src/layouthandler.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef LAYOUTHANDLER_H +#define LAYOUTHANDLER_H + +#include +#include + +class LayoutHandler : public QObject +{ + Q_OBJECT +public: + explicit LayoutHandler(QObject *parent = 0); + ~LayoutHandler(); + + void init(int port, const char* token); + void activateSurface(); + +signals: + +public slots: + void slotActivateSurface(); + void slotHomeButton(); + +private: + LibWindowmanager* mp_wm; + bool isActived; +}; + +#endif // LAYOUTHANDLER_H diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp new file mode 100644 index 0000000..7c78166 --- /dev/null +++ b/homescreen/src/main.cpp @@ -0,0 +1,133 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include "layouthandler.h" +#include "homescreencontrolinterface.h" +#include "applicationlauncher.h" +#include "statusbarmodel.h" +#include "applicationmodel.h" +#include "appinfo.h" +#include "afm_user_daemon_proxy.h" +#include "mastervolume.h" +#include "homescreenhandler.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 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"; + + if (positionalArguments.length() == 2) { + port = positionalArguments.takeFirst().toInt(); + token = positionalArguments.takeFirst(); + } + + qDebug("HomeScreen port = %d, token = %s", port, token.toStdString().c_str()); + + // import C++ class to QML + qmlRegisterType("HomeScreen", 1, 0, "ApplicationLauncher"); + qmlRegisterType("Home", 1, 0, "ApplicationModel"); + qmlRegisterType("HomeScreen", 1, 0, "StatusBarModel"); + qmlRegisterType("MasterVolume", 1, 0, "MasterVolume"); + + // DBus + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); + + LayoutHandler* layoutHandler = new LayoutHandler(); + layoutHandler->init(port, token.toStdString().c_str()); + + HomescreenHandler* homescreenHandler = new HomescreenHandler(); + homescreenHandler->init(port, token.toStdString().c_str()); + +// HomeScreenControlInterface* hsci = new HomeScreenControlInterface(); + +// QObject::connect(hsci, SIGNAL(newRequestGetSurfaceStatus(int)), layoutHandler, SLOT(requestGetSurfaceStatus(int))); +// QObject::connect(hsci, SIGNAL(newRequestsToBeVisibleApp(int)), layoutHandler, SLOT(makeMeVisible(int))); +// QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToArea(int, int)), layoutHandler, SLOT(requestRenderSurfaceToArea(int,int))); +// QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToAreaAllowed(int, int)), layoutHandler, SLOT(requestRenderSurfaceToAreaAllowed(int,int))); +// QObject::connect(hsci, SIGNAL(newRequestSurfaceIdToFullScreen(int)), layoutHandler, SLOT(requestSurfaceIdToFullScreen(int))); + + // mail.qml loading + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("layoutHandler", layoutHandler); + engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + QObject *root = engine.rootObjects().first(); + QQuickWindow *window = qobject_cast(root); + QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface())); + QObject::connect(homescreenHandler, SIGNAL(homeButton()), layoutHandler, SLOT(slotHomeButton())); + +// layoutHandler->activateSurface(); + + // Connect C++ / QML +// QList mobjs = engine.rootObjects(); +// MasterVolume *mv = mobjs.first()->findChild("mv"); +// engine.rootContext()->setContextProperty("MasterVolume", mv); +// QObject::connect(mv, SIGNAL(sliderVolumeChanged(int)), client, SLOT(incDecVolume(int))); +// QObject::connect(client, SIGNAL(volumeExternallyChanged(int)), mv, SLOT(changeExternalVolume(int))); + + return a.exec(); +} diff --git a/homescreen/src/mastervolume.cpp b/homescreen/src/mastervolume.cpp new file mode 100644 index 0000000..46985ee --- /dev/null +++ b/homescreen/src/mastervolume.cpp @@ -0,0 +1,33 @@ +/* + * 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 + +void MasterVolume::setVolume(pa_volume_t volume) +{ + int volume_delta = volume - m_volume; + m_volume = volume; + emit sliderVolumeChanged(volume_delta); + +} + +void MasterVolume::changeExternalVolume(int volume) +{ + m_volume = volume; + emit volumeChanged(); +} diff --git a/homescreen/src/mastervolume.h b/homescreen/src/mastervolume.h new file mode 100644 index 0000000..edcdd8c --- /dev/null +++ b/homescreen/src/mastervolume.h @@ -0,0 +1,49 @@ +/* + * 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 +#include +#include + +#include + +class MasterVolume : public QObject +{ + Q_OBJECT + Q_PROPERTY (uint32_t volume READ getVolume WRITE setVolume NOTIFY volumeChanged) + + public: + MasterVolume(QObject *parent = 0) + : QObject(parent), m_volume(32768) + { + } + + ~MasterVolume() {} + + uint32_t getVolume() const { return m_volume; } + void setVolume(pa_volume_t volume); + + public slots: + void changeExternalVolume(int volume); + + signals: + void volumeChanged(void); + void sliderVolumeChanged(int volume_delta); + void externalVolumeChanged(uint32_t volume); + + private: + uint32_t m_volume; +}; diff --git a/homescreen/src/popupwidget.cpp b/homescreen/src/popupwidget.cpp new file mode 100644 index 0000000..1f062f1 --- /dev/null +++ b/homescreen/src/popupwidget.cpp @@ -0,0 +1,92 @@ +/* + * 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 "popupwidget.h" +#include "ui_popupwidget.h" +#include + +PopupWidget::PopupWidget(QWidget *parent) : + QWidget(parent), + mp_ui(new Ui::PopupWidget), + mp_popupAdaptor(0), + m_sendComboBoxChoice(false) +{ + // publish dbus popup interface + mp_popupAdaptor = new PopupAdaptor((QObject*)this); + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/Popup", this); + dbus.registerService("org.agl.homescreen"); + + // no window decoration + setWindowFlags(Qt::FramelessWindowHint); + + mp_ui->setupUi(this); + + this->close(); +} + +PopupWidget::~PopupWidget() +{ + delete mp_popupAdaptor; + delete mp_ui; +} + +void PopupWidget::updateColorScheme() +{ + QSettings settings; + QSettings settings_cs(QApplication::applicationDirPath() + + "/colorschemes/" + + settings.value("systemsettings/colorscheme", "default").toString() + + "/" + + QString::number(settings.value("systemsettings/proximityobjectdetected", false).toBool()) + + "/" + + QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) + + ".ini", + QSettings::IniFormat); + + mp_ui->widget_popup->setStyleSheet(settings_cs.value(QString("PopupWidget/widget_popup_css")).toString()); + mp_ui->label_text->setStyleSheet(settings_cs.value(QString("PopupWidget/label_text_css")).toString()); +} + +void PopupWidget::showPopup(int /*type*/, const QString &text) +{ + m_sendComboBoxChoice = false; + mp_ui->comboBox_choice->hide(); + this->show(); + this->raise(); + mp_ui->label_text->setText(text); +} + +void PopupWidget::showPopupComboBox(const QString &text, const QStringList &choices) +{ + mp_ui->comboBox_choice->clear(); + m_sendComboBoxChoice = true; + mp_ui->comboBox_choice->addItems(choices); + mp_ui->comboBox_choice->show(); + this->show(); + this->raise(); + mp_ui->label_text->setText(text); +} + +void PopupWidget::on_pushButton_OK_clicked() +{ + if (m_sendComboBoxChoice) + { + emit comboBoxResult(mp_ui->comboBox_choice->currentText()); + m_sendComboBoxChoice = false; + } + this->close(); +} diff --git a/homescreen/src/popupwidget.h b/homescreen/src/popupwidget.h new file mode 100644 index 0000000..7f3aaa8 --- /dev/null +++ b/homescreen/src/popupwidget.h @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#ifndef POPUPWIDGET_H +#define POPUPWIDGET_H + +#include +#include +#include "popup_adaptor.h" + +namespace Ui { +class PopupWidget; +} + +class PopupWidget : public QWidget +{ + Q_OBJECT + +public: + explicit PopupWidget(QWidget *parent = 0); + ~PopupWidget(); +public slots: + void updateColorScheme(); + + // from popup_adaptor.h +public Q_SLOTS: // METHODS + void showPopup(int /*type*/, const QString &text); + void showPopupComboBox(const QString &text, const QStringList &choices); + +private slots: + void on_pushButton_OK_clicked(); + +signals: + void comboBoxResult(QString choice); + +private: + Ui::PopupWidget *mp_ui; + + PopupAdaptor *mp_popupAdaptor; + bool m_sendComboBoxChoice; + // for showPupupFor LayoutSelection + //QList m_pushButtons; +}; + +#endif // POPUPWIDGET_H diff --git a/homescreen/src/settingswidget.cpp b/homescreen/src/settingswidget.cpp new file mode 100644 index 0000000..1629bf0 --- /dev/null +++ b/homescreen/src/settingswidget.cpp @@ -0,0 +1,103 @@ +/* + * 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 "settingswidget.h" +#include "ui_settingswidget.h" +#include +#include + +SettingsWidget::SettingsWidget(QWidget *parent) : + QWidget(parent), + mp_ui(new Ui::SettingsWidget), + mp_translator(0) +{ + // no window decoration + setWindowFlags(Qt::FramelessWindowHint); + + // multi-language support + mp_translator = new QTranslator(); + mp_translator->load("homescreen_en_US.qm", ":/translations"); // TODO: read from system + QApplication::instance()->installTranslator(mp_translator); + + mp_ui->setupUi(this); + + mp_ui->comboBox_language->addItem(QString("English"), QVariant("homescreen_en_US.qm")); // TODO: make this configurable + mp_ui->comboBox_language->addItem(QString("Deutsch"), QVariant("homescreen_de_DE.qm")); + mp_ui->comboBox_language->addItem(QString("日本語"), QVariant("homescreen_ja_JP.qm")); + + mp_ui->comboBox_colorScheme->addItem(QString("Default"), QVariant("default")); // TODO: make this configurable + mp_ui->comboBox_colorScheme->addItem(QString("Demo 1"), QVariant("demo1")); + mp_ui->comboBox_colorScheme->addItem(QString("Demo 2"), QVariant("demo2")); + + QSettings settings; + mp_ui->comboBox_language->setCurrentIndex(settings.value("systemsettings/language", 0).toInt()); + mp_ui->comboBox_colorScheme->setCurrentIndex(settings.value("systemsettings/colorschemeindex", 0).toInt()); +} + +SettingsWidget::~SettingsWidget() +{ + delete mp_translator; + delete mp_ui; +} + +void SettingsWidget::updateColorScheme() +{ + QSettings settings; + QSettings settings_cs(QApplication::applicationDirPath() + + "/colorschemes/" + + settings.value("systemsettings/colorscheme", "default").toString() + + "/" + + QString::number(settings.value("systemsettings/proximityobjectdetected", false).toBool()) + + "/" + + QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) + + ".ini", + QSettings::IniFormat); + + mp_ui->widget_background->setStyleSheet(settings_cs.value("SettingsWidget/widget_background_css").toString()); + mp_ui->comboBox_language->setStyleSheet(settings_cs.value("SettingsWidget/comboBox_language_css").toString()); + mp_ui->comboBox_colorScheme->setStyleSheet(settings_cs.value("SettingsWidget/comboBox_colorScheme_css").toString()); + mp_ui->widget_settingsIcon->setStyleSheet(settings_cs.value("SettingsWidget/widget_settingsIcon_css").toString()); +} + +void SettingsWidget::changeEvent(QEvent* event) +{ + if (QEvent::LanguageChange == event->type()) + { + mp_ui->retranslateUi(this); + } + + QWidget::changeEvent(event); +} + +void SettingsWidget::on_comboBox_language_currentIndexChanged(const QString &) +{ + if (0 != mp_translator) + mp_translator->load(mp_ui->comboBox_language->currentData().toString(), ":/translations"); + + QSettings settings; + settings.setValue("systemsettings/language", mp_ui->comboBox_language->currentIndex()); +} + +void SettingsWidget::on_comboBox_colorScheme_currentIndexChanged(const QString &) +{ + QSettings settings; + settings.setValue("systemsettings/colorscheme", mp_ui->comboBox_colorScheme->currentData().toString()); + settings.setValue("systemsettings/colorschemeindex", mp_ui->comboBox_colorScheme->currentIndex()); + // make sure that everything is written to the settings file before continuing + settings.sync(); + + emit colorSchemeChanged(); +} diff --git a/homescreen/src/settingswidget.h b/homescreen/src/settingswidget.h new file mode 100644 index 0000000..75bb383 --- /dev/null +++ b/homescreen/src/settingswidget.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef SETTINGSWIDGET_H +#define SETTINGSWIDGET_H + +#include +#include + +namespace Ui { +class SettingsWidget; +} + +class SettingsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit SettingsWidget(QWidget *parent = 0); + ~SettingsWidget(); +public slots: + void updateColorScheme(); + +protected: + // called when the translator loaded a new language set + void changeEvent(QEvent* event); + +private slots: + void on_comboBox_language_currentIndexChanged(const QString &); + void on_comboBox_colorScheme_currentIndexChanged(const QString &); + +signals: + void colorSchemeChanged(void); + +private: + Ui::SettingsWidget *mp_ui; + QTranslator *mp_translator; +}; + +#endif // SETTINGSWIDGET_H diff --git a/homescreen/src/statusbarmodel.cpp b/homescreen/src/statusbarmodel.cpp new file mode 100644 index 0000000..5438e89 --- /dev/null +++ b/homescreen/src/statusbarmodel.cpp @@ -0,0 +1,92 @@ +/* + * 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. + */ + +#include "statusbarmodel.h" +#include "statusbarserver.h" + +#include + +class StatusBarModel::Private +{ +public: + Private(StatusBarModel *parent); + +private: + StatusBarModel *q; +public: + StatusBarServer server; + QString iconList[StatusBarServer::SupportedCount]; +}; + +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; +} + +int StatusBarModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return StatusBarServer::SupportedCount; +} + +QVariant StatusBarModel::data(const QModelIndex &index, int role) const +{ + QVariant ret; + if (!index.isValid()) + return ret; + + switch (role) { + case Qt::DisplayRole: + ret = d->iconList[index.row()]; + break; + default: + break; + } + + return ret; +} + +QHash StatusBarModel::roleNames() const +{ + QHash roles; + roles[Qt::DisplayRole] = "icon"; + return roles; +} diff --git a/homescreen/src/statusbarmodel.h b/homescreen/src/statusbarmodel.h new file mode 100644 index 0000000..8d6a70b --- /dev/null +++ b/homescreen/src/statusbarmodel.h @@ -0,0 +1,39 @@ +/* + * 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 + +class StatusBarModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit StatusBarModel(QObject *parent = NULL); + ~StatusBarModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + +private: + class Private; + Private *d; +}; + +#endif // STATUSBARMODEL_H diff --git a/homescreen/src/statusbarserver.cpp b/homescreen/src/statusbarserver.cpp new file mode 100644 index 0000000..805c582 --- /dev/null +++ b/homescreen/src/statusbarserver.cpp @@ -0,0 +1,91 @@ +/* + * 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 StatusBarServer::getAvailablePlaceholders() const +{ + QList 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 new file mode 100644 index 0000000..a5b89e5 --- /dev/null +++ b/homescreen/src/statusbarserver.h @@ -0,0 +1,49 @@ +/* + * 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 + +class StatusBarServer : public QObject +{ + Q_OBJECT +public: + enum { + SupportedCount = 3, + }; + explicit StatusBarServer(QObject *parent = NULL); + ~StatusBarServer(); + + Q_INVOKABLE QList 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 -- cgit 1.2.3-korg