1 /*****************************************************************************
2 * simple_preferences.cpp : "Simple preferences"
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
29 #include "components/simple_preferences.hpp"
30 #include "components/preferences_widgets.hpp"
32 #include <vlc_config_cat.h>
33 #include <vlc_configuration.h>
37 #include <QToolButton>
38 #include <QButtonGroup>
40 #include <QVBoxLayout>
44 #define ICON_HEIGHT 64
45 #define BUTTON_HEIGHT 74
47 /*********************************************************************
48 * The List of categories
49 *********************************************************************/
50 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51 QWidget( _parent ), p_intf( _p_intf )
53 QVBoxLayout *layout = new QVBoxLayout();
55 QButtonGroup *buttonGroup = new QButtonGroup( this );
56 buttonGroup->setExclusive ( true );
57 CONNECT( buttonGroup, buttonClicked ( int ),
58 this, switchPanel( int ) );
60 #define ADD_CATEGORY( button, label, icon, numb ) \
61 QToolButton * button = new QToolButton( this ); \
62 button->setIcon( QIcon( ":/pixmaps/" #icon ) ); \
63 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
64 button->setText( label ); \
65 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
66 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
67 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
68 button->setAutoRaise( true ); \
69 button->setCheckable( true ); \
70 buttonGroup->addButton( button, numb ); \
71 layout->addWidget( button );
73 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74 spref_cone_Interface_64.png, 0 );
75 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
76 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles & OSD"),
78 spref_cone_Subtitles_64.png, 3 );
79 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80 spref_cone_Input_64.png, 4 );
81 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
83 SPrefsInterface->setChecked( true );
84 layout->setMargin( 0 );
85 layout->setSpacing( 1 );
87 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
92 void SPrefsCatList::switchPanel( int i )
94 emit currentItemChanged( i );
97 /*********************************************************************
99 *********************************************************************/
100 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
101 int _number ) : QWidget( _parent ), p_intf( _p_intf )
103 module_config_t *p_config;
104 ConfigControl *control;
107 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
108 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
111 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
112 p_config, label, ui.qcontrol, false ); \
113 controls.append( control ); \
116 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
117 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
120 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
121 p_config, label, ui.qcontrol ); \
122 controls.append( control ); \
125 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
126 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
129 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
130 p_config, label, ui.qcontrol, ui.qbutton, \
132 controls.append( control ); \
135 #define START_SPREFS_CAT( name , label ) \
136 case SPrefs ## name: \
138 Ui::SPrefs ## name ui; \
139 ui.setupUi( panel ); \
140 panel_label->setText( label );
142 #define END_SPREFS_CAT \
146 QVBoxLayout *panel_layout = new QVBoxLayout();
147 QWidget *panel = new QWidget();
148 panel_layout->setMargin( 3 );
151 QLabel *panel_label = new QLabel;
152 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
153 labelFont.setPointSize( labelFont.pointSize() + 6 );
154 labelFont.setFamily( "Verdana" );
155 panel_label->setFont( labelFont );
158 QFrame *title_line = new QFrame;
159 title_line->setFrameShape(QFrame::HLine);
160 title_line->setFrameShadow(QFrame::Sunken);
162 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
163 italicFont.setItalic( true );
167 /******************************
168 * VIDEO Panel Implementation *
169 ******************************/
170 START_SPREFS_CAT( Video , qtr("General video settings") );
171 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
173 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
174 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
175 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
176 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
177 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
178 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
181 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
182 CONFIG_GENERIC( "directx-device", StringList, NULL,
185 ui.directXBox->setVisible( false );
188 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
189 snapshotsDirectory, snapshotsDirectoryBrowse );
190 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
191 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
192 snapshotsSequentialNumbering );
193 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
197 /******************************
198 * AUDIO Panel Implementation *
199 ******************************/
200 START_SPREFS_CAT( Audio, qtr("General audio settings") );
202 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
204 /* hide if necessary */
206 ui.OSSControl->hide();
207 ui.alsaControl->hide();
209 ui.DirectXControl->hide();
211 ui.lastfm_user_edit->hide();
212 ui.lastfm_user_label->hide();
213 ui.lastfm_pass_edit->hide();
214 ui.lastfm_pass_label->hide();
216 /* General Audio Options */
217 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
219 CONNECT( ui.defaultVolume, valueChanged( int ),
220 this, updateAudioVolume( int ) );
222 CONFIG_GENERIC( "audio-language" , String , NULL,
223 preferredAudioLanguage );
225 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
226 CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
227 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
230 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
232 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
234 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
236 /* Audio Output Specifics */
237 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
239 CONNECT( ui.outputModule, currentIndexChanged( int ),
240 this, updateAudioOptions( int ) );
243 CONFIG_GENERIC( "directx-audio-device", IntegerList,
244 ui.DirectXLabel, DirectXDevice );
246 if( module_Exists( p_intf, "alsa" ) )
248 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel,
251 if( module_Exists( p_intf, "oss" ) )
253 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
257 // File exists everywhere
258 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
259 fileName, fileBrowseButton );
261 optionWidgets.append( ui.alsaControl );
262 optionWidgets.append( ui.OSSControl );
263 optionWidgets.append( ui.DirectXControl );
264 optionWidgets.append( ui.fileControl );
265 optionWidgets.append( ui.outputModule );
266 optionWidgets.append( ui.volNormBox );
267 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
269 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
271 optionWidgets.append( ui.volumeValue );
272 updateAudioOptions( ui.outputModule->currentIndex() );
275 if( module_Exists( p_intf, "audioscrobbler" ) )
277 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
279 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
282 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
283 ui.lastfm->setChecked( true );
285 ui.lastfm->setChecked( false );
286 CONNECT( ui.lastfm, stateChanged( int ), this ,
287 lastfm_Changed( int ) );
294 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
295 setEnabled( bool ) );
296 qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
297 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
299 ui.volNormBox->setChecked( b_normalizer );
300 ui.volNormSpin->setEnabled( b_normalizer );
304 updateAudioVolume( ui.defaultVolume->value() ); // First time init
308 /* Input and Codecs Panel Implementation */
309 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
313 ui.DVDDevice->setToolTip(
314 //TODO: make this sentence understandable
315 qtr( "If this property is blank, then you have\n"
316 "values for DVD, VCD, and CDDA.\n"
317 "You can define a unique one or set that in"
318 "the advanced preferences" ) );
319 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
320 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
321 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
322 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
323 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
324 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
326 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
328 delete psz_cddadiscpath; delete psz_dvddiscpath;
329 delete psz_vcddiscpath;
332 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
333 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
334 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
335 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
336 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
338 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
340 ui.systemCodecBox->hide();
343 qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
344 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
345 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
346 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
347 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
349 optionWidgets.append( ui.recordBox );
350 optionWidgets.append( ui.dumpBox );
351 optionWidgets.append( ui.bandwidthBox );
352 optionWidgets.append( ui.timeshiftBox );
353 optionWidgets.append( ui.DVDDevice );
354 optionWidgets.append( ui.cachingCombo );
357 /* Add the things to the ComboBox */
358 #define addToCachingBox( str, cachingNumber ) \
359 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
360 addToCachingBox( "Custom", CachingCustom );
361 addToCachingBox( "Lowest latency", CachingLowest );
362 addToCachingBox( "Low latency", CachingLow );
363 addToCachingBox( "Normal", CachingNormal );
364 addToCachingBox( "High latency", CachingHigh );
365 addToCachingBox( "Higher latency", CachingHigher );
367 #define TestCaC( name ) \
368 b_cache_equal = b_cache_equal && \
369 ( i_cache == config_GetInt( p_intf, name ) )
371 #define TestCaCi( name, int ) \
372 b_cache_equal = b_cache_equal && \
373 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
374 /* Select the accurate value of the ComboBox */
375 bool b_cache_equal = true;
376 int i_cache = config_GetInt( p_intf, "file-caching");
378 TestCaC( "udp-caching" );
379 if (module_Exists (p_intf, "dvdread"))
380 TestCaC( "dvdread-caching" );
381 if (module_Exists (p_intf, "dvdnav"))
382 TestCaC( "dvdnav-caching" );
383 TestCaC( "tcp-caching" );
384 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
385 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
387 TestCaC( "dshow-caching" );
389 if (module_Exists (p_intf, "v4l"))
390 TestCaC( "v4l-caching" );
391 if (module_Exists (p_intf, "access_jack"))
392 TestCaC( "jack-input-caching" );
393 if (module_Exists (p_intf, "v4l2"))
394 TestCaC( "v4l2-caching" );
395 if (module_Exists (p_intf, "pvr"))
396 TestCaC( "pvr-caching" );
398 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
399 TestCaCi( "http-caching", 4 );
400 if (module_Exists (p_intf, "access_realrtsp"))
401 TestCaCi( "realrtsp-caching", 10 );
402 TestCaCi( "mms-caching", 19 );
403 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
404 ui.cachingCombo->findData( QVariant( i_cache ) ) );
410 START_SPREFS_CAT( Interface, qtr("Interface settings") );
411 ui.defaultLabel->setFont( italicFont );
412 ui.skinsLabel->setFont( italicFont );
414 #if defined( WIN32 ) || defined (__APPLE__)
415 CONFIG_GENERIC( "language", StringList, NULL, language );
416 BUTTONACT( ui.assoButton, assoDialog() );
419 ui.languageLabel->hide();
421 ui.assoButton->hide();
425 char *psz_intf = config_GetPsz( p_intf, "intf" );
428 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
429 if( strstr( psz_intf, "skin" ) )
430 ui.skins->setChecked( true );
431 else if( strstr( psz_intf, "qt" ) )
432 ui.qt4->setChecked( true );
436 optionWidgets.append( ui.skins );
437 optionWidgets.append( ui.qt4 );
439 CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
441 CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
442 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
445 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
447 CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
448 CONFIG_GENERIC( "security-policy", IntegerList,
449 ui.netPolicyLabel, netPolicyBox );
453 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
454 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
456 CONNECT( ui.updatesBox, toggled( bool ),
457 ui.updatesDays, setEnabled( bool ) );
459 ui.updatesBox->hide();
460 ui.updatesDays->hide();
462 /* ONE INSTANCE options */
463 #if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
464 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
465 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
466 EnqueueOneInterfaceMode );
468 ui.OneInterfaceBox->hide();
472 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
473 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
475 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
476 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
477 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
479 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
480 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
482 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
488 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
490 QGridLayout *gLayout = new QGridLayout;
491 panel->setLayout( gLayout );
494 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
495 this, gLayout, line );
497 panel_label->setText( qtr( "Configure Hotkeys" ) );
498 controls.append( control );
504 panel_layout->addWidget( panel_label );
505 panel_layout->addWidget( title_line );
506 panel_layout->addWidget( panel );
507 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
509 setLayout( panel_layout );
512 void SPrefsPanel::updateAudioOptions( int number)
514 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
515 ->itemData( number ).toString();
518 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
520 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
521 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
523 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
526 void SPrefsPanel::updateAudioVolume( int volume )
528 qobject_cast<QSpinBox *>(optionWidgets[volLW])
529 ->setValue( volume * 100 / 256 );
533 /* Function called from the main Preferences dialog on each SPrefs Panel */
534 void SPrefsPanel::apply()
536 msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
538 /* Generic save for ever panel */
539 QList<ConfigControl *>::Iterator i;
540 for( i = controls.begin() ; i != controls.end() ; i++ )
542 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
543 c->doApply( p_intf );
548 case SPrefsInputAndCodecs:
550 /* Device default selection */
551 char *psz_devicepath =
552 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
553 if( !EMPTY_STR( psz_devicepath ) )
555 config_PutPsz( p_intf, "dvd", psz_devicepath );
556 config_PutPsz( p_intf, "vcd", psz_devicepath );
557 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
561 #define saveBox( name, box ) {\
562 if( box->isChecked() ) { \
564 qs_filter.append( name ); \
567 else qs_filter.append( ":" ).append( name ); \
572 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
573 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
574 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
575 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
576 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
578 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
579 #define CaC( name ) CaCi( name, 1 )
581 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
582 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
585 msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
586 CaC( "udp-caching" );
587 if (module_Exists (p_intf, "dvdread" ))
588 CaC( "dvdread-caching" );
589 if (module_Exists (p_intf, "dvdnav" ))
590 CaC( "dvdnav-caching" );
591 CaC( "tcp-caching" ); CaC( "vcd-caching" );
592 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
593 CaC( "screen-caching" );
594 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
595 CaCi( "http-caching", 4 );
596 if (module_Exists (p_intf, "access_realrtsp" ))
597 CaCi( "realrtsp-caching", 10 );
598 CaCi( "mms-caching", 19 );
600 CaC( "dshow-caching" );
602 if (module_Exists (p_intf, "v4l" ))
603 CaC( "v4l-caching" );
604 if (module_Exists (p_intf, "access_jack" ))
605 CaC( "jack-input-caching" );
606 if (module_Exists (p_intf, "v4l2" ))
607 CaC( "v4l2-caching" );
608 if (module_Exists (p_intf, "pvr" ))
609 CaC( "pvr-caching" );
611 //CaCi( "dv-caching" ) too short...
617 case SPrefsInterface:
619 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
620 config_PutPsz( p_intf, "intf", "skins2" );
621 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
622 config_PutPsz( p_intf, "intf", "qt4" );
629 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
630 if( qs_filter.isEmpty() )
632 /* the psz_filter is already empty, so we just append it needed */
633 if( b_normChecked ) qs_filter = "volnorm";
637 if( qs_filter.contains( "volnorm" ) )
639 /* The qs_filter not empty and contains "volnorm"
640 that we have to remove */
644 qs_filter.remove( "volnorm:" );
645 qs_filter.remove( ":volnorm" );
646 qs_filter.remove( "volnorm" );
649 else /* qs_filter not empty, but doesn't have volnorm inside */
650 if( b_normChecked ) qs_filter.append( ":volnorm" );
652 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
658 void SPrefsPanel::clean()
661 void SPrefsPanel::lastfm_Changed( int i_state )
663 if( i_state == Qt::Checked )
664 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
665 else if( i_state == Qt::Unchecked )
666 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
670 #include <QDialogButtonBox>
671 #include <QHeaderView>
672 #include "util/registry.hpp"
674 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
675 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
678 const char* psz_VLC = "VLC";
679 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
681 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
683 current->setCheckState( 0, Qt::Checked );
688 current->setCheckState( 0, Qt::Unchecked );
691 listAsso.append( current );
695 void SPrefsPanel::assoDialog()
697 QDialog *d = new QDialog( this );
698 QGridLayout *assoLayout = new QGridLayout( d );
700 QTreeWidget *filetypeList = new QTreeWidget;
701 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
702 filetypeList->header()->hide();
704 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
706 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
707 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
708 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
710 filetypeList->addTopLevelItem( audioType );
711 filetypeList->addTopLevelItem( videoType );
712 filetypeList->addTopLevelItem( otherType );
714 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
715 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
716 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
718 QTreeWidgetItem *currentItem;
721 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
722 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
723 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
725 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
726 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
727 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
728 aTa( ".wma" ); aTa( ".xm" );
729 audioType->setCheckState( 0, ( i_temp > 0 ) ?
730 ( ( i_temp == audioType->childCount() ) ?
731 Qt::Checked : Qt::PartiallyChecked )
735 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
736 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
737 aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
738 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
739 aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
740 aTv( ".vob" ); aTv( ".wmv" );
741 videoType->setCheckState( 0, ( i_temp > 0 ) ?
742 ( ( i_temp == audioType->childCount() ) ?
743 Qt::Checked : Qt::PartiallyChecked )
747 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
749 otherType->setCheckState( 0, ( i_temp > 0 ) ?
750 ( ( i_temp == audioType->childCount() ) ?
751 Qt::Checked : Qt::PartiallyChecked )
754 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
755 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
756 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
757 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
758 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
760 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
762 CONNECT( closeButton, clicked(), this, saveAsso() );
763 CONNECT( clearButton, clicked(), d, reject() );
764 d->resize( 300, 400 );
771 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
773 std::string s_path( "VLC" ); s_path += psz_ext;
774 std::string s_path2 = s_path;
776 /* Save a backup if already assigned */
777 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
779 if( psz_value && strlen( psz_value ) > 0 )
780 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
783 /* Put a "link" to VLC.EXT as default */
784 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
786 /* Create the needed Key if they weren't done in the installer */
787 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
789 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
790 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
791 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
793 /* Get the installer path */
794 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
795 std::string str_temp; str_temp.assign(
796 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
798 if( str_temp.size() )
800 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
801 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
803 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
804 "", str_temp.append(",0").c_str() );
810 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
812 char psz_VLC[] = "VLC";
813 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
815 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
818 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
820 qvReg->WriteRegistryString( psz_ext, "", psz_value );
822 qvReg->DeleteKey( psz_ext, "VLC.backup" );
826 void SPrefsPanel::saveAsso()
828 QVLCRegistry * qvReg;
829 for( int i = 0; i < listAsso.size(); i ++ )
831 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
832 if( listAsso[i]->checkState( 0 ) > 0 )
834 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
838 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
842 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();