aboutsummaryrefslogtreecommitdiffstats
path: root/mobility
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2011-09-23 15:52:31 -0300
committerLauro Neto <lauro.neto@openbossa.org>2011-09-28 19:29:05 -0300
commit244ec2f8221c1fead0796b1df8ed6de7b8a9502b (patch)
tree6d5578d8d6c4000f8ccb4e529c81725b29597140 /mobility
parent114e5a5da973403bde4af5a66f8861e591c2e864 (diff)
Add storage page
Diffstat (limited to 'mobility')
-rw-r--r--mobility/sysinfo/qml/StoragePage.qml47
-rw-r--r--mobility/sysinfo/qml/main.py49
2 files changed, 96 insertions, 0 deletions
diff --git a/mobility/sysinfo/qml/StoragePage.qml b/mobility/sysinfo/qml/StoragePage.qml
index b912250..8db0a36 100644
--- a/mobility/sysinfo/qml/StoragePage.qml
+++ b/mobility/sysinfo/qml/StoragePage.qml
@@ -5,4 +5,51 @@ Page {
id: storageTab
orientationLock: PageOrientation.LockLandscape
anchors.margins: UiConstants.DefaultMargin
+
+ Flickable {
+ anchors.fill: parent
+ flickableDirection: Flickable.VerticalFlick
+ contentHeight: columnStorage.height + toolBarLayout.height
+ contentWidth: width
+ Column {
+ id: columnStorage
+ anchors.top: parent.top
+ width: parent.width
+
+ spacing: 25
+
+ Repeater {
+
+ model: dataModel.volumeNames
+
+ Column {
+
+ width: parent.width
+
+ Label {
+ width: parent.width
+ text: "Volume: " + modelData
+ platformStyle: LabelStyle {
+ fontPixelSize: 32
+ }
+ }
+
+ Row {
+ spacing: 30
+ Label {
+ text: "Type: " + dataModel.storageType(modelData)
+ }
+
+ Label {
+ text: "Total size: " + dataModel.totalStorageSize(modelData)
+ }
+
+ Label {
+ text: "Available: " + dataModel.availableStorageSize(modelData)
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/mobility/sysinfo/qml/main.py b/mobility/sysinfo/qml/main.py
index fb0960a..407b305 100644
--- a/mobility/sysinfo/qml/main.py
+++ b/mobility/sysinfo/qml/main.py
@@ -19,6 +19,7 @@ class SystemInfoModel(QtCore.QObject):
self.setupGeneral()
self.setupDevice()
self.setupDisplay()
+ self.setupStorage()
self.setupScreenSaver()
@QtCore.Property(str, notify=changed)
@@ -77,6 +78,10 @@ class SystemInfoModel(QtCore.QObject):
def bluetoothState(self):
return self._bluetoothState
+ @QtCore.Property("QStringList", notify=changed)
+ def volumeNames(self):
+ return self._volumeNames
+
@QtCore.Property(bool, notify=changed)
def screenSaverInhibited(self):
return self._screenSaverInhibited
@@ -125,6 +130,50 @@ class SystemInfoModel(QtCore.QObject):
self._displayBrightness = self.displayInfo.displayBrightness(0)
self._colorDepth = self.displayInfo.colorDepth(0)
+ def setupStorage(self):
+ self.storageInfo = QSystemStorageInfo()
+ self._volumeNames = self.storageInfo.logicalDrives()
+
+ @QtCore.Slot(str, result=str)
+ def storageType(self, volumeName):
+ names = {
+ QSystemStorageInfo.InternalDrive: "Internal",
+ QSystemStorageInfo.RemovableDrive: "Removable",
+ QSystemStorageInfo.CdromDrive: "CD-Rom",
+ QSystemStorageInfo.RemoteDrive: "Network",
+ }
+
+ volType = self.storageInfo.typeForDrive(volumeName)
+
+ return names.get(volType, "Unknown")
+
+ @QtCore.Slot(str, result=str)
+ def totalStorageSize(self, volumeName):
+ return self.convert_bytes(self.storageInfo.totalDiskSpace(volumeName))
+
+ @QtCore.Slot(str, result=str)
+ def availableStorageSize(self, volumeName):
+ return self.convert_bytes(self.storageInfo.availableDiskSpace(volumeName))
+
+ def convert_bytes(self, bytes):
+ # From http://www.5dollarwhitebox.org/drupal/node/84
+ bytes = float(bytes)
+ if bytes >= 1099511627776:
+ terabytes = bytes / 1099511627776
+ size = '%.2fT' % terabytes
+ elif bytes >= 1073741824:
+ gigabytes = bytes / 1073741824
+ size = '%.2fG' % gigabytes
+ elif bytes >= 1048576:
+ megabytes = bytes / 1048576
+ size = '%.2fM' % megabytes
+ elif bytes >= 1024:
+ kilobytes = bytes / 1024
+ size = '%.2fK' % kilobytes
+ else:
+ size = '%.2fb' % bytes
+ return size
+
def setupScreenSaver(self):
self.saverInfo = QSystemScreenSaver(self)
self._screenSaverInhibited = self.saverInfo.screenSaverInhibited()