2 * Copyright 2016 Canonical Ltd.
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.
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.
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/>.
17#include "deviceconfigparser.h"
22#include <QStandardPaths>
24DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
26 // Local files have highest priority
28 Q_FOREACH (const QString &standardPath, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
29 if (QFileInfo::exists(standardPath + "/devices.conf")) {
30 path = standardPath + "/devices.conf";
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";
40 // No higher priority files found. Use standard of /etc/
42 path = "/etc/ubuntu/devices.conf";
45 qDebug() << "Using" << path << "as device configuration file";
46 m_config = new QSettings(path, QSettings::IniFormat, this);
49QString DeviceConfigParser::name() const
54void DeviceConfigParser::setName(const QString &name)
63Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
65 return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
68Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
70 QStringList values = readOrientationsFromConfig("SupportedOrientations");
71 if (values.isEmpty()) {
72 return Qt::PortraitOrientation
73 | Qt::InvertedPortraitOrientation
74 | Qt::LandscapeOrientation
75 | Qt::InvertedLandscapeOrientation;
78 Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
79 Q_FOREACH(const QString &orientationString, values) {
80 ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
85Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
87 return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
90Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
92 return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
95Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
97 return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
100Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
102 return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
105QString DeviceConfigParser::category() const
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(", ") << ".";
115 m_config->endGroup();
119QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
121 m_config->beginGroup(m_name);
124 if (m_config->contains(key)) {
125 ret = m_config->value(key).toStringList();
128 m_config->endGroup();
132QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
134 QStringList ret = readOrientationsFromConfig(key);
135 return ret.count() > 0 ? ret.first() : QString();
138Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
140 if (orientationString == "Landscape") {
141 return Qt::LandscapeOrientation;
143 if (orientationString == "InvertedLandscape") {
144 return Qt::InvertedLandscapeOrientation;
146 if (orientationString == "Portrait") {
147 return Qt::PortraitOrientation;
149 if (orientationString == "InvertedPortrait") {
150 return Qt::InvertedPortraitOrientation;
152 if (!orientationString.isEmpty()) {
153 // Some option we don't know. Give some hint on what went wrong.
154 qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\" in " << m_config->fileName()
155 << ". Supported options are: Landscape, InvertedLandscape, Portrait and InvertedPortrait.";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list