summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Wu Won <kevin.wu-won@nokia.com>2010-05-31 15:00:29 +1000
committerKevin Wu Won <kevin.wu-won@nokia.com>2010-05-31 16:29:05 +1000
commit5d2c4b9723e1362262366ec518164a728ca75779 (patch)
treea694945dd8892b0d1ed28b77be67aa97b00c97d6
parent530b87908aa83666ade74561ff52321418bf1962 (diff)
Implemented basic functionality in QVersitOrganizerImporter
VEVENT component is now supported with DTSTART, DTEND and SUMMARY Includes unit tests
-rw-r--r--src/versit/qversitorganizerimporter.cpp30
-rw-r--r--src/versit/qversitorganizerimporter.h2
-rw-r--r--src/versit/qversitorganizerimporter_p.cpp100
-rw-r--r--src/versit/qversitorganizerimporter_p.h21
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qversitorganizerimporter/qversitorganizerimporter.pro31
-rw-r--r--tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.cpp98
-rw-r--r--tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.h64
8 files changed, 331 insertions, 16 deletions
diff --git a/src/versit/qversitorganizerimporter.cpp b/src/versit/qversitorganizerimporter.cpp
index f9e2694cad..31732af67e 100644
--- a/src/versit/qversitorganizerimporter.cpp
+++ b/src/versit/qversitorganizerimporter.cpp
@@ -68,26 +68,38 @@ QVersitOrganizerImporter::~QVersitOrganizerImporter()
}
/*!
- * Converts \a documents into a corresponding list of QOrganizerItems. After calling this, the
+ * Converts \a document into a corresponding list of QOrganizerItems. After calling this, the
* converted organizer items can be retrieved by calling items().
*
- * Returns true on success. If any of the documents cannot be imported as organizer items (eg. they
- * don't conform to the iCalendar format), false is returned and errors() will return a list
- * describing the errors that occurred. The successfully imported documents will still be available
- * via items().
+ * Returns true on success. The document should contain at least one subdocument. In the
+ * importing process, each subdocument roughly corresponds to a QOrganizerItem. If any of the
+ * subdocuments cannot be imported as organizer items (eg. they don't conform to the iCalendar
+ * format), false is returned and errors() will return a list describing the errors that occurred.
+ * The successfully imported items will still be available via items().
*
* \sa items(), errors()
*/
-bool QVersitOrganizerImporter::importDocuments(const QList<QVersitDocument>& documents)
+bool QVersitOrganizerImporter::importDocument(const QVersitDocument& document)
{
- int documentIndex = 0;
d->mItems.clear();
d->mErrors.clear();
bool ok = true;
- foreach (const QVersitDocument& document, documents) {
+ if (document.type() != QVersitDocument::ICalendar20Type
+ || document.componentType() != QLatin1String("VCALENDAR")) {
+ d->mErrors.insert(-1, QVersitOrganizerImporter::InvalidDocumentError);
+ return false;
+ }
+ const QList<QVersitDocument> subDocuments = document.subDocuments();
+ if (subDocuments.isEmpty()) {
+ d->mErrors.insert(-1, QVersitOrganizerImporter::EmptyDocumentError);
+ return false;
+ }
+
+ int documentIndex = 0;
+ foreach (const QVersitDocument& subDocument, subDocuments) {
QOrganizerItem item;
QVersitOrganizerImporter::Error error;
- if (d->importItem(document, &item, &error)) {
+ if (d->importDocument(subDocument, &item, &error)) {
d->mItems.append(item);
} else {
d->mErrors.insert(documentIndex, error);
diff --git a/src/versit/qversitorganizerimporter.h b/src/versit/qversitorganizerimporter.h
index 78f8826e2e..9daed3bf79 100644
--- a/src/versit/qversitorganizerimporter.h
+++ b/src/versit/qversitorganizerimporter.h
@@ -82,7 +82,7 @@ public:
QVersitOrganizerImporter();
~QVersitOrganizerImporter();
- bool importDocuments(const QList<QVersitDocument>& documents);
+ bool importDocument(const QVersitDocument& documents);
QList<QOrganizerItem> items() const;
QMap<int, Error> errors() const;
diff --git a/src/versit/qversitorganizerimporter_p.cpp b/src/versit/qversitorganizerimporter_p.cpp
index 38d20da01a..53fa601774 100644
--- a/src/versit/qversitorganizerimporter_p.cpp
+++ b/src/versit/qversitorganizerimporter_p.cpp
@@ -43,6 +43,7 @@
#include "qversitdocument.h"
#include "qversitproperty.h"
#include "qmobilityglobal.h"
+#include "qtorganizer.h"
QTM_USE_NAMESPACE
@@ -59,11 +60,104 @@ QVersitOrganizerImporterPrivate::~QVersitOrganizerImporterPrivate()
delete mDefaultResourceHandler;
}
-bool QVersitOrganizerImporterPrivate::importItem(
- const QVersitDocument& versitDocument,
+bool QVersitOrganizerImporterPrivate::importDocument(
+ const QVersitDocument& document,
QOrganizerItem* item,
QVersitOrganizerImporter::Error* error)
{
- // TODO
+ if (document.componentType() == QLatin1String("VEVENT")) {
+ item->setType(QOrganizerItemType::TypeEvent);
+ } else {
+ *error = QVersitOrganizerImporter::InvalidDocumentError;
+ return false;
+ }
+ const QList<QVersitProperty> properties = document.properties();
+ if (properties.isEmpty()) {
+ *error = QVersitOrganizerImporter::EmptyDocumentError;
+ return false;
+ }
+
+ foreach (const QVersitProperty& property, properties) {
+ importProperty(document, property, item);
+ }
+ return true;
+}
+
+void QVersitOrganizerImporterPrivate::importProperty(
+ const QVersitDocument& document,
+ const QVersitProperty& property,
+ QOrganizerItem* item)
+{
+ QList<QOrganizerItemDetail> updatedDetails;
+
+ bool success = false;
+ if (property.name() == QLatin1String("SUMMARY")) {
+ success = createDisplayLabel(property, item, &updatedDetails);
+ }
+
+ if (document.componentType() == QLatin1String("VEVENT")) {
+ if (property.name() == QLatin1String("DTSTART")) {
+ success = createStartDateTime(property, item, &updatedDetails);
+ } else if (property.name() == QLatin1String("DTEND")) {
+ success = createEndDateTime(property, item, &updatedDetails);
+ }
+ }
+
+ foreach (QOrganizerItemDetail detail, updatedDetails) {
+ item->saveDetail(&detail);
+ }
+}
+
+bool QVersitOrganizerImporterPrivate::createDisplayLabel(
+ const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails)
+{
+ if (property.value().isEmpty())
+ return false;
+ QOrganizerItemDisplayLabel displayLabel(item->detail<QOrganizerItemDisplayLabel>());
+ displayLabel.setLabel(property.value());
+ updatedDetails->append(displayLabel);
return true;
}
+
+bool QVersitOrganizerImporterPrivate::createStartDateTime(
+ const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails) {
+ if (property.value().isEmpty())
+ return false;
+ QDateTime datetime = parseDateTime(property.value());
+ if (!datetime.isValid())
+ return false;
+ QOrganizerItemEventTimeRange etr(item->detail<QOrganizerItemEventTimeRange>());
+ etr.setStartDateTime(datetime);
+ updatedDetails->append(etr);
+ return true;
+}
+
+bool QVersitOrganizerImporterPrivate::createEndDateTime(
+ const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails) {
+ if (property.value().isEmpty())
+ return false;
+ QDateTime datetime = parseDateTime(property.value());
+ if (!datetime.isValid())
+ return false;
+ QOrganizerItemEventTimeRange etr(item->detail<QOrganizerItemEventTimeRange>());
+ etr.setEndDateTime(datetime);
+ updatedDetails->append(etr);
+ return true;
+}
+
+QDateTime QVersitOrganizerImporterPrivate::parseDateTime(QString str)
+{
+ bool utc = str.endsWith(QLatin1Char('Z'), Qt::CaseInsensitive);
+ if (utc)
+ str.chop(1); // take away z from end;
+ QDateTime dt(QDateTime::fromString(str, QLatin1String("yyyyMMddTHHmmss")));
+ if (utc)
+ dt.setTimeSpec(Qt::UTC);
+ return dt;
+}
diff --git a/src/versit/qversitorganizerimporter_p.h b/src/versit/qversitorganizerimporter_p.h
index 4a1fb445aa..82263f9e7e 100644
--- a/src/versit/qversitorganizerimporter_p.h
+++ b/src/versit/qversitorganizerimporter_p.h
@@ -66,15 +66,30 @@ class Q_AUTOTEST_EXPORT QVersitOrganizerImporterPrivate
public:
QVersitOrganizerImporterPrivate();
~QVersitOrganizerImporterPrivate();
- bool importItem(const QVersitDocument& versitDocument,
- QOrganizerItem* item,
- QVersitOrganizerImporter::Error* error);
+ bool importDocument(const QVersitDocument& versitDocument,
+ QOrganizerItem* item,
+ QVersitOrganizerImporter::Error* error);
+ void importProperty(const QVersitDocument& document,
+ const QVersitProperty& property,
+ QOrganizerItem* item);
QList<QOrganizerItem> mItems;
QMap<int, QVersitOrganizerImporter::Error> mErrors;
QVersitOrganizerImporterPropertyHandler* mPropertyHandler;
QVersitDefaultResourceHandler* mDefaultResourceHandler;
QVersitResourceHandler* mResourceHandler;
+
+private:
+ bool createDisplayLabel(const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails);
+ bool createStartDateTime(const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails);
+ bool createEndDateTime(const QVersitProperty& property,
+ QOrganizerItem* item,
+ QList<QOrganizerItemDetail>* updatedDetails);
+ QDateTime parseDateTime(QString str);
};
QTM_END_NAMESPACE
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 9915b06b4b..93af3c22e7 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -92,6 +92,7 @@ contains(mobility_modules,versit) {
qversitcontactexporter \
qversitcontactimporter \
qversitdocument \
+ qversitorganizerimporter \
qversitproperty \
qversitreader \
qversitwriter
diff --git a/tests/auto/qversitorganizerimporter/qversitorganizerimporter.pro b/tests/auto/qversitorganizerimporter/qversitorganizerimporter.pro
new file mode 100644
index 0000000000..838934f78d
--- /dev/null
+++ b/tests/auto/qversitorganizerimporter/qversitorganizerimporter.pro
@@ -0,0 +1,31 @@
+QT += testlib
+TEMPLATE=app
+TARGET=tst_qversitorganizerimporter
+CONFIG+=testcase
+
+include(../../../common.pri)
+DEFINES += QT_ASCII_CAST_WARNINGS
+
+DEPENDPATH += .
+INCLUDEPATH += \
+ . \
+ ../../ \
+ ../../../src/versit \
+ ../../../src/organizer \
+ ../../../src/organizer/details \
+ ../../../src/organizer/requests \
+ ../../../src/organizer/filters \
+ ../../../src/organizer/items
+
+HEADERS += tst_qversitorganizerimporter.h
+SOURCES += tst_qversitorganizerimporter.cpp
+
+CONFIG += mobility
+MOBILITY += organizer versit contacts
+
+symbian: {
+ TARGET.CAPABILITY = ALL \
+ -TCB
+ LIBS += -lws32 \
+ -lbafl
+}
diff --git a/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.cpp b/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.cpp
new file mode 100644
index 0000000000..fd56d6291b
--- /dev/null
+++ b/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tst_qversitorganizerimporter.h"
+#include <QtTest/QtTest>
+
+Q_DECLARE_METATYPE(QList<QOrganizerItem>);
+
+void tst_QVersitOrganizerImporter::testImport()
+{
+ QFETCH(QVersitDocument, document);
+ QFETCH(QList<QOrganizerItem>, expectedItems);
+
+ QVersitOrganizerImporter importer;
+ QVERIFY(importer.importDocument(document));
+ QVERIFY(importer.errors().isEmpty());
+ QList<QOrganizerItem> items = importer.items();
+ if (items != expectedItems) {
+ qDebug() << "Actual:" << items;
+ qDebug() << "Expected:" << expectedItems;
+ QCOMPARE(items, expectedItems);
+ }
+}
+
+void tst_QVersitOrganizerImporter::testImport_data()
+{
+ QTest::addColumn<QVersitDocument>("document");
+ QTest::addColumn<QList<QOrganizerItem> >("expectedItems");
+
+ QVersitDocument document(QVersitDocument::ICalendar20Type);
+ document.setComponentType(QLatin1String("VCALENDAR"));
+ QVersitProperty property;
+ property.setName(QLatin1String("PRODID"));
+ property.setValue(QLatin1String("-//hacksw/handcal//NONSGML v1.0//EN"));
+ document.addProperty(property);
+ QVersitDocument nested(QVersitDocument::ICalendar20Type);
+ nested.setComponentType(QLatin1String("VEVENT"));
+ property.setName(QLatin1String("SUMMARY"));
+ property.setValue(QLatin1String("Bastille Day Party"));
+ nested.addProperty(property);
+ property.setName(QLatin1String("DTSTART"));
+ property.setValue(QLatin1String("19970714T170000Z"));
+ nested.addProperty(property);
+ property.setName(QLatin1String("DTEND"));
+ property.setValue(QLatin1String("19970715T035959Z"));
+ nested.addProperty(property);
+ document.addSubDocument(nested);
+
+ QOrganizerEvent event;
+ event.setDisplayLabel(QLatin1String("Bastille Day Party"));
+ event.setStartDateTime(QDateTime(QDate(1997, 7, 14), QTime(17, 0, 0), Qt::UTC));
+ event.setEndDateTime(QDateTime(QDate(1997, 7, 15), QTime(3, 59, 59), Qt::UTC));
+
+ QList<QOrganizerItem> items;
+ items << static_cast<QOrganizerItem>(event);
+
+ QTest::newRow("sample event") << document << items;
+}
+
+QTEST_MAIN(tst_QVersitOrganizerImporter)
diff --git a/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.h b/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.h
new file mode 100644
index 0000000000..b66c8fc105
--- /dev/null
+++ b/tests/auto/qversitorganizerimporter/tst_qversitorganizerimporter.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef tst_QVERSITORGANIZERIMPORTER_H
+#define tst_QVERSITORGANIZERIMPORTER_H
+
+#include <QObject>
+#include "qversitorganizerimporter.h"
+#include "qversitdocument.h"
+#include "qversitproperty.h"
+#include "qtorganizer.h"
+
+QTM_BEGIN_NAMESPACE
+QTM_END_NAMESPACE
+QTM_USE_NAMESPACE
+
+class tst_QVersitOrganizerImporter : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testImport();
+ void testImport_data();
+};
+
+#endif