-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_dialog.cpp
More file actions
167 lines (135 loc) · 4.54 KB
/
Copy pathsettings_dialog.cpp
File metadata and controls
167 lines (135 loc) · 4.54 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Renamifier's settings dialog.
* Copyright (c) 2026 Benjamin Johnson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cstdlib> // for std::getenv()
#include <QtCore>
#include <QtWidgets>
#include "settings_dialog.h"
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle("Options");
mainLayout = new QVBoxLayout(this);
setLayout(mainLayout);
createHelperSettings();
createButtons();
loadSettings();
}
void SettingsDialog::accept()
{
saveSettings();
QDialog::accept();
}
void SettingsDialog::createHelperSettings()
{
QString initialBrowseDir;
QString gsFilter;
QString gxpsFilter;
#ifdef Q_OS_WIN
initialBrowseDir = std::getenv("ProgramFiles");
gsFilter = "Ghostscript executables (gswin??c.exe)";
gxpsFilter = "GhostXPS executables (gxpswin??.exe)";
#else
initialBrowseDir = "/usr/bin";
gsFilter = "Ghostscript executables (gs)";
gxpsFilter = "GhostXPS executables (gxps)";
#endif
helperGroupBox = new QGroupBox("Helper Programs", this);
mainLayout->addWidget(helperGroupBox);
helperLayout = new QGridLayout(helperGroupBox);
helperLayout->setColumnStretch(1, 1);
helperGroupBox->setLayout(helperLayout);
gsLabel = new QLabel("Ghostscript:", helperGroupBox);
helperLayout->addWidget(gsLabel, 0, 0);
gsPathEdit = new PathEdit(helperGroupBox);
gsPathEdit->setDir(initialBrowseDir);
gsPathEdit->setFilter(gsFilter);
gsLabel->setBuddy(gsPathEdit);
helperLayout->addWidget(gsPathEdit, 0, 1);
gxpsLabel = new QLabel("GhostXPS:", helperGroupBox);
helperLayout->addWidget(gxpsLabel, 1, 0);
gxpsPathEdit = new PathEdit(helperGroupBox);
gxpsPathEdit->setDir(initialBrowseDir);
gxpsPathEdit->setFilter(gxpsFilter);
gxpsLabel->setBuddy(gxpsPathEdit);
helperLayout->addWidget(gxpsPathEdit, 1, 1);
connect(gsPathEdit, &PathEdit::returnPressed,
this, &SettingsDialog::accept);
connect(gxpsPathEdit, &PathEdit::returnPressed,
this, &SettingsDialog::accept);
}
void SettingsDialog::createButtons()
{
buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(); // right-align buttons
mainLayout->addLayout(buttonLayout);
buttonOK = new QPushButton("OK", this);
buttonOK->setDefault(true);
buttonLayout->addWidget(buttonOK);
buttonCancel = new QPushButton("Cancel", this);
buttonLayout->addWidget(buttonCancel);
connect(buttonOK, &QPushButton::clicked,
this, &SettingsDialog::accept);
connect(buttonCancel, &QPushButton::clicked,
this, &SettingsDialog::reject);
}
void SettingsDialog::loadSettings()
{
QSettings settings;
gsPathEdit->setPath(settings.value("helpers/gs").toString());
gxpsPathEdit->setPath(settings.value("helpers/gxps").toString());
}
void SettingsDialog::saveSettings()
{
QSettings settings;
QString gsPath = gsPathEdit->path();
if (gsPath.isEmpty())
settings.remove("helpers/gs");
else
settings.setValue("helpers/gs", gsPath);
QString gxpsPath = gxpsPathEdit->path();
if (gxpsPath.isEmpty())
settings.remove("helpers/gxps");
else
settings.setValue("helpers/gxps", gxpsPath);
}
PathEdit::PathEdit(QWidget *parent)
: QWidget(parent)
{
layout = new QHBoxLayout(this);
setLayout(layout);
lineEdit = new QLineEdit(this);
layout->addWidget(lineEdit, 1);
connect(lineEdit, &QLineEdit::returnPressed,
this, &PathEdit::returnPressed);
browseButton = new QPushButton("Browse...", this);
layout->addWidget(browseButton);
connect(browseButton, &QPushButton::clicked,
this, &PathEdit::browse);
}
void PathEdit::browse()
{
QString fileName = QFileDialog::getOpenFileName(
this,
"Browse",
dir_,
filter_);
if (!fileName.isEmpty())
lineEdit->setText(fileName);
lineEdit->setFocus();
}