• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KUriFilter Class Reference

#include <kurifilter.h>

Public Types

enum  SearchFilterType { NormalTextFilter = 0x01, WebShortcutFilter = 0x02 }
 

Public Member Functions

 ~KUriFilter ()
 
KUrl filteredUri (const KUrl &uri, const QStringList &filters=QStringList())
 
QString filteredUri (const QString &uri, const QStringList &filters=QStringList())
 
bool filterSearchUri (KUriFilterData &data)
 
bool filterSearchUri (KUriFilterData &data, SearchFilterTypes types)
 
bool filterUri (KUriFilterData &data, const QStringList &filters=QStringList())
 
bool filterUri (KUrl &uri, const QStringList &filters=QStringList())
 
bool filterUri (QString &uri, const QStringList &filters=QStringList())
 
QStringList pluginNames () const
 

Static Public Member Functions

static KUriFilter * self ()
 

Protected Member Functions

 KUriFilter ()
 
void loadPlugins ()
 

Detailed Description

KUriFilter applies a number of filters to a URI and returns a filtered version if any filter matches.

A simple example is "kde.org" to "http://www.kde.org", which is commonplace in web browsers.

The filters are implemented as plugins in KUriFilterPlugin subclasses.

KUriFilter is a singleton object: obtain the instance by calling KUriFilter::self() and use the public member functions to perform the filtering.

Example

To simply filter a given string:

QString url("kde.org");
bool filtered = KUriFilter::self()->filteredUri( url );

You can alternatively use a KUrl:

KUrl url("kde.org");
bool filtered = KUriFilter::self()->filterUri( url );

If you have a constant string or a constant URL, simply invoke the corresponding function to obtain the filtered string or URL instead of a boolean flag:

QString filteredText = KUriFilter::self()->filteredUri( "kde.org" );

All of the above examples should result in "kde.org" being filtered into "http://kde.org".

You can also restrict the filters to be used by supplying the name of the filters you want to use. By defualt all available filters are used.

To use specific filters, add the names of the filters you want to use to a QStringList and invoke the appropriate filtering function.

The examples below show the use of specific filters. KDE ships with the following filter plugins by default:

kshorturifilter: This is used for filtering potentially valid url inputs such as "kde.org" Additionally it filters shell variables and shortcuts such as $HOME and ~ as well as man and info page shortcuts, # and ## respectively.

kuriikwsfilter: This is used for filtering normal input text into a web search url using the configured fallback search engine selected by the user.

kurisearchfilter: This is used for filtering KDE webshortcuts. For example "gg:KDE" will be converted to a url for searching the work "KDE" using the Google search engine.

localdomainfilter: This is used for doing a DNS lookup to determine whether the input is a valid local address.

fixuphosturifilter: This is used to append "www." to the host name of a pre filtered http url if the original url cannot be resolved.

QString text ("kde.org");
bool filtered = KUriFilter::self()->filterUri(text, QLatin1String("kshorturifilter"));

The above code should result in "kde.org" being filtered into "http://kde.org".

QStringList list;
list << QLatin1String("kshorturifilter") << QLatin1String("localdomainfilter");
bool filtered = KUriFilter::self()->filterUri( text, list );

Additionally if you only want to do search related filtering, you can use the search specific function, filterSearchUri, that is available in KDE 4.5 and higher. For example, to search for a given input on the web you can do the following:

KUriFilterData filterData ("foo"); bool filtered = KUriFilter::self()->filterSearchUri(filterData, KUriFilterData::NormalTextFilter);

KUriFilter converts all filtering requests to use KUriFilterData internally. The use of this bi-directional class allows you to send specific instructions to the filter plugins as well as receive detailed information about the filtered request from them. See the documentation of KUriFilterData class for more examples and details.

All functions in this class are thread safe and reentrant.

Filters the given input into a valid url whenever possible.

Definition at line 871 of file kurifilter.h.

Member Enumeration Documentation

enum KUriFilter::SearchFilterType

This enum describes the types of search plugin filters available.

  • NormalTextFilter The plugin used to filter normal text, e.g. "some term to search".
  • WebShortcutFilter The plugin used to filter web shortcuts, e.g. gg:KDE.
Enumerator
NormalTextFilter 
WebShortcutFilter 

Definition at line 880 of file kurifilter.h.

Constructor & Destructor Documentation

KUriFilter::~KUriFilter ( )

Destructor.

Definition at line 607 of file kurifilter.cpp.

KUriFilter::KUriFilter ( )
protected

Constructor.

Creates a KUriFilter object and calls loadPlugins to load all available URI filter plugins.

Definition at line 601 of file kurifilter.cpp.

Member Function Documentation

KUrl KUriFilter::filteredUri ( const KUrl &  uri,
const QStringList &  filters = QStringList() 
)

Returns the filtered URI.

The given URL is filtered based on the specified list of filters. If the list is empty all available filters would be used.

Parameters
uriThe URI to filter.
filtersspecify the list of filters to be used.
Returns
the filtered URI or null if it cannot be filtered

Definition at line 653 of file kurifilter.cpp.

QString KUriFilter::filteredUri ( const QString &  uri,
const QStringList &  filters = QStringList() 
)

Return a filtered string representation of a URI.

The given URL is filtered based on the specified list of filters. If the list is empty all available filters would be used.

Parameters
urithe URI to filter.
filtersspecify the list of filters to be used.
Returns
the filtered URI or null if it cannot be filtered

Definition at line 660 of file kurifilter.cpp.

bool KUriFilter::filterSearchUri ( KUriFilterData &  data)

See filterSearchUri(KUriFilterData&, SearchFilterTypes)

Since
4.5
Deprecated:
Use filterSearchUri(KUriFilterData&, SearchFilterTypes) instead.

Definition at line 668 of file kurifilter.cpp.

bool KUriFilter::filterSearchUri ( KUriFilterData &  data,
SearchFilterTypes  types 
)

Filter data using the criteria specified by types.

The search filter type can be individual value of SearchFilterTypes or a combination of those types using the bitwise OR operator.

You can also use the flags from KUriFilterData::SearchFilterOption to alter the filtering mechanisms of the search filter providers.

Parameters
dataobject that contains the URI to be filtered.
typesthe search filters used to filter the request.
Returns
true if the specified data was successfully filtered.
See also
KUriFilterData::setSearchFilteringOptions
Since
4.6

Definition at line 674 of file kurifilter.cpp.

bool KUriFilter::filterUri ( KUriFilterData &  data,
const QStringList &  filters = QStringList() 
)

Filters data using the specified filters.

If no named filters are specified, the default, then all the URI filter plugins found will be used.

Parameters
dataobject that contains the URI to be filtered.
filtersspecify the list of filters to be used.
Returns
a boolean indicating whether the URI has been changed

Definition at line 612 of file kurifilter.cpp.

bool KUriFilter::filterUri ( KUrl &  uri,
const QStringList &  filters = QStringList() 
)

Filters the URI given by the URL.

The given URL is filtered based on the specified list of filters. If the list is empty all available filters would be used.

Parameters
urithe URI to filter.
filtersspecify the list of filters to be used.
Returns
a boolean indicating whether the URI has been changed

Definition at line 637 of file kurifilter.cpp.

bool KUriFilter::filterUri ( QString &  uri,
const QStringList &  filters = QStringList() 
)

Filters a string representing a URI.

The given URL is filtered based on the specified list of filters. If the list is empty all available filters would be used.

Parameters
uriThe URI to filter.
filtersspecify the list of filters to be used.
Returns
a boolean indicating whether the URI has been changed

Definition at line 645 of file kurifilter.cpp.

void KUriFilter::loadPlugins ( )
protected

Loads all allowed plugins.

This function only loads URI filter plugins that have not been disabled.

Definition at line 693 of file kurifilter.cpp.

QStringList KUriFilter::pluginNames ( ) const

Return a list of the names of all loaded plugins.

Returns
a QStringList of plugin names

Definition at line 688 of file kurifilter.cpp.

KUriFilter * KUriFilter::self ( )
static

Returns an instance of KUriFilter.

Definition at line 595 of file kurifilter.cpp.


The documentation for this class was generated from the following files:
  • kurifilter.h
  • kurifilter.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal