本文整理汇总了C++中CFileItemList::Randomize方法的典型用法代码示例。如果您正苦于以下问题:C++ CFileItemList::Randomize方法的具体用法?C++ CFileItemList::Randomize怎么用?C++ CFileItemList::Randomize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFileItemList
的用法示例。
在下文中一共展示了CFileItemList::Randomize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddInitialSongs
bool CPartyModeManager::AddInitialSongs(vector<pair<int,long> > &songIDs)
{
int iPlaylist = PLAYLIST_MUSIC;
if (m_bIsVideo)
iPlaylist = PLAYLIST_VIDEO;
CPlayList& playlist = g_playlistPlayer.GetPlaylist(iPlaylist);
int iMissingSongs = QUEUE_DEPTH - playlist.size();
if (iMissingSongs > 0)
{
// generate iMissingSongs random ids from songIDs
if (iMissingSongs > (int)songIDs.size())
return false; // can't do it if we have less songs than we need
vector<pair<int,long> > chosenSongIDs;
GetRandomSelection(songIDs, iMissingSongs, chosenSongIDs);
CStdString sqlWhereMusic = "where songview.idsong in (";
CStdString sqlWhereVideo = "where musicvideo.idmvideo in (";
for (vector<pair<int,long> >::iterator it = chosenSongIDs.begin(); it != chosenSongIDs.end(); it++)
{
CStdString song;
song.Format("%i,", it->second);
if (it->first == 1)
sqlWhereMusic += song;
if (it->first == 2)
sqlWhereVideo += song;
}
// add songs to fill queue
CFileItemList items;
if (sqlWhereMusic.size() > 26)
{
sqlWhereMusic[sqlWhereMusic.size() - 1] = ')'; // replace the last comma with closing bracket
CMusicDatabase database;
database.Open();
database.GetSongsByWhere("", sqlWhereMusic, items);
}
if (sqlWhereVideo.size() > 30)
{
sqlWhereVideo[sqlWhereVideo.size() - 1] = ')'; // replace the last comma with closing bracket
CVideoDatabase database;
database.Open();
database.GetMusicVideosByWhere("videodb://3/2/", sqlWhereVideo, items);
}
m_history = chosenSongIDs;
items.Randomize(); //randomizing the initial list or they will be in database order
for (int i = 0; i < items.Size(); i++)
{
Add(items[i]);
// TODO: Allow "relaxed restrictions" later?
}
}
return true;
}
示例2: AddInitialSongs
bool CPartyModeManager::AddInitialSongs(std::vector< std::pair<int,int > > &songIDs)
{
int iPlaylist = m_bIsVideo ? PLAYLIST_VIDEO : PLAYLIST_MUSIC;
CPlayList& playlist = g_playlistPlayer.GetPlaylist(iPlaylist);
int iMissingSongs = QUEUE_DEPTH - playlist.size();
if (iMissingSongs > 0)
{
// generate iMissingSongs random ids from songIDs
if (iMissingSongs > (int)songIDs.size())
return false; // can't do it if we have less songs than we need
std::vector<std::pair<int,int> > chosenSongIDs;
GetRandomSelection(songIDs, iMissingSongs, chosenSongIDs);
std::string sqlWhereMusic = "songview.idSong IN (";
std::string sqlWhereVideo = "idMVideo IN (";
for (std::vector< std::pair<int,int> >::iterator it = chosenSongIDs.begin(); it != chosenSongIDs.end(); ++it)
{
std::string song = StringUtils::Format("%i,", it->second);
if (it->first == 1)
sqlWhereMusic += song;
if (it->first == 2)
sqlWhereVideo += song;
}
// add songs to fill queue
CFileItemList items;
if (sqlWhereMusic.size() > 26)
{
sqlWhereMusic[sqlWhereMusic.size() - 1] = ')'; // replace the last comma with closing bracket
CMusicDatabase database;
database.Open();
database.GetSongsByWhere("musicdb://songs/", sqlWhereMusic, items);
}
if (sqlWhereVideo.size() > 19)
{
sqlWhereVideo[sqlWhereVideo.size() - 1] = ')'; // replace the last comma with closing bracket
CVideoDatabase database;
database.Open();
database.GetMusicVideosByWhere("videodb://musicvideos/titles/", sqlWhereVideo, items);
}
m_history = chosenSongIDs;
items.Randomize(); //randomizing the initial list or they will be in database order
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr item(items[i]);
Add(item);
//! @todo Allow "relaxed restrictions" later?
}
}
return true;
}
示例3: ProcessFoldersAndArchives
void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
{
if (pItem->HasThumbnail())
return;
CTextureDatabase db;
db.Open();
if (pItem->IsCBR() || pItem->IsCBZ())
{
CStdString strTBN(URIUtils::ReplaceExtension(pItem->GetPath(),".tbn"));
if (CFile::Exists(strTBN))
{
db.SetTextureForPath(pItem->GetPath(), "thumb", strTBN);
CTextureCache::Get().BackgroundCacheImage(strTBN);
pItem->SetThumbnailImage(strTBN);
return;
}
}
if ((pItem->m_bIsFolder || pItem->IsCBR() || pItem->IsCBZ()) && !pItem->m_bIsShareOrDrive && !pItem->IsParentFolder())
{
// first check for a folder.jpg
CStdString thumb = "folder.jpg";
CStdString strPath = pItem->GetPath();
if (pItem->IsCBR())
{
URIUtils::CreateArchivePath(strPath,"rar",pItem->GetPath(),"");
thumb = "cover.jpg";
}
if (pItem->IsCBZ())
{
URIUtils::CreateArchivePath(strPath,"zip",pItem->GetPath(),"");
thumb = "cover.jpg";
}
if (pItem->IsMultiPath())
strPath = CMultiPathDirectory::GetFirstPath(pItem->GetPath());
thumb = URIUtils::AddFileToFolder(strPath, thumb);
if (CFile::Exists(thumb))
{
db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
CTextureCache::Get().BackgroundCacheImage(thumb);
pItem->SetThumbnailImage(thumb);
return;
}
if (!pItem->IsPlugin())
{
// we load the directory, grab 4 random thumb files (if available) and then generate
// the thumb.
CFileItemList items;
CDirectory::GetDirectory(strPath, items, g_settings.m_pictureExtensions, DIR_FLAG_NO_FILE_DIRS);
// create the folder thumb by choosing 4 random thumbs within the folder and putting
// them into one thumb.
// count the number of images
for (int i=0; i < items.Size();)
{
if (!items[i]->IsPicture() || items[i]->IsZIP() || items[i]->IsRAR() || items[i]->IsPlayList())
{
items.Remove(i);
}
else
i++;
}
if (items.IsEmpty())
{
if (pItem->IsCBZ() || pItem->IsCBR())
{
CDirectory::GetDirectory(strPath, items, g_settings.m_pictureExtensions, DIR_FLAG_NO_FILE_DIRS);
for (int i=0;i<items.Size();++i)
{
CFileItemPtr item = items[i];
if (item->m_bIsFolder)
{
ProcessFoldersAndArchives(item.get());
pItem->SetThumbnailImage(items[i]->GetThumbnailImage());
pItem->SetIconImage(items[i]->GetIconImage());
return;
}
}
}
return; // no images in this folder
}
// randomize them
items.Randomize();
if (items.Size() < 4 || pItem->IsCBR() || pItem->IsCBZ())
{ // less than 4 items, so just grab the first thumb
items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC);
CStdString thumb = CTextureCache::GetWrappedThumbURL(items[0]->GetPath());
db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
CTextureCache::Get().BackgroundCacheImage(thumb);
pItem->SetThumbnailImage(thumb);
}
else
{
// ok, now we've got the files to get the thumbs from, lets create it...
// we basically load the 4 images and combine them
//.........这里部分代码省略.........
示例4: ProcessFoldersAndArchives
void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
{
if (pItem->HasArt("thumb"))
return;
CTextureDatabase db;
db.Open();
if ((pItem->m_bIsFolder) && !pItem->m_bIsShareOrDrive
&& !pItem->IsParentFolder() && !pItem->IsPath("add"))
{
// first check for a folder.jpg
std::string thumb = "folder.jpg";
CURL pathToUrl = pItem->GetURL();
if (pItem->IsMultiPath())
pathToUrl = CURL(CMultiPathDirectory::GetFirstPath(pItem->GetPath()));
thumb = URIUtils::AddFileToFolder(pathToUrl.Get(), thumb);
if (CFile::Exists(thumb))
{
db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
CTextureCache::GetInstance().BackgroundCacheImage(thumb);
pItem->SetArt("thumb", thumb);
return;
}
// we load the directory, grab 4 random thumb files (if available) and then generate
// the thumb.
CFileItemList items;
CDirectory::GetDirectory(pathToUrl, items, g_advancedSettings.m_pictureExtensions, DIR_FLAG_NO_FILE_DIRS);
// create the folder thumb by choosing 4 random thumbs within the folder and putting
// them into one thumb.
// count the number of images
for (int i=0; i < items.Size();)
{
if (!items[i]->IsPicture() || items[i]->IsPlayList())
{
items.Remove(i);
}
else
i++;
}
if (items.IsEmpty())
return; // no images in this folder
// randomize them
items.Randomize();
if (items.Size() < 4)
{ // less than 4 items, so just grab the first thumb
items.Sort(SortByLabel, SortOrderAscending);
std::string thumb = CTextureUtils::GetWrappedThumbURL(items[0]->GetPath());
db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
CTextureCache::GetInstance().BackgroundCacheImage(thumb);
pItem->SetArt("thumb", thumb);
}
else
{
// ok, now we've got the files to get the thumbs from, lets create it...
// we basically load the 4 images and combine them
vector<string> files;
for (int thumb = 0; thumb < 4; thumb++)
files.push_back(items[thumb]->GetPath());
std::string thumb = CTextureUtils::GetWrappedImageURL(pItem->GetPath(), "picturefolder");
std::string relativeCacheFile = CTextureCache::GetCacheFile(thumb) + ".png";
if (CPicture::CreateTiledThumb(files, CTextureCache::GetCachedPath(relativeCacheFile)))
{
CTextureDetails details;
details.file = relativeCacheFile;
details.width = g_advancedSettings.GetThumbSize();
details.height = g_advancedSettings.GetThumbSize();
CTextureCache::GetInstance().AddCachedTexture(thumb, details);
db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
pItem->SetArt("thumb", CTextureCache::GetCachedPath(relativeCacheFile));
}
}
// refill in the icon to get it to update
pItem->FillInDefaultIcon();
}
}