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