File indexing completed on 2024-04-28 05:47:34

0001 /*
0002     SPDX-FileCopyrightText: 2009 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "extractHereDndPlugin.h"
0008 #include "archive_kerfuffle.h"
0009 #include "ark_debug.h"
0010 #include "batchextract.h"
0011 #include "pluginmanager.h"
0012 
0013 #include <QAction>
0014 
0015 #include <KFileItemListProperties>
0016 #include <KLocalizedString>
0017 #include <KPluginFactory>
0018 
0019 K_PLUGIN_CLASS_WITH_JSON(ExtractHereDndPlugin, "ark_dndextract.json")
0020 
0021 void ExtractHereDndPlugin::slotTriggered()
0022 {
0023     qCDebug(ARK) << "Preparing job";
0024     BatchExtract *batchJob = new BatchExtract();
0025 
0026     batchJob->setAutoSubfolder(true);
0027     batchJob->setDestinationFolder(m_dest.toDisplayString(QUrl::PreferLocalFile));
0028     batchJob->setPreservePaths(true);
0029     for (const QUrl &url : std::as_const(m_urls)) {
0030         batchJob->addInput(url);
0031     }
0032 
0033     qCDebug(ARK) << "Starting job";
0034     batchJob->start();
0035 }
0036 
0037 ExtractHereDndPlugin::ExtractHereDndPlugin(QObject *parent, const QVariantList &)
0038     : KIO::DndPopupMenuPlugin(parent)
0039 {
0040 }
0041 
0042 QList<QAction *> ExtractHereDndPlugin::setup(const KFileItemListProperties &popupMenuInfo, const QUrl &destination)
0043 {
0044     QList<QAction *> actionList;
0045 
0046     Kerfuffle::PluginManager pluginManager;
0047     if (!pluginManager.supportedMimeTypes().contains(popupMenuInfo.mimeType())) {
0048         qCDebug(ARK) << popupMenuInfo.mimeType() << "is not a supported mimetype";
0049         return actionList;
0050     }
0051 
0052     qCDebug(ARK) << "Plugin executed";
0053 
0054     const QString extractHereMessage = i18nc("@action:inmenu Context menu shown when an archive is being drag'n'dropped", "Extract here");
0055 
0056     QAction *action = new QAction(QIcon::fromTheme(QStringLiteral("archive-extract")), extractHereMessage, nullptr);
0057     connect(action, &QAction::triggered, this, &ExtractHereDndPlugin::slotTriggered);
0058 
0059     actionList.append(action);
0060     m_dest = destination;
0061     m_urls = popupMenuInfo.urlList();
0062 
0063     return actionList;
0064 }
0065 
0066 #include "extractHereDndPlugin.moc"
0067 #include "moc_extractHereDndPlugin.cpp"