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

x11_factory.cpp

00001 /*****************************************************************************
00002  * x11_factory.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: x11_factory.cpp 12207 2005-08-15 15:54:32Z 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 #ifdef X11_SKINS
00026 
00027 #include <unistd.h>
00028 #include <dirent.h>
00029 #include <sys/stat.h>
00030 #include <X11/Xlib.h>
00031 
00032 #include "x11_factory.hpp"
00033 #include "x11_display.hpp"
00034 #include "x11_graphics.hpp"
00035 #include "x11_loop.hpp"
00036 #include "x11_timer.hpp"
00037 #include "x11_window.hpp"
00038 #include "x11_tooltip.hpp"
00039 
00040 
00041 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
00042     m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
00043 {
00044     // see init()
00045 }
00046 
00047 
00048 X11Factory::~X11Factory()
00049 {
00050     delete m_pTimerLoop;
00051     delete m_pDisplay;
00052 }
00053 
00054 
00055 bool X11Factory::init()
00056 {
00057     // Create the X11 display
00058     m_pDisplay = new X11Display( getIntf() );
00059 
00060     // Get the display
00061     Display *pDisplay = m_pDisplay->getDisplay();
00062     if( pDisplay == NULL )
00063     {
00064         // Initialization failed
00065         return false;
00066     }
00067 
00068     // Create the timer loop
00069     m_pTimerLoop = new X11TimerLoop( getIntf(),
00070                                      ConnectionNumber( pDisplay ) );
00071 
00072     // Initialize the resource path
00073     m_resourcePath.push_back( (string)getIntf()->p_vlc->psz_homedir +
00074         m_dirSep + CONFIG_DIR + "/skins2" );
00075     m_resourcePath.push_back( (string)"share/skins2" );
00076     m_resourcePath.push_back( (string)DATA_PATH + "/skins2" );
00077 
00078     return true;
00079 }
00080 
00081 
00082 OSGraphics *X11Factory::createOSGraphics( int width, int height )
00083 {
00084     return new X11Graphics( getIntf(), *m_pDisplay, width, height );
00085 }
00086 
00087 
00088 OSLoop *X11Factory::getOSLoop()
00089 {
00090     return X11Loop::instance( getIntf(), *m_pDisplay );
00091 }
00092 
00093 
00094 void X11Factory::destroyOSLoop()
00095 {
00096     X11Loop::destroy( getIntf() );
00097 }
00098 
00099 void X11Factory::minimize()
00100 {
00101     XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
00102                     DefaultScreen( m_pDisplay->getDisplay() ) );
00103 }
00104 
00105 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
00106 {
00107     return new X11Timer( getIntf(), rCmd );
00108 }
00109 
00110 
00111 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
00112                                       bool playOnDrop, OSWindow *pParent )
00113 {
00114     return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
00115                           playOnDrop, (X11Window*)pParent );
00116 }
00117 
00118 
00119 OSTooltip *X11Factory::createOSTooltip()
00120 {
00121     return new X11Tooltip( getIntf(), *m_pDisplay );
00122 }
00123 
00124 
00125 int X11Factory::getScreenWidth() const
00126 {
00127     Display *pDisplay = m_pDisplay->getDisplay();
00128     int screen = DefaultScreen( pDisplay );
00129     return DisplayWidth( pDisplay, screen );
00130 }
00131 
00132 
00133 int X11Factory::getScreenHeight() const
00134 {
00135     Display *pDisplay = m_pDisplay->getDisplay();
00136     int screen = DefaultScreen( pDisplay );
00137     return DisplayHeight( pDisplay, screen );
00138 }
00139 
00140 
00141 Rect X11Factory::getWorkArea() const
00142 {
00143     // XXX
00144     return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
00145 }
00146 
00147 
00148 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
00149 {
00150     Window rootReturn, childReturn;
00151     int winx, winy;
00152     unsigned int xmask;
00153 
00154     Display *pDisplay = m_pDisplay->getDisplay();
00155     Window root = DefaultRootWindow( pDisplay );
00156     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
00157                    &rXPos, &rYPos, &winx, &winy, &xmask );
00158 }
00159 
00160 
00161 void X11Factory::rmDir( const string &rPath )
00162 {
00163     struct dirent *file;
00164     DIR *dir;
00165 
00166     dir = opendir( rPath.c_str() );
00167     if( !dir ) return;
00168 
00169     // Parse the directory and remove everything it contains
00170     while( (file = readdir( dir )) )
00171     {
00172         struct stat statbuf;
00173         string filename = file->d_name;
00174 
00175         // Skip "." and ".."
00176         if( filename == "." || filename == ".." )
00177         {
00178             continue;
00179         }
00180 
00181         filename = rPath + "/" + filename;
00182 
00183         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
00184         {
00185             rmDir( filename );
00186         }
00187         else
00188         {
00189             unlink( filename.c_str() );
00190         }
00191     }
00192 
00193     // Close the directory
00194     closedir( dir );
00195 
00196     // And delete it
00197     rmdir( rPath.c_str() );
00198 }
00199 
00200 
00201 #endif

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