KFileMetaData

usermetadata.cpp
1 /*
2  * Copyright (C) 2014 Vishesh Handa <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #include "usermetadata.h"
21 #include "xattr_p.h"
22 
23 
24 using namespace KFileMetaData;
25 
26 class Q_DECL_HIDDEN UserMetaData::Private
27 {
28 public:
29  QString filePath;
30 };
31 
32 UserMetaData::UserMetaData(const QString& filePath)
33  : d(new Private)
34 {
35  d->filePath = filePath;
36 }
37 
38 UserMetaData::UserMetaData(const UserMetaData& rhs)
39  : d(new Private(*rhs.d))
40 {
41 }
42 
43 UserMetaData::~UserMetaData()
44 {
45  delete d;
46 }
47 
48 const UserMetaData& UserMetaData::operator=(const UserMetaData& rhs)
49 {
50  d->filePath = rhs.d->filePath;
51  return *this;
52 }
53 
54 QString UserMetaData::filePath() const
55 {
56  return d->filePath;
57 }
58 
59 UserMetaData::Error UserMetaData::setTags(const QStringList& tags)
60 {
61  if (!tags.isEmpty()) {
62  k_setxattr(d->filePath, QStringLiteral("user.xdg.tags"), tags.join(QLatin1Char(',')));
63  } else {
64  k_removexattr(d->filePath, QStringLiteral("user.xdg.tags"));
65  }
66 
67  return NoError;
68 }
69 
70 QStringList UserMetaData::tags() const
71 {
72  QString value;
73 
74  k_getxattr(d->filePath, QStringLiteral("user.xdg.tags"), &value);
75  return value.split(QLatin1Char(','), QString::SkipEmptyParts);
76 }
77 
78 int UserMetaData::rating() const
79 {
80  QString value;
81 
82  k_getxattr(d->filePath, QStringLiteral("user.baloo.rating"), &value);
83  return value.toInt();
84 }
85 
86 UserMetaData::Error UserMetaData::setRating(int rating)
87 {
88  if (rating) {
89  k_setxattr(d->filePath, QStringLiteral("user.baloo.rating"), QString::number(rating));
90  } else {
91  k_removexattr(d->filePath, QStringLiteral("user.baloo.rating"));
92  }
93 
94  return NoError;
95 }
96 
97 QString UserMetaData::userComment() const
98 {
99  QString value;
100  k_getxattr(d->filePath, QStringLiteral("user.xdg.comment"), &value);
101 
102  return value;
103 }
104 
105 UserMetaData::Error UserMetaData::setUserComment(const QString& userComment)
106 {
107  if (!userComment.isEmpty()) {
108  k_setxattr(d->filePath, QStringLiteral("user.xdg.comment"), userComment);
109  } else {
110  k_removexattr(d->filePath, QStringLiteral("user.xdg.comment"));
111  }
112 
113  return NoError;
114 }
115 
116 QUrl UserMetaData::originUrl() const
117 {
118  QString value;
119  k_getxattr(d->filePath, QStringLiteral("user.xdg.origin.url"), &value);
120 
121  return QUrl(value);
122 }
123 
124 UserMetaData::Error UserMetaData::setOriginUrl(const QUrl &originUrl)
125 {
126  if (!originUrl.isEmpty()) {
127  k_setxattr(d->filePath, QStringLiteral("user.xdg.origin.url"), originUrl.toString());
128  } else {
129  k_removexattr(d->filePath, QStringLiteral("user.xdg.origin.url"));
130  }
131 
132  return NoError;
133 }
134 
135 QString UserMetaData::originEmailSubject() const
136 {
137  QString value;
138  k_getxattr(d->filePath, QStringLiteral("user.xdg.origin.email.subject"), &value);
139  return value;
140 }
141 
142 UserMetaData::Error UserMetaData::setOriginEmailSubject(const QString &originEmailSubject)
143 {
144  if (!originEmailSubject.isEmpty()) {
145  k_setxattr(d->filePath, QStringLiteral("user.xdg.origin.email.subject"), originEmailSubject);
146  } else {
147  k_removexattr(d->filePath, QStringLiteral("user.xdg.origin.email.subject"));
148  }
149 
150  return NoError;
151 }
152 
153 QString UserMetaData::originEmailSender() const
154 {
155  QString value;
156  k_getxattr(d->filePath, QStringLiteral("user.xdg.origin.email.sender"), &value);
157  return value;
158 }
159 
160 UserMetaData::Error UserMetaData::setOriginEmailSender(const QString &originEmailSender)
161 {
162  if (!originEmailSender.isEmpty()) {
163  k_setxattr(d->filePath, QStringLiteral("user.xdg.origin.email.sender"), originEmailSender);
164  } else {
165  k_removexattr(d->filePath, QStringLiteral("user.xdg.origin.email.sender"));
166  }
167 
168  return NoError;
169 }
170 
171 QString UserMetaData::originEmailMessageId() const
172 {
173  QString value;
174  k_getxattr(d->filePath, QStringLiteral("user.xdg.origin.email.message-id"), &value);
175  return value;
176 }
177 
178 UserMetaData::Error UserMetaData::setOriginEmailMessageId(const QString &originEmailMessageId)
179 {
180  if (!originEmailMessageId.isEmpty()) {
181  k_setxattr(d->filePath, QStringLiteral("user.xdg.origin.email.message-id"), originEmailMessageId);
182  } else {
183  k_removexattr(d->filePath, QStringLiteral("user.xdg.origin.email.message-id"));
184  }
185 
186  return NoError;
187 }
188 
189 UserMetaData::Error UserMetaData::setAttribute(const QString& key, const QString& value)
190 {
191  if (!value.isEmpty()) {
192  k_setxattr(d->filePath, QStringLiteral("user.") + key, value);
193  } else {
194  k_removexattr(d->filePath, QStringLiteral("user.") + key);
195  }
196 
197  return NoError;
198 }
199 
200 bool UserMetaData::hasAttribute(const QString& key)
201 {
202  return k_hasAttribute(d->filePath, QStringLiteral("user.") + key);
203 }
204 
205 QString UserMetaData::attribute(const QString& key)
206 {
207  QString value;
208  k_getxattr(d->filePath, QStringLiteral("user.") + key, &value);
209 
210  return value;
211 }
212 
213 bool UserMetaData::isSupported() const
214 {
215  return k_isSupported(d->filePath);
216 }
217 
218 UserMetaData::Attributes UserMetaData::queryAttributes(UserMetaData::Attributes attributes) const
219 {
220  return k_queryAttributes(d->filePath, attributes);
221 }
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString join(const QString &separator) const const
bool isEmpty() const const
QString toString(QUrl::FormattingOptions options) const const
QString number(int n, int base)
int toInt(bool *ok, int base) const const
bool isEmpty() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 31 2020 23:13:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.