summaryrefslogtreecommitdiff
path: root/src/opensearch
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-07-25 19:48:41 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-07-25 19:48:41 +0200
commit14664e54b1a2dbe9c06f474a0918a262dba04e20 (patch)
tree2f48b455d90b5a966045f8ba6388ac8c0620259f /src/opensearch
parentLast SSL fixes (diff)
downloadrekonq-14664e54b1a2dbe9c06f474a0918a262dba04e20.tar.xz
clean up
- QL1S - one stupid kDebug less - codingstyle
Diffstat (limited to 'src/opensearch')
-rw-r--r--src/opensearch/opensearchengine.cpp22
-rw-r--r--src/opensearch/opensearchmanager.cpp44
-rw-r--r--src/opensearch/opensearchreader.cpp40
-rw-r--r--src/opensearch/opensearchwriter.cpp22
-rw-r--r--src/opensearch/searchengine.cpp14
-rw-r--r--src/opensearch/suggestionparser.cpp28
6 files changed, 85 insertions, 85 deletions
diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp
index f48118ca..d5c64d68 100644
--- a/src/opensearch/opensearchengine.cpp
+++ b/src/opensearch/opensearchengine.cpp
@@ -51,7 +51,7 @@ OpenSearchEngine::OpenSearchEngine(QObject *parent)
OpenSearchEngine::~OpenSearchEngine()
{
- if(m_parser)
+ if (m_parser)
{
delete m_parser;
}
@@ -66,7 +66,7 @@ QString OpenSearchEngine::parseTemplate(const QString &searchTerm, const QString
QString country = language;
country = (country.remove(0, country.indexOf(QL1C('-')) + 1)).toLower();
const int firstDashPosition = country.indexOf(QL1C('-'));
- if(firstDashPosition >= 0)
+ if (firstDashPosition >= 0)
country = country.mid(firstDashPosition + 1);
QString result = searchTemplate;
@@ -121,7 +121,7 @@ void OpenSearchEngine::setSearchUrlTemplate(const QString &searchUrlTemplate)
KUrl OpenSearchEngine::searchUrl(const QString &searchTerm) const
{
- if(m_searchUrlTemplate.isEmpty())
+ if (m_searchUrlTemplate.isEmpty())
{
return KUrl();
}
@@ -129,7 +129,7 @@ KUrl OpenSearchEngine::searchUrl(const QString &searchTerm) const
KUrl retVal = KUrl::fromEncoded(parseTemplate(searchTerm, m_searchUrlTemplate).toUtf8());
QList<Parameter>::const_iterator i;
- for(i = m_searchParameters.constBegin(); i != m_searchParameters.constEnd(); ++i)
+ for (i = m_searchParameters.constBegin(); i != m_searchParameters.constEnd(); ++i)
{
retVal.addQueryItem(i->first, parseTemplate(searchTerm, i->second));
}
@@ -158,7 +158,7 @@ void OpenSearchEngine::setSuggestionsUrlTemplate(const QString &suggestionsUrlTe
KUrl OpenSearchEngine::suggestionsUrl(const QString &searchTerm) const
{
- if(m_suggestionsUrlTemplate.isEmpty())
+ if (m_suggestionsUrlTemplate.isEmpty())
{
return KUrl();
}
@@ -166,7 +166,7 @@ KUrl OpenSearchEngine::suggestionsUrl(const QString &searchTerm) const
KUrl retVal = KUrl::fromEncoded(parseTemplate(searchTerm, m_suggestionsUrlTemplate).toUtf8());
QList<Parameter>::const_iterator i;
- for(i = m_suggestionsParameters.constBegin(); i != m_suggestionsParameters.constEnd(); ++i)
+ for (i = m_suggestionsParameters.constBegin(); i != m_suggestionsParameters.constEnd(); ++i)
{
retVal.addQueryItem(i->first, parseTemplate(searchTerm, i->second));
}
@@ -255,7 +255,7 @@ bool OpenSearchEngine::operator<(const OpenSearchEngine &other) const
ResponseList OpenSearchEngine::parseSuggestion(const QString &searchTerm, const QByteArray &resp)
{
QFile file(suggestionPathFor(searchTerm));
- if(file.open(QIODevice::WriteOnly | QIODevice::Text))
+ if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
file.write(resp, resp.size());
file.close();
@@ -267,10 +267,10 @@ ResponseList OpenSearchEngine::parseSuggestion(const QString &searchTerm, const
ResponseList OpenSearchEngine::parseSuggestion(const QByteArray &resp)
{
- if(!m_parser)
+ if (!m_parser)
return ResponseList();
- if(resp.isEmpty())
+ if (resp.isEmpty())
return ResponseList();
return m_parser->parse(resp);
@@ -299,11 +299,11 @@ bool OpenSearchEngine::hasCachedSuggestionsFor(const QString &searchTerm)
ResponseList OpenSearchEngine::cachedSuggestionsFor(const QString &searchTerm)
{
QFile file(suggestionPathFor(searchTerm));
- if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return ResponseList();
QByteArray resp;
- while(!file.atEnd())
+ while (!file.atEnd())
{
resp += file.readLine();
}
diff --git a/src/opensearch/opensearchmanager.cpp b/src/opensearch/opensearchmanager.cpp
index ea2ace32..05c2e116 100644
--- a/src/opensearch/opensearchmanager.cpp
+++ b/src/opensearch/opensearchmanager.cpp
@@ -76,17 +76,17 @@ void OpenSearchManager::setSearchProvider(const QString &searchProvider)
{
m_activeEngine = 0;
- if(!m_engineCache.contains(searchProvider))
+ if (!m_engineCache.contains(searchProvider))
{
const QString fileName = KGlobal::dirs()->findResource("data", "rekonq/opensearch/" + trimmedEngineName(searchProvider) + ".xml");
kDebug() << searchProvider << " trimmed name: " << trimmedEngineName(searchProvider) << " file name path: " << fileName;
- if(fileName.isEmpty())
+ if (fileName.isEmpty())
{
return;
}
QFile file(fileName);
- if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return;
}
@@ -94,7 +94,7 @@ void OpenSearchManager::setSearchProvider(const QString &searchProvider)
OpenSearchReader reader;
OpenSearchEngine *engine = reader.read(&file);
- if(engine)
+ if (engine)
{
m_engineCache.insert(searchProvider, engine);
}
@@ -120,7 +120,7 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl
m_shortcut = shortcut;
- if(m_state != IDLE)
+ if (m_state != IDLE)
{
idleJob();
}
@@ -134,10 +134,10 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl
void OpenSearchManager::requestSuggestion(const QString &searchText)
{
- if(!m_activeEngine)
+ if (!m_activeEngine)
return;
- if(m_state != IDLE)
+ if (m_state != IDLE)
{
// NOTE:
// changing OpenSearchManager behavior
@@ -146,7 +146,7 @@ void OpenSearchManager::requestSuggestion(const QString &searchText)
idleJob();
}
- if(m_activeEngine->hasCachedSuggestionsFor(searchText))
+ if (m_activeEngine->hasCachedSuggestionsFor(searchText))
{
emit suggestionsReceived(searchText, m_activeEngine->cachedSuggestionsFor(searchText));
}
@@ -172,14 +172,14 @@ 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())
+ if (job->error() || _typedText.isEmpty())
{
emit suggestionsReceived(_typedText, ResponseList());
m_state = IDLE;
return; // just silently return
}
- if(m_state == REQ_SUGGESTION)
+ if (m_state == REQ_SUGGESTION)
{
const ResponseList suggestionsList = m_activeEngine->parseSuggestion(_typedText, m_jobData);
Q_FOREACH(const Response & r, suggestionsList)
@@ -191,18 +191,18 @@ void OpenSearchManager::jobFinished(KJob *job)
return;
}
- if(m_state == REQ_DESCRIPTION)
+ if (m_state == REQ_DESCRIPTION)
{
OpenSearchReader reader;
OpenSearchEngine *engine = reader.read(m_jobData);
- if(engine)
+ if (engine)
{
m_engineCache.insert(engine->name(), engine);
m_engines.insert(m_jobUrl, trimmedEngineName(engine->name()));
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/");
@@ -246,14 +246,14 @@ void OpenSearchManager::jobFinished(KJob *job)
void OpenSearchManager::loadEngines()
{
QFile file(KStandardDirs::locate("appdata", "opensearch/db_opensearch.json"));
- if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return;
}
QString fileContent = QString::fromUtf8(file.readAll());
QScriptEngine reader;
- if(!reader.canEvaluate(fileContent))
+ if (!reader.canEvaluate(fileContent))
{
return;
}
@@ -274,7 +274,7 @@ void OpenSearchManager::loadEngines()
void OpenSearchManager::saveEngines()
{
QFile file(KStandardDirs::locateLocal("appdata", "opensearch/db_opensearch.json"));
- if(!file.open(QIODevice::WriteOnly))
+ if (!file.open(QIODevice::WriteOnly))
{
return;
}
@@ -286,7 +286,7 @@ void OpenSearchManager::saveEngines()
{
out << "[\"" << url.url() << "\",\"" << m_engines.value(url) << "\"]";
i++;
- if(i != urls.size())
+ if (i != urls.size())
{
out << ",\n";
}
@@ -302,7 +302,7 @@ void OpenSearchManager::removeDeletedEngines()
Q_FOREACH(const KUrl & url, m_engines.keys())
{
service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(m_engines.value(url)));
- if(!service)
+ if (!service)
{
QString path = KStandardDirs::locateLocal("appdata", "opensearch/" + trimmedEngineName(m_engines.value(url)) + ".xml");
QFile::remove(path + trimmedEngineName(m_engines.value(url)) + ".xml");
@@ -323,15 +323,15 @@ QString OpenSearchManager::trimmedEngineName(const QString &engineName) const
{
QString trimmed;
QString::ConstIterator constIter = engineName.constBegin();
- while(constIter != engineName.constEnd())
+ while (constIter != engineName.constEnd())
{
- if(constIter->isSpace())
+ if (constIter->isSpace())
{
trimmed.append('_');
}
else
{
- if(*constIter != '.')
+ if (*constIter != '.')
{
trimmed.append(constIter->toLower());
}
@@ -345,7 +345,7 @@ QString OpenSearchManager::trimmedEngineName(const QString &engineName) const
void OpenSearchManager::idleJob()
{
- if(m_currentJob)
+ if (m_currentJob)
{
disconnect(m_currentJob);
m_currentJob->kill();
diff --git a/src/opensearch/opensearchreader.cpp b/src/opensearch/opensearchreader.cpp
index a789c413..c2bf0f09 100644
--- a/src/opensearch/opensearchreader.cpp
+++ b/src/opensearch/opensearchreader.cpp
@@ -60,7 +60,7 @@ OpenSearchEngine *OpenSearchReader::read(QIODevice *device)
{
clear();
- if(!device->isOpen())
+ if (!device->isOpen())
{
device->open(QIODevice::ReadOnly);
}
@@ -74,56 +74,56 @@ OpenSearchEngine *OpenSearchReader::read()
{
OpenSearchEngine *engine = new OpenSearchEngine();
- while(!isStartElement() && !atEnd())
+ while (!isStartElement() && !atEnd())
{
readNext();
}
- if(name() != QL1S("OpenSearchDescription")
+ if (name() != QL1S("OpenSearchDescription")
|| namespaceUri() != QL1S("http://a9.com/-/spec/opensearch/1.1/")
- )
+ )
{
raiseError(i18n("The file is not an OpenSearch 1.1 file."));
return engine;
}
- while(!(isEndElement() && name() == QL1S("OpenSearchDescription")) && !atEnd())
+ while (!(isEndElement() && name() == QL1S("OpenSearchDescription")) && !atEnd())
{
readNext();
- if(!isStartElement())
+ if (!isStartElement())
continue;
// ShortName
- if(name() == QL1S("ShortName"))
+ if (name() == QL1S("ShortName"))
{
engine->setName(readElementText());
continue;
}
// Description
- if(name() == QL1S("Description"))
+ if (name() == QL1S("Description"))
{
engine->setDescription(readElementText());
continue;
}
// Url
- if(name() == QL1S("Url"))
+ if (name() == QL1S("Url"))
{
QString type = attributes().value(QL1S("type")).toString();
QString url = attributes().value(QL1S("template")).toString();
- if(url.isEmpty())
+ if (url.isEmpty())
continue;
QList<OpenSearchEngine::Parameter> parameters;
readNext();
- while(!(isEndElement() && name() == QL1S("Url")))
+ while (!(isEndElement() && name() == QL1S("Url")))
{
- if(!isStartElement()
+ if (!isStartElement()
|| (name() != QL1S("Param")
&& name() != QL1S("Parameter")))
{
@@ -134,32 +134,32 @@ OpenSearchEngine *OpenSearchReader::read()
QString key = attributes().value(QL1S("name")).toString();
QString value = attributes().value(QL1S("value")).toString();
- if(!key.isEmpty() && !value.isEmpty())
+ if (!key.isEmpty() && !value.isEmpty())
{
parameters.append(OpenSearchEngine::Parameter(key, value));
}
- while(!isEndElement())
+ while (!isEndElement())
{
readNext();
}
}
- if(type == QL1S("text/html"))
+ if (type == QL1S("text/html"))
{
engine->setSearchUrlTemplate(url);
engine->setSearchParameters(parameters);
}
else
{
- if(engine->suggestionsUrlTemplate().isEmpty()
+ if (engine->suggestionsUrlTemplate().isEmpty()
&& type == QL1S("application/x-suggestions+json")) //note: xml is preferred
{
engine->setSuggestionsUrlTemplate(url);
engine->setSuggestionsParameters(parameters);
engine->setSuggestionParser(new JSONParser());
}
- else if(type == QL1S("application/x-suggestions+xml"))
+ else if (type == QL1S("application/x-suggestions+xml"))
{
engine->setSuggestionsUrlTemplate(url);
engine->setSuggestionsParameters(parameters);
@@ -171,19 +171,19 @@ OpenSearchEngine *OpenSearchReader::read()
}
// Image
- if(name() == QL1S("Image"))
+ if (name() == QL1S("Image"))
{
engine->setImageUrl(readElementText());
continue;
}
// Engine check
- if(!engine->name().isEmpty()
+ if (!engine->name().isEmpty()
&& !engine->description().isEmpty()
&& !engine->suggestionsUrlTemplate().isEmpty()
&& !engine->searchUrlTemplate().isEmpty()
&& !engine->imageUrl().isEmpty()
- )
+ )
{
break;
}
diff --git a/src/opensearch/opensearchwriter.cpp b/src/opensearch/opensearchwriter.cpp
index d6a34f54..0b50ca6a 100644
--- a/src/opensearch/opensearchwriter.cpp
+++ b/src/opensearch/opensearchwriter.cpp
@@ -45,10 +45,10 @@ OpenSearchWriter::OpenSearchWriter()
bool OpenSearchWriter::write(QIODevice *device, OpenSearchEngine *engine)
{
- if(!engine)
+ if (!engine)
return false;
- if(!device->isOpen())
+ if (!device->isOpen())
device->open(QIODevice::WriteOnly);
setDevice(device);
@@ -63,29 +63,29 @@ void OpenSearchWriter::write(OpenSearchEngine *engine)
writeStartElement(QL1S("OpenSearchDescription"));
writeDefaultNamespace(QL1S("http://a9.com/-/spec/opensearch/1.1/"));
- if(!engine->name().isEmpty())
+ if (!engine->name().isEmpty())
{
writeTextElement(QL1S("ShortName"), engine->name());
}
- if(!engine->description().isEmpty())
+ if (!engine->description().isEmpty())
{
writeTextElement(QL1S("Description"), engine->description());
}
- if(!engine->searchUrlTemplate().isEmpty())
+ if (!engine->searchUrlTemplate().isEmpty())
{
writeStartElement(QL1S("Url"));
writeAttribute(QL1S("method"), QL1S("get"));
writeAttribute(QL1S("template"), engine->searchUrlTemplate());
- if(!engine->searchParameters().empty())
+ if (!engine->searchParameters().empty())
{
writeNamespace(QL1S("http://a9.com/-/spec/opensearch/extensions/parameters/1.0/"), QL1S("p"));
QList<OpenSearchEngine::Parameter>::const_iterator end = engine->searchParameters().constEnd();
QList<OpenSearchEngine::Parameter>::const_iterator i = engine->searchParameters().constBegin();
- for(; i != end; ++i)
+ for (; i != end; ++i)
{
writeStartElement(QL1S("p:Parameter"));
writeAttribute(QL1S("name"), i->first);
@@ -97,20 +97,20 @@ void OpenSearchWriter::write(OpenSearchEngine *engine)
writeEndElement();
}
- if(!engine->suggestionsUrlTemplate().isEmpty())
+ if (!engine->suggestionsUrlTemplate().isEmpty())
{
writeStartElement(QL1S("Url"));
writeAttribute(QL1S("method"), QL1S("get"));
writeAttribute(QL1S("type"), engine->type());
writeAttribute(QL1S("template"), engine->suggestionsUrlTemplate());
- if(!engine->suggestionsParameters().empty())
+ if (!engine->suggestionsParameters().empty())
{
writeNamespace(QL1S("http://a9.com/-/spec/opensearch/extensions/parameters/1.0/"), QL1S("p"));
QList<OpenSearchEngine::Parameter>::const_iterator end = engine->suggestionsParameters().constEnd();
QList<OpenSearchEngine::Parameter>::const_iterator i = engine->suggestionsParameters().constBegin();
- for(; i != end; ++i)
+ for (; i != end; ++i)
{
writeStartElement(QL1S("p:Parameter"));
writeAttribute(QL1S("name"), i->first);
@@ -122,7 +122,7 @@ void OpenSearchWriter::write(OpenSearchEngine *engine)
writeEndElement();
}
- if(!engine->imageUrl().isEmpty())
+ if (!engine->imageUrl().isEmpty())
writeTextElement(QL1S("Image"), engine->imageUrl());
writeEndElement();
diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp
index 224a8d56..b54d9434 100644
--- a/src/opensearch/searchengine.cpp
+++ b/src/opensearch/searchengine.cpp
@@ -64,7 +64,7 @@ void SearchEngine::reload()
Q_FOREACH(const QString & engine, favoriteEngines)
{
service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
- if(service)
+ if (service)
{
QUrl url = service->property("Query").toUrl();
rApp->iconManager()->downloadIconFromUrl(url);
@@ -84,7 +84,7 @@ void SearchEngine::reload()
QString SearchEngine::delimiter()
{
- if(!d->isLoaded)
+ if (!d->isLoaded)
reload();
return d->delimiter;
@@ -93,7 +93,7 @@ QString SearchEngine::delimiter()
KService::List SearchEngine::favorites()
{
- if(!d->isLoaded)
+ if (!d->isLoaded)
reload();
return d->favorites;
@@ -102,7 +102,7 @@ KService::List SearchEngine::favorites()
KService::Ptr SearchEngine::defaultEngine()
{
- if(!d->isLoaded)
+ if (!d->isLoaded)
reload();
return d->defaultEngine;
@@ -115,13 +115,13 @@ KService::Ptr SearchEngine::fromString(const QString &text)
int i = 0;
bool found = false;
KService::Ptr service;
- while(!found && i < providers.size())
+ while (!found && i < providers.size())
{
QStringList list = providers.at(i)->property("Keys").toStringList();
Q_FOREACH(const QString & key, list)
{
const QString searchPrefix = key + delimiter();
- if(text.startsWith(searchPrefix))
+ if (text.startsWith(searchPrefix))
{
service = providers.at(i);
found = true;
@@ -136,7 +136,7 @@ KService::Ptr SearchEngine::fromString(const QString &text)
QString SearchEngine::buildQuery(KService::Ptr engine, const QString &text)
{
- if(!engine)
+ if (!engine)
return QString();
QString query = engine->property("Query").toString();
query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
diff --git a/src/opensearch/suggestionparser.cpp b/src/opensearch/suggestionparser.cpp
index 6b467353..3c5350bf 100644
--- a/src/opensearch/suggestionparser.cpp
+++ b/src/opensearch/suggestionparser.cpp
@@ -51,14 +51,14 @@ ResponseList XMLParser::parse(const QByteArray &resp)
m_reader.clear();
m_reader.addData(resp);
- while(!m_reader.atEnd() && !m_reader.hasError())
+ while (!m_reader.atEnd() && !m_reader.hasError())
{
m_reader.readNext();
- if(m_reader.isStartDocument())
+ if (m_reader.isStartDocument())
continue;
- if(m_reader.isStartElement() && m_reader.name() == QL1S("Item"))
+ if (m_reader.isStartElement() && m_reader.name() == QL1S("Item"))
{
QString title;
QString description;
@@ -69,24 +69,24 @@ ResponseList XMLParser::parse(const QByteArray &resp)
m_reader.readNext();
- while(!(m_reader.isEndElement() && m_reader.name() == QL1S("Item")))
+ while (!(m_reader.isEndElement() && m_reader.name() == QL1S("Item")))
{
- if(m_reader.isStartElement())
+ if (m_reader.isStartElement())
{
- if(m_reader.name() == QL1S("Text"))
+ if (m_reader.name() == QL1S("Text"))
title = m_reader.readElementText();
- if(m_reader.name() == QL1S("Url"))
+ if (m_reader.name() == QL1S("Url"))
url = m_reader.readElementText();
- if(m_reader.name() == QL1S("Image"))
+ if (m_reader.name() == QL1S("Image"))
{
image = m_reader.attributes().value("source").toString();
image_width = m_reader.attributes().value("width").toString().toInt();
image_height = m_reader.attributes().value("height").toString().toInt();
}
- if(m_reader.name() == QL1S("Description"))
+ if (m_reader.name() == QL1S("Description"))
description = m_reader.readElementText();
}
@@ -105,22 +105,22 @@ ResponseList JSONParser::parse(const QByteArray &resp)
QString response = QString::fromLocal8Bit(resp);
response = response.trimmed();
- if(response.isEmpty())
+ if (response.isEmpty())
{
// RESPONSE IS EMPTY
return ResponseList();
}
- if(!response.startsWith(QL1C('['))
+ if (!response.startsWith(QL1C('['))
|| !response.endsWith(QL1C(']'))
- )
+ )
{
// RESPONSE is NOT well FORMED
return ResponseList();
}
// Evaluate the JSON response using QtScript.
- if(!m_reader.canEvaluate(response))
+ if (!m_reader.canEvaluate(response))
{
// m_reader cannot evaluate the response
return ResponseList();
@@ -128,7 +128,7 @@ ResponseList JSONParser::parse(const QByteArray &resp)
QScriptValue responseParts = m_reader.evaluate(response);
- if(!responseParts.property(1).isArray())
+ if (!responseParts.property(1).isArray())
{
// RESPONSE is not an array
return ResponseList();