-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstartoption.cc
84 lines (68 loc) · 2.51 KB
/
startoption.cc
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
#include "startoption.h"
#include <QApplication>
#include <QDir>
#include <QPushButton>
#include <QSysInfo>
#include <QSystemTrayIcon>
#include <QVBoxLayout>
StartOption::StartOption(QWidget *parent)
: QDialog(parent)
{
setWindowTitle("启动选项");
setFixedSize(500, 300);
autoStartup->setFixedWidth(100);
showMainWindow->setFixedWidth(100);
updateCheck->setFixedWidth(100);
if (QSysInfo::productType() == "windows") {
autoStartup->setChecked(settings.value("autostartup", true).toBool());
} else {
autoStartup->setChecked(false);
autoStartup->setDisabled(true);
}
if (QSystemTrayIcon::isSystemTrayAvailable()) {
showMainWindow->setChecked(settings.value("showmainwindow", true).toBool());
} else {
showMainWindow->setChecked(true);
showMainWindow->setDisabled(true);
}
updateCheck->setChecked(settings.value("updatecheck", true).toBool());
QPushButton *saveButton = new QPushButton("保存", this);
connect(saveButton, &QPushButton::clicked, this, &StartOption::save);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(autoStartup, 0, Qt::AlignCenter);
layout->addWidget(showMainWindow, 0, Qt::AlignCenter);
layout->addWidget(updateCheck, 0, Qt::AlignCenter);
layout->addWidget(saveButton, 0, Qt::AlignCenter);
save();
}
void StartOption::showEvent(QShowEvent *event)
{
if (QSysInfo::productType() == "windows") {
autoStartup->setChecked(settings.value("autostartup", true).toBool());
}
if (QSystemTrayIcon::isSystemTrayAvailable()) {
showMainWindow->setChecked(settings.value("showmainwindow", true).toBool());
}
QWidget::showEvent(event);
}
void StartOption::save()
{
if (QSysInfo::productType() == "windows") {
settings.setValue("autostartup", autoStartup->isChecked());
QSettings reg("HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
QString filePath = QCoreApplication::applicationFilePath();
QFileInfo fileInfo(filePath);
QString fileName = fileInfo.fileName();
if (autoStartup->isChecked()) {
reg.setValue(fileName, QDir::toNativeSeparators(filePath));
} else {
reg.remove(fileName);
}
reg.sync();
}
if (QSystemTrayIcon::isSystemTrayAvailable()) {
settings.setValue("showmainwindow", showMainWindow->isChecked());
}
settings.setValue("updatecheck", updateCheck->isChecked());
close();
}