StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 22 skipping to change at line 22
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelUtils.hpp"
#include "kfilterdev.h" #include "kfilterdev.h"
#include <QStringListModel> #include <QStringListModel>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
StelLocationMgr::StelLocationMgr() StelLocationMgr::StelLocationMgr()
{ {
// The line below allows to re-generate the location file, you still need to gunzip manually it afterward. // The line below allows to re-generate the location file, you still need to gunzip manually it afterward.
// generateBinaryLocationFile("data/base_locations.txt", false, "dat a/base_locations.bin"); // generateBinaryLocationFile("data/base_locations.txt", false, "dat a/base_locations.bin");
locations = loadCitiesBin("data/base_locations.bin.gz"); locations = loadCitiesBin("data/base_locations.bin.gz");
locations.unite(loadCities("data/user_locations.txt", true)); locations.unite(loadCities("data/user_locations.txt", true));
modelAllLocation = new QStringListModel(this); modelAllLocation = new QStringListModel(this);
modelAllLocation->setStringList(locations.keys()); modelAllLocation->setStringList(locations.keys());
// Init to Paris France because it's the center of the world.
lastResortLocation = locationForSmallString("Paris, France");
} }
void StelLocationMgr::generateBinaryLocationFile(const QString& fileName, b ool isUserLocation, const QString& binFilePath) const void StelLocationMgr::generateBinaryLocationFile(const QString& fileName, b ool isUserLocation, const QString& binFilePath) const
{ {
const QMap<QString, StelLocation>& cities = loadCities(fileName, isU serLocation); const QMap<QString, StelLocation>& cities = loadCities(fileName, isU serLocation);
QFile binfile(binFilePath); QFile binfile(binFilePath);
binfile.open(QIODevice::WriteOnly); binfile.open(QIODevice::WriteOnly);
QDataStream out(&binfile); QDataStream out(&binfile);
out.setVersion(QDataStream::Qt_4_6); out.setVersion(QDataStream::Qt_4_6);
out << cities; out << cities;
skipping to change at line 156 skipping to change at line 160
} }
} }
sourcefile.close(); sourcefile.close();
return locations; return locations;
} }
StelLocationMgr::~StelLocationMgr() StelLocationMgr::~StelLocationMgr()
{ {
} }
const StelLocation StelLocationMgr::locationForSmallString(const QString& s ) const const StelLocation StelLocationMgr::locationForSmallString(const QString& s , bool* ok) const
{ {
QMap<QString, StelLocation>::const_iterator iter = locations.find(s) ; QMap<QString, StelLocation>::const_iterator iter = locations.find(s) ;
if (iter==locations.end()) if (iter==locations.end())
{ {
qWarning() << "Warning: location" << s << "is unknown"; if (ok)
return locations["Paris, France"]; *ok=false;
return lastResortLocation;
} }
else else
{ {
if (ok)
*ok = true;
return locations.value(s); return locations.value(s);
} }
} }
const StelLocation StelLocationMgr::locationForString(const QString& s, boo
l* ok) const
{
bool myOk;
StelLocation ret = locationForSmallString(s, &myOk);
if (myOk)
{
if (ok)
*ok=true;
return ret;
}
// Maybe it is a coordinate set ? (e.g. GPS +41d51'00" -51d00'00" )
QRegExp reg("(.*)([\\+\\-](?:\\d+)d(?:\\d+)'(?:\\d+)\") ([\\+\\-](?:
\\d+)d(?:\\d+)'(?:\\d+)\")");
reg.setMinimal(true);
if (!reg.exactMatch(s))
{
if (ok)
*ok=false;
return ret;
}
// We have a set of coordinates
ret.name = reg.capturedTexts()[1].trimmed();
ret.latitude = StelUtils::dmsStrToRad(reg.capturedTexts()[2]) * 180
/ M_PI;
ret.longitude = StelUtils::dmsStrToRad(reg.capturedTexts()[3]) * 180
/ M_PI;
if (ok)
*ok=true;
return ret;
}
// Get whether a location can be permanently added to the list of user loca tions // Get whether a location can be permanently added to the list of user loca tions
bool StelLocationMgr::canSaveUserLocation(const StelLocation& loc) const bool StelLocationMgr::canSaveUserLocation(const StelLocation& loc) const
{ {
return locations.find(loc.getID())==locations.end(); return locations.find(loc.getID())==locations.end();
} }
// Add permanently a location to the list of user locations // Add permanently a location to the list of user locations
bool StelLocationMgr::saveUserLocation(const StelLocation& loc) bool StelLocationMgr::saveUserLocation(const StelLocation& loc)
{ {
if (!canSaveUserLocation(loc)) if (!canSaveUserLocation(loc))
 End of changes. 6 change blocks. 
3 lines changed or deleted 42 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/