• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6685397774

29 Oct 2023 07:37PM UTC coverage: 11.735% (-0.002%) from 11.737%
6685397774

push

github

10110111
Deduplicate title bar implementation

131 of 131 new or added lines in 56 files covered. (100.0%)

14842 of 126472 relevant lines covered (11.74%)

21617.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/RemoteControl/src/gui/RemoteControlDialog.cpp
1
/*
2
 * Angle Measure plug-in for Stellarium
3
 *
4
 * Copyright (C) 2014 Alexander Wolf, Georg Zotti
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include <QHostInfo>
21
#include <QRegularExpression>
22

23
#include "RemoteControl.hpp"
24
#include "RemoteControlDialog.hpp"
25
#include "ui_remoteControlDialog.h"
26

27
#include "StelApp.hpp"
28
#include "StelGui.hpp"
29
#include "StelTranslator.hpp"
30
#include "StelModule.hpp"
31
#include "StelModuleMgr.hpp"
32

33
RemoteControlDialog::RemoteControlDialog()
×
34
        : StelDialog("RemoteControl")
35
        , rc(nullptr)
×
36
{
37
        ui = new Ui_remoteControlDialog();
×
38
}
×
39

40
RemoteControlDialog::~RemoteControlDialog()
×
41
{
42
        delete ui;
×
43
}
×
44

45
void RemoteControlDialog::retranslate()
×
46
{
47
        if (dialog)
×
48
        {
49
                ui->retranslateUi(dialog);
×
50
                setAboutHtml();
×
51
        }
52
}
×
53

54
void RemoteControlDialog::createDialogContent()
×
55
{
56
        rc = GETSTELMODULE(RemoteControl);
×
57
        ui->setupUi(dialog);
×
58

59
        // Kinetic scrolling
60
        kineticScrollingList << ui->aboutTextBrowser;
×
61
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
62
        if (gui)
×
63
        {
64
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
65
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
66
        }
67

68

69
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
70
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
71
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
72

73
        // TODO Fill other buttons
74

75
        connectCheckBox(ui->enabledCheckbox,"actionShow_Remote_Control");
×
76
        connect(ui->enabledCheckbox, SIGNAL(clicked(bool)), this, SLOT(updateIPlabel(bool)));
×
77
        updateIPlabel(ui->enabledCheckbox->isChecked());
×
78

79
        ui->activateOnStartCheckBox->setChecked(rc->getFlagAutoStart());
×
80
        connect(ui->activateOnStartCheckBox, SIGNAL(toggled(bool)), rc, SLOT(setFlagAutoStart(bool)));
×
81
        connect(rc, SIGNAL(flagAutoStartChanged(bool)), ui->activateOnStartCheckBox, SLOT(setChecked(bool)));
×
82

83
        ui->passwordCheckBox->setChecked(rc->getFlagUsePassword());
×
84
        connect(ui->passwordCheckBox, SIGNAL(toggled(bool)), rc, SLOT(setFlagUsePassword(bool)));
×
85
        connect(rc, SIGNAL(flagUsePasswordChanged(bool)), ui->passwordCheckBox, SLOT(setChecked(bool)));
×
86

87
        ui->passwordEdit->setEnabled(rc->getFlagUsePassword());
×
88
        ui->passwordEdit->setText(rc->getPassword());
×
89

90
        connect(rc,SIGNAL(flagUsePasswordChanged(bool)),ui->passwordEdit,SLOT(setEnabled(bool)));
×
91
        connect(ui->passwordEdit, SIGNAL(textChanged(QString)), rc, SLOT(setPassword(QString)));
×
92

93
        ui->portNumberSpinBox->setValue(rc->getPort());
×
94
        connect(ui->portNumberSpinBox, SIGNAL(valueChanged(int)), rc, SLOT(setPort(int)));
×
95

96
        ui->enableCorsCheckbox->setChecked(rc->getFlagEnableCors());
×
97
        connect(ui->enableCorsCheckbox, SIGNAL(toggled(bool)), rc, SLOT(setFlagEnableCors(bool)));
×
98
        connect(rc, SIGNAL(flagEnableCorsChanged(bool)), ui->enableCorsCheckbox, SLOT(setChecked(bool)));
×
99

100
        ui->corsOriginEdit->setEnabled(rc->getFlagEnableCors());
×
101
        ui->corsOriginEdit->setText(rc->getCorsOrigin());
×
102

103
        connect(rc,SIGNAL(flagEnableCorsChanged(bool)),ui->corsOriginEdit,SLOT(setEnabled(bool)));
×
104
        connect(ui->corsOriginEdit, SIGNAL(textChanged(QString)), rc, SLOT(setCorsOrigin(QString)));
×
105

106
        ui->restartPanel->setVisible(false);
×
107
        connect(rc, SIGNAL(flagUsePasswordChanged(bool)), this, SLOT(requiresRestart()));
×
108
        connect(rc, SIGNAL(passwordChanged(QString)), this, SLOT(requiresRestart()));
×
109
        connect(rc, SIGNAL(flagEnableCorsChanged(bool)), this, SLOT(requiresRestart()));
×
110
        connect(rc, SIGNAL(corsOriginChanged(QString)), this, SLOT(requiresRestart()));
×
111
        connect(rc, SIGNAL(portChanged(int)), this, SLOT(requiresRestart()));
×
112

113
        connect(ui->resetButton, SIGNAL(clicked(bool)),this,SLOT(restart()));
×
114

115
        connect(ui->saveSettingsButton, SIGNAL(clicked()), rc, SLOT(saveSettings()));        
×
116
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(restoreDefaults()));
×
117

118
        setAboutHtml();
×
119
}
×
120

121
void RemoteControlDialog::restoreDefaults()
×
122
{
123
        if (askConfirmation())
×
124
        {
125
                qDebug() << "[RemoteControl] restore defaults...";
×
126
                rc->restoreDefaultSettings();
×
127
        }
128
        else
129
                qDebug() << "[RemoteControl] restore defaults is canceled...";
×
130
}
×
131

132
void RemoteControlDialog::setAboutHtml(void)
×
133
{
134
        QString html = "<html><head></head><body>";
×
135
        html += "<h2>" + q_("Remote Control Plug-in") + "</h2><table width=\"90%\">";
×
136
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + REMOTECONTROL_PLUGIN_VERSION + "</td></tr>";
×
137
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + REMOTECONTROL_PLUGIN_LICENSE + "</td></tr>";
×
138
        html += "<tr><td rowspan=2><strong>" + q_("Authors") + ":</strong></td><td>Florian Schaukowitsch</td></tr>";
×
139
        html += "<tr><td>Georg Zotti</td></tr>";
×
140
        html += "<tr><td><strong>" + q_("Contributors") + ":</strong></td><td>Alexander Wolf</td></tr>";
×
141
        html += "</table>";
×
142

143
        html += "<p>" + q_("The Remote Control plugin provides a web interface to allow state changes and triggering scripts using a connected webbrowser.") + "</p>";
×
144
        // TODO Add longer instructions?
145

146
        // Regexp to replace {text} with an HTML link.
147
        static const QRegularExpression a_rx("[{]([^{]*)[}]");
×
148

149
        html += "<p>" + q_("It is also possible to send commands via command line, e.g..");
×
150
        html += "<pre>\n"
151
                "wget -q --post-data 'id=myScript.ssc' http://localhost:8090/api/scripts/run >/dev/null 2>&amp;1\n"
152
                "curl --data 'id=myScript.ssc' http://localhost:8090/api/scripts/run >/dev/null 2>&amp;1\n"
153
                "curl -d     'id=myScript.ssc' http://localhost:8090/api/scripts/run >/dev/null 2>&amp;1\n"
154
                "</pre>";
×
155
        html += q_("This allows triggering automatic show setups for museums etc.") + "</p>";
×
156
        html += "<p>" + q_("This plugin was developed during ESA SoCiS 2015.") + "</p>";
×
157
        // TRANSLATORS: The text between braces is the text of an HTML link.
158
        html += "<p>" + q_("This plugin uses the {QtWebApp HTTP server} by Stefan Frings.").toHtmlEscaped().replace(a_rx, "<a href=\"http://stefanfrings.de/qtwebapp/index-en.html\">\\1</a>") + "</p>";
×
159

160
        html += "<h3>" + q_("Publications") + "</h3>";
×
161
        html += "<p>"  + q_("If you use this plugin in your publications, please cite:") + "</p>";
×
162
        html += "<p><ul>";
×
163
        html += "<li>" + QString("{Georg Zotti, Florian Schaukowitsch, and Michael Wimmer. The Skyscape Planetarium}. In Liz Henty, Bernadette Brady, Darrelyn Gunzburg, Frank Prendergast, and Fabio Silva, editors, The Marriage of Astronomy and Culture: Theory and Method in the Study of Cultural Astronomy (Papers from the 2016 SEAC Conference), volume 21 of Culture and Cosmos, pages 269–281, Lampeter, Ceredigion, Wales, Spring/Summer and Autumn/Winter 2017. Culture and Cosmos & Sophia Centre Press.")
×
164
                        .toHtmlEscaped().replace(a_rx, "<a href=\"http://www.cultureandcosmos.org/pdfs/21/CCv21_17Zotti.pdf\">\\1</a>") + "</li>";
×
165
        html += "</ul></p>";
×
166

167
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("Remote Control plugin", true);
×
168
        html += "</body></html>";
×
169

170
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
171
        if(gui!=nullptr)
×
172
        {
173
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
174
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
175
        }
×
176
        ui->aboutTextBrowser->setHtml(html);
×
177
}
×
178

179
void RemoteControlDialog::requiresRestart()
×
180
{
181
        ui->restartPanel->setVisible(rc->getFlagEnabled());
×
182
}
×
183

184
void RemoteControlDialog::restart()
×
185
{
186
        rc->stopServer();
×
187
        rc->startServer();
×
188
        ui->restartPanel->setVisible(false);
×
189
}
×
190

191
void RemoteControlDialog::updateIPlabel(bool running)
×
192
{
193
        if (running)
×
194
        {
195
                QString localHostName=QHostInfo::localHostName();
×
196
                QHostInfo hostInfo = QHostInfo::fromName(localHostName);
×
197
                QString ipString("");
×
198
                for (auto &a : hostInfo.addresses())
×
199
                {
200
                        if ((a.protocol() == QAbstractSocket::IPv4Protocol) && a != QHostAddress(QHostAddress::LocalHost))
×
201
                        {
202
                                ipString += a.toString() + " ";
×
203
                                continue;
×
204
                        }
205
                }
×
206
                ui->label_RemoteRunningState->setText(q_("Listening on %1, IP: ").arg(localHostName) + ipString);
×
207
                ui->label_RemoteRunningState->show();
×
208
        }
×
209
        else
210
        {
211
                ui->label_RemoteRunningState->setText(q_("Not active."));
×
212
                // Maybe even hide the label?
213
                ui->label_RemoteRunningState->hide();
×
214
        }
215
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc