Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / searchclients / gpsclient.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 GPSCLIENT_H
19 #define GPSCLIENT_H
20
21 #include "searchclientsemaphore.h"
22
23 #include <QObject>
24 #include <QMutex>
25 #include <QNetworkReply>
26
27 class QNetworkAccessManager;
28
29 #ifdef QT_MOBILITY_LOCATION
30 #include <qmobilityglobal.h>
31
32 QTM_BEGIN_NAMESPACE
33         class QGeoPositionInfo;
34 class QGeoPositionInfoSource;
35 QTM_END_NAMESPACE;
36
37 QTM_USE_NAMESPACE;
38 #endif
39
40 #ifdef LIBLOCATION
41 extern "C" {
42 #include <location/location-gps-device.h>
43 #include <location/location-gpsd-control.h>
44 }
45 class QTimer;
46 #endif
47
48 class GpsClient : public QObject
49 {
50     Q_OBJECT
51 public:
52     static const int INVALID_SEARCH_TASK_ID = -1;
53
54 public:
55     GpsClient();
56     ~GpsClient();
57
58 public:
59     int GetSearchTaskId() const { return _search_task_id; }
60
61     void SearchLocation();
62
63     static void CancelAllRunningSearchs();
64
65 public:
66     Q_SIGNAL void SearchStarted(int search_task_id);
67     Q_SIGNAL void PositionUpdate(int search_task_id);
68     Q_SIGNAL void SearchForTownStarted(int search_task_id);
69     Q_SIGNAL void TownUpdate(int search_task_id, QString town);
70     Q_SIGNAL void SearchError(int search_task_id);
71     Q_SIGNAL void SearchFinished(int search_task_id, bool success);
72
73 private:
74 #ifdef QT_MOBILITY_LOCATION
75     Q_SLOT void GeoPositionUpdated(const QGeoPositionInfo &);
76     Q_SLOT void GeoPositionTimedOut();
77 #endif
78
79 #ifdef LIBLOCATION
80 public:
81     void GpsConnected();
82     void GpsChanged();
83     void GpsDisconnected();
84     Q_SLOT void GpsTimedOut();
85 #endif
86
87 private:
88     void SearchTown(const QString &longitude, const QString &latitude);
89     Q_SLOT void ReplyFinished(QNetworkReply *);
90     Q_SLOT void NetworkError(QNetworkReply::NetworkError);
91
92 private:
93 #ifdef QT_MOBILITY_LOCATION
94     QGeoPositionInfoSource *_geo_position_info_source;
95 #endif
96
97 #ifdef LIBLOCATION
98     LocationGPSDControl *_location_gpsd_control;
99     LocationGPSDevice *_location_gps_device;
100     QTimer *_time_out_timer;
101 #endif
102
103     QNetworkAccessManager *_network;
104     static QMutex _next_search_task_id_mutex;
105     static int _next_search_task_id;
106     int _search_task_id;
107     static SearchClientSemaphore _semaphore;
108 };
109
110 #endif // GPSCLIENT_H