-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathconfigwindow.cpp
More file actions
248 lines (210 loc) · 8.83 KB
/
configwindow.cpp
File metadata and controls
248 lines (210 loc) · 8.83 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/****************************************************************************
**
** Copyright (C) 2006-2008 Urs Wolfer <uwolfer @ fwo.ch>
**
** This file is part of QtEmu.
**
** 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 Library General Public License
** along with this library; see the file COPYING.LIB. If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
****************************************************************************/
#include "configwindow.h"
#include "config.h"
#include <QTextEdit>
#include <QComboBox>
#include <QSettings>
#include <QBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QGroupBox>
#include <QCheckBox>
#include <QFileDialog>
#include <QCoreApplication>
ConfigWindow::ConfigWindow(const QString &myMachinesPathParent, int tabPosition, QWidget *parent)
: QDialog((QWidget*)parent)
{
myMachinesPath = myMachinesPathParent;
setWindowTitle(tr("QtEmu Config"));
resize(400, 200);
setSizeGripEnabled(true);
QGroupBox *generalGroupBox = new QGroupBox(tr("General"), this);
QLabel *myMachinesPathLabel = new QLabel(tr("Default \"MyMachines\" Path:"));
myMachinePathLineEdit = new QLineEdit(myMachinesPath);
myMachinesPathLabel->setBuddy(myMachinePathLineEdit);
QSettings settings("QtEmu", "QtEmu");
QString iconTheme = settings.value("iconTheme", "oxygen").toString();
QPushButton *pathSelectButton = new QPushButton(QIcon(":/images/" + iconTheme + "/open.png"), QString());
connect(pathSelectButton, SIGNAL(clicked()), this, SLOT(setNewPath()));
QHBoxLayout *pathLayout = new QHBoxLayout;
pathLayout->addWidget(myMachinePathLineEdit);
pathLayout->addWidget(pathSelectButton);
QLabel *tabPositionLabel = new QLabel(tr("Tabbar position:"));
comboTabPosition = new QComboBox;
comboTabPosition->addItem(tr("Top"));
comboTabPosition->addItem(tr("Bottom"));
comboTabPosition->addItem(tr("Left"));
comboTabPosition->addItem(tr("Right"));
comboTabPosition->setCurrentIndex(tabPosition);
tabPositionLabel->setBuddy(comboTabPosition);
QLabel *iconThemeLabel = new QLabel(tr("Icon theme (*):"));
comboIconTheme = new QComboBox;
comboIconTheme->addItem("Oxygen");
comboIconTheme->addItem("Crystal");
comboIconTheme->setCurrentIndex(tabPosition);
iconThemeLabel->setBuddy(comboIconTheme);
QLabel *languageLabel = new QLabel(tr("Language (*):"));
languagePosition = new QComboBox; //make the language name not tranlatable (no tr()!) and write them translated
languagePosition->addItem("English");
languagePosition->addItem("Deutsch");
languagePosition->addItem(QString::fromUtf8("Türkçe"));
languagePosition->addItem(QString::fromUtf8("Русский"));
languagePosition->addItem(QString::fromUtf8("Česky"));
languagePosition->addItem(QString::fromUtf8("Español"));
languagePosition->addItem(QString::fromUtf8("Français"));
languagePosition->addItem(QString::fromUtf8("Italiano"));
languagePosition->addItem(QString::fromUtf8("Português do Brasil"));
languagePosition->addItem(QString::fromUtf8("Polski"));
QString language = settings.value("language", QString(QLocale::system().name())).toString();
int index;
if (language == "en")
index = 0;
else if (language == "de")
index = 1;
else if (language == "tr")
index = 2;
else if (language == "ru")
index = 3;
else if (language == "cz")
index = 4;
else if (language == "es")
index = 5;
else if (language == "fr")
index = 6;
else if (language == "it")
index = 7;
else if (language == "pt-BR")
index = 8;
else if (language == "pl")
index = 9;
else
index = 0;
languagePosition->setCurrentIndex(index);
connect(languagePosition, SIGNAL(currentIndexChanged(int)), this, SLOT(languageChange(int)));
languageLabel->setBuddy(languagePosition);
QLabel *restartLabel = new QLabel(tr("<i>(*) Change requires restart of QtEmu.</i>"));
QGridLayout *generalLayout = new QGridLayout;
generalLayout->addWidget(myMachinesPathLabel, 1, 0);
generalLayout->addLayout(pathLayout, 1, 1);
generalLayout->addWidget(tabPositionLabel, 2, 0);
generalLayout->addWidget(comboTabPosition, 2, 1);
generalLayout->addWidget(iconThemeLabel, 3, 0);
generalLayout->addWidget(comboIconTheme, 3, 1);
generalLayout->addWidget(languageLabel, 4, 0);
generalLayout->addWidget(languagePosition, 4, 1);
generalLayout->addWidget(restartLabel, 5, 0);
generalGroupBox->setLayout(generalLayout);
QGroupBox *qemuGroupBox = new QGroupBox(tr("Start and stop QEMU"), this);
QLabel *beforeStartExeLabel = new QLabel(tr("Execute before start:"));
beforeStartExeTextEdit = new QTextEdit;
beforeStartExeLabel->setBuddy(beforeStartExeTextEdit);
QLabel *commandLabel = new QLabel(tr("QEMU start command:"));
commandLineEdit = new QLineEdit;
commandLabel->setBuddy(commandLineEdit);
QLabel *afterExitExeLabel = new QLabel(tr("Execute after exit:"));
afterExitExeTextEdit = new QTextEdit;
afterExitExeLabel->setBuddy(afterExitExeTextEdit);
QGridLayout *qemuLayout = new QGridLayout;
qemuLayout->addWidget(beforeStartExeLabel, 1, 0, Qt::AlignTop);
qemuLayout->addWidget(beforeStartExeTextEdit, 1, 1);
qemuLayout->addWidget(commandLabel, 2, 0);
qemuLayout->addWidget(commandLineEdit, 2, 1);
qemuLayout->addWidget(afterExitExeLabel, 4, 0, Qt::AlignTop);
qemuLayout->addWidget(afterExitExeTextEdit, 4, 1);
qemuLayout->setRowStretch(4, 1);
qemuGroupBox->setLayout(qemuLayout);
QPushButton *okButton = new QPushButton(tr("OK"));
connect(okButton, SIGNAL(clicked()), this, SLOT(writeSettings()));
QPushButton *cancelButton = new QPushButton(tr("Cancel"));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(okButton);
buttonsLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(generalGroupBox);
mainLayout->addWidget(qemuGroupBox);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
loadSettings();
}
void ConfigWindow::setNewPath()
{
QString newPath = QFileDialog::getExistingDirectory(this, tr("Select a folder for \"MyMachines\""),
myMachinesPath);
if (!newPath.isEmpty())
myMachinePathLineEdit->setText(newPath);
}
void ConfigWindow::languageChange(int index)
{
QSettings settings("QtEmu", "QtEmu");
QString languageString;
switch(index)
{
case 0: languageString = "en";
break;
case 1: languageString = "de";
break;
case 2: languageString = "tr";
break;
case 3: languageString = "ru";
break;
case 4: languageString = "cz";
break;
case 5: languageString = "es";
break;
case 6: languageString = "fr";
break;
case 7: languageString = "it";
break;
case 8: languageString = "pt-BR";
break;
case 9: languageString = "pl";
break;
default: languageString = "en";
}
settings.setValue("language", languageString);
}
void ConfigWindow::loadSettings()
{
QSettings settings("QtEmu", "QtEmu");
beforeStartExeTextEdit->setPlainText(settings.value("beforeStart").toString());
#ifndef Q_OS_WIN32
commandLineEdit->setText(settings.value("command", "qemu").toString());
#elif defined(Q_OS_WIN32)
commandLineEdit->setText(settings.value("command", QCoreApplication::applicationDirPath() + "/qemu/qemu.exe").toString());
#endif
afterExitExeTextEdit->setPlainText(settings.value("afterExit").toString());
comboIconTheme->setCurrentIndex(comboIconTheme->findText(settings.value("iconTheme", "oxygen").toString(), Qt::MatchContains));
}
void ConfigWindow::writeSettings()
{
QSettings settings("QtEmu", "QtEmu");
settings.setValue("beforeStart", beforeStartExeTextEdit->toPlainText());
settings.setValue("command", commandLineEdit->text());
settings.setValue("afterExit", afterExitExeTextEdit->toPlainText());
settings.setValue("iconTheme", comboIconTheme->currentText().toLower());
accept();
}