Debian Codegraph @

src/settingsdialog.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "settingsdialog.h"
19 #include "collectionsetupmodel.h"
20 #include "djsettings.h"
21 #include "ui_settingsdialog.h"
22
23 #include <QFileDialog>
24 #include <QMessageBox>
25 #include <QtDebug>
26 #include <QtGui>
27 #include <QtSql>
28
29 class SettingsDialogPrivate {
30 public:
31 Ui::SettingsDialog ui;
32 QWidget* parent;
33 CollectionSetupModel* model;
34 };
35
36 SettingsDialog::SettingsDialog(QWidget* parent)
37 : QDialog(parent)
38 {
39 p = new SettingsDialogPrivate;
40 p->ui.setupUi(this);
41 p->parent = parent;
42
43 // set icons in the settings list
44
45 QTableWidgetItem* item;
46 p->ui.settingsGroupsTable->setIconSize(QSize(32, 32));
47
48 item = p->ui.settingsGroupsTable->item(0, 0);
49 item->setIcon(QIcon(":slider.png"));
50 item->setTextAlignment(Qt::AlignCenter);
51 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
52
53 item = p->ui.settingsGroupsTable->item(1, 0);
54 item->setIcon(QIcon(":database.png"));
55 item->setTextAlignment(Qt::AlignCenter);
56 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
57
58 item = p->ui.settingsGroupsTable->item(2, 0);
59 item->setIcon(QIcon(":volume.png"));
60 item->setTextAlignment(Qt::AlignCenter);
61 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
62
63 item = p->ui.settingsGroupsTable->item(3, 0);
64 item->setIcon(QIcon(":DJ.png"));
65 item->setTextAlignment(Qt::AlignCenter);
66 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
67
68 item = p->ui.settingsGroupsTable->item(4, 0);
69 item->setIcon(QIcon(":list.png"));
70 item->setTextAlignment(Qt::AlignCenter);
71 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
72
73 item = p->ui.settingsGroupsTable->item(5, 0);
74 item->setIcon(QIcon(":folder.png"));
75 item->setTextAlignment(Qt::AlignCenter);
76 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
77
78 item = p->ui.settingsGroupsTable->item(6, 0);
79 item->setIcon(QIcon(":settings.png"));
80 item->setTextAlignment(Qt::AlignCenter);
81 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
82
83 int w = p->ui.settingsGroupsTable->width();
84 p->ui.settingsGroupsTable->setColumnWidth(0, w);
85
86 // select first item
87 p->ui.settingsGroupsTable->setCurrentCell(0, 0);
88
89 // select first page
90 p->ui.pages->setCurrentIndex(0);
91
92 //Collection folder setup
93 p->model = new CollectionSetupModel();
94
95 p->ui.collectionsTreeView->setModel(p->model);
96 p->ui.collectionsTreeView->setColumnHidden(1, true);
97 p->ui.collectionsTreeView->setColumnHidden(2, true);
98 p->ui.collectionsTreeView->setColumnHidden(3, true);
99 p->ui.collectionsTreeView->expandToDepth(0);
100
101 connect(p->ui.settingsGroupsTable, SIGNAL(itemSelectionChanged()),
102 this, SLOT(tableSelectionChanged()));
103
104 connect(p->ui.faderEndSlider, SIGNAL(sliderMoved(int)),
105 this, SLOT(on_faderEndSlider_sliderMoved(int)));
106 connect(p->ui.faderTimeSlider, SIGNAL(sliderMoved(int)),
107 this, SLOT(on_faderTimeSlider_sliderMoved(int)));
108
109 connect(p->ui.pushScanNow, SIGNAL(clicked()), this, SLOT(onScanNow()));
110 connect(p->ui.pushResetStats, SIGNAL(clicked()), this, SIGNAL(resetStatsPressed()));
111
112 connect(p->ui.countDJ, SIGNAL(valueChanged(int)), this, SLOT(loadDjList(int)));
113 }
114
115 SettingsDialog::~SettingsDialog()
116 {
117 delete p;
118 }
119
120 void SettingsDialog::setCurrentTab(SettingsDialog::Tab tab)
121 {
122 p->ui.settingsGroupsTable->setCurrentCell(tab, 0);
123 p->ui.pages->setCurrentIndex(tab);
124 }
125
126 int SettingsDialog::exec()
127 {
128 // load settings
129 if (!loadSettings()) {
130 return QDialog::Rejected;
131 }
132
133 return QDialog::exec();
134 }
135
136 void SettingsDialog::accept()
137 {
138 QSettings settings;
139 settings.setValue("MonitorOutputDevice", p->ui.monitorOutputDevice->currentText());
140
141 //Common
142 settings.setValue("language", p->ui.comboLanguage->currentIndex());
143
144 //save fade slider
145 settings.setValue("faderTimeSlider", p->ui.faderTimeSlider->value());
146 settings.setValue("faderEndSlider", p->ui.faderEndSlider->value());
147
148 //Playlist settings
149 settings.setValue("checkAutoRemove", p->ui.checkAutoRemove->isChecked());
150
151 //Silent settings
152 settings.setValue("checkAutoCue", p->ui.checkAutoCue->isChecked());
153 settings.setValue("checkSkipSilentEnd", p->ui.checkSkipSilentEnd->isChecked());
154
155 //AutoDJ
156 settings.setValue("minTracks", p->ui.minTracks->value());
157 settings.setValue("countDJ", p->ui.countDJ->value());
158 settings.setValue("isEnabledAutoDJCount", p->ui.checkAutoDjCountPlayed->isChecked());
159 settings.beginGroup("AutoDJ");
160 int maxDj = p->ui.countDJ->value();
161
162 for (int d = 0; d < maxDj; d++) {
163 settings.beginGroup(QString::number(d));
164 QListWidgetItem* item = p->ui.listDjNames->item(d);
165 if (DjSettings* djs = dynamic_cast<DjSettings*>(p->ui.listDjNames->itemWidget(item))) {
166 settings.setValue("Name", djs->name());
167 settings.setValue("FilterCount", djs->filterCount());
168 }
169 settings.endGroup();
170 }
171 settings.endGroup();
172
173 //CollectionFolders
174 settings.setValue("Dirs", p->model->dirsChecked());
175 settings.setValue("Monitor", p->ui.chkMonitor->isChecked());
176
177 //File Browser
178 settings.setValue("editBrowerRoot", p->ui.txtBrowserRoot->text());
179
180 QDialog::accept();
181 }
182
183 bool SettingsDialog::loadSettings()
184 {
185 QSettings settings;
186 p->ui.monitorOutputDevice->clear();
187 p->ui.monitorOutputDevice->addItems(settings.value("MonitorOutputDevices").toStringList());
188
189 int index = p->ui.monitorOutputDevice->findText(settings.value("MonitorOutputDevice").toString());
190 p->ui.monitorOutputDevice->setCurrentIndex(index);
191
192 //Common
193 p->ui.comboLanguage->setCurrentIndex(settings.value("language", 0).toInt());
194
195 //fade slider
196 p->ui.faderTimeSlider->setValue(settings.value("faderTimeSlider", "12").toInt());
197 p->ui.faderTimeLabel->setText(settings.value("faderTimeSlider", "12").toString() + "s");
198 p->ui.faderEndSlider->setValue(settings.value("faderEndSlider", "12").toInt());
199 p->ui.faderEndLabel->setText(settings.value("faderEndSlider", "12").toString() + "s");
200
201 //Playlist setting
202 p->ui.checkAutoRemove->setChecked(settings.value("checkAutoRemove", true).toBool());
203
204 //Silent setting
205 p->ui.checkSkipSilentEnd->setChecked(settings.value("checkSkipSilentEnd", true).toBool());
206 p->ui.checkAutoCue->setChecked(settings.value("checkAutoCue", true).toBool());
207
208 //AutoDJ
209 p->ui.minTracks->setValue(settings.value("minTracks", "6").toInt());
210 p->ui.countDJ->setValue(settings.value("countDJ", "3").toInt());
211 p->ui.checkAutoDjCountPlayed->setChecked(settings.value("isEnabledAutoDJCount", false).toBool());
212
213 //CollectionFolders
214 p->model->setDirsChecked(settings.value("Dirs").toStringList());
215 p->ui.chkMonitor->setChecked(settings.value("Monitor").toBool());
216
217 //File Browser
218 p->ui.txtBrowserRoot->setText(settings.value("editBrowerRoot", "").toString());
219
220 //Load Dj list
221 loadDjList(p->ui.countDJ->value());
222
223 return true;
224 }
225
226 void SettingsDialog::loadDjList(int count)
227 {
228 QSettings settings;
229 QListWidgetItem* itm;
230 DjSettings* djs;
231
232 p->ui.listDjNames->clear();
233
234 settings.beginGroup("AutoDJ");
235 for (int d = 0; d < count; d++) {
236 settings.beginGroup(QString::number(d));
237 itm = new QListWidgetItem(p->ui.listDjNames);
238 p->ui.listDjNames->addItem(itm);
239 djs = new DjSettings(p->ui.listDjNames);
240 djs->setID(d + 1);
241 djs->setName(settings.value("Name", "Dj%1").toString().arg(d + 1));
242 djs->setFilterCount(settings.value("FilterCount", "2").toInt());
243 p->ui.listDjNames->setItemWidget(itm, djs);
244 settings.endGroup();
245 }
246 settings.endGroup();
247 }
248
249 void SettingsDialog::on_pushButton_clicked()
250 {
251 QFileDialog dialog(this);
252 dialog.setFileMode(QFileDialog::DirectoryOnly);
253 if (dialog.exec())
254 p->ui.txtBrowserRoot->setText(dialog.selectedFiles().first());
255 }
256
257 void SettingsDialog::on_pushAbout_clicked()
258 {
259 QMessageBox msgBox;
260 msgBox.setIconPixmap(QIcon(":knowthelist.png").pixmap(65, 65));
261 msgBox.setText(QString("%1").arg("<h3>Knowthelist</h3>"
262 " Version "
263 + QApplication::applicationVersion() + "<br />Copyright (C) 2005-2014 Mario Stephan "
264 "<br /><a href='mailto:[email protected]'>[email protected]</a>"
265 "<br /><br /><a href='http://knowthelist.github.io/knowthelist'>"
266 "http://knowthelist.github.io/knowthelist</a>"
267 "<br /><br /><div style='font-size:9px;'>Thanks to :"
268 "<br />* Heiko Fischer (for testing and new ideas)"
269 "<br />* David Geiger and Adrien Daugabel (for French translation and issue reports)"
270 "<br />* Pavel Fric (for Czech translation)"
271 "<br />* László Farkas (for Hungarian translation)</div>"));
272 msgBox.setWindowTitle(tr("About Knowthelist"));
273 msgBox.exec();
274 }
275
276 void SettingsDialog::onScanNow()
277 {
278 QSettings settings;
279 settings.setValue("Dirs", p->model->dirsChecked());
280 Q_EMIT scanNowPressed();
281 }
282
283 void SettingsDialog::on_faderEndSlider_sliderMoved(int position)
284 {
285 p->ui.faderEndLabel->setText(QString::number(position) + "s");
286 }
287
288 void SettingsDialog::on_faderTimeSlider_sliderMoved(int position)
289 {
290 p->ui.faderTimeLabel->setText(QString::number(position) + "s");
291 }
292
293 void SettingsDialog::tableSelectionChanged()
294 {
295 QTableWidgetItem* item = p->ui.settingsGroupsTable->selectedItems().first();
296 p->ui.pages->setCurrentIndex(item->row());
297 }