aboutsummaryrefslogtreecommitdiffstats
path: root/mobility/sysinfo/qml/main.py
blob: 6131ff9a65802c9c3f6f161a7378bb14a6388f0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/python

import sys
import os

from PySide import QtCore
from PySide import QtGui
from PySide import QtDeclarative
from PySide import QtOpenGL
from QtMobility.SystemInfo import QSystemInfo, QSystemDeviceInfo, QSystemDisplayInfo, QSystemStorageInfo, QSystemNetworkInfo, QSystemScreenSaver


class SystemInfoModel(QtCore.QObject):
    changed = QtCore.Signal()

    def __init__(self):
        super(SystemInfoModel, self).__init__()
        self.systemInfo = QSystemInfo(self)
        self.setupGeneral()
        self.setupDevice()
        self.setupDisplay()

    @QtCore.Property(str, notify=changed)
    def currentLanguage(self):
        return self._currentLanguage

    @QtCore.Property("QStringList", notify=changed)
    def availableLanguages(self):
        return self._availableLanguages

    @QtCore.Property(int, notify=changed)
    def displayBrightness(self):
        return self._displayBrightness

    @QtCore.Property(int, notify=changed)
    def colorDepth(self):
        return self._colorDepth

    @QtCore.Property(str, notify=changed)
    def imei(self):
        return self._imei

    @QtCore.Property(str, notify=changed)
    def imsi(self):
        return self._imsi

    @QtCore.Property(str, notify=changed)
    def manufacturer(self):
        return self._manufacturer

    @QtCore.Property(str, notify=changed)
    def product(self):
        return self._product

    @QtCore.Property(str, notify=changed)
    def model(self):
        return self._model

    @QtCore.Property(str, notify=changed)
    def profile(self):
        return self._profile

    @QtCore.Property(str, notify=changed)
    def inputMethod(self):
        return self._inputMethod

    @QtCore.Property(bool, notify=changed)
    def deviceLock(self):
        return self._deviceLock

    @QtCore.Property(str, notify=changed)
    def simStatus(self):
        return self._simStatus

    @QtCore.Property(bool, notify=changed)
    def bluetoothState(self):
        return self._bluetoothState

    def setupGeneral(self):
        self._currentLanguage = self.systemInfo.currentLanguage()
        self._availableLanguages = self.systemInfo.availableLanguages()

    def setupDevice(self):
        self.deviceInfo = QSystemDeviceInfo(self)
        self._batteryLevel = self.deviceInfo.batteryLevel()
        self.deviceInfo.batteryLevelChanged.connect(self.updateBatteryStatus)
        self.deviceInfo.batteryStatusChanged.connect(self.displayBatteryStatus)
        self.deviceInfo.powerStateChanged.connect(self.updatePowerState)
        self._imei = self.deviceInfo.imei()
        self._imsi = self.deviceInfo.imsi()
        self._manufacturer = self.deviceInfo.manufacturer()
        self._model = self.deviceInfo.model()
        self._product = self.deviceInfo.productName()
        self._deviceLock = self.deviceInfo.isDeviceLocked()

        methods = self.deviceInfo.inputMethodType()
        inputs = []
        if methods & QSystemDeviceInfo.Keys:
            inputs.append("Keys")
        if methods & QSystemDeviceInfo.Keypad:
            inputs.append("Keypad")
        if methods & QSystemDeviceInfo.Keyboard:
            inputs.append("Keyboard")
        if methods & QSystemDeviceInfo.SingleTouch:
            inputs.append("Touch Screen")
        if methods & QSystemDeviceInfo.MultiTouch:
            inputs.append("Multi touch")
        if methods & QSystemDeviceInfo.Mouse:
            inputs.append("Mouse")

        self._inputMethod = " ".join(inputs)
        self.updateSimStatus()
        self.updateProfile()

        self._bluetoothState = self.deviceInfo.currentBluetoothPowerState()
        self.deviceInfo.bluetoothStateChanged.connect(self.updateBluetoothState)

    def setupDisplay(self):
        self.displayInfo = QSystemDisplayInfo()
        self._displayBrightness = self.displayInfo.displayBrightness(0)
        self._colorDepth = self.displayInfo.colorDepth(0)

    def updateBluetoothState(self, on):
        self._bluetoothState = on
        self.changed.emit()

    def updateBatteryStatus(self, status):
        self._batteryLevel = status
        self.emit(QtCore.SIGNAL('changed()'))

    def displayBatteryStatus(self, status):
        pass

    def updatePowerState(self, newState):
        pass

    def updateSimStatus(self):
        if self.deviceInfo:
            status = self.deviceInfo.simStatus()
            if status == QSystemDeviceInfo.SimLocked:
                simstring = "Sim Locked";
            elif status == QSystemDeviceInfo.SimNotAvailable:
                simstring = "Sim not available";
            elif status == QSystemDeviceInfo.SingleSimAvailable:
                simstring = "Single Sim Available";
            elif status == QSystemDeviceInfo.DualSimAvailable:
                simstring = "Dual Sim available";
            else:
                simstring = ""

            self._simStatus = simstring


    def updateProfile(self):
        if self.deviceInfo:
            current = self.deviceInfo.currentProfile()
            if current == QSystemDeviceInfo.UnknownProfile:
                profilestring = "Unknown"
            elif current == QSystemDeviceInfo.SilentProfile:
                profilestring = "Silent"
            elif current == QSystemDeviceInfo.NormalProfile:
                profilestring = "Normal"
            elif current == QSystemDeviceInfo.LoudProfile:
                profilestring = "Loud"
            elif current == QSystemDeviceInfo.VibProfile:
                profilestring = "Vibrate"
            elif current == QSystemDeviceInfo.OfflineProfile:
                profilestring = "Offline";
            elif current == QSystemDeviceInfo.PowersaveProfile:
                profilestring = "Powersave";
            elif current ==  QSystemDeviceInfo.CustomProfile:
                profilestring = "custom";

            self._profile = profilestring

class SystemInfoUI(QtCore.QObject):
    def __init__(self):
        super(SystemInfoUI, self).__init__()
        self.view = QtDeclarative.QDeclarativeView()
        self.rc = self.view.rootContext()

        self.model = SystemInfoModel()
        self.rc.setContextProperty('dataModel', self.model)

        self.view.setSource('main.qml')

        if "-no-fs" in sys.argv:
            self.view.show()
        else:
            self.view.showFullScreen()

        self.systemInfo = QSystemInfo(self)

if __name__ == "__main__":
    app = QtGui.QApplication([])
    ui = SystemInfoUI()
    app.exec_()