StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 28 skipping to change at line 28
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "kfilterdev.h" #include "kfilterdev.h"
#include <QStringListModel> #include <QStringListModel>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir>
StelLocationMgr::StelLocationMgr() StelLocationMgr::StelLocationMgr()
{ {
// The line below allows to re-generate the location file, you still need to gunzip it manually afterward. // The line below allows to re-generate the location file, you still need to gunzip it manually 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);
skipping to change at line 71 skipping to change at line 72
cityDataPath = StelFileMgr::findFile(fileName); cityDataPath = StelFileMgr::findFile(fileName);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
return res; return res;
} }
QFile sourcefile(cityDataPath); QFile sourcefile(cityDataPath);
if (!sourcefile.open(QIODevice::ReadOnly)) if (!sourcefile.open(QIODevice::ReadOnly))
{ {
qWarning() << "ERROR: Could not open location data file: " < < cityDataPath; qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath);
return res; return res;
} }
if (fileName.endsWith(".gz")) if (fileName.endsWith(".gz"))
{ {
QIODevice* d = KFilterDev::device(&sourcefile, "application/ x-gzip", false); QIODevice* d = KFilterDev::device(&sourcefile, "application/ x-gzip", false);
d->open(QIODevice::ReadOnly); d->open(QIODevice::ReadOnly);
QDataStream in(d); QDataStream in(d);
in.setVersion(QDataStream::Qt_4_6); in.setVersion(QDataStream::Qt_4_6);
in >> res; in >> res;
skipping to change at line 108 skipping to change at line 109
QMap<QString, StelLocation> locations; QMap<QString, StelLocation> locations;
QString cityDataPath; QString cityDataPath;
try try
{ {
cityDataPath = StelFileMgr::findFile(fileName); cityDataPath = StelFileMgr::findFile(fileName);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
// Note it is quite normal to nor have a user locations file (e.g. first run) // Note it is quite normal to nor have a user locations file (e.g. first run)
if (!isUserLocation) if (!isUserLocation)
qWarning() << "WARNING: Failed to locate location da ta file: " << fileName << e.what(); qWarning() << "WARNING: Failed to locate location da ta file: " << QDir::toNativeSeparators(fileName) << e.what();
return locations; return locations;
} }
QFile sourcefile(cityDataPath); QFile sourcefile(cityDataPath);
if (!sourcefile.open(QIODevice::ReadOnly | QIODevice::Text)) if (!sourcefile.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qWarning() << "ERROR: Could not open location data file: " < < cityDataPath; qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath);
return locations; return locations;
} }
// Read the data serialized from the file. // Read the data serialized from the file.
// Code below borrowed from Marble (http://edu.kde.org/marble/) // Code below borrowed from Marble (http://edu.kde.org/marble/)
QTextStream sourcestream(&sourcefile); QTextStream sourcestream(&sourcefile);
sourcestream.setCodec("UTF-8"); sourcestream.setCodec("UTF-8");
StelLocation loc; StelLocation loc;
while (!sourcestream.atEnd()) while (!sourcestream.atEnd())
{ {
skipping to change at line 235 skipping to change at line 236
try try
{ {
cityDataPath = StelFileMgr::findFile("data/user_locations.tx t", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::File)); cityDataPath = StelFileMgr::findFile("data/user_locations.tx t", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::File));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data")) if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data"))
{ {
if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data")) if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data"))
{ {
qWarning() << "ERROR - cannot create non-exi stent data directory" << StelFileMgr::getUserDir()+"/data"; qWarning() << "ERROR - cannot create non-exi stent data directory" << QDir::toNativeSeparators(StelFileMgr::getUserDir() +"/data");
qWarning() << "Location cannot be saved"; qWarning() << "Location cannot be saved";
return false; return false;
} }
} }
cityDataPath = StelFileMgr::getUserDir()+"/data/user_locatio ns.txt"; cityDataPath = StelFileMgr::getUserDir()+"/data/user_locatio ns.txt";
qWarning() << "Will create a new user location file: " << ci tyDataPath; qWarning() << "Will create a new user location file: " << QD ir::toNativeSeparators(cityDataPath);
} }
QFile sourcefile(cityDataPath); QFile sourcefile(cityDataPath);
if (!sourcefile.open(QIODevice::WriteOnly | QIODevice::Text | QIODev ice::Append)) if (!sourcefile.open(QIODevice::WriteOnly | QIODevice::Text | QIODev ice::Append))
{ {
qWarning() << "ERROR: Could not open location data file: " < < cityDataPath; qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath);
return false; return false;
} }
QTextStream outstream(&sourcefile); QTextStream outstream(&sourcefile);
outstream.setCodec("UTF-8"); outstream.setCodec("UTF-8");
outstream << loc.serializeToLine() << '\n'; outstream << loc.serializeToLine() << '\n';
sourcefile.close(); sourcefile.close();
return true; return true;
} }
skipping to change at line 296 skipping to change at line 297
try try
{ {
cityDataPath = StelFileMgr::findFile("data/user_locations.tx t", StelFileMgr::Writable); cityDataPath = StelFileMgr::findFile("data/user_locations.tx t", StelFileMgr::Writable);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data")) if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data"))
{ {
if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data")) if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data"))
{ {
qWarning() << "ERROR - cannot create non-exi stent data directory" << StelFileMgr::getUserDir()+"/data"; qWarning() << "ERROR - cannot create non-exi stent data directory" << QDir::toNativeSeparators(StelFileMgr::getUserDir() +"/data");
qWarning() << "Location cannot be saved"; qWarning() << "Location cannot be saved";
return false; return false;
} }
} }
cityDataPath = StelFileMgr::getUserDir()+"/data/user_locatio ns.txt"; cityDataPath = StelFileMgr::getUserDir()+"/data/user_locatio ns.txt";
qWarning() << "Will create a new user location file: " << ci tyDataPath; qWarning() << "Will create a new user location file: " << QD ir::toNativeSeparators(cityDataPath);
} }
QFile sourcefile(cityDataPath); QFile sourcefile(cityDataPath);
if (!sourcefile.open(QIODevice::WriteOnly | QIODevice::Text)) if (!sourcefile.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
qWarning() << "ERROR: Could not open location data file: " < < cityDataPath; qWarning() << "ERROR: Could not open location data file: " < < QDir::toNativeSeparators(cityDataPath);
return false; return false;
} }
QTextStream outstream(&sourcefile); QTextStream outstream(&sourcefile);
outstream.setCodec("UTF-8"); outstream.setCodec("UTF-8");
for (QMap<QString, StelLocation>::ConstIterator iter=locations.const Begin();iter!=locations.constEnd();++iter) for (QMap<QString, StelLocation>::ConstIterator iter=locations.const Begin();iter!=locations.constEnd();++iter)
{ {
if (iter.value().isUserLocation) if (iter.value().isUserLocation)
{ {
 End of changes. 10 change blocks. 
9 lines changed or deleted 10 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/