]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Bind simple prefs forms to corresponding simple prefs categories
[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 enum {
52     SPrefsVideo,
53     SPrefsAudio,
54     SPrefsInputAndCodecs,
55     SPrefsPlaylist,
56     SPrefsInterface,
57     SPrefsSubtitles,
58     SPrefsAdvanced
59 };
60
61 /*********************************************************************
62  * The List of categories
63  *********************************************************************/
64 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
65                                   QListWidget( _parent ), p_intf( _p_intf )
66 {
67     setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
68     setAlternatingRowColors( true );
69
70 #ifndef WIN32
71     // Fixme - A bit UGLY
72     QFont f = font();
73     int pSize = f.pointSize();
74     if( pSize > 0 )
75         f.setPointSize( pSize + 1 );
76     else
77         f.setPixelSize( f.pixelSize() + 1 );
78     setFont( f );
79 #endif
80
81 #define ADD_CATEGORY( id, label, icon )                             \
82     addItem( label );                                               \
83     item( id )->setIcon( QIcon( QPixmap( icon ) ) );                \
84     item( id )->setData( Qt::UserRole, qVariantFromValue( (int)id ) );
85
86     ADD_CATEGORY( SPrefsVideo, "Video", video_50x50_xpm );
87     ADD_CATEGORY( SPrefsAudio, "Audio", audio_50x50_xpm );
88     ADD_CATEGORY( SPrefsInputAndCodecs, "Input and Codecs",
89                   input_and_codecs_50x50_xpm );
90     ADD_CATEGORY( SPrefsPlaylist, "Playlist", playlist_50x50_xpm );
91     ADD_CATEGORY( SPrefsInterface, "Interface", interface_50x50_xpm );
92     ADD_CATEGORY( SPrefsSubtitles, "Subtitles", subtitles_50x50_xpm );
93     ADD_CATEGORY( SPrefsAdvanced, "Advanced", advanced_50x50_xpm );
94 }
95
96 void SPrefsCatList::ApplyAll()
97 {
98     DoAll( false );
99 }
100
101 void SPrefsCatList::CleanAll()
102 {
103     DoAll( true );
104 }
105
106 /// \todo When cleaning, we should remove the panel ?
107 void SPrefsCatList::DoAll( bool doclean )
108 {
109     /* Todo */
110 }
111
112 /*********************************************************************
113  * The Panels
114  *********************************************************************/
115 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
116                           int number ) : QWidget( _parent ), p_intf( _p_intf )
117 {
118     switch( number )
119     {
120         case SPrefsVideo:
121         {
122             Ui::SPrefsVideo ui;
123             ui.setupUi( this );
124             break;
125         }
126
127         case SPrefsAudio:
128         {
129             Ui::SPrefsAudio ui;
130             ui.setupUi( this );
131             break;
132         }
133
134         case SPrefsInputAndCodecs:
135         {
136             break;
137         }
138
139         case SPrefsPlaylist:
140         {
141             Ui::SPrefsPlaylist ui;
142             ui.setupUi( this );
143             break;
144         }
145
146         case SPrefsInterface:
147         {
148             break;
149         }
150
151         case SPrefsSubtitles:
152         {
153             Ui::SPrefsSubtitles ui;
154             ui.setupUi( this );
155             break;
156         }
157
158         case SPrefsAdvanced:
159         {
160             Ui::SPrefsTrivial ui;
161             ui.setupUi( this );
162             module_config_t *p_config =
163                             config_FindConfig( VLC_OBJECT(p_intf), "memcpy" );
164             ConfigControl *control =
165                             new ModuleConfigControl( VLC_OBJECT(p_intf),
166                             p_config, ui.memcpyLabel, ui.memcpyCombo, false );
167             controls.append( control );
168             break;
169         }
170     }
171 }
172
173 void SPrefsPanel::Apply()
174 {
175     /* todo: factorize with PrefsPanel  */
176     QList<ConfigControl *>::Iterator i;
177     for( i = controls.begin() ; i != controls.end() ; i++ )
178     {
179         VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
180         if( !vicc )
181         {
182             VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
183             if( !vfcc)
184             {
185                 VStringConfigControl *vscc =
186                                qobject_cast<VStringConfigControl *>(*i);
187                 assert( vscc );
188                 config_PutPsz( p_intf, vscc->getName().toAscii().data(),
189                                        vscc->getValue().toAscii().data() );
190                 continue;
191             }
192             config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
193                                      vfcc->getValue() );
194             continue;
195         }
196         config_PutInt( p_intf, vicc->getName().toAscii().data(),
197                                vicc->getValue() );
198     }
199 }
200
201 void SPrefsPanel::Clean()
202 {}