summaryrefslogtreecommitdiff
path: root/src/prefinterface.cpp
blob: 21c58010cef4c9db8d55de56b3cf033259f35139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include "prefinterface.h"
#include "images.h"
#include "preferences.h"
#include "paths.h"
#include "languages.h"
#include "recents.h"
#include "urlhistory.h"
#include "autohidewidget.h"

#include <QDir>
#include <QStyleFactory>
#include <QFontDialog>
#include <QDebug>

#ifdef HDPI_SUPPORT
#include "hdpisupport.h"

#if QT_VERSION >= 0x050600
#define HDPI_USE_SCALE_FACTOR
#endif
#endif

#define SINGLE_INSTANCE_TAB 2
#define HDPI_TAB 5

PrefInterface::PrefInterface(QWidget * parent, Qt::WindowFlags f)
	: PrefWidget(parent, f )
{
	setupUi(this);
	/* volume_icon->hide(); */

	// Style combo
#if !STYLE_SWITCHING
	style_label->hide();
	style_combo->hide();
#else
	style_combo->addItem( "Default" );
	style_combo->addItems( QStyleFactory::keys() );
#endif

	// Icon set combo
	iconset_combo->addItem( "H2O", "H2O" );
	iconset_combo->addItem( "Default", "" );

#ifdef SKINS
	n_skins = 0;
#endif

	// User
	QDir icon_dir = Paths::configPath() + "/themes";
	qDebug() << "PrefInterface::PrefInterface: icon_dir:" << icon_dir.absolutePath();
	QStringList iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
	for (int n=0; n < iconsets.count(); n++) {
		#ifdef SKINS
		QString css_file = Paths::configPath() + "/themes/" + iconsets[n] + "/main.css";
		bool is_skin = QFile::exists(css_file);
		//qDebug() << "PrefInterface::PrefInterface: css_file:" << css_file << "is_skin:" << is_skin;
		if (is_skin) {
			skin_combo->addItem( iconsets[n], iconsets[n] );
			n_skins++;
		}
		else
		#endif
		iconset_combo->addItem( iconsets[n], iconsets[n] );
	}

	// Global
	icon_dir = Paths::themesPath();
	qDebug() << "PrefInterface::PrefInterface: icon_dir:" << icon_dir.absolutePath();
	iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
	for (int n=0; n < iconsets.count(); n++) {
		#ifdef SKINS
		QString css_file = Paths::themesPath() + "/" + iconsets[n] + "/main.css";
		bool is_skin = QFile::exists(css_file);
		//qDebug() << "PrefInterface::PrefInterface: css_file:" << css_file << "is_skin:" << is_skin;
		if (is_skin) {
			if (skin_combo->findData( iconsets[n] ) == -1) {
				skin_combo->addItem( iconsets[n], iconsets[n] );
				n_skins++;
			}
		}
		else
		#endif
		if (iconset_combo->findData( iconsets[n] ) == -1) {
			iconset_combo->addItem( iconsets[n], iconsets[n] );
		}
	}

	#ifdef SKINS
	if (skin_combo->itemText(0) == "Black") {
		skin_combo->removeItem(0);
		skin_combo->addItem("Black", "Black");
	}
	#endif

#ifdef SINGLE_INSTANCE
	connect(single_instance_check, SIGNAL(toggled(bool)), 
            this, SLOT(changeInstanceImages()));
#else
	tabWidget->setTabEnabled(SINGLE_INSTANCE_TAB, false);
#endif

#ifdef SKINS
	connect(gui_combo, SIGNAL(currentIndexChanged(int)),
            this, SLOT(GUIChanged(int)));
#endif

	connect(mainwindow_resize_combo, SIGNAL(currentIndexChanged(int)),
            this, SLOT(resizeMethodChanged(int)));

#ifndef SEEKBAR_RESOLUTION
	seeking_method_group->hide();
#endif

#ifndef SKINS
	skin_combo->hide();
	skin_label->hide();
	skin_sp->hide();
#endif

#ifdef HDPI_SUPPORT
	scale_group->setEnabled(false);
	connect(hdpi_scale_slider, SIGNAL(valueChanged(int)), this, SLOT(updateHDPIScaleNumber(int)));
	#ifndef HDPI_STORE_DATA
	tabWidget->setTabEnabled(HDPI_TAB, false);
	#endif
#else
	tabWidget->setTabEnabled(HDPI_TAB, false);
#endif

	retranslateStrings();
}

PrefInterface::~PrefInterface()
{
}

QString PrefInterface::sectionName() {
	return tr("Interface");
}

QPixmap PrefInterface::sectionIcon() {
    return Images::icon("pref_gui");
}

void PrefInterface::createLanguageCombo() {
	QMap <QString,QString> m = Languages::translations();

	// Language combo
	QDir translation_dir = Paths::translationPath();
	QStringList languages = translation_dir.entryList( QStringList() << "*.qm");
	QRegExp rx_lang("smplayer_(.*)\\.qm");
	language_combo->clear();
	language_combo->addItem("<" + tr("System language") + ">");
	for (int n=0; n < languages.count(); n++) {
		if (rx_lang.indexIn(languages[n]) > -1) {
			QString l = rx_lang.cap(1);
			QString text = l;
			if (m.contains(l)) text = m[l] + " ("+l+")";
			language_combo->addItem( text, l );
		}
	}
}

void PrefInterface::retranslateStrings() {
	int mainwindow_resize = mainwindow_resize_combo->currentIndex();
	int timeslider_pos = timeslider_behaviour_combo->currentIndex();

	retranslateUi(this);

	mainwindow_resize_combo->setCurrentIndex(mainwindow_resize);
	timeslider_behaviour_combo->setCurrentIndex(timeslider_pos);

	// Icons
	/* resize_window_icon->setPixmap( Images::icon("resize_window") ); */
	/* volume_icon->setPixmap( Images::icon("speaker") ); */

#ifdef SINGLE_INSTANCE
	changeInstanceImages();
#endif

	// Seek widgets
	seek1->setLabel( tr("&Short jump") );
	seek2->setLabel( tr("&Medium jump") );
	seek3->setLabel( tr("&Long jump") );
	seek4->setLabel( tr("Mouse &wheel jump") );

	if (qApp->isLeftToRight()) {
		seek1->setIcon( Images::icon("forward10s", 32) );
		seek2->setIcon( Images::icon("forward1m", 32) );
		seek3->setIcon( Images::icon("forward10m", 32) );
	} else {
		seek1->setIcon( Images::flippedIcon("forward10s", 32) );
		seek2->setIcon( Images::flippedIcon("forward1m", 32) );
		seek3->setIcon( Images::flippedIcon("forward10m", 32) );
	}
	seek4->setIcon( Images::icon("mouse",32) );

	// Language combo
	int language_item = language_combo->currentIndex();
	createLanguageCombo();
	language_combo->setCurrentIndex( language_item );

	// Iconset combo
	{
		int pos = iconset_combo->findData("");
		if (pos != -1) iconset_combo->setItemText(pos, tr("Classic"));
		pos = iconset_combo->findData("H2O");
		if (pos != -1) iconset_combo->setItemText(pos, tr("Default"));
	}

#if STYLE_SWITCHING
	style_combo->setItemText( 0, tr("Default") );
#endif

	int gui_index = gui_combo->currentIndex();
	gui_combo->clear();
#ifdef DEFAULTGUI
	gui_combo->addItem( tr("Basic GUI"), "DefaultGUI");
#endif
#ifdef MINIGUI
	gui_combo->addItem( tr("Mini GUI"), "MiniGUI");
#endif
#ifdef MPCGUI
	gui_combo->addItem( tr("Mpc GUI"), "MpcGUI");
#endif
#ifdef SKINS
	gui_combo->addItem( tr("Skinnable GUI"), "SkinGUI");
	if (n_skins == 0) {
		QModelIndex index = gui_combo->model()->index(gui_combo->count()-1,0);
		gui_combo->model()->setData(index, QVariant(0), Qt::UserRole -1);
	}
#endif
	gui_combo->setCurrentIndex(gui_index);

	floating_width_label->setNum(floating_width_slider->value());
	floating_margin_label->setNum(floating_margin_slider->value());

#ifdef HDPI_SUPPORT
	#ifdef HDPI_USE_SCALE_FACTOR
	hdpi_scale_label->setText(tr("Scale fact&or:"));
	hdpi_scale_num_label->setNum((double) hdpi_scale_slider->value() / 10);
	#else
	hdpi_scale_label->setText(tr("Pixel rati&o:"));
	hdpi_scale_num_label->setNum(hdpi_scale_slider->value());
	#endif
#endif

	createHelp();
}

void PrefInterface::setData(Preferences * pref) {
	setLanguage( pref->language );
	setIconSet( pref->iconset );

	setResizeMethod( pref->resize_method );
	setSaveSize( pref->save_window_size_on_exit );

	center_window_check->setChecked(pref->center_window);
	center_if_outside_check->setChecked(pref->center_window_if_outside);

	use_native_openfile_check->setChecked(pref->use_native_open_dialog);

#ifdef SINGLE_INSTANCE
	setUseSingleInstance(pref->use_single_instance);
#endif
	setSeeking1(pref->seeking1);
	setSeeking2(pref->seeking2);
	setSeeking3(pref->seeking3);
	setSeeking4(pref->seeking4);

	setUpdateWhileDragging(pref->update_while_seeking);
#ifdef SEEKBAR_RESOLUTION
	setRelativeSeeking(pref->relative_seeking);
#endif
	setPreciseSeeking(pref->precise_seeking);

	reset_stop_check->setChecked(pref->reset_stop);

	setDefaultFont(pref->default_font);

	setHideVideoOnAudioFiles(pref->hide_video_window_on_audio_files);

#if STYLE_SWITCHING
	setStyle( pref->style );
#endif

	setGUI(pref->gui);

	setFloatingAnimated(pref->floating_control_animated);
	setFloatingWidth(pref->floating_control_width);
	setFloatingMargin(pref->floating_control_margin);
	setDisplayFloatingInCompactMode(pref->floating_display_in_compact_mode);
	floating_move_bottom_check->setChecked(pref->floating_activation_area == AutohideWidget::Bottom);
	floating_hide_delay_spin->setValue(pref->floating_hide_delay);

	setRecentsMaxItems(pref->history_recents->maxItems());
	setURLMaxItems(pref->history_urls->maxItems());
	setRememberDirs(pref->save_dirs);

#ifdef HDPI_SUPPORT
	loadHDPIData();
#endif
}

void PrefInterface::getData(Preferences * pref) {
	requires_restart = false;
	language_changed = false;
	iconset_changed = false;
	gui_changed = false;
	style_changed = false;
	font_changed = false;
	recents_changed = false;

	if (pref->language != language()) {
		pref->language = language();
		language_changed = true;
		qDebug("PrefInterface::getData: chosen language: '%s'", pref->language.toUtf8().data());
	}

	if (pref->iconset != iconSet()) {
		pref->iconset = iconSet();
		iconset_changed = true;
	}

	if (pref->gui != GUI()) {
		pref->gui = GUI();
		gui_changed = true;
	}

	pref->resize_method = resizeMethod();
	pref->save_window_size_on_exit = saveSize();

	pref->center_window = center_window_check->isChecked();
	pref->center_window_if_outside = center_if_outside_check->isChecked();

#ifdef SINGLE_INSTANCE
	pref->use_single_instance = useSingleInstance();
#endif

	pref->use_native_open_dialog = use_native_openfile_check->isChecked();

	pref->seeking1 = seeking1();
	pref->seeking2 = seeking2();
	pref->seeking3 = seeking3();
	pref->seeking4 = seeking4();

	pref->update_while_seeking = updateWhileDragging();
#ifdef SEEKBAR_RESOLUTION
	pref->relative_seeking= relativeSeeking();
#endif
	pref->precise_seeking = preciseSeeking();

	pref->reset_stop = reset_stop_check->isChecked();

	if (pref->default_font != defaultFont()) {
		pref->default_font = defaultFont();
		font_changed = true;
	}

	pref->hide_video_window_on_audio_files = hideVideoOnAudioFiles();

#if STYLE_SWITCHING
	if ( pref->style != style() ) {
		pref->style = style();
		style_changed = true;
	}
#endif

	pref->floating_control_animated = floatingAnimated();
	pref->floating_control_width = floatingWidth();
	pref->floating_control_margin = floatingMargin();
	pref->floating_display_in_compact_mode = displayFloatingInCompactMode();
	pref->floating_activation_area = floating_move_bottom_check->isChecked() ? AutohideWidget::Bottom : AutohideWidget::Anywhere;
	pref->floating_hide_delay = floating_hide_delay_spin->value();

	if (pref->history_recents->maxItems() != recentsMaxItems()) {
		pref->history_recents->setMaxItems( recentsMaxItems() );
		recents_changed = true;
	}

	if (pref->history_urls->maxItems() != urlMaxItems()) {
		pref->history_urls->setMaxItems( urlMaxItems() );
		url_max_changed = true;
	}

	pref->save_dirs = rememberDirs();

#ifdef HDPI_SUPPORT
	saveHDPIData();
#endif
}

