TelescopeControl.cpp   TelescopeControl.cpp 
skipping to change at line 132 skipping to change at line 132
//Make sure that the module directory exists //Make sure that the module directory exists
QString moduleDirectoryPath = StelFileMgr::getUserDir() + "/ modules/TelescopeControl"; QString moduleDirectoryPath = StelFileMgr::getUserDir() + "/ modules/TelescopeControl";
if(!StelFileMgr::exists(moduleDirectoryPath)) if(!StelFileMgr::exists(moduleDirectoryPath))
StelFileMgr::mkDir(moduleDirectoryPath); StelFileMgr::mkDir(moduleDirectoryPath);
//Load the device models //Load the device models
loadDeviceModels(); loadDeviceModels();
if(deviceModels.isEmpty()) if(deviceModels.isEmpty())
{ {
qWarning() << "TelescopeControl: No device model des criptions have been loaded. Stellarium will not be able to control a telesc ope on its own, but it is still possible to do it through an external appli cation or to connect to a remote host."; qWarning() << "[TelescopeControl] No device model de scriptions have been loaded. Stellarium will not be able to control a teles cope on its own, but it is still possible to do it through an external appl ication or to connect to a remote host.";
} }
//Unload Stellarium's internal telescope control module //Unload Stellarium's internal telescope control module
//(not necessary since revision 6308; remains as an example) //(not necessary since revision 6308; remains as an example)
//StelApp::getInstance().getModuleMgr().unloadModule("Telesc opeMgr", false); //StelApp::getInstance().getModuleMgr().unloadModule("Telesc opeMgr", false);
/*If the alsoDelete parameter is set to true, Stellarium cra shes with a /*If the alsoDelete parameter is set to true, Stellarium cra shes with a
segmentation fault when an object is selected. TODO: Find out why. segmentation fault when an object is selected. TODO: Find out why.
unloadModule() didn't work prior to revision 5058: t he module unloaded unloadModule() didn't work prior to revision 5058: t he module unloaded
normally, but Stellarium crashed later with a segmen tation fault, normally, but Stellarium crashed later with a segmen tation fault,
because LandscapeMgr::getCallOrder() depended on the module's because LandscapeMgr::getCallOrder() depended on the module's
existence to return a value.*/ existence to return a value.*/
//Load and start all telescope clients //Load and start all telescope clients
loadTelescopes(); loadTelescopes();
//Load OpenGL textures //Load OpenGL textures
reticleTexture = StelApp::getInstance().getTextureManager(). createTexture(":/telescopeControl/telescope_reticle.png"); reticleTexture = StelApp::getInstance().getTextureManager(). createTexture(":/telescopeControl/telescope_reticle.png");
selectionTexture = StelApp::getInstance().getTextureManager( ).createTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png" ); selectionTexture = StelApp::getInstance().getTextureManager( ).createTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png" );
QSignalMapper* slewObj = new QSignalMapper(this);
QSignalMapper* slewDir = new QSignalMapper(this);
//Create telescope key bindings //Create telescope key bindings
/* StelAction-s with these key bindings existed in Stellariu m prior to /* StelAction-s with these key bindings existed in Stellariu m prior to
revision 6311. Any future backports should account f or that. */ revision 6311. Any future backports should account f or that. */
QString section = N_("Telescope Control");
for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++) for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++)
{ {
// "Slew to object" commands // "Slew to object" commands
QString name = moveToSelectedActionId.arg(i); QString name = moveToSelectedActionId.arg(i);
QString shortcut = QString("Ctrl+%1").arg(i); QString shortcut = QString("Ctrl+%1").arg(i);
QString text; QString text;
text = q_("Move telescope #%1 to selected object").a rg(i); text = q_("Move telescope #%1 to selected object").a rg(i);
addAction(name, N_("Telescope Control"), text, "slew StelAction* actionSlewObj = addAction(name, section,
TelescopeToSelectedObject()", shortcut); text, slewObj, "map()", shortcut);
slewObj->setMapping(actionSlewObj, i);
// "Slew to the center of the screen" commands // "Slew to the center of the screen" commands
name = moveToCenterActionId.arg(i); name = moveToCenterActionId.arg(i);
shortcut = QString("Alt+%1").arg(i); shortcut = QString("Alt+%1").arg(i);
text = q_("Move telescope #%1 to the point currently in the center of the screen").arg(i); text = q_("Move telescope #%1 to the point currently in the center of the screen").arg(i);
addAction(name, N_("Telescope Control"), text, "slew StelAction* actionSlewDir = addAction(name, section,
TelescopeToViewDirection()", shortcut); text, slewDir, "map()", shortcut);
slewDir->setMapping(actionSlewDir, i);
} }
connect(slewObj,SIGNAL(mapped(int)),this,SLOT(slewTelescopeT
oSelectedObject(int)));
connect(slewDir,SIGNAL(mapped(int)),this,SLOT(slewTelescopeT
oViewDirection(int)));
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
this, SLOT(translateActionDescriptions())); this, SLOT(translateActionDescriptions()));
//Create and initialize dialog windows //Create and initialize dialog windows
telescopeDialog = new TelescopeDialog(); telescopeDialog = new TelescopeDialog();
slewDialog = new SlewDialog(); slewDialog = new SlewDialog();
addAction("actionShow_Slew_Window", N_("Telescope Control"), N_("Move a telescope to a given set of coordinates"), slewDialog, "visible ", "Ctrl+0"); addAction("actionShow_Slew_Window", N_("Telescope Control"), N_("Move a telescope to a given set of coordinates"), slewDialog, "visible ", "Ctrl+0");
//Create toolbar button //Create toolbar button
skipping to change at line 193 skipping to change at line 201
toolbarButton = new StelButton(NULL, toolbarButton = new StelButton(NULL,
QPixmap(":/telescopeC ontrol/button_Slew_Dialog_on.png"), QPixmap(":/telescopeC ontrol/button_Slew_Dialog_on.png"),
QPixmap(":/telescopeC ontrol/button_Slew_Dialog_off.png"), QPixmap(":/telescopeC ontrol/button_Slew_Dialog_off.png"),
QPixmap(":/graphicGui /glow32x32.png"), QPixmap(":/graphicGui /glow32x32.png"),
"actionShow_Slew_Wind ow"); "actionShow_Slew_Wind ow");
gui->getButtonBar()->addButton(toolbarButton, "065-p luginsGroup"); gui->getButtonBar()->addButton(toolbarButton, "065-p luginsGroup");
} }
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "TelescopeControl::init() error: " << e.what() ; qWarning() << "[TelescopeControl] init() error: " << e.what( );
return; return;
} }
GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this); GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
//Initialize style, as it is not called at startup:
//(necessary to initialize the reticle/label/circle colors)
setStelStyle(StelApp::getInstance().getCurrentStelStyle());
connect(&StelApp::getInstance(), SIGNAL(colorSchemeChanged(const QSt
ring&)), this, SLOT(setStelStyle(const QString&)));
} }
void TelescopeControl::translateActionDescriptions() void TelescopeControl::translateActionDescriptions()
{ {
StelActionMgr* actionMgr = StelApp::getInstance().getStelActionManag er(); StelActionMgr* actionMgr = StelApp::getInstance().getStelActionManag er();
for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++) for (int i = MIN_SLOT_NUMBER; i <= MAX_SLOT_NUMBER; i++)
{ {
QString name; QString name;
QString description; QString description;
skipping to change at line 240 skipping to change at line 243
while(iterator != telescopeServerProcess.constEnd()) while(iterator != telescopeServerProcess.constEnd())
{ {
int slotNumber = iterator.key(); int slotNumber = iterator.key();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
telescopeServerProcess[slotNumber]->close(); telescopeServerProcess[slotNumber]->close();
#else #else
telescopeServerProcess[slotNumber]->terminate(); telescopeServerProcess[slotNumber]->terminate();
#endif #endif
telescopeServerProcess[slotNumber]->waitForFinished(); telescopeServerProcess[slotNumber]->waitForFinished();
delete telescopeServerProcess[slotNumber]; delete telescopeServerProcess[slotNumber];
qDebug() << "TelescopeControl::deinit(): Server process at s lot" << slotNumber << "terminated successfully."; qDebug() << "[TelescopeControl] deinit(): Server process at slot" << slotNumber << "terminated successfully.";
++iterator; ++iterator;
} }
//TODO: Decide if it should be saved on change //TODO: Decide if it should be saved on change
//Save the configuration on exit //Save the configuration on exit
saveConfiguration(); saveConfiguration();
} }
void TelescopeControl::update(double deltaTime) void TelescopeControl::update(double deltaTime)
skipping to change at line 310 skipping to change at line 313
reticleTexture->bind(); reticleTexture->bind();
} }
} }
} }
} }
if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if(GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(prj, core, sPainter); drawPointer(prj, core, sPainter);
} }
void TelescopeControl::setStelStyle(const QString& section)
{
if (section == "night_color")
{
setLabelColor(labelNightColor);
setReticleColor(reticleNightColor);
setCircleColor(circleNightColor);
}
else
{
setLabelColor(labelNormalColor);
setReticleColor(reticleNormalColor);
setCircleColor(circleNormalColor);
}
telescopeDialog->updateStyle();
}
double TelescopeControl::getCallOrder(StelModuleActionName actionName) cons t double TelescopeControl::getCallOrder(StelModuleActionName actionName) cons t
{ {
//TODO: Remove magic number (call order offset) //TODO: Remove magic number (call order offset)
if (actionName == StelModule::ActionDraw) if (actionName == StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName) + 2.; return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName) + 2.;
return 0.; return 0.;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Methods inherited from the StelObjectModule class // Methods inherited from the StelObjectModule class
skipping to change at line 377 skipping to change at line 362
StelObjectP TelescopeControl::searchByName(const QString &name) const StelObjectP TelescopeControl::searchByName(const QString &name) const
{ {
foreach (const TelescopeClientP& telescope, telescopeClients) foreach (const TelescopeClientP& telescope, telescopeClients)
{ {
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, bool useStartOfWords) const
{
QStringList result;
if (maxNbItem==0)
return result;
QString tn;
bool find;
foreach (const TelescopeClientP& telescope, telescopeClients)
{
tn = telescope->getNameI18n();
find = false;
if (useStartOfWords)
{
if (objPrefix.toUpper()==tn.mid(0, objPrefix.size())
.toUpper())
find = true;
}
else
{
if (tn.contains(objPrefix, Qt::CaseInsensitive))
find = true;
}
if (find)
{
result << tn;
}
}
result.sort();
if (result.size()>maxNbItem)
{
result.erase(result.begin() + maxNbItem, result.end());
}
return result;
}
QStringList TelescopeControl::listMatchingObjects(const QString& objPrefix,
int maxNbItem, bool useStartOfWords) const
{
QStringList result;
if (maxNbItem==0)
return result;
QString tn;
bool find;
foreach (const TelescopeClientP& telescope, telescopeClients)
{
tn = telescope->getEnglishName();
find = false;
if (useStartOfWords)
{
if (objPrefix.toUpper()==tn.mid(0, objPrefix.size())
.toUpper())
find = true;
}
else
{
if (tn.contains(objPrefix, Qt::CaseInsensitive))
find = true;
}
if (find)
{
result << tn;
}
}
result.sort();
if (result.size()>maxNbItem)
{
result.erase(result.begin() + maxNbItem, result.end());
}
return result;
}
bool TelescopeControl::configureGui(bool show) bool TelescopeControl::configureGui(bool show)
{ {
if(show) if(show)
{ {
telescopeDialog->setVisible(true); telescopeDialog->setVisible(true);
} }
return true; return true;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Misc methods (from TelescopeMgr; TODO: Better categorization) // Misc methods (from TelescopeMgr; TODO: Better categorization)
void TelescopeControl::setFontSize(int fontSize) void TelescopeControl::setFontSize(int fontSize)
{ {
labelFont.setPixelSize(fontSize); labelFont.setPixelSize(fontSize);
} }
void TelescopeControl::slewTelescopeToSelectedObject() void TelescopeControl::slewTelescopeToSelectedObject(const int idx)
{ {
// Find out for which telescope is the command
if (sender() == NULL)
return;
int slotNumber = sender()->objectName().right(1).toInt();
// Find out the coordinates of the target // Find out the coordinates of the target
StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr); StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
if (omgr->getSelectedObject().isEmpty()) if (omgr->getSelectedObject().isEmpty())
return; return;
StelObjectP selectObject = omgr->getSelectedObject().at(0); StelObjectP selectObject = omgr->getSelectedObject().at(0);
if (!selectObject) // should never happen if (!selectObject) // should never happen
return; return;
Vec3d objectPosition = selectObject->getJ2000EquatorialPos(StelApp:: getInstance().getCore()); Vec3d objectPosition = selectObject->getJ2000EquatorialPos(StelApp:: getInstance().getCore());
telescopeGoto(slotNumber, objectPosition); telescopeGoto(idx, objectPosition);
} }
void TelescopeControl::slewTelescopeToViewDirection() void TelescopeControl::slewTelescopeToViewDirection(const int idx)
{ {
// Find out for which telescope is the command
if (sender() == NULL)
return;
// XXX: we could use a QSignalMapper instead of this trick.
int slotNumber = sender()->objectName().right(1).toInt();
// Find out the coordinates of the target // Find out the coordinates of the target
Vec3d centerPosition = GETSTELMODULE(StelMovementMgr)->getViewDirect ionJ2000(); Vec3d centerPosition = GETSTELMODULE(StelMovementMgr)->getViewDirect ionJ2000();
telescopeGoto(slotNumber, centerPosition); telescopeGoto(idx, centerPosition);
} }
void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelCor e* core, StelPainter& sPainter) void TelescopeControl::drawPointer(const StelProjectorP& prj, const StelCor e* core, StelPainter& sPainter)
{ {
#ifndef COMPATIBILITY_001002 #ifndef COMPATIBILITY_001002
//Leaves this whole routine empty if this is the backport version. //Leaves this whole routine empty if this is the backport version.
//Otherwise, there will be two concentric selection markers drawn ar ound the telescope pointer. //Otherwise, there will be two concentric selection markers drawn ar ound the telescope pointer.
//In 0.10.3, the plug-in unloads the module that draws the surplus m arker. //In 0.10.3, the plug-in unloads the module that draws the surplus m arker.
const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope"); const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)- >getSelectedObject("Telescope");
if (!newSelected.empty()) if (!newSelected.empty())
skipping to change at line 591 skipping to change at line 495
//TODO: I don't like how this turned out //TODO: I don't like how this turned out
if(serverExecutablesDirectoryPath.isEmpty()) if(serverExecutablesDirectoryPath.isEmpty())
return; return;
//As StelFileMgr is quite limited, use Qt's handy methods (I love Qt !) //As StelFileMgr is quite limited, use Qt's handy methods (I love Qt !)
//Get all executable files with names beginning with "TelescopeServe r" in this directory //Get all executable files with names beginning with "TelescopeServe r" in this directory
QDir serverDirectory(serverExecutablesDirectoryPath); QDir serverDirectory(serverExecutablesDirectoryPath);
if(!serverDirectory.exists()) if(!serverDirectory.exists())
{ {
qWarning() << "TelescopeControl: No telescope server directo ry has been found."; qWarning() << "[TelescopeControl] No telescope server direct ory has been found.";
return; return;
} }
QList<QFileInfo> telescopeServerExecutables = serverDirectory.entryI nfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|QDir ::CaseSensitive), QDir::Name); QList<QFileInfo> telescopeServerExecutables = serverDirectory.entryI nfoList(QStringList("TelescopeServer*"), (QDir::Files|QDir::Executable|QDir ::CaseSensitive), QDir::Name);
if(!telescopeServerExecutables.isEmpty()) if(!telescopeServerExecutables.isEmpty())
{ {
foreach(QFileInfo telescopeServerExecutable, telescopeServer Executables) foreach(QFileInfo telescopeServerExecutable, telescopeServer Executables)
telescopeServers.append(telescopeServerExecutable.ba seName());//This strips the ".exe" suffix on Windows telescopeServers.append(telescopeServerExecutable.ba seName());//This strips the ".exe" suffix on Windows
} }
else else
{ {
qWarning() << "TelescopeControl: No telescope server executa qWarning() << "[TelescopeControl] No telescope server execut
bles found in" ables found in" << serverExecutablesDirectoryPath;
<< serverExecutable
sDirectoryPath;
} }
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Methods for reading from and writing to the configuration file // Methods for reading from and writing to the configuration file
void TelescopeControl::loadConfiguration() void TelescopeControl::loadConfiguration()
{ {
QSettings* settings = StelApp::getInstance().getSettings(); QSettings* settings = StelApp::getInstance().getSettings();
Q_ASSERT(settings); Q_ASSERT(settings);
skipping to change at line 630 skipping to change at line 533
setFlagTelescopeCircles(settings->value("flag_telescope_circles", tr ue).toBool()); setFlagTelescopeCircles(settings->value("flag_telescope_circles", tr ue).toBool());
//Load font size //Load font size
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
setFontSize(settings->value("telescope_labels_font_size", 13).toInt( )); //Windows Qt bug workaround setFontSize(settings->value("telescope_labels_font_size", 13).toInt( )); //Windows Qt bug workaround
#else #else
setFontSize(settings->value("telescope_labels_font_size", 12).toInt( )); setFontSize(settings->value("telescope_labels_font_size", 12).toInt( ));
#endif #endif
//Load colours //Load colours
reticleNormalColor = StelUtils::strToVec3f(settings->value("color_te setReticleColor(StelUtils::strToVec3f(settings->value("color_telesco
lescope_reticles", "0.6,0.4,0").toString()); pe_reticles", "0.6,0.4,0").toString()));
reticleNightColor = StelUtils::strToVec3f(settings->value("night_col setLabelColor(StelUtils::strToVec3f(settings->value("color_telescope
or_telescope_reticles", "0.5,0,0").toString()); _labels", "0.6,0.4,0").toString()));
labelNormalColor = StelUtils::strToVec3f(settings->value("color_tele setCircleColor(StelUtils::strToVec3f(settings->value("color_telescop
scope_labels", "0.6,0.4,0").toString()); e_circles", "0.6,0.4,0").toString()));
labelNightColor = StelUtils::strToVec3f(settings->value("night_color
_telescope_labels", "0.5,0,0").toString());
circleNormalColor = StelUtils::strToVec3f(settings->value("color_tel
escope_circles", "0.6,0.4,0").toString());
circleNightColor = StelUtils::strToVec3f(settings->value("night_colo
r_telescope_circles", "0.5,0,0").toString());
//Load server executables flag and directory //Load server executables flag and directory
useServerExecutables = settings->value("flag_use_server_executables" , false).toBool(); useServerExecutables = settings->value("flag_use_server_executables" , false).toBool();
serverExecutablesDirectoryPath = settings->value("server_executables _path").toString(); serverExecutablesDirectoryPath = settings->value("server_executables _path").toString();
//If no directory is specified in the configuration file, try to fin d the default one //If no directory is specified in the configuration file, try to fin d the default one
if(serverExecutablesDirectoryPath.isEmpty() || !QDir(serverExecutabl esDirectoryPath).exists()) if(serverExecutablesDirectoryPath.isEmpty() || !QDir(serverExecutabl esDirectoryPath).exists())
{ {
//Find out if the default server directory exists //Find out if the default server directory exists
QString serverDirectoryPath = StelFileMgr::findFile("servers ", StelFileMgr::Directory); QString serverDirectoryPath = StelFileMgr::findFile("servers ", StelFileMgr::Directory);
skipping to change at line 677 skipping to change at line 577
Q_ASSERT(settings); Q_ASSERT(settings);
settings->beginGroup("TelescopeControl"); settings->beginGroup("TelescopeControl");
//Save display flags //Save display flags
settings->setValue("flag_telescope_reticles", getFlagTelescopeReticl es()); settings->setValue("flag_telescope_reticles", getFlagTelescopeReticl es());
settings->setValue("flag_telescope_labels", getFlagTelescopeLabels() ); settings->setValue("flag_telescope_labels", getFlagTelescopeLabels() );
settings->setValue("flag_telescope_circles", getFlagTelescopeCircles ()); settings->setValue("flag_telescope_circles", getFlagTelescopeCircles ());
//Save colours //Save colours
settings->setValue("color_telescope_reticles", QString("%1,%2,%3").a settings->setValue("color_telescope_reticles", StelUtils::vec3fToHtm
rg(reticleNormalColor[0], 0, 'f', 2).arg(reticleNormalColor[1], 0, 'f', 2). lColor(getReticleColor()));
arg(reticleNormalColor[2], 0, 'f', 2)); settings->setValue("color_telescope_labels", StelUtils::vec3fToHtmlC
settings->setValue("night_color_telescope_reticles", QString("%1,%2, olor(getLabelColor()));
%3").arg(reticleNightColor[0], 0, 'f', 2).arg(reticleNightColor[1], 0, 'f', settings->setValue("color_telescope_circles", StelUtils::vec3fToHtml
2).arg(reticleNightColor[2], 0, 'f', 2)); Color(getCircleColor()));
settings->setValue("color_telescope_labels", QString("%1,%2,%3").arg
(labelNormalColor[0], 0, 'f', 2).arg(labelNormalColor[1], 0, 'f', 2).arg(la
belNormalColor[2], 0, 'f', 2));
settings->setValue("night_color_telescope_labels", QString("%1,%2,%3
").arg(labelNightColor[0], 0, 'f', 2).arg(labelNightColor[1], 0, 'f', 2).ar
g(labelNightColor[2], 0, 'f', 2));
settings->setValue("color_telescope_circles", QString("%1,%2,%3").ar
g(circleNormalColor[0], 0, 'f', 2).arg(circleNormalColor[1], 0, 'f', 2).arg
(circleNormalColor[2], 0, 'f', 2));
settings->setValue("night_color_telescope_circles", QString("%1,%2,%
3").arg(circleNightColor[0], 0, 'f', 2).arg(circleNightColor[1], 0, 'f', 2)
.arg(circleNightColor[2], 0, 'f', 2));
//Save telescope server executables flag and directory //Save telescope server executables flag and directory
settings->setValue("flag_use_server_executables", useServerExecutabl es); settings->setValue("flag_use_server_executables", useServerExecutabl es);
if(useServerExecutables) if(useServerExecutables)
{ {
settings->setValue("server_executables_path", serverExecutab lesDirectoryPath); settings->setValue("server_executables_path", serverExecutab lesDirectoryPath);
} }
else else
{ {
settings->remove("server_executables_path"); settings->remove("server_executables_path");
} }
//Save logging flag //Save logging flag
settings->setValue("flag_enable_telescope_logs", useTelescopeServerL ogs); settings->setValue("flag_enable_telescope_logs", useTelescopeServerL ogs);
settings->endGroup(); settings->endGroup();
// Remove outdated config items
if (settings->contains("TelescopeControl/night_color_telescope_retic
les"))
settings->remove("TelescopeControl/night_color_telescope_ret
icles");
if (settings->contains("TelescopeControl/night_color_telescope_label
s"))
settings->remove("TelescopeControl/night_color_telescope_lab
els");
if (settings->contains("TelescopeControl/night_color_telescope_circl
es"))
settings->remove("TelescopeControl/night_color_telescope_cir
cles");
} }
void TelescopeControl::saveTelescopes() void TelescopeControl::saveTelescopes()
{ {
//Open/create the JSON file //Open/create the JSON file
QString telescopesJsonPath = StelFileMgr::findFile("modules/Telescop eControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writabl e)) + "/telescopes.json"; QString telescopesJsonPath = StelFileMgr::findFile("modules/Telescop eControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writabl e)) + "/telescopes.json";
if (telescopesJsonPath.isEmpty()) if (telescopesJsonPath.isEmpty())
{ {
qWarning() << "TelescopeControl: Error saving telescopes"; qWarning() << "[TelescopeControl] Error saving telescopes";
return; return;
} }
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:" << QDir::toNativeSeparators(telescop esJsonPath); qWarning() << "[TelescopeControl] Telescopes can not be save d. A file can not be open for writing:" << QDir::toNativeSeparators(telesco pesJsonPath);
return; return;
} }
//Add the version: //Add the version:
telescopeDescriptions.insert("version", QString(TELESCOPE_CONTROL_VE RSION)); telescopeDescriptions.insert("version", QString(TELESCOPE_CONTROL_VE RSION));
//Convert the tree to JSON //Convert the tree to JSON
StelJsonParser::write(telescopeDescriptions, &telescopesJsonFile); StelJsonParser::write(telescopeDescriptions, &telescopesJsonFile);
telescopesJsonFile.flush();//Is this necessary? telescopesJsonFile.flush();//Is this necessary?
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
void TelescopeControl::loadTelescopes() void TelescopeControl::loadTelescopes()
{ {
QVariantMap result; QVariantMap result;
QString telescopesJsonPath = StelFileMgr::findFile("modules/Telescop eControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writabl e)) + "/telescopes.json"; QString telescopesJsonPath = StelFileMgr::findFile("modules/Telescop eControl", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writabl e)) + "/telescopes.json";
if (telescopesJsonPath.isEmpty()) if (telescopesJsonPath.isEmpty())
{ {
qWarning() << "TelescopeControl: Error loading telescopes"; qWarning() << "[TelescopeControl] Error loading telescopes";
return; return;
} }
if(!QFileInfo(telescopesJsonPath).exists()) if(!QFileInfo(telescopesJsonPath).exists())
{ {
qWarning() << "TelescopeControl::loadTelescopes(): No telesc opes loaded. File is missing:" << QDir::toNativeSeparators(telescopesJsonPa th); qWarning() << "[TelescopeControl] loadTelescopes(): No teles copes loaded. File is missing:" << QDir::toNativeSeparators(telescopesJsonP ath);
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 loaded. Can't open for reading" << QDir::toNativeSeparators(telescopesJsonPath); qWarning() << "[TelescopeControl] No telescopes loaded. Can' t open for reading" << QDir::toNativeSeparators(telescopesJsonPath);
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
else else
{ {
map = StelJsonParser::parse(&telescopesJsonFile).toMap(); map = StelJsonParser::parse(&telescopesJsonFile).toMap();
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
//File contains any telescopes? //File contains any telescopes?
if(map.isEmpty()) if(map.isEmpty())
{ {
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(StelUtils::compareVersions(version, QString(TELESCOPE_CONTROL_VER SION))!=0)
{ {
QString newName = telescopesJsonPath + ".backup." + QDateTim e::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); QString newName = telescopesJsonPath + ".backup." + QDateTim e::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(telescopesJsonFile.rename(newName)) if(telescopesJsonFile.rename(newName))
{ {
qWarning() << "TelescopeControl: The existing versio qWarning() << "[TelescopeControl] The existing versi
n of telescopes.json is obsolete. Backing it up as " << QDir::toNativeSepar on of telescopes.json is obsolete. Backing it up as" << QDir::toNativeSepar
ators(newName); ators(newName);
qWarning() << "TelescopeControl: A blank telescopes. qWarning() << "[TelescopeControl] A blank telescopes
json file will have to be created."; .json file will have to be created.";
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
else else
{ {
qWarning() << "TelescopeControl: The existing versio n of telescopes.json is obsolete. Unable to rename."; qWarning() << "[TelescopeControl] The existing versi on of telescopes.json is obsolete. Unable to rename.";
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
} }
map.remove("version");//Otherwise it will try to read it as a telesc ope map.remove("version"); // Otherwise it will try to read it as a tele scope
//Make sure that there are no telescope clients yet //Make sure that there are no telescope clients yet
deleteAllTelescopes(); deleteAllTelescopes();
//Read telescopes, if any //Read telescopes, if any
int telescopesCount = 0; int telescopesCount = 0;
QMapIterator<QString, QVariant> node(map); QMapIterator<QString, QVariant> node(map);
bool ok; bool ok;
while(node.hasNext()) while(node.hasNext())
{ {
node.next(); node.next();
QString key = node.key(); QString key = node.key();
//If this is not a valid slot number, remove the node //If this is not a valid slot number, remove the node
int slot = key.toInt(&ok); int slot = key.toInt(&ok);
if(!ok || !isValidSlotNumber(slot)) if(!ok || !isValidSlotNumber(slot))
{ {
qDebug() << "TelescopeControl::loadTelescopes(): Del eted node unrecogised as slot:" << key; qDebug() << "[TelescopeControl] loadTelescopes(): De leted node unrecogised as slot:" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
QVariantMap telescope = node.value().toMap(); QVariantMap telescope = node.value().toMap();
//Essential parameters: Name, connection type, equinox //Essential parameters: Name, connection type, equinox
//Validation: Name //Validation: Name
QString name = telescope.value("name").toString(); QString name = telescope.value("name").toString();
if(name.isEmpty()) if(name.isEmpty())
{ {
qDebug() << "TelescopeControl: Unable to load telesc ope: No name specified at slot" << key; qDebug() << "[TelescopeControl] Unable to load teles cope: No name specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
//Validation: Connection //Validation: Connection
QString connection = telescope.value("connection").toString( ); QString connection = telescope.value("connection").toString( );
if(connection.isEmpty() || !connectionTypeNames.values().con tains(connection)) if(connection.isEmpty() || !connectionTypeNames.values().con tains(connection))
{ {
qDebug() << "TelescopeControl: Unable to load telesc ope: No valid connection type at slot" << key; qDebug() << "[TelescopeControl] Unable to load teles cope: No valid connection type at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
ConnectionType connectionType = connectionTypeNames.key(conn ection); ConnectionType connectionType = connectionTypeNames.key(conn ection);
QString equinox = telescope.value("equinox", "J2000").toStri ng(); QString equinox = telescope.value("equinox", "J2000").toStri ng();
if (equinox != "J2000" && equinox != "JNow") if (equinox != "J2000" && equinox != "JNow")
{ {
qDebug() << "TelescopeControl: Unable to load telesc ope: Invalid equinox value at slot" << key; qDebug() << "[TelescopeControl] Unable to load teles cope: Invalid equinox value at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
QString hostName("localhost"); QString hostName("localhost");
int portTCP = 0; int portTCP = 0;
int delay = 0; int delay = 0;
QString deviceModelName; QString deviceModelName;
QString portSerial; QString portSerial;
if (connectionType == ConnectionInternal) if (connectionType == ConnectionInternal)
{ {
//Serial port and device model //Serial port and device model
deviceModelName = telescope.value("device_model").to String(); deviceModelName = telescope.value("device_model").to String();
portSerial = telescope.value("serial_port").toString (); portSerial = telescope.value("serial_port").toString ();
if(deviceModelName.isEmpty()) if(deviceModelName.isEmpty())
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No device model specified at slot" << key; qDebug() << "[TelescopeControl] Unable to lo ad telescope: No device model specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
//Do we have this server? //Do we have this server?
if(!deviceModels.contains(deviceModelName)) if(!deviceModels.contains(deviceModelName))
{ {
qWarning() << "TelescopeControl: Unable to l qWarning() << "[TelescopeControl] Unable to
oad telescope at slot" << slot << "because the specified device model is mi load telescope at slot" << slot
ssing:" << deviceModelName; << "because the specified device
model is missing:" << deviceModelName;
map.remove(key); map.remove(key);
continue; continue;
} }
if(portSerial.isEmpty()) if(portSerial.isEmpty())
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No valid serial port specified at slot" << key; qDebug() << "[TelescopeControl] Unable to lo ad telescope: No valid serial port specified at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
} }
if (connectionType == ConnectionRemote) if (connectionType == ConnectionRemote)
{ {
//Validation: Host name //Validation: Host name
hostName = telescope.value("host_name").toString(); hostName = telescope.value("host_name").toString();
if(hostName.isEmpty()) if(hostName.isEmpty())
{ {
qDebug() << "TelescopeControl::loadTelescope s(): No host name at slot" << key; qDebug() << "[TelescopeControl] loadTelescop es(): No host name at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
} }
if (connectionType != ConnectionVirtual) if (connectionType != ConnectionVirtual)
{ {
//Validation: TCP port //Validation: TCP port
portTCP = telescope.value("tcp_port").toInt(); portTCP = telescope.value("tcp_port").toInt();
if(!telescope.contains("tcp_port") || !isValidPort(p ortTCP)) if(!telescope.contains("tcp_port") || !isValidPort(p ortTCP))
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No valid TCP port at slot" << key; qDebug() << "[TelescopeControl] Unable to lo ad telescope: No valid TCP port at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
//Validation: Delay //Validation: Delay
delay = telescope.value("delay", 0).toInt(); delay = telescope.value("delay", 0).toInt();
if(!isValidDelay(delay)) if(!isValidDelay(delay))
{ {
qDebug() << "TelescopeControl: Unable to loa d telescope: No valid delay at slot" << key; qDebug() << "[TelescopeControl] Unable to lo ad telescope: No valid delay at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
} }
//Connect at startup //Connect at startup
bool connectAtStartup = telescope.value("connect_at_startup" , false).toBool(); bool connectAtStartup = telescope.value("connect_at_startup" , false).toBool();
//Validation: FOV circles //Validation: FOV circles
QVariantList parsedJsonCircles = telescope.value("circles"). toList(); QVariantList parsedJsonCircles = telescope.value("circles"). toList();
skipping to change at line 948 skipping to change at line 856
{ {
//Use a sever if necessary //Use a sever if necessary
if(deviceModels[deviceModelName].useExecutab le) if(deviceModels[deviceModelName].useExecutab le)
{ {
if(startClientAtSlot(slot, connectio nType, name, equinox, hostName, portTCP, delay, internalCircles)) if(startClientAtSlot(slot, connectio nType, name, equinox, hostName, portTCP, delay, internalCircles))
{ {
if(!startServerAtSlot(slot, deviceModelName, portTCP, portSerial)) if(!startServerAtSlot(slot, deviceModelName, portTCP, portSerial))
{ {
stopClientAtSlot(slo t); stopClientAtSlot(slo t);
qDebug() << "Telesco peControl: Unable to launch a telescope server at slot" << slot; qDebug() << "[Telesc opeControl] Unable to launch a telescope server at slot" << slot;
} }
} }
else else
{ {
qDebug() << "TelescopeContro l: Unable to create a telescope client at slot" << slot; qDebug() << "[TelescopeContr ol] Unable to create a telescope client at slot" << slot;
//Unnecessary due to if-else construction; //Unnecessary due to if-else construction;
//also, causes bug #608533 //also, causes bug #608533
//continue; //continue;
} }
} }
else else
{ {
addLogAtSlot(slot); addLogAtSlot(slot);
logAtSlot(slot); logAtSlot(slot);
if(!startClientAtSlot(slot, connecti onType, name, equinox, QString(), 0, delay, internalCircles, deviceModelNam e, portSerial)) if(!startClientAtSlot(slot, connecti onType, name, equinox, QString(), 0, delay, internalCircles, deviceModelNam e, portSerial))
{ {
qDebug() << "TelescopeContro l: Unable to create a telescope client at slot" << slot; qDebug() << "[TelescopeContr ol] Unable to create a telescope client at slot" << slot;
//Unnecessary due to if-else construction; //Unnecessary due to if-else construction;
//also, causes bug #608533 //also, causes bug #608533
//continue; //continue;
} }
} }
} }
else else
{ {
if(!startClientAtSlot(slot, connectionType, name, equinox, hostName, portTCP, delay, internalCircles)) if(!startClientAtSlot(slot, connectionType, name, equinox, hostName, portTCP, delay, internalCircles))
{ {
qDebug() << "TelescopeControl: Unabl e to create a telescope client at slot" << slot; qDebug() << "[TelescopeControl] Unab le to create a telescope client at slot" << slot;
//Unnecessary due to if-else constru ction; //Unnecessary due to if-else constru ction;
//also, causes bug #608533 //also, causes bug #608533
//continue; //continue;
} }
} }
} }
//If this line is reached, the telescope at this slot has be en loaded successfully //If this line is reached, the telescope at this slot has be en loaded successfully
telescopesCount++; telescopesCount++;
} }
if(telescopesCount > 0) if(telescopesCount > 0)
{ {
result = map; result = map;
qDebug() << "TelescopeControl: Loaded successfully" << teles qDebug() << "[TelescopeControl] Loaded successfully" << tele
copesCount << "telescopes."; scopesCount
<< "telescopes.";
} }
telescopeDescriptions = result; telescopeDescriptions = result;
} }
bool TelescopeControl::addTelescopeAtSlot(int slot, ConnectionType connecti onType, QString name, QString equinox, QString host, int portTCP, int delay , bool connectAtStartup, QList<double> circles, QString deviceModelName, QS tring portSerial) bool TelescopeControl::addTelescopeAtSlot(int slot, ConnectionType connecti onType, QString name, QString equinox, QString host, int portTCP, int delay , bool connectAtStartup, QList<double> circles, QString deviceModelName, QS tring portSerial)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot) || name.isEmpty() || equinox.isEmpty() | | connectionType <= ConnectionNA || connectionType >= ConnectionCount) if(!isValidSlotNumber(slot) || name.isEmpty() || equinox.isEmpty() | | connectionType <= ConnectionNA || connectionType >= ConnectionCount)
return false; return false;
skipping to change at line 1239 skipping to change at line 1148
} }
QString slotName = QString::number(slotNumber); QString slotName = QString::number(slotNumber);
QString serverName = deviceModels.value(deviceModelName).server; QString serverName = deviceModels.value(deviceModelName).server;
if (telescopeServers.contains(serverName)) if (telescopeServers.contains(serverName))
{ {
QString serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File); QString serverExecutablePath = StelFileMgr::findFile(serverE xecutablesDirectoryPath + TELESCOPE_SERVER_PATH.arg(serverName), StelFileMg r::File);
if (serverExecutablePath.isEmpty()) if (serverExecutablePath.isEmpty())
{ {
qDebug() << "TelescopeControl: Error starting telesc ope server: Can't find executable:" << QDir::toNativeSeparators(serverExecu tablePath); qDebug() << "[TelescopeControl] Error starting teles cope server: Can't find executable:" << QDi r::toNativeSeparators(serverExecutablePath);
return false; return false;
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString serialPortName = "\\\\.\\" + portSerial; QString serialPortName = "\\\\.\\" + portSerial;
#else #else
QString serialPortName = portSerial; QString serialPortName = portSerial;
#endif //Q_OS_WIN #endif //Q_OS_WIN
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 qDebug() << "[TelescopeControl] Starting tellescope server a
slot" << slotName << "with path" << QDir::toNativeSeparators(serverExecuta t slot" << slotName
blePath) << "and arguments" << serverArguments.join(" "); << "with path" << QDir::toNativeSeparators(serverE
xecutablePath)
<< "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;
} }
else else
qDebug() << "TelescopeControl: Error starting telescope serv er: No such server found:" << serverName; qDebug() << "[TelescopeControl] Error starting telescope ser ver: No such server found:" << serverName;
return false; return false;
} }
bool TelescopeControl::stopServerAtSlot(int slotNumber) bool TelescopeControl::stopServerAtSlot(int slotNumber)
{ {
//Validate //Validate
if(!isValidSlotNumber(slotNumber) || !telescopeServerProcess.contain s(slotNumber)) if(!isValidSlotNumber(slotNumber) || !telescopeServerProcess.contain s(slotNumber))
return false; return false;
skipping to change at line 1382 skipping to change at line 1293
{ {
//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 " << QDir::toNativeSeparators(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 " << QDir::toNativeSeparators(deviceModelsJsonPath); qWarning() << "[TelescopeControl] Can't open for rea ding " << 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(StelUtils::compareVersions(version, QString(TELES COPE_CONTROL_VERSION))!=0)
{ {
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 " << QDir::toNativeSeparators(newName); qWarning() << "[TelescopeControl] Th e 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] Th e existing version of device_models.json is obsolete. Unable to rename.";
useDefaultList = true; useDefaultList = true;
} }
} }
else else
deviceModelsJsonFile.close(); deviceModelsJsonFile.close();
} }
} }
if (useDefaultList) if (useDefaultList)
{ {
qWarning() << "TelescopeControl: Using embedded device model s list."; qWarning() << "[TelescopeControl] Using embedded device mode ls list.";
deviceModelsJsonPath = ":/telescopeControl/device_models.jso n"; deviceModelsJsonPath = ":/telescopeControl/device_models.jso n";
} }
//Open the file and parse the device list //Open the file and parse the device list
QVariantList deviceModelsList; QVariantList deviceModelsList;
QFile deviceModelsJsonFile(deviceModelsJsonPath); QFile deviceModelsJsonFile(deviceModelsJsonPath);
if(deviceModelsJsonFile.open(QFile::ReadOnly)) if(deviceModelsJsonFile.open(QFile::ReadOnly))
{ {
deviceModelsList = (StelJsonParser::parse(&deviceModelsJsonF ile).toMap()).value("list").toList(); deviceModelsList = (StelJsonParser::parse(&deviceModelsJsonF ile).toMap()).value("list").toList();
deviceModelsJsonFile.close(); deviceModelsJsonFile.close();
skipping to change at line 1448 skipping to change at line 1359
{ {
return; return;
} }
//Compile a list of the available telescope server executables //Compile a list of the available telescope server executables
loadTelescopeServerExecutables(); loadTelescopeServerExecutables();
if(telescopeServers.isEmpty()) if(telescopeServers.isEmpty())
{ {
//deviceModels = QHash<QString, DeviceModel>(); //deviceModels = QHash<QString, DeviceModel>();
//return; //return;
qWarning() << "TelescopeControl: Only embedded telescope ser vers are available."; qWarning() << "[TelescopeControl] Only embedded telescope se rvers are available.";
} }
//Clear the list of device models - it may not be empty. //Clear the list of device models - it may not be empty.
deviceModels.clear(); deviceModels.clear();
//Cicle the list of telescope deifinitions //Cicle the list of telescope deifinitions
for(int i = 0; i < deviceModelsList.size(); i++) for(int i = 0; i < deviceModelsList.size(); i++)
{ {
QVariantMap model = deviceModelsList.at(i).toMap(); QVariantMap model = deviceModelsList.at(i).toMap();
if(model.isEmpty()) if(model.isEmpty())
skipping to change at line 1471 skipping to change at line 1382
//Model name //Model name
QString name = model.value("name").toString(); QString name = model.value("name").toString();
if(name.isEmpty()) if(name.isEmpty())
{ {
//TODO: Add warning //TODO: Add warning
continue; continue;
} }
if(deviceModels.contains(name)) if(deviceModels.contains(name))
{ {
qWarning() << "TelescopeControl: Skipping device mod el: Duplicate name:" << name; qWarning() << "[TelescopeControl] Skipping device mo del: Duplicate name:" << name;
continue; continue;
} }
//Telescope server //Telescope server
QString server = model.value("server").toString(); QString server = model.value("server").toString();
//The default behaviour is to use embedded servers: //The default behaviour is to use embedded servers:
bool useExecutable = false; bool useExecutable = false;
if(server.isEmpty()) if(server.isEmpty())
{ {
qWarning() << "TelescopeControl: Skipping device mod el: No server specified for" << name; qWarning() << "[TelescopeControl] Skipping device mo del: No server specified for" << name;
continue; continue;
} }
if(useServerExecutables) if(useServerExecutables)
{ {
if(telescopeServers.contains(server)) if(telescopeServers.contains(server))
{ {
qDebug() << "TelescopeControl: Using telesco pe server executable for" << name; qDebug() << "[TelescopeControl] Using telesc ope server executable for" << name;
useExecutable = true; useExecutable = true;
} }
else if(EMBEDDED_TELESCOPE_SERVERS.contains(server)) else if(EMBEDDED_TELESCOPE_SERVERS.contains(server))
{ {
qWarning() << "TelescopeControl: No external qWarning() << "[TelescopeControl] No externa
telescope server executable found for" << name; l telescope server executable found for" << name;
qWarning() << "TelescopeControl: Using embed qWarning() << "[TelescopeControl] Using embe
ded telescope server" << server << "for" << name; dded telescope server" << server
<< "for" << name;
useExecutable = false; useExecutable = false;
} }
else else
{ {
qWarning() << "TelescopeControl: Skipping de qWarning() << "[TelescopeControl] Skipping d
vice model: No server" << server << "found for" << name; evice model: No server" << server
<< "found for" << name;
continue; continue;
} }
} }
else else
{ {
if(!EMBEDDED_TELESCOPE_SERVERS.contains(server)) if(!EMBEDDED_TELESCOPE_SERVERS.contains(server))
{ {
qWarning() << "TelescopeControl: Skipping de qWarning() << "[TelescopeControl] Skipping d
vice model: No server" << server << "found for" << name; evice model: No server" << server
<< "found for" << name;
continue; continue;
} }
//else: everything is OK, using embedded server //else: everything is OK, using embedded server
} }
//Description and default connection delay //Description and default connection delay
QString description = model.value("description", "No descrip tion is available.").toString(); QString description = model.value("description", "No descrip tion is available.").toString();
int delay = model.value("default_delay", DEFAULT_DELAY).toIn t(); int delay = model.value("default_delay", DEFAULT_DELAY).toIn t();
//Add this to the main list //Add this to the main list
DeviceModel newDeviceModel = {name, description, server, del ay, useExecutable}; DeviceModel newDeviceModel = {name, description, server, del ay, useExecutable};
deviceModels.insert(name, newDeviceModel); deviceModels.insert(name, newDeviceModel);
//qDebug() << "TelescopeControl: Adding device model:" << na me << description << server << delay; qDebug() << "[TelescopeControl] Adding device model:" << nam e << description << server << delay;
} }
} }
const QHash<QString, DeviceModel>& TelescopeControl::getDeviceModels() const QHash<QString, DeviceModel>& TelescopeControl::getDeviceModels()
{ {
return deviceModels; return deviceModels;
} }
QHash<int, QString> TelescopeControl::getConnectedClientsNames() QHash<int, QString> TelescopeControl::getConnectedClientsNames()
{ {
skipping to change at line 1549 skipping to change at line 1463
} }
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" << QDir::toNativeSeparators(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" << QDir::toNativeSeparators(deviceModelsListPath); qDebug() << "[TelescopeControl] The default device models list has b een 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 : " << QDir::toNativeSeparators(newPath); qWarning() << "[TelescopeControl] Can't find such a director y: " << 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 qWarning() << "[TelescopeControl] No telescope server execut
bles found in" ables found in"
<< QDir::toNativeSe << QDir::toNativeSeparators(serverExecutablesDire
parators(serverExecutablesDirectoryPath); ctoryPath);
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 1616 skipping to change at line 1530
{ {
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 qWarning() << "[TelescopeControl] Unable to create a
log file for slot" log file for slot" << slot
<< slot << << ":" << QDir::toNativeSeparators(filePa
":" << QDir::toNativeSeparators(filePath); th);
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. 68 change blocks. 
221 lines changed or deleted 125 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/