KIO

kurisearchfilter.cpp
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
23K_PLUGIN_CLASS_WITH_JSON(KUriSearchFilter, "kurisearchfilter.json")
24
25namespace
26{
27Q_LOGGING_CATEGORY(category, "kf.kio.urifilters.ikws", QtWarningMsg)
28}
29
30KUriSearchFilter::~KUriSearchFilter()
31{
32}
33
34bool 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
41 return false;
42 }
43
44 QString searchTerm;
45 auto filter = KIO::KURISearchFilterEngine::self();
46 SearchProvider *provider(filter->webShortcutQuery(data.typedString(), searchTerm));
47 if (!provider) {
48 return false;
49 }
50
51 const QUrl result = filter->formatResult(provider->query(), provider->charset(), QString(), searchTerm, true);
52 setFilteredUri(data, result);
53 setUriType(data, KUriFilterData::NetProtocol);
54 setSearchProvider(data, provider, searchTerm, QLatin1Char(filter->keywordDelimiter()));
55 return true;
56}
57
58#include "kurisearchfilter.moc"
59#include "moc_kurisearchfilter.cpp"
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
This class is a basic messaging class used to exchange filtering information between the filter plugi...
Definition kurifilter.h:153
QUrl uri() const
Returns the filtered or the original URL.
QString typedString() const
The string as typed by the user, before any URL processing is done.
@ Error
An incorrect URI (ex: "~johndoe" when user johndoe does not exist in that system)
Definition kurifilter.h:166
@ NetProtocol
Any network protocol: http, ftp, nttp, pop3, etc...
Definition kurifilter.h:159
@ Unknown
A URI that is not identified. Default value when a KUriFilterData is first created.
Definition kurifilter.h:167
UriTypes uriType() const
Returns the URI type.
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:48:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.