Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
thp committed Apr 28, 2015
1 parent 3289b63 commit 93e09d6
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 83 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-systemsettings.spec
Expand Up @@ -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}.
Expand Down
167 changes: 125 additions & 42 deletions src/datetimesettings.cpp
Expand Up @@ -30,63 +30,109 @@
*/

#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());
}


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
Expand All @@ -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();
}
}
20 changes: 15 additions & 5 deletions src/datetimesettings.h
Expand Up @@ -35,7 +35,8 @@
#include <QObject>
#include <QTime>

#include <qmtime.h>
#include <timed-qt5/interface>
#include <timed-qt5/wallclock>

class DateTimeSettings: public QObject
{
Expand Down Expand Up @@ -76,13 +77,22 @@ class DateTimeSettings: public QObject
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
2 changes: 1 addition & 1 deletion src/plugin/plugin.pro
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/src.pro
Expand Up @@ -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)

Expand Down Expand Up @@ -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

0 comments on commit 93e09d6

Please sign in to comment.