File indexing completed on 2024-04-21 04:57:28
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "kio_archive.h" 0008 0009 #include <K7Zip> 0010 #include <KAr> 0011 #include <KTar> 0012 #include <KZip> 0013 0014 #include <QCoreApplication> 0015 #include <QUrl> 0016 0017 #include "kio_archive_debug.h" 0018 0019 // Pseudo plugin class to embed meta data 0020 class KIOPluginForMetaData : public QObject 0021 { 0022 Q_OBJECT 0023 Q_PLUGIN_METADATA(IID "org.kde.kio.worker.archive" FILE "archive.json") 0024 }; 0025 0026 using namespace KIO; 0027 0028 extern "C" { 0029 int Q_DECL_EXPORT kdemain(int argc, char **argv); 0030 } 0031 0032 int kdemain(int argc, char **argv) 0033 { 0034 QCoreApplication app(argc, argv); 0035 app.setApplicationName(QLatin1String("kio_archive")); 0036 0037 qCDebug(KIO_ARCHIVE_LOG) << "Starting" << QCoreApplication::applicationPid(); 0038 0039 if (argc != 4) { 0040 fprintf(stderr, "Usage: kio_archive protocol domain-socket1 domain-socket2\n"); 0041 exit(-1); 0042 } 0043 0044 ArchiveProtocol worker(argv[1], argv[2], argv[3]); 0045 worker.dispatchLoop(); 0046 0047 qCDebug(KIO_ARCHIVE_LOG) << "Done"; 0048 return 0; 0049 } 0050 0051 ArchiveProtocol::ArchiveProtocol(const QByteArray &proto, const QByteArray &pool, const QByteArray &app) 0052 : ArchiveProtocolBase(proto, pool, app) 0053 { 0054 qCDebug(KIO_ARCHIVE_LOG); 0055 } 0056 0057 KArchive *ArchiveProtocol::createArchive(const QString &proto, const QString &archiveFile) 0058 { 0059 if (proto == QLatin1String("ar")) { 0060 qCDebug(KIO_ARCHIVE_LOG) << "Opening KAr on " << archiveFile; 0061 return new KAr(archiveFile); 0062 } else if (proto == QLatin1String("tar")) { 0063 qCDebug(KIO_ARCHIVE_LOG) << "Opening KTar on " << archiveFile; 0064 return new KTar(archiveFile); 0065 } else if (proto == QLatin1String("zip")) { 0066 qCDebug(KIO_ARCHIVE_LOG) << "Opening KZip on " << archiveFile; 0067 return new KZip(archiveFile); 0068 } else if (proto == QLatin1String("sevenz")) { 0069 qCDebug(KIO_ARCHIVE_LOG) << "Opening K7Zip on " << archiveFile; 0070 return new K7Zip(archiveFile); 0071 } else { 0072 qCWarning(KIO_ARCHIVE_LOG) << "Protocol" << proto << "not supported by this IOWorker"; 0073 return nullptr; 0074 } 0075 } 0076 0077 // needed for JSON file embedding 0078 #include "kio_archive.moc" 0079 0080 // kate: space-indent on; indent-width 4; replace-tabs on;