forked from ic005k/OCAuxiliaryTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgdatabase.cpp
275 lines (216 loc) · 7.87 KB
/
dlgdatabase.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include "dlgdatabase.h"
#include "Method.h"
#include "mainwindow.h"
#include "ui_dlgdatabase.h"
extern MainWindow *mw_one;
extern Method *mymethod;
extern QString SaveFileName, strIniFile, strAppName, strAppExePath;
extern bool blDEV;
extern int red;
dlgDatabase::dlgDatabase(QWidget *parent)
: QDialog(parent), ui(new Ui::dlgDatabase) {
ui->setupUi(this);
Method::init_UIWidget(this, red);
processPing = new QProcess;
connect(processPing, SIGNAL(readyReadStandardOutput()), this,
SLOT(on_readoutput()));
connect(processPing, SIGNAL(readyReadStandardError()), this,
SLOT(on_readerror()));
ui->editFind->setClearButtonEnabled(true);
// tableDatabase->setEditTriggers(QAbstractItemView::NoEditTriggers);
QTableWidgetItem *id0;
ui->tableDatabase->setColumnCount(2);
ui->tableDatabase->setColumnWidth(0, 400);
id0 = new QTableWidgetItem(tr("Configs"));
ui->tableDatabase->setHorizontalHeaderItem(0, id0);
ui->tableDatabase->setColumnWidth(1, 220);
id0 = new QTableWidgetItem(tr("Comment"));
ui->tableDatabase->setHorizontalHeaderItem(1, id0);
ui->tableDatabase->setAlternatingRowColors(true);
ui->tableDatabase->horizontalHeader()->setStretchLastSection(true);
ui->tableDatabase->horizontalHeader()->setHidden(false);
ui->tableDatabase->setSelectionBehavior(
QAbstractItemView::SelectItems); //设置选择行为时每次选择一行或单个条目
for (int i = 0; i < ui->tableDatabase->columnCount(); i++) {
ui->tableDatabase->horizontalHeader()->setSectionResizeMode(
i, QHeaderView::ResizeToContents);
}
// Find Table
ui->tableDatabaseFind->horizontalHeader()->setHidden(true);
ui->tableDatabaseFind->setAlternatingRowColors(true);
ui->tableDatabaseFind->setHidden(true);
ui->tableDatabaseFind->horizontalHeader()->setStretchLastSection(true);
ui->tableDatabaseFind->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableDatabaseFind->horizontalHeader()->setSectionResizeMode(
0, QHeaderView::ResizeToContents);
}
dlgDatabase::~dlgDatabase() { delete ui; }
void dlgDatabase::init_Database(QStringList files) {
ui->tableDatabase->setRowCount(0);
ui->tableDatabase->setRowCount(files.count());
QString dirpath = strAppExePath + "/Database/BaseConfigs/";
for (int i = 0; i < files.count(); i++) {
QTableWidgetItem *newItem1;
newItem1 = new QTableWidgetItem(files.at(i));
ui->tableDatabase->setItem(i, 0, newItem1);
newItem1 =
new QTableWidgetItem(mymethod->readPlistComment(dirpath + files.at(i)));
ui->tableDatabase->setItem(i, 1, newItem1);
}
listItemModi.clear();
for (int i = 0; i < files.count(); i++) {
listItemModi.append(false);
}
setWindowTitle(tr("Configuration file database") + " : " +
mw_one->getDatabaseVer());
}
void dlgDatabase::closeEvent(QCloseEvent *event) {
Q_UNUSED(event);
QFileInfo appInfo(qApp->applicationDirPath());
QString dirpath = appInfo.filePath() + "/Database/BaseConfigs/";
for (int i = 0; i < ui->tableDatabase->rowCount(); i++) {
QString plistFile =
dirpath + ui->tableDatabase->item(i, 0)->text().trimmed();
if (listItemModi.at(i))
mymethod->writePlistComment(
plistFile, ui->tableDatabase->item(i, 1)->text().trimmed());
}
}
void dlgDatabase::keyPressEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_Escape:
close();
break;
case Qt::Key_Return:
break;
case Qt::Key_Backspace:
break;
case Qt::Key_Space:
break;
case Qt::Key_F1:
break;
}
if (event->modifiers() == Qt::ControlModifier) {
if (event->key() == Qt::Key_M) {
this->setWindowState(Qt::WindowMaximized);
}
}
}
void dlgDatabase::on_tableDatabase_cellDoubleClicked(int row, int column) {
get_EFI(row, column, ui->tableDatabase);
}
void dlgDatabase::get_EFI(int row, int column, QTableWidget *table) {
if (column != 0) return;
QString dirpath = strAppExePath + "/Database/BaseConfigs/";
QString file = table->item(row, 0)->text();
if (blDEV) {
if (file == "SampleCustom.plist" || file == "Sample.plist") {
dirpath = mw_one->userDataBaseDir + "BaseConfigs/";
}
}
mw_one->isGetEFI = true;
mw_one->openFile(dirpath + file);
mw_one->isGetEFI = false;
close();
mymethod->generateEFI(file);
}
void dlgDatabase::on_btnFind_clicked() {
QString text = ui->editFind->text().trimmed();
if (text == "") return;
ui->tableDatabase->setFocus();
// tableDatabase->setSelectionMode(QAbstractItemView::MultiSelection);
// tableDatabase->clearSelection();
ui->tableDatabaseFind->setRowCount(0);
int count = 0;
for (int i = 0; i < ui->tableDatabase->rowCount(); i++) {
QString str = ui->tableDatabase->item(i, 0)->text();
QString str1 = str;
str1.replace(".plist", "");
if (str1.toLower().contains(text.toLower())) {
ui->tableDatabaseFind->setRowCount(count + 1);
QTableWidgetItem *newItem1;
newItem1 = new QTableWidgetItem(str);
ui->tableDatabaseFind->setItem(count, 0, newItem1);
count++;
} else {
// tableDatabase->selectRow(i);
}
}
if (count > 0)
ui->tableDatabaseFind->setHidden(false);
else
ui->tableDatabaseFind->setHidden(true);
ui->editFind->setFocus();
ui->lblCount->setText(QString::number(count));
// tableDatabase->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
void dlgDatabase::on_editFind_textChanged(const QString &arg1) {
if (arg1 == "") {
ui->lblCount->setText("0");
ui->tableDatabaseFind->setHidden(true);
return;
}
on_btnFind_clicked();
}
void dlgDatabase::on_editFind_returnPressed() { on_btnFind_clicked(); }
void dlgDatabase::on_tableDatabaseFind_cellDoubleClicked(int row, int column) {
get_EFI(row, column, ui->tableDatabaseFind);
}
void dlgDatabase::on_readoutput() {
// QString str = processPing->readAllStandardOutput();
}
void dlgDatabase::on_readerror() {
QMessageBox::information(0, "Error", processPing->readAllStandardError());
}
void dlgDatabase::on_tableDatabase_itemDoubleClicked(QTableWidgetItem *item) {
Q_UNUSED(item);
}
void dlgDatabase::on_btnIntel_clicked() {
QString qtManulFile =
strAppExePath + "/Database/BaseConfigs/Instructions_Intel.md";
QDesktopServices::openUrl(QUrl::fromLocalFile(qtManulFile));
}
void dlgDatabase::on_btnAMD_clicked() {
QString qtManulFile =
strAppExePath + "/Database/BaseConfigs/Instructions_AMD.md";
QDesktopServices::openUrl(QUrl::fromLocalFile(qtManulFile));
}
void dlgDatabase::on_btnOpenDir_clicked() {
QString dirpath = strAppExePath + "/Database/BaseConfigs/";
QString dir = "file:" + dirpath;
QDesktopServices::openUrl(QUrl(dir, QUrl::TolerantMode));
}
void dlgDatabase::on_btnIntelOnline_clicked() {
QUrl url(QString("https://github.com/ic005k/" + strAppName +
"/blob/master/Database/"
"BaseConfigs/Instructions_Intel.md"));
QDesktopServices::openUrl(url);
}
void dlgDatabase::on_btnAMDOnline_clicked() {
QUrl url(QString("https://github.com/ic005k/" + strAppName +
"/blob/master/Database/"
"BaseConfigs/Instructions_AMD.md"));
QDesktopServices::openUrl(url);
}
void dlgDatabase::on_btnGenerateEFI_clicked() {
if (ui->tableDatabase->hasFocus()) {
if (!ui->tableDatabase->currentIndex().isValid()) return;
int row = ui->tableDatabase->currentRow();
on_tableDatabase_cellDoubleClicked(row, 0);
}
if (ui->tableDatabaseFind->hasFocus()) {
if (!ui->tableDatabaseFind->currentIndex().isValid()) return;
int row = ui->tableDatabaseFind->currentRow();
on_tableDatabaseFind_cellDoubleClicked(row, 0);
}
}
void dlgDatabase::on_tableDatabase_currentItemChanged(
QTableWidgetItem *current, QTableWidgetItem *previous) {
Q_UNUSED(current);
Q_UNUSED(previous);
if (ui->tableDatabase->currentColumn() == 1) {
int row = ui->tableDatabase->currentRow();
listItemModi.removeAt(row);
listItemModi.insert(row, true);
}
}