1 /**
2 * Copyright (C) 2002-2003 by Koos Vriezen <koos.vriezen@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
18
19 #include <algorithm>
20 #include <functional>
21 #include <assert.h>
22
23 #include "config-kmplayer.h"
24 #include <qcheckbox.h>
25 #include <qtextedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
28 #include <qtabwidget.h>
29 #include <qslider.h>
30 #include <qspinbox.h>
31 #include <qlabel.h>
32 #include <qfileinfo.h>
33 #include <QButtonGroup>
34 #include <QListWidget>
35
36 #include <kurlrequester.h>
37 #include <klineedit.h>
38 #include <kstatusbar.h>
39
40 #include <kconfig.h>
41 #include <kconfiggroup.h>
42 #include <kurl.h>
43 #include <kdebug.h>
44 #include <klocale.h>
45 #include <kcombobox.h>
46 #include <kmessagebox.h>
47 #include <kglobalsettings.h>
48 #include <kcolorscheme.h>
49
50 #include "kmplayerconfig.h"
51 #include "kmplayerpartbase.h"
52 #include "kmplayerprocess.h"
53 #include "playlistview.h"
54 #include "viewarea.h"
55 #include "pref.h"
56
57 using namespace KMPlayer;
58
59 static OutputDriver _ads[] = {
60 { "alsa,oss,sdl,arts", i18n ("Auto") },
61 { "oss", i18n ("Open Sound System") },
62 { "sdl", i18n ("Simple DirectMedia Layer") },
63 { "alsa", i18n ("Advanced Linux Sound Architecture") },
64 { "arts", i18n ("Analog Real-Time Synthesizer") },
65 { "jack", i18n ("JACK Audio Connection Kit") },
66 { "openal", i18n ("OpenAL") },
67 { "esd", i18n ("Enlightened Sound Daemon") },
68 { "alsa5", i18n ("Advanced Linux Sound Architecture v0.5") },
69 { "alsa9", i18n ("Advanced Linux Sound Architecture v0.9") },
70 { "", i18n ("Use back-end defaults") },
71 { "pulse", i18n ("PulseAudio") },
72 { 0, QString () }
73 };
74
75 static OutputDriver _vds [] = {
76 { "xv,sdl,x11", i18n ("Auto") },
77 { "x11", i18n ("X11Shm") },
78 { "xvidix", i18n ("XVidix") },
79 { "xvmc,xv", i18n ("XvMC") },
80 { "sdl", i18n ("SDL") },
81 { "gl", i18n ("OpenGL") },
82 { "gl2", i18n ("OpenGL MT") },
83 { "xv", i18n ("XVideo") },
84 { "vdpau", i18n ("Video Decode and Presentation API for Unix") },
85 { 0, QString () }
86 };
87
88 static const int ADRIVER_ARTS_INDEX = 4;
89
90
Settings(PartBase * player,KSharedConfigPtr config)91 KDE_NO_CDTOR_EXPORT Settings::Settings (PartBase * player, KSharedConfigPtr config)
92 : pagelist (0L), configdialog (0L), m_config (config), m_player (player) {
93 audiodrivers = _ads;
94 videodrivers = _vds;
95 colors [ColorSetting::playlist_background].title = i18n ("Playlist background");
96 colors [ColorSetting::playlist_background].option = "PlaylistBackground";
97 colors [ColorSetting::playlist_background].color =
98 KColorScheme(QPalette::Active, KColorScheme::View).background().color();
99 colors [ColorSetting::playlist_foreground].title = i18n ("Playlist foreground");
100 colors [ColorSetting::playlist_foreground].option = "PlaylistForeground";
101 colors [ColorSetting::playlist_foreground].color =
102 KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
103 colors [ColorSetting::console_background].title =i18n("Console background");
104 colors [ColorSetting::playlist_active].title = i18n("Playlist active item");
105 colors [ColorSetting::playlist_active].option = "PlaylistActive";
106 colors [ColorSetting::playlist_active].color =
107 KColorScheme(QPalette::Active, KColorScheme::Selection).foreground().color();
108 colors [ColorSetting::console_background].option = "ConsoleBackground";
109 colors [ColorSetting::console_background].color = QColor (0, 0, 0);
110 colors [ColorSetting::console_foreground].title = i18n ("Console foreground");
111 colors [ColorSetting::console_foreground].option = "ConsoleForeground";
112 colors [ColorSetting::console_foreground].color = QColor (0xB2, 0xB2, 0xB2);
113 colors [ColorSetting::video_background].title = i18n ("Video background");
114 colors [ColorSetting::video_background].option = "VideoBackground";
115 colors [ColorSetting::video_background].color = QColor (0, 0, 0);
116 colors [ColorSetting::area_background].title = i18n ("Viewing area background");
117 colors [ColorSetting::area_background].option = "ViewingAreaBackground";
118 colors [ColorSetting::area_background].color = QColor (0, 0, 0);
119 colors [ColorSetting::infowindow_background].title = i18n ("Info window background");
120 colors [ColorSetting::infowindow_background].option ="InfoWindowBackground";
121 colors [ColorSetting::infowindow_background].color =
122 KColorScheme(QPalette::Active, KColorScheme::View).background().color();
123 colors [ColorSetting::infowindow_foreground].title = i18n ("Info window foreground");
124 colors [ColorSetting::infowindow_foreground].option ="InfoWindowForeground";
125 colors [ColorSetting::infowindow_foreground].color =
126 colors [ColorSetting::playlist_foreground].color;
127 fonts [FontSetting::playlist].title = i18n ("Playlist");
128 fonts [FontSetting::playlist].option = "PlaylistFont";
129 fonts [FontSetting::playlist].font = KGlobalSettings::generalFont();
130 fonts [FontSetting::playlist].font.setItalic (true);
131 fonts [FontSetting::infowindow].title = i18n ("Info window");
132 fonts [FontSetting::infowindow].option = "InfoWindowFont";
133 fonts [FontSetting::infowindow].font = KGlobalSettings::generalFont();
134 }
135
~Settings()136 KDE_NO_CDTOR_EXPORT Settings::~Settings () {
137 // configdialog should be destroyed when the view is destroyed
138 //delete configdialog;
139 }
140
141 KDE_EXPORT const char * strMPlayerGroup = "MPlayer";
142 const char * strGeneralGroup = "General Options";
143 static const char * strKeepSizeRatio = "Keep Size Ratio";
144 static const char * strRememberSize = "Remember Size";
145 static const char * strAutoResize = "Auto Resize";
146 static const char * strDockSysTray = "Dock in System Tray";
147 static const char * strNoIntro = "No Intro";
148 static const char * strVolume = "Volume";
149 static const char * strContrast = "Contrast";
150 static const char * strBrightness = "Brightness";
151 static const char * strHue = "Hue";
152 static const char * strSaturation = "Saturation";
153 static const char * strURLList = "URL List";
154 static const char * strSubURLList = "URL Sub Title List";
155 static const char * strPrefBitRate = "Preferred Bitrate";
156 static const char * strMaxBitRate = "Maximum Bitrate";
157 //static const char * strUseArts = "Use aRts";
158 static const char * strVoDriver = "Video Driver";
159 static const char * strAoDriver = "Audio Driver";
160 static const char * strLoop = "Loop";
161 static const char * strFrameDrop = "Frame Drop";
162 static const char * strAdjustVolume = "Auto Adjust Volume";
163 static const char * strAdjustColors = "Auto Adjust Colors";
164 static const char * strAddConfigButton = "Add Configure Button";
165 static const char * strAddPlaylistButton = "Add Playlist Button";
166 static const char * strAddRecordButton = "Add Record Button";
167 static const char * strAddBroadcastButton = "Add Broadcast Button";
168 //static const char * strAutoHideSlider = "Auto Hide Slider";
169 static const char * strSeekTime = "Forward/Backward Seek Time";
170 static const char * strDVDDevice = "DVD Device";
171 //static const char * strShowDVD = "Show DVD Menu";
172 //static const char * strShowVCD = "Show VCD Menu";
173 static const char * strVCDDevice = "VCD Device";
174 const char * strUrlBackend = "URL Backend";
175 static const char * strClickToPlay = "Click to Play";
176 static const char * strAllowHref = "Allow HREF";
177 // postproc thingies
178 static const char * strPPGroup = "Post processing options";
179 static const char * strPostProcessing = "Post processing";
180 static const char * strDisablePPauto = "Automatically disable post processing";
181 static const char * strPP_Default = "Default preset";
182 static const char * strPP_Fast = "Fast preset";
183 static const char * strPP_Custom = "Custom preset";
184
185 static const char * strCustom_Hz = "Horizontal deblocking";
186 static const char * strCustom_Hz_Aq = "Horizontal deblocking auto quality";
187 static const char * strCustom_Hz_Ch = "Horizontal deblocking chrominance";
188
189 static const char * strCustom_Vt = "Vertical deblocking";
190 static const char * strCustom_Vt_Aq = "Vertical deblocking auto quality";
191 static const char * strCustom_Vt_Ch = "Vertical deblocking chrominance";
192
193 static const char * strCustom_Dr = "Dering filter";
194 static const char * strCustom_Dr_Aq = "Dering auto quality";
195 static const char * strCustom_Dr_Ch = "Dering chrominance";
196
197 static const char * strCustom_Al = "Autolevel";
198 static const char * strCustom_Al_F = "Autolevel full range";
199
200 static const char * strCustom_Tn = "Temporal Noise Reducer";
201 static const char * strCustom_Tn_S = "Temporal Noise Reducer strength";
202
203 static const char * strPP_Lin_Blend_Int = "Linear Blend Deinterlacer";
204 static const char * strPP_Lin_Int = "Linear Interpolating Deinterlacer";
205 static const char * strPP_Cub_Int = "Cubic Interpolating Deinterlacer";
206 static const char * strPP_Med_Int = "Median Interpolating Deinterlacer";
207 static const char * strPP_FFmpeg_Int = "FFmpeg Interpolating Deinterlacer";
208 // end of postproc
209 // recording
210 static const char * strRecordingGroup = "Recording";
211 static const char * strRecorder = "Recorder";
212 static const char * strMencoderArgs = "Mencoder Arguments";
213 static const char * strFFMpegArgs = "FFMpeg Arguments";
214 static const char * strRecordingFile = "Last Recording Output File";
215 static const char * strAutoPlayAfterRecording = "Auto Play After Recording";
216 static const char * strAutoPlayAfterTime = "Auto Play After Recording Time";
217 static const char * strRecordingCopy = "Recording Is Copy";
218
applyColorSetting(bool only_changed_ones)219 KDE_NO_EXPORT void Settings::applyColorSetting (bool only_changed_ones) {
220 View *view = static_cast <View *> (m_player->view ());
221 if (!view) return;
222 for (int i = 0; i < int (ColorSetting::last_target); i++)
223 if (!only_changed_ones || colors[i].color != colors[i].newcolor) {
224 colors[i].color = colors[i].newcolor;
225 QPalette palette;
226 switch (ColorSetting::Target (i)) {
227 case ColorSetting::playlist_background:
228 palette.setColor (view->playList()->viewport ()->backgroundRole(), colors[i].color);
229 view->playList()->viewport ()->setPalette (palette);
230 break;
231 case ColorSetting::playlist_foreground:
232 palette.setColor (view->playList()->foregroundRole(), colors[i].color);
233 view->playList()->setPalette (palette);
234 break;
235 case ColorSetting::playlist_active:
236 view->playList()->setActiveForegroundColor (colors[i].color);
237 break;
238 case ColorSetting::console_background:
239 palette.setColor (view->console()->backgroundRole(), colors[i].color);
240 view->console()->setPalette (palette);
241 break;
242 case ColorSetting::console_foreground:
243 palette.setColor (view->console()->foregroundRole(), colors[i].color);
244 view->console()->setPalette (palette);
245 break;
246 case ColorSetting::video_background:
247 //palette.setColor (view->viewer()->backgroundRole(), colors[i].color);
248 //view->viewer()->setPalette (palette);
249 break;
250 case ColorSetting::area_background:
251 palette.setColor (view->viewArea()->backgroundRole(), colors[i].color);
252 view->viewArea()->setPalette (palette);
253 break;
254 case ColorSetting::infowindow_background:
255 palette.setColor(view->infoPanel()->backgroundRole(), colors[i].color);
256 view->infoPanel()->setPalette (palette);
257 break;
258 case ColorSetting::infowindow_foreground:
259 palette.setColor(view->infoPanel()->foregroundRole(), colors[i].color);
260 view->infoPanel()->setPalette (palette);
261 break;
262 default:
263 ;
264 }
265 }
266 for (int i = 0; i < int (FontSetting::last_target); i++)
267 if (!only_changed_ones || fonts[i].font != fonts[i].newfont) {
268 fonts[i].font = fonts[i].newfont;
269 switch (FontSetting::Target (i)) {
270 case FontSetting::playlist:
271 view->playList ()->setFont (fonts[i].font);
272 break;
273 case FontSetting::infowindow:
274 view->infoPanel ()->setFont (fonts[i].font);
275 break;
276 default:
277 ;
278 }
279 }
280 }
281
defaultView()282 View * Settings::defaultView () {
283 return static_cast <View *> (m_player->view ());
284 }
285
readConfig()286 KDE_NO_EXPORT void Settings::readConfig () {
287 KConfigGroup general (m_config, strGeneralGroup);
288 no_intro = general.readEntry (strNoIntro, false);
289 urllist = general.readEntry (strURLList, QStringList());
290 sub_urllist = general.readEntry (strSubURLList, QStringList());
291 prefbitrate = general.readEntry (strPrefBitRate, 512);
292 maxbitrate = general.readEntry (strMaxBitRate, 1024);
293 volume = general.readEntry (strVolume, 20);
294 contrast = general.readEntry (strContrast, 0);
295 brightness = general.readEntry (strBrightness, 0);
296 hue = general.readEntry (strHue, 0);
297 saturation = general.readEntry (strSaturation, 0);
298 const QMap <QString, Source*>::const_iterator e = m_player->sources ().constEnd ();
299 QMap <QString, Source *>::const_iterator i = m_player->sources().constBegin ();
300 for (; i != e; ++i)
301 backends[i.value()->name ()] = general.readEntry (i.value()->name ());
302 for (int i = 0; i < int (ColorSetting::last_target); i++)
303 colors[i].newcolor = colors[i].color = general.readEntry (colors[i].option, colors[i].color);
304 for (int i = 0; i < int (FontSetting::last_target); i++)
305 fonts[i].newfont = fonts[i].font = general.readEntry (fonts[i].option, fonts[i].font);
306
307 KConfigGroup mplayer (m_config, strMPlayerGroup);
308 sizeratio = mplayer.readEntry (strKeepSizeRatio, true);
309 remembersize = mplayer.readEntry (strRememberSize, true);
310 autoresize = mplayer.readEntry (strAutoResize, true);
311 docksystray = mplayer.readEntry (strDockSysTray, true);
312 loop = mplayer.readEntry (strLoop, false);
313 framedrop = mplayer.readEntry (strFrameDrop, true);
314 autoadjustvolume = mplayer.readEntry (strAdjustVolume, true);
315 autoadjustcolors = mplayer.readEntry (strAdjustColors, true);
316 showcnfbutton = mplayer.readEntry (strAddConfigButton, true);
317 showrecordbutton = mplayer.readEntry (strAddRecordButton, true);
318 showbroadcastbutton = mplayer.readEntry (strAddBroadcastButton, true);
319 showplaylistbutton = mplayer.readEntry (strAddPlaylistButton, true);
320 seektime = mplayer.readEntry (strSeekTime, 10);
321 dvddevice = mplayer.readEntry (strDVDDevice, "/dev/dvd");
322 vcddevice = mplayer.readEntry (strVCDDevice, "/dev/cdrom");
323 videodriver = mplayer.readEntry (strVoDriver, 0);
324 audiodriver = mplayer.readEntry (strAoDriver, 0);
325 clicktoplay = mplayer.readEntry (strClickToPlay, false);
326 grabhref = mplayer.readEntry (strAllowHref, false);
327
328 // recording
329 KConfigGroup rec_cfg (m_config, strRecordingGroup);
330 mencoderarguments = rec_cfg.readEntry (strMencoderArgs, QString ("-oac mp3lame -ovc lavc"));
331 ffmpegarguments = rec_cfg.readEntry (strFFMpegArgs, QString ("-f avi -acodec mp3 -vcodec mpeg4"));
332 recordfile = rec_cfg.readPathEntry(strRecordingFile, QDir::homePath () + "/record.avi");
333 recorder = Recorder (rec_cfg.readEntry (strRecorder, int (MEncoder)));
334 replayoption = ReplayOption (rec_cfg.readEntry (strAutoPlayAfterRecording, int (ReplayFinished)));
335 replaytime = rec_cfg.readEntry (strAutoPlayAfterTime, 60);
336 recordcopy = rec_cfg.readEntry(strRecordingCopy, true);
337
338 // postproc
339 KConfigGroup pp_cfg (m_config, strPPGroup);
340 postprocessing = pp_cfg.readEntry (strPostProcessing, false);
341 disableppauto = pp_cfg.readEntry (strDisablePPauto, true);
342
343 pp_default = pp_cfg.readEntry (strPP_Default, true);
344 pp_fast = pp_cfg.readEntry (strPP_Fast, false);
345 pp_custom = pp_cfg.readEntry (strPP_Custom, false);
346 // default these to default preset
347 pp_custom_hz = pp_cfg.readEntry (strCustom_Hz, true);
348 pp_custom_hz_aq = pp_cfg.readEntry (strCustom_Hz_Aq, true);
349 pp_custom_hz_ch = pp_cfg.readEntry (strCustom_Hz_Ch, false);
350
351 pp_custom_vt = pp_cfg.readEntry (strCustom_Vt, true);
352 pp_custom_vt_aq = pp_cfg.readEntry (strCustom_Vt_Aq, true);
353 pp_custom_vt_ch = pp_cfg.readEntry (strCustom_Vt_Ch, false);
354
355 pp_custom_dr = pp_cfg.readEntry (strCustom_Dr, true);
356 pp_custom_dr_aq = pp_cfg.readEntry (strCustom_Dr_Aq, true);
357 pp_custom_dr_ch = pp_cfg.readEntry (strCustom_Dr_Ch, false);
358
359 pp_custom_al = pp_cfg.readEntry (strCustom_Al, true);
360 pp_custom_al_f = pp_cfg.readEntry (strCustom_Al_F, false);
361
362 pp_custom_tn = pp_cfg.readEntry (strCustom_Tn, true);
363 pp_custom_tn_s = pp_cfg.readEntry (strCustom_Tn_S, 0);
364
365 pp_lin_blend_int = pp_cfg.readEntry (strPP_Lin_Blend_Int, false);
366 pp_lin_int = pp_cfg.readEntry (strPP_Lin_Int, false);
367 pp_cub_int = pp_cfg.readEntry (strPP_Cub_Int, false);
368 pp_med_int = pp_cfg.readEntry (strPP_Med_Int, false);
369 pp_ffmpeg_int = pp_cfg.readEntry (strPP_FFmpeg_Int, false);
370
371 for (PreferencesPage * p = pagelist; p; p = p->next)
372 p->read (m_config);
373 emit configChanged ();
374 }
375
createDialog()376 KDE_NO_EXPORT bool Settings::createDialog () {
377 if (configdialog) return false;
378 configdialog = new Preferences (m_player, this);
379 const MediaManager::ProcessInfoMap::const_iterator e = m_player->mediaManager()->processInfos ().constEnd ();
380 for (MediaManager::ProcessInfoMap::const_iterator i = m_player->mediaManager()->processInfos ().constBegin(); i != e; ++i) {
381 ProcessInfo *p = i.value ();
382 if (p->supports ("urlsource")) {
383 QString lbl = p->label.remove (QChar ('&'));
384 configdialog->m_SourcePageURL->backend->addItem(lbl);
385 }
386 }
387 assert(configdialog->m_SourcePageURL->backend->count() > 0);
388 connect (configdialog, SIGNAL (accepted ()),
389 this, SLOT (okPressed ()));
390 connect (configdialog->button(QDialogButtonBox::Apply), SIGNAL(clicked ()),
391 this, SLOT (okPressed ()));
392 /*if (KApplication::kApplication())
393 connect (configdialog, SIGNAL (helpClicked ()),
394 this, SLOT (getHelp ()));*/
395 return true;
396 }
397
addPage(PreferencesPage * page)398 void Settings::addPage (PreferencesPage * page) {
399 for (PreferencesPage * p = pagelist; p; p = p->next)
400 if (p == page)
401 return;
402 page->read (m_config);
403 if (configdialog) {
404 configdialog->addPrefPage (page);
405 page->sync (false);
406 }
407 page->next = pagelist;
408 pagelist = page;
409 }
410
removePage(PreferencesPage * page)411 void Settings::removePage (PreferencesPage * page) {
412 if (configdialog)
413 configdialog->removePrefPage (page);
414 PreferencesPage * prev = 0L;
415 for (PreferencesPage * p = pagelist; p; prev = p, p = p->next)
416 if (p == page) {
417 if (prev)
418 prev->next = p->next;
419 else
420 pagelist = p->next;
421 break;
422 }
423 }
424
selectItem(QButtonGroup * group,int id)425 static void selectItem(QButtonGroup* group, int id) {
426 const QList<QAbstractButton *> buttons = group->buttons();
427 for (int i = 0; i < buttons.size(); ++i)
428 buttons[i]->setChecked(group->id(buttons[i]) == id);
429 }
430
show(const char * pagename)431 void Settings::show (const char * pagename) {
432 bool created = createDialog ();
433 configdialog->m_GeneralPageGeneral->keepSizeRatio->setChecked (sizeratio);
434 configdialog->m_GeneralPageGeneral->autoResize->setChecked (autoresize);
435 configdialog->m_GeneralPageGeneral->sizesChoice->button(0)->setChecked(!remembersize);
436 configdialog->m_GeneralPageGeneral->sizesChoice->button(1)->setChecked(remembersize);
437 configdialog->m_GeneralPageGeneral->dockSysTray->setChecked (docksystray);
438 configdialog->m_GeneralPageGeneral->loop->setChecked (loop);
439 configdialog->m_GeneralPageGeneral->framedrop->setChecked (framedrop);
440 configdialog->m_GeneralPageGeneral->adjustvolume->setChecked (autoadjustvolume);
441 configdialog->m_GeneralPageGeneral->adjustcolors->setChecked (autoadjustcolors);
442 //configdialog->m_GeneralPageGeneral->autoHideSlider->setChecked (autohideslider);
443 configdialog->m_GeneralPageGeneral->showConfigButton->setChecked (showcnfbutton);
444 configdialog->m_GeneralPageGeneral->showPlaylistButton->setChecked (showplaylistbutton);
445 configdialog->m_GeneralPageGeneral->showRecordButton->setChecked (showrecordbutton);
446 configdialog->m_GeneralPageGeneral->showBroadcastButton->setChecked (showbroadcastbutton);
447 configdialog->m_GeneralPageGeneral->seekTime->setValue(seektime);
448 for (int i = 0; i < int (ColorSetting::last_target); i++)
449 colors[i].newcolor = colors[i].color;
450 for (int i = 0; i < int (FontSetting::last_target); i++)
451 fonts[i].newfont = fonts[i].font;
452
453 QString current = m_player->source()->url().prettyUrl();
454 if (!current.isEmpty() && !urllist.contains(current))
455 urllist.push_front(current);
456 configdialog->m_SourcePageURL->urllist->clear ();
457 configdialog->m_SourcePageURL->urllist->insertItems (0, urllist);
458 if (!current.isEmpty())
459 configdialog->m_SourcePageURL->urllist->setCurrentText(current);
460 else
461 configdialog->m_SourcePageURL->urllist->setCurrentIndex(-1);
462 current = m_player->source()->subUrl().prettyUrl();
463 if (!current.isEmpty() && !sub_urllist.contains(current))
464 sub_urllist.push_front(current);
465 configdialog->m_SourcePageURL->sub_urllist->clear ();
466 configdialog->m_SourcePageURL->sub_urllist->insertItems (0, sub_urllist);
467 if (!current.isEmpty())
468 configdialog->m_SourcePageURL->sub_urllist->setCurrentText(current);
469 else
470 configdialog->m_SourcePageURL->sub_urllist->setCurrentIndex(-1);
471 configdialog->m_SourcePageURL->changed = false;
472
473 configdialog->m_SourcePageURL->prefBitRate->setText (QString::number (prefbitrate));
474 configdialog->m_SourcePageURL->maxBitRate->setText (QString::number (maxbitrate));
475
476 configdialog->m_GeneralPageOutput->videoDriver->setCurrentRow(videodriver);
477 configdialog->m_GeneralPageOutput->audioDriver->setCurrentRow(audiodriver);
478 configdialog->m_SourcePageURL->backend->setCurrentItem(configdialog->m_SourcePageURL->backend->findItems(backends["urlsource"], Qt::MatchFixedString).first());
479 int id = 0;
480 const MediaManager::ProcessInfoMap::const_iterator e = m_player->mediaManager()->processInfos ().constEnd ();
481 for (MediaManager::ProcessInfoMap::const_iterator i = m_player->mediaManager()->processInfos ().constBegin(); i != e; ++i) {
482 ProcessInfo *p = i.value ();
483 if (p->supports ("urlsource")) {
484 if (backends["urlsource"] == QString (p->name))
485 configdialog->m_SourcePageURL->backend->setCurrentRow(id);
486 id++;
487 }
488 }
489 configdialog->m_SourcePageURL->clicktoplay->setChecked (clicktoplay);
490 configdialog->m_SourcePageURL->grabhref->setChecked (grabhref);
491
492 // postproc
493 configdialog->m_OPPagePostproc->postProcessing->setChecked (postprocessing);
494 configdialog->m_OPPagePostproc->disablePPauto->setChecked (disableppauto);
495 configdialog->m_OPPagePostproc->PostprocessingOptions->setEnabled (postprocessing);
496
497 configdialog->m_OPPagePostproc->defaultPreset->setChecked (pp_default);
498 configdialog->m_OPPagePostproc->fastPreset->setChecked (pp_fast);
499 configdialog->m_OPPagePostproc->customPreset->setChecked (pp_custom);
500
501 configdialog->m_OPPagePostproc->HzDeblockFilter->setChecked (pp_custom_hz);
502 configdialog->m_OPPagePostproc->HzDeblockAQuality->setChecked (pp_custom_hz_aq);
503 configdialog->m_OPPagePostproc->HzDeblockCFiltering->setChecked (pp_custom_hz_ch);
504
505 configdialog->m_OPPagePostproc->VtDeblockFilter->setChecked (pp_custom_vt);
506 configdialog->m_OPPagePostproc->VtDeblockAQuality->setChecked (pp_custom_vt_aq);
507 configdialog->m_OPPagePostproc->VtDeblockCFiltering->setChecked (pp_custom_vt_ch);
508
509 configdialog->m_OPPagePostproc->DeringFilter->setChecked (pp_custom_dr);
510 configdialog->m_OPPagePostproc->DeringAQuality->setChecked (pp_custom_dr_aq);
511 configdialog->m_OPPagePostproc->DeringCFiltering->setChecked (pp_custom_dr_ch);
512
513 configdialog->m_OPPagePostproc->AutolevelsFilter->setChecked (pp_custom_al);
514 configdialog->m_OPPagePostproc->AutolevelsFullrange->setChecked (pp_custom_al_f);
515 configdialog->m_OPPagePostproc->TmpNoiseFilter->setChecked (pp_custom_tn);
516 //configdialog->m_OPPagePostproc->TmpNoiseSlider->setValue (pp_custom_tn_s);
517
518 configdialog->m_OPPagePostproc->LinBlendDeinterlacer->setChecked (pp_lin_blend_int);
519 configdialog->m_OPPagePostproc->LinIntDeinterlacer->setChecked (pp_lin_int);
520 configdialog->m_OPPagePostproc->CubicIntDeinterlacer->setChecked (pp_cub_int);
521 configdialog->m_OPPagePostproc->MedianDeinterlacer->setChecked (pp_med_int);
522 configdialog->m_OPPagePostproc->FfmpegDeinterlacer->setChecked (pp_ffmpeg_int);
523 // recording
524 configdialog->m_RecordPage->url->lineEdit()->setText (recordfile);
525 selectItem(configdialog->m_RecordPage->replay, int (replayoption));
526 selectItem(configdialog->m_RecordPage->recorder, int (recorder));
527 configdialog->m_RecordPage->replayClicked (int (replayoption));
528 configdialog->m_RecordPage->recorderClicked (int (recorder));
529 configdialog->m_RecordPage->replaytime->setValue (replaytime);
530 configdialog->m_MEncoderPage->arguments->setText (mencoderarguments);
531 selectItem(configdialog->m_MEncoderPage->format, recordcopy ? 0 : 1);
532 configdialog->m_MEncoderPage->formatClicked (recordcopy ? 0 : 1);
533 configdialog->m_FFMpegPage->arguments->setText (ffmpegarguments);
534
535 //dynamic stuff
536 for (PreferencesPage * p = pagelist; p; p = p->next)
537 p->sync (false);
538 //\dynamic stuff
539 if (pagename)
540 configDialog ()->setPage (pagename);
541 if (created)
542 configdialog->resize (configdialog->minimumSize ());
543 configdialog->show ();
544 }
545
writeConfig()546 void Settings::writeConfig () {
547 KConfigGroup gen_cfg (m_config, strGeneralGroup);
548 gen_cfg.writeEntry (strURLList, urllist);
549 gen_cfg.writeEntry (strSubURLList, sub_urllist);
550 gen_cfg.writeEntry (strPrefBitRate, prefbitrate);
551 gen_cfg.writeEntry (strMaxBitRate, maxbitrate);
552 gen_cfg.writeEntry (strVolume, volume);
553 gen_cfg.writeEntry (strContrast, contrast);
554 gen_cfg.writeEntry (strBrightness, brightness);
555 gen_cfg.writeEntry (strHue, hue);
556 gen_cfg.writeEntry (strSaturation, saturation);
557 const QMap<QString,QString>::ConstIterator b_end = backends.constEnd ();
558 for (QMap<QString,QString>::ConstIterator i = backends.constBegin(); i != b_end; ++i)
559 gen_cfg.writeEntry (i.key (), i.value ());
560 for (int i = 0; i < int (ColorSetting::last_target); i++)
561 gen_cfg.writeEntry (colors[i].option, colors[i].color);
562 for (int i = 0; i < int (FontSetting::last_target); i++)
563 gen_cfg.writeEntry (fonts[i].option, fonts[i].font);
564
565 KConfigGroup mplayer_cfg (m_config, strMPlayerGroup);
566 mplayer_cfg.writeEntry (strKeepSizeRatio, sizeratio);
567 mplayer_cfg.writeEntry (strAutoResize, autoresize);
568 mplayer_cfg.writeEntry (strRememberSize, remembersize);
569 mplayer_cfg.writeEntry (strDockSysTray, docksystray);
570 mplayer_cfg.writeEntry (strLoop, loop);
571 mplayer_cfg.writeEntry (strFrameDrop, framedrop);
572 mplayer_cfg.writeEntry (strAdjustVolume, autoadjustvolume);
573 mplayer_cfg.writeEntry (strAdjustColors, autoadjustcolors);
574 mplayer_cfg.writeEntry (strSeekTime, seektime);
575 mplayer_cfg.writeEntry (strVoDriver, videodriver);
576 mplayer_cfg.writeEntry (strAoDriver, audiodriver);
577 mplayer_cfg.writeEntry (strClickToPlay, clicktoplay);
578 mplayer_cfg.writeEntry (strAllowHref, grabhref);
579 mplayer_cfg.writeEntry (strAddConfigButton, showcnfbutton);
580 mplayer_cfg.writeEntry (strAddPlaylistButton, showplaylistbutton);
581 mplayer_cfg.writeEntry (strAddRecordButton, showrecordbutton);
582 mplayer_cfg.writeEntry (strAddBroadcastButton, showbroadcastbutton);
583 mplayer_cfg.writeEntry (strDVDDevice, dvddevice);
584 mplayer_cfg.writeEntry (strVCDDevice, vcddevice);
585
586 //postprocessing stuff
587 KConfigGroup pp_cfg (m_config, strPPGroup);
588 pp_cfg.writeEntry (strPostProcessing, postprocessing);
589 pp_cfg.writeEntry (strDisablePPauto, disableppauto);
590 pp_cfg.writeEntry (strPP_Default, pp_default);
591 pp_cfg.writeEntry (strPP_Fast, pp_fast);
592 pp_cfg.writeEntry (strPP_Custom, pp_custom);
593
594 pp_cfg.writeEntry (strCustom_Hz, pp_custom_hz);
595 pp_cfg.writeEntry (strCustom_Hz_Aq, pp_custom_hz_aq);
596 pp_cfg.writeEntry (strCustom_Hz_Ch, pp_custom_hz_ch);
597
598 pp_cfg.writeEntry (strCustom_Vt, pp_custom_vt);
599 pp_cfg.writeEntry (strCustom_Vt_Aq, pp_custom_vt_aq);
600 pp_cfg.writeEntry (strCustom_Vt_Ch, pp_custom_vt_ch);
601
602 pp_cfg.writeEntry (strCustom_Dr, pp_custom_dr);
603 pp_cfg.writeEntry (strCustom_Dr_Aq, pp_custom_vt_aq);
604 pp_cfg.writeEntry (strCustom_Dr_Ch, pp_custom_vt_ch);
605
606 pp_cfg.writeEntry (strCustom_Al, pp_custom_al);
607 pp_cfg.writeEntry (strCustom_Al_F, pp_custom_al_f);
608
609 pp_cfg.writeEntry (strCustom_Tn, pp_custom_tn);
610 pp_cfg.writeEntry (strCustom_Tn_S, pp_custom_tn_s);
611
612 pp_cfg.writeEntry (strPP_Lin_Blend_Int, pp_lin_blend_int);
613 pp_cfg.writeEntry (strPP_Lin_Int, pp_lin_int);
614 pp_cfg.writeEntry (strPP_Cub_Int, pp_cub_int);
615 pp_cfg.writeEntry (strPP_Med_Int, pp_med_int);
616 pp_cfg.writeEntry (strPP_FFmpeg_Int, pp_ffmpeg_int);
617
618 // recording
619 KConfigGroup rec_cfg (m_config, strRecordingGroup);
620 rec_cfg.writePathEntry (strRecordingFile, recordfile);
621 rec_cfg.writeEntry (strAutoPlayAfterRecording, int (replayoption));
622 rec_cfg.writeEntry (strAutoPlayAfterTime, replaytime);
623 rec_cfg.writeEntry (strRecorder, int (recorder));
624 rec_cfg.writeEntry (strRecordingCopy, recordcopy);
625 rec_cfg.writeEntry (strMencoderArgs, mencoderarguments);
626 rec_cfg.writeEntry (strFFMpegArgs, ffmpegarguments);
627
628 //dynamic stuff
629 for (PreferencesPage * p = pagelist; p; p = p->next)
630 p->write (m_config);
631 //\dynamic stuff
632 m_config->sync ();
633 }
634
okPressed()635 void Settings::okPressed () {
636 bool urlchanged = configdialog->m_SourcePageURL->changed;
637 bool playerchanged = false;
638 KUrl url = configdialog->m_SourcePageURL->url->url ();
639 KUrl sub_url = configdialog->m_SourcePageURL->sub_url->url ();
640 if (urlchanged) {
641 if (url.isEmpty ()) {
642 urlchanged = false;
643 } else {
644 if (KUrl (url.url ()).isLocalFile () || KUrl::isRelativeUrl (url.url ())) {
645 QFileInfo fi (url.path ());
646 int hpos = url.url ().lastIndexOf ('#');
647 QString xine_directives ("");
648 while (!fi.exists () && hpos > -1) {
649 xine_directives = url.url ().mid (hpos);
650 fi.setFile (url.url ().left (hpos));
651 hpos = url.url ().lastIndexOf ('#', hpos-1);
652 }
653 if (!fi.exists ()) {
654 urlchanged = false;
655 KMessageBox::error (m_player->view (), i18n ("File %1 does not exist.",url.url ()), i18n ("Error"));
656 } else {
657 configdialog->m_SourcePageURL->url->setUrl (QString(fi.absoluteFilePath () + xine_directives));
658 }
659 }
660 if (urlchanged &&
661 !sub_url.url ().isEmpty () &&
662 (KUrl (sub_url.url ()).isLocalFile () ||
663 KUrl::isRelativeUrl (sub_url.url ()))) {
664 QFileInfo sfi (sub_url.path ());
665 if (!sfi.exists ()) {
666 KMessageBox::error (m_player->view (), i18n ("Sub title file %1 does not exist.",sub_url.url ()), i18n ("Error"));
667 configdialog->m_SourcePageURL->sub_url->setUrl (QString ());
668 } else
669 configdialog->m_SourcePageURL->sub_url->setUrl (sfi.absoluteFilePath ());
670 }
671 }
672 }
673 if (urlchanged) {
674 KUrl uri (url.url ());
675 m_player->setUrl (uri.url ());
676 if (urllist.indexOf (uri.prettyUrl ()) < 0)
677 configdialog->m_SourcePageURL->urllist->insertItem (0, uri.prettyUrl ());
678 KUrl sub_uri (sub_url.url ());
679 if (sub_urllist.indexOf (sub_uri.prettyUrl ()) < 0)
680 configdialog->m_SourcePageURL->sub_urllist->insertItem (0, sub_uri.prettyUrl ());
681 }
682 urllist.clear ();
683 for (int i = 0; i < configdialog->m_SourcePageURL->urllist->count () && i < 20; ++i)
684 // damnit why don't maxCount and setDuplicatesEnabled(false) work :(
685 // and why can I put a qstringlist in it, but cannot get it out of it again..
686 if (!configdialog->m_SourcePageURL->urllist->itemText (i).isEmpty ())
687 urllist.push_back (configdialog->m_SourcePageURL->urllist->itemText (i));
688 sub_urllist.clear ();
689 for (int i = 0; i < configdialog->m_SourcePageURL->sub_urllist->count () && i < 20; ++i)
690 if (!configdialog->m_SourcePageURL->sub_urllist->itemText (i).isEmpty ())
691 sub_urllist.push_back (configdialog->m_SourcePageURL->sub_urllist->itemText (i));
692 prefbitrate = configdialog->m_SourcePageURL->prefBitRate->text ().toInt ();
693 maxbitrate = configdialog->m_SourcePageURL->maxBitRate->text ().toInt ();
694 sizeratio = configdialog->m_GeneralPageGeneral->keepSizeRatio->isChecked ();
695 autoresize = configdialog->m_GeneralPageGeneral->autoResize->isChecked ();
696 remembersize= configdialog->m_GeneralPageGeneral->sizesChoice->checkedId();
697 docksystray = configdialog->m_GeneralPageGeneral->dockSysTray->isChecked ();
698 loop = configdialog->m_GeneralPageGeneral->loop->isChecked ();
699 framedrop = configdialog->m_GeneralPageGeneral->framedrop->isChecked ();
700 autoadjustvolume = configdialog->m_GeneralPageGeneral->adjustvolume->isChecked ();
701 autoadjustcolors = configdialog->m_GeneralPageGeneral->adjustcolors->isChecked ();
702 showcnfbutton = configdialog->m_GeneralPageGeneral->showConfigButton->isChecked ();
703 showplaylistbutton = configdialog->m_GeneralPageGeneral->showPlaylistButton->isChecked ();
704 showrecordbutton = configdialog->m_GeneralPageGeneral->showRecordButton->isChecked ();
705 showbroadcastbutton = configdialog->m_GeneralPageGeneral->showBroadcastButton->isChecked ();
706 seektime = configdialog->m_GeneralPageGeneral->seekTime->value();
707
708 videodriver = configdialog->m_GeneralPageOutput->videoDriver->currentRow();
709 audiodriver = configdialog->m_GeneralPageOutput->audioDriver->currentRow();
710 QString backend_name = configdialog->m_SourcePageURL->backend->currentItem()->text();
711 if (!backend_name.isEmpty ()) {
712 const MediaManager::ProcessInfoMap::const_iterator e = m_player->mediaManager()->processInfos ().constEnd ();
713 for (MediaManager::ProcessInfoMap::const_iterator i = m_player->mediaManager()->processInfos ().constBegin(); i != e; ++i) {
714 ProcessInfo *p = i.value ();
715 if (p->supports ("urlsource") &&
716 p->label.remove (QChar ('&')) == backend_name) {
717 backends["urlsource"] = p->name;
718 break;
719 }
720 }
721 }
722 clicktoplay = configdialog->m_SourcePageURL->clicktoplay->isChecked ();
723 grabhref = configdialog->m_SourcePageURL->grabhref->isChecked ();
724 //postproc
725 postprocessing = configdialog->m_OPPagePostproc->postProcessing->isChecked();
726 disableppauto = configdialog->m_OPPagePostproc->disablePPauto->isChecked();
727 pp_default = configdialog->m_OPPagePostproc->defaultPreset->isChecked();
728 pp_fast = configdialog->m_OPPagePostproc->fastPreset->isChecked();
729 pp_custom = configdialog->m_OPPagePostproc->customPreset->isChecked();
730
731 pp_custom_hz = configdialog->m_OPPagePostproc->HzDeblockFilter->isChecked();
732 pp_custom_hz_aq = configdialog->m_OPPagePostproc->HzDeblockAQuality->isChecked();
733 pp_custom_hz_ch = configdialog->m_OPPagePostproc->HzDeblockCFiltering->isChecked();
734
735 pp_custom_vt = configdialog->m_OPPagePostproc->VtDeblockFilter->isChecked();
736 pp_custom_vt_aq = configdialog->m_OPPagePostproc->VtDeblockAQuality->isChecked();
737 pp_custom_vt_ch = configdialog->m_OPPagePostproc->VtDeblockCFiltering->isChecked();
738
739 pp_custom_dr = configdialog->m_OPPagePostproc->DeringFilter->isChecked();
740 pp_custom_dr_aq = configdialog->m_OPPagePostproc->DeringAQuality->isChecked();
741 pp_custom_dr_ch = configdialog->m_OPPagePostproc->DeringCFiltering->isChecked();
742
743 pp_custom_al = configdialog->m_OPPagePostproc->AutolevelsFilter->isChecked();
744 pp_custom_al_f = configdialog->m_OPPagePostproc->AutolevelsFullrange->isChecked();
745
746 pp_custom_tn = configdialog->m_OPPagePostproc->TmpNoiseFilter->isChecked();
747 pp_custom_tn_s = 0; // gotta fix this later
748 //pp_custom_tn_s = configdialog->m_OPPagePostproc->TmpNoiseSlider->value();
749
750 pp_lin_blend_int = configdialog->m_OPPagePostproc->LinBlendDeinterlacer->isChecked();
751 pp_lin_int = configdialog->m_OPPagePostproc->LinIntDeinterlacer->isChecked();
752 pp_cub_int = configdialog->m_OPPagePostproc->CubicIntDeinterlacer->isChecked();
753 pp_med_int = configdialog->m_OPPagePostproc->MedianDeinterlacer->isChecked();
754 pp_ffmpeg_int = configdialog->m_OPPagePostproc->FfmpegDeinterlacer->isChecked();
755 // recording
756 recorder = Recorder (configdialog->m_RecordPage->recorder->checkedId());
757 replaytime = configdialog->m_RecordPage->replaytime->value ();
758 recordfile = configdialog->m_RecordPage->url->lineEdit()->text ();
759 mencoderarguments = configdialog->m_MEncoderPage->arguments->text ();
760 ffmpegarguments = configdialog->m_FFMpegPage->arguments->text ();
761 recordcopy = !configdialog->m_MEncoderPage->format->checkedId();
762
763 //dynamic stuff
764 for (PreferencesPage * p = pagelist; p; p = p->next)
765 p->sync (true);
766 //\dynamic stuff
767
768 writeConfig ();
769 emit configChanged ();
770
771 if (urlchanged || playerchanged) {
772 m_player->sources () ["urlsource"]->setSubURL
773 (KUrl(configdialog->m_SourcePageURL->sub_url->url()));
774 m_player->openUrl (KUrl (configdialog->m_SourcePageURL->url->url ()));
775 m_player->source ()->setSubURL (KUrl (configdialog->m_SourcePageURL->sub_url->url ()));
776 }
777 }
778
getHelp()779 KDE_NO_EXPORT void Settings::getHelp () {
780 // KApplication::kApplication()->invokeBrowser ("man:/mplayer");
781 }
782
783 #include "kmplayerconfig.moc"
784
785