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

Last change on this file since 112 was 112, checked in by Silvan Scherrer, 15 years ago

Smplayer: eol-style

  • Property svn:eol-style set to LF
File size: 16.5 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2010 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
183 setDefaultFont(pref->default_font);
184
185#if STYLE_SWITCHING
186 setStyle( pref->style );
187#endif
188
189 setGUI(pref->gui);
190
191 setFloatingAnimated(pref->floating_control_animated);
192 setFloatingWidth(pref->floating_control_width);
193 setFloatingMargin(pref->floating_control_margin);
194 setDisplayFloatingInCompactMode(pref->floating_display_in_compact_mode);
195#ifndef Q_OS_WIN
196 setFloatingBypassWindowManager(pref->bypass_window_manager);
197#endif
198}
199
200void PrefInterface::getData(Preferences * pref) {
201 requires_restart = false;
202 language_changed = false;
203 iconset_changed = false;
204 recents_changed = false;
205 port_changed = false;
206 style_changed = false;
207
208 if (pref->language != language()) {
209 pref->language = language();
210 language_changed = true;
211 qDebug("PrefInterface::getData: chosen language: '%s'", pref->language.toUtf8().data());
212 }
213
214 if (pref->iconset != iconSet()) {
215 pref->iconset = iconSet();
216 iconset_changed = true;
217 }
218
219 pref->resize_method = resizeMethod();
220 pref->save_window_size_on_exit = saveSize();
221
222 pref->use_single_instance = useSingleInstance();
223 if (pref->connection_port != serverPort()) {
224 pref->connection_port = serverPort();
225 port_changed = true;
226 }
227
228 if (pref->use_autoport != useAutoPort()) {
229 pref->use_autoport = useAutoPort();
230 port_changed = true;
231 }
232
233 if (pref->history_recents->maxItems() != recentsMaxItems()) {
234 pref->history_recents->setMaxItems( recentsMaxItems() );
235 recents_changed = true;
236 }
237
238 pref->seeking1 = seeking1();
239 pref->seeking2 = seeking2();
240 pref->seeking3 = seeking3();
241 pref->seeking4 = seeking4();
242
243 pref->update_while_seeking = updateWhileDragging();
244
245 pref->default_font = defaultFont();
246
247#if STYLE_SWITCHING
248 if ( pref->style != style() ) {
249 pref->style = style();
250 style_changed = true;
251 }
252#endif
253
254 pref->gui = GUI();
255
256 pref->floating_control_animated = floatingAnimated();
257 pref->floating_control_width = floatingWidth();
258 pref->floating_control_margin = floatingMargin();
259 pref->floating_display_in_compact_mode = displayFloatingInCompactMode();
260#ifndef Q_OS_WIN
261 pref->bypass_window_manager = floatingBypassWindowManager();
262#endif
263}
264
265void PrefInterface::setLanguage(QString lang) {
266 if (lang.isEmpty()) {
267 language_combo->setCurrentIndex(0);
268 }
269 else {
270 int pos = language_combo->findData(lang);
271 if (pos != -1)
272 language_combo->setCurrentIndex( pos );
273 else
274 language_combo->setCurrentText(lang);
275 }
276}
277
278QString PrefInterface::language() {
279 if (language_combo->currentIndex()==0)
280 return "";
281 else
282 return language_combo->itemData( language_combo->currentIndex() ).toString();
283}
284
285void PrefInterface::setIconSet(QString set) {
286 if (set.isEmpty())
287 iconset_combo->setCurrentIndex(0);
288 else
289 iconset_combo->setCurrentText(set);
290}
291
292QString PrefInterface::iconSet() {
293 if (iconset_combo->currentIndex()==0)
294 return "";
295 else
296 return iconset_combo->currentText();
297}
298
299void PrefInterface::setResizeMethod(int v) {
300 mainwindow_resize_combo->setCurrentIndex(v);
301}
302
303int PrefInterface::resizeMethod() {
304 return mainwindow_resize_combo->currentIndex();
305}
306
307void PrefInterface::setSaveSize(bool b) {
308 save_size_check->setChecked(b);
309}
310
311bool PrefInterface::saveSize() {
312 return save_size_check->isChecked();
313}
314
315
316void PrefInterface::setStyle(QString style) {
317 if (style.isEmpty())
318 style_combo->setCurrentIndex(0);
319 else
320 style_combo->setCurrentText(style);
321}
322
323QString PrefInterface::style() {
324 if (style_combo->currentIndex()==0)
325 return "";
326 else
327 return style_combo->currentText();
328}
329
330void PrefInterface::setGUI(QString gui_name) {
331 int i = gui_combo->findData(gui_name);
332 if (i < 0) i=0;
333 gui_combo->setCurrentIndex(i);
334}
335
336QString PrefInterface::GUI() {
337 return gui_combo->itemData(gui_combo->currentIndex()).toString();
338}
339
340void PrefInterface::setUseSingleInstance(bool b) {
341 single_instance_check->setChecked(b);
342 //singleInstanceButtonToggled(b);
343}
344
345bool PrefInterface::useSingleInstance() {
346 return single_instance_check->isChecked();
347}
348
349void PrefInterface::setServerPort(int port) {
350 server_port_spin->setValue(port);
351}
352
353int PrefInterface::serverPort() {
354 return server_port_spin->value();
355}
356
357void PrefInterface::setUseAutoPort(bool b) {
358 automatic_port_button->setChecked(b);
359 manual_port_button->setChecked(!b);
360}
361
362bool PrefInterface::useAutoPort() {
363 return automatic_port_button->isChecked();
364}
365
366void PrefInterface::setRecentsMaxItems(int n) {
367 recents_max_items_spin->setValue(n);
368}
369
370int PrefInterface::recentsMaxItems() {
371 return recents_max_items_spin->value();
372}
373
374void PrefInterface::setSeeking1(int n) {
375 seek1->setTime(n);
376}
377
378int PrefInterface::seeking1() {
379 return seek1->time();
380}
381
382void PrefInterface::setSeeking2(int n) {
383 seek2->setTime(n);
384}
385
386int PrefInterface::seeking2() {
387 return seek2->time();
388}
389
390void PrefInterface::setSeeking3(int n) {
391 seek3->setTime(n);
392}
393
394int PrefInterface::seeking3() {
395 return seek3->time();
396}
397
398void PrefInterface::setSeeking4(int n) {
399 seek4->setTime(n);
400}
401
402int PrefInterface::seeking4() {
403 return seek4->time();
404}
405
406void PrefInterface::setUpdateWhileDragging(bool b) {
407 if (b)
408 timeslider_behaviour_combo->setCurrentIndex(0);
409 else
410 timeslider_behaviour_combo->setCurrentIndex(1);
411}
412
413bool PrefInterface::updateWhileDragging() {
414 return (timeslider_behaviour_combo->currentIndex() == 0);
415}
416
417void PrefInterface::setDefaultFont(QString font_desc) {
418 default_font_edit->setText(font_desc);
419}
420
421QString PrefInterface::defaultFont() {
422 return default_font_edit->text();
423}
424
425void PrefInterface::on_changeFontButton_clicked() {
426 QFont f = qApp->font();
427
428 if (!default_font_edit->text().isEmpty()) {
429 f.fromString(default_font_edit->text());
430 }
431
432 bool ok;
433 f = QFontDialog::getFont( &ok, f, this);
434
435 if (ok) {
436 default_font_edit->setText( f.toString() );
437 }
438}
439
440void PrefInterface::changeInstanceImages() {
441 if (single_instance_check->isChecked())
442 instances_icon->setPixmap( Images::icon("instance1") );
443 else
444 instances_icon->setPixmap( Images::icon("instance2") );
445}
446
447// Floating tab
448void PrefInterface::setFloatingAnimated(bool b) {
449 floating_animated_check->setChecked(b);
450}
451
452bool PrefInterface::floatingAnimated() {
453 return floating_animated_check->isChecked();
454}
455
456void PrefInterface::setFloatingWidth(int percentage) {
457 floating_width_slider->setValue(percentage);
458}
459
460int PrefInterface::floatingWidth() {
461 return floating_width_slider->value();
462}
463
464void PrefInterface::setFloatingMargin(int pixels) {
465 floating_margin_slider->setValue(pixels);
466}
467
468int PrefInterface::floatingMargin() {
469 return floating_margin_slider->value();
470}
471
472void PrefInterface::setDisplayFloatingInCompactMode(bool b) {
473 floating_compact_check->setChecked(b);
474}
475
476bool PrefInterface::displayFloatingInCompactMode() {
477 return floating_compact_check->isChecked();
478}
479
480#ifndef Q_OS_WIN
481void PrefInterface::setFloatingBypassWindowManager(bool b) {
482 floating_bypass_wm_check->setChecked(b);
483}
484
485bool PrefInterface::floatingBypassWindowManager() {
486 return floating_bypass_wm_check->isChecked();
487}
488#endif
489
490void PrefInterface::createHelp() {
491 clearHelp();
492
493 addSectionTitle(tr("Interface"));
494
495 setWhatsThis(mainwindow_resize_combo, tr("Autoresize"),
496 tr("The main window can be resized automatically. Select the option "
497 "you prefer.") );
498
499 setWhatsThis(save_size_check, tr("Remember position and size"),
500 tr("If you check this option, the position and size of the main "
501 "window will be saved and restored when you run SMPlayer again.") );
502
503 setWhatsThis(recents_max_items_spin, tr("Recent files"),
504 tr("Select the maximum number of items that will be shown in the "
505 "<b>Open->Recent files</b> submenu. If you set it to 0 that "
506 "menu won't be shown at all.") );
507
508 setWhatsThis(language_combo, tr("Language"),
509 tr("Here you can change the language of the application.") );
510
511 setWhatsThis(iconset_combo, tr("Icon set"),
512 tr("Select the icon set you prefer for the application.") );
513
514 setWhatsThis(style_combo, tr("Style"),
515 tr("Select the style you prefer for the application.") );
516
517 setWhatsThis(gui_combo, tr("GUI"),
518 tr("Select the GUI you prefer for the application. Currently "
519 "there are two available: Default GUI and Mini GUI.<br>"
520 "The <b>Default GUI</b> provides the traditional GUI, with the "
521 "toolbar and control bar. The <b>Mini GUI</b> provides a "
522 "more simple GUI, without toolbar and a control bar with few "
523 "buttons.<br>"
524 "<b>Note:</b> this option will take effect the next "
525 "time you run SMPlayer.") );
526
527 setWhatsThis(changeFontButton, tr("Default font"),
528 tr("You can change here the application's font.") );
529
530 addSectionTitle(tr("Seeking"));
531
532 setWhatsThis(seek1, tr("Short jump"),
533 tr("Select the time that should be go forward or backward when you "
534 "choose the %1 action.").arg(tr("short jump")) );
535
536 setWhatsThis(seek2, tr("Medium jump"),
537 tr("Select the time that should be go forward or backward when you "
538 "choose the %1 action.").arg(tr("medium jump")) );
539
540 setWhatsThis(seek3, tr("Long jump"),
541 tr("Select the time that should be go forward or backward when you "
542 "choose the %1 action.").arg(tr("long jump")) );
543
544 setWhatsThis(seek4, tr("Mouse wheel jump"),
545 tr("Select the time that should be go forward or backward when you "
546 "move the mouse wheel.") );
547
548 setWhatsThis(timeslider_behaviour_combo, tr("Behaviour of time slider"),
549 tr("Select what to do when dragging the time slider.") );
550
551 addSectionTitle(tr("Instances"));
552
553 setWhatsThis(single_instance_check,
554 tr("Use only one running instance of SMPlayer"),
555 tr("Check this option if you want to use an already running instance "
556 "of SMPlayer when opening other files.") );
557
558 setWhatsThis(automatic_port_button, tr("Automatic port"),
559 tr("SMPlayer needs to listen to a port to receive commands from other "
560 "instances. If you select this option, a port will be "
561 "automatically chosen.") );
562
563 setWhatsThis(server_port_spin, tr("Manual port"),
564 tr("SMPlayer needs to listen to a port to receive commands from other "
565 "instances. You can change the port in case the default one is "
566 "used by another application.") );
567
568 manual_port_button->setWhatsThis( server_port_spin->whatsThis() );
569
570 addSectionTitle(tr("Floating control"));
571
572 setWhatsThis(floating_animated_check, tr("Animated"),
573 tr("If this option is enabled, the floating control will appear "
574 "with an animation.") );
575
576 setWhatsThis(floating_width_slider, tr("Width"),
577 tr("Specifies the width of the control (as a percentage).") );
578
579 setWhatsThis(floating_margin_slider, tr("Margin"),
580 tr("This option sets the number of pixels that the floating control "
581 "will be away from the bottom of the screen. Useful when the "
582 "screen is a TV, as the overscan might prevent the control to be "
583 "visible.") );
584
585 setWhatsThis(floating_compact_check, tr("Display in compact mode too"),
586 tr("If this option is enabled, the floating control will appear "
587 "in compact mode too. <b>Warning:</b> the floating control has not been "
588 "designed for compact mode and it might not work properly.") );
589
590#ifndef Q_OS_WIN
591 setWhatsThis(floating_bypass_wm_check, tr("Bypass window manager"),
592 tr("If this option is checked, the control is displayed bypassing the "
593 "window manager. Disable this option if the floating control "
594 "doesn't work well with your window manager.") );
595#endif
596}
597
598#include "moc_prefinterface.cpp"
Note: See TracBrowser for help on using the repository browser.