13#include "../utils_p.h"
30 void reserve(
int size);
31 void insert(uint udsField,
const QString &value);
32 void replace(uint udsField,
const QString &value);
33 void insert(uint udsField,
long long value);
34 void replace(uint udsField,
long long value);
36 QString stringValue(uint udsField)
const;
37 long long numberValue(uint udsField,
long long defaultValue = -1)
const;
39 bool contains(uint udsField)
const;
43 void debugUDSEntry(
QDebug &stream)
const;
48 static QString nameOfUdsField(uint field);
55 inline Field(
const uint index,
const QString &value)
60 inline Field(
const uint index,
long long value = 0)
67 long long m_long = LLONG_MIN;
70 std::vector<Field> storage;
73void UDSEntryPrivate::reserve(
int size)
75 storage.reserve(size);
78void UDSEntryPrivate::insert(uint udsField,
const QString &value)
81 Q_ASSERT(std::find_if(storage.cbegin(),
83 [udsField](
const Field &entry) {
84 return entry.m_index == udsField;
87 storage.emplace_back(udsField, value);
90void UDSEntryPrivate::replace(uint udsField,
const QString &value)
93 auto it = std::find_if(storage.begin(), storage.end(), [udsField](
const Field &entry) {
94 return entry.m_index == udsField;
96 if (it != storage.end()) {
100 storage.emplace_back(udsField, value);
103void UDSEntryPrivate::insert(uint udsField,
long long value)
106 Q_ASSERT(std::find_if(storage.cbegin(),
108 [udsField](
const Field &entry) {
109 return entry.m_index == udsField;
112 storage.emplace_back(udsField, value);
115void UDSEntryPrivate::replace(uint udsField,
long long value)
118 auto it = std::find_if(storage.begin(), storage.end(), [udsField](
const Field &entry) {
119 return entry.m_index == udsField;
121 if (it != storage.end()) {
125 storage.emplace_back(udsField, value);
128int UDSEntryPrivate::count()
const
130 return storage.size();
133QString UDSEntryPrivate::stringValue(uint udsField)
const
135 auto it = std::find_if(storage.cbegin(), storage.cend(), [udsField](
const Field &entry) {
136 return entry.m_index == udsField;
138 if (it != storage.cend()) {
144long long UDSEntryPrivate::numberValue(uint udsField,
long long defaultValue)
const
146 auto it = std::find_if(storage.cbegin(), storage.cend(), [udsField](
const Field &entry) {
147 return entry.m_index == udsField;
149 if (it != storage.cend()) {
159 for (
const Field &field : storage) {
160 res.
append(field.m_index);
165bool UDSEntryPrivate::contains(uint udsField)
const
167 auto it = std::find_if(storage.cbegin(), storage.cend(), [udsField](
const Field &entry) {
168 return entry.m_index == udsField;
170 return (it != storage.cend());
173void UDSEntryPrivate::clear()
180 s << static_cast<quint32>(storage.size());
182 for (
const Field &field : storage) {
183 uint uds = field.m_index;
191 Q_ASSERT_X(
false,
"KIO::UDSEntry",
"Found a field with an invalid type");
208 if (quint32(cachedStrings.
size()) < size) {
209 cachedStrings.
resize(size);
212 for (quint32 i = 0; i < size; ++i) {
223 if (buffer != cachedStrings.
at(i)) {
224 cachedStrings[i] = buffer;
227 insert(uds, cachedStrings.
at(i));
233 Q_ASSERT_X(
false,
"KIO::UDSEntry",
"Found a field with an invalid type");
238QString UDSEntryPrivate::nameOfUdsField(uint field)
242 return QStringLiteral(
"UDS_SIZE");
244 return QStringLiteral(
"UDS_SIZE_LARGE");
246 return QStringLiteral(
"UDS_USER");
248 return QStringLiteral(
"UDS_ICON_NAME");
250 return QStringLiteral(
"UDS_GROUP");
252 return QStringLiteral(
"UDS_NAME");
254 return QStringLiteral(
"UDS_LOCAL_GROUP_ID");
256 return QStringLiteral(
"UDS_LOCAL_USER_ID");
258 return QStringLiteral(
"UDS_LOCAL_PATH");
260 return QStringLiteral(
"UDS_HIDDEN");
262 return QStringLiteral(
"UDS_ACCESS");
264 return QStringLiteral(
"UDS_MODIFICATION_TIME");
266 return QStringLiteral(
"UDS_ACCESS_TIME");
268 return QStringLiteral(
"UDS_CREATION_TIME");
270 return QStringLiteral(
"UDS_FILE_TYPE");
272 return QStringLiteral(
"UDS_LINK_DEST");
274 return QStringLiteral(
"UDS_URL");
276 return QStringLiteral(
"UDS_MIME_TYPE");
278 return QStringLiteral(
"UDS_GUESSED_MIME_TYPE");
280 return QStringLiteral(
"UDS_XML_PROPERTIES");
282 return QStringLiteral(
"UDS_EXTENDED_ACL");
284 return QStringLiteral(
"UDS_ACL_STRING");
286 return QStringLiteral(
"UDS_DEFAULT_ACL_STRING");
288 return QStringLiteral(
"UDS_DISPLAY_NAME");
290 return QStringLiteral(
"UDS_TARGET_URL");
292 return QStringLiteral(
"UDS_DISPLAY_TYPE");
294 return QStringLiteral(
"UDS_ICON_OVERLAY_NAMES");
296 return QStringLiteral(
"UDS_COMMENT");
298 return QStringLiteral(
"UDS_DEVICE_ID");
300 return QStringLiteral(
"UDS_INODE");
302 return QStringLiteral(
"UDS_EXTRA");
304 return QStringLiteral(
"UDS_EXTRA_END");
306 return QStringLiteral(
"Unknown uds field %1").arg(field);
310void UDSEntryPrivate::debugUDSEntry(
QDebug &stream)
const
314 for (
const Field &field : storage) {
315 stream <<
" " << nameOfUdsField(field.m_index) <<
"=";
317 stream << field.m_str;
319 stream << field.m_long;
321 Q_ASSERT_X(
false,
"KIO::UDSEntry",
"Found a field with an invalid type");
332 : d(new UDSEntryPrivate())
337UDSEntry::UDSEntry(
const QT_STATBUF &buff,
const QString &name)
338 : d(new UDSEntryPrivate())
359UDSEntry::UDSEntry(
const UDSEntry &) =
default;
361UDSEntry::UDSEntry(
UDSEntry &&) =
default;
367 return d->stringValue(field);
372 return d->numberValue(field, defaultValue);
392 d->insert(field, value);
397 d->insert(field, value);
402 d->replace(field, value);
407 d->replace(field, value);
422 return d->contains(field);
433 entry.d->debugUDSEntry(stream);
470 for (uint field : fields) {
Universal Directory Service.
QList< uint > fields() const
A vector of fields being present for the current entry.
void reserve(int size)
Calling this function before inserting items into an empty UDSEntry may save time and memory.
void fastInsert(uint field, const QString &value)
insert field with string value, it will assert if the field is already inserted.
QString stringValue(uint field) const
long long numberValue(uint field, long long defaultValue=0) const
@ UDS_LOCAL_USER_ID
User ID of the file owner.
@ UDS_CREATION_TIME
The time the file was created. Required time format: seconds since UNIX epoch.
@ UDS_ICON_OVERLAY_NAMES
A comma-separated list of supplementary icon overlays which will be added to the list of overlays cre...
@ UDS_HIDDEN
Treat the file as a hidden file (if set to 1) or as a normal file (if set to 0).
@ UDS_URL
An alternative URL (If different from the caption).
@ UDS_GROUP
Group Name of the file owner Not present on local fs, use UDS_LOCAL_GROUP_ID.
@ UDS_LINK_DEST
Name of the file where the link points to Allows to check for a symlink (don't use S_ISLNK !...
@ UDS_LOCAL_GROUP_ID
Group ID of the file owner.
@ UDS_MIME_TYPE
A MIME type; the KIO worker should set it if it's known.
@ UDS_LOCAL_PATH
A local file path if the KIO worker display files sitting on the local filesystem (but in another hie...
@ UDS_FILE_TYPE
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
@ UDS_DISPLAY_TYPE
User-readable type of file (if not specified, the MIME type's description is used)
@ UDS_MODIFICATION_TIME
The last time the file was modified. Required time format: seconds since UNIX epoch.
@ UDS_COMMENT
A comment which will be displayed as is to the user.
@ UDS_SIZE
Size of the file.
@ UDS_DEVICE_ID
Device number for this file, used to detect hardlinks.
@ UDS_ACCESS_TIME
The last time the file was opened. Required time format: seconds since UNIX epoch.
@ UDS_DISPLAY_NAME
If set, contains the label to display instead of the 'real name' in UDS_NAME.
@ UDS_DEFAULT_ACL_STRING
The default access control list serialized into a single string.
@ UDS_NAME
Filename - as displayed in directory listings etc.
@ UDS_TARGET_URL
This file is a shortcut or mount, pointing to an URL in a different hierarchy.
@ UDS_ICON_NAME
Name of the icon, that should be used for displaying.
@ UDS_EXTRA
Extra data (used only if you specified Columns/ColumnsTypes) NB: you cannot repeat this entry; use UD...
@ UDS_ACL_STRING
The access control list serialized into a single string.
@ UDS_EXTRA_END
Extra data (used only if you specified Columns/ColumnsTypes) NB: you cannot repeat this entry; use UD...
@ UDS_GUESSED_MIME_TYPE
A MIME type to be used for displaying only.
@ UDS_XML_PROPERTIES
XML properties, e.g. for WebDAV.
@ UDS_INODE
Inode number for this file, used to detect hardlinks.
@ UDS_USER
User Name of the file owner Not present on local fs, use UDS_LOCAL_USER_ID.
@ UDS_EXTENDED_ACL
Indicates that the entry has extended ACL entries.
@ UDS_ACCESS
Access permissions (part of the mode returned by stat)
bool contains(uint field) const
check existence of a field
UDSEntry & operator=(const UDSEntry &)
Copy assignment.
void replace(uint field, const QString &value)
Replace or insert field with string value.
void clear()
remove all fields
@ UDS_STRING
Indicates that the field is a QString.
@ UDS_NUMBER
Indicates that the field is a number (long long)
int count() const
count fields
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
A namespace for KIO globals.
KIOCORE_EXPORT bool operator!=(const UDSEntry &entry, const UDSEntry &other)
Returns true if the entry does not contain the same data as the other.
KIOCORE_EXPORT bool operator==(const UDSEntry &entry, const UDSEntry &other)
Returns true if the entry contains the same data as the other.
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
void reserve(qsizetype size)
void resize(qsizetype size)
qsizetype size() const const
bool isEmpty() const const