A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "preferencesdialog.h"
23#include "ui_preferencesdialog.h"
24#include "fontdownloader.h"
25#include "targetdownloader.h"
26
27#include <QSettings>
28#include <QColorDialog>
29#include <QFileDialog>
30
31PreferencesDialog::PreferencesDialog(QWidget *parent) :
32 QDialog(parent),
33 ui(new Ui::PreferencesDialog)
34{
35 ui->setupUi(this);
36 setupUI();
37 loadSettings();
38}
39
40PreferencesDialog::~PreferencesDialog()
41{
42 delete ui;
43}
44
45void PreferencesDialog::loadSettings()
46{
47 loadColors();
48 loadFont();
49 loadRender();
50
51 QSettings settings;
52 settings.beginGroup("CodeEditor");
53 ui->completionBox->setChecked(settings.value("completeSyntax",
54 true).toBool());
55 settings.endGroup();
56}
57
58void PreferencesDialog::loadColors()
59{
60
61 QSettings settings;
62
63 /* The list of buttons from the SkinHighlighter group */
64
65 settings.beginGroup("SkinHighlighter");
66
67 commentColor = settings.value("commentColor",
68 QColor(0, 180, 0)).value<QColor>();
69 setButtonColor(ui->commentButton, commentColor);
70
71 escapedColor = settings.value("escapedColor",
72 QColor(120,120,120)).value<QColor>();
73 setButtonColor(ui->escapedButton, escapedColor);
74
75 conditionalColor = settings.value("conditionalColor",
76 QColor(0, 0, 180)).value<QColor>();
77 setButtonColor(ui->conditionalButton, conditionalColor);
78
79 tagColor = settings.value("tagColor",
80 QColor(180, 0, 0)).value<QColor>();
81 setButtonColor(ui->tagButton, tagColor);
82
83 settings.endGroup();
84
85 /* Buttons from the editor group */
86 settings.beginGroup("SkinDocument");
87
88 fgColor = settings.value("fgColor", QColor(Qt::black)).value<QColor>();
89 setButtonColor(ui->fgButton, fgColor);
90
91 bgColor = settings.value("bgColor", QColor(Qt::white)).value<QColor>();
92 setButtonColor(ui->bgButton, bgColor);
93
94 errorColor = settings.value("errorColor", QColor(Qt::red)).value<QColor>();
95 setButtonColor(ui->errorButton, errorColor);
96
97 settings.endGroup();
98}
99
100void PreferencesDialog::loadFont()
101{
102 QSettings settings;
103 settings.beginGroup("SkinDocument");
104
105 QFont def("Monospace");
106 def.setStyleHint(QFont::TypeWriter);
107
108 QVariant family = settings.value("fontFamily", def);
109 int size = settings.value("fontSize", 12).toInt();
110
111 settings.endGroup();
112
113 ui->fontSelect->setCurrentFont(family.value<QFont>());
114 ui->fontSize->setValue(size);
115
116}
117
118void PreferencesDialog::loadRender()
119{
120 QSettings settings;
121 settings.beginGroup("RBFont");
122
123 QString confDir = QDir::homePath() + "/.rbthemeeditor";
124
125 ui->fontBox->setText(settings.value("fontDir", confDir + "/fonts/")
126 .toString());
127
128 settings.endGroup();
129
130 settings.beginGroup("EditorWindow");
131
132 ui->autoExpandBox->setChecked(settings.value("autoExpandTree",
133 false).toBool());
134 ui->autoHighlightBox->setChecked(settings.value("autoHighlightTree",
135 false).toBool());
136
137 settings.endGroup();
138
139 settings.beginGroup("TargetData");
140
141 ui->dbBox->setText(settings.value("targetDbPath",
142 confDir + "/targetdb")
143 .toString());
144
145 settings.endGroup();
146}
147
148void PreferencesDialog::saveSettings()
149{
150 saveColors();
151 saveFont();
152 saveRender();
153
154 QSettings settings;
155 settings.beginGroup("CodeEditor");
156 settings.setValue("completeSyntax", ui->completionBox->isChecked());
157 settings.endGroup();
158
159}
160
161void PreferencesDialog::saveColors()
162{
163 QSettings settings;
164
165 /* Saving the editor colors */
166 settings.beginGroup("SkinDocument");
167
168 settings.setValue("fgColor", fgColor);
169 settings.setValue("bgColor", bgColor);
170 settings.setValue("errorColor", errorColor);
171
172 settings.endGroup();
173
174 /* Saving the highlighting colors */
175 settings.beginGroup("SkinHighlighter");
176
177 settings.setValue("tagColor", tagColor);
178 settings.setValue("commentColor", commentColor);
179 settings.setValue("conditionalColor", conditionalColor);
180 settings.setValue("escapedColor", escapedColor);
181
182 settings.endGroup();
183}
184
185void PreferencesDialog::saveFont()
186{
187 QSettings settings;
188 settings.beginGroup("SkinDocument");
189
190 settings.setValue("fontFamily", ui->fontSelect->currentFont());
191 settings.setValue("fontSize", ui->fontSize->value());
192
193 settings.endGroup();
194}
195
196void PreferencesDialog::saveRender()
197{
198 QSettings settings;
199 settings.beginGroup("RBFont");
200
201 settings.setValue("fontDir", ui->fontBox->text());
202
203 settings.endGroup();
204
205 settings.beginGroup("EditorWindow");
206
207 settings.setValue("autoExpandTree", ui->autoExpandBox->isChecked());
208 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
209
210 settings.endGroup();
211
212 settings.beginGroup("TargetData");
213 settings.setValue("targetDbPath", ui->dbBox->text());
214 settings.endGroup();
215}
216
217void PreferencesDialog::setupUI()
218{
219 /* Connecting color buttons */
220 QList<QPushButton*> buttons;
221 buttons.append(ui->bgButton);
222 buttons.append(ui->fgButton);
223 buttons.append(ui->commentButton);
224 buttons.append(ui->tagButton);
225 buttons.append(ui->conditionalButton);
226 buttons.append(ui->escapedButton);
227 buttons.append(ui->errorButton);
228
229 for(int i = 0; i < buttons.count(); i++)
230 QObject::connect(buttons[i], SIGNAL(pressed()),
231 this, SLOT(colorClicked()));
232
233 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
234 this, SLOT(browseFont()));
235 QObject::connect(ui->browseDB, SIGNAL(clicked()),
236 this, SLOT(browseDB()));
237 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
238 this, SLOT(dlFonts()));
239 QObject::connect(ui->dlTargetButton, SIGNAL(clicked()),
240 this, SLOT(dlTargetDB()));
241}
242
243void PreferencesDialog::colorClicked()
244{
245 QColor* toEdit = 0, newColor;
246
247 if(QObject::sender() == ui->bgButton)
248 toEdit = &bgColor;
249 else if(QObject::sender() == ui->fgButton)
250 toEdit = &fgColor;
251 else if(QObject::sender() == ui->commentButton)
252 toEdit = &commentColor;
253 else if(QObject::sender() == ui->tagButton)
254 toEdit = &tagColor;
255 else if(QObject::sender() == ui->conditionalButton)
256 toEdit = &conditionalColor;
257 else if(QObject::sender() == ui->escapedButton)
258 toEdit = &escapedColor;
259 else if(QObject::sender() == ui->errorButton)
260 toEdit = &errorColor;
261
262 if(!toEdit)
263 return;
264
265 newColor = QColorDialog::getColor(*toEdit, this);
266 if (newColor.isValid())
267 {
268 *toEdit = newColor;
269 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
270 }
271}
272
273void PreferencesDialog::browseFont()
274{
275 QString path = QFileDialog::
276 getExistingDirectory(this, "Font Directory",
277 ui->fontBox->text());
278 ui->fontBox->setText(path);
279}
280
281void PreferencesDialog::browseDB()
282{
283 QString path = QFileDialog::getOpenFileName(this, tr("Target DB"),
284 QDir(ui->dbBox->text()).
285 absolutePath(),
286 "All Files (*)");
287 ui->dbBox->setText(path);
288}
289
290void PreferencesDialog::dlFonts()
291{
292 FontDownloader* dl = new FontDownloader(this, ui->fontBox->text());
293 dl->show();
294}
295
296void PreferencesDialog::dlTargetDB()
297{
298 TargetDownloader* dl = new TargetDownloader(this, ui->dbBox->text());
299 dl->show();
300}
301
302void PreferencesDialog::accept()
303{
304 saveSettings();
305 QDialog::accept();
306}
307
308void PreferencesDialog::reject()
309{
310 loadSettings();
311 QDialog::reject();
312}