-
Notifications
You must be signed in to change notification settings - Fork 0
/
otherspage.cpp
413 lines (379 loc) · 13.7 KB
/
otherspage.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#include "otherspage.h"
#include "ui_otherspage.h"
#include "texthelper.h"
#include <QMessageBox>
#include <QLabel>
#include <QScrollArea>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QPixmap>
#include <QImage>
#include <QLineEdit>
#include <QSpacerItem>
#include <QDebug>
#include <QFileDialog>
#include <QDir>
#include <QCheckBox>
OthersPage::OthersPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::OthersPage)
{
ui->setupUi(this);
initWidget();
disableWidget();
}
OthersPage::~OthersPage()
{
delete ui;
}
void OthersPage::initWidget()
{
scroll = new QScrollArea();
scroll->setWidgetResizable(true);
w = new QWidget(scroll);
scroll->setWidget(w);
gridLayout = new QGridLayout(w);
lbl_wallpaper = new QLabel("默认壁纸:");
lbl_img = new QLabel();
le_wallpaper = new QLineEdit();
le_wallpaper->setFocusPolicy(Qt::NoFocus);
btn_wallper = new QPushButton(tr("选择默认壁纸"));
btn_wallper->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(btn_wallper, SIGNAL(clicked(bool)), this, SLOT(selectWallpaper()));
lbl_extFiles = new QLabel("额外打包数据:");
le_extFiles = new QLineEdit();
le_extFiles->setFocusPolicy(Qt::NoFocus);
btn_extFiles = new QPushButton("选择额外打包数据");
connect(btn_extFiles, SIGNAL(clicked(bool)), this, SLOT(selectExtFiles()));
lbl_logo = new QLabel("开机logo");
lbl_img_logo = new QLabel();
le_logo =new QLineEdit();
le_logo->setFocusPolicy(Qt::NoFocus);
btn_logo = new QPushButton("选择开机logo");
connect(btn_logo, SIGNAL(clicked()), this, SLOT(selectLogo()));
lbl_preinstall = new QLabel("可卸载APK");
le_preinstall = new QLineEdit();
btn_preinstall = new QPushButton("选择apk拷贝目录");
connect(btn_preinstall, SIGNAL(clicked()), this, SLOT(selectPreinstall()));
lbl_system = new QLabel("不可卸载APK");
le_system = new QLineEdit();
btn_system = new QPushButton("选择apk拷贝目录");
connect(btn_system, SIGNAL(clicked()), this, SLOT(selectSystemApp()));
lbl_battery = new QLabel("电池参数:");
le_battery = new QLineEdit();
ckb_battery = new QCheckBox("修改电池参数");
connect(ckb_battery, SIGNAL(clicked()), this, SLOT(enableBatteryLineedit()));
QImage img;
img.load(":/new/img/img/black.png");
QImage result = img.scaled(200,200);
lbl_img->setPixmap(QPixmap::fromImage(result));
// QImage logo_img;
// img.load(":/new/img/img/black.png");
// QImage logo_sml = logo_img.scaled(200,200);
lbl_img_logo->setPixmap(QPixmap::fromImage(result));
gridLayout->setColumnStretch(1,3);
gridLayout->addWidget(lbl_wallpaper, 0, 0, 1, 1);
gridLayout->addWidget(lbl_img, 0, 1, 1, 2);
gridLayout->addItem(new QSpacerItem(40,20), 0, 2);
gridLayout->addWidget(le_wallpaper, 1, 0, 1, 3);
gridLayout->addWidget(btn_wallper, 1, 3, 1, 1);
gridLayout->addWidget(lbl_extFiles,2, 0);
gridLayout->addWidget(le_extFiles, 2, 1, 1, 3);
gridLayout->addWidget(btn_extFiles, 2, 3);
gridLayout->addWidget(lbl_logo, 3, 0);
gridLayout->addWidget(lbl_img_logo, 3, 1);
gridLayout->addWidget(le_logo, 4, 0, 1, 3);
gridLayout->addWidget(btn_logo, 4, 3);
gridLayout->addWidget(lbl_preinstall, 5, 0);
gridLayout->addWidget(le_preinstall, 5, 1, 1, 3);
gridLayout->addWidget(btn_preinstall, 5, 3);
gridLayout->addWidget(lbl_system, 6, 0);
gridLayout->addWidget(le_system, 6, 1, 1, 3);
gridLayout->addWidget(btn_system, 6, 3);
gridLayout->addWidget(lbl_battery, 7, 0);
gridLayout->addWidget(le_battery, 7, 1, 1, 2);
gridLayout->addWidget(ckb_battery, 7, 3);
gridLayout->addItem(new QSpacerItem(20,40, QSizePolicy::Expanding, QSizePolicy::Expanding), 8, 0);
// gridLayout->setSpacing(20);
vLayout = new QVBoxLayout(this);
vLayout->addWidget(scroll);
}
void OthersPage::selectWallpaper()
{
QString def_wallpaper_path = QFileDialog::getOpenFileName(this, "选择默认壁纸", "/home/heyuan", "图片文件(*jpg)");
if(def_wallpaper_path == "")
return;
le_wallpaper->setText(def_wallpaper_path);
QImage img(def_wallpaper_path);
QImage res = img.scaled(200,200);
lbl_img->setPixmap(QPixmap::fromImage(res));
}
void OthersPage::loadCfg()
{
if(Global::srcPath == "")
{
return;
}
enableWidget();
QString pathWallpaper600Overlay = Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-sw600dp-nodpi/default_wallpaper.jpg";
wallpaper_600dp = Global::srcPath + "/frameworks/base/core/res/res/drawable-sw600dp-nodpi/default_wallpaper.jpg";
wallpaper_720dp = Global::srcPath + "/frameworks/base/core/res/res/drawable-sw720dp-nodpi/default_wallpaper.jpg";
wallpaper_nodp = Global::srcPath + "/frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.jpg";
QString logo_path = Global::srcPath + "/" + Global::devicePath + "/boot_logo/splash_screen.jpg";
if(!QFile::exists(pathWallpaper600Overlay))
{
QImage img;
img.load(wallpaper_600dp);
QImage result = img.scaled(200,200);
lbl_img->setPixmap(QPixmap::fromImage(result));
}else
{
QImage img;
img.load(pathWallpaper600Overlay);
QImage result = img.scaled(200,200);
lbl_img->setPixmap(QPixmap::fromImage(result));
}
if(!QFile::exists(logo_path))
{
QMessageBox::warning(this, tr("警告~~"), tr("logo图片不存在。。"));
}else
{
QImage img;
img.load(logo_path);
QImage res = img.scaled(200,200);
lbl_img_logo->setPixmap(QPixmap::fromImage(res));
}
TextHelper textHelper;
QString strBattery = textHelper.readBatteryPar();
if(strBattery.isEmpty())
{
QMessageBox::warning(this, tr("警告~~"), tr("电池参数读取错误,请检查dts里电池参数格式是否正确。。"));
}else
{
le_battery->setText(strBattery);
}
}
void OthersPage::saveCfg()
{
copyExtFiles();
copyDefWallpaper();
copyLogo();
copyPreinstall();
copySystemApp();
writeBatterypar(le_battery->text());
QMessageBox::information(this, tr("Info"), tr("此页面选项修改完毕"));
}
void OthersPage::selectExtFiles()
{
QString extFilesPath = QFileDialog::getExistingDirectory(this);
if(extFilesPath == "")
return;
le_extFiles->setText(extFilesPath);
}
void OthersPage::copyDefWallpaper()
{
if(le_wallpaper->text() == "")
{
return;
}
QString pathWallpaper600Overlay = Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-sw600dp-nodpi/default_wallpaper.jpg";
QString pathWallpaper720Overlay = Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-sw720dp-nodpi/default_wallpaper.jpg";
QString pathWallpaperOverlay = Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.jpg";
QFile::remove(pathWallpaper600Overlay);
QFile::remove(pathWallpaper720Overlay);
QFile::remove(pathWallpaperOverlay);
QDir *dir = new QDir(Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res");
dir->mkpath(Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-sw600dp-nodpi");
dir->mkpath(Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-sw720dp-nodpi");
dir->mkpath(Global::srcPath + "/" + Global::overlayPath + "/frameworks/base/core/res/res/drawable-nodpi");
QFile::copy(le_wallpaper->text(), pathWallpaper600Overlay);
QFile::copy(le_wallpaper->text(), pathWallpaper720Overlay);
QFile::copy(le_wallpaper->text(), pathWallpaperOverlay);
}
void OthersPage::copyExtFiles()
{
if(le_extFiles->text() == "")
{
qDebug() << "no extFiles need to copy";
return;
}
QDir *extDir = new QDir(le_extFiles->text());
QStringList fileList = extDir->entryList();
if(fileList.length() < 3)
{
QMessageBox::warning(this, tr("提示信息~~"), tr("额外打包目录空~~"));
return;
}
QDir dir(Global::srcPath + "/" + Global::devicePath);
qDebug() << Global::srcPath + "/" + Global::devicePath;
if(!dir.exists(Global::srcPath + "/" + Global::devicePath + "/presentation_file"))
{
dir.mkdir("presentation_file");
}
copyDir(le_extFiles->text(), Global::srcPath + "/" + Global::devicePath + "/presentation_file", false);
}
void OthersPage::selectLogo()
{
QString def_logo = QFileDialog::getOpenFileName(this, "选择开机logo", "/home/heyuan", "图片文件(*jpg)");
if(def_logo == "")
return;
le_logo->setText(def_logo);
QImage img(def_logo);
QImage res = img.scaled(200,200);
lbl_img_logo->setPixmap(QPixmap::fromImage(res));
}
void OthersPage::selectPreinstall()
{
QString preinstallPath = QFileDialog::getExistingDirectory(this);
if(preinstallPath == "")
return;
le_preinstall->setText(preinstallPath);
}
void OthersPage::selectSystemApp()
{
QString systemAppPath = QFileDialog::getExistingDirectory(this);
if(systemAppPath == "")
return;
le_system->setText(systemAppPath);
}
void OthersPage::enableBatteryLineedit()
{
if(ckb_battery->isChecked())
{
lbl_battery->setEnabled(true);
le_battery->setEnabled(true);
}else
{
lbl_battery->setDisabled(true);
le_battery->setDisabled(true);
}
}
bool OthersPage::copyDir(const QString &source, const QString &destination, bool override)
{
QDir directory(source);
if (!directory.exists())
{
return false;
}
QString srcPath = QDir::toNativeSeparators(source);
if (!srcPath.endsWith(QDir::separator()))
srcPath += QDir::separator();
QString dstPath = QDir::toNativeSeparators(destination);
if (!dstPath.endsWith(QDir::separator()))
dstPath += QDir::separator();
bool error = false;
QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
for (QStringList::size_type i=0; i != fileNames.size(); ++i)
{
QString fileName = fileNames.at(i);
QString srcFilePath = srcPath + fileName;
QString dstFilePath = dstPath + fileName;
QFileInfo fileInfo(srcFilePath);
if (fileInfo.isFile() || fileInfo.isSymLink())
{
if (override)
{
QFile::setPermissions(dstFilePath, QFile::WriteOwner);
}
QFile::copy(srcFilePath, dstFilePath);
}
else if (fileInfo.isDir())
{
QDir dstDir(dstFilePath);
dstDir.mkpath(dstFilePath);
if (!copyDir(srcFilePath, dstFilePath, override))
{
error = true;
}
}
}
return !error;
}
void OthersPage::disableWidget()
{
QList<QObject *> list = w->children();
for(int i = 1; i < list.count(); i++)
{
QWidget *w = qobject_cast<QWidget *>(list.at(i));
w->setDisabled(true);
}
}
void OthersPage::enableWidget()
{
QList<QObject *> list = w->children();
for(int i = 1; i < list.count(); i++)
{
QWidget *w = qobject_cast<QWidget *>(list.at(i));
w->setEnabled(true);
}
le_battery->setDisabled(true);
}
void OthersPage::copyLogo()
{
if(le_logo->text() == "")
{
return;
}
QString logo_path = Global::srcPath + "/" + Global::devicePath + "/boot_logo/splash_screen.jpg";
if(!QFile::exists(logo_path))
{
QFile::copy(le_logo->text(), logo_path);
}else
{
if(!QFile::remove(logo_path))
{
QMessageBox::critical(this, tr(" 错误"), tr("删除原始logo失败,请检查路径是否有写权限或logo被其他软件占用"));
return;
}else
{
QFile::copy(le_logo->text(), logo_path);
}
}
}
void OthersPage::copyPreinstall()
{
QString preinstallPath = le_preinstall->text();
if(preinstallPath == "")
return;
QDir *dir = new QDir(preinstallPath);
QStringList fileList = dir->entryList();
if(!dir->exists(Global::srcPath + "/" + Global::devicePath + "/preinstall_data_app"))
{
dir->mkpath(Global::srcPath + "/" + Global::devicePath + "/preinstall_data_app");
}
for(int i = 2; i < fileList.length(); i++)
{
QFile::copy(preinstallPath + "/" + fileList[i], Global::srcPath + "/" + Global::devicePath + "/preinstall_data_app/" + fileList[i].trimmed());
}
}
void OthersPage::copySystemApp()
{
QString systemAppPath = le_system->text();
if(systemAppPath == "")
return;
QDir *dir = new QDir(systemAppPath);
QStringList fileList = dir->entryList();
if(!dir->exists(Global::srcPath + "/" + Global::devicePath + "/preinstall_2_system_app"))
{
dir->mkpath(Global::srcPath + "/" + Global::devicePath + "/preinstall_2_system_app");
}
for(int i = 2; i < fileList.length(); i++)
{
QFile::copy(systemAppPath + "/" + fileList[i], Global::srcPath + "/" + Global::devicePath + "/preinstall_2_system_app/" + fileList[i].trimmed());
}
}
void OthersPage::writeBatterypar(QString batteryPar)
{
QStringList strList= batteryPar.trimmed().split(" ");
if(strList.length() != 21)
{
QMessageBox::warning(this, "警告!!", "电池参数个数不对,应为21个");
return;
}
TextHelper textHelper;
if(!textHelper.writeBatteryPar(batteryPar))
{
QMessageBox::critical(this, "错误!!", "电池参数写入失败");
}
}