1 /*****************************************************************************
2 * simple_preferences.cpp : "Simple preferences"
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
5 * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
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"),
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 this->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( "force-dolby-surround" , IntegerList , NULL,
229 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
231 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
233 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
235 /* Audio Output Specifics */
236 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
238 CONNECT( ui.outputModule, currentIndexChanged( int ),
239 this, updateAudioOptions( int ) );
242 CONFIG_GENERIC( "directx-audio-device", IntegerList,
243 ui.DirectXLabel, DirectXDevice );
245 if( module_Exists( p_intf, "alsa" ) )
247 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel,
250 if( module_Exists( p_intf, "oss" ) )
252 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
256 // File exists everywhere
257 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
258 fileName, fileBrowseButton );
260 optionWidgets.append( ui.alsaControl );
261 optionWidgets.append( ui.OSSControl );
262 optionWidgets.append( ui.DirectXControl );
263 optionWidgets.append( ui.fileControl );
264 optionWidgets.append( ui.outputModule );
265 optionWidgets.append( ui.volNormBox );
266 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
268 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
270 optionWidgets.append( ui.volumeValue );
271 updateAudioOptions( ui.outputModule->currentIndex() );
274 if( module_Exists( p_intf, "audioscrobbler" ) )
276 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
278 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
281 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
282 ui.lastfm->setChecked( true );
284 ui.lastfm->setChecked( false );
285 CONNECT( ui.lastfm, stateChanged( int ), this ,
286 lastfm_Changed( int ) );
293 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
294 setEnabled( bool ) );
295 qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
296 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
298 ui.volNormBox->setChecked( b_normalizer );
299 ui.volNormSpin->setEnabled( b_normalizer );
303 updateAudioVolume( ui.defaultVolume->value() ); // First time init
307 /* Input and Codecs Panel Implementation */
308 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
312 ui.DVDDevice->setToolTip(
313 //TODO: make this sentence understandable
314 qtr( "If this property is blank, then you have\n"
315 "values for DVD, VCD, and CDDA.\n"
316 "You can define a unique one or set that in"
317 "the advanced preferences" ) );
318 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
319 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
320 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
321 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
322 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
323 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
325 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
327 delete psz_cddadiscpath; delete psz_dvddiscpath;
328 delete psz_vcddiscpath;
331 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
332 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
333 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
334 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
335 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
337 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
339 ui.systemCodecBox->hide();
342 qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
343 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
344 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
345 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
346 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
348 optionWidgets.append( ui.recordBox );
349 optionWidgets.append( ui.dumpBox );
350 optionWidgets.append( ui.bandwidthBox );
351 optionWidgets.append( ui.timeshiftBox );
352 optionWidgets.append( ui.DVDDevice );
353 optionWidgets.append( ui.cachingCombo );
356 /* Add the things to the ComboBox */
357 #define addToCachingBox( str, cachingNumber ) \
358 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
359 addToCachingBox( "Custom", CachingCustom );
360 addToCachingBox( "Lowest latency", CachingLowest );
361 addToCachingBox( "Low latency", CachingLow );
362 addToCachingBox( "Normal", CachingNormal );
363 addToCachingBox( "High latency", CachingHigh );
364 addToCachingBox( "Higher latency", CachingHigher );
366 #define TestCaC( name ) \
367 b_cache_equal = b_cache_equal && \
368 ( i_cache == config_GetInt( p_intf, name ) )
370 #define TestCaCi( name, int ) \
371 b_cache_equal = b_cache_equal && \
372 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
373 /* Select the accurate value of the ComboBox */
374 bool b_cache_equal = true;
375 int i_cache = config_GetInt( p_intf, "file-caching");
377 TestCaC( "udp-caching" );
378 if (module_Exists (p_intf, "dvdread"))
379 TestCaC( "dvdread-caching" );
380 if (module_Exists (p_intf, "dvdnav"))
381 TestCaC( "dvdnav-caching" );
382 TestCaC( "tcp-caching" );
383 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
384 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
386 TestCaC( "dshow-caching" );
388 if (module_Exists (p_intf, "v4l"))
389 TestCaC( "v4l-caching" );
390 if (module_Exists (p_intf, "access_jack"))
391 TestCaC( "jack-input-caching" );
392 if (module_Exists (p_intf, "v4l2"))
393 TestCaC( "v4l2-caching" );
394 if (module_Exists (p_intf, "pvr"))
395 TestCaC( "pvr-caching" );
397 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
398 TestCaCi( "http-caching", 4 );
399 if (module_Exists (p_intf, "access_realrtsp"))
400 TestCaCi( "realrtsp-caching", 10 );
401 TestCaCi( "mms-caching", 19 );
402 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
403 ui.cachingCombo->findData( QVariant( i_cache ) ) );
409 START_SPREFS_CAT( Interface, qtr("Interface settings") );
410 ui.defaultLabel->setFont( italicFont );
411 ui.skinsLabel->setFont( italicFont );
413 #if defined( WIN32 ) || defined (__APPLE__)
414 CONFIG_GENERIC( "language", StringList, NULL, language );
415 BUTTONACT( ui.assoButton, assoDialog() );
418 ui.languageLabel->hide();
420 ui.assoButton->hide();
424 char *psz_intf = config_GetPsz( p_intf, "intf" );
427 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
428 if( strstr( psz_intf, "skin" ) )
429 ui.skins->setChecked( true );
430 else if( strstr( psz_intf, "qt" ) )
431 ui.qt4->setChecked( true );
435 optionWidgets.append( ui.skins );
436 optionWidgets.append( ui.qt4 );
438 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel, artFetcher );
439 CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
441 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
442 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
444 CONNECT( ui.updatesBox, toggled( bool ),
445 ui.updatesDays, setEnabled( bool ) );
447 ui.updatesBox->hide();
448 ui.updatesDays->hide();
450 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
451 CONFIG_GENERIC( "embeded-video", Bool, NULL, embedVideo );
452 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
454 #if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
455 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
456 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
457 EnqueueOneInterfaceMode );
459 ui.OneInterfaceBox->hide();
463 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
464 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
466 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
467 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
468 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
470 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
471 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
473 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
479 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
481 QGridLayout *gLayout = new QGridLayout;
482 panel->setLayout( gLayout );
485 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
486 this, gLayout, line );
488 panel_label->setText( qtr( "Configure Hotkeys" ) );
489 controls.append( control );
495 panel_layout->addWidget( panel_label );
496 panel_layout->addWidget( title_line );
497 panel_layout->addWidget( panel );
498 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
500 setLayout( panel_layout );
503 void SPrefsPanel::updateAudioOptions( int number)
505 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
506 ->itemData( number ).toString();
509 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
511 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
512 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
514 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
517 void SPrefsPanel::updateAudioVolume( int volume )
519 qobject_cast<QSpinBox *>(optionWidgets[volLW])
520 ->setValue( volume * 100 / 256 );
524 /* Function called from the main Preferences dialog on each SPrefs Panel */
525 void SPrefsPanel::apply()
527 msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
529 /* Generic save for ever panel */
530 QList<ConfigControl *>::Iterator i;
531 for( i = controls.begin() ; i != controls.end() ; i++ )
533 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
534 c->doApply( p_intf );
539 case SPrefsInputAndCodecs:
541 /* Device default selection */
542 char *psz_devicepath =
543 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
544 if( !EMPTY_STR( psz_devicepath ) )
546 config_PutPsz( p_intf, "dvd", psz_devicepath );
547 config_PutPsz( p_intf, "vcd", psz_devicepath );
548 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
552 #define saveBox( name, box ) {\
553 if( box->isChecked() ) { \
555 qs_filter.append( name ); \
558 else qs_filter.append( ":" ).append( name ); \
563 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
564 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
565 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
566 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
567 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
569 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
570 #define CaC( name ) CaCi( name, 1 )
572 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
573 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
576 msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
577 CaC( "udp-caching" );
578 if (module_Exists (p_intf, "dvdread" ))
579 CaC( "dvdread-caching" );
580 if (module_Exists (p_intf, "dvdnav" ))
581 CaC( "dvdnav-caching" );
582 CaC( "tcp-caching" ); CaC( "vcd-caching" );
583 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
584 CaC( "screen-caching" );
585 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
586 CaCi( "http-caching", 4 );
587 if (module_Exists (p_intf, "access_realrtsp" ))
588 CaCi( "realrtsp-caching", 10 );
589 CaCi( "mms-caching", 19 );
591 CaC( "dshow-caching" );
593 if (module_Exists (p_intf, "v4l" ))
594 CaC( "v4l-caching" );
595 if (module_Exists (p_intf, "access_jack" ))
596 CaC( "jack-input-caching" );
597 if (module_Exists (p_intf, "v4l2" ))
598 CaC( "v4l2-caching" );
599 if (module_Exists (p_intf, "pvr" ))
600 CaC( "pvr-caching" );
602 //CaCi( "dv-caching" ) too short...
608 case SPrefsInterface:
610 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
611 config_PutPsz( p_intf, "intf", "skins2" );
612 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
613 config_PutPsz( p_intf, "intf", "qt4" );
620 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
621 if( qs_filter.isEmpty() )
623 /* the psz_filter is already empty, so we just append it needed */
624 if( b_normChecked ) qs_filter = "volnorm";
628 if( qs_filter.contains( "volnorm" ) )
630 /* The qs_filter not empty and contains "volnorm"
631 that we have to remove */
635 qs_filter.remove( "volnorm:" );
636 qs_filter.remove( ":volnorm" );
637 qs_filter.remove( "volnorm" );
640 else /* qs_filter not empty, but doesn't have volnorm inside */
641 if( b_normChecked ) qs_filter.append( ":volnorm" );
643 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
649 void SPrefsPanel::clean()
652 void SPrefsPanel::lastfm_Changed( int i_state )
654 if( i_state == Qt::Checked )
655 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
656 else if( i_state == Qt::Unchecked )
657 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
661 #include <QDialogButtonBox>
662 #include <QHeaderView>
663 #include "util/registry.hpp"
665 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
666 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
669 const char* psz_VLC = "VLC";
670 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
672 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
674 current->setCheckState( 0, Qt::Checked );
679 current->setCheckState( 0, Qt::Unchecked );
682 listAsso.append( current );
686 void SPrefsPanel::assoDialog()
688 QDialog *d = new QDialog( this );
689 QGridLayout *assoLayout = new QGridLayout( d );
691 QTreeWidget *filetypeList = new QTreeWidget;
692 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
693 filetypeList->header()->hide();
695 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
697 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
698 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
699 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
701 filetypeList->addTopLevelItem( audioType );
702 filetypeList->addTopLevelItem( videoType );
703 filetypeList->addTopLevelItem( otherType );
705 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
706 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
707 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
709 QTreeWidgetItem *currentItem;
712 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
713 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
714 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
716 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
717 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
718 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
719 aTa( ".wma" ); aTa( ".xm" );
720 audioType->setCheckState( 0, ( i_temp > 0 ) ?
721 ( ( i_temp == audioType->childCount() ) ?
722 Qt::Checked : Qt::PartiallyChecked )
726 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
727 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
728 aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
729 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
730 aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
731 aTv( ".vob" ); aTv( ".wmv" );
732 videoType->setCheckState( 0, ( i_temp > 0 ) ?
733 ( ( i_temp == audioType->childCount() ) ?
734 Qt::Checked : Qt::PartiallyChecked )
738 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
740 otherType->setCheckState( 0, ( i_temp > 0 ) ?
741 ( ( i_temp == audioType->childCount() ) ?
742 Qt::Checked : Qt::PartiallyChecked )
745 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
746 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
747 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
748 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
749 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
751 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
753 CONNECT( closeButton, clicked(), this, saveAsso() );
754 CONNECT( clearButton, clicked(), d, reject() );
755 d->resize( 300, 400 );
762 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
764 std::string s_path( "VLC" ); s_path += psz_ext;
765 std::string s_path2 = s_path;
767 /* Save a backup if already assigned */
768 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
770 if( psz_value && strlen( psz_value ) > 0 )
771 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
774 /* Put a "link" to VLC.EXT as default */
775 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
777 /* Create the needed Key if they weren't done in the installer */
778 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
780 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
781 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
782 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
784 /* Get the installer path */
785 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
786 std::string str_temp; str_temp.assign(
787 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
789 if( str_temp.size() )
791 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
792 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
794 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
795 "", str_temp.append(",0").c_str() );
801 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
803 char psz_VLC[] = "VLC";
804 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
806 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
809 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
811 qvReg->WriteRegistryString( psz_ext, "", psz_value );
813 qvReg->DeleteKey( psz_ext, "VLC.backup" );
817 void SPrefsPanel::saveAsso()
819 QVLCRegistry * qvReg;
820 for( int i = 0; i < listAsso.size(); i ++ )
822 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
823 if( listAsso[i]->checkState( 0 ) > 0 )
825 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
829 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
833 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();