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