2011-10-21 23:26:34 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Jakub Wieczorek <faw217@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-10-21 23:26:34 +02:00
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
|
|
|
|
#ifndef OPENSEARCHENGINE_H
|
|
|
|
#define OPENSEARCHENGINE_H
|
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
#include <qpair.h>
|
|
|
|
#include <qimage.h>
|
|
|
|
#include <qmap.h>
|
|
|
|
#include <qnetworkaccessmanager.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qurl.h>
|
|
|
|
|
|
|
|
class QNetworkReply;
|
|
|
|
|
|
|
|
class OpenSearchEngineDelegate;
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT OpenSearchEngine : public QObject
|
2011-10-21 23:26:34 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void imageChanged();
|
|
|
|
void suggestions(const QStringList &suggestions);
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef QPair<QString, QString> Parameter;
|
|
|
|
typedef QList<Parameter> Parameters;
|
|
|
|
|
|
|
|
Q_PROPERTY(QString name READ name WRITE setName)
|
|
|
|
Q_PROPERTY(QString description READ description WRITE setDescription)
|
|
|
|
Q_PROPERTY(QString searchUrlTemplate READ searchUrlTemplate WRITE setSearchUrlTemplate)
|
|
|
|
Q_PROPERTY(Parameters searchParameters READ searchParameters WRITE setSearchParameters)
|
|
|
|
Q_PROPERTY(QString searchMethod READ searchMethod WRITE setSearchMethod)
|
|
|
|
Q_PROPERTY(QString suggestionsUrlTemplate READ suggestionsUrlTemplate WRITE setSuggestionsUrlTemplate)
|
|
|
|
Q_PROPERTY(Parameters suggestionsParameters READ suggestionsParameters WRITE setSuggestionsParameters)
|
|
|
|
Q_PROPERTY(QString suggestionsMethod READ suggestionsMethod WRITE setSuggestionsMethod)
|
|
|
|
Q_PROPERTY(bool providesSuggestions READ providesSuggestions)
|
|
|
|
Q_PROPERTY(QString imageUrl READ imageUrl WRITE setImageUrl)
|
|
|
|
Q_PROPERTY(bool valid READ isValid)
|
2011-11-06 17:01:23 +01:00
|
|
|
Q_PROPERTY(QNetworkAccessManager* networkAccessManager READ networkAccessManager WRITE setNetworkAccessManager)
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
OpenSearchEngine(QObject* parent = 0);
|
2011-10-21 23:26:34 +02:00
|
|
|
~OpenSearchEngine();
|
|
|
|
|
|
|
|
QString name() const;
|
|
|
|
void setName(const QString &name);
|
|
|
|
|
|
|
|
QString description() const;
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
|
|
|
QString searchUrlTemplate() const;
|
|
|
|
void setSearchUrlTemplate(const QString &searchUrl);
|
|
|
|
QUrl searchUrl(const QString &searchTerm) const;
|
|
|
|
|
2013-11-09 15:48:24 +01:00
|
|
|
QByteArray getPostData(const QString &searchTerm) const;
|
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
bool providesSuggestions() const;
|
|
|
|
|
|
|
|
QString suggestionsUrlTemplate() const;
|
|
|
|
void setSuggestionsUrlTemplate(const QString &suggestionsUrl);
|
|
|
|
QUrl suggestionsUrl(const QString &searchTerm) const;
|
|
|
|
|
|
|
|
Parameters searchParameters() const;
|
|
|
|
void setSearchParameters(const Parameters &searchParameters);
|
|
|
|
|
|
|
|
Parameters suggestionsParameters() const;
|
|
|
|
void setSuggestionsParameters(const Parameters &suggestionsParameters);
|
|
|
|
|
|
|
|
QString searchMethod() const;
|
|
|
|
void setSearchMethod(const QString &method);
|
|
|
|
|
|
|
|
QString suggestionsMethod() const;
|
|
|
|
void setSuggestionsMethod(const QString &method);
|
|
|
|
|
|
|
|
QString imageUrl() const;
|
|
|
|
void setImageUrl(const QString &url);
|
|
|
|
|
|
|
|
QImage image() const;
|
|
|
|
void setImage(const QImage &image);
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
void setSuggestionsUrl(const QString &string);
|
|
|
|
void setSuggestionsParameters(const QByteArray ¶meters);
|
|
|
|
QString getSuggestionsUrl();
|
|
|
|
QByteArray getSuggestionsParameters();
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QNetworkAccessManager* networkAccessManager() const;
|
|
|
|
void setNetworkAccessManager(QNetworkAccessManager* networkAccessManager);
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
OpenSearchEngineDelegate* delegate() const;
|
|
|
|
void setDelegate(OpenSearchEngineDelegate* delegate);
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
bool operator==(const OpenSearchEngine &other) const;
|
|
|
|
bool operator<(const OpenSearchEngine &other) const;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void requestSuggestions(const QString &searchTerm);
|
|
|
|
void requestSearchResults(const QString &searchTerm);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static QString parseTemplate(const QString &searchTerm, const QString &searchTemplate);
|
|
|
|
void loadImage() const;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void imageObtained();
|
|
|
|
void suggestionsObtained();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_name;
|
|
|
|
QString m_description;
|
|
|
|
|
|
|
|
QString m_imageUrl;
|
|
|
|
QImage m_image;
|
|
|
|
|
|
|
|
QString m_searchUrlTemplate;
|
|
|
|
QString m_suggestionsUrlTemplate;
|
|
|
|
Parameters m_searchParameters;
|
|
|
|
Parameters m_suggestionsParameters;
|
|
|
|
QString m_searchMethod;
|
|
|
|
QString m_suggestionsMethod;
|
|
|
|
|
|
|
|
QByteArray m_preparedSuggestionsParameters;
|
|
|
|
QString m_preparedSuggestionsUrl;
|
|
|
|
|
|
|
|
QMap<QString, QNetworkAccessManager::Operation> m_requestMethods;
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QNetworkAccessManager* m_networkAccessManager;
|
|
|
|
QNetworkReply* m_suggestionsReply;
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
OpenSearchEngineDelegate* m_delegate;
|
2011-10-21 23:26:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OPENSEARCHENGINE_H
|
|
|
|
|