]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Implement basic panel change
[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/audio.xpm"
36 #include "pixmaps/video.xpm"
37 #include "ui/sprefs_trivial.h"
38
39 #define ITEM_HEIGHT 25
40
41 /*********************************************************************
42  * The List of categories
43  *********************************************************************/
44 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
45                                   QListWidget( _parent ), p_intf( _p_intf )
46 {
47     setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
48     setAlternatingRowColors( true );
49
50 #ifndef WIN32
51     // Fixme - A bit UGLY
52     QFont f = font();
53     int pSize = f.pointSize();
54     if( pSize > 0 )
55         f.setPointSize( pSize + 1 );
56     else
57         f.setPixelSize( f.pixelSize() + 1 );
58     setFont( f );
59 #endif
60
61     addItem( "Very trivial" );
62     item(0)->setIcon( QIcon( QPixmap( audio_xpm ) ) );
63     item(0)->setData( Qt::UserRole, qVariantFromValue( 0 ) );
64     addItem( "Video" );
65     item(1)->setIcon( QIcon( QPixmap( video_xpm ) ) );
66     item(1)->setData( Qt::UserRole, qVariantFromValue( 1 ) );
67 }
68
69 void SPrefsCatList::ApplyAll()
70 {
71     DoAll( false );
72 }
73
74 void SPrefsCatList::CleanAll()
75 {
76     DoAll( true );
77 }
78
79 /// \todo When cleaning, we should remove the panel ?
80 void SPrefsCatList::DoAll( bool doclean )
81 {
82     /* Todo */
83 }
84
85 /*********************************************************************
86  * The Panels
87  *********************************************************************/
88 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
89                           int number ) : QWidget( _parent ), p_intf( _p_intf )
90 {
91     if( number == 0 )
92     {
93         Ui::SPrefsTrivial ui;
94         ui.setupUi( this );
95         module_config_t *p_config = config_FindConfig( VLC_OBJECT(p_intf),
96                                                         "memcpy" );
97         ConfigControl *control = new ModuleConfigControl( VLC_OBJECT(p_intf),
98                         p_config, ui.memcpyLabel, ui.memcpyCombo, false );
99         controls.append( control );
100     }
101     else
102     {
103         int *p = NULL;
104         fprintf( stderr, "Ha ha ca te fait bien la bite\n" );
105         *p=42;
106     }
107 }
108
109 void SPrefsPanel::Apply()
110 {
111     /* todo: factorize with PrefsPanel  */
112     QList<ConfigControl *>::Iterator i;
113     for( i = controls.begin() ; i != controls.end() ; i++ )
114     {
115         VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
116         if( !vicc )
117         {
118             VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
119             if( !vfcc)
120             {
121                 VStringConfigControl *vscc =
122                                qobject_cast<VStringConfigControl *>(*i);
123                 assert( vscc );
124                 config_PutPsz( p_intf, vscc->getName().toAscii().data(),
125                                        vscc->getValue().toAscii().data() );
126                 continue;
127             }
128             config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
129                                      vfcc->getValue() );
130             continue;
131         }
132         config_PutInt( p_intf, vicc->getName().toAscii().data(),
133                                vicc->getValue() );
134     }
135 }
136
137 void SPrefsPanel::Clean()
138 {}