Navigation Menu

Skip to content

Commit

Permalink
Fix battery level indication for MTP.
Browse files Browse the repository at this point in the history
[mtp] Show battery level over MTP. Fixes JB#27741

Use statefs instead of upower for reading battery level.

Signed-off-by: Marko Saukko <marko.saukko@jolla.com>
  • Loading branch information
saukko committed Feb 15, 2016
1 parent 2c25479 commit 9817f9d
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 66 deletions.
5 changes: 0 additions & 5 deletions mtpserver/mtpserver.pro
@@ -1,7 +1,3 @@
######################################################################
# Automatically generated by qmake (2.01a) Wed Jan 7 15:19:33 2009
######################################################################

TEMPLATE = lib
TARGET = mtp-server
DEPENDPATH += .
Expand All @@ -10,7 +6,6 @@ INCLUDEPATH += . \
../mts/ \
../mts/common


CONFIG += plugin debug_and_release link_pkgconfig
PKGCONFIG += buteosyncfw5
QT -= gui
Expand Down
2 changes: 2 additions & 0 deletions mts/common.pri
@@ -0,0 +1,2 @@
CONFIG += link_pkgconfig
PKGCONFIG += contextkit-statefs
7 changes: 0 additions & 7 deletions mts/mts.pro
@@ -1,7 +1,3 @@
######################################################################
# Automatically generated by qmake (2.01a) Mon Jul 27 09:33:14 2009
######################################################################

QT += xml dbus
QT -= gui

Expand Down Expand Up @@ -86,9 +82,6 @@ SOURCES += mts.cpp \
transport/usb/descriptor.c \
transport/usb/threadio.cpp

DBUS_INTERFACES = \
platform/deviceinfo/org.freedesktop.UPower.Device.xml

target.path = /usr/lib/
INSTALLS += target

Expand Down
17 changes: 7 additions & 10 deletions mts/platform/deviceinfo/deviceinfoprovider.cpp
Expand Up @@ -37,8 +37,7 @@
#include <QVariant>
#include <QMap>
#include <ssudeviceinfo.h>

#include "device_interface.h" // generated
#include <contextproperty.h>

using namespace meegomtp1dot0;

Expand All @@ -53,19 +52,17 @@ using namespace meegomtp1dot0;
* DeviceInfoProvider::DeviceInfoProvider
*********************************************/
DeviceInfoProvider::DeviceInfoProvider():
battery(new OrgFreedesktopUPowerDeviceInterface("org.freedesktop.UPower",
"/org/freedesktop/UPower/devices/battery_battery",
QDBusConnection::systemBus(), this))
battery(new ContextProperty("Battery.ChargePercentage", this))
{
getSystemInfo();

// Get the BT adapter interface, this interface can later be used to get the BT name
// which will serve as the device friendly name.
getBTAdapterInterface();

setBatteryLevel(battery->percentage());
connect(battery, &OrgFreedesktopUPowerDeviceInterface::Changed,
this, &DeviceInfoProvider::onBatteryChanged);
connect(battery, SIGNAL(valueChanged()), this, SLOT(onBatteryPercentageChanged()));
// Initialize the battery charge value.
onBatteryPercentageChanged();
}

/**********************************************
Expand Down Expand Up @@ -156,7 +153,7 @@ const QString& DeviceInfoProvider::deviceFriendlyName( bool /*current*/ )
}
#endif

void DeviceInfoProvider::onBatteryChanged()
void DeviceInfoProvider::onBatteryPercentageChanged()
{
setBatteryLevel(battery->percentage());
setBatteryLevel(battery->value().toUInt());
}
6 changes: 3 additions & 3 deletions mts/platform/deviceinfo/deviceinfoprovider.h
Expand Up @@ -34,7 +34,7 @@

#include "deviceinfo.h"

class OrgFreedesktopUPowerDeviceInterface;
class ContextProperty;

/// This class implements DeviceInfo for getting and setting device info and properties for an MTP session.

Expand Down Expand Up @@ -76,10 +76,10 @@ class DeviceInfoProvider : public DeviceInfo

QString m_defaultAdapterPath; ///< The BT default adapter interface path.

OrgFreedesktopUPowerDeviceInterface *battery;
ContextProperty *battery;

private slots:
void onBatteryChanged();
void onBatteryPercentageChanged();
};
}

Expand Down
8 changes: 0 additions & 8 deletions mts/platform/deviceinfo/org.freedesktop.UPower.Device.xml

This file was deleted.

12 changes: 4 additions & 8 deletions mts/platform/deviceinfo/unittests/unittests.pro
@@ -1,10 +1,8 @@
######################################################################
# Automatically generated by qmake (2.01a) Mon Nov 2 10:00:03 2009
######################################################################
include(../../../common.pri)

QT += dbus xml testlib
QT -= gui
CONFIG += warn_off debug_and_release link_pkgconfig
CONFIG += warn_off debug_and_release

