source: smplayer/trunk/src/prefadvanced.cpp@ 128

Last change on this file since 128 was 128, checked in by Silvan Scherrer, 13 years ago

SMPlayer: trunk update to latest svn

  • Property svn:eol-style set to LF
File size: 15.7 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
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 "prefadvanced.h"
21#include "images.h"
22#include "preferences.h"
23#include "paths.h"
24#include <QColorDialog>
25
26#define LOGS_TAB 3
27
28PrefAdvanced::PrefAdvanced(QWidget * parent, Qt::WindowFlags f)
29 : PrefWidget(parent, f )
30{
31 setupUi(this);
32
33#ifndef Q_OS_WIN
34 shortnames_check->hide();
35#endif
36
37#if !USE_COLORKEY
38 colorkey_label->hide();
39 colorkey_view->hide();
40 changeButton->hide();
41#endif
42
43#if !REPAINT_BACKGROUND_OPTION
44 repaint_video_background_check->hide();
45#endif
46
47#ifndef LOG_MPLAYER
48 mplayer_log_box->hide();
49#endif
50
51#ifndef LOG_SMPLAYER
52 smplayer_log_box->hide();
53#endif
54
55#if !defined(LOG_MPLAYER) && !defined(LOG_SMPLAYER)
56 advanced_tab->setTabEnabled(LOGS_TAB, false);
57#endif
58
59 // Monitor aspect
60 monitoraspect_combo->addItem("Auto");
61 monitoraspect_combo->addItem("4:3");
62 monitoraspect_combo->addItem("16:9");
63 monitoraspect_combo->addItem("5:4");
64 monitoraspect_combo->addItem("16:10");
65
66 retranslateStrings();
67}
68
69PrefAdvanced::~PrefAdvanced()
70{
71}
72
73QString PrefAdvanced::sectionName() {
74 return tr("Advanced");
75}
76
77QPixmap PrefAdvanced::sectionIcon() {
78 return Images::icon("pref_advanced", 22);
79}
80
81
82void PrefAdvanced::retranslateStrings() {
83 retranslateUi(this);
84
85 monitor_aspect_icon->setPixmap( Images::icon("monitor") );
86
87 monitoraspect_combo->setItemText(0, tr("Auto") );
88
89 createHelp();
90}
91
92void PrefAdvanced::setData(Preferences * pref) {
93 setMonitorAspect( pref->monitor_aspect );
94
95#if REPAINT_BACKGROUND_OPTION
96 setRepaintVideoBackground( pref->repaint_video_background );
97#endif
98 setUseMplayerWindow( pref->use_mplayer_window );
99 setMplayerAdditionalArguments( pref->mplayer_additional_options );
100 setMplayerAdditionalVideoFilters( pref->mplayer_additional_video_filters );
101 setMplayerAdditionalAudioFilters( pref->mplayer_additional_audio_filters );
102#if USE_COLORKEY
103 setColorKey( pref->color_key );
104#endif
105 setPreferIpv4( pref->prefer_ipv4 );
106 setUseIdx( pref->use_idx );
107 setUseCorrectPts( pref->use_correct_pts );
108 setActionsToRun( pref->actions_to_run );
109 setShowTagInTitle( pref->show_tag_in_window_title );
110
111#ifdef LOG_MPLAYER
112 setLogMplayer( pref->log_mplayer );
113 setMplayerLogVerbose( pref->verbose_log );
114 setSaveMplayerLog( pref->autosave_mplayer_log );
115 setMplayerLogName( pref->mplayer_log_saveto );
116#endif
117
118#ifdef LOG_SMPLAYER
119 setLogSmplayer( pref->log_smplayer );
120 setLogFilter( pref->log_filter );
121 setSaveSmplayerLog( pref->save_smplayer_log );
122#endif
123
124 setUseShortNames( pref->use_short_pathnames );
125}
126
127void PrefAdvanced::getData(Preferences * pref) {
128 requires_restart = false;
129
130#if REPAINT_BACKGROUND_OPTION
131 repaint_video_background_changed = false;
132#endif
133
134 monitor_aspect_changed = false;
135#if USE_COLORKEY
136 colorkey_changed = false;
137#endif
138 pref->prefer_ipv4 = preferIpv4();
139 TEST_AND_SET(pref->use_idx, useIdx());
140 TEST_AND_SET(pref->use_correct_pts, useCorrectPts());
141 pref->actions_to_run = actionsToRun();
142 //TEST_AND_SET(pref->show_tag_in_window_title, showTagInTitle());
143 pref->show_tag_in_window_title = showTagInTitle(); // TODO: detect change and apply
144
145 if (pref->monitor_aspect != monitorAspect()) {
146 pref->monitor_aspect = monitorAspect();
147 monitor_aspect_changed = true;
148 requires_restart = true;
149 }
150
151#if REPAINT_BACKGROUND_OPTION
152 if (pref->repaint_video_background != repaintVideoBackground()) {
153 pref->repaint_video_background = repaintVideoBackground();
154 repaint_video_background_changed = true;
155 }
156#endif
157
158 TEST_AND_SET(pref->use_mplayer_window, useMplayerWindow());
159 TEST_AND_SET(pref->mplayer_additional_options, mplayerAdditionalArguments());
160 TEST_AND_SET(pref->mplayer_additional_video_filters, mplayerAdditionalVideoFilters());
161 TEST_AND_SET(pref->mplayer_additional_audio_filters, mplayerAdditionalAudioFilters());
162#if USE_COLORKEY
163 if (pref->color_key != colorKey()) {
164 pref->color_key = colorKey();
165 colorkey_changed = true;
166 requires_restart = true;
167 }
168#endif
169
170#ifdef LOG_MPLAYER
171 pref->log_mplayer = logMplayer();
172 TEST_AND_SET( pref->verbose_log, mplayerLogVerbose() );
173 pref->autosave_mplayer_log = saveMplayerLog();
174 pref->mplayer_log_saveto = mplayerLogName();
175#endif
176
177#ifdef LOG_SMPLAYER
178 pref->log_smplayer = logSmplayer();
179 pref->log_filter = logFilter();
180 pref->save_smplayer_log = saveSmplayerLog();
181#endif
182
183 pref->use_short_pathnames = useShortNames();
184}
185
186void PrefAdvanced::setMonitorAspect(QString asp) {
187 if (asp.isEmpty())
188 monitoraspect_combo->setCurrentIndex( 0 );
189 else
190 monitoraspect_combo->setCurrentText(asp);
191 //monitoraspect_combo->setEditText(asp);
192}
193
194QString PrefAdvanced::monitorAspect() {
195 if (monitoraspect_combo->currentIndex() == 0 )
196 return "";
197 else
198 return monitoraspect_combo->currentText();
199}
200
201#if REPAINT_BACKGROUND_OPTION
202void PrefAdvanced::setRepaintVideoBackground(bool b) {
203 repaint_video_background_check->setChecked(b);
204}
205
206bool PrefAdvanced::repaintVideoBackground() {
207 return repaint_video_background_check->isChecked();
208}
209#endif
210
211void PrefAdvanced::setUseMplayerWindow(bool v) {
212 mplayer_use_window_check->setChecked(v);
213}
214
215bool PrefAdvanced::useMplayerWindow() {
216 return mplayer_use_window_check->isChecked();
217}
218
219void PrefAdvanced::setUseShortNames(bool b) {
220 shortnames_check->setChecked(b);
221}
222
223bool PrefAdvanced::useShortNames() {
224 return shortnames_check->isChecked();
225}
226
227void PrefAdvanced::setMplayerAdditionalArguments(QString args) {
228 mplayer_args_edit->setText(args);
229}
230
231QString PrefAdvanced::mplayerAdditionalArguments() {
232 return mplayer_args_edit->text();
233}
234
235void PrefAdvanced::setMplayerAdditionalVideoFilters(QString s) {
236 mplayer_vfilters_edit->setText(s);
237}
238
239QString PrefAdvanced::mplayerAdditionalVideoFilters() {
240 return mplayer_vfilters_edit->text();
241}
242
243void PrefAdvanced::setMplayerAdditionalAudioFilters(QString s) {
244 mplayer_afilters_edit->setText(s);
245}
246
247QString PrefAdvanced::mplayerAdditionalAudioFilters() {
248 return mplayer_afilters_edit->text();
249}
250
251#if USE_COLORKEY
252void PrefAdvanced::setColorKey(unsigned int c) {
253 QString color = QString::number(c, 16);
254 while (color.length() < 6) color = "0"+color;
255 colorkey_view->setText( "#" + color );
256}
257
258unsigned int PrefAdvanced::colorKey() {
259 QString c = colorkey_view->text();
260 if (c.startsWith("#")) c = c.mid(1);
261
262 bool ok;
263 unsigned int color = c.toUInt(&ok, 16);
264
265 if (!ok)
266 qWarning("PrefAdvanced::colorKey: cannot convert color to uint");
267
268 qDebug("PrefAdvanced::colorKey: color: %s", QString::number(color,16).toUtf8().data() );
269
270 return color;
271}
272#endif
273
274void PrefAdvanced::setPreferIpv4(bool b) {
275 if (b)
276 ipv4_button->setChecked(true);
277 else
278 ipv6_button->setChecked(true);
279}
280
281bool PrefAdvanced::preferIpv4() {
282 return ipv4_button->isChecked();
283}
284
285void PrefAdvanced::setUseIdx(bool b) {
286 idx_check->setChecked(b);
287}
288
289bool PrefAdvanced::useIdx() {
290 return idx_check->isChecked();
291}
292
293void PrefAdvanced::setUseCorrectPts(Preferences::OptionState value) {
294 correct_pts_combo->setState(value);
295}
296
297Preferences::OptionState PrefAdvanced::useCorrectPts() {
298 return correct_pts_combo->state();
299}
300
301void PrefAdvanced::setActionsToRun(QString actions) {
302 actions_to_run_edit->setText(actions);
303}
304
305QString PrefAdvanced::actionsToRun() {
306 return actions_to_run_edit->text();
307}
308
309void PrefAdvanced::setShowTagInTitle(bool b) {
310 show_tag_in_title_check->setChecked(b);
311}
312
313bool PrefAdvanced::showTagInTitle() {
314 return show_tag_in_title_check->isChecked();
315}
316
317void PrefAdvanced::on_changeButton_clicked() {
318 //bool ok;
319 //int color = colorkey_view->text().toUInt(&ok, 16);
320 QColor color( colorkey_view->text() );
321 QColor c = QColorDialog::getColor ( color, this );
322 if (c.isValid()) {
323 //colorkey_view->setText( QString::number( c.rgb(), 16 ) );
324 colorkey_view->setText( c.name() );
325 }
326}
327
328// Log options
329#ifdef LOG_MPLAYER
330void PrefAdvanced::setLogMplayer(bool b) {
331 log_mplayer_check->setChecked(b);
332}
333
334bool PrefAdvanced::logMplayer() {
335 return log_mplayer_check->isChecked();
336}
337
338void PrefAdvanced::setMplayerLogVerbose(bool b) {
339 verbose_check->setChecked(b);
340}
341
342bool PrefAdvanced::mplayerLogVerbose() {
343 return verbose_check->isChecked();
344}
345
346void PrefAdvanced::setSaveMplayerLog(bool b) {
347 log_mplayer_save_check->setChecked(b);
348}
349
350bool PrefAdvanced::saveMplayerLog() {
351 return log_mplayer_save_check->isChecked();
352}
353
354void PrefAdvanced::setMplayerLogName(QString filter) {
355 log_mplayer_save_name->setText(filter);
356}
357
358QString PrefAdvanced::mplayerLogName() {
359 return log_mplayer_save_name->text();
360}
361#endif
362
363#ifdef LOG_SMPLAYER
364void PrefAdvanced::setLogSmplayer(bool b) {
365 log_smplayer_check->setChecked(b);
366}
367
368bool PrefAdvanced::logSmplayer() {
369 return log_smplayer_check->isChecked();
370}
371
372void PrefAdvanced::setLogFilter(QString filter) {
373 log_filter_edit->setText(filter);
374}
375
376QString PrefAdvanced::logFilter() {
377 return log_filter_edit->text();
378}
379
380void PrefAdvanced::setSaveSmplayerLog(bool b) {
381 log_smplayer_save_check->setChecked(b);
382}
383
384bool PrefAdvanced::saveSmplayerLog(){
385 return log_smplayer_save_check->isChecked();
386}
387#endif
388
389void PrefAdvanced::createHelp() {
390 clearHelp();
391
392 addSectionTitle(tr("Advanced"));
393
394 setWhatsThis(monitoraspect_combo, tr("Monitor aspect"),
395 tr("Select the aspect ratio of your monitor.") );
396
397 setWhatsThis(mplayer_use_window_check, tr("Run MPlayer in its own window"),
398 tr("If you check this option, the MPlayer video window won't be "
399 "embedded in SMPlayer's main window but instead it will use its "
400 "own window. Note that mouse and keyboard events will be handled "
401 "directly by MPlayer, that means key shortcuts and mouse clicks "
402 "probably won't work as expected when the MPlayer window has the "
403 "focus.") );
404
405 setWhatsThis(idx_check, tr("Rebuild index if needed"),
406 tr("Rebuilds index of files if no index was found, allowing seeking. "
407 "Useful with broken/incomplete downloads, or badly created files. "
408 "This option only works if the underlying media supports "
409 "seeking (i.e. not with stdin, pipe, etc).<br> "
410 "<b>Note:</b> the creation of the index may take some time.") );
411
412 setWhatsThis(correct_pts_combo, tr("Correct pts"),
413 tr("Switches MPlayer to an experimental mode where timestamps for "
414 "video frames are calculated differently and video filters which "
415 "add new frames or modify timestamps of existing ones are "
416 "supported. The more accurate timestamps can be visible for "
417 "example when playing subtitles timed to scene changes with the "
418 "SSA/ASS library enabled. Without correct pts the subtitle timing "
419 "will typically be off by some frames. This option does not work "
420 "correctly with some demuxers and codecs.") );
421
422#ifdef Q_OS_WIN
423 setWhatsThis(shortnames_check, tr("Pass short filenames (8+3) to MPlayer"),
424 tr("Currently MPlayer can't open filenames which contains characters "
425 "outside the local codepage. Checking this option will make "
426 "SMPlayer to pass to MPlayer the short version of the filenames, "
427 "and thus it will able to open them.") );
428#endif
429
430#if REPAINT_BACKGROUND_OPTION
431 setWhatsThis(repaint_video_background_check,
432 tr("Repaint the background of the video window"),
433 tr("Checking this option may reduce flickering, but it also might "
434 "produce that the video won't be displayed properly.") );
435#endif
436
437#if USE_COLORKEY
438 setWhatsThis(colorkey_view, tr("Colorkey"),
439 tr("If you see parts of the video over any other window, you can "
440 "change the colorkey to fix it. Try to select a color close to "
441 "black.") );
442#endif
443
444 setWhatsThis(actions_to_run_edit, tr("Actions list"),
445 tr("Here you can specify a list of <i>actions</i> which will be "
446 "run every time a file is opened. You'll find all available "
447 "actions in the key shortcut editor in the <b>Keyboard and mouse</b> "
448 "section. The actions must be separated by spaces. Checkable "
449 "actions can be followed by <i>true</i> or <i>false</i> to "
450 "enable or disable the action.") +"<br>"+
451 tr("Example:") +" <i>auto_zoom compact true</i><br>" +
452 tr("Limitation: the actions are run only when a file is opened and "
453 "not when the mplayer process is restarted (e.g. you select an "
454 "audio or video filter).") );
455
456 setWhatsThis(show_tag_in_title_check, tr("Show tag info in window title"),
457 tr("If this option is enabled, information from tags will be "
458 "shown in window title. "
459 "Otherwise only the filename will be shown.") );
460
461 addSectionTitle(tr("Options for MPlayer"));
462
463 setWhatsThis(mplayer_args_edit, tr("Options"),
464 tr("Here you can type options for MPlayer. Write them separated "
465 "by spaces.") );
466
467 setWhatsThis(mplayer_vfilters_edit, tr("Video filters"),
468 tr("Here you can add video filters for MPlayer. Write them separated "
469 "by commas. Don't use spaces!") );
470
471 setWhatsThis(mplayer_afilters_edit, tr("Audio filters"),
472 tr("Here you can add audio filters for MPlayer. Write them separated "
473 "by commas. Don't use spaces!") );
474
475 addSectionTitle(tr("Network"));
476
477 setWhatsThis(ipv4_button, tr("IPv4"),
478 tr("Use IPv4 on network connections. Falls back on IPv6 automatically."));
479
480 setWhatsThis(ipv6_button, tr("IPv6"),
481 tr("Use IPv6 on network connections. Falls back on IPv4 automatically."));
482
483 addSectionTitle(tr("Logs"));
484
485#ifdef LOG_SMPLAYER
486 setWhatsThis(log_smplayer_check, tr("Log SMPlayer output"),
487 tr("If this option is checked, SMPlayer will store the debugging "
488 "messages that SMPlayer outputs "
489 "(you can see the log in <b>Options -> View logs -> SMPlayer</b>). "
490 "This information can be very useful for the developer in case "
491 "you find a bug." ) );
492
493 setWhatsThis(log_smplayer_save_check, tr("Save SMPlayer log to file"),
494 tr("If this option is checked, the SMPlayer log wil be recorded to %1")
495 .arg( "<i>"+ Paths::configPath() + "/smplayer_log.txt</i>" ) );
496#endif
497
498#ifdef LOG_MPLAYER
499 setWhatsThis(log_mplayer_check, tr("Log MPlayer output"),
500 tr("If checked, SMPlayer will store the output of MPlayer "
501 "(you can see it in <b>Options -> View logs -> MPlayer</b>). "
502 "In case of problems this log can contain important information, "
503 "so it's recommended to keep this option checked.") );
504
505 setWhatsThis(log_mplayer_save_check, tr("Autosave MPlayer log"),
506 tr("If this option is checked, the MPlayer log will be saved to the "
507 "specified file every time a new file starts to play. "
508 "It's intended for external applications, so they can get "
509 "info about the file you're playing.") );
510
511 setWhatsThis(log_mplayer_save_name, tr("Autosave MPlayer log filename"),
512 tr("Enter here the path and filename that will be used to save the "
513 "MPlayer log.") );
514#endif
515
516#ifdef LOG_SMPLAYER
517 setWhatsThis(log_filter_edit, tr("Filter for SMPlayer logs"),
518 tr("This option allows to filter the SMPlayer messages that will "
519 "be stored in the log. Here you can write any regular expression.<br>"
520 "For instance: <i>^Core::.*</i> will display only the lines "
521 "starting with <i>Core::</i>") );
522#endif
523}
524
525#include "moc_prefadvanced.cpp"
Note: See TracBrowser for help on using the repository browser.