on xenial help sign in
address comments & issues
da86b26Lukáš Tinkl
plugins/Utils/CMakeLists.txt+1
@@ -22,6 +22,7 @@ set(QMLPLUGIN_SRC
22 windowscreenshotprovider.cpp
22 windowscreenshotprovider.cpp
23 easingcurve.cpp
23 easingcurve.cpp
24 windowstatestorage.cpp
24 windowstatestorage.cpp
25+ timezoneFormatter.cpp
25 plugin.cpp
26 plugin.cpp
26 )
27 )
27
28
plugins/Utils/plugin.cpp+3
@@ -35,6 +35,7 @@
35#include "windowscreenshotprovider.h"
35#include "windowscreenshotprovider.h"
36#include "windowstatestorage.h"
36#include "windowstatestorage.h"
37#include "constants.h"
37#include "constants.h"
38+#include "timezoneFormatter.h"
38
39
39static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
40static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
40{
41{
@@ -66,6 +67,8 @@ void UtilsPlugin::registerTypes(const char *uri)
66 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
67 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
67 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
68 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
68 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
69 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
70+ qmlRegisterSingletonType<TimezoneFormatter>(uri, 0, 1, "TimezoneFormatter",
71+ [](QQmlEngine*, QJSEngine*) -> QObject* { return new TimezoneFormatter; });
69}
72}
70
73
71void UtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
74void UtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
plugins/Utils/timeformatter.cpp−12
@@ -20,7 +20,6 @@
20
20
21#include <gio/gio.h>
21#include <gio/gio.h>
22#include <QDateTime>
22#include <QDateTime>
23−#include <QTimeZone>
24
23
25struct TimeFormatterPrivate
24struct TimeFormatterPrivate
26{
25{
@@ -177,17 +176,6 @@ void TimeFormatter::update()
177 Q_EMIT timeStringChanged(priv->timeString);
176 Q_EMIT timeStringChanged(priv->timeString);
178}
177}
179
178
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−
191QString TimeFormatter::formatTime() const
179QString TimeFormatter::formatTime() const
192{
180{
193 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
181 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
plugins/Utils/timeformatter.h−2
@@ -42,8 +42,6 @@ public:
42
42
43 void update();
43 void update();
44
44
45− Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
46−
47Q_SIGNALS:
45Q_SIGNALS:
48 void formatChanged(const QString &format);
46 void formatChanged(const QString &format);
49 void timeStringChanged(const QString &timeString);
47 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
20import QMenuModel 0.1
20import QMenuModel 0.1
21import Utils 0.1 as Utils
21import Utils 0.1 as Utils
22import Ubuntu.Components.ListItems 0.1 as ListItems
22import Ubuntu.Components.ListItems 0.1 as ListItems
23−import Ubuntu.Components 1.1
23+import Ubuntu.Components 1.2
24import Unity.Session 0.1
24import Unity.Session 0.1
25
25
26Item {
26Item {
@@ -58,17 +58,15 @@ Item {
58 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
58 "unity.widgets.systemsettings.tablet.wifisection" : wifiSection,
59 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
59 "unity.widgets.systemsettings.tablet.accesspoint" : accessPoint,
60 "com.canonical.indicator.network.modeminfoitem" : modeminfoitem,
60 "com.canonical.indicator.network.modeminfoitem" : modeminfoitem,
61− },
61+
62− "indicator-messages" : {
63− "com.canonical.indicator.button" : messagesButtonMenu
64− },
65− "indicator-datetime" : {
66 "com.canonical.indicator.calendar": calendarMenu,
62 "com.canonical.indicator.calendar": calendarMenu,
67− "com.canonical.indicator.location": timezoneMenu
63+ "com.canonical.indicator.location": timezoneMenu,
68− },
64+
69− "indicator-session" : {
70 "indicator.user-menu-item": userMenuItem,
65 "indicator.user-menu-item": userMenuItem,
71 "indicator.guest-menu-item": userMenuItem
66 "indicator.guest-menu-item": userMenuItem
67+ },
68+ "indicator-messages" : {
69+ "com.canonical.indicator.button" : messagesButtonMenu
72 }
70 }
73 }
71 }
74
72
@@ -79,11 +77,6 @@ Item {
79 return defaultValue;
77 return defaultValue;
80 }
78 }
81
79
82− Utils.TimeFormatter
83− {
84− id: tzFormatter
85− }
86−
87 Component {
80 Component {
88 id: separatorMenu;
81 id: separatorMenu;
89
82
@@ -448,7 +441,8 @@ Item {
448 iconSource: menuData && menuData.icon || ""
441 iconSource: menuData && menuData.icon || ""
449
442
450 // would be better to compare with the logname but sadly the indicator doesn't expose that
443 // 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
452
446
453 onTriggered: {
447 onTriggered: {
454 menuModel.activate(menuIndex);
448 menuModel.activate(menuIndex);
@@ -480,12 +474,15 @@ Item {
480 readonly property var tz: getExtendedProperty(extendedData, "xCanonicalTimezone", "UTC")
474 readonly property var tz: getExtendedProperty(extendedData, "xCanonicalTimezone", "UTC")
481 property var updateTimer: Timer {
475 property var updateTimer: Timer {
482 repeat: true
476 repeat: true
483− running: identifier == "indicator-datetime" // only run when we're open
477+ running: identifier == "indicator-datetime" && tzMenuItem.visible // only run when we're open
484− onTriggered: tzMenuItem.time = tzFormatter.currentTimeInTimezone(tzMenuItem.tz)
478+ onTriggered: tzMenuItem.time = Utils.TimezoneFormatter.currentTimeInTimezone(tzMenuItem.tz)
479+ onRunningChanged: {
480+ print("LIVE TIMER RUNNING:", running)
481+ }
485 }
482 }
486
483
487 city: menuData && menuData.label || ""
484 city: menuData && menuData.label || ""
488− time: tzFormatter.currentTimeInTimezone(tz)
485+ time: Utils.TimezoneFormatter.currentTimeInTimezone(tz)
489 enabled: menuData && menuData.sensitive || false
486 enabled: menuData && menuData.sensitive || false
490 highlightWhenPressed: false
487 highlightWhenPressed: false
491
488