Falkon Develop
Cross-platform Qt-based web browser
opensearchengine.h
Go to the documentation of this file.
1/*
2 * Copyright 2009 Jakub Wieczorek <faw217@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
18 */
19/* ============================================================
20* Falkon - Qt web browser
21* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
22*
23* This program is free software: you can redistribute it and/or modify
24* it under the terms of the GNU General Public License as published by
25* the Free Software Foundation, either version 3 of the License, or
26* (at your option) any later version.
27*
28* This program is distributed in the hope that it will be useful,
29* but WITHOUT ANY WARRANTY; without even the implied warranty of
30* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31* GNU General Public License for more details.
32*
33* You should have received a copy of the GNU General Public License
34* along with this program. If not, see <http://www.gnu.org/licenses/>.
35* ============================================================ */
36
37#ifndef OPENSEARCHENGINE_H
38#define OPENSEARCHENGINE_H
39
40#include "qzcommon.h"
41
42#include <qpair.h>
43#include <qimage.h>
44#include <qmap.h>
45#include <qnetworkaccessmanager.h>
46#include <qstring.h>
47#include <qurl.h>
48
49class QNetworkReply;
50
52class FALKON_EXPORT OpenSearchEngine : public QObject
53{
54 Q_OBJECT
55
56Q_SIGNALS:
58 void suggestions(const QStringList &suggestions);
59
60public:
61 using Parameter = QPair<QString, QString>;
62 using Parameters = QList<Parameter>;
63
64 Q_PROPERTY(QString name READ name WRITE setName)
65 Q_PROPERTY(QString description READ description WRITE setDescription)
66 Q_PROPERTY(QString searchUrlTemplate READ searchUrlTemplate WRITE setSearchUrlTemplate)
67 Q_PROPERTY(Parameters searchParameters READ searchParameters WRITE setSearchParameters)
68 Q_PROPERTY(QString searchMethod READ searchMethod WRITE setSearchMethod)
69 Q_PROPERTY(QString suggestionsUrlTemplate READ suggestionsUrlTemplate WRITE setSuggestionsUrlTemplate)
70 Q_PROPERTY(Parameters suggestionsParameters READ suggestionsParameters WRITE setSuggestionsParameters)
71 Q_PROPERTY(QString suggestionsMethod READ suggestionsMethod WRITE setSuggestionsMethod)
72 Q_PROPERTY(bool providesSuggestions READ providesSuggestions)
73 Q_PROPERTY(QString imageUrl READ imageUrl WRITE setImageUrl)
74 Q_PROPERTY(bool valid READ isValid)
75 Q_PROPERTY(QNetworkAccessManager* networkAccessManager READ networkAccessManager WRITE setNetworkAccessManager)
76
77 OpenSearchEngine(QObject* parent = nullptr);
79
80 QString name() const;
81 void setName(const QString &name);
82
83 QString description() const;
84 void setDescription(const QString &description);
85
86 QString searchUrlTemplate() const;
87 void setSearchUrlTemplate(const QString &searchUrl);
88 QUrl searchUrl(const QString &searchTerm) const;
89
90 QByteArray getPostData(const QString &searchTerm) const;
91
92 bool providesSuggestions() const;
93
94 QString suggestionsUrlTemplate() const;
95 void setSuggestionsUrlTemplate(const QString &suggestionsUrl);
96 QUrl suggestionsUrl(const QString &searchTerm) const;
97
98 Parameters searchParameters() const;
99 void setSearchParameters(const Parameters &searchParameters);
100
101 Parameters suggestionsParameters() const;
102 void setSuggestionsParameters(const Parameters &suggestionsParameters);
103
104 QString searchMethod() const;
105 void setSearchMethod(const QString &method);
106
107 QString suggestionsMethod() const;
108 void setSuggestionsMethod(const QString &method);
109
110 QString imageUrl() const;
111 void setImageUrl(const QString &url);
112
113 QImage image() const;
114 void setImage(const QImage &image);
115
116 bool isValid() const;
117
118 void setSuggestionsUrl(const QString &string);
119 void setSuggestionsParameters(const QByteArray &parameters);
120 QString getSuggestionsUrl();
121 QByteArray getSuggestionsParameters();
122
123 QNetworkAccessManager* networkAccessManager() const;
124 void setNetworkAccessManager(QNetworkAccessManager* networkAccessManager);
125
126 OpenSearchEngineDelegate* delegate() const;
127 void setDelegate(OpenSearchEngineDelegate* delegate);
128
129 bool operator==(const OpenSearchEngine &other) const;
130 bool operator<(const OpenSearchEngine &other) const;
131
132public Q_SLOTS:
133 void requestSuggestions(const QString &searchTerm);
134 void requestSearchResults(const QString &searchTerm);
135
136protected:
137 static QString parseTemplate(const QString &searchTerm, const QString &searchTemplate);
138 void loadImage() const;
139
140private Q_SLOTS:
141 void imageObtained();
142 void suggestionsObtained();
143
144private:
145 QString m_name;
146 QString m_description;
147
148 QString m_imageUrl;
149 QImage m_image;
150
151 QString m_searchUrlTemplate;
152 QString m_suggestionsUrlTemplate;
153 Parameters m_searchParameters;
154 Parameters m_suggestionsParameters;
155 QString m_searchMethod;
156 QString m_suggestionsMethod;
157
158 QByteArray m_preparedSuggestionsParameters;
159 QString m_preparedSuggestionsUrl;
160
161 QMap<QString, QNetworkAccessManager::Operation> m_requestMethods;
162
163 QNetworkAccessManager* m_networkAccessManager;
164 QNetworkReply* m_suggestionsReply;
165
166 OpenSearchEngineDelegate* m_delegate;
167};
168
169#endif // OPENSEARCHENGINE_H
170
An abstract class providing custom processing of specific activities.
A class representing a single search engine described in OpenSearch format.
QPair< QString, QString > Parameter
QList< Parameter > Parameters
bool operator==(const HistoryEntry &x, const HistoryEntry &y)
Definition: qmlstaticdata.h:84
#define FALKON_EXPORT
Definition: qzcommon.h:28