2 Copyright (c) 2009, 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3 Author: Frank Osterfeld <osterfeld@kde.org>
4 Author: Andras Mantia <andras@kdab.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
24 #ifndef CALENDARSUPPORT_UTILS_H
25 #define CALENDARSUPPORT_UTILS_H
27 #include "calendarsupport_export.h"
31 #include <Akonadi/Calendar/ETMCalendar>
33 #include <KCalCore/Event>
34 #include <KCalCore/Incidence>
35 #include <KCalCore/Journal>
36 #include <KCalCore/ScheduleMessage>
37 #include <KCalCore/Todo>
41 #include <QModelIndex>
53 class QAbstractItemModel
;
57 typedef QList
<QModelIndex
> QModelIndexList
;
59 namespace CalendarSupport
64 * returns the incidence from an akonadi item, or a null pointer if the item has no such payload
66 CALENDARSUPPORT_EXPORT
KCalCore::Incidence::Ptr
incidence(const Akonadi::Item
&item
);
69 * returns the event from an akonadi item, or a null pointer if the item has no such payload
71 CALENDARSUPPORT_EXPORT
KCalCore::Event::Ptr
event(const Akonadi::Item
&item
);
74 * returns the event from an incidence, or a null pointer if the item has no such payload
76 CALENDARSUPPORT_EXPORT
KCalCore::Event::Ptr
event(const KCalCore::Incidence::Ptr
&incidence
);
79 * returns event pointers from an akonadi item, or a null pointer if the item has no such payload
81 CALENDARSUPPORT_EXPORT
KCalCore::Event::List
eventsFromItems(const Akonadi::Item::List
&items
);
84 * returns incidence pointers from an akonadi item.
86 CALENDARSUPPORT_EXPORT
KCalCore::Incidence::List
incidencesFromItems(
87 const Akonadi::Item::List
&items
);
90 * returns the todo from an akonadi item, or a null pointer if the item has no such payload
92 CALENDARSUPPORT_EXPORT
KCalCore::Todo::Ptr
todo(const Akonadi::Item
&item
);
95 * returns the todo from an incidence, or a null pointer if the item has no such payload
97 CALENDARSUPPORT_EXPORT
KCalCore::Todo::Ptr
todo(const KCalCore::Incidence::Ptr
&incidence
);
100 * returns the journal from an akonadi item, or a null pointer if the item has no such payload
102 CALENDARSUPPORT_EXPORT
KCalCore::Journal::Ptr
journal(const Akonadi::Item
&item
);
105 * returns the journal from an incidence, or a null pointer if the item has no such payload
107 CALENDARSUPPORT_EXPORT
KCalCore::Journal::Ptr
journal(const KCalCore::Incidence::Ptr
&incidence
);
110 * returns whether an Akonadi item contains an incidence
112 CALENDARSUPPORT_EXPORT
bool hasIncidence(const Akonadi::Item
&item
);
115 * returns whether an Akonadi item contains an event
117 CALENDARSUPPORT_EXPORT
bool hasEvent(const Akonadi::Item
&item
);
120 * returns whether an incidence contains an event
122 CALENDARSUPPORT_EXPORT
bool hasEvent(const KCalCore::Incidence::Ptr
&incidence
);
125 * returns whether an Akonadi item contains a todo
127 CALENDARSUPPORT_EXPORT
bool hasTodo(const Akonadi::Item
&item
);
130 * returns whether an incidence contains a todo
132 CALENDARSUPPORT_EXPORT
bool hasTodo(const KCalCore::Incidence::Ptr
&incidence
);
135 * returns whether an Akonadi item contains a journal
137 CALENDARSUPPORT_EXPORT
bool hasJournal(const Akonadi::Item
&item
);
140 * returns whether an incidence contains a journal
142 CALENDARSUPPORT_EXPORT
bool hasJournal(const KCalCore::Incidence::Ptr
&incidence
);
145 * returns whether this item can be deleted
147 CALENDARSUPPORT_EXPORT
bool hasDeleteRights(const Akonadi::Item
&item
);
150 * returns whether this item can be changed
152 CALENDARSUPPORT_EXPORT
bool hasChangeRights(const Akonadi::Item
&item
);
155 * returns @p true if the URL represents an Akonadi item and has one of the given mimetypes.
157 CALENDARSUPPORT_EXPORT
bool isValidIncidenceItemUrl(const QUrl
&url
,
158 const QStringList
&supportedMimeTypes
);
160 CALENDARSUPPORT_EXPORT
bool isValidIncidenceItemUrl(const QUrl
&url
);
163 * returns @p true if the mime data object contains any of the following:
165 * - an Akonadi item with a supported KCal mimetype
169 CALENDARSUPPORT_EXPORT
bool canDecode(const QMimeData
*mimeData
);
171 CALENDARSUPPORT_EXPORT QList
<QUrl
> incidenceItemUrls(const QMimeData
*mimeData
);
173 CALENDARSUPPORT_EXPORT QList
<QUrl
> todoItemUrls(const QMimeData
*mimeData
);
175 CALENDARSUPPORT_EXPORT
bool mimeDataHasIncidence(const QMimeData
*mimeData
);
176 CALENDARSUPPORT_EXPORT
bool mimeDataHasTodo(const QMimeData
*mimeData
);
178 CALENDARSUPPORT_EXPORT
KCalCore::Todo::List
todos(const QMimeData
*mimeData
,
179 const KDateTime::Spec
&timeSpec
);
181 CALENDARSUPPORT_EXPORT
KCalCore::Incidence::List
incidences(const QMimeData
*mimeData
,
182 const KDateTime::Spec
&timeSpec
);
185 * returns @p true if the URL represents an Akonadi item and has one of the given mimetypes.
187 CALENDARSUPPORT_EXPORT
bool isValidTodoItemUrl(const QUrl
&url
);
190 * creates mime data object for dragging an akonadi item containing an incidence
192 CALENDARSUPPORT_EXPORT QMimeData
*createMimeData(const Akonadi::Item
&item
,
193 const KDateTime::Spec
&timeSpec
);
196 * creates mime data object for dragging akonadi items containing an incidence
198 CALENDARSUPPORT_EXPORT QMimeData
*createMimeData(const Akonadi::Item::List
&items
,
199 const KDateTime::Spec
&timeSpec
);
201 #ifndef QT_NO_DRAGANDDROP
203 * creates a drag object for dragging an akonadi item containing an incidence
205 CALENDARSUPPORT_EXPORT QDrag
*createDrag(const Akonadi::Item
&item
,
206 const KDateTime::Spec
&timeSpec
, QWidget
*parent
);
209 * creates a drag object for dragging akonadi items containing an incidence
211 CALENDARSUPPORT_EXPORT QDrag
*createDrag(const Akonadi::Item::List
&items
,
212 const KDateTime::Spec
&timeSpec
, QWidget
*parent
);
215 Applies a filter to a list of items containing incidences.
216 Items not containing incidences or not matching the filter are removed.
217 Helper method anologous to KCalCore::CalFilter::apply()
218 @see KCalCore::CalFilter::apply()
219 @param items the list of items to filter
220 @param filter the filter to apply to the list of items
221 @return the filtered list of items
223 CALENDARSUPPORT_EXPORT
Akonadi::Item::List
applyCalFilter(const Akonadi::Item::List
&items
,
224 const KCalCore::CalFilter
*filter
);
227 Shows a modal dialog that allows to select a collection.
229 @param will contain the dialogCode, QDialog::Accepted if the user pressed Ok,
230 QDialog::Rejected otherwise
231 @param parent The optional parent of the modal dialog.
232 @return The select collection or an invalid collection if
233 there was no collection selected.
235 CALENDARSUPPORT_EXPORT
Akonadi::Collection
selectCollection(
236 QWidget
*parent
, int &dialogCode
,
237 const QStringList
&mimeTypes
,
238 const Akonadi::Collection
&defaultCollection
= Akonadi::Collection());
240 CALENDARSUPPORT_EXPORT
Akonadi::Item
itemFromIndex(const QModelIndex
&index
);
242 CALENDARSUPPORT_EXPORT
Akonadi::Item::List
itemsFromModel(
243 const QAbstractItemModel
*model
,
244 const QModelIndex
&parentIndex
= QModelIndex(),
248 CALENDARSUPPORT_EXPORT
Akonadi::Collection::List
collectionsFromModel(
249 const QAbstractItemModel
*model
,
250 const QModelIndex
&parentIndex
= QModelIndex(),
254 CALENDARSUPPORT_EXPORT
Akonadi::Collection
collectionFromIndex(const QModelIndex
&index
);
256 CALENDARSUPPORT_EXPORT
Akonadi::Collection::Id
collectionIdFromIndex(const QModelIndex
&index
);
258 CALENDARSUPPORT_EXPORT
Akonadi::Collection::List
collectionsFromIndexes(
259 const QModelIndexList
&indexes
);
261 CALENDARSUPPORT_EXPORT QString
displayName(Akonadi::ETMCalendar
*calendar
,
262 const Akonadi::Collection
&coll
);
264 CALENDARSUPPORT_EXPORT QString
subMimeTypeForIncidence(
265 const KCalCore::Incidence::Ptr
&incidence
);
268 * Returns a list containing work days between @p start and @end.
270 CALENDARSUPPORT_EXPORT QList
<QDate
> workDays(const QDate
&start
, const QDate
&end
);
273 * Returns a list of holidays that occur at @param date.
275 CALENDARSUPPORT_EXPORT QStringList
holiday(const QDate
&date
);
277 CALENDARSUPPORT_EXPORT
void saveAttachments(const Akonadi::Item
&item
,
278 QWidget
*widget
= Q_NULLPTR
);
280 CALENDARSUPPORT_EXPORT QStringList
categories(const KCalCore::Incidence::List
&incidences
);
282 CALENDARSUPPORT_EXPORT
bool mergeCalendar(const QString
&srcFilename
, const KCalCore::Calendar::Ptr
&destCalendar
);