Implemented settings dialog and refactored accordingly.
[vlc-remote] / src / settingsdialog.cpp
1 /*   VLC-REMOTE for MAEMO 5
2 *   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 #include "settingsdialog.h"
19 #include "ui_settingsdialog.h"
20 #include "appsettings.h"
21
22
23
24 SettingsDialog::SettingsDialog(QWidget *parent) :
25         QDialog(parent),
26         ui(new Ui::SettingsDialog)
27 {
28     ui->setupUi(this);
29     ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
30     connect(ui->radioButtonAutoRotate, SIGNAL(released()), this, SLOT(setOrientationAutoRotate()));
31     connect(ui->radioButtonLandscape, SIGNAL(released()), this, SLOT(setOrientationLandscape()));
32     connect(ui->radioButtonPortrait, SIGNAL(released()), this, SLOT(setOrientationPortrait()));
33     connect(ui->checkBoxAlertOnClose, SIGNAL(toggled(bool)), this, SLOT(setAlertOnClose(bool)));
34     connect(ui->checkBoxShowArt, SIGNAL(toggled(bool)), this, SLOT(setShowAlbumArt(bool)));
35     connect(ui->checkBoxUnknownFiles, SIGNAL(toggled(bool)), this, SLOT(setShowUnknownFileTypes(bool)));
36     connect(ui->comboBoxPollFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(setStatusPollTimeout(int)));
37     connect(ui->comboBoxPingTimeout, SIGNAL(currentIndexChanged(int)), this, SLOT(setPingTimeout(int)));
38     connect(ui->comboBoxConnectionTimeout, SIGNAL(currentIndexChanged(int)), this, SLOT(setConnectionTimeout(int)));
39     connect(ui->comboBoxRetryNetworkDelay, SIGNAL(currentIndexChanged(int)), this, SLOT(setRetryNetworkTimeout(int)));
40     connect(ui->comboBoxRetrieveArtDelay, SIGNAL(currentIndexChanged(int)), this, SLOT(setRetrieveArtTimeout(int)));
41     init();
42
43 }
44
45 SettingsDialog::~SettingsDialog()
46 {
47     delete ui;
48 }
49
50 void SettingsDialog::init()
51 {
52     switch (AppSettings::getOrientation()) {
53     case LANDSCAPE:
54         ui->radioButtonLandscape->setChecked(true);
55         break;
56     case PORTRAIT:
57         ui->radioButtonPortrait->setChecked(true);
58         break;
59     case AUTO_ROTATE:
60     default:
61         ui->radioButtonAutoRotate->setChecked(true);
62         break;
63     }
64
65     ui->checkBoxAlertOnClose->setChecked(AppSettings::getAlertOnClose());
66     ui->checkBoxShowArt->setChecked(AppSettings::getShowAlbumArt());
67     ui->checkBoxUnknownFiles->setChecked(AppSettings::getShowUnknownFileTypes());
68     int idx = -1;
69     idx = ui->comboBoxPollFrequency->findText(QString::number(AppSettings::getStatusPollTimeout()));
70     ui->comboBoxPollFrequency->setCurrentIndex(-1 < idx ? idx : 0);
71     idx = ui->comboBoxConnectionTimeout->findText(QString::number(AppSettings::getConnectionTimeout()));
72     ui->comboBoxConnectionTimeout->setCurrentIndex(-1 < idx ? idx : 0);
73     idx = ui->comboBoxPingTimeout->findText(QString::number(AppSettings::getPingTimeout()));
74     ui->comboBoxPingTimeout->setCurrentIndex(-1 < idx ? idx : 0);
75     idx = ui->comboBoxRetryNetworkDelay->findText(QString::number(AppSettings::getRetryNetworkTimeout()));
76     ui->comboBoxRetryNetworkDelay->setCurrentIndex(-1 < idx ? idx : 0);
77     idx = ui->comboBoxRetrieveArtDelay->findText(QString::number(AppSettings::getRetrieveArtTimeout()));
78     ui->comboBoxRetrieveArtDelay->setCurrentIndex(-1 < idx ? idx : 0);
79 }
80
81 void SettingsDialog::setOrientationLandscape() {
82     setOrientation(LANDSCAPE);
83 }
84 void SettingsDialog::setOrientationPortrait() {
85     setOrientation(PORTRAIT);
86 }
87 void SettingsDialog::setOrientationAutoRotate() {
88     setOrientation(AUTO_ROTATE);
89 }
90 void SettingsDialog::setOrientation(Orientation orientation) {
91     AppSettings::setOrientation(orientation);
92 }
93 void SettingsDialog::setStatusPollTimeout(int idx) {
94     Q_UNUSED(idx);
95     AppSettings::setStatusPollTimeout(ui->comboBoxPollFrequency->currentText().toInt());
96 }
97 void SettingsDialog::setPingTimeout(int idx) {
98     Q_UNUSED(idx);
99     AppSettings::setPingTimeout(ui->comboBoxPingTimeout->currentText().toInt());
100 }
101 void SettingsDialog::setConnectionTimeout(int idx) {
102     Q_UNUSED(idx);
103     AppSettings::setConnectionTimeout(ui->comboBoxConnectionTimeout->currentText().toInt());
104 }
105 void SettingsDialog::setRetrieveArtTimeout(int idx) {
106     Q_UNUSED(idx);
107     AppSettings::setRetrieveArtTimeout(ui->comboBoxRetrieveArtDelay->currentText().toInt());
108 }
109 void SettingsDialog::setRetryNetworkTimeout(int idx) {
110     Q_UNUSED(idx);
111     AppSettings::setRetryNetworkTimeout(ui->comboBoxRetryNetworkDelay->currentText().toInt());
112 }
113 void SettingsDialog::setShowUnknownFileTypes(bool state) {
114     AppSettings::setShowUnknownFileTypes(state);
115 }
116 void SettingsDialog::setShowAlbumArt(bool state) {
117     AppSettings::setShowAlbumArt(state);
118 }
119 void SettingsDialog::setAlertOnClose(bool state) {
120     AppSettings::setAlertOnClose(state);
121 }
122
123 void SettingsDialog::closeEvent(QCloseEvent * event) {
124     Q_UNUSED(event);
125     emit closeSignal();
126     this->close();
127 }