Commit c8c2eff2 authored by David Faure's avatar David Faure
Browse files

GIT_SILENT Reformat code using uncrustify-kf5

parent 2c379fec
......@@ -34,25 +34,25 @@
*/
FixHostUriFilter::FixHostUriFilter(QObject *parent, const QVariantList & /*args*/)
:KUriFilterPlugin(QStringLiteral("fixhosturifilter"), parent)
: KUriFilterPlugin(QStringLiteral("fixhosturifilter"), parent)
{
}
static bool isHttpUrl(const QString& scheme)
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);
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)
static bool hasCandidateHostName(const QString &host)
{
return (host.contains(QL1C('.')) &&
!host.startsWith(QL1S("www."), Qt::CaseInsensitive));
return host.contains(QL1C('.'))
&& !host.startsWith(QL1S("www."), Qt::CaseInsensitive);
}
bool FixHostUriFilter::filterUri( KUriFilterData& data ) const
bool FixHostUriFilter::filterUri(KUriFilterData &data) const
{
QUrl url = data.uri();
......@@ -76,18 +76,18 @@ bool FixHostUriFilter::filterUri( KUriFilterData& data ) const
return false;
}
bool FixHostUriFilter::isResolvable(const QString& host) const
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);
return info.error() == QHostInfo::NoError
|| info.error() == QHostInfo::UnknownError;
}
bool FixHostUriFilter::exists(const QString& host) const
bool FixHostUriFilter::exists(const QString &host) const
{
QHostInfo info = resolveName(host, 1500);
return (info.error() == QHostInfo::NoError);
return info.error() == QHostInfo::NoError;
}
K_PLUGIN_CLASS_WITH_JSON(FixHostUriFilter, "fixhosturifilter.json")
......
......@@ -34,12 +34,12 @@ class FixHostUriFilter : public KUriFilterPlugin
Q_OBJECT
public:
FixHostUriFilter(QObject* parent, const QVariantList& args);
FixHostUriFilter(QObject *parent, const QVariantList &args);
bool filterUri(KUriFilterData &data) const override;
private:
bool exists(const QString& host) const;
bool isResolvable(const QString& host) const;
bool exists(const QString &host) const;
bool isResolvable(const QString &host) const;
};
#endif
This diff is collapsed.
......@@ -37,20 +37,19 @@ class FilterOptions : public KCModule
Q_OBJECT
public:
explicit FilterOptions(const KAboutData* about, QWidget *parent = nullptr);
explicit FilterOptions(const KAboutData *about, QWidget *parent = nullptr);
void load() override;
void save() override;
void defaults() override;
QString quickHelp() const override;
private Q_SLOTS:
void updateSearchProviderEditingButons();
void addSearchProvider();
void changeSearchProvider();
void deleteSearchProvider();
private:
void setDelimiter(char);
char delimiter();
......@@ -60,7 +59,7 @@ private:
// these are marked as deleted in the user's homedirectory
// on save if a global service file exists for it.
QStringList m_deletedProviders;
ProvidersModel* m_providersModel;
ProvidersModel *m_providersModel;
SearchProviderRegistry m_registry;
Ui::FilterOptionsUI m_dlg;
......
......@@ -23,38 +23,48 @@
class SearchProvider;
class ProvidersModel: public QAbstractTableModel
class ProvidersModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum {Name,Shortcuts,Preferred,ColumnCount};
explicit ProvidersModel(QObject* parent = nullptr): QAbstractTableModel(parent){}
enum {Name, Shortcuts, Preferred, ColumnCount};
explicit ProvidersModel(QObject *parent = nullptr) : QAbstractTableModel(parent)
{
}
~ProvidersModel();
Qt::ItemFlags flags(const QModelIndex& index) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override{Q_UNUSED(parent); return ColumnCount;}
void setProviders(const QList<SearchProvider*>&, const QStringList&);
void setFavoriteProviders(const QStringList&);
void addProvider(SearchProvider* p);
void deleteProvider(SearchProvider* p);
void changeProvider(SearchProvider* p);
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
Q_UNUSED(parent);
return ColumnCount;
}
void setProviders(const QList<SearchProvider *> &, const QStringList &);
void setFavoriteProviders(const QStringList &);
void addProvider(SearchProvider *p);
void deleteProvider(SearchProvider *p);
void changeProvider(SearchProvider *p);
QStringList favoriteEngines() const;
QList<SearchProvider*> providers() const{ return m_providers;}
QList<SearchProvider *> providers() const
{
return m_providers;
}
///Creates new ProvidersListModel which directly uses data of this model.
QAbstractListModel* createListModel();
QAbstractListModel *createListModel();
Q_SIGNALS:
void dataModified();
private:
QSet<QString> m_favoriteEngines;
QList<SearchProvider*> m_providers;
QList<SearchProvider *> m_providers;
};
/**
......@@ -62,28 +72,47 @@ private:
* It is created via ProvidersModel::createListModel() and uses createListModel's data directly,
* just forwarding all the signals
*/
class ProvidersListModel: public QAbstractListModel
class ProvidersListModel : public QAbstractListModel
{
Q_OBJECT
public:
enum{ShortNameRole = Qt::UserRole};
enum {ShortNameRole = Qt::UserRole};
private:
explicit ProvidersListModel(QList<SearchProvider*>& providers, QObject* parent = nullptr) ;
explicit ProvidersListModel(QList<SearchProvider *> &providers, QObject *parent = nullptr);
public:
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
public Q_SLOTS:
void emitDataChanged(const QModelIndex& start, const QModelIndex& end){emit dataChanged(index(start.row(),0),index(end.row(),0));}
void emitRowsAboutToBeInserted(const QModelIndex&, int start, int end){beginInsertRows(QModelIndex(),start,end);}
void emitRowsAboutToBeRemoved(const QModelIndex&, int start, int end){beginRemoveRows(QModelIndex(),start,end);}
void emitRowsInserted(const QModelIndex&, int , int){endInsertRows();}
void emitRowsRemoved(const QModelIndex& , int , int){endRemoveRows();}
void emitDataChanged(const QModelIndex &start, const QModelIndex &end)
{
emit dataChanged(index(start.row(), 0), index(end.row(), 0));
}
void emitRowsAboutToBeInserted(const QModelIndex &, int start, int end)
{
beginInsertRows(QModelIndex(), start, end);
}
void emitRowsAboutToBeRemoved(const QModelIndex &, int start, int end)
{
beginRemoveRows(QModelIndex(), start, end);
}
void emitRowsInserted(const QModelIndex &, int, int)
{
endInsertRows();
}
void emitRowsRemoved(const QModelIndex &, int, int)
{
endRemoveRows();
}
private:
QList<SearchProvider*>& m_providers;
QList<SearchProvider *> &m_providers;
friend class ProvidersModel;
};
......
......@@ -43,12 +43,12 @@ QLoggingCategory category("org.kde.kurifilter-ikws", QtWarningMsg);
K_PLUGIN_CLASS_WITH_JSON(KAutoWebSearch, "kuriikwsfilter.json")
KAutoWebSearch::KAutoWebSearch(QObject *parent, const QVariantList&)
:KUriFilterPlugin( QStringLiteral("kuriikwsfilter"), parent )
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()));
KLocalizedString::insertQtDomain("kurifilter");
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"),
QStringLiteral("configure"), this, SLOT(configure()));
}
KAutoWebSearch::~KAutoWebSearch()
......@@ -57,116 +57,106 @@ KAutoWebSearch::~KAutoWebSearch()
void KAutoWebSearch::configure()
{
qCDebug(category) << "Config reload requested...";
KURISearchFilterEngine::self()->loadConfig();
qCDebug(category) << "Config reload requested...";
KURISearchFilterEngine::self()->loadConfig();
}
void KAutoWebSearch::populateProvidersList(QList<KUriFilterSearchProvider*>& searchProviders,
const KUriFilterData& data, bool allproviders) const
void KAutoWebSearch::populateProvidersList(QList<KUriFilterSearchProvider *> &searchProviders, const KUriFilterData &data, bool allproviders) const
{
QList<SearchProvider*> providers;
KURISearchFilterEngine *filter = KURISearchFilterEngine::self();
if (allproviders)
providers = filter->registry()->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...
std::stable_sort(favEngines.begin(), favEngines.end());
// Add the search engine set as the default provider...
const QString defaultEngine = filter->defaultSearchEngine();
if (!defaultEngine.isEmpty()) {
favEngines.removeAll(defaultEngine);
favEngines.insert(0, defaultEngine);
}
QList<SearchProvider *> providers;
KURISearchFilterEngine *filter = KURISearchFilterEngine::self();
QStringListIterator it (favEngines);
while (it.hasNext())
{
SearchProvider *favProvider = filter->registry()->findByDesktopName(it.next());
if (favProvider)
providers << favProvider;
if (allproviders) {
providers = filter->registry()->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...
std::stable_sort(favEngines.begin(), favEngines.end());
// 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 = filter->registry()->findByDesktopName(it.next());
if (favProvider) {
providers << favProvider;
}
}
}
}
for (int i = 0, count = providers.count(); i < count; ++i)
{
searchProviders << providers[i];
}
for (int i = 0, count = providers.count(); i < count; ++i) {
searchProviders << providers[i];
}
}
bool KAutoWebSearch::filterUri( KUriFilterData &data ) const
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<KUriFilterSearchProvider*> 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<KUriFilterSearchProvider*> searchProviders;
populateProvidersList(searchProviders, data, true);
if (searchProviders.isEmpty())
{
setUriType(data, KUriFilterData::Error);
setErrorMsg(data, i18n("No search providers were found."));
return false;
qCDebug(category) << data.typedString();
KUriFilterData::SearchFilterOptions option = data.searchFilteringOptions();
// Handle the flag to retrieve only preferred providers, no filtering...
if (option & KUriFilterData::RetrievePreferredSearchProvidersOnly) {
QList<KUriFilterSearchProvider *> 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;
}
}
setSearchProvider(data, QString(), data.typedString(), QL1C(KURISearchFilterEngine::self()->keywordDelimiter()));
setSearchProviders(data, searchProviders);
return true;
}
if (option & KUriFilterData::RetrieveSearchProvidersOnly) {
QList<KUriFilterSearchProvider *> 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<KUriFilterSearchProvider*> searchProviders;
populateProvidersList(searchProviders, data);
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<KUriFilterSearchProvider *> searchProviders;
populateProvidersList(searchProviders, data);
setSearchProviders(data, searchProviders);
return true;
}
}
}
return false;
return false;
}
#include "kuriikwsfilter.moc"
......@@ -29,15 +29,15 @@ class KAutoWebSearch : public KUriFilterPlugin
{
Q_OBJECT
public:
explicit KAutoWebSearch(QObject *parent = nullptr, const QVariantList &args = QVariantList() );
explicit KAutoWebSearch(QObject *parent = nullptr, const QVariantList &args = QVariantList());
~KAutoWebSearch();
bool filterUri( KUriFilterData& ) const override;
bool filterUri(KUriFilterData &) const override;
public Q_SLOTS:
void configure();
private:
void populateProvidersList(QList<KUriFilterSearchProvider*>& searchProviders, const KUriFilterData&, bool allproviders = false) const;
void populateProvidersList(QList<KUriFilterSearchProvider *> &searchProviders, const KUriFilterData &, bool allproviders = false) const;
};
#endif
This diff is collapsed.
......@@ -31,50 +31,47 @@
#include "searchproviderregistry.h"
#define DEFAULT_PREFERRED_SEARCH_PROVIDERS \
QStringList() << QStringLiteral("google") << QStringLiteral("youtube") << QStringLiteral("yahoo") << QStringLiteral("wikipedia") << QStringLiteral("wikit")
QStringList() << QStringLiteral("google") << QStringLiteral("youtube") << QStringLiteral("yahoo") << QStringLiteral("wikipedia") << QStringLiteral("wikit")
class SearchProvider;
class KURISearchFilterEngine
{
public:
typedef QMap <QString, QString> SubstMap;
typedef QMap <QString, QString> SubstMap;
KURISearchFilterEngine();
~KURISearchFilterEngine();
KURISearchFilterEngine();
~KURISearchFilterEngine();
QByteArray name() const;
char keywordDelimiter() const;
QString defaultSearchEngine() const;
QStringList favoriteEngineList() const;
SearchProvider* webShortcutQuery (const QString& typedString, QString& searchTerm) const;
SearchProvider* autoWebSearchQuery (const QString& typedString, const QString& defaultShortcut = QString()) const;
QUrl formatResult (const QString& url, const QString& cset1, const QString& cset2,
const QString& query, bool isMalformed) const;
QByteArray name() const;
char keywordDelimiter() const;
QString defaultSearchEngine() const;
QStringList favoriteEngineList() const;
SearchProvider *webShortcutQuery(const QString &typedString, QString &searchTerm) const;
SearchProvider *autoWebSearchQuery(const QString &typedString, const QString &defaultShortcut = QString()) const;
QUrl formatResult(const QString &url, const QString &cset1, const QString &cset2, const QString &query, bool isMalformed) const;
SearchProviderRegistry *registry();
SearchProviderRegistry *registry();
static KURISearchFilterEngine *self();
void loadConfig();
static KURISearchFilterEngine *self();
void loadConfig();
protected:
QUrl formatResult (const QString& url, const QString& cset1, const QString& cset2,
const QString& query, bool isMalformed, SubstMap& map) const;
QUrl formatResult(const QString &url, const QString &cset1, const QString &cset2, const QString &query, bool isMalformed, SubstMap &map) const;
private:
KURISearchFilterEngine(const KURISearchFilterEngine&) = delete;
KURISearchFilterEngine& operator= (const KURISearchFilterEngine&) = delete;
QStringList modifySubstitutionMap (SubstMap& map, const QString& query) const;
QString substituteQuery (const QString& url, SubstMap &map,
const QString& userquery, QTextCodec *codec) const;
SearchProviderRegistry m_registry;
QString m_defaultWebShortcut;
QStringList m_preferredWebShortcuts;
bool m_bWebShortcutsEnabled;
bool m_bUseOnlyPreferredWebShortcuts;
char m_cKeywordDelimiter;
KURISearchFilterEngine(const KURISearchFilterEngine &) = delete;
KURISearchFilterEngine &operator=(const KURISearchFilterEngine &) = delete;
QStringList modifySubstitutionMap(SubstMap &map, const QString &query) const;
QString substituteQuery(const QString &url, SubstMap &map, const QString &userquery, QTextCodec *codec) const;
SearchProviderRegistry m_registry;
QString m_defaultWebShortcut;
QStringList m_preferredWebShortcuts;
bool m_bWebShortcutsEnabled;
bool m_bUseOnlyPreferredWebShortcuts;
char m_cKeywordDelimiter;
};
#endif // KURIIKWSFILTERENG_H
......@@ -43,11 +43,11 @@ QLoggingCategory category("org.kde.kurifilter-ikws", QtWarningMsg);
}
KUriSearchFilter::KUriSearchFilter(QObject *parent, const QVariantList &)
:KUriFilterPlugin( QStringLiteral("kurisearchfilter"), parent )
: KUriFilterPlugin(QStringLiteral("kurisearchfilter"), parent)
{
KLocalizedString::insertQtDomain("kurifilter");
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"),
QStringLiteral("configure"), this, SLOT(configure()));
KLocalizedString::insertQtDomain("kurifilter");
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/"), QStringLiteral("org.kde.KUriFilterPlugin"),
QStringLiteral("configure"), this, SLOT(configure()));
}
KUriSearchFilter::~KUriSearchFilter()
......@@ -56,43 +56,42 @@ KUriSearchFilter::~KUriSearchFilter()
void KUriSearchFilter::configure()
{
qCDebug(category) << "Config reload requested...";
KURISearchFilterEngine::self()->loadConfig();
qCDebug(category) << "Config reload requested...";
KURISearchFilterEngine::self()->loadConfig();
}
bool KUriSearchFilter::filterUri( KUriFilterData &data ) const
bool KUriSearchFilter::filterUri(KUriFilterData &data) const
{