This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsettingsdialog.cpp
More file actions
122 lines (109 loc) · 4.04 KB
/
settingsdialog.cpp
File metadata and controls
122 lines (109 loc) · 4.04 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
119
120
121
122
#include "settingsdialog.h"
#include "mainwindow.h"
#include "interface/core_commands.h"
#include <QPushButton>
#include <QSettings>
#include <QFileDialog>
#include <QMessageBox>
void SettingsDialog::handleConfigButton()
{
QString fileName = QFileDialog::getExistingDirectory(this, tr("Set Config Directory"),
NULL,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!fileName.isNull())
{
configPath->setText(fileName);
w->getSettings()->setValue("configDirPath", fileName);
}
}
void SettingsDialog::handleAppPathButton()
{
configPath->setText(QCoreApplication::applicationDirPath());
w->getSettings()->setValue("configDirPath", QCoreApplication::applicationDirPath());
}
void SettingsDialog::handleClearConfigButton()
{
configPath->setText("");
w->getSettings()->remove("configDirPath");
}
void SettingsDialog::handleConfigEdit()
{
w->getSettings()->setValue("configDirPath", configPath->text());
}
void SettingsDialog::initStuff()
{
layout = new QGridLayout(this);
QLabel *note = new QLabel("Note: If you change the Config Path, you need to close and re-open simple64-gui before it will take effect.", this);
QLabel *configLabel = new QLabel("Config Dir Path", this);
configPath = new QLineEdit(this);
configPath->setText(w->getSettings()->value("configDirPath").toString());
QPushButton *configButton = new QPushButton("Set Path", this);
connect(configButton, &QPushButton::released, this, &SettingsDialog::handleConfigButton);
connect(configPath, &QLineEdit::editingFinished, this, &SettingsDialog::handleConfigEdit);
QPushButton *appPathButton = new QPushButton("Use Application Path", this);
connect(appPathButton, &QPushButton::released, this, &SettingsDialog::handleAppPathButton);
QPushButton *clearConfigButton = new QPushButton("Clear", this);
connect(clearConfigButton, &QPushButton::released, this, &SettingsDialog::handleClearConfigButton);
configPath->setStyleSheet("border: 1px solid; padding: 10px");
layout->addWidget(note, 0, 0, 1, -1);
layout->addWidget(configLabel, 1, 0);
layout->addWidget(configPath, 1, 1);
layout->addWidget(configButton, 1, 2);
layout->addWidget(appPathButton, 1, 3);
layout->addWidget(clearConfigButton, 1, 4);
#ifdef CONFIG_DIR_PATH
configPath->setEnabled(false);
configButton->setEnabled(false);
clearConfigButton->setEnabled(false);
#endif
#ifdef PLUGIN_DIR_PATH
QString pluginPath = PLUGIN_DIR_PATH;
#else
QString pluginPath = QCoreApplication::applicationDirPath();
#endif
QDir PluginDir(pluginPath);
QStringList Filter;
Filter.append("");
QStringList current;
QLabel *inputLabel = new QLabel("Input Plugin", this);
layout->addWidget(inputLabel, 5, 0);
QComboBox *inputChoice = new QComboBox(this);
Filter.replace(0, "*-input-*");
current = PluginDir.entryList(Filter);
inputChoice->addItems(current);
QString qtInputPlugin = w->getSettings()->value("inputPlugin").toString();
int my_index = inputChoice->findText(qtInputPlugin);
if (my_index == -1)
{
inputChoice->addItem(qtInputPlugin);
my_index = inputChoice->findText(qtInputPlugin);
}
inputChoice->setCurrentIndex(my_index);
connect(inputChoice, QOverload<int>::of(&QComboBox::activated),
[=](int index)
{
w->getSettings()->setValue("inputPlugin", inputChoice->itemText(index));
w->updatePlugins();
});
layout->addWidget(inputChoice, 5, 1);
setLayout(layout);
}
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
{
initStuff();
}
void SettingsDialog::closeEvent(QCloseEvent *event)
{
w->getSettings()->sync();
int value;
if (w->getCoreLib())
{
(*CoreDoCommand)(M64CMD_CORE_STATE_QUERY, M64CORE_EMU_STATE, &value);
if (value == M64EMU_STOPPED)
w->resetCore();
}
else
w->resetCore();
event->accept();
}