void PrefInterface::setLanguage(QString lang) {
	if (lang.isEmpty()) {
		language_combo->setCurrentIndex(0);
	}
	else {
		int pos = language_combo->findData(lang);
		if (pos != -1) 
			language_combo->setCurrentIndex( pos );
		else
			language_combo->setCurrentText(lang);
	}
}

QString PrefInterface::language() {
	if (language_combo->currentIndex()==0) 
		return "";
	else 
		return language_combo->itemData( language_combo->currentIndex() ).toString();
}

void PrefInterface::setIconSet(QString set) {
	iconset_combo->setCurrentIndex(0);
	int pos = iconset_combo->findData(set);
	if (pos != -1) iconset_combo->setCurrentIndex(pos);

#ifdef SKINS
	skin_combo->setCurrentIndex(0);
	pos = skin_combo->findData(set);
	if (pos != -1) skin_combo->setCurrentIndex(pos);
#endif
}

QString PrefInterface::iconSet() {
#ifdef SKINS
	QString GUI = gui_combo->itemData(gui_combo->currentIndex()).toString();
	if (GUI == "SkinGUI") {
		return skin_combo->itemData(skin_combo->currentIndex()).toString();
	}
	else
#endif
	return iconset_combo->itemData(iconset_combo->currentIndex()).toString();
}

void PrefInterface::setResizeMethod(int v) {
	mainwindow_resize_combo->setCurrentIndex(v);
}

int PrefInterface::resizeMethod() {
	return mainwindow_resize_combo->currentIndex();
}

void PrefInterface::setSaveSize(bool b) {
	save_size_check->setChecked(b);
}

bool PrefInterface::saveSize() {
	return save_size_check->isChecked();
}


void PrefInterface::setStyle(QString style) {
	if (style.isEmpty()) {
		style_combo->setCurrentIndex(0);
	} else {
		int i = style_combo->findText(style, Qt::MatchFixedString);
		if (i < 0) i = 0;
		style_combo->setCurrentIndex(i);
	}
}

QString PrefInterface::style() {
	if (style_combo->currentIndex() == 0)
		return "";
	else
		return style_combo->currentText();
}

void PrefInterface::setGUI(QString gui_name) {
#ifdef SKINS
	if ((n_skins == 0) && (gui_name == "SkinGUI")) gui_name = "DefaultGUI";
#endif
	int i = gui_combo->findData(gui_name);
	if (i < 0) i=0;
	gui_combo->setCurrentIndex(i);
}

QString PrefInterface::GUI() {
	return gui_combo->itemData(gui_combo->currentIndex()).toString();
}

#ifdef SKINS
void PrefInterface::GUIChanged(int index) {
	if (gui_combo->itemData(index).toString() == "SkinGUI") {
		iconset_combo->hide();
		iconset_label->hide();
		iconset_sp->hide();
		skin_combo->show();
		skin_label->show();
		skin_sp->show();
	} else {
		iconset_combo->show();
		iconset_label->show();
		iconset_sp->show();
		skin_combo->hide();
		skin_label->hide();
		skin_sp->hide();
	}
}
#endif

void PrefInterface::resizeMethodChanged(int index) {
	center_if_outside_check->setEnabled(index != 0);
}

