KUriFilterData

Search for usage in LXR

KUriFilterData Class Reference

#include <KUriFilter>

Public Types

enum  SearchFilterOption { SearchFilterOptionNone = 0x0 , RetrieveSearchProvidersOnly = 0x01 , RetrievePreferredSearchProvidersOnly = 0x02 , RetrieveAvailableSearchProvidersOnly = (RetrievePreferredSearchProvidersOnly | RetrieveSearchProvidersOnly) }
 
typedef QFlags< SearchFilterOptionSearchFilterOptions
 
enum  UriTypes {
  NetProtocol = 0 , LocalFile , LocalDir , Executable ,
  Help , Shell , Blocked , Error ,
  Unknown
}
 

Public Member Functions

 KUriFilterData ()
 
 KUriFilterData (const KUriFilterData &other)
 
 KUriFilterData (const QString &url)
 
 KUriFilterData (const QUrl &url)
 
 ~KUriFilterData ()
 
QString absolutePath () const
 
QStringList allQueriesForSearchProvider (const QString &provider) const
 
QString alternateDefaultSearchProvider () const
 
QStringList alternateSearchProviders () const
 
QString argsAndOptions () const
 
bool checkForExecutables () const
 
QString defaultUrlScheme () const
 
QString errorMsg () const
 
bool hasAbsolutePath () const
 
bool hasArgsAndOptions () const
 
QString iconName ()
 
QString iconNameForPreferredSearchProvider (const QString &provider) const
 
KUriFilterDataoperator= (const QString &url)
 
KUriFilterDataoperator= (const QUrl &url)
 
QStringList preferredSearchProviders () const
 
QString queryForPreferredSearchProvider (const QString &provider) const
 
KUriFilterSearchProvider queryForSearchProvider (const QString &provider) const
 
SearchFilterOptions searchFilteringOptions () const
 
QString searchProvider () const
 
QString searchTerm () const
 
QChar searchTermSeparator () const
 
bool setAbsolutePath (const QString &abs_path)
 
void setAlternateDefaultSearchProvider (const QString &provider)
 
void setAlternateSearchProviders (const QStringList &providers)
 
void setCheckForExecutables (bool check)
 
void setData (const QString &url)
 
void setData (const QUrl &url)
 
void setDefaultUrlScheme (const QString &)
 
void setSearchFilteringOptions (SearchFilterOptions options)
 
QString typedString () const
 
QUrl uri () const
 
UriTypes uriType () const
 

Detailed Description

This class is a basic messaging class used to exchange filtering information between the filter plugins and the application requesting the filtering service.

Use this object if you require a more detailed information about the URI you want to filter. Any application can create an instance of this class and send it to KUriFilter to have the plugins fill out all possible information about the URI.

On successful filtering you can use uriType() to determine what type of resource the request was filtered into. See KUriFilter::UriTypes for details. If an error is encountered, then KUriFilter::Error is returned. You can use errorMsg to obtain the error information.

The functions in this class are not reentrant.

Example

Here is a basic example of how this class is used with KUriFilter:

KUriFilterData filterData (QLatin1String("kde.org"));
bool filtered = KUriFilter::self()->filterUri(filterData);
This class is a basic messaging class used to exchange filtering information between the filter plugi...
Definition kurifilter.h:153
static KUriFilter * self()
Returns an instance of KUriFilter.
bool filterUri(KUriFilterData &data, const QStringList &filters=QStringList())
Filters data using the specified filters.

If you are only interested in getting the list of preferred search providers, then you can do the following:

data.setData("<text-to-search-for>");
data.setSearchFilteringOption(KUriFilterData::RetrievePreferredSearchProvidersOnly);
bool filtered = KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter);
void setData(const QUrl &url)
Same as above except the argument is a URL.
bool filterSearchUri(KUriFilterData &data, SearchFilterTypes types)
Filter data using the criteria specified by types.

A class for exchanging filtering information.

Author
Dawit Alemayehu <adawit at kde.org>

Definition at line 152 of file kurifilter.h.

Member Typedef Documentation

◆ SearchFilterOptions

Stores a combination of SearchFilterOption values.

Definition at line 202 of file kurifilter.h.

Member Enumeration Documentation

◆ SearchFilterOption

This enum describes the search filtering options to be used.

  • SearchFilterOptionNone No search filter options are set and normal filtering is performed on the input data.
  • RetrieveSearchProvidersOnly If set, the list of all available search providers are returned without any input filtering. This flag only applies when used in conjunction with the KUriFilter::NormalTextFilter flag.
  • RetrievePreferredSearchProvidersOnly If set, the list of preferred search providers are returned without any input filtering. This flag only applies when used in conjunction with the KUriFilter::NormalTextFilter flag.
  • RetrieveAvailableSearchProvidersOnly Same as doing RetrievePreferredSearchProvidersOnly | RetrieveSearchProvidersOnly, where all available search providers are returned if no preferred ones ones are available. No input filtering will be performed.
See also
setSearchFilteringOptions
KUriFilter::filterSearchUri
SearchFilterOptions

Definition at line 193 of file kurifilter.h.

◆ UriTypes

Describes the type of the URI that was filtered.

Enumerator
NetProtocol 

Any network protocol: http, ftp, nttp, pop3, etc...

LocalFile 

A local file whose executable flag is not set.

LocalDir 

A local directory.

Executable 

A local file whose executable flag is set.

Help 

A man or info page.

Shell 

A shell executable (ex: echo "Test..." >> ~/testfile)

Blocked 

A URI that should be blocked/filtered (ex: ad filtering)

Error 

An incorrect URI (ex: "~johndoe" when user johndoe does not exist in that system)

Unknown 

A URI that is not identified. Default value when a KUriFilterData is first created.

Definition at line 158 of file kurifilter.h.

Constructor & Destructor Documentation

◆ KUriFilterData() [1/4]

KUriFilterData::KUriFilterData ( )

Default constructor.

Creates a UriFilterData object.

Definition at line 159 of file kurifilter.cpp.

◆ KUriFilterData() [2/4]

KUriFilterData::KUriFilterData ( const QUrl & url)
explicit

Creates a KUriFilterData object from the given URL.

Parameters
urlis the URL to be filtered.

Definition at line 164 of file kurifilter.cpp.

◆ KUriFilterData() [3/4]

KUriFilterData::KUriFilterData ( const QString & url)
explicit

Creates a KUriFilterData object from the given string.

Parameters
urlis the string to be filtered.

Definition at line 169 of file kurifilter.cpp.

◆ KUriFilterData() [4/4]

KUriFilterData::KUriFilterData ( const KUriFilterData & other)

Copy constructor.

Creates a KUriFilterData object from another KURIFilterData object.

Parameters
otherthe uri filter data to be copied.

Definition at line 174 of file kurifilter.cpp.

◆ ~KUriFilterData()

KUriFilterData::~KUriFilterData ( )
default

Destructor.

Member Function Documentation

◆ absolutePath()

QString KUriFilterData::absolutePath ( ) const

Returns the absolute path if one has already been set.

Returns
the absolute path, or QString()
See also
hasAbsolutePath()

Definition at line 196 of file kurifilter.cpp.

◆ allQueriesForSearchProvider()

QStringList KUriFilterData::allQueriesForSearchProvider ( const QString & provider) const

Returns all the query urls for the given search provider.

Use this function to obtain all the different queries that can be used for the given provider. For example, if a search engine provider named "foobar" has web shortcuts named "foobar", "foo" and "bar", then this function, unlike queryForPreferredSearchProvider, will return a a query for each and every web shortcut.

See also
queryForPreferredSearchProvider

Definition at line 266 of file kurifilter.cpp.

◆ alternateDefaultSearchProvider()

QString KUriFilterData::alternateDefaultSearchProvider ( ) const

Returns the search provider to use when a default provider is not available.

This function returns an empty string if setAlternateDefaultSearchProvider was not called to set the default search provider to be used when none has been chosen by the user through the search configuration module.

See also
setAlternateDefaultSearchProvider

Definition at line 289 of file kurifilter.cpp.

◆ alternateSearchProviders()

QStringList KUriFilterData::alternateSearchProviders ( ) const

Returns the list of alternate search providers.

This function returns an empty list if setAlternateSearchProviders was not called to set the alternate search providers to be when no preferred providers have been chosen by the user through the search configuration module.

See also
setAlternatteSearchProviders
preferredSearchProviders

Definition at line 284 of file kurifilter.cpp.

◆ argsAndOptions()

QString KUriFilterData::argsAndOptions ( ) const

Returns the command line options and arguments for a local resource when present.

Returns
options and arguments when present, otherwise QString()

Definition at line 206 of file kurifilter.cpp.

◆ checkForExecutables()

bool KUriFilterData::checkForExecutables ( ) const
Returns
true if the filters should attempt to check whether the supplied uri is an executable. False otherwise.

Definition at line 216 of file kurifilter.cpp.

◆ defaultUrlScheme()

QString KUriFilterData::defaultUrlScheme ( ) const

Returns the default protocol to use when filtering potentially valid url inputs.

By default this function will return an empty string.

See also
setDefaultUrlScheme

Definition at line 294 of file kurifilter.cpp.

◆ errorMsg()

QString KUriFilterData::errorMsg ( ) const

Returns an error message.

This functions returns the error message set by the plugin whenever the uri type is set to KUriFilterData::ERROR. Otherwise, it returns a nullptr string.

Returns
the error message or a nullptr when there is none.

Definition at line 186 of file kurifilter.cpp.

◆ hasAbsolutePath()

bool KUriFilterData::hasAbsolutePath ( ) const

Checks whether the supplied data had an absolute path.

Returns
true if the supplied data has an absolute path
See also
absolutePath()

Definition at line 201 of file kurifilter.cpp.

◆ hasArgsAndOptions()

bool KUriFilterData::hasArgsAndOptions ( ) const

Checks whether the current data is a local resource with command line options and arguments.

Returns
true if the current data has command line options and arguments

Definition at line 211 of file kurifilter.cpp.

◆ iconName()

QString KUriFilterData::iconName ( )

The name of the icon that matches the current filtered URL.

This function returns a null string by default and when no icon is found for the filtered URL.

Definition at line 304 of file kurifilter.cpp.

◆ iconNameForPreferredSearchProvider()

QString KUriFilterData::iconNameForPreferredSearchProvider ( const QString & provider) const

Returns the icon associated with the given preferred search provider.

You can use this function to obtain the icon names associated with the preferred search providers returned by preferredSearchProviders.

See also
preferredSearchProviders

Definition at line 275 of file kurifilter.cpp.

◆ operator=() [1/2]

KUriFilterData & KUriFilterData::operator= ( const QString & url)

Overloaded assignment operator.

This function allows you to easily assign a QString to a KUriFilterData object.

Returns
an instance of a KUriFilterData object.

Definition at line 371 of file kurifilter.cpp.

◆ operator=() [2/2]

KUriFilterData & KUriFilterData::operator= ( const QUrl & url)

Overloaded assignment operator.

This function allows you to easily assign a QUrl to a KUriFilterData object.

Returns
an instance of a KUriFilterData object.

Definition at line 365 of file kurifilter.cpp.

◆ preferredSearchProviders()

QStringList KUriFilterData::preferredSearchProviders ( ) const

Returns a list of the names of preferred or available search providers.

This function returns the list of providers marked as preferred whenever the input data, i.e. typedString, is successfully filtered.

If no default search provider has been selected prior to a filter request, this function will return an empty list. To avoid this problem you must either set an alternate default search provider using setAlternateDefaultSearchProvider or set one of the SearchFilterOption flags if you are only interested in getting the list of providers and not filtering the input.

Additionally, you can also provide alternate search providers in case there are no preferred ones already selected.

You can use queryForPreferredServiceProvider to obtain the query associated with the list of search providers returned by this function.

See also
setAlternateSearchProviders
setAlternateDefaultSearchProvider
setSearchFilteringOption
queryForPreferredServiceProvider

Definition at line 241 of file kurifilter.cpp.

◆ queryForPreferredSearchProvider()

QString KUriFilterData::queryForPreferredSearchProvider ( const QString & provider) const

Returns the web shortcut url for the given preferred search provider.

You can use this function to obtain the query for the preferred search providers returned by preferredSearchProviders.

The query returned by this function is in web shortcut format, i.e. "gg:foo bar", and must be re-filtered through KUriFilter to obtain a valid url.

See also
preferredSearchProviders

Definition at line 257 of file kurifilter.cpp.

◆ queryForSearchProvider()

KUriFilterSearchProvider KUriFilterData::queryForSearchProvider ( const QString & provider) const

Returns information about provider.

You can use this function to obtain the more information about the search providers returned by preferredSearchProviders.

See also
preferredSearchProviders
KUriFilterSearchProvider

Definition at line 246 of file kurifilter.cpp.

◆ searchFilteringOptions()

KUriFilterData::SearchFilterOptions KUriFilterData::searchFilteringOptions ( ) const

Returns the specified search filter options.

By default this function returns SearchFilterOptionNone.

See also
setSearchFilteringOptions

Definition at line 299 of file kurifilter.cpp.

◆ searchProvider()

QString KUriFilterData::searchProvider ( ) const

Returns the name of the search service provider, e.g. Google.

If typedString was not filtered by a search filter plugin, this function returns an empty string.

See also
typedString

Definition at line 236 of file kurifilter.cpp.

◆ searchTerm()

QString KUriFilterData::searchTerm ( ) const

Returns the search term portion of the typed string.

If the typedString was not filtered by a search filter plugin, this function returns an empty string.

See also
typedString

Definition at line 226 of file kurifilter.cpp.

◆ searchTermSeparator()

QChar KUriFilterData::searchTermSeparator ( ) const

Returns the character that is used to separate the search term from the keyword.

If typedString was not filtered by a search filter plugin, this function returns a null character.

See also
typedString

Definition at line 231 of file kurifilter.cpp.

◆ setAbsolutePath()

bool KUriFilterData::setAbsolutePath ( const QString & abs_path)

Sets the absolute path to be used whenever the supplied data is a relative local URL.

NOTE: This function should only be used for local resources, i.e. the "file:/" protocol. It is useful for specifying the absolute path in cases where the actual URL might be relative. If deriving the path from a QUrl, make sure you set the argument for this function to the result of calling path () instead of url ().

Parameters
abs_paththe absolute path to the local resource.
Returns
true if absolute path is successfully set. Otherwise, false.

Definition at line 329 of file kurifilter.cpp.

◆ setAlternateDefaultSearchProvider()

void KUriFilterData::setAlternateDefaultSearchProvider ( const QString & provider)

Sets the search provider to use in case no default provider is available.

The default search provider set using this function will only be used if the default and favorite search providers have not yet been selected by the user. Otherwise, the default provider specified by through function will be ignored.

See also
alternateDefaultSearchProvider
preferredSearchProviders

Definition at line 350 of file kurifilter.cpp.

◆ setAlternateSearchProviders()

void KUriFilterData::setAlternateSearchProviders ( const QStringList & providers)

Sets a list of search providers to use in case no preferred search providers are available.

The list of preferred search providers set using this function will only be used if the default and favorite search providers have not yet been selected by the user. Otherwise, the providers specified through this function will be ignored.

See also
alternateSearchProviders
preferredSearchProviders

Definition at line 345 of file kurifilter.cpp.

◆ setCheckForExecutables()

void KUriFilterData::setCheckForExecutables ( bool check)

Check whether the provided uri is executable or not.

Setting this to false ensures that typing the name of an executable does not start that application. This is useful in the location bar of a browser. The default value is true.

Definition at line 340 of file kurifilter.cpp.

◆ setData() [1/2]

void KUriFilterData::setData ( const QString & url)

Sets the URL to be filtered.

Use this function to set the string to be filtered when you construct an empty filter object.

Parameters
urlthe string to be filtered.

Definition at line 324 of file kurifilter.cpp.

◆ setData() [2/2]

void KUriFilterData::setData ( const QUrl & url)

Same as above except the argument is a URL.

Use this function to set the string to be filtered when you construct an empty filter object.

Parameters
urlthe URL to be filtered.

Definition at line 319 of file kurifilter.cpp.

◆ setDefaultUrlScheme()

void KUriFilterData::setDefaultUrlScheme ( const QString & scheme)

Sets the default scheme used when filtering potentially valid url inputs.

Use this function to change the default protocol used when filtering potentially valid url inputs. The default protocol is http.

If the scheme is specified without a separator, then "://" will be used as the separator by default. For example, if the default url scheme was simply set to "ftp", then a potentially valid url input such as "kde.org" will be filtered to "ftp://kde.org".

See also
defaultUrlScheme

Definition at line 355 of file kurifilter.cpp.

◆ setSearchFilteringOptions()

void KUriFilterData::setSearchFilteringOptions ( SearchFilterOptions options)

Sets the options used by search filter plugins to filter requests.

The default search filter option is SearchFilterOptionNone. See SearchFilterOption for the description of the other flags.

It is important to note that the options set through this function can prevent any filtering from being performed by search filter plugins. As such, uriTypes can return KUriFilterData::Unknown and uri can return an invalid url even though the filtering request returned a successful response.

See also
searchFilteringOptions

Definition at line 360 of file kurifilter.cpp.

◆ typedString()

QString KUriFilterData::typedString ( ) const

The string as typed by the user, before any URL processing is done.

Definition at line 221 of file kurifilter.cpp.

◆ uri()

QUrl KUriFilterData::uri ( ) const

Returns the filtered or the original URL.

If one of the plugins successfully filtered the original input, this function returns it. Otherwise, it will return the input itself.

Returns
the filtered or original url.

Definition at line 181 of file kurifilter.cpp.

◆ uriType()

KUriFilterData::UriTypes KUriFilterData::uriType ( ) const

Returns the URI type.

This method always returns KUriFilterData::UNKNOWN if the given URL was not filtered.

Returns
the type of the URI

Definition at line 191 of file kurifilter.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.