summaryrefslogtreecommitdiff
path: root/src/opensearch/opensearchmanager.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-04-23 00:34:19 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-04-23 00:34:19 +0200
commitae1c295495659fb01874ae6af4d0b89a0a2424dc (patch)
tree8143905fece76f036e893d4684443025a67ea4d4 /src/opensearch/opensearchmanager.cpp
parentAdd fixed favorite icon in the toolbar to let add favorites easier (diff)
downloadrekonq-ae1c295495659fb01874ae6af4d0b89a0a2424dc.tar.xz
Fix opensearch add shortcut handling
(at least on every site tested, but opensearch.org itself. Broken?) BUG: 296707
Diffstat (limited to 'src/opensearch/opensearchmanager.cpp')
-rw-r--r--src/opensearch/opensearchmanager.cpp100
1 files changed, 51 insertions, 49 deletions
diff --git a/src/opensearch/opensearchmanager.cpp b/src/opensearch/opensearchmanager.cpp
index 04e687f3..c315f9c8 100644
--- a/src/opensearch/opensearchmanager.cpp
+++ b/src/opensearch/opensearchmanager.cpp
@@ -115,9 +115,8 @@ bool OpenSearchManager::isSuggestionAvailable()
void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &title, const QString &shortcut)
{
- Q_UNUSED(title);
-
m_shortcut = shortcut;
+ m_title = trimmedEngineName(title);
if (m_state != IDLE)
{
@@ -171,67 +170,49 @@ void OpenSearchManager::dataReceived(KIO::Job *job, const QByteArray &data)
void OpenSearchManager::jobFinished(KJob *job)
{
- // Do NOT parse if job had same errors or the typed string is empty
- if (job->error() || _typedText.isEmpty())
- {
- emit suggestionsReceived(_typedText, ResponseList());
- m_state = IDLE;
- return; // just silently return
- }
-
- if (m_state == REQ_SUGGESTION)
- {
- ResponseList suggestionsList;
- if (isSuggestionAvailable())
- {
- suggestionsList = m_activeEngine->parseSuggestion(_typedText, m_jobData);
- }
- emit suggestionsReceived(_typedText, suggestionsList);
- idleJob();
- return;
- }
-
- if (m_state == REQ_DESCRIPTION)
+ if (!job->error() && m_state == REQ_DESCRIPTION)
{
OpenSearchReader reader;
OpenSearchEngine *engine = reader.read(m_jobData);
if (engine)
{
- m_engineCache.insert(engine->name(), engine);
- m_engines.insert(m_jobUrl, trimmedEngineName(engine->name()));
+ m_engineCache.insert(m_title, engine);
+ m_engines.insert(m_jobUrl, m_shortcut);
saveEngines();
QString path;
- if (engine->providesSuggestions()) //save opensearch description only if it provides suggestions
+ if (engine->providesSuggestions())
{
+ // save opensearch description only if it provides suggestions
OpenSearchWriter writer;
path = KGlobal::dirs()->findResource("data", "rekonq/opensearch/");
QFile file(path + trimmedEngineName(engine->name()) + ".xml");
writer.write(&file, engine);
- }
- QString searchUrl = OpenSearchEngine::parseTemplate("\\{@}", engine->searchUrlTemplate());
- m_currentJob = NULL;
-
- path = KGlobal::mainComponent().dirs()->saveLocation("services", "searchproviders/");
- KConfig _service(path + trimmedEngineName(engine->name()) + ".desktop", KConfig::SimpleConfig);
- KConfigGroup service(&_service, "Desktop Entry");
- service.writeEntry("Type", "Service");
- service.writeEntry("ServiceTypes", "SearchProvider");
- service.writeEntry("Name", engine->name());
- service.writeEntry("Query", searchUrl);
- service.writeEntry("Keys", m_shortcut);
- // TODO charset
- service.writeEntry("Charset", "" /* provider->charset() */);
- // we might be overwriting a hidden entry
- service.writeEntry("Hidden", false);
- service.sync();
-
- // Update filters in running applications...
- QDBusMessage msg = QDBusMessage::createSignal("/", "org.kde.KUriFilterPlugin", "configure");
- QDBusConnection::sessionBus().send(msg);
-
- emit openSearchEngineAdded(engine->name(), searchUrl, m_shortcut);
+ // save desktop file here
+ QString searchUrl = OpenSearchEngine::parseTemplate("\\{@}", engine->searchUrlTemplate());
+ m_currentJob = NULL;
+
+ path = KGlobal::mainComponent().dirs()->saveLocation("services", "searchproviders/");
+ KConfig _service(path + m_title + ".desktop", KConfig::SimpleConfig);
+ KConfigGroup service(&_service, "Desktop Entry");
+ service.writeEntry("Type", "Service");
+ service.writeEntry("ServiceTypes", "SearchProvider");
+ service.writeEntry("Name", m_title);
+ service.writeEntry("Query", searchUrl);
+ service.writeEntry("Keys", m_shortcut);
+ // TODO charset
+ service.writeEntry("Charset", "" /* provider->charset() */);
+ // we might be overwriting a hidden entry
+ service.writeEntry("Hidden", false);
+ service.sync();
+
+ // Update filters in running applications...
+ QDBusMessage msg = QDBusMessage::createSignal("/", "org.kde.KUriFilterPlugin", "configure");
+ QDBusConnection::sessionBus().send(msg);
+
+ emit openSearchEngineAdded(engine->name());
+ }
}
else
{
@@ -239,6 +220,27 @@ void OpenSearchManager::jobFinished(KJob *job)
}
idleJob();
+ return;
+ }
+
+ // Do NOT parse if job had same errors or the typed string is empty
+ if (job->error() || _typedText.isEmpty())
+ {
+ emit suggestionsReceived(_typedText, ResponseList());
+ m_state = IDLE;
+ return; // just silently return
+ }
+
+ if (m_state == REQ_SUGGESTION)
+ {
+ ResponseList suggestionsList;
+ if (isSuggestionAvailable())
+ {
+ suggestionsList = m_activeEngine->parseSuggestion(_typedText, m_jobData);
+ }
+ emit suggestionsReceived(_typedText, suggestionsList);
+ idleJob();
+ return;
}
}