KFileMetaData

usermetadata.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "usermetadata.h"
8#include "xattr_p.h"
9
10
11using namespace KFileMetaData;
12
13class KFileMetaData::UserMetaDataPrivate
14{
15public:
16 QString filePath;
17};
18
19UserMetaData::UserMetaData(const QString& filePath)
20 : d(new UserMetaDataPrivate)
21{
22 d->filePath = filePath;
23}
24
25UserMetaData::UserMetaData(const UserMetaData& rhs)
26 : d(new UserMetaDataPrivate(*rhs.d))
27{
28}
29
30UserMetaData::~UserMetaData() = default;
31
32const UserMetaData& UserMetaData::operator=(const UserMetaData& rhs)
33{
34 d->filePath = rhs.d->filePath;
35 return *this;
36}
37
38QString UserMetaData::filePath() const
39{
40 return d->filePath;
41}
42
43UserMetaData::Error UserMetaData::setTags(const QStringList& tags)
44{
45 if (!tags.isEmpty()) {
46 k_setxattr(d->filePath, QStringLiteral("xdg.tags"), tags.join(QLatin1Char(',')));
47 } else {
48 k_removexattr(d->filePath, QStringLiteral("xdg.tags"));
49 }
50
51 return NoError;
52}
53
54QStringList UserMetaData::tags() const
55{
56 QString value;
57
58 k_getxattr(d->filePath, QStringLiteral("xdg.tags"), &value);
59 return value.split(QLatin1Char(','), Qt::SkipEmptyParts);
60}
61
62int UserMetaData::rating() const
63{
64 QString value;
65
66 k_getxattr(d->filePath, QStringLiteral("baloo.rating"), &value);
67 return value.toInt();
68}
69
70UserMetaData::Error UserMetaData::setRating(int rating)
71{
72 if (rating) {
73 k_setxattr(d->filePath, QStringLiteral("baloo.rating"), QString::number(rating));
74 } else {
75 k_removexattr(d->filePath, QStringLiteral("baloo.rating"));
76 }
77
78 return NoError;
79}
80
81QString UserMetaData::userComment() const
82{
83 QString value;
84 k_getxattr(d->filePath, QStringLiteral("xdg.comment"), &value);
85
86 return value;
87}
88
89UserMetaData::Error UserMetaData::setUserComment(const QString& userComment)
90{
91 if (!userComment.isEmpty()) {
92 k_setxattr(d->filePath, QStringLiteral("xdg.comment"), userComment);
93 } else {
94 k_removexattr(d->filePath, QStringLiteral("xdg.comment"));
95 }
96
97 return NoError;
98}
99
100QUrl UserMetaData::originUrl() const
101{
102 QString value;
103 k_getxattr(d->filePath, QStringLiteral("xdg.origin.url"), &value);
104
105 return QUrl(value);
106}
107
108UserMetaData::Error UserMetaData::setOriginUrl(const QUrl &originUrl)
109{
110 if (!originUrl.isEmpty()) {
111 k_setxattr(d->filePath, QStringLiteral("xdg.origin.url"), originUrl.toString());
112 } else {
113 k_removexattr(d->filePath, QStringLiteral("xdg.origin.url"));
114 }
115
116 return NoError;
117}
118
119QString UserMetaData::originEmailSubject() const
120{
121 QString value;
122 k_getxattr(d->filePath, QStringLiteral("xdg.origin.email.subject"), &value);
123 return value;
124}
125
126UserMetaData::Error UserMetaData::setOriginEmailSubject(const QString &originEmailSubject)
127{
128 if (!originEmailSubject.isEmpty()) {
129 k_setxattr(d->filePath, QStringLiteral("xdg.origin.email.subject"), originEmailSubject);
130 } else {
131 k_removexattr(d->filePath, QStringLiteral("xdg.origin.email.subject"));
132 }
133
134 return NoError;
135}
136
137QString UserMetaData::originEmailSender() const
138{
139 QString value;
140 k_getxattr(d->filePath, QStringLiteral("xdg.origin.email.sender"), &value);
141 return value;
142}
143
144UserMetaData::Error UserMetaData::setOriginEmailSender(const QString &originEmailSender)
145{
146 if (!originEmailSender.isEmpty()) {
147 k_setxattr(d->filePath, QStringLiteral("xdg.origin.email.sender"), originEmailSender);
148 } else {
149 k_removexattr(d->filePath, QStringLiteral("xdg.origin.email.sender"));
150 }
151
152 return NoError;
153}
154
155QString UserMetaData::originEmailMessageId() const
156{
157 QString value;
158 k_getxattr(d->filePath, QStringLiteral("xdg.origin.email.message-id"), &value);
159 return value;
160}
161
162UserMetaData::Error UserMetaData::setOriginEmailMessageId(const QString &originEmailMessageId)
163{
164 if (!originEmailMessageId.isEmpty()) {
165 k_setxattr(d->filePath, QStringLiteral("xdg.origin.email.message-id"), originEmailMessageId);
166 } else {
167 k_removexattr(d->filePath, QStringLiteral("xdg.origin.email.message-id"));
168 }
169
170 return NoError;
171}
172
173UserMetaData::Error UserMetaData::setAttribute(const QString& key, const QString& value)
174{
175 if (!value.isEmpty()) {
176 k_setxattr(d->filePath, key, value);
177 } else {
178 k_removexattr(d->filePath, key);
179 }
180
181 return NoError;
182}
183
184bool UserMetaData::hasAttribute(const QString& key)
185{
186 return k_hasAttribute(d->filePath, key);
187}
188
189QString UserMetaData::attribute(const QString& key)
190{
191 QString value;
192 k_getxattr(d->filePath, key, &value);
193
194 return value;
195}
196
197bool UserMetaData::isSupported() const
198{
199 return k_isSupported(d->filePath);
200}
201
202UserMetaData::Attributes UserMetaData::queryAttributes(UserMetaData::Attributes attributes) const
203{
204 return k_queryAttributes(d->filePath, attributes);
205}
bool isEmpty() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString number(int n, int base)
int toInt(bool *ok, int base) const const
QString join(const QString &separator) const const
SkipEmptyParts
bool isEmpty() const const
QString toString(QUrl::FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:44:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.