]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4- SImple Preferences. Add file and directory configuration.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
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 #include <QListWidget>
27 #include <QListWidgetItem>
28 #include <QString>
29 #include <QFont>
30
31 #include "components/simple_preferences.hpp"
32 #include "components/preferences_widgets.hpp"
33 #include "qt4.hpp"
34
35 #include <vlc_config_cat.h>
36 #include <assert.h>
37
38 #include "pixmaps/hotkeys_50x50.xpm"
39 #include "pixmaps/audio_50x50.xpm"
40 #include "pixmaps/input_and_codecs_50x50.xpm"
41 #include "pixmaps/interface_50x50.xpm"
42 #include "pixmaps/subtitles_50x50.xpm"
43 #include "pixmaps/video_50x50.xpm"
44
45 #include "ui/sprefs_audio.h"
46 #include "ui/sprefs_input.h"
47 #include "ui/sprefs_video.h"
48 #include "ui/sprefs_subtitles.h"
49 #include "ui/sprefs_hotkeys.h"
50 #include "ui/sprefs_interface.h"
51
52 #define ITEM_HEIGHT 50
53
54 /*********************************************************************
55  * The List of categories
56  *********************************************************************/
57 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
58                                   QListWidget( _parent ), p_intf( _p_intf )
59 {
60     setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
61     setAlternatingRowColors( true );
62     setViewMode(QListView::IconMode);
63     setMaximumWidth(200);
64
65 #define ADD_CATEGORY( id, label, icon )                                 \
66     addItem( label );                                                   \
67     item( id )->setIcon( QIcon( QPixmap( icon ) ) );                    \
68     item( id )->setData( Qt::UserRole, qVariantFromValue( (int)id ) );  \
69     item( id )->setTextAlignment(Qt::AlignHCenter);                     \
70     item( id )->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
71
72     ADD_CATEGORY( SPrefsVideo, qtr("Video"), video_50x50_xpm );
73     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), audio_50x50_xpm );
74     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
75                   input_and_codecs_50x50_xpm );
76     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), interface_50x50_xpm );
77     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"), subtitles_50x50_xpm );
78     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), hotkeys_50x50_xpm );
79
80     setCurrentRow( SPrefsInterface );
81 }
82
83 /*********************************************************************
84  * The Panels
85  *********************************************************************/
86 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
87                           int number ) : QWidget( _parent ), p_intf( _p_intf )
88 {
89     module_config_t *p_config;
90     ConfigControl *control;
91
92 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
93             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
94             if( p_config )                                                \
95             {                                                             \
96                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
97                            p_config, label, ui.qcontrol, false );         \
98                 controls.append( control );                               \
99             }
100
101 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
102             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
103             if( p_config )                                                \
104             {                                                             \
105                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
106                            p_config, label, ui.qcontrol );                \
107                 controls.append( control );                               \
108             }
109
110 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
111                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
112                 if( p_config )                                                \
113                 {                                                             \
114                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
115                                p_config, label, ui.qcontrol, ui.qbutton,      \
116                             false );                                          \
117                     controls.append( control );                               \
118                 }
119
120
121
122 #define START_SPREFS_CAT( name , label )    \
123         case SPrefs ## name:                \
124         {                                   \
125             Ui::SPrefs ## name ui;          \
126             ui.setupUi( panel );            \
127             panel_label->setText( qtr( label ) );
128
129 #define END_SPREFS_CAT      \
130             break;          \
131         }
132
133     QVBoxLayout *panel_layout = new QVBoxLayout();
134     QWidget *panel = new QWidget();
135
136     // Title Label
137     QLabel *panel_label = new QLabel;
138     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
139     labelFont.setPointSize( labelFont.pointSize() + 4 );
140     labelFont.setBold( true );
141     panel_label->setFont( labelFont );
142
143     // Title <hr>
144     QFrame *title_line = new QFrame;
145     title_line->setFrameShape(QFrame::HLine);
146     title_line->setFrameShadow(QFrame::Sunken);
147
148     switch( number )
149     {
150         /* Video Panel Implementation */
151         START_SPREFS_CAT( Video , "General video settings" );
152          #ifndef WIN32
153             ui.directXBox->setVisible( false );
154          #endif
155             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
156
157             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
158             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
159             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
160             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
161             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames);
162             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
163
164 #ifdef WIN32
165             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
166             CONFIG_GENERIC( "directx-device", StringList, NULL, 
167                     dXdisplayDevice );
168 #endif
169
170             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
171                     snapshotsDirectory, snapshotsDirectoryBrowse );
172             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
173             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
174                             snapshotsSequentialNumbering );
175             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
176                             snapshotsFormat );
177          END_SPREFS_CAT;
178
179          /* Audio Panel Implementation */
180         START_SPREFS_CAT( Audio,  "General audio settings" );
181 #ifdef WIN32
182             ui.OSSBrowse->hide();
183             ui.OSSDevice->hide();
184             ui.OSSLabel->hide();
185             ui.alsaDevice->hide();
186             ui.alsaLabel->hide();
187 #else
188             ui.DirectXLabel->setVisible( false );
189             ui.DirectXDevice->setVisible( false );
190 #endif
191          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
192
193          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
194                  defaultVolume );
195          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
196                     preferredAudioLanguage );
197          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
198          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
199                     detectionDolby );
200
201          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
202 #ifndef WIN32
203          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
204          CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
205 #else
206          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
207                  DirectXDevice );
208 #endif
209          CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName, 
210                  fileBrowseButton );
211
212          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
213 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer 
214          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
215                  volNormalizer );
216          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
217         END_SPREFS_CAT;
218
219         /* Input and Codecs Panel Implementation */
220         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
221           /* Disk Devices */
222 /*          CONFIG_GENERIC( );*/
223
224           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
225           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
226
227           /* Caching */
228 /*          CONFIG_GENERIC( );*/
229
230           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
231           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
232           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
233
234           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
235           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
236 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
237         END_SPREFS_CAT;
238
239         /* Interface Panel */
240         START_SPREFS_CAT( Interface, "Interfaces settings" );
241
242             CONFIG_GENERIC( "language", StringList, NULL, language );
243 #if !defined( WIN32 ) && !defined( HAVE_DBUS_3 )
244             ui.OneInterfaceBox->hide();
245 #endif
246             /* interface */
247 /*            p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
248             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
249                     ui.qt4->setChecked( true );
250             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
251                     ui.skins->setChecked( true );*/
252 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
253             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
254             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, 
255                     skinBrowse );
256 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
257             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
258             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, 
259                     EnqueueOneInterfaceMode );
260 #endif
261         END_SPREFS_CAT;
262
263         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
264             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
265
266             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
267             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
268
269             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font, 
270                     fontBrowse ); 
271             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
272             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
273                             fontSize );
274             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
275
276         END_SPREFS_CAT;
277
278         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
279         END_SPREFS_CAT;
280         }
281
282     panel_layout->addWidget(panel_label);
283     panel_layout->addWidget(title_line);
284     panel_layout->addWidget( panel );
285     panel_layout->addStretch( 2 );
286
287     this->setLayout(panel_layout);
288 }
289
290 void SPrefsPanel::apply()
291 {
292     QList<ConfigControl *>::Iterator i;
293     for( i = controls.begin() ; i != controls.end() ; i++ )
294     {
295         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
296         c->doApply( p_intf );
297     }
298 }
299
300 void SPrefsPanel::clean()
301 {}