Skip to content

Instantly share code, notes, and snippets.

@litew
Created February 7, 2016 11:45
Show Gist options
  • Save litew/20764e06d3c67214adcd to your computer and use it in GitHub Desktop.
Save litew/20764e06d3c67214adcd to your computer and use it in GitHub Desktop.
import QtQuick 2.0
import Sailfish.Silica 1.0
import com.jolla.settings.system 1.0
import org.nemomobile.systemsettings 1.0
import org.nemomobile.dbus 1.0
import Qt.labs.folderlistmodel 2.1
Page {
id: aboutPage
AboutSettings {
id: aboutSettings
}
onStatusChanged: {
if (status == PageStatus.Activating) {
diskUsageAreaRepeater.model = aboutSettings.diskUsageModel()
}
}
DBusInterface {
id: ssuDBus
busType: DBusInterface.SystemBus
destination: 'org.nemo.ssu'
path: '/org/nemo/ssu'
iface: 'org.nemo.ssu'
}
DBusInterface {
id: invokerIface
busType: DBusInterface.SessionBus
destination: "org.freedesktop.DBus"
path: "/org/freedesktop/DBus"
iface: "org.freedesktop.DBus"
}
SilicaFlickable {
anchors.fill: parent
contentHeight: content.height + Theme.paddingLarge
Column {
id: content
width: parent.width
spacing: Theme.paddingLarge
PageHeader {
//% "About device"
title: qsTrId("settings_about-he-about_device")
}
Row {
width: parent.width
Repeater {
id: diskUsageAreaRepeater
delegate: BackgroundItem {
id: diskUsageArea
property int outerIndex: index
onClicked: pageStack.push('DiskUsagePage.qml', {storageType: modelData.storageType})
width: aboutPage.width / diskUsageAreaRepeater.count
height: discUsageColumn.height + 2 * Theme.paddingMedium
Column {
id: discUsageColumn
anchors.right: (diskUsageArea.outerIndex === 0 && diskUsageAreaRepeater.count === 2) ? parent.right : undefined
anchors.left: (diskUsageArea.outerIndex === 1 && diskUsageAreaRepeater.count === 2) ? parent.left : undefined
anchors.horizontalCenter: (diskUsageAreaRepeater.count === 1) ? parent.horizontalCenter : undefined
anchors.margins: 2 * Theme.paddingMedium
width: Theme.itemSizeHuge
spacing: Theme.paddingMedium
y: Theme.paddingMedium
ProgressCircleBase {
id: discUsage
property real usedSpace: modelData.total - modelData.available
property real totalSpace: modelData.total
property color commonColor: diskUsageArea.highlighted ? Theme.rgba(Theme.highlightColor, 0.5) : Theme.secondaryColor
width: parent.width
height: width
value: usedSpace / totalSpace
borderWidth: 2 * Theme.pixelRatio
backgroundColor: diskUsageArea.highlighted ? Theme.rgba(Theme.highlightColor, 0.5) : Theme.rgba(Theme.primaryColor, 0.3)
progressColor: diskUsageArea.highlighted ? Theme.highlightColor : Theme.primaryColor
Column {
width: parent.width * 0.7
anchors.centerIn: parent
Text {
width: parent.width
color: discUsage.progressColor
font.pixelSize: Theme.fontSizeExtraLarge
horizontalAlignment: Text.AlignHCenter
text: Number(discUsage.usedSpace / 1073741824).toLocaleString(Qt.locale(), "f", 1)
}
Rectangle {
color: discUsage.commonColor
width: parent.width
height: 2
opacity: 0.4
}
Text {
width: parent.width
color: discUsage.commonColor
opacity: 0.6
font.pixelSize: Theme.fontSizeExtraLarge
horizontalAlignment: Text.AlignHCenter
text: Number(discUsage.totalSpace / 1073741824).toLocaleString(Qt.locale(), "f", 1)
}
}
}
Label {
anchors.right: (diskUsageArea.outerIndex === 0 && diskUsageAreaRepeater.count === 2) ? discUsage.right : undefined
anchors.left: (diskUsageArea.outerIndex === 1 && diskUsageAreaRepeater.count === 2) ? discUsage.left : undefined
anchors.horizontalCenter: (diskUsageAreaRepeater.count === 1) ? parent.horizontalCenter : undefined
text: {
switch (modelData.storageType) {
case 'system':
//% "System storage (GB)"
return qsTrId("settings_about-la-system_storage_gigabytes_used")
case 'user':
//% "User storage (GB)"
return qsTrId("settings_about-la-user_storage_gigabytes_used")
case 'mass':
//% "Mass memory (GB)"
return qsTrId("settings_about-la-gigabytes_used")
default:
// Unknown storage type -- show the raw path and raw storage type instead
return '' + modelData.path + '(' + modelData.storageType + ')'
}
}
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
color: discUsage.commonColor
opacity: 0.6
}
}
}
}
}
Column {
width: parent.width
Text {
width: parent.width
height: implicitHeight + Theme.paddingSmall // match DetailItem padding
horizontalAlignment: Text.AlignHCenter
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeSmall
textFormat: Text.PlainText
wrapMode: Text.Wrap
//% "Sailfish OS 2.0"
text: qsTrId("settings_about-la-sailfish_os_2")
}
DetailItem {
//% "Manufacturer"
label: qsTrId("settings_about-la-manufacturer")
Component.onCompleted: {
// 0 -> manufacturer
ssuDBus.typedCallWithReturn("displayName", [ {"type": "i", "value": "0"} ],
function (type) {
value = type
})
}
}
DetailItem {
Component.onCompleted: {
// 1 -> device model
ssuDBus.typedCallWithReturn("displayName", [ {"type": "i", "value": "1"} ],
function (type) {
value = type
})
}
//% "Product name"
label: qsTrId("settings_about-la-product_name")
}
DetailItem {
//% "IMEI"
label: qsTrId("settings_about-la-imei")
value: aboutSettings.imei
visible: aboutSettings.imei !== ''
}
DetailItem {
//% "Serial number"
label: qsTrId("settings_about-la-serial")
value: aboutSettings.serial
visible: aboutSettings.serial !== ''
}
DetailItem {
//: The build/version number of the currently installed Sailfish OS.
//% "Build"
label: qsTrId("settings_about-la-sailfish_os_build")
//% "Unknown version"
value: aboutSettings.softwareVersion ? aboutSettings.softwareVersion
: qsTrId("settings_about-la-unknown_sailfish_version")
// CSD tool invoker
MouseArea {
property int numberOfTaps
anchors.fill: parent
onClicked: {
numberOfTaps++
if (numberOfTaps === 5) {
numberOfTaps = 0
invokerIface.typedCall("StartServiceByName", [{type:'s', value:'com.jolla.csd'}, {type:'u', value:0}])
}
}
}
}
DetailItem {
//: Label for the version of the device-specific software package (drivers)
//% "Device adaptation"
label: qsTrId("settings_about-la-adaptation")
value: aboutSettings.adaptationVersion
}
DetailItem {
//% "WLAN MAC address"
label: qsTrId("settings_about-la-wlan_mac_address")
value: aboutSettings.wlanMacAddress
}
DetailItem {
//% "Bluetooth address"
label: qsTrId("settings_about-la-bluetooth_address")
// value: bluetoothInfo.adapterAddress
value: aboutSettings.bluetoothAddress
visible: aboutSettings.bluetoothAddress !== '00:00:00:00:00:00'
// aboutSettings.bluetoothAddress may be 00:00:00:00:00 if the adapter could not
// be initialized at start-up, use BluetoothInfo instead (guarantees a valid address)
// BluetoothInfo {
// id: bluetoothInfo
// }
}
DetailItem {
visible: tohInfo.tohReady && value !== ""
label: "The Other Half"
value: tohInfo.tohId
TohInfo {
id: tohInfo
}
}
}
Repeater {
model: FolderListModel {
folder: "/usr/share/jolla-settings/pages/about/snippets"
showDirs: false
nameFilters: ["*.qml"]
sortField: FolderListModel.Name
}
delegate: Loader {
width: content.width
// work around model filtering entries asynchronously
source: (filePath && filePath.substr(-4, 4) === ".qml") ? filePath : ""
}
}
}
VerticalScrollDecorator {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment