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

0001 /*
0002   This file is part of the kcalutils library.
0003 
0004   SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
0005   SPDX-FileCopyrightText: 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org>
0006   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0007   SPDX-FileCopyrightText: 2008 Thomas Thrainer <tom_t@gmx.at>
0008 
0009   SPDX-License-Identifier: LGPL-2.0-or-later
0010 */
0011 /**
0012   @file
0013   This file is part of the API for handling calendar data and
0014   defines the DndFactory class.
0015 
0016   @author Preston Brown \<pbrown@kde.org\>
0017   @author Cornelius Schumacher \<schumacher@kde.org\>
0018   @author Reinhold Kainhofer \<reinhold@kainhofer.com\>
0019 */
0020 #pragma once
0021 
0022 #include "kcalutils_export.h"
0023 
0024 #include <KCalendarCore/Calendar>
0025 #include <KCalendarCore/Event>
0026 #include <KCalendarCore/Todo>
0027 
0028 #include <QDateTime>
0029 
0030 #include <memory>
0031 
0032 class QDrag;
0033 class QDropEvent;
0034 class QMimeData;
0035 
0036 namespace KCalUtils
0037 {
0038 class DndFactoryPrivate;
0039 /**
0040   @brief
0041   vCalendar/iCalendar Drag-and-Drop object factory.
0042 
0043   This class implements functions to create Drag and Drop objects used for
0044   Drag-and-Drop and Copy-and-Paste.
0045 */
0046 class KCALUTILS_EXPORT DndFactory
0047 {
0048 public:
0049     enum PasteFlag {
0050         FlagTodosPasteAtDtStart = 1, /**< If the cloned incidence is a to-do, the date/time passed
0051                                         to DndFactory::pasteIncidence() will change dtStart if this
0052                                         flag is on, changes dtDue otherwise. */
0053         FlagPasteAtOriginalTime = 2 /**< If set, incidences will be pasted at the specified date
0054                                        but will preserve their original time */
0055     };
0056 
0057     Q_DECLARE_FLAGS(PasteFlags, PasteFlag)
0058 
0059     explicit DndFactory(const KCalendarCore::Calendar::Ptr &cal);
0060 
0061     ~DndFactory();
0062 
0063     /**
0064       Create the calendar that is contained in the drop event's data.
0065      */
0066     KCalendarCore::Calendar::Ptr createDropCalendar(QDropEvent *de);
0067 
0068     /**
0069      Create the calendar that is contained in the mime data.
0070     */
0071     static KCalendarCore::Calendar::Ptr createDropCalendar(const QMimeData *md);
0072 
0073     /**
0074       Create the mime data for the whole calendar.
0075     */
0076     QMimeData *createMimeData();
0077 
0078     /**
0079       Create a drag object for the whole calendar.
0080     */
0081     QDrag *createDrag(QObject *owner);
0082 
0083     /**
0084       Create the mime data for a single incidence.
0085     */
0086     QMimeData *createMimeData(const KCalendarCore::Incidence::Ptr &incidence);
0087 
0088     /**
0089       Create a drag object for a single incidence.
0090     */
0091     QDrag *createDrag(const KCalendarCore::Incidence::Ptr &incidence, QObject *owner);
0092 
0093     /**
0094       Create Todo object from mime data.
0095     */
0096     KCalendarCore::Todo::Ptr createDropTodo(const QMimeData *md);
0097 
0098     /**
0099       Create Todo object from drop event.
0100     */
0101     KCalendarCore::Todo::Ptr createDropTodo(QDropEvent *de);
0102 
0103     /**
0104       Create Event object from mime data.
0105     */
0106     KCalendarCore::Event::Ptr createDropEvent(const QMimeData *md);
0107 
0108     /**
0109       Create Event object from drop event.
0110     */
0111     KCalendarCore::Event::Ptr createDropEvent(QDropEvent *de);
0112 
0113     /**
0114       Cut the incidence to the clipboard.
0115     */
0116     void cutIncidence(const KCalendarCore::Incidence::Ptr &);
0117 
0118     /**
0119       Copy the incidence to clipboard/
0120     */
0121     bool copyIncidence(const KCalendarCore::Incidence::Ptr &);
0122 
0123     /**
0124       Cuts a list of @p incidences to the clipboard.
0125     */
0126     bool cutIncidences(const KCalendarCore::Incidence::List &incidences);
0127 
0128     /**
0129       Copies a list of @p incidences to the clipboard.
0130     */
0131     bool copyIncidences(const KCalendarCore::Incidence::List &incidences);
0132 
0133     /**
0134       This function clones the incidences that are in the clipboard and sets the clone's
0135       date/time to the specified @p newDateTime.
0136 
0137       @see pasteIncidence()
0138     */
0139     KCalendarCore::Incidence::List pasteIncidences(const QDateTime &newDateTime = QDateTime(), PasteFlags pasteOptions = PasteFlags());
0140 
0141     /**
0142       This function clones the incidence that's in the clipboard and sets the clone's
0143       date/time to the specified @p newDateTime.
0144 
0145       @param newDateTime The new date/time that the incidence will have. If it's an event
0146       or journal, DTSTART will be set. If it's a to-do, DTDUE is set.
0147       If you wish another behaviour, like changing DTSTART on to-dos, specify
0148       @p pasteOptions. If newDateTime is invalid the original incidence's dateTime
0149       will be used, regardless of @p pasteOptions.
0150 
0151       @param pasteOptions Control how @p newDateTime changes the incidence's dates. @see PasteFlag.
0152 
0153       @return A pointer to the cloned incidence.
0154     */
0155     KCalendarCore::Incidence::Ptr pasteIncidence(const QDateTime &newDateTime = QDateTime(), PasteFlags pasteOptions = PasteFlags());
0156 
0157 private:
0158     //@cond PRIVATE
0159     Q_DISABLE_COPY(DndFactory)
0160     std::unique_ptr<DndFactoryPrivate> const d;
0161     //@endcond
0162 };
0163 }