File indexing completed on 2025-01-26 04:49:22
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 "adblockinterceptorinterface.h" 0008 #include "adblockinterceptor_debug.h" 0009 #include "adblockmanager.h" 0010 #include "globalsettings_webengineurlinterceptoradblock.h" 0011 #include <QAction> 0012 #include <QPointer> 0013 #include <QWebEngineView> 0014 0015 AdblockInterceptorInterface::AdblockInterceptorInterface(QObject *parent) 0016 : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent) 0017 { 0018 } 0019 0020 AdblockInterceptorInterface::~AdblockInterceptorInterface() = default; 0021 0022 bool AdblockInterceptorInterface::interceptRequest(QWebEngineUrlRequestInfo &info) 0023 { 0024 if (!AdBlockSettings::self()->adBlockEnabled()) { 0025 qDebug(ADBLOCKINTERCEPTOR_LOG) << "Disable at the moment"; 0026 return false; 0027 } 0028 qDebug(ADBLOCKINTERCEPTOR_LOG) << "Enabled at the moment"; 0029 return AdblockManager::self()->interceptRequest(info); 0030 } 0031 0032 QList<QAction *> AdblockInterceptorInterface::interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const 0033 { 0034 // TODO 0035 Q_UNUSED(result); 0036 QList<QAction *> lstAction; 0037 /* 0038 if (mAdblockManager->isEnabled()) { 0039 lstAction.append(mShowBlockableItems); 0040 if (!result.imageUrl().isEmpty()) { 0041 lstAction.append(mBlockImage); 0042 } 0043 mCurrentWebHitTest = result; 0044 } 0045 */ 0046 return lstAction; 0047 } 0048 0049 void AdblockInterceptorInterface::createActions(KActionCollection *ac) 0050 { 0051 // TODO 0052 Q_UNUSED(ac); 0053 /* 0054 if (ac) { 0055 mShowBlockableItems = new QAction(i18n("Open Blockable Items..."), this); 0056 ac->addAction(QStringLiteral("adblock_blockable_items"), mShowBlockableItems); 0057 connect(mShowBlockableItems, &QAction::triggered, this, &AdblockInterceptorInterface::slotShowBlockableElement); 0058 0059 mBlockImage = new QAction(i18n("Block Image"), this); 0060 ac->addAction(QStringLiteral("adblock_image"), mBlockImage); 0061 ac->setShortcutsConfigurable(mBlockImage, false); 0062 connect(mBlockImage, &QAction::triggered, this, &AdblockInterceptorInterface::slotBlockImage); 0063 } 0064 */ 0065 } 0066 0067 QWebEngineView *AdblockInterceptorInterface::webEngineView() const 0068 { 0069 return mWebEngineView; 0070 } 0071 0072 void AdblockInterceptorInterface::setWebEngineView(QWebEngineView *webEngineView) 0073 { 0074 mWebEngineView = webEngineView; 0075 } 0076 0077 #include "moc_adblockinterceptorinterface.cpp"