diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..439ae67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +build +.DS_Store +*.pro.user diff --git a/README b/README new file mode 100644 index 0000000..d9eb767 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Qt client for mce, and a declarative plugin for it. diff --git a/lib/dbus/com.nokia.mce.request.xml b/lib/dbus/com.nokia.mce.request.xml new file mode 100644 index 0000000..a1af125 --- /dev/null +++ b/lib/dbus/com.nokia.mce.request.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/lib/dbus/com.nokia.mce.signal.xml b/lib/dbus/com.nokia.mce.signal.xml new file mode 100644 index 0000000..e85f63b --- /dev/null +++ b/lib/dbus/com.nokia.mce.signal.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/lib/include/qmcedisplay.h b/lib/include/qmcedisplay.h new file mode 100644 index 0000000..3a3d226 --- /dev/null +++ b/lib/include/qmcedisplay.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef QMCE_DISPLAY_H +#define QMCE_DISPLAY_H + +#include "qmcetypes.h" + +class QMCE_EXPORT QMceDisplay : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool valid READ valid NOTIFY validChanged) + Q_PROPERTY(State state READ state NOTIFY stateChanged) + Q_ENUMS(State) + +public: + enum State { + DisplayOff, + DisplayDim, + DisplayOn + }; + + QMceDisplay(QObject* aParent = NULL); + + bool valid() const; + State state() const; + +Q_SIGNALS: + void validChanged(); + void stateChanged(); + +private: + class Private; + Private* iPrivate; +}; + +#endif // QMCE_DISPLAY_H diff --git a/lib/include/qmcetklock.h b/lib/include/qmcetklock.h new file mode 100644 index 0000000..6d38d48 --- /dev/null +++ b/lib/include/qmcetklock.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef QMCE_TKLOCK_H +#define QMCE_TKLOCK_H + +#include "qmcetypes.h" + +class QMCE_EXPORT QMceTkLock : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool valid READ valid NOTIFY validChanged) + Q_PROPERTY(bool locked READ locked NOTIFY lockedChanged) + Q_PROPERTY(Mode mode READ mode NOTIFY modeChanged) + Q_ENUMS(Mode) + +public: + enum Mode { + Locked, + SilentLocked, + LockedDim, + LockedDelay, + SilentLockedDim, + Unlocked, + SilentUnlocked + }; + + QMceTkLock(QObject* aParent = NULL); + + bool valid() const; + bool locked() const; + Mode mode() const; + +Q_SIGNALS: + void validChanged(); + void lockedChanged(); + void modeChanged(); + +private: + class Private; + Private* iPrivate; +}; + +#endif // QMCE_TKLOCK_H diff --git a/lib/include/qmcetypes.h b/lib/include/qmcetypes.h new file mode 100644 index 0000000..e08f6f9 --- /dev/null +++ b/lib/include/qmcetypes.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef QMCE_TYPES_H +#define QMCE_TYPES_H + +#include + +#ifdef QMCE_LIBRARY +# define QMCE_EXPORT Q_DECL_EXPORT +#else +# define QMCE_EXPORT Q_DECL_IMPORT +#endif + +#endif // QMCE_TYPES_H diff --git a/lib/lib.pro b/lib/lib.pro new file mode 100644 index 0000000..ff4d923 --- /dev/null +++ b/lib/lib.pro @@ -0,0 +1,64 @@ +TARGET = mce-qt5 +CONFIG += create_pc create_prl no_install_prl link_pkgconfig +PKGCONFIG += mce + +QT += dbus +QT -= gui +QMAKE_CXXFLAGS += -Wno-unused-parameter -Wno-psabi +INCLUDEPATH += include + +include(version.pri) + +TEMPLATE = lib +DEFINES += QMCE_LIBRARY + +isEmpty(PREFIX) { + PREFIX=/usr +} + +XML_FILES += \ + dbus/com.nokia.mce.request.xml \ + dbus/com.nokia.mce.signal.xml + +OTHER_FILES += $$XML_FILES + +SOURCES += \ + src/qmcedisplay.cpp \ + src/qmceproxy.cpp \ + src/qmcetklock.cpp + +PUBLIC_HEADERS += \ + include/qmcedisplay.h \ + include/qmcetypes.h \ + include/qmcetklock.h + +HEADERS += \ + $$PUBLIC_HEADERS \ + src/qmceproxy.h + +DBUS_INTERFACES += com_nokia_mce_request +com_nokia_mce_request.files = dbus/com.nokia.mce.request.xml +com_nokia_mce_request.header_flags = -N -c QMceRequestProxy +com_nokia_mce_request.source_flags = -N -c QMceRequestProxy + +DBUS_INTERFACES += com_nokia_mce_signal +com_nokia_mce_signal.files = dbus/com.nokia.mce.signal.xml +com_nokia_mce_signal.header_flags = -N -c QMceSignalProxy +com_nokia_mce_signal.source_flags = -N -c QMceSignalProxy + +target.path = $$[QT_INSTALL_LIBS] + +headers.files = $$PUBLIC_HEADERS +headers.path = $$INSTALL_ROOT$$PREFIX/include/mce-qt5 + +pkgconfig.files = mce-qt5.pc +pkgconfig.path = $$[QT_INSTALL_LIBS]/pkgconfig + +QMAKE_PKGCONFIG_NAME = $$TARGET +QMAKE_PKGCONFIG_DESTDIR = pkgconfig +QMAKE_PKGCONFIG_INCDIR = $$headers.path +QMAKE_PKGCONFIG_DESCRIPTION = Qt bindings for mce +QMAKE_PKGCONFIG_PREFIX = $$PREFIX +QMAKE_PKGCONFIG_VERSION = $$VERSION + +INSTALLS += target headers pkgconfig diff --git a/lib/src/qmcedisplay.cpp b/lib/src/qmcedisplay.cpp new file mode 100644 index 0000000..6fd4ef8 --- /dev/null +++ b/lib/src/qmcedisplay.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "qmcedisplay.h" +#include "qmceproxy.h" + +#include "mce/mode-names.h" + +class QMceDisplay::Private : public QObject { + Q_OBJECT + +public: + Private(QMceDisplay* aParent); + + void queryDisplayStatus(); + +private Q_SLOTS: + void onProxyValidChanged(); + void onQueryFinished(QDBusPendingCallWatcher* aWatcher); + void updateDisplayStatus(QString aStatus); + +public: + QMceDisplay* iParent; + QSharedPointer iProxy; + bool iValid; + QMceDisplay::State iState; +}; + +QMceDisplay::Private::Private(QMceDisplay* aParent) : + QObject(aParent), + iParent(aParent), + iProxy(QMceProxy::instance()), + iValid(false), + iState(DisplayOff) +{ + connect(iProxy->signalProxy(), + SIGNAL(display_status_ind(QString)), + SLOT(updateDisplayStatus(QString))); + connect(iProxy.data(), + SIGNAL(validChanged()), + SLOT(onProxyValidChanged())); + if (iProxy->valid()) { + queryDisplayStatus(); + } +} + +void QMceDisplay::Private::queryDisplayStatus() +{ + connect(new QDBusPendingCallWatcher( + iProxy->requestProxy()->get_display_status(), this), + SIGNAL(finished(QDBusPendingCallWatcher*)), + SLOT(onQueryFinished(QDBusPendingCallWatcher*))); +} + +void QMceDisplay::Private::updateDisplayStatus(QString aStatus) +{ + static const QString MCE_DISPLAY_OFF(MCE_DISPLAY_OFF_STRING); + static const QString MCE_DISPLAY_DIM(MCE_DISPLAY_DIM_STRING); + static const QString MCE_DISPLAY_ON(MCE_DISPLAY_ON_STRING); + QMceDisplay::State state; + if (aStatus == MCE_DISPLAY_OFF) { + state = DisplayOff; + } else if (aStatus == MCE_DISPLAY_DIM) { + state = DisplayDim; + } else { + state = DisplayOn; + } + if (iState != state) { + iState = state; + Q_EMIT iParent->stateChanged(); + } +} + +void QMceDisplay::Private::onQueryFinished(QDBusPendingCallWatcher* aWatcher) +{ + QDBusPendingReply reply(*aWatcher); + if (!reply.isError()) { + updateDisplayStatus(reply.value()); + if (!iValid) { + iValid = true; + Q_EMIT iParent->validChanged(); + } + } + aWatcher->deleteLater(); +} + +void QMceDisplay::Private::onProxyValidChanged() +{ + if (iProxy->valid()) { + queryDisplayStatus(); + } else { + if (iValid) { + iValid = false; + Q_EMIT iParent->validChanged(); + } + } +} + +// ========================================================================== +// QMceDisplay +// ========================================================================== + +QMceDisplay::QMceDisplay(QObject* aParent) : + QObject(aParent), + iPrivate(new Private(this)) +{ +} + +bool QMceDisplay::valid() const +{ + return iPrivate->iValid; +} + +QMceDisplay::State QMceDisplay::state() const +{ + return iPrivate->iState; +} + +#include "qmcedisplay.moc" diff --git a/lib/src/qmceproxy.cpp b/lib/src/qmceproxy.cpp new file mode 100644 index 0000000..888b343 --- /dev/null +++ b/lib/src/qmceproxy.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "qmceproxy.h" + +#include "mce/dbus-names.h" + +class QMceProxy::Private : public QObject { + Q_OBJECT + +public: + Private(QMceProxy* aParent); + + QMceRequestProxy* requestProxy(); + QMceSignalProxy* signalProxy(); + +private Q_SLOTS: + void onServiceRegistered(); + void onServiceUnregistered(); + +public: + QMceProxy* iParent; + bool iValid; + +private: + QDBusConnection iBus; + QString iService; + QMceRequestProxy* iRequestProxy; + QMceSignalProxy* iSignalProxy; +}; + +QMceProxy::Private::Private(QMceProxy* aParent) : + QObject(aParent), + iParent(aParent), + iBus(QDBusConnection::systemBus()), + iService(MCE_SERVICE), + iRequestProxy(NULL), + iSignalProxy(NULL) +{ + iValid = iBus.interface()->isServiceRegistered(iService); + QDBusServiceWatcher* watcher = new QDBusServiceWatcher(iService, iBus, + QDBusServiceWatcher::WatchForRegistration | + QDBusServiceWatcher::WatchForUnregistration, this); + connect(watcher, + SIGNAL(serviceRegistered(QString)), + SLOT(onServiceRegistered())); + connect(watcher, + SIGNAL(serviceUnregistered(QString)), + SLOT(onServiceUnregistered())); +} + +QMceRequestProxy* QMceProxy::Private::requestProxy() +{ + if (!iRequestProxy) { + iRequestProxy = new QMceRequestProxy(iService, + MCE_REQUEST_PATH, iBus, this); + } + return iRequestProxy; +} + +QMceSignalProxy* QMceProxy::Private::signalProxy() +{ + if (!iSignalProxy) { + iSignalProxy = new QMceSignalProxy(iService, + MCE_SIGNAL_PATH, iBus, this); + } + return iSignalProxy; +} + +void QMceProxy::Private::onServiceRegistered() +{ + if (!iValid) { + iValid = true; + Q_EMIT iParent->validChanged(); + } +} + +void QMceProxy::Private::onServiceUnregistered() +{ + if (iValid) { + iValid = false; + Q_EMIT iParent->validChanged(); + } +} + +// ========================================================================== +// QMceProxy +// ========================================================================== + +QMceProxy::QMceProxy() : + iPrivate(new Private(this)) +{ +} + +bool QMceProxy::valid() const +{ + return iPrivate->iValid; +} + +QMceRequestProxy* QMceProxy::requestProxy() +{ + return iPrivate->requestProxy(); +} + +QMceSignalProxy* QMceProxy::signalProxy() +{ + return iPrivate->signalProxy(); +} + +QSharedPointer QMceProxy::instance() +{ + static QWeakPointer sSharedInstance; + QSharedPointer ref = sSharedInstance; + if (ref.isNull()) { + ref = QSharedPointer(new QMceProxy, &QObject::deleteLater); + sSharedInstance = ref; + } + return ref; +} + +#include "qmceproxy.moc" diff --git a/lib/src/qmceproxy.h b/lib/src/qmceproxy.h new file mode 100644 index 0000000..14f8e30 --- /dev/null +++ b/lib/src/qmceproxy.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef QMCE_PROXY_H +#define QMCE_PROXY_H + +#include "qmcetypes.h" + +// Generated headers +#include "request_interface.h" +#include "signal_interface.h" + +class QMceProxy : public QObject +{ + Q_OBJECT + + QMceProxy(); + +public: + static QSharedPointer instance(); + + bool valid() const; + + QMceRequestProxy* requestProxy(); + QMceSignalProxy* signalProxy(); + +Q_SIGNALS: + void validChanged(); + +private: + class Private; + Private* iPrivate; +}; + +#endif // QMCE_PROXY_H diff --git a/lib/src/qmcetklock.cpp b/lib/src/qmcetklock.cpp new file mode 100644 index 0000000..3a8fa13 --- /dev/null +++ b/lib/src/qmcetklock.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "qmcetklock.h" +#include "qmceproxy.h" + +#include "mce/mode-names.h" + +class QMceTkLock::Private : public QObject { + Q_OBJECT + +public: + Private(QMceTkLock* aParent); + + void queryMode(); + +private Q_SLOTS: + void onProxyValidChanged(); + void onQueryFinished(QDBusPendingCallWatcher* aWatcher); + void updateMode(QString aStatus); + +public: + QMceTkLock* iParent; + QSharedPointer iProxy; + bool iValid; + bool iLocked; + Mode iMode; +}; + +QMceTkLock::Private::Private(QMceTkLock* aParent) : + QObject(aParent), + iParent(aParent), + iProxy(QMceProxy::instance()), + iValid(false), + iLocked(true), + iMode(Locked) +{ + connect(iProxy->signalProxy(), + SIGNAL(tklock_mode_ind(QString)), + SLOT(updateMode(QString))); + connect(iProxy.data(), + SIGNAL(validChanged()), + SLOT(onProxyValidChanged())); + if (iProxy->valid()) { + queryMode(); + } +} + +void QMceTkLock::Private::queryMode() +{ + connect(new QDBusPendingCallWatcher( + iProxy->requestProxy()->get_tklock_mode(), this), + SIGNAL(finished(QDBusPendingCallWatcher*)), + SLOT(onQueryFinished(QDBusPendingCallWatcher*))); +} + +void QMceTkLock::Private::updateMode(QString aMode) +{ + static const struct tklock_mode { + QString name; + Mode mode; + bool locked; + } modes [] = { + /* Most commonly used modes first */ + { MCE_TK_LOCKED, Locked, true }, + { MCE_TK_UNLOCKED, Unlocked, false }, + { MCE_TK_SILENT_LOCKED, SilentLocked, true }, + { MCE_TK_LOCKED_DIM, LockedDim, true }, + { MCE_TK_LOCKED_DELAY, LockedDelay, true }, + { MCE_TK_SILENT_LOCKED_DIM, SilentLockedDim, true }, + { MCE_TK_SILENT_UNLOCKED, SilentUnlocked, false } + }; + const Mode prevMode = iMode; + const bool prevLocked = iLocked; + for (uint i=0; imodeChanged(); + } + if (iLocked != prevLocked) { + Q_EMIT iParent->lockedChanged(); + } +} + +void QMceTkLock::Private::onQueryFinished(QDBusPendingCallWatcher* aWatcher) +{ + QDBusPendingReply reply(*aWatcher); + if (!reply.isError()) { + updateMode(reply.value()); + if (!iValid) { + iValid = true; + Q_EMIT iParent->validChanged(); + } + } + aWatcher->deleteLater(); +} + +void QMceTkLock::Private::onProxyValidChanged() +{ + if (iProxy->valid()) { + queryMode(); + } else { + if (iValid) { + iValid = false; + Q_EMIT iParent->validChanged(); + } + } +} + +// ========================================================================== +// QMceTkLock +// ========================================================================== + +QMceTkLock::QMceTkLock(QObject* aParent) : + QObject(aParent), + iPrivate(new Private(this)) +{ +} + +bool QMceTkLock::valid() const +{ + return iPrivate->iValid; +} + +bool QMceTkLock::locked() const +{ + return iPrivate->iLocked; +} + +QMceTkLock::Mode QMceTkLock::mode() const +{ + return iPrivate->iMode; +} + +#include "qmcetklock.moc" diff --git a/lib/version.pri b/lib/version.pri new file mode 100644 index 0000000..f69ac30 --- /dev/null +++ b/lib/version.pri @@ -0,0 +1 @@ +VERSION = 1.0.0 diff --git a/libmce-qt.pro b/libmce-qt.pro new file mode 100644 index 0000000..f314e33 --- /dev/null +++ b/libmce-qt.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS += lib plugin +OTHER_FILES += rpm/libmce-qt5.spec README +lib.target = lib-target +plugin.depends = lib-target diff --git a/plugin/plugin.pro b/plugin/plugin.pro new file mode 100644 index 0000000..ef0b3af --- /dev/null +++ b/plugin/plugin.pro @@ -0,0 +1,19 @@ +TARGET = qmcedeclarative +TEMPLATE = lib +CONFIG += plugin link_pkgconfig +PKGCONFIG += mce +QMAKE_CXXFLAGS += -Wno-unused-parameter -Wno-psabi + +QT += qml +QT -= gui +LIBS += -L../lib -lmce-qt5 +INCLUDEPATH += ../lib/include + +SOURCES = qmcedeclarativeplugin.cpp +OTHER_FILES += qmldir + +target.path = $$[QT_INSTALL_QML]/org/sailfish/mce +qmldir.path = $$[QT_INSTALL_QML]/org/sailfish/mce +qmldir.files += qmldir + +INSTALLS += target qmldir diff --git a/plugin/qmcedeclarativeplugin.cpp b/plugin/qmcedeclarativeplugin.cpp new file mode 100644 index 0000000..4f9f048 --- /dev/null +++ b/plugin/qmcedeclarativeplugin.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 Jolla Ltd. + * Contact: Slava Monich + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Jolla Ltd nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "qmcedisplay.h" +#include "qmcetklock.h" + +#include + +class QMCE_EXPORT QMceDeclarativePlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char* aUri); + static void registerTypes(const char* aUri, int aMajor, int aMinor); +}; + +void QMceDeclarativePlugin::registerTypes(const char* aUri, int aMajor, int aMinor) +{ + qmlRegisterType(aUri, aMajor, aMinor, "MceDisplay"); + qmlRegisterType(aUri, aMajor, aMinor, "MceTkLock"); +} + +void QMceDeclarativePlugin::registerTypes(const char* aUri) +{ + registerTypes(aUri, 1, 0); +} + +#include "qmcedeclarativeplugin.moc" diff --git a/plugin/qmldir b/plugin/qmldir new file mode 100644 index 0000000..b3b82e9 --- /dev/null +++ b/plugin/qmldir @@ -0,0 +1,2 @@ +module org.sailfish.mce +plugin qmcedeclarative diff --git a/rpm/libmce-qt5.spec b/rpm/libmce-qt5.spec new file mode 100644 index 0000000..c8d4ac3 --- /dev/null +++ b/rpm/libmce-qt5.spec @@ -0,0 +1,68 @@ +Name: libmce-qt5 + +Summary: A library of Qt bindings for mce +Version: 1.0.0 +Release: 1 +Group: System/Libraries +License: BSD +URL: https://git.merproject.org/mer-core/libmce-qt5 +Source0: libmce-qt5-%{version}.tar.bz2 +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(Qt5DBus) +BuildRequires: pkgconfig(Qt5Quick) +BuildRequires: pkgconfig(mce) + +%{!?qtc_qmake5:%define qtc_qmake5 %qmake5} +%{!?qtc_make:%define qtc_make make} + +%description +This package contains Qt bindings for mce + +%package declarative +Summary: Declarative plugin for libmce-qt5 +Group: Development/Tools +Requires: %{name} = %{version}-%{release} +Requires: %{name} = %{version} + +%description declarative +This package contains declarative plugin for libmce-qt5 + +%package devel +Summary: Development files for libmce-qt5 +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: %{name} = %{version} + +%description devel +This package contains the development header files for libmce-qt5 + +%prep +%setup -q -n %{name}-%{version} + +%build +%qtc_qmake5 +%qtc_make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +%qmake5_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root,-) +%{_libdir}/%{name}.so.* + +%files declarative +%defattr(-,root,root,-) +%{_libdir}/qt5/qml/org/sailfish/mce + +%files devel +%defattr(-,root,root,-) +%{_libdir}/%{name}.so +%{_libdir}/pkgconfig/mce-qt5.pc +%{_includedir}/mce-qt5/*.h