Logo Search packages:      
Sourcecode: bangarang version File versions  Download package

void MediaItemModel::loadSources ( const QList< MediaItem > &  mediaList  ) 

Loads playable MediaItems into the model.

Parameters:
mediaList mediaList containing MediaItems to load. If mediaList contains "Category" type MediaItems then the playable MediaItems associated with that category (as specified by the lri in MediaItem.url) will be loaded. If the mediaList contains playable MediaItems (type = "Audio" or "Video") then they will be directly loaded into the model.

Definition at line 254 of file mediaitemmodel.cpp.

References ListEngineFactory::availableListEngine(), MediaListProperties::engine(), ListEngineFactory::engineExists(), MediaListProperties::engineFilter(), ListEngineFactory::generateRequestSignature(), MediaListCache::isInCache(), loadMediaItem(), MediaListProperties::lri, mediaListChanged(), ListEngine::mediaListProperties(), mediaListProperties(), MediaListProperties::name, ListEngine::setFilterForSources(), ListEngine::setMediaListProperties(), ListEngine::setRequestSignature(), and ListEngine::setSubRequestSignature().

Referenced by Playlist::playMediaList(), and reload().

{

    if (mediaList.count() == 0) {
        return;
    }
    
    setLoadingState(true);
    
    //Load data only for media sources
    m_subRequestMediaLists.clear();
    m_subRequestSignatures.clear();
    m_subRequestsDone = 0;
    bool onlySources = true;
    QList<MediaItem> categories;
    m_requestSignature = m_listEngineFactory->generateRequestSignature();
    for (int i = 0; i < mediaList.count(); ++i) {
        if ((mediaList.at(i).type == "Audio") || (mediaList.at(i).type == "Video") || (mediaList.at(i).type == "Image")){
            setLoadingState(false);
            if (!mediaList.at(i).url.isEmpty()) { //url of sources can't be empty
                loadMediaItem(mediaList.at(i));
            }
        } else if (mediaList.at(i).type == "Category") {
            onlySources = false;
            categories.append(mediaList.at(i));
            if (mediaList.count() == 1) {
                MediaListProperties mediaListProperties;
                mediaListProperties.lri =  mediaList.at(i).url;
                mediaListProperties.name = mediaList.at(i).title;
                
                // - Get the lri for loading sources using this category item
                ListEngine * listEngine = m_listEngineFactory->availableListEngine(m_mediaListProperties.engine());
                listEngine->setMediaListProperties(m_mediaListProperties);
                listEngine->setFilterForSources(m_mediaListProperties.engineFilter());
                QString loadSourcesLri = listEngine->mediaListProperties().lri;
                mediaListProperties.lri = loadSourcesLri;
                
                //Just directly load the sources since it's one category
                m_mediaListProperties = mediaListProperties;
            } else {
                //Generate signatures and media list holders for each subrequest
                //This must be complete for all categories before launching subrequests
                //to ensure full order of subrequests are available when results are returned
                MediaListProperties mediaListProperties;
                mediaListProperties.lri = mediaList.at(i).url;
                mediaListProperties.name = mediaList.at(i).title;
                if (m_listEngineFactory->engineExists(mediaListProperties.engine())) {
                    QString subRequestSignature = m_listEngineFactory->generateRequestSignature();
                    m_subRequestSignatures.append(subRequestSignature);
                    QList<MediaItem> emptyList;
                    m_subRequestMediaLists.append(emptyList);
                }
            }
        } else {
            setLoadingState(false);
        }
    }
    if (onlySources) {
        if (rowCount() == 0) {
            showNoResultsMessage();
        }
        emit mediaListChanged();
    } else {
        //Launch load requests
        for (int i = 0; i < categories.count(); ++i) {
            MediaListProperties mediaListProperties;
            mediaListProperties.lri = categories.at(i).url;
            mediaListProperties.name = categories.at(i).title;
            if (m_listEngineFactory->engineExists(mediaListProperties.engine())) {
                
                ListEngine * listEngine = m_listEngineFactory->availableListEngine(mediaListProperties.engine());
                listEngine->setMediaListProperties(mediaListProperties);
                listEngine->setFilterForSources(mediaListProperties.engineFilter());
                QString loadSourcesLri = listEngine->mediaListProperties().lri;
                
                if (m_mediaListCache->isInCache(loadSourcesLri)) {
                    // Load data from from the cache
                    listEngine = m_listEngineFactory->availableListEngine("cache://");
                    MediaListProperties cacheListProperties;
                    cacheListProperties.lri = QString("cache://dummyarg?%1").arg(loadSourcesLri);
                    m_requestSignature = m_listEngineFactory->generateRequestSignature();
                    listEngine->setRequestSignature(m_requestSignature);
                    if (mediaList.count() > 1) {
                        listEngine->setSubRequestSignature(m_subRequestSignatures.at(i));
                    }
                    listEngine->setMediaListProperties(cacheListProperties);
                    listEngine->start();
                    
                } else {
                    if (m_lrisLoading.indexOf(loadSourcesLri) == -1) {
                        // Since this lri is not currently being loaded by any list engine
                        // go ahead and start a new load
                        listEngine->setRequestSignature(m_requestSignature);
                        if (mediaList.count() > 1) {
                            listEngine->setSubRequestSignature(m_subRequestSignatures.at(i));
                        }
                        m_lriStartTimes.insert(loadSourcesLri, QTime::currentTime());
                        m_lrisLoading.append(loadSourcesLri);
                        listEngine->start();
                        kDebug()<< "started load for " << loadSourcesLri;
                    } else {
                        kDebug()<< "waiting for " << mediaListProperties.lri;
                    }
                }
            }
        }
    }
    
    m_loadSources = true;
    m_mediaListForLoadSources = mediaList;
}


Generated by  Doxygen 1.6.0   Back to index