diff --git a/kerfuffle/archiveentry.cpp b/kerfuffle/archiveentry.cpp index d79787ca..889aac21 100644 --- a/kerfuffle/archiveentry.cpp +++ b/kerfuffle/archiveentry.cpp @@ -1,192 +1,202 @@ // // Created by mvlabat on 5/27/16. // #include "archiveentry.h" namespace Kerfuffle { Archive::Entry::Entry(Entry *parent, QString fullPath, QString rootNode) : QObject(parent) , rootNode(rootNode) , compressedSizeIsSet(true) , m_parent(parent) { clearMetaData(); if (!fullPath.isEmpty()) setFullPath(fullPath); } Archive::Entry::~Entry() { clear(); } QList Archive::Entry::entries() { Q_ASSERT(isDir()); return m_entries; } const QList Archive::Entry::entries() const { Q_ASSERT(isDir()); return m_entries; } void Archive::Entry::setEntryAt(int index, Entry *value) { Q_ASSERT(isDir()); m_entries[index] = value; } void Archive::Entry::appendEntry(Entry *entry) { Q_ASSERT(isDir()); m_entries.append(entry); } void Archive::Entry::removeEntryAt(int index) { Q_ASSERT(isDir()); delete m_entries.takeAt(index); } Archive::Entry *Archive::Entry::getParent() const { return m_parent; } void Archive::Entry::setParent(Archive::Entry *parent) { m_parent = parent; } void Archive::Entry::setFullPath(const QString &fullPath) { m_fullPath = fullPath; processNameAndIcon(); } void Archive::Entry::setIsDirectory(const bool isDirectory) { m_isDirectory = isDirectory; processNameAndIcon(); } int Archive::Entry::row() const { if (getParent()) { return getParent()->entries().indexOf(const_cast(this)); } return 0; } bool Archive::Entry::isDir() const { return m_isDirectory; } void Archive::Entry::processNameAndIcon() { const QStringList pieces = m_fullPath.split(QLatin1Char( '/' ), QString::SkipEmptyParts); m_name = pieces.isEmpty() ? QString() : pieces.last(); QMimeDatabase db; if (isDir()) { m_icon = QIcon::fromTheme(db.mimeTypeForName(QStringLiteral("inode/directory")).iconName()).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)); } else { m_icon = QIcon::fromTheme(db.mimeTypeForFile(m_fullPath).iconName()).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)); } } QPixmap Archive::Entry::icon() const { return m_icon; } QString Archive::Entry::name() const { return m_name; } Archive::Entry *Archive::Entry::find(const QString & name) { foreach(Entry *entry, m_entries) { if (entry && (entry->name() == name)) { return entry; } } return 0; } Archive::Entry *Archive::Entry::findByPath(const QStringList & pieces, int index) { if (index == pieces.count()) { return 0; } Entry *next = find(pieces.at(index)); if (index == pieces.count() - 1) { return next; } if (next && next->isDir()) { return next->findByPath(pieces, index + 1); } return 0; } void Archive::Entry::clearMetaData() { m_fullPath.clear(); m_permissions.clear(); m_owner.clear(); m_group.clear(); m_size = 0; m_compressedSize = 0; m_link.clear(); m_ratio.clear(); m_CRC.clear(); m_method.clear(); m_version.clear(); m_timestamp = QDateTime(); m_isDirectory = false; m_comment.clear(); m_isPasswordProtected = false; } void Archive::Entry::returnDirEntries(QList *store) { foreach(Entry *entry, m_entries) { if (entry->isDir()) { store->prepend(entry); entry->returnDirEntries(store); } } } void Archive::Entry::clear() { if (isDir()) { qDeleteAll(m_entries); m_entries.clear(); } } bool Archive::Entry::operator==(const Archive::Entry *right) const { return m_fullPath == right->m_fullPath; } -QDebug operator<<(QDebug d, const Archive::Entry &entry) +QDebug operator<<(QDebug d, const Kerfuffle::Archive::Entry &entry) { d.nospace() << "Entry(" << entry.property("fullPath"); if (!entry.rootNode.isEmpty()) { d.nospace() << "," << entry.rootNode; } d.nospace() << ")"; return d.space(); } +QDebug operator<<(QDebug d, const Kerfuffle::Archive::Entry *entry) +{ + d.nospace() << "Entry(" << entry->property("fullPath"); + if (!entry->rootNode.isEmpty()) { + d.nospace() << "," << entry->rootNode; + } + d.nospace() << ")"; + return d.space(); +} + } diff --git a/kerfuffle/archiveentry.h b/kerfuffle/archiveentry.h index 3b541008..0fe09a2a 100644 --- a/kerfuffle/archiveentry.h +++ b/kerfuffle/archiveentry.h @@ -1,120 +1,112 @@ // // Created by mvlabat on 5/27/16. // #ifndef ARK_ENTRY_H #define ARK_ENTRY_H #include "archive_kerfuffle.h" #include "app/ark_debug.h" #include #include #include #include #include namespace Kerfuffle { class Archive::Entry : public QObject { Q_OBJECT /** * Meta data related to one entry in a compressed archive. * * When creating a plugin, information about every single entry in * an archive is contained in an ArchiveEntry, and metadata * is set with the entries in this enum. * * Please notice that not all archive formats support all the properties * below, so set those that are available. */ Q_PROPERTY(QString fullPath MEMBER m_fullPath WRITE setFullPath) Q_PROPERTY(QString name READ name) Q_PROPERTY(QString permissions MEMBER m_permissions) Q_PROPERTY(QString owner MEMBER m_owner) Q_PROPERTY(QString group MEMBER m_group) Q_PROPERTY(qulonglong size MEMBER m_size) Q_PROPERTY(qulonglong compressedSize MEMBER m_compressedSize) Q_PROPERTY(QString link MEMBER m_link) Q_PROPERTY(QString ratio MEMBER m_ratio) Q_PROPERTY(QString CRC MEMBER m_CRC) Q_PROPERTY(QString method MEMBER m_method) Q_PROPERTY(QString version MEMBER m_version) Q_PROPERTY(QDateTime timestamp MEMBER m_timestamp) Q_PROPERTY(bool isDirectory MEMBER m_isDirectory WRITE setIsDirectory) Q_PROPERTY(QString comment MEMBER m_comment) Q_PROPERTY(bool isPasswordProtected MEMBER m_isPasswordProtected) public: Entry(Entry *parent, QString fullPath = QString(), QString rootNode = QString()); ~Entry(); QList entries(); const QList entries() const; void setEntryAt(int index, Entry *value); void appendEntry(Entry *entry); void removeEntryAt(int index); Entry *getParent() const; void setParent(Entry *parent); void setFullPath(const QString &fullPath); void setIsDirectory(const bool isDirectory); int row() const; bool isDir() const; QPixmap icon() const; QString name() const; Entry *find(const QString & name); Entry *findByPath(const QStringList & pieces, int index = 0); void clearMetaData(); void returnDirEntries(QList *store); void clear(); bool operator==(const Archive::Entry *right) const; private: void processNameAndIcon(); public: QString rootNode; bool compressedSizeIsSet; private: QList m_entries; QPixmap m_icon; QString m_name; Entry *m_parent; QString m_fullPath; QString m_permissions; QString m_owner; QString m_group; qulonglong m_size; qulonglong m_compressedSize; QString m_link; QString m_ratio; QString m_CRC; QString m_method; QString m_version; QDateTime m_timestamp; bool m_isDirectory; QString m_comment; bool m_isPasswordProtected; }; -QDebug operator<<(QDebug d, const Archive::Entry &entry); -//QDebug operator<<(QDebug d, const QList &list); - -/*QDebug operator<<(QDebug d, const QList &list) -{ - foreach (Archive::Entry *entry, list) { - d.nospace() << entry; - } - return d.space(); -}*/ +QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const Kerfuffle::Archive::Entry &entry); +QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const Kerfuffle::Archive::Entry *entry); } #endif //ARK_ENTRY_H