@@ -0,0 +1,94 @@
2+ * Copyright (C) 2015 Canonical Ltd.
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU General Public License version 3, as published
6+ * by the Free Software Foundation.
8+ * This program is distributed in the hope that it will be useful, but
9+ * WITHOUT ANY WARRANTY; without even the implied warranties of
10+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11+ * PURPOSE. See the GNU General Public License for more details.
13+ * You should have received a copy of the GNU General Public License along
14+ * with this program. If not, see <http://www.gnu.org/licenses/>.
16+ * Author: Lukáš Tinkl <lukas.tinkl@canonical.com>
22+#include "timezonemodel.h"
25+TimeZoneModel::TimeZoneModel(QObject *parent)
26+ : QAbstractListModel(parent)
28+ QMetaObject::invokeMethod(this, "init");
31+QString TimeZoneModel::selectedZoneId() const
33+ return m_selectedZoneId;
36+void TimeZoneModel::setSelectedZoneId(const QString &selectedZoneId)
38+ if (m_selectedZoneId == selectedZoneId)
41+ m_selectedZoneId = selectedZoneId;
42+ Q_EMIT selectedZoneIdChanged(selectedZoneId);
45+int TimeZoneModel::rowCount(const QModelIndex &parent) const
48+ return m_zoneIds.count();
51+QVariant TimeZoneModel::data(const QModelIndex &index, int role) const
53+ if (index.isValid()) {
54+ const QByteArray tzid = m_zoneIds.at(index.row());
58+ qWarning() << Q_FUNC_INFO << "Invalid timezone" << tzid;
66+ return tz.abbreviation(QDateTime::currentDateTime());
68+ return QLocale::countryToString(tz.country());
70+ const QString cityName = QString::fromUtf8(tzid.split('/').last());
76+ qWarning() << Q_FUNC_INFO << "Unsupported data role";
84+QHash<int, QByteArray> TimeZoneModel::roleNames() const
86+ return {{IdRole, "id"}, {Abbreviation, "abbreviation"}, {Country, "country"}, {City, "city"}, {Comment, "comment"}};
89+void TimeZoneModel::init()
92+ m_zoneIds = QTimeZone::availableTimeZoneIds();