Merge lp:~nick-dedekind/unity8/StrFTimeFormatter into lp:unity8

Proposed by Nick Dedekind
Status: Merged
Approved by: Michał Sawicz
Approved revision: 473
Merged at revision: 598
Proposed branch: lp:~nick-dedekind/unity8/StrFTimeFormatter
Merge into: lp:unity8
Prerequisite: lp:~larsu/unity8/lp1236413
Diff against target: 239 lines (+67/-11)
11 files modified
plugins/Unity/Indicators/CMakeLists.txt (+0/-1)
plugins/Unity/Indicators/Messaging/qml/SimpleTextMessage.qml (+2/-1)
plugins/Unity/Indicators/Messaging/qml/SnapDecision.qml (+2/-2)
plugins/Unity/Indicators/plugin.cpp (+0/-2)
plugins/Utils/CMakeLists.txt (+1/-0)
plugins/Utils/plugin.cpp (+3/-0)
plugins/Utils/timeformatter.cpp (+30/-1)
plugins/Utils/timeformatter.h (+15/-3)
tests/plugins/Unity/Indicators/CMakeLists.txt (+0/-1)
tests/plugins/Utils/CMakeLists.txt (+1/-0)
tests/plugins/Utils/timeformattertest.cpp (+13/-0)
To merge this branch: bzr merge lp:~nick-dedekind/unity8/StrFTimeFormatter
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michał Sawicz Approve
Lars Karlitski (community) Approve
Review via email: mp+192343@code.launchpad.net

Commit message

Added parser for strftime in TimeFormatter.
Moved TimeFormatter to Utils plugin.

Description of the change

Added parser for strftime in TimeFormatter.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

This patch doesn't check the return value of strftime() and might thus pass an uninitialized buffer into QString().

According to strftime(3), the return value of that function is 0 when the resulting string is longer than the passed in buffer. However, it can also be 0 when the resulting string is legitimately empty. For example, when the format string is "".

I think the best solution is to prepend a " " to the format string. That way, the return value is never smaller than 1, unless there's an error. And then simply return QString(buffer + 1).

You could also use g_date_time_format(), which supports all of the POSIX formats as well.

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> This patch doesn't check the return value of strftime() and might thus pass an
> uninitialized buffer into QString().
>
> According to strftime(3), the return value of that function is 0 when the
> resulting string is longer than the passed in buffer. However, it can also be
> 0 when the resulting string is legitimately empty. For example, when the
> format string is "".
>
> I think the best solution is to prepend a " " to the format string. That way,
> the return value is never smaller than 1, unless there's an error. And then
> simply return QString(buffer + 1).
>
> You could also use g_date_time_format(), which supports all of the POSIX
> formats as well.

GDateTime it is.
Renamed to GDateTimeFormatter as well.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:470
http://jenkins.qa.ubuntu.com/job/unity8-ci/1487/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/59/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/59/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/11
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/11
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/11
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/11/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/11
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/52/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/59
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/59/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/59
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/59/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2689/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2740/console
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/420
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/416

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1487/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Great, thanks.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:470
http://jenkins.qa.ubuntu.com/job/unity8-ci/1594/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/553
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/541/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/160
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/118
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/118
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/118/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/118
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/510
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/553
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/553/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/541
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/541/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/3008/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/3190
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/1200
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/1199

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1594/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:470
http://jenkins.qa.ubuntu.com/job/unity8-ci/1600/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/570
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/555
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/166
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/123/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/124
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/124/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/123
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/524
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/570
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/570/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/555
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/555/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/3019
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/3201
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/1226
    SUCCESS: http://10.97.0.26:8080/job/touch-flash-device/1221

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1600/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

What did we decide in the end on that? Should this come pre-formatted from the indicator?

review: Needs Information
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> What did we decide in the end on that? Should this come pre-formatted from the
> indicator?

No, we would need to subscribe to tz changes and update each event in the indicator service and update the actions. The indicator should keep processing to a minimum (times are read in as unix time).

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> What did we decide in the end on that? Should this come pre-formatted from the
> indicator?

I think this is still the correct way to do it. I'm not sure where the indicator gets it's format string from, but perhaps it should be a gsettting somewhere.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:472
http://jenkins.qa.ubuntu.com/job/unity8-ci/1864/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/1585
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/1533
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/628
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/387
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/388
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/388/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/387
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/1407
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1585
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1585/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1533
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1533/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/4057
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/2221

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/1864/rebuild

review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:473
http://jenkins.qa.ubuntu.com/job/unity8-ci/1897/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/1703
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/1634
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/674
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/420
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/421
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/421/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/420
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/1510
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1703
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1703/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1634
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1634/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/4143
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/2336

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/1897/rebuild

review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Ohkay ;P

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
http://jenkins.qa.ubuntu.com/job/unity8-autolanding/870/
Executed test runs:
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/generic-cleanup-mbs/3665
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/1816
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/1733/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/713
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-autolanding/256
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-autolanding/256
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-autolanding/256/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-autolanding/256
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/1603
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1816
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/1816/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1733
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/1733/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/4228/console
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/2468

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/Unity/Indicators/CMakeLists.txt'
--- plugins/Unity/Indicators/CMakeLists.txt 2013-10-16 19:48:57 +0000
+++ plugins/Unity/Indicators/CMakeLists.txt 2013-12-13 13:24:49 +0000
@@ -36,7 +36,6 @@
36 unitymenumodelcache.cpp36 unitymenumodelcache.cpp
37 unitymenumodelstack.cpp37 unitymenumodelstack.cpp
38 visibleindicatorsmodel.cpp38 visibleindicatorsmodel.cpp
39 timeformatter.cpp
40)39)
41add_definitions(-DUNITYINDICATORS_LIBRARY)40add_definitions(-DUNITYINDICATORS_LIBRARY)
4241
4342
=== modified file 'plugins/Unity/Indicators/Messaging/qml/SimpleTextMessage.qml'
--- plugins/Unity/Indicators/Messaging/qml/SimpleTextMessage.qml 2013-10-16 19:48:57 +0000
+++ plugins/Unity/Indicators/Messaging/qml/SimpleTextMessage.qml 2013-12-13 13:24:49 +0000
@@ -21,6 +21,7 @@
21import QtQuick 2.021import QtQuick 2.0
22import Ubuntu.Components 0.122import Ubuntu.Components 0.1
23import Unity.Indicators 0.123import Unity.Indicators 0.1
24import Utils 0.1 as Utils
2425
25HeroMessage {26HeroMessage {
26 id: __heroMessage27 id: __heroMessage
@@ -50,7 +51,7 @@
50 opacity: 0.051 opacity: 0.0
51 enabled: false52 enabled: false
5253
53 TimeFormatter {54 Utils.TimeFormatter {
54 id: timeFormatter55 id: timeFormatter
55 time: __heroMessage.time56 time: __heroMessage.time
56 format: "hh:mm - MMM dd"57 format: "hh:mm - MMM dd"
5758
=== modified file 'plugins/Unity/Indicators/Messaging/qml/SnapDecision.qml'
--- plugins/Unity/Indicators/Messaging/qml/SnapDecision.qml 2013-10-16 19:48:57 +0000
+++ plugins/Unity/Indicators/Messaging/qml/SnapDecision.qml 2013-12-13 13:24:49 +0000
@@ -20,8 +20,8 @@
2020
21import QtQuick 2.021import QtQuick 2.0
22import Ubuntu.Components 0.122import Ubuntu.Components 0.1
23import Unity.Indicators 0.1 as Indicators
24import Unity.Indicators 0.123import Unity.Indicators 0.1
24import Utils 0.1 as Utils
2525
26HeroMessage {26HeroMessage {
27 id: snapDecision27 id: snapDecision
@@ -59,7 +59,7 @@
59 height: units.gu(4)59 height: units.gu(4)
60 opacity: 0.060 opacity: 0.0
6161
62 TimeFormatter {62 Utils.TimeFormatter {
63 id: timeFormatter63 id: timeFormatter
64 time: snapDecision.time64 time: snapDecision.time
65 format: "hh:mm - MMM dd"65 format: "hh:mm - MMM dd"
6666
=== modified file 'plugins/Unity/Indicators/plugin.cpp'
--- plugins/Unity/Indicators/plugin.cpp 2013-10-16 19:48:57 +0000
+++ plugins/Unity/Indicators/plugin.cpp 2013-12-13 13:24:49 +0000
@@ -33,7 +33,6 @@
33#include "unitymenumodelcache.h"33#include "unitymenumodelcache.h"
34#include "unitymenumodelstack.h"34#include "unitymenumodelstack.h"
35#include "visibleindicatorsmodel.h"35#include "visibleindicatorsmodel.h"
36#include "timeformatter.h"
3736
38static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {37static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
39 Q_UNUSED(engine);38 Q_UNUSED(engine);
@@ -52,7 +51,6 @@
52 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");51 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");
53 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");52 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
54 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");53 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
55 qmlRegisterType<TimeFormatter>(uri, 0, 1, "TimeFormatter");
5654
57 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);55 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
5856
5957
=== modified file 'plugins/Utils/CMakeLists.txt'
--- plugins/Utils/CMakeLists.txt 2013-11-22 17:11:03 +0000
+++ plugins/Utils/CMakeLists.txt 2013-12-13 13:24:49 +0000
@@ -16,6 +16,7 @@
16 mediaartcache.cpp16 mediaartcache.cpp
17 qlimitproxymodelqml.cpp17 qlimitproxymodelqml.cpp
18 qsortfilterproxymodelqml.cpp18 qsortfilterproxymodelqml.cpp
19 timeformatter.cpp
19 unitymenumodelpaths.cpp20 unitymenumodelpaths.cpp
20 plugin.cpp21 plugin.cpp
21 )22 )
2223
=== modified file 'plugins/Utils/plugin.cpp'
--- plugins/Utils/plugin.cpp 2013-11-22 17:11:03 +0000
+++ plugins/Utils/plugin.cpp 2013-12-13 13:24:49 +0000
@@ -30,6 +30,7 @@
30#include "bottombarvisibilitycommunicatorshell.h"30#include "bottombarvisibilitycommunicatorshell.h"
31#include "qlimitproxymodelqml.h"31#include "qlimitproxymodelqml.h"
32#include "qsortfilterproxymodelqml.h"32#include "qsortfilterproxymodelqml.h"
33#include "timeformatter.h"
33#include "unitymenumodelpaths.h"34#include "unitymenumodelpaths.h"
3435
35static const char* BOTTOM_BAR_VISIBILITY_COMMUNICATOR_DBUS_PATH = "/BottomBarVisibilityCommunicator";36static const char* BOTTOM_BAR_VISIBILITY_COMMUNICATOR_DBUS_PATH = "/BottomBarVisibilityCommunicator";
@@ -42,6 +43,8 @@
42 qmlRegisterType<QLimitProxyModelQML>(uri, 0, 1, "LimitProxyModel");43 qmlRegisterType<QLimitProxyModelQML>(uri, 0, 1, "LimitProxyModel");
43 qmlRegisterType<QSortFilterProxyModelQML>(uri, 0, 1, "SortFilterProxyModel");44 qmlRegisterType<QSortFilterProxyModelQML>(uri, 0, 1, "SortFilterProxyModel");
44 qmlRegisterType<UnityMenuModelPaths>(uri, 0, 1, "UnityMenuModelPaths");45 qmlRegisterType<UnityMenuModelPaths>(uri, 0, 1, "UnityMenuModelPaths");
46 qmlRegisterType<TimeFormatter>(uri, 0, 1, "TimeFormatter");
47 qmlRegisterType<GDateTimeFormatter>(uri, 0, 1, "GDateTimeFormatter");
45 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");48 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
46}49}
4750
4851
=== renamed file 'plugins/Unity/Indicators/timeformatter.cpp' => 'plugins/Utils/timeformatter.cpp'
--- plugins/Unity/Indicators/timeformatter.cpp 2013-10-16 19:48:57 +0000
+++ plugins/Utils/timeformatter.cpp 2013-12-13 13:24:49 +0000
@@ -167,6 +167,35 @@
167167
168void TimeFormatter::update()168void TimeFormatter::update()
169{169{
170 priv->timeString = QDateTime::fromMSecsSinceEpoch(priv->time / 1000).toString(priv->format);170 priv->timeString = formatTime();
171 Q_EMIT timeStringChanged(priv->timeString);171 Q_EMIT timeStringChanged(priv->timeString);
172}172}
173
174QString TimeFormatter::formatTime() const
175{
176 return QDateTime::fromMSecsSinceEpoch(time() / 1000).toString(format());
177}
178
179GDateTimeFormatter::GDateTimeFormatter(QObject* parent)
180: TimeFormatter(parent)
181{
182}
183
184QString GDateTimeFormatter::formatTime() const
185{
186 gchar* time_string;
187 GDateTime* datetime;
188 QByteArray formatBytes = format().toUtf8();
189
190 datetime = g_date_time_new_from_unix_local(time());
191 if (!datetime) {
192 return "";
193 }
194
195 time_string = g_date_time_format(datetime, formatBytes.constData());
196 QString formattedTime(QString::fromUtf8(time_string));
197
198 g_free(time_string);
199 g_date_time_unref(datetime);
200 return formattedTime;
201}
173202
=== renamed file 'plugins/Unity/Indicators/timeformatter.h' => 'plugins/Utils/timeformatter.h'
--- plugins/Unity/Indicators/timeformatter.h 2013-10-16 19:48:57 +0000
+++ plugins/Utils/timeformatter.h 2013-12-13 13:24:49 +0000
@@ -19,10 +19,10 @@
19#ifndef TIME_FORMATTER_H19#ifndef TIME_FORMATTER_H
20#define TIME_FORMATTER_H20#define TIME_FORMATTER_H
2121
22#include "unityindicatorsglobal.h"
23#include <QObject>22#include <QObject>
2423
25class UNITYINDICATORS_EXPORT TimeFormatter : public QObject24// TODO - bug #1260728
25class TimeFormatter : public QObject
26{26{
27 Q_OBJECT27 Q_OBJECT
28 Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged)28 Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged)
@@ -31,7 +31,7 @@
3131
32public:32public:
33 TimeFormatter(QObject *parent = 0);33 TimeFormatter(QObject *parent = 0);
34 ~TimeFormatter();34 virtual ~TimeFormatter();
3535
36 QString format() const;36 QString format() const;
37 QString timeString() const;37 QString timeString() const;
@@ -47,8 +47,20 @@
47 void timeStringChanged(const QString &timeString);47 void timeStringChanged(const QString &timeString);
48 void timeChanged(qint64 time);48 void timeChanged(qint64 time);
4949
50protected:
51 virtual QString formatTime() const;
52
50private:53private:
51 struct TimeFormatterPrivate *priv;54 struct TimeFormatterPrivate *priv;
52};55};
5356
57class GDateTimeFormatter : public TimeFormatter
58{
59public:
60 GDateTimeFormatter(QObject *parent = 0);
61
62protected:
63 virtual QString formatTime() const;
64};
65
54#endif66#endif
5567
=== modified file 'tests/plugins/Unity/Indicators/CMakeLists.txt'
--- tests/plugins/Unity/Indicators/CMakeLists.txt 2013-11-06 10:26:58 +0000
+++ tests/plugins/Unity/Indicators/CMakeLists.txt 2013-12-13 13:24:49 +0000
@@ -40,4 +40,3 @@
40indicator_test(menucontentactivatortest ADDITIONAL_CPPS ${INDICATORS_DIR}/menucontentactivator.cpp)40indicator_test(menucontentactivatortest ADDITIONAL_CPPS ${INDICATORS_DIR}/menucontentactivator.cpp)
41indicator_test(unitymenumodelstacktest ADDITIONAL_CPPS ${TEST_DIR}/mocks/QMenuModel/unitymenumodel.cpp ${INDICATORS_DIR}/unitymenumodelstack.cpp)41indicator_test(unitymenumodelstacktest ADDITIONAL_CPPS ${TEST_DIR}/mocks/QMenuModel/unitymenumodel.cpp ${INDICATORS_DIR}/unitymenumodelstack.cpp)
42indicator_test(rootactionstatetest ADDITIONAL_LIBS IndicatorsQml)42indicator_test(rootactionstatetest ADDITIONAL_LIBS IndicatorsQml)
43indicator_test(timeformattertest ADDITIONAL_LIBS IndicatorsQml)
4443
=== modified file 'tests/plugins/Utils/CMakeLists.txt'
--- tests/plugins/Utils/CMakeLists.txt 2013-06-05 22:03:08 +0000
+++ tests/plugins/Utils/CMakeLists.txt 2013-12-13 13:24:49 +0000
@@ -24,4 +24,5 @@
24run_tests(24run_tests(
25 qlimitproxymodeltest25 qlimitproxymodeltest
26 qsortfilterproxymodeltest26 qsortfilterproxymodeltest
27 timeformattertest
27 )28 )
2829
=== renamed file 'tests/plugins/Unity/Indicators/timeformattertest.cpp' => 'tests/plugins/Utils/timeformattertest.cpp'
--- tests/plugins/Unity/Indicators/timeformattertest.cpp 2013-10-16 20:17:15 +0000
+++ tests/plugins/Utils/timeformattertest.cpp 2013-12-13 13:24:49 +0000
@@ -48,6 +48,19 @@
4848
49 QCOMPARE(formatter.timeString(), time.toString(format));49 QCOMPARE(formatter.timeString(), time.toString(format));
50 }50 }
51
52 void testFormatStrF()
53 {
54 const QString format = "%d-%m-%Y %I:%M%p";
55
56 QDateTime time = QDateTime::currentDateTime();
57
58 GDateTimeFormatter formatter;
59 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
60 formatter.setFormat(format);
61
62 QCOMPARE(formatter.timeString(), time.toString("dd-MM-yyyy hh:mmAP"));
63 }
51};64};
5265
53QTEST_GUILESS_MAIN(TimeFormatterTest)66QTEST_GUILESS_MAIN(TimeFormatterTest)

Subscribers

People subscribed via source and target branches