Changeset View
Changeset View
Standalone View
Standalone View
part/archivemodel.cpp
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 81 | case Qt::DisplayRole: { | |||
---|---|---|---|---|---|
126 | } | 126 | } | ||
127 | 127 | | |||
128 | default: | 128 | default: | ||
129 | return entry->property(m_propertiesMap[column].constData()); | 129 | return entry->property(m_propertiesMap[column].constData()); | ||
130 | } | 130 | } | ||
131 | } | 131 | } | ||
132 | case Qt::DecorationRole: | 132 | case Qt::DecorationRole: | ||
133 | if (index.column() == 0) { | 133 | if (index.column() == 0) { | ||
134 | const Archive::Entry *e = static_cast<Archive::Entry*>(index.internalPointer()); | 134 | Archive::Entry *e = static_cast<Archive::Entry*>(index.internalPointer()); | ||
135 | QIcon::Mode mode = (filesToMove.contains(e->fullPath())) ? QIcon::Disabled : QIcon::Normal; | 135 | QIcon::Mode mode = (filesToMove.contains(e->fullPath())) ? QIcon::Disabled : QIcon::Normal; | ||
136 | return m_entryIcons.value(e->fullPath(NoTrailingSlash)).pixmap(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize), mode); | 136 | return e->icon().pixmap(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize), mode); | ||
137 | } | 137 | } | ||
138 | return QVariant(); | 138 | return QVariant(); | ||
139 | case Qt::FontRole: { | 139 | case Qt::FontRole: { | ||
140 | QFont f; | 140 | QFont f; | ||
141 | f.setItalic(entry->property("isPasswordProtected").toBool()); | 141 | f.setItalic(entry->property("isPasswordProtected").toBool()); | ||
142 | return f; | 142 | return f; | ||
143 | } | 143 | } | ||
144 | default: | 144 | default: | ||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Line(s) | 448 | #else | |||
449 | Archive::Entry *entry = m_rootEntry->findByPath(entryFileName.split(QLatin1Char('/'), Qt::SkipEmptyParts)); | 449 | Archive::Entry *entry = m_rootEntry->findByPath(entryFileName.split(QLatin1Char('/'), Qt::SkipEmptyParts)); | ||
450 | #endif | 450 | #endif | ||
451 | if (entry) { | 451 | if (entry) { | ||
452 | Archive::Entry *parent = entry->getParent(); | 452 | Archive::Entry *parent = entry->getParent(); | ||
453 | QModelIndex index = indexForEntry(entry); | 453 | QModelIndex index = indexForEntry(entry); | ||
454 | Q_UNUSED(index); | 454 | Q_UNUSED(index); | ||
455 | 455 | | |||
456 | beginRemoveRows(indexForEntry(parent), entry->row(), entry->row()); | 456 | beginRemoveRows(indexForEntry(parent), entry->row(), entry->row()); | ||
457 | m_entryIcons.remove(parent->entries().at(entry->row())->fullPath(NoTrailingSlash)); | | |||
458 | parent->removeEntryAt(entry->row()); | 457 | parent->removeEntryAt(entry->row()); | ||
459 | endRemoveRows(); | 458 | endRemoveRows(); | ||
460 | } | 459 | } | ||
461 | } | 460 | } | ||
462 | 461 | | |||
463 | void ArchiveModel::slotUserQuery(Kerfuffle::Query *query) | 462 | void ArchiveModel::slotUserQuery(Kerfuffle::Query *query) | ||
464 | { | 463 | { | ||
465 | query->execute(); | 464 | query->execute(); | ||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 580 | { | |||
584 | Q_ASSERT(parent); | 583 | Q_ASSERT(parent); | ||
585 | if (behaviour == NotifyViews) { | 584 | if (behaviour == NotifyViews) { | ||
586 | beginInsertRows(indexForEntry(parent), parent->entries().count(), parent->entries().count()); | 585 | beginInsertRows(indexForEntry(parent), parent->entries().count(), parent->entries().count()); | ||
587 | } | 586 | } | ||
588 | parent->appendEntry(entry); | 587 | parent->appendEntry(entry); | ||
589 | if (behaviour == NotifyViews) { | 588 | if (behaviour == NotifyViews) { | ||
590 | endInsertRows(); | 589 | endInsertRows(); | ||
591 | } | 590 | } | ||
592 | | ||||
593 | // Save an icon for each newly added entry. | | |||
594 | QMimeDatabase db; | | |||
595 | QIcon icon; | | |||
596 | entry->isDir() | | |||
597 | ? icon = QIcon::fromTheme(db.mimeTypeForName(QStringLiteral("inode/directory")).iconName()) | | |||
598 | : icon = QIcon::fromTheme(db.mimeTypeForFile(entry->fullPath()).iconName()); | | |||
599 | m_entryIcons.insert(entry->fullPath(NoTrailingSlash), icon); | | |||
600 | } | 591 | } | ||
601 | 592 | | |||
602 | Kerfuffle::Archive* ArchiveModel::archive() const | 593 | Kerfuffle::Archive* ArchiveModel::archive() const | ||
603 | { | 594 | { | ||
604 | return m_archive.data(); | 595 | return m_archive.data(); | ||
605 | } | 596 | } | ||
606 | 597 | | |||
607 | void ArchiveModel::reset() | 598 | void ArchiveModel::reset() | ||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Line(s) | |||||
834 | { | 825 | { | ||
835 | QMap<QString, Archive::Entry*> map; | 826 | QMap<QString, Archive::Entry*> map; | ||
836 | for (Archive::Entry *entry : entries) { | 827 | for (Archive::Entry *entry : entries) { | ||
837 | map.insert(entry->fullPath(), entry); | 828 | map.insert(entry->fullPath(), entry); | ||
838 | } | 829 | } | ||
839 | return map; | 830 | return map; | ||
840 | } | 831 | } | ||
841 | 832 | | |||
842 | const QHash<QString, QIcon> ArchiveModel::entryIcons() const | | |||
843 | { | | |||
844 | return m_entryIcons; | | |||
845 | } | | |||
846 | | ||||
847 | void ArchiveModel::slotCleanupEmptyDirs() | 833 | void ArchiveModel::slotCleanupEmptyDirs() | ||
848 | { | 834 | { | ||
849 | QList<QPersistentModelIndex> queue; | 835 | QList<QPersistentModelIndex> queue; | ||
850 | QList<QPersistentModelIndex> nodesToDelete; | 836 | QList<QPersistentModelIndex> nodesToDelete; | ||
851 | 837 | | |||
852 | // Add root nodes. | 838 | // Add root nodes. | ||
853 | for (int i = 0; i < rowCount(); ++i) { | 839 | for (int i = 0; i < rowCount(); ++i) { | ||
854 | queue.append(QPersistentModelIndex(index(i, 0))); | 840 | queue.append(QPersistentModelIndex(index(i, 0))); | ||
Show All 14 Lines | 852 | } else { | |||
869 | } | 855 | } | ||
870 | } | 856 | } | ||
871 | } | 857 | } | ||
872 | 858 | | |||
873 | for (const QPersistentModelIndex& node : qAsConst(nodesToDelete)) { | 859 | for (const QPersistentModelIndex& node : qAsConst(nodesToDelete)) { | ||
874 | Archive::Entry *rawEntry = static_cast<Archive::Entry*>(node.internalPointer()); | 860 | Archive::Entry *rawEntry = static_cast<Archive::Entry*>(node.internalPointer()); | ||
875 | qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); | 861 | qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); | ||
876 | beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); | 862 | beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); | ||
877 | m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(NoTrailingSlash)); | | |||
878 | rawEntry->getParent()->removeEntryAt(rawEntry->row()); | 863 | rawEntry->getParent()->removeEntryAt(rawEntry->row()); | ||
879 | endRemoveRows(); | 864 | endRemoveRows(); | ||
880 | } | 865 | } | ||
881 | } | 866 | } | ||
882 | 867 | | |||
883 | void ArchiveModel::countEntriesAndSize() | 868 | void ArchiveModel::countEntriesAndSize() | ||
884 | { | 869 | { | ||
885 | // This function is used to count the number of folders/files and | 870 | // This function is used to count the number of folders/files and | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |