2 * Copyright 2016 Canonical Ltd.
3 * 2019 UBports foundation.
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.
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.
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/>.
18#include "deviceconfig.h"
20#include <deviceinfo.h>
23DeviceConfig::DeviceConfig(QObject *parent):
25 m_info(std::make_shared<DeviceInfo>())
29QString DeviceConfig::name() const
31 return QString::fromStdString(m_info->name());
34Qt::ScreenOrientation DeviceConfig::primaryOrientation() const
36 return stringToOrientation(m_info->primaryOrientation(), Qt::PrimaryOrientation);
39Qt::ScreenOrientations DeviceConfig::supportedOrientations() const
41 auto values = m_info->supportedOrientations();
43 return Qt::PortraitOrientation
44 | Qt::InvertedPortraitOrientation
45 | Qt::LandscapeOrientation
46 | Qt::InvertedLandscapeOrientation;
49 Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
50 for (auto orientationString : values) {
51 ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
56Qt::ScreenOrientation DeviceConfig::landscapeOrientation() const
58 return stringToOrientation(m_info->landscapeOrientation(), Qt::LandscapeOrientation);
61Qt::ScreenOrientation DeviceConfig::invertedLandscapeOrientation() const
63 return stringToOrientation(m_info->invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
66Qt::ScreenOrientation DeviceConfig::portraitOrientation() const
68 return stringToOrientation(m_info->portraitOrientation(), Qt::PortraitOrientation);
71Qt::ScreenOrientation DeviceConfig::invertedPortraitOrientation() const
73 return stringToOrientation(m_info->invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
76QString DeviceConfig::category() const
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(", ") << ".";
88Qt::ScreenOrientation DeviceConfig::stringToOrientation(const std::string &orientationString, Qt::ScreenOrientation defaultValue) const
90 if (orientationString == "Landscape") {
91 return Qt::LandscapeOrientation;
93 if (orientationString == "InvertedLandscape") {
94 return Qt::InvertedLandscapeOrientation;
96 if (orientationString == "Portrait") {
97 return Qt::PortraitOrientation;
99 if (orientationString == "InvertedPortrait") {
100 return Qt::InvertedPortraitOrientation;
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.";
110bool DeviceConfig::supportsMultiColorLed() const
112 return m_info->contains("supportsMultiColorLed");
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