Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / searchclients / abstractsearchclient.h
1 // Copyright 2010 Jochen Becher
2 //
3 // This file is part of MovieSchedule.
4 //
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // MovieSchedule is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with MovieSchedule.  If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef ABSTRACTSEARCHCLIENT_H
19 #define ABSTRACTSEARCHCLIENT_H
20
21 #include <QObject>
22 #include <QNetworkAccessManager>
23 #include <QNetworkReply>
24 #include <QMutex>
25
26 class AbstractSearchClient : public QObject
27 {
28     Q_OBJECT
29 public:
30     static const int INVALID_SEARCH_TASK_ID = -1;
31
32 public:
33     explicit AbstractSearchClient(QObject *parent = 0);
34     virtual ~AbstractSearchClient();
35
36     int GetSearchTaskId() const { return _search_task_id; }
37
38 protected:
39     int GetStartIndex() { return _start; }
40
41     virtual void Search(const QUrl &url, int start);
42     virtual void SearchEncodedUrl(const QString &endcoded_url, int start);
43
44 public:
45     Q_SIGNAL void SearchStarted(int search_task_id);
46     Q_SIGNAL void Progress(int search_task_id, qint64, qint64);
47     Q_SIGNAL void Reply(int search_task_id, bool intermediate);
48     Q_SIGNAL void Error(int search_task_id);
49     Q_SIGNAL void Cancelled(int search_task_id);
50     Q_SIGNAL void SearchFinished(int search_task_id, bool success);
51
52 protected:
53     Q_SLOT virtual void ReplyFinished(QNetworkReply *) = 0;
54     Q_SLOT virtual void DownloadProgress(qint64, qint64);
55     Q_SLOT virtual void NetworkError(QNetworkReply::NetworkError);
56
57 protected:
58     QList<QTime> TimesFromString(const QList<QString> &time_strings);
59
60 private:
61     void FixLocation(QUrl *url);
62
63 private:
64     QNetworkAccessManager *_network;
65     static QMutex _next_search_task_id_mutex;
66     static int _next_search_task_id;
67     int _search_task_id;
68     int _start;
69     QString _location;
70 };
71
72 #endif // ABSTRACTSEARCHCLIENT_H