| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtVersitOrganizer module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #ifndef QVERSITORGANIZERIMPORTER_P_H |
| 35 | #define QVERSITORGANIZERIMPORTER_P_H |
| 36 | |
| 37 | // |
| 38 | // W A R N I N G |
| 39 | // ------------- |
| 40 | // |
| 41 | // This file is not part of the Qt API. It exists purely as an |
| 42 | // implementation detail. This header file may change from version to |
| 43 | // version without notice, or even be removed. |
| 44 | // |
| 45 | // We mean it. |
| 46 | // |
| 47 | |
| 48 | #include <QtCore/qpair.h> |
| 49 | #include <QtCore/qset.h> |
| 50 | |
| 51 | #include <QtOrganizer/qorganizeritem.h> |
| 52 | #include <QtOrganizer/qorganizeritemdetail.h> |
| 53 | |
| 54 | #include <QtVersitOrganizer/qversitorganizerimporter.h> |
| 55 | #include <QtVersitOrganizer/private/qtimezones_p.h> |
| 56 | |
| 57 | QT_BEGIN_NAMESPACE_ORGANIZER |
| 58 | class QOrganizerRecurrenceRule; |
| 59 | QT_END_NAMESPACE_ORGANIZER |
| 60 | |
| 61 | QTORGANIZER_USE_NAMESPACE |
| 62 | |
| 63 | QT_BEGIN_NAMESPACE_VERSITORGANIZER |
| 64 | |
| 65 | class QVersitOrganizerHandler; |
| 66 | class QVersitTimeZoneHandler; |
| 67 | |
| 68 | class Duration |
| 69 | { |
| 70 | public: |
| 71 | Duration() : |
| 72 | mNegative(false), mWeeks(0), mDays(0), mHours(0), mMinutes(0), mSeconds(0), mValid(true) |
| 73 | {} |
| 74 | static Duration invalidDuration() { Duration d; d.setValid(false); return d; } |
| 75 | static Duration parseDuration(QString str); |
| 76 | static void parseDurationTime(QString* str, Duration* dur); |
| 77 | static void parseDurationMinutes(QString* str, Duration* dur); |
| 78 | static void parseDurationSeconds(QString* str, Duration* dur); |
| 79 | static QString nextToken(QString* str); |
| 80 | |
| 81 | void setNegative(bool neg) { mNegative = neg; } |
| 82 | void setWeeks(int weeks) { mWeeks = weeks; } |
| 83 | void setDays(int days) { mDays = days; } |
| 84 | void setHours(int hours) { mHours = hours; } |
| 85 | void setMinutes(int minutes) { mMinutes = minutes; } |
| 86 | void setSeconds(int seconds) { mSeconds = seconds; } |
| 87 | void setValid(bool val) { mValid = val; } |
| 88 | int weeks() { return mNegative ? -mWeeks : mWeeks; } |
| 89 | int days() { return mNegative ? -mDays : mDays; } |
| 90 | int hours() { return mNegative ? -mHours : mHours; } |
| 91 | int minutes() { return mNegative ? -mMinutes : mMinutes; } |
| 92 | int seconds() { return mNegative ? -mSeconds : mSeconds; } |
| 93 | bool isValid() { return mValid; } |
| 94 | int toSeconds() { return (seconds() |
| 95 | + 60*minutes() |
| 96 | + 3600*hours() |
| 97 | + 86400*days() |
| 98 | + 604800*weeks()); |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | bool mNegative; |
| 103 | int mWeeks; |
| 104 | int mDays; |
| 105 | int mHours; |
| 106 | int mMinutes; |
| 107 | int mSeconds; |
| 108 | bool mValid; |
| 109 | }; |
| 110 | |
| 111 | class QVersitOrganizerImporterPrivate |
| 112 | { |
| 113 | public: |
| 114 | QVersitOrganizerImporterPrivate(const QString& profile = QString()); |
| 115 | ~QVersitOrganizerImporterPrivate(); |
| 116 | bool importDocument(const QVersitDocument& topLevel, |
| 117 | const QVersitDocument& subDocument, |
| 118 | QOrganizerItem* item, |
| 119 | QVersitOrganizerImporter::Error* error); |
| 120 | void importProperty(const QVersitDocument& document, |
| 121 | const QVersitProperty& property, |
| 122 | QOrganizerItem* item); |
| 123 | |
| 124 | QList<QOrganizerItem> mItems; |
| 125 | QMap<int, QVersitOrganizerImporter::Error> mErrors; |
| 126 | QVersitOrganizerImporterPropertyHandler* mPropertyHandler; |
| 127 | QList<QVersitOrganizerHandler*> mPluginPropertyHandlers; |
| 128 | QVersitTimeZoneHandler* mTimeZoneHandler; |
| 129 | bool mDurationSpecified; // true iff a valid DURATION property has been seen in the current |
| 130 | // document with no subsequent DTEND property |
| 131 | |
| 132 | private: |
| 133 | bool createSimpleDetail( |
| 134 | const QVersitProperty& property, |
| 135 | QOrganizerItem* item, |
| 136 | QList<QOrganizerItemDetail>* updatedDetails); |
| 137 | bool createTimestampCreated( |
| 138 | const QVersitProperty& property, |
| 139 | QOrganizerItem* item, |
| 140 | QList<QOrganizerItemDetail>* updatedDetails); |
| 141 | bool createTimestampModified( |
| 142 | const QVersitProperty& property, |
| 143 | QOrganizerItem* item, |
| 144 | QList<QOrganizerItemDetail>* updatedDetails); |
| 145 | bool createVersion( |
| 146 | const QVersitProperty& property, |
| 147 | QOrganizerItem* item, |
| 148 | QList<QOrganizerItemDetail>* updatedDetails); |
| 149 | bool createPriority( |
| 150 | const QVersitProperty& property, |
| 151 | QOrganizerItem* item, |
| 152 | QList<QOrganizerItemDetail>* updatedDetails); |
| 153 | bool ( |
| 154 | const QVersitProperty& property, |
| 155 | QList<QOrganizerItemDetail>* updatedDetails); |
| 156 | bool createItemReminder( |
| 157 | const QVersitDocument &valarmDocument, |
| 158 | QOrganizerItem *item, |
| 159 | QList<QOrganizerItemDetail> *updatedDetails); |
| 160 | int triggerToSecondsBeforeStart(const QVersitProperty& triggerProperty, const QOrganizerItem &item); |
| 161 | |
| 162 | bool createExtendedDetail( |
| 163 | const QVersitProperty &property, |
| 164 | QList<QOrganizerItemDetail> *updatedDetails); |
| 165 | bool createRecurrenceId( |
| 166 | const QVersitProperty& property, |
| 167 | QOrganizerItem* item, |
| 168 | QList<QOrganizerItemDetail>* updatedDetails); |
| 169 | bool createStartDateTime( |
| 170 | const QVersitProperty& property, |
| 171 | QOrganizerItem* item, |
| 172 | QList<QOrganizerItemDetail>* updatedDetails); |
| 173 | bool createEndDateTime( |
| 174 | const QVersitProperty& property, |
| 175 | QOrganizerItem* item, |
| 176 | QList<QOrganizerItemDetail>* updatedDetails); |
| 177 | bool createDuration( |
| 178 | const QVersitProperty& property, |
| 179 | QOrganizerItem* item, |
| 180 | QList<QOrganizerItemDetail>* updatedDetails); |
| 181 | bool createTodoStartDateTime( |
| 182 | const QVersitProperty& property, |
| 183 | QOrganizerItem* item, |
| 184 | QList<QOrganizerItemDetail>* updatedDetails); |
| 185 | bool createDueDateTime( |
| 186 | const QVersitProperty& property, |
| 187 | QOrganizerItem* item, |
| 188 | QList<QOrganizerItemDetail>* updatedDetails); |
| 189 | bool createJournalEntryDateTime( |
| 190 | const QVersitProperty& property, |
| 191 | QOrganizerItem* item, |
| 192 | QList<QOrganizerItemDetail>* updatedDetails); |
| 193 | QDateTime parseDateTime(const QVersitProperty& property, bool* hasTime = 0) const; |
| 194 | QDateTime parseDateTime(QString str) const; |
| 195 | |
| 196 | bool createRecurrenceRule( |
| 197 | const QVersitProperty& property, |
| 198 | QOrganizerItem* item, |
| 199 | QList<QOrganizerItemDetail>* updatedDetails); |
| 200 | bool parseRecurRule(const QString& str, QOrganizerRecurrenceRule* rule) const; |
| 201 | void parseRecurFragment(const QString& key, const QString& value, |
| 202 | QOrganizerRecurrenceRule* rule) const; |
| 203 | QSet<int> parseInts(const QString& str, int min, int max) const; |
| 204 | int parseDayOfWeek(const QString& str) const; |
| 205 | |
| 206 | bool createRecurrenceDates( |
| 207 | const QVersitProperty& property, |
| 208 | QOrganizerItem* item, |
| 209 | QList<QOrganizerItemDetail>* updatedDetails); |
| 210 | bool parseDates(const QString& str, QSet<QDate>* dates) const; |
| 211 | QDate parseDate(QString str) const; |
| 212 | |
| 213 | bool createStatus( |
| 214 | const QVersitProperty& property, |
| 215 | QOrganizerItem* item, |
| 216 | QList<QOrganizerItemDetail>* updatedDetails); |
| 217 | bool createPercentageComplete( |
| 218 | const QVersitProperty& property, |
| 219 | QOrganizerItem* item, |
| 220 | QList<QOrganizerItemDetail>* updatedDetails); |
| 221 | bool createFinishedDateTime( |
| 222 | const QVersitProperty& property, |
| 223 | QOrganizerItem* item, |
| 224 | QList<QOrganizerItemDetail>* updatedDetails); |
| 225 | |
| 226 | TimeZone importTimeZone(const QVersitDocument& document) const; |
| 227 | TimeZonePhase importTimeZonePhase(const QVersitDocument& document) const; |
| 228 | |
| 229 | QString takeFirst(QList<QString>& list) const; |
| 230 | |
| 231 | // versit property name -> <definition name, field name>: |
| 232 | QMap<QString, QPair<QOrganizerItemDetail::DetailType, int> > mPropertyMappings; |
| 233 | TimeZones mTimeZones; |
| 234 | }; |
| 235 | |
| 236 | QT_END_NAMESPACE_VERSITORGANIZER |
| 237 | |
| 238 | #endif // QVERSITORGANIZERIMPORTER_P_H |
| 239 | |