File indexing completed on 2024-05-19 05:50:48
0001 /* 0002 SPDX-FileCopyrightText: 2010-2011 Raphael Kubo da Costa <rakuco@FreeBSD.org> 0003 0004 SPDX-License-Identifier: BSD-2-Clause 0005 */ 0006 0007 #include "jsonarchiveinterface.h" 0008 #include "archiveentry.h" 0009 0010 #include <QFile> 0011 0012 JSONArchiveInterface::JSONArchiveInterface(QObject *parent, const QVariantList &args) 0013 : Kerfuffle::ReadWriteArchiveInterface(parent, args) 0014 { 0015 } 0016 0017 JSONArchiveInterface::~JSONArchiveInterface() 0018 { 0019 } 0020 0021 bool JSONArchiveInterface::list() 0022 { 0023 JSONParser::JSONArchive::const_iterator it = m_archive.constBegin(); 0024 for (; it != m_archive.constEnd(); ++it) { 0025 Q_EMIT entry(*it); 0026 } 0027 0028 return true; 0029 } 0030 0031 bool JSONArchiveInterface::open() 0032 { 0033 QFile file(filename()); 0034 0035 if (!file.exists()) { 0036 return false; 0037 } 0038 0039 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 0040 return false; 0041 } 0042 0043 m_archive = JSONParser::parse(&file); 0044 0045 return !m_archive.isEmpty(); 0046 } 0047 0048 bool JSONArchiveInterface::addFiles(const QVector<Kerfuffle::Archive::Entry *> &files, 0049 const Kerfuffle::Archive::Entry *destination, 0050 const Kerfuffle::CompressionOptions &options, 0051 uint numberOfEntriesToAdd) 0052 { 0053 Q_UNUSED(options) 0054 Q_UNUSED(numberOfEntriesToAdd) 0055 0056 for (const Kerfuffle::Archive::Entry *entry : files) { 0057 const QString &path = destination->fullPath() + entry->fullPath(); 0058 if (m_archive.contains(path)) { 0059 return false; 0060 } 0061 0062 Kerfuffle::Archive::Entry *e = new Kerfuffle::Archive::Entry(nullptr); 0063 e->setProperty("fullPath", path); 0064 0065 m_archive[path] = e; 0066 } 0067 0068 return true; 0069 } 0070 0071 bool JSONArchiveInterface::moveFiles(const QVector<Kerfuffle::Archive::Entry *> &files, 0072 Kerfuffle::Archive::Entry *destination, 0073 const Kerfuffle::CompressionOptions &options) 0074 { 0075 Q_UNUSED(files) 0076 Q_UNUSED(destination) 0077 Q_UNUSED(options) 0078 0079 return true; 0080 } 0081 0082 bool JSONArchiveInterface::copyFiles(const QVector<Kerfuffle::Archive::Entry *> &files, 0083 Kerfuffle::Archive::Entry *destination, 0084 const Kerfuffle::CompressionOptions &options) 0085 { 0086 Q_UNUSED(files) 0087 Q_UNUSED(destination) 0088 Q_UNUSED(options) 0089 0090 return false; 0091 } 0092 0093 bool JSONArchiveInterface::extractFiles(const QVector<Kerfuffle::Archive::Entry *> &files, 0094 const QString &destinationDirectory, 0095 const Kerfuffle::ExtractionOptions &options) 0096 { 0097 Q_UNUSED(files) 0098 Q_UNUSED(destinationDirectory) 0099 Q_UNUSED(options) 0100 0101 return true; 0102 } 0103 0104 bool JSONArchiveInterface::deleteFiles(const QVector<Kerfuffle::Archive::Entry *> &files) 0105 { 0106 for (const Kerfuffle::Archive::Entry *file : files) { 0107 const QString &fileName = file->fullPath(); 0108 if (m_archive.contains(fileName)) { 0109 m_archive.remove(fileName); 0110 Q_EMIT entryRemoved(fileName); 0111 } 0112 } 0113 0114 return true; 0115 } 0116 0117 bool JSONArchiveInterface::addComment(const QString &comment) 0118 { 0119 Q_UNUSED(comment) 0120 return true; 0121 } 0122 0123 bool JSONArchiveInterface::testArchive() 0124 { 0125 return true; 0126 } 0127 0128 #include "moc_jsonarchiveinterface.cpp"