Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

theme.cpp

00001 /*****************************************************************************
00002  * theme.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: theme.cpp 12912 2005-10-22 11:57:29Z asmax $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "theme.hpp"
00026 
00027 
00028 Theme::~Theme()
00029 {
00030     // Be sure things are destroyed in the right order (XXX check)
00031     m_layouts.clear();
00032     m_controls.clear();
00033     m_windows.clear();
00034     m_bitmaps.clear();
00035     m_fonts.clear();
00036     m_commands.clear();
00037     m_vars.clear();
00038     m_curves.clear();
00039 }
00040 
00041 
00042 void Theme::loadConfig()
00043 {
00044     msg_Dbg( getIntf(), "Loading theme configuration");
00045 
00046     // Get config from vlcrc file
00047     char *save = config_GetPsz( getIntf(), "skins2-config" );
00048     if( !save ) return;
00049 
00050     // Is there an existing config?
00051     if( !strcmp( save, "" ) )
00052     {
00053         // Show the windows
00054         m_windowManager.showAll( true );
00055         return;
00056     }
00057 
00058     // Initialization
00059     map<string, TopWindowPtr>::const_iterator it;
00060     int i = 0;
00061     int x, y, visible, scan;
00062 
00063     // Get config for each window
00064     for( it = m_windows.begin(); it != m_windows.end(); it++ )
00065     {
00066         TopWindow *pWin = (*it).second.get();
00067         // Get config
00068         scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &visible );
00069 
00070         // If config has the correct number of arguments
00071         if( scan > 2 )
00072         {
00073             m_windowManager.startMove( *pWin );
00074             m_windowManager.move( *pWin, x, y );
00075             m_windowManager.stopMove();
00076             if( visible )
00077             {
00078                 m_windowManager.show( *pWin );
00079             }
00080         }
00081 
00082         // Next window
00083         i++;
00084     }
00085     free( save );
00086 }
00087 
00088 
00089 void Theme::saveConfig()
00090 {
00091     msg_Dbg( getIntf(), "Saving theme configuration");
00092 
00093     // Initialize char where config is stored
00094     char *save  = new char[400];
00095     map<string, TopWindowPtr>::const_iterator it;
00096     int i = 0;
00097     int x, y;
00098 
00099     // Save config of every window
00100     for( it = m_windows.begin(); it != m_windows.end(); it++ )
00101     {
00102         TopWindow *pWin = (*it).second.get();
00103         // Print config
00104         x = pWin->getLeft();
00105         y = pWin->getTop();
00106         sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
00107             pWin->getVisibleVar().get() );
00108         i++;
00109     }
00110 
00111     // Save config to file
00112     config_PutPsz( getIntf(), "skins2-config", save );
00113 
00114     // Free memory
00115     delete[] save;
00116 }
00117 
00118 
00119 // Useful macro
00120 #define FIND_OBJECT( mapData, mapName ) \
00121     map<string, mapData>::const_iterator it; \
00122     it = mapName.find( id ); \
00123     if( it == mapName.end() ) \
00124     { \
00125         return NULL; \
00126     } \
00127     return (*it).second.get();
00128 
00129 GenericBitmap *Theme::getBitmapById( const string &id )
00130 {
00131     FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
00132 }
00133 
00134 GenericFont *Theme::getFontById( const string &id )
00135 {
00136     FIND_OBJECT( GenericFontPtr, m_fonts );
00137 }
00138 
00139 TopWindow *Theme::getWindowById( const string &id )
00140 {
00141     FIND_OBJECT( TopWindowPtr, m_windows );
00142 }
00143 
00144 GenericLayout *Theme::getLayoutById( const string &id )
00145 {
00146     FIND_OBJECT( GenericLayoutPtr, m_layouts );
00147 }
00148 
00149 CtrlGeneric *Theme::getControlById( const string &id )
00150 {
00151     FIND_OBJECT( CtrlGenericPtr, m_controls );
00152 }
00153 
00154 
00155 

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2