ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FwUpgradeDialog Class Reference

#include <src/ckb/fwupgradedialog.h>

+ Inheritance diagram for FwUpgradeDialog:
+ Collaboration diagram for FwUpgradeDialog:

Public Member Functions

 FwUpgradeDialog (QWidget *parent, float newV, const QByteArray &fwBlob, Kb *device)
 
 ~FwUpgradeDialog ()
 
int exec ()
 

Private Slots

void fwUpdateProgress (int current, int total)
 
void fwUpdateFinished (bool succeeded)
 
void removeDev ()
 
void on_cancelButton_clicked ()
 
void on_actionButton_clicked ()
 

Private Member Functions

void closeEvent (QCloseEvent *event)
 
const QString & saveBlob ()
 
void cleanBlob ()
 

Private Attributes

Ui::FwUpgradeDialogui
 
QString savePath
 
QByteArray blob
 
Kbkb
 
QEventLoop * evLoop
 
bool exitSuccess
 

Detailed Description

Definition at line 13 of file fwupgradedialog.h.

Constructor & Destructor Documentation

FwUpgradeDialog::FwUpgradeDialog ( QWidget parent,
float  newV,
const QByteArray &  fwBlob,
Kb device 
)

Definition at line 32 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::curLabel, Ui_FwUpgradeDialog::devLabel, DIALOG_HEIGHT_MIN, DIALOG_WIDTH, Kb::firmware, fwUpdateFinished(), fwUpdateProgress(), kb, Ui_FwUpgradeDialog::newLabel, removeDev(), Ui_FwUpgradeDialog::setupUi(), ui, and Kb::usbModel.

32  :
33  QDialog(parent),
35  blob(fwBlob), kb(device), evLoop(0), exitSuccess(true)
36 {
37  ui->setupUi(this);
38  ui->curLabel->setText(kb->firmware);
39  ui->newLabel->setText(QString::number(newV, 'f', 2));
40  ui->devLabel->setText(kb->usbModel);
41 
42  connect(device, SIGNAL(destroyed()), this, SLOT(removeDev()));
43  connect(device, SIGNAL(fwUpdateProgress(int,int)), this, SLOT(fwUpdateProgress(int,int)));
44  connect(device, SIGNAL(fwUpdateFinished(bool)), this, SLOT(fwUpdateFinished(bool)));
45 
46  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MIN);
47 }
void fwUpdateFinished(bool succeeded)
QString firmware
Definition: kb.h:18
QString usbModel
Definition: kb.h:16
QEventLoop * evLoop
void fwUpdateProgress(int current, int total)
static const int DIALOG_WIDTH
Ui::FwUpgradeDialog * ui
static const int DIALOG_HEIGHT_MIN
void setupUi(QDialog *FwUpgradeDialog)

+ Here is the call graph for this function:

FwUpgradeDialog::~FwUpgradeDialog ( )

Definition at line 49 of file fwupgradedialog.cpp.

References cleanBlob(), and ui.

49  {
50  cleanBlob();
51  delete ui;
52 }
Ui::FwUpgradeDialog * ui

+ Here is the call graph for this function:

Member Function Documentation

void FwUpgradeDialog::cleanBlob ( )
private

Definition at line 78 of file fwupgradedialog.cpp.

References savePath.

Referenced by fwUpdateFinished(), and ~FwUpgradeDialog().

78  {
79  if(savePath.isEmpty())
80  return;
81  QFile(savePath).remove();
82  savePath = "";
83 }

+ Here is the caller graph for this function:

void FwUpgradeDialog::closeEvent ( QCloseEvent *  event)
private

Definition at line 54 of file fwupgradedialog.cpp.

54  {
55  event->ignore();
56 }
int FwUpgradeDialog::exec ( )

Definition at line 108 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::actionButton, blob, Ui_FwUpgradeDialog::cancelButton, KbFirmware::dataForBoard(), DIALOG_HEIGHT_MAX(), DIALOG_WIDTH, evLoop, exitSuccess, Kb::features, kb, Ui_FwUpgradeDialog::newLabel, Ui_FwUpgradeDialog::progressBar, saveBlob(), Ui_FwUpgradeDialog::statusLabel, ui, and verifyFw().

