KUriFilter Class Reference
from PyKDE4.kio import *
Detailed Description
Manages the filtering of URIs.
The intention of this plugin class is to allow people to extend the functionality of KUrl without modifying it directly. This way KUrl will remain a generic parser capable of parsing any generic URL that adheres to specifications.
The KUriFilter class applies a number of filters to a URI and returns the filtered version whenever possible. The filters are implemented using plugins to provide easy extensibility of the filtering mechanism. New filters can be added in the future by simply inheriting from KUriFilterPlugin and implementing the KUriFilterPlugin.filterUri method.
Use of this plugin-manager class is straight forward. Since it is a singleton object, all you have to do is obtain an instance by doing KUriFilter.self() and use any of the public member functions to preform the filtering.
Example
To simply filter a given string:
bool filtered = KUriFilter.self()->filterUri( "kde.org" );
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 u = KUriFilter.self()->filteredUri( "kde.org" );
You can also restrict the filter(s) to be used by supplying the name of the filter(s) to use. By defualt all available filters will be 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. The first one uses a single filter called kshorturifilter while the second example uses multiple filters:
QString text = "kde.org"; bool filtered = KUriFilter.self()->filterUri( text, "kshorturifilter" );
QStringList list; list << "kshorturifilter" << "localdomainfilter"; bool filtered = KUriFilter.self()->filterUri( text, list );
KUriFilter also allows richer data exchange through a simple meta-object called KUriFilterData. Using this meta-object you can find out more information about the URL you want to filter. See KUriFilterData for examples and details.
Filters a given URL into its proper format whenever possible.
Methods | |
__init__ (self) | |
__init__ (self, KUriFilter other) | |
bool | filterUri (self, KUriFilterData data, QStringList filters=QStringList()) |
bool | filterUri (self, KUrl uri, QStringList filters=QStringList()) |
bool | filterUri (self, QString uri, QStringList filters=QStringList()) |
KUrl | filteredUri (self, KUrl uri, QStringList filters=QStringList()) |
QString | filteredUri (self, QString uri, QStringList filters=QStringList()) |
loadPlugins (self) | |
QStringList | pluginNames (self) |
Static Methods | |
KUriFilter | self () |
Method Documentation
__init__ | ( | self ) |
A protected constructor.
This constructor creates a KUriFilter and initializes all plugins it can find by invoking loadPlugins.
__init__ | ( | self, | ||
KUriFilter | other | |||
) |
bool filterUri | ( | self, | ||
KUriFilterData | data, | |||
QStringList | filters=QStringList() | |||
) |
Filters the URI given by the object UriFilterData.
The given URL is filtered based on the specified list of filters. If the list is empty all available filters would be used.
- Parameters:
-
data object that contains the URI to be filtered. filters specify the list of filters to be used.
- Returns:
- a boolean indicating whether the URI has been changed
bool filterUri | ( | self, | ||
KUrl | uri, | |||
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:
-
uri the URI to filter. filters specify the list of filters to be used.
- Returns:
- a boolean indicating whether the URI has been changed
bool filterUri | ( | self, | ||
QString | uri, | |||
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:
-
uri The URI to filter. filters specify the list of filters to be used.
- Returns:
- a boolean indicating whether the URI has been changed
KUrl filteredUri | ( | self, | ||
KUrl | uri, | |||
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:
-
uri The URI to filter. filters specify the list of filters to be used.
- Returns:
- the filtered URI or null if it cannot be filtered
QString filteredUri | ( | self, | ||
QString | uri, | |||
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:
-
uri the URI to filter. filters specify the list of filters to be used.
- Returns:
- the filtered URI or null if it cannot be filtered
loadPlugins | ( | self ) |
Loads all allowed plugins.
This function loads all filters that have not been disbled.
QStringList pluginNames | ( | self ) |
Return a list of the names of all loaded plugins.
- Returns:
- a QStringList of plugin names
KUriFilter self | ( | ) |
Returns an instance of KUriFilter.