Skip to content

Commit

Permalink
[contextkit] Reimplement contextkit QML API. Contributes to JB#48573
Browse files Browse the repository at this point in the history
Reimplement this module to provide context properties implemented by
a QML backend.

The API is unchanged. In the implementation, ContextProperty is now a
QML type that dynamically loads the QML file specified by the 'key'.

The module is installed to /usr/lib/qt5/qml/org/freedesktop/contextkit.
Provider files are installed to /usr/share/contextkit.

See examples/allkeys.qml for an example showing all supported keys and
their values.

The keys supported by statefs-providers have been ported here, except
for the following legacy providers:

- back_cover providing "BackCover.*" keys
- keyboard_generic providing "maemo_InternalKeyboard.*" keys
- provider_bme and provider_upower, which were obsoleted by power_udev
  • Loading branch information
Bea Lam committed Feb 13, 2020
1 parent 4a39923 commit 973e9f4
Show file tree
Hide file tree
Showing 36 changed files with 1,668 additions and 424 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt

This file was deleted.

13 changes: 8 additions & 5 deletions README
Expand Up @@ -3,11 +3,14 @@ ContextKit QML bindings
Usage:

# some.qml
...
import org.freedesktop.contextkit 1.0
...

ContextProperty {
key: "keyname"
value: default_value_before_update
key: "KeyGroup.Key"
value: optionalDefaultValueBeforeUpdate

onValueChanged: console.log("Value updated:", value)
}
...


Load examples/allkeys.qml to see all supported keys and their values.
45 changes: 0 additions & 45 deletions examples/ShowContextKitProperty.qml

This file was deleted.

188 changes: 188 additions & 0 deletions examples/allkeys.qml
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2020 Open Mobile Platform LLC.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

import QtQuick 2.6
import Sailfish.Silica 1.0
import org.freedesktop.contextkit 1.0

ApplicationWindow {
id: root

initialPage: demoComponent
allowedOrientations: Orientation.All
_defaultPageOrientations: Orientation.All

readonly property var keys: {
"Alarm": [
"Present",
"Triggers",
],

"Battery": [
"Capacity",
"ChargePercentage",
"ChargerType",
"ChargingState",
"Current",
"Energy",
"EnergyFull",
"IsCharging",
"Level",
"LowBattery",
"OnBattery",
"Power",
"State",
"Temperature",
"TimeUntilFull",
"TimeUntilLow",
"Voltage",
],

"Cellular": [
"CachedCardIdentifier",
"CachedSubscriberIdentity",
"CallCount",
"CapabilityData",
"CapabilityVoice",
"CellName",
"CurrentMCC",
"CurrentMNC",
"DataRoamingAllowed",
"DataTechnology",
"ExtendedNetworkName",
"GPRSAttached",
"HomeMCC",
"HomeMNC",
"MMSContext",
"ModemPath",
"NetworkName",
"RegistrationStatus",
"ServiceProviderName",
"SignalBars",
"SignalStrength",
"Sim",
"Status",
"StkIdleModeText",
"SubscriberIdentity",
"Technology",
],

"Internet": [
"NetworkName",
"NetworkState",
"NetworkType",
"SignalStrength",
"Tethering",
],

"Profile": [
"Name",
],

"Screen": [
"Blanked",
],

"Sensors": [
"Orientation",
],

"System": [
"PowerSaveMode",
"OfflineMode",
"WlanEnabled",
"InternetEnabled",
"KeyboardPresent",
"KeyboardOpen",
]
}

ListModel {
id: listModel

Component.onCompleted: {
for (var k in root.keys) {
append({"namespace": k})
if (k === "Cellular") {
append({"namespace": "Cellular_1"})
}
}
}
}

Component {
id: demoComponent

Page {
ListView {
anchors.fill: parent
header: PageHeader { title: "Context properties" }
model: listModel

delegate: ListItem {
Label {
anchors.centerIn: parent
text: model.namespace
}

onClicked: {
var keys = model.namespace === "Cellular_1"
? root.keys["Cellular"]
: root.keys[model.namespace]
pageStack.animatorPush(keysComponent, {
"namespace": model.namespace,
"keyList": keys
})
}
}
}
}
}

Component {
id: keysComponent

Page {
property string namespace
property var keyList

ListView {
anchors.fill: parent
header: PageHeader { title: namespace }
model: keyList

delegate: DetailItem {
label: modelData
value: contextProperty.value === undefined
? "undefined"
: contextProperty.value.toString()

ContextProperty {
id: contextProperty
key: namespace + "." + modelData
value: ""
}
}
}
}
}
}

3 changes: 3 additions & 0 deletions nemo-qml-plugin-contextkit.pro
@@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = src
OTHER_FILES += examples/*.qml
26 changes: 15 additions & 11 deletions rpm/nemo-qml-plugin-contextkit-qt5.spec
@@ -1,15 +1,20 @@
Summary: ContextKit QML bindings
Name: nemo-qml-plugin-contextkit-qt5
Version: 1.1
Version: 2.0
Release: 2
License: LGPLv2
Group: Applications/System
URL: https://github.com/nemomobile/nemo-qml-plugin-contextkit
URL: https://git.sailfishos.org/mer-core/nemo-qml-plugin-contextkit
Source0: %{name}-%{version}.tar.bz2

Obsoletes: contextkit-declarative-qt5
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(contextkit-statefs) >= 0.2.34
BuildRequires: cmake >= 2.8
Requires: nemo-qml-plugin-dbus
Requires: nemo-qml-plugin-mce
Requires: kf5bluezqt-bluez5-declarative
Requires: libqofono-qt5-declarative
Requires: connman-qt5-declarative
Requires: qt5-qtdeclarative-import-sensors

%description
%{summary}
Expand All @@ -18,15 +23,14 @@ BuildRequires: cmake >= 2.8
%setup -q -n %{name}-%{version}

%build
%cmake -DUSEQT=5
make %{?jobs:-j%jobs}
%qmake5
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
%cmake -DUSEQT=5
make install DESTDIR=%{buildroot}
%qmake5_install

%files
%defattr(-,root,root,-)
%{_libdir}/qt5/qml/org/freedesktop/contextkit/libcontextkit.so
%{_libdir}/qt5/qml/org/freedesktop/contextkit/qmldir
%{_libdir}/qt5/qml/org/freedesktop/contextkit
%{_datadir}/contextkit/providers
34 changes: 0 additions & 34 deletions rpm/nemo-qml-plugin-contextkit.spec

This file was deleted.

0 comments on commit 973e9f4

Please sign in to comment.