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 | #include <QDBusConnection> |
18 | #include <QLoggingCategory> |
19 | |
20 | K_PLUGIN_CLASS_WITH_JSON(KUriSearchFilter, "kurisearchfilter.json" ) |
21 | |
22 | namespace |
23 | { |
24 | Q_LOGGING_CATEGORY(category, "kf.kio.urifilters.ikws" , QtWarningMsg) |
25 | } |
26 | |
27 | KUriSearchFilter::~KUriSearchFilter() |
28 | { |
29 | } |
30 | |
31 | bool KUriSearchFilter::filterUri(KUriFilterData &data) const |
32 | { |
33 | qCDebug(category) << data.typedString() << ":" << data.uri() << ", type =" << data.uriType(); |
34 | |
35 | // some URLs like gg:www.kde.org are not accepted by QUrl, but we still want them |
36 | // This means we also have to allow KUriFilterData::Error |
37 | if (data.uriType() != KUriFilterData::Unknown && data.uriType() != KUriFilterData::Error) { |
38 | return false; |
39 | } |
40 | |
41 | QString searchTerm; |
42 | auto filter = KIO::KURISearchFilterEngine::self(); |
43 | SearchProvider *provider(filter->webShortcutQuery(typedString: data.typedString(), searchTerm)); |
44 | if (!provider) { |
45 | return false; |
46 | } |
47 | |
48 | const QUrl result = filter->formatResult(url: provider->query(), cset1: provider->charset(), cset2: QString(), query: searchTerm, isMalformed: true); |
49 | setFilteredUri(data, uri: result); |
50 | setUriType(data, type: KUriFilterData::NetProtocol); |
51 | setSearchProvider(data, provider, term: searchTerm, separator: QLatin1Char(filter->keywordDelimiter())); |
52 | return true; |
53 | } |
54 | |
55 | #include "kurisearchfilter.moc" |
56 | #include "moc_kurisearchfilter.cpp" |
57 | |