Ejemplo n.º 1
0
string ThemeLoader::fixDirSeparators( const string &rPath )
{
    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    const string &sep = pOsFactory->getDirSeparator();
    string::size_type p = rPath.find( "/", 0 );
    string newPath = rPath;
    while( p != string::npos )
    {
        newPath = newPath.replace( p, 1, sep );
        p = newPath.find( "/", p + 1 );
    }
    return newPath;
}
Ejemplo n.º 2
0
void XMLParser::LoadCatalog()
{
    // Get the resource path and look for the DTD
    OSFactory *pOSFactory = OSFactory::instance( getIntf() );
    const list<string> &resPath = pOSFactory->getResourcePath();
    const string &sep = pOSFactory->getDirSeparator();
    list<string>::const_iterator it;

#ifdef HAVE_SYS_STAT_H
    struct stat statBuf;

    // Try to load the catalog first (needed at least on win32 where
    // we don't have a default catalog)
    for( it = resPath.begin(); it != resPath.end(); ++it )
    {
        string catalog_path = (*it) + sep + "skin.catalog";
        if( !stat( catalog_path.c_str(), &statBuf ) )
        {
            msg_Dbg( getIntf(), "Using catalog %s", catalog_path.c_str() );
            xml_CatalogLoad( m_pXML, catalog_path.c_str() );
            break;
        }
    }
    if( it == resPath.end() )
    {
        // Ok, try the default one
        xml_CatalogLoad( m_pXML, NULL );
    }

    for( it = resPath.begin(); it != resPath.end(); ++it )
    {
        string path = (*it) + sep + "skin.dtd";
        if( !stat( path.c_str(), &statBuf ) )
        {
            // DTD found
            msg_Dbg( getIntf(), "using DTD %s", path.c_str() );

            // Add an entry in the default catalog
            xml_CatalogAdd( m_pXML, "public",
                            "-//VideoLAN//DTD VLC Skins V"
                            SKINS_DTD_VERSION "//EN", path.c_str() );
            break;
        }
    }
    if( it == resPath.end() )
    {
        msg_Err( getIntf(), "cannot find the skins DTD");
    }
#endif
}
Ejemplo n.º 3
0
const string Stream::getAsStringName() const
{
    string fullName = getAsStringFullName();

    // XXX: This should be done in VLC core, not here...
    // Remove path information if any
    OSFactory *pFactory = OSFactory::instance( getIntf() );
    string::size_type pos = fullName.rfind( pFactory->getDirSeparator() );
    if( pos != string::npos )
    {
        fullName = fullName.substr( pos + 1, fullName.size() - pos + 1 );
    }

    return fullName;
}
Ejemplo n.º 4
0
string ThemeLoader::getFilePath( const string &rFullPath )
{
    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    const string &sep = pOsFactory->getDirSeparator();
    // Find the last separator ('/' or '\')
    string::size_type p = rFullPath.rfind( sep, rFullPath.size() );
    string basePath;
    if( p != string::npos )
    {
        if( p < rFullPath.size() - 1)
        {
            basePath = rFullPath.substr( 0, p );
        }
        else
        {
            basePath = rFullPath;
        }
    }
    return basePath;
}
Ejemplo n.º 5
0
void CmdUpdateItem::execute()
{
    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
    if( pPlaylist == NULL )
        return;

    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
    if( !p_input )
        return;

    // Get playlist item information
    input_item_t *pItem = input_GetItem( p_input );

    char *pszName = input_item_GetName( pItem );
    char *pszUri = input_item_GetURI( pItem );

    string name = pszName;
    // XXX: This should be done in VLC core, not here...
    // Remove path information if any
    OSFactory *pFactory = OSFactory::instance( getIntf() );
    string::size_type pos = name.rfind( pFactory->getDirSeparator() );
    if( pos != string::npos )
    {
        name = name.substr( pos + 1, name.size() - pos + 1 );
    }
    UString srcName( getIntf(), name.c_str() );
    UString srcURI( getIntf(), pszUri );

    free( pszName );
    free( pszUri );

    // Create commands to update the stream variables
    CmdSetText *pCmd1 = new CmdSetText( getIntf(), m_rStreamName, srcName );
    CmdSetText *pCmd2 = new CmdSetText( getIntf(), m_rStreamURI, srcURI );
    // Push the commands in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
    pQueue->push( CmdGenericPtr( pCmd1 ), false );
    pQueue->push( CmdGenericPtr( pCmd2 ), false );
    vlc_object_release( p_input );
}
Ejemplo n.º 6
0
bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir,
                                    bool isWsz )
{
    // Read info for the current file
    char filenameInZip[256];
    unz_file_info fileInfo;
    if( unzGetCurrentFileInfo( file, &fileInfo, filenameInZip,
                               sizeof( filenameInZip), NULL, 0, NULL, 0 )
        != UNZ_OK )
    {
        return false;
    }

    // Convert the file name to lower case, because some winamp skins
    // use the wrong case...
    if( isWsz )
        for( size_t i = 0; i < strlen( filenameInZip ); i++ )
            filenameInZip[i] = tolower( filenameInZip[i] );

    // Allocate the buffer
    void *pBuffer = malloc( ZIP_BUFFER_SIZE );
    if( !pBuffer )
        return false;

    // Get the path of the file
    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    string fullPath = rootDir
        + pOsFactory->getDirSeparator()
        + fixDirSeparators( filenameInZip );
    string basePath = getFilePath( fullPath );

    // Extract the file if is not a directory
    if( basePath != fullPath )
    {
        if( unzOpenCurrentFile( file ) )
        {
            free( pBuffer );
            return false;
        }
        makedir( basePath.c_str() );
        FILE *fout = fopen( fullPath.c_str(), "wb" );
        if( fout == NULL )
        {
            msg_Err( getIntf(), "error opening %s", fullPath.c_str() );
            free( pBuffer );
            return false;
        }

        // Extract the current file
        int n;
        do
        {
            n = unzReadCurrentFile( file, pBuffer, ZIP_BUFFER_SIZE );
            if( n < 0 )
            {
                msg_Err( getIntf(), "error while reading zip file" );
                free( pBuffer );
                return false;
            }
            else if( n > 0 )
            {
                if( fwrite( pBuffer, n , 1, fout) != 1 )
                {
                    msg_Err( getIntf(), "error while writing %s",
                             fullPath.c_str() );
                    free( pBuffer );
                    return false;
                }
            }
        } while( n > 0 );

        fclose(fout);

        if( unzCloseCurrentFile( file ) != UNZ_OK )
        {
            free( pBuffer );
            return false;
        }
    }

    free( pBuffer );
    return true;
}
Ejemplo n.º 7
0
void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
{
#define RequireAttr( attr, name, a ) \
    if( MissingAttr( attr, name, a ) ) return;

    if( rName == "Include" )
    {
        RequireAttr( attr, rName, "file" );

        OSFactory *pFactory = OSFactory::instance( getIntf() );
        string fullPath = m_path + pFactory->getDirSeparator() + attr["file"];
        msg_Dbg( getIntf(), "opening included XML file: %s", fullPath.c_str() );
        SkinParser subParser( getIntf(), fullPath.c_str(), m_path, m_pData );
        subParser.parse();
    }

    else if( rName == "IniFile" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "file" );

        const BuilderData::IniFile iniFile( uniqueId( attr["id"] ),
                attr["file"] );
        m_pData->m_listIniFile.push_back( iniFile );
    }

    else if( rName == "Anchor" )
    {
        RequireAttr( attr, rName, "priority" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "points", "(0,0)" );
        DefaultAttr( attr, "range", "10" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        const BuilderData::Anchor anchor( x + m_xOffset,
                y + m_yOffset, attr["lefttop"],
                atoi( attr["range"] ), atoi( attr["priority"] ),
                attr["points"], m_curLayoutId );
        m_pData->m_listAnchor.push_back( anchor );
    }

    else if( rName == "Bitmap" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "file" );
        RequireAttr( attr, rName, "alphacolor" );
        DefaultAttr( attr, "nbframes", "1" );
        DefaultAttr( attr, "fps", "4" );
        DefaultAttr( attr, "loop", "0" );

        m_curBitmapId = uniqueId( attr["id"] );
        const BuilderData::Bitmap bitmap( m_curBitmapId,
                attr["file"], convertColor( attr["alphacolor"] ),
                atoi( attr["nbframes"] ), atoi( attr["fps"] ),
                atoi( attr["loop"] ) );
        m_pData->m_listBitmap.push_back( bitmap );
    }

    else if( rName == "SubBitmap" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "x" );
        RequireAttr( attr, rName, "y" );
        RequireAttr( attr, rName, "width" );
        RequireAttr( attr, rName, "height" );
        DefaultAttr( attr, "nbframes", "1" );
        DefaultAttr( attr, "fps", "4" );
        DefaultAttr( attr, "loop", "0" );

        const BuilderData::SubBitmap bitmap( uniqueId( attr["id"] ),
                m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ),
                atoi( attr["width"] ), atoi( attr["height"] ),
                atoi( attr["nbframes"] ), atoi( attr["fps"] ),
                atoi( attr["loop"] ) );
        m_pData->m_listSubBitmap.push_back( bitmap );
    }

    else if( rName == "BitmapFont" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "file" );
        DefaultAttr( attr, "type", "digits" );

        const BuilderData::BitmapFont font( uniqueId( attr["id"] ),
                attr["file"], attr["type"] );
        m_pData->m_listBitmapFont.push_back( font );
    }

    else if( rName == "PopupMenu" )
    {
        RequireAttr( attr, rName, "id" );

        m_popupPosList.push_back(0);
        m_curPopupId = uniqueId( attr["id"] );
        const BuilderData::PopupMenu popup( m_curPopupId );
        m_pData->m_listPopupMenu.push_back( popup );
    }

    else if( rName == "MenuItem" )
    {
        RequireAttr( attr, rName, "label" );
        DefaultAttr( attr, "action", "none" );

        const BuilderData::MenuItem item( attr["label"], attr["action"],
                                          m_popupPosList.back(),
                                          m_curPopupId );
        m_pData->m_listMenuItem.push_back( item );
        m_popupPosList.back()++;
    }

    else if( rName == "MenuSeparator" )
    {
        const BuilderData::MenuSeparator sep( m_popupPosList.back(),
                                              m_curPopupId );
        m_pData->m_listMenuSeparator.push_back( sep );
        m_popupPosList.back()++;
    }

    else if( rName == "Button" )
    {
        RequireAttr( attr, rName, "up" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "down", "none" );
        DefaultAttr( attr, "over", "none" );
        DefaultAttr( attr, "action", "none" );
        DefaultAttr( attr, "tooltiptext", "" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        const BuilderData::Button button( uniqueId( attr["id"] ),
                x + m_xOffset, y + m_yOffset,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ), attr["visible"],
                attr["up"], attr["down"], attr["over"], attr["action"],
                attr["tooltiptext"], attr["help"],
                m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listButton.push_back( button );
    }

    else if( rName == "Checkbox" )
    {
        RequireAttr( attr, rName, "up1" );
        RequireAttr( attr, rName, "up2" );
        RequireAttr( attr, rName, "state" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "down1", "none" );
        DefaultAttr( attr, "over1", "none" );
        DefaultAttr( attr, "down2", "none" );
        DefaultAttr( attr, "over2", "none" );
        DefaultAttr( attr, "action1", "none" );
        DefaultAttr( attr, "action2", "none" );
        DefaultAttr( attr, "tooltiptext1", "" );
        DefaultAttr( attr, "tooltiptext2", "" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
                x + m_xOffset, y + m_yOffset,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ), attr["visible"],
                attr["up1"], attr["down1"], attr["over1"],
                attr["up2"], attr["down2"], attr["over2"], attr["state"],
                attr["action1"], attr["action2"], attr["tooltiptext1"],
                attr["tooltiptext2"], attr["help"], m_curLayer, m_curWindowId,
                m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listCheckbox.push_back( checkbox );
    }

    else if( rName == "Font" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "file" );
        DefaultAttr( attr, "size", "12" );

        const BuilderData::Font fontData( uniqueId( attr["id"] ),
                attr["file"], atoi( attr["size"] ) );
        m_pData->m_listFont.push_back( fontData );
    }

    else if( rName == "Group" )
    {
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );

        m_xOffset += atoi( attr["x"] );
        m_yOffset += atoi( attr["y"] );
        m_xOffsetList.push_back( atoi( attr["x"] ) );
        m_yOffsetList.push_back( atoi( attr["y"] ) );
    }

    else if( rName == "Image" )
    {
        RequireAttr( attr, rName, "image" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "width", "-1" );
        DefaultAttr( attr, "height", "-1" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "action", "none" );
        DefaultAttr( attr, "action2", "none" );
        DefaultAttr( attr, "resize", "mosaic" );
        DefaultAttr( attr, "help", "" );
        DefaultAttr( attr, "art", "false" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        const BuilderData::Image imageData( uniqueId( attr["id"] ),
                x + m_xOffset, y + m_yOffset, width, height,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ), attr["visible"],
                attr["image"], attr["action"], attr["action2"], attr["resize"],
                attr["help"], convertBoolean( attr["art"] ),
                m_curLayer, m_curWindowId, m_curLayoutId,
                m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listImage.push_back( imageData );
    }

    else if( rName == "Layout" )
    {
        RequireAttr( attr, rName, "width" );
        RequireAttr( attr, rName, "height" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "minwidth", "-1" );
        DefaultAttr( attr, "maxwidth", "-1" );
        DefaultAttr( attr, "minheight", "-1" );
        DefaultAttr( attr, "maxheight", "-1" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, true );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );

        m_curLayoutId = uniqueId( attr["id"] );
        const BuilderData::Layout layout( m_curLayoutId,
                width, height,
                getDimension( attr["minwidth"], refWidth ),
                getDimension( attr["maxwidth"], refWidth ),
                getDimension( attr["minheight"], refHeight ),
                getDimension( attr["maxheight"], refHeight ),
                m_curWindowId );

        updateWindowPos( width, height );
        m_pData->m_listLayout.push_back( layout );
        m_curLayer = 0;
    }

    else if( rName == "Panel" )
    {
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        RequireAttr( attr, rName, "width" );
        RequireAttr( attr, rName, "height" );
        DefaultAttr( attr, "position", "-1" );
        DefaultAttr( attr, "xoffset", "0" );
        DefaultAttr( attr, "yoffset", "0" );
        DefaultAttr( attr, "xmargin", "0" );
        DefaultAttr( attr, "ymargin", "0" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        convertPosition( attr["position"],
                         attr["xoffset"], attr["yoffset"],
                         attr["xmargin"], attr["ymargin"],
                         width, height, refWidth, refHeight, &x, &y );

        string panelId = uniqueId( "none" );
        const BuilderData::Panel panel( panelId,
                x + m_xOffset, y + m_yOffset,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ),
                width, height,
                m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listPanel.push_back( panel );
        // Add the panel to the stack
        m_panelStack.push_back( panelId );
    }

    else if( rName == "Playlist" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "font" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "flat", "true" ); // Only difference here
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "width", "0" );
        DefaultAttr( attr, "height", "0" );
        DefaultAttr( attr, "position", "-1" );
        DefaultAttr( attr, "xoffset", "0" );
        DefaultAttr( attr, "yoffset", "0" );
        DefaultAttr( attr, "xmargin", "0" );
        DefaultAttr( attr, "ymargin", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "bgimage", "none" );
        DefaultAttr( attr, "itemimage", "none" );
        DefaultAttr( attr, "openimage", "none" );
        DefaultAttr( attr, "closedimage", "none" );
        DefaultAttr( attr, "fgcolor", "#000000" );
        DefaultAttr( attr, "playcolor", "#FF0000" );
        DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
        DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
        DefaultAttr( attr, "selcolor", "#0000FF" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        convertPosition( attr["position"],
                         attr["xoffset"], attr["yoffset"],
                         attr["xmargin"], attr["ymargin"],
                         width, height, refWidth, refHeight, &x, &y );

        m_curTreeId = uniqueId( attr["id"] );
        const BuilderData::Tree treeData( m_curTreeId,
                x + m_xOffset, y + m_yOffset, attr["visible"],
                attr["flat"],
                width, height,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ),
                attr["font"], "playtree",
                attr["bgimage"], attr["itemimage"],
                attr["openimage"], attr["closedimage"],
                attr["fgcolor"],
                attr["playcolor"],
                attr["bgcolor1"],
                attr["bgcolor2"],
                attr["selcolor"], attr["help"],
                m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listTree.push_back( treeData );
    }
    else if( rName == "Playtree" )
    {
        RequireAttr( attr, rName, "id" );
        RequireAttr( attr, rName, "font" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "flat", "false" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "width", "0" );
        DefaultAttr( attr, "height", "0" );
        DefaultAttr( attr, "position", "-1" );
        DefaultAttr( attr, "xoffset", "0" );
        DefaultAttr( attr, "yoffset", "0" );
        DefaultAttr( attr, "xmargin", "0" );
        DefaultAttr( attr, "ymargin", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "bgimage", "none" );
        DefaultAttr( attr, "itemimage", "none" );
        DefaultAttr( attr, "openimage", "none" );
        DefaultAttr( attr, "closedimage", "none" );
        DefaultAttr( attr, "fgcolor", "#000000" );
        DefaultAttr( attr, "playcolor", "#FF0000" );
        DefaultAttr( attr, "bgcolor1", "#FFFFFF" );
        DefaultAttr( attr, "bgcolor2", "#FFFFFF" );
        DefaultAttr( attr, "selcolor", "#0000FF" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        convertPosition( attr["position"],
                         attr["xoffset"], attr["yoffset"],
                         attr["xmargin"], attr["ymargin"],
                         width, height, refWidth, refHeight, &x, &y );

        m_curTreeId = uniqueId( attr["id"] );
        const BuilderData::Tree treeData( m_curTreeId,
                x + m_xOffset, y + m_yOffset, attr["visible"],
                attr["flat"],
                width, height,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ),
                attr["font"], "playtree",
                attr["bgimage"], attr["itemimage"],
                attr["openimage"], attr["closedimage"],
                attr["fgcolor"], attr["playcolor"],
                attr["bgcolor1"], attr["bgcolor2"],
                attr["selcolor"], attr["help"],
                m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listTree.push_back( treeData );
    }

    else if( rName == "RadialSlider" )
    {
        RequireAttr( attr, rName, "sequence" );
        RequireAttr( attr, rName, "nbimages" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "minangle", "0" );
        DefaultAttr( attr, "maxangle", "360" );
        DefaultAttr( attr, "value", "none" );
        DefaultAttr( attr, "tooltiptext", "" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
                attr["visible"],
                x + m_xOffset, y + m_yOffset,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ), attr["sequence"],
                atoi( attr["nbimages"] ), atof( attr["minangle"] ) * M_PI /180,
                atof( attr["maxangle"] ) * M_PI / 180, attr["value"],
                attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
                m_curLayoutId, m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listRadialSlider.push_back( radial );
    }

    else if( rName == "Slider" )
    {
        RequireAttr( attr, rName, "up" );
        RequireAttr( attr, rName, "points" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "width", "-1" );
        DefaultAttr( attr, "height", "-1" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "down", "none" );
        DefaultAttr( attr, "over", "none" );
        DefaultAttr( attr, "thickness", "10" );
        DefaultAttr( attr, "value", "none" );
        DefaultAttr( attr, "tooltiptext", "" );
        DefaultAttr( attr, "help", "" );

        string newValue = attr["value"];
        if( m_curTreeId != "" )
        {
            // Slider associated to a tree
            newValue = "playtree.slider";
        }

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        const BuilderData::Slider slider( uniqueId( attr["id"] ),
                attr["visible"], x + m_xOffset, y + m_yOffset,
                width, height, attr["lefttop"],
                attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
                attr["over"], attr["points"], atoi( attr["thickness"] ),
                newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
                attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
                m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listSlider.push_back( slider );
    }

    else if( rName == "SliderBackground" )
    {
        RequireAttr( attr, rName, "image" );
        DefaultAttr( attr, "nbhoriz", "1" );
        DefaultAttr( attr, "nbvert", "1" );
        DefaultAttr( attr, "padhoriz", "0" );
        DefaultAttr( attr, "padvert", "0" );

        // Retrieve the current slider data
        BuilderData::Slider &slider = m_pData->m_listSlider.back();

        slider.m_imageId = attr["image"];
        slider.m_nbHoriz = atoi( attr["nbhoriz"] );
        slider.m_nbVert = atoi( attr["nbvert"] );
        slider.m_padHoriz = atoi( attr["padhoriz"] );
        slider.m_padVert = atoi( attr["padvert"] );
    }

    else if( rName == "Text" )
    {
        RequireAttr( attr, rName, "font" );
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "text", "" );
        DefaultAttr( attr, "color", "#000000" );
        DefaultAttr( attr, "scrolling", "auto" );
        DefaultAttr( attr, "alignment", "left" );
        DefaultAttr( attr, "focus", "true" );
        DefaultAttr( attr, "width", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );

        const BuilderData::Text textData( uniqueId( attr["id"] ),
                x + m_xOffset, y + m_yOffset,
                attr["visible"], attr["font"],
                attr["text"],
                width,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ),
                convertColor( attr["color"] ),
                attr["scrolling"], attr["alignment"],
                attr["focus"], attr["help"],
                m_curLayer, m_curWindowId, m_curLayoutId,
                m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listText.push_back( textData );
    }

    else if( rName == "Theme" )
    {
        RequireAttr( attr, rName, "version" );
        DefaultAttr( attr, "tooltipfont", "defaultfont" );
        DefaultAttr( attr, "magnet", "15" );
        DefaultAttr( attr, "alpha", "255" );
        DefaultAttr( attr, "movealpha", "255" );

        // Check the version
        if( strcmp( attr["version"], SKINS_DTD_VERSION ) )
        {
            msg_Err( getIntf(), "bad theme version : %s (you need version %s)",
                     attr["version"], SKINS_DTD_VERSION );
            m_errors = true;
            return;
        }
        const BuilderData::Theme theme( attr["tooltipfont"],
                atoi( attr["magnet"] ),
                convertInRange( attr["alpha"], 1, 255, "alpha" ),
                convertInRange( attr["movealpha"], 1, 255, "movealpha" ) );
        m_pData->m_listTheme.push_back( theme );
    }

    else if( rName == "ThemeInfo" )
    {
        DefaultAttr( attr, "name", "" );
        DefaultAttr( attr, "author", "" );
        DefaultAttr( attr, "email", "" );
        DefaultAttr( attr, "website", "" );
        msg_Info( getIntf(), "skin: %s  author: %s", attr["name"],
                  attr["author"] );
    }

    else if( rName == "Video" )
    {
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "width", "0" );
        DefaultAttr( attr, "height", "0" );
        DefaultAttr( attr, "position", "-1" );
        DefaultAttr( attr, "xoffset", "0" );
        DefaultAttr( attr, "yoffset", "0" );
        DefaultAttr( attr, "xmargin", "0" );
        DefaultAttr( attr, "ymargin", "0" );
        DefaultAttr( attr, "lefttop", "lefttop" );
        DefaultAttr( attr, "rightbottom", "lefttop" );
        DefaultAttr( attr, "xkeepratio", "false" );
        DefaultAttr( attr, "ykeepratio", "false" );
        DefaultAttr( attr, "autoresize", "true" );
        DefaultAttr( attr, "help", "" );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, false );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        int width = getDimension( attr["width"], refWidth );
        int height = getDimension( attr["height"], refHeight );
        convertPosition( attr["position"],
                         attr["xoffset"], attr["yoffset"],
                         attr["xmargin"], attr["ymargin"],
                         width, height, refWidth, refHeight, &x, &y );

        const BuilderData::Video videoData( uniqueId( attr["id"] ),
                x + m_xOffset, y + m_yOffset, width, height,
                attr["lefttop"], attr["rightbottom"],
                convertBoolean( attr["xkeepratio"] ),
                convertBoolean( attr["ykeepratio"] ),
                attr["visible"], convertBoolean( attr["autoresize"] ),
                attr["help"], m_curLayer, m_curWindowId, m_curLayoutId,
                m_panelStack.back() );
        m_curLayer++;
        m_pData->m_listVideo.push_back( videoData );
    }

    else if( rName == "Window" )
    {
        DefaultAttr( attr, "id", "none" );
        DefaultAttr( attr, "visible", "true" );
        DefaultAttr( attr, "x", "0" );
        DefaultAttr( attr, "y", "0" );
        DefaultAttr( attr, "position", "-1" );
        DefaultAttr( attr, "xoffset", "0" );
        DefaultAttr( attr, "yoffset", "0" );
        DefaultAttr( attr, "xmargin", "0" );
        DefaultAttr( attr, "ymargin", "0" );
        DefaultAttr( attr, "dragdrop", "true" );
        DefaultAttr( attr, "playondrop", "true" );

        m_curWindowId = uniqueId( attr["id"] );

        int refWidth, refHeight;
        getRefDimensions( refWidth, refHeight, true );
        int x = getDimension( attr["x"], refWidth );
        int y = getDimension( attr["y"], refHeight );
        const BuilderData::Window window( m_curWindowId,
                x + m_xOffset, y + m_yOffset,
                attr["position"],
                attr["xoffset"], attr["yoffset"],
                attr["xmargin"], attr["ymargin"],
                convertBoolean( attr["visible"] ),
                convertBoolean( attr["dragdrop"] ),
                convertBoolean( attr["playondrop"] ) );
        m_pData->m_listWindow.push_back( window );
    }
