Debian Codegraph @

headers/deviceinfo.h

raw
1 /*
2 * Copyright (C) 2019 UBports foundation.
3 * Author(s): Marius Gripsgard <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 3, as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 #pragma once
20
21 #include <memory>
22 #include <vector>
23
24 class Device;
25 class DeviceInfo {
26 public:
27 enum DeviceType {
28 Phone,
29 Tablet,
30 Desktop,
31 Unknown = -1
32 };
33
34 enum DriverType {
35 Linux,
36 Halium
37 };
38
39 enum PrintMode {
40 None = -2,
41 Error = -1,
42 Info = 0,
43 Debug = 1,
44 Verbose = 2
45 };
46
47 DeviceInfo(PrintMode printMode = PrintMode::Info);
48
49 // For tests
50 DeviceInfo(Device *device);
51
52 // Internal logging
53 void setPrintMode(PrintMode printMode);
54
55 // Props with auto detections
56 std::string name();
57 std::string prettyName();
58 DeviceType deviceType();
59 DriverType driverType();
60 int gridUnit();
61
62 // Get props that does not have auto detection
63 std::string get(std::string prop, std::string defaultValue);
64 bool contains(std::string prop);
65
66 // Handy wrappers around get
67 std::vector<std::string> supportedOrientations();
68 std::string primaryOrientation();
69 std::string portraitOrientation();
70 std::string invertedPortraitOrientation();
71 std::string landscapeOrientation();
72 std::string invertedLandscapeOrientation();
73
74 // Handy helpers
75 static std::string deviceTypeToString(DeviceType type);
76 static DeviceType deviceTypeFromString(std::string str);
77 static std::string driverTypeToString(DriverType type);
78 static DriverType driverTypeFromString(std::string str);
79
80 private:
81 std::shared_ptr<Device> m_device;
82 };