on xenial help sign in
reuse the timezone model provided by System Settings
53b0e4fLukáš Tinkl
plugins/Utils/timezoneFormatter.cpp+10
@@ -33,3 +33,13 @@ QString TimezoneFormatter::currentTimeInTimezone(const QVariant &tzId) const
33 }
33 }
34 return QString();
34 return QString();
35}
35}
36+
37+QString TimezoneFormatter::currentTimeInTimezoneWithAbbrev(const QVariant &tzId) const
38+{
39+ QTimeZone tz(tzId.toByteArray());
40+ if (tz.isValid()) {
41+ const QDateTime now = QDateTime::currentDateTime().toTimeZone(tz);
42+ return QStringLiteral("%1 %2").arg(now.time().toString("h:mm")).arg(tz.abbreviation(now));
43+ }
44+ return QString();
45+}
plugins/Utils/timezoneFormatter.h+1
@@ -27,6 +27,7 @@ public:
27 ~TimezoneFormatter() = default;
27 ~TimezoneFormatter() = default;
28
28
29 Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
29 Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
30+ Q_INVOKABLE QString currentTimeInTimezoneWithAbbrev(const QVariant &tzId) const;
30};
31};
31
32
32#endif
33#endif
qml/Wizard/Pages/50-timezone.qml+18−18
@@ -18,6 +18,7 @@ import QtQuick 2.3
18import Ubuntu.Components 1.2
18import Ubuntu.Components 1.2
19import Wizard 0.1
19import Wizard 0.1
20import Ubuntu.SystemSettings.TimeDate 1.0
20import Ubuntu.SystemSettings.TimeDate 1.0
21+import Utils 0.1 as Utils
21import ".." as LocalComponents
22import ".." as LocalComponents
22
23
23LocalComponents.Page {
24LocalComponents.Page {
@@ -27,21 +28,11 @@ LocalComponents.Page {
27 title: i18n.tr("Time Zone")
28 title: i18n.tr("Time Zone")
28 forwardButtonSourceComponent: forwardButton
29 forwardButtonSourceComponent: forwardButton
29
30
30− property alias selectedTimeZone: tzModel.selectedZoneId
31+ property string selectedTimeZone: ""
31
32
32 UbuntuTimeDatePanel {
33 UbuntuTimeDatePanel {
33 id: timeDatePanel
34 id: timeDatePanel
34− }
35−
36− TimeZoneModel {
37− id: tzModel
38− }
39−
40− TimeZoneFilterModel {
41− id: tzFilterModel
42− sourceModel: tzModel
43 filter: searchField.text
35 filter: searchField.text
44− country: root.countryCode
45 }
36 }
46
37
47 Component.onCompleted: {
38 Component.onCompleted: {
@@ -61,28 +52,34 @@ LocalComponents.Page {
61 id: tz
52 id: tz
62 objectName: "tz"
53 objectName: "tz"
63 highlightColor: backgroundColor
54 highlightColor: backgroundColor
64− readonly property bool currentTz: !!id ? selectedTimeZone === id : false
55+ readonly property bool currentTz: ListView.view.currentIndex === index
65
56
66 Column {
57 Column {
67 anchors.verticalCenter: parent.verticalCenter
58 anchors.verticalCenter: parent.verticalCenter
68 anchors.left: parent.left
59 anchors.left: parent.left
69 anchors.leftMargin: leftMargin
60 anchors.leftMargin: leftMargin
61+ anchors.right: image.left
62+ anchors.rightMargin: rightMargin
70 Label {
63 Label {
71 id: cityLabel
64 id: cityLabel
72− text: !!city ? city : ""
65+ text: displayName
73 font.weight: tz.currentTz ? Font.Normal : Font.Light
66 font.weight: tz.currentTz ? Font.Normal : Font.Light
74 fontSize: "medium"
67 fontSize: "medium"
75 color: textColor
68 color: textColor
69+ elide: Text.ElideMiddle
70+ maximumLineCount: 1
71+ width: parent.width
76 }
72 }
77 Label {
73 Label {
78 id: timeLabel
74 id: timeLabel
79− text: !!time ? time + " " + abbreviation : ""
75+ text: Utils.TimezoneFormatter.currentTimeInTimezoneWithAbbrev(timeZone)
80 font.weight: tz.currentTz ? Font.Normal : Font.Light
76 font.weight: tz.currentTz ? Font.Normal : Font.Light
81 fontSize: "small"
77 fontSize: "small"
82 color: textColor
78 color: textColor
83 }
79 }
84 }
80 }
85 Image {
81 Image {
82+ id: image
86 anchors {
83 anchors {
87 right: parent.right
84 right: parent.right
88 verticalCenter: parent.verticalCenter
85 verticalCenter: parent.verticalCenter
@@ -96,9 +93,10 @@ LocalComponents.Page {
96 }
93 }
97
94
98 onClicked: {
95 onClicked: {
99− selectedTimeZone = id
96+ print("Clicked index", index)
100− print("Selected tz: " + selectedTimeZone)
97+ ListView.view.currentIndex = index
98+ selectedTimeZone = timeZone
101− print("Clicked country", countryCode)
99+ print("Clicked country", country)
102 }
100 }
103 }
101 }
104 }
102 }
@@ -121,7 +119,9 @@ LocalComponents.Page {
121 inputMethodHints: Qt.ImhNoPredictiveText
119 inputMethodHints: Qt.ImhNoPredictiveText
122 onTextChanged: {
120 onTextChanged: {
123 // reset when switching between filter modes (text/country)
121 // reset when switching between filter modes (text/country)
122+ print("Filter:", text)
124 selectedTimeZone = ""
123 selectedTimeZone = ""
124+ tzList.currentIndex = -1
125 }
125 }
126 }
126 }
127
127
@@ -139,7 +139,7 @@ LocalComponents.Page {
139 }
139 }
140
140
141 height: column.height - searchField.height - column.spacing - topMargin
141 height: column.height - searchField.height - column.spacing - topMargin
142− model: tzFilterModel
142+ model: timeDatePanel.timeZoneModel
143 delegate: tzComponent
143 delegate: tzComponent
144 }
144 }
145 }
145 }
tests/mocks/Utils/CMakeLists.txt+1−1
@@ -20,10 +20,10 @@ set(QMLPLUGIN_SRC
20 ${CMAKE_SOURCE_DIR}/plugins/Utils/windowscreenshotprovider.cpp
20 ${CMAKE_SOURCE_DIR}/plugins/Utils/windowscreenshotprovider.cpp
21 ${CMAKE_SOURCE_DIR}/plugins/Utils/easingcurve.cpp
21 ${CMAKE_SOURCE_DIR}/plugins/Utils/easingcurve.cpp
22 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputwatcher.cpp
22 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputwatcher.cpp
23+ ${CMAKE_SOURCE_DIR}/plugins/Utils/timezoneFormatter.cpp
23 constants.cpp
24 constants.cpp
24 plugin.cpp
25 plugin.cpp
25 windowstatestorage.cpp
26 windowstatestorage.cpp
26− plugin.cpp
27 )
27 )
28
28
29add_library(FakeUtils-qml SHARED
29add_library(FakeUtils-qml SHARED
tests/mocks/Utils/plugin.cpp+3
@@ -45,6 +45,7 @@
45#include <windowkeysfilter.h>
45#include <windowkeysfilter.h>
46#include <windowscreenshotprovider.h>
46#include <windowscreenshotprovider.h>
47#include <easingcurve.h>
47#include <easingcurve.h>
48+#include <timezoneFormatter.h>
48
49
49static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
50static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
50{
51{
@@ -75,6 +76,8 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
75 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
76 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
76 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
77 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
77 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
78 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
79+ qmlRegisterSingletonType<TimezoneFormatter>(uri, 0, 1, "TimezoneFormatter",
80+ [](QQmlEngine*, QJSEngine*) -> QObject* { return new TimezoneFormatter; });
78 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
81 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
79}
82}
80
83