-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.cpp
executable file
·49 lines (43 loc) · 1.41 KB
/
preferences.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
#include "preferences.h"
#include "ui_preferences.h"
#include <QFileInfo>
#include <QFileDialog>
#include <QSettings>
QString selectFile(const QString& path, QWidget* parent) {
QString dir;
if (path.isEmpty()) {
#ifdef Q_OS_LINUX
dir = QString("/usr/bin");
#endif
}
else {
QFileInfo fi(path);
dir = fi.absoluteDir().path();
}
QString fN = QFileDialog::getOpenFileName(parent, Preferences::tr("Select Executable Path"), dir, QString(), 0, 0);
if (fN.isEmpty())
return path;
return fN;
}
Preferences::Preferences(QWidget *parent) :
QDialog(parent),
ui(new Ui::Preferences)
{
ui->setupUi(this);
QSettings s;
ui->txtKindlegen->setText(s.value("KINDLEGEN_PATH").toString());
ui->txtPython->setText(s.value("PYTHON_PATH").toString());
ui->chkEBOK->setChecked(s.value("EBOK_TAG", false).toBool());
connect(ui->btnKindlegen, &QPushButton::clicked, [=]() { ui->txtKindlegen->setText(selectFile(ui->txtKindlegen->text(), this)); });
connect(ui->btnPython, &QPushButton::clicked, [=]() { ui->txtPython->setText(selectFile(ui->txtPython->text(), this)); });
}
Preferences::~Preferences() {
delete ui;
}
void Preferences::accept() {
QSettings s;
s.setValue("KINDLEGEN_PATH", ui->txtKindlegen->text());
s.setValue("PYTHON_PATH", ui->txtPython->text());
s.setValue("EBOK_TAG", ui->chkEBOK->isChecked());
QDialog::accept();
}