📄 musictree.cpp
字号:
}
}
HTREEITEM MusicBrowserUI::CreateStreamFolder(string& treePath)
{
HTREEITEM result = m_hStreamsItem;
string::size_type begin = 0;
while((begin = treePath.find('/', begin)) != string::npos)
{
string::size_type end;
end = treePath.find('/', begin + 1);
string folder;
if(end != string::npos)
{
folder = treePath.substr(begin + 1, end - 1);
begin = end + 1;
}
else
{
folder = treePath.substr(begin + 1);
begin = string::npos;
}
HTREEITEM treeItem = TreeView_GetChild(m_hMusicView, result);
bool found = false;
while(treeItem)
{
TV_ITEM tv_item;
char buf[512];
tv_item.hItem = treeItem;
tv_item.mask = TVIF_TEXT;
tv_item.pszText = buf;
tv_item.cchTextMax = sizeof(buf);
TreeView_GetItem(m_hMusicView, &tv_item);
if(!folder.compare(buf))
{
found = true;
break;
}
treeItem = TreeView_GetNextSibling(m_hMusicView, treeItem);
}
if(found)
{
result = treeItem;
}
else
{
TV_INSERTSTRUCT insert;
insert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_CHILDREN |
TVIF_SELECTEDIMAGE | TVIF_PARAM;
insert.item.pszText = (char*)folder.c_str();
insert.item.cchTextMax = strlen(insert.item.pszText);
insert.item.iImage = 14;
insert.item.iSelectedImage = 14;
insert.item.cChildren= 1;
insert.item.lParam = NULL;
insert.hInsertAfter = TVI_LAST;
insert.hParent = result;
result = TreeView_InsertItem(m_hMusicView, &insert);
}
}
return result;
}
int32 MusicBrowserUI::GetCurrentItemFromMousePos()
{
TV_ITEM tv_item;
TV_HITTESTINFO tv_htinfo;
GetCursorPos(&tv_htinfo.pt);
ScreenToClient(m_hMusicView, &tv_htinfo.pt);
if(TreeView_HitTest(m_hMusicView, &tv_htinfo))
{
tv_item.hItem = TreeView_GetSelection(m_hMusicView);
tv_item.mask = TVIF_PARAM | TVIF_HANDLE;
TreeView_GetItem(m_hMusicView, &tv_item);
return tv_item.lParam;
}
return -1;
}
HTREEITEM MusicBrowserUI::FindArtist(const ArtistList* artist)
{
HTREEITEM result = NULL;
HWND hwnd = m_hMusicView;
TV_ITEM tv_item;
tv_item.hItem = m_hUncatItem;
tv_item.mask = TVIF_PARAM;
// this should retrieve the first artist
tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem);
BOOL success;
do
{
success = TreeView_GetItem(hwnd, &tv_item);
if(success)
{
TreeData* treedata = (TreeData*)tv_item.lParam;
if(treedata && artist == treedata->m_pArtist)
{
result = tv_item.hItem;
break;
}
}
}while(success && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
return result;
}
HTREEITEM MusicBrowserUI::FindAlbum(HTREEITEM artistItem, const AlbumList* album)
{
HTREEITEM result = NULL;
HWND hwnd = m_hMusicView;
TV_ITEM tv_item;
tv_item.hItem = NULL;
tv_item.mask = TVIF_PARAM;
// this should retrieve the first artist
tv_item.hItem = TreeView_GetChild(m_hMusicView, artistItem);
BOOL success;
do
{
success = TreeView_GetItem(hwnd, &tv_item);
if(success)
{
TreeData* treedata = (TreeData*)tv_item.lParam;
if(treedata && album == treedata->m_pAlbum)
{
result = tv_item.hItem;
break;
}
}
}while(success && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
return result;
}
HTREEITEM MusicBrowserUI::FindTrack(HTREEITEM albumItem, const PlaylistItem* track)
{
HTREEITEM result = NULL;
HWND hwnd = m_hMusicView;
TV_ITEM tv_item;
tv_item.hItem = NULL;
tv_item.mask = TVIF_PARAM;
// this should retrieve the first artist
tv_item.hItem = TreeView_GetChild(m_hMusicView, albumItem);
BOOL success;
do
{
success = TreeView_GetItem(hwnd, &tv_item);
if(success)
{
TreeData* treedata = (TreeData*)tv_item.lParam;
if(treedata && track == treedata->m_pTrack)
{
result = tv_item.hItem;
break;
}
}
}while(success && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
return result;
}
HTREEITEM MusicBrowserUI::FindPlaylist(const string playlist)
{
HTREEITEM result = NULL;
HWND hwnd = m_hMusicView;
TV_ITEM tv_item;
tv_item.hItem = NULL;
tv_item.mask = TVIF_PARAM;
// this should retrieve the first playlist
tv_item.hItem = TreeView_GetChild(m_hMusicView, m_hPlaylistItem);
// but we want the second one... not the magic "Create New Playlist..."
tv_item.hItem = TreeView_GetNextSibling(m_hMusicView, tv_item.hItem);
BOOL success;
do
{
success = TreeView_GetItem(hwnd, &tv_item);
if(success)
{
TreeData* treedata = (TreeData*)tv_item.lParam;
if(treedata && playlist == treedata->m_oPlaylistPath)
{
result = tv_item.hItem;
break;
}
}
}while(success && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
return result;
}
HTREEITEM MusicBrowserUI::FindFavorite(const PlaylistItem* stream)
{
HTREEITEM result = NULL;
HWND hwnd = m_hMusicView;
TV_ITEM tv_item;
tv_item.hItem = NULL;
tv_item.mask = TVIF_PARAM;
// this should retrieve the first stream
tv_item.hItem = TreeView_GetChild(m_hMusicView, m_hFavoritesItem);
// but we want the second one... not the magic "Add New Stream..."
tv_item.hItem = TreeView_GetNextSibling(m_hMusicView, tv_item.hItem);
BOOL success;
do
{
success = TreeView_GetItem(hwnd, &tv_item);
if(success)
{
TreeData* treedata = (TreeData*)tv_item.lParam;
if(treedata && *stream == *treedata->m_pStream)
{
result = tv_item.hItem;
break;
}
}
}while(success && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
return result;
}
void MusicBrowserUI::MusicCatalogCleared()
{
bool check = true;
if(m_initialized)
InitTree();
m_cdId = -1;
m_context->prefs->GetPrefBoolean(kCheckCDAutomaticallyPref, &check);
if (check)
CheckForCD();
}
void MusicBrowserUI::MusicCatalogPlaylistAdded(string item)
{
// put it under playlists
if(TreeView_GetChild(m_hMusicView, m_hPlaylistItem))
{
TV_INSERTSTRUCT insert;
TreeData data;
MetaData metadata;
char szBase[MAX_PATH];
_splitpath((char *)item.c_str(), NULL, NULL, szBase, NULL);
insert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_CHILDREN |
TVIF_SELECTEDIMAGE | TVIF_PARAM;
data.m_iLevel = 1;
data.m_oPlaylistName = string(szBase);
data.m_oPlaylistPath = item;
insert.item.pszText = szBase;
insert.item.cchTextMax = strlen(szBase);
insert.item.iImage = 1;
insert.item.iSelectedImage = 1;
insert.item.cChildren= 0;
insert.item.lParam = (LPARAM) new TreeData(data);
insert.hInsertAfter = TVI_SORT;
insert.hParent = m_hPlaylistItem;
TreeView_InsertItem(m_hMusicView, &insert);
TreeView_DeleteItem(m_hMusicView, m_hNewPlaylistItem);
insert.item.pszText = kNewPlaylist;
insert.item.cchTextMax = strlen(kNewPlaylist);
insert.item.iImage = 1;
insert.item.iSelectedImage = 1;
insert.item.cChildren= 0;
insert.item.lParam = NULL;
insert.hInsertAfter = TVI_FIRST;
insert.hParent = m_hPlaylistItem;
m_hNewPlaylistItem = TreeView_InsertItem(m_hMusicView, &insert);
}
}
void MusicBrowserUI::MusicCatalogPlaylistRemoved(string item)
{
HTREEITEM playlistItem = NULL;
playlistItem = FindPlaylist(item);
if(playlistItem)
{
TreeView_DeleteItem(m_hMusicView, playlistItem);
}
}
void MusicBrowserUI::MusicCatalogTrackChanged(const ArtistList *oldArtist,
const ArtistList *newArtist,
const AlbumList *oldAlbum,
const AlbumList *newAlbum,
const PlaylistItem *oldItem,
const PlaylistItem *newItem)
{
HTREEITEM artistItem = NULL;
HTREEITEM albumItem = NULL;
HTREEITEM trackItem = NULL;
UINT artistState = 0;
UINT albumState = 0;
// is this in the uncatagorized section?
if(!oldArtist)
{
trackItem = FindTrack(m_hUncatItem, oldItem);
}
else
{
artistItem = FindArtist(oldArtist);
if(artistItem)
{
TV_ITEM tv_item;
tv_item.hItem = artistItem;
tv_item.mask = TVIF_STATE;
tv_item.stateMask = TVIS_SELECTED|TVIS_EXPANDED;
tv_item.state = 0;
TreeView_GetItem(m_hMusicView, &tv_item);
artistState = tv_item.state;
albumItem = FindAlbum(artistItem, oldAlbum);
if(albumItem)
{
tv_item.hItem = albumItem;
tv_item.mask = TVIF_STATE;
tv_item.stateMask = TVIS_SELECTED|TVIS_EXPANDED;
tv_item.state = 0;
TreeView_GetItem(m_hMusicView, &tv_item);
albumState = tv_item.state;
//trackItem = FindTrack(albumItem, oldItem);
}
}
}
MusicCatalogTrackRemoved(oldArtist, oldAlbum, oldItem);
MusicCatalogTrackAdded(newArtist,newAlbum, newItem);
if(oldArtist != newArtist)
{
if(!FindArtist(oldArtist))
{
artistItem = FindArtist(newArtist);
if(artistItem)
{
if(artistState & TVIS_EXPANDED)
TreeView_Expand(m_hMusicView, artistItem, TVE_EXPAND);
}
}
}
if(oldAlbum != newAlbum)
{
artistItem = FindArtist(newArtist);
if(artistItem)
{
if(!FindAlbum(artistItem, oldAlbum))
{
albumItem = FindAlbum(artistItem, newAlbum);
if(albumItem)
{
if(albumState & TVIS_EXPANDED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -