StelLocationMgr.cpp   StelLocationMgr.cpp 
skipping to change at line 42 skipping to change at line 42
modelAllLocation = new QStringListModel(this); modelAllLocation = new QStringListModel(this);
modelAllLocation->setStringList(locations.keys()); modelAllLocation->setStringList(locations.keys());
} }
void StelLocationMgr::loadCities(const QString& fileName, bool isUserLocati on) void StelLocationMgr::loadCities(const QString& fileName, bool isUserLocati on)
{ {
// Load the cities from data file // Load the cities from data file
QString cityDataPath; QString cityDataPath;
try try
{ {
cityDataPath = StelApp::getInstance().getFileMgr().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: " << fileName << e.what();
return; return;
} }
skipping to change at line 64 skipping to change at line 64
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: " < < cityDataPath;
return; return;
} }
// 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;
while (!sourcestream.atEnd()) while (!sourcestream.atEnd())
{ {
const QString& rawline=sourcestream.readLine(); const QString& rawline=sourcestream.readLine();
if (rawline.isEmpty() || rawline.startsWith('#')) if (rawline.isEmpty() || rawline.startsWith('#'))
continue; continue;
StelLocation loc = StelLocation::createFromLine(rawline); loc = StelLocation::createFromLine(rawline);
loc.isUserLocation = isUserLocation; loc.isUserLocation = isUserLocation;
const QString& locId = loc.getID();
if (locations.contains(loc.getID())) if (locations.contains(locId))
{ {
// Add the state in the name of the existing one and the new one to differentiate // Add the state in the name of the existing one and the new one to differentiate
StelLocation loc2 = locations[loc.getID()]; StelLocation loc2 = locations[locId];
if (!loc2.state.isEmpty()) if (!loc2.state.isEmpty())
loc2.name += " ("+loc2.state+")"; loc2.name += " ("+loc2.state+")";
// remove and re-add the fixed version // remove and re-add the fixed version
locations.remove(loc.getID()); locations.remove(locId);
locations[loc2.getID()] = loc2; locations[loc2.getID()] = loc2;
if (!loc.state.isEmpty()) if (!loc.state.isEmpty())
loc.name += " ("+loc.state+")"; loc.name += " ("+loc.state+")";
locations[loc.getID()] = loc; locations[locId] = loc;
} }
else else
{ {
locations[loc.getID()] = loc; locations.insert(locId, loc);
} }
} }
sourcefile.close(); sourcefile.close();
} }
StelLocationMgr::~StelLocationMgr() StelLocationMgr::~StelLocationMgr()
{ {
} }
const StelLocation StelLocationMgr::locationForSmallString(const QString& s ) const const StelLocation StelLocationMgr::locationForSmallString(const QString& s ) const
skipping to change at line 134 skipping to change at line 136
// Add in the program // Add in the program
locations[loc.getID()]=loc; locations[loc.getID()]=loc;
// Append in the Qt model // Append in the Qt model
modelAllLocation->setStringList(locations.keys()); modelAllLocation->setStringList(locations.keys());
// Append to the user location file // Append to the user location file
QString cityDataPath; QString cityDataPath;
try try
{ {
cityDataPath = StelApp::getInstance().getFileMgr().findFile( "data/user_locations.txt", StelFileMgr::Flags(StelFileMgr::Writable|StelFil eMgr::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(StelApp::getInstance().getFileMgr() .getUserDir()+"/data")) if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data"))
{ {
if (!StelFileMgr::mkDir(StelApp::getInstance().getFi leMgr().getUserDir()+"/data")) if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data"))
{ {
qWarning() << "ERROR - cannot create non-exi stent data directory" << StelApp::getInstance().getFileMgr().getUserDir()+" /data"; qWarning() << "ERROR - cannot create non-exi stent data directory" << StelFileMgr::getUserDir()+"/data";
qWarning() << "Location cannot be saved"; qWarning() << "Location cannot be saved";
return false; return false;
} }
} }
cityDataPath = StelApp::getInstance().getFileMgr().getUserDi r()+"/data/user_locations.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: " << ci tyDataPath;
} }
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: " < < cityDataPath;
return false; return false;
} }
skipping to change at line 195 skipping to change at line 197
return false; return false;
locations.remove(id); locations.remove(id);
// Remove in the Qt model file // Remove in the Qt model file
modelAllLocation->setStringList(locations.keys()); modelAllLocation->setStringList(locations.keys());
// Resave the whole remaining user locations file // Resave the whole remaining user locations file
QString cityDataPath; QString cityDataPath;
try try
{ {
cityDataPath = StelApp::getInstance().getFileMgr().findFile( "data/user_locations.txt", 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(StelApp::getInstance().getFileMgr() .getUserDir()+"/data")) if (!StelFileMgr::exists(StelFileMgr::getUserDir()+"/data"))
{ {
if (!StelFileMgr::mkDir(StelApp::getInstance().getFi leMgr().getUserDir()+"/data")) if (!StelFileMgr::mkDir(StelFileMgr::getUserDir()+"/ data"))
{ {
qWarning() << "ERROR - cannot create non-exi stent data directory" << StelApp::getInstance().getFileMgr().getUserDir()+" /data"; qWarning() << "ERROR - cannot create non-exi stent data directory" << StelFileMgr::getUserDir()+"/data";
qWarning() << "Location cannot be saved"; qWarning() << "Location cannot be saved";
return false; return false;
} }
} }
cityDataPath = StelApp::getInstance().getFileMgr().getUserDi r()+"/data/user_locations.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: " << ci tyDataPath;
} }
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: " < < cityDataPath;
return false; return false;
} }
 End of changes. 19 change blocks. 
17 lines changed or deleted 19 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/