diff --git a/src/urifilters/fixhost/CMakeLists.txt b/src/urifilters/fixhost/CMakeLists.txt index 2da460e7..43d0aecf 100644 --- a/src/urifilters/fixhost/CMakeLists.txt +++ b/src/urifilters/fixhost/CMakeLists.txt @@ -1,13 +1,5 @@ -set(fixhosturifilter_PART_SRCS fixhosturifilter.cpp ) +set(fixhosturifilter_SRCS fixhosturifilter.cpp ) -add_library(fixhosturifilter MODULE ${fixhosturifilter_PART_SRCS}) +kcoreaddons_add_plugin(fixhosturifilter INSTALL_NAMESPACE "kf5/urifilters" JSON fixhosturifilter.json SOURCES ${fixhosturifilter_SRCS}) target_link_libraries(fixhosturifilter KF5::KIOWidgets) - -set_target_properties(fixhosturifilter PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/urifilters") -install(TARGETS fixhosturifilter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/urifilters) - -########### install files ############### - -install(FILES fixhosturifilter.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) - diff --git a/src/urifilters/fixhost/fixhosturifilter.cpp b/src/urifilters/fixhost/fixhosturifilter.cpp index a79bb3b1..8f27d77d 100644 --- a/src/urifilters/fixhost/fixhosturifilter.cpp +++ b/src/urifilters/fixhost/fixhosturifilter.cpp @@ -1,95 +1,95 @@ /* fixhostfilter.cpp This file is part of the KDE project Copyright (C) 2007 Lubos Lunak Copyright (C) 2010 Dawit Alemayehu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "fixhosturifilter.h" #include #include #define QL1S(x) QLatin1String(x) #define QL1C(x) QLatin1Char(x) /** * IMPORTANT: If you change anything here, make sure you run the kurifiltertest * regression test (this should be included as part of "make test"). */ FixHostUriFilter::FixHostUriFilter(QObject *parent, const QVariantList & /*args*/) :KUriFilterPlugin(QStringLiteral("fixhosturifilter"), parent) { } static bool isHttpUrl(const QString& scheme) { return (scheme.compare(QL1S("http"), Qt::CaseInsensitive) == 0 || scheme.compare(QL1S("https"), Qt::CaseInsensitive) == 0 || scheme.compare(QL1S("webdav"), Qt::CaseInsensitive) == 0 || scheme.compare(QL1S("webdavs"), Qt::CaseInsensitive) == 0); } static bool hasCandidateHostName(const QString& host) { return (host.contains(QL1C('.')) && !host.startsWith(QL1S("www."), Qt::CaseInsensitive)); } bool FixHostUriFilter::filterUri( KUriFilterData& data ) const { QUrl url = data.uri(); const QString protocol = url.scheme(); const bool isHttp = isHttpUrl(protocol); if (isHttp || protocol == data.defaultUrlScheme()) { const QString host = url.host(); if (hasCandidateHostName(host) && !isResolvable(host)) { if (isHttp) { url.setHost((QL1S("www.") + host)); if (exists(url.host())) { setFilteredUri(data, url); setUriType(data, KUriFilterData::NetProtocol); return true; } } } } return false; } bool FixHostUriFilter::isResolvable(const QString& host) const { // Unlike exists, this function returns true if the lookup timeout out. QHostInfo info = resolveName(host, 1500); return (info.error() == QHostInfo::NoError || info.error() == QHostInfo::UnknownError); } bool FixHostUriFilter::exists(const QString& host) const { QHostInfo info = resolveName(host, 1500); return (info.error() == QHostInfo::NoError); } -K_PLUGIN_FACTORY(FixHostUriFilterFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(FixHostUriFilterFactory, "fixhosturifilter.json", registerPlugin();) #include "fixhosturifilter.moc" diff --git a/src/urifilters/fixhost/fixhosturifilter.desktop b/src/urifilters/fixhost/fixhosturifilter.desktop deleted file mode 100644 index cf9065f0..00000000 --- a/src/urifilters/fixhost/fixhosturifilter.desktop +++ /dev/null @@ -1,88 +0,0 @@ -[Desktop Entry] -Type=Service -Name=FixHostFilter -Name[af]=FixHostFilter -Name[ast]=FixHostFilter -Name[be]=FixHostFilter -Name[be@latin]=FixHostFilter -Name[bg]=FixHostFilter -Name[bn]=FixHostFilter -Name[bn_IN]=FixHostFilter -Name[bs]=Filter za popravku domaćina -Name[ca]=FixHostFilter -Name[ca@valencia]=FixHostFilter -Name[cs]=FixHostFilter -Name[csb]=Filter FixHost -Name[da]=FixHostFilter -Name[de]=Rechnernamen-Korrektur-Filter -Name[el]=FixHostFilter -Name[en_GB]=FixHostFilter -Name[eo]=FixHostFilter -Name[es]=FixHostFilter -Name[et]=FixHostFilter -Name[eu]=FixHostFilter -Name[fa]=FixHostFilter -Name[fi]=FixHostFilter -Name[fr]=FixHostFilter -Name[fy]=FixHostFilter -Name[ga]=FixHostFilter -Name[gd]=Criathrag càraidh nan òstairean -Name[gl]=FixHostFilter -Name[gu]=FixHostFilter -Name[he]=FixHostFilter -Name[hi]=फ़िक्स-होस्ट-फ़िल्टर -Name[hne]=फिक्स-होस्ट-फिल्टर -Name[hr]=FixHostFilter -Name[hsb]=FixHostFilter -Name[hu]=FixHostFilter -Name[ia]=FixHostFilter -Name[id]=Perbaiki Filter Host -Name[is]=LagaHostSía -Name[it]=Filtro degli host fissi -Name[kk]=FixHostFilter -Name[km]=FixHostFilter -Name[kn]=ಫಿಕ್ಸ್ ಹೋಸ್ಟ್ ಫಿಲ್ಟರ್ -Name[ko]=FixHostFilter -Name[ku]=FixHostFilter -Name[lt]=FixHostFilter -Name[lv]=FixHostFilter -Name[mai]=फिक्स-होस्ट-फिल्टर -Name[mk]=FixHostFilter -Name[ml]=ഫിക്സ്ഹൊസ്റ്റ് അരിപ്പകള്‍ -Name[mr]=फिक्स होस्ट गाळणी -Name[nb]=FixHostFilter -Name[nds]=Fast Reeknerfilter -Name[ne]=होस्ट फिल्टर निश्चित गर्नुहोस् -Name[nl]=FixHostFilter -Name[nn]=FiksVertFilter -Name[or]=FixHostFilter -Name[pa]=FixHostFilter -Name[pl]=Filtr nazw komputerów -Name[pt]=Filtro de Correcção da Máquina -Name[pt_BR]=FixHostFilter -Name[ro]=FixHostFilter -Name[ru]=FixHostFilter -Name[se]=FixHostFilter -Name[si]=සැකසූ ධාරක පෙරහන -Name[sk]=FixHostFilter -Name[sl]=FixHostFilter -Name[sr]=Филтер за поправку домаћина -Name[sr@ijekavian]=Филтер за поправку домаћина -Name[sr@ijekavianlatin]=Filter za popravku domaćina -Name[sr@latin]=Filter za popravku domaćina -Name[sv]=Fast värddatorfilter -Name[ta]=FixHostFilter -Name[te]=FixHostFilter -Name[tg]=FixHostFilter -Name[th]=FixHostFilter -Name[tr]=FixHostFilter -Name[ug]=مۇقىم ماشىنا سۈزگۈچ -Name[uk]=FixHostFilter -Name[vi]=FixHostFilter -Name[wa]=FixHostFilter -Name[x-test]=xxFixHostFilterxx -Name[zh_CN]=固定主机过滤器 -Name[zh_TW]=固定主機過濾 -X-KDE-Library=kf5/urifilters/fixhosturifilter -X-KDE-ServiceTypes=KUriFilter/Plugin -InitialPreference=1 diff --git a/src/urifilters/fixhost/fixhosturifilter.h b/src/urifilters/fixhost/fixhosturifilter.h index 79b9fecc..60260a51 100644 --- a/src/urifilters/fixhost/fixhosturifilter.h +++ b/src/urifilters/fixhost/fixhosturifilter.h @@ -1,45 +1,45 @@ /* fixhosturifilter.h This file is part of the KDE project Copyright (C) 2007 Lubos Lunak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef FIXHOSTURIFILTER_H #define FIXHOSTURIFILTER_H #include class QHostInfo; class QEventLoop; /** This filter tries to automatically prepend www. to http URLs that need it. */ class FixHostUriFilter : public KUriFilterPlugin { -Q_OBJECT + Q_OBJECT public: FixHostUriFilter(QObject* parent, const QVariantList& args); bool filterUri(KUriFilterData &data) const Q_DECL_OVERRIDE; private: bool exists(const QString& host) const; bool isResolvable(const QString& host) const; }; #endif diff --git a/src/urifilters/fixhost/fixhosturifilter.json b/src/urifilters/fixhost/fixhosturifilter.json new file mode 100644 index 00000000..011e53af --- /dev/null +++ b/src/urifilters/fixhost/fixhosturifilter.json @@ -0,0 +1,7 @@ +{ + "KPlugin": { + "ServiceTypes": [ "KUriFilter/Plugin" ] + }, + "X-KDE-InitialPreference": 1 +} + diff --git a/src/urifilters/ikws/CMakeLists.txt b/src/urifilters/ikws/CMakeLists.txt index 2572882c..a0e060b0 100644 --- a/src/urifilters/ikws/CMakeLists.txt +++ b/src/urifilters/ikws/CMakeLists.txt @@ -1,43 +1,40 @@ add_subdirectory(searchproviders) -set(kuriikwsfilter_PART_SRCS kuriikwsfiltereng.cpp kuriikwsfilter.cpp searchprovider.cpp) +#### -ki18n_wrap_ui(kuriikwsfilter_PART_SRCS ikwsopts_ui.ui searchproviderdlg_ui.ui) +set(kuriikwsfilter_SRCS kuriikwsfiltereng.cpp kuriikwsfilter.cpp searchprovider.cpp) -add_library(kuriikwsfilter MODULE ${kuriikwsfilter_PART_SRCS}) +ki18n_wrap_ui(kuriikwsfilter_SRCS ikwsopts_ui.ui searchproviderdlg_ui.ui) + +kcoreaddons_add_plugin(kuriikwsfilter INSTALL_NAMESPACE "kf5/urifilters" JSON kuriikwsfilter.json SOURCES ${kuriikwsfilter_SRCS}) target_link_libraries(kuriikwsfilter KF5::ConfigWidgets # KCModule KF5::KIOWidgets # KUriFilter KF5::I18n Qt5::DBus ) -set_target_properties(kuriikwsfilter PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/urifilters") -install(TARGETS kuriikwsfilter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/urifilters) +##### -set(kurisearchfilter_PART_SRCS +set(kurisearchfilter_SRCS kurisearchfilter.cpp kuriikwsfiltereng.cpp ikwsopts.cpp searchproviderdlg.cpp searchprovider.cpp ) -ki18n_wrap_ui(kurisearchfilter_PART_SRCS ikwsopts_ui.ui searchproviderdlg_ui.ui) +ki18n_wrap_ui(kurisearchfilter_SRCS ikwsopts_ui.ui searchproviderdlg_ui.ui) -add_library(kurisearchfilter MODULE ${kurisearchfilter_PART_SRCS}) +kcoreaddons_add_plugin(kurisearchfilter INSTALL_NAMESPACE "kf5/urifilters" JSON kurisearchfilter.json SOURCES ${kurisearchfilter_SRCS}) target_link_libraries(kurisearchfilter KF5::ConfigWidgets # KCModule KF5::KIOWidgets # KUriFilter KF5::I18n Qt5::DBus ) -set_target_properties(kurisearchfilter PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/urifilters") -install(TARGETS kurisearchfilter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/urifilters) - ########### install files ############### -install( FILES kuriikwsfilter.desktop kurisearchfilter.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( FILES searchprovider.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR} ) diff --git a/src/urifilters/ikws/kuriikwsfilter.cpp b/src/urifilters/ikws/kuriikwsfilter.cpp index 7a69a1f7..995b9aac 100644 --- a/src/urifilters/ikws/kuriikwsfilter.cpp +++ b/src/urifilters/ikws/kuriikwsfilter.cpp @@ -1,173 +1,173 @@ /* This file is part of the KDE project Copyright (C) 1999 Simon Hausmann Copyright (C) 2000 Yves Arrouye Copyright (C) 2002, 2003 Dawit Alemayehu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kuriikwsfilter.h" #include "kuriikwsfiltereng.h" #include "searchprovider.h" #include "ikwsopts.h" #include #include #include #define QL1S(x) QLatin1String(x) #define QL1C(x) QLatin1Char(x) namespace { QLoggingCategory category("org.kde.kurifilter-ikws", QtWarningMsg); } /** * IMPORTANT: If you change anything here, make sure you run the kurifiltertest * regression test (this should be included as part of "make test"). */ -K_PLUGIN_FACTORY(KAutoWebSearchFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KAutoWebSearchFactory, "kuriikwsfilter.json", registerPlugin();) KAutoWebSearch::KAutoWebSearch(QObject *parent, const QVariantList&) :KUriFilterPlugin( QStringLiteral("kuriikwsfilter"), parent ) { KLocalizedString::insertQtDomain("kurifilter"); QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"), QStringLiteral("configure"), this, SLOT(configure())); } KAutoWebSearch::~KAutoWebSearch() { } void KAutoWebSearch::configure() { qCDebug(category) << "Config reload requested..."; KURISearchFilterEngine::self()->loadConfig(); } void KAutoWebSearch::populateProvidersList(QList& searchProviders, const KUriFilterData& data, bool allproviders) const { QList providers; KURISearchFilterEngine *filter = KURISearchFilterEngine::self(); const QString searchTerm = filter->keywordDelimiter() + data.typedString(); if (allproviders) providers = SearchProvider::findAll(); else { // Start with the search engines marked as preferred... QStringList favEngines = filter->favoriteEngineList(); if (favEngines.isEmpty()) favEngines = data.alternateSearchProviders(); // Get rid of duplicates... favEngines.removeDuplicates(); - + // Sort the items... qStableSort(favEngines); // Add the search engine set as the default provider... const QString defaultEngine = filter->defaultSearchEngine(); if (!defaultEngine.isEmpty()) { favEngines.removeAll(defaultEngine); favEngines.insert(0, defaultEngine); } QStringListIterator it (favEngines); while (it.hasNext()) { SearchProvider *favProvider = SearchProvider::findByDesktopName(it.next()); if (favProvider) providers << favProvider; } } for (int i = 0, count = providers.count(); i < count; ++i) { searchProviders << providers[i]; } } bool KAutoWebSearch::filterUri( KUriFilterData &data ) const { qCDebug(category) << data.typedString(); KUriFilterData::SearchFilterOptions option = data.searchFilteringOptions(); // Handle the flag to retrieve only preferred providers, no filtering... if (option & KUriFilterData::RetrievePreferredSearchProvidersOnly) { QList searchProviders; populateProvidersList(searchProviders, data); if (searchProviders.isEmpty()) { if (!(option & KUriFilterData::RetrieveSearchProvidersOnly)) { setUriType(data, KUriFilterData::Error); setErrorMsg(data, i18n("No preferred search providers were found.")); return false; } } else { setSearchProvider(data, QString(), data.typedString(), QL1C(KURISearchFilterEngine::self()->keywordDelimiter())); setSearchProviders(data, searchProviders); return true; } } if (option & KUriFilterData::RetrieveSearchProvidersOnly) { QList searchProviders; populateProvidersList(searchProviders, data, true); if (searchProviders.isEmpty()) { setUriType(data, KUriFilterData::Error); setErrorMsg(data, i18n("No search providers were found.")); return false; } setSearchProvider(data, QString(), data.typedString(), QL1C(KURISearchFilterEngine::self()->keywordDelimiter())); setSearchProviders(data, searchProviders); return true; } if ( data.uriType() == KUriFilterData::Unknown && data.uri().password().isEmpty() ) { KURISearchFilterEngine *filter = KURISearchFilterEngine::self(); SearchProvider *provider = filter->autoWebSearchQuery( data.typedString(), data.alternateDefaultSearchProvider() ); if( provider ) { const QUrl result = filter->formatResult(provider->query(), provider->charset(), QString(), data.typedString(), true); setFilteredUri(data, result); setUriType( data, KUriFilterData::NetProtocol ); setSearchProvider(data, provider->name(), data.typedString(), QL1C(filter->keywordDelimiter())); QList searchProviders; populateProvidersList(searchProviders, data); setSearchProviders(data, searchProviders); delete provider; return true; } } return false; } #include "kuriikwsfilter.moc" diff --git a/src/urifilters/ikws/kuriikwsfilter.desktop b/src/urifilters/ikws/kuriikwsfilter.desktop deleted file mode 100644 index da8a599a..00000000 --- a/src/urifilters/ikws/kuriikwsfilter.desktop +++ /dev/null @@ -1,94 +0,0 @@ -[Desktop Entry] -Type=Service -Name=InternetKeywordsFilter -Name[af]=Internetsleutelwoordefilter -Name[ast]=InternetKeywordsFilter -Name[be]=Фільтр ключавых словаў -Name[be@latin]=InternetKeywordsFilter -Name[bg]=InternetKeywordsFilter -Name[bn]=InternetKeywordsFilter -Name[bn_IN]=InternetKeywordsFilter -Name[br]=SilGerioùAlc'hwezArKenrouedad -Name[bs]=Filter ključnih riječi Interneta -Name[ca]=Filtre per a les paraules clau d'Internet -Name[ca@valencia]=Filtre per a les paraules clau d'Internet -Name[cs]=InternetKeywordsFilter -Name[csb]=Filter internetowëch kluczowëch słów -Name[cy]=HidlAllweddeiriauRhyngrwyd -Name[da]=InternetNøgleordsFilter -Name[de]=Internet-Stichwort-Filter -Name[el]=Φίλτρο λέξεων κλειδιών διαδικτύου -Name[en_GB]=InternetKeywordsFilter -Name[eo]=InternetKeywordsFilter -Name[es]=Filtro de palabras clave de Internet -Name[et]=Interneti võtmesõnade filter -Name[eu]=InternetKeywordsFilter -Name[fa]=پالایه واژه‌های کلیدی اینترنت -Name[fi]=InternetKeywordsFilter -Name[fr]=Filtre de mots clés Internet -Name[fy]=YnternetSykwurdenFilter -Name[ga]=InternetKeywordsFilter -Name[gd]=Criathrag faclan-luirg an eadar-lìn -Name[gl]=InternetKeywordsFilter -Name[gu]=InternetKeywordsFilter -Name[he]=InternetKeywordsFilter -Name[hi]=इंटरनेट-की-वर्ड्स-फ़िल्टर -Name[hne]=इंटरनेट-की-वर्ड्स-फिल्टर -Name[hr]=Filtar internetskih ključnih riječi -Name[hsb]=InternetKeywordsFilter -Name[hu]=Internetes kulcsszavak szűrője -Name[ia]=InternetKeywordsFilter -Name[id]=Filter Kata Kunci Filter -Name[is]=InternetStikkorðaSía -Name[it]=Filtro delle parole chiave di Internet -Name[kk]=ИнтернетТүйіндіСөздерСүзгісі -Name[km]=InternetKeywordsFilter -Name[kn]=ಅಂತರ್ಜಾಲ ಕೀಲಿಪದಗಳ (ಕೀವರ್ಡ್) ಶೋಧಕ -Name[ko]=InternetKeywordsFilter -Name[ku]=ParzînaPeyvênmifteyêTorê -Name[lt]=InternetoRaktažodžiųfiltras -Name[lv]=InternetaAtslēgvārduFiltrs -Name[mai]=इंटरनेट-की-वर्ड्स-फिल्टर -Name[mk]=InternetKeywordsFilter -Name[ml]=ഇന്റര്‍നെറ്റ് കീവാക്കുകളുടെ അരിപ്പകള്‍ -Name[mr]=इंटरनेट मूळ शब्द गाळणी -Name[ms]=InternetKeywordsFilter -Name[nb]=InternetKeywordsFilter -Name[nds]=Internet-Slötelwöörfilter -Name[ne]=इन्टरनेट शब्दकुञ्जी फिल्टर -Name[nl]=InternetZoektermenFilter -Name[nn]=InternettNøkkelordFilter -Name[or]=InternetKeywordsFilter -Name[pa]=ਇੰਟਰਨੈੱਟ ਸ਼ਬਦ ਫਿਲਟਰ -Name[pl]=Filtr internetowych słów kluczowych -Name[pt]=Filtro de Palavras-chave na Internet -Name[pt_BR]=Filtro de palavras chave da Internet -Name[ro]=InternetKeywordsFilter -Name[ru]=InternetKeywordsFilter -Name[se]=InternetKeywordsFilter -Name[si]=අන්තර්ජාල යතුරු වදන් පෙරහන -Name[sk]=Filter kľúčových slov pre Internet -Name[sl]=Filter ključnih besed za internet -Name[sr]=Филтер кључних речи Интернета -Name[sr@ijekavian]=Филтер кључних ријечи Интернета -Name[sr@ijekavianlatin]=Filter ključnih riječi Interneta -Name[sr@latin]=Filter ključnih reči Interneta -Name[sv]=Internet-nyckelordsfilter -Name[ta]=தேடல் மூலச்சொற்கள் வடிகட்டி -Name[te]=InternetKeywordsFilter -Name[tg]=InternetKeywordsFilter -Name[th]=ตัวกรองคำค้นหาบนอินเทอร์เน็ต -Name[tr]=İnternetAnahtarSözcükSüzgeci -Name[ug]=ئىنتېرنېت ئاچقۇچلۇق سۆز سۈزگۈچ -Name[uk]=Фільтр ключових слів інтернет -Name[uz]=Internet kalit soʻzlar filteri -Name[uz@cyrillic]=Интернет калит сўзлар филтери -Name[vi]=InternetKeywordsFilter -Name[wa]=PasseteMotsclésDaegntoele -Name[xh]=Amagama Angundoqo ecebo lokucoca ulwelo e Internet -Name[x-test]=xxInternetKeywordsFilterxx -Name[zh_CN]=互联网关键字过滤 -Name[zh_TW]=網際網路關鍵字過濾 -X-KDE-Library=kf5/urifilters/kuriikwsfilter -X-KDE-ServiceTypes=KUriFilter/Plugin -InitialPreference=0 diff --git a/src/urifilters/ikws/kuriikwsfilter.json b/src/urifilters/ikws/kuriikwsfilter.json new file mode 100644 index 00000000..b1af8bd6 --- /dev/null +++ b/src/urifilters/ikws/kuriikwsfilter.json @@ -0,0 +1,6 @@ +{ + "KPlugin": { + "ServiceTypes": [ "KUriFilter/Plugin" ] + }, + "X-KDE-InitialPreference": 0 +} diff --git a/src/urifilters/ikws/kurisearchfilter.cpp b/src/urifilters/ikws/kurisearchfilter.cpp index a2ffd8da..63654add 100644 --- a/src/urifilters/ikws/kurisearchfilter.cpp +++ b/src/urifilters/ikws/kurisearchfilter.cpp @@ -1,95 +1,95 @@ /* This file is part of the KDE project Copyright (C) 1999 Simon Hausmann Copyright (C) 2000 Yves Arrouye Copyright (C) 2002, 2003 Dawit Alemayehu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kurisearchfilter.h" #include "kuriikwsfiltereng.h" #include "searchprovider.h" #include "ikwsopts.h" #include #include #include /** * IMPORTANT: If you change anything here, make sure you run the kurifiltertest * regression test (this should be included as part of "make test"). */ -K_PLUGIN_FACTORY(KUriSearchFilterFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KUriSearchFilterFactory, "kurisearchfilter.json", registerPlugin();) namespace { QLoggingCategory category("org.kde.kurifilter-ikws", QtWarningMsg); } KUriSearchFilter::KUriSearchFilter(QObject *parent, const QVariantList &) :KUriFilterPlugin( QStringLiteral("kurisearchfilter"), parent ) { KLocalizedString::insertQtDomain("kurifilter"); QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"), QStringLiteral("configure"), this, SLOT(configure())); } KUriSearchFilter::~KUriSearchFilter() { } void KUriSearchFilter::configure() { qCDebug(category) << "Config reload requested..."; KURISearchFilterEngine::self()->loadConfig(); } bool KUriSearchFilter::filterUri( KUriFilterData &data ) const { qCDebug(category) << data.typedString() << ":" << data.uri() << ", type =" << data.uriType(); // some URLs like gg:www.kde.org are not accepted by QUrl, but we still want them // This means we also have to allow KUriFilterData::Error if (data.uriType() != KUriFilterData::Unknown && data.uriType() != KUriFilterData::Error) { return false; } QString searchTerm; KURISearchFilterEngine *filter = KURISearchFilterEngine::self(); QScopedPointer provider(filter->webShortcutQuery(data.typedString(), searchTerm)); if (!provider) { return false; } const QUrl result = filter->formatResult(provider->query(), provider->charset(), QString(), searchTerm, true ); setFilteredUri(data, result); setUriType( data, KUriFilterData::NetProtocol ); setSearchProvider( data, provider->name(), searchTerm, QLatin1Char(filter->keywordDelimiter())); return true; } KCModule *KUriSearchFilter::configModule(QWidget *parent, const char *) const { return new FilterOptions( KAboutData::pluginData(QStringLiteral("kcmkurifilt")), parent); } QString KUriSearchFilter::configName() const { return i18n("Search F&ilters"); } #include "kurisearchfilter.moc" diff --git a/src/urifilters/ikws/kurisearchfilter.desktop b/src/urifilters/ikws/kurisearchfilter.desktop deleted file mode 100644 index b6be6dc1..00000000 --- a/src/urifilters/ikws/kurisearchfilter.desktop +++ /dev/null @@ -1,94 +0,0 @@ -[Desktop Entry] -Type=Service -Name=SearchKeywordsFilter -Name[af]=Soektogsleutelwoordfilter -Name[ast]=SearchKeywordsFilter -Name[be]=Фільтр пошуку ключавых словаў -Name[be@latin]=SearchKeywordsFilter -Name[bg]=SearchKeywordsFilter -Name[bn]=SearchKeywordsFilter -Name[bn_IN]=SearchKeywordsFilter -Name[br]=SilGerioùAlc'hwezKlask -Name[bs]=Filter riječi za pretraživanje -Name[ca]=Filtre per a les paraules clau de cerca -Name[ca@valencia]=Filtre per a les paraules clau de busca -Name[cs]=SearchKeywordsFilter -Name[csb]=Filter kluczowëch słów -Name[cy]=HidlChwilioAllweddeiriau -Name[da]=SøgNøgleordsFilter -Name[de]=Suchstichwort-Filter -Name[el]=Φίλτρο λέξεων κλειδιών αναζήτησης -Name[en_GB]=SearchKeywordsFilter -Name[eo]=SearchKeywordsFilter -Name[es]=Filtro de palabras clave de búsqueda -Name[et]=SearchKeywordsFilter -Name[eu]=SearchKeywordsFilter -Name[fa]=پالایه واژه‌های کلیدی جستجو -Name[fi]=SearchKeywordsFilter -Name[fr]=Filtre de mots clés de recherche -Name[fy]=SykwurdenFilter -Name[ga]=SearchKeywordsFilter -Name[gd]=Criathrag nam faclan-luirg -Name[gl]=SearchKeywordsFilter -Name[gu]=SearchKeywordsFilter -Name[he]=SearchKeywordsFilter -Name[hi]=सर्च-की-वर्ड्स-फ़िल्टर -Name[hne]=सर्च-की-वर्ड्स-फिल्टर -Name[hr]=Filtar ključnih riječi pretraživanja -Name[hsb]=SearchKeywordsFilter -Name[hu]=Kulcsszavak keresési szűrője -Name[ia]=SearchKeywordsFilter -Name[id]=Filter Kata Kunci Pencarian -Name[is]=StikkorðaLeitarSía -Name[it]=Filtro delle chiavi di ricerca -Name[kk]=ТүйіндіСөздерІздеуСүзгісі -Name[km]=SearchKeywordsFilter -Name[kn]=ಹುಡುಕು ಕೀಲಿಪದ (ಕೀವರ್ಡ್) ಶೋಧಕ -Name[ko]=SearchKeywordsFilter -Name[ku]=ParzûnaPeyvênmifteyêLêgerînê -Name[lt]=PaieškosRaktažodžiųFiltras -Name[lv]=MeklēšanasAtslēgvārduFiltrs -Name[mai]=सर्च-की-वर्ड्स-फिल्टर -Name[mk]=SearchKeywordsFilter -Name[ml]=തെരച്ചില്‍ കീവാക്കുകളുടെ അരിപ്പകള്‍ -Name[mr]=शोध मूळ शब्द गाळणी -Name[ms]=SearchKeywordsFilter -Name[nb]=SearchKeywordsFilter -Name[nds]=Filter för Söökafkörten -Name[ne]=शब्दकुञ्जी फिल्टर खोजी गर्नुहोस् -Name[nl]=ZoekTermenFilter -Name[nn]=SøkjeuttrykkFilter -Name[or]=SearchKeywordsFilter -Name[pa]=ਖੋਜ ਸ਼ਬਦ ਫਿਲਟਰ -Name[pl]=Filtr słów kluczowych -Name[pt]=Filtro de Pesquisa de Palavras-Chave -Name[pt_BR]=Filtro de busca de palavras chave -Name[ro]=SearchKeywordsFilter -Name[ru]=SearchKeywordsFilter -Name[se]=SearchKeywordsFilter -Name[si]=සෙවුම් යතුරුවදන් පෙරහණ -Name[sk]=Filter kľúčových slov hľadania -Name[sl]=Filter ključnih besed za iskanje -Name[sr]=Филтер речи за претраживање -Name[sr@ijekavian]=Филтер ријечи за претраживање -Name[sr@ijekavianlatin]=Filter riječi za pretraživanje -Name[sr@latin]=Filter reči za pretraživanje -Name[sv]=Sök-nyckelordsfilter -Name[ta]=முக்கிய வார்த்தைகள் வடிகட்டியை தேடு -Name[te]=SearchKeywordsFilter -Name[tg]=SearchKeywordsFilter -Name[th]=ตัวกรองคำค้นหา -Name[tr]=TaramaKelimeSüzgeci -Name[ug]=ئىزدەش ئاچقۇچلۇق سۆز سۈزگۈچى -Name[uk]=Фільтр ключових слів інтернет -Name[uz]=Qidirish kalit soʻzlar filteri -Name[uz@cyrillic]=Қидириш калит сўзлар филтери -Name[vi]=SearchKeywordsFilter -Name[wa]=PasseteTapreceCweraedje -Name[xh]=Phendla Amagama Angundoqo Ecebo Lokucoca Ulwelo -Name[x-test]=xxSearchKeywordsFilterxx -Name[zh_CN]=搜索关键字过滤 -Name[zh_TW]=搜索關鍵字過濾 -X-KDE-Library=kf5/urifilters/kurisearchfilter -X-KDE-ServiceTypes=KUriFilter/Plugin -InitialPreference=4 diff --git a/src/urifilters/ikws/kurisearchfilter.json b/src/urifilters/ikws/kurisearchfilter.json new file mode 100644 index 00000000..91e136e3 --- /dev/null +++ b/src/urifilters/ikws/kurisearchfilter.json @@ -0,0 +1,6 @@ +{ + "KPlugin": { + "ServiceTypes": [ "KUriFilter/Plugin" ] + }, + "X-KDE-InitialPreference": 4 +} diff --git a/src/urifilters/localdomain/CMakeLists.txt b/src/urifilters/localdomain/CMakeLists.txt index b657f52a..4de825a6 100644 --- a/src/urifilters/localdomain/CMakeLists.txt +++ b/src/urifilters/localdomain/CMakeLists.txt @@ -1,12 +1,6 @@ -set(localdomainurifilter_PART_SRCS localdomainurifilter.cpp ) +set(localdomainurifilter_SRCS localdomainurifilter.cpp ) -add_library(localdomainurifilter MODULE ${localdomainurifilter_PART_SRCS}) +kcoreaddons_add_plugin(localdomainurifilter INSTALL_NAMESPACE "kf5/urifilters" JSON localdomainurifilter.json SOURCES ${localdomainurifilter_SRCS}) target_link_libraries(localdomainurifilter KF5::KIOWidgets) -set_target_properties(localdomainurifilter PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/urifilters") -install(TARGETS localdomainurifilter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/urifilters) - -########### install files ############### - -install(FILES localdomainurifilter.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) diff --git a/src/urifilters/localdomain/localdomainurifilter.cpp b/src/urifilters/localdomain/localdomainurifilter.cpp index fe4fbdb7..dd9cbb82 100644 --- a/src/urifilters/localdomain/localdomainurifilter.cpp +++ b/src/urifilters/localdomain/localdomainurifilter.cpp @@ -1,89 +1,89 @@ /* localdomainfilter.cpp This file is part of the KDE project Copyright (C) 2002 Lubos Lunak Copyright (C) 2010 Dawit Alemayehu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "localdomainurifilter.h" #include #include #include #include #include #define QL1C(x) QLatin1Char(x) #define QL1S(x) QLatin1String(x) #define HOSTPORT_PATTERN "[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*" namespace { QLoggingCategory category("org.kde.kurifilter-localdomain", QtWarningMsg); } /** * IMPORTANT: If you change anything here, make sure you run the kurifiltertest * regression test (this should be included as part of "make test"). */ LocalDomainUriFilter::LocalDomainUriFilter( QObject *parent, const QVariantList & /*args*/ ) :KUriFilterPlugin( QStringLiteral("localdomainurifilter"), parent ), m_hostPortPattern(QL1S(HOSTPORT_PATTERN)) { } bool LocalDomainUriFilter::filterUri(KUriFilterData& data) const { const QUrl url = data.uri(); const QString protocol = url.scheme(); // When checking for local domain just validate it is indeed a local domain, // but do not modify the hostname! See bug# if ((protocol.isEmpty() || !KProtocolInfo::isKnownProtocol(protocol)) && m_hostPortPattern.exactMatch(data.typedString())) { QString host (data.typedString().left(data.typedString().indexOf(QL1C('/')))); const int pos = host.indexOf(QL1C(':')); if (pos > -1) host.truncate(pos); // Remove port number if (exists(host)) { qCDebug(category) << "QHostInfo found a host called" << host; QString scheme (data.defaultUrlScheme()); if (scheme.isEmpty()) scheme = QStringLiteral("http://"); setFilteredUri(data, QUrl(scheme + data.typedString())); setUriType(data, KUriFilterData::NetProtocol); return true; } } return false; } bool LocalDomainUriFilter::exists(const QString& host) const { qCDebug(category) << "Checking if a host called" << host << "exists"; QHostInfo hostInfo = resolveName (host, 1500); return (hostInfo.error() == QHostInfo::NoError); } -K_PLUGIN_FACTORY(LocalDomainUriFilterFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(LocalDomainUriFilterFactory, "localdomainurifilter.json", registerPlugin();) #include "localdomainurifilter.moc" diff --git a/src/urifilters/localdomain/localdomainurifilter.desktop b/src/urifilters/localdomain/localdomainurifilter.desktop deleted file mode 100644 index a398a39c..00000000 --- a/src/urifilters/localdomain/localdomainurifilter.desktop +++ /dev/null @@ -1,94 +0,0 @@ -[Desktop Entry] -Type=Service -Name=LocalDomainFilter -Name[af]=Plaaslike domein filter -Name[as]=LocalDomainFilter -Name[ast]=LocalDomainFilter -Name[be]=LocalDomainFilter -Name[be@latin]=LocalDomainFilter -Name[bg]=LocalDomainFilter -Name[bn]=LocalDomainFilter -Name[bn_IN]=LocalDomainFilter -Name[bs]=Filter lokalnog domena -Name[ca]=Filtre de dominis locals -Name[ca@valencia]=Filtre de dominis locals -Name[cs]=Filtr pro lokální doménu -Name[csb]=Filter môlowi domenë -Name[cy]=HidlParthLleol -Name[da]=LocalDomainFilter -Name[de]=LocalDomainFilter -Name[el]=Φίλτρο τοπικού τομέα -Name[en_GB]=LocalDomainFilter -Name[eo]=LocalDomainFilter -Name[es]=FiltrodeDominioLocal -Name[et]=LocalDomainFilter -Name[eu]=LocalDomainFilter -Name[fa]=LocalDomainFilter -Name[fi]=LocalDomainFilter -Name[fr]=Filtre de domaine local -Name[fy]=Lokaaldomeinfilter -Name[ga]=LocalDomainFilter -Name[gd]=Criathrag nan àrainnean ionadail -Name[gl]=LocalDomainFilter -Name[gu]=સ્થાનિકડોમેઇનગાળક -Name[he]=LocalDomainFilter -Name[hi]=लोकल-डोमेन-फ़िल्टर -Name[hne]=लोकल-डोमेन-फिल्टर -Name[hr]=Filtar lokalnih domena -Name[hsb]=LocalDomainFilter -Name[hu]=HelyiTartománySzűrő -Name[ia]=LocalDomainFilter -Name[id]=LocalDomainFilter -Name[is]=LocalDomainFilter -Name[it]=Filtro di dominio locale -Name[kk]=LocalDomainFilter -Name[km]=LocalDomainFilter -Name[kn]=LocalDomainFilter -Name[ko]=LocalDomainFilter -Name[ku]=LocalDomainFilter -Name[lt]=LocalDomainFilter -Name[lv]=LokāloDomēnuFiltrs -Name[mai]=लोकल-डोमेन-फिल्टर -Name[mk]=LocalDomainFilter -Name[ml]=ലോക്കല്‍ഡൊമൈന്‍ഫില്‍ട്ടര്‍ -Name[mr]=स्थानिक क्षेत्र गाळणी -Name[ms]=LocalDomainFilter -Name[nb]=LocalDomainFilter -Name[nds]=Lokaaldomään-Filter -Name[ne]=स्थानीय डोमेन फिल्टर -Name[nl]=Lokaaldomeinfilter -Name[nn]=LocalDomainFilter -Name[or]=LocalDomainFilter -Name[pa]=ਲੋਕਲ ਡੋਮੇਨ ਫਿਲਟਰ -Name[pl]=Filtr lokalnej domeny -Name[pt]=LocalDomainFilter -Name[pt_BR]=Filtro de domínio local -Name[ro]=Filtru de domeniu local -Name[ru]=LocalDomainFilter -Name[se]=LocalDomainFilter -Name[si]=දේශීය ඩොමේන පෙරහන -Name[sk]=Filter lokálnej domény -Name[sl]=FilterLokalneDomene -Name[sr]=Филтер локалног домена -Name[sr@ijekavian]=Филтер локалног домена -Name[sr@ijekavianlatin]=Filter lokalnog domena -Name[sr@latin]=Filter lokalnog domena -Name[sv]=Lokal domänfilter -Name[ta]=LocalDomainFilter -Name[te]=LocalDomainFilter -Name[tg]=LocalDomainFilter -Name[th]=ตัวกรองโดเมนท้องถื่น -Name[tr]=LocalDomainFilter -Name[ug]=يەرلىك دائىرە سۈزگۈچ -Name[uk]=Фільтр локальних доменів -Name[uz]=LocalDomainFilter -Name[uz@cyrillic]=LocalDomainFilter -Name[vi]=LocalDomainFilter -Name[wa]=Passete Dominne coinrece -Name[xh]=LocalDomainFilter -Name[x-test]=xxLocalDomainFilterxx -Name[zh_CN]=本地域名过滤 -Name[zh_TW]=區域網域過濾器 -X-KDE-Library=kf5/urifilters/localdomainurifilter -X-KDE-ServiceTypes=KUriFilter/Plugin -InitialPreference=2 diff --git a/src/urifilters/localdomain/localdomainurifilter.json b/src/urifilters/localdomain/localdomainurifilter.json new file mode 100644 index 00000000..7fb47ad1 --- /dev/null +++ b/src/urifilters/localdomain/localdomainurifilter.json @@ -0,0 +1,6 @@ +{ + "KPlugin": { + "ServiceTypes": [ "KUriFilter/Plugin" ] + }, + "X-KDE-InitialPreference": 2 +} diff --git a/src/urifilters/shorturi/CMakeLists.txt b/src/urifilters/shorturi/CMakeLists.txt index cfbe7c83..02787470 100644 --- a/src/urifilters/shorturi/CMakeLists.txt +++ b/src/urifilters/shorturi/CMakeLists.txt @@ -1,13 +1,8 @@ -add_library(kshorturifilter MODULE kshorturifilter.cpp) +set(kshorturifilter_SRCS kshorturifilter.cpp) -target_link_libraries(kshorturifilter KF5::I18n KF5::KIOWidgets Qt5::DBus) - -set_target_properties(kshorturifilter PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/urifilters") -install(TARGETS kshorturifilter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/urifilters) +kcoreaddons_add_plugin(kshorturifilter INSTALL_NAMESPACE "kf5/urifilters" JSON kshorturifilter.json SERVICETYPES ${CMAKE_SOURCE_DIR}/src/widgets/kurifilterplugin.desktop SOURCES ${kshorturifilter_SRCS}) +target_link_libraries(kshorturifilter KF5::I18n KF5::KIOWidgets Qt5::DBus) -########### install files ############### - -install( FILES kshorturifilter.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( FILES kshorturifilterrc DESTINATION ${KDE_INSTALL_CONFDIR} ) diff --git a/src/urifilters/shorturi/kshorturifilter.cpp b/src/urifilters/shorturi/kshorturifilter.cpp index b00cc1d7..19e7e3be 100644 --- a/src/urifilters/shorturi/kshorturifilter.cpp +++ b/src/urifilters/shorturi/kshorturifilter.cpp @@ -1,573 +1,573 @@ /* -*- c-basic-offset: 2 -*- kshorturifilter.h This file is part of the KDE project Copyright (C) 2000 Dawit Alemayehu Copyright (C) 2000 Malte Starostik This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kshorturifilter.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { QLoggingCategory category("org.kde.kurifilter-shorturi", QtWarningMsg); } /** * IMPORTANT: If you change anything here, make sure you run the kurifiltertest * regression test (this should be included as part of "make test"). * * If you add anything, make sure to extend kurifiltertest to make sure it is * covered. */ typedef QMap EntryMap; static QRegularExpression sEnvVarExp (QStringLiteral("\\$[a-zA-Z_][a-zA-Z0-9_]*")); static bool isPotentialShortURL(const QString& cmd) { // Host names and IPv4 address... if (cmd.contains(QLatin1Char('.'))) { return true; } // IPv6 Address... if (cmd.startsWith(QLatin1Char('[')) && cmd.contains(QLatin1Char(':'))) { return true; } return false; } static QString removeArgs( const QString& _cmd ) { QString cmd( _cmd ); if( cmd[0] != '\'' && cmd[0] != '"' ) { // Remove command-line options (look for first non-escaped space) int spacePos = 0; do { spacePos = cmd.indexOf( ' ', spacePos+1 ); } while ( spacePos > 1 && cmd[spacePos - 1] == '\\' ); if( spacePos > 0 ) { cmd = cmd.left( spacePos ); qCDebug(category) << "spacePos=" << spacePos << " returning " << cmd; } } return cmd; } static bool isKnownProtocol(const QString &protocol) { if (KProtocolInfo::isKnownProtocol(protocol) || protocol == QLatin1String("mailto")) { return true; } const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QLatin1String("x-scheme-handler/") + protocol); return service; } KShortUriFilter::KShortUriFilter( QObject *parent, const QVariantList & /*args*/ ) :KUriFilterPlugin( QStringLiteral("kshorturifilter"), parent ) { QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"), QStringLiteral("configure"), this, SLOT(configure())); configure(); } bool KShortUriFilter::filterUri( KUriFilterData& data ) const { /* * Here is a description of how the shortURI deals with the supplied * data. First it expands any environment variable settings and then * deals with special shortURI cases. These special cases are the "smb:" * URL scheme which is very specific to KDE, "#" and "##" which are * shortcuts for man:/ and info:/ protocols respectively. It then handles * local files. Then it checks to see if the URL is valid and one that is * supported by KDE's IO system. If all the above checks fails, it simply * lookups the URL in the user-defined list and returns without filtering * if it is not found. TODO: the user-defined table is currently only manually * hackable and is missing a config dialog. */ //QUrl url = data.uri(); QString cmd = data.typedString(); int firstNonSlash = 0; while (firstNonSlash < cmd.length() && (cmd.at(firstNonSlash) == '/')) { firstNonSlash++; } if (firstNonSlash > 1) { cmd = cmd.mid(firstNonSlash - 1); } // Replicate what KUrl(cmd) did in KDE4. This could later be folded into the checks further down... QUrl url; if (QDir::isAbsolutePath(cmd)) { url = QUrl::fromLocalFile(cmd); } else { url.setUrl(cmd); } // WORKAROUND: Allow the use of '@' in the username component of a URL since // other browsers such as firefox in their infinite wisdom allow such blatant // violations of RFC 3986. BR# 69326/118413. if (cmd.count(QLatin1Char('@')) > 1) { const int lastIndex = cmd.lastIndexOf(QLatin1Char('@')); // Percent encode all but the last '@'. QString encodedCmd = QUrl::toPercentEncoding(cmd.left(lastIndex), ":/"); encodedCmd += cmd.midRef(lastIndex); cmd = encodedCmd; url.setUrl(encodedCmd); } const bool isMalformed = !url.isValid(); QString protocol = url.scheme(); qCDebug(category) << cmd; // Fix misparsing of "foo:80", QUrl thinks "foo" is the protocol and "80" is the path. // However, be careful not to do that for valid hostless URLs, e.g. file:///foo! if (!protocol.isEmpty() && url.host().isEmpty() && !url.path().isEmpty() && cmd.contains(':') && !isKnownProtocol(protocol)) { protocol.clear(); } qCDebug(category) << "url=" << url << "cmd=" << cmd << "isMalformed=" << isMalformed; // TODO: Make this a bit more intelligent for Minicli! There // is no need to make comparisons if the supplied data is a local // executable and only the argument part, if any, changed! (Dawit) // You mean caching the last filtering, to try and reuse it, to save stat()s? (David) const QString starthere_proto = QStringLiteral("start-here:"); if (cmd.indexOf(starthere_proto) == 0 ) { setFilteredUri( data, QUrl(QStringLiteral("system:/")) ); setUriType( data, KUriFilterData::LocalDir ); return true; } // Handle MAN & INFO pages shortcuts... const QString man_proto = QStringLiteral("man:"); const QString info_proto = QStringLiteral("info:"); if( cmd[0] == '#' || cmd.indexOf( man_proto ) == 0 || cmd.indexOf( info_proto ) == 0 ) { if( cmd.leftRef(2) == QLatin1String("##") ) cmd = QStringLiteral("info:/") + cmd.mid(2); else if ( cmd[0] == '#' ) cmd = QStringLiteral("man:/") + cmd.mid(1); else if ((cmd==info_proto) || (cmd==man_proto)) cmd+='/'; setFilteredUri( data, QUrl( cmd )); setUriType( data, KUriFilterData::Help ); return true; } // Detect UNC style (aka windows SMB) URLs if ( cmd.startsWith( QLatin1String( "\\\\") ) ) { // make sure path is unix style cmd.replace('\\', '/'); cmd.prepend( QLatin1String( "smb:" ) ); setFilteredUri( data, QUrl( cmd )); setUriType( data, KUriFilterData::NetProtocol ); return true; } bool expanded = false; // Expanding shortcut to HOME URL... QString path; QString ref; QString query; QString nameFilter; if (QDir::isRelativePath(cmd) && QUrl(cmd).isRelative()) { path = cmd; qCDebug(category) << "path=cmd=" << path; } else { if (url.isLocalFile()) { qCDebug(category) << "hasRef=" << url.hasFragment(); // Split path from ref/query // but not for "/tmp/a#b", if "a#b" is an existing file, // or for "/tmp/a?b" (#58990) if( ( url.hasFragment() || !url.query().isEmpty() ) && !url.path().endsWith(QLatin1Char('/')) ) // /tmp/?foo is a namefilter, not a query { path = url.path(); ref = url.fragment(); qCDebug(category) << "isLocalFile set path to" << path << "and ref to" << ref; query = url.query(); if (path.isEmpty() && !url.host().isEmpty()) path = '/'; } else { if (cmd.startsWith(QLatin1String("file://"))) { path = cmd.mid(strlen("file://")); } else { path = cmd; } qCDebug(category) << "(2) path=cmd=" << path; } } } if( path[0] == '~' ) { int slashPos = path.indexOf('/'); if( slashPos == -1 ) slashPos = path.length(); if( slashPos == 1 ) // ~/ { path.replace ( 0, 1, QDir::homePath() ); } else // ~username/ { const QString userName (path.mid( 1, slashPos-1 )); KUser user (userName); if( user.isValid() && !user.homeDir().isEmpty()) { path.replace (0, slashPos, user.homeDir()); } else { if (user.isValid()) { setErrorMsg(data, i18n("%1 does not have a home folder.", userName)); } else { setErrorMsg(data, i18n("There is no user called %1.", userName)); } setUriType( data, KUriFilterData::Error ); // Always return true for error conditions so // that other filters will not be invoked !! return true; } } expanded = true; } else if ( path[0] == '$' ) { // Environment variable expansion. auto match = sEnvVarExp.match(path); if ( match.hasMatch() ) { QByteArray exp = qgetenv( path.mid( 1, match.capturedLength() - 1 ).toLocal8Bit().data() ); if (!exp.isEmpty()) { path.replace( 0, match.capturedLength(), QFile::decodeName(exp) ); expanded = true; } } } if ( expanded || cmd.startsWith( '/' ) ) { // Look for #ref again, after $ and ~ expansion (testcase: $QTDIR/doc/html/functions.html#s) // Can't use QUrl here, setPath would escape it... const int pos = path.indexOf('#'); if ( pos > -1 ) { const QString newPath = path.left( pos ); if ( QFile::exists( newPath ) ) { ref = path.mid( pos + 1 ); path = newPath; qCDebug(category) << "Extracted ref: path=" << path << " ref=" << ref; } } } bool isLocalFullPath = QDir::isAbsolutePath(path); // Checking for local resource match... // Determine if "uri" is an absolute path to a local resource OR // A local resource with a supplied absolute path in KUriFilterData const QString abs_path = data.absolutePath(); const bool canBeAbsolute = (protocol.isEmpty() && !abs_path.isEmpty()); const bool canBeLocalAbsolute = (canBeAbsolute && abs_path[0] =='/' && !isMalformed); bool exists = false; /*qCDebug(category) << "abs_path=" << abs_path << "protocol=" << protocol << "canBeAbsolute=" << canBeAbsolute << "canBeLocalAbsolute=" << canBeLocalAbsolute << "isLocalFullPath=" << isLocalFullPath;*/ QT_STATBUF buff; if ( canBeLocalAbsolute ) { QString abs = QDir::cleanPath( abs_path ); // combine absolute path (abs_path) and relative path (cmd) into abs_path int len = path.length(); if( (len==1 && path[0]=='.') || (len==2 && path[0]=='.' && path[1]=='.') ) path += '/'; qCDebug(category) << "adding " << abs << " and " << path; abs = QDir::cleanPath(abs + '/' + path); qCDebug(category) << "checking whether " << abs << " exists."; // Check if it exists if(QT_STAT(QFile::encodeName(abs), &buff) == 0) { path = abs; // yes -> store as the new cmd exists = true; isLocalFullPath = true; } } if (isLocalFullPath && !exists && !isMalformed) { exists = QT_STAT(QFile::encodeName(path), &buff) == 0; if ( !exists ) { // Support for name filter (/foo/*.txt), see also KonqMainWindow::detectNameFilter // If the app using this filter doesn't support it, well, it'll simply error out itself int lastSlash = path.lastIndexOf( '/' ); if ( lastSlash > -1 && path.indexOf( ' ', lastSlash ) == -1 ) // no space after last slash, otherwise it's more likely command-line arguments { QString fileName = path.mid( lastSlash + 1 ); QString testPath = path.left(lastSlash); if ((fileName.indexOf('*') != -1 || fileName.indexOf('[') != -1 || fileName.indexOf( '?' ) != -1) && QT_STAT(QFile::encodeName(testPath), &buff) == 0) { nameFilter = fileName; qCDebug(category) << "Setting nameFilter to" << nameFilter << "and path to" << testPath; path = testPath; exists = true; } } } } qCDebug(category) << "path =" << path << " isLocalFullPath=" << isLocalFullPath << " exists=" << exists << " url=" << url; if( exists ) { QUrl u = QUrl::fromLocalFile(path); qCDebug(category) << "ref=" << ref << "query=" << query; u.setFragment(ref); u.setQuery(query); if (!KUrlAuthorized::authorizeUrlAction( QStringLiteral("open"), QUrl(), u)) { // No authorization, we pretend it's a file will get // an access denied error later on. setFilteredUri( data, u ); setUriType( data, KUriFilterData::LocalFile ); return true; } // Can be abs path to file or directory, or to executable with args bool isDir = ((buff.st_mode & QT_STAT_MASK) == QT_STAT_DIR); if( !isDir && access ( QFile::encodeName(path).data(), X_OK) == 0 ) { qCDebug(category) << "Abs path to EXECUTABLE"; setFilteredUri( data, u ); setUriType( data, KUriFilterData::Executable ); return true; } // Open "uri" as file:/xxx if it is a non-executable local resource. if( isDir || (( buff.st_mode & QT_STAT_MASK ) == QT_STAT_REG) ) { qCDebug(category) << "Abs path as local file or directory"; if ( !nameFilter.isEmpty() ) u.setPath( u.path() + '/' + nameFilter ); setFilteredUri( data, u ); setUriType( data, ( isDir ) ? KUriFilterData::LocalDir : KUriFilterData::LocalFile ); return true; } // Should we return LOCAL_FILE for non-regular files too? qCDebug(category) << "File found, but not a regular file nor dir... socket?"; } if( data.checkForExecutables()) { // Let us deal with possible relative URLs to see // if it is executable under the user's $PATH variable. // We try hard to avoid parsing any possible command // line arguments or options that might have been supplied. QString exe = removeArgs( cmd ); qCDebug(category) << "findExe with" << exe; if (!QStandardPaths::findExecutable( exe ).isNull() ) { qCDebug(category) << "EXECUTABLE exe=" << exe; setFilteredUri( data, QUrl::fromLocalFile( exe )); // check if we have command line arguments if( exe != cmd ) setArguments(data, cmd.right(cmd.length() - exe.length())); setUriType( data, KUriFilterData::Executable ); return true; } } // Process URLs of known and supported protocols so we don't have // to resort to the pattern matching scheme below which can possibly // slow things down... if ( !isMalformed && !isLocalFullPath && !protocol.isEmpty() ) { qCDebug(category) << "looking for protocol" << protocol; if (isKnownProtocol(protocol)) { setFilteredUri( data, url ); if ( protocol == QLatin1String("man") || protocol == QLatin1String("help") ) setUriType( data, KUriFilterData::Help ); else setUriType( data, KUriFilterData::NetProtocol ); return true; } } // Short url matches if ( !cmd.contains( ' ' ) ) { // Okay this is the code that allows users to supply custom matches for // specific URLs using Qt's regexp class. This is hard-coded for now. // TODO: Make configurable at some point... Q_FOREACH(const URLHint& hint, m_urlHints) { qCDebug(category) << "testing regexp for" << hint.prepend; if (hint.regexp.indexIn(cmd) == 0) { const QString cmdStr = hint.prepend + cmd; QUrl url(cmdStr); qCDebug(category) << "match - prepending" << hint.prepend << "->" << cmdStr << "->" << url; setFilteredUri( data, url ); setUriType( data, hint.type ); return true; } } // No protocol and not malformed means a valid short URL such as kde.org or // user@192.168.0.1. However, it might also be valid only because it lacks // the scheme component, e.g. www.kde,org (illegal ',' before 'org'). The // check below properly deciphers the difference between the two and sends // back the proper result. if (protocol.isEmpty() && isPotentialShortURL(cmd)) { QString urlStr = data.defaultUrlScheme(); if (urlStr.isEmpty()) urlStr = m_strDefaultUrlScheme; const int index = urlStr.indexOf(QLatin1Char(':')); if (index == -1 || !isKnownProtocol(urlStr.left(index))) urlStr += QStringLiteral("://"); urlStr += cmd; QUrl url (urlStr); if (url.isValid()) { setFilteredUri(data, url); setUriType(data, KUriFilterData::NetProtocol); } else if (isKnownProtocol(url.scheme())) { setFilteredUri(data, data.uri()); setUriType(data, KUriFilterData::Error); } return true; } } // If we previously determined that the URL might be a file, // and if it doesn't exist, then error if( isLocalFullPath && !exists ) { QUrl u = QUrl::fromLocalFile(path); u.setFragment(ref); if (!KUrlAuthorized::authorizeUrlAction( QStringLiteral("open"), QUrl(), u)) { // No authorization, we pretend it exists and will get // an access denied error later on. setFilteredUri( data, u ); setUriType( data, KUriFilterData::LocalFile ); return true; } qCDebug(category) << "fileNotFound -> ERROR"; setErrorMsg( data, i18n( "The file or folder %1 does not exist.", data.uri().toDisplayString() ) ); setUriType( data, KUriFilterData::Error ); return true; } // If we reach this point, we cannot filter this thing so simply return false // so that other filters, if present, can take a crack at it. return false; } KCModule* KShortUriFilter::configModule( QWidget*, const char* ) const { return nullptr; //new KShortUriOptions( parent, name ); } QString KShortUriFilter::configName() const { // return i18n("&ShortURLs"); we don't have a configModule so no need for a configName that confuses translators return KUriFilterPlugin::configName(); } void KShortUriFilter::configure() { KConfig config( objectName() + QStringLiteral( "rc"), KConfig::NoGlobals ); KConfigGroup cg( config.group("") ); m_strDefaultUrlScheme = cg.readEntry( "DefaultProtocol", QStringLiteral("http://") ); const EntryMap patterns = config.entryMap( QStringLiteral("Pattern") ); const EntryMap protocols = config.entryMap( QStringLiteral("Protocol") ); KConfigGroup typeGroup(&config, "Type"); for( EntryMap::ConstIterator it = patterns.begin(); it != patterns.end(); ++it ) { QString protocol = protocols[it.key()]; if (!protocol.isEmpty()) { int type = typeGroup.readEntry(it.key(), -1); if (type > -1 && type <= KUriFilterData::Unknown) m_urlHints.append( URLHint(it.value(), protocol, static_cast(type) ) ); else m_urlHints.append( URLHint(it.value(), protocol) ); } } } -K_PLUGIN_FACTORY(KShortUriFilterFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KShortUriFilterFactory, "kshorturifilter.json", registerPlugin();) #include "kshorturifilter.moc" diff --git a/src/urifilters/shorturi/kshorturifilter.desktop b/src/urifilters/shorturi/kshorturifilter.desktop deleted file mode 100644 index b7095799..00000000 --- a/src/urifilters/shorturi/kshorturifilter.desktop +++ /dev/null @@ -1,95 +0,0 @@ -[Desktop Entry] -Type=Service -Name=ShortURIFilter -Name[af]=KortURIfilter -Name[as]=ShortURIFilter -Name[ast]=ShortURIFilter -Name[be]=ShortURIFilter -Name[be@latin]=ShortURIFilter -Name[bg]=ShortURIFilter -Name[bn]=ShortURIFilter -Name[bn_IN]=ShortURIFilter -Name[br]=SilURLBerr -Name[bs]=Filter kratkih URI‑ja -Name[ca]=Filtre d'URI curt -Name[ca@valencia]=Filtre d'URI curt -Name[cs]=ShortURIFilter -Name[csb]=Filter krótczich URI -Name[cy]=HidlURIByr -Name[da]=KortURIFilter -Name[de]=Kurz-URL-Filter -Name[el]=Φίλτρο σύντομων URI -Name[en_GB]=ShortURIFilter -Name[eo]=ShortURIFilter -Name[es]=Filtro de URI cortas -Name[et]=Lühi-URL-ide filter -Name[eu]=ShortURIFilter -Name[fa]=ShortURIFilter -Name[fi]=ShortURIFilter -Name[fr]=Filtres d'URL courtes -Name[fy]=ShortURIFilter -Name[ga]=ShortURIFilter -Name[gd]=Criathrag nan URichean goirid -Name[gl]=ShortURIFilter -Name[gu]=ટૂંકુંURIગાળક -Name[he]=ShortURIFilter -Name[hi]=शॉर्ट-यूआरआई-फ़िल्टर -Name[hne]=सार्ट-यूआरआई-फिल्टर -Name[hr]=Filtar kratkih URI-a -Name[hsb]=ShortURIFilter -Name[hu]=RövidURISzűrő -Name[ia]=ShortURIFilter -Name[id]=ShortURIFilter -Name[is]=ShortURIFilter -Name[it]=Filtro di URI brevi -Name[kk]=ShortURIFilter -Name[km]=ShortURIFilter -Name[kn]=ShortURIFilter -Name[ko]=ShortURIFilter -Name[ku]=ShortURIFilter -Name[lt]=ShortURIFilter -Name[lv]=ĪssURIFiltrs -Name[mai]=शार्ट-यूआरआई-फिल्टर -Name[mk]=ShortURIFilter -Name[ml]=ഷോര്‍ട്ട്‌യുആര്‍ഐഫില്‍ട്ടര്‍ -Name[mr]=शॉर्ट URI गाळणी -Name[ms]=ShortURIFilter -Name[nb]=ShortURIFilter -Name[nds]=KortURI-Filter -Name[ne]=छोटो यूआरआई फिल्टर -Name[nl]=ShortURIFilter -Name[nn]=ShortURIFilter -Name[or]=ShortURIFilter -Name[pa]=ShortURI ਫਿਲਟਰ -Name[pl]=Filtr Krótkich URI -Name[pt]=ShortURIFilter -Name[pt_BR]=Filtro URI -Name[ro]=Filtru de URI-uri scurte -Name[ru]=ShortURIFilter -Name[se]=ShortURIFilter -Name[si]=කෙටි URI පෙරණය -Name[sk]=KrátkyURIFilter -Name[sl]=FilterZaKratkeURI -Name[sr]=Филтер кратких УРИ‑ја -Name[sr@ijekavian]=Филтер кратких УРИ‑ја -Name[sr@ijekavianlatin]=Filter kratkih URI‑ja -Name[sr@latin]=Filter kratkih URI‑ja -Name[sv]=Kort webbadressfilter -Name[ta]=ShortURIFilter -Name[te]=ShortURIFilter -Name[tg]=ShortURIFilter -Name[th]=ShortURIFilter -Name[tr]=KısaURISüzgeci -Name[ug]=قىسقا URI سۈزگۈچ -Name[uk]=Фільтр коротких URI -Name[uz]=ShortURIFilter -Name[uz@cyrillic]=ShortURIFilter -Name[vi]=ShortURIFilter -Name[wa]=Passete Coûte URI -Name[xh]=ShortURIFilter -Name[x-test]=xxShortURIFilterxx -Name[zh_CN]=短 URI 过滤 -Name[zh_TW]=短 URI 過濾器 -X-KDE-Library=kf5/urifilters/kshorturifilter -X-KDE-ServiceTypes=KUriFilter/Plugin -InitialPreference=5 diff --git a/src/urifilters/shorturi/kshorturifilter.json b/src/urifilters/shorturi/kshorturifilter.json new file mode 100644 index 00000000..e69c00ae --- /dev/null +++ b/src/urifilters/shorturi/kshorturifilter.json @@ -0,0 +1,6 @@ +{ + "KPlugin": { + "ServiceTypes": [ "KUriFilter/Plugin" ] + }, + "X-KDE-InitialPreference": 5 +} diff --git a/src/widgets/kurifilter.cpp b/src/widgets/kurifilter.cpp index 200fc08c..3efc97f9 100644 --- a/src/widgets/kurifilter.cpp +++ b/src/widgets/kurifilter.cpp @@ -1,693 +1,699 @@ /* This file is part of the KDE libraries * Copyright (C) 2000 Yves Arrouye * Copyright (C) 2000,2010 Dawit Alemayehu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. **/ #include "kurifilter.h" #include "hostinfo.h" #include -#include +#include #include +#include + #include #include #include #include typedef QList KUriFilterPluginList; typedef QMap SearchProviderMap; static QString lookupIconNameFor(const QUrl &url, KUriFilterData::UriTypes type) { QString iconName; switch (type) { case KUriFilterData::NetProtocol: iconName = KIO::iconNameForUrl(url); break; case KUriFilterData::Executable: { QString exeName = url.path(); exeName = exeName.mid(exeName.lastIndexOf('/') + 1); // strip path if given KService::Ptr service = KService::serviceByDesktopName(exeName); if (service && service->icon() != QLatin1String("unknown")) { iconName = service->icon(); } // Try to find an icon with the same name as the binary (useful for non-kde apps) // Use iconPath rather than loadIcon() as the latter uses QPixmap (not threadsafe) else if (!KIconLoader::global()->iconPath(exeName, KIconLoader::NoGroup, true).isNull()) { iconName = exeName; } else // not found, use default { iconName = QStringLiteral("system-run"); } break; } case KUriFilterData::Help: { iconName = QStringLiteral("khelpcenter"); break; } case KUriFilterData::Shell: { iconName = QStringLiteral("konsole"); break; } case KUriFilterData::Error: case KUriFilterData::Blocked: { iconName = QStringLiteral("error"); break; } default: break; } return iconName; } class KUriFilterSearchProvider::KUriFilterSearchProviderPrivate { public: KUriFilterSearchProviderPrivate() {} KUriFilterSearchProviderPrivate(const KUriFilterSearchProviderPrivate &other) : desktopEntryName(other.desktopEntryName), iconName(other.iconName), name(other.name), keys(other.keys) {} QString desktopEntryName; QString iconName; QString name; QStringList keys; }; KUriFilterSearchProvider::KUriFilterSearchProvider() : d(new KUriFilterSearchProvider::KUriFilterSearchProviderPrivate) { } KUriFilterSearchProvider::KUriFilterSearchProvider(const KUriFilterSearchProvider &other) : d(new KUriFilterSearchProvider::KUriFilterSearchProviderPrivate(*(other.d))) { } KUriFilterSearchProvider::~KUriFilterSearchProvider() { delete d; } QString KUriFilterSearchProvider::desktopEntryName() const { return d->desktopEntryName; } QString KUriFilterSearchProvider::iconName() const { return d->iconName; } QString KUriFilterSearchProvider::name() const { return d->name; } QStringList KUriFilterSearchProvider::keys() const { return d->keys; } QString KUriFilterSearchProvider::defaultKey() const { if (d->keys.isEmpty()) { return QString(); } return d->keys.first(); } KUriFilterSearchProvider &KUriFilterSearchProvider::operator=(const KUriFilterSearchProvider &other) { d->desktopEntryName = other.d->desktopEntryName; d->iconName = other.d->iconName; d->keys = other.d->keys; d->name = other.d->name; return *this; } void KUriFilterSearchProvider::setDesktopEntryName(const QString &desktopEntryName) { d->desktopEntryName = desktopEntryName; } void KUriFilterSearchProvider::setIconName(const QString &iconName) { d->iconName = iconName; } void KUriFilterSearchProvider::setName(const QString &name) { d->name = name; } void KUriFilterSearchProvider::setKeys(const QStringList &keys) { d->keys = keys; } class KUriFilterDataPrivate { public: explicit KUriFilterDataPrivate(const QUrl &u, const QString &typedUrl) : checkForExecs(true), wasModified(true), uriType(KUriFilterData::Unknown), searchFilterOptions(KUriFilterData::SearchFilterOptionNone), url(u), typedString(typedUrl) { } ~KUriFilterDataPrivate() { qDeleteAll(searchProviderMap.begin(), searchProviderMap.end()); } void setData(const QUrl &u, const QString &typedUrl) { checkForExecs = true; wasModified = true; uriType = KUriFilterData::Unknown; searchFilterOptions = KUriFilterData::SearchFilterOptionNone; url = u; typedString = typedUrl; errMsg.clear(); iconName.clear(); absPath.clear(); args.clear(); searchTerm.clear(); searchProvider.clear(); searchTermSeparator = QChar(); alternateDefaultSearchProvider.clear(); alternateSearchProviders.clear(); searchProviderMap.clear(); defaultUrlScheme.clear(); } KUriFilterDataPrivate(KUriFilterDataPrivate *data) { wasModified = data->wasModified; checkForExecs = data->checkForExecs; uriType = data->uriType; searchFilterOptions = data->searchFilterOptions; url = data->url; typedString = data->typedString; errMsg = data->errMsg; iconName = data->iconName; absPath = data->absPath; args = data->args; searchTerm = data->searchTerm; searchTermSeparator = data->searchTermSeparator; searchProvider = data->searchProvider; alternateDefaultSearchProvider = data->alternateDefaultSearchProvider; alternateSearchProviders = data->alternateSearchProviders; searchProviderMap = data->searchProviderMap; defaultUrlScheme = data->defaultUrlScheme; } bool checkForExecs; bool wasModified; KUriFilterData::UriTypes uriType; KUriFilterData::SearchFilterOptions searchFilterOptions; QUrl url; QString typedString; QString errMsg; QString iconName; QString absPath; QString args; QString searchTerm; QString searchProvider; QString alternateDefaultSearchProvider; QString defaultUrlScheme; QChar searchTermSeparator; QStringList alternateSearchProviders; QStringList searchProviderList; SearchProviderMap searchProviderMap; }; KUriFilterData::KUriFilterData() : d(new KUriFilterDataPrivate(QUrl(), QString())) { } KUriFilterData::KUriFilterData(const QUrl &url) : d(new KUriFilterDataPrivate(url, url.toString())) { } KUriFilterData::KUriFilterData(const QString &url) : d(new KUriFilterDataPrivate(QUrl::fromUserInput(url), url)) { } KUriFilterData::KUriFilterData(const KUriFilterData &other) : d(new KUriFilterDataPrivate(other.d)) { } KUriFilterData::~KUriFilterData() { delete d; } QUrl KUriFilterData::uri() const { return d->url; } QString KUriFilterData::errorMsg() const { return d->errMsg; } KUriFilterData::UriTypes KUriFilterData::uriType() const { return d->uriType; } QString KUriFilterData::absolutePath() const { return d->absPath; } bool KUriFilterData::hasAbsolutePath() const { return !d->absPath.isEmpty(); } QString KUriFilterData::argsAndOptions() const { return d->args; } bool KUriFilterData::hasArgsAndOptions() const { return !d->args.isEmpty(); } bool KUriFilterData::checkForExecutables() const { return d->checkForExecs; } QString KUriFilterData::typedString() const { return d->typedString; } QString KUriFilterData::searchTerm() const { return d->searchTerm; } QChar KUriFilterData::searchTermSeparator() const { return d->searchTermSeparator; } QString KUriFilterData::searchProvider() const { return d->searchProvider; } QStringList KUriFilterData::preferredSearchProviders() const { return d->searchProviderList; } KUriFilterSearchProvider KUriFilterData::queryForSearchProvider(const QString &provider) const { const KUriFilterSearchProvider *searchProvider = d->searchProviderMap.value(provider); if (searchProvider) { return *(searchProvider); } return KUriFilterSearchProvider(); } QString KUriFilterData::queryForPreferredSearchProvider(const QString &provider) const { const KUriFilterSearchProvider *searchProvider = d->searchProviderMap.value(provider); if (searchProvider) { return (searchProvider->defaultKey() % searchTermSeparator() % searchTerm()); } return QString(); } QStringList KUriFilterData::allQueriesForSearchProvider(const QString &provider) const { const KUriFilterSearchProvider *searchProvider = d->searchProviderMap.value(provider); if (searchProvider) { return searchProvider->keys(); } return QStringList(); } QString KUriFilterData::iconNameForPreferredSearchProvider(const QString &provider) const { const KUriFilterSearchProvider *searchProvider = d->searchProviderMap.value(provider); if (searchProvider) { return searchProvider->iconName(); } return QString(); } QStringList KUriFilterData::alternateSearchProviders() const { return d->alternateSearchProviders; } QString KUriFilterData::alternateDefaultSearchProvider() const { return d->alternateDefaultSearchProvider; } QString KUriFilterData::defaultUrlScheme() const { return d->defaultUrlScheme; } KUriFilterData::SearchFilterOptions KUriFilterData::searchFilteringOptions() const { return d->searchFilterOptions; } QString KUriFilterData::iconName() { if (d->wasModified) { d->iconName = lookupIconNameFor(d->url, d->uriType); d->wasModified = false; } return d->iconName; } void KUriFilterData::setData(const QUrl &url) { d->setData(url, url.toString()); } void KUriFilterData::setData(const QString &url) { d->setData(QUrl(url), url); } bool KUriFilterData::setAbsolutePath(const QString &absPath) { // Since a malformed URL could possibly be a relative // URL we tag it as a possible local resource... if ((d->url.scheme().isEmpty() || d->url.isLocalFile())) { d->absPath = absPath; return true; } return false; } void KUriFilterData::setCheckForExecutables(bool check) { d->checkForExecs = check; } void KUriFilterData::setAlternateSearchProviders(const QStringList &providers) { d->alternateSearchProviders = providers; } void KUriFilterData::setAlternateDefaultSearchProvider(const QString &provider) { d->alternateDefaultSearchProvider = provider; } void KUriFilterData::setDefaultUrlScheme(const QString &scheme) { d->defaultUrlScheme = scheme; } void KUriFilterData::setSearchFilteringOptions(SearchFilterOptions options) { d->searchFilterOptions = options; } KUriFilterData &KUriFilterData::operator=(const QUrl &url) { d->setData(url, url.toString()); return *this; } KUriFilterData &KUriFilterData::operator=(const QString &url) { d->setData(QUrl(url), url); return *this; } /************************* KUriFilterPlugin ******************************/ KUriFilterPlugin::KUriFilterPlugin(const QString &name, QObject *parent) : QObject(parent), d(nullptr) { setObjectName(name); } KCModule *KUriFilterPlugin::configModule(QWidget *, const char *) const { return nullptr; } QString KUriFilterPlugin::configName() const { return objectName(); } void KUriFilterPlugin::setFilteredUri(KUriFilterData &data, const QUrl &uri) const { data.d->url = uri; data.d->wasModified = true; //qDebug() << "Got filtered to:" << uri; } void KUriFilterPlugin::setErrorMsg(KUriFilterData &data, const QString &errmsg) const { data.d->errMsg = errmsg; } void KUriFilterPlugin::setUriType(KUriFilterData &data, KUriFilterData::UriTypes type) const { data.d->uriType = type; data.d->wasModified = true; } void KUriFilterPlugin::setArguments(KUriFilterData &data, const QString &args) const { data.d->args = args; } void KUriFilterPlugin::setSearchProvider(KUriFilterData &data, const QString &provider, const QString &term, const QChar &separator) const { data.d->searchProvider = provider; data.d->searchTerm = term; data.d->searchTermSeparator = separator; } void KUriFilterPlugin::setSearchProviders(KUriFilterData &data, const QList &providers) const { Q_FOREACH (KUriFilterSearchProvider *searchProvider, providers) { data.d->searchProviderList << searchProvider->name(); data.d->searchProviderMap.insert(searchProvider->name(), searchProvider); } } QString KUriFilterPlugin::iconNameFor(const QUrl &url, KUriFilterData::UriTypes type) const { return lookupIconNameFor(url, type); } QHostInfo KUriFilterPlugin::resolveName(const QString &hostname, unsigned long timeout) const { return KIO::HostInfo::lookupHost(hostname, timeout); } /******************************* KUriFilter ******************************/ class KUriFilterPrivate { public: KUriFilterPrivate() {} ~KUriFilterPrivate() { qDeleteAll(plugins); plugins.clear(); } QHash plugins; // NOTE: DO NOT REMOVE this variable! Read the // comments in KUriFilter::loadPlugins to understand why... QStringList pluginNames; }; class KUriFilterSingleton { public: KUriFilter instance; }; Q_GLOBAL_STATIC(KUriFilterSingleton, m_self) KUriFilter *KUriFilter::self() { return &m_self()->instance; } KUriFilter::KUriFilter() : d(new KUriFilterPrivate()) { loadPlugins(); } KUriFilter::~KUriFilter() { delete d; } bool KUriFilter::filterUri(KUriFilterData &data, const QStringList &filters) { bool filtered = false; // If no specific filters were requested, iterate through all the plugins. // Otherwise, only use available filters. if (filters.isEmpty()) { QStringListIterator it(d->pluginNames); while (it.hasNext()) { KUriFilterPlugin *plugin = d->plugins.value(it.next()); if (plugin && plugin->filterUri(data)) { filtered = true; } } } else { QStringListIterator it(filters); while (it.hasNext()) { KUriFilterPlugin *plugin = d->plugins.value(it.next()); if (plugin && plugin->filterUri(data)) { filtered = true; } } } return filtered; } bool KUriFilter::filterUri(QUrl &uri, const QStringList &filters) { KUriFilterData data(uri); bool filtered = filterUri(data, filters); if (filtered) { uri = data.uri(); } return filtered; } bool KUriFilter::filterUri(QString &uri, const QStringList &filters) { KUriFilterData data(uri); bool filtered = filterUri(data, filters); if (filtered) { uri = data.uri().toString(); } return filtered; } QUrl KUriFilter::filteredUri(const QUrl &uri, const QStringList &filters) { KUriFilterData data(uri); filterUri(data, filters); return data.uri(); } QString KUriFilter::filteredUri(const QString &uri, const QStringList &filters) { KUriFilterData data(uri); filterUri(data, filters); return data.uri().toString(); } #ifndef KIOWIDGETS_NO_DEPRECATED bool KUriFilter::filterSearchUri(KUriFilterData &data) { return filterSearchUri(data, (NormalTextFilter | WebShortcutFilter)); } #endif bool KUriFilter::filterSearchUri(KUriFilterData &data, SearchFilterTypes types) { QStringList filters; if (types & WebShortcutFilter) { filters << QStringLiteral("kurisearchfilter"); } if (types & NormalTextFilter) { filters << QStringLiteral("kuriikwsfilter"); } return filterUri(data, filters); } QStringList KUriFilter::pluginNames() const { return d->pluginNames; } void KUriFilter::loadPlugins() { - const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KUriFilter/Plugin")); - - // NOTE: Plugin priority is determined by the InitialPreference entry in - // the .desktop files, so the trader result is already sorted and should - // not be manually sorted. - Q_FOREACH (const KService::Ptr &ptr, offers) { - KUriFilterPlugin *plugin = ptr->createInstance(); - if (plugin) { - const QString &pluginName = plugin->objectName(); - Q_ASSERT(!pluginName.isEmpty()); - d->plugins.insert(pluginName, plugin); - // Needed to ensure the order of filtering is honored since - // items are ordered arbitrarily in a QHash and QMap always - // sorts by keys. Both undesired behavior. - d->pluginNames << pluginName; + QVector plugins = KPluginLoader::findPlugins("kf5/urifilters"); + // Sort the plugins by order of priority + std::sort(plugins.begin(), plugins.end(), [](const KPluginMetaData &a, const KPluginMetaData &b) { + return a.rawData().value("X-KDE-InitialPreference").toInt() > b.rawData().value("X-KDE-InitialPreference").toInt(); + }); + + for (const KPluginMetaData &pluginMetaData : plugins) { + KPluginFactory *factory = qobject_cast(pluginMetaData.instantiate()); + if (factory) { + KUriFilterPlugin *plugin = factory->create(nullptr); + if (plugin) { + const QString &pluginName = plugin->objectName(); + Q_ASSERT(!pluginName.isEmpty()); + d->plugins.insert(pluginName, plugin); + // Needed to ensure the order of filtering is honored since + // items are ordered arbitrarily in a QHash and QMap always + // sorts by keys. Both undesired behavior. + d->pluginNames << pluginName; + } } } } diff --git a/src/widgets/kurifilterplugin.desktop b/src/widgets/kurifilterplugin.desktop index 7fd75ec0..8358608b 100644 --- a/src/widgets/kurifilterplugin.desktop +++ b/src/widgets/kurifilterplugin.desktop @@ -1,55 +1,58 @@ [Desktop Entry] Type=ServiceType X-KDE-ServiceType=KUriFilter/Plugin Name=Enhanced Browsing Plugin Name[ar]=ملحقة تصفّح محسنة Name[ast]=Complementu de restolar ameyoráu Name[ca]=Connector per a la navegació millorada Name[ca@valencia]=Connector per a la navegació millorada Name[cs]=Modul rozšířeného procházení Name[da]=Plugin til forbedret browsing Name[de]=Erweitertes Browser-Modul Name[el]=Πρότυπο εμπλουτισμένης περιήγησης Name[en_GB]=Enhanced Browsing Plugin Name[es]=Complemento de exploración avanzada Name[et]=Täiustatud brausimise plugin Name[eu]=Arakatze hobeturako plugina Name[fi]=Laajennetun selauksen liitännäinen Name[fr]=Module externe de navigation avancée Name[gd]=Plugan airson brabhsadh leasaichte Name[gl]=Complemento de navegación mellorada Name[hu]=Továbbfejlesztett böngészés bővítőmodul Name[hy]=Հավելյալ թերթելու հարմարանք Name[ia]=Plugin de navigation avantiate Name[id]=Plugin Meramban Canggih Name[it]=Estensione di navigazione avanzata Name[ja]=拡張ブラウズプラグイン Name[ko]=고급 탐색 플러그인 Name[lb]=Erweiderte Browser-Plugin Name[lt]=Išplėstinio naršymo papildinys Name[mr]=प्रगत ब्राउजिंग प्लगइन Name[nb]=Programtillegg for utvidet nettlesing Name[nds]=Nettkiekverwiedern-Plugin Name[nl]=Verbeterd Browsen Plugin Name[nn]=Programtillegg for nettlesarforbetringar Name[pa]=ਇੰਹਾਂਸਡ ਬਰਾਊਜ਼ਿੰਗ ਪਲੱਗਇਨ Name[pl]=Moduł do rozszerzonego przeglądania Name[ps]=پرمختللی لټوونی لګون Name[pt]='Plugin' de Navegação Melhorada Name[pt_BR]=Plugin de navegação melhorada Name[ru]=Расширение просмотра Name[se]=Njuovžilut fierbmádatlogadeami lassemoduvla Name[sk]=Modul rozšíreného prehliadania Name[sl]=Vstavek za izboljšano brskanje Name[sr]=Прикључак за побољшано прегледање Name[sr@ijekavian]=Прикључак за побољшано прегледање Name[sr@ijekavianlatin]=Priključak za poboljšano pregledanje Name[sr@latin]=Priključak za poboljšano pregledanje Name[sv]=Utökad webbläsning Name[tr]=Gelişmiş Tarayıcı Eklentisi Name[tt]=Киңәйтелгән күзәтү өстәмәсе Name[uk]=Додаток розширеної навігації Name[x-test]=xxEnhanced Browsing Pluginxx Name[zh_CN]=增强的浏览插件 Name[zh_HK]=增強功能的瀏覽外掛程式 Name[zh_TW]=增強的瀏覽外掛程式 + +[PropertyDef::X-KDE-InitialPreference] +Type=int