1 /* 2 SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #include "viewerpluginexpandurlinterface.h" 8 #include "expandurlplugin_debug.h" 9 #include <MessageViewer/ScamCheckShortUrl> 10 #include <MessageViewer/ScamCheckShortUrlManager> 11 #include <MessageViewer/ScamExpandUrlJob> 12 13 #include <QAction> 14 15 #include <KActionCollection> 16 #include <KLocalizedString> 17 #include <PimCommon/BroadcastStatus> 18 19 using namespace MessageViewer; 20 ViewerPluginExpandurlInterface(KActionCollection * ac,QWidget * parent)21ViewerPluginExpandurlInterface::ViewerPluginExpandurlInterface(KActionCollection *ac, QWidget *parent) 22 : ViewerPluginInterface(parent) 23 { 24 createAction(ac); 25 } 26 ~ViewerPluginExpandurlInterface()27ViewerPluginExpandurlInterface::~ViewerPluginExpandurlInterface() 28 { 29 } 30 actions() const31QList<QAction *> ViewerPluginExpandurlInterface::actions() const 32 { 33 return mAction; 34 } 35 execute()36void ViewerPluginExpandurlInterface::execute() 37 { 38 if (mCurrentUrl.isValid()) { 39 if (MessageViewer::ScamCheckShortUrlManager::self()->scamCheckShortUrl()->isShortUrl(mCurrentUrl)) { 40 auto job = new MessageViewer::ScamExpandUrlJob(this); 41 job->expandedUrl(mCurrentUrl); 42 } else { 43 PimCommon::BroadcastStatus::instance()->setStatusMsg(i18n("Current URL is not a shortened URL.")); 44 } 45 } else { 46 qCWarning(EXPANDURLPLUGIN_LOG) << "Url is not valid"; 47 } 48 } 49 featureTypes() const50ViewerPluginInterface::SpecificFeatureTypes ViewerPluginExpandurlInterface::featureTypes() const 51 { 52 return NeedUrl; 53 } 54 createAction(KActionCollection * ac)55void ViewerPluginExpandurlInterface::createAction(KActionCollection *ac) 56 { 57 if (ac) { 58 auto act = new QAction(i18n("Expand URL"), this); 59 ac->addAction(QStringLiteral("expand_short_url"), act); 60 ac->setShortcutsConfigurable(act, false); 61 connect(act, &QAction::triggered, this, &ViewerPluginExpandurlInterface::slotActivatePlugin); 62 mAction.append(act); 63 } 64 } 65 setUrl(const QUrl & url)66void ViewerPluginExpandurlInterface::setUrl(const QUrl &url) 67 { 68 mCurrentUrl = url; 69 } 70