File indexing completed on 2024-04-28 05:19:26

0001 /*
0002     ktnefwriter.cpp
0003 
0004     SPDX-FileCopyrightText: 2002 Bo Thorsen <bo@sonofthor.dk>
0005 
0006     This file is part of KTNEF, the KDE TNEF support library/program.
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009  */
0010 /**
0011  * @file
0012  * This file is part of the API for handling TNEF data and
0013  * defines the KTNEFWriter class.
0014  *
0015  * @author Bo Thorsen
0016  */
0017 
0018 #pragma once
0019 #include <QStringList>
0020 
0021 #include "ktnef_export.h"
0022 #include <memory>
0023 #include <qglobal.h>
0024 
0025 class QString;
0026 class QVariant;
0027 class QIODevice;
0028 class QDataStream;
0029 class QDateTime;
0030 
0031 namespace KTnef
0032 {
0033 class KTNEFWriterPrivateData;
0034 /**
0035  * @brief
0036  * Manages the writing of @acronym TNEF attachments.
0037  */
0038 class KTNEF_EXPORT KTNEFWriter
0039 {
0040 public:
0041     /**
0042      * The different types of messages.
0043      */
0044     enum MessageType {
0045         Appointment, /**< Appointment */
0046         MeetingCancelled, /**< The meeting is cancelled */
0047         MeetingRequest, /**< Meeting request */
0048         MeetingNo, /**< Negative response to a meeting request */
0049         MeetingYes, /**< Affirmative response to a meeting request */
0050         MeetingTent /**< Tentative affirmative to a meeting request */
0051     };
0052 
0053     /**
0054      * The different types of message statuses.
0055      */
0056     enum Method {
0057         PublishNew, /**< Publish new */
0058         Obsolete, /**< Replace the message */
0059         RequestNew, /**< Request a new message */
0060         RequestUpdate, /**< Request an update */
0061         Unknown /**< Unknown */
0062     };
0063 
0064     /**
0065      * The different types of meeting roles.
0066      */
0067     enum Role {
0068         ReqParticipant, /**< Required participant */
0069         OptParticipant, /**< Optional participant */
0070         NonParticipant, /**< Non-participant */
0071         Chair /**< Meeting chairperson */
0072     };
0073 
0074     /**
0075      * The different types of participant statuses.
0076      */
0077     enum PartStat {
0078         NeedsAction, /**< No information about the task/invitation received */
0079         Accepted, /**< Accepted the task/invitation */
0080         Declined, /**< Declined the task/invitation */
0081         Tentative, /**< Tentatively accepted the task/invitation */
0082         Delegated, /**< Delegated the task to another */
0083         Completed, /**< Completed the task */
0084         InProcess /**< Work on the task is in-progress */
0085     };
0086 
0087     /**
0088      * The different priorities.
0089      */
0090     enum Priority {
0091         High = 2, /**< High priority task */
0092         Normal = 3, /**< Normal priority task */
0093         Low = 1 /**< Low priority task */
0094     };
0095 
0096     /**
0097      * The different alarm actions.
0098      */
0099     enum AlarmAction {
0100         Display /**< Display the alarm */
0101     };
0102 
0103     /**
0104      * Constructs a @acronym TNEF writer object.
0105      */
0106     KTNEFWriter();
0107 
0108     /**
0109      * Destroys the @acronym TNEF writer object.
0110      */
0111     ~KTNEFWriter();
0112 
0113     /**
0114      * Adds a @acronym TNEF property.
0115      *
0116      * @param tag is the @acronym TNEF tag
0117      * @param type is the property type
0118      * @param value is the property value
0119      */
0120     void addProperty(int tag, int type, const QVariant &value);
0121 
0122     /**
0123      * Writes a @acronym TNEF property to the #QDataStream specified by @p stream.
0124      *
0125      * A @acronym TNEF property has a 1 byte type (LVL_MESSAGE or LVL_ATTACHMENT),
0126      * a 4 byte type/tag, a 4 byte length, the data and finally the checksum.
0127      *
0128      * The checksum is a 16 byte int with all bytes in the data added.
0129      *
0130      * @param stream is the #QDataStream to write
0131      * @param bytes is a pointer to an int type that will contain
0132      * the number of bytes written to the @p stream
0133      * @param tag is the @acronym TNEF tag
0134      *
0135      * @return false if an invalid @acronym TNEF tag was specified by @p tag or
0136      * if there are no properties to write; else true.
0137      */
0138     [[nodiscard]] bool writeProperty(QDataStream &stream, int &bytes, int tag) const;
0139 
0140     /**
0141      * Writes the attachment to the #QIODevice specified by @p file.
0142      *
0143      * @param file is the #QIODevice to write.
0144      * @return true if the write was successful; otherwise false.
0145      */
0146     [[nodiscard]] bool writeFile(QIODevice &file) const;
0147 
0148     /**
0149      * Writes the attachment to the #QDataStream specified by @p stream.
0150      *
0151      * @param stream is the #QDataStream to write.
0152      * @return true if the write was successful; otherwise false.
0153      */
0154     [[nodiscard]] bool writeFile(QDataStream &stream) const;
0155 
0156     /**
0157      * Sets the sender's @p name and @p email address.
0158      *
0159      * @param name is the sender's name.
0160      * @param email is the sender's email address.
0161      */
0162     void setSender(const QString &name, const QString &email);
0163 
0164     /**
0165      * Sets the #MessageType to @p methodType.
0166      *
0167      * @param methodType is the #MessageType.
0168      */
0169     void setMessageType(MessageType methodType);
0170 
0171     /**
0172      * Sets the #Method to @p method.
0173      *
0174      * @param method is the #Method.
0175      */
0176     void setMethod(Method method);
0177 
0178     /**
0179      * Clears the attendees list.
0180      */
0181     void clearAttendees();
0182 
0183     /**
0184      * Adds a meeting participant (attendee).
0185      *
0186      * @param name is the name of the attendee
0187      * @param role is the #Role of the attendee
0188      * @param partstat is the status #PartStat of the attendee
0189      * @param rsvp is true if the attendee will attend the meeting; else false
0190      * @param email is the email address of the attendee
0191      */
0192     void addAttendee(const QString &name, Role role, PartStat partstat, bool rsvp, const QString &email);
0193 
0194     /**
0195      * Sets the name of the organizer to @p organizer.
0196      * The organizer is any string identifier; it could be the name
0197      * of a person, or the application that sent the invitation, for example.
0198      *
0199      * @param organizer is the organizer identifier.
0200      */
0201     void setOrganizer(const QString &organizer);
0202 
0203     /**
0204      * Sets the Starting Date and Time to @p dtStart.
0205      *
0206      * @param dtStart is the starting date/time.
0207      */
0208     void setDtStart(const QDateTime &dtStart);
0209 
0210     /**
0211      * Sets the Ending Date and Time to @p dtEnd.
0212      *
0213      * @param dtEnd is the ending date/time.
0214      */
0215     void setDtEnd(const QDateTime &dtEnd);
0216 
0217     /**
0218      * Sets the Location to @p location.
0219      *
0220      * @param location is the location.
0221      */
0222     void setLocation(const QString &location);
0223 
0224     /**
0225      * Sets the @acronym UID to @p uid.
0226      *
0227      * @param uid is the @acronym UID.
0228      */
0229     void setUID(const QString &uid);
0230 
0231     /**
0232      * Sets the timestamp to @p dtStamp.
0233      *
0234      * @param dtStamp is the timestamp.
0235      */
0236     void setDtStamp(const QDateTime &dtStamp);
0237 
0238     /**
0239      * Sets the category list to @p categories.
0240      *
0241      * @param categories is the list categories.
0242      */
0243     void setCategories(const QStringList &categories);
0244 
0245     /**
0246      * Sets the description to @p description.
0247      *
0248      * @param description is the description.
0249      */
0250     void setDescription(const QString &description);
0251 
0252     /**
0253      * Sets the summary to @p summary.
0254      *
0255      * @param summary is the summary.
0256      */
0257     void setSummary(const QString &summary);
0258 
0259     /**
0260      * Sets the priority to @p priority.
0261      *
0262      * @param priority is the #Priority.
0263      */
0264     void setPriority(Priority priority);
0265 
0266     /**
0267      * Sets the alarm.
0268      *
0269      * @param description is the alarm description
0270      * @param action is the alaram #AlarmAction
0271      * @param wakeBefore is the alarm Date/Time
0272      */
0273     void setAlarm(const QString &description, AlarmAction action, const QDateTime &wakeBefore);
0274 
0275 private:
0276     //@cond PRIVATE
0277     std::unique_ptr<KTNEFWriterPrivateData> const d;
0278     //@endcond
0279 
0280     Q_DISABLE_COPY(KTNEFWriter)
0281 };
0282 
0283 }