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)
27 Q_FOREACH (const QString &standardPath, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
28 if (QFileInfo(standardPath + "/devices.conf").exists()) {
29 path = standardPath + "/devices.conf";
35 path = "/etc/ubuntu/devices.conf";
37 qDebug() << "Using" << path << "as device configuration file";
38 m_config = new QSettings(path, QSettings::IniFormat, this);
41QString DeviceConfigParser::name() const
46void DeviceConfigParser::setName(const QString &name)
55Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
57 return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
60Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
62 QStringList values = readOrientationsFromConfig("SupportedOrientations");
63 if (values.isEmpty()) {
64 return Qt::PortraitOrientation
65 | Qt::InvertedPortraitOrientation
66 | Qt::LandscapeOrientation
67 | Qt::InvertedLandscapeOrientation;
70 Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
71 Q_FOREACH(const QString &orientationString, values) {
72 ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
77Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
79 return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
82Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
84 return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
87Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
89 return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
92Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
94 return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
97QString DeviceConfigParser::category() const
99 QStringList supportedValues = {"phone", "tablet", "desktop"};
100 m_config->beginGroup(m_name);
101 QString value = m_config->value("Category", "phone").toString();
102 if (!supportedValues.contains(value)) {
103 qWarning().nospace().noquote() << "Unknown option \"" << value << "\" in " << m_config->fileName()
104 << ". Supported options are: " << supportedValues.join(", ") << ".";
107 m_config->endGroup();
111QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
113 m_config->beginGroup(m_name);
116 if (m_config->contains(key)) {
117 ret = m_config->value(key).toStringList();
120 m_config->endGroup();
124QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
126 QStringList ret = readOrientationsFromConfig(key);
127 return ret.count() > 0 ? ret.first() : QString();
130Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
132 if (orientationString == "Landscape") {
133 return Qt::LandscapeOrientation;
135 if (orientationString == "InvertedLandscape") {
136 return Qt::InvertedLandscapeOrientation;
138 if (orientationString == "Portrait") {
139 return Qt::PortraitOrientation;
141 if (orientationString == "InvertedPortrait") {
142 return Qt::InvertedPortraitOrientation;
144 if (!orientationString.isEmpty()) {
145 // Some option we don't know. Give some hint on what went wrong.
146 qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\" in " << m_config->fileName()
147 << ". 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