1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 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 General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | #include "preferencesdialog.h"
|
---|
21 |
|
---|
22 | #include "prefwidget.h"
|
---|
23 | #include "prefgeneral.h"
|
---|
24 | #include "prefdrives.h"
|
---|
25 | #include "prefinterface.h"
|
---|
26 | #include "prefperformance.h"
|
---|
27 | #include "prefinput.h"
|
---|
28 | #include "prefsubtitles.h"
|
---|
29 | #include "prefadvanced.h"
|
---|
30 | #include "prefplaylist.h"
|
---|
31 | #include "preftv.h"
|
---|
32 |
|
---|
33 | #if USE_ASSOCIATIONS
|
---|
34 | #include "prefassociations.h"
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include "preferences.h"
|
---|
38 |
|
---|
39 | #include <QVBoxLayout>
|
---|
40 | #include <QTextBrowser>
|
---|
41 |
|
---|
42 | #include "images.h"
|
---|
43 |
|
---|
44 | PreferencesDialog::PreferencesDialog(QWidget * parent, Qt::WindowFlags f)
|
---|
45 | : QDialog(parent, f )
|
---|
46 | {
|
---|
47 | setupUi(this);
|
---|
48 |
|
---|
49 | // Setup buttons
|
---|
50 | okButton = buttonBox->button(QDialogButtonBox::Ok);
|
---|
51 | cancelButton = buttonBox->button(QDialogButtonBox::Cancel);
|
---|
52 | applyButton = buttonBox->button(QDialogButtonBox::Apply);
|
---|
53 | helpButton = buttonBox->button(QDialogButtonBox::Help);
|
---|
54 | connect( applyButton, SIGNAL(clicked()), this, SLOT(apply()) );
|
---|
55 | connect( helpButton, SIGNAL(clicked()), this, SLOT(showHelp()) );
|
---|
56 |
|
---|
57 |
|
---|
58 | setWindowIcon( Images::icon("logo") );
|
---|
59 |
|
---|
60 | help_window = new QTextBrowser(this);
|
---|
61 | help_window->setWindowFlags(Qt::Window);
|
---|
62 | help_window->resize(300, 450);
|
---|
63 | //help_window->adjustSize();
|
---|
64 | help_window->setWindowTitle( tr("SMPlayer - Help") );
|
---|
65 | help_window->setWindowIcon( Images::icon("logo") );
|
---|
66 |
|
---|
67 | page_general = new PrefGeneral;
|
---|
68 | addSection( page_general );
|
---|
69 |
|
---|
70 | page_drives = new PrefDrives;
|
---|
71 | addSection( page_drives );
|
---|
72 |
|
---|
73 | page_performance = new PrefPerformance;
|
---|
74 | addSection( page_performance );
|
---|
75 |
|
---|
76 | page_subtitles = new PrefSubtitles;
|
---|
77 | addSection( page_subtitles );
|
---|
78 |
|
---|
79 | page_interface = new PrefInterface;
|
---|
80 | addSection( page_interface );
|
---|
81 |
|
---|
82 | page_input = new PrefInput;
|
---|
83 | addSection( page_input );
|
---|
84 |
|
---|
85 | page_playlist = new PrefPlaylist;
|
---|
86 | addSection( page_playlist );
|
---|
87 |
|
---|
88 | page_tv = new PrefTV;
|
---|
89 | addSection( page_tv );
|
---|
90 |
|
---|
91 | #if USE_ASSOCIATIONS
|
---|
92 | page_associations = new PrefAssociations;
|
---|
93 | addSection(page_associations);
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | page_advanced = new PrefAdvanced;
|
---|
97 | addSection( page_advanced );
|
---|
98 |
|
---|
99 | sections->setCurrentRow(General);
|
---|
100 |
|
---|
101 | //adjustSize();
|
---|
102 | retranslateStrings();
|
---|
103 | }
|
---|
104 |
|
---|
105 | PreferencesDialog::~PreferencesDialog()
|
---|
106 | {
|
---|
107 | }
|
---|
108 |
|
---|
109 | void PreferencesDialog::showSection(Section s) {
|
---|
110 | qDebug("PreferencesDialog::showSection: %d", s);
|
---|
111 |
|
---|
112 | sections->setCurrentRow(s);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void PreferencesDialog::retranslateStrings() {
|
---|
116 | retranslateUi(this);
|
---|
117 |
|
---|
118 | for (int n=0; n < pages->count(); n++) {
|
---|
119 | PrefWidget * w = (PrefWidget*) pages->widget(n);
|
---|
120 | sections->item(n)->setText( w->sectionName() );
|
---|
121 | sections->item(n)->setIcon( w->sectionIcon() );
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (help_window->isVisible()) {
|
---|
125 | // Makes the help to retranslate
|
---|
126 | showHelp();
|
---|
127 | }
|
---|
128 |
|
---|
129 | help_window->setWindowTitle( tr("SMPlayer - Help") );
|
---|
130 |
|
---|
131 | // Qt 4.2 doesn't update the buttons' text
|
---|
132 | #if QT_VERSION < 0x040300
|
---|
133 | okButton->setText( tr("OK") );
|
---|
134 | cancelButton->setText( tr("Cancel") );
|
---|
135 | applyButton->setText( tr("Apply") );
|
---|
136 | helpButton->setText( tr("Help") );
|
---|
137 | #endif
|
---|
138 | }
|
---|
139 |
|
---|
140 | void PreferencesDialog::accept() {
|
---|
141 | hide();
|
---|
142 | help_window->hide();
|
---|
143 | setResult( QDialog::Accepted );
|
---|
144 | emit applied();
|
---|
145 | }
|
---|
146 |
|
---|
147 | void PreferencesDialog::apply() {
|
---|
148 | setResult( QDialog::Accepted );
|
---|
149 | emit applied();
|
---|
150 | }
|
---|
151 |
|
---|
152 | void PreferencesDialog::reject() {
|
---|
153 | hide();
|
---|
154 | help_window->hide();
|
---|
155 | setResult( QDialog::Rejected );
|
---|
156 |
|
---|
157 | setResult( QDialog::Accepted );
|
---|
158 | }
|
---|
159 |
|
---|
160 | void PreferencesDialog::addSection(PrefWidget *w) {
|
---|
161 | QListWidgetItem *i = new QListWidgetItem( w->sectionIcon(), w->sectionName() );
|
---|
162 | sections->addItem( i );
|
---|
163 | pages->addWidget(w);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void PreferencesDialog::setData(Preferences * pref) {
|
---|
167 | page_general->setData(pref);
|
---|
168 | page_drives->setData(pref);
|
---|
169 | page_interface->setData(pref);
|
---|
170 | page_performance->setData(pref);
|
---|
171 | page_input->setData(pref);
|
---|
172 | page_subtitles->setData(pref);
|
---|
173 | page_advanced->setData(pref);
|
---|
174 | page_playlist->setData(pref);
|
---|
175 | page_tv->setData(pref);
|
---|
176 |
|
---|
177 | #if USE_ASSOCIATIONS
|
---|
178 | page_associations->setData(pref);
|
---|
179 | #endif
|
---|
180 | }
|
---|
181 |
|
---|
182 | void PreferencesDialog::getData(Preferences * pref) {
|
---|
183 | page_general->getData(pref);
|
---|
184 | page_drives->getData(pref);
|
---|
185 | page_interface->getData(pref);
|
---|
186 | page_performance->getData(pref);
|
---|
187 | page_input->getData(pref);
|
---|
188 | page_subtitles->getData(pref);
|
---|
189 | page_advanced->getData(pref);
|
---|
190 | page_playlist->getData(pref);
|
---|
191 | page_tv->getData(pref);
|
---|
192 |
|
---|
193 | #if USE_ASSOCIATIONS
|
---|
194 | page_associations->getData(pref);
|
---|
195 | #endif
|
---|
196 | }
|
---|
197 |
|
---|
198 | bool PreferencesDialog::requiresRestart() {
|
---|
199 | bool need_restart = page_general->requiresRestart();
|
---|
200 | if (!need_restart) need_restart = page_drives->requiresRestart();
|
---|
201 | if (!need_restart) need_restart = page_interface->requiresRestart();
|
---|
202 | if (!need_restart) need_restart = page_performance->requiresRestart();
|
---|
203 | if (!need_restart) need_restart = page_input->requiresRestart();
|
---|
204 | if (!need_restart) need_restart = page_subtitles->requiresRestart();
|
---|
205 | if (!need_restart) need_restart = page_advanced->requiresRestart();
|
---|
206 | if (!need_restart) need_restart = page_playlist->requiresRestart();
|
---|
207 | if (!need_restart) need_restart = page_tv->requiresRestart();
|
---|
208 |
|
---|
209 | return need_restart;
|
---|
210 | }
|
---|
211 |
|
---|
212 | void PreferencesDialog::showHelp() {
|
---|
213 | PrefWidget * w = (PrefWidget*) pages->currentWidget();
|
---|
214 | help_window->setHtml( w->help() );
|
---|
215 | help_window->show();
|
---|
216 | help_window->raise();
|
---|
217 | }
|
---|
218 |
|
---|
219 | // Language change stuff
|
---|
220 | void PreferencesDialog::changeEvent(QEvent *e) {
|
---|
221 | if (e->type() == QEvent::LanguageChange) {
|
---|
222 | retranslateStrings();
|
---|
223 | } else {
|
---|
224 | QDialog::changeEvent(e);
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | #include "moc_preferencesdialog.cpp"
|
---|