Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
[qml] Merge old and new QML interfaces. Fixes MER#1418
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Nov 12, 2015
1 parent a152239 commit a30e6e9
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 2 deletions.
36 changes: 35 additions & 1 deletion rpm/statefs-qt5.spec
Expand Up @@ -57,6 +57,22 @@ Requires: statefs-contextkit-subscriber = %{version}-%{release}
%description %{subscriber_devel}
Contextkit property interface using statefs instead of contextkit

%package -n statefs-declarative-qt5
Summary: Statefs QML plugin
Group: System Environment/Libraries
Requires: statefs-contextkit-subscriber = %{version}-%{release}
%description -n statefs-declarative-qt5
%{summary}

%package -n contextkit-declarative-qt5
Summary: Contextkit QML plugin
Group: System Environment/Libraries
Requires: statefs-contextkit-subscriber = %{version}-%{release}
Obsoletes: nemo-qml-plugin-contextkit-qt5 <= 1.1.8
Provides: nemo-qml-plugin-contextkit-qt5 = 1.1.9
%description -n contextkit-declarative-qt5
%{summary}

%package tests
Summary: Tests for %{name}
Group: System Environment/Libraries
Expand Down Expand Up @@ -86,6 +102,7 @@ rm -rf %{buildroot}

%files devel
%defattr(-,root,root,-)
%dir %{_libqt5_includedir}/statefs/qt
%{_libqt5_includedir}/statefs/qt/*.hpp
%{_libdir}/pkgconfig/statefs-qt5.pc

Expand All @@ -97,17 +114,34 @@ rm -rf %{buildroot}
%defattr(-,root,root,-)
%{_libdir}/libcontextkit-statefs-qt5.so
%{_bindir}/contextkit-monitor
%{_libdir}/qt5/qml/Mer/State/*

%files %{subscriber_devel}
%defattr(-,root,root,-)
%{_includedir}/contextproperty.h
%{_libdir}/pkgconfig/contextkit-statefs.pc
%{_libdir}/pkgconfig/contextsubscriber-1.0.pc


%files -n statefs-declarative-qt5
%defattr(-,root,root,-)
%{_libdir}/qt5/qml/Mer/State/*

%files -n contextkit-declarative-qt5
%defattr(-,root,root,-)
%{_libdir}/qt5/qml/org/freedesktop/contextkit/*

%files tests
%defattr(-,root,root,-)
/opt/tests/%{name}/*

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%post %{subscriber} -p /sbin/ldconfig
%postun %{subscriber} -p /sbin/ldconfig

%post -n statefs-declarative-qt5 -p /sbin/ldconfig
%postun -n statefs-declarative-qt5 -p /sbin/ldconfig

%post -n contextkit-declarative-qt5 -p /sbin/ldconfig
%postun -n contextkit-declarative-qt5 -p /sbin/ldconfig
14 changes: 14 additions & 0 deletions src/qml/CMakeLists.txt
Expand Up @@ -20,3 +20,17 @@ set_target_properties(statefs-declarative PROPERTIES

install(TARGETS statefs-declarative DESTINATION ${DST_LIB}/qt5/qml/Mer/State)
install(FILES qmldir DESTINATION ${DST_LIB}/qt5/qml/Mer/State)

add_library(contextkit
SHARED
contextkit_plugin.cpp contextkit_property.cpp
)
qt5_use_modules(contextkit Qml)
target_link_libraries(contextkit
contextkit-statefs-qt5
)

install(TARGETS contextkit DESTINATION ${DST_LIB}/qt5/qml/org/freedesktop/contextkit)
install(FILES contextkit-qmldir
DESTINATION ${DST_LIB}/qt5/qml/org/freedesktop/contextkit
RENAME qmldir)
2 changes: 2 additions & 0 deletions src/qml/contextkit-qmldir
@@ -0,0 +1,2 @@
module org.freedesktop.contextkit
plugin contextkit
16 changes: 16 additions & 0 deletions src/qml/contextkit_plugin.cpp
@@ -0,0 +1,16 @@
/**
* @file client.hpp
* @brief Statefs QML plugin
* @copyright (C) 2013-2014 Jolla Ltd.
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

#include "contextkit_plugin.hpp"
#include "contextkit_property.hpp"

#include <qqml.h>

void ContextkitPlugin::registerTypes(char const* uri)
{
qmlRegisterType<ContextPropertyDeclarative>(uri, 1, 0, "ContextProperty");
}
14 changes: 14 additions & 0 deletions src/qml/contextkit_plugin.hpp
@@ -0,0 +1,14 @@
#ifndef _STATEFS_QML_PLUGIN_QT5_HPP_
#define _STATEFS_QML_PLUGIN_QT5_HPP_

#include <QtQml/QQmlExtensionPlugin>

class ContextkitPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.freedesktop.contextkit")
public:
void registerTypes(char const* uri);
};

#endif // _STATEFS_QML_PLUGIN_QT5_HPP_
98 changes: 98 additions & 0 deletions src/qml/contextkit_property.cpp
@@ -0,0 +1,98 @@
/**
* @file qml/property.cpp
* @brief Statefs property binding
* @copyright (C) 2012-2015 Jolla Ltd.
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

#include "contextkit_property.hpp"
#include <contextsubscriber/contextproperty.h>

ContextPropertyDeclarative::ContextPropertyDeclarative(QObject* parent)
: QObject(parent)
, state_(State::Unknown)
, impl_(nullptr)
{
}

ContextPropertyDeclarative::~ContextPropertyDeclarative()
{
}

void ContextPropertyDeclarative::componentComplete()
{
if (state_ == State::Unknown)
setSubscribed(true);
else
updateImpl();
}

void ContextPropertyDeclarative::updateImpl()
{
if (state_ == State::Subscribed) {
if (impl_) {
if (impl_->key() != key_) {
delete impl_;
} else {
impl_->subscribe();
}
}
if (!impl_) {
impl_ = new ContextProperty(key_, this);
connect(impl_, &ContextProperty::valueChanged
, this, &ContextPropertyDeclarative::valueChanged);
}
} else if (state_ == State::Unsubscribed) {
if (impl_)
impl_->unsubscribe();
}
}

QString ContextPropertyDeclarative::getKey() const
{
return key_;
}

void ContextPropertyDeclarative::setKey(QString const &key)
{
if (key_ != key) {
key_ = key;
updateImpl();
emit keyChanged();
}
}

QVariant ContextPropertyDeclarative::getValue() const
{
return impl_ ? impl_->value(default_value_) : default_value_;
}

void ContextPropertyDeclarative::setDefaultValue(QVariant const &v)
{
default_value_ = v;
}

bool ContextPropertyDeclarative::getSubscribed() const
{
return state_ == State::Subscribed;
}

void ContextPropertyDeclarative::setSubscribed(bool v)
{
auto newState = v ? State::Subscribed : State::Unsubscribed;
if (state_ != newState) {
state_ = newState;
updateImpl();
emit subscribedChanged();
}
}

void ContextPropertyDeclarative::subscribe()
{
setSubscribed(true);
}

void ContextPropertyDeclarative::unsubscribe()
{
setSubscribed(false);
}
66 changes: 66 additions & 0 deletions src/qml/contextkit_property.hpp
@@ -0,0 +1,66 @@
#ifndef _CONTEXTKIT_QML_PROPERTY_HPP_
#define _CONTEXTKIT_QML_PROPERTY_HPP_
/**
* @file qml/context_property.hpp
* @brief Contextkit property binding
* @copyright (C) 2012-2015 Jolla Ltd.
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
*/

