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

0001 /*
0002     ktnefparser.h
0003 
0004     SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be>
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 KTNEFParser class.
0014  *
0015  * @author Michael Goffioul
0016  */
0017 
0018 #pragma once
0019 
0020 #include "ktnef_export.h"
0021 #include <QIODevice>
0022 #include <QString>
0023 #include <memory>
0024 
0025 namespace KTnef
0026 {
0027 class KTNEFMessage;
0028 }
0029 
0030 namespace KTnef
0031 {
0032 /**
0033  * @brief
0034  * Provides an @acronym TNEF parser.
0035  */
0036 class KTNEF_EXPORT KTNEFParser
0037 {
0038 public:
0039     /**
0040       Constructs a @acronym TNEF parser object.
0041     */
0042     KTNEFParser();
0043 
0044     /**
0045       Destroys the @acronym TNEF parser object.
0046      */
0047     ~KTNEFParser();
0048 
0049     /**
0050       Opens the @p filename for parsing.
0051 
0052       @param filename is the name of the file to open.
0053       @return true if the open succeeded; otherwise false.
0054     */
0055     [[nodiscard]] bool openFile(const QString &filename) const;
0056 
0057     /**
0058       Opens the #QIODevice @p device for parsing.
0059 
0060       @param device is the #QIODevice to open.
0061       @return true if the open succeeded; otherwise false.
0062     */
0063     [[nodiscard]] bool openDevice(QIODevice *device);
0064 
0065     /**
0066       Extracts a @acronym TNEF attachment having filename @p filename
0067       into the default directory.
0068 
0069       @param filename is the name of the file to extract the attachment into.
0070       @return true if the extraction succeeds; otherwise false.
0071     */
0072     [[nodiscard]] bool extractFile(const QString &filename) const;
0073 
0074     /**
0075       Extracts a @acronym TNEF attachment having filename @p filename
0076       into the directory @p dirname.
0077 
0078       @param filename is the name of the file to extract the attachment into.
0079       @param dirname is the name of the directory where the @p filename
0080       should be written.
0081 
0082       @return true if the extraction succeeds; otherwise false.
0083     */
0084     [[nodiscard]] bool extractFileTo(const QString &filename, const QString &dirname) const;
0085 
0086     /**
0087       Extracts all @acronym TNEF attachments into the default directory.
0088 
0089       @return true if the extraction succeeds; otherwise false.
0090     */
0091     [[nodiscard]] bool extractAll();
0092 
0093     /**
0094       Sets the default extraction directory to @p dirname.
0095 
0096       @param dirname is the name of the default extraction directory.
0097     */
0098     void setDefaultExtractDir(const QString &dirname);
0099 
0100     /**
0101       Returns the KTNEFMessage used in the parsing process.
0102 
0103       @return a pointer to a KTNEFMessage object.
0104     */
0105     KTNEFMessage *message() const;
0106 
0107 private:
0108     //@cond PRIVATE
0109     class ParserPrivate;
0110     std::unique_ptr<ParserPrivate> const d;
0111     //@endcond
0112 
0113     Q_DISABLE_COPY(KTNEFParser)
0114 };
0115 
0116 }