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"
23DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
26 if (QFileInfo("./devices.conf").exists()) {
27 path = "./devices.conf";
29 path = "/etc/ubuntu/devices.conf";
31 m_config = new QSettings(path, QSettings::IniFormat, this);
34QString DeviceConfigParser::name() const
39void DeviceConfigParser::setName(const QString &name)
48Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
50 return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
53Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
55 QStringList values = readOrientationsFromConfig("SupportedOrientations");
56 if (values.isEmpty()) {
57 return Qt::PortraitOrientation
58 | Qt::InvertedPortraitOrientation
59 | Qt::LandscapeOrientation
60 | Qt::InvertedLandscapeOrientation;
63 Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
64 Q_FOREACH(const QString &orientationString, values) {
65 ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
70Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
72 return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
75Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
77 return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
80Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
82 return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
85Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
87 return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
90QString DeviceConfigParser::category() const
92 QStringList supportedValues = {"phone", "tablet", "desktop"};
93 m_config->beginGroup(m_name);
94 QString value = m_config->value("Category", "phone").toString();
95 if (!supportedValues.contains(value)) {
96 qDebug().nospace().noquote() << "Unknown option \"" << value << "\" in " << m_config->fileName()
97 << ". Supported options are: " << supportedValues.join(", ") << ".";
100 m_config->endGroup();
104QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
106 m_config->beginGroup(m_name);
109 if (m_config->contains(key)) {
110 ret = m_config->value(key).toStringList();
113 m_config->endGroup();
117QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
119 QStringList ret = readOrientationsFromConfig(key);
120 return ret.count() > 0 ? ret.first() : QString();
123Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
125 if (orientationString == "Landscape") {
126 return Qt::LandscapeOrientation;
128 if (orientationString == "InvertedLandscape") {
129 return Qt::InvertedLandscapeOrientation;
131 if (orientationString == "Portrait") {
132 return Qt::PortraitOrientation;
134 if (orientationString == "InvertedPortrait") {
135 return Qt::InvertedPortraitOrientation;
137 if (!orientationString.isEmpty()) {
138 // Some option we don't know. Give some hint on what went wrong.
139 qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\" in " << m_config->fileName()
140 << ". 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