2 * This file is part of Jenirok.
4 * Jenirok 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 3 of the License, or
7 * (at your option) any later version.
9 * Jenirok 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.
14 * You should have received a copy of the GNU General Public License
15 * along with Jenirok. If not, see <http://www.gnu.org/licenses/>.
22 #include <QtCore/QObject>
23 #include <QtCore/QString>
24 #include <QtCore/QTimerEvent>
25 #include <QtCore/QUrl>
26 #include <QtCore/QByteArray>
27 #include <QtNetwork/QHttp>
29 class Source : public QObject
44 enum SearchType {YELLOW_PAGES, PERSONS, BOTH};
51 SearchDetails(QString const& query = "",
52 QString const& location = "",
53 SearchType type = PERSONS);
57 enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
58 enum SourceId {ENIRO, MOBIL1881, DASTELEFONBUCH};
59 static int const SOURCE_COUNT = 3;
68 static unsigned int const DEFAULT_MAX_RESULTS = 30;
70 static Source* getSource(SourceId id, QObject* parent = 0);
71 static void getSources(QList<SourceDetails>& list);
72 static SourceId stringToId(QString const& str);
73 Source(QObject* parent = 0);
75 static Source* getSource();
77 virtual void search(SearchDetails const& details) = 0;
78 virtual void getSearchTypes(QList<SearchType>& types) const;
79 void setMaxResults(unsigned int results);
80 unsigned int getMaxResults() const;
81 void setTimeout(unsigned int ms);
82 unsigned int getTimeout() const;
84 void setFindNumber(bool value);
85 bool getFindNumber() const;
87 const QString& errorString() const;
90 void resultAvailable(Source::Result const& result, Source::SearchDetails const& details);
91 void requestFinished(QVector <Source::Result> const& results, Source::SearchDetails const& details, bool error);
94 void setError(Error error, QString const& errorString = "");
95 virtual void timerEvent(QTimerEvent *te);
96 static QString ucFirst(QString& string);
97 static QString& cleanUpNumber(QString& number);
98 static QString& stripTags(QString& string);
99 static QString& htmlEntityDecode(QString& string);
100 static bool isPhoneNumber(QString const& string);
101 void fixUrl(QUrl& url);
105 void httpReady(int id, bool error);
108 Q_DISABLE_COPY(Source);
109 virtual void handleHttpData(int id, QByteArray const& data) = 0;
110 virtual void handleHttpError(int id) = 0;
111 unsigned int maxResults_;
112 unsigned int timeout_;
116 QString errorString_;
121 static QRegExp numberCleaner_;
122 static QRegExp tagStripper_;