File indexing completed on 2024-04-21 04:58:03
0001 /* This file is part of Webarchiver 0002 0003 SPDX-FileCopyrightText: 2001 Andreas Schlapbach <schlpbch@iam.unibe.ch> 0004 SPDX-FileCopyrightText: 2020 Jonathan Marten <jjm@keelhaul.me.uk> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "plugin_webarchiver.h" 0010 0011 #include <QIcon> 0012 #include <QUrl> 0013 #include <QStandardPaths> 0014 #include <QProcess> 0015 0016 #include <klocalizedstring.h> 0017 #include <kpluginfactory.h> 0018 #include <kactioncollection.h> 0019 #include <kmessagebox.h> 0020 0021 #include <kparts/readonlypart.h> 0022 0023 #include "webarchiverdebug.h" 0024 0025 K_PLUGIN_CLASS_WITH_JSON(PluginWebArchiver, "plugin_webarchiver.json") 0026 0027 PluginWebArchiver::PluginWebArchiver(QObject *parent, const QVariantList &args) 0028 : KonqParts::Plugin(parent) 0029 { 0030 QAction *a = actionCollection()->addAction(QStringLiteral("archivepage")); 0031 a->setText(i18n("Archive Web Page...")); 0032 a->setIcon(QIcon::fromTheme(QStringLiteral("webarchiver"))); 0033 connect(a, &QAction::triggered, this, &PluginWebArchiver::slotSaveToArchive); 0034 } 0035 0036 0037 void PluginWebArchiver::slotSaveToArchive() 0038 { 0039 KParts::ReadOnlyPart *part = qobject_cast<KParts::ReadOnlyPart *>(parent()); 0040 if (part==nullptr) return; 0041 0042 const QUrl pageUrl = part->url(); 0043 if (!pageUrl.isValid()) return; 0044 0045 const QString helper = QStandardPaths::findExecutable("kcreatewebarchive"); 0046 if (helper.isEmpty()) 0047 { 0048 KMessageBox::error(part->widget(), 0049 xi18nc("@info", "Cannot find the <command>kcreatewebarchive</command> executable,<nl/>check the plugin and helper installation."), 0050 i18n("Cannot Create Web Archive")); 0051 return; 0052 } 0053 0054 qCDebug(WEBARCHIVERPLUGIN_LOG) << "Executing" << helper; 0055 QProcess::startDetached(helper, (QStringList() << pageUrl.url())); 0056 } 0057 0058 0059 #include "plugin_webarchiver.moc"