Пример #1
0
void tst_OpenSearchReader::read()
{
    QFETCH(QString, fileName);
    QFETCH(bool, valid);
    QFETCH(QString, name);
    QFETCH(QString, description);
    QFETCH(QString, searchUrlTemplate);
    QFETCH(QString, suggestionsUrlTemplate);
    QFETCH(QString, imageUrl);
    QFETCH(OpenSearchEngine::Parameters, searchParameters);
    QFETCH(OpenSearchEngine::Parameters, suggestionsParameters);

    QFile file(fileName);
    file.open(QIODevice::ReadOnly);
    OpenSearchReader reader;
    OpenSearchEngine *engine = reader.read(&file);

    QCOMPARE(engine->isValid(), valid);
    QCOMPARE(engine->name(), name);
    QCOMPARE(engine->description(), description);
    QCOMPARE(engine->searchUrlTemplate(), searchUrlTemplate);
    QCOMPARE(engine->suggestionsUrlTemplate(), suggestionsUrlTemplate);
    QCOMPARE(engine->searchParameters(), searchParameters);
    QCOMPARE(engine->suggestionsParameters(), suggestionsParameters);
    QCOMPARE(engine->imageUrl(), imageUrl);

    delete engine;
}
Пример #2
0
void OpenSearchManager::setSearchProvider(const QString &searchProvider)
{
    m_activeEngine = 0;

    if (!m_enginesMap.contains(searchProvider)) {
        const QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "konqueror/opensearch/" + searchProvider + ".xml");
        if (fileName.isEmpty()) {
            return;
        }
        QFile file(fileName);

        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            kWarning(1202) << "Cannot open opensearch description file: " + fileName;
            return;
        }

        OpenSearchReader reader;
        OpenSearchEngine *engine = reader.read(&file);

        if (engine) {
            m_enginesMap.insert(searchProvider, engine);
        } else {
            return;
        }
    }

    m_activeEngine = m_enginesMap.value(searchProvider);
}
Пример #3
0
void SearchEnginesManager::replyFinished()
{
    qApp->restoreOverrideCursor();

    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    if (!reply) {
        return;
    }

    if (reply->error() != QNetworkReply::NoError) {
        reply->close();
        reply->deleteLater();
        return;
    }

    OpenSearchReader reader;
    OpenSearchEngine* engine = reader.read(reply);
    engine->setNetworkAccessManager(mApp->networkManager());

    reply->close();
    reply->deleteLater();

    if (checkEngine(engine)) {
        addEngine(engine);
        QMessageBox::information(0, tr("Search Engine Added"), tr("Search Engine \"%1\" has been successfully added.").arg(engine->name()));
    }
}
Пример #4
0
void OpenSearchManager::jobFinished(KJob *job)
{
    if (job->error()) {
        return; // just silently return
    }

    if (m_state == REQ_SUGGESTION) {
        const QStringList suggestionsList = m_activeEngine->parseSuggestion(m_jobData);
        kDebug(1202) << "Received suggestion from " << m_activeEngine->name() << ": " << suggestionsList;

        emit suggestionReceived(suggestionsList);
    } else if (m_state == REQ_DESCRIPTION) {
        OpenSearchReader reader;
        OpenSearchEngine *engine = reader.read(m_jobData);
        if (engine) {
            m_enginesMap.insert(engine->name(), engine);
            QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("/konqueror/opensearch/"), QStandardPaths::LocateDirectory) + "/";
            QString fileName = trimmedEngineName(engine->name());
            QFile file(path + fileName + ".xml");
            OpenSearchWriter writer;
            writer.write(&file, engine);

            QString searchUrl = OpenSearchEngine::parseTemplate(QStringLiteral("\\{@}"), engine->searchUrlTemplate());
            emit openSearchEngineAdded(engine->name(), searchUrl, fileName);
        } else {
            kFatal() << "Error while adding new open search engine";
        }
    }
}