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