source: smplayer/trunk/src/prefinterface.cpp@ 119

Last change on this file since 119 was 119, checked in by Silvan Scherrer, 14 years ago

SMPlayer: latest svn update

  • Property svn:eol-style set to LF
File size: 17.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
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 "config.h"
25#include "languages.h"
26#include "recents.h"
27
28#include <QDir>
29#include <QStyleFactory>
30#include <QFontDialog>
31
32PrefInterface::PrefInterface(QWidget * parent, Qt::WindowFlags f)
33 : PrefWidget(parent, f )
34{
35 setupUi(this);
36 /* volume_icon->hide(); */
37
38 // Style combo
39#if !STYLE_SWITCHING
40 style_label->hide();
41 style_combo->hide();
42#else
43 style_combo->addItem( "<default>" );
44 style_combo->addItems( QStyleFactory::keys() );
45#endif
46
47 // Icon set combo
48 iconset_combo->addItem( "Default" );
49
50 // User
51 QDir icon_dir = Paths::configPath() + "/themes";
52 qDebug("icon_dir: %s", icon_dir.absolutePath().toUtf8().data());
53 QStringList iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
54 for (int n=0; n < iconsets.count(); n++) {
55 iconset_combo->addItem( iconsets[n] );
56 }
57 // Global
58 icon_dir = Paths::themesPath();
59 qDebug("icon_dir: %s", icon_dir.absolutePath().toUtf8().data());
60 iconsets = icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
61 for (int n=0; n < iconsets.count(); n++) {
62 if (iconset_combo->findText( iconsets[n] ) == -1) {
63 iconset_combo->addItem( iconsets[n] );
64 }
65 }
66
67 connect(single_instance_check, SIGNAL(toggled(bool)),
68 this, SLOT(changeInstanceImages()));
69
70#ifdef Q_OS_WIN
71 floating_bypass_wm_check->hide();
72#endif
73
74 retranslateStrings();
75}
76
77PrefInterface::~PrefInterface()
78{
79}
80
81QString PrefInterface::sectionName() {
82 return tr("Interface");
83}
84
85QPixmap PrefInterface::sectionIcon() {
86 return Images::icon("pref_gui");
87}
88
89void PrefInterface::createLanguageCombo() {
90 QMap <QString,QString> m = Languages::translations();
91
92 // Language combo
93 QDir translation_dir = Paths::translationPath();
94 QStringList languages = translation_dir.entryList( QStringList() << "*.qm");
95 QRegExp rx_lang("smplayer_(.*)\\.qm");
96 language_combo->clear();
97 language_combo->addItem( tr("<Autodetect>") );
98 for (int n=0; n < languages.count(); n++) {
99 if (rx_lang.indexIn(languages[n]) > -1) {
100 QString l = rx_lang.cap(1);
101 QString text = l;
102 if (m.contains(l)) text = m[l] + " ("+l+")";
103 language_combo->addItem( text, l );
104 }
105 }
106}
107
108void PrefInterface::retranslateStrings() {
109 int mainwindow_resize = mainwindow_resize_combo->currentIndex();
110 int timeslider_pos = timeslider_behaviour_combo->currentIndex();
111
112 retranslateUi(this);
113
114 mainwindow_resize_combo->setCurrentIndex(mainwindow_resize);
115 timeslider_behaviour_combo->setCurrentIndex(timeslider_pos);
116
117 // Icons
118 resize_window_icon->setPixmap( Images::icon("resize_window") );
119 /* volume_icon->setPixmap( Images::icon("speaker") ); */
120
121 changeInstanceImages();
122
123 // Seek widgets
124 seek1->setLabel( tr("&Short jump") );
125 seek2->setLabel( tr("&Medium jump") );
126 seek3->setLabel( tr("&Long jump") );
127 seek4->setLabel( tr("Mouse &wheel jump") );
128
129 if (qApp->isLeftToRight()) {
130 seek1->setIcon( Images::icon("forward10s") );
131 seek2->setIcon( Images::icon("forward1m") );
132 seek3->setIcon( Images::icon("forward10m") );
133 } else {
134 seek1->setIcon( Images::flippedIcon("forward10s") );
135 seek2->setIcon( Images::flippedIcon("forward1m") );
136 seek3->setIcon( Images::flippedIcon("forward10m") );
137 }
138 seek4->setIcon( Images::icon("mouse", seek1->icon()->width()) );
139
140 // Language combo
141 int language_item = language_combo->currentIndex();
142 createLanguageCombo();
143 language_combo->setCurrentIndex( language_item );
144
145 // Iconset combo
146 iconset_combo->setItemText( 0, tr("Default") );
147
148#if STYLE_SWITCHING
149 style_combo->setItemText( 0, tr("Default") );
150#endif
151
152 int gui_index = gui_combo->currentIndex();
153 gui_combo->clear();
154 gui_combo->addItem( tr("Default GUI"), "DefaultGUI");
155 gui_combo->addItem( tr("Mini GUI"), "MiniGUI");
156 gui_combo->addItem( tr("Mpc GUI"), "MpcGUI");
157 gui_combo->setCurrentIndex(gui_index);
158
159 floating_width_label->setNum(floating_width_slider->value());
160 floating_margin_label->setNum(floating_margin_slider->value());
161
162 createHelp();
163}
164
165void PrefInterface::setData(Preferences * pref) {
166 setLanguage( pref->language );
167 setIconSet( pref->iconset );
168
169 setResizeMethod( pref->resize_method );
170 setSaveSize( pref->save_window_size_on_exit );
171 setUseSingleInstance(pref->use_single_instance);
172 setServerPort(pref->connection_port);
173 setUseAutoPort(pref->use_autoport);
174 setRecentsMaxItems(pref->history_recents->maxItems());
175
176 setSeeking1(pref->seeking1);
177 setSeeking2(pref->seeking2);
178 setSeeking3(pref->seeking3);
179 setSeeking4(pref->seeking4);
180
181 setUpdateWhileDragging(pref->update_while_seeking);
182 setRelativeSeeking(pref->relative_seeking);
183
184 setDefaultFont(pref->default_font);
185
186#if STYLE_SWITCHING
187 setStyle( pref->style );
188#endif
189
190 setGUI(pref->gui);
191
192 setFloatingAnimated(pref->floating_control_animated);
193 setFloatingWidth(pref->floating_control_width);
194 setFloatingMargin(pref->floating_control_margin);
195 setDisplayFloatingInCompactMode(pref->floating_display_in_compact_mode);
196#ifndef Q_OS_WIN
197 setFloatingBypassWindowManager(pref->bypass_window_manager);
198#endif
199}
200
201void PrefInterface::getData(Preferences * pref) {
202 requires_restart = false;
203 language_changed = false;
204 iconset_changed = false;
205 recents_changed = false;
206 port_changed = false;
207 style_changed = false;
208
209 if (pref->language != language()) {
210 pref->language = language();
211 language_changed = true;
212 qDebug("PrefInterface::getData: chosen language: '%s'", pref->language.toUtf8().data());
213 }
214
215 if (pref->iconset != iconSet()) {
216 pref->iconset = iconSet();
217 iconset_changed = true;
218 }
219
220 pref->resize_method = resizeMethod();
221 pref->save_window_size_on_exit = saveSize();
222
223 pref->use_single_instance = useSingleInstance();
224 if (pref->connection_port != serverPort()) {
225 pref->connection_port = serverPort();
226 port_changed = true;
227 }
228
229 if (pref->use_autoport != useAutoPort()) {
230 pref->use_autoport = useAutoPort();
231 port_changed = true;
232 }
233
234 if (pref->history_recents->maxItems() != recentsMaxItems()) {
235 pref->history_recents->setMaxItems( recentsMaxItems() );
236 recents_changed = true;
237 }
238
239 pref->seeking1 = seeking1();
240 pref->seeking2 = seeking2();
241 pref->seeking3 = seeking3();
242 pref->seeking4 = seeking4();
243
244 pref->update_while_seeking = updateWhileDragging();
245 pref->relative_seeking= relativeSeeking();
246
247 pref->default_font = defaultFont();
248
249#if STYLE_SWITCHING
250 if ( pref->style != style() ) {
251 pref->style = style();
252 style_changed = true;
253 }
254#endif
255
256 pref->gui = GUI();
257
258 pref->floating_control_animated = floatingAnimated();
259 pref->floating_control_width = floatingWidth();
260 pref->floating_control_margin = floatingMargin();
261 pref->floating_display_in_compact_mode = displayFloatingInCompactMode();
262#ifndef Q_OS_WIN
263 pref->bypass_window_manager = floatingBypassWindowManager();
264#endif
265}
266
267void PrefInterface::setLanguage(QString lang) {
268 if (lang.isEmpty()) {
269 language_combo->setCurrentIndex(0);
270 }
271 else {
272 int pos = language_combo->findData(lang);
273 if (pos != -1)
274 language_combo->setCurrentIndex( pos );
275 else
276 language_combo->setCurrentText(lang);
277 }
278}
279
280QString PrefInterface::language() {
281 if (language_combo->currentIndex()==0)
282 return "";
283 else
284 return language_combo->itemData( language_combo->currentIndex() ).toString();
285}
286
287void PrefInterface::setIconSet(QString set) {
288 if (set.isEmpty())
289 iconset_combo->setCurrentIndex(0);
290 else
291 iconset_combo->setCurrentText(set);
292}
293
294QString PrefInterface::iconSet() {
295 if (iconset_combo->currentIndex()==0)
296 return "";
297 else
298 return iconset_combo->currentText();
299}
300
301void PrefInterface::setResizeMethod(int v) {
302 mainwindow_resize_combo->setCurrentIndex(v);
303}
304
305int PrefInterface::resizeMethod() {
306 return mainwindow_resize_combo->currentIndex();
307}
308
309void PrefInterface::setSaveSize(bool b) {
310 save_size_check->setChecked(b);
311}
312
313bool PrefInterface::saveSize() {
314 return save_size_check->isChecked();
315}
316
317
318void PrefInterface::setStyle(QString style) {
319 if (style.isEmpty())
320 style_combo->setCurrentIndex(0);
321 else
322 style_combo->setCurrentText(style);
323}
324
325QString PrefInterface::style() {
326 if (style_combo->currentIndex()==0)
327 return "";
328 else
329 return style_combo->currentText();
330}
331
332void PrefInterface::setGUI(QString gui_name) {
333 int i = gui_combo->findData(gui_name);
334 if (i < 0) i=0;
335 gui_combo->setCurrentIndex(i);
336}
337
338QString PrefInterface::GUI() {
339 return gui_combo->itemData(gui_combo->currentIndex()).toString();
340}
341
342void PrefInterface::setUseSingleInstance(bool b) {
343 single_instance_check->setChecked(b);
344 //singleInstanceButtonToggled(b);
345}
346
347bool PrefInterface::useSingleInstance() {
348 return single_instance_check->isChecked();
349}
350
351void PrefInterface::setServerPort(int port) {
352 server_port_spin->setValue(port);
353}
354
355int PrefInterface::serverPort() {
356 return server_port_spin->value();
357}
358
359void PrefInterface::setUseAutoPort(bool b) {
360 automatic_port_button->setChecked(b);
361 manual_port_button->setChecked(!b);
362}
363
364bool PrefInterface::useAutoPort() {
365 return automatic_port_button->isChecked();
366}
367
368void PrefInterface::setRecentsMaxItems(int n) {
369 recents_max_items_spin->setValue(n);
370}
371
372int PrefInterface::recentsMaxItems() {
373 return recents_max_items_spin->value();
374}
375
376void PrefInterface::setSeeking1(int n) {
377 seek1->setTime(n);
378}
379
380int PrefInterface::seeking1() {
381 return seek1->time();
382}
383
384void PrefInterface::setSeeking2(int n) {
385 seek2->setTime(n);
386}
387
388int PrefInterface::seeking2() {
389 return seek2->time();
390}
391
392void PrefInterface::setSeeking3(int n) {
393 seek3->setTime(n);
394}
395
396int PrefInterface::seeking3() {
397 return seek3->time();
398}
399
400void PrefInterface::setSeeking4(int n) {
401 seek4->setTime(n);
402}
403
404int PrefInterface::seeking4() {
405 return seek4->time();
406}
407
408void PrefInterface::setUpdateWhileDragging(bool b) {
409 if (b)
410 timeslider_behaviour_combo->setCurrentIndex(0);
411 else
412 timeslider_behaviour_combo->setCurrentIndex(1);
413}
414
415bool PrefInterface::updateWhileDragging() {
416 return (timeslider_behaviour_combo->currentIndex() == 0);
417}
418
419void PrefInterface::setRelativeSeeking(bool b) {
420 relative_seeking_button->setChecked(b);
421 absolute_seeking_button->setChecked(!b);
422}
423
424bool PrefInterface::relativeSeeking() {
425 return relative_seeking_button->isChecked();
426}
427
428void PrefInterface::setDefaultFont(QString font_desc) {
429 default_font_edit->setText(font_desc);
430}
431
432QString PrefInterface::defaultFont() {
433 return default_font_edit->text();
434}
435
436void PrefInterface::on_changeFontButton_clicked() {
437 QFont f = qApp->font();
438
439 if (!default_font_edit->text().isEmpty()) {
440 f.fromString(default_font_edit->text());
441 }
442
443 bool ok;
444 f = QFontDialog::getFont( &ok, f, this);
445
446 if (ok) {
447 default_font_edit->setText( f.toString() );
448 }
449}
450
451void PrefInterface::changeInstanceImages() {
452 if (single_instance_check->isChecked())
453 instances_icon->setPixmap( Images::icon("instance1") );
454 else
455 instances_icon->setPixmap( Images::icon("instance2") );
456}
457
458// Floating tab
459void PrefInterface::setFloatingAnimated(bool b) {
460 floating_animated_check->setChecked(b);
461}
462
463bool PrefInterface::floatingAnimated() {
464 return floating_animated_check->isChecked();
465}
466
467void PrefInterface::setFloatingWidth(int percentage) {
468 floating_width_slider->setValue(percentage);
469}
470
471int PrefInterface::floatingWidth() {
472 return floating_width_slider->value();
473}
474
475void PrefInterface::setFloatingMargin(int pixels) {
476 floating_margin_slider->setValue(pixels);
477}
478
479int PrefInterface::floatingMargin() {
480 return floating_margin_slider->value();
481}
482
483void PrefInterface::setDisplayFloatingInCompactMode(bool b) {
484 floating_compact_check->setChecked(b);
485}
486
487bool PrefInterface::displayFloatingInCompactMode() {
488 return floating_compact_check->isChecked();
489}
490
491#ifndef Q_OS_WIN
492void PrefInterface::setFloatingBypassWindowManager(bool b) {
493 floating_bypass_wm_check->setChecked(b);
494}
495
496bool PrefInterface::floatingBypassWindowManager() {
497 return floating_bypass_wm_check->isChecked();
498}
499#endif
500
501void PrefInterface::createHelp() {
502 clearHelp();
503
504 addSectionTitle(tr("Interface"));
505
506 setWhatsThis(mainwindow_resize_combo, tr("Autoresize"),
507 tr("The main window can be resized automatically. Select the option "
508 "you prefer.") );
509
510 setWhatsThis(save_size_check, tr("Remember position and size"),
511 tr("If you check this option, the position and size of the main "
512 "window will be saved and restored when you run SMPlayer again.") );
513
514 setWhatsThis(recents_max_items_spin, tr("Recent files"),
515 tr("Select the maximum number of items that will be shown in the "
516 "<b>Open->Recent files</b> submenu. If you set it to 0 that "
517 "menu won't be shown at all.") );
518
519 setWhatsThis(language_combo, tr("Language"),
520 tr("Here you can change the language of the application.") );
521
522 setWhatsThis(iconset_combo, tr("Icon set"),
523 tr("Select the icon set you prefer for the application.") );
524
525 setWhatsThis(style_combo, tr("Style"),
526 tr("Select the style you prefer for the application.") );
527
528 setWhatsThis(gui_combo, tr("GUI"),
529 tr("Select the GUI you prefer for the application. Currently "
530 "there are two available: Default GUI and Mini GUI.<br>"
531 "The <b>Default GUI</b> provides the traditional GUI, with the "
532 "toolbar and control bar. The <b>Mini GUI</b> provides a "
533 "more simple GUI, without toolbar and a control bar with few "
534 "buttons.<br>"
535 "<b>Note:</b> this option will take effect the next "
536 "time you run SMPlayer.") );
537
538 setWhatsThis(changeFontButton, tr("Default font"),
539 tr("You can change here the application's font.") );
540
541 addSectionTitle(tr("Seeking"));
542
543 setWhatsThis(seek1, tr("Short jump"),
544 tr("Select the time that should be go forward or backward when you "
545 "choose the %1 action.").arg(tr("short jump")) );
546
547 setWhatsThis(seek2, tr("Medium jump"),
548 tr("Select the time that should be go forward or backward when you "
549 "choose the %1 action.").arg(tr("medium jump")) );
550
551 setWhatsThis(seek3, tr("Long jump"),
552 tr("Select the time that should be go forward or backward when you "
553 "choose the %1 action.").arg(tr("long jump")) );
554
555 setWhatsThis(seek4, tr("Mouse wheel jump"),
556 tr("Select the time that should be go forward or backward when you "
557 "move the mouse wheel.") );
558
559 setWhatsThis(timeslider_behaviour_combo, tr("Behaviour of time slider"),
560 tr("Select what to do when dragging the time slider.") );
561
562 setWhatsThis(seeking_method_group, tr("Seeking method"),
563 tr("Sets the method to be used when seeking with the slider. "
564 "Absolute seeking may be a little bit more accurate, while "
565 "relative seeking may work better with files with a wrong length.") );
566
567 addSectionTitle(tr("Instances"));
568
569 setWhatsThis(single_instance_check,
570 tr("Use only one running instance of SMPlayer"),
571 tr("Check this option if you want to use an already running instance "
572 "of SMPlayer when opening other files.") );
573
574 setWhatsThis(automatic_port_button, tr("Automatic port"),
575 tr("SMPlayer needs to listen to a port to receive commands from other "
576 "instances. If you select this option, a port will be "
577 "automatically chosen.") );
578
579 setWhatsThis(server_port_spin, tr("Manual port"),
580 tr("SMPlayer needs to listen to a port to receive commands from other "
581 "instances. You can change the port in case the default one is "
582 "used by another application.") );
583
584 manual_port_button->setWhatsThis( server_port_spin->whatsThis() );
585
586 addSectionTitle(tr("Floating control"));
587
588 setWhatsThis(floating_animated_check, tr("Animated"),
589 tr("If this option is enabled, the floating control will appear "
590 "with an animation.") );
591
592 setWhatsThis(floating_width_slider, tr("Width"),
593 tr("Specifies the width of the control (as a percentage).") );
594
595 setWhatsThis(floating_margin_slider, tr("Margin"),
596 tr("This option sets the number of pixels that the floating control "
597 "will be away from the bottom of the screen. Useful when the "
598 "screen is a TV, as the overscan might prevent the control to be "
599 "visible.") );
600
601 setWhatsThis(floating_compact_check, tr("Display in compact mode too"),
602 tr("If this option is enabled, the floating control will appear "
603 "in compact mode too. <b>Warning:</b> the floating control has not been "
604 "designed for compact mode and it might not work properly.") );
605
606#ifndef Q_OS_WIN
607 setWhatsThis(floating_bypass_wm_check, tr("Bypass window manager"),
608 tr("If this option is checked, the control is displayed bypassing the "
609 "window manager. Disable this option if the floating control "
610 "doesn't work well with your window manager.") );
611#endif
612}
613
614#include "moc_prefinterface.cpp"
Note: See TracBrowser for help on using the repository browser.