-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstartoption.cc
More file actions
109 lines (92 loc) · 3.49 KB
/
Copy pathstartoption.cc
File metadata and controls
109 lines (92 loc) · 3.49 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
#include "startoption.h"
#include <QApplication>
#include <QDir>
#include <QLabel>
#include <QPushButton>
#include <QSysInfo>
#include <QSystemTrayIcon>
#include <QVBoxLayout>
static QWidget *wrapOption(QCheckBox *checkBox, const QString &hint)
{
QWidget *wrapper = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(wrapper);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);
layout->addWidget(checkBox);
QLabel *hintLabel = new QLabel(hint, wrapper);
hintLabel->setObjectName("dialogHint");
hintLabel->setWordWrap(true);
hintLabel->setContentsMargins(26, 0, 0, 0);
layout->addWidget(hintLabel);
return wrapper;
}
StartOption::StartOption(QWidget *parent)
: FramelessDialog("Startup", parent)
{
resize(440, 340);
setMinimumSize(400, 300);
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());
QLabel *subtitle = new QLabel("Configure how Cake behaves on startup.", this);
subtitle->setObjectName("dialogSubtitle");
subtitle->setWordWrap(true);
QPushButton *saveButton = new QPushButton("Save", this);
saveButton->setObjectName("primaryButton");
saveButton->setMaximumWidth(100);
connect(saveButton, &QPushButton::clicked, this, &StartOption::save);
QVBoxLayout *layout = contentLayout();
layout->setContentsMargins(32, 20, 32, 20);
layout->setSpacing(8);
layout->addWidget(subtitle);
layout->addSpacing(8);
layout->addWidget(wrapOption(autoStartup, "Automatically launch Cake when you sign in to your system."));
layout->addSpacing(4);
layout->addWidget(wrapOption(showMainWindow, "Display the main window when Cake starts."));
layout->addSpacing(4);
layout->addWidget(wrapOption(updateCheck, "Automatically check for new versions on startup."));
layout->addStretch();
layout->addWidget(saveButton, 0, Qt::AlignRight);
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();
}