File indexing completed on 2025-01-05 04:49:45
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "viewerpluginexpandurlinterface.h" 0008 #include "expandurlplugin_debug.h" 0009 #include <MessageViewer/ScamCheckShortUrl> 0010 #include <MessageViewer/ScamCheckShortUrlManager> 0011 #include <MessageViewer/ScamExpandUrlJob> 0012 0013 #include <QAction> 0014 0015 #include <KActionCollection> 0016 #include <KLocalizedString> 0017 #include <PimCommon/BroadcastStatus> 0018 0019 using namespace MessageViewer; 0020 0021 ViewerPluginExpandurlInterface::ViewerPluginExpandurlInterface(KActionCollection *ac, QWidget *parent) 0022 : ViewerPluginInterface(parent) 0023 { 0024 createAction(ac); 0025 } 0026 0027 ViewerPluginExpandurlInterface::~ViewerPluginExpandurlInterface() = default; 0028 0029 QList<QAction *> ViewerPluginExpandurlInterface::actions() const 0030 { 0031 return mAction; 0032 } 0033 0034 void ViewerPluginExpandurlInterface::execute() 0035 { 0036 if (mCurrentUrl.isValid()) { 0037 if (MessageViewer::ScamCheckShortUrlManager::self()->scamCheckShortUrl()->isShortUrl(mCurrentUrl)) { 0038 auto job = new MessageViewer::ScamExpandUrlJob(this); 0039 job->expandedUrl(mCurrentUrl); 0040 } else { 0041 PimCommon::BroadcastStatus::instance()->setStatusMsg(i18n("Current URL is not a shortened URL.")); 0042 } 0043 } else { 0044 qCWarning(EXPANDURLPLUGIN_LOG) << "Url is not valid"; 0045 } 0046 } 0047 0048 ViewerPluginInterface::SpecificFeatureTypes ViewerPluginExpandurlInterface::featureTypes() const 0049 { 0050 return NeedUrl; 0051 } 0052 0053 void ViewerPluginExpandurlInterface::createAction(KActionCollection *ac) 0054 { 0055 if (ac) { 0056 auto act = new QAction(i18n("Expand URL"), this); 0057 ac->addAction(QStringLiteral("expand_short_url"), act); 0058 ac->setShortcutsConfigurable(act, false); 0059 connect(act, &QAction::triggered, this, &ViewerPluginExpandurlInterface::slotActivatePlugin); 0060 mAction.append(act); 0061 } 0062 } 0063 0064 void ViewerPluginExpandurlInterface::setUrl(const QUrl &url) 0065 { 0066 mCurrentUrl = url; 0067 } 0068 0069 #include "moc_viewerpluginexpandurlinterface.cpp"