on xenial help sign in
address comments & issues
commitda86b26f0058d1ef9b2dcc1e0af50fc0156154e3 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 17 Sep 2015, 15:42 (11 years ago) parent7f93f50
7 files changed+86−32
plugins/Utils/CMakeLists.txt+1 plugins/Utils/plugin.cpp+3 plugins/Utils/timeformatter.cpp−12 plugins/Utils/timeformatter.h−2 plugins/Utils/timezoneFormatter.cpp+35 plugins/Utils/timezoneFormatter.h+32 qml/Panel/Indicators/MenuItemFactory.qml+15−18
plugins/Utils/CMakeLists.txt+1
@@ -22,6 +22,7 @@ set(QMLPLUGIN_SRC
2222 windowscreenshotprovider.cpp
2323 easingcurve.cpp
2424 windowstatestorage.cpp
25+ timezoneFormatter.cpp
2526 plugin.cpp
2627 )
2728
plugins/Utils/plugin.cpp+3
@@ -35,6 +35,7 @@
3535#include "windowscreenshotprovider.h"
3636#include "windowstatestorage.h"
3737#include "constants.h"
38+#include "timezoneFormatter.h"
3839
3940static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
4041{
@@ -66,6 +67,8 @@ void UtilsPlugin::registerTypes(const char *uri)
6667 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
6768 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
6869 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
70+ qmlRegisterSingletonType<TimezoneFormatter>(uri, 0, 1, "TimezoneFormatter",
71+ [](QQmlEngine*, QJSEngine*) -> QObject* { return new TimezoneFormatter; });
6972}
7073
7174void UtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
plugins/Utils/timeformatter.cpp−12
@@ -20,7 +20,6 @@
2020
2121#include <gio/gio.h>
2222#include <QDateTime>
23−#include <QTimeZone>
2423
2524struct TimeFormatterPrivate
2625{
@@ -177,17 +176,6 @@ void TimeFormatter::update()
177176 Q_EMIT timeStringChanged(priv->timeString);
178177}
179178
180−QString TimeFormatter::currentTimeInTimezone(const QVariant &tzId) const
181−{
182− QTimeZone tz(tzId.toByteArray());
183− if (tz.isValid()) {
184− const QDateTime now = QDateTime::currentDateTime().toTimeZone(tz);
185− // return locale-aware string in the form "day, hh:mm", e.g. "Mon 14:30" or "Mon 1:30 pm"
186− return QStringLiteral("%1 %2").arg(now.toString("ddd")).arg(now.time().toString(Qt::DefaultLocaleShortDate));
187− }
188− return QString();
189−}
190−
191179QString TimeFormatter::formatTime() const
192180{
193181 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
plugins/Utils/timeformatter.h−2
@@ -42,8 +42,6 @@ public:
4242
4343 void update();
4444
45− Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
46−
4745Q_SIGNALS:
4846 void formatChanged(const QString &format);
4947 void timeStringChanged(const QString &timeString);
plugins/Utils/timezoneFormatter.cppnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include <QTimeZone>
18+
19+#include "timezoneFormatter.h"
20+
21+TimezoneFormatter::TimezoneFormatter(QObject *parent)
22+ : QObject(parent)
23+{
24+}
25+
26+QString TimezoneFormatter::currentTimeInTimezone(const QVariant &tzId) const
27+{
28+ QTimeZone tz(tzId.toByteArray());
29+ if (tz.isValid()) {
30+ const QDateTime now = QDateTime::currentDateTime().toTimeZone(tz);
31+ // return locale-aware string in the form "day, hh:mm", e.g. "Mon 14:30" or "Mon 1:30 pm"
32+ return QStringLiteral("%1 %2").arg(now.toString("ddd")).arg(now.time().toString(Qt::DefaultLocaleShortDate));
33+ }
34+ return QString();
35+}
plugins/Utils/timezoneFormatter.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef TIMEZONE_FORMATTER_H
18+#define TIMEZONE_FORMATTER_H
19+
20+#include <QObject>
21+
22+class TimezoneFormatter : public QObject
23+{
24+ Q_OBJECT
25+public:
26+ TimezoneFormatter(QObject * parent = nullptr);
27+ ~TimezoneFormatter() = default;
28+
29+ Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
30+};
31+
32+#endif
qml/Panel/Indicators/MenuItemFactory.qml+15−18
@@ -20,7 +20,7 @@ import Ubuntu.Settings.Components 0.1
2020import QMenuModel 0.1
2121import Utils 0.1 as Utils
2222import Ubuntu.Components.ListItems 0.1 as ListItems
23−import Ubuntu.Components 1.1
23+import Ubuntu.Components 1.2
2424import Unity.Session 0.1
2525
2626Item {
@@ -58,17 +58,15 @@ Item {
5858 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
5959 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
6060 "com.canonical.indicator.network.modeminfoitem" : modeminfoitem,
61− },
62− "indicator-messages" : {
63− "com.canonical.indicator.button" : messagesButtonMenu
64− },
65− "indicator-datetime" : {
61+
6662 "com.canonical.indicator.calendar": calendarMenu,
67− "com.canonical.indicator.location": timezoneMenu
68− },
69− "indicator-session" : {
63+ "com.canonical.indicator.location": timezoneMenu,
64+
7065 "indicator.user-menu-item": userMenuItem,
7166 "indicator.guest-menu-item": userMenuItem
67+ },
68+ "indicator-messages" : {
69+ "com.canonical.indicator.button" : messagesButtonMenu
7270 }
7371 }
7472
@@ -79,11 +77,6 @@ Item {
7977 return defaultValue;
8078 }
8179
82− Utils.TimeFormatter
83− {
84− id: tzFormatter
85− }
86−
8780 Component {
8881 id: separatorMenu;
8982
@@ -448,7 +441,8 @@ Item {
448441 iconSource: menuData && menuData.icon || ""
449442
450443 // would be better to compare with the logname but sadly the indicator doesn't expose that
451− active: DBusUnitySessionService.RealName() !== "" ? DBusUnitySessionService.RealName() == name : DBusUnitySessionService.UserName() == name
444+ active: DBusUnitySessionService.RealName() !== "" ? DBusUnitySessionService.RealName() == name
445+ : DBusUnitySessionService.UserName() == name
452446
453447 onTriggered: {
454448 menuModel.activate(menuIndex);
@@ -480,12 +474,15 @@ Item {
480474 readonly property var tz: getExtendedProperty(extendedData, "xCanonicalTimezone", "UTC")
481475 property var updateTimer: Timer {
482476 repeat: true
483− running: identifier == "indicator-datetime" // only run when we're open
484− onTriggered: tzMenuItem.time = tzFormatter.currentTimeInTimezone(tzMenuItem.tz)
477+ running: identifier == "indicator-datetime" && tzMenuItem.visible // only run when we're open
478+ onTriggered: tzMenuItem.time = Utils.TimezoneFormatter.currentTimeInTimezone(tzMenuItem.tz)
479+ onRunningChanged: {
480+ print("LIVE TIMER RUNNING:", running)
481+ }
485482 }
486483
487484 city: menuData && menuData.label || ""
488− time: tzFormatter.currentTimeInTimezone(tz)
485+ time: Utils.TimezoneFormatter.currentTimeInTimezone(tz)
489486 enabled: menuData && menuData.sensitive || false
490487 highlightWhenPressed: false
491488