ckb-next  beta-v0.2.8 at branch testing
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 31 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.

31  :
32  QDialog(parent),
34  blob(fwBlob), kb(device), evLoop(0), exitSuccess(true)
35 {
36  ui->setupUi(this);
37  ui->curLabel->setText(kb->firmware);
38  ui->newLabel->setText(QString::number(newV, 'f', 2));
39  ui->devLabel->setText(kb->usbModel);
40 
41  connect(device, SIGNAL(destroyed()), this, SLOT(removeDev()));
42  connect(device, SIGNAL(fwUpdateProgress(int,int)), this, SLOT(fwUpdateProgress(int,int)));
43  connect(device, SIGNAL(fwUpdateFinished(bool)), this, SLOT(fwUpdateFinished(bool)));
44 
45  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MIN);
46 }
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 48 of file fwupgradedialog.cpp.

References cleanBlob(), and ui.

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

+ Here is the call graph for this function:

Member Function Documentation

void FwUpgradeDialog::cleanBlob ( )
private

Definition at line 77 of file fwupgradedialog.cpp.

References savePath.

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

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

+ Here is the caller graph for this function:

void FwUpgradeDialog::closeEvent ( QCloseEvent *  event)
private

Definition at line 53 of file fwupgradedialog.cpp.

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

Definition at line 107 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().

107  {
108  QString features = kb->features;
109  if(!blob.isEmpty()){
110  // If a blob was already specified, check its version and validity
111  float newV = verifyFw(blob, features);
112  if(newV == 0.f){
113  QMessageBox::warning(parentWidget(), "Error", "<center>Not a valid firmware for this device.</center>");
114  return QDialog::Rejected;
115  }
116  ui->newLabel->setText(QString::number(newV, 'f', 2));
117  } else {
118  // Download a new blob file
119  ui->progressBar->show();
120  ui->cancelButton->setEnabled(false);
121  ui->actionButton->setEnabled(false);
122  show();
123  // This can take a while
124  blob = KbFirmware::dataForBoard(features);
125  // Check validity
126  float newV = verifyFw(blob, features);
127  if(newV == 0.f){
128  hide();
129  QMessageBox::warning(parentWidget(), "Error", "<center>There was a problem with the downloaded file.<br />Please try again later.</center>");
130  return QDialog::Rejected;
131  }
132  }
133  // Save temporary file
134  if(saveBlob().isEmpty()){
135  hide();
136  QMessageBox::warning(parentWidget(), "Error", "<center>Unable to save temporary file.</center>");
137  return QDialog::Rejected;
138  }
139  // Set up UI
140  ui->progressBar->setValue(0);
141  ui->progressBar->setMaximum(1);
142  ui->progressBar->setTextVisible(false);
143  ui->statusLabel->setText("Ready to install new firmware.<br /><br /><b>Disclaimer:</b> ckb is not endorsed by Corsair. This is <i>unlikely</i> to brick your device, but I accept no responsibility if it does. If you're paranoid, update from Windows.");
144  ui->cancelButton->setEnabled(true);
145  ui->actionButton->setEnabled(true);
146  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MAX);
147  show();
148  // Run modal event loop
149  evLoop = new QEventLoop(this);
150  evLoop->exec();
151  delete evLoop;
152  hide();
153  return exitSuccess ? QDialog::Accepted : QDialog::Rejected;
154 }
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 170 of file fwupgradedialog.cpp.

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

Referenced by FwUpgradeDialog(), and removeDev().

170  {
171  cleanBlob();
172  if(succeeded)
173  ui->statusLabel->setText("Update successful!");
174  else
175  ui->statusLabel->setText("Update failed.");
176  ui->actionButton->setText("OK");
177  ui->actionButton->setEnabled(true);
178  ui->progressBar->setMaximum(1);
179  ui->progressBar->setValue(1);
180  // Exit after 10s
181  if(evLoop)
182  QTimer::singleShot(10000, evLoop, SLOT(quit()));
183 }
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 163 of file fwupgradedialog.cpp.

References Ui_FwUpgradeDialog::progressBar, and ui.

Referenced by FwUpgradeDialog().

163  {
164  if(current > 0 && total > 0){
165  ui->progressBar->setMaximum(total);
166  ui->progressBar->setValue(current);
167  }
168 }
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 191 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.

191  {
192  if(!savePath.isEmpty() && kb){
193  // Start upgrade
194  setFixedSize(DIALOG_WIDTH, DIALOG_HEIGHT_MIN);
195  ui->progressBar->show();
196  ui->progressBar->setValue(0);
197  ui->progressBar->setMaximum(0);
198  ui->progressBar->setTextVisible(true);
199  ui->cancelButton->hide();
200  ui->actionButton->setEnabled(false);
201  ui->actionButton->setText("Please wait");
202  ui->statusLabel->setText("Installing firmware...");
203  kb->fwUpdate(savePath);
204  } else {
205  // Finished, close dialog.
206  if(evLoop)
207  evLoop->quit();
208  }
209 }
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 185 of file fwupgradedialog.cpp.

References evLoop, and exitSuccess.

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

Definition at line 156 of file fwupgradedialog.cpp.

References fwUpdateFinished(), kb, and savePath.

Referenced by FwUpgradeDialog().

156  {
157  kb = 0;
158  // Assume success if upgrade in progress
159  if(!savePath.isEmpty())
160  fwUpdateFinished(true);
161 }
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 57 of file fwupgradedialog.cpp.

References blob, and savePath.

Referenced by exec().

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

+ 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: