TelescopeControl.cpp   TelescopeControl.cpp 
skipping to change at line 60 skipping to change at line 60
#include "renderer/StelTextureNew.hpp" #include "renderer/StelTextureNew.hpp"
#include <QAction> #include <QAction>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QMapIterator> #include <QMapIterator>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDir>
#include <QDebug> #include <QDebug>
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// //
StelModule* TelescopeControlStelPluginInterface::getStelModule() const StelModule* TelescopeControlStelPluginInterface::getStelModule() const
{ {
return new TelescopeControl(); return new TelescopeControl();
} }
skipping to change at line 394 skipping to change at line 395
{ {
if (telescope->getEnglishName() == name) if (telescope->getEnglishName() == name)
return qSharedPointerCast<StelObject>(telescope); return qSharedPointerCast<StelObject>(telescope);
} }
return 0; return 0;
} }
QStringList TelescopeControl::listMatchingObjectsI18n(const QString& objPre fix, int maxNbItem) const QStringList TelescopeControl::listMatchingObjectsI18n(const QString& objPre fix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0)
return result;
QString objw = objPrefix.toUpper();
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
QString constw = telescope->getNameI18n().mid(0, objw.size() QString tn = telescope->getNameI18n();
).toUpper(); if (tn.contains(objPrefix, Qt::CaseInsensitive))
if (constw==objw)
{ {
result << telescope->getNameI18n(); result << tn;
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) if (result.size()>maxNbItem)
{ {
result.erase(result.begin() + maxNbItem, result.end()); result.erase(result.begin() + maxNbItem, result.end());
} }
return result; return result;
} }
QStringList TelescopeControl::listMatchingObjects(const QString& objPrefix, int maxNbItem) const QStringList TelescopeControl::listMatchingObjects(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0)
return result;
QString objw = objPrefix.toUpper();
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
QString constw = telescope->getEnglishName().mid(0, objw.siz QString tn = telescope->getEnglishName();
e()).toUpper(); if (tn.contains(objPrefix, Qt::CaseInsensitive))
if (constw==objw)
{ {
result << telescope->getEnglishName(); result << tn;
} }
} }
result.sort(); result.sort();
if (result.size()>maxNbItem) if (result.size()>maxNbItem)
{ {
result.erase(result.begin() + maxNbItem, result.end()); result.erase(result.begin() + maxNbItem, result.end());
} }
return result; return result;
} }
skipping to change at line 700 skipping to change at line 701
void TelescopeControl::saveTelescopes() void TelescopeControl::saveTelescopes()
{ {
try try
{ {
//Open/create the JSON file //Open/create the JSON file
QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json"; QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json";
QFile telescopesJsonFile(telescopesJsonPath); QFile telescopesJsonFile(telescopesJsonPath);
if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text)) if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text))
{ {
qWarning() << "TelescopeControl: Telescopes can not be saved. A file can not be open for writing:" << telescopesJsonPath; qWarning() << "TelescopeControl: Telescopes can not be saved. A file can not be open for writing:" << QDir::toNativeSeparators( telescopesJsonPath);
return; return;
} }
//Add the version: //Add the version:
telescopeDescriptions.insert("version", QString(TELESCOPE_CO NTROL_VERSION)); telescopeDescriptions.insert("version", QString(TELESCOPE_CO NTROL_VERSION));
//Convert the tree to JSON //Convert the tree to JSON
StelJsonParser::write(telescopeDescriptions, &telescopesJson File); StelJsonParser::write(telescopeDescriptions, &telescopesJson File);
telescopesJsonFile.flush();//Is this necessary? telescopesJsonFile.flush();//Is this necessary?
telescopesJsonFile.close(); telescopesJsonFile.close();
skipping to change at line 728 skipping to change at line 729
void TelescopeControl::loadTelescopes() void TelescopeControl::loadTelescopes()
{ {
QVariantMap result; QVariantMap result;
try try
{ {
QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json"; QString telescopesJsonPath = StelFileMgr::findFile("modules/ TelescopeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr: :Writable)) + "/telescopes.json";
if(!QFileInfo(telescopesJsonPath).exists()) if(!QFileInfo(telescopesJsonPath).exists())
{ {
qWarning() << "TelescopeControl::loadTelescopes(): N o telescopes loaded. File is missing:" << telescopesJsonPath; qWarning() << "TelescopeControl::loadTelescopes(): N o telescopes loaded. File is missing:" << QDir::toNativeSeparators(telescop esJsonPath);
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
QFile telescopesJsonFile(telescopesJsonPath); QFile telescopesJsonFile(telescopesJsonPath);
QVariantMap map; QVariantMap map;
if(!telescopesJsonFile.open(QFile::ReadOnly)) if(!telescopesJsonFile.open(QFile::ReadOnly))
{ {
qWarning() << "TelescopeControl: No telescopes loade d. Can't open for reading" << telescopesJsonPath; qWarning() << "TelescopeControl: No telescopes loade d. Can't open for reading" << QDir::toNativeSeparators(telescopesJsonPath);
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
else else
{ {
map = StelJsonParser::parse(&telescopesJsonFile).toM ap(); map = StelJsonParser::parse(&telescopesJsonFile).toM ap();
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
//File contains any telescopes? //File contains any telescopes?
skipping to change at line 762 skipping to change at line 763
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
QString version = map.value("version", "0.0.0").toString(); QString version = map.value("version", "0.0.0").toString();
if(version < QString(TELESCOPE_CONTROL_VERSION)) if(version < QString(TELESCOPE_CONTROL_VERSION))
{ {
QString newName = telescopesJsonPath + ".backup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); QString newName = telescopesJsonPath + ".backup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(telescopesJsonFile.rename(newName)) if(telescopesJsonFile.rename(newName))
{ {
qWarning() << "TelescopeControl: The existin g version of telescopes.json is obsolete. Backing it up as" << newName; qWarning() << "TelescopeControl: The existin g version of telescopes.json is obsolete. Backing it up as " << QDir::toNat iveSeparators(newName);
qWarning() << "TelescopeControl: A blank tel escopes.json file will have to be created."; qWarning() << "TelescopeControl: A blank tel escopes.json file will have to be created.";
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
else else
{ {
qWarning() << "TelescopeControl: The existin g version of telescopes.json is obsolete. Unable to rename."; qWarning() << "TelescopeControl: The existin g version of telescopes.json is obsolete. Unable to rename.";
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
skipping to change at line 1239 skipping to change at line 1240
if (telescopeServers.contains(serverName)) if (telescopeServers.contains(serverName))
{ {
QString serverExecutablePath; QString serverExecutablePath;
//Is the try/catch really necessary? //Is the try/catch really necessary?
try try
{ {
serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File); serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "TelescopeControl: Error starting telesc ope server: Can't find executable:" << serverExecutablePath; qDebug() << "TelescopeControl: Error starting telesc ope server: Can't find executable:" << QDir::toNativeSeparators(serverExecu tablePath);
return false; return false;
} }
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
QString serialPortName; QString serialPortName;
if(portSerial.right(portSerial.size() - SERIAL_PORT_PREFIX.s ize()).toInt() > 9) if(portSerial.right(portSerial.size() - SERIAL_PORT_PREFIX.s ize()).toInt() > 9)
serialPortName = "\\\\.\\" + portSerial;//"\\.\COMxx ", not sure if it will work serialPortName = "\\\\.\\" + portSerial;//"\\.\COMxx ", not sure if it will work
else else
serialPortName = portSerial; serialPortName = portSerial;
#else #else
QString serialPortName = portSerial; QString serialPortName = portSerial;
#endif //Q_OS_WIN32 #endif //Q_OS_WIN32
QStringList serverArguments; QStringList serverArguments;
serverArguments << QString::number(portTCP) << serialPortNam e; serverArguments << QString::number(portTCP) << serialPortNam e;
if(useTelescopeServerLogs) if(useTelescopeServerLogs)
serverArguments << QString(StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt"); serverArguments << QString(StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");
qDebug() << "TelescopeControl: Starting tellescope server at slot" << slotName << "with path" << serverExecutablePath << "and arguments " << serverArguments.join(" "); qDebug() << "TelescopeControl: Starting tellescope server at slot" << slotName << "with path" << QDir::toNativeSeparators(serverExecuta blePath) << "and arguments" << serverArguments.join(" ");
//Starting the new process //Starting the new process
telescopeServerProcess.insert(slotNumber, new QProcess()); telescopeServerProcess.insert(slotNumber, new QProcess());
//telescopeServerProcess[slotNumber]->setStandardOutputFile( StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");//I n case the server does not accept logfiles //telescopeServerProcess[slotNumber]->setStandardOutputFile( StelFileMgr::getUserDir() + "/log_TelescopeServer" + slotName + ".txt");//I n case the server does not accept logfiles
telescopeServerProcess[slotNumber]->start(serverExecutablePa th, serverArguments); telescopeServerProcess[slotNumber]->start(serverExecutablePa th, serverArguments);
//return telescopeServerProcess[slotNumber]->waitForStarted( ); //return telescopeServerProcess[slotNumber]->waitForStarted( );
//The server is supposed to start immediately //The server is supposed to start immediately
return true; return true;
} }
skipping to change at line 1386 skipping to change at line 1387
{ {
//qDebug() << "TelescopeControl: Loading device model descriptions.. ."; //qDebug() << "TelescopeControl: Loading device model descriptions.. .";
//Make sure that the device models file exists //Make sure that the device models file exists
bool useDefaultList = false; bool useDefaultList = false;
QString deviceModelsJsonPath = StelFileMgr::findFile("modules/Telesc opeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writa ble)) + "/device_models.json"; QString deviceModelsJsonPath = StelFileMgr::findFile("modules/Telesc opeControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writa ble)) + "/device_models.json";
if(!QFileInfo(deviceModelsJsonPath).exists()) if(!QFileInfo(deviceModelsJsonPath).exists())
{ {
if(!restoreDeviceModelsListTo(deviceModelsJsonPath)) if(!restoreDeviceModelsListTo(deviceModelsJsonPath))
{ {
qWarning() << "TelescopeControl: Unable to find" << deviceModelsJsonPath; qWarning() << "TelescopeControl: Unable to find " << QDir::toNativeSeparators(deviceModelsJsonPath);
useDefaultList = true; useDefaultList = true;
} }
} }
else else
{ {
QFile deviceModelsJsonFile(deviceModelsJsonPath); QFile deviceModelsJsonFile(deviceModelsJsonPath);
if(!deviceModelsJsonFile.open(QFile::ReadOnly)) if(!deviceModelsJsonFile.open(QFile::ReadOnly))
{ {
qWarning() << "TelescopeControl: Can't open for read ing" << deviceModelsJsonPath; qWarning() << "TelescopeControl: Can't open for read ing " << QDir::toNativeSeparators(deviceModelsJsonPath);
useDefaultList = true; useDefaultList = true;
} }
else else
{ {
//Check the version and move the old file if necessa ry //Check the version and move the old file if necessa ry
QVariantMap deviceModelsJsonMap; QVariantMap deviceModelsJsonMap;
deviceModelsJsonMap = StelJsonParser::parse(&deviceM odelsJsonFile).toMap(); deviceModelsJsonMap = StelJsonParser::parse(&deviceM odelsJsonFile).toMap();
QString version = deviceModelsJsonMap.value("version ", "0.0.0").toString(); QString version = deviceModelsJsonMap.value("version ", "0.0.0").toString();
if(version < QString(TELESCOPE_CONTROL_VERSION)) if(version < QString(TELESCOPE_CONTROL_VERSION))
{ {
deviceModelsJsonFile.close(); deviceModelsJsonFile.close();
QString newName = deviceModelsJsonPath + ".b ackup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); QString newName = deviceModelsJsonPath + ".b ackup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(deviceModelsJsonFile.rename(newName)) if(deviceModelsJsonFile.rename(newName))
{ {
qWarning() << "TelescopeControl: The existing version of device_models.json is obsolete. Backing it up as" << n ewName; qWarning() << "TelescopeControl: The existing version of device_models.json is obsolete. Backing it up as " << QDir::toNativeSeparators(newName);
if(!restoreDeviceModelsListTo(device ModelsJsonPath)) if(!restoreDeviceModelsListTo(device ModelsJsonPath))
{ {
useDefaultList = true; useDefaultList = true;
} }
} }
else else
{ {
qWarning() << "TelescopeControl: The existing version of device_models.json is obsolete. Unable to rename."; qWarning() << "TelescopeControl: The existing version of device_models.json is obsolete. Unable to rename.";
useDefaultList = true; useDefaultList = true;
} }
skipping to change at line 1553 skipping to change at line 1554
} }
return connectedClientsNames; return connectedClientsNames;
} }
bool TelescopeControl::restoreDeviceModelsListTo(QString deviceModelsListPa th) bool TelescopeControl::restoreDeviceModelsListTo(QString deviceModelsListPa th)
{ {
QFile defaultFile(":/telescopeControl/device_models.json"); QFile defaultFile(":/telescopeControl/device_models.json");
if (!defaultFile.copy(deviceModelsListPath)) if (!defaultFile.copy(deviceModelsListPath))
{ {
qWarning() << "TelescopeControl: Unable to copy the default device models list to" << deviceModelsListPath; qWarning() << "TelescopeControl: Unable to copy the default device models list to" << QDir::toNativeSeparators(deviceModelsListPath);
return false; return false;
} }
QFile newCopy(deviceModelsListPath); QFile newCopy(deviceModelsListPath);
newCopy.setPermissions(newCopy.permissions() | QFile::WriteOwner); newCopy.setPermissions(newCopy.permissions() | QFile::WriteOwner);
qDebug() << "TelescopeControl: The default device models list has be en copied to" << deviceModelsListPath; qDebug() << "TelescopeControl: The default device models list has be en copied to" << QDir::toNativeSeparators(deviceModelsListPath);
return true; return true;
} }
const QString& TelescopeControl::getServerExecutablesDirectoryPath() const QString& TelescopeControl::getServerExecutablesDirectoryPath()
{ {
return serverExecutablesDirectoryPath; return serverExecutablesDirectoryPath;
} }
bool TelescopeControl::setServerExecutablesDirectoryPath(const QString& new Path) bool TelescopeControl::setServerExecutablesDirectoryPath(const QString& new Path)
{ {
//TODO: Reuse code. //TODO: Reuse code.
QDir newServerDirectory(newPath); QDir newServerDirectory(newPath);
if(!newServerDirectory.exists()) if(!newServerDirectory.exists())
{ {
qWarning() << "TelescopeControl: Can't find such a directory :" << newPath; qWarning() << "TelescopeControl: Can't find such a directory : " << QDir::toNativeSeparators(newPath);
return false; return false;
} }
QList<QFileInfo> telescopeServerExecutables = newServerDirectory.ent ryInfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|Q Dir::CaseSensitive), QDir::Name); QList<QFileInfo> telescopeServerExecutables = newServerDirectory.ent ryInfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|Q Dir::CaseSensitive), QDir::Name);
if(telescopeServerExecutables.isEmpty()) if(telescopeServerExecutables.isEmpty())
{ {
qWarning() << "TelescopeControl: No telescope server executa bles found in" qWarning() << "TelescopeControl: No telescope server executa bles found in"
<< serverExecutable sDirectoryPath; << QDir::toNativeSe parators(serverExecutablesDirectoryPath);
return false; return false;
} }
//If everything is fine... //If everything is fine...
serverExecutablesDirectoryPath = newPath; serverExecutablesDirectoryPath = newPath;
stopAllTelescopes(); stopAllTelescopes();
loadDeviceModels(); loadDeviceModels();
return true; return true;
} }
skipping to change at line 1621 skipping to change at line 1622
telescopeServerLogFiles.insert(slot, new QFile()); telescopeServerLogFiles.insert(slot, new QFile());
telescopeServerLogStreams.insert(slot, new QTextStre am(telescopeServerLogFiles.value(slot))); telescopeServerLogStreams.insert(slot, new QTextStre am(telescopeServerLogFiles.value(slot)));
return; return;
} }
QString filePath = StelFileMgr::getUserDir() + "/log_Telesco peServer" + QString::number(slot) + ".txt"; QString filePath = StelFileMgr::getUserDir() + "/log_Telesco peServer" + QString::number(slot) + ".txt";
QFile* logFile = new QFile(filePath); QFile* logFile = new QFile(filePath);
if (!logFile->open(QFile::WriteOnly|QFile::Text|QFile::Trunc ate|QFile::Unbuffered)) if (!logFile->open(QFile::WriteOnly|QFile::Text|QFile::Trunc ate|QFile::Unbuffered))
{ {
qWarning() << "TelescopeControl: Unable to create a log file for slot" qWarning() << "TelescopeControl: Unable to create a log file for slot"
<< slot << ":" << filePath; << slot << ":" << QDir::toNativeSeparators(filePath);
telescopeServerLogFiles.insert(slot, logFile); telescopeServerLogFiles.insert(slot, logFile);
telescopeServerLogStreams.insert(slot, new QTextStre am(new QFile())); telescopeServerLogStreams.insert(slot, new QTextStre am(new QFile()));
} }
telescopeServerLogFiles.insert(slot, logFile); telescopeServerLogFiles.insert(slot, logFile);
QTextStream * logStream = new QTextStream(logFile); QTextStream * logStream = new QTextStream(logFile);
telescopeServerLogStreams.insert(slot, logStream); telescopeServerLogStreams.insert(slot, logStream);
} }
} }
 End of changes. 23 change blocks. 
26 lines changed or deleted 25 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/