| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2016 Ricardo Villalba <[email protected]>
|
|---|
| 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 "prefinterface.h"
|
|---|
| 21 | #include "images.h"
|
|---|
| 22 | #include "preferences.h"
|
|---|
| 23 | #include "paths.h"
|
|---|
| 24 | #include "languages.h"
|
|---|
| 25 | #include "recents.h"
|
|---|
| 26 | #include "urlhistory.h"
|
|---|
| 27 | #include "autohidewidget.h"
|
|---|
| 28 |
|
|---|
| 29 | #include <QDir>
|
|---|
| 30 | #include <QStyleFactory>
|
|---|
| 31 | #include <QFontDialog>
|
|---|
| 32 |
|
|---|
| 33 | #ifdef HDPI_SUPPORT
|
|---|
| 34 | #include "hdpisupport.h"
|
|---|
| 35 |
|
|---|
| 36 | #if QT_VERSION >= 0x050600
|
|---|
| 37 | #define HDPI_USE_SCALE_FACTOR
|
|---|
| 38 | #endif
|
|---|
| 39 | #endif
|
|---|
| 40 |
|
|---|
| 41 | #define SINGLE_INSTANCE_TAB 2
|
|---|
| 42 | #define HDPI_TAB 5
|
|---|
| 43 |
|
|---|
| 44 | PrefInterface::PrefInterface(QWidget * parent, Qt::WindowFlags f)
|
|---|
| 45 | : PrefWidget(parent, f )
|
|---|
| 46 | {
|
|---|
| 47 | setupUi(this);
|
|---|
| 48 | /* volume_icon->hide(); */
|
|---|
| 49 |
|
|---|
| 50 | // Style combo
|
|---|
| 51 | #if !STYLE_SWITCHING
|
|---|
| 52 | style_label->hide();
|
|---|
| 53 | style_combo->hide();
|
|---|
| 54 | #else
|
|---|
| 55 | style_combo->addItem( "<default>" );
|
|---|
| 56 | style_combo->addItems( QStyleFactory::keys() );
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | // Icon set combo
|
|---|
| 60 | iconset_combo->addItem( "Default" );
|
|---|
| 61 |
|
|---|
| 62 | #ifdef SKINS
|
|---|
| 63 | n_skins = 0;
|
|---|
| 64 | #endif
|
|---|
| 65 |
|
|---|
| 66 | // User
|
|---|
| 67 | QDir icon_dir = Paths::configPath() + "/themes";
|
|---|
| 68 | qDebug("icon_dir: %s", icon_dir.absolutePath().toUtf8().data());
|
|---|
| 69 | QStringList iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|---|
| 70 | for (int n=0; n < iconsets.count(); n++) {
|
|---|
| 71 | #ifdef SKINS
|
|---|
| 72 | QString css_file = Paths::configPath() + "/themes/" + iconsets[n] + "/main.css";
|
|---|
| 73 | bool is_skin = QFile::exists(css_file);
|
|---|
| 74 | //qDebug("***** %s %d", css_file.toUtf8().constData(), is_skin);
|
|---|
| 75 | if (is_skin) {
|
|---|
| 76 | skin_combo->addItem( iconsets[n] );
|
|---|
| 77 | n_skins++;
|
|---|
| 78 | }
|
|---|
| 79 | else
|
|---|
| 80 | #endif
|
|---|
| 81 | iconset_combo->addItem( iconsets[n] );
|
|---|
| 82 | }
|
|---|
| 83 | // Global
|
|---|
| 84 | icon_dir = Paths::themesPath();
|
|---|
| 85 | qDebug("icon_dir: %s", icon_dir.absolutePath().toUtf8().data());
|
|---|
| 86 | iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|---|
| 87 | for (int n=0; n < iconsets.count(); n++) {
|
|---|
| 88 | #ifdef SKINS
|
|---|
| 89 | QString css_file = Paths::themesPath() + "/" + iconsets[n] + "/main.css";
|
|---|
| 90 | bool is_skin = QFile::exists(css_file);
|
|---|
| 91 | //qDebug("***** %s %d", css_file.toUtf8().constData(), is_skin);
|
|---|
| 92 | if ((is_skin) && (skin_combo->findText( iconsets[n] ) == -1)) {
|
|---|
| 93 | skin_combo->addItem( iconsets[n] );
|
|---|
| 94 | n_skins++;
|
|---|
| 95 | }
|
|---|
| 96 | else
|
|---|
| 97 | #endif
|
|---|
| 98 | if (iconset_combo->findText( iconsets[n] ) == -1) {
|
|---|
| 99 | iconset_combo->addItem( iconsets[n] );
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 | #ifdef SKINS
|
|---|
| 103 | if (skin_combo->itemText(0) == "Black") {
|
|---|
| 104 | skin_combo->removeItem(0);
|
|---|
| 105 | skin_combo->addItem("Black");
|
|---|
| 106 | }
|
|---|
| 107 | #endif
|
|---|
| 108 |
|
|---|
| 109 | #ifdef SINGLE_INSTANCE
|
|---|
| 110 | connect(single_instance_check, SIGNAL(toggled(bool)),
|
|---|
| 111 | this, SLOT(changeInstanceImages()));
|
|---|
| 112 | #else
|
|---|
| 113 | tabWidget->setTabEnabled(SINGLE_INSTANCE_TAB, false);
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|
| 116 | #ifdef SKINS
|
|---|
| 117 | connect(gui_combo, SIGNAL(currentIndexChanged(int)),
|
|---|
| 118 | this, SLOT(GUIChanged(int)));
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | connect(mainwindow_resize_combo, SIGNAL(currentIndexChanged(int)),
|
|---|
| 122 | this, SLOT(resizeMethodChanged(int)));
|
|---|
| 123 |
|
|---|
| 124 | #ifndef SEEKBAR_RESOLUTION
|
|---|
| 125 | seeking_method_group->hide();
|
|---|
| 126 | #endif
|
|---|
| 127 |
|
|---|
| 128 | #ifndef SKINS
|
|---|
| 129 | skin_combo->hide();
|
|---|
| 130 | skin_label->hide();
|
|---|
| 131 | skin_sp->hide();
|
|---|
| 132 | #endif
|
|---|
| 133 |
|
|---|
| 134 | #ifdef HDPI_SUPPORT
|
|---|
| 135 | scale_group->setEnabled(false);
|
|---|
| 136 | connect(hdpi_scale_slider, SIGNAL(valueChanged(int)), this, SLOT(updateHDPIScaleNumber(int)));
|
|---|
| 137 | #ifndef HDPI_STORE_DATA
|
|---|
| 138 | tabWidget->setTabEnabled(HDPI_TAB, false);
|
|---|
| 139 | #endif
|
|---|
| 140 | #else
|
|---|
| 141 | tabWidget->setTabEnabled(HDPI_TAB, false);
|
|---|
| 142 | #endif
|
|---|
| 143 |
|
|---|
| 144 | retranslateStrings();
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | PrefInterface::~PrefInterface()
|
|---|
| 148 | {
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | QString PrefInterface::sectionName() {
|
|---|
| 152 | return tr("Interface");
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | QPixmap PrefInterface::sectionIcon() {
|
|---|
| 156 | return Images::icon("pref_gui");
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | void PrefInterface::createLanguageCombo() {
|
|---|
| 160 | QMap <QString,QString> m = Languages::translations();
|
|---|
| 161 |
|
|---|
| 162 | // Language combo
|
|---|
| 163 | QDir translation_dir = Paths::translationPath();
|
|---|
| 164 | QStringList languages = translation_dir.entryList( QStringList() << "*.qm");
|
|---|
| 165 | QRegExp rx_lang("smplayer_(.*)\\.qm");
|
|---|
| 166 | language_combo->clear();
|
|---|
| 167 | language_combo->addItem("<" + tr("System language") + ">");
|
|---|
| 168 | for (int n=0; n < languages.count(); n++) {
|
|---|
| 169 | if (rx_lang.indexIn(languages[n]) > -1) {
|
|---|
| 170 | QString l = rx_lang.cap(1);
|
|---|
| 171 | QString text = l;
|
|---|
| 172 | if (m.contains(l)) text = m[l] + " ("+l+")";
|
|---|
| 173 | language_combo->addItem( text, l );
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | void PrefInterface::retranslateStrings() {
|
|---|
| 179 | int mainwindow_resize = mainwindow_resize_combo->currentIndex();
|
|---|
| 180 | int timeslider_pos = timeslider_behaviour_combo->currentIndex();
|
|---|
| 181 |
|
|---|
| 182 | retranslateUi(this);
|
|---|
| 183 |
|
|---|
| 184 | mainwindow_resize_combo->setCurrentIndex(mainwindow_resize);
|
|---|
| 185 | timeslider_behaviour_combo->setCurrentIndex(timeslider_pos);
|
|---|
| 186 |
|
|---|
| 187 | // Icons
|
|---|
| 188 | /* resize_window_icon->setPixmap( Images::icon("resize_window") ); */
|
|---|
| 189 | /* volume_icon->setPixmap( Images::icon("speaker") ); */
|
|---|
| 190 |
|
|---|
| 191 | #ifdef SINGLE_INSTANCE
|
|---|
| 192 | changeInstanceImages();
|
|---|
| 193 | #endif
|
|---|
| 194 |
|
|---|
| 195 | // Seek widgets
|
|---|
| 196 | seek1->setLabel( tr("&Short jump") );
|
|---|
| 197 | seek2->setLabel( tr("&Medium jump") );
|
|---|
| 198 | seek3->setLabel( tr("&Long jump") );
|
|---|
| 199 | seek4->setLabel( tr("Mouse &wheel jump") );
|
|---|
| 200 |
|
|---|
| 201 | if (qApp->isLeftToRight()) {
|
|---|
| 202 | seek1->setIcon( Images::icon("forward10s", 32) );
|
|---|
| 203 | seek2->setIcon( Images::icon("forward1m", 32) );
|
|---|
| 204 | seek3->setIcon( Images::icon("forward10m", 32) );
|
|---|
| 205 | } else {
|
|---|
| 206 | seek1->setIcon( Images::flippedIcon("forward10s", 32) );
|
|---|
| 207 | seek2->setIcon( Images::flippedIcon("forward1m", 32) );
|
|---|
| 208 | seek3->setIcon( Images::flippedIcon("forward10m", 32) );
|
|---|
| 209 | }
|
|---|
| 210 | seek4->setIcon( Images::icon("mouse",32) );
|
|---|
| 211 |
|
|---|
| 212 | // Language combo
|
|---|
| 213 | int language_item = language_combo->currentIndex();
|
|---|
| 214 | createLanguageCombo();
|
|---|
| 215 | language_combo->setCurrentIndex( language_item );
|
|---|
| 216 |
|
|---|
| 217 | // Iconset combo
|
|---|
| 218 | iconset_combo->setItemText( 0, tr("Default") );
|
|---|
| 219 |
|
|---|
| 220 | #if STYLE_SWITCHING
|
|---|
| 221 | style_combo->setItemText( 0, tr("Default") );
|
|---|
| 222 | #endif
|
|---|
| 223 |
|
|---|
| 224 | int gui_index = gui_combo->currentIndex();
|
|---|
| 225 | gui_combo->clear();
|
|---|
| 226 | #ifdef DEFAULTGUI
|
|---|
| 227 | gui_combo->addItem( tr("Basic GUI"), "DefaultGUI");
|
|---|
| 228 | #endif
|
|---|
| 229 | #ifdef MINIGUI
|
|---|
| 230 | gui_combo->addItem( tr("Mini GUI"), "MiniGUI");
|
|---|
| 231 | #endif
|
|---|
| 232 | #ifdef MPCGUI
|
|---|
| 233 | gui_combo->addItem( tr("Mpc GUI"), "MpcGUI");
|
|---|
| 234 | #endif
|
|---|
| 235 | #ifdef SKINS
|
|---|
| 236 | gui_combo->addItem( tr("Skinnable GUI"), "SkinGUI");
|
|---|
| 237 | if (n_skins == 0) {
|
|---|
| 238 | QModelIndex index = gui_combo->model()->index(gui_combo->count()-1,0);
|
|---|
| 239 | gui_combo->model()->setData(index, QVariant(0), Qt::UserRole -1);
|
|---|
| 240 | }
|
|---|
| 241 | #endif
|
|---|
| 242 | gui_combo->setCurrentIndex(gui_index);
|
|---|
| 243 |
|
|---|
| 244 | floating_width_label->setNum(floating_width_slider->value());
|
|---|
| 245 | floating_margin_label->setNum(floating_margin_slider->value());
|
|---|
| 246 |
|
|---|
| 247 | #ifdef HDPI_SUPPORT
|
|---|
| 248 | #ifdef HDPI_USE_SCALE_FACTOR
|
|---|
| 249 | hdpi_scale_label->setText(tr("Scale fact&or:"));
|
|---|
| 250 | hdpi_scale_num_label->setNum((double) hdpi_scale_slider->value() / 10);
|
|---|
| 251 | #else
|
|---|
| 252 | hdpi_scale_label->setText(tr("Pixel rati&o:"));
|
|---|
| 253 | hdpi_scale_num_label->setNum(hdpi_scale_slider->value());
|
|---|
| 254 | #endif
|
|---|
| 255 | #endif
|
|---|
| 256 |
|
|---|
| 257 | createHelp();
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void PrefInterface::setData(Preferences * pref) {
|
|---|
| 261 | setLanguage( pref->language );
|
|---|
| 262 | setIconSet( pref->iconset );
|
|---|
| 263 |
|
|---|
| 264 | setResizeMethod( pref->resize_method );
|
|---|
| 265 | setSaveSize( pref->save_window_size_on_exit );
|
|---|
| 266 |
|
|---|
| 267 | center_window_check->setChecked(pref->center_window);
|
|---|
| 268 | center_if_outside_check->setChecked(pref->center_window_if_outside);
|
|---|
| 269 |
|
|---|
| 270 | #ifdef SINGLE_INSTANCE
|
|---|
| 271 | setUseSingleInstance(pref->use_single_instance);
|
|---|
| 272 | #endif
|
|---|
| 273 | setSeeking1(pref->seeking1);
|
|---|
| 274 | setSeeking2(pref->seeking2);
|
|---|
| 275 | setSeeking3(pref->seeking3);
|
|---|
| 276 | setSeeking4(pref->seeking4);
|
|---|
| 277 |
|
|---|
| 278 | setUpdateWhileDragging(pref->update_while_seeking);
|
|---|
| 279 | #ifdef SEEKBAR_RESOLUTION
|
|---|
| 280 | setRelativeSeeking(pref->relative_seeking);
|
|---|
| 281 | #endif
|
|---|
| 282 | setPreciseSeeking(pref->precise_seeking);
|
|---|
| 283 |
|
|---|
| 284 | reset_stop_check->setChecked(pref->reset_stop);
|
|---|
| 285 |
|
|---|
| 286 | setDefaultFont(pref->default_font);
|
|---|
| 287 |
|
|---|
| 288 | setHideVideoOnAudioFiles(pref->hide_video_window_on_audio_files);
|
|---|
| 289 |
|
|---|
| 290 | #if STYLE_SWITCHING
|
|---|
| 291 | setStyle( pref->style );
|
|---|
| 292 | #endif
|
|---|
| 293 |
|
|---|
| 294 | setGUI(pref->gui);
|
|---|
| 295 |
|
|---|
| 296 | setFloatingAnimated(pref->floating_control_animated);
|
|---|
| 297 | setFloatingWidth(pref->floating_control_width);
|
|---|
| 298 | setFloatingMargin(pref->floating_control_margin);
|
|---|
| 299 | setDisplayFloatingInCompactMode(pref->floating_display_in_compact_mode);
|
|---|
| 300 | floating_move_bottom_check->setChecked(pref->floating_activation_area == AutohideWidget::Bottom);
|
|---|
| 301 | floating_hide_delay_spin->setValue(pref->floating_hide_delay);
|
|---|
| 302 |
|
|---|
| 303 | setRecentsMaxItems(pref->history_recents->maxItems());
|
|---|
| 304 | setURLMaxItems(pref->history_urls->maxItems());
|
|---|
| 305 | setRememberDirs(pref->save_dirs);
|
|---|
| 306 |
|
|---|
| 307 | #ifdef HDPI_SUPPORT
|
|---|
| 308 | loadHDPIData();
|
|---|
| 309 | #endif
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | void PrefInterface::getData(Preferences * pref) {
|
|---|
| 313 | requires_restart = false;
|
|---|
| 314 | language_changed = false;
|
|---|
| 315 | iconset_changed = false;
|
|---|
| 316 | gui_changed = false;
|
|---|
| 317 | style_changed = false;
|
|---|
| 318 | recents_changed = false;
|
|---|
| 319 |
|
|---|
| 320 | if (pref->language != language()) {
|
|---|
| 321 | pref->language = language();
|
|---|
| 322 | language_changed = true;
|
|---|
| 323 | qDebug("PrefInterface::getData: chosen language: '%s'", pref->language.toUtf8().data());
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | if (pref->iconset != iconSet()) {
|
|---|
| 327 | pref->iconset = iconSet();
|
|---|
| 328 | iconset_changed = true;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | if (pref->gui != GUI()) {
|
|---|
| 332 | pref->gui = GUI();
|
|---|
| 333 | gui_changed = true;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | pref->resize_method = resizeMethod();
|
|---|
| 337 | pref->save_window_size_on_exit = saveSize();
|
|---|
| 338 |
|
|---|
| 339 | pref->center_window = center_window_check->isChecked();
|
|---|
| 340 | pref->center_window_if_outside = center_if_outside_check->isChecked();
|
|---|
| 341 |
|
|---|
| 342 | #ifdef SINGLE_INSTANCE
|
|---|
| 343 | pref->use_single_instance = useSingleInstance();
|
|---|
| 344 | #endif
|
|---|
| 345 |
|
|---|
| 346 | pref->seeking1 = seeking1();
|
|---|
| 347 | pref->seeking2 = seeking2();
|
|---|
| 348 | pref->seeking3 = seeking3();
|
|---|
| 349 | pref->seeking4 = seeking4();
|
|---|
| 350 |
|
|---|
|
|---|