#ifdef SINGLE_INSTANCE
void PrefInterface::setUseSingleInstance(bool b) {
	single_instance_check->setChecked(b);
	//singleInstanceButtonToggled(b);
}

bool PrefInterface::useSingleInstance() {
	return single_instance_check->isChecked();
}
#endif

void PrefInterface::setSeeking1(int n) {
	seek1->setTime(n);
}

int PrefInterface::seeking1() {
	return seek1->time();
}

void PrefInterface::setSeeking2(int n) {
	seek2->setTime(n);
}

int PrefInterface::seeking2() {
	return seek2->time();
}

void PrefInterface::setSeeking3(int n) {
	seek3->setTime(n);
}

int PrefInterface::seeking3() {
	return seek3->time();
}

void PrefInterface::setSeeking4(int n) {
	seek4->setTime(n);
}

int PrefInterface::seeking4() {
	return seek4->time();
}

void PrefInterface::setUpdateWhileDragging(bool b) {
	if (b) 
		timeslider_behaviour_combo->setCurrentIndex(0);
	else
		timeslider_behaviour_combo->setCurrentIndex(1);
}

bool PrefInterface::updateWhileDragging() {
	return (timeslider_behaviour_combo->currentIndex() == 0);
}

#ifdef SEEKBAR_RESOLUTION
void PrefInterface::setRelativeSeeking(bool b) {
	relative_seeking_button->setChecked(b);
	absolute_seeking_button->setChecked(!b);
}

bool PrefInterface::relativeSeeking() {
	return relative_seeking_button->isChecked();
}
#endif

void PrefInterface::setPreciseSeeking(bool b) {
	precise_seeking_check->setChecked(b);
}

bool PrefInterface::preciseSeeking() {
	return precise_seeking_check->isChecked();
}

void PrefInterface::setDefaultFont(QString font_desc) {
	default_font_edit->setText(font_desc);
}

QString PrefInterface::defaultFont() {
	return default_font_edit->text();
}

void PrefInterface::on_changeFontButton_clicked() {
	QFont f = qApp->font();

	if (!default_font_edit->text().isEmpty()) {
		f.fromString(default_font_edit->text());
	}

	bool ok;
	f = QFontDialog::getFont( &ok, f, this);

	if (ok) {
		default_font_edit->setText( f.toString() );
	}
}

#ifdef SINGLE_INSTANCE
void PrefInterface::changeInstanceImages() {
	if (single_instance_check->isChecked())
		instances_icon->setPixmap( Images::icon("instance1") );
	else
		instances_icon->setPixmap( Images::icon("instance2") );
}
#endif

void PrefInterface::setHideVideoOnAudioFiles(bool b) {
	hide_video_window_on_audio_check->setChecked(b);
}

bool PrefInterface::hideVideoOnAudioFiles() {
	return hide_video_window_on_audio_check->isChecked();
}

// Floating tab
void PrefInterface::setFloatingAnimated(bool b) {
	floating_animated_check->setChecked(b);
}

bool PrefInterface::floatingAnimated() {
	return floating_animated_check->isChecked();
}

void PrefInterface::setFloatingWidth(int percentage) {
	floating_width_slider->setValue(percentage);
}

int PrefInterface::floatingWidth() {
	return floating_width_slider->value();
}

void PrefInterface::setFloatingMargin(int pixels) {
	floating_margin_slider->setValue(pixels);
}

int PrefInterface::floatingMargin() {
	return floating_margin_slider->value();
}

void PrefInterface::setDisplayFloatingInCompactMode(bool b) {
	floating_compact_check->setChecked(b);
}

bool PrefInterface::displayFloatingInCompactMode() {
	return floating_compact_check->isChecked();
}

void PrefInterface::setRecentsMaxItems(int n) {
	recents_max_items_spin->setValue(n);
}

int PrefInterface::recentsMaxItems() {
	return recents_max_items_spin->value();
}

void PrefInterface::setURLMaxItems(int n) {
	url_max_items_spin->setValue(n);
}

int PrefInterface::urlMaxItems() {
	return url_max_items_spin->value();
}

void PrefInterface::setRememberDirs(bool b) {
	save_dirs_check->setChecked(b);
}

bool PrefInterface::rememberDirs() {
	return save_dirs_check->isChecked();
}

#ifdef HDPI_SUPPORT
void PrefInterface::loadHDPIData() {
	HDPISupport * hdpi = HDPISupport::instance();
	enable_hdpi_check->setChecked(hdpi->isHDPIEnabled());
	auto_scale_check->setChecked(hdpi->autoScale());

	#ifdef HDPI_USE_SCALE_FACTOR
	hdpi_scale_slider->setMinimum(5);
	hdpi_scale_slider->setMaximum(4*10);
	hdpi_scale_slider->setValue(hdpi->scaleFactor() * 10);
	#else
	hdpi_scale_slider->setMinimum(0);
	hdpi_scale_slider->setMaximum(4);
	hdpi_scale_slider->setValue(hdpi->pixelRatio());
	#endif
}

void PrefInterface::updateHDPIScaleNumber(int v) {
	#ifdef HDPI_USE_SCALE_FACTOR
	hdpi_scale_num_label->setNum((double) v / 10);
	#else
	hdpi_scale_num_label->setNum(v);
	#endif
}

void PrefInterface::saveHDPIData() {
	HDPISupport * hdpi = HDPISupport::instance();
	hdpi->setHDPIEnabled(enable_hdpi_check->isChecked());
	hdpi->setAutoScale(auto_scale_check->isChecked());
	#ifdef HDPI_USE_SCALE_FACTOR
	hdpi->setScaleFactor((double) hdpi_scale_slider->value() / 10);
	#else
	hdpi->setPixelRatio(hdpi_scale_slider->value());
	#endif
	#ifdef HDPI_STORE_DATA
	hdpi->save();
	#endif
}
#endif

void PrefInterface::createHelp() {
	clearHelp();

	addSectionTitle(tr("Interface"));

	setWhatsThis(mainwindow_resize_combo, tr("Autoresize"),
        tr("The main window can be resized automatically. Select the option "
           "you prefer.") );

	setWhatsThis(center_if_outside_check, tr("Prevent window to get outside of screen"),
		tr("If after an autoresize the main window gets outside of the screen this option "
           "will center the window to prevent it.") );

	setWhatsThis(center_window_check, tr("Center window"),
        tr("When this option is enabled, the main window will be centered on the desktop.") );

	setWhatsThis(save_size_check, tr("Remember position and size"),
        tr("If you check this option, the position and size of the main "
           "window will be saved and restored when you run SMPlayer again.") );

	setWhatsThis(hide_video_window_on_audio_check, tr("Hide video window when playing audio files"),
        tr("If this option is enabled the video window will be hidden when playing audio files.") );

	setWhatsThis(language_combo, tr("Language"),
		tr("Here you can change the language of the application.") );

	setWhatsThis(gui_combo, tr("GUI"),
        tr("Select the graphic interface you prefer for the application.") +"<br>"+
        tr("The <b>Basic GUI</b> provides the traditional interface, with the "
           "toolbar and control bar.") +" "+ 
        tr("The <b>Mini GUI</b> provides a more simple interface, without toolbar and a control bar with few "
           "buttons.")
#ifdef MPCGUI
        +" "+
        tr("The <b>Mpc GUI</b> looks like the interface in Media Player Classic.")
#endif
#ifdef SKINS
        +" "+
        tr("The <b>Skinnable GUI</b> provides an interface where several skins are available.")
#endif

        );

	setWhatsThis(iconset_combo, tr("Icon set"),
        tr("Select the icon set you prefer for the application.") );

#ifdef SKINS
	setWhatsThis(skin_combo, tr("Skin"),
        tr("Select the skin you prefer for the application. Only available with the skinnable GUI.") );
#endif

	setWhatsThis(style_combo, tr("Style"),
        tr("Select the style you prefer for the application.") );


	setWhatsThis(changeFontButton, tr("Default font"),
        tr("You can change here the application's font.") );

	setWhatsThis(use_native_openfile_check, tr("Use the system native file dialog"),
        tr("When this option is enabled, SMPlayer will try to use the system native file dialog. Otherwise it will use the internal one.") );

	addSectionTitle(tr("Seeking"));

	setWhatsThis(seek1, tr("Short jump"),
        tr("Select the time that should be go forward or backward when you "
           "choose the %1 action.").arg(tr("short jump")) );

	setWhatsThis(seek2, tr("Medium jump"),
        tr("Select the time that should be go forward or backward when you "
           "choose the %1 action.").arg(tr("medium jump")) );

	setWhatsThis(seek3, tr("Long jump"),
        tr("Select the time that should be go forward or backward when you "
           "choose the %1 action.").arg(tr("long jump")) );

	setWhatsThis(seek4, tr("Mouse wheel jump"),
        tr("Select the time that should be go forward or backward when you "
           "move the mouse wheel.") );

	setWhatsThis(timeslider_behaviour_combo, tr("Behaviour of time slider"),
        tr("Select what to do when dragging the time slider.") );

#ifdef SEEKBAR_RESOLUTION
	setWhatsThis(seeking_method_group, tr("Seeking method"),
		tr("Sets the method to be used when seeking with the slider. "
           "Absolute seeking may be a little bit more accurate, while "
           "relative seeking may work better with files with a wrong length.") );
#endif

	setWhatsThis(precise_seeking_check, tr("Precise seeking"),
		tr("If this option is enabled, seeks are more accurate but they "
           "can be a little bit slower. May not work with some video formats.") +"<br>"+
		tr("Note: this option only works when using mpv as multimedia engine.") );

	setWhatsThis(reset_stop_check, tr("Pressing the stop button once resets the time position"),
		tr("By default when the stop button is pressed the time position is remembered "
           "so if you press play button the media will resume at the same point. You need "
           "to press the stop button twice to reset the time position, but if this "
           "option is checked the time position will be set to 0 with only one "
           "press of the stop button.") );

#ifdef SINGLE_INSTANCE
	addSectionTitle(tr("Instances"));

	setWhatsThis(single_instance_check, 
        tr("Use only one running instance of SMPlayer"),
        tr("Check this option if you want to use an already running instance "
           "of SMPlayer when opening other files.") );
#endif

	addSectionTitle(tr("Floating control"));

	setWhatsThis(floating_animated_check, tr("Animated"),
		tr("If this option is enabled, the floating control will appear "
           "with an animation.") );

	setWhatsThis(floating_width_slider, tr("Width"),
		tr("Specifies the width of the control (as a percentage).") );

	setWhatsThis(floating_margin_slider, tr("Margin"),
		tr("This option sets the number of pixels that the floating control "
           "will be away from the bottom of the screen. Useful when the "
           "screen is a TV, as the overscan might prevent the control to be "
           "visible.") );

	setWhatsThis(floating_move_bottom_check, tr("Show only when moving the mouse to the bottom of the screen"),
		tr("If this option is checked, the floating control will only be displayed when the mouse is moved "
           "to the bottom of the screen. Otherwise the control will appear whenever the mouse is moved, no matter "
           "its position.") );

	setWhatsThis(floating_compact_check, tr("Display in compact mode too"),
		tr("If this option is enabled, the floating control will appear "
           "in compact mode too.") +" " +
		tr("This option only works with the basic GUI.") +" "+
		tr("<b>Warning:</b> the floating control has not been "
           "designed for compact mode and it might not work properly.") );

	setWhatsThis(floating_hide_delay_spin, tr("Time to hide the control"),
		tr("Sets the time (in milliseconds) to hide the control after the mouse went away from the control."));

	addSectionTitle(tr("Privacy"));

	setWhatsThis(recents_max_items_spin, tr("Recent files"),
        tr("Select the maximum number of items that will be shown in the "
           "<b>Open->Recent files</b> submenu. If you set it to 0 that "
           "menu won't be shown at all.") );

	setWhatsThis(url_max_items_spin, tr("Max. URLs"),
        tr("Select the maximum number of items that the <b>Open->URL</b> "
           "dialog will remember. Set it to 0 if you don't want any URL "
           "to be stored.") );

	setWhatsThis(save_dirs_check, tr("Remember last directory"),
		tr("If this option is checked, SMPlayer will remember the last folder you use to open a file.") );
}

#include "moc_prefinterface.cpp"