Commit 93e09d64 authored by Thomas Perl's avatar Thomas Perl

[packaging] Remove qmsystem2 dependency (contributes to JB#12048)

[datetimesettings] Remove QmTime dependency (use timed directly)
[usbsettings] Remove QmUsbMode usage (use usb_moded directly)
[usbsettings] Allow setting of current mode
[usbsettings] Re-use old enum values from qmsystem2 for compatibility
[usbsettings] Require usb-moded >= 0.82
parent 3289b63a
......@@ -11,11 +11,11 @@ Requires(postun): /sbin/ldconfig
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5SystemInfo)
BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(qmsystem2-qt5) >= 1.4.17
BuildRequires: pkgconfig(timed-qt5)
BuildRequires: pkgconfig(profile)
BuildRequires: pkgconfig(mce)
BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(usb_moded) >= 0.82
%description
%{summary}.
......
......@@ -30,30 +30,61 @@
*/
#include "datetimesettings.h"
#include <timed-qt5/interface>
#include <timed-qt5/wallclock>
#include <QDebug>
DateTimeSettings::DateTimeSettings(QObject *parent)
: QObject(parent),
m_autoSystemTime(m_time.autoSystemTime()),
m_autoTimezone(m_time.autoTimeZone())
: QObject(parent)
, m_timed()
, m_timezone()
, m_autoSystemTime(false)
, m_autoTimezone(false)
, m_timedInfoValid(false)
, m_timedInfo()
{
m_time.getTimezone(m_timezone);
connect(&m_time, SIGNAL(timeOrSettingsChanged(MeeGo::QmTime::WhatChanged)),
this, SLOT(handleTimeChanged(MeeGo::QmTime::WhatChanged)));
if (!m_timed.settings_changed_connect(this, SLOT(onTimedSignal(const Maemo::Timed::WallClock::Info &, bool)))) {
qWarning("Connection to timed signal failed: '%s'", Maemo::Timed::bus().lastError().message().toStdString().c_str());
}
// Request the first update of the wall clock info
updateTimedInfo();
}
DateTimeSettings::~DateTimeSettings()
{
}
void DateTimeSettings::updateTimedInfo()
{
QDBusPendingCall call = m_timed.get_wall_clock_info_async();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
this, SLOT(onGetWallClockInfoFinished(QDBusPendingCallWatcher *)));
}
void DateTimeSettings::onGetWallClockInfoFinished(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<Maemo::Timed::WallClock::Info> reply = *watcher;
if (reply.isError()) {
qWarning("Could not retrieve wall clock info: '%s'", reply.error().message().toStdString().c_str());
} else {
onTimedSignal(reply.value(), false);
}
watcher->deleteLater();
}
void DateTimeSettings::setTime(int hour, int minute)
{
QDate currentDate = QDate::currentDate();
QTime time(hour, minute);
QDateTime newTime(currentDate, time);
m_time.setTime(newTime.toTime_t());
setTime(newTime.toTime_t());
}
......@@ -61,32 +92,47 @@ void DateTimeSettings::setDate(const QDate &date)
{
QDateTime newTime = QDateTime::currentDateTime();
newTime.setDate(date);
m_time.setTime(newTime.toTime_t());
setTime(newTime.toTime_t());
}
bool DateTimeSettings::automaticTimeUpdate()
{
return m_autoSystemTime == MeeGo::QmTime::AutoSystemTimeOn;
return m_autoSystemTime;
}
void DateTimeSettings::setAutomaticTimeUpdate(bool enable)
{
m_time.setAutoSystemTime(enable ? MeeGo::QmTime::AutoSystemTimeOn : MeeGo::QmTime::AutoSystemTimeOff);
if (enable != m_autoSystemTime) {
Maemo::Timed::WallClock::Settings s;
if (enable) {
s.setTimeNitz();
} else {
s.setTimeManual();
}
setSettings(s);
}
}
bool DateTimeSettings::automaticTimezoneUpdate()
{
return m_autoTimezone == MeeGo::QmTime::AutoTimeZoneOn;
return m_autoTimezone;
}
void DateTimeSettings::setAutomaticTimezoneUpdate(bool enable)
{
bool enabled = m_autoTimezone == MeeGo::QmTime::AutoTimeZoneOn;
if (enabled == enable) {
return;
}
if (enable != m_autoTimezone) {
Maemo::Timed::WallClock::Settings s;
if (enable) {
s.setTimezoneCellular();
} else {
s.setTimezoneManual("");
}
m_time.setAutoTimeZone(enable ? MeeGo::QmTime::AutoTimeZoneOn : MeeGo::QmTime::AutoTimeZoneOff);
setSettings(s);
}
}
QString DateTimeSettings::timezone() const
......@@ -100,40 +146,77 @@ void DateTimeSettings::setTimezone(const QString &tz)
return;
}
m_time.setTimezone(tz);
Maemo::Timed::WallClock::Settings s;
s.setTimezoneManual(tz);
setSettings(s);
}
void DateTimeSettings::setHourMode(DateTimeSettings::HourMode mode)
{
Maemo::Timed::Interface timedInterface;
Maemo::Timed::WallClock::Settings settings;
settings.setFlag24(mode == TwentyFourHours);
timedInterface.wall_clock_settings_async(settings);
Maemo::Timed::WallClock::Settings s;
s.setFlag24(mode == TwentyFourHours);
setSettings(s);
}
void DateTimeSettings::onWallClockSettingsFinished(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<bool> reply = *watcher;
if (reply.isError()) {
qWarning("Could not set wall clock settings: '%s'", reply.error().message().toStdString().c_str());
} else if (!reply.value()) {
qWarning("Could not set wall clock settings");
}
watcher->deleteLater();
}
bool DateTimeSettings::setSettings(Maemo::Timed::WallClock::Settings &s)
{
if (!s.check()) {
return false;
}
QDBusPendingCall call = m_timed.wall_clock_settings_async(s);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
this, SLOT(onWallClockSettingsFinished(QDBusPendingCallWatcher *)));
return true;
}
bool DateTimeSettings::setTime(time_t time)
{
Maemo::Timed::WallClock::Settings s;
s.setTimeManual(time);
return setSettings(s);
}
void DateTimeSettings::handleTimeChanged(MeeGo::QmTime::WhatChanged what)
void DateTimeSettings::onTimedSignal(const Maemo::Timed::WallClock::Info &info, bool time_changed)
{
switch (what) {
case MeeGo::QmTime::TimeChanged:
m_timedInfo = info;
m_timedInfoValid = true;
if (time_changed) {
emit timeChanged();
// fall through
case MeeGo::QmTime::OnlySettingsChanged:
{
MeeGo::QmTime::AutoSystemTimeStatus newAutoSystemTime = m_time.autoSystemTime();
if (newAutoSystemTime != m_autoSystemTime) {
m_autoSystemTime = newAutoSystemTime;
emit automaticTimeUpdateChanged();
}
MeeGo::QmTime::AutoTimeZoneStatus newAutoTimezone = m_time.autoTimeZone();
if (newAutoTimezone != m_autoTimezone) {
m_autoTimezone = newAutoTimezone;
emit automaticTimezoneUpdateChanged();
}
QString newTimezone;
if (m_time.getTimezone(newTimezone) && newTimezone != m_timezone) {
m_timezone = newTimezone;
emit timezoneChanged();
}
}
bool newAutoSystemTime = info.flagTimeNitz();
if (newAutoSystemTime != m_autoSystemTime) {
m_autoSystemTime = newAutoSystemTime;
emit automaticTimeUpdateChanged();
}
bool newAutoTimezone = info.flagLocalCellular();
if (newAutoTimezone != m_autoTimezone) {
m_autoTimezone = newAutoTimezone;
emit automaticTimezoneUpdateChanged();
}
QString newTimezone = info.humanReadableTz();
if (newTimezone != m_timezone) {
m_timezone = newTimezone;
emit timezoneChanged();
}
}
......@@ -35,7 +35,8 @@
#include <QObject>
#include <QTime>
#include <qmtime.h>
#include <timed-qt5/interface>
#include <timed-qt5/wallclock>
class DateTimeSettings: public QObject
{
......@@ -76,13 +77,22 @@ signals:
void timezoneChanged();
private slots:
void handleTimeChanged(MeeGo::QmTime::WhatChanged what);
void onTimedSignal(const Maemo::Timed::WallClock::Info &info, bool time_changed);
void onGetWallClockInfoFinished(QDBusPendingCallWatcher *watcher);
void onWallClockSettingsFinished(QDBusPendingCallWatcher *watcher);
private:
MeeGo::QmTime m_time;
MeeGo::QmTime::AutoSystemTimeStatus m_autoSystemTime;
MeeGo::QmTime::AutoTimeZoneStatus m_autoTimezone;
bool setTime(time_t time);
bool setSettings(Maemo::Timed::WallClock::Settings &s);
void updateTimedInfo();
private:
Maemo::Timed::Interface m_timed;
QString m_timezone;
bool m_autoSystemTime;
bool m_autoTimezone;
bool m_timedInfoValid;
Maemo::Timed::WallClock::Info m_timedInfo;
};
#endif
......@@ -6,7 +6,7 @@ CONFIG += qt plugin hide_symbols link_pkgconfig
QT += qml dbus network
QT -= gui
PKGCONFIG += qmsystem2-qt5 profile
PKGCONFIG += profile
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
INSTALLS += target
......
......@@ -7,7 +7,7 @@ QT += qml dbus systeminfo
QT -= gui
CONFIG += link_pkgconfig
PKGCONFIG += qmsystem2-qt5 profile mlite5
PKGCONFIG += profile mlite5 usb_moded timed-qt5
system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
......@@ -51,6 +51,6 @@ QMAKE_PKGCONFIG_DESCRIPTION = System settings application development files
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$develheaders.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus profile qmsystem2-qt5
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus profile
INSTALLS += target develheaders pkgconfig
......@@ -31,17 +31,89 @@
#include "usbsettings.h"
USBSettings::USBSettings(QObject *parent)
: QObject(parent),
m_qmmode(new MeeGo::QmUSBMode(this))
#include "usb_moded-dbus.h"
#include "usb_moded-modes.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusReply>
static QDBusMessage call_usb_moded(const QString &method, const QList<QVariant> &arguments=QList<QVariant>())
{
QDBusMessage methodCall = QDBusMessage::createMethodCall(USB_MODE_SERVICE, USB_MODE_OBJECT,
USB_MODE_INTERFACE, method);
methodCall.setArguments(arguments);
return QDBusConnection::systemBus().call(methodCall);
}
static const struct {
const char *name;
enum USBSettings::Mode mode;
} mode_mapping[] = {
// States (from usb_moded-dbus.h)
{ USB_CONNECTED, USBSettings::Connected },
{ DATA_IN_USE, USBSettings::DataInUse },
{ USB_DISCONNECTED, USBSettings::Disconnected },
{ USB_CONNECTED_DIALOG_SHOW, USBSettings::ModeRequest },
// Modes (from usb_moded-modes.h)
{ MODE_MASS_STORAGE, USBSettings::MassStorage },
{ MODE_CHARGING, USBSettings::ChargingOnly },
{ MODE_CHARGING_FALLBACK, USBSettings::ChargingOnly },
{ MODE_PC_SUITE, USBSettings::PCSuite },
{ MODE_ASK, USBSettings::Ask },
{ MODE_UNDEFINED, USBSettings::Undefined },
{ MODE_DEVELOPER, USBSettings::Developer },
{ MODE_MTP, USBSettings::MTP },
{ MODE_ADB, USBSettings::Adb },
{ MODE_DIAG, USBSettings::Diag },
{ MODE_CONNECTION_SHARING, USBSettings::ConnectionSharing },
{ MODE_HOST, USBSettings::Host },
{ MODE_CHARGER, USBSettings::Charger },
};
#define ARRAY_SIZE(x) (int)(sizeof(x)/sizeof((x)[0]))
static enum USBSettings::Mode decodeMode(const QString &name)
{
for (int i=0; i<ARRAY_SIZE(mode_mapping); i++) {
if (name == mode_mapping[i].name) {
return mode_mapping[i].mode;
}
}
return USBSettings::Undefined;
}
static QString encodeMode(enum USBSettings::Mode mode)
{
connect(m_qmmode, SIGNAL(modeChanged(MeeGo::QmUSBMode::Mode)),
this, SIGNAL(currentModeChanged()));
for (int i=0; i<ARRAY_SIZE(mode_mapping); i++) {
if (mode == mode_mapping[i].mode) {
return QString(mode_mapping[i].name);
}
}
foreach (MeeGo::QmUSBMode::Mode supportedMode, m_qmmode->getSupportedModes()) {
m_supportedUSBModes.append((int)supportedMode);
return MODE_UNDEFINED;
}
USBSettings::USBSettings(QObject *parent)
: QObject(parent)
, m_supportedUSBModes()
{
// TODO: We could connect to USB_MODE_SUPPORTED_MODES_SIGNAL_NAME and update the internal
// list plus emit supportedUSBModesChanged()
QDBusReply<QString> supportedModes = call_usb_moded("get_modes");
foreach (QString part, supportedModes.value().split(',')) {
m_supportedUSBModes << decodeMode(part.trimmed());
}
emit supportedUSBModesChanged();
QDBusConnection::systemBus().connect(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE,
USB_MODE_SIGNAL_NAME, this, SLOT(currentModeChanged()));
// TODO: We could watch the default mode (no signal yet in usb_moded) and
// emit defaultModeChanged() so that the settings UI is always up to date
}
USBSettings::~USBSettings()
......@@ -50,12 +122,14 @@ USBSettings::~USBSettings()
USBSettings::Mode USBSettings::currentMode() const
{
return (Mode)m_qmmode->getMode();
QDBusReply<QString> reply = call_usb_moded("mode_request");
return reply.isValid() ? decodeMode(reply.value()) : USBSettings::Undefined;
}
USBSettings::Mode USBSettings::defaultMode() const
{
return (Mode)m_qmmode->getDefaultMode();
QDBusReply<QString> reply = call_usb_moded("get_config");
return reply.isValid() ? decodeMode(reply.value()) : USBSettings::Undefined;
}
QList<int> USBSettings::supportedUSBModes() const
......@@ -69,9 +143,17 @@ void USBSettings::setDefaultMode(const Mode mode)
return;
}
if (m_qmmode->setDefaultMode((MeeGo::QmUSBMode::Mode)mode)) {
QDBusReply<QString> reply = call_usb_moded("set_config", QVariantList() << encodeMode(mode));
if (reply.isValid() && decodeMode(reply.value()) == mode) {
emit defaultModeChanged();
} else {
qWarning("Couldn't set default mode");
}
}
void USBSettings::setCurrentMode(const Mode mode)
{
QDBusMessage call = QDBusMessage::createMethodCall(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_STATE_SET);
call << encodeMode(mode);
QDBusConnection::systemBus().call(call, QDBus::NoBlock);
}
......@@ -32,7 +32,8 @@
#ifndef USBSETTINGS_H
#define USBSETTINGS_H
#include <qmusbmode.h>
#include <QObject>
#include <QList>
class USBSettings: public QObject
{
......@@ -40,29 +41,37 @@ class USBSettings: public QObject
Q_ENUMS(Mode)
Q_PROPERTY(Mode currentMode READ currentMode NOTIFY currentModeChanged)
Q_PROPERTY(Mode currentMode READ currentMode WRITE setCurrentMode NOTIFY currentModeChanged)
Q_PROPERTY(Mode defaultMode READ defaultMode WRITE setDefaultMode NOTIFY defaultModeChanged)
Q_PROPERTY(QList<int> supportedUSBModes READ supportedUSBModes NOTIFY supportedUSBModesChanged)
public:
/**
* Keep this in sync with usb_moded-dbus.h (for states) and usb_moded-modes.h (for modes),
* existing enum values taken from legacy qmsystem2 enum mapping for compatibility
**/
enum Mode {
Connected = MeeGo::QmUSBMode::Connected,
DataInUse = MeeGo::QmUSBMode::DataInUse,
Disconnected = MeeGo::QmUSBMode::Disconnected,
MassStorage = MeeGo::QmUSBMode::MassStorage,
ChargingOnly = MeeGo::QmUSBMode::ChargingOnly,
OviSuite = MeeGo::QmUSBMode::OviSuite,
ModeRequest = MeeGo::QmUSBMode::ModeRequest,
Ask = MeeGo::QmUSBMode::Ask,
Undefined = MeeGo::QmUSBMode::Undefined,
SDK = MeeGo::QmUSBMode::SDK,
Developer = MeeGo::QmUSBMode::Developer,
MTP = MeeGo::QmUSBMode::MTP,
Adb = MeeGo::QmUSBMode::Adb,
Diag = MeeGo::QmUSBMode::Diag,
Host = MeeGo::QmUSBMode::Host,
Charger = MeeGo::QmUSBMode::Charger,
ConnectionSharing = MeeGo::QmUSBMode::ConnectionSharing
// States (from usb_moded-dbus.h)
Connected = 0,
DataInUse = 1,
Disconnected = 2,
ModeRequest = 6,
// Modes (from usb_moded-modes.h)
MassStorage = 3,
ChargingOnly = 4,
PCSuite = 5,
Ask = 7,
Undefined = 8,
Developer = 10,
MTP = 11,
Adb = 12,
Diag = 13,
ConnectionSharing = 14,
Host = 15,
Charger = 16,
// When adding new Mode/State IDs, start with 50 (assume 0-49 was used by qmsystem2)
};
explicit USBSettings(QObject *parent = 0);
......@@ -74,6 +83,7 @@ public:
public slots:
void setDefaultMode(const Mode mode);
void setCurrentMode(const Mode mode);
signals:
void currentModeChanged();
......@@ -81,8 +91,6 @@ signals:
void supportedUSBModesChanged();
private:
MeeGo::QmUSBMode *m_qmmode;
QList<int> m_supportedUSBModes;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment