Skip to content

Commit

Permalink
Making the indiserver path more responsive to clicking the List of IP
Browse files Browse the repository at this point in the history
addresses.  Also making it update the active profile if that changes but
the drivers don't.  And improving the get Server Port Method so that it
works even when the INDI Server is not running.
  • Loading branch information
rlancaste committed Sep 10, 2019
1 parent fd85eab commit 05259bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->displayWebManagerPath->setText(getWebManagerURL());
ui->displayWebManagerPath->setCursorPosition(0);
ui->ipInformation->setText(ui->ipListDisplay->currentItem()->toolTip());
checkINDIServerStatus(); //This will update the address for the indi server in the box
});

//These two connections enable the clipboard copy buttons
Expand Down Expand Up @@ -911,20 +912,21 @@ void MainWindow::checkINDIServerStatus()
bool INDIServerOnline = isINDIServerOnline(activeProfile);
displayServerStatusOnline(INDIServerOnline);
QStringList profiles = getProfiles();
if(oldProfiles.join(",") != profiles.join(",") || ui->profileBox->count() == 0)
if(oldProfiles.join(",") != profiles.join(",") || ui->profileBox->count() == 0 || oldActiveProfile != activeProfile)
{
ui->profileBox->clear();
ui->profileBox->addItems(profiles);
ui->profileBox->setCurrentText(activeProfile);
oldProfiles = profiles;
oldActiveProfile = activeProfile;
}
ui->profileBox->setDisabled(INDIServerOnline);
QString port = "";
port = getINDIServerPort();
ui->displayINDIServerPath->setText(getINDIServerURL(port));
ui->displayINDIServerPath->setCursorPosition(0);
if(INDIServerOnline)
{
port = getINDIServerPort(activeProfile);
ui->displayINDIServerPath->setText(getINDIServerURL(port));
ui->displayINDIServerPath->setCursorPosition(0);
QString webManagerDrivers="";
getRunningDrivers(webManagerDrivers);
if(oldDrivers != webManagerDrivers || ui->driversDisplay->count() ==0)
Expand All @@ -942,6 +944,7 @@ void MainWindow::checkINDIServerStatus()
{
ui->driversDisplay->clear();
oldDrivers.clear();

}

}
Expand Down Expand Up @@ -1034,18 +1037,24 @@ void MainWindow::stopINDIServer()
/*
* This method determines the port of the active server if one is running.
*/
QString MainWindow::getINDIServerPort(QString &activeProfile)
QString MainWindow::getINDIServerPort()
{
QUrl url(QString(getWebManagerURL() + "/api/profiles/" + activeProfile));
QUrl url(QString(getWebManagerURL() + "/api/profiles"));

QJsonDocument json;
if (getWebManagerResponse( url, &json))
{
QJsonObject jsonObj = json.object();
if(jsonObj.isEmpty())
QJsonArray array = json.array();

if (array.isEmpty())
return "";

return QString::number(jsonObj["port"].toInt());
for (auto value : array)
{
QJsonObject profile = value.toObject();
if(profile["name"].toString() == ui->profileBox->currentText())
return QString::number(profile["port"].toInt());
}
}
return "";
}
Expand Down
5 changes: 4 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ class MainWindow : public QMainWindow
QTimer serverMonitor;
QStringList getProfiles();
bool getRunningDrivers(QString &webManagerDrivers);
QString getINDIServerPort(QString &activeProfile);
QString getINDIServerPort();
void sendWebManagerCommand(const QUrl &url);
bool getWebManagerResponse(const QUrl &url, QJsonDocument *reply);
void updateDisplaysforShutDown();

QAction *managerStatusinTray;
QAction *serverStatusinTray;

//Thse parameters are used to prevent the constant update of the UI.
//When these things don't change, there is no need to redraw or recreate UI components.
QStringList oldProfiles;
QString oldActiveProfile;
QString oldDrivers;
QList<QHostAddress> oldIPList;

Expand Down

0 comments on commit 05259bb

Please sign in to comment.