on xenial help sign in
improve datetime and session indicators
0f4c4fdLukáš Tinkl
plugins/Utils/timeformatter.cpp+13−1
@@ -20,6 +20,7 @@
20
20
21#include <gio/gio.h>
21#include <gio/gio.h>
22#include <QDateTime>
22#include <QDateTime>
23+#include <QTimeZone>
23
24
24struct TimeFormatterPrivate
25struct TimeFormatterPrivate
25{
26{
@@ -176,13 +177,24 @@ void TimeFormatter::update()
176 Q_EMIT timeStringChanged(priv->timeString);
177 Q_EMIT timeStringChanged(priv->timeString);
177}
178}
178
179
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+
179QString TimeFormatter::formatTime() const
191QString TimeFormatter::formatTime() const
180{
192{
181 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
193 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
182}
194}
183
195
184GDateTimeFormatter::GDateTimeFormatter(QObject* parent)
196GDateTimeFormatter::GDateTimeFormatter(QObject* parent)
185−: TimeFormatter("%d-%m-%Y %I:%M%p", parent)
197+ : TimeFormatter("%d-%m-%Y %I:%M%p", parent)
186{
198{
187}
199}
188
200
plugins/Utils/timeformatter.h+2
@@ -42,6 +42,8 @@ public:
42
42
43 void update();
43 void update();
44
44
45+ Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
46+
45Q_SIGNALS:
47Q_SIGNALS:
46 void formatChanged(const QString &format);
48 void formatChanged(const QString &format);
47 void timeStringChanged(const QString &timeString);
49 void timeStringChanged(const QString &timeString);
qml/Panel/Indicators/MenuItemFactory.qml+83
@@ -24,6 +24,7 @@ import QMenuModel 0.1
24import Utils 0.1 as Utils
24import Utils 0.1 as Utils
25import Ubuntu.Components.ListItems 0.1 as ListItems
25import Ubuntu.Components.ListItems 0.1 as ListItems
26import Ubuntu.Components 1.1
26import Ubuntu.Components 1.1
27+import "../../Greeter"
27
28
28Item {
29Item {
29 id: menuFactory
30 id: menuFactory
@@ -63,6 +64,14 @@ Item {
63 },
64 },
64 "indicator-messages" : {
65 "indicator-messages" : {
65 "com.canonical.indicator.button" : messagesButtonMenu
66 "com.canonical.indicator.button" : messagesButtonMenu
67+ },
68+ "indicator-datetime" : {
69+ "com.canonical.indicator.calendar": calendarMenu,
70+ "com.canonical.indicator.location": timezoneMenu
71+ },
72+ "indicator-session" : {
73+ "indicator.user-menu-item": userMenuItem,
74+ "indicator.guest-menu-item": userMenuItem
66 }
75 }
67 }
76 }
68
77
@@ -73,6 +82,8 @@ Item {
73 return defaultValue;
82 return defaultValue;
74 }
83 }
75
84
85+ LightDM {id: lightDM} // Provide backend access
86+
76 Component {
87 Component {
77 id: separatorMenu;
88 id: separatorMenu;
78
89
@@ -422,6 +433,78 @@ Item {
422 }
433 }
423 }
434 }
424
435
436+ Component {
437+ id: userMenuItem
438+
439+ Menus.UserSessionMenu {
440+ objectName: "userSessionMenu"
441+ highlightWhenPressed: false
442+
443+ property QtObject menuData: null
444+ property var menuModel: menuFactory.menuModel
445+ property int menuIndex: -1
446+ //property var extendedData: menuData && menuData.ext || undefined
447+
448+ name: menuData && menuData.label || ""
449+ iconSource: menuData && menuData.icon || ""
450+ // active: true // TODO hook up with lightdm
451+
452+ onTriggered: {
453+ menuModel.activate(menuIndex);
454+ }
455+ }
456+ }
457+
458+ Component {
459+ id: calendarMenu
460+
461+ Menus.CalendarMenu {
462+ objectName: "calendarMenu"
463+ highlightWhenPressed: false
464+ }
465+ }
466+
467+ Component {
468+ id: timezoneMenu
469+
470+ Menus.TimeZoneMenu {
471+ id: tzMenuItem
472+ objectName: "timezoneMenu"
473+
474+ property QtObject menuData: null
475+ property var menuModel: menuFactory.menuModel
476+ property int menuIndex: -1
477+ property var extendedData: menuData && menuData.ext || undefined
478+ readonly property var tz: getExtendedProperty(extendedData, "xCanonicalTimezone", "UTC")
479+ property var tzFormatter: Utils.TimeFormatter {}
480+ property var updateTimer: Timer {
481+ repeat: true
482+ running: true
483+ onTriggered: tzMenuItem.time = tzMenuItem.tzFormatter.currentTimeInTimezone(tzMenuItem.tz)
484+ }
485+
486+ city: menuData && menuData.label || ""
487+ time: tzFormatter.currentTimeInTimezone(tz)
488+ enabled: menuData && menuData.sensitive || false
489+ highlightWhenPressed: false
490+
491+ onMenuModelChanged: {
492+ loadAttributes();
493+ }
494+ onMenuIndexChanged: {
495+ loadAttributes();
496+ }
497+ onTriggered: {
498+ menuModel.activate(menuIndex);
499+ }
500+
501+ function loadAttributes() {
502+ if (!menuModel || menuIndex == -1) return;
503+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-timezone': 'string'});
504+ }
505+ }
506+ }
507+
425 Component {
508 Component {
426 id: wifiSection;
509 id: wifiSection;
427
510