on xenial help sign in
Replace own config parser with libdeviceinfo

This replaces our own "hacky" parser with the new "global" libdeviceinfo, this give us a central config place for different devices.

commit752546e8c2f8654834b42ba871296fa5764c01b2 authorMarius Gripsgard <marius@ubports.com> dateWed 18 Sep 2019, 01:36 (7 years ago) parentbc6776d
24 files changed+196−344
CMakeLists.txt+1 debian/control+1−1 plugins/Utils/CMakeLists.txt+4−2 plugins/Utils/deviceconfig.cpp+113 plugins/Utils/deviceconfigparser.h → plugins/Utils/deviceconfig.h+9−16 plugins/Utils/deviceconfigparser.cpp−176 plugins/Utils/plugin.cpp+2−2 qml/DeviceConfiguration.qml+26−15 qml/DisabledScreenNotice.qml+1−1 qml/OrientedShell.qml+4−1 src/ApplicationArguments.h−13 src/CMakeLists.txt+1−5 src/ShellApplication.cpp−15 src/ShellApplication.h−1 src/UnityCommandLineParser.cpp−5 src/UnityCommandLineParser.h−2 tests/mocks/Utils/CMakeLists.txt+4−2 tests/mocks/Utils/plugin.cpp+2−2 tests/plugins/Utils/CMakeLists.txt−1 tests/plugins/Utils/DeviceConfigParserTest.cpp−76 tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml+3−3 tests/qmltests/tst_DeviceConfiguration.qml+23−2 tests/qmltests/tst_DisabledScreenNotice.qml+1−3 tests/qmltests/tst_OrientedShell.qml+1
CMakeLists.txt+1
@@ -74,6 +74,7 @@ find_package(Qt5Svg 5.6 REQUIRED)
7474find_package(Qt5Network 5.6 REQUIRED)
7575find_package(Qt5Xml 5.6 REQUIRED)
7676
77+pkg_check_modules(DEVICEINFO REQUIRED deviceinfo)
7778pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
7879pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
7980pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
debian/control+1−1
@@ -15,7 +15,6 @@ Build-Depends: cmake,
1515 gdb,
1616 graphviz,
1717 gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),
18− libandroid-properties-dev,
1918 libconnectivity-qt1-dev (>= 0.7.1),
2019 libevdev-dev,
2120 libgeonames-dev (>= 0.2),
@@ -74,6 +73,7 @@ Build-Depends: cmake,
7473 qtdeclarative5-ubuntu-settings-components (>= 0.11),
7574 ttf-ubuntu-font-family,
7675 xvfb,
76+ libdeviceinfo-dev,
7777Standards-Version: 3.9.4
7878Homepage: http://launchpad.net/unity
7979# If you aren't a member of ~unity-team but need to upload
plugins/Utils/CMakeLists.txt+4−2
@@ -7,6 +7,7 @@ include_directories(
77 SYSTEM
88 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
99 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
10+ ${DEVICEINFO_INCLUDE_DIRS}
1011)
1112
1213set(QMLPLUGIN_SRC
@@ -30,7 +31,7 @@ set(QMLPLUGIN_SRC
3031 windowstatestorage.cpp
3132 timezoneFormatter.cpp
3233 inputeventgenerator.cpp
33− deviceconfigparser.cpp
34+ deviceconfig.cpp
3435 globalfunctions.cpp
3536 URLDispatcher.cpp
3637 tabfocusfence.cpp
@@ -45,7 +46,8 @@ add_library(Utils-qml SHARED
4546
4647target_link_libraries(Utils-qml
4748 Qt5::Qml Qt5::Quick Qt5::DBus Qt5::Network Qt5::Gui Qt5::Sql Qt5::Concurrent
48− )
49+ ${DEVICEINFO_LDFLAGS}
50+)
4951
5052# Because this is an internal support library, we want
5153# to expose all symbols in it. Consider changing this
plugins/Utils/deviceconfig.cppnew file+113
@@ -0,0 +1,113 @@
1+/*
2+ * Copyright 2016 Canonical Ltd.
3+ * 2019 UBports foundation.
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU Lesser General Public License as published by
7+ * the Free Software Foundation; version 3.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#include "deviceconfig.h"
19+
20+#include <deviceinfo.h>
21+#include <QDebug>
22+
23+DeviceConfig::DeviceConfig(QObject *parent):
24+ QObject(parent),
25+ m_info(std::make_shared<DeviceInfo>())
26+{
27+}
28+
29+QString DeviceConfig::name() const
30+{
31+ return QString::fromStdString(m_info->name());
32+}
33+
34+Qt::ScreenOrientation DeviceConfig::primaryOrientation() const
35+{
36+ return stringToOrientation(m_info->primaryOrientation(), Qt::PrimaryOrientation);
37+}
38+
39+Qt::ScreenOrientations DeviceConfig::supportedOrientations() const
40+{
41+ auto values = m_info->supportedOrientations();
42+ if (values.empty()) {
43+ return Qt::PortraitOrientation
44+ | Qt::InvertedPortraitOrientation
45+ | Qt::LandscapeOrientation
46+ | Qt::InvertedLandscapeOrientation;
47+ }
48+
49+ Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
50+ for (auto orientationString : values) {
51+ ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
52+ }
53+ return ret;
54+}
55+
56+Qt::ScreenOrientation DeviceConfig::landscapeOrientation() const
57+{
58+ return stringToOrientation(m_info->landscapeOrientation(), Qt::LandscapeOrientation);
59+}
60+
61+Qt::ScreenOrientation DeviceConfig::invertedLandscapeOrientation() const
62+{
63+ return stringToOrientation(m_info->invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
64+}
65+
66+Qt::ScreenOrientation DeviceConfig::portraitOrientation() const
67+{
68+ return stringToOrientation(m_info->portraitOrientation(), Qt::PortraitOrientation);
69+}
70+
71+Qt::ScreenOrientation DeviceConfig::invertedPortraitOrientation() const
72+{
73+ return stringToOrientation(m_info->invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
74+}
75+
76+QString DeviceConfig::category() const
77+{
78+ QStringList supportedValues = {"phone", "tablet", "desktop"};
79+ QString value = QString::fromStdString(DeviceInfo::deviceTypeToString(m_info->deviceType()));
80+ if (!supportedValues.contains(value)) {
81+ qWarning().nospace().noquote() << "Unknown option \"" << value
82+ << ". Supported options are: " << supportedValues.join(", ") << ".";
83+ return "phone";
84+ }
85+ return value;
86+}
87+
88+Qt::ScreenOrientation DeviceConfig::stringToOrientation(const std::string &orientationString, Qt::ScreenOrientation defaultValue) const
89+{
90+ if (orientationString == "Landscape") {
91+ return Qt::LandscapeOrientation;
92+ }
93+ if (orientationString == "InvertedLandscape") {
94+ return Qt::InvertedLandscapeOrientation;
95+ }
96+ if (orientationString == "Portrait") {
97+ return Qt::PortraitOrientation;
98+ }
99+ if (orientationString == "InvertedPortrait") {
100+ return Qt::InvertedPortraitOrientation;
101+ }
102+ if (!orientationString.empty()) {
103+ // Some option we don't know. Give some hint on what went wrong.
104+ qWarning().nospace().noquote() << "Unknown option \"" << QString::fromStdString(orientationString)
105+ << ". Supported options are: Landscape, InvertedLandscape, Portrait and InvertedPortrait.";
106+ }
107+ return defaultValue;
108+}
109+
110+bool DeviceConfig::supportsMultiColorLed() const
111+{
112+ return m_info->contains("supportsMultiColorLed");
113+}
plugins/Utils/deviceconfigparser.h → plugins/Utils/deviceconfig.hrenamed+9−16
@@ -14,16 +14,16 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef DEVICECONFIGPARSER_H
18−#define DEVICECONFIGPARSER_H
17+#pragma once
1918
2019#include <QObject>
21−#include <QSettings>
20+#include <memory>
2221
23−class DeviceConfigParser: public QObject
22+class DeviceInfo;
23+class DeviceConfig: public QObject
2424{
2525 Q_OBJECT
26− Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
26+ Q_PROPERTY(QString name READ name NOTIFY changed)
2727
2828 // NOTE: When changing this properties, also update the examples in docs and data
2929 Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY changed)
@@ -33,13 +33,12 @@ class DeviceConfigParser: public QObject
3333 Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
3434 Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
3535 Q_PROPERTY(QString category READ category NOTIFY changed)
36− Q_PROPERTY(bool supportsMultiColorLed READ supportsMultiColorLed NOTIFY changed)
36+ Q_PROPERTY(bool supportsMultiColorLed READ supportsMultiColorLed)
3737
3838public:
39− DeviceConfigParser(QObject *parent = nullptr);
39+ DeviceConfig(QObject *parent = nullptr);
4040
4141 QString name() const;
42− void setName(const QString &name);
4342
4443 Qt::ScreenOrientation primaryOrientation() const;
4544 Qt::ScreenOrientations supportedOrientations() const;
@@ -54,13 +53,7 @@ Q_SIGNALS:
5453 void changed();
5554
5655private:
57− QString m_name;
58− QSettings *m_config;
56+ std::shared_ptr<DeviceInfo> m_info;
5957
60− QStringList readOrientationsFromConfig(const QString &key) const;
61− QString readOrientationFromConfig(const QString &key) const;
62− Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
63− bool readBoolFromConfig(const QString &key, bool defaultValue) const;
58+ Qt::ScreenOrientation stringToOrientation(const std::string &orientationString, Qt::ScreenOrientation defaultValue) const;
6459};
65−
66−#endif
plugins/Utils/deviceconfigparser.cppdeleted−176
@@ -1,176 +0,0 @@
1−/*
2− * Copyright 2016 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "deviceconfigparser.h"
18−
19−#include <QSettings>
20−#include <QFileInfo>
21−#include <QDebug>
22−#include <QStandardPaths>
23−
24−DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
25−{
26− // Local files have highest priority
27− QString path;
28− Q_FOREACH (const QString &standardPath, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
29− if (QFileInfo::exists(standardPath + "/devices.conf")) {
30− path = standardPath + "/devices.conf";
31− break;
32− }
33− }
34−
35− // Check if there is an override in the device tarball (/system/etc/)
36− if (path.isEmpty() && QFileInfo::exists("/system/etc/ubuntu/devices.conf")) {
37− path = "/system/etc/ubuntu/devices.conf";
38− }
39−
40− // No higher priority files found. Use standard of /etc/
41− if (path.isEmpty()) {
42− path = "/etc/ubuntu/devices.conf";
43− }
44−
45− qDebug() << "Using" << path << "as device configuration file";
46− m_config = new QSettings(path, QSettings::IniFormat, this);
47−}
48−
49−QString DeviceConfigParser::name() const
50−{
51− return m_name;
52−}
53−
54−void DeviceConfigParser::setName(const QString &name)
55−{
56− if (m_name == name) {
57− return;
58− }
59− m_name = name;
60− Q_EMIT changed();
61−}
62−
63−Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
64−{
65− return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
66−}
67−
68−Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
69−{
70− QStringList values = readOrientationsFromConfig("SupportedOrientations");
71− if (values.isEmpty()) {
72− return Qt::PortraitOrientation
73− | Qt::InvertedPortraitOrientation
74− | Qt::LandscapeOrientation
75− | Qt::InvertedLandscapeOrientation;
76− }
77−
78− Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
79− Q_FOREACH(const QString &orientationString, values) {
80− ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
81− }
82− return ret;
83−}
84−
85−Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
86−{
87− return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
88−}
89−
90−Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
91−{
92− return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
93−}
94−
95−Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
96−{
97− return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
98−}
99−
100−Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
101−{
102− return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
103−}
104−
105−QString DeviceConfigParser::category() const
106−{
107− QStringList supportedValues = {"phone", "tablet", "desktop"};
108− m_config->beginGroup(m_name);
109− QString value = m_config->value("Category", "phone").toString();
110− if (!supportedValues.contains(value)) {
111− qWarning().nospace().noquote() << "Unknown option \"" << value << "\" in " << m_config->fileName()
112− << ". Supported options are: " << supportedValues.join(", ") << ".";
113− return "phone";
114− }
115− m_config->endGroup();
116− return value;
117−}
118−
119−bool DeviceConfigParser::supportsMultiColorLed() const
120−{
121− return readBoolFromConfig("SupportsMultiColorLed", true);
122−}
123−
124−bool DeviceConfigParser::readBoolFromConfig(const QString &key, bool defaultValue) const
125−{
126− m_config->beginGroup(m_name);
127−
128− bool ret = defaultValue;
129− if (m_config->contains(key)) {
130− ret = m_config->value(key).toBool();
131− }
132−
133− m_config->endGroup();
134− return ret;
135−}
136−
137−QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
138−{
139− m_config->beginGroup(m_name);
140−
141− QStringList ret;
142− if (m_config->contains(key)) {
143− ret = m_config->value(key).toStringList();
144− }
145−
146− m_config->endGroup();
147− return ret;
148−}
149−
150−QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
151−{
152− QStringList ret = readOrientationsFromConfig(key);
153− return ret.count() > 0 ? ret.first() : QString();
154−}
155−
156−Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
157−{
158− if (orientationString == "Landscape") {
159− return Qt::LandscapeOrientation;
160− }
161− if (orientationString == "InvertedLandscape") {
162− return Qt::InvertedLandscapeOrientation;
163− }
164− if (orientationString == "Portrait") {
165− return Qt::PortraitOrientation;
166− }
167− if (orientationString == "InvertedPortrait") {
168− return Qt::InvertedPortraitOrientation;
169− }
170− if (!orientationString.isEmpty()) {
171− // Some option we don't know. Give some hint on what went wrong.
172− qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\" in " << m_config->fileName()
173− << ". Supported options are: Landscape, InvertedLandscape, Portrait and InvertedPortrait.";
174− }
175− return defaultValue;
176−}
plugins/Utils/plugin.cpp+2−2
@@ -36,7 +36,7 @@
3636#include "timezoneFormatter.h"
3737#include "applicationsfiltermodel.h"
3838#include "inputeventgenerator.h"
39−#include "deviceconfigparser.h"
39+#include "deviceconfig.h"
4040#include "globalfunctions.h"
4141#include "URLDispatcher.h"
4242#include "appdrawerproxymodel.h"
@@ -83,7 +83,7 @@ void UtilsPlugin::registerTypes(const char *uri)
8383 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
8484 qmlRegisterType<ApplicationsFilterModel>(uri, 0, 1, "ApplicationsFilterModel");
8585 qmlRegisterType<InputEventGenerator>(uri, 0, 1, "InputEventGenerator");
86− qmlRegisterType<DeviceConfigParser>(uri, 0, 1, "DeviceConfigParser");
86+ qmlRegisterType<DeviceConfig>(uri, 0, 1, "DeviceConfig");
8787 qmlRegisterSingletonType<GlobalFunctions>(uri, 0, 1, "Functions", createGlobalFunctions);
8888 qmlRegisterType<URLDispatcher>(uri, 0, 1, "URLDispatcher");
8989 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
qml/DeviceConfiguration.qml+26−15
@@ -20,11 +20,13 @@ import Utils 0.1
2020QtObject {
2121 id: root
2222
23+ // This allows to override device name, used for convergence
24+ // to set screens to desktop "mode"
25+ property var overrideName: false
26+
2327 readonly property int useNativeOrientation: -1
2428
25− // The only writable property in the API
26− // all other properties are set according to the device name
27− property alias name: priv.state
29+ readonly property alias name: priv.name;
2830
2931 readonly property alias primaryOrientation: priv.primaryOrientation
3032 readonly property alias supportedOrientations: priv.supportedOrientations
@@ -35,26 +37,29 @@ QtObject {
3537
3638 readonly property alias category: priv.category
3739
38− readonly property alias supportsMultiColorLed: priv.supportsMultiColorLed
40+ readonly property var deviceConfig: DeviceConfig {}
3941
40− readonly property var deviceConfigParser: DeviceConfigParser {
41− name: root.name
42+ readonly property var binding: Binding {
43+ target: priv
44+ property: "state"
45+ value: root.overrideName ? overrideName : deviceConfig.name
4246 }
4347
4448 readonly property var priv: StateGroup {
4549 id: priv
4650
47− property int primaryOrientation: deviceConfigParser.primaryOrientation == Qt.PrimaryOrientation ?
48− root.useNativeOrientation : deviceConfigParser.primaryOrientation
51+ property int primaryOrientation: deviceConfig.primaryOrientation == Qt.PrimaryOrientation ?
52+ root.useNativeOrientation : deviceConfig.primaryOrientation
4953
50− property int supportedOrientations: deviceConfigParser.supportedOrientations
54+ property int supportedOrientations: deviceConfig.supportedOrientations
5155
52− property int landscapeOrientation: deviceConfigParser.landscapeOrientation
53− property int invertedLandscapeOrientation: deviceConfigParser.invertedLandscapeOrientation
54− property int portraitOrientation: deviceConfigParser.portraitOrientation
55− property int invertedPortraitOrientation: deviceConfigParser.invertedPortraitOrientation
56− property string category: deviceConfigParser.category
57− property bool supportsMultiColorLed: deviceConfigParser.supportsMultiColorLed
56+ property int landscapeOrientation: deviceConfig.landscapeOrientation
57+ property int invertedLandscapeOrientation: deviceConfig.invertedLandscapeOrientation
58+ property int portraitOrientation: deviceConfig.portraitOrientation
59+ property int invertedPortraitOrientation: deviceConfig.invertedPortraitOrientation
60+ property string category: deviceConfig.category
61+ property string name: deviceConfig.name
62+ property bool supportsMultiColorLed: deviceConfig.supportsMultiColorLed
5863
5964 states: [
6065 State {
@@ -70,6 +75,7 @@ QtObject {
7075 portraitOrientation: Qt.PortraitOrientation
7176 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
7277 category: "phone"
78+ name: "mako"
7379 }
7480 },
7581 State {
@@ -85,6 +91,7 @@ QtObject {
8591 portraitOrientation: Qt.PortraitOrientation
8692 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
8793 category: "phone"
94+ name: "krillin"
8895 }
8996 },
9097 State {
@@ -102,6 +109,7 @@ QtObject {
102109 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
103110 supportsMultiColorLed: false
104111 category: "phone"
112+ name: "arale"
105113 }
106114 },
107115 State {
@@ -118,6 +126,7 @@ QtObject {
118126 portraitOrientation: Qt.PortraitOrientation
119127 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
120128 category: "tablet"
129+ name: "manta"
121130 }
122131 },
123132 State {
@@ -134,6 +143,7 @@ QtObject {
134143 portraitOrientation: Qt.PortraitOrientation
135144 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
136145 category: "tablet"
146+ name: "flo"
137147 }
138148 },
139149 State {
@@ -147,6 +157,7 @@ QtObject {
147157 portraitOrientation: Qt.PortraitOrientation
148158 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
149159 category: "desktop"
160+ name: "desktop"
150161 }
151162 },
152163 State {
qml/DisabledScreenNotice.qml+1−1
@@ -27,10 +27,10 @@ Item {
2727 // For testing
2828 property var screen: Screen
2929 property var orientationLock: OrientationLock
30+ property alias overrideDeviceName: deviceConfiguration.overrideName
3031
3132 DeviceConfiguration {
3233 id: deviceConfiguration
33− name: applicationArguments.deviceName
3434 }
3535
3636 Item {
qml/OrientedShell.qml+4−1
@@ -33,10 +33,13 @@ Item {
3333 implicitHeight: units.gu(71)
3434
3535 onWidthChanged: calculateUsageMode();
36+ property var overrideDeviceName: screens.count > 1 ? "desktop" : false
3637
3738 DeviceConfiguration {
3839 id: deviceConfiguration
39− name: applicationArguments.deviceName
40+
41+ // Override for convergence to set scale etc for second monitor
42+ overrideName: root.overrideDeviceName
4043 }
4144
4245 property alias orientations: d.orientations
src/ApplicationArguments.h−13
@@ -26,27 +26,14 @@
2626class ApplicationArguments : public QObject
2727{
2828 Q_OBJECT
29− Q_PROPERTY(QString deviceName READ deviceName NOTIFY deviceNameChanged)
3029 Q_PROPERTY(QString mode READ mode CONSTANT)
3130public:
3231 ApplicationArguments(QObject *parent = nullptr);
3332
34− void setDeviceName(const QString &deviceName) {
35− if (deviceName != m_deviceName) {
36− m_deviceName = deviceName;
37− Q_EMIT deviceNameChanged(m_deviceName);
38− }
39− }
40− QString deviceName() const { return m_deviceName; }
41−
4233 void setMode(const QString &mode) { m_mode = mode; }
4334 QString mode() const { return m_mode; }
4435
45−Q_SIGNALS:
46− void deviceNameChanged(const QString&);
47−
4836private:
49− QString m_deviceName;
5037 QString m_mode;
5138};
5239
src/CMakeLists.txt+1−5
@@ -42,15 +42,11 @@ if (ENABLE_TOUCH_EMULATION)
4242 set(SOURCE_FILES ${SOURCE_FILES} MouseTouchAdaptor.cpp)
4343endif()
4444
45−pkg_check_modules(ANDROID_PROPERTIES REQUIRED libandroid-properties)
4645add_executable(${SHELL_APP} ${SOURCE_FILES})
4746
48−if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
49− set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
50−endif()
5147target_link_libraries(${SHELL_APP}
5248 Qt5::DBus Qt5::Gui Qt5::Qml Qt5::Quick Qt5::Test
53− ${ANDROID_PROPERTIES_LDFLAGS} ${GSETTINGS_QT_LDFLAGS}
49+ ${GSETTINGS_QT_LDFLAGS}
5450 UbuntuGestures connectivity-qt1 unity8-private
5551 )
5652
src/ShellApplication.cpp−15
@@ -25,9 +25,6 @@
2525
2626#include <libintl.h>
2727
28−// libandroid-properties
29−#include <hybris/properties/properties.h>
30−
3128// local
3229#include <paths.h>
3330#include "CachingNetworkManagerFactory.h"
@@ -47,15 +44,6 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
4744
4845 UnityCommandLineParser parser(*this);
4946
50− if (!parser.deviceName().isEmpty()) {
51− m_deviceName = parser.deviceName();
52− } else {
53− char buffer[200];
54− property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
55− m_deviceName = QString(buffer);
56− }
57− m_qmlArgs.setDeviceName(m_deviceName);
58−
5947 m_qmlArgs.setMode(parser.mode());
6048
6149 // The testability driver is only loaded by QApplication but not by QGuiApplication.
@@ -110,7 +98,6 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
11098 // (eg cloned desktop, several desktops, etc)
11199 if (isMirServer && screens().count() == 2) {
112100 m_shellView->setScreen(screens().at(1));
113− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
114101
115102 m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
116103 m_secondaryWindow->setScreen(screens().at(0));
@@ -182,7 +169,6 @@ void ShellApplication::onScreenAdded(QScreen * /*screen*/)
182169 // (eg cloned desktop, several desktops, etc)
183170 if (screens().count() == 2) {
184171 m_shellView->setScreen(screens().at(1));
185− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
186172 // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
187173 // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
188174 m_shellView->setVisible(true);
@@ -214,7 +200,6 @@ void ShellApplication::onScreenRemoved(QScreen *screen)
214200 delete m_secondaryWindow;
215201 m_secondaryWindow = nullptr;
216202 m_shellView->setScreen(allScreens.first());
217− m_qmlArgs.setDeviceName(m_deviceName);
218203 // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
219204 // its backing QPlatformWindow recreated). So lets refocus it.
220205 m_shellView->requestActivate();
src/ShellApplication.h−1
@@ -46,7 +46,6 @@ private Q_SLOTS:
4646
4747private:
4848 void setupQmlEngine(bool isMirServer);
49− QString m_deviceName;
5049 ApplicationArguments m_qmlArgs;
5150 ShellView *m_shellView{nullptr};
5251 SecondaryWindow *m_secondaryWindow{nullptr};
src/UnityCommandLineParser.cpp−5
@@ -51,10 +51,6 @@ UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
5151 QStringLiteral("DISCOURAGED: Please set QT_LOAD_TESTABILITY instead.\nLoad the testability driver"));
5252 parser.addOption(testabilityOption);
5353
54− QCommandLineOption devicenameOption(QStringList() << QStringLiteral("devicename"),
55− QStringLiteral("Specify the device name instead of letting Unity 8 find it out"), QStringLiteral("devicename"), QLatin1String(""));
56− parser.addOption(devicenameOption);
57−
5854 QCommandLineOption modeOption(QStringLiteral("mode"),
5955 QStringLiteral("Whether to run greeter and/or shell [full-greeter, full-shell, greeter, shell]"),
6056 QStringLiteral("mode"), QStringLiteral("full-greeter"));
@@ -83,7 +79,6 @@ UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
8379 #endif
8480
8581 m_hasFullscreen = parser.isSet(fullscreenOption);
86− m_deviceName = parser.value(devicenameOption);
8782 resolveMode(parser, modeOption);
8883}
8984
src/UnityCommandLineParser.h−2
@@ -34,7 +34,6 @@ public:
3434 #endif
3535
3636 bool hasFullscreen() const { return m_hasFullscreen; }
37− QString deviceName() const { return m_deviceName; }
3837 QString mode() const { return m_mode; }
3938private:
4039
@@ -53,7 +52,6 @@ private:
5352 #endif
5453
5554 bool m_hasFullscreen;
56− QString m_deviceName;
5755 QString m_mode;
5856};
5957
tests/mocks/Utils/CMakeLists.txt+4−2
@@ -9,6 +9,7 @@ include_directories(
99 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
1010 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
1111 ${GIO_INCLUDE_DIRS}
12+ ${DEVICEINFO_INCLUDE_DIRS}
1213)
1314
1415set(QMLPLUGIN_SRC
@@ -22,7 +23,7 @@ set(QMLPLUGIN_SRC
2223 ${CMAKE_SOURCE_DIR}/plugins/Utils/timezoneFormatter.cpp
2324 ${CMAKE_SOURCE_DIR}/plugins/Utils/applicationsfiltermodel.cpp
2425 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputeventgenerator.cpp
25− ${CMAKE_SOURCE_DIR}/plugins/Utils/deviceconfigparser.cpp
26+ ${CMAKE_SOURCE_DIR}/plugins/Utils/deviceconfig.cpp
2627 ${CMAKE_SOURCE_DIR}/plugins/Utils/globalfunctions.cpp
2728 ${CMAKE_SOURCE_DIR}/plugins/Utils/appdrawerproxymodel.cpp
2829 ${CMAKE_SOURCE_DIR}/plugins/Utils/tabfocusfence.cpp
@@ -50,7 +51,8 @@ add_library(FakeUtils-qml SHARED
5051target_link_libraries(FakeUtils-qml
5152 ${GIO_LDFLAGS}
5253 Qt5::Qml Qt5::Quick Qt5::DBus Qt5::Network Qt5::Gui
53− )
54+ ${DEVICEINFO_LDFLAGS}
55+)
5456
5557# Because this is an internal support library, we want
5658# to expose all symbols in it. Consider changing this
tests/mocks/Utils/plugin.cpp+2−2
@@ -38,7 +38,7 @@
3838#include <timezoneFormatter.h>
3939#include <applicationsfiltermodel.h>
4040#include <inputeventgenerator.h>
41−#include <deviceconfigparser.h>
41+#include <deviceconfig.h>
4242#include <globalfunctions.h>
4343#include <appdrawerproxymodel.h>
4444#include <tabfocusfence.h>
@@ -83,7 +83,7 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
8383 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
8484 qmlRegisterType<ApplicationsFilterModel>(uri, 0, 1, "ApplicationsFilterModel");
8585 qmlRegisterType<InputEventGenerator>(uri, 0, 1, "InputEventGenerator");
86− qmlRegisterType<DeviceConfigParser>(uri, 0, 1, "DeviceConfigParser");
86+ qmlRegisterType<DeviceConfig>(uri, 0, 1, "DeviceConfig");
8787 qmlRegisterSingletonType<GlobalFunctions>(uri, 0, 1, "Functions", createGlobalFunctions);
8888 qmlRegisterType<URLDispatcher>(uri, 0, 1, "URLDispatcher");
8989 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
tests/plugins/Utils/CMakeLists.txt−1
@@ -12,7 +12,6 @@ foreach(util_test
1212 QLimitProxyModel
1313 UnitySortFilterProxyModel
1414 WindowInputMonitor
15− DeviceConfigParser
1615 WindowStateStorage
1716)
1817 add_executable(${util_test}TestExec ${util_test}Test.cpp ModelTest.cpp)
tests/plugins/Utils/DeviceConfigParserTest.cppdeleted−76
@@ -1,76 +0,0 @@
1−/*
2− * Copyright (C) 2016 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−// local
18−#include "deviceconfigparser.h"
19−
20−// Qt
21−#include <QTest>
22−#include <QDebug>
23−#include <QSettings>
24−#include <QTemporaryDir>
25−
26−class DeviceConfigParserTest : public QObject
27−{
28− Q_OBJECT
29−
30−private Q_SLOTS:
31−
32− void initTestCase() {
33− }
34−
35− void testDefaults()
36− {
37− DeviceConfigParser p;
38− p.setName("nonexistent");
39−
40− QCOMPARE(p.supportedOrientations(), Qt::PortraitOrientation | Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
41− QCOMPARE(p.primaryOrientation(), Qt::PrimaryOrientation);
42− QCOMPARE(p.portraitOrientation(), Qt::PortraitOrientation);
43− QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
44− QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
45− QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
46− QCOMPARE(p.supportsMultiColorLed(), true);
47− }
48−
49− void testCustomFile() {
50− QTemporaryDir dir;
51− QSettings s(dir.path() + "/devices.conf", QSettings::IniFormat);
52− s.beginGroup("fakedevice");
53−
54− s.setValue("SupportedOrientations", QStringList() << "Portrait" << "Landscape" << "InvertedLandscape");
55− s.setValue("PrimaryOrientation", "InvertedLandscape");
56− s.setValue("SupportsMultiColorLed", false);
57− s.sync();
58−
59− qputenv("XDG_CONFIG_HOME", dir.path().toUtf8());
60− DeviceConfigParser p;
61− p.setName("fakedevice");
62−
63− QCOMPARE(p.supportedOrientations(), Qt::PortraitOrientation | Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
64− QCOMPARE(p.primaryOrientation(), Qt::InvertedLandscapeOrientation);
65− QCOMPARE(p.portraitOrientation(), Qt::PortraitOrientation);
66− QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
67− QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
68− QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
69− QCOMPARE(p.supportsMultiColorLed(), false);
70− }
71−
72−};
73−
74−QTEST_GUILESS_MAIN(DeviceConfigParserTest)
75−
76−#include "DeviceConfigParserTest.moc"
tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml+3−3
@@ -257,13 +257,13 @@ Item {
257257 // Support for Multicolor LED
258258 //
259259 { tag: "Powerd.Off with New Message & no support for multicolor led",
260− expectedLightsState: Lights.On,
260+ expectedLightsState: Leds.On,
261261 powerd: Powerd.Off, actionData: newMessage, supportsMultiColorLed: false },
262262 { tag: "Powerd.Off while charging & support for multicolor led",
263− expectedLightsState: Lights.On,
263+ expectedLightsState: Leds.On,
264264 powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: true },
265265 { tag: "Powerd.Off while charging & no support for multicolor led",
266− expectedLightsState: Lights.Off,
266+ expectedLightsState: Leds.Off,
267267 powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: false },
268268 ]
269269 }
tests/qmltests/tst_DeviceConfiguration.qml+23−2
@@ -34,8 +34,9 @@ Item {
3434 when: windowShown
3535
3636 function test_defaults() {
37− deviceConfiguration.name = "nonexisting"
38− compare(deviceConfiguration.primaryOrientation, -1)
37+ compare(deviceConfiguration.name, "generic");
38+ compare(deviceConfiguration.category, "desktop");
39+ compare(deviceConfiguration.primaryOrientation, Qt.LandscapeOrientation)
3940 compare(deviceConfiguration.landscapeOrientation, Qt.LandscapeOrientation)
4041 compare(deviceConfiguration.portraitOrientation, Qt.PortraitOrientation)
4142 compare(deviceConfiguration.invertedLandscapeOrientation, Qt.InvertedLandscapeOrientation)
@@ -45,5 +46,25 @@ Item {
4546 | Qt.LandscapeOrientation
4647 | Qt.InvertedLandscapeOrientation)
4748 }
49+
50+ function test_nameOverride() {
51+ deviceConfiguration.overrideName = "flo";
52+ compare(deviceConfiguration.name, "flo");
53+ compare(deviceConfiguration.category, "tablet");
54+ compare(deviceConfiguration.primaryOrientation, Qt.InvertedLandscapeOrientation)
55+ compare(deviceConfiguration.landscapeOrientation, Qt.InvertedLandscapeOrientation)
56+ compare(deviceConfiguration.portraitOrientation, Qt.PortraitOrientation)
57+ compare(deviceConfiguration.invertedLandscapeOrientation, Qt.LandscapeOrientation)
58+ compare(deviceConfiguration.invertedPortraitOrientation, Qt.InvertedPortraitOrientation)
59+ compare(deviceConfiguration.supportedOrientations, Qt.PortraitOrientation
60+ | Qt.InvertedPortraitOrientation
61+ | Qt.LandscapeOrientation
62+ | Qt.InvertedLandscapeOrientation)
63+
64+ // Also try reseting override
65+ deviceConfiguration.overrideName = false;
66+ compare(deviceConfiguration.name, "generic");
67+ compare(deviceConfiguration.category, "desktop");
68+ }
4869 }
4970}
tests/qmltests/tst_DisabledScreenNotice.qml+1−3
@@ -31,12 +31,10 @@ Item {
3131 id: touchScreenPad
3232 anchors.fill: parent
3333 anchors.rightMargin: units.gu(40)
34+ overrideDeviceName: "mako"
3435
3536 // Mock some things here
3637 property int internalGu: units.gu(1)
37− property var applicationArguments: QtObject {
38− property string deviceName: "mako"
39− }
4038
4139 screen: QtObject {
4240 property int orientation: {
tests/qmltests/tst_OrientedShell.qml+1
@@ -171,6 +171,7 @@ Rectangle {
171171 physicalOrientation: root.physicalOrientation0
172172 orientationLocked: orientationLockedCheckBox.checked
173173 orientationLock: mockOrientationLock
174+ overrideDeviceName: applicationArguments.deviceName
174175 Component.onDestruction: {
175176 orientedShellLoader.itemDestroyed = true;
176177 }