Changeset View
Changeset View
Standalone View
Standalone View
part/archivemodel.cpp
Show First 20 Lines • Show All 301 Lines • ▼ Show 20 Line(s) | 295 | { | |||
---|---|---|---|---|---|
302 | if (archive()->isReadOnly() || | 302 | if (archive()->isReadOnly() || | ||
303 | (archive()->encryptionType() != Archive::Unencrypted && | 303 | (archive()->encryptionType() != Archive::Unencrypted && | ||
304 | archive()->password().isEmpty())) { | 304 | archive()->password().isEmpty())) { | ||
305 | emit messageWidget(KMessageWidget::Error, i18n("Adding files is not supported for this archive.")); | 305 | emit messageWidget(KMessageWidget::Error, i18n("Adding files is not supported for this archive.")); | ||
306 | return false; | 306 | return false; | ||
307 | } | 307 | } | ||
308 | 308 | | |||
309 | QStringList paths; | 309 | QStringList paths; | ||
310 | foreach(const QUrl &url, data->urls()) { | 310 | const auto urls = data->urls(); | ||
311 | for (const QUrl &url : urls) { | ||||
311 | paths << url.toLocalFile(); | 312 | paths << url.toLocalFile(); | ||
312 | } | 313 | } | ||
313 | 314 | | |||
314 | const Archive::Entry *entry = nullptr; | 315 | const Archive::Entry *entry = nullptr; | ||
315 | QModelIndex droppedOnto = index(row, column, parent); | 316 | QModelIndex droppedOnto = index(row, column, parent); | ||
316 | if (droppedOnto.isValid()) { | 317 | if (droppedOnto.isValid()) { | ||
317 | entry = entryForIndex(droppedOnto); | 318 | entry = entryForIndex(droppedOnto); | ||
318 | if (!entry->isDir()) { | 319 | if (!entry->isDir()) { | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 364 | if (s_previousPieces->count() == pieces.count()) { | |||
375 | if (equal) { | 376 | if (equal) { | ||
376 | return s_previousMatch; | 377 | return s_previousMatch; | ||
377 | } | 378 | } | ||
378 | } | 379 | } | ||
379 | } | 380 | } | ||
380 | 381 | | |||
381 | Archive::Entry *parent = m_rootEntry.data(); | 382 | Archive::Entry *parent = m_rootEntry.data(); | ||
382 | 383 | | |||
383 | foreach(const QString &piece, pieces) { | 384 | for (const QString &piece : qAsConst(pieces)) { | ||
384 | Archive::Entry *entry = parent->find(piece); | 385 | Archive::Entry *entry = parent->find(piece); | ||
385 | if (!entry) { | 386 | if (!entry) { | ||
386 | // Directory entry will be traversed later (that happens for some archive formats, 7z for instance). | 387 | // Directory entry will be traversed later (that happens for some archive formats, 7z for instance). | ||
387 | // We have to create one before, in order to construct tree from its children, | 388 | // We have to create one before, in order to construct tree from its children, | ||
388 | // and then delete the existing one (see ArchiveModel::newEntry). | 389 | // and then delete the existing one (see ArchiveModel::newEntry). | ||
389 | entry = new Archive::Entry(parent); | 390 | entry = new Archive::Entry(parent); | ||
390 | 391 | | |||
391 | entry->setProperty("fullPath", (parent == m_rootEntry.data()) | 392 | entry->setProperty("fullPath", (parent == m_rootEntry.data()) | ||
▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | 737 | if (destinationParts.count() > 0) { | |||
737 | destination = m_rootEntry->findByPath(destinationParts); | 738 | destination = m_rootEntry->findByPath(destinationParts); | ||
738 | } else { | 739 | } else { | ||
739 | destination = m_rootEntry.data(); | 740 | destination = m_rootEntry.data(); | ||
740 | } | 741 | } | ||
741 | } | 742 | } | ||
742 | const Archive::Entry *lastDirEntry = destination; | 743 | const Archive::Entry *lastDirEntry = destination; | ||
743 | QString skippedDirPath; | 744 | QString skippedDirPath; | ||
744 | 745 | | |||
745 | foreach (const QString &entry, entries) { | 746 | for (const QString &entry : entries) { | ||
746 | if (skippedDirPath.count() > 0 && entry.startsWith(skippedDirPath)) { | 747 | if (skippedDirPath.count() > 0 && entry.startsWith(skippedDirPath)) { | ||
747 | continue; | 748 | continue; | ||
748 | } else { | 749 | } else { | ||
749 | skippedDirPath.clear(); | 750 | skippedDirPath.clear(); | ||
750 | } | 751 | } | ||
751 | 752 | | |||
752 | while (!entry.startsWith(lastDirEntry->fullPath())) { | 753 | while (!entry.startsWith(lastDirEntry->fullPath())) { | ||
753 | lastDirEntry = lastDirEntry->getParent(); | 754 | lastDirEntry = lastDirEntry->getParent(); | ||
Show All 27 Lines | |||||
781 | } | 782 | } | ||
782 | 783 | | |||
783 | return error; | 784 | return error; | ||
784 | } | 785 | } | ||
785 | 786 | | |||
786 | bool ArchiveModel::hasDuplicatedEntries(const QStringList &entries) | 787 | bool ArchiveModel::hasDuplicatedEntries(const QStringList &entries) | ||
787 | { | 788 | { | ||
788 | QStringList tempList; | 789 | QStringList tempList; | ||
789 | foreach (const QString &entry, entries) { | 790 | for (const QString &entry : entries) { | ||
790 | if (tempList.contains(entry)) { | 791 | if (tempList.contains(entry)) { | ||
791 | return true; | 792 | return true; | ||
792 | } | 793 | } | ||
793 | tempList << entry; | 794 | tempList << entry; | ||
794 | } | 795 | } | ||
795 | return false; | 796 | return false; | ||
796 | } | 797 | } | ||
797 | 798 | | |||
798 | QMap<QString, Archive::Entry*> ArchiveModel::entryMap(const QVector<Archive::Entry*> &entries) | 799 | QMap<QString, Archive::Entry*> ArchiveModel::entryMap(const QVector<Archive::Entry*> &entries) | ||
799 | { | 800 | { | ||
800 | QMap<QString, Archive::Entry*> map; | 801 | QMap<QString, Archive::Entry*> map; | ||
801 | foreach (Archive::Entry *entry, entries) { | 802 | for (Archive::Entry *entry : entries) { | ||
802 | map.insert(entry->fullPath(), entry); | 803 | map.insert(entry->fullPath(), entry); | ||
803 | } | 804 | } | ||
804 | return map; | 805 | return map; | ||
805 | } | 806 | } | ||
806 | 807 | | |||
807 | const QHash<QString, QIcon> ArchiveModel::entryIcons() const | 808 | const QHash<QString, QIcon> ArchiveModel::entryIcons() const | ||
808 | { | 809 | { | ||
809 | return m_entryIcons; | 810 | return m_entryIcons; | ||
Show All 20 Lines | 828 | if (!hasChildren(node)) { | |||
830 | } | 831 | } | ||
831 | } else { | 832 | } else { | ||
832 | for (int i = 0; i < rowCount(node); ++i) { | 833 | for (int i = 0; i < rowCount(node); ++i) { | ||
833 | queue.append(QPersistentModelIndex(index(i, 0, node))); | 834 | queue.append(QPersistentModelIndex(index(i, 0, node))); | ||
834 | } | 835 | } | ||
835 | } | 836 | } | ||
836 | } | 837 | } | ||
837 | 838 | | |||
838 | foreach(const QPersistentModelIndex& node, nodesToDelete) { | 839 | for (const QPersistentModelIndex& node : qAsConst(nodesToDelete)) { | ||
839 | Archive::Entry *rawEntry = static_cast<Archive::Entry*>(node.internalPointer()); | 840 | Archive::Entry *rawEntry = static_cast<Archive::Entry*>(node.internalPointer()); | ||
840 | qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); | 841 | qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); | ||
841 | beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); | 842 | beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); | ||
842 | m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(NoTrailingSlash)); | 843 | m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(NoTrailingSlash)); | ||
843 | rawEntry->getParent()->removeEntryAt(rawEntry->row()); | 844 | rawEntry->getParent()->removeEntryAt(rawEntry->row()); | ||
844 | endRemoveRows(); | 845 | endRemoveRows(); | ||
845 | } | 846 | } | ||
846 | } | 847 | } | ||
Show All 16 Lines | 850 | { | |||
863 | 864 | | |||
864 | traverseAndCountDirNode(m_rootEntry.data()); | 865 | traverseAndCountDirNode(m_rootEntry.data()); | ||
865 | 866 | | |||
866 | qCDebug(ARK) << "Time to count entries and size:" << timer.elapsed() << "ms"; | 867 | qCDebug(ARK) << "Time to count entries and size:" << timer.elapsed() << "ms"; | ||
867 | } | 868 | } | ||
868 | 869 | | |||
869 | void ArchiveModel::traverseAndCountDirNode(Archive::Entry *dir) | 870 | void ArchiveModel::traverseAndCountDirNode(Archive::Entry *dir) | ||
870 | { | 871 | { | ||
871 | foreach(Archive::Entry *entry, dir->entries()) { | 872 | const auto entries = dir->entries(); | ||
873 | for (Archive::Entry *entry : entries) { | ||||
872 | if (entry->isDir()) { | 874 | if (entry->isDir()) { | ||
873 | traverseAndCountDirNode(entry); | 875 | traverseAndCountDirNode(entry); | ||
874 | m_numberOfFolders++; | 876 | m_numberOfFolders++; | ||
875 | } else { | 877 | } else { | ||
876 | m_numberOfFiles++; | 878 | m_numberOfFiles++; | ||
877 | m_uncompressedSize += entry->property("size").toULongLong(); | 879 | m_uncompressedSize += entry->property("size").toULongLong(); | ||
878 | } | 880 | } | ||
879 | } | 881 | } | ||
Show All 26 Lines |