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 Eniro(Site site, QObject *parent = 0);
72 void login(QString const& username, QString const& password);
76 void setMaxResults(unsigned int value);
77 void setFindNumber(bool value);
78 void setTimeout(unsigned int ms);
79 bool search(SearchDetails const& details);
82 const QString& errorString() const;
83 static QMap<Site, SiteDetails> getSites();
84 static Site stringToSite(QString const& str);
87 void resultAvailable(Eniro::Result const& result, Eniro::SearchDetails const& details);
88 void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
89 void loginStatus(bool success);
92 void httpReady(int id, bool error);
96 Q_DISABLE_COPY(Eniro);
106 SearchDetails details;
107 QVector <Result> results;
108 unsigned int foundNumbers;
109 unsigned int numbersTotal;
112 QUrl createUrl(QString const& query, QString const& location);
113 void loadResults(int id, QString const& data);
114 void loadNumber(int id, QString const& data);
115 void getNumberForResult(int id, int index, SearchDetails const& details);
116 void emitRequestFinished(int key, SearchData* data, bool error);
118 void timerEvent(QTimerEvent *te);
119 QString ucFirst(QString& string);
120 QString& cleanUpNumber(QString& number);
121 QString& stripTags(QString& string);
129 QString errorString_;
130 unsigned int maxResults_;
131 unsigned int timeout_;
134 typedef QMap <int, SearchData*> searchMap;
135 typedef QMap <int, NumberData*> numberMap;
137 searchMap pendingSearches_;
138 numberMap pendingNumberRequests_;
139 QSet <int> pendingLoginRequests_;
141 static QRegExp numberCleaner_;
142 static QRegExp tagStripper_;