| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KFILEMETADATA_USERMETADATA_H |
| 8 | #define KFILEMETADATA_USERMETADATA_H |
| 9 | |
| 10 | #include "kfilemetadata_export.h" |
| 11 | #include <QStringList> |
| 12 | #include <QUrl> |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | namespace KFileMetaData { |
| 17 | |
| 18 | class UserMetaDataPrivate; |
| 19 | |
| 20 | /*! |
| 21 | * \class KFileMetaData::UserMetaData |
| 22 | * \inheaderfile KFileMetaData/UserMetaData |
| 23 | * \inmodule KFileMetaData |
| 24 | * |
| 25 | * \brief The UserMetaData class can be used to read and set user meta data of files. |
| 26 | */ |
| 27 | class KFILEMETADATA_EXPORT UserMetaData |
| 28 | { |
| 29 | public: |
| 30 | /*! |
| 31 | * |
| 32 | */ |
| 33 | UserMetaData(const QString &filePath); |
| 34 | UserMetaData(const UserMetaData &rhs); |
| 35 | virtual ~UserMetaData(); |
| 36 | |
| 37 | /*! |
| 38 | * \value NoError i.e. Success |
| 39 | * \value[since 6.2] UnknownError An error that's not currently handled specifically |
| 40 | * \value[since 6.2] NotSupported Underlying filesystem does not provide extended attributes features |
| 41 | * \value[since 6.2] NoSpace There is insufficient space remaining to store the extended attribute |
| 42 | * \value[since 6.2] MissingPermission Process doesn't have write permission to the file or the file is marked append-only |
| 43 | * \value[since 6.2] ValueTooBig The value size exceeds the maximum size allowed per-value (64 kB for Linux VFS |
| 44 | * \value[since 6.2] NameToolong The attribute name is too long (255 bytes for Linux VFS) |
| 45 | * |
| 46 | */ |
| 47 | enum Error { |
| 48 | NoError = 0, |
| 49 | UnknownError, |
| 50 | NotSupported, |
| 51 | NoSpace, |
| 52 | MissingPermission, |
| 53 | ValueTooBig, |
| 54 | NameToolong, |
| 55 | }; |
| 56 | |
| 57 | /*! |
| 58 | * \value None |
| 59 | * \value Any |
| 60 | * \value Tags |
| 61 | * \value Rating |
| 62 | * \value Comment |
| 63 | * \value OriginUrl |
| 64 | * \value OriginEmailSubject |
| 65 | * \value OriginEmailSender |
| 66 | * \value OriginEmailMessageId |
| 67 | * \value Other |
| 68 | * \value All |
| 69 | */ |
| 70 | enum Attribute : uint32_t { |
| 71 | None = 0x0, |
| 72 | Any = None, |
| 73 | Tags = 0x1, |
| 74 | Rating = 0x2, |
| 75 | = 0x4, |
| 76 | OriginUrl = 0x8, |
| 77 | OriginEmailSubject = 0x10, |
| 78 | OriginEmailSender = 0x20, |
| 79 | OriginEmailMessageId = 0x40, |
| 80 | Other = 0xffffff80, |
| 81 | All = 0xffffffff, |
| 82 | }; |
| 83 | Q_DECLARE_FLAGS(Attributes, Attribute) |
| 84 | |
| 85 | const UserMetaData& operator =(const UserMetaData& rhs); |
| 86 | |
| 87 | /*! |
| 88 | * |
| 89 | */ |
| 90 | QString filePath() const; |
| 91 | |
| 92 | /*! |
| 93 | * |
| 94 | */ |
| 95 | bool isSupported() const; |
| 96 | |
| 97 | /*! |
| 98 | * |
| 99 | */ |
| 100 | Error setTags(const QStringList& tags); |
| 101 | |
| 102 | /*! |
| 103 | * |
| 104 | */ |
| 105 | QStringList tags() const; |
| 106 | |
| 107 | /*! |
| 108 | * |
| 109 | */ |
| 110 | int rating() const; |
| 111 | |
| 112 | /*! |
| 113 | * |
| 114 | */ |
| 115 | Error setRating(int rating); |
| 116 | |
| 117 | /*! |
| 118 | * |
| 119 | */ |
| 120 | QString () const; |
| 121 | |
| 122 | /*! |
| 123 | * |
| 124 | */ |
| 125 | Error (const QString& ); |
| 126 | |
| 127 | /*! |
| 128 | * |
| 129 | */ |
| 130 | QUrl originUrl() const; |
| 131 | |
| 132 | /*! |
| 133 | * |
| 134 | */ |
| 135 | Error setOriginUrl(const QUrl &originUrl); |
| 136 | |
| 137 | /*! |
| 138 | * |
| 139 | */ |
| 140 | QString originEmailSubject() const; |
| 141 | |
| 142 | /*! |
| 143 | * |
| 144 | */ |
| 145 | Error setOriginEmailSubject(const QString &originEmailSubject); |
| 146 | |
| 147 | /*! |
| 148 | * |
| 149 | */ |
| 150 | QString originEmailSender() const; |
| 151 | |
| 152 | /*! |
| 153 | * |
| 154 | */ |
| 155 | Error setOriginEmailSender(const QString &originEmailSender); |
| 156 | |
| 157 | /*! |
| 158 | * |
| 159 | */ |
| 160 | QString originEmailMessageId() const; |
| 161 | |
| 162 | /*! |
| 163 | * |
| 164 | */ |
| 165 | Error setOriginEmailMessageId(const QString &originEmailMessageId); |
| 166 | |
| 167 | #if KFILEMETADATA_ENABLE_DEPRECATED_SINCE(6, 2) |
| 168 | /*! |
| 169 | * \deprecated[6.2] |
| 170 | */ |
| 171 | QString attribute(const QString &name); |
| 172 | #endif |
| 173 | /*! |
| 174 | * \since 6.2 |
| 175 | */ |
| 176 | QString attribute(const QString &name) const; |
| 177 | |
| 178 | /*! |
| 179 | * |
| 180 | */ |
| 181 | Error setAttribute(const QString &name, const QString &value); |
| 182 | |
| 183 | #if KFILEMETADATA_ENABLE_DEPRECATED_SINCE(6, 2) |
| 184 | /*! |
| 185 | * \deprecated[6.2] |
| 186 | */ |
| 187 | bool hasAttribute(const QString &name); |
| 188 | #endif |
| 189 | /*! |
| 190 | * \since 6.2 |
| 191 | */ |
| 192 | bool hasAttribute(const QString &name) const; |
| 193 | |
| 194 | /*! |
| 195 | * Query list of available attributes |
| 196 | * |
| 197 | * Checks for the availability of the given \a attributes. May return |
| 198 | * a superset of the input value when the file has attributes set |
| 199 | * beyond the requested ones. |
| 200 | * |
| 201 | * If the input attribute mask is Attribute::Any, either Attribute::None |
| 202 | * (the file has no user attributes) or Attribute::All (the file has at |
| 203 | * least one attribute set) is returned. |
| 204 | * |
| 205 | * \since 5.60 |
| 206 | */ |
| 207 | Attributes queryAttributes(Attributes attributes = Attribute::Any) const; |
| 208 | |
| 209 | private: |
| 210 | const std::unique_ptr<UserMetaDataPrivate> d; |
| 211 | }; |
| 212 | |
| 213 | Q_DECLARE_OPERATORS_FOR_FLAGS(UserMetaData::Attributes) |
| 214 | } |
| 215 | |
| 216 | #endif // KFILEMETADATA_USERMETADATA_H |
| 217 | |