File indexing completed on 2024-05-19 05:00:09
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2004 Dario Massarin <nekkar@libero.it> 0004 Copyright (C) 2006 Manolo Valdes <nolis71cu@gmail.com> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 */ 0011 0012 #include "transfermultisegkiofactory.h" 0013 0014 #include "core/scheduler.h" 0015 #include "core/transfergroup.h" 0016 #include "multisegkiodatasource.h" 0017 #include "multisegkiosettings.h" 0018 #include "transfermultisegkio.h" 0019 0020 #include <QDomElement> 0021 0022 #include "kget_debug.h" 0023 #include "kget_macro.h" 0024 #include <QDebug> 0025 0026 K_PLUGIN_CLASS_WITH_JSON(TransferMultiSegKioFactory, "kget_multisegkiofactory.json") 0027 0028 TransferMultiSegKioFactory::TransferMultiSegKioFactory(QObject *parent, const QVariantList &args) 0029 : TransferFactory(parent, args) 0030 { 0031 } 0032 0033 TransferMultiSegKioFactory::~TransferMultiSegKioFactory() 0034 { 0035 } 0036 0037 Transfer *TransferMultiSegKioFactory::createTransfer(const QUrl &srcUrl, const QUrl &destUrl, TransferGroup *parent, Scheduler *scheduler, const QDomElement *e) 0038 { 0039 qCDebug(KGET_DEBUG); 0040 0041 if (isSupported(srcUrl) && (!e || !e->firstChildElement("factories").isNull())) { 0042 return new TransferMultiSegKio(parent, this, scheduler, srcUrl, destUrl, e); 0043 } 0044 return nullptr; 0045 } 0046 0047 TransferHandler *TransferMultiSegKioFactory::createTransferHandler(Transfer *transfer, Scheduler *scheduler) 0048 { 0049 return new TransferHandler(transfer, scheduler); 0050 } 0051 0052 QWidget *TransferMultiSegKioFactory::createDetailsWidget(TransferHandler *transfer) 0053 { 0054 Q_UNUSED(transfer) 0055 return nullptr; // Temporary!! 0056 } 0057 0058 const QList<QAction *> TransferMultiSegKioFactory::actions(TransferHandler *handler) 0059 { 0060 Q_UNUSED(handler) 0061 return QList<QAction *>(); 0062 } 0063 0064 TransferDataSource *TransferMultiSegKioFactory::createTransferDataSource(const QUrl &srcUrl, const QDomElement &type, QObject *parent) 0065 { 0066 qCDebug(KGET_DEBUG); 0067 0068 // only use this TransferDataSource if no type is specified and the protocols match 0069 if (!type.attribute("type").isEmpty()) { 0070 return nullptr; 0071 } 0072 0073 if (isSupported(srcUrl)) { 0074 return new MultiSegKioDataSource(srcUrl, parent); 0075 } 0076 return nullptr; 0077 } 0078 0079 bool TransferMultiSegKioFactory::isSupported(const QUrl &url) const 0080 { 0081 QString prot = url.scheme(); 0082 qCDebug(KGET_DEBUG) << "Protocol = " << prot; 0083 return addsProtocols().contains(prot); 0084 } 0085 0086 QStringList TransferMultiSegKioFactory::addsProtocols() const 0087 { 0088 static const QStringList protocols = QStringList() << "http" 0089 << "https" 0090 << "ftp" 0091 << "sftp"; 0092 return protocols; 0093 } 0094 0095 #include "moc_transfermultisegkiofactory.cpp" 0096 #include "transfermultisegkiofactory.moc"