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

0001 /*
0002   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 /**
0008   @file
0009   This file is part of the API for handling calendar data and provides
0010   static functions for dealing with calendar incidence attachments.
0011 
0012   @author Allen Winter \<winter@kde.org\>
0013 */
0014 #pragma once
0015 
0016 #include <KCalendarCore/Attachment>
0017 #include <KCalendarCore/Incidence>
0018 #include <KCalendarCore/ScheduleMessage>
0019 
0020 #include <QObject>
0021 
0022 #include <memory>
0023 
0024 class KJob;
0025 
0026 class QWidget;
0027 
0028 namespace CalendarSupport
0029 {
0030 class AttachmentHandlerPrivate;
0031 
0032 /**
0033   @brief
0034   Provides methods to handle incidence attachments.
0035 
0036   Includes functions to view and save attachments.
0037 */
0038 class AttachmentHandler : public QObject
0039 {
0040     Q_OBJECT
0041 public:
0042     /**
0043      * Constructs an AttachmentHandler.
0044      * @param parent is the parent widget for the dialogs used by this class.
0045      */
0046     explicit AttachmentHandler(QWidget *parent);
0047     ~AttachmentHandler() override;
0048 
0049     /**
0050      * Finds the attachment in the user's calendar, by @p attachmentName and @p incidence.
0051      *
0052      * @param attachmentName is the name of the attachment
0053      * @param incidence is a pointer to a valid Incidence object containing the attachment.
0054      * @return a pointer to the Attachment object located; 0 if no such attachment could be found.
0055      */
0056     KCalendarCore::Attachment find(const QString &attachmentName, const KCalendarCore::Incidence::Ptr &incidence);
0057 
0058     /**
0059      * Finds the attachment in the user's calendar, by @p attachmentName and a scheduler message;
0060      * in other words, this function is intended to retrieve attachments from calendar invitations.
0061      *
0062      * @param attachmentName is the name of the attachment
0063      * @param message is a pointer to a valid ScheduleMessage object containing the attachment.
0064      * @return a pointer to the Attachment object located; 0 if no such attachment could be found.
0065      */
0066     KCalendarCore::Attachment find(const QString &attachmentName, const KCalendarCore::ScheduleMessage::Ptr &message);
0067 
0068     /**
0069      * Launches a viewer on the specified attachment.
0070      *
0071      * @param attachment is a pointer to a valid Attachment object.
0072      * @return true if the viewer program successfully launched; false otherwise.
0073      */
0074     bool view(const KCalendarCore::Attachment &attachment);
0075 
0076     /**
0077      * Launches a viewer on the specified attachment.
0078      *
0079      * @param attachmentName is the name of the attachment
0080      * @param incidence is a pointer to a valid Incidence object containing the attachment.
0081      * @return true if the attachment could be found and the viewer program successfully launched;
0082      * false otherwise.
0083      */
0084     bool view(const QString &attachmentName, const KCalendarCore::Incidence::Ptr &incidence);
0085 
0086     /**
0087       Launches a viewer on the specified attachment.
0088 
0089       @param attachmentName is the name of the attachment
0090       @param uid is a QString containing a UID of the incidence containing the attachment.
0091 
0092       This function is async and will return immediately. Listen to signal viewFinished()
0093       if you're interested on the success of this operation.
0094 
0095     */
0096     void view(const QString &attachmentName, const QString &uid);
0097 
0098     /**
0099       Launches a viewer on the specified attachment.
0100 
0101       @param attachmentName is the name of the attachment
0102       @param message is a pointer to a valid ScheduleMessage object containing the attachment.
0103 
0104       @return true if the attachment could be found and the viewer program successfully launched;
0105       false otherwise.
0106     */
0107     bool view(const QString &attachmentName, const KCalendarCore::ScheduleMessage::Ptr &message);
0108 
0109     /**
0110       Saves the specified attachment to a file of the user's choice.
0111 
0112       @param attachment is a pointer to a valid Attachment object.
0113 
0114       @return true if the save operation was successful; false otherwise.
0115     */
0116     bool saveAs(const KCalendarCore::Attachment &attachment);
0117 
0118     /**
0119       Saves the specified attachment to a file of the user's choice.
0120 
0121       @param attachmentName is the name of the attachment
0122       @param incidence is a pointer to a valid Incidence object containing the attachment.
0123 
0124       @return true if the attachment could be found and the save operation was successful;
0125       false otherwise.
0126     */
0127     bool saveAs(const QString &attachmentName, const KCalendarCore::Incidence::Ptr &incidence);
0128 
0129     /**
0130       Saves the specified attachment to a file of the user's choice.
0131 
0132       @param attachmentName is the name of the attachment
0133       @param uid is a QString containing a UID of the incidence containing the attachment.
0134 
0135       This function is async, it will return immediately. Listen to signal saveAsFinished()
0136       if you're interested on the success of this operation.
0137     */
0138     void saveAs(const QString &attachmentName, const QString &uid);
0139 
0140     /**
0141       Saves the specified attachment to a file of the user's choice.
0142 
0143       @param attachmentName is the name of the attachment
0144       @param message is a pointer to a valid ScheduleMessage object containing the attachment.
0145 
0146       @return true if the attachment could be found and the save operation was successful;
0147       false otherwise.
0148     */
0149     bool saveAs(const QString &attachmentName, const KCalendarCore::ScheduleMessage::Ptr &message);
0150 
0151 Q_SIGNALS:
0152     void viewFinished(const QString &uid, const QString &attachmentName, bool success);
0153     void saveAsFinished(const QString &uid, const QString &attachmentName, bool success);
0154 
0155 private:
0156     void slotFinishView(KJob *job);
0157     void slotFinishSaveAs(KJob *job);
0158     //@cond PRIVATE
0159     std::unique_ptr<AttachmentHandlerPrivate> const d;
0160     //@endcond
0161 }; // class AttachmentHandler
0162 } // namespace CalendarSupport