-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingswindow.cpp
More file actions
118 lines (96 loc) · 2.94 KB
/
settingswindow.cpp
File metadata and controls
118 lines (96 loc) · 2.94 KB
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
#include "settingswindow.h"
#include "ui_settingswindow.h"
// 按道理可以把SettingsWindow、AdvancedKeyboard抽象为一个
// 一起共享主窗口的数据,但是懒得重构了。头疼。
SettingsWindow::SettingsWindow(GlobalConfig *config ,QWidget *parent)
: QWidget(parent),
ui(new Ui::SettingsWindow),
m_lastPos(QPoint(0, 0)),
conf(config)
{
ui->setupUi(this);
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint|
Qt::Tool);
proc = new ExternalProcess(this);
connect(proc, &ExternalProcess::finished, this,
[this](int exitCode, QProcess::ExitStatus exitStatus, const QString &output){
emit settingProcessFinished(exitCode, exitStatus, output);
});
}
SettingsWindow::~SettingsWindow()
{
delete ui;
}
void SettingsWindow::changeEvent(QEvent *event){
if (event->type() == QEvent::LanguageChange) {
ui->retranslateUi(this); // 自动更新所有文本!
}
}
QString SettingsWindow::config() const
{
return ui->edConfig->toPlainText();
}
void SettingsWindow::setConfig(const QString &config)
{
ui->edConfig->setText(config);
}
void SettingsWindow::closeEvent(QCloseEvent *event)
{
m_lastPos = pos();
emit closed();
QWidget::closeEvent(event);
}
void SettingsWindow::showEvent(QShowEvent *event)
{
// if (!m_lastPos.isNull()) {
// move(m_lastPos);
// } else if (parentWidget()) {
// move(parentWidget()->geometry().center() - rect().center());
// }
emit configRequested();
QWidget::showEvent(event);
}
void SettingsWindow::on_btSaveOnly_clicked()
{
emit configSaved(ui->edConfig->toPlainText());
emit configRequested();
}
void SettingsWindow::on_btSaveClose_clicked()
{
emit configSaved(ui->edConfig->toPlainText());
emit configRequested();
close();
}
void SettingsWindow::on_btClose_clicked()
{
close();
}
void SettingsWindow::on_btReloadConfig_clicked()
{
emit configRequested();
}
void SettingsWindow::on_btInstallSndcpy_clicked()
{
QString sndcpy = conf->sndcpyApkPath();
QStringList args;
if (!conf->deviceSerial().isEmpty()) {
args << conf->deviceSerial(); // 只在有设备号时添加
}
args << "install" << sndcpy;
emit sendTrayMessage(tr("正在开始安装。请等待..."));
ExternalProcess *p;
p = new ExternalProcess(this);
p->set(conf->adbPath(), args, this);
p->run();
connect(p, &ExternalProcess::finished, this,
[this](int exitCode, QProcess::ExitStatus exitStatus, const QString &output){
if(exitCode != 0){
emit sendTrayMessage(tr("安装失败%1:%2").arg(exitCode).arg(output));
}
else
{
emit sendTrayMessage(tr("安装成功。"));
}
});
}