forked from mrkite/minutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
126 lines (106 loc) · 3.61 KB
/
settings.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
/** Copyright (c) 2013, Sean Kasun */
#include <QtWidgets/QFileDialog>
#include <QSettings>
#include <QDir>
#include "./settings.h"
Settings::Settings(QWidget *parent) : QDialog(parent) {
m_ui.setupUi(this);
setWindowTitle(tr("%1 Settings").arg(qApp->applicationName()));
connect(m_ui.checkBox_DefaultLocation, SIGNAL(toggled(bool)),
this, SLOT(toggleDefaultLocation(bool)));
connect(m_ui.checkBox_DefaultLocation, SIGNAL(toggled(bool)),
m_ui.lineEdit_Location, SLOT(setDisabled(bool)));
connect(this, SIGNAL(locationChanged(const QString)),
m_ui.lineEdit_Location, SLOT(setText(const QString &)));
connect(m_ui.lineEdit_Location, SIGNAL(textChanged(const QString &)),
this, SLOT(pathChanged(const QString &)));
connect(m_ui.pushButton_Browse, SIGNAL(clicked(bool)),
this, SLOT(browseLocation(bool)));
connect(m_ui.checkBox_VerticalDepth, SIGNAL(toggled(bool)),
this, SLOT(toggleVerticalDepth(bool)));
connect(m_ui.checkBox_AutoUpdate, SIGNAL(toggled(bool)),
this, SLOT(toggleAutoUpdate(bool)));
// Load the settings:
QSettings info;
auto useDefault = info.value("usedefault", true).toBool();
if (useDefault) {
mcpath = getDefaultLocation();
}
else {
mcpath = info.value("mcdir", "").toString();
}
autoUpdate = info.value("autoupdate", true).toBool();
verticalDepth = info.value("verticaldepth", true).toBool();
fineZoom = info.value("finezoom", false).toBool();
zoomOut = info.value("zoomout", false).toBool();
// Set the UI to the current settings' values:
m_ui.checkBox_AutoUpdate->setChecked(autoUpdate);
m_ui.lineEdit_Location->setText(mcpath);
m_ui.lineEdit_Location->setDisabled(useDefault);
m_ui.checkBox_DefaultLocation->setChecked(useDefault);
m_ui.checkBox_VerticalDepth->setChecked(verticalDepth);
m_ui.checkBox_fine_zoom->setChecked(fineZoom);
m_ui.checkBox_zoom_out->setChecked(zoomOut);
}
QString Settings::getDefaultLocation()
{
#ifdef Q_OS_MAC
return QDir::homePath() +
QDir::toNativeSeparators("/Library/Application Support/minecraft");
#elif defined Q_OS_WIN32
// pretend to be minecraft
QSettings ini(QSettings::IniFormat, QSettings::UserScope,
".minecraft", "minecraft1");
return QFileInfo(ini.fileName()).absolutePath();
#else
return QDir::homePath() + QDir::toNativeSeparators("/.minecraft");
#endif
}
void Settings::toggleAutoUpdate(bool up) {
autoUpdate = up;
QSettings info;
info.setValue("autoupdate", up);
emit settingsUpdated();
}
void Settings::browseLocation(bool /* on */) {
QString dirName = QFileDialog::getExistingDirectory(this,
tr("Find Minecraft"));
if (!dirName.isEmpty()) {
emit locationChanged(dirName);
}
}
void Settings::pathChanged(const QString &path) {
mcpath = path;
QSettings info;
info.setValue("mcdir", path);
// save settings
emit settingsUpdated();
}
void Settings::toggleDefaultLocation(bool def) {
QSettings info;
info.setValue("usedefault", def);
if (!def) { // we unchecked default.. but we're still technically default
return;
}
emit locationChanged(getDefaultLocation());
}
void Settings::toggleVerticalDepth(bool value) {
verticalDepth = value;
QSettings info;
info.setValue("verticaldepth", value);
emit settingsUpdated();
}
void Settings::on_checkBox_zoom_out_toggled(bool checked)
{
zoomOut = checked;
QSettings info;
info.setValue("zoomout", checked);
emit settingsUpdated();
}
void Settings::on_checkBox_fine_zoom_toggled(bool checked)
{
fineZoom = checked;
QSettings info;
info.setValue("finezoom", checked);
emit settingsUpdated();
}