1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2010 the VideoLAN team
5  * $Id: 78ba18ec6f30d919942e7ba2d7082965214d75b6 $
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25 
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29 
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32 
33 #include <vlc_config_cat.h>
34 #include <vlc_configuration.h>
35 
36 #include <QString>
37 #include <QFont>
38 #include <QToolButton>
39 #include <QButtonGroup>
40 #include <QSignalMapper>
41 #include <QVBoxLayout>
42 #include <QScrollArea>
43 #include <QHeaderView>
44 
45 #include <QStyleFactory>
46 #include <QSettings>
47 #include <QScreen>
48 #include <QtAlgorithms>
49 #include <QDir>
50 #include <assert.h>
51 #include <math.h>
52 
53 #define ICON_HEIGHT 48
54 #define ICON_WIDTH 48
55 
56 #ifdef _WIN32
57 # include <vlc_charset.h>
58 # include <shobjidl.h>
59 #endif
60 #include <vlc_modules.h>
61 #include <vlc_arrays.h>
62 
63 static struct {
64     const char iso[6];
65     const char name[34];
66 
67 } const language_map[] = {
68     { "auto",  N_("Auto") },
69     { "en",    "American English" },
70     { "ar",    "عربي" },
71     { "an",    "Aragonés" },
72     { "as_IN", "অসমীয়া" },
73     { "ast",   "Asturianu" },
74     { "be",    "беларуская мова" },
75     { "brx",   "बर'/बड़" },
76     { "bn",    "বাংলা" },
77     { "pt_BR", "Português Brasileiro" },
78     { "en_GB", "British English" },
79     { "el",    "Νέα Ελληνικά" },
80     { "bg",    "български език" },
81     { "ca",    "Català" },
82     { "zh_TW", "正體中文" },
83     { "co",    "Corsu" },
84     { "cs",    "Čeština" },
85     { "cy",    "Cymraeg" },
86     { "da",    "Dansk" },
87     { "nl",    "Nederlands" },
88     { "fi",    "Suomi" },
89     { "et",    "eesti keel" },
90     { "eu",    "Euskara" },
91     { "fr",    "Français" },
92     { "ga",    "Gaeilge" },
93     { "gd",    "Gàidhlig" },
94     { "gl",    "Galego" },
95     { "gu",    "ગુજરાતી" },
96     { "de",    "Deutsch" },
97     { "he",    "עברית" },
98     { "hr",    "hrvatski" },
99     { "kn",    "ಕನ್ನಡ" },
100     { "lv",    "Latviešu valoda" },
101     { "hu",    "Magyar" },
102     { "mr",    "मराठी" },
103     { "is",    "íslenska" },
104     { "id",    "Bahasa Indonesia" },
105     { "it",    "Italiano" },
106     { "ja",    "日本語" },
107     { "ko",    "한국어" },
108     { "lt",    "lietuvių" },
109     { "ms",    "Melayu" },
110     { "nb",    "Bokmål" },
111     { "nn",    "Nynorsk" },
112     { "kk",    "Қазақ тілі" },
113     { "km",    "ភាសាខ្មែរ" },
114     { "ne",    "नेपाली" },
115     { "oc",    "Occitan" },
116     { "pl",    "Polski" },
117     { "pt_PT", "Português" },
118     { "pa",    "ਪੰਜਾਬੀ" },
119     { "ro",    "Română" },
120     { "ru",    "Русский" },
121     { "zh_CN", "简体中文" },
122     { "si",    "සිංහල" },
123     { "sr",    "српски" },
124     { "sk",    "Slovensky" },
125     { "sl",    "slovenščina" },
126     { "es",    "Español" },
127     { "es_MX", "Español Mexicano" },
128     { "sv",    "Svenska" },
129     { "th",    "ภาษาไทย" },
130     { "tr",    "Türkçe" },
131     { "uk",    "украї́нська мо́ва" },
132     { "vi",    "tiếng Việt" },
133     { "wa",    "Walon" }
134 };
135 
getDefaultAudioVolume(vlc_object_t * obj,const char * aout)136 static int getDefaultAudioVolume(vlc_object_t *obj, const char *aout)
137 {
138     if (!strcmp(aout, "") || !strcmp(aout, "any"))
139 #ifdef _WIN32
140         /* All Windows aouts, that can be selected automatically, handle volume
141          * saving. In case of automatic mode, we'll save the last volume for
142          * every modules. Therefore, all volumes variable we be the same and we
143          * can use the first one (mmdevice). */
144         return config_GetFloat(obj, "mmdevice-volume") * 100.f + .5f;
145 #else
146         return -1;
147 #endif
148     else
149     /* Note: For hysterical raisins, this is sorted by decreasing priority
150      * order (then alphabetical order). */
151     if (!strcmp(aout, "pulse"))
152         return -1;
153     else
154 #ifdef __linux__
155     if (!strcmp(aout, "alsa") && module_exists("alsa"))
156         return cbrtf(config_GetFloat(obj, "alsa-gain")) * 100.f + .5f;
157     else
158 #endif
159 #ifdef _WIN32
160     if (!strcmp(aout, "mmdevice"))
161         return config_GetFloat(obj, "mmdevice-volume") * 100.f + .5f;
162     else
163 #endif
164     if (!strcmp(aout, "sndio"))
165         return -1;
166     else
167 #ifdef __APPLE__
168     if (!strcmp(aout, "auhal") && module_exists("auhal"))
169         return (config_GetFloat(obj, "auhal-volume") * 100.f + .5f)
170                  / AOUT_VOLUME_DEFAULT;
171     else
172 #endif
173 #ifdef _WIN32
174     if (!strcmp(aout, "directsound") && module_exists("directsound"))
175         return config_GetFloat(obj, "directx-volume") * 100.f + .5f;
176     else
177 #endif
178     if (!strcmp(aout, "jack"))
179         return cbrtf(config_GetFloat(obj, "jack-gain")) * 100.f + 0.5f;
180     else
181 #ifdef __OS2__
182     if (!strcmp(aout, "kai"))
183         return cbrtf(config_GetFloat(obj, "kai-gain")) * 100.f + .5f;
184     else
185 #endif
186     if (!strcmp(aout, "oss"))
187         return -1;
188     else
189 #ifdef _WIN32
190     if (!strcmp(aout, "waveout"))
191         return config_GetFloat(obj, "waveout-volume") * 100.f + .5f;
192     else
193 #endif
194         return -1;
195 }
196 
197 /*********************************************************************
198  * The List of categories
199  *********************************************************************/
SPrefsCatList(intf_thread_t * _p_intf,QWidget * _parent)200 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
201                                   QWidget( _parent ), p_intf( _p_intf )
202 {
203     QHBoxLayout *layout = new QHBoxLayout();
204 
205     /* Use autoExclusive buttons and a mapper as QButtonGroup can't
206        set focus (keys) when it manages the buttons's exclusivity.
207        See QT bugs 131 & 816 and QAbstractButton's source code. */
208     QSignalMapper *mapper = new QSignalMapper( layout );
209     CONNECT( mapper, mapped(int), this, switchPanel(int) );
210 
211     QPixmap scaled;
212 #if HAS_QT56
213     qreal dpr = devicePixelRatioF();
214 #else
215     qreal dpr = devicePixelRatio();
216 #endif
217 
218 #define ADD_CATEGORY( button, label, ltooltip, icon, numb )                 \
219     QToolButton * button = new QToolButton( this );                         \
220     /* Scale icon to non native size outside of toolbutton to avoid widget size */\
221     /* computation using native size */\
222     scaled = QPixmap( ":/prefsmenu/" #icon ".png" )\
223              .scaledToHeight( ICON_HEIGHT * dpr, Qt::SmoothTransformation );\
224     scaled.setDevicePixelRatio( dpr ); \
225     button->setIcon( scaled );                \
226     button->setText( label );                                               \
227     button->setToolTip( ltooltip );                                         \
228     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
229     button->setIconSize( QSize( ICON_WIDTH, ICON_HEIGHT ) );          \
230     button->setMinimumWidth( 40 + ICON_WIDTH );\
231     button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); \
232     button->setAutoRaise( true );                                           \
233     button->setCheckable( true );                                           \
234     button->setAutoExclusive( true );                                       \
235     CONNECT( button, clicked(), mapper, map() );                            \
236     mapper->setMapping( button, numb );                                     \
237     layout->addWidget( button );
238 
239     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), qtr("Interface Settings"),
240                   cone_interface_64, 0 );
241     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), qtr("Audio Settings"),
242                   cone_audio_64, 1 );
243     ADD_CATEGORY( SPrefsVideo, qtr("Video"), qtr("Video Settings"),
244                   cone_video_64, 2 );
245     ADD_CATEGORY( SPrefsSubtitles, qtr(SUBPIC_TITLE), qtr("Subtitle & On Screen Display Settings"),
246                   cone_subtitles_64, 3 );
247     ADD_CATEGORY( SPrefsInputAndCodecs, qtr(INPUT_TITLE), qtr("Input & Codecs Settings"),
248                   cone_input_64, 4 );
249     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), qtr("Configure Hotkeys"),
250                   cone_hotkeys_64, 5 );
251 
252 #undef ADD_CATEGORY
253 
254     SPrefsInterface->setChecked( true );
255     layout->setMargin( 0 );
256     layout->setSpacing( 1 );
257 
258     setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
259     setMinimumWidth( ICON_HEIGHT * 6 + 10 );
260     setLayout( layout );
261 }
262 
switchPanel(int i)263 void SPrefsCatList::switchPanel( int i )
264 {
265     emit currentItemChanged( i );
266 }
267 
268 /*********************************************************************
269  * The Panels
270  *********************************************************************/
SPrefsPanel(intf_thread_t * _p_intf,QWidget * _parent,int _number)271 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
272                           int _number ) : QWidget( _parent ), p_intf( _p_intf )
273 {
274     module_config_t *p_config;
275     ConfigControl *control;
276     number = _number;
277     lang = NULL;
278     radioGroup = NULL;
279 
280 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
281             p_config =  config_FindConfig( option );                      \
282             if( p_config )                                                \
283             {                                                             \
284                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
285                            p_config, label, ui.qcontrol, false );         \
286                 controls.append( control );                               \
287             }                                                             \
288             else {                                                        \
289                 ui.qcontrol->setEnabled( false );                         \
290                 if( label ) label->setEnabled( false );                   \
291             }
292 
293 #define CONFIG_BOOL( option, qcontrol )                           \
294             p_config =  config_FindConfig( option );                      \
295             if( p_config )                                                \
296             {                                                             \
297                 control =  new BoolConfigControl( VLC_OBJECT(p_intf),     \
298                            p_config, NULL, ui.qcontrol );          \
299                 controls.append( control );                               \
300             }                                                             \
301             else { ui.qcontrol->setEnabled( false ); }
302 
303 
304 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol )             \
305             p_config =  config_FindConfig( option );                      \
306             if( p_config )                                                \
307             {                                                             \
308                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
309                            p_config, label, qcontrol, false );            \
310                 controls.append( control );                               \
311             }                                                             \
312             else {                                                        \
313                 QWidget *widget = label;                                  \
314                 qcontrol->setVisible( false );                            \
315                 if( widget ) widget->setEnabled( false );                 \
316             }
317 
318 
319 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
320             p_config =  config_FindConfig( option );                      \
321             if( p_config )                                                \
322             {                                                             \
323                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
324                            p_config, label, ui.qcontrol );                \
325                 controls.append( control );                               \
326             }
327 
328 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )     \
329             p_config =  config_FindConfig( option );                      \
330             if( p_config )                                                \
331             {                                                             \
332                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
333                            p_config, label, qcontrol, qbutton );          \
334                 controls.append( control );                               \
335             }
336 
337 #define START_SPREFS_CAT( name , label )    \
338         case SPrefs ## name:                \
339         {                                   \
340             Ui::SPrefs ## name ui;      \
341             ui.setupUi( panel );            \
342             panel_label->setText( label );
343 
344 #define END_SPREFS_CAT      \
345             break;          \
346         }
347 
348     QVBoxLayout *panel_layout = new QVBoxLayout();
349     QWidget *panel = new QWidget();
350     panel_layout->setMargin( 3 );
351 
352     // Title Label
353     QLabel *panel_label = new QLabel;
354     QFont labelFont = QApplication::font();
355     labelFont.setPointSize( labelFont.pointSize() + 6 );
356     panel_label->setFont( labelFont );
357 
358     // Title <hr>
359     QFrame *title_line = new QFrame;
360     title_line->setFrameShape(QFrame::HLine);
361     title_line->setFrameShadow(QFrame::Sunken);
362 
363     QFont italicFont = QApplication::font();
364     italicFont.setItalic( true );
365 
366     switch( number )
367     {
368         /******************************
369          * VIDEO Panel Implementation *
370          ******************************/
371         START_SPREFS_CAT( Video , qtr("Video Settings") );
372             CONFIG_BOOL( "video", enableVideo );
373             ui.videoZone->setEnabled( ui.enableVideo->isChecked() );
374             CONNECT( ui.enableVideo, toggled( bool ),
375                      ui.videoZone, setEnabled( bool ) );
376 
377             CONFIG_BOOL( "fullscreen", fullscreen );
378             CONFIG_BOOL( "video-deco", windowDecorations );
379             CONFIG_GENERIC( "vout", StringList, ui.voutLabel, outputModule );
380 
381             CONNECT( ui.outputModule, currentIndexChanged( int ),
382                      this, updateVideoOptions( int ) );
383             optionWidgets["videoOutCoB"] = ui.outputModule;
384 
385             optionWidgets["fullscreenScreenB"] = ui.fullscreenScreenBox;
386             ui.fullscreenScreenBox->addItem( qtr("Automatic"), -1 );
387             int i_screenCount = 0;
388             foreach( QScreen* screen, QGuiApplication::screens() )
389             {
390                 ui.fullscreenScreenBox->addItem( screen->name(), i_screenCount );
391                 i_screenCount++;
392             }
393             p_config =  config_FindConfig( "qt-fullscreen-screennumber" );
394             if( p_config )
395             {
396                 int i_defaultScreen = p_config->value.i + 1;
397                 if ( i_defaultScreen < 0 || i_defaultScreen > ( ui.fullscreenScreenBox->count() - 1 ) )
398                     ui.fullscreenScreenBox->setCurrentIndex( 0 );
399                 else
400                     ui.fullscreenScreenBox->setCurrentIndex(p_config->value.i + 1);
401             }
402 
403 #ifdef _WIN32
404             CONFIG_BOOL( "directx-overlay", overlay );
405             CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
406             CONNECT( ui.overlay, toggled( bool ), ui.hwYUVBox, setEnabled( bool ) );
407             optionWidgets["directxVideoB"] = ui.directXBox;
408 #else
409             ui.directXBox->setVisible( false );
410 #endif
411 
412 #ifdef __OS2__
413             CONFIG_BOOL( "kva-fixt23", kvaFixT23 );
414             CONFIG_GENERIC( "kva-video-mode", StringList, ui.kvaVideoModeLabel,
415                             kvaVideoMode );
416 #else
417             ui.kvaBox->setVisible( false );
418 #endif
419 
420             CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
421             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
422             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
423 
424             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
425                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
426             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
427             CONFIG_BOOL( "snapshot-sequential",
428                             snapshotsSequentialNumbering );
429             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
430                             snapshotsFormat );
431 
432             updateVideoOptions( ui.outputModule->currentIndex() );
433          END_SPREFS_CAT;
434 
435         /******************************
436          * AUDIO Panel Implementation *
437          ******************************/
438         START_SPREFS_CAT( Audio, qtr("Audio Settings") );
439 
440             CONFIG_BOOL( "audio", enableAudio );
441             ui.audioZone->setEnabled( ui.enableAudio->isChecked() );
442             CONNECT( ui.enableAudio, toggled( bool ),
443                      ui.audioZone, setEnabled( bool ) );
444 
445 #define audioCommon( name ) \
446             QLabel * name ## Label = new QLabel( qtr( "Device:" ) ); \
447             name ## Label->setMinimumSize(QSize(250, 0)); \
448             outputAudioLayout->addWidget( name ## Label, outputAudioLayout->rowCount(), 0, 1, 1 ); \
449 
450 #define audioControl( name) \
451             audioCommon( name ) \
452             QComboBox * name ## Device = new QComboBox; \
453             name ## Label->setBuddy( name ## Device ); \
454             name ## Device->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred  );\
455             outputAudioLayout->addWidget( name ## Device, outputAudioLayout->rowCount() - 1, 1, 1, -1 );
456 
457 #define audioControl2( name) \
458             audioCommon( name ) \
459             QHBoxLayout * name ## hboxLayout = new QHBoxLayout; \
460             QLineEdit * name ## Device = new QLineEdit; \
461             name ## Label->setBuddy( name ## Device ); \
462             name ## hboxLayout->addWidget( name ## Device ); \
463             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ) ); \
464             name ## hboxLayout->addWidget( name ## Browse ); \
465             outputAudioLayout->addLayout( name ## hboxLayout, outputAudioLayout->rowCount() - 1, 1, 1, 1, Qt::AlignLeft );
466 
467             /* Build if necessary */
468             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
469 #ifdef _WIN32
470             audioControl( DirectX );
471             optionWidgets["directxL" ] = DirectXLabel;
472             optionWidgets["directxW" ] = DirectXDevice;
473             CONFIG_GENERIC_NO_UI( "directx-audio-device", StringList,
474                     DirectXLabel, DirectXDevice );
475 
476             audioControl( Waveout );
477             optionWidgets["waveoutL" ] = WaveoutLabel;
478             optionWidgets["waveoutW" ] = WaveoutDevice;
479             CONFIG_GENERIC_NO_UI( "waveout-audio-device", StringList,
480                     WaveoutLabel, WaveoutDevice );
481 
482 #elif defined( __OS2__ )
483             audioControl( kai );
484             optionWidgets["kaiL"] = kaiLabel;
485             optionWidgets["kaiW"] = kaiDevice;
486             CONFIG_GENERIC_NO_UI( "kai-audio-device", StringList, kaiLabel,
487                     kaiDevice );
488 #else
489             if( module_exists( "alsa" ) )
490             {
491                 audioControl( alsa );
492                 optionWidgets["alsaL"] = alsaLabel;
493                 optionWidgets["alsaW"] = alsaDevice;
494                 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
495                                 alsaDevice );
496             }
497             if( module_exists( "oss" ) )
498             {
499                 audioControl2( OSS );
500                 optionWidgets["ossL"] = OSSLabel;
501                 optionWidgets["ossW"] = OSSDevice;
502                 optionWidgets["ossB"] = OSSBrowse;
503                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, OSSLabel, OSSDevice,
504                                  OSSBrowse );
505             }
506 #endif
507 
508 #ifdef _WIN32
509             audioControl( MMDevice );
510             optionWidgets["mmdeviceL" ] = MMDeviceLabel;
511             optionWidgets["mmdeviceW" ] = MMDeviceDevice;
512             CONFIG_GENERIC_NO_UI( "mmdevice-audio-device", StringList,
513                                   MMDeviceLabel, MMDeviceDevice );
514 
515             CONFIG_GENERIC( "mmdevice-passthrough", IntegerList,
516                             ui.mmdevicePassthroughLabel, mmdevicePassthroughBox );
517             optionWidgets["mmdevicePassthroughL"] = ui.mmdevicePassthroughLabel;
518             optionWidgets["mmdevicePassthroughB"] = ui.mmdevicePassthroughBox;
519 #else
520             ui.mmdevicePassthroughLabel->setVisible( false );
521             ui.mmdevicePassthroughBox->setVisible( false );
522 #endif
523 
524 
525 #undef audioControl2
526 #undef audioControl
527 #undef audioCommon
528 
529             int i_max_volume = config_GetInt( p_intf, "qt-max-volume" );
530 
531             /* Audio Options */
532             ui.volumeValue->setMaximum( i_max_volume );
533             ui.defaultVolume->setMaximum( i_max_volume );
534 
535             CONNECT( ui.defaultVolume, valueChanged( int ),
536                      this, updateAudioVolume( int ) );
537 
538             ui.defaultVolume_zone->setEnabled( ui.resetVolumeCheckbox->isChecked() );
539             CONNECT( ui.resetVolumeCheckbox, toggled( bool ),
540                      ui.defaultVolume_zone, setEnabled( bool ) );
541 
542             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
543                             preferredAudioLanguage );
544 
545             CONFIG_BOOL( "spdif", spdifBox );
546 
547             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
548                                     volNormSpin );
549             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
550                             replayCombo );
551             CONFIG_GENERIC( "audio-visual" , StringList, ui.visuLabel,
552                             visualisation);
553             CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
554 
555             /* Audio Output Specifics */
556             CONFIG_GENERIC( "aout", StringList, ui.outputLabel, outputModule );
557 
558             CONNECT( ui.outputModule, currentIndexChanged( int ),
559                      this, updateAudioOptions( int ) );
560 
561             /* File output exists on all platforms */
562             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
563                                  ui.fileName, ui.fileBrowseButton );
564 
565             optionWidgets["fileW"] = ui.fileControl;
566             optionWidgets["audioOutCoB"] = ui.outputModule;
567             optionWidgets["normalizerChB"] = ui.volNormBox;
568             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
569             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
570             optionWidgets["volLW"] = ui.volumeValue;
571             optionWidgets["spdifChB"] = ui.spdifBox;
572             optionWidgets["defaultVolume"] = ui.defaultVolume;
573             optionWidgets["resetVolumeCheckbox"] = ui.resetVolumeCheckbox;
574             updateAudioOptions( ui.outputModule->currentIndex() );
575 
576             /* LastFM */
577             if( module_exists( "audioscrobbler" ) )
578             {
579                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
580                         lastfm_user_edit );
581                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
582                         lastfm_pass_edit );
583 
584                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
585                     ui.lastfm->setChecked( true );
586                 else
587                     ui.lastfm->setChecked( false );
588 
589                 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
590 
591                 CONNECT( ui.lastfm, toggled( bool ),
592                          ui.lastfm_zone, setVisible( bool ) );
593                 CONNECT( ui.lastfm, stateChanged( int ),
594                          this, lastfm_Changed( int ) );
595             }
596             else
597             {
598                 ui.lastfm->hide();
599                 ui.lastfm_zone->hide();
600             }
601 
602             /* Normalizer */
603             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
604                      setEnabled( bool ) );
605 
606             char* psz = config_GetPsz( p_intf, "audio-filter" );
607             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
608             free( psz );
609 
610             bool b_enabled = ( qs_filter.contains( "normvol" ) );
611             ui.volNormBox->setChecked( b_enabled );
612             ui.volNormSpin->setEnabled( b_enabled );
613 
614             /* Volume Label */
615             updateAudioVolume( ui.defaultVolume->value() ); // First time init
616 
617         END_SPREFS_CAT;
618 
619         /* Input and Codecs Panel Implementation */
620         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
621 
622             /* Disk Devices */
623             {
624                 ui.DVDDeviceComboBox->setToolTip(
625                     qtr( "If this property is blank, different values\n"
626                          "for DVD, VCD, and CDDA are set.\n"
627                          "You can define a unique one or configure them \n"
628                          "individually in the advanced preferences." ) );
629                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
630                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
631                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
632                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
633                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
634                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
635                 {
636                     ui.DVDDeviceComboBox->setEditText( qfu( psz_dvddiscpath ) );
637                 }
638                 free( psz_cddadiscpath );
639                 free( psz_dvddiscpath );
640                 free( psz_vcddiscpath );
641             }
642 #ifndef _WIN32
643             QStringList DVDDeviceComboBoxStringList = QStringList();
644             DVDDeviceComboBoxStringList
645                     << "dvd*" << "scd*" << "sr*" << "sg*" << "cd*";
646             ui.DVDDeviceComboBox->addItems( QDir( "/dev/" )
647                     .entryList( DVDDeviceComboBoxStringList, QDir::System )
648                     .replaceInStrings( QRegExp("^"), "/dev/" )
649             );
650 #endif
651             CONFIG_GENERIC( "dvd", String, ui.DVDLabel,
652                             DVDDeviceComboBox->lineEdit() );
653             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
654                                  ui.recordPath, ui.recordBrowse );
655 
656             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
657             CONFIG_GENERIC_NO_BOOL( "postproc-q", Integer, ui.ppLabel,
658                                     PostProcLevel );
659             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
660 
661             /* live555 module prefs */
662             CONFIG_BOOL( "rtsp-tcp",
663                                 live555TransportRTSP_TCPRadio );
664             if ( !module_exists( "live555" ) )
665             {
666                 ui.live555TransportRTSP_TCPRadio->hide();
667                 ui.live555TransportHTTPRadio->hide();
668                 ui.live555TransportLabel->hide();
669             }
670             CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel, hwAccelModule );
671 #ifdef _WIN32
672             HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
673             if( !hdxva2_dll )
674                 ui.hwAccelModule->setEnabled( false );
675             else
676                 FreeLibrary( hdxva2_dll );
677 #endif
678             CONFIG_BOOL( "input-fast-seek", fastSeekBox );
679             optionWidgets["inputLE"] = ui.DVDDeviceComboBox;
680             optionWidgets["cachingCoB"] = ui.cachingCombo;
681             CONFIG_GENERIC( "avcodec-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
682             CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
683             CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
684             CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
685             CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
686             CONFIG_BOOL( "mkv-preload-local-dir", mkvPreloadBox );
687 
688             /* Caching */
689             /* Add the things to the ComboBox */
690             #define addToCachingBox( str, cachingNumber ) \
691                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
692             addToCachingBox( N_("Custom"), CachingCustom );
693             addToCachingBox( N_("Lowest latency"), CachingLowest );
694             addToCachingBox( N_("Low latency"), CachingLow );
695             addToCachingBox( N_("Normal"), CachingNormal );
696             addToCachingBox( N_("High latency"), CachingHigh );
697             addToCachingBox( N_("Higher latency"), CachingHigher );
698             #undef addToCachingBox
699 
700 #define TestCaC( name, factor ) \
701     b_cache_equal =  b_cache_equal && \
702      ( i_cache * factor == config_GetInt( p_intf, name ) );
703             /* Select the accurate value of the ComboBox */
704             bool b_cache_equal = true;
705             int i_cache = config_GetInt( p_intf, "file-caching" );
706 
707             TestCaC( "network-caching", 10/3 );
708             TestCaC( "disc-caching", 1);
709             TestCaC( "live-caching", 1 );
710             if( b_cache_equal == 1 )
711                 ui.cachingCombo->setCurrentIndex(
712                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
713 #undef TestCaC
714 
715         END_SPREFS_CAT;
716         /*******************
717          * Interface Panel *
718          *******************/
719         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
720 
721 #ifndef _WIN32
722             ui.langBox->hide();
723 #else
724             for( int i = 0; i < ARRAY_SIZE( language_map ); i++)
725                 ui.langCombo->addItem( qfu( language_map[i].name ), language_map[i].iso );
726             CONNECT( ui.langCombo, currentIndexChanged( int ), this, langChanged( int ) );
727 
728             HKEY h_key;
729             char *langReg = NULL;
730             if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
731                     == ERROR_SUCCESS )
732             {
733                 TCHAR szData[256];
734                 DWORD len = 256;
735                 if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) {
736                     langReg = FromWide( szData );
737                     ui.langCombo->setCurrentIndex( ui.langCombo->findData(langReg) );
738                 }
739             }
740             free( langReg);
741 #endif
742 
743 //            ui.defaultLabel->setFont( italicFont );
744             ui.skinsLabel->setText(
745                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
746                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">" )
747                     + qtr( "VLC skins website" )+ QString( "</a>." ) );
748             ui.skinsLabel->setFont( italicFont );
749 
750 #ifdef _WIN32
751             BUTTONACT( ui.assoButton, assoDialog() );
752 #else
753             ui.osGroupBox->hide();
754 #endif
755 
756             /* interface */
757             char *psz_intf = config_GetPsz( p_intf, "intf" );
758             if( psz_intf )
759             {
760                 if( strstr( psz_intf, "skin" ) )
761                     ui.skins->setChecked( true );
762             } else {
763                 /* defaults to qt */
764                 ui.qt->setChecked( true );
765             }
766             free( psz_intf );
767 
768             optionWidgets["skinRB"] = ui.skins;
769             optionWidgets["qtRB"] = ui.qt;
770 #if !defined( _WIN32)
771             ui.stylesCombo->addItem( qtr("System's default") );
772             ui.stylesCombo->addItems( QStyleFactory::keys() );
773             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
774                         getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
775             ui.stylesCombo->insertSeparator( 1 );
776             if ( ui.stylesCombo->currentIndex() < 0 )
777                 ui.stylesCombo->setCurrentIndex( 0 ); /* default */
778 
779             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
780             optionWidgets["styleCB"] = ui.stylesCombo;
781 #else
782             ui.stylesCombo->hide();
783             ui.stylesLabel->hide();
784 #endif
785             radioGroup = new QButtonGroup(this);
786             radioGroup->addButton( ui.qt, 0 );
787             radioGroup->addButton( ui.skins, 1 );
788             CONNECT( radioGroup, buttonClicked( int ),
789                      ui.styleStackedWidget, setCurrentIndex( int ) );
790             ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
791 
792             CONNECT( ui.minimalviewBox, toggled( bool ),
793                      ui.mainPreview, setNormalPreview( bool ) );
794             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
795             ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
796             ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
797 
798             CONFIG_BOOL( "embedded-video", embedVideo );
799             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
800             CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
801             ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );
802 
803             CONFIG_BOOL( "qt-fs-controller", fsController );
804             CONFIG_BOOL( "qt-system-tray", systrayBox );
805             CONFIG_GENERIC( "qt-notification", IntegerList, ui.notificationComboLabel,
806                                                       notificationCombo );
807             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationCombo, setEnabled( bool ) );
808             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationComboLabel, setEnabled( bool ) );
809             ui.notificationCombo->setEnabled( ui.systrayBox->isChecked() );
810 
811             CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
812             CONFIG_BOOL( "playlist-tree", treePlaylist );
813             CONFIG_BOOL( "play-and-pause", playPauseBox );
814             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
815                                  ui.fileSkin, ui.skinBrowse );
816 
817             CONFIG_BOOL( "metadata-network-access", MetadataNetworkAccessMode );
818 
819             /* UPDATE options */
820 #ifdef UPDATE_CHECK
821             CONFIG_BOOL( "qt-updates-notif", updatesBox );
822             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
823                     updatesDays );
824             ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
825             CONNECT( ui.updatesBox, toggled( bool ),
826                      ui.updatesDays, setEnabled( bool ) );
827 #else
828             ui.updatesBox->hide();
829             ui.updatesDays->hide();
830 #endif
831             /* ONE INSTANCE options */
832 #if !defined( _WIN32 ) && !defined(__APPLE__) && !defined(__OS2__)
833             if( !module_exists( "dbus" ) )
834                 ui.OneInterfaceBox->hide();
835             else
836 #endif
837             {
838                 CONFIG_BOOL( "one-instance", OneInterfaceMode );
839                 CONFIG_BOOL( "playlist-enqueue", EnqueueOneInterfaceMode );
840                 ui.EnqueueOneInterfaceMode->setEnabled(
841                                                        ui.OneInterfaceMode->isChecked() );
842                 CONNECT( ui.OneInterfaceMode, toggled( bool ),
843                          ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
844                 CONFIG_BOOL( "one-instance-when-started-from-file", oneInstanceFromFile );
845             }
846 
847             /* RECENTLY PLAYED options */
848             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
849                      ui.recentlyPlayedFilters, setEnabled( bool ) );
850             ui.recentlyPlayedFilters->setEnabled( false );
851             CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
852             CONFIG_GENERIC( "qt-continue", IntegerList, ui.continuePlaybackLabel, continuePlaybackComboBox );
853             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
854                     recentlyPlayedFilters );
855             CONFIG_GENERIC( "qt-auto-raise", IntegerList, ui.autoRaiseLabel, autoRaiseComboBox );
856 
857         END_SPREFS_CAT;
858 
859         START_SPREFS_CAT( Subtitles,
860                             qtr("Subtitle & On Screen Display Settings") );
861             CONFIG_BOOL( "osd", OSDBox);
862             CONFIG_BOOL( "video-title-show", OSDTitleBox);
863             CONFIG_GENERIC( "video-title-position", IntegerList,
864                             ui.OSDTitlePosLabel, OSDTitlePos );
865 
866             CONFIG_BOOL( "spu", spuActiveBox);
867             ui.spuZone->setEnabled( ui.spuActiveBox->isChecked() );
868             CONNECT( ui.spuActiveBox, toggled( bool ),
869                      ui.spuZone, setEnabled( bool ) );
870 
871             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
872                             encoding );
873             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
874                             preferredLanguage );
875 
876             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
877                             ui.fontSizeLabel, fontSize );
878 
879             CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
880             CONFIG_GENERIC_NO_BOOL( "freetype-color", Color, ui.fontColorLabel,
881                             fontColor );
882             CONFIG_GENERIC( "freetype-outline-thickness", IntegerList,
883                             ui.fontEffectLabel, effect );
884             CONFIG_GENERIC_NO_BOOL( "freetype-outline-color", Color, ui.outlineColorLabel,
885                             outlineColor );
886 
887             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
888 
889             ui.shadowCheck->setChecked( config_GetInt( p_intf, "freetype-shadow-opacity" ) > 0 );
890             ui.backgroundCheck->setChecked( config_GetInt( p_intf, "freetype-background-opacity" ) > 0 );
891             optionWidgets["shadowCB"] = ui.shadowCheck;
892             optionWidgets["backgroundCB"] = ui.backgroundCheck;
893 
894         END_SPREFS_CAT;
895 
896         case SPrefsHotkeys:
897         {
898             p_config = config_FindConfig( "key-play" );
899 
900             QGridLayout *gLayout = new QGridLayout;
901             panel->setLayout( gLayout );
902             int line = 0;
903 
904             panel_label->setText( qtr( "Configure Hotkeys" ) );
905             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config, this );
906             control->insertIntoExistingGrid( gLayout, line );
907             controls.append( control );
908 
909             line++;
910 
911             QFrame *sepline = new QFrame;
912             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
913             gLayout->addWidget( sepline, line, 0, 1, -1 );
914 
915             line++;
916 
917             p_config = config_FindConfig( "hotkeys-y-wheel-mode" );
918             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
919                     p_config, this, false );
920             control->insertIntoExistingGrid( gLayout, line );
921             controls.append( control );
922 
923             line++;
924 
925             p_config = config_FindConfig( "hotkeys-x-wheel-mode" );
926             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
927                     p_config, this, false );
928             control->insertIntoExistingGrid( gLayout, line );
929             controls.append( control );
930 
931 #ifdef _WIN32
932             line++;
933 
934             p_config = config_FindConfig( "qt-disable-volume-keys" );
935             control = new BoolConfigControl( VLC_OBJECT(p_intf), p_config, this );
936             control->insertIntoExistingGrid( gLayout, line );
937             controls.append( control );
938 #endif
939 
940             break;
941         }
942     }
943 
944     panel_layout->addWidget( panel_label );
945     panel_layout->addWidget( title_line );
946 
947     QScrollArea *scroller= new QScrollArea;
948     scroller->setWidget( panel );
949     scroller->setWidgetResizable( true );
950     scroller->setFrameStyle( QFrame::NoFrame );
951     panel_layout->addWidget( scroller );
952 
953     setLayout( panel_layout );
954 
955 #undef END_SPREFS_CAT
956 #undef START_SPREFS_CAT
957 #undef CONFIG_GENERIC_FILE
958 #undef CONFIG_GENERIC_NO_BOOL
959 #undef CONFIG_GENERIC_NO_UI
960 #undef CONFIG_GENERIC
961 #undef CONFIG_BOOL
962 }
963 
updateVideoOptions(int number)964 void SPrefsPanel::updateVideoOptions( int number )
965 {
966     QString value = qobject_cast<QComboBox *>(optionWidgets["videoOutCoB"])
967                                             ->itemData( number ).toString();
968 #ifdef _WIN32
969     if( optionWidgets["directxVideoB"] ) {
970         optionWidgets["directxVideoB"]->setVisible( ( value == "directdraw" ) );
971     }
972 #endif
973 }
974 
975 
updateAudioOptions(int number)976 void SPrefsPanel::updateAudioOptions( int number)
977 {
978     QString value = qobject_cast<QComboBox *>(optionWidgets["audioOutCoB"])
979                                             ->itemData( number ).toString();
980 #ifdef _WIN32
981     /* Since MMDevice is most likely to be used by default, we show MMDevice
982      * options by default */
983     const bool mmDeviceEnabled = value == "mmdevice" || value == "any";
984     optionWidgets["mmdevicePassthroughL"]->setVisible( mmDeviceEnabled );
985     optionWidgets["mmdevicePassthroughB"]->setVisible( mmDeviceEnabled );
986     optionWidgets["mmdeviceW"]->setVisible( mmDeviceEnabled );
987     optionWidgets["mmdeviceL"]->setVisible( mmDeviceEnabled );
988 
989     optionWidgets["directxW"]->setVisible( ( value == "directsound" ) );
990     optionWidgets["directxL"]->setVisible( ( value == "directsound" ) );
991     optionWidgets["waveoutW"]->setVisible( ( value == "waveout" ) );
992     optionWidgets["waveoutL"]->setVisible( ( value == "waveout" ) );
993 #elif defined( __OS2__ )
994     optionWidgets["kaiL"]->setVisible( ( value == "kai" ) );
995     optionWidgets["kaiW"]->setVisible( ( value == "kai" ) );
996 #else
997     /* optionWidgets["ossW] can be NULL */
998     if( optionWidgets["ossW"] ) {
999         optionWidgets["ossW"]->setVisible( ( value == "oss" ) );
1000         optionWidgets["ossL"]->setVisible( ( value == "oss" ) );
1001         optionWidgets["ossB"]->setVisible( ( value == "oss" ) );
1002     }
1003     /* optionWidgets["alsaW] can be NULL */
1004     if( optionWidgets["alsaW"] ) {
1005         optionWidgets["alsaW"]->setVisible( ( value == "alsa" ) );
1006         optionWidgets["alsaL"]->setVisible( ( value == "alsa" ) );
1007     }
1008 #endif
1009     optionWidgets["fileW"]->setVisible( ( value == "afile" ) );
1010     optionWidgets["spdifChB"]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
1011                                            value == "directsound" || value == "waveout" ) );
1012 
1013     int volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), qtu(value));
1014     bool save = true;
1015 
1016     if (volume >= 0)
1017         save = config_GetInt(VLC_OBJECT(p_intf), "volume-save");
1018 
1019     QCheckBox *resetVolumeCheckBox =
1020         qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"]);
1021     resetVolumeCheckBox->setChecked(!save);
1022     resetVolumeCheckBox->setEnabled(volume >= 0);
1023 
1024     QSlider *defaultVolume =
1025         qobject_cast<QSlider *>(optionWidgets["defaultVolume"]);
1026     defaultVolume->setValue((volume >= 0) ? volume : 100);
1027     defaultVolume->setEnabled(volume >= 0);
1028 }
1029 
1030 
~SPrefsPanel()1031 SPrefsPanel::~SPrefsPanel()
1032 {
1033     qDeleteAll( controls ); controls.clear();
1034     free( lang );
1035 }
1036 
updateAudioVolume(int volume)1037 void SPrefsPanel::updateAudioVolume( int volume )
1038 {
1039     qobject_cast<QSpinBox *>(optionWidgets["volLW"])
1040         ->setValue( volume );
1041 }
1042 
1043 
1044 /* Function called from the main Preferences dialog on each SPrefs Panel */
apply()1045 void SPrefsPanel::apply()
1046 {
1047     /* Generic save for ever panel */
1048     QList<ConfigControl *>::const_iterator i;
1049     for( i = controls.begin() ; i != controls.end() ; ++i )
1050     {
1051         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
1052         c->doApply();
1053     }
1054 
1055     switch( number )
1056     {
1057     case SPrefsInputAndCodecs:
1058     {
1059         /* Device default selection */
1060         QByteArray devicepath =
1061             qobject_cast<QComboBox *>(optionWidgets["inputLE"])->currentText().toUtf8();
1062         if( devicepath.size() > 0 )
1063         {
1064             config_PutPsz( p_intf, "dvd", devicepath );
1065             config_PutPsz( p_intf, "vcd", devicepath );
1066             config_PutPsz( p_intf, "cd-audio", devicepath );
1067         }
1068 
1069 #define CaC( name, factor ) config_PutInt( p_intf, name, i_comboValue * factor )
1070         /* Caching */
1071         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets["cachingCoB"]);
1072         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
1073         if( i_comboValue )
1074         {
1075             CaC( "file-caching", 1 );
1076             CaC( "network-caching", 10/3 );
1077             CaC( "disc-caching", 1 );
1078             CaC( "live-caching", 1 );
1079         }
1080         break;
1081 #undef CaC
1082     }
1083 
1084     /* Interfaces */
1085     case SPrefsInterface:
1086     {
1087         if( qobject_cast<QRadioButton *>(optionWidgets["skinRB"])->isChecked() )
1088             config_PutPsz( p_intf, "intf", "skins2,any" );
1089         else
1090         //if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
1091             config_PutPsz( p_intf, "intf", "" );
1092         if( qobject_cast<QComboBox *>(optionWidgets["styleCB"]) )
1093             getSettings()->setValue( "MainWindow/QtStyle",
1094                 qobject_cast<QComboBox *>(optionWidgets["styleCB"])->currentText() );
1095 #ifdef _WIN32
1096     saveLang();
1097 #endif
1098         break;
1099     }
1100 
1101     case SPrefsVideo:
1102     {
1103         int i_fullscreenScreen =  qobject_cast<QComboBox *>(optionWidgets["fullscreenScreenB"])->currentData().toInt();
1104         config_PutInt( p_intf, "qt-fullscreen-screennumber", i_fullscreenScreen );
1105         break;
1106     }
1107 
1108     case SPrefsAudio:
1109     {
1110         bool b_checked =
1111             qobject_cast<QCheckBox *>(optionWidgets["normalizerChB"])->isChecked();
1112         if( b_checked && !qs_filter.contains( "normvol" ) )
1113             qs_filter.append( "normvol" );
1114         if( !b_checked && qs_filter.contains( "normvol" ) )
1115             qs_filter.removeAll( "normvol" );
1116 
1117         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
1118 
1119         /* Default volume */
1120         int i_volume =
1121             qobject_cast<QSlider *>(optionWidgets["defaultVolume"])->value();
1122         bool b_reset_volume =
1123             qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"])->isChecked();
1124         char *psz_aout = config_GetPsz( p_intf, "aout" );
1125 
1126         float f_gain = powf( i_volume / 100.f, 3 );
1127 
1128 #define save_vol_aout( name ) \
1129             module_exists( name ) && ( !psz_aout || !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
1130 
1131         //FIXME this is moot
1132 #if defined( _WIN32 )
1133         VLC_UNUSED( f_gain );
1134         if( save_vol_aout( "mmdevice" ) )
1135             config_PutFloat( p_intf, "mmdevice-volume", i_volume / 100.f );
1136         if( save_vol_aout( "directsound" ) )
1137             config_PutFloat( p_intf, "directx-volume", i_volume / 100.f );
1138         if( save_vol_aout( "waveout" ) )
1139             config_PutFloat( p_intf, "waveout-volume", i_volume / 100.f );
1140 #elif defined( Q_OS_MAC )
1141         VLC_UNUSED( f_gain );
1142         if( save_vol_aout( "auhal" ) )
1143             config_PutFloat( p_intf, "auhal-volume", i_volume / 100.f
1144                     * AOUT_VOLUME_DEFAULT );
1145 #elif defined( __OS2__ )
1146         if( save_vol_aout( "kai" ) )
1147             config_PutFloat( p_intf, "kai-gain",  f_gain );
1148 #else
1149         if( save_vol_aout( "alsa" ) )
1150             config_PutFloat( p_intf, "alsa-gain", f_gain );
1151         if( save_vol_aout( "jack" ) )
1152             config_PutFloat( p_intf, "jack-gain", f_gain );
1153 #endif
1154 #undef save_vol_aout
1155         free( psz_aout );
1156 
1157         config_PutInt( p_intf, "volume-save", !b_reset_volume );
1158 
1159         break;
1160     }
1161     case SPrefsSubtitles:
1162     {
1163         bool b_checked = qobject_cast<QCheckBox *>(optionWidgets["shadowCB"])->isChecked();
1164         if( b_checked && config_GetInt( p_intf, "freetype-shadow-opacity" ) == 0 ) {
1165             config_PutInt( p_intf, "freetype-shadow-opacity", 128 );
1166         }
1167         else if (!b_checked ) {
1168             config_PutInt( p_intf, "freetype-shadow-opacity", 0 );
1169         }
1170 
1171         b_checked = qobject_cast<QCheckBox *>(optionWidgets["backgroundCB"])->isChecked();
1172         if( b_checked && config_GetInt( p_intf, "freetype-background-opacity" ) == 0 ) {
1173             config_PutInt( p_intf, "freetype-background-opacity", 128 );
1174         }
1175         else if (!b_checked ) {
1176             config_PutInt( p_intf, "freetype-background-opacity", 0 );
1177         }
1178 
1179     }
1180     }
1181 }
1182 
clean()1183 void SPrefsPanel::clean()
1184 {}
1185 
lastfm_Changed(int i_state)1186 void SPrefsPanel::lastfm_Changed( int i_state )
1187 {
1188     if( i_state == Qt::Checked )
1189         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1190     else if( i_state == Qt::Unchecked )
1191         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1192 }
1193 
changeStyle(QString s_style)1194 void SPrefsPanel::changeStyle( QString s_style )
1195 {
1196     QApplication::setStyle( s_style );
1197 
1198     /* force refresh on all widgets */
1199     QWidgetList widgets = QApplication::allWidgets();
1200     QWidgetList::iterator it = widgets.begin();
1201     while( it != widgets.end() ) {
1202         (*it)->update();
1203         ++it;
1204     };
1205 }
1206 
langChanged(int i)1207 void SPrefsPanel::langChanged( int i )
1208 {
1209     free( lang );
1210     lang = strdup( language_map[i].iso );
1211 }
1212 
configML()1213 void SPrefsPanel::configML()
1214 {
1215 #ifdef SQL_MEDIA_LIBRARY
1216     MLConfDialog *mld = new MLConfDialog( this, p_intf );
1217     mld->exec();
1218     delete mld;
1219 #endif
1220 }
1221 
1222 #ifdef _WIN32
1223 #include <QDialogButtonBox>
1224 #include "util/registry.hpp"
1225 
cleanLang()1226 void SPrefsPanel::cleanLang() {
1227     QVLCRegistry qvReg( HKEY_CURRENT_USER );
1228     qvReg.DeleteValue( "Software\\VideoLAN\\VLC\\", "Lang" );
1229     qvReg.DeleteKey( "Software\\VideoLAN\\", "VLC" );
1230     qvReg.DeleteKey( "Software\\", "VideoLAN" );
1231 }
1232 
saveLang()1233 void SPrefsPanel::saveLang() {
1234     if( !lang ) return;
1235 
1236     if( !strncmp( lang, "auto", 4 ) ) {
1237         cleanLang();
1238     }
1239     else
1240     {
1241         QVLCRegistry qvReg( HKEY_CURRENT_USER );
1242         qvReg.WriteRegistry( "Software\\VideoLAN\\VLC\\", "Lang", lang );
1243     }
1244 }
1245 
addType(const char * psz_ext,QTreeWidgetItem * current,QTreeWidgetItem * parent,QVLCRegistry * qvReg)1246 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
1247                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
1248 {
1249     bool b_temp;
1250     const char* psz_VLC = "VLC";
1251     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
1252 
1253     char* psz_reg = qvReg->ReadRegistry( psz_ext, "", "" );
1254     if( psz_reg == NULL )
1255         return false;
1256     if( strstr( psz_reg, psz_VLC ) )
1257     {
1258         current->setCheckState( 0, Qt::Checked );
1259         b_temp = true;
1260     }
1261     else
1262     {
1263         current->setCheckState( 0, Qt::Unchecked );
1264         b_temp = false;
1265     }
1266     free( psz_reg );
1267     listAsso.append( current );
1268     return b_temp;
1269 }
1270 
1271 #if !defined(__IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__)
1272 #define __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__
1273     const GUID IID_IApplicationAssociationRegistrationUI = {0x1f76a169,0xf994,0x40ac, {0x8f,0xc8,0x09,0x59,0xe8,0x87,0x47,0x10}};
1274     extern const GUID CLSID_ApplicationAssociationRegistrationUI;
1275     interface IApplicationAssociationRegistrationUI : public IUnknown
1276     {
1277         virtual HRESULT STDMETHODCALLTYPE LaunchAdvancedAssociationUI(
1278                 LPCWSTR pszAppRegName) = 0;
1279     };
1280 #endif /* __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__ */
1281 
1282 void SPrefsPanel::assoDialog()
1283 {
1284     HRESULT hr;
1285 
1286     hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
1287     if( SUCCEEDED(hr) )
1288     {
1289         void *p;
1290 
1291         hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
1292                               NULL, CLSCTX_INPROC_SERVER,
1293                               IID_IApplicationAssociationRegistrationUI, &p);
1294         if( SUCCEEDED(hr) )
1295         {
1296             IApplicationAssociationRegistrationUI *p_regui =
1297                 (IApplicationAssociationRegistrationUI *)p;
1298 
1299             hr = p_regui->LaunchAdvancedAssociationUI(L"VLC" );
1300             p_regui->Release();
1301         }
1302         CoUninitialize();
1303     }
1304 
1305     if( SUCCEEDED(hr) )
1306         return;
1307 
1308     QDialog *d = new QDialog( this );
1309     d->setWindowTitle( qtr( "File associations" ) );
1310     QGridLayout *assoLayout = new QGridLayout( d );
1311 
1312     QTreeWidget *filetypeList = new QTreeWidget;
1313     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
1314     filetypeList->header()->hide();
1315 
1316     QVLCRegistry qvReg( HKEY_CLASSES_ROOT );
1317 
1318     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
1319     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
1320     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
1321 
1322     filetypeList->addTopLevelItem( audioType );
1323     filetypeList->addTopLevelItem( videoType );
1324     filetypeList->addTopLevelItem( otherType );
1325 
1326     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
1327     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
1328     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
1329 
1330     QTreeWidgetItem *currentItem = NULL;
1331 
1332     int i_temp = 0;
1333 #define aTa( name ) i_temp += addType( name, currentItem, audioType, &qvReg )
1334 #define aTv( name ) i_temp += addType( name, currentItem, videoType, &qvReg )
1335 #define aTo( name ) i_temp += addType( name, currentItem, otherType, &qvReg )
1336 
1337     aTa( ".3ga" ); aTa( ".669" ); aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" );
1338     aTa( ".adt" ); aTa( ".adts" ); aTa( ".aif" ); aTa( ".aifc" ); aTa( ".aiff" );
1339     aTa( ".au" ); aTa( ".amr" ); aTa( ".aob" ); aTa( ".ape" ); aTa( ".caf" );
1340     aTa( ".cda" ); aTa( ".dts" ); aTa( ".flac" ); aTa( ".it" ); aTa( ".m4a" );
1341     aTa( ".m4p" ); aTa( ".mid" ); aTa( ".mka" ); aTa( ".mlp" ); aTa( ".mod" );
1342     aTa( ".mp1" ); aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".mpc" ); aTa( ".mpga" );
1343     aTa( ".oga" ); aTa( ".oma" ); aTa( ".opus" ); aTa( ".qcp" ); aTa( ".ra" );
1344     aTa( ".rmi" ); aTa( ".snd" ); aTa( ".s3m" ); aTa( ".spx" ); aTa( ".tta" );
1345     aTa( ".voc" ); aTa( ".vqf" ); aTa( ".w64" ); aTa( ".wav" ); aTa( ".wma" );
1346     aTa( ".wv" ); aTa( ".xa" ); aTa( ".xm" );
1347     audioType->setCheckState( 0, ( i_temp > 0 ) ?
1348                               ( ( i_temp == audioType->childCount() ) ?
1349                                Qt::Checked : Qt::PartiallyChecked )
1350                             : Qt::Unchecked );
1351 
1352     i_temp = 0;
1353     aTv( ".3g2" ); aTv( ".3gp" ); aTv( ".3gp2" ); aTv( ".3gpp" ); aTv( ".amv" );
1354     aTv( ".asf" ); aTv( ".avi" ); aTv( ".bik" ); aTv( ".divx" ); aTv( ".drc" );
1355     aTv( ".dv" ); aTv( ".f4v" ); aTv( ".flv" ); aTv( ".gvi" ); aTv( ".gxf" );
1356     aTv( ".m1v" ); aTv( ".m2t" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
1357     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2v" ); aTv( ".mp4" ); aTv( ".mp4v" );
1358     aTv( ".mpa" ); aTv( ".mpe" ); aTv( ".mpeg" ); aTv( ".mpeg1" ); aTv( ".mpeg2" );
1359     aTv( ".mpeg4" ); aTv( ".mpg" ); aTv( ".mpv2" ); aTv( ".mts" ); aTv( ".mtv" );
1360     aTv( ".mxf" ); aTv( ".nsv" ); aTv( ".nuv" ); aTv( ".ogg" ); aTv( ".ogm" );
1361     aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".rec" ); aTv( ".rm" ); aTv( ".rmvb" );
1362     aTv( ".rpl" ); aTv( ".thp" ); aTv( ".tod" ); aTv( ".ts" ); aTv( ".tts" );
1363     aTv( ".vob" ); aTv( ".vro" ); aTv( ".webm" ); aTv( ".wmv" ); aTv( ".xesc" );
1364     videoType->setCheckState( 0, ( i_temp > 0 ) ?
1365                               ( ( i_temp == videoType->childCount() ) ?
1366                                Qt::Checked : Qt::PartiallyChecked )
1367                             : Qt::Unchecked );
1368 
1369     i_temp = 0;
1370     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".cue" ); aTo( ".ifo" ); aTo( ".m3u" );
1371     aTo( ".m3u8" ); aTo( ".pls" ); aTo( ".ram" ); aTo( ".sdp" ); aTo( ".vlc" );
1372     aTo( ".wvx" ); aTo( ".xspf" );
1373     otherType->setCheckState( 0, ( i_temp > 0 ) ?
1374                               ( ( i_temp == otherType->childCount() ) ?
1375                                Qt::Checked : Qt::PartiallyChecked )
1376                             : Qt::Unchecked );
1377 
1378 #undef aTo
1379 #undef aTv
1380 #undef aTa
1381 
1382     CONNECT( filetypeList, itemChanged(QTreeWidgetItem*, int), this, updateCheckBoxes(QTreeWidgetItem*, int) );
1383 
1384     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
1385     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
1386     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
1387     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1388     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
1389 
1390     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
1391 
1392     CONNECT( closeButton, clicked(), this, saveAsso() );
1393     CONNECT( clearButton, clicked(), d, reject() );
1394     d->resize( 300, 400 );
1395     d->exec();
1396     listAsso.clear();
1397 }
1398 
1399 void SPrefsPanel::updateCheckBoxes(QTreeWidgetItem* item, int column)
1400 {
1401     if( column != 0 )
1402         return;
1403 
1404     /* temporarily block signals to avoid signal loops */
1405     bool b_signalsBlocked = item->treeWidget()->blockSignals(true);
1406 
1407     /* A parent checkbox was changed */
1408     if( item->parent() == 0 )
1409     {
1410         Qt::CheckState checkState = item->checkState(0);
1411         for( int i = 0; i < item->childCount(); i++ )
1412         {
1413             item->child(i)->setCheckState(0, checkState);
1414         }
1415     }
1416 
1417     /* A child checkbox was changed */
1418     else
1419     {
1420         bool b_diff = false;
1421         for( int i = 0; i < item->parent()->childCount(); i++ )
1422         {
1423             if( i != item->parent()->indexOfChild(item) && item->checkState(0) != item->parent()->child(i)->checkState(0) )
1424             {
1425                 b_diff = true;
1426                 break;
1427             }
1428         }
1429 
1430         if( b_diff )
1431             item->parent()->setCheckState(0, Qt::PartiallyChecked);
1432         else
1433             item->parent()->setCheckState(0, item->checkState(0));
1434     }
1435 
1436     /* Stop signal blocking */
1437     item->treeWidget()->blockSignals(b_signalsBlocked);
1438 }
1439 
1440 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
1441 {
1442     QString s_path( "VLC" ); s_path += psz_ext;
1443     QString s_path2 = s_path;
1444 
1445     /* Save a backup if already assigned */
1446     char *psz_value = qvReg->ReadRegistry( psz_ext, "", ""  );
1447 
1448     if( !EMPTY_STR(psz_value) && strcmp( qtu(s_path), psz_value ) )
1449         qvReg->WriteRegistry( psz_ext, "VLC.backup", psz_value );
1450     free( psz_value );
1451 
1452     /* Put a "link" to VLC.EXT as default */
1453     qvReg->WriteRegistry( psz_ext, "", qtu( s_path ) );
1454 
1455     /* Create the needed Key if they weren't done in the installer */
1456     if( !qvReg->RegistryKeyExists( qtu( s_path ) ) )
1457     {
1458         qvReg->WriteRegistry( psz_ext, "", qtu( s_path ) );
1459         qvReg->WriteRegistry( qtu( s_path ), "", "Media file" );
1460         qvReg->WriteRegistry( qtu( s_path.append( "\\shell" ) ), "", "Play" );
1461 
1462         /* Get the installer path */
1463         QVLCRegistry qvReg2( HKEY_LOCAL_MACHINE );
1464         QString str_temp = qvReg2.ReadRegistry( "Software\\VideoLAN\\VLC", "", "" );
1465 
1466         if( str_temp.size() )
1467         {
1468             qvReg->WriteRegistry( qtu( s_path.append( "\\Play\\command" ) ),
1469                 "", qtu( str_temp.append(" --started-from-file \"%1\"" ) ) );
1470 
1471             qvReg->WriteRegistry( qtu( s_path2.append( "\\DefaultIcon" ) ),
1472                         "", qtu( str_temp.append(",0") ) );
1473         }
1474     }
1475 }
1476 
1477 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1478 {
1479     QString s_path( "VLC"); s_path += psz_ext;
1480     char *psz_value = qvReg->ReadRegistry( psz_ext, "", "" );
1481 
1482     if( psz_value && !strcmp( qtu(s_path), psz_value ) )
1483     {
1484         free( psz_value );
1485         psz_value = qvReg->ReadRegistry( psz_ext, "VLC.backup", "" );
1486         if( psz_value )
1487             qvReg->WriteRegistry( psz_ext, "", psz_value );
1488 
1489         qvReg->DeleteValue( psz_ext, "VLC.backup" );
1490     }
1491     free( psz_value );
1492 }
1493 
1494 void SPrefsPanel::saveAsso()
1495 {
1496     QVLCRegistry qvReg( HKEY_CLASSES_ROOT );
1497     for( int i = 0; i < listAsso.size(); i ++ )
1498     {
1499         if( listAsso[i]->checkState( 0 ) > 0 )
1500         {
1501             addAsso( &qvReg, qtu( listAsso[i]->text( 0 ) ) );
1502         }
1503         else
1504         {
1505             delAsso( &qvReg, qtu( listAsso[i]->text( 0 ) ) );
1506         }
1507     }
1508     /* Gruik ? Naaah */
1509     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1510 }
1511 
1512 #endif /* _WIN32 */
1513 
1514