summaryrefslogtreecommitdiffstats
path: root/src/timedatesettings
diff options
context:
space:
mode:
authorTeemu Holappa <teemu.holappa@theqtcompany.com>2016-02-11 11:50:55 +0200
committerTeemu Holappa <teemu.holappa@theqtcompany.com>2016-02-17 11:57:20 +0000
commitf1d884b6dad5a93d7a3077b6b05d3ec7fcd9a6ea (patch)
tree9d48669bdf1e8877b19c3a98cd8bbd8c90df5290 /src/timedatesettings
parentb4088adc7f2666d468a478e379b94c5cb4494c1b (diff)
Refactored Qml plugins into modules.
Separated C++ and Qml interfaces. All the UI's from plugins are moved to the settingsui folder. Change-Id: Id6a6623346b18321357bc42d24121c4d9cdfd098 Reviewed-by: Kimmo Ollila <kimmo.ollila@theqtcompany.com>
Diffstat (limited to 'src/timedatesettings')
-rw-r--r--src/timedatesettings/systemtime.cpp85
-rw-r--r--src/timedatesettings/systemtime.h73
-rw-r--r--src/timedatesettings/systemtime_p.h88
-rw-r--r--src/timedatesettings/timedated.xml30
-rw-r--r--src/timedatesettings/timedateplugin.pro42
-rw-r--r--src/timedatesettings/timedatesettings.pro23
-rw-r--r--src/timedatesettings/timezonefiltermodel.cpp104
-rw-r--r--src/timedatesettings/timezonefiltermodel.h59
-rw-r--r--src/timedatesettings/timezonemodel.cpp139
-rw-r--r--src/timedatesettings/timezonemodel.h88
10 files changed, 731 insertions, 0 deletions
diff --git a/src/timedatesettings/systemtime.cpp b/src/timedatesettings/systemtime.cpp
new file mode 100644
index 0000000..c84b036
--- /dev/null
+++ b/src/timedatesettings/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/timedatesettings/systemtime.h b/src/timedatesettings/systemtime.h
new file mode 100644
index 0000000..2f61ab5
--- /dev/null
+++ b/src/timedatesettings/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 <QObject>
+#include <QTime>
+
+class SystemTimePrivate;
+
+class Q_DECL_EXPORT 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/timedatesettings/systemtime_p.h b/src/timedatesettings/systemtime_p.h
new file mode 100644
index 0000000..5ee6eef
--- /dev/null
+++ b/src/timedatesettings/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/timedatesettings/timedated.xml b/src/timedatesettings/timedated.xml
new file mode 100644
index 0000000..95bafb8
--- /dev/null
+++ b/src/timedatesettings/timedated.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+<node>
+ <interface name="org.freedesktop.timedate1">
+ <property name="Timezone" type="s" access="read"/>
+ <property name="LocalRTC" type="b" access="read"/>
+ <property name="CanNTP" type="b" access="read"/>
+ <property name="NTP" type="b" access="read"/>
+ <method name="SetTime">
+ <arg name="usec_utc" type="x" direction="in"/>
+ <arg name="relative" type="b" direction="in"/>
+ <arg name="user_interaction" type="b" direction="in"/>
+ </method>
+ <method name="SetTimezone">
+ <arg name="timezone" type="s" direction="in"/>
+ <arg name="user_interaction" type="b" direction="in"/>
+ </method>
+ <method name="SetLocalRTC">
+ <arg name="local_rtc" type="b" direction="in"/>
+ <arg name="fix_system" type="b" direction="in"/>
+ <arg name="user_interaction" type="b" direction="in"/>
+ </method>
+ <method name="SetNTP">
+ <arg name="use_ntp" type="b" direction="in"/>
+ <arg name="user_interaction" type="b" direction="in"/>
+ </method>
+ </interface>
+</node>
+
+
diff --git a/src/timedatesettings/timedateplugin.pro b/src/timedatesettings/timedateplugin.pro
new file mode 100644
index 0000000..d82529d
--- /dev/null
+++ b/src/timedatesettings/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/timedatesettings/timedatesettings.pro b/src/timedatesettings/timedatesettings.pro
new file mode 100644
index 0000000..6f3f4e9
--- /dev/null
+++ b/src/timedatesettings/timedatesettings.pro
@@ -0,0 +1,23 @@
+load(qt_build_config)
+
+TARGET = QtTimeDateSettings
+VERSION = 1.0
+CONFIG += dll warn_on
+
+QT = core dbus
+
+MODULE = timedatesettings
+load(qt_module)
+
+DBUS_INTERFACES = timedated.xml
+
+SOURCES += systemtime.cpp \
+ timezonemodel.cpp \
+ timezonefiltermodel.cpp
+
+HEADERS += \
+ systemtime.h \
+ systemtime_p.h \
+ timezonemodel.h \
+ timezonefiltermodel.h
+
diff --git a/src/timedatesettings/timezonefiltermodel.cpp b/src/timedatesettings/timezonefiltermodel.cpp
new file mode 100644
index 0000000..3d1c0a4
--- /dev/null
+++ b/src/timedatesettings/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/timedatesettings/timezonefiltermodel.h b/src/timedatesettings/timezonefiltermodel.h
new file mode 100644
index 0000000..62c65c9
--- /dev/null
+++ b/src/timedatesettings/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 <QSortFilterProxyModel>
+
+class Q_DECL_EXPORT 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/timedatesettings/timezonemodel.cpp b/src/timedatesettings/timezonemodel.cpp
new file mode 100644
index 0000000..2a8d0ed
--- /dev/null
+++ b/src/timedatesettings/timezonemodel.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** 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 <QLocale>
+#include <QFuture>
+#include <QThread>
+#include <QtConcurrent/QtConcurrentRun>
+#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<void> t1 = QtConcurrent::run(TimezoneModel::generateModel, this);
+}
+
+void TimezoneModel::generateModel(TimezoneModel* model)
+{
+ QList<QByteArray> 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<QObject*>(zone)));
+ }
+}
+
+void TimezoneModel::addNewItem(QObject* item)
+{
+ beginInsertRows(QModelIndex(), m_items.count(), m_items.count());
+ TimezoneItem* newItem = qobject_cast<TimezoneItem*>(item);
+ if (newItem)
+ m_items.append(newItem);
+ endInsertRows();
+}
+
+TimezoneModel::~TimezoneModel()
+{
+ qDeleteAll(m_items);
+}
+
+QHash<int, QByteArray> 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/timedatesettings/timezonemodel.h b/src/timedatesettings/timezonemodel.h
new file mode 100644
index 0000000..7404954
--- /dev/null
+++ b/src/timedatesettings/timezonemodel.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 TIMEZONEMODEL_H
+#define TIMEZONEMODEL_H
+
+#include <QObject>
+#include <QAbstractListModel>
+#include <QTimeZone>
+#include <QMutex>
+
+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 Q_DECL_EXPORT 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<int, QByteArray> roleNames() const;
+
+ enum Roles {
+ Name = Qt::UserRole + 1,
+ Country,
+ Id
+ };
+
+ static void generateModel(TimezoneModel* model);
+
+private slots:
+ void addNewItem(QObject* item);
+
+private:
+ QList<TimezoneItem*> m_items;
+ QHash<int, QByteArray> m_roleNames;
+};
+
+#endif // TIMEZONEMODEL_H