#include <QObject>
#include <QVariant>
#include <QString>
#include <QQmlParserStatus>

class ContextProperty;

class ContextPropertyDeclarative : public QObject, public QQmlParserStatus
{
Q_OBJECT;
Q_PROPERTY(QString key READ getKey WRITE setKey
NOTIFY keyChanged);
Q_PROPERTY(QVariant value READ getValue WRITE setDefaultValue
NOTIFY valueChanged);
Q_PROPERTY(bool subscribed READ getSubscribed WRITE setSubscribed
NOTIFY subscribedChanged)
Q_CLASSINFO("DefaultProperty", "value");
Q_INTERFACES(QQmlParserStatus)

public:
ContextPropertyDeclarative(QObject* parent = 0);
~ContextPropertyDeclarative();

QString getKey() const;
void setKey(QString const&);

QVariant getValue() const;
void setDefaultValue(QVariant const&);

bool getSubscribed() const;
void setSubscribed(bool subscribed);

Q_INVOKABLE void subscribe();
Q_INVOKABLE void unsubscribe();

signals:
void valueChanged();
void subscribedChanged();
void keyChanged();

protected:
// QQmlParserStatus
virtual void classBegin() {}
virtual void componentComplete();

private:

void updateImpl();

QString key_;
QVariant default_value_;
enum class State { Unknown, Subscribed, Unsubscribed };
State state_;
ContextProperty *impl_;
};

#endif
1 change: 0 additions & 1 deletion src/qml/plugin.cpp
Expand Up @@ -13,5 +13,4 @@
void StatefsPlugin::registerTypes(char const* uri)
{
qmlRegisterType<StateProperty>(uri, 1, 1, "StateProperty");
qmlRegisterType<StateProperty>(uri, 1, 1, "ContextProperty");
}

0 comments on commit a30e6e9

Please sign in to comment.