File indexing completed on 2024-04-28 03:55:43

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0004     SPDX-FileCopyrightText: 2000 Yves Arrouye <yves@realnames.com>
0005     SPDX-FileCopyrightText: 2002, 2003 Dawit Alemayehu <adawit@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "kurisearchfilter.h"
0011 #include "kuriikwsfiltereng_p.h"
0012 #include "searchprovider.h"
0013 
0014 #include <KPluginFactory>
0015 
0016 #include <QDBusConnection>
0017 #include <QLoggingCategory>
0018 
0019 K_PLUGIN_CLASS_WITH_JSON(KUriSearchFilter, "kurisearchfilter.json")
0020 
0021 namespace
0022 {
0023 Q_LOGGING_CATEGORY(category, "kf.kio.urifilters.ikws", QtWarningMsg)
0024 }
0025 
0026 KUriSearchFilter::~KUriSearchFilter()
0027 {
0028 }
0029 
0030 bool KUriSearchFilter::filterUri(KUriFilterData &data) const
0031 {
0032     qCDebug(category) << data.typedString() << ":" << data.uri() << ", type =" << data.uriType();
0033 
0034     // some URLs like gg:www.kde.org are not accepted by QUrl, but we still want them
0035     // This means we also have to allow KUriFilterData::Error
0036     if (data.uriType() != KUriFilterData::Unknown && data.uriType() != KUriFilterData::Error) {
0037         return false;
0038     }
0039 
0040     QString searchTerm;
0041     auto filter = KIO::KURISearchFilterEngine::self();
0042     SearchProvider *provider(filter->webShortcutQuery(data.typedString(), searchTerm));
0043     if (!provider) {
0044         return false;
0045     }
0046 
0047     const QUrl result = filter->formatResult(provider->query(), provider->charset(), QString(), searchTerm, true);
0048     setFilteredUri(data, result);
0049     setUriType(data, KUriFilterData::NetProtocol);
0050     setSearchProvider(data, provider->name(), searchTerm, QLatin1Char(filter->keywordDelimiter()));
0051     return true;
0052 }
0053 
0054 #include "kurisearchfilter.moc"
0055 #include "moc_kurisearchfilter.cpp"