Referenced by KbWidget::on_fwUpdButton_clicked().

108  {
109  QString features = kb->features;
110  if(!blob.isEmpty()){
111  // If a blob was already specified, check its version and validity
112  float newV = verifyFw(blob, features);
113  if(newV == 0.f){
114  QMessageBox::warning(parentWidget(), "Error", "<center>Not a valid firmware for this device.</center>");
115  return QDialog::Rejected;
116  }
117  ui->newLabel->setText(QString::number(newV, 'f', 2));
118  } else {
119  // Download a new blob file
120  ui->progressBar->show();
121  ui->cancelButton->setEnabled(false);
122  ui->actionButton->setEnabled(false);
123  show();
124  // This can take a while
125  blob = KbFirmware::dataForBoard(features);
126  // Check validity
127  float newV = verifyFw(blob, features);
128  if(newV == 0.f){
129  hide();
130  QMessageBox::warning(parentWidget(), "Error", "<center>There was a problem with the downloaded file.<br />Please try again later.</center>");
131  return QDialog::Rejected;
132  }
133  }
134  // Save temporary file
135  if(saveBlob().isEmpty()){
136  hide();
137  QMessageBox::warning(parentWidget(), "Error", "<center>Unable to save temporary file.</center>");
138  return QDialog::Rejected;
139  }
140  // Set up UI
141  ui->progressBar->setValue(0);
142  ui->progressBar->setMaximum(1);
143  ui->progressBar->setTextVisible(false);
144  ui->statusLabel->setText("Ready to install new firmware.<br /><br /><b>Disclaimer:</b> ckb-next is not endorsed by Corsair.<br />This is <i>unlikely</i> to cause any damage, however the developers of this software do not accept any responsibility in such an event.");
145  ui->cancelButton->setEnabled(true);
146  ui->actionButton->setEnabled(true);
147  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MAX);
148  show();
149  // Run modal event loop
150  evLoop = new QEventLoop(this);
151  evLoop->exec();
152  delete evLoop;
153  hide();
154  return exitSuccess ? QDialog::Accepted : QDialog::Rejected;
155 }
QPushButton * cancelButton
static QByteArray dataForBoard(const QString &features)
Definition: kbfirmware.h:25
static const int DIALOG_HEIGHT_MAX(240)
QPushButton * actionButton
const QString & saveBlob()
QProgressBar * progressBar
QEventLoop * evLoop
QString features
Definition: kb.h:18
static const int DIALOG_WIDTH
static float verifyFw(const QByteArray &blob, const QString &features)
Ui::FwUpgradeDialog * ui

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void FwUpgradeDialog::fwUpdateFinished ( bool  succeeded)
privateslot

Definition at line 171 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::actionButton, cleanBlob(), evLoop, Ui_FwUpgradeDialog::progressBar, quit(), Ui_FwUpgradeDialog::statusLabel, and ui.

Referenced by FwUpgradeDialog(), and removeDev().

171  {
172  cleanBlob();
173  if(succeeded)
174  ui->statusLabel->setText("Update successful!");
175  else
176  ui->statusLabel->setText("Update failed.");
177  ui->actionButton->setText("OK");
178  ui->actionButton->setEnabled(true);
179  ui->progressBar->setMaximum(1);
180  ui->progressBar->setValue(1);
181  // Exit after 10s
182  if(evLoop)
183  QTimer::singleShot(10000, evLoop, SLOT(quit()));
184 }
static void quit()
quit Stop working the daemon. function is called if the daemon received a sigterm In this case...
Definition: main.c:30
QPushButton * actionButton
QProgressBar * progressBar
QEventLoop * evLoop
Ui::FwUpgradeDialog * ui

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void FwUpgradeDialog::fwUpdateProgress ( int  current,
int  total 
)
privateslot

Definition at line 164 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::progressBar, and ui.

Referenced by FwUpgradeDialog().

164  {
165  if(current > 0 && total > 0){
166  ui->progressBar->setMaximum(total);
167  ui->progressBar->setValue(current);
168  }
169 }
rgb * current
Definition: main.c:46
QProgressBar * progressBar
Ui::FwUpgradeDialog * ui

+ Here is the caller graph for this function:

void FwUpgradeDialog::on_actionButton_clicked ( )
privateslot

Definition at line 192 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::actionButton, Ui_FwUpgradeDialog::cancelButton, DIALOG_HEIGHT_MIN, DIALOG_WIDTH, evLoop, Kb::fwUpdate(), kb, Ui_FwUpgradeDialog::progressBar, savePath, Ui_FwUpgradeDialog::statusLabel, and ui.

192  {
193  if(!savePath.isEmpty() && kb){
194  // Start upgrade
195  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MIN);
196  ui->progressBar->show();
197  ui->progressBar->setValue(0);
198  ui->progressBar->setMaximum(0);
199  ui->progressBar->setTextVisible(true);
200  ui->cancelButton->hide();
201  ui->actionButton->setEnabled(false);
202  ui->actionButton->setText("Please wait");
203  ui->statusLabel->setText("Installing firmware...");
204  kb->fwUpdate(savePath);
205  } else {
206  // Finished, close dialog.
207  if(evLoop)
208  evLoop->quit();
209  }
210 }
QPushButton * cancelButton
QPushButton * actionButton
void fwUpdate(const QString &path)
Definition: kb.cpp:365
QProgressBar * progressBar
QEventLoop * evLoop
static const int DIALOG_WIDTH
Ui::FwUpgradeDialog * ui
static const int DIALOG_HEIGHT_MIN

+ Here is the call graph for this function:

void FwUpgradeDialog::on_cancelButton_clicked ( )
privateslot

Definition at line 186 of file fwupgradedialog.cpp.

References evLoop, and exitSuccess.

186  {
187  exitSuccess = false;
188  if(evLoop)
189  evLoop->quit();
190 }
QEventLoop * evLoop
void FwUpgradeDialog::removeDev ( )
privateslot

Definition at line 157 of file fwupgradedialog.cpp.

References fwUpdateFinished(), kb, and savePath.

Referenced by FwUpgradeDialog().

157  {
158  kb = 0;
159  // Assume success if upgrade in progress
160  if(!savePath.isEmpty())
161  fwUpdateFinished(true);
162 }
void fwUpdateFinished(bool succeeded)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const QString & FwUpgradeDialog::saveBlob ( )
private

Definition at line 58 of file fwupgradedialog.cpp.

References blob, and savePath.

Referenced by exec().

58  {
59  if(!savePath.isEmpty())
60  return savePath;
61  QDir tmp = QDir::temp();
62  qint64 pid = QCoreApplication::applicationPid();
63  QString path = tmp.absoluteFilePath(QString("ckb-%1-fwblob.bin").arg(pid));
64  QFile output(path);
65  if(!output.open(QIODevice::WriteOnly)){
66  return savePath;
67  }
68  if(!output.write(blob)){
69  output.close();
70  tmp.remove(path);
71  return savePath;
72  }
73  output.close();
74  savePath = path;
75  return savePath;
76 }

+ Here is the caller graph for this function:

Field Documentation

QByteArray FwUpgradeDialog::blob
private

Definition at line 41 of file fwupgradedialog.h.

Referenced by exec(), and saveBlob().

QEventLoop* FwUpgradeDialog::evLoop
private
bool FwUpgradeDialog::exitSuccess
private

Definition at line 46 of file fwupgradedialog.h.

Referenced by exec(), and on_cancelButton_clicked().

Kb* FwUpgradeDialog::kb
private

Definition at line 42 of file fwupgradedialog.h.

Referenced by exec(), FwUpgradeDialog(), on_actionButton_clicked(), and removeDev().

QString FwUpgradeDialog::savePath
private

Definition at line 37 of file fwupgradedialog.h.

Referenced by cleanBlob(), on_actionButton_clicked(), removeDev(), and saveBlob().


The documentation for this class was generated from the following files: