• 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/Novae/src/gui/NovaeDialog.cpp
1
/*
2
 * Stellarium Novae Plug-in GUI
3
 *
4
 * Copyright (C) 2013 Alexander Wolf
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, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
*/
20

21
#include <QDebug>
22
#include <QTimer>
23
#include <QDateTime>
24
#include <QUrl>
25
#include <QFileDialog>
26

27
#include "StelApp.hpp"
28
#include "ui_novaeDialog.h"
29
#include "NovaeDialog.hpp"
30
#include "Novae.hpp"
31
#include "StelModuleMgr.hpp"
32
#include "StelStyle.hpp"
33
#include "StelGui.hpp"
34
#include "StelTranslator.hpp"
35

36
NovaeDialog::NovaeDialog()
×
37
        : StelDialog("Novae")
38
        , nova(Q_NULLPTR)
×
39
        , updateTimer(Q_NULLPTR)
×
40
{
41
        ui = new Ui_novaeDialog;
×
42
}
×
43

44
NovaeDialog::~NovaeDialog()
×
45
{
46
        if (updateTimer)
×
47
        {
48
                updateTimer->stop();
×
49
                delete updateTimer;
×
50
                updateTimer = Q_NULLPTR;
×
51
        }
52
        delete ui;
×
53
}
×
54

55
void NovaeDialog::retranslate()
×
56
{
57
        if (dialog)
×
58
        {
59
                ui->retranslateUi(dialog);
×
60
                refreshUpdateValues();
×
61
                setAboutHtml();
×
62
        }
63
}
×
64

65
// Initialize the dialog widgets and connect the signals/slots
66
void NovaeDialog::createDialogContent()
×
67
{
68
        nova = GETSTELMODULE(Novae);
×
69
        ui->setupUi(dialog);
×
70
        ui->tabs->setCurrentIndex(0);        
×
71
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
×
72
                this, SLOT(retranslate()));
73

74
        // Kinetic scrolling
75
        kineticScrollingList << ui->aboutTextBrowser;
×
76
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
77
        if (gui)
×
78
        {
79
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
80
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
81
        }
82

83

84
        // Settings tab / updates group
85
        connect(ui->internetUpdatesCheckbox, SIGNAL(stateChanged(int)), this, SLOT(setUpdatesEnabled(int)));
×
86
        connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(updateJSON()));
×
87
        connect(nova, SIGNAL(updateStateChanged(Novae::UpdateState)), this, SLOT(updateStateReceiver(Novae::UpdateState)));
×
88
        connect(nova, SIGNAL(jsonUpdateComplete(void)), this, SLOT(updateCompleteReceiver(void)));        
×
89
        connect(ui->updateFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setUpdateValues(int)));
×
90
        refreshUpdateValues(); // fetch values for last updated and so on
×
91
        // if the state didn't change, setUpdatesEnabled will not be called, so we force it
92
        setUpdatesEnabled(ui->internetUpdatesCheckbox->checkState());
×
93

94
        updateTimer = new QTimer(this);
×
95
        connect(updateTimer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
96
        updateTimer->start(7000);
×
97

98
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
99
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
100

101
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(restoreDefaults()));
×
102
        connect(ui->saveSettingsButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
×
103

104
        // About tab
105
        setAboutHtml();
×
106

107
        updateGuiFromSettings();
×
108
}
×
109

110
void NovaeDialog::setAboutHtml(void)
×
111
{
112
        QString html = "<html><head></head><body>";
×
113
        html += "<h2>" + q_("Bright Novae Plug-in") + "</h2><table width=\"90%\">";
×
114
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + NOVAE_PLUGIN_VERSION + "</td></tr>";
×
115
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + NOVAE_PLUGIN_LICENSE + "</td></tr>";
×
116
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Alexander Wolf</td></tr>";
×
117
        html += "</table>";
×
118

119
        html += "<p>" + q_("A plugin that shows some bright novae in the Milky Way galaxy.");
×
120
        html += " " + q_("You can find novae via search tool by entering designation of nova or its common name (e.g. 'Nova Cygni 1975' or 'V1500 Cyg').") + "</p>";
×
121

122
        html += "<p>" + q_("This plugin allows you to see recent bright novae: ");
×
123
        html += nova->getNovaeList();
×
124
        html += ". " + q_("This list altogether contains %1 stars.").arg(nova->getCountNovae());
×
125
        html += " " + q_("All those novae are brighter than %1 at peak of brightness.").arg(QString::number(nova->getLowerLimitBrightness(), 'f', 2) + "<sup>m</sup>") + "</p>";
×
126
        html += "<h3>" + q_("Light curves") + "</h3>";
×
127
        html += q_("This plugin uses a very simple model for calculation of light curves for novae stars.") + " ";
×
128
        html += q_("This model is based on time for decay by %1 magnitudes from the maximum value, where %1 is 2, 3, 6 and 9.").arg("<em>N</em>") + " ";
×
129
        html += q_("If a nova has no values for decay of magnitude then this plugin will use generalized values for it.");
×
130
        html += "<p>";
×
131

132
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("Bright Novae plugin");
×
133
        html += "</body></html>";
×
134

135
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
136
        if(gui!=Q_NULLPTR)
×
137
        {
138
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
139
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
140
        }
×
141

142
        ui->aboutTextBrowser->setHtml(html);
×
143
}
×
144

145
void NovaeDialog::refreshUpdateValues(void)
×
146
{
147
        QString nextUpdate = q_("Next update");
×
148
        ui->lastUpdateDateTimeEdit->setDateTime(nova->getLastUpdate());
×
149
        ui->updateFrequencySpinBox->setValue(nova->getUpdateFrequencyDays());
×
150
        int secondsToUpdate = nova->getSecondsToUpdate();
×
151
        ui->internetUpdatesCheckbox->setChecked(nova->getUpdatesEnabled());
×
152
        if (!nova->getUpdatesEnabled())
×
153
                ui->nextUpdateLabel->setText(q_("Internet updates disabled"));
×
154
        else if (nova->getUpdateState() == Novae::Updating)
×
155
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
156
        else if (secondsToUpdate <= 60)
×
157
                ui->nextUpdateLabel->setText(QString("%1: %2").arg(nextUpdate, q_("< 1 minute")));
×
158
        else if (secondsToUpdate < 3600)
×
159
        {
160
                int n = (secondsToUpdate/60)+1;
×
161
                // TRANSLATORS: minutes.
162
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("m", "time")));
×
163
        }
164
        else if (secondsToUpdate < 86400)
×
165
        {
166
                int n = (secondsToUpdate/3600)+1;
×
167
                // TRANSLATORS: hours.
168
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("h", "time")));
×
169
        }
170
        else
171
        {
172
                int n = (secondsToUpdate/86400)+1;
×
173
                // TRANSLATORS: days.
174
                ui->nextUpdateLabel->setText(QString("%1: %2 %3").arg(nextUpdate, QString::number(n), qc_("d", "time")));
×
175
        }
176
}
×
177

178
void NovaeDialog::setUpdateValues(int days)
×
179
{
180
        nova->setUpdateFrequencyDays(days);
×
181
        refreshUpdateValues();
×
182
}
×
183

184
void NovaeDialog::setUpdatesEnabled(int checkState)
×
185
{
186
        bool b = checkState != Qt::Unchecked;
×
187
        nova->setUpdatesEnabled(b);
×
188
        ui->updateFrequencySpinBox->setEnabled(b);
×
189
        if(b)
×
190
                ui->updateButton->setText(q_("Update now"));
×
191
        else
192
                ui->updateButton->setText(q_("Update from files"));
×
193

194
        refreshUpdateValues();
×
195
}
×
196

197
void NovaeDialog::updateStateReceiver(Novae::UpdateState state)
×
198
{
199
        //qDebug() << "NovaeDialog::updateStateReceiver got a signal";
200
        if (state==Novae::Updating)
×
201
                ui->nextUpdateLabel->setText(q_("Updating now..."));
×
202
        else if (state==Novae::DownloadError || state==Novae::OtherError)
×
203
        {
204
                ui->nextUpdateLabel->setText(q_("Update error"));
×
205
                updateTimer->start();  // make sure message is displayed for a while...
×
206
        }
207
}
×
208

209
void NovaeDialog::updateCompleteReceiver(void)
×
210
{
211
        ui->nextUpdateLabel->setText(QString(q_("Novae is updated")));
×
212
        // display the status for another full interval before refreshing status
213
        updateTimer->start();
×
214
        ui->lastUpdateDateTimeEdit->setDateTime(nova->getLastUpdate());
×
215
        QTimer *timer = new QTimer(this);
×
216
        connect(timer, SIGNAL(timeout()), this, SLOT(refreshUpdateValues()));
×
217
        setAboutHtml();
×
218
}
×
219

220
void NovaeDialog::restoreDefaults(void)
×
221
{
222
        if (askConfirmation())
×
223
        {
224
                qDebug() << "[Novae] restore defaults...";
×
225
                nova->restoreDefaults();
×
226
                nova->readSettingsFromConfig();
×
227
                updateGuiFromSettings();
×
228
        }
229
        else
230
                qDebug() << "[Novae] restore defaults is canceled...";
×
231
}
×
232

233
void NovaeDialog::updateGuiFromSettings(void)
×
234
{
235
        ui->internetUpdatesCheckbox->setChecked(nova->getUpdatesEnabled());
×
236
        refreshUpdateValues();
×
237
}
×
238

239
void NovaeDialog::saveSettings(void)
×
240
{
241
        nova->saveSettingsToConfig();
×
242
}
×
243

244
void NovaeDialog::updateJSON(void)
×
245
{
246
        if(nova->getUpdatesEnabled())
×
247
        {
248
                nova->updateJSON();
×
249
        }
250
}
×
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