File indexing completed on 2024-05-12 05:13:15

0001 /*
0002   SPDX-FileCopyrightText: 2009, 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0003   SPDX-FileContributor: Frank Osterfeld <osterfeld@kde.org>
0004   SPDX-FileContributor: Andras Mantia <andras@kdab.com>
0005 
0006   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #pragma once
0010 
0011 #include "calendarsupport_export.h"
0012 
0013 #include <Akonadi/Item>
0014 
0015 #include <KCalendarCore/Calendar>
0016 #include <KCalendarCore/Event>
0017 #include <KCalendarCore/Incidence>
0018 #include <KCalendarCore/Journal>
0019 #include <KCalendarCore/Todo>
0020 
0021 #include <QModelIndex>
0022 
0023 namespace KCalendarCore
0024 {
0025 class CalFilter;
0026 }
0027 
0028 class QAbstractItemModel;
0029 class QDrag;
0030 class QMimeData;
0031 
0032 namespace CalendarSupport
0033 {
0034 class Calendar;
0035 /**
0036  * returns the event from an incidence, or a null pointer if the item has no such payload
0037  */
0038 CALENDARSUPPORT_EXPORT KCalendarCore::Event::Ptr event(const KCalendarCore::Incidence::Ptr &incidence);
0039 
0040 /**
0041  * returns incidence pointers from an akonadi item.
0042  */
0043 CALENDARSUPPORT_EXPORT KCalendarCore::Incidence::List incidencesFromItems(const Akonadi::Item::List &items);
0044 
0045 /**
0046  * returns the todo from an incidence, or a null pointer if the item has no such payload
0047  */
0048 CALENDARSUPPORT_EXPORT KCalendarCore::Todo::Ptr todo(const KCalendarCore::Incidence::Ptr &incidence);
0049 
0050 /**
0051  * returns the journal from an incidence, or a null pointer if the item has no such payload
0052  */
0053 CALENDARSUPPORT_EXPORT KCalendarCore::Journal::Ptr journal(const KCalendarCore::Incidence::Ptr &incidence);
0054 
0055 /**
0056  * returns whether an Akonadi item contains an incidence
0057  */
0058 CALENDARSUPPORT_EXPORT bool hasIncidence(const Akonadi::Item &item);
0059 
0060 /**
0061  * returns whether an Akonadi item contains an event
0062  */
0063 CALENDARSUPPORT_EXPORT bool hasEvent(const Akonadi::Item &item);
0064 
0065 /**
0066  * returns whether an incidence contains an event
0067  */
0068 CALENDARSUPPORT_EXPORT bool hasEvent(const KCalendarCore::Incidence::Ptr &incidence);
0069 
0070 /**
0071  * returns whether an Akonadi item contains a todo
0072  */
0073 CALENDARSUPPORT_EXPORT bool hasTodo(const Akonadi::Item &item);
0074 
0075 /**
0076  * returns whether an incidence contains a todo
0077  */
0078 CALENDARSUPPORT_EXPORT bool hasTodo(const KCalendarCore::Incidence::Ptr &incidence);
0079 
0080 /**
0081  * returns whether an Akonadi item contains a journal
0082  */
0083 CALENDARSUPPORT_EXPORT bool hasJournal(const Akonadi::Item &item);
0084 
0085 /**
0086  * returns whether an incidence contains a journal
0087  */
0088 CALENDARSUPPORT_EXPORT bool hasJournal(const KCalendarCore::Incidence::Ptr &incidence);
0089 
0090 /**
0091  * returns @p true if the URL represents an Akonadi item and has one of the given mimetypes.
0092  */
0093 bool isValidIncidenceItemUrl(const QUrl &url, const QStringList &supportedMimeTypes);
0094 
0095 bool isValidIncidenceItemUrl(const QUrl &url);
0096 
0097 /**
0098  * returns @p true if the mime data object contains any of the following:
0099  *
0100  * - an Akonadi item with a supported KCal mimetype
0101  * - an iCalendar
0102  * - a VCard
0103  */
0104 CALENDARSUPPORT_EXPORT bool canDecode(const QMimeData *mimeData);
0105 
0106 CALENDARSUPPORT_EXPORT QList<QUrl> incidenceItemUrls(const QMimeData *mimeData);
0107 
0108 CALENDARSUPPORT_EXPORT QList<QUrl> todoItemUrls(const QMimeData *mimeData);
0109 
0110 CALENDARSUPPORT_EXPORT bool mimeDataHasIncidence(const QMimeData *mimeData);
0111 
0112 CALENDARSUPPORT_EXPORT KCalendarCore::Todo::List todos(const QMimeData *mimeData);
0113 
0114 CALENDARSUPPORT_EXPORT KCalendarCore::Incidence::List incidences(const QMimeData *mimeData);
0115 
0116 #ifndef QT_NO_DRAGANDDROP
0117 /**
0118  * creates a drag object for dragging an akonadi item containing an incidence
0119  */
0120 CALENDARSUPPORT_EXPORT QDrag *createDrag(const Akonadi::Item &item, QObject *parent);
0121 
0122 /**
0123  * creates a drag object for dragging akonadi items containing an incidence
0124  */
0125 CALENDARSUPPORT_EXPORT QDrag *createDrag(const Akonadi::Item::List &items, QObject *parent);
0126 #endif
0127 /**
0128   Applies a filter to a list of items containing incidences.
0129   Items not containing incidences or not matching the filter are removed.
0130   Helper method anologous to KCalendarCore::CalFilter::apply()
0131   @see KCalendarCore::CalFilter::apply()
0132   @param items the list of items to filter
0133   @param filter the filter to apply to the list of items
0134   @return the filtered list of items
0135 */
0136 CALENDARSUPPORT_EXPORT Akonadi::Item::List applyCalFilter(const Akonadi::Item::List &items, const KCalendarCore::CalFilter *filter);
0137 
0138 /**
0139   Shows a modal dialog that allows to select a collection.
0140 
0141   @param will contain the dialogCode, QDialog::Accepted if the user pressed Ok,
0142   QDialog::Rejected otherwise
0143   @param parent The optional parent of the modal dialog.
0144   @return The select collection or an invalid collection if
0145   there was no collection selected.
0146 */
0147 CALENDARSUPPORT_EXPORT Akonadi::Collection
0148 selectCollection(QWidget *parent, int &dialogCode, const QStringList &mimeTypes, const Akonadi::Collection &defaultCollection = Akonadi::Collection());
0149 
0150 CALENDARSUPPORT_EXPORT Akonadi::Item itemFromIndex(const QModelIndex &index);
0151 
0152 CALENDARSUPPORT_EXPORT Akonadi::Item::List
0153 itemsFromModel(const QAbstractItemModel *model, const QModelIndex &parentIndex = QModelIndex(), int start = 0, int end = -1);
0154 
0155 CALENDARSUPPORT_EXPORT Akonadi::Collection::List
0156 collectionsFromModel(const QAbstractItemModel *model, const QModelIndex &parentIndex = QModelIndex(), int start = 0, int end = -1);
0157 
0158 CALENDARSUPPORT_EXPORT Akonadi::Collection::Id collectionIdFromIndex(const QModelIndex &index);
0159 
0160 CALENDARSUPPORT_EXPORT Akonadi::Collection::List collectionsFromIndexes(const QModelIndexList &indexes);
0161 
0162 CALENDARSUPPORT_EXPORT QString subMimeTypeForIncidence(const KCalendarCore::Incidence::Ptr &incidence);
0163 
0164 /**
0165  * Returns a list containing work days between @p start and @end.
0166  */
0167 CALENDARSUPPORT_EXPORT QList<QDate> workDays(QDate start, QDate end);
0168 
0169 /**
0170  * Creates a nicely formatted toolTip string for a calendar, containing some quick,
0171  * useful information to the user.
0172  *
0173  * @param coll is the Akonadi collection representing the calendar.
0174  * @param richText switches off richText (on by default) [CURRENTLY UNIMPLEMENTED]
0175  *
0176  * @return a QString containing the calendar info suitable for a toolTip.
0177  * @since 5.9
0178  */
0179 CALENDARSUPPORT_EXPORT QString toolTipString(const Akonadi::Collection &coll, bool richText = true);
0180 
0181 /**
0182  * Returns a list of holidays that occur at @param date.
0183  */
0184 CALENDARSUPPORT_EXPORT QStringList holiday(QDate date);
0185 
0186 CALENDARSUPPORT_EXPORT QStringList categories(const KCalendarCore::Incidence::List &incidences);
0187 
0188 CALENDARSUPPORT_EXPORT bool mergeCalendar(const QString &srcFilename, const KCalendarCore::Calendar::Ptr &destCalendar);
0189 
0190 CALENDARSUPPORT_EXPORT bool mergeCalendar(const QString &srcFilename, const KCalendarCore::Calendar::Ptr &destCalendar);
0191 
0192 CALENDARSUPPORT_EXPORT void createAlarmReminder(const KCalendarCore::Alarm::Ptr &alarm, KCalendarCore::IncidenceBase::IncidenceType type);
0193 }