]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Begin simple prefs 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  *
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 "components/simple_preferences.hpp"
26 #include "components/preferences_widgets.hpp"
27 #include "qt4.hpp"
28 #include <vlc_config_cat.h>
29 #include <assert.h>
30 #include <QListWidget>
31 #include <QListWidgetItem>
32 #include <QString>
33 #include <QFont>
34
35 #include "pixmaps/advanced_50x50.xpm"
36 #include "pixmaps/audio_50x50.xpm"
37 #include "pixmaps/input_and_codecs_50x50.xpm"
38 #include "pixmaps/interface_50x50.xpm"
39 #include "pixmaps/playlist_50x50.xpm"
40 #include "pixmaps/subtitles_50x50.xpm"
41 #include "pixmaps/video_50x50.xpm"
42
43 #include "ui/sprefs_trivial.h"
44 #include "ui/sprefs_audio.h"
45 #include "ui/sprefs_video.h"
46 #include "ui/sprefs_subtitles.h"
47 #include "ui/sprefs_playlist.h"
48 #include "ui/sprefs_interface.h"
49
50 #define ITEM_HEIGHT 50
51
52 /*********************************************************************
53  * The List of categories
54  *********************************************************************/
55 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
56                                   QListWidget( _parent ), p_intf( _p_intf )
57 {
58     setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
59     setAlternatingRowColors( true );
60
61 #ifndef WIN32
62     // Fixme - A bit UGLY
63     QFont f = font();
64     int pSize = f.pointSize();
65     if( pSize > 0 )
66         f.setPointSize( pSize + 1 );
67     else
68         f.setPixelSize( f.pixelSize() + 1 );
69     setFont( f );
70 #endif
71
72 #define ADD_CATEGORY( id, label, icon )                             \
73     addItem( label );                                               \
74     item( id )->setIcon( QIcon( QPixmap( icon ) ) );                \
75     item( id )->setData( Qt::UserRole, qVariantFromValue( (int)id ) );
76
77     ADD_CATEGORY( SPrefsVideo, "Video", video_50x50_xpm );
78     ADD_CATEGORY( SPrefsAudio, "Audio", audio_50x50_xpm );
79     ADD_CATEGORY( SPrefsInputAndCodecs, "Input and Codecs",
80                   input_and_codecs_50x50_xpm );
81     ADD_CATEGORY( SPrefsPlaylist, "Playlist", playlist_50x50_xpm );
82     ADD_CATEGORY( SPrefsInterface, "Interface", interface_50x50_xpm );
83     ADD_CATEGORY( SPrefsSubtitles, "Subtitles", subtitles_50x50_xpm );
84     ADD_CATEGORY( SPrefsAdvanced, "Advanced", advanced_50x50_xpm );
85
86     setCurrentRow( SPrefsInterface );
87 }
88
89 void SPrefsCatList::ApplyAll()
90 {
91     DoAll( false );
92 }
93
94 void SPrefsCatList::CleanAll()
95 {
96     DoAll( true );
97 }
98
99 /// \todo When cleaning, we should remove the panel ?
100 void SPrefsCatList::DoAll( bool doclean )
101 {
102     /* Todo */
103 }
104
105 /*********************************************************************
106  * The Panels
107  *********************************************************************/
108 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
109                           int number ) : QWidget( _parent ), p_intf( _p_intf )
110 {
111     module_config_t *p_config;
112     ConfigControl *control;
113
114 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
115             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
116             if( p_config )                                                \
117             {                                                             \
118                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
119                            p_config, label, ui.qcontrol, false );         \
120                 controls.append( control );                               \
121             }
122
123 #define START_SPREFS_CAT( name )    \
124         case SPrefs ## name:        \
125         {                           \
126             Ui::SPrefs ## name ui;  \
127             ui.setupUi( this );
128
129 #define END_SPREFS_CAT      \
130             break;          \
131         }
132
133
134     switch( number )
135     {
136         START_SPREFS_CAT( Video );
137
138             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
139
140             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
141             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
142             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
143             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
144
145             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
146
147             CONFIG_GENERIC( "snapshot-path", String, NULL,
148             snapshotsDirectory ); /* FIXME -> use file instead of string */
149             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
150             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
151                             snapshotsSequentialNumbering );
152             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
153                             snapshotsFormat );
154
155         END_SPREFS_CAT;
156
157         START_SPREFS_CAT( Audio );
158
159             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
160
161         END_SPREFS_CAT;
162
163         case SPrefsInputAndCodecs: break;
164
165         START_SPREFS_CAT( Playlist );
166         END_SPREFS_CAT;
167
168         START_SPREFS_CAT( Interface );
169
170             CONFIG_GENERIC( "language", StringList, NULL, language );
171
172         END_SPREFS_CAT;
173
174         START_SPREFS_CAT( Subtitles );
175
176             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
177             CONFIG_GENERIC( "sub-language", String, NULL, preferedLanguage );
178             CONFIG_GENERIC( "freetype-font", String, NULL, font ); /* FIXME -> use file instead of string */
179             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
180             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
181                             fontSize );
182             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
183
184         END_SPREFS_CAT;
185
186         case SPrefsAdvanced: break;
187     }
188 }
189
190 void SPrefsPanel::Apply()
191 {
192     /* todo: factorize with PrefsPanel  */
193     QList<ConfigControl *>::Iterator i;
194     for( i = controls.begin() ; i != controls.end() ; i++ )
195     {
196         VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
197         if( !vicc )
198         {
199             VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
200             if( !vfcc)
201             {
202                 VStringConfigControl *vscc =
203                                qobject_cast<VStringConfigControl *>(*i);
204                 assert( vscc );
205                 config_PutPsz( p_intf, vscc->getName().toAscii().data(),
206                                        vscc->getValue().toAscii().data() );
207                 continue;
208             }
209             config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
210                                      vfcc->getValue() );
211             continue;
212         }
213         config_PutInt( p_intf, vicc->getName().toAscii().data(),
214                                vicc->getValue() );
215     }
216 }
217
218 void SPrefsPanel::Clean()
219 {}