TelescopeDialog.cpp   TelescopeDialog.cpp 
/* /*
* Stellarium Telescope Control Plug-in * Stellarium Telescope Control Plug-in
* *
* Copyright (C) 2009-2010 Bogdan Marinov (this file) * Copyright (C) 2009-2011 Bogdan Marinov (this file)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "Dialog.hpp" #include "Dialog.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelTranslator.hpp"
#include "TelescopeControl.hpp" #include "TelescopeControl.hpp"
#include "TelescopeConfigurationDialog.hpp" #include "TelescopeConfigurationDialog.hpp"
#include "TelescopeDialog.hpp" #include "TelescopeDialog.hpp"
#include "ui_telescopeDialog.h" #include "ui_telescopeDialog.h"
#include "StelGui.hpp" #include "StelGui.hpp"
#include <QDebug> #include <QDebug>
#include <QFrame> #include <QFrame>
#include <QTimer> #include <QTimer>
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
skipping to change at line 54 skipping to change at line 55
TelescopeDialog::TelescopeDialog() TelescopeDialog::TelescopeDialog()
{ {
ui = new Ui_telescopeDialogForm; ui = new Ui_telescopeDialogForm;
//TODO: Fix this - it's in the same plugin //TODO: Fix this - it's in the same plugin
telescopeManager = GETSTELMODULE(TelescopeControl); telescopeManager = GETSTELMODULE(TelescopeControl);
telescopeListModel = new QStandardItemModel(0, ColumnCount); telescopeListModel = new QStandardItemModel(0, ColumnCount);
//TODO: This shouldn't be a hash... //TODO: This shouldn't be a hash...
statusString[StatusNA] = QString("N/A"); statusString[StatusNA] = QString(N_("N/A"));
statusString[StatusStarting] = QString("Starting"); statusString[StatusStarting] = QString(N_("Starting"));
statusString[StatusConnecting] = QString("Connecting"); statusString[StatusConnecting] = QString(N_("Connecting"));
statusString[StatusConnected] = QString("Connected"); statusString[StatusConnected] = QString(N_("Connected"));
statusString[StatusDisconnected] = QString("Disconnected"); statusString[StatusDisconnected] = QString(N_("Disconnected"));
statusString[StatusStopped] = QString("Stopped"); statusString[StatusStopped] = QString(N_("Stopped"));
telescopeCount = 0; telescopeCount = 0;
} }
TelescopeDialog::~TelescopeDialog() TelescopeDialog::~TelescopeDialog()
{ {
delete ui; delete ui;
delete telescopeListModel; delete telescopeListModel;
} }
void TelescopeDialog::languageChanged() void TelescopeDialog::retranslate()
{ {
if (dialog) if (dialog)
{
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
setAboutText();
setHeaderNames();
updateWarningTexts();
//Retranslate type strings
for (int i = 0; i < telescopeListModel->rowCount(); i++)
{
QStandardItem* item = telescopeListModel->item(i, Co
lumnType);
QString original = item->data(Qt::UserRole).toString
();
QModelIndex index = telescopeListModel->index(i, Col
umnType);
telescopeListModel->setData(index, q_(original), Qt:
:DisplayRole);
}
}
} }
// Initialize the dialog widgets and connect the signals/slots // Initialize the dialog widgets and connect the signals/slots
void TelescopeDialog::createDialogContent() void TelescopeDialog::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
//Inherited connect //Inherited connect
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(languageChanged())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
//Connect: sender, signal, receiver, method //Connect: sender, signal, receiver, method
//Page: Telescopes //Page: Telescopes
connect(ui->pushButtonChangeStatus, SIGNAL(clicked()), this, SLOT(bu ttonChangeStatusPressed())); connect(ui->pushButtonChangeStatus, SIGNAL(clicked()), this, SLOT(bu ttonChangeStatusPressed()));
connect(ui->pushButtonConfigure, SIGNAL(clicked()), this, SLOT(butto nConfigurePressed())); connect(ui->pushButtonConfigure, SIGNAL(clicked()), this, SLOT(butto nConfigurePressed()));
connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(buttonAddPr essed())); connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(buttonAddPr essed()));
connect(ui->pushButtonRemove, SIGNAL(clicked()), this, SLOT(buttonRe movePressed())); connect(ui->pushButtonRemove, SIGNAL(clicked()), this, SLOT(buttonRe movePressed()));
connect(ui->telescopeTreeView, SIGNAL(clicked (const QModelIndex &)) , this, SLOT(selectTelecope(const QModelIndex &))); connect(ui->telescopeTreeView, SIGNAL(clicked (const QModelIndex &)) , this, SLOT(selectTelecope(const QModelIndex &)));
//connect(ui->telescopeTreeView, SIGNAL(activated (const QModelIndex &)), this, SLOT(configureTelescope(const QModelIndex &))); //connect(ui->telescopeTreeView, SIGNAL(activated (const QModelIndex &)), this, SLOT(configureTelescope(const QModelIndex &)));
//Page: Options: //Page: Options:
connect(ui->checkBoxReticles, SIGNAL(stateChanged(int)), this, SLOT( connect(ui->checkBoxReticles, SIGNAL(clicked(bool)),
toggleReticles(int))); telescopeManager, SLOT(setFlagTelescopeReticles(bool)));
connect(ui->checkBoxLabels, SIGNAL(stateChanged(int)), this, SLOT(to connect(ui->checkBoxLabels, SIGNAL(clicked(bool)),
ggleLabels(int))); telescopeManager, SLOT(setFlagTelescopeLabels(bool)));
connect(ui->checkBoxCircles, SIGNAL(stateChanged(int)), this, SLOT(t connect(ui->checkBoxCircles, SIGNAL(clicked(bool)),
oggleCircles(int))); telescopeManager, SLOT(setFlagTelescopeCircles(bool)));
connect(ui->checkBoxEnableLogs, SIGNAL(toggled(bool)), telescopeMana ger, SLOT(setFlagUseTelescopeServerLogs(bool))); connect(ui->checkBoxEnableLogs, SIGNAL(toggled(bool)), telescopeMana ger, SLOT(setFlagUseTelescopeServerLogs(bool)));
connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->label ExecutablesDirectory, SLOT(setEnabled(bool))); connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->label ExecutablesDirectory, SLOT(setEnabled(bool)));
connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->lineE ditExecutablesDirectory, SLOT(setEnabled(bool))); connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->lineE ditExecutablesDirectory, SLOT(setEnabled(bool)));
connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->pushB uttonPickExecutablesDirectory, SLOT(setEnabled(bool))); connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), ui->pushB uttonPickExecutablesDirectory, SLOT(setEnabled(bool)));
connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), this, SLO T(checkBoxUseExecutablesToggled(bool))); connect(ui->checkBoxUseExecutables, SIGNAL(toggled(bool)), this, SLO T(checkBoxUseExecutablesToggled(bool)));
connect(ui->pushButtonPickExecutablesDirectory, SIGNAL(clicked()), t his, SLOT(buttonBrowseServerDirectoryPressed())); connect(ui->pushButtonPickExecutablesDirectory, SIGNAL(clicked()), t his, SLOT(buttonBrowseServerDirectoryPressed()));
//In other dialogs: //In other dialogs:
connect(&configurationDialog, SIGNAL(changesDiscarded()), this, SLOT (discardChanges())); connect(&configurationDialog, SIGNAL(changesDiscarded()), this, SLOT (discardChanges()));
connect(&configurationDialog, SIGNAL(changesSaved(QString, Connectio nType)), this, SLOT(saveChanges(QString, ConnectionType))); connect(&configurationDialog, SIGNAL(changesSaved(QString, Connectio nType)), this, SLOT(saveChanges(QString, ConnectionType)));
//Initialize the style //Initialize the style
updateStyle(); updateStyle();
//Initializing the list of telescopes //Initializing the list of telescopes
telescopeListModel->setColumnCount(ColumnCount); telescopeListModel->setColumnCount(ColumnCount);
QStringList headerStrings; setHeaderNames();
headerStrings << "#";
//headerStrings << "Start";
headerStrings << "Status";
headerStrings << "Type";
headerStrings << "Name";
telescopeListModel->setHorizontalHeaderLabels(headerStrings);
ui->telescopeTreeView->setModel(telescopeListModel); ui->telescopeTreeView->setModel(telescopeListModel);
ui->telescopeTreeView->header()->setMovable(false); ui->telescopeTreeView->header()->setMovable(false);
ui->telescopeTreeView->header()->setResizeMode(ColumnSlot, QHeaderVi ew::ResizeToContents); ui->telescopeTreeView->header()->setResizeMode(ColumnSlot, QHeaderVi ew::ResizeToContents);
ui->telescopeTreeView->header()->setStretchLastSection(true); ui->telescopeTreeView->header()->setStretchLastSection(true);
//Populating the list //Populating the list
QStandardItem * tempItem;
QModelIndex modelIndex;
//Cycle the slots //Cycle the slots
for (int slotNumber = MIN_SLOT_NUMBER; slotNumber < SLOT_NUMBER_LIMI T; slotNumber++) for (int slotNumber = MIN_SLOT_NUMBER; slotNumber < SLOT_NUMBER_LIMI T; slotNumber++)
{ {
//Slot # //Slot #
//int slotNumber = (i+1)%SLOT_COUNT;//Making sure slot 0 is last //int slotNumber = (i+1)%SLOT_COUNT;//Making sure slot 0 is last
//Make sure that this is initialized for all slots //Make sure that this is initialized for all slots
telescopeStatus[slotNumber] = StatusNA; telescopeStatus[slotNumber] = StatusNA;
//Read the telescope properties //Read the telescope properties
skipping to change at line 160 skipping to change at line 169
int portTCP; int portTCP;
int delay; int delay;
bool connectAtStartup; bool connectAtStartup;
QList<double> circles; QList<double> circles;
QString serverName; QString serverName;
QString portSerial; QString portSerial;
if(!telescopeManager->getTelescopeAtSlot(slotNumber, connect ionType, name, equinox, host, portTCP, delay, connectAtStartup, circles, se rverName, portSerial)) if(!telescopeManager->getTelescopeAtSlot(slotNumber, connect ionType, name, equinox, host, portTCP, delay, connectAtStartup, circles, se rverName, portSerial))
continue; continue;
//Determine the server type //Determine the server type
QString connectionTypeLabel;
switch (connectionType)
{
case ConnectionInternal:
connectionTypeLabel = "local, Stellarium";
break;
case ConnectionLocal:
connectionTypeLabel = "local, external";
break;
case ConnectionRemote:
connectionTypeLabel = "remote, unknown";
break;
case ConnectionVirtual:
default:
connectionTypeLabel = "virtual";
break;
}
telescopeType[slotNumber] = connectionType; telescopeType[slotNumber] = connectionType;
//Determine the telescope's status //Determine the telescope's status
if (telescopeManager->isConnectedClientAtSlot(slotNumber)) if (telescopeManager->isConnectedClientAtSlot(slotNumber))
{ {
telescopeStatus[slotNumber] = StatusConnected; telescopeStatus[slotNumber] = StatusConnected;
} }
else else
{ {
//TODO: Fix this! //TODO: Fix this!
//At startup everything exists and attempts to conne ct //At startup everything exists and attempts to conne ct
telescopeStatus[slotNumber] = StatusConnecting; telescopeStatus[slotNumber] = StatusConnecting;
} }
//New column on a new row in the list: Slot number addModelRow(slotNumber, connectionType, telescopeStatus[slot
int lastRow = telescopeListModel->rowCount(); Number], name);
tempItem = new QStandardItem(QString::number(slotNumber));
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnSlot, tempItem);
//TODO: This is not updated, because it was commented out
//tempItem = new QStandardItem;
//tempItem->setEditable(false);
//tempItem->setCheckable(true);
//tempItem->setCheckState(Qt::Checked);
//tempItem->setData("If checked, this telescope will start w
hen Stellarium is started", Qt::ToolTipRole);
//telescopeListModel->setItem(lastRow, ColumnStartup, tempIt
em);//Start-up checkbox
//New column on a new row in the list: Telescope status
tempItem = new QStandardItem(statusString[telescopeStatus[sl
otNumber]]);
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnStatus, tempItem)
;
//New column on a new row in the list: Telescope type
tempItem = new QStandardItem(connectionTypeLabel);
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnType, tempItem);
//New column on a new row in the list: Telescope name
tempItem = new QStandardItem(name);
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnName, tempItem);
//After everything is done, count this as loaded //After everything is done, count this as loaded
telescopeCount++; telescopeCount++;
} }
//Finished populating the table, let's sort it by slot number //Finished populating the table, let's sort it by slot number
//ui->telescopeTreeView->setSortingEnabled(true);//Set in the .ui fi le //ui->telescopeTreeView->setSortingEnabled(true);//Set in the .ui fi le
ui->telescopeTreeView->sortByColumn(ColumnSlot, Qt::AscendingOrder); ui->telescopeTreeView->sortByColumn(ColumnSlot, Qt::AscendingOrder);
//(Works even when the table is empty) //(Works even when the table is empty)
//(Makes redundant the delay of 0 above) //(Makes redundant the delay of 0 above)
//TODO: Reuse code. //TODO: Reuse code.
if(telescopeCount > 0) if(telescopeCount > 0)
{ {
ui->telescopeTreeView->setFocus(); ui->telescopeTreeView->setFocus();
ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::ResizeToContents); ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::ResizeToContents);
ui->labelWarning->setText(LABEL_TEXT_CONTROL_TIP);
} }
else else
{ {
ui->pushButtonChangeStatus->setEnabled(false); ui->pushButtonChangeStatus->setEnabled(false);
ui->pushButtonConfigure->setEnabled(false); ui->pushButtonConfigure->setEnabled(false);
ui->pushButtonRemove->setEnabled(false); ui->pushButtonRemove->setEnabled(false);
ui->pushButtonAdd->setFocus(); ui->pushButtonAdd->setFocus();
if(telescopeManager->getDeviceModels().isEmpty())
ui->labelWarning->setText(LABEL_TEXT_NO_DEVICE_MODEL
S);
else
ui->labelWarning->setText(LABEL_TEXT_ADD_TIP);
} }
updateWarningTexts();
if(telescopeCount >= SLOT_COUNT) if(telescopeCount >= SLOT_COUNT)
ui->pushButtonAdd->setEnabled(false); ui->pushButtonAdd->setEnabled(false);
//Checkboxes //Checkboxes
ui->checkBoxReticles->setChecked(telescopeManager->getFlagTelescopeR eticles()); ui->checkBoxReticles->setChecked(telescopeManager->getFlagTelescopeR eticles());
ui->checkBoxLabels->setChecked(telescopeManager->getFlagTelescopeLab els()); ui->checkBoxLabels->setChecked(telescopeManager->getFlagTelescopeLab els());
ui->checkBoxCircles->setChecked(telescopeManager->getFlagTelescopeCi rcles()); ui->checkBoxCircles->setChecked(telescopeManager->getFlagTelescopeCi rcles());
ui->checkBoxEnableLogs->setChecked(telescopeManager->getFlagUseTeles copeServerLogs()); ui->checkBoxEnableLogs->setChecked(telescopeManager->getFlagUseTeles copeServerLogs());
//Telescope server directory //Telescope server directory
ui->checkBoxUseExecutables->setChecked(telescopeManager->getFlagUseS erverExecutables()); ui->checkBoxUseExecutables->setChecked(telescopeManager->getFlagUseS erverExecutables());
ui->lineEditExecutablesDirectory->setText(telescopeManager->getServe rExecutablesDirectoryPath()); ui->lineEditExecutablesDirectory->setText(telescopeManager->getServe rExecutablesDirectoryPath());
//About page //About page
setAboutText();
//Everything must be initialized by now, start the updateTimer
//TODO: Find if it's possible to run it only when the dialog is visi
ble
QTimer* updateTimer = new QTimer(this);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateTelescopeSt
ates()));
updateTimer->start(200);
}
void TelescopeDialog::setAboutText()
{
//TODO: Expand //TODO: Expand
QString htmlPage = "<html><head></head><body>"; QString aboutPage = "<html><head></head><body>";
htmlPage += "<h2>Stellarium Telescope Control Plug-in</h2>"; aboutPage += QString("<h2>%1</h2>").arg(q_("Telescope Control plug-i
htmlPage += "<h3>Version " + QString(PLUGIN_VERSION) + "</h3>"; n"));
aboutPage += "<h3>" + QString(q_("Version %1")).arg(TELESCOPE_CONTRO
L_VERSION) + "</h3>";
QFile aboutFile(":/telescopeControl/about.utf8");
aboutFile.open(QFile::ReadOnly | QFile::Text);
aboutPage += aboutFile.readAll();
aboutFile.close();
aboutPage += "</body></html>";
QString helpPage = "<html><head></head><body>";
QFile helpFile(":/telescopeControl/help.utf8"); QFile helpFile(":/telescopeControl/help.utf8");
helpFile.open(QFile::ReadOnly | QFile::Text); helpFile.open(QFile::ReadOnly | QFile::Text);
htmlPage += helpFile.readAll(); helpPage += helpFile.readAll();
helpFile.close(); helpFile.close();
htmlPage += "</body></html>"; helpPage += "</body></html>";
ui->textBrowserAbout->setHtml(htmlPage);
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( )); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( ));
Q_ASSERT(gui); Q_ASSERT(gui);
ui->textBrowserAbout->document()->setDefaultStyleSheet(QString(gui-> getStelStyle().htmlStyleSheet)); ui->textBrowserAbout->document()->setDefaultStyleSheet(QString(gui-> getStelStyle().htmlStyleSheet));
ui->textBrowserHelp->document()->setDefaultStyleSheet(QString(gui->g
etStelStyle().htmlStyleSheet));
ui->textBrowserAbout->setHtml(aboutPage);
ui->textBrowserHelp->setHtml(helpPage);
}
//Everything must be initialized by now, start the updateTimer void TelescopeDialog::setHeaderNames()
//TODO: Find if it's possible to run it only when the dialog is visi {
ble QStringList headerStrings;
QTimer* updateTimer = new QTimer(this); // TRANSLATORS: Symbol for "number"
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateTelescopeSt headerStrings << q_("#");
ates())); //headerStrings << "Start";
updateTimer->start(200); headerStrings << q_("Status");
headerStrings << q_("Type");
headerStrings << q_("Name");
telescopeListModel->setHorizontalHeaderLabels(headerStrings);
} }
void TelescopeDialog::toggleReticles(int state) void TelescopeDialog::updateWarningTexts()
{ {
if(state == Qt::Checked) QString text;
if (telescopeCount > 0)
{ {
telescopeManager->setFlagTelescopeReticles(true); #ifdef Q_OS_MAC
QString modifierName = "Command";
#else
QString modifierName = "Ctrl";
#endif
text = QString(q_("To slew a connected telescope to an objec
t (for example, a star), select that object, then hold down the %1 key and
press the key with that telescope's number. To slew it to the center of the
current view, hold down the Alt key and press the key with that telescope'
s number.")).arg(modifierName);
} }
else else
{ {
telescopeManager->setFlagTelescopeReticles(false); if (telescopeManager->getDeviceModels().isEmpty())
{
// TRANSLATORS: Currently, it is very unlikely if no
t impossible to actually see this text. :)
text = q_("No device model descriptions are availabl
e. Stellarium will not be able to control a telescope on its own, but it is
still possible to do it through an external application or to connect to a
remote host.");
}
else
{
// TRANSLATORS: The translated name of the Add butto
n is automatically inserted.
text = QString(q_("Press the \"%1\" button to set up
a new telescope connection.")).arg(ui->pushButtonAdd->text());
}
} }
ui->labelWarning->setText(text);
} }
void TelescopeDialog::toggleLabels(int state) QString TelescopeDialog::getTypeLabel(ConnectionType type)
{ {
if(state == Qt::Checked) QString typeLabel;
{ switch (type)
telescopeManager->setFlagTelescopeLabels(true);
}
else
{ {
telescopeManager->setFlagTelescopeLabels(false); case ConnectionInternal:
// TRANSLATORS: Telescope connection type
typeLabel = N_("local, Stellarium");
break;
case ConnectionLocal:
// TRANSLATORS: Telescope connection type
typeLabel = N_("local, external");
break;
case ConnectionRemote:
// TRANSLATORS: Telescope connection type
typeLabel = N_("remote, unknown");
break;
case ConnectionVirtual:
// TRANSLATORS: Telescope connection type
typeLabel = N_("virtual");
break;
default:
;
} }
return typeLabel;
} }
void TelescopeDialog::toggleCircles(int state) void TelescopeDialog::addModelRow(int number,
ConnectionType type,
TelescopeStatus status,
const QString& name)
{
Q_ASSERT(telescopeListModel);
QStandardItem* tempItem = 0;
int lastRow = telescopeListModel->rowCount();
// Number
tempItem = new QStandardItem(QString::number(number));
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnSlot, tempItem);
// Checkbox
//TODO: This is not updated, because it was commented out
//tempItem = new QStandardItem;
//tempItem->setEditable(false);
//tempItem->setCheckable(true);
//tempItem->setCheckState(Qt::Checked);
//tempItem->setData("If checked, this telescope will start when Stel
larium is started", Qt::ToolTipRole);
//telescopeListModel->setItem(lastRow, ColumnStartup, tempItem);//St
art-up checkbox
//Status
tempItem = new QStandardItem(q_(statusString[status]));
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnStatus, tempItem);
//Type
QString typeLabel = getTypeLabel(type);
tempItem = new QStandardItem(q_(typeLabel));
tempItem->setEditable(false);
tempItem->setData(typeLabel, Qt::UserRole);
telescopeListModel->setItem(lastRow, ColumnType, tempItem);
//Name
tempItem = new QStandardItem(name);
tempItem->setEditable(false);
telescopeListModel->setItem(lastRow, ColumnName, tempItem);
}
void TelescopeDialog::updateModelRow(int rowNumber,
ConnectionType type,
TelescopeStatus status,
const QString& name)
{ {
if(state == Qt::Checked) Q_ASSERT(telescopeListModel);
{ if (rowNumber > telescopeListModel->rowCount())
telescopeManager->setFlagTelescopeCircles(true); return;
}
else //The slot number doesn't need to be updated. :)
{ //Status
telescopeManager->setFlagTelescopeCircles(false); QString statusLabel = q_(statusString[status]);
} QModelIndex index = telescopeListModel->index(rowNumber, ColumnStatu
s);
telescopeListModel->setData(index, statusLabel, Qt::DisplayRole);
//Type
QString typeLabel = getTypeLabel(type);
index = telescopeListModel->index(rowNumber, ColumnType);
telescopeListModel->setData(index, typeLabel, Qt::UserRole);
telescopeListModel->setData(index, q_(typeLabel), Qt::DisplayRole);
//Name
index = telescopeListModel->index(rowNumber, ColumnName);
telescopeListModel->setData(index, name, Qt::DisplayRole);
} }
void TelescopeDialog::selectTelecope(const QModelIndex & index) void TelescopeDialog::selectTelecope(const QModelIndex & index)
{ {
//Extract selected item index //Extract selected item index
int selectedSlot = telescopeListModel->data( telescopeListModel->ind ex(index.row(),0) ).toInt(); int selectedSlot = telescopeListModel->data( telescopeListModel->ind ex(index.row(),0) ).toInt();
updateStatusButtonForSlot(selectedSlot); updateStatusButtonForSlot(selectedSlot);
//In all cases //In all cases
ui->pushButtonRemove->setEnabled(true); ui->pushButtonRemove->setEnabled(true);
skipping to change at line 349 skipping to change at line 425
telescopeStatus[configuredSlot] = StatusDisc onnected; telescopeStatus[configuredSlot] = StatusDisc onnected;
else else
return; return;
} }
else if(telescopeStatus[configuredSlot] != StatusStopped) else if(telescopeStatus[configuredSlot] != StatusStopped)
{ {
if(telescopeManager->stopTelescopeAtSlot(configuredSlot)) // Act as "Stop" if(telescopeManager->stopTelescopeAtSlot(configuredSlot)) // Act as "Stop"
telescopeStatus[configuredSlot] = St atusStopped; telescopeStatus[configuredSlot] = St atusStopped;
} }
//Update the status in the list //Update the status in the list
telescopeListModel->setData(telescopeListModel->index(ui->telescopeT int curRow = ui->telescopeTreeView->currentIndex().row();
reeView->currentIndex().row(), ColumnStatus), statusString[telescopeStatus[ QModelIndex curIndex = telescopeListModel->index(curRow, ColumnStatu
configuredSlot]], Qt::DisplayRole); s);
QString string = q_(statusString[telescopeStatus[configuredSlot]]);
telescopeListModel->setData(curIndex, string, Qt::DisplayRole);
setVisible(false); setVisible(false);
configurationDialog.setVisible(true); //This should be called first to actually create the dialog content configurationDialog.setVisible(true); //This should be called first to actually create the dialog content
configurationDialog.initExistingTelescopeConfiguration(configuredSlo t); configurationDialog.initExistingTelescopeConfiguration(configuredSlo t);
} }
void TelescopeDialog::buttonChangeStatusPressed() void TelescopeDialog::buttonChangeStatusPressed()
{ {
if(!ui->telescopeTreeView->currentIndex().isValid()) if(!ui->telescopeTreeView->currentIndex().isValid())
skipping to change at line 406 skipping to change at line 485
if(telescopeManager->stopTelescopeAtSlot(sel ectedSlot)) //Act as "Stop" if(telescopeManager->stopTelescopeAtSlot(sel ectedSlot)) //Act as "Stop"
telescopeStatus[selectedSlot] = Stat usStopped; telescopeStatus[selectedSlot] = Stat usStopped;
} }
break; break;
default: default:
break; break;
} }
} }
//Update the status in the list //Update the status in the list
telescopeListModel->setData(telescopeListModel->index(ui->telescopeT int curRow = ui->telescopeTreeView->currentIndex().row();
reeView->currentIndex().row(), ColumnStatus), statusString[telescopeStatus[ QModelIndex curIndex = telescopeListModel->index(curRow, ColumnStatu
selectedSlot]], Qt::DisplayRole); s);
QString string = q_(statusString[telescopeStatus[selectedSlot]]);
telescopeListModel->setData(curIndex, string, Qt::DisplayRole);
} }
void TelescopeDialog::buttonConfigurePressed() void TelescopeDialog::buttonConfigurePressed()
{ {
if(ui->telescopeTreeView->currentIndex().isValid()) if(ui->telescopeTreeView->currentIndex().isValid())
configureTelescope(ui->telescopeTreeView->currentIndex()); configureTelescope(ui->telescopeTreeView->currentIndex());
} }
void TelescopeDialog::buttonAddPressed() void TelescopeDialog::buttonAddPressed()
{ {
skipping to change at line 487 skipping to change at line 569
//If there are no telescopes left, disable some buttons //If there are no telescopes left, disable some buttons
if(telescopeCount == 0) if(telescopeCount == 0)
{ {
//TODO: Fix the phantom text of the Status button (reuse cod e?) //TODO: Fix the phantom text of the Status button (reuse cod e?)
//IDEA: Vsible/invisible instead of enabled/disabled? //IDEA: Vsible/invisible instead of enabled/disabled?
//The other buttons expand to take the place (delete spacers ) //The other buttons expand to take the place (delete spacers )
ui->pushButtonChangeStatus->setEnabled(false); ui->pushButtonChangeStatus->setEnabled(false);
ui->pushButtonConfigure->setEnabled(false); ui->pushButtonConfigure->setEnabled(false);
ui->pushButtonRemove->setEnabled(false); ui->pushButtonRemove->setEnabled(false);
if(telescopeManager->getDeviceModels().isEmpty())
ui->labelWarning->setText(LABEL_TEXT_NO_DEVICE_MODEL
S);
else
ui->labelWarning->setText(LABEL_TEXT_ADD_TIP);
} }
else else
{ {
ui->labelWarning->setText(LABEL_TEXT_CONTROL_TIP);
ui->telescopeTreeView->setCurrentIndex(telescopeListModel->i ndex(0,0)); ui->telescopeTreeView->setCurrentIndex(telescopeListModel->i ndex(0,0));
} }
updateWarningTexts();
} }
void TelescopeDialog::saveChanges(QString name, ConnectionType type) void TelescopeDialog::saveChanges(QString name, ConnectionType type)
{ {
//Save the changes to file //Save the changes to file
telescopeManager->saveTelescopes(); telescopeManager->saveTelescopes();
//Type and server properties //Type and server properties
telescopeType[configuredSlot] = type; telescopeType[configuredSlot] = type;
QString typeString;
switch (type) switch (type)
{ {
case ConnectionVirtual: case ConnectionVirtual:
telescopeStatus[configuredSlot] = StatusStopped; telescopeStatus[configuredSlot] = StatusStopped;
typeString = "virtual";
break; break;
case ConnectionInternal: case ConnectionInternal:
if(configuredTelescopeIsNew) if(configuredTelescopeIsNew)
telescopeStatus[configuredSlot] = StatusStop ped;//TODO: Is there a point? Isn't it better to force the status update me thod? telescopeStatus[configuredSlot] = StatusStop ped;//TODO: Is there a point? Isn't it better to force the status update me thod?
typeString = "local, Stellarium";
break; break;
case ConnectionLocal: case ConnectionLocal:
telescopeStatus[configuredSlot] = StatusDisconnected ; telescopeStatus[configuredSlot] = StatusDisconnected ;
typeString = "local, external";
break; break;
case ConnectionRemote: case ConnectionRemote:
default: default:
telescopeStatus[configuredSlot] = StatusDisconnected ; telescopeStatus[configuredSlot] = StatusDisconnected ;
typeString = "remote, unknown";
} }
//Update the model/list //Update the model/list
TelescopeStatus status = telescopeStatus[configuredSlot];
if(configuredTelescopeIsNew) if(configuredTelescopeIsNew)
{ {
QList<QStandardItem *> newRow; addModelRow(configuredSlot, type, status, name);
newRow << new QStandardItem(QString::number(configuredSlot))
<< new QStandardItem(statusString[telescopeStatus[con
figuredSlot]])
<< new QStandardItem(typeString)
<< new QStandardItem(name);
telescopeListModel->appendRow(newRow);
telescopeCount++; telescopeCount++;
} }
else else
{ {
int currentRow = ui->telescopeTreeView->currentIndex().row() ; int currentRow = ui->telescopeTreeView->currentIndex().row() ;
//ColumnSlot doesn't need to be updated. :) updateModelRow(currentRow, type, status, name);
telescopeListModel->setData(telescopeListModel->index(curren
tRow, ColumnStatus), statusString[telescopeStatus[configuredSlot]], Qt::Dis
playRole);
telescopeListModel->setData(telescopeListModel->index(curren
tRow, ColumnType), typeString, Qt::DisplayRole);
telescopeListModel->setData(telescopeListModel->index(curren
tRow, ColumnName), name, Qt::DisplayRole);
} }
//Sort the updated table by slot number //Sort the updated table by slot number
ui->telescopeTreeView->sortByColumn(ColumnSlot, Qt::AscendingOrder); ui->telescopeTreeView->sortByColumn(ColumnSlot, Qt::AscendingOrder);
//Can't add more telescopes if they have reached the maximum number //Can't add more telescopes if they have reached the maximum number
if (telescopeCount >= SLOT_COUNT) if (telescopeCount >= SLOT_COUNT)
ui->pushButtonAdd->setEnabled(false); ui->pushButtonAdd->setEnabled(false);
// //
if (telescopeCount == 0) if (telescopeCount == 0)
{ {
ui->pushButtonChangeStatus->setEnabled(false); ui->pushButtonChangeStatus->setEnabled(false);
ui->pushButtonConfigure->setEnabled(false); ui->pushButtonConfigure->setEnabled(false);
ui->pushButtonRemove->setEnabled(false); ui->pushButtonRemove->setEnabled(false);
ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::Interactive); ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::Interactive);
if(telescopeManager->getDeviceModels().isEmpty())
ui->labelWarning->setText(LABEL_TEXT_NO_DEVICE_MODEL
S);
else
ui->labelWarning->setText(LABEL_TEXT_ADD_TIP);
} }
else else
{ {
ui->telescopeTreeView->setFocus(); ui->telescopeTreeView->setFocus();
ui->telescopeTreeView->setCurrentIndex(telescopeListModel->i ndex(0,0)); ui->telescopeTreeView->setCurrentIndex(telescopeListModel->i ndex(0,0));
ui->pushButtonConfigure->setEnabled(true); ui->pushButtonConfigure->setEnabled(true);
ui->pushButtonRemove->setEnabled(true); ui->pushButtonRemove->setEnabled(true);
ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::ResizeToContents); ui->telescopeTreeView->header()->setResizeMode(ColumnType, Q HeaderView::ResizeToContents);
ui->labelWarning->setText(LABEL_TEXT_CONTROL_TIP);
} }
updateWarningTexts();
configuredTelescopeIsNew = false; configuredTelescopeIsNew = false;
configurationDialog.setVisible(false); configurationDialog.setVisible(false);
setVisible(true);//Brings the current window to the foreground setVisible(true);//Brings the current window to the foreground
} }
void TelescopeDialog::discardChanges() void TelescopeDialog::discardChanges()
{ {
configurationDialog.setVisible(false); configurationDialog.setVisible(false);
setVisible(true);//Brings the current window to the foreground setVisible(true);//Brings the current window to the foreground
skipping to change at line 624 skipping to change at line 686
} }
else else
{ {
if(telescopeType[slotNumber] == ConnectionInternal) if(telescopeType[slotNumber] == ConnectionInternal)
telescopeStatus[slotNumber] = StatusStopped; telescopeStatus[slotNumber] = StatusStopped;
else else
telescopeStatus[slotNumber] = StatusDisconne cted; telescopeStatus[slotNumber] = StatusDisconne cted;
} }
//Update the status in the list //Update the status in the list
telescopeListModel->setData(telescopeListModel->index(i, Col QModelIndex index = telescopeListModel->index(i, ColumnStatu
umnStatus), statusString[telescopeStatus[slotNumber]], Qt::DisplayRole); s);
QString statusStr = q_(statusString[telescopeStatus[slotNumb
er]]);
telescopeListModel->setData(index, statusStr, Qt::DisplayRol
e);
} }
if(ui->telescopeTreeView->currentIndex().isValid()) if(ui->telescopeTreeView->currentIndex().isValid())
{ {
int selectedSlot = telescopeListModel->data( telescopeListMo del->index(ui->telescopeTreeView->currentIndex().row(), ColumnSlot) ).toInt (); int selectedSlot = telescopeListModel->data( telescopeListMo del->index(ui->telescopeTreeView->currentIndex().row(), ColumnSlot) ).toInt ();
//Update the ChangeStatus button //Update the ChangeStatus button
updateStatusButtonForSlot(selectedSlot); updateStatusButtonForSlot(selectedSlot);
} }
} }
skipping to change at line 678 skipping to change at line 742
ui->pushButtonChangeStatus->setEnabled(false ); ui->pushButtonChangeStatus->setEnabled(false );
ui->pushButtonConfigure->setEnabled(false); ui->pushButtonConfigure->setEnabled(false);
ui->pushButtonRemove->setEnabled(false); ui->pushButtonRemove->setEnabled(false);
break; break;
} }
} }
} }
void TelescopeDialog::setStatusButtonToStart() void TelescopeDialog::setStatusButtonToStart()
{ {
ui->pushButtonChangeStatus->setText("Start"); ui->pushButtonChangeStatus->setText(q_("Start"));
ui->pushButtonChangeStatus->setToolTip("Start the selected local tel ui->pushButtonChangeStatus->setToolTip(q_("Start the selected local
escope"); telescope"));
} }
void TelescopeDialog::setStatusButtonToStop() void TelescopeDialog::setStatusButtonToStop()
{ {
ui->pushButtonChangeStatus->setText("Stop"); ui->pushButtonChangeStatus->setText(q_("Stop"));
ui->pushButtonChangeStatus->setToolTip("Stop the selected local tele ui->pushButtonChangeStatus->setToolTip(q_("Stop the selected local
scope"); telescope"));
} }
void TelescopeDialog::setStatusButtonToConnect() void TelescopeDialog::setStatusButtonToConnect()
{ {
ui->pushButtonChangeStatus->setText("Connect"); ui->pushButtonChangeStatus->setText(q_("Connect"));
ui->pushButtonChangeStatus->setToolTip("Connect to the selected tele ui->pushButtonChangeStatus->setToolTip(q_("Connect to the selected
scope"); telescope"));
} }
void TelescopeDialog::setStatusButtonToDisconnect() void TelescopeDialog::setStatusButtonToDisconnect()
{ {
ui->pushButtonChangeStatus->setText("Disconnect"); ui->pushButtonChangeStatus->setText(q_("Disconnect"));
ui->pushButtonChangeStatus->setToolTip("Disconnect from the selected ui->pushButtonChangeStatus->setToolTip(q_("Disconnect from the sele
telescope"); cted telescope"));
} }
void TelescopeDialog::updateStyle() void TelescopeDialog::updateStyle()
{ {
if (dialog) if (dialog)
{ {
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
Q_ASSERT(gui); Q_ASSERT(gui);
QString style(gui->getStelStyle().htmlStyleSheet); QString style(gui->getStelStyle().htmlStyleSheet);
ui->textBrowserAbout->document()->setDefaultStyleSheet(style ); ui->textBrowserAbout->document()->setDefaultStyleSheet(style );
} }
} }
void TelescopeDialog::checkBoxUseExecutablesToggled(bool useExecutables) void TelescopeDialog::checkBoxUseExecutablesToggled(bool useExecutables)
{ {
telescopeManager->setFlagUseServerExecutables(useExecutables); telescopeManager->setFlagUseServerExecutables(useExecutables);
} }
void TelescopeDialog::buttonBrowseServerDirectoryPressed() void TelescopeDialog::buttonBrowseServerDirectoryPressed()
{ {
QString newPath = QFileDialog::getExistingDirectory (0, QString("Sel ect a directory"), telescopeManager->getServerExecutablesDirectoryPath()); QString newPath = QFileDialog::getExistingDirectory (0, QString(q_( "Select a directory")), telescopeManager->getServerExecutablesDirectoryPath ());
//TODO: Validation? Directory exists and contains servers? //TODO: Validation? Directory exists and contains servers?
if(!newPath.isEmpty()) if(!newPath.isEmpty())
{ {
ui->lineEditExecutablesDirectory->setText(newPath); ui->lineEditExecutablesDirectory->setText(newPath);
telescopeManager->setServerExecutablesDirectoryPath(newPath) ; telescopeManager->setServerExecutablesDirectoryPath(newPath) ;
telescopeManager->setFlagUseServerExecutables(true); telescopeManager->setFlagUseServerExecutables(true);
} }
} }
 End of changes. 55 change blocks. 
167 lines changed or deleted 237 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/