equals(QT_MAJOR_VERSION, 4): {
CONFIG += mobility
Expand Down Expand Up @@ -33,14 +31,12 @@ INCLUDEPATH += . \
HEADERS += deviceinfoprovider_test.h \
../deviceinfoprovider.h \
../deviceinfo.h \
../xmlhandler.h \
../../../device_interface.h
../xmlhandler.h

SOURCES += deviceinfoprovider_test.cpp \
../deviceinfoprovider.cpp \
../deviceinfo.cpp \
../xmlhandler.cpp \
../../../device_interface.cpp
../xmlhandler.cpp

target.path = /opt/tests/buteo-mtp/
INSTALLS += target
Expand Down
6 changes: 2 additions & 4 deletions mts/platform/storage/fsstorageplugin/fsstorageplugin.pro
@@ -1,11 +1,9 @@
######################################################################
# Automatically generated by qmake (2.01a) Mon Nov 2 15:56:26 2009
######################################################################
include(../../../common.pri)

TEMPLATE = lib
TARGET = fsstorage

CONFIG += plugin link_pkgconfig debug qtsparql
CONFIG += plugin debug qtsparql

QT += dbus xml
QT -= gui
Expand Down
8 changes: 2 additions & 6 deletions mts/platform/storage/fsstorageplugin/unittests/unittests.pro
@@ -1,8 +1,6 @@
######################################################################
# Automatically generated by qmake (2.01a) Tue Oct 27 14:29:51 2009
######################################################################
include(../../../../common.pri)

CONFIG += warn_off debug_and_release link_pkgconfig
CONFIG += warn_off debug_and_release
CONFIG += qtsparql

PKGCONFIG += buteosyncfw5 Qt5SystemInfo
Expand Down Expand Up @@ -46,7 +44,6 @@ HEADERS += fsstorageplugin_test.h \
../thumbnailerproxy.h \
../storagetracker.h \
../../storagefactory.h \
../../../../device_interface.h \
../storageitem.h \
mts.h \
protocol/mtpresponder.h \
Expand Down Expand Up @@ -75,7 +72,6 @@ SOURCES += fsstorageplugin_test.cpp \
../storagetracker.cpp \
../../storagefactory.cpp \
../../storageplugin.cpp \
../../../../device_interface.cpp \
mts.cpp \
protocol/mtpresponder.cpp \
protocol/mtpcontainer.cpp \
Expand Down
5 changes: 2 additions & 3 deletions mts/platform/storage/unittests/unittests.pro
@@ -1,4 +1,5 @@
CONFIG += link_pkgconfig
include(../../../common.pri)

TEMPLATE = app
TARGET = storagefactory-test
QT += testlib xml dbus
Expand Down Expand Up @@ -28,7 +29,6 @@ HEADERS += \
../../deviceinfo/deviceinfo.h \
../../deviceinfo/deviceinfoprovider.h \
../../deviceinfo/xmlhandler.h \
../../../device_interface.h \
../../../protocol/mtpresponder.h \
../../../protocol/objectpropertycache.h \
../../../protocol/propertypod.h \
Expand All @@ -43,7 +43,6 @@ SOURCES += \
../../deviceinfo/deviceinfo.cpp \
../../deviceinfo/deviceinfoprovider.cpp \
../../deviceinfo/xmlhandler.cpp \
../../../device_interface.cpp \
../../../protocol/mtpcontainer.cpp \
../../../protocol/mtpcontainerwrapper.cpp \
../../../protocol/mtpextensionmanager.cpp \
Expand Down
12 changes: 4 additions & 8 deletions mts/protocol/unittests/unittests.pro
@@ -1,8 +1,6 @@
######################################################################
# Automatically generated by qmake (2.01a) Tue Oct 27 14:29:51 2009
######################################################################
include(../../common.pri)

CONFIG += warn_off debug_and_release link_pkgconfig
CONFIG += warn_off debug_and_release

equals(QT_MAJOR_VERSION, 4): {
CONFIG += mobility
Expand Down Expand Up @@ -65,8 +63,7 @@ HEADERS += mtpresponder_test.h \
../../transport/usb/mtptransporterusb.h \
../../transport/usb/threadio.h \
../../transport/dummy/mtptransporterdummy.h \
../../device_interface.h \
../../mts.h
../../mts.h

SOURCES += mtpresponder_test.cpp \
../mtpresponder.cpp \
Expand All @@ -85,8 +82,7 @@ SOURCES += mtpresponder_test.cpp \
../../transport/usb/descriptor.c \
../../transport/usb/threadio.cpp \
../../transport/dummy/mtptransporterdummy.cpp \
../../device_interface.cpp \
../../mts.cpp
../../mts.cpp

target.path = /opt/tests/buteo-mtp/
INSTALLS += target
Expand Down
1 change: 1 addition & 0 deletions rpm/buteo-mtp-qt5.spec
Expand Up @@ -19,6 +19,7 @@ BuildRequires: pkgconfig(mount)
# for the thumbnailer unit test
BuildRequires: pkgconfig(Qt5Gui)
BuildRequires: ssu-devel >= 0.37.9
BuildRequires: pkgconfig(contextkit-statefs) >= 0.2.7
Requires: mtp-vendor-configuration
# buteo-mtp can use org.freedesktop.thumbnails.Thumbnailer1 to create
# thumbnails on request; at least Windows 8 requires thumbnails to be
Expand Down
4 changes: 0 additions & 4 deletions test/test.pro
@@ -1,7 +1,3 @@
######################################################################
# Automatically generated by qmake (2.01a) Mon Jul 27 10:46:26 2009
######################################################################

TEMPLATE = app
TARGET = mtp_test
DEPENDPATH += .
Expand Down

0 comments on commit 9817f9d

Please sign in to comment.