File indexing completed on 2024-05-05 16:09:03

0001 /*
0002     SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef KFILEMETADATA_USERMETADATA_H
0008 #define KFILEMETADATA_USERMETADATA_H
0009 
0010 #include "kfilemetadata_export.h"
0011 #include <QStringList>
0012 #include <QUrl>
0013 
0014 #include <memory>
0015 
0016 namespace KFileMetaData {
0017 
0018 class UserMetaDataPrivate;
0019 /**
0020  * \class UserMetaData usermetadata.h <KFileMetaData/UserMetaData>
0021  */
0022 class KFILEMETADATA_EXPORT UserMetaData {
0023 public:
0024     UserMetaData(const QString &filePath);
0025     UserMetaData(const UserMetaData &rhs);
0026     virtual ~UserMetaData();
0027 
0028     enum Error {
0029         NoError = 0
0030     };
0031 
0032     /**
0033      * @see Attributes
0034      */
0035     enum Attribute : uint32_t {
0036         None                 = 0x0,
0037         Any                  = None,
0038         Tags                 = 0x1,
0039         Rating               = 0x2,
0040         Comment              = 0x4,
0041         OriginUrl            = 0x8,
0042         OriginEmailSubject   = 0x10,
0043         OriginEmailSender    = 0x20,
0044         OriginEmailMessageId = 0x40,
0045         Other                = 0xffffff80,
0046         All                  = 0xffffffff,
0047     };
0048     /**
0049      * Stores a combination of #Attribute values.
0050      */
0051     Q_DECLARE_FLAGS(Attributes, Attribute)
0052 
0053     const UserMetaData& operator =(const UserMetaData& rhs);
0054 
0055     QString filePath() const;
0056     bool isSupported() const;
0057 
0058     Error setTags(const QStringList& tags);
0059     QStringList tags() const;
0060 
0061     int rating() const;
0062     Error setRating(int rating);
0063 
0064     QString userComment() const;
0065     Error setUserComment(const QString& userComment);
0066 
0067     QUrl originUrl() const;
0068     Error setOriginUrl(const QUrl &originUrl);
0069 
0070     QString originEmailSubject() const;
0071     Error setOriginEmailSubject(const QString &originEmailSubject);
0072 
0073     QString originEmailSender() const;
0074     Error setOriginEmailSender(const QString &originEmailSender);
0075 
0076     QString originEmailMessageId() const;
0077     Error setOriginEmailMessageId(const QString &originEmailMessageId);
0078 
0079     QString attribute(const QString& name);
0080     Error setAttribute(const QString& name, const QString& value);
0081     bool hasAttribute(const QString& name);
0082 
0083     /**
0084       * Query list of available attributes
0085       *
0086       * Checks for the availability of the given \p attributes. May return
0087       * a superset of the input value when the file has attributes set
0088       * beyond the requested ones.
0089       *
0090       * If the input attribute mask is Attribute::Any, either Attribute::None
0091       * (the file has no user attributes) or Attribute::All (the file has at
0092       * least one attribute set) is returned.
0093       *
0094       * \since 5.60
0095       */
0096     Attributes queryAttributes(Attributes attributes = Attribute::Any) const;
0097 
0098 private:
0099     const std::unique_ptr<UserMetaDataPrivate> d;
0100 };
0101 
0102 Q_DECLARE_OPERATORS_FOR_FLAGS(UserMetaData::Attributes)
0103 }
0104 
0105 #endif // KFILEMETADATA_USERMETADATA_H