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