#undef  RequireAttr
}
Ejemplo n.º 8
0
//---------------------------------------------------------------------------
// Run: main loop
//---------------------------------------------------------------------------
static void *Run( void * p_obj )
{
    int canc = vlc_savecancel();

    intf_thread_t *p_intf = (intf_thread_t *)p_obj;

    bool b_error = false;
    char *skin_last = NULL;
    ThemeLoader *pLoader = NULL;
    OSLoop *loop = NULL;

    vlc_mutex_lock( &p_intf->p_sys->init_lock );

    // Initialize singletons
    if( OSFactory::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot initialize OSFactory" );
        b_error = true;
        goto end;
    }
    if( AsyncQueue::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot initialize AsyncQueue" );
        b_error = true;
        goto end;
    }
    if( Interpreter::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot instanciate Interpreter" );
        b_error = true;
        goto end;
    }
    if( VarManager::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot instanciate VarManager" );
        b_error = true;
        goto end;
    }
    if( VlcProc::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot initialize VLCProc" );
        b_error = true;
        goto end;
    }
    if( VoutManager::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot instanciate VoutManager" );
        b_error = true;
        goto end;
    }
    if( ThemeRepository::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot instanciate ThemeRepository" );
        b_error = true;
        goto end;
    }
    if( Dialogs::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
        b_error = true;
        goto end;
    }

    // Load a theme
    skin_last = config_GetPsz( p_intf, "skins2-last" );
    pLoader = new ThemeLoader( p_intf );

    if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
    {
        // Get the resource path and try to load the default skin
        OSFactory *pOSFactory = OSFactory::instance( p_intf );
        const list<string> &resPath = pOSFactory->getResourcePath();
        const string &sep = pOSFactory->getDirSeparator();

        list<string>::const_iterator it;
        for( it = resPath.begin(); it != resPath.end(); it++ )
        {
            string path = (*it) + sep + "default.vlt";
            if( pLoader->load( path ) )
            {
                // Theme loaded successfully
                break;
            }
        }
        if( it == resPath.end() )
        {
            // Last chance: the user can select a new theme file
            if( Dialogs::instance( p_intf ) )
            {
                CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
                pQueue->push( CmdGenericPtr( pCmd ) );
            }
            else
            {
                // No dialogs provider, just quit...
                CmdQuit *pCmd = new CmdQuit( p_intf );
                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
                pQueue->push( CmdGenericPtr( pCmd ) );
                msg_Err( p_intf,
                         "cannot show the \"open skin\" dialog: exiting...");
            }
        }
    }

    delete pLoader;
    free( skin_last );

    // Get the instance of OSLoop
    loop = OSFactory::instance( p_intf )->getOSLoop();

    // Signal the main thread this thread is now ready
    p_intf->p_sys->b_ready = true;
    vlc_cond_signal( &p_intf->p_sys->init_wait );
    vlc_mutex_unlock( &p_intf->p_sys->init_lock );

    // Enter the main event loop
    loop->run();

    // Destroy OSLoop
    OSFactory::instance( p_intf )->destroyOSLoop();

    // save and delete the theme
    if( p_intf->p_sys->p_theme )
    {
        p_intf->p_sys->p_theme->saveConfig();

        delete p_intf->p_sys->p_theme;
        p_intf->p_sys->p_theme = NULL;

        msg_Dbg( p_intf, "current theme deleted" );
    }

    // save config file
    config_SaveConfigFile( p_intf, NULL );

end:
    // Destroy "singleton" objects
    Dialogs::destroy( p_intf );
    ThemeRepository::destroy( p_intf );
    VoutManager::destroy( p_intf );
    VlcProc::destroy( p_intf );
    VarManager::destroy( p_intf );
    Interpreter::destroy( p_intf );
    AsyncQueue::destroy( p_intf );
    OSFactory::destroy( p_intf );

    if( b_error )
    {
        p_intf->p_sys->b_ready = true;
        vlc_cond_signal( &p_intf->p_sys->init_wait );
        vlc_mutex_unlock( &p_intf->p_sys->init_lock );

        libvlc_Quit( p_intf->p_libvlc );
    }

    vlc_restorecancel(canc);
    return NULL;
}
Ejemplo n.º 9
0
//---------------------------------------------------------------------------
// Run: main loop
//---------------------------------------------------------------------------
static void Run( intf_thread_t *p_intf )
{
    // Load a theme
    ThemeLoader *pLoader = new ThemeLoader( p_intf );
    char *skin_last = config_GetPsz( p_intf, "skins2-last" );

    if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
    {
        // Get the resource path and try to load the default skin
        OSFactory *pOSFactory = OSFactory::instance( p_intf );
        const list<string> &resPath = pOSFactory->getResourcePath();
        const string &sep = pOSFactory->getDirSeparator();

        list<string>::const_iterator it;
        for( it = resPath.begin(); it != resPath.end(); it++ )
        {
            string path = (*it) + sep + "default.vlt";
            if( pLoader->load( path ) )
            {
                // Theme loaded successfully
                break;
            }
        }
        if( it == resPath.end() )
        {
            // Last chance: the user can select a new theme file
            if( Dialogs::instance( p_intf ) )
            {
                CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
                pQueue->push( CmdGenericPtr( pCmd ) );
            }
            else
            {
                // No dialogs provider, just quit...
                CmdQuit *pCmd = new CmdQuit( p_intf );
                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
                pQueue->push( CmdGenericPtr( pCmd ) );
                msg_Err( p_intf,
                         "Cannot show the \"open skin\" dialog: exiting...");
            }
        }
    }
    delete pLoader;

    if( skin_last )
    {
        free( skin_last );
    }

    // Get the instance of OSLoop
    OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();

    // Check if we need to start playing
    if( p_intf->b_play )
    {
        playlist_t *p_playlist =
            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                           FIND_ANYWHERE );
        if( p_playlist )
        {
            playlist_Play( p_playlist );
            vlc_object_release( p_playlist );
        }
    }

    // Enter the main event loop
    loop->run();

    // Delete the theme and save the configuration of the windows
    if( p_intf->p_sys->p_theme )
    {
        p_intf->p_sys->p_theme->saveConfig();
        delete p_intf->p_sys->p_theme;
        p_intf->p_sys->p_theme = NULL;
    }
}