File indexing completed on 2025-01-19 03:41:34
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000-2001, 2003, 2010 Dawit Alemayehu <adawit at kde.org> 0004 0005 Original author 0006 SPDX-FileCopyrightText: 2000 Yves Arrouye <yves@realnames.com> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef KURIFILTER_H 0012 #define KURIFILTER_H 0013 0014 #include "kiogui_export.h" 0015 0016 #include <QHash> 0017 #include <QObject> 0018 #include <QPair> 0019 #include <QStringList> 0020 #include <QUrl> 0021 0022 #include <memory> 0023 0024 #ifdef Q_OS_WIN 0025 #undef ERROR 0026 #endif 0027 0028 class KUriFilterPrivate; 0029 class KUriFilterDataPrivate; 0030 class QHostInfo; 0031 0032 /** 0033 * @class KUriFilterSearchProvider kurifilter.h <KUriFilter> 0034 * 0035 * Class that holds information about a search provider. 0036 * 0037 */ 0038 class KIOGUI_EXPORT KUriFilterSearchProvider 0039 { 0040 public: 0041 /** 0042 * Default constructor. 0043 */ 0044 KUriFilterSearchProvider(); 0045 0046 /** 0047 * Copy constructor. 0048 */ 0049 KUriFilterSearchProvider(const KUriFilterSearchProvider &); 0050 0051 /** 0052 * Destructor. 0053 */ 0054 virtual ~KUriFilterSearchProvider(); 0055 0056 /** 0057 * Returns the desktop filename of the search provider without any extension. 0058 * 0059 * For example, if the desktop filename of the search provider was 0060 * "foobar.desktop", this function will return "foobar". 0061 */ 0062 QString desktopEntryName() const; 0063 0064 /** 0065 * Returns the descriptive name of the search provider, e.g.\ "Google News". 0066 * 0067 * This name comes from the "Name=" property entry in the desktop file that 0068 * contains the search provider's information. 0069 */ 0070 QString name() const; 0071 0072 /** 0073 * Returns the icon name associated with the search provider when available. 0074 */ 0075 virtual QString iconName() const; 0076 0077 /** 0078 * Returns all the web shortcut keys associated with this search provider. 0079 * 0080 * @see defaultKey 0081 */ 0082 QStringList keys() const; 0083 0084 /** 0085 * Returns the default web shortcut key for this search provider. 0086 * 0087 * Right now this is the same as doing keys().first(), it might however 0088 * change based on what the backend plugins do. 0089 * 0090 * @see keys 0091 */ 0092 QString defaultKey() const; 0093 0094 /** 0095 * Assignment operator. 0096 */ 0097 KUriFilterSearchProvider &operator=(const KUriFilterSearchProvider &); 0098 0099 protected: 0100 void setDesktopEntryName(const QString &); 0101 void setIconName(const QString &); 0102 void setKeys(const QStringList &); 0103 void setName(const QString &); 0104 0105 private: 0106 friend class KUriFilterPlugin; 0107 class KUriFilterSearchProviderPrivate; 0108 std::unique_ptr<KUriFilterSearchProviderPrivate> const d; 0109 }; 0110 0111 /** 0112 * @class KUriFilterData kurifilter.h <KUriFilter> 0113 * 0114 * This class is a basic messaging class used to exchange filtering information 0115 * between the filter plugins and the application requesting the filtering 0116 * service. 0117 * 0118 * Use this object if you require a more detailed information about the URI you 0119 * want to filter. Any application can create an instance of this class and send 0120 * it to KUriFilter to have the plugins fill out all possible information about 0121 * the URI. 0122 * 0123 * On successful filtering you can use @ref uriType() to determine what type 0124 * of resource the request was filtered into. See @ref KUriFilter::UriTypes for 0125 * details. If an error is encountered, then @ref KUriFilter::Error is returned. 0126 * You can use @ref errorMsg to obtain the error information. 0127 * 0128 * The functions in this class are not reentrant. 0129 * 0130 * \b Example 0131 * 0132 * Here is a basic example of how this class is used with @ref KUriFilter: 0133 * \code 0134 * KUriFilterData filterData (QLatin1String("kde.org")); 0135 * bool filtered = KUriFilter::self()->filterUri(filterData); 0136 * \endcode 0137 * 0138 * If you are only interested in getting the list of preferred search providers, 0139 * then you can do the following: 0140 * 0141 * \code 0142 * KUriFilterData data; 0143 * data.setData("<text-to-search-for>"); 0144 * data.setSearchFilteringOption(KUriFilterData::RetrievePreferredSearchProvidersOnly); 0145 * bool filtered = KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter); 0146 * \endcode 0147 * 0148 * @short A class for exchanging filtering information. 0149 * @author Dawit Alemayehu <adawit at kde.org> 0150 */ 0151 0152 class KIOGUI_EXPORT KUriFilterData 0153 { 0154 public: 0155 /** 0156 * Describes the type of the URI that was filtered. 0157 */ 0158 enum UriTypes { 0159 NetProtocol = 0, ///< Any network protocol: http, ftp, nttp, pop3, etc... 0160 LocalFile, ///< A local file whose executable flag is not set 0161 LocalDir, ///< A local directory 0162 Executable, ///< A local file whose executable flag is set 0163 Help, ///< A man or info page 0164 Shell, ///< A shell executable (ex: echo "Test..." >> ~/testfile) 0165 Blocked, ///< A URI that should be blocked/filtered (ex: ad filtering) 0166 Error, ///< An incorrect URI (ex: "~johndoe" when user johndoe does not exist in that system) 0167 Unknown, ///< A URI that is not identified. Default value when a KUriFilterData is first created. 0168 }; 0169 0170 /** 0171 * This enum describes the search filtering options to be used. 0172 * 0173 * @li SearchFilterOptionNone 0174 * No search filter options are set and normal filtering is performed 0175 * on the input data. 0176 * @li RetrieveSearchProvidersOnly 0177 * If set, the list of all available search providers are returned without 0178 * any input filtering. This flag only applies when used in conjunction 0179 * with the @ref KUriFilter::NormalTextFilter flag. 0180 * @li RetrievePreferredSearchProvidersOnly 0181 * If set, the list of preferred search providers are returned without 0182 * any input filtering. This flag only applies when used in conjunction 0183 * with the @ref KUriFilter::NormalTextFilter flag. 0184 * @li RetrieveAvailableSearchProvidersOnly 0185 * Same as doing RetrievePreferredSearchProvidersOnly | RetrieveSearchProvidersOnly, 0186 * where all available search providers are returned if no preferred ones 0187 * ones are available. No input filtering will be performed. 0188 * 0189 * @see setSearchFilteringOptions 0190 * @see KUriFilter::filterSearchUri 0191 * @see SearchFilterOptions 0192 */ 0193 enum SearchFilterOption { 0194 SearchFilterOptionNone = 0x0, 0195 RetrieveSearchProvidersOnly = 0x01, 0196 RetrievePreferredSearchProvidersOnly = 0x02, 0197 RetrieveAvailableSearchProvidersOnly = (RetrievePreferredSearchProvidersOnly | RetrieveSearchProvidersOnly), 0198 }; 0199 /** 0200 * Stores a combination of #SearchFilterOption values. 0201 */ 0202 Q_DECLARE_FLAGS(SearchFilterOptions, SearchFilterOption) 0203 0204 /** 0205 * Default constructor. 0206 * 0207 * Creates a UriFilterData object. 0208 */ 0209 KUriFilterData(); 0210 0211 /** 0212 * Creates a KUriFilterData object from the given URL. 0213 * 0214 * @param url is the URL to be filtered. 0215 */ 0216 explicit KUriFilterData(const QUrl &url); 0217 0218 /** 0219 * Creates a KUriFilterData object from the given string. 0220 * 0221 * @param url is the string to be filtered. 0222 */ 0223 explicit KUriFilterData(const QString &url); 0224 0225 /** 0226 * Copy constructor. 0227 * 0228 * Creates a KUriFilterData object from another KURIFilterData object. 0229 * 0230 * @param other the uri filter data to be copied. 0231 */ 0232 KUriFilterData(const KUriFilterData &other); 0233 0234 /** 0235 * Destructor. 0236 */ 0237 ~KUriFilterData(); 0238 0239 /** 0240 * Returns the filtered or the original URL. 0241 * 0242 * If one of the plugins successfully filtered the original input, this 0243 * function returns it. Otherwise, it will return the input itself. 0244 * 0245 * @return the filtered or original url. 0246 */ 0247 QUrl uri() const; 0248 0249 /** 0250 * Returns an error message. 0251 * 0252 * This functions returns the error message set by the plugin whenever the 0253 * uri type is set to KUriFilterData::ERROR. Otherwise, it returns a nullptr 0254 * string. 0255 * 0256 * @return the error message or a nullptr when there is none. 0257 */ 0258 QString errorMsg() const; 0259 0260 /** 0261 * Returns the URI type. 0262 * 0263 * This method always returns KUriFilterData::UNKNOWN if the given URL was 0264 * not filtered. 0265 * 0266 * @return the type of the URI 0267 */ 0268 UriTypes uriType() const; 0269 0270 /** 0271 * Returns the absolute path if one has already been set. 0272 * 0273 * @return the absolute path, or QString() 0274 * 0275 * @see hasAbsolutePath() 0276 */ 0277 QString absolutePath() const; 0278 0279 /** 0280 * Checks whether the supplied data had an absolute path. 0281 * 0282 * @return true if the supplied data has an absolute path 0283 * 0284 * @see absolutePath() 0285 */ 0286 bool hasAbsolutePath() const; 0287 0288 /** 0289 * Returns the command line options and arguments for a local resource 0290 * when present. 0291 * 0292 * @return options and arguments when present, otherwise QString() 0293 */ 0294 QString argsAndOptions() const; 0295 0296 /** 0297 * Checks whether the current data is a local resource with command line 0298 * options and arguments. 0299 * 0300 * @return true if the current data has command line options and arguments 0301 */ 0302 bool hasArgsAndOptions() const; 0303 0304 /** 0305 * @return true if the filters should attempt to check whether the 0306 * supplied uri is an executable. False otherwise. 0307 */ 0308 bool checkForExecutables() const; 0309 0310 /** 0311 * The string as typed by the user, before any URL processing is done. 0312 */ 0313 QString typedString() const; 0314 0315 /** 0316 * Returns the search term portion of the typed string. 0317 * 0318 * If the @ref typedString was not filtered by a search filter plugin, this 0319 * function returns an empty string. 0320 * 0321 * @see typedString 0322 */ 0323 QString searchTerm() const; 0324 0325 /** 0326 * Returns the character that is used to separate the search term from the 0327 * keyword. 0328 * 0329 * If @ref typedString was not filtered by a search filter plugin, this 0330 * function returns a null character. 0331 * 0332 * @see typedString 0333 */ 0334 QChar searchTermSeparator() const; 0335 0336 /** 0337 * Returns the name of the search service provider, e.g.\ Google. 0338 * 0339 * If @ref typedString was not filtered by a search filter plugin, this 0340 * function returns an empty string. 0341 * 0342 * @see typedString 0343 */ 0344 QString searchProvider() const; 0345 0346 /** 0347 * Returns a list of the names of preferred or available search providers. 0348 * 0349 * This function returns the list of providers marked as preferred whenever 0350 * the input data, i.e. @ref typedString, is successfully filtered. 0351 * 0352 * If no default search provider has been selected prior to a filter request, 0353 * this function will return an empty list. To avoid this problem you must 0354 * either set an alternate default search provider using @ref setAlternateDefaultSearchProvider 0355 * or set one of the @ref SearchFilterOption flags if you are only interested 0356 * in getting the list of providers and not filtering the input. 0357 * 0358 * Additionally, you can also provide alternate search providers in case 0359 * there are no preferred ones already selected. 0360 * 0361 * You can use @ref queryForPreferredServiceProvider to obtain the query 0362 * associated with the list of search providers returned by this function. 0363 * 0364 * @see setAlternateSearchProviders 0365 * @see setAlternateDefaultSearchProvider 0366 * @see setSearchFilteringOption 0367 * @see queryForPreferredServiceProvider 0368 */ 0369 QStringList preferredSearchProviders() const; 0370 0371 /** 0372 * Returns information about @p provider. 0373 * 0374 * You can use this function to obtain the more information about the search 0375 * providers returned by @ref preferredSearchProviders. 0376 * 0377 * @see preferredSearchProviders 0378 * @see KUriFilterSearchProvider 0379 */ 0380 KUriFilterSearchProvider queryForSearchProvider(const QString &provider) const; 0381 0382 /** 0383 * Returns the web shortcut url for the given preferred search provider. 0384 * 0385 * You can use this function to obtain the query for the preferred search 0386 * providers returned by @ref preferredSearchProviders. 0387 * 0388 * The query returned by this function is in web shortcut format, i.e. 0389 * "gg:foo bar", and must be re-filtered through KUriFilter to obtain a 0390 * valid url. 0391 * 0392 * @see preferredSearchProviders 0393 */ 0394 QString queryForPreferredSearchProvider(const QString &provider) const; 0395 0396 /** 0397 * Returns all the query urls for the given search provider. 0398 * 0399 * Use this function to obtain all the different queries that can be used 0400 * for the given provider. For example, if a search engine provider named 0401 * "foobar" has web shortcuts named "foobar", "foo" and "bar", then this 0402 * function, unlike @ref queryForPreferredSearchProvider, will return a 0403 * a query for each and every web shortcut. 0404 * 0405 * @see queryForPreferredSearchProvider 0406 */ 0407 QStringList allQueriesForSearchProvider(const QString &provider) const; 0408 0409 /** 0410 * Returns the icon associated with the given preferred search provider. 0411 * 0412 * You can use this function to obtain the icon names associated with the 0413 * preferred search providers returned by @ref preferredSearchProviders. 0414 * 0415 * @see preferredSearchProviders 0416 */ 0417 QString iconNameForPreferredSearchProvider(const QString &provider) const; 0418 0419 /** 0420 * Returns the list of alternate search providers. 0421 * 0422 * This function returns an empty list if @ref setAlternateSearchProviders 0423 * was not called to set the alternate search providers to be when no 0424 * preferred providers have been chosen by the user through the search 0425 * configuration module. 0426 * 0427 * @see setAlternatteSearchProviders 0428 * @see preferredSearchProviders 0429 */ 0430 QStringList alternateSearchProviders() const; 0431 0432 /** 0433 * Returns the search provider to use when a default provider is not available. 0434 * 0435 * This function returns an empty string if @ref setAlternateDefaultSearchProvider 0436 * was not called to set the default search provider to be used when none has been 0437 * chosen by the user through the search configuration module. 0438 * 0439 * @see setAlternateDefaultSearchProvider 0440 */ 0441 QString alternateDefaultSearchProvider() const; 0442 0443 /** 0444 * Returns the default protocol to use when filtering potentially valid url inputs. 0445 * 0446 * By default this function will return an empty string. 0447 * 0448 * @see setDefaultUrlScheme 0449 */ 0450 QString defaultUrlScheme() const; 0451 0452 /** 0453 * Returns the specified search filter options. 0454 * 0455 * By default this function returns @ref SearchFilterOptionNone. 0456 * 0457 * @see setSearchFilteringOptions 0458 */ 0459 SearchFilterOptions searchFilteringOptions() const; 0460 0461 /** 0462 * The name of the icon that matches the current filtered URL. 0463 * 0464 * This function returns a null string by default and when no icon is found 0465 * for the filtered URL. 0466 */ 0467 QString iconName(); 0468 0469 /** 0470 * Check whether the provided uri is executable or not. 0471 * 0472 * Setting this to false ensures that typing the name of an executable does 0473 * not start that application. This is useful in the location bar of a 0474 * browser. The default value is true. 0475 */ 0476 void setCheckForExecutables(bool check); 0477 0478 /** 0479 * Same as above except the argument is a URL. 0480 * 0481 * Use this function to set the string to be filtered when you construct an 0482 * empty filter object. 0483 * 0484 * @param url the URL to be filtered. 0485 */ 0486 void setData(const QUrl &url); 0487 0488 /** 0489 * Sets the URL to be filtered. 0490 * 0491 * Use this function to set the string to be 0492 * filtered when you construct an empty filter 0493 * object. 0494 * 0495 * @param url the string to be filtered. 0496 */ 0497 void setData(const QString &url); 0498 0499 /** 0500 * Sets the absolute path to be used whenever the supplied data is a 0501 * relative local URL. 0502 * 0503 * NOTE: This function should only be used for local resources, i.e. the 0504 * "file:/" protocol. It is useful for specifying the absolute path in 0505 * cases where the actual URL might be relative. If deriving the path from 0506 * a QUrl, make sure you set the argument for this function to the result 0507 * of calling path () instead of url (). 0508 * 0509 * @param abs_path the absolute path to the local resource. 0510 * 0511 * @return true if absolute path is successfully set. Otherwise, false. 0512 */ 0513 bool setAbsolutePath(const QString &abs_path); 0514 0515 /** 0516 * Sets a list of search providers to use in case no preferred search 0517 * providers are available. 0518 * 0519 * The list of preferred search providers set using this function will only 0520 * be used if the default and favorite search providers have not yet been 0521 * selected by the user. Otherwise, the providers specified through this 0522 * function will be ignored. 0523 * 0524 * @see alternateSearchProviders 0525 * @see preferredSearchProviders 0526 */ 0527 void setAlternateSearchProviders(const QStringList &providers); 0528 0529 /** 0530 * Sets the search provider to use in case no default provider is available. 0531 * 0532 * The default search provider set using this function will only be used if 0533 * the default and favorite search providers have not yet been selected by 0534 * the user. Otherwise, the default provider specified by through function 0535 * will be ignored. 0536 * 0537 * @see alternateDefaultSearchProvider 0538 * @see preferredSearchProviders 0539 */ 0540 void setAlternateDefaultSearchProvider(const QString &provider); 0541 0542 /** 0543 * Sets the default scheme used when filtering potentially valid url inputs. 0544 * 0545 * Use this function to change the default protocol used when filtering 0546 * potentially valid url inputs. The default protocol is http. 0547 * 0548 * If the scheme is specified without a separator, then "://" will be used 0549 * as the separator by default. For example, if the default url scheme was 0550 * simply set to "ftp", then a potentially valid url input such as "kde.org" 0551 * will be filtered to "ftp://kde.org". 0552 * 0553 * @see defaultUrlScheme 0554 */ 0555 void setDefaultUrlScheme(const QString &); 0556 0557 /** 0558 * Sets the options used by search filter plugins to filter requests. 0559 * 0560 * The default search filter option is @ref SearchFilterOptionNone. See 0561 * @ref SearchFilterOption for the description of the other flags. 0562 * 0563 * It is important to note that the options set through this function can 0564 * prevent any filtering from being performed by search filter plugins. 0565 * As such, @ref uriTypes can return KUriFilterData::Unknown and @ref uri 0566 * can return an invalid url even though the filtering request returned 0567 * a successful response. 0568 * 0569 * @see searchFilteringOptions 0570 */ 0571 void setSearchFilteringOptions(SearchFilterOptions options); 0572 0573 /** 0574 * Overloaded assignment operator. 0575 * 0576 * This function allows you to easily assign a QUrl 0577 * to a KUriFilterData object. 0578 * 0579 * @return an instance of a KUriFilterData object. 0580 */ 0581 KUriFilterData &operator=(const QUrl &url); 0582 0583 /** 0584 * Overloaded assignment operator. 0585 * 0586 * This function allows you to easily assign a QString to a KUriFilterData 0587 * object. 0588 * 0589 * @return an instance of a KUriFilterData object. 0590 */ 0591 KUriFilterData &operator=(const QString &url); 0592 0593 private: 0594 friend class KUriFilterPlugin; 0595 std::unique_ptr<KUriFilterDataPrivate> d; 0596 }; 0597 0598 /** 0599 * @class KUriFilter kurifilter.h <KUriFilter> 0600 * 0601 * KUriFilter applies a number of filters to a URI and returns a filtered version if any 0602 * filter matches. 0603 * A simple example is "kde.org" to "http://www.kde.org", which is commonplace in web browsers. 0604 * 0605 * The filters are implemented as plugins in @ref KUriFilterPlugin subclasses. 0606 * 0607 * KUriFilter is a singleton object: obtain the instance by calling 0608 * @p KUriFilter::self() and use the public member functions to 0609 * perform the filtering. 0610 * 0611 * \b Example 0612 * 0613 * To simply filter a given string: 0614 * 0615 * \code 0616 * QString url("kde.org"); 0617 * bool filtered = KUriFilter::self()->filteredUri( url ); 0618 * \endcode 0619 * 0620 * You can alternatively use a QUrl: 0621 * 0622 * \code 0623 * QUrl url("kde.org"); 0624 * bool filtered = KUriFilter::self()->filterUri( url ); 0625 * \endcode 0626 * 0627 * If you have a constant string or a constant URL, simply invoke the 0628 * corresponding function to obtain the filtered string or URL instead 0629 * of a boolean flag: 0630 * 0631 * \code 0632 * QString filteredText = KUriFilter::self()->filteredUri( "kde.org" ); 0633 * \endcode 0634 * 0635 * All of the above examples should result in "kde.org" being filtered into 0636 * "http://kde.org". 0637 * 0638 * You can also restrict the filters to be used by supplying the name of the 0639 * filters you want to use. By default all available filters are used. 0640 * 0641 * To use specific filters, add the names of the filters you want to use to a 0642 * QStringList and invoke the appropriate filtering function. 0643 * 0644 * The examples below show the use of specific filters. KDE ships with the 0645 * following filter plugins by default: 0646 * 0647 * kshorturifilter: 0648 * This is used for filtering potentially valid url inputs such as "kde.org" 0649 * Additionally it filters shell variables and shortcuts such as $HOME and 0650 * ~ as well as man and info page shortcuts, # and ## respectively. 0651 * 0652 * kuriikwsfilter: 0653 * This is used for filtering normal input text into a web search url using the 0654 * configured fallback search engine selected by the user. 0655 * 0656 * kurisearchfilter: 0657 * This is used for filtering KDE webshortcuts. For example "gg:KDE" will be 0658 * converted to a url for searching the work "KDE" using the Google search 0659 * engine. 0660 * 0661 * localdomainfilter: 0662 * This is used for doing a DNS lookup to determine whether the input is a valid 0663 * local address. 0664 * 0665 * fixuphosturifilter: 0666 * This is used to append "www." to the host name of a pre filtered http url 0667 * if the original url cannot be resolved. 0668 * 0669 * \code 0670 * QString text ("kde.org"); 0671 * bool filtered = KUriFilter::self()->filterUri(text, QLatin1String("kshorturifilter")); 0672 * \endcode 0673 * 0674 * The above code should result in "kde.org" being filtered into "http://kde.org". 0675 * 0676 * \code 0677 * QStringList list; 0678 * list << QLatin1String("kshorturifilter") << QLatin1String("localdomainfilter"); 0679 * bool filtered = KUriFilter::self()->filterUri( text, list ); 0680 * \endcode 0681 * 0682 * Additionally if you only want to do search related filtering, you can use the 0683 * search specific function, @ref filterSearchUri, that is available in KDE 0684 * 4.5 and higher. For example, to search for a given input on the web you 0685 * can do the following: 0686 * 0687 * KUriFilterData filterData ("foo"); 0688 * bool filtered = KUriFilter::self()->filterSearchUri(filterData, KUriFilterData::NormalTextFilter); 0689 * 0690 * KUriFilter converts all filtering requests to use @ref KUriFilterData 0691 * internally. The use of this bi-directional class allows you to send specific 0692 * instructions to the filter plugins as well as receive detailed information 0693 * about the filtered request from them. See the documentation of KUriFilterData 0694 * class for more examples and details. 0695 * 0696 * All functions in this class are thread safe and reentrant. 0697 * 0698 * @short Filters the given input into a valid url whenever possible. 0699 */ 0700 class KIOGUI_EXPORT KUriFilter 0701 { 0702 public: 0703 /** 0704 * This enum describes the types of search plugin filters available. 0705 * 0706 * @li NormalTextFilter The plugin used to filter normal text, e.g. "some term to search". 0707 * @li WebShortcutFilter The plugin used to filter web shortcuts, e.g. gg:KDE. 0708 * 0709 * @see SearchFilterTypes 0710 */ 0711 enum SearchFilterType { 0712 NormalTextFilter = 0x01, 0713 WebShortcutFilter = 0x02, 0714 }; 0715 /** 0716 * Stores a combination of #SearchFilterType values. 0717 */ 0718 Q_DECLARE_FLAGS(SearchFilterTypes, SearchFilterType) 0719 0720 /** 0721 * Destructor 0722 */ 0723 ~KUriFilter(); 0724 0725 /** 0726 * Returns an instance of KUriFilter. 0727 */ 0728 static KUriFilter *self(); 0729 0730 /** 0731 * Filters @p data using the specified @p filters. 0732 * 0733 * If no named filters are specified, the default, then all the 0734 * URI filter plugins found will be used. 0735 * 0736 * @param data object that contains the URI to be filtered. 0737 * @param filters specify the list of filters to be used. 0738 * 0739 * @return a boolean indicating whether the URI has been changed 0740 */ 0741 bool filterUri(KUriFilterData &data, const QStringList &filters = QStringList()); 0742 0743 /** 0744 * Filters the URI given by the URL. 0745 * 0746 * The given URL is filtered based on the specified list of filters. 0747 * If the list is empty all available filters would be used. 0748 * 0749 * @param uri the URI to filter. 0750 * @param filters specify the list of filters to be used. 0751 * 0752 * @return a boolean indicating whether the URI has been changed 0753 */ 0754 bool filterUri(QUrl &uri, const QStringList &filters = QStringList()); 0755 0756 /** 0757 * Filters a string representing a URI. 0758 * 0759 * The given URL is filtered based on the specified list of filters. 0760 * If the list is empty all available filters would be used. 0761 * 0762 * @param uri The URI to filter. 0763 * @param filters specify the list of filters to be used. 0764 * 0765 * @return a boolean indicating whether the URI has been changed 0766 */ 0767 bool filterUri(QString &uri, const QStringList &filters = QStringList()); 0768 0769 /** 0770 * Returns the filtered URI. 0771 * 0772 * The given URL is filtered based on the specified list of filters. 0773 * If the list is empty all available filters would be used. 0774 * 0775 * @param uri The URI to filter. 0776 * @param filters specify the list of filters to be used. 0777 * 0778 * @return the filtered URI or null if it cannot be filtered 0779 */ 0780 QUrl filteredUri(const QUrl &uri, const QStringList &filters = QStringList()); 0781 0782 /** 0783 * Return a filtered string representation of a URI. 0784 * 0785 * The given URL is filtered based on the specified list of filters. 0786 * If the list is empty all available filters would be used. 0787 * 0788 * @param uri the URI to filter. 0789 * @param filters specify the list of filters to be used. 0790 * 0791 * @return the filtered URI or null if it cannot be filtered 0792 */ 0793 QString filteredUri(const QString &uri, const QStringList &filters = QStringList()); 0794 0795 /** 0796 * Filter @p data using the criteria specified by @p types. 0797 * 0798 * The search filter type can be individual value of @ref SearchFilterTypes 0799 * or a combination of those types using the bitwise OR operator. 0800 * 0801 * You can also use the flags from @ref KUriFilterData::SearchFilterOption 0802 * to alter the filtering mechanisms of the search filter providers. 0803 * 0804 * @param data object that contains the URI to be filtered. 0805 * @param types the search filters used to filter the request. 0806 * @return true if the specified @p data was successfully filtered. 0807 * 0808 * @see KUriFilterData::setSearchFilteringOptions 0809 */ 0810 bool filterSearchUri(KUriFilterData &data, SearchFilterTypes types); 0811 0812 /** 0813 * Return a list of the names of all loaded plugins. 0814 * 0815 * @return a QStringList of plugin names 0816 */ 0817 QStringList pluginNames() const; 0818 0819 protected: 0820 /** 0821 * Constructor. 0822 * 0823 * Creates a KUriFilter object and calls loads all available URI filter plugins. 0824 */ 0825 KUriFilter(); 0826 0827 private: 0828 std::unique_ptr<KUriFilterPrivate> const d; 0829 friend class KUriFilterSingleton; 0830 }; 0831 0832 Q_DECLARE_OPERATORS_FOR_FLAGS(KUriFilterData::SearchFilterOptions) 0833 Q_DECLARE_OPERATORS_FOR_FLAGS(KUriFilter::SearchFilterTypes) 0834 0835 #endif