-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogFastboot.cpp
177 lines (139 loc) · 5.17 KB
/
DialogFastboot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QCloseEvent>
#include "DialogFastboot.h"
#include "ui_DialogFastboot.h"
#ifdef _WIN32
static const QString fastboot = "fastboot.exe";
#else
static const QString fastboot = "fastboot";
#endif //_WIN32
static const char* RED_CROSS = ":/icons/icons/red_cross.png";
static const char* GREEN_TICK = ":/icons/icons/green_tick.png";
DialogFastboot::DialogFastboot(QWidget* parent) : QDialog(parent),
mUi(new Ui::DialogFastboot) {
mUi->setupUi(this);
mGotFastbootFile = false;
mGotImageFile = false;
mGotDeviceSelected = false;
mUi->boxPartition->addItem("boot");
mUi->boxPartition->addItem("system");
mUi->boxPartition->addItem("recovery");
}
DialogFastboot::~DialogFastboot() {
delete mUi;
}
void DialogFastboot::closeEvent(QCloseEvent* event) {
if (event) {
event->ignore();
hide();
}
}
void DialogFastboot::on_pushBrowseFastboot_clicked() {
QString filename = QFileDialog::getOpenFileName(this, "Get fastboot location", ".", fastboot);
if (filename.length() > 0) {
mUi->lineFastbootFile->setText(filename);
}
}
void DialogFastboot::on_pushBrowseImage_clicked() {
QString filename = QFileDialog::getOpenFileName(this, "Get fastboot location", ".");
if (filename.length() > 0) {
mUi->lineImageFile->setText(filename);
}
}
void DialogFastboot::on_lineFastbootFile_textChanged(const QString& text) {
QFileInfo fileInfo(text);
if (fileInfo.fileName() == fastboot && fileInfo.exists()) {
mGotFastbootFile = true;
} else {
mGotFastbootFile = false;
}
analyzeSelections();
}
void DialogFastboot::on_lineImageFile_textChanged(const QString& text) {
QFileInfo fileInfo(text);
if (fileInfo.exists()) {
mGotImageFile = true;
} else {
mGotImageFile = false;
}
analyzeSelections();
}
void DialogFastboot::on_pushFlash_clicked() {
qDebug() << "Flashing...";
analyzeSelections();
QString fastbootFilename = mUi->lineFastbootFile->text();
//create fastboot process and setup signals
mProcess = new QProcess(this);
connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(on_processStdOutput()));
connect(mProcess, SIGNAL(readyReadStandardError()), this, SLOT(on_processStdError()));
connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(on_processFinished(int, QProcess::ExitStatus)));
//setup arguments
QString partition = mUi->boxPartition->currentText();
QStringList args;
args.append("flash");
args.append(partition);
//start process
mProcess->start(fastbootFilename, args);
if (mProcess->waitForStarted()) {
} else {
/* QMessageBox::critical(this, windowTitle(), KFailedToStart.arg(KProgram));
ui->statusBar->showMessage(KAnalysisFailed);*/
}
}
void DialogFastboot::on_pushClose_clicked() {
hide();
}
void DialogFastboot::on_listDevices_itemChanged(QListWidgetItem* item) {
qDebug() << "on_listDevices_itemChanged";
if (item) {
mGotDeviceSelected = true;
} else {
mGotDeviceSelected = false;
}
analyzeSelections();
}
void DialogFastboot::on_processStdOutput() {
qDebug() << "on_processStdOutput";
QByteArray output = mProcess->readAllStandardOutput();
mUi->textOutput->setTextColor(Qt::black);
mUi->textOutput->append(output);
}
void DialogFastboot::on_processStdError() {
qDebug() << "on_processStdError";
QByteArray output = mProcess->readAllStandardError();
mUi->textOutput->setTextColor(Qt::red);
mUi->textOutput->append(output);
}
void DialogFastboot::on_processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "on_processFinished";
mUi->textOutput->setTextColor(Qt::blue);
if (exitStatus == QProcess::NormalExit) {
mUi->textOutput->append(" -- process finished, code: " + QString::number(exitCode) + ", status: NormalExit");
} else {
mUi->textOutput->append(" -- process finished, code: " + QString::number(exitCode) + ", status: CrashExit");
}
}
void DialogFastboot::on_boxPartition_currentIndexChanged(const QString& text) {
analyzeSelections();
}
void DialogFastboot::analyzeSelections() {
QString commandLine;
if (mGotFastbootFile) {
//execute fastboot with devices parameter and parse output
mUi->labelFastbootFileStatus->setPixmap(QPixmap(QString::fromUtf8(GREEN_TICK)));
commandLine += fastboot;
} else {
mUi->labelFastbootFileStatus->setPixmap(QPixmap(QString::fromUtf8(RED_CROSS)));
}
commandLine += " flash ";
commandLine += mUi->boxPartition->currentText() + " ";
if (mGotImageFile) {
mUi->labelImageFileStatus->setPixmap(QPixmap(QString::fromUtf8(GREEN_TICK)));
commandLine += mUi->lineImageFile->text();
} else {
mUi->labelImageFileStatus->setPixmap(QPixmap(QString::fromUtf8(RED_CROSS)));
}
mUi->lineCommandLine->setText(commandLine);
}