diff --git a/src/urifilters/ikws/searchprovider.cpp b/src/urifilters/ikws/searchprovider.cpp index fd8f43be..021cd595 100644 --- a/src/urifilters/ikws/searchprovider.cpp +++ b/src/urifilters/ikws/searchprovider.cpp @@ -1,128 +1,133 @@ /* * 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 "searchprovider.h" #include #include #include #include // KIO::iconNameForUrl #include #include #include #include SearchProvider::SearchProvider(const QString &servicePath) : m_dirty(false) { setDesktopEntryName(QFileInfo(servicePath).baseName()); KDesktopFile parser(servicePath); setName(parser.readName()); KConfigGroup group(parser.desktopGroup()); setKeys(group.readEntry(QStringLiteral("Keys"), QStringList())); m_query = group.readEntry(QStringLiteral("Query")); m_charset = group.readEntry(QStringLiteral("Charset")); + m_iconName = group.readEntry(QStringLiteral("Icon")); } SearchProvider::~SearchProvider() { } void SearchProvider::setName(const QString &name) { if (KUriFilterSearchProvider::name() == name) return; KUriFilterSearchProvider::setName(name); } void SearchProvider::setQuery(const QString &query) { if (m_query == query) return; m_query = query; } void SearchProvider::setKeys(const QStringList &keys) { if (KUriFilterSearchProvider::keys() == keys) return; KUriFilterSearchProvider::setKeys(keys); QString name = desktopEntryName(); if (!name.isEmpty()) return; // New provider. Set the desktopEntryName. // Take the longest search shortcut as filename, // if such a file already exists, append a number and increase it // until the name is unique Q_FOREACH(const QString& key, keys) { if (key.length() > name.length()) name = key.toLower(); } const QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/searchproviders/"); bool firstRun = true; while (true) { QString check(name); if (!firstRun) check += KRandom::randomString(4); const QString located = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/searchproviders/") + check + QLatin1String(".desktop")); if (located.isEmpty()) { name = check; break; } else if (located.startsWith(path)) { // If it's a deleted (hidden) entry, overwrite it if (KService(located).isDeleted()) break; } firstRun = false; } setDesktopEntryName(name); } void SearchProvider::setCharset(const QString &charset) { if (m_charset == charset) return; m_charset = charset; } QString SearchProvider::iconName() const { + if (!m_iconName.isEmpty()) { + return m_iconName; + } + return KIO::iconNameForUrl(QUrl(m_query)); } void SearchProvider::setDirty(bool dirty) { m_dirty = dirty; } diff --git a/src/urifilters/ikws/searchprovider.h b/src/urifilters/ikws/searchprovider.h index 65259785..bad149ec 100644 --- a/src/urifilters/ikws/searchprovider.h +++ b/src/urifilters/ikws/searchprovider.h @@ -1,50 +1,51 @@ /* * 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. */ #ifndef SEARCHPROVIDER_H #define SEARCHPROVIDER_H #include class SearchProvider : public KUriFilterSearchProvider { public: SearchProvider() : m_dirty(false) {} explicit SearchProvider(const QString &servicePath); ~SearchProvider(); const QString& charset() const { return m_charset; } const QString& query() const { return m_query; } bool isDirty() const { return m_dirty; } void setName(const QString&); void setQuery(const QString&); void setKeys(const QStringList&); void setCharset(const QString&); void setDirty(bool dirty); QString iconName() const override; private: QString m_query; QString m_charset; + QString m_iconName; bool m_dirty; }; #endif