source: smplayer/trunk/src/preferencesdialog.cpp@ 178

Last change on this file since 178 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

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