]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 - SPrefs : Interface Panel.
[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  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <QListWidget>
26 #include <QListWidgetItem>
27 #include <QString>
28 #include <QFont>
29
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32 #include "qt4.hpp"
33
34 #include <vlc_config_cat.h>
35 #include <assert.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
62 #define ADD_CATEGORY( id, label, icon )                             \
63     addItem( label );                                               \
64     item( id )->setIcon( QIcon( QPixmap( icon ) ) );                \
65     item( id )->setData( Qt::UserRole, qVariantFromValue( (int)id ) );
66
67     ADD_CATEGORY( SPrefsVideo, qtr("Video"), video_50x50_xpm );
68     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), audio_50x50_xpm );
69     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
70                   input_and_codecs_50x50_xpm );
71     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), interface_50x50_xpm );
72     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"), subtitles_50x50_xpm );
73     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), hotkeys_50x50_xpm );
74
75     setCurrentRow( SPrefsInterface );
76 }
77
78 /*********************************************************************
79  * The Panels
80  *********************************************************************/
81 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
82                           int number ) : QWidget( _parent ), p_intf( _p_intf )
83 {
84     module_config_t *p_config;
85     ConfigControl *control;
86
87 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
88             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
89             if( p_config )                                                \
90             {                                                             \
91                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
92                            p_config, label, ui.qcontrol, false );         \
93                 controls.append( control );                               \
94             }
95
96 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
97             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
98             if( p_config )                                                \
99             {                                                             \
100                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
101                            p_config, label, ui.qcontrol );                \
102                 controls.append( control );                               \
103             }
104
105
106
107 #define START_SPREFS_CAT( name , label )    \
108         case SPrefs ## name:                \
109         {                                   \
110             Ui::SPrefs ## name ui;          \
111             ui.setupUi( panel );            \
112             panel_label->setText( qtr( label ) );
113
114 #define END_SPREFS_CAT      \
115             break;          \
116         }
117
118     QVBoxLayout *panel_layout = new QVBoxLayout();
119     QWidget *panel = new QWidget();
120
121     // Title Label
122     QLabel *panel_label = new QLabel;
123     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
124     labelFont.setPointSize( labelFont.pointSize() + 4 );
125     labelFont.setBold( true );
126     panel_label->setFont( labelFont );
127
128     // Title <hr>
129     QFrame *title_line = new QFrame;
130     title_line->setFrameShape(QFrame::HLine);
131     title_line->setFrameShadow(QFrame::Sunken);
132
133     switch( number )
134     {
135         /* Video Panel Implementation */
136         START_SPREFS_CAT( Video , "General video settings" );
137          #ifndef WIN32
138             ui.directXBox->setVisible( false );
139          #endif
140             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
141
142             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
143             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
144             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
145             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
146             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames);
147             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
148
149 #ifdef WIN32
150             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
151             CONFIG_GENERIC( "directx-device", StringList, NULL, 
152                     dXdisplayDevice );
153 #endif
154
155             CONFIG_GENERIC( "snapshot-path", String, NULL,
156                     snapshotsDirectory ); /* FIXME -> use file instead of string */
157             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
158             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
159                             snapshotsSequentialNumbering );
160             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
161                             snapshotsFormat );
162          END_SPREFS_CAT;
163
164          /* Audio Panel Implementation */
165         START_SPREFS_CAT( Audio,  "General audio settings" );
166 #ifdef WIN32
167             ui.OSSBrowse->hide();
168             ui.OSSDevice->hide();
169             ui.OSSLabel->hide();
170             ui.alsaDevice->hide();
171             ui.alsaLabel->hide();
172 #else
173             ui.DirectXLabel->setVisible( false );
174             ui.DirectXDevice->setVisible( false );
175 #endif
176          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
177
178          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
179                  defaultVolume );
180          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
181                     preferredAudioLanguage );
182          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
183          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
184                     detectionDolby );
185
186          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
187 #ifndef WIN32
188          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
189          CONFIG_GENERIC( "dspdev" , String , NULL, OSSDevice );//FIXME File
190 #else
191          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
192                  DirectXDevice );
193 #endif
194          CONFIG_GENERIC( "audiofile-file" , String , NULL, FileName ); //Fixme File
195
196          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
197 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer 
198          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
199                  volNormalizer );
200          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
201         END_SPREFS_CAT;
202
203         /* Input and Codecs Panel Implementation */
204         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
205           /* Disk Devices */
206 /*          CONFIG_GENERIC( );*/
207
208           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
209           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
210
211           /* Caching */
212 /*          CONFIG_GENERIC( );*/
213
214           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
215           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
216           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
217
218           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
219           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
220 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
221         END_SPREFS_CAT;
222
223         /* Interface Panel */
224         START_SPREFS_CAT( Interface, "Interfaces settings" );
225             CONFIG_GENERIC( "language", StringList, NULL, language );
226
227 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
228             CONFIG_GENERIC ("one-instance", Bool, NULL, OneInterfaceMode );
229             CONFIG_GENERIC ("playlist-enqueue", Bool, NULL, 
230                     EnqueueOneInterfaceMode );
231         END_SPREFS_CAT;
232
233         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
234
235             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
236             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
237             CONFIG_GENERIC( "freetype-font", String, NULL, font ); /* FIXME -> use file instead of string */
238             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
239             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
240                             fontSize );
241             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
242
243         END_SPREFS_CAT;
244
245         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
246         END_SPREFS_CAT;
247         }
248
249     panel_layout->addWidget(panel_label);
250     panel_layout->addWidget(title_line);
251     panel_layout->addWidget( panel );
252     panel_layout->addStretch( 2 );
253
254     this->setLayout(panel_layout);
255 }
256
257 void SPrefsPanel::apply()
258 {
259     QList<ConfigControl *>::Iterator i;
260     for( i = controls.begin() ; i != controls.end() ; i++ )
261     {
262         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
263         c->doApply( p_intf );
264     }
265 }
266
267 void SPrefsPanel::clean()
268 {}