diff --git a/autotests/udsentrytest.cpp b/autotests/udsentrytest.cpp index 8da7b6f1..50286347 100644 --- a/autotests/udsentrytest.cpp +++ b/autotests/udsentrytest.cpp @@ -1,224 +1,273 @@ /* This file is part of the KDE project Copyright (C) 2013 Frank Reininghaus This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "udsentrytest.h" #include #include #include +#include +#include #include struct UDSTestField { UDSTestField() {} UDSTestField(uint uds, const QString &value) : m_uds(uds), m_string(value) { Q_ASSERT(uds & KIO::UDSEntry::UDS_STRING); } UDSTestField(uint uds, long long value) : m_uds(uds), m_long(value) { Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); } uint m_uds; QString m_string; long long m_long; }; /** * Test that storing UDSEntries to a stream and then re-loading them works. */ void UDSEntryTest::testSaveLoad() { QVector > testCases; QVector testCase; // Data for 1st UDSEntry. testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 1) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user1")) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group1")) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename1")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 123456) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 12345) << UDSTestField(KIO::UDSEntry::UDS_DEVICE_ID, 2) << UDSTestField(KIO::UDSEntry::UDS_INODE, 56); testCases << testCase; // 2nd entry: change some of the data. testCase.clear(); testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 2) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user2")) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group1")) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename2")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 12345) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 1234) << UDSTestField(KIO::UDSEntry::UDS_DEVICE_ID, 87) << UDSTestField(KIO::UDSEntry::UDS_INODE, 42); testCases << testCase; // 3rd entry: keep the data, but change the order of the entries. testCase.clear(); testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 2) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group1")) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user2")) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename2")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 12345) << UDSTestField(KIO::UDSEntry::UDS_DEVICE_ID, 87) << UDSTestField(KIO::UDSEntry::UDS_INODE, 42) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 1234); testCases << testCase; // 4th entry: change some of the data and the order of the entries. testCase.clear(); testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 2) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user4")) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group4")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 12346) << UDSTestField(KIO::UDSEntry::UDS_DEVICE_ID, 87) << UDSTestField(KIO::UDSEntry::UDS_INODE, 42) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 1235) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename4")); testCases << testCase; // 5th entry: remove one field. testCase.clear(); testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 2) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user4")) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group4")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 12346) << UDSTestField(KIO::UDSEntry::UDS_INODE, 42) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 1235) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename4")); testCases << testCase; // 6th entry: add a new field, and change some others. testCase.clear(); testCase << UDSTestField(KIO::UDSEntry::UDS_SIZE, 89) << UDSTestField(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("icon6")) << UDSTestField(KIO::UDSEntry::UDS_USER, QStringLiteral("user6")) << UDSTestField(KIO::UDSEntry::UDS_GROUP, QStringLiteral("group4")) << UDSTestField(KIO::UDSEntry::UDS_MODIFICATION_TIME, 12346) << UDSTestField(KIO::UDSEntry::UDS_INODE, 32) << UDSTestField(KIO::UDSEntry::UDS_CREATION_TIME, 1235) << UDSTestField(KIO::UDSEntry::UDS_NAME, QStringLiteral("filename6")); testCases << testCase; // Store the entries in a QByteArray. QByteArray data; { QDataStream stream(&data, QIODevice::WriteOnly); foreach (const QVector &testCase, testCases) { KIO::UDSEntry entry; foreach (const UDSTestField &field, testCase) { uint uds = field.m_uds; if (uds & KIO::UDSEntry::UDS_STRING) { entry.insert(uds, field.m_string); } else { Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); entry.insert(uds, field.m_long); } } QCOMPARE(entry.count(), testCase.count()); stream << entry; } } // Re-load the entries and compare with the data in testCases. { QDataStream stream(data); foreach (const QVector &testCase, testCases) { KIO::UDSEntry entry; stream >> entry; QCOMPARE(entry.count(), testCase.count()); foreach (const UDSTestField &field, testCase) { uint uds = field.m_uds; QVERIFY(entry.contains(uds)); if (uds & KIO::UDSEntry::UDS_STRING) { QCOMPARE(entry.stringValue(uds), field.m_string); } else { Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); QCOMPARE(entry.numberValue(uds), field.m_long); } } } } // Now: Store the fields manually in the order in which they appear in // testCases, and re-load them. This ensures that loading the entries // works no matter in which order the fields appear in the QByteArray. data.clear(); { QDataStream stream(&data, QIODevice::WriteOnly); foreach (const QVector &testCase, testCases) { stream << testCase.count(); foreach (const UDSTestField &field, testCase) { uint uds = field.m_uds; stream << uds; if (uds & KIO::UDSEntry::UDS_STRING) { stream << field.m_string; } else { Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); stream << field.m_long; } } } } { QDataStream stream(data); foreach (const QVector &testCase, testCases) { KIO::UDSEntry entry; stream >> entry; QCOMPARE(entry.count(), testCase.count()); foreach (const UDSTestField &field, testCase) { uint uds = field.m_uds; QVERIFY(entry.contains(uds)); if (uds & KIO::UDSEntry::UDS_STRING) { QCOMPARE(entry.stringValue(uds), field.m_string); } else { Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); QCOMPARE(entry.numberValue(uds), field.m_long); } } } } } +/** + * Test to verify that move semantics work. This is only useful when ran through callgrind. + */ +void UDSEntryTest::testMove() +{ + // Create a temporary file. Just to make a UDSEntry further down. + QTemporaryFile file; + QVERIFY(file.open()); + const QByteArray filePath = file.fileName().toLocal8Bit(); + const QString fileName = QUrl(file.fileName()).fileName(); // QTemporaryFile::fileName returns the full path. + QVERIFY(!fileName.isEmpty()); + + // We have a file now. Get the stat data from it to make the UDSEntry. + QT_STATBUF statBuf; + QVERIFY(QT_LSTAT(filePath.constData(), &statBuf) == 0); + KIO::UDSEntry entry(statBuf, fileName); + + // Verify that the name in the UDSEntry is the same as we've got from the fileName var. + QCOMPARE(fileName, entry.stringValue(KIO::UDSEntry::UDS_NAME)); + + // That was the boilerplate code. Now for move semantics. + // First: move assignment. + { + // First a copy as we need to keep the entry for the next test. + KIO::UDSEntry entryCopy = entry; + + // Now move-assignement (two lines to prevent compiler optimization) + KIO::UDSEntry movedEntry; + movedEntry = std::move(entryCopy); + + // And veryfy that this works. + QCOMPARE(fileName, movedEntry.stringValue(KIO::UDSEntry::UDS_NAME)); + } + + // Move constructor + { + // First a copy again + KIO::UDSEntry entryCopy = entry; + + // Now move-assignement + KIO::UDSEntry movedEntry(std::move(entryCopy)); + + // And veryfy that this works. + QCOMPARE(fileName, movedEntry.stringValue(KIO::UDSEntry::UDS_NAME)); + } +} + QTEST_MAIN(UDSEntryTest) diff --git a/autotests/udsentrytest.h b/autotests/udsentrytest.h index fab70653..3e41c9e6 100644 --- a/autotests/udsentrytest.h +++ b/autotests/udsentrytest.h @@ -1,33 +1,34 @@ /* This file is part of the KDE project Copyright (C) 2013 Frank Reininghaus This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef UDSENTRYTEST_H #define UDSENTRYTEST_H #include class UDSEntryTest : public QObject { Q_OBJECT private Q_SLOTS: void testSaveLoad(); + void testMove(); }; #endif diff --git a/src/core/udsentry.cpp b/src/core/udsentry.cpp index 5e1aaf5d..52dbb482 100644 --- a/src/core/udsentry.cpp +++ b/src/core/udsentry.cpp @@ -1,289 +1,280 @@ /* This file is part of the KDE project Copyright (C) 2000-2005 David Faure Copyright (C) 2007 Norbert Frese Copyright (C) 2007 Thiago Macieira Copyright (C) 2013-2014 Frank Reininghaus This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "udsentry.h" #include #include #include #include #include #include using namespace KIO; /* ---------- UDSEntry ------------ */ class KIO::UDSEntryPrivate : public QSharedData { public: struct Field { inline Field(const QString &value) : m_str(value), m_long(0) {} inline Field(long long value = 0) : m_long(value) { } QString m_str; long long m_long; }; QVector fields; // If udsIndexes[i] == uds, then fields[i] contains the value for 'uds'. Example: // udsIndexes = {UDS_NAME, UDS_FILE_SIZE, ...} // fields = {Field("filename"), Field(1234), ...} QVector udsIndexes; void insert(uint uds, const Field& field) { const int index = udsIndexes.indexOf(uds); if (index >= 0) { fields[index] = field; } else { udsIndexes.append(uds); fields.append(field); } } static void save(QDataStream &, const UDSEntry &); static void load(QDataStream &, UDSEntry &); }; Q_DECLARE_TYPEINFO(KIO::UDSEntryPrivate::Field, Q_MOVABLE_TYPE); UDSEntry::UDSEntry() : d(new UDSEntryPrivate()) { } -UDSEntry::UDSEntry(const UDSEntry &other) - : d(other.d) -{ -} - // BUG: this API doesn't allow to handle symlinks correctly (we need buff from QT_LSTAT for most things, but buff from QT_STAT for st_mode and st_size) UDSEntry::UDSEntry(const QT_STATBUF &buff, const QString &name) : d(new UDSEntryPrivate()) { reserve(9); insert(UDS_NAME, name); insert(UDS_SIZE, buff.st_size); insert(UDS_DEVICE_ID, buff.st_dev); insert(UDS_INODE, buff.st_ino); insert(UDS_FILE_TYPE, buff.st_mode & QT_STAT_MASK); // extract file type insert(UDS_ACCESS, buff.st_mode & 07777); // extract permissions insert(UDS_MODIFICATION_TIME, buff.st_mtime); insert(UDS_ACCESS_TIME, buff.st_atime); #ifndef Q_OS_WIN insert(UDS_USER, KUser(buff.st_uid).loginName()); insert(UDS_GROUP, KUserGroup(buff.st_gid).name()); #endif } -UDSEntry::~UDSEntry() -{ -} - -UDSEntry &UDSEntry::operator=(const UDSEntry &other) -{ - d = other.d; - return *this; -} +UDSEntry::UDSEntry(const UDSEntry&) = default; +UDSEntry::~UDSEntry() = default; +UDSEntry::UDSEntry(UDSEntry&&) = default; +UDSEntry& UDSEntry::operator=(const UDSEntry&) = default; +UDSEntry& UDSEntry::operator=(UDSEntry&&) = default; QString UDSEntry::stringValue(uint field) const { const int index = d->udsIndexes.indexOf(field); if (index >= 0) { return d->fields.at(index).m_str; } else { return QString(); } } long long UDSEntry::numberValue(uint field, long long defaultValue) const { const int index = d->udsIndexes.indexOf(field); if (index >= 0) { return d->fields.at(index).m_long; } else { return defaultValue; } } bool UDSEntry::isDir() const { return (numberValue(UDS_FILE_TYPE) & QT_STAT_MASK) == QT_STAT_DIR; } bool UDSEntry::isLink() const { return !stringValue(UDS_LINK_DEST).isEmpty(); } void UDSEntry::reserve(int size) { d->fields.reserve(size); d->udsIndexes.reserve(size); } void UDSEntry::insert(uint field, const QString &value) { d->insert(field, UDSEntryPrivate::Field(value)); } void UDSEntry::insert(uint field, long long value) { d->insert(field, UDSEntryPrivate::Field(value)); } #ifndef KIOCORE_NO_DEPRECATED QList UDSEntry::listFields() const { return d->udsIndexes.toList(); } #endif QVector UDSEntry::fields() const { return d->udsIndexes; } int UDSEntry::count() const { return d->udsIndexes.count(); } bool UDSEntry::contains(uint field) const { return d->udsIndexes.contains(field); } void UDSEntry::clear() { d->fields.clear(); d->udsIndexes.clear(); } QDataStream &operator<<(QDataStream &s, const UDSEntry &a) { UDSEntryPrivate::save(s, a); return s; } QDataStream &operator>>(QDataStream &s, UDSEntry &a) { UDSEntryPrivate::load(s, a); return s; } void UDSEntryPrivate::save(QDataStream &s, const UDSEntry &a) { const QVector &udsIndexes = a.d->udsIndexes; const QVector &fields = a.d->fields; const int size = udsIndexes.size(); s << size; for (int index = 0; index < size; ++index) { uint uds = udsIndexes.at(index); s << uds; if (uds & KIO::UDSEntry::UDS_STRING) { s << fields.at(index).m_str; } else if (uds & KIO::UDSEntry::UDS_NUMBER) { s << fields.at(index).m_long; } else { Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type"); } } } KIOCORE_EXPORT QDebug operator<<(QDebug stream, const KIO::UDSEntry &entry) { debugUDSEntry(stream, entry); return stream; } void UDSEntryPrivate::load(QDataStream &s, UDSEntry &a) { a.clear(); QVector &fields = a.d->fields; QVector &udsIndexes = a.d->udsIndexes; quint32 size; s >> size; fields.reserve(size); udsIndexes.reserve(size); // We cache the loaded strings. Some of them, like, e.g., the user, // will often be the same for many entries in a row. Caching them // permits to use implicit sharing to save memory. static QVector cachedStrings; if (quint32(cachedStrings.size()) < size) { cachedStrings.resize(size); } for (quint32 i = 0; i < size; ++i) { quint32 uds; s >> uds; udsIndexes.append(uds); if (uds & KIO::UDSEntry::UDS_STRING) { // If the QString is the same like the one we read for the // previous UDSEntry at the i-th position, use an implicitly // shared copy of the same QString to save memory. QString buffer; s >> buffer; if (buffer != cachedStrings.at(i)) { cachedStrings[i] = buffer; } fields.append(Field(cachedStrings.at(i))); } else if (uds & KIO::UDSEntry::UDS_NUMBER) { long long value; s >> value; fields.append(Field(value)); } else { Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type"); } } } void debugUDSEntry(QDebug stream, const KIO::UDSEntry &entry) { const QVector &udsIndexes = entry.d->udsIndexes; const QVector &fields = entry.d->fields; const int size = udsIndexes.size(); QDebugStateSaver saver(stream); stream.nospace() << "["; for (int index = 0; index < size; ++index) { const uint uds = udsIndexes.at(index); stream << " " << (uds & 0xffff) << "="; // we could use a switch statement for readability :-) if (uds & KIO::UDSEntry::UDS_STRING) { stream << fields.at(index).m_str; } else if (uds & KIO::UDSEntry::UDS_NUMBER) { stream << fields.at(index).m_long; } else { Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type"); } } stream << " ]"; } diff --git a/src/core/udsentry.h b/src/core/udsentry.h index 52eb91c6..11a1fbdc 100644 --- a/src/core/udsentry.h +++ b/src/core/udsentry.h @@ -1,329 +1,353 @@ /* This file is part of the KDE libraries Copyright (C) 2000-2005 David Faure Copyright (C) 2007 Norbert Frese Copyright (C) 2007 Thiago Macieira This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef UDSENTRY_H #define UDSENTRY_H #include #include #include #include #include #include #include "kiocore_export.h" namespace KIO { class UDSEntry; } void debugUDSEntry(QDebug stream, const KIO::UDSEntry &entry); namespace KIO { class UDSEntryPrivate; /** * @class KIO::UDSEntry udsentry.h * * Universal Directory Service * * UDS entry is the data structure representing all the fields about a given URL * (file or directory). * * The KIO::listDir() and KIO:stat() operations use this data structure. * * KIO defines a number of standard fields, see the UDS_XXX enums (see StandardFieldTypes). * at the moment UDSEntry only provides fields with numeric indexes, * but there might be named fields with string indexes in the future. * * For instance, to retrieve the name of the entry, use: * \code * QString displayName = entry.stringValue( KIO::UDSEntry::UDS_NAME ); * \endcode * * To know the modification time of the file/url: * \code * QDateTime mtime = QDateTime::fromTime_t(entry.numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, 0)); * if (mtime.isValid()) * ... * \endcode */ class KIOCORE_EXPORT UDSEntry { public: UDSEntry(); - UDSEntry(const UDSEntry &other); /** * Create a UDSEntry by QT_STATBUF * @param buff QT_STATBUFF object * @param name filename * @since 5.0 */ UDSEntry(const QT_STATBUF &buff, const QString &name = QString()); + + /** + * Copy constructor + */ + UDSEntry(const UDSEntry&); + + /** + * Destructor + */ ~UDSEntry(); - UDSEntry &operator=(const UDSEntry &other); + + /** + * Move constructor + * @since 5.44 + */ + UDSEntry(UDSEntry&&); + + /** + * Copy assignment + */ + UDSEntry& operator=(const UDSEntry&); + + /** + * Move assignment + * @since 5.44 + */ + UDSEntry& operator=(UDSEntry&&); /** * @return value of a textual field */ QString stringValue(uint field) const; /** * @return value of a numeric field */ long long numberValue(uint field, long long defaultValue = 0) const; // Convenience methods. // Let's not add one method per field, only methods that have some more logic // than just calling stringValue(field) or numberValue(field). /// @return true if this entry is a directory (or a link to a directory) bool isDir() const; /// @return true if this entry is a link bool isLink() const; /** * Calling this function before inserting items into an empty UDSEntry may save time and memory. * @param size number of items for which memory will be pre-allocated */ void reserve(int size); /** * insert field with string value * @param field numeric field id * @param value to set */ void insert(uint field, const QString &value); /** * insert field with numeric value * @param field numeric field id * @param l value to set */ void insert(uint field, long long l); /** * count fields * @return the number of fields */ int count() const; /** * check existence of a field * @param field numeric field id */ bool contains(uint field) const; /** * List all fields. * @return all fields. * @deprecated since 5.8. Use fields() instead. */ #ifndef KIOCORE_NO_DEPRECATED KIOCORE_DEPRECATED QList listFields() const; #endif /** * A vector of fields being present for the current entry. * @return all fields for the current entry. * @since 5.8 */ QVector fields() const; /** * remove all fields */ void clear(); /** * Constants used to specify the type of a UDSField. */ enum StandardFieldTypes { // First let's define the item types: bit field /// Indicates that the field is a QString UDS_STRING = 0x01000000, /// Indicates that the field is a number (long long) UDS_NUMBER = 0x02000000, /// Indicates that the field represents a time, which is modelled by a long long UDS_TIME = 0x04000000 | UDS_NUMBER, // The rest isn't a bit field /// Size of the file UDS_SIZE = 1 | UDS_NUMBER, /// @internal UDS_SIZE_LARGE = 2 | UDS_NUMBER, /// User ID of the file owner UDS_USER = 3 | UDS_STRING, /// Name of the icon, that should be used for displaying. /// It overrides all other detection mechanisms UDS_ICON_NAME = 4 | UDS_STRING, /// Group ID of the file owner UDS_GROUP = 5 | UDS_STRING, /// Filename - as displayed in directory listings etc. /// "." has the usual special meaning of "current directory" /// UDS_NAME must always be set and never be empty, neither contain '/'. /// /// Note that KIO will append the UDS_NAME to the url of their /// parent directory, so all kioslaves must use that naming scheme /// ("url_of_parent/filename" will be the full url of that file). /// To customize the appearance of files without changing the url /// of the items, use UDS_DISPLAY_NAME. UDS_NAME = 6 | UDS_STRING, /// A local file path if the ioslave display files sitting /// on the local filesystem (but in another hierarchy, e.g. settings:/ or remote:/) UDS_LOCAL_PATH = 7 | UDS_STRING, /// Treat the file as a hidden file (if set to 1) or as a normal file (if set to 0). /// This field overrides the default behavior (the check for a leading dot in the filename). UDS_HIDDEN = 8 | UDS_NUMBER, /// Access permissions (part of the mode returned by stat) UDS_ACCESS = 9 | UDS_NUMBER, /// The last time the file was modified UDS_MODIFICATION_TIME = 10 | UDS_TIME, /// The last time the file was opened UDS_ACCESS_TIME = 11 | UDS_TIME, /// The time the file was created UDS_CREATION_TIME = 12 | UDS_TIME, /// File type, part of the mode returned by stat /// (for a link, this returns the file type of the pointed item) /// check UDS_LINK_DEST to know if this is a link UDS_FILE_TYPE = 13 | UDS_NUMBER, /// Name of the file where the link points to /// Allows to check for a symlink (don't use S_ISLNK !) UDS_LINK_DEST = 14 | UDS_STRING, /// An alternative URL (If different from the caption). /// Can be used to mix different hierarchies. /// /// Use UDS_DISPLAY_NAME if you simply want to customize the user-visible filenames, or use /// UDS_TARGET_URL if you want "links" to unrelated urls. UDS_URL = 15 | UDS_STRING, /// A mime type; the slave should set it if it's known. UDS_MIME_TYPE = 16 | UDS_STRING, /// A mime type to be used for displaying only. /// But when 'running' the file, the mimetype is re-determined /// This is for special cases like symlinks in FTP; you probably don't want to use this one. UDS_GUESSED_MIME_TYPE = 17 | UDS_STRING, /// XML properties, e.g. for WebDAV UDS_XML_PROPERTIES = 18 | UDS_STRING, /// Indicates that the entry has extended ACL entries UDS_EXTENDED_ACL = 19 | UDS_NUMBER, /// The access control list serialized into a single string. UDS_ACL_STRING = 20 | UDS_STRING, /// The default access control list serialized into a single string. /// Only available for directories. UDS_DEFAULT_ACL_STRING = 21 | UDS_STRING, /// If set, contains the label to display instead of /// the 'real name' in UDS_NAME /// @since 4.1 UDS_DISPLAY_NAME = 22 | UDS_STRING, /// This file is a shortcut or mount, pointing to an /// URL in a different hierarchy /// @since 4.1 UDS_TARGET_URL = 23 | UDS_STRING, /// User-readable type of file (if not specified, /// the mimetype's description is used) /// @since 4.4 UDS_DISPLAY_TYPE = 24 | UDS_STRING, /// 25 was used by the now removed UDS_NEPOMUK_URI /// A comma-separated list of supplementary icon overlays /// which will be added to the list of overlays created /// by KFileItem. /// /// @since 4.5 UDS_ICON_OVERLAY_NAMES = 26 | UDS_STRING, /// 27 was used by the now removed UDS_NEPOMUK_QUERY /// A comment which will be displayed as is to the user. The string /// value may contain plain text or Qt-style rich-text extensions. /// /// @since 4.6 UDS_COMMENT = 28 | UDS_STRING, /// Device number for this file, used to detect hardlinks /// @since 4.7.3 UDS_DEVICE_ID = 29 | UDS_NUMBER, /// Inode number for this file, used to detect hardlinks /// @since 4.7.3 UDS_INODE = 30 | UDS_NUMBER, /// Extra data (used only if you specified Columns/ColumnsTypes) /// NB: you cannot repeat this entry; use UDS_EXTRA + i /// until UDS_EXTRA_END. UDS_EXTRA = 100 | UDS_STRING, /// Extra data (used only if you specified Columns/ColumnsTypes) /// NB: you cannot repeat this entry; use UDS_EXTRA + i /// until UDS_EXTRA_END. UDS_EXTRA_END = 140 | UDS_STRING }; private: friend class UDSEntryPrivate; friend void ::debugUDSEntry(QDebug stream, const KIO::UDSEntry &entry); QSharedDataPointer d; }; } Q_DECLARE_TYPEINFO(KIO::UDSEntry, Q_MOVABLE_TYPE); namespace KIO { /** * A directory listing is a list of UDSEntry instances. * * To list the name and size of all the files in a directory listing you would do: * \code * KIO::UDSEntryList::ConstIterator it = entries.begin(); * const KIO::UDSEntryList::ConstIterator end = entries.end(); * for (; it != end; ++it) { * const KIO::UDSEntry& entry = *it; * QString name = entry.stringValue( KIO::UDSEntry::UDS_NAME ); * bool isDir = entry.isDir(); * KIO::filesize_t size = entry.numberValue( KIO::UDSEntry::UDS_SIZE, -1 ); * ... * } * \endcode */ typedef QList UDSEntryList; } // end namespace KIOCORE_EXPORT QDataStream &operator<< (QDataStream &s, const KIO::UDSEntry &a); KIOCORE_EXPORT QDataStream &operator>> (QDataStream &s, KIO::UDSEntry &a); /** * Support for qDebug() << aUDSEntry * \since 5.22 */ KIOCORE_EXPORT QDebug operator<<(QDebug stream, const KIO::UDSEntry &entry); Q_DECLARE_METATYPE(KIO::UDSEntry) #endif /*UDSENTRY_H*/