New Appointment -> New Task
[kdepim.git] / calendarsupport / utils.h
blob50228d07fd4611bd2f55ef0058a258721d556d3e
1 /*
2 Copyright (C) 2009 KDAB (author: Frank Osterfeld <osterfeld@kde.org>)
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 As a special exception, permission is given to link this program
19 with any edition of Qt, and distribute the resulting executable,
20 without including the source code for Qt in the source distribution.
22 #ifndef CALENDARSUPPORT_UTILS_H
23 #define CALENDARSUPPORT_UTILS_H
25 #include "calendarsupport_export.h"
27 #include <Akonadi/Collection>
28 #include <Akonadi/Item>
30 #include <KCalCore/Event>
31 #include <KCalCore/Incidence>
32 #include <KCalCore/Journal>
33 #include <KCalCore/Todo>
35 #include <KDateTime>
37 #include <QModelIndex>
39 namespace KCalCore {
40 class CalFilter;
43 class QAbstractItemModel;
44 class QDrag;
45 class QMimeData;
47 typedef QList<QModelIndex> QModelIndexList;
49 namespace CalendarSupport
51 /**
52 * returns the incidence from an akonadi item, or a null pointer if the item has no such payload
54 CALENDARSUPPORT_EXPORT KCalCore::Incidence::Ptr incidence( const Akonadi::Item &item );
56 /**
57 * returns the event from an akonadi item, or a null pointer if the item has no such payload
59 CALENDARSUPPORT_EXPORT KCalCore::Event::Ptr event( const Akonadi::Item &item );
61 /**
62 * returns event pointers from an akonadi item, or a null pointer if the item has no such payload
64 CALENDARSUPPORT_EXPORT KCalCore::Event::List eventsFromItems(
65 const Akonadi::Item::List &items );
67 /**
68 * returns the todo from an akonadi item, or a null pointer if the item has no such payload
70 CALENDARSUPPORT_EXPORT KCalCore::Todo::Ptr todo( const Akonadi::Item &item );
72 /**
73 * returns the journal from an akonadi item, or a null pointer if the item has no such payload
75 CALENDARSUPPORT_EXPORT KCalCore::Journal::Ptr journal( const Akonadi::Item &item );
77 /**
78 * returns whether an Akonadi item contains an incidence
80 CALENDARSUPPORT_EXPORT bool hasIncidence( const Akonadi::Item &item );
82 /**
83 * returns whether an Akonadi item contains an event
85 CALENDARSUPPORT_EXPORT bool hasEvent( const Akonadi::Item &item );
87 /**
88 * returns whether an Akonadi item contains a todo
90 CALENDARSUPPORT_EXPORT bool hasTodo( const Akonadi::Item &item );
92 /**
93 * returns whether an Akonadi item contains a journal
95 CALENDARSUPPORT_EXPORT bool hasJournal( const Akonadi::Item &item );
97 /**
98 * returns whether this item can be deleted
100 CALENDARSUPPORT_EXPORT bool hasDeleteRights( const Akonadi::Item &item );
103 * returns whether this item can be changed
105 CALENDARSUPPORT_EXPORT bool hasChangeRights( const Akonadi::Item &item );
108 * returns @p true if the URL represents an Akonadi item and has one of the given mimetypes.
110 CALENDARSUPPORT_EXPORT bool isValidIncidenceItemUrl( const KUrl &url,
111 const QStringList &supportedMimeTypes );
113 CALENDARSUPPORT_EXPORT bool isValidIncidenceItemUrl( const KUrl &url );
116 * returns @p true if the mime data object contains any of the following:
118 * * An akonadi item with a supported KCal mimetype
119 * * an iCalendar
120 * * a VCard
122 CALENDARSUPPORT_EXPORT bool canDecode( const QMimeData *mimeData );
124 CALENDARSUPPORT_EXPORT QList<KUrl> incidenceItemUrls( const QMimeData *mimeData );
126 CALENDARSUPPORT_EXPORT QList<KUrl> todoItemUrls( const QMimeData *mimeData );
128 CALENDARSUPPORT_EXPORT bool mimeDataHasTodo( const QMimeData *mimeData );
130 CALENDARSUPPORT_EXPORT KCalCore::Todo::List todos( const QMimeData *mimeData,
131 const KDateTime::Spec &timeSpec );
134 * returns @p true if the URL represents an Akonadi item and has one of the given mimetypes.
136 CALENDARSUPPORT_EXPORT bool isValidTodoItemUrl( const KUrl &url );
139 * creates mime data object for dragging an akonadi item containing an incidence
141 CALENDARSUPPORT_EXPORT QMimeData *createMimeData( const Akonadi::Item &item,
142 const KDateTime::Spec &timeSpec );
145 * creates mime data object for dragging akonadi items containing an incidence
147 CALENDARSUPPORT_EXPORT QMimeData *createMimeData( const Akonadi::Item::List &items,
148 const KDateTime::Spec &timeSpec );
150 #ifndef QT_NO_DRAGANDDROP
152 * creates a drag object for dragging an akonadi item containing an incidence
154 CALENDARSUPPORT_EXPORT QDrag *createDrag( const Akonadi::Item &item,
155 const KDateTime::Spec &timeSpec, QWidget *parent );
158 * creates a drag object for dragging akonadi items containing an incidence
160 CALENDARSUPPORT_EXPORT QDrag *createDrag( const Akonadi::Item::List &items,
161 const KDateTime::Spec &timeSpec, QWidget *parent );
162 #endif
164 Applies a filter to a list of items containing incidences.
165 Items not containing incidences or not matching the filter are removed.
166 Helper method anologous to KCalCore::CalFilter::apply()
167 @see KCalCore::CalFilter::apply()
168 @param items the list of items to filter
169 @param filter the filter to apply to the list of items
170 @return the filtered list of items
172 CALENDARSUPPORT_EXPORT Akonadi::Item::List applyCalFilter( const Akonadi::Item::List &items,
173 const KCalCore::CalFilter *filter );
176 Shows a modal dialog that allows to select a collection.
178 @param will contain the dialogCode, QDialog::Accepted if the user pressed Ok,
179 QDialog::Rejected otherwise
180 @param parent The optional parent of the modal dialog.
181 @return The select collection or an invalid collection if
182 there was no collection selected.
184 CALENDARSUPPORT_EXPORT Akonadi::Collection selectCollection(
185 QWidget *parent, int dialogCode,
186 const QStringList &mimeTypes,
187 const Akonadi::Collection &defaultCollection = Akonadi::Collection() );
189 CALENDARSUPPORT_EXPORT Akonadi::Item itemFromIndex( const QModelIndex &index );
191 CALENDARSUPPORT_EXPORT Akonadi::Item::List itemsFromModel(
192 const QAbstractItemModel *model,
193 const QModelIndex &parentIndex = QModelIndex(),
194 int start = 0,
195 int end = -1 );
197 CALENDARSUPPORT_EXPORT Akonadi::Collection::List collectionsFromModel(
198 const QAbstractItemModel *model,
199 const QModelIndex &parentIndex = QModelIndex(),
200 int start = 0,
201 int end = -1 );
203 CALENDARSUPPORT_EXPORT Akonadi::Collection collectionFromIndex( const QModelIndex &index );
205 CALENDARSUPPORT_EXPORT Akonadi::Collection::Id collectionIdFromIndex( const QModelIndex &index );
207 CALENDARSUPPORT_EXPORT Akonadi::Collection::List collectionsFromIndexes(
208 const QModelIndexList &indexes );
210 CALENDARSUPPORT_EXPORT QString displayName( const Akonadi::Collection &coll );
212 CALENDARSUPPORT_EXPORT QString subMimeTypeForIncidence(
213 const KCalCore::Incidence::Ptr &incidence );
216 Returns a list containing work days between @p start and @end.
218 CALENDARSUPPORT_EXPORT QList<QDate> workDays( const QDate &start, const QDate &end );
221 Returns a list of holidays that occur at @param date.
223 CALENDARSUPPORT_EXPORT QStringList holiday( const QDate &date );
226 #endif