From ccbfa0884072c26979a6475de71635c19a474cca Mon Sep 17 00:00:00 2001 From: Teemu Holappa Date: Mon, 9 Nov 2015 16:39:08 +0200 Subject: Device settings UI. Implemented settings application for changing device settings. There are implemented settings UI for network, time and date, locale, bluetooth, audio and display. Change-Id: I26077ce1f2356eb8520fad61cf07407c6a0f98c1 Reviewed-by: Kimmo Ollila Reviewed-by: Risto Avila --- .../timedateplugin/AnalogClock.qml | 255 +++++++++++++++++++++ src/qtdevicesettings/timedateplugin/TimeDate.qml | 167 ++++++++++++++ .../timedateplugin/TimezonesView.qml | 94 ++++++++ src/qtdevicesettings/timedateplugin/icons.qrc | 4 + src/qtdevicesettings/timedateplugin/plugin.cpp | 78 +++++++ src/qtdevicesettings/timedateplugin/qml.qrc | 7 + src/qtdevicesettings/timedateplugin/qmldir | 3 + src/qtdevicesettings/timedateplugin/systemtime.cpp | 85 +++++++ src/qtdevicesettings/timedateplugin/systemtime.h | 73 ++++++ src/qtdevicesettings/timedateplugin/systemtime_p.h | 88 +++++++ src/qtdevicesettings/timedateplugin/timedated.xml | 30 +++ .../timedateplugin/timedateplugin.pro | 42 ++++ .../timedateplugin/timezonefiltermodel.cpp | 104 +++++++++ .../timedateplugin/timezonefiltermodel.h | 59 +++++ .../timedateplugin/timezonemodel.cpp | 140 +++++++++++ .../timedateplugin/timezonemodel.h | 89 +++++++ 16 files changed, 1318 insertions(+) create mode 100644 src/qtdevicesettings/timedateplugin/AnalogClock.qml create mode 100644 src/qtdevicesettings/timedateplugin/TimeDate.qml create mode 100644 src/qtdevicesettings/timedateplugin/TimezonesView.qml create mode 100644 src/qtdevicesettings/timedateplugin/icons.qrc create mode 100644 src/qtdevicesettings/timedateplugin/plugin.cpp create mode 100644 src/qtdevicesettings/timedateplugin/qml.qrc create mode 100644 src/qtdevicesettings/timedateplugin/qmldir create mode 100644 src/qtdevicesettings/timedateplugin/systemtime.cpp create mode 100644 src/qtdevicesettings/timedateplugin/systemtime.h create mode 100644 src/qtdevicesettings/timedateplugin/systemtime_p.h create mode 100644 src/qtdevicesettings/timedateplugin/timedated.xml create mode 100644 src/qtdevicesettings/timedateplugin/timedateplugin.pro create mode 100644 src/qtdevicesettings/timedateplugin/timezonefiltermodel.cpp create mode 100644 src/qtdevicesettings/timedateplugin/timezonefiltermodel.h create mode 100644 src/qtdevicesettings/timedateplugin/timezonemodel.cpp create mode 100644 src/qtdevicesettings/timedateplugin/timezonemodel.h (limited to 'src/qtdevicesettings/timedateplugin') diff --git a/src/qtdevicesettings/timedateplugin/AnalogClock.qml b/src/qtdevicesettings/timedateplugin/AnalogClock.qml new file mode 100644 index 0000000..2b89401 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/AnalogClock.qml @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.timedate 1.0 + +Item { + property var currentTime: TimeManager.time + property var newTime: new Date + property bool editMode: false + + function showTime(time) { + return time.getHours() + ":" + time.getMinutes() + } + + onEditModeChanged: if (editMode) newTime = new Date + + Rectangle { + border.color: "#bdbebf" + border.width: 1 + color: "white" + anchors.fill: parent + + Connections { + target: TimeManager + onTimeChanged : newTime.setSeconds(currentTime.getSeconds()) + onTimeZoneChanged : Date.timeZoneUpdated() + } + + TextLabel { + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 10 + anchors.top: parent.top + text: editMode ? newTime.toTimeString() : currentTime.toTimeString() + } + + Rectangle { + id: root + anchors.fill: parent + anchors.margins: Math.round(40 * Flat.FlatStyle.scaleFactor) + color: "white" + border.color: editMode ? "#d6d6d6" : "#5caa15" + border.width: Math.round(root.width * 0.120) + radius: parent.width / 2 + property int handOffset: Math.round(root.width * 0.040) + antialiasing: true + + Rectangle { + id: minutes + x: root.height / 2 - width / 2 + y: root.height / 2 - height + root.handOffset + color: editMode ? "#d6d6d6" : "#5caa15" + width: Math.round(root.width * 0.080) + height: Math.round(root.height / 2 * 0.65 + root.handOffset) + antialiasing: true + transform: Rotation { + id: minuteRotation + origin.x: Math.round(minutes.width / 2) + origin.y: Math.round(minutes.height - root.handOffset) + angle: currentTime.getMinutes() * 6 + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + Rectangle { + id: hours + x: Math.round(root.height / 2 - width / 2) + y: Math.round(root.height / 2 - height + root.handOffset) + height: Math.round(root.height / 2 * 0.4 + root.handOffset) + width: Math.round(root.width * 0.080) + color: editMode ? "#d6d6d6" : "#80c342" + antialiasing: true + transform: Rotation { + id: hourRotation + origin.x: Math.round(hours.width / 2) + origin.y: hours.height - root.handOffset; + angle: (currentTime.getHours() * 30) + (currentTime.getMinutes() * 0.5) + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + Rectangle { + id: seconds + x: root.height / 2 - width / 2 + y: root.height / 2 - height + root.handOffset + visible: !editMode + color: "#46a2da" + width: Math.round(root.width * 0.0128) + height: Math.round(root.height / 2 * 0.74) + radius: Math.round(width / 2) + antialiasing: true + transform: Rotation { + id: secondRotation + origin.x: Math.round(seconds.width / 2) + origin.y: Math.round(seconds.height - root.handOffset) + angle: currentTime.getSeconds() * 6 + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + Component { + id: editor + + Rectangle { + id: rect + property var angle: mouseArea.drag ? mouseArea.angle : defaultAngle + property var defaultAngle: angleBinding + x: Math.round(Math.cos((-90+ angle)*Math.PI/180) * + (pos - root.handOffset - width /2 + radius) + root.width / 2 - width / 2) + y: Math.round(Math.sin((-90+ angle)*Math.PI/180) * + (pos - root.handOffset - width /2 + radius) + root.height / 2 - width / 2) + color: "#5caa15" + width: size + radius: width / 2 + height: width + antialiasing: true + + function calcAngle(mouse) { + var mouseGlobal = mapToItem(root, mouse.x, mouse.y) + var origin = root.width/2 + var angle = (90+Math.atan2((mouseGlobal.y-origin), (mouseGlobal.x-origin))*180/Math.PI) + if (angle < 0) + angle += 360; + updateAngle(angle); + return angle; + } + + MouseArea { + id: mouseArea + anchors.fill: parent + property int startX: 0 + property int startY: 0 + property bool drag: false + property var angle: 0.0 + preventStealing: true + + onPressed: { + var mouseGlobal = mapToItem(root, mouse.x, mouse.y); + startX = mouseGlobal.x; + startY = mouseGlobal.y; + angle = calcAngle(mouse); + drag = true; + } + onReleased: { + drag = false; + ready(angle) + } + onMouseXChanged: if (drag) angle = calcAngle(mouse) + } + } + } + + Loader { + property var angleBinding: (currentTime.getHours() * 30) + (currentTime.getMinutes() * 0.5) + property int size: Math.round(root.width * 0.120) + property int pos: hours.height + property bool pm: false + visible: editMode + + function updateAngle(angle) { + var newHour = Math.floor(angle / 30); + var preHour = newTime.getHours(); + + if (preHour == 11 && newHour == 0) { + newHour = 12; + pm = true; + } + else if (preHour === 23 && newHour === 0) { + pm = false; + } + else if (preHour == 0 && newHour === 11) { + pm = true; + } + else if (preHour == 12 && newHour == 11) { + pm = false; + } + + if (pm == true) { + newHour += 12; + } + + newTime.setHours(newHour); + } + + function ready(val) { + var newhours = Math.round(val / 30); + currentTime.setHours(newhours); + TimeManager.time = currentTime; + } + sourceComponent: editor + } + + Loader { + property var angleBinding: currentTime.getMinutes() * 6 + property int size: Math.round(root.width * 0.120) + property int pos: minutes.height + visible: editMode + sourceComponent: editor + + function updateAngle(angle) { + var newMin = Math.round(angle / 6); + var hours = newTime.getHours(); + newTime.setMinutes(newMin); + newTime.setHours(hours); + } + + function ready(val) { + var newmins = Math.round(val / 6); + currentTime.setMinutes(newmins); + TimeManager.time = currentTime; + } + } + } + } +} + diff --git a/src/qtdevicesettings/timedateplugin/TimeDate.qml b/src/qtdevicesettings/timedateplugin/TimeDate.qml new file mode 100644 index 0000000..6731805 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/TimeDate.qml @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.timedate 1.0 + +Item { + id: root + property string title: qsTr("Time and Date settings") + + Flickable { + anchors.fill: parent + anchors.margins: Math.round(40 * Flat.FlatStyle.scaleFactor) + anchors.bottomMargin: Math.round(20 * Flat.FlatStyle.scaleFactor) + contentHeight: content.height + contentWidth: width + + Column { + id: content + width: parent.width + + GroupBox { + width: parent.width + title: qsTr("Time Settings") + Layout.fillWidth: true + + ColumnLayout { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + width: parent.width + Layout.fillWidth: true + + ExclusiveGroup { id: exgroup } + + RadioButton { + id: automatic + text: qsTr("Automatic time set") + exclusiveGroup: exgroup + checked: TimeManager.ntp + onCheckedChanged: if (checked) calloader.reload(); + } + RadioButton { + id: custom + text: qsTr("Manual") + exclusiveGroup: exgroup + checked: !TimeManager.ntp + onCheckedChanged: TimeManager.ntp = !checked + } + RowLayout { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Layout.fillWidth: true + + Component { + id: calendar + + Item { + width: cal.width + height: cal.height + + Timer { + id: timer + } + function delay(delayTime, cb) { + timer.interval = delayTime; + timer.repeat = false; + timer.triggered.connect(cb); + timer.start(); + } + + Calendar { + id: cal + weekNumbersVisible: false + enabled: !automatic.checked + onClicked: { + var currentTime = TimeManager.time; + var newDate = date; + newDate.setHours(currentTime.getHours()); + newDate.setMinutes(currentTime.getMinutes()); + newDate.setSeconds(currentTime.getSeconds()); + TimeManager.time = newDate; + delay(100, function() { + calloader.reload(); + }); + } + } + } + } + + Loader { + id: calloader + sourceComponent: calendar + function reload() { + calloader.sourceComponent = undefined; + calloader.sourceComponent = calendar; + } + } + + AnalogClock { + id: clock + width: calloader.width + height: width + editMode: !automatic.checked + } + } + + Component { + id: zoneselect + TimezonesView { } + } + + GroupBox { + title: qsTr("Timezone Settings") + Layout.fillWidth: true + width: parent.width + visible: true + flat: true + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: TimeManager.timeZone + } + Button { + text: "Change" + onClicked : stackView.push(zoneselect) + } + } + } + } + } + } + } +} diff --git a/src/qtdevicesettings/timedateplugin/TimezonesView.qml b/src/qtdevicesettings/timedateplugin/TimezonesView.qml new file mode 100644 index 0000000..458d611 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/TimezonesView.qml @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.timedate 1.0 + + +Item { + id: root + Component.onCompleted: timezone.text = TimezonesFilter.filter + + Column { + id: content + anchors.fill: parent + anchors.margins: Math.round(20 * Flat.FlatStyle.scaleFactor) + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + + TextLabel { + text: qsTr("Search area: ") + } + + TextField { + id: timezone + text: "" + onTextChanged: TimezonesFilter.filter = timezone.text + } + } + + TableView { + width: parent.width + height: Math.round(parent.height - 40 * Flat.FlatStyle.scaleFactor) + Layout.fillWidth: true + model: TimezonesFilter + headerVisible: true + + TableViewColumn { + role: "name" + title: qsTr("Timezone") + width: Math.round(parent.width * 0.66) + } + TableViewColumn { + role: "country" + title: qsTr("Country") + width: Math.round(parent.width * 0.33) + } + + onClicked: { + var val = model.itemFromRow(row); + if (val !== "") { + TimeManager.timeZone = val; + stackView.pop(); + } + } + } + } +} diff --git a/src/qtdevicesettings/timedateplugin/icons.qrc b/src/qtdevicesettings/timedateplugin/icons.qrc new file mode 100644 index 0000000..af8a564 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/icons.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/src/qtdevicesettings/timedateplugin/plugin.cpp b/src/qtdevicesettings/timedateplugin/plugin.cpp new file mode 100644 index 0000000..3fa4939 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/plugin.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "systemtime.h" +#include "timezonemodel.h" +#include "timezonefiltermodel.h" + +template +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class TimeDateSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + const QString prefix = "qrc:"; + qmlRegisterSingletonType(uri, 1, 0, "TimeManager", &instance); + } + + void initializeEngine(QQmlEngine * engine, const char * uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.timedate")); + TimezoneModel* timezoneModel = new TimezoneModel(engine); + TimezoneFilterModel* filter = new TimezoneFilterModel(engine); + filter->setSourceModel(timezoneModel); + + engine->rootContext()->setContextProperty("Timezones", timezoneModel); + engine->rootContext()->setContextProperty("TimezonesFilter", filter); + } +}; + +#include "plugin.moc" diff --git a/src/qtdevicesettings/timedateplugin/qml.qrc b/src/qtdevicesettings/timedateplugin/qml.qrc new file mode 100644 index 0000000..e04454d --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/qml.qrc @@ -0,0 +1,7 @@ + + + TimeDate.qml + AnalogClock.qml + TimezonesView.qml + + diff --git a/src/qtdevicesettings/timedateplugin/qmldir b/src/qtdevicesettings/timedateplugin/qmldir new file mode 100644 index 0000000..2d7a8a6 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/qmldir @@ -0,0 +1,3 @@ +module com.theqtcompany.settings.timedate +TimeDate 1.0 TimeDate.qml +plugin qmltimedatesettingsplugin diff --git a/src/qtdevicesettings/timedateplugin/systemtime.cpp b/src/qtdevicesettings/timedateplugin/systemtime.cpp new file mode 100644 index 0000000..c84b036 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/systemtime.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "systemtime.h" +#include "systemtime_p.h" + +SystemTime::SystemTime(QObject *parent) : + QObject(parent) + ,d_ptr(new SystemTimePrivate(this)) +{ + QTimer *secTimer = new QTimer(this); + connect(secTimer, &QTimer::timeout, this, &SystemTime::timeChanged); + secTimer->setInterval(1001); + secTimer->setSingleShot(false); + secTimer->start(); +} + +bool SystemTime::ntp() const +{ + const Q_D(SystemTime); + return d->ntp(); +} + +void SystemTime::setNtp(const bool aNtp) +{ + Q_D(SystemTime); + d->setNtp(aNtp); +} + +void SystemTime::setTime(const QDateTime& aTime) +{ + Q_D(SystemTime); + d->setTime(aTime.toMSecsSinceEpoch()*1000); + emit timeChanged(); +} + +QString SystemTime::timeZone() const +{ + Q_D(const SystemTime); + return d->timeZone(); +} + +void SystemTime::setTimeZone(const QString& aTimeZone) +{ + Q_D(SystemTime); + d->setTimeZone(aTimeZone); + emit timeZoneChanged(); +} + +QDateTime SystemTime::time() const +{ + return QDateTime::currentDateTime(); +} diff --git a/src/qtdevicesettings/timedateplugin/systemtime.h b/src/qtdevicesettings/timedateplugin/systemtime.h new file mode 100644 index 0000000..092712c --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/systemtime.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_H +#define SYSTEMTIME_H + +#include +#include + +class SystemTimePrivate; + +class SystemTime : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged) + Q_PROPERTY(bool ntp READ ntp WRITE setNtp NOTIFY ntpChanged) + Q_PROPERTY(QDateTime time READ time WRITE setTime NOTIFY timeChanged) +public: + explicit SystemTime(QObject *parent = 0); + bool ntp() const; + void setNtp(const bool aNtp); + void setTime(const QDateTime& aTime); + QString timeZone() const; + QDateTime time() const; + void setTimeZone(const QString& aTimeZone); + +signals: + void timeZoneChanged(); + void ntpChanged(); + void timeChanged(); + +public slots: + +protected: + SystemTimePrivate *d_ptr; + + Q_DISABLE_COPY(SystemTime) + Q_DECLARE_PRIVATE(SystemTime) +}; + +#endif // SYSTEMTIME_H diff --git a/src/qtdevicesettings/timedateplugin/systemtime_p.h b/src/qtdevicesettings/timedateplugin/systemtime_p.h new file mode 100644 index 0000000..5ee6eef --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/systemtime_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_P_H +#define SYSTEMTIME_P_H + +#include "systemtime.h" +#include "timedated_interface.h" + +class SystemTimePrivate +{ + Q_DECLARE_PUBLIC(SystemTime) +public: + SystemTimePrivate(SystemTime *qq) + :q_ptr(qq) + { + m_timeInterface = new OrgFreedesktopTimedate1Interface(QStringLiteral("org.freedesktop.timedate1"), + QStringLiteral("/org/freedesktop/timedate1"), + QDBusConnection::systemBus(), qq); + + } + + bool ntp() const { + if (m_timeInterface) + return m_timeInterface->nTP(); + return false; + } + + void setNtp(bool val) { + if (m_timeInterface) + m_timeInterface->SetNTP(val, true); + } + + QString timeZone() const { + if (m_timeInterface) + return m_timeInterface->timezone(); + return ""; + } + + void setTimeZone(const QString& aTimeZone) { + if (m_timeInterface) + m_timeInterface->SetTimezone(aTimeZone, true); + } + + void setTime(qlonglong usecsSinceEpoch) { + if (m_timeInterface) + m_timeInterface->SetTime(usecsSinceEpoch, false, true); + } + +private: + OrgFreedesktopTimedate1Interface *m_timeInterface; + SystemTime *q_ptr; +}; + + +#endif // SYSTEMTIME_P_H diff --git a/src/qtdevicesettings/timedateplugin/timedated.xml b/src/qtdevicesettings/timedateplugin/timedated.xml new file mode 100644 index 0000000..95bafb8 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timedated.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtdevicesettings/timedateplugin/timedateplugin.pro b/src/qtdevicesettings/timedateplugin/timedateplugin.pro new file mode 100644 index 0000000..d82529d --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timedateplugin.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml dbus + +uri = com.theqtcompany.settings.timedate + +DBUS_INTERFACES = timedated.xml + +DESTDIR = imports/TimeDate +TARGET = qmltimedatesettingsplugin + +SOURCES += plugin.cpp \ + systemtime.cpp \ + timezonemodel.cpp \ + timezonefiltermodel.cpp + +pluginfiles.files += \ + qmldir + + +pluginfiles.files += \ + AnalogClock.qml \ + TimeDate.qml \ + TimezonesView.qml \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + + +RESOURCES += \ + icons.qrc + +HEADERS += \ + systemtime.h \ + systemtime_p.h \ + timezonemodel.h \ + timezonefiltermodel.h + + diff --git a/src/qtdevicesettings/timedateplugin/timezonefiltermodel.cpp b/src/qtdevicesettings/timedateplugin/timezonefiltermodel.cpp new file mode 100644 index 0000000..3d1c0a4 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timezonefiltermodel.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "timezonemodel.h" +#include "timezonefiltermodel.h" + +TimezoneFilterModel::TimezoneFilterModel(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &TimezoneFilterModel::filterChanged, this, &TimezoneFilterModel::invalidate); +} + +TimezoneFilterModel::~TimezoneFilterModel() +{ + +} + +QString TimezoneFilterModel::filter() const +{ + return m_filter; +} + +void TimezoneFilterModel::setFilter(const QString& aFilter) +{ + m_filter = aFilter; + emit filterChanged(); +} + +bool TimezoneFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + bool ret = false; + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + QVariant nameRole = index.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + QString name = nameRole.toString(); + if (name.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + QVariant countryRole = index.data(TimezoneModel::Country); + if (ret == false && countryRole.isValid()) + { + QString country = countryRole.toString(); + if (country.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + } + } + return ret; +} + +QVariant TimezoneFilterModel::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant nameRole = mapped.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + return nameRole; + } + } + return QVariant::fromValue(QString("")); +} + diff --git a/src/qtdevicesettings/timedateplugin/timezonefiltermodel.h b/src/qtdevicesettings/timedateplugin/timezonefiltermodel.h new file mode 100644 index 0000000..dd9009f --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timezonefiltermodel.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEFILTERMODEL_H +#define TIMEZONEFILTERMODEL_H + +#include + +class TimezoneFilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) +public: + explicit TimezoneFilterModel(QObject* parent); + virtual ~TimezoneFilterModel(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QString filter() const; + void setFilter(const QString& aFilter); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void filterChanged(); +private: + QString m_filter; + +}; + +#endif // TIMEZONEFILTERMODEL_H diff --git a/src/qtdevicesettings/timedateplugin/timezonemodel.cpp b/src/qtdevicesettings/timedateplugin/timezonemodel.cpp new file mode 100644 index 0000000..b6cf27b --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timezonemodel.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include "timezonemodel.h" + +TimezoneItem::TimezoneItem(const QByteArray& id, QObject *parent) + :QObject(parent) +{ + QTimeZone tz = QTimeZone(id); + m_name = tz.displayName(QTimeZone::StandardTime); + m_country = QLocale::countryToString(tz.country()); + m_id = id; +} + +QString TimezoneItem::name() const +{ + return m_name; +} + +QString TimezoneItem::country() const +{ + return m_country; +} + +QString TimezoneItem::id() const +{ + return m_id; +} + +TimezoneModel::TimezoneModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Country, "country"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(Id, "id"); + + QFuture t1 = QtConcurrent::run(TimezoneModel::generateModel, this); +} + +void TimezoneModel::generateModel(TimezoneModel* model) +{ + QList ids = QTimeZone::availableTimeZoneIds(); + foreach (QByteArray id, ids) { + TimezoneItem *zone = new TimezoneItem(id); + zone->moveToThread(model->thread()); + QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast(zone))); + } +} + +void TimezoneModel::addNewItem(QObject* item) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + TimezoneItem* newItem = qobject_cast(item); + if (newItem) + m_items.append(newItem); + endInsertRows(); +} + +TimezoneModel::~TimezoneModel() +{ + qDeleteAll(m_items); +} + +QHash TimezoneModel::roleNames() const +{ + return m_roleNames; +} + + +int TimezoneModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant TimezoneModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + TimezoneItem *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return item->id(); + } + + switch (role) { + case Name: + return item->id(); + break; + case Country: + return item->country(); + break; + case Id: + return item->id(); + break; + case Qt::DisplayRole: + return item->id(); + break; + default: + return ""; + } +} diff --git a/src/qtdevicesettings/timedateplugin/timezonemodel.h b/src/qtdevicesettings/timedateplugin/timezonemodel.h new file mode 100644 index 0000000..af86c75 --- /dev/null +++ b/src/qtdevicesettings/timedateplugin/timezonemodel.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEMODEL_H +#define TIMEZONEMODEL_H + +#include +#include +#include +#include + +class TimezoneItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) +public: + explicit TimezoneItem(const QByteArray& id, QObject *parent=0); + QString name() const; + QString country() const; + QString id() const; + +private: + QString m_name; + QString m_country; + QString m_id; +}; + +class TimezoneModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit TimezoneModel(QObject *parent=0); + virtual ~TimezoneModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash roleNames() const; + Q_INVOKABLE QVariant itemFromRow(const int row) const; + + enum Roles { + Name = Qt::UserRole + 1, + Country, + Id + }; + + static void generateModel(TimezoneModel* model); + +private slots: + void addNewItem(QObject* item); + +private: + QList m_items; + QHash m_roleNames; +}; + +#endif // TIMEZONEMODEL_H -- cgit v1.2.3