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/QVector>
25 #include <QtCore/QSet>
26 #include <QtCore/QRegExp>
27 #include <QtCore/QUrl>
28 #include <QtCore/QTimerEvent>
29 #include <QtNetwork/QHttp>
31 class Eniro: public QObject
37 enum Site {FI, SE, DK};
38 static const int SITE_COUNT = 3;
40 enum SearchType {YELLOW_PAGES, PERSONS};
42 enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
57 SearchDetails(QString const& query = "",
58 QString const& location = "",
59 SearchType type = PERSONS);
68 static unsigned int const DEFAULT_MAX_RESULTS = 30;
70 Eniro(Site site, QObject *parent = 0);
74 void login(QString const& username, QString const& password);
78 void setMaxResults(unsigned int value);
79 void setFindNumber(bool value);
80 void setTimeout(unsigned int ms);
81 bool search(SearchDetails const& details);
84 const QString& errorString() const;
85 static QMap<Site, SiteDetails> getSites();
86 static Site stringToSite(QString const& str);
89 void resultAvailable(Eniro::Result const& result, Eniro::SearchDetails const& details);
90 void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
91 void loginStatus(bool success);
94 void httpReady(int id, bool error);
98 Q_DISABLE_COPY(Eniro);
108 SearchDetails details;
109 QVector <Result> results;
110 unsigned int foundNumbers;
111 unsigned int numbersTotal;
114 QUrl createUrl(QString const& query, QString const& location);
115 void loadResults(int id, QString const& data);
116 void loadNumber(int id, QString const& data);
117 void getNumberForResult(int id, int index, SearchDetails const& details);
118 void emitRequestFinished(int key, SearchData* data, bool error);
120 void timerEvent(QTimerEvent *te);
121 QString ucFirst(QString& string);
122 QString& cleanUpNumber(QString& number);
123 QString& stripTags(QString& string);
131 QString errorString_;
132 unsigned int maxResults_;
133 unsigned int timeout_;
136 typedef QMap <int, SearchData*> searchMap;
137 typedef QMap <int, NumberData*> numberMap;
139 searchMap pendingSearches_;
140 numberMap pendingNumberRequests_;
141 QSet <int> pendingLoginRequests_;
143 static QRegExp numberCleaner_;
144 static QRegExp tagStripper_;