| 1 | /* |
| 2 | This file is part of the KDE project |
| 3 | SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> |
| 4 | SPDX-FileCopyrightText: 2000 Yves Arrouye <yves@realnames.com> |
| 5 | SPDX-FileCopyrightText: 2002, 2003 Dawit Alemayehu <adawit@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: GPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #include "kurisearchfilter.h" |
| 11 | #include "kurifilterdata_p.h" |
| 12 | #include "kuriikwsfiltereng_p.h" |
| 13 | #include "searchprovider.h" |
| 14 | |
| 15 | #include <KPluginFactory> |
| 16 | |
| 17 | #ifdef WITH_QTDBUS |
| 18 | #include <QDBusConnection> |
| 19 | #endif |
| 20 | |
| 21 | #include <QLoggingCategory> |
| 22 | |
| 23 | K_PLUGIN_CLASS_WITH_JSON(KUriSearchFilter, "kurisearchfilter.json" ) |
| 24 | |
| 25 | namespace |
| 26 | { |
| 27 | Q_LOGGING_CATEGORY(category, "kf.kio.urifilters.ikws" , QtWarningMsg) |
| 28 | } |
| 29 | |
| 30 | KUriSearchFilter::~KUriSearchFilter() |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | bool KUriSearchFilter::filterUri(KUriFilterData &data) const |
| 35 | { |
| 36 | qCDebug(category) << data.typedString() << ":" << data.uri() << ", type =" << data.uriType(); |
| 37 | |
| 38 | // some URLs like gg:www.kde.org are not accepted by QUrl, but we still want them |
| 39 | // This means we also have to allow KUriFilterData::Error |
| 40 | if (data.uriType() != KUriFilterData::Unknown && data.uriType() != KUriFilterData::Error) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | QString searchTerm; |
| 45 | auto filter = KIO::KURISearchFilterEngine::self(); |
| 46 | SearchProvider *provider(filter->webShortcutQuery(typedString: data.typedString(), searchTerm)); |
| 47 | if (!provider) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | const QUrl result = filter->formatResult(url: provider->query(), cset1: provider->charset(), cset2: QString(), query: searchTerm, isMalformed: true); |
| 52 | setFilteredUri(data, uri: result); |
| 53 | setUriType(data, type: KUriFilterData::NetProtocol); |
| 54 | setSearchProvider(data, provider, term: searchTerm, separator: QLatin1Char(filter->keywordDelimiter())); |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | #include "kurisearchfilter.moc" |
| 59 | #include "moc_kurisearchfilter.cpp" |
| 60 | |