← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/plasma-indicatordisplay/trunk] Rev 73: Moved datetime formatting to a separate namespace to prepare for unit-testing.

 

------------------------------------------------------------
revno: 73
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-indicatordisplay
timestamp: Fri 2009-09-11 12:18:06 +0200
message:
  Moved datetime formatting to a separate namespace to prepare for unit-testing.
added:
  src/timeutils.cpp
  src/timeutils.h
  tests/timeutilstest.cpp
  tests/timeutilstest.h
modified:
  src/CMakeLists.txt
  src/delegate.cpp
  tests/CMakeLists.txt


--
lp:plasma-indicatordisplay
https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk

Your team ayatana-commits is subscribed to branch lp:plasma-indicatordisplay.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-indicatordisplay/trunk/+edit-subscription.
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt	2009-08-10 16:04:49 +0000
+++ src/CMakeLists.txt	2009-09-11 10:18:06 +0000
@@ -9,6 +9,7 @@
     filtermodel.cpp
     listenermodel.cpp
     modeldump.cpp
+    timeutils.cpp
     view.cpp
     )
 

=== modified file 'src/delegate.cpp'
--- src/delegate.cpp	2009-09-11 10:03:01 +0000
+++ src/delegate.cpp	2009-09-11 10:18:06 +0000
@@ -19,11 +19,10 @@
 
 // KDE
 #include <KDebug>
-#include <KGlobal>
-#include <KLocale>
 
 // Local
 #include "listenermodel.h"
+#include "timeutils.h"
 
 static const int SEPARATOR_HEIGHT = 6;
 static const int VSPACING = 2;
@@ -57,8 +56,7 @@
         // Indicator
         QDateTime dateTime = index.data(ListenerModel::IndicatorDateTimeRole).toDateTime();
         if (dateTime.isValid()) {
-            kDebug() << "FIXME: Handle date part";
-            return KGlobal::locale()->formatTime(dateTime.time());
+            return TimeUtils::formatDateTime(dateTime);
         }
     }
     return QString();

=== added file 'src/timeutils.cpp'
--- src/timeutils.cpp	1970-01-01 00:00:00 +0000
+++ src/timeutils.cpp	2009-09-11 10:18:06 +0000
@@ -0,0 +1,29 @@
+/*
+ * Plasma applet to display indicators from libindicate
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: GPL v3
+ */
+#include "timeutils.h"
+
+// Qt
+#include <QDateTime>
+
+// KDE
+#include <KDebug>
+#include <KGlobal>
+#include <KLocale>
+
+namespace TimeUtils
+{
+
+QString formatDateTime(const QDateTime& dateTime, const QDateTime& now)
+{
+    return KGlobal::locale()->formatTime(dateTime.time());
+}
+
+} // namespace

=== added file 'src/timeutils.h'
--- src/timeutils.h	1970-01-01 00:00:00 +0000
+++ src/timeutils.h	2009-09-11 10:18:06 +0000
@@ -0,0 +1,29 @@
+/*
+ * Plasma applet to display indicators from libindicate
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: GPL v3
+ */
+#ifndef TIMEUTILS_H
+#define TIMEUTILS_H
+
+// Qt
+#include <QDateTime>
+
+namespace TimeUtils
+{
+
+/**
+ * Format a date time according to the messaging menu spec.
+ * @param dateTime the date to format
+ * @param now defines the current date, useful for unittesting
+ */
+QString formatDateTime(const QDateTime& dateTime, const QDateTime& now = QDateTime());
+
+} // namespace
+
+#endif /* TIMEUTILS_H */

=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt	2009-07-30 14:54:42 +0000
+++ tests/CMakeLists.txt	2009-09-11 10:18:06 +0000
@@ -33,3 +33,15 @@
 target_link_libraries(filtermodeltest
     ${test_LIBRARIES}
     )
+
+# timeutilstest
+set(timeutilstest_SRCS
+    timeutilstest.cpp
+    ../src/timeutils.cpp
+    )
+
+kde4_add_unit_test(timeutilstest ${timeutilstest_SRCS})
+
+target_link_libraries(timeutilstest
+    ${test_LIBRARIES}
+    )

=== added file 'tests/timeutilstest.cpp'
--- tests/timeutilstest.cpp	1970-01-01 00:00:00 +0000
+++ tests/timeutilstest.cpp	2009-09-11 10:18:06 +0000
@@ -0,0 +1,34 @@
+/*
+ * Plasma applet to display indicators from libindicate
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: GPL v3
+ */
+// Self
+#include "timeutilstest.h"
+
+// Qt
+#include <QtTest>
+
+// KDE
+#include <qtest_kde.h>
+#include <KDebug>
+
+// Local
+#include <timeutils.h>
+
+QTEST_KDEMAIN(TimeUtilsTest, GUI)
+
+void TimeUtilsTest::testFormatDateTime()
+{
+}
+
+void TimeUtilsTest::testFormatDateTime_data()
+{
+}
+
+#include "timeutilstest.moc"

=== added file 'tests/timeutilstest.h'
--- tests/timeutilstest.h	1970-01-01 00:00:00 +0000
+++ tests/timeutilstest.h	2009-09-11 10:18:06 +0000
@@ -0,0 +1,28 @@
+/*
+ * Plasma applet to display indicators from libindicate
+ *
+ * Copyright 2009 Canonical Ltd.
+ *
+ * Authors:
+ * - Aurélien Gâteau <aurelien.gateau@xxxxxxxxxxxxx>
+ *
+ * License: GPL v3
+ */
+#ifndef TIMEUTILSTEST_H
+#define TIMEUTILSTEST_H
+
+// Qt
+#include <QObject>
+
+/**
+ * Test the TimeUtils format code
+ */
+class TimeUtilsTest : public QObject
+{
+Q_OBJECT
+private Q_SLOTS:
+    void testFormatDateTime();
+    void testFormatDateTime_data();
+};
+
+#endif /* TIMEUTILSTEST_H */