Unity 8
deviceconfigparser.h
1 /*
2  * Copyright 2016 Canonical Ltd.
3  *
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.
7  *
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.
12  *
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/>.
15  */
16 
17 #ifndef DEVICECONFIGPARSER_H
18 #define DEVICECONFIGPARSER_H
19 
20 #include <QObject>
21 #include <QSettings>
22 
23 class DeviceConfigParser: public QObject
24 {
25  Q_OBJECT
26  Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
27 
28  Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY changed)
29  Q_PROPERTY(Qt::ScreenOrientations supportedOrientations READ supportedOrientations NOTIFY changed)
30  Q_PROPERTY(Qt::ScreenOrientation landscapeOrientation READ landscapeOrientation NOTIFY changed)
31  Q_PROPERTY(Qt::ScreenOrientation invertedLandscapeOrientation READ invertedLandscapeOrientation NOTIFY changed)
32  Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
33  Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
34  Q_PROPERTY(QString category READ category NOTIFY changed)
35 
36 public:
37  DeviceConfigParser(QObject *parent = nullptr);
38 
39  QString name() const;
40  void setName(const QString &name);
41 
42  Qt::ScreenOrientation primaryOrientation() const;
43  Qt::ScreenOrientations supportedOrientations() const;
44  Qt::ScreenOrientation landscapeOrientation() const;
45  Qt::ScreenOrientation invertedLandscapeOrientation() const;
46  Qt::ScreenOrientation portraitOrientation() const;
47  Qt::ScreenOrientation invertedPortraitOrientation() const;
48  QString category() const;
49 
50 Q_SIGNALS:
51  void changed();
52 
53 private:
54  QString m_name;
55  QSettings *m_config;
56 
57  QStringList readOrientationsFromConfig(const QString &key) const;
58  QString readOrientationFromConfig(const QString &key) const;
59  Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
60 };
61 
62 #endif