Skip to content

Commit 2829d93

Browse files
committed
Implemented firmware update dialog
1 parent 82eedc9 commit 2829d93

File tree

6 files changed

+231
-8
lines changed

6 files changed

+231
-8
lines changed

qt/firmware_update_dialog.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Copyright (C) 2017 Bogdan Bogush <[email protected]>
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License version 3.
4+
*/
5+
6+
#include "firmware_update_dialog.h"
7+
#include "ui_firmware_update_dialog.h"
8+
#include <QFileDialog>
9+
10+
FirmwareUpdateDialog::FirmwareUpdateDialog(QWidget *parent) :
11+
QDialog(parent),
12+
ui(new Ui::FirmwareUpdateDialog)
13+
{
14+
ui->setupUi(this);
15+
16+
connect(ui->selectFileButton, SIGNAL(clicked()), this,
17+
SLOT(slotSelectFileButtonPressed()));
18+
connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()),
19+
this, SLOT(accept()));
20+
}
21+
22+
FirmwareUpdateDialog::~FirmwareUpdateDialog()
23+
{
24+
delete ui;
25+
}
26+
27+
void FirmwareUpdateDialog::slotSelectFileButtonPressed()
28+
{
29+
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
30+
".", tr("Binary Files (*.bin)"));
31+
32+
if (fileName.isNull())
33+
return;
34+
35+
ui->filePathEdit->setText(fileName);
36+
}
37+
38+
QString FirmwareUpdateDialog::getFilePath()
39+
{
40+
return ui->filePathEdit->text();
41+
}

qt/firmware_update_dialog.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright (C) 2017 Bogdan Bogush <[email protected]>
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License version 3.
4+
*/
5+
6+
#ifndef FIRMWARE_UPDATE_DIALOG_H
7+
#define FIRMWARE_UPDATE_DIALOG_H
8+
9+
#include <QDialog>
10+
11+
namespace Ui {
12+
class FirmwareUpdateDialog;
13+
}
14+
15+
class FirmwareUpdateDialog : public QDialog
16+
{
17+
Q_OBJECT
18+
19+
public:
20+
explicit FirmwareUpdateDialog(QWidget *parent = nullptr);
21+
~FirmwareUpdateDialog();
22+
QString getFilePath();
23+
24+
private slots:
25+
void slotSelectFileButtonPressed();
26+
27+
private:
28+
Ui::FirmwareUpdateDialog *ui;
29+
};
30+
31+
#endif // FIRMWARE_UPDATE_DIALOG_H

qt/firmware_update_dialog.ui

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>FirmwareUpdateDialog</class>
4+
<widget class="QDialog" name="FirmwareUpdateDialog">
5+
<property name="windowModality">
6+
<enum>Qt::WindowModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>420</width>
13+
<height>150</height>
14+
</rect>
15+
</property>
16+
<property name="sizePolicy">
17+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
18+
<horstretch>0</horstretch>
19+
<verstretch>0</verstretch>
20+
</sizepolicy>
21+
</property>
22+
<property name="minimumSize">
23+
<size>
24+
<width>420</width>
25+
<height>150</height>
26+
</size>
27+
</property>
28+
<property name="maximumSize">
29+
<size>
30+
<width>420</width>
31+
<height>150</height>
32+
</size>
33+
</property>
34+
<property name="windowTitle">
35+
<string>Firmware update</string>
36+
</property>
37+
<widget class="QWidget" name="">
38+
<property name="geometry">
39+
<rect>
40+
<x>10</x>
41+
<y>20</y>
42+
<width>392</width>
43+
<height>109</height>
44+
</rect>
45+
</property>
46+
<layout class="QVBoxLayout" name="verticalLayout_2">
47+
<item>
48+
<layout class="QVBoxLayout" name="verticalLayout">
49+
<item>
50+
<widget class="QLabel" name="pathLabel">
51+
<property name="text">
52+
<string>Path to firmware update file</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item>
57+
<layout class="QHBoxLayout" name="horizontalLayout">
58+
<item>
59+
<widget class="QLineEdit" name="filePathEdit">
60+
<property name="minimumSize">
61+
<size>
62+
<width>300</width>
63+
<height>0</height>
64+
</size>
65+
</property>
66+
</widget>
67+
</item>
68+
<item>
69+
<widget class="QPushButton" name="selectFileButton">
70+
<property name="text">
71+
<string>Select</string>
72+
</property>
73+
</widget>
74+
</item>
75+
</layout>
76+
</item>
77+
</layout>
78+
</item>
79+
<item>
80+
<spacer name="verticalSpacer">
81+
<property name="orientation">
82+
<enum>Qt::Vertical</enum>
83+
</property>
84+
<property name="sizeType">
85+
<enum>QSizePolicy::Fixed</enum>
86+
</property>
87+
<property name="sizeHint" stdset="0">
88+
<size>
89+
<width>20</width>
90+
<height>20</height>
91+
</size>
92+
</property>
93+
</spacer>
94+
</item>
95+
<item>
96+
<widget class="QDialogButtonBox" name="buttonBox">
97+
<property name="orientation">
98+
<enum>Qt::Horizontal</enum>
99+
</property>
100+
<property name="standardButtons">
101+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel</set>
102+
</property>
103+
</widget>
104+
</item>
105+
</layout>
106+
</widget>
107+
</widget>
108+
<resources/>
109+
<connections>
110+
<connection>
111+
<sender>buttonBox</sender>
112+
<signal>accepted()</signal>
113+
<receiver>FirmwareUpdateDialog</receiver>
114+
<slot>accept()</slot>
115+
<hints>
116+
<hint type="sourcelabel">
117+
<x>248</x>
118+
<y>254</y>
119+
</hint>
120+
<hint type="destinationlabel">
121+
<x>157</x>
122+
<y>274</y>
123+
</hint>
124+
</hints>
125+
</connection>
126+
<connection>
127+
<sender>buttonBox</sender>
128+
<signal>rejected()</signal>
129+
<receiver>FirmwareUpdateDialog</receiver>
130+
<slot>reject()</slot>
131+
<hints>
132+
<hint type="sourcelabel">
133+
<x>316</x>
134+
<y>260</y>
135+
</hint>
136+
<hint type="destinationlabel">
137+
<x>286</x>
138+
<y>274</y>
139+
</hint>
140+
</hints>
141+
</connection>
142+
</connections>
143+
</ui>

qt/main_window.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "ui_main_window.h"
88
#include "settings_programmer_dialog.h"
99
#include "chip_db_dialog.h"
10+
#include "firmware_update_dialog.h"
1011
#include "chip_db.h"
1112
#include "logger.h"
1213
#include "about_dialog.h"
@@ -88,7 +89,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
8889
connect(ui->detectPushButton, SIGNAL(clicked()), this,
8990
SLOT(slotDetectChip()));
9091
connect(ui->actionFirmwareUpdate, SIGNAL(triggered()), this,
91-
SLOT(slotFirmwareUpdate()));
92+
SLOT(slotFirmwareUpdateDialog()));
9293
}
9394

9495
MainWindow::~MainWindow()
@@ -620,10 +621,14 @@ void MainWindow::slotProgFirmwareUpdateProgress(unsigned int progress)
620621
setProgress(progress);
621622
}
622623

623-
void MainWindow::slotFirmwareUpdate()
624+
void MainWindow::slotFirmwareUpdateDialog()
624625
{
625-
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
626-
".", tr("Binary Files (*.bin)"));
626+
FirmwareUpdateDialog fwUpdateDialog(this);
627+
628+
if (fwUpdateDialog.exec() != QDialog::Accepted)
629+
return;
630+
631+
QString fileName = fwUpdateDialog.getFilePath();
627632

628633
if (fileName.isNull())
629634
return;

qt/main_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public slots:
6868
void slotSettingsProgrammer();
6969
void slotSettingsChipDb();
7070
void slotAboutDialog();
71-
void slotFirmwareUpdate();
71+
void slotFirmwareUpdateDialog();
7272
};
7373

7474
#endif // MAIN_WINDOW_H

qt/qt.pro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ SOURCES += main.cpp\
3636
chip_db_dialog.cpp \
3737
chip_db_table_model.cpp \
3838
err.cpp \
39-
about_dialog.cpp
39+
about_dialog.cpp \
40+
firmware_update_dialog.cpp
4041

4142
HEADERS += main_window.h \
4243
programmer.h \
@@ -52,12 +53,14 @@ HEADERS += main_window.h \
5253
chip_db_table_model.h \
5354
err.h \
5455
about_dialog.h \
55-
version.h
56+
version.h \
57+
firmware_update_dialog.h
5658

5759
FORMS += main_window.ui \
5860
settings_programmer_dialog.ui \
5961
chip_db_dialog.ui \
60-
about_dialog.ui
62+
about_dialog.ui \
63+
firmware_update_dialog.ui
6164

6265
QMAKE_CXXFLAGS += -std=c++11 -Wextra -Werror
6366
mingw:QMAKE_CXXFLAGS += -mno-ms-bitfields

0 commit comments

Comments
 (0)