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