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)
28QString DeviceConfigParser::name() const
33void DeviceConfigParser::setName(const QString &name)
42Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
44 return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
47Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
49 QStringList values = readOrientationsFromConfig("SupportedOrientations");
50 if (values.isEmpty()) {
51 return Qt::PortraitOrientation
52 | Qt::InvertedPortraitOrientation
53 | Qt::LandscapeOrientation
54 | Qt::InvertedLandscapeOrientation;
57 Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
58 Q_FOREACH(const QString &orientationString, values) {
59 ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
64Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
66 return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
69Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
71 return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
74Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
76 return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
79Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
81 return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
84QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
86 QFileInfo fi("./devices.conf");
89 path = "./devices.conf";
91 path = "/etc/ubuntu/devices.conf";
93 QSettings config(path, QSettings::IniFormat);
94 config.beginGroup(m_name);
96 if (config.contains(key)) {
97 return config.value(key).toStringList();
102QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
104 QStringList ret = readOrientationsFromConfig(key);
105 return ret.count() > 0 ? ret.first() : QString();
108Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
110 if (orientationString == "Landscape") {
111 return Qt::LandscapeOrientation;
113 if (orientationString == "InvertedLandscape") {
114 return Qt::InvertedLandscapeOrientation;
116 if (orientationString == "Portrait") {
117 return Qt::PortraitOrientation;
119 if (orientationString == "InvertedPortrait") {
120 return Qt::InvertedPortraitOrientation;
122 if (!orientationString.isEmpty()) {
123 // Some option we don't know. Give some hint on what went wrong.
124 qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\". 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