dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
upgradeassistantdialog.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  *
25  * Additional note on redistribution: The copyright and license notices above
26  * must be maintained in each individual source file that is a derivative work
27  * of this source file; otherwise redistribution is prohibited.
28  */
29 
30 #include <QDebug>
31 #include <QFont>
32 #include <QPushButton>
33 
34 #include "upgradeassistantdialog.h"
35 #include "ui_upgradeassistant.h"
36 
38  : QDialog(parent)
39  , ui(new Ui::UpgradeAssistant)
40 {
41  ui->setupUi(this);
42 
43  setModal(true);
44 
45  stepLabels[STEP_ENTERLOADER] = ui->lblEnterLoader;
46  stepLabels[STEP_CHECKCLOUD] = ui->lblCheckCloud;
47  stepLabels[STEP_UPGRADEBOOTLOADER] = ui->lblUpgradeBootloader;
48  stepLabels[STEP_DOWNLOADSETTINGS] = ui->lblDownloadSettings;
49  stepLabels[STEP_TRANSLATESETTINGS] = ui->lblTranslateSettings;
50  stepLabels[STEP_ERASESETTINGS] = ui->lblEraseSettings;
51  stepLabels[STEP_FLASHFIRMWARE] = ui->lblFlashFirmware;
52  stepLabels[STEP_BOOT] = ui->lblBoot;
53  stepLabels[STEP_IMPORT] = ui->lblImport;
54 
55  for (int i = STEP_FIRST; i < STEP_NUM; i++) {
56  originalText[i] = new QString(stepLabels[i]->text());
57  }
58 
59  connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
60 }
61 
63 {
64  delete ui;
65 }
66 
67 void UpgradeAssistantDialog::setOperatingMode(bool upgradingBootloader, bool blankFC)
68 {
69  ui->lblUpgradeBootloader->setEnabled(upgradingBootloader);
70 
71  ui->lblDownloadSettings->setEnabled(!blankFC);
72  ui->lblTranslateSettings->setEnabled(!blankFC);
73  ui->lblImport->setEnabled(!blankFC);
74 
75  onStepChanged(curStep);
76 }
77 
78 int UpgradeAssistantDialog::PromptUser(QString promptText, QString detailText,
79  QStringList buttonText)
80 {
81  int clickIndex = -1;
82 
83  QList<QPushButton *> buttons;
84 
85  QEventLoop loop;
86 
87  int i = 0;
88 
89  foreach (const QString &buttLabel, buttonText) {
90  QPushButton *newButt = new QPushButton(buttLabel);
91  buttons.append(newButt);
92  ui->buttonBox->addButton(newButt, QDialogButtonBox::ActionRole);
93 
94  connect(newButt, &QPushButton::clicked, &loop, [&, i](bool checked) {
95  Q_UNUSED(checked);
96  clickIndex = i;
97  loop.exit();
98  });
99 
100  i++;
101  }
102 
103  connect(this, &UpgradeAssistantDialog::finished, &loop, &QEventLoop::quit);
104 
105  ui->lblStatus->setText(promptText);
106  ui->lblDetailStatus->setText(detailText);
107 
108  loop.exec();
109 
110  foreach (QPushButton *button, buttons) {
111  ui->buttonBox->removeButton(button);
112 
113  delete button;
114  }
115 
116  ui->lblStatus->setText(tr("Auto-upgrade running..."));
117  ui->lblDetailStatus->setText(
118  tr("Please wait while the upgrader performs automated actions on the flight board."));
119 
120  return clickIndex;
121 }
122 
124 {
125  qDebug() << QString("UpgradeAssistant: in step %1").arg(step);
126 
127  curStep = step;
128 
129  int stepVal = step;
130 
131  for (int i = STEP_FIRST; i < STEP_NUM; i++) {
132  if (i < stepVal) {
133  // Ensure marked done
134  if (stepLabels[i]->isEnabled()) {
135  stepLabels[i]->setText(*originalText[i] + tr(" done!"));
136  } else {
137  stepLabels[i]->setText(*originalText[i] + tr(" (skipped)"));
138  }
139  } else if (i == stepVal) {
140  // Ensure not marked done..
141  stepLabels[i]->setText(QString("<b>%1</b>").arg(*originalText[i]));
142  } else /* i > stepVal */ {
143  // Ensure not marked done..
144  stepLabels[i]->setText(*originalText[i]);
145  }
146  }
147 
148  if (step == STEP_DONE) {
149  ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
150 
151  ui->lblStatus->setText(tr("Auto-upgrade complete!"));
152  ui->lblDetailStatus->setText(
153  tr("It may be necessary to reset your flight board (by removing and attaching power "
154  "and USB) to apply settings."));
155  } else {
156  ui->buttonBox->setStandardButtons(QDialogButtonBox::Abort);
157 
158  ui->lblStatus->setText(tr("Auto-upgrade running..."));
159  ui->lblDetailStatus->setText(
160  tr("Please wait while the upgrader performs automated actions on the flight board."));
161  }
162 
163  if (isVisible()) {
164  raise();
165  }
166 }
167 
168 void UpgradeAssistantDialog::closeEvent(QCloseEvent *event)
169 {
170  (void)event;
171 
172  reject();
173 }
void closeEvent(QCloseEvent *event)
int PromptUser(QString promptText, QString detailText, QStringList buttonText)
for i
Definition: OPPlots.m:140
UpgradeAssistantDialog(QWidget *parent=nullptr)
void setOperatingMode(bool upgradingBootloader, bool blankFC)
void(NAME)
void onStepChanged(UpgradeAssistantStep step)