[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 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"
|
---|
[156] | 31 | #include "prefupdates.h"
|
---|
[176] | 32 | #include "prefnetwork.h"
|
---|
[181] | 33 | #include "infowindow.h"
|
---|
| 34 | #include "preferences.h"
|
---|
| 35 | #include "images.h"
|
---|
| 36 | #include <QVBoxLayout>
|
---|
| 37 | #include <QDebug>
|
---|
[112] | 38 |
|
---|
[181] | 39 | #ifdef TV_SUPPORT
|
---|
| 40 | #include "preftv.h"
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
[112] | 43 | #if USE_ASSOCIATIONS
|
---|
| 44 | #include "prefassociations.h"
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
[181] | 47 | #if QT_VERSION >= 0x050000
|
---|
| 48 | #include "myscroller.h"
|
---|
| 49 | #endif
|
---|
[112] | 50 |
|
---|
| 51 | PreferencesDialog::PreferencesDialog(QWidget * parent, Qt::WindowFlags f)
|
---|
| 52 | : QDialog(parent, f )
|
---|
[181] | 53 | , icon_mode(false)
|
---|
[112] | 54 | {
|
---|
| 55 | setupUi(this);
|
---|
[181] | 56 | /*
|
---|
| 57 | sections->setUniformItemSizes(true);
|
---|
| 58 | sections->setResizeMode(QListView::Adjust);
|
---|
| 59 | */
|
---|
| 60 | sections->setMovement(QListView::Static);
|
---|
[112] | 61 |
|
---|
[181] | 62 | #if QT_VERSION >= 0x050000
|
---|
| 63 | MyScroller::setScroller(sections->viewport());
|
---|
| 64 | #endif
|
---|
| 65 |
|
---|
[112] | 66 | // Setup buttons
|
---|
| 67 | okButton = buttonBox->button(QDialogButtonBox::Ok);
|
---|
| 68 | cancelButton = buttonBox->button(QDialogButtonBox::Cancel);
|
---|
| 69 | applyButton = buttonBox->button(QDialogButtonBox::Apply);
|
---|
| 70 | helpButton = buttonBox->button(QDialogButtonBox::Help);
|
---|
| 71 | connect( applyButton, SIGNAL(clicked()), this, SLOT(apply()) );
|
---|
| 72 | connect( helpButton, SIGNAL(clicked()), this, SLOT(showHelp()) );
|
---|
| 73 |
|
---|
| 74 | setWindowIcon( Images::icon("logo") );
|
---|
| 75 |
|
---|
[181] | 76 | help_window = new InfoWindow(this);
|
---|
[112] | 77 |
|
---|
| 78 | page_general = new PrefGeneral;
|
---|
| 79 | addSection( page_general );
|
---|
| 80 |
|
---|
| 81 | page_drives = new PrefDrives;
|
---|
| 82 | addSection( page_drives );
|
---|
| 83 |
|
---|
| 84 | page_performance = new PrefPerformance;
|
---|
| 85 | addSection( page_performance );
|
---|
| 86 |
|
---|
| 87 | page_subtitles = new PrefSubtitles;
|
---|
| 88 | addSection( page_subtitles );
|
---|
| 89 |
|
---|
| 90 | page_interface = new PrefInterface;
|
---|
| 91 | addSection( page_interface );
|
---|
| 92 |
|
---|
| 93 | page_input = new PrefInput;
|
---|
| 94 | addSection( page_input );
|
---|
| 95 |
|
---|
| 96 | page_playlist = new PrefPlaylist;
|
---|
| 97 | addSection( page_playlist );
|
---|
| 98 |
|
---|
[181] | 99 | #ifdef TV_SUPPORT
|
---|
[112] | 100 | page_tv = new PrefTV;
|
---|
| 101 | addSection( page_tv );
|
---|
[181] | 102 | #endif
|
---|
[112] | 103 |
|
---|
| 104 | #if USE_ASSOCIATIONS
|
---|
| 105 | page_associations = new PrefAssociations;
|
---|
| 106 | addSection(page_associations);
|
---|
| 107 | #endif
|
---|
| 108 |
|
---|
[156] | 109 | page_updates = new PrefUpdates;
|
---|
| 110 | addSection( page_updates );
|
---|
| 111 |
|
---|
[176] | 112 | page_network = new PrefNetwork;
|
---|
| 113 | addSection( page_network );
|
---|
| 114 |
|
---|
[112] | 115 | page_advanced = new PrefAdvanced;
|
---|
| 116 | addSection( page_advanced );
|
---|
| 117 |
|
---|
[124] | 118 | //sections->setIconSize( QSize(22,22) );
|
---|
[112] | 119 | sections->setCurrentRow(General);
|
---|
| 120 |
|
---|
| 121 | //adjustSize();
|
---|
| 122 | retranslateStrings();
|
---|
[181] | 123 |
|
---|
| 124 | /*
|
---|
| 125 | qDebug() << "PreferencesDialog: movement:" << sections->movement();
|
---|
| 126 | qDebug() << "PreferencesDialog: maximumWidth:" << sections->maximumWidth();
|
---|
| 127 | qDebug() << "PreferencesDialog: spacing:" << sections->spacing();
|
---|
| 128 | */
|
---|
[112] | 129 | }
|
---|
| 130 |
|
---|
[181] | 131 | PreferencesDialog::~PreferencesDialog() {
|
---|
[112] | 132 | }
|
---|
| 133 |
|
---|
[181] | 134 | void PreferencesDialog::setIconMode(bool b) {
|
---|
| 135 | qDebug() << "PreferencesDialog::setIconMode:" << b;
|
---|
| 136 |
|
---|
| 137 | if (b) {
|
---|
| 138 | sections->setUniformItemSizes(true);
|
---|
| 139 | sections->setViewMode(QListView::IconMode);
|
---|
| 140 | sections->setMaximumWidth(128);
|
---|
| 141 | sections->setSpacing(12);
|
---|
| 142 | } else {
|
---|
| 143 | sections->setUniformItemSizes(false);
|
---|
| 144 | sections->setViewMode(QListView::ListMode);
|
---|
| 145 | sections->setMaximumWidth(16777215);
|
---|
| 146 | sections->setSpacing(0);
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[112] | 150 | void PreferencesDialog::showSection(Section s) {
|
---|
| 151 | qDebug("PreferencesDialog::showSection: %d", s);
|
---|
| 152 |
|
---|
| 153 | sections->setCurrentRow(s);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | void PreferencesDialog::retranslateStrings() {
|
---|
| 157 | retranslateUi(this);
|
---|
| 158 |
|
---|
| 159 | for (int n=0; n < pages->count(); n++) {
|
---|
| 160 | PrefWidget * w = (PrefWidget*) pages->widget(n);
|
---|
| 161 | sections->item(n)->setText( w->sectionName() );
|
---|
| 162 | sections->item(n)->setIcon( w->sectionIcon() );
|
---|
[181] | 163 | sections->item(n)->setToolTip( w->sectionName() );
|
---|
[112] | 164 | }
|
---|
| 165 |
|
---|
| 166 | if (help_window->isVisible()) {
|
---|
| 167 | // Makes the help to retranslate
|
---|
| 168 | showHelp();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | help_window->setWindowTitle( tr("SMPlayer - Help") );
|
---|
[181] | 172 | help_window->setWindowIcon( Images::icon("logo") );
|
---|
[112] | 173 |
|
---|
[181] | 174 | // Some Qt versions don't provide translated strings
|
---|
| 175 | // for these buttons
|
---|
| 176 | okButton->setText( tr("&OK") );
|
---|
| 177 | cancelButton->setText( tr("&Cancel") );
|
---|
[112] | 178 | applyButton->setText( tr("Apply") );
|
---|
| 179 | helpButton->setText( tr("Help") );
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void PreferencesDialog::accept() {
|
---|
| 183 | hide();
|
---|
| 184 | help_window->hide();
|
---|
| 185 | setResult( QDialog::Accepted );
|
---|
| 186 | emit applied();
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | void PreferencesDialog::apply() {
|
---|
| 190 | setResult( QDialog::Accepted );
|
---|
| 191 | emit applied();
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | void PreferencesDialog::reject() {
|
---|
| 195 | hide();
|
---|
| 196 | help_window->hide();
|
---|
| 197 | setResult( QDialog::Rejected );
|
---|
| 198 |
|
---|
| 199 | setResult( QDialog::Accepted );
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | void PreferencesDialog::addSection(PrefWidget *w) {
|
---|
| 203 | QListWidgetItem *i = new QListWidgetItem( w->sectionIcon(), w->sectionName() );
|
---|
| 204 | sections->addItem( i );
|
---|
| 205 | pages->addWidget(w);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | void PreferencesDialog::setData(Preferences * pref) {
|
---|
| 209 | page_general->setData(pref);
|
---|
| 210 | page_drives->setData(pref);
|
---|
| 211 | page_interface->setData(pref);
|
---|
| 212 | page_performance->setData(pref);
|
---|
| 213 | page_input->setData(pref);
|
---|
| 214 | page_subtitles->setData(pref);
|
---|
| 215 | page_advanced->setData(pref);
|
---|
| 216 | page_playlist->setData(pref);
|
---|
[181] | 217 | #ifdef TV_SUPPORT
|
---|
[112] | 218 | page_tv->setData(pref);
|
---|
[181] | 219 | #endif
|
---|
[156] | 220 | page_updates->setData(pref);
|
---|
[176] | 221 | page_network->setData(pref);
|
---|
[112] | 222 |
|
---|
| 223 | #if USE_ASSOCIATIONS
|
---|
| 224 | page_associations->setData(pref);
|
---|
| 225 | #endif
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void PreferencesDialog::getData(Preferences * pref) {
|
---|
| 229 | page_general->getData(pref);
|
---|
| 230 | page_drives->getData(pref);
|
---|
| 231 | page_interface->getData(pref);
|
---|
| 232 | page_performance->getData(pref);
|
---|
| 233 | page_input->getData(pref);
|
---|
| 234 | page_subtitles->getData(pref);
|
---|
| 235 | page_advanced->getData(pref);
|
---|
| 236 | page_playlist->getData(pref);
|
---|
[181] | 237 | #ifdef TV_SUPPORT
|
---|
[112] | 238 | page_tv->getData(pref);
|
---|
[181] | 239 | #endif
|
---|
[156] | 240 | page_updates->getData(pref);
|
---|
[176] | 241 | page_network->getData(pref);
|
---|
[112] | 242 |
|
---|
| 243 | #if USE_ASSOCIATIONS
|
---|
| 244 | page_associations->getData(pref);
|
---|
| 245 | #endif
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | bool PreferencesDialog::requiresRestart() {
|
---|
| 249 | bool need_restart = page_general->requiresRestart();
|
---|
| 250 | if (!need_restart) need_restart = page_drives->requiresRestart();
|
---|
| 251 | if (!need_restart) need_restart = page_interface->requiresRestart();
|
---|
| 252 | if (!need_restart) need_restart = page_performance->requiresRestart();
|
---|
| 253 | if (!need_restart) need_restart = page_input->requiresRestart();
|
---|
| 254 | if (!need_restart) need_restart = page_subtitles->requiresRestart();
|
---|
| 255 | if (!need_restart) need_restart = page_advanced->requiresRestart();
|
---|
| 256 | if (!need_restart) need_restart = page_playlist->requiresRestart();
|
---|
[181] | 257 | #ifdef TV_SUPPORT
|
---|
[112] | 258 | if (!need_restart) need_restart = page_tv->requiresRestart();
|
---|
[181] | 259 | #endif
|
---|
[156] | 260 | if (!need_restart) need_restart = page_updates->requiresRestart();
|
---|
[176] | 261 | if (!need_restart) need_restart = page_network->requiresRestart();
|
---|
[112] | 262 |
|
---|
| 263 | return need_restart;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | void PreferencesDialog::showHelp() {
|
---|
| 267 | PrefWidget * w = (PrefWidget*) pages->currentWidget();
|
---|
| 268 | help_window->setHtml( w->help() );
|
---|
| 269 | help_window->show();
|
---|
| 270 | help_window->raise();
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | // Language change stuff
|
---|
| 274 | void PreferencesDialog::changeEvent(QEvent *e) {
|
---|
| 275 | if (e->type() == QEvent::LanguageChange) {
|
---|
| 276 | retranslateStrings();
|
---|
| 277 | } else {
|
---|
| 278 | QDialog::changeEvent(e);
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | #include "moc_preferencesdialog.cpp"
|
---|