Skip to content

Commit

Permalink
[mce-qt] Add support for charger type tracking. JB#38667
Browse files Browse the repository at this point in the history
Required constants are defined in mce-dev >= 1.27.0

The D-Bus methods and signals are available in mce >= 1.102.9

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Aug 28, 2019
1 parent df25cb4 commit 9e8fb61
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/dbus/com.nokia.mce.request.xml
Expand Up @@ -134,6 +134,9 @@
<method name="get_charger_state">
<arg direction="out" name="charger_state" type="s"/>
</method>
<method name="get_charger_type">
<arg direction="out" name="charger_type" type="s"/>
</method>
<method name="get_usb_cable_state">
<arg direction="out" name="usb_cable_state" type="s"/>
</method>
Expand Down
3 changes: 3 additions & 0 deletions lib/dbus/com.nokia.mce.signal.xml
Expand Up @@ -57,6 +57,9 @@
<signal name="charger_state_ind">
<arg name="charger_state" type="s"/>
</signal>
<signal name="charger_type_ind">
<arg name="charger_type" type="s"/>
</signal>
<signal name="usb_cable_state_ind">
<arg name="usb_cable_state" type="s"/>
</signal>
Expand Down
62 changes: 62 additions & 0 deletions lib/include/qmcechargertype.h
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* 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_CHARGERTYPE_H_
#define QMCE_CHARGERTYPE_H_

#include "qmcetypes.h"

class QMCE_EXPORT QMceChargerType : public QObject
{
Q_OBJECT
Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
Q_PROPERTY(Type type READ type NOTIFY typeChanged)
Q_ENUMS(Type)
public:
enum Type { None, USB, DCP, HVDCP, CDP, Wireless, Other, };
QMceChargerType(QObject* aParent = NULL);
bool valid() const;
Type type() const;
Q_SIGNALS:
void validChanged();
void typeChanged();
private:
class Private;
Private* iPrivate;
};

#endif // QMCE_CHARGERTYPE_H_
2 changes: 2 additions & 0 deletions lib/lib.pro
Expand Up @@ -27,6 +27,7 @@ SOURCES += \
src/qmcebatterystatus.cpp \
src/qmcecablestate.cpp \
src/qmcecallstate.cpp \
src/qmcechargertype.cpp \
src/qmcechargerstate.cpp \
src/qmcedisplay.cpp \
src/qmcepowersavemode.cpp \
Expand All @@ -38,6 +39,7 @@ PUBLIC_HEADERS += \
include/qmcebatterystatus.h \
include/qmcecablestate.h \
include/qmcecallstate.h \
include/qmcechargertype.h \
include/qmcechargerstate.h \
include/qmcedisplay.h \
include/qmcepowersavemode.h \
Expand Down
180 changes: 180 additions & 0 deletions lib/src/qmcechargertype.cpp
@@ -0,0 +1,180 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* 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 "qmcechargertype.h"
#include "qmceproxy.h"

#include <mce/mode-names.h>

// ==========================================================================
// QMceChargerType::Private
// ==========================================================================

class QMceChargerType::Private : public QObject {
Q_OBJECT
public:
Private(QMceChargerType* aParent);
bool valid() const;
QMceChargerType::Type value() const;
private:
void queryValue();
void setValid(bool valid);
private Q_SLOTS:
void onProxyValidChanged();
void onQueryFinished(QDBusPendingCallWatcher* aWatcher);
void updateValue(QString type);
private:
QMceChargerType* iParent;
QSharedPointer<QMceProxy> iProxy;
bool iValid;
QMceChargerType::Type iValue;
};

QMceChargerType::Private::Private(QMceChargerType* aParent) :
QObject(aParent),
iParent(aParent),
iProxy(QMceProxy::instance()),
iValid(false),
iValue(None)
{
connect(iProxy->signalProxy(),
SIGNAL(charger_type_ind(QString)),
SLOT(updateValue(QString)));
connect(iProxy.data(),
SIGNAL(validChanged()),
SLOT(onProxyValidChanged()));
if (iProxy->valid()) {
queryValue();
}
}

bool QMceChargerType::Private::valid() const
{
return iValid;
}

void QMceChargerType::Private::setValid(bool valid)
{
if (iValid != valid) {
iValid = valid;
Q_EMIT iParent->validChanged();
}
}

QMceChargerType::Type QMceChargerType::Private::value() const
{
return iValue;
}

void QMceChargerType::Private::updateValue(QString type)
{
bool valid = true;
QMceChargerType::Type value = Other;

if (type == QStringLiteral(MCE_CHARGER_TYPE_NONE))
value = None;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_USB))
value = USB;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_DCP))
value = DCP;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_HVDCP))
value = HVDCP;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_CDP))
value = CDP;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_WIRELESS))
value = Wireless;
else if (type == QStringLiteral(MCE_CHARGER_TYPE_OTHER))
value = Other;
else
valid = false;

if (valid) {
if (iValue != value) {
iValue = value;
Q_EMIT iParent->typeChanged();
}
}
setValid(valid);
}

void QMceChargerType::Private::queryValue()
{
connect(new QDBusPendingCallWatcher(
iProxy->requestProxy()->get_charger_type(), this),
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(onQueryFinished(QDBusPendingCallWatcher*)));
}

void QMceChargerType::Private::onQueryFinished(QDBusPendingCallWatcher* aWatcher)
{
QDBusPendingReply<QString> reply(*aWatcher);
if (!reply.isError()) {
updateValue(reply.value());
}
aWatcher->deleteLater();
}

void QMceChargerType::Private::onProxyValidChanged()
{
if (iProxy->valid()) {
queryValue();
} else {
setValid(false);
}
}

// ==========================================================================
// QMceChargerType
// ==========================================================================

QMceChargerType::QMceChargerType(QObject* aParent) :
QObject(aParent),
iPrivate(new Private(this))
{
}

bool QMceChargerType::valid() const
{
return iPrivate->valid();
}

QMceChargerType::Type QMceChargerType::type() const
{
return iPrivate->value();
}

#include "qmcechargertype.moc"
2 changes: 2 additions & 0 deletions plugin/qmcedeclarativeplugin.cpp
Expand Up @@ -43,6 +43,7 @@
#include "qmcechargerstate.h"
#include "qmcepowersavemode.h"
#include "qmcecallstate.h"
#include "qmcechargertype.h"

#include <QtQml>

Expand All @@ -66,6 +67,7 @@ void QMceDeclarativePlugin::registerTypes(const char* aUri, int aMajor, int aMin
qmlRegisterType<QMceChargerState>(aUri, aMajor, aMinor, "MceChargerState");
qmlRegisterType<QMcePowerSaveMode>(aUri, aMajor, aMinor, "McePowerSaveMode");
qmlRegisterType<QMceCallState>(aUri, aMajor, aMinor, "QMceCallState");
qmlRegisterType<QMceChargerType>(aUri, aMajor, aMinor, "QMceChargerType");
}

void QMceDeclarativePlugin::registerTypes(const char* aUri)
Expand Down
3 changes: 2 additions & 1 deletion rpm/libmce-qt5.spec
Expand Up @@ -12,7 +12,8 @@ Requires(postun): /sbin/ldconfig
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(mce)
BuildRequires: pkgconfig(mce) >= 1.27.0
Requires: mce >= 1.102.0

%{!?qtc_qmake5:%define qtc_qmake5 %qmake5}
%{!?qtc_make:%define qtc_make make}
Expand Down

0 comments on commit 9e8fb61

Please sign in to comment.