From 9d20e99fffeebe67fd8ff27cb4f9e353892f5190 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 25 Feb 2011 00:19:27 +0100 Subject: Coding style --- src/opensearch/opensearchengine.cpp | 18 +++++------ src/opensearch/opensearchengine.h | 2 +- src/opensearch/opensearchmanager.cpp | 56 ++++++++++++++++---------------- src/opensearch/opensearchmanager.h | 8 ++--- src/opensearch/opensearchreader.cpp | 62 ++++++++++++++++++------------------ src/opensearch/opensearchwriter.cpp | 18 +++++------ src/opensearch/searchengine.cpp | 2 +- src/opensearch/suggestionparser.cpp | 22 ++++++------- src/opensearch/suggestionparser.h | 46 ++++++++++++++------------ 9 files changed, 120 insertions(+), 114 deletions(-) (limited to 'src/opensearch') diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp index febcebea..dcd0f8b4 100644 --- a/src/opensearch/opensearchengine.cpp +++ b/src/opensearch/opensearchengine.cpp @@ -43,15 +43,15 @@ OpenSearchEngine::OpenSearchEngine(QObject *parent) - : QObject(parent) - , m_parser(0) + : QObject(parent) + , m_parser(0) { } OpenSearchEngine::~OpenSearchEngine() { - if (m_parser) + if (m_parser) { delete m_parser; } @@ -64,10 +64,10 @@ QString OpenSearchEngine::parseTemplate(const QString &searchTerm, const QString // Simple conversion to RFC 3066. language = language.replace(QL1C('_'), QL1C('-')); QString country = language; - country = (country.remove(0, country.indexOf(QL1C('-'))+1)).toLower(); + country = (country.remove(0, country.indexOf(QL1C('-')) + 1)).toLower(); const int firstDashPosition = country.indexOf(QL1C('-')); if (firstDashPosition >= 0) - country = country.mid(firstDashPosition+1); + country = country.mid(firstDashPosition + 1); QString result = searchTemplate; result.replace(QL1S("{count}"), QL1S("20")); @@ -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::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::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)); } diff --git a/src/opensearch/opensearchengine.h b/src/opensearch/opensearchengine.h index 8b0cf6bf..8194cfb2 100644 --- a/src/opensearch/opensearchengine.h +++ b/src/opensearch/opensearchengine.h @@ -48,7 +48,7 @@ class OpenSearchEngine : public QObject { - Q_OBJECT + Q_OBJECT public: typedef QPair Parameter; diff --git a/src/opensearch/opensearchmanager.cpp b/src/opensearch/opensearchmanager.cpp index a52abf22..0b482409 100644 --- a/src/opensearch/opensearchmanager.cpp +++ b/src/opensearch/opensearchmanager.cpp @@ -54,16 +54,16 @@ #include OpenSearchManager::OpenSearchManager(QObject *parent) - : QObject(parent) - , m_activeEngine(0) - , m_currentJob(0) + : QObject(parent) + , m_activeEngine(0) + , m_currentJob(0) { m_state = IDLE; loadEngines(); } -OpenSearchManager::~OpenSearchManager() +OpenSearchManager::~OpenSearchManager() { qDeleteAll(m_engineCache.values()); m_engineCache.clear(); @@ -79,14 +79,14 @@ void OpenSearchManager::setSearchProvider(const QString &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()) { kDebug() << "OpenSearch file name empty"; return; } QFile file(fileName); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { kDebug() << "Cannot open opensearch description file: " + fileName; return; @@ -95,11 +95,11 @@ void OpenSearchManager::setSearchProvider(const QString &searchProvider) OpenSearchReader reader; OpenSearchEngine *engine = reader.read(&file); - if (engine) + if (engine) { m_engineCache.insert(searchProvider, engine); } - else + else { return; } @@ -121,7 +121,7 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl m_shortcut = shortcut; - if (m_state != IDLE) + if (m_state != IDLE) { idleJob(); } @@ -135,12 +135,12 @@ 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: + // NOTE: // changing OpenSearchManager behavior // using idleJob here lets opensearchmanager to start another search, while // if we want in any case lets it finish its previous job we can just return here. @@ -180,24 +180,24 @@ void OpenSearchManager::jobFinished(KJob *job) return; // just silently return } - if (m_state == REQ_SUGGESTION) + if (m_state == REQ_SUGGESTION) { const ResponseList suggestionsList = m_activeEngine->parseSuggestion(_typedText, m_jobData); - kDebug() << "Received suggestions in "<< _typedText << " from " << m_activeEngine->name() << ": "; + kDebug() << "Received suggestions in " << _typedText << " from " << m_activeEngine->name() << ": "; Q_FOREACH(const Response &r, suggestionsList) { - kDebug() << r.title; + kDebug() << r.title; } emit suggestionsReceived(_typedText, suggestionsList); idleJob(); 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())); @@ -235,7 +235,7 @@ void OpenSearchManager::jobFinished(KJob *job) emit openSearchEngineAdded(engine->name(), searchUrl, m_shortcut); } - else + else { kFatal() << "Error while adding new open search engine"; } @@ -250,16 +250,16 @@ void OpenSearchManager::loadEngines() QFile file(KStandardDirs::locate("appdata", "opensearch/db_opensearch.json")); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - kDebug() << "opensearch db cannot be read"; - return; + kDebug() << "opensearch db cannot be read"; + return; } QString fileContent = QString::fromUtf8(file.readAll()); QScriptEngine reader; if (!reader.canEvaluate(fileContent)) { - kDebug() << "opensearch db cannot be read"; - return; + kDebug() << "opensearch db cannot be read"; + return; } QScriptValue responseParts = reader.evaluate(fileContent); @@ -268,8 +268,8 @@ void OpenSearchManager::loadEngines() QStringList l; Q_FOREACH(const QVariant &e, list) { - l=e.toStringList(); - m_engines.insert(KUrl(l.first()),l.last()); + l = e.toStringList(); + m_engines.insert(KUrl(l.first()), l.last()); } file.close(); } @@ -280,12 +280,12 @@ void OpenSearchManager::saveEngines() QFile file(KStandardDirs::locateLocal("appdata", "opensearch/db_opensearch.json")); if (!file.open(QIODevice::WriteOnly)) { - kDebug() << "opensearch db cannot be writen"; - return; + kDebug() << "opensearch db cannot be writen"; + return; } QTextStream out(&file); out << "["; - int i=0; + int i = 0; QList urls = m_engines.keys(); Q_FOREACH(const KUrl &url, urls) { @@ -355,7 +355,7 @@ void OpenSearchManager::idleJob() disconnect(m_currentJob); m_currentJob->kill(); } - + m_jobData.clear(); m_state = IDLE; } diff --git a/src/opensearch/opensearchmanager.h b/src/opensearch/opensearchmanager.h index ca969810..a75c765b 100644 --- a/src/opensearch/opensearchmanager.h +++ b/src/opensearch/opensearchmanager.h @@ -45,16 +45,16 @@ class OpenSearchEngine; /** - * This class acts as a proxy between the SearchBar plugin + * This class acts as a proxy between the SearchBar plugin * and the individual suggestion engine. - * This class has a map of all available engines, + * This class has a map of all available engines, * and route the suggestion request to the correct engine. */ class OpenSearchManager : public QObject { Q_OBJECT - enum STATE + enum STATE { REQ_SUGGESTION, REQ_DESCRIPTION, @@ -82,7 +82,7 @@ public: public Q_SLOTS: /** * Ask the specific suggestion engine to request for suggestion for the search text - * + * * @param searchText the text to be queried to the suggestion service */ void requestSuggestion(const QString &searchText); diff --git a/src/opensearch/opensearchreader.cpp b/src/opensearch/opensearchreader.cpp index 4d9130a8..2076338b 100644 --- a/src/opensearch/opensearchreader.cpp +++ b/src/opensearch/opensearchreader.cpp @@ -42,7 +42,7 @@ OpenSearchReader::OpenSearchReader() - : QXmlStreamReader() + : QXmlStreamReader() { } @@ -60,7 +60,7 @@ OpenSearchEngine *OpenSearchReader::read(QIODevice *device) { clear(); - if (!device->isOpen()) + if (!device->isOpen()) { device->open(QIODevice::ReadOnly); } @@ -74,20 +74,20 @@ OpenSearchEngine *OpenSearchReader::read() { OpenSearchEngine *engine = new OpenSearchEngine(); - while (!isStartElement() && !atEnd()) + while (!isStartElement() && !atEnd()) { readNext(); } - if ( name() != QL1S("OpenSearchDescription") - || namespaceUri() != QL1S("http://a9.com/-/spec/opensearch/1.1/") - ) + 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(); @@ -95,21 +95,21 @@ OpenSearchEngine *OpenSearchReader::read() 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(); @@ -121,11 +121,11 @@ OpenSearchEngine *OpenSearchReader::read() readNext(); - while (!(isEndElement() && name() == QL1S("Url"))) + while (!(isEndElement() && name() == QL1S("Url"))) { - if (!isStartElement() - || (name() != QL1S("Param") - && name() != QL1S("Parameter"))) + if (!isStartElement() + || (name() != QL1S("Param") + && name() != QL1S("Parameter"))) { readNext(); continue; @@ -134,12 +134,12 @@ 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(); } @@ -152,8 +152,8 @@ OpenSearchEngine *OpenSearchReader::read() } else { - if (engine->suggestionsUrlTemplate().isEmpty() - && type == QL1S("application/x-suggestions+json")) //note: xml is preferred + if (engine->suggestionsUrlTemplate().isEmpty() + && type == QL1S("application/x-suggestions+json")) //note: xml is preferred { engine->setSuggestionsUrlTemplate(url); engine->setSuggestionsParameters(parameters); @@ -166,24 +166,24 @@ OpenSearchEngine *OpenSearchReader::read() engine->setSuggestionParser(new XMLParser()); } } - + continue; } - + // Image - if (name() == QL1S("Image")) + if (name() == QL1S("Image")) { - engine->setImageUrl(readElementText()); - continue; + engine->setImageUrl(readElementText()); + continue; } // Engine check - if ( !engine->name().isEmpty() - && !engine->description().isEmpty() - && !engine->suggestionsUrlTemplate().isEmpty() - && !engine->searchUrlTemplate().isEmpty() - && !engine->imageUrl().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 d6649477..d1464275 100644 --- a/src/opensearch/opensearchwriter.cpp +++ b/src/opensearch/opensearchwriter.cpp @@ -37,7 +37,7 @@ OpenSearchWriter::OpenSearchWriter() - : QXmlStreamWriter() + : QXmlStreamWriter() { setAutoFormatting(true); } @@ -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::const_iterator end = engine->searchParameters().constEnd(); QList::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::const_iterator end = engine->suggestionsParameters().constEnd(); QList::const_iterator i = engine->suggestionsParameters().constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { writeStartElement(QL1S("p:Parameter")); writeAttribute(QL1S("name"), i->first); diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp index 5c1d34de..974bcc77 100644 --- a/src/opensearch/searchengine.cpp +++ b/src/opensearch/searchengine.cpp @@ -137,7 +137,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 d824f04b..a6619441 100644 --- a/src/opensearch/suggestionparser.cpp +++ b/src/opensearch/suggestionparser.cpp @@ -1,5 +1,5 @@ /* ============================================================ - * + * * This file is a part of the rekonq project * * Copyright (C) 2010-2011 by Lionel Chauvin @@ -55,7 +55,7 @@ ResponseList XMLParser::parse(const QByteArray &resp) { m_reader.readNext(); - if (m_reader.isStartDocument()) + if (m_reader.isStartDocument()) continue; if (m_reader.isStartElement() && m_reader.name() == QL1S("Item")) @@ -64,19 +64,19 @@ ResponseList XMLParser::parse(const QByteArray &resp) QString description; QString url; QString image; - int image_width=0; - int image_height=0; + int image_width = 0; + int image_height = 0; 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")) @@ -86,7 +86,7 @@ ResponseList XMLParser::parse(const QByteArray &resp) 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(); } @@ -112,8 +112,8 @@ ResponseList JSONParser::parse(const QByteArray &resp) } if (!response.startsWith(QL1C('[')) - || !response.endsWith(QL1C(']')) - ) + || !response.endsWith(QL1C(']')) + ) { kDebug() << "RESPONSE is NOT well FORMED"; return ResponseList(); diff --git a/src/opensearch/suggestionparser.h b/src/opensearch/suggestionparser.h index 902793d0..f96061c7 100644 --- a/src/opensearch/suggestionparser.h +++ b/src/opensearch/suggestionparser.h @@ -1,5 +1,5 @@ /* ============================================================ - * + * * This file is a part of the rekonq project * * Copyright (C) 2010-2011 by Lionel Chauvin @@ -50,20 +50,20 @@ public: int image_height; Response(const Response &item) : title(item.title), - description(item.description), - url(item.url), - image(item.image), - image_width(item.image_width), - image_height(item.image_height) + description(item.description), + url(item.url), + image(item.image), + image_width(item.image_width), + image_height(item.image_height) {}; Response() : title(QString()), - description(QString()), - url(QString()), - image(QString()), - image_width(0), - image_height(0) + description(QString()), + url(QString()), + image(QString()), + image_width(0), + image_height(0) {}; @@ -73,11 +73,11 @@ public: const QString &_image = QString(), const int &_image_width = 0, const int &_image_height = 0) : title(_title), - description(_description), - url(_url), - image(_image), - image_width(_image_width), - image_height(_image_height) + description(_description), + url(_url), + image(_image), + image_width(_image_width), + image_height(_image_height) {}; }; @@ -98,13 +98,16 @@ public: class XMLParser : public SuggestionParser -{ +{ protected: QXmlStreamReader m_reader; public: ResponseList parse(const QByteArray &resp); - inline QString type() { return QL1S("application/x-suggestions+xml"); } + inline QString type() + { + return QL1S("application/x-suggestions+xml"); + } }; @@ -112,10 +115,13 @@ class JSONParser : public SuggestionParser { private: QScriptEngine m_reader; - + public: ResponseList parse(const QByteArray &resp); - inline QString type() { return QL1S("application/x-suggestions+json"); } + inline QString type() + { + return QL1S("application/x-suggestions+json"); + } }; #endif //SUGGESTIONPARSER_H -- cgit v1.2.1