Stellarium  0.16.1
StelLocationMgr.hpp
1 /*
2  * Copyright (C) 2008 Fabien Chereau
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _STELLOCATIONMGR_HPP_
20 #define _STELLOCATIONMGR_HPP_
21 
22 #include "StelLocation.hpp"
23 #include <QString>
24 #include <QObject>
25 #include <QMetaType>
26 #include <QMap>
27 
28 typedef QList<StelLocation> LocationList;
29 typedef QMap<QString,StelLocation> LocationMap;
30 typedef QMap<QByteArray,QByteArray> TimezoneNameMap;
31 
32 class GPSLookupHelper;
33 
36 class StelLocationMgr : public QObject
37 {
38  Q_OBJECT
39 
40 public:
43  ~StelLocationMgr();
44 
46  StelLocationMgr(const LocationList& locations);
47 
49  void setLocations(const LocationList& locations);
50 
52  LocationList getAll() const {return locations.values();}
53 
55  LocationMap getAllMap() const { return locations; }
56 
58  const StelLocation locationFromCLI() const;
59 
61  const StelLocation& getLastResortLocation() const {return lastResortLocation;}
62 
65  bool canSaveUserLocation(const StelLocation& loc) const;
66 
69  bool saveUserLocation(const StelLocation& loc);
70 
74  bool canDeleteUserLocation(const QString& id) const;
75 
79  bool deleteUserLocation(const QString& id);
80 
82  LocationMap pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees);
84  LocationMap pickLocationsInCountry(const QString country);
85 
86 public slots:
89  const StelLocation locationForString(const QString& s) const;
90 
92  void locationFromIP();
93 
94 #ifdef ENABLE_GPS
95  bool locationFromGPS();
101 #endif
102 
106  static QString sanitizeTimezoneStringForLocationDB(QString tzString);
111  static QString sanitizeTimezoneStringFromLocationDB(QString dbString);
112 
113 signals:
116  void locationListChanged();
117 
118 #ifdef ENABLE_GPS
119  void gpsQueryFinished(bool success);
122 #endif
123 private slots:
125  void changeLocationFromNetworkLookup();
126 #ifdef ENABLE_GPS
127  void changeLocationFromGPSQuery(const StelLocation& loc);
128  void gpsQueryError(const QString& err);
129 #endif
130 private:
131  void generateBinaryLocationFile(const QString& txtFile, bool isUserLocation, const QString& binFile) const;
132 
134  static LocationMap loadCities(const QString& fileName, bool isUserLocation);
135  static LocationMap loadCitiesBin(const QString& fileName);
136 
138  LocationMap locations;
148  static TimezoneNameMap locationDBToIANAtranslations;
149 
150  StelLocation lastResortLocation;
151 
152  GPSLookupHelper *nmeaHelper,*libGpsHelper;
153 };
154 
155 #endif // _STELLOCATIONMGR_HPP_
const StelLocation locationForString(const QString &s) const
Return the StelLocation for a given string Can match location name, or coordinates.
Store the informations for a location on a planet.
StelLocationMgr()
Default constructor which loads the list of locations from the base and user location files...
LocationMap getAllMap() const
Returns a map of all loaded locations. The key is the location ID, suitable for a list view...
static QString sanitizeTimezoneStringFromLocationDB(QString dbString)
Attempt to translate a timezone name from those used in Stellarium&#39;s location database to a name whic...
Manage the list of available location.
const StelLocation locationFromCLI() const
Return the StelLocation from a CLI.
bool saveUserLocation(const StelLocation &loc)
Add permanently a location to the list of user locations It is later identified by its small string...
void locationListChanged()
Can be used to detect changes to the full location list i.e.
void setLocations(const LocationList &locations)
Replaces the loaded location list.
LocationMap pickLocationsInCountry(const QString country)
Find list of locations in a particular country only.
LocationMap pickLocationsNearby(const QString planetName, const float longitude, const float latitude, const float radiusDegrees)
Find list of locations within.
const StelLocation & getLastResortLocation() const
Return a valid location when no valid one was found.
static QString sanitizeTimezoneStringForLocationDB(QString tzString)
Check timezone string and return either the same or one that we use in the Stellarium location databa...
bool deleteUserLocation(const QString &id)
Delete permanently the given location from the list of user locations If the location comes from the ...
bool canDeleteUserLocation(const QString &id) const
Get whether a location can be deleted from the list of user locations If the location comes from the ...
LocationList getAll() const
Return the list of all loaded locations.
void locationFromIP()
Find location via online lookup of IP address.
bool canSaveUserLocation(const StelLocation &loc) const
Get whether a location can be permanently added to the list of user locations The main constraint is ...