KDE 4.5 PyKDE API Reference

- KDE's Python API

# 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 the KUriFilterPlugin class.

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 | filterSearchUri (self, KUriFilterData data)
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 ) |

Constructor.

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

__init__ | ( | self, |
|  | KUriFilter | other
| ) |  |  |

bool filterSearchUri | ( | self, |
|  | KUriFilterData | data
| ) |  |  |

Filters data using only the default search uri filter plugins.

Only use this function if you are sure that the input you want to filter is a search term.

Parameters:

  | data | object that contains the URI to be filtered.

Returns:
  true if the the data specified by data was successfully filtered.

Since:
  4.5

bool filterUri | ( | self, |
|  | KUriFilterData | data,
|  | 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

bool filterUri | ( | self, |
|  | KUrl | 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

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()
| ) |  |  |

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

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 only loads URI filter plugins that have not been disabled.

QStringList pluginNames | ( |  | self ) |

Return a list of the names of all loaded plugins.

Returns:
  a QStringList of plugin names

## Static Method Documentation

KUriFilter self | ( |  | ) |

Returns an instance of KUriFilter.