// MainDlg.cpp : Implementation of CMediaLibraryDlg
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#include "stdafx.h"
#include "MediaLibraryDlg.h"
#include "PopDlgs.h"
/////////////////////////////////////////////////////////////////////////////
// CMediaLibraryDlg
/***********************************************************************
* Constructor
***********************************************************************/
CMediaLibraryDlg::CMediaLibraryDlg(IWMPPlayer* pPlayer)
{
// Initialize member variables
m_hTree = NULL;
m_hList = NULL;
m_hMetadata = NULL;
m_hAllMusicNode = NULL;
m_hAllVideoNode = NULL;
m_hMyPlaylistsNode = NULL;
m_hAutoPlaylistwNode = NULL;
m_bIsShowingMedia = TRUE;
m_spSavedPlaylist = NULL;
m_iSelectedNode = TREE_PARENT;
m_spPlayer = pPlayer;
}
/***********************************************************************
* Destructor
***********************************************************************/
CMediaLibraryDlg::~CMediaLibraryDlg()
{
}
/***********************************************************************
* OnInitDialog
*
* Initialize member variables of handlers
* Initialize WMP OCX
***********************************************************************/
LRESULT CMediaLibraryDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// Get handler of list and tree for later usage
m_hTree = GetDlgItem(IDC_TREE);
m_hList = GetDlgItem(IDC_LIST);
m_hMetadata = GetDlgItem(IDC_METADATA);
// get mediaCollection and playlistCollection objects for later use.
m_spPlayer->get_mediaCollection(&m_spMC);
m_spPlayer->get_playlistCollection(&m_spPC);
// Use tree view to show media library
ShowMainTree();
return 1; // Let the system set the focus
}
/***********************************************************************
* OnDestroy
* Release WMP OCX
***********************************************************************/
LRESULT CMediaLibraryDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// Release all WMP objects before exit
m_spSavedPlaylist = NULL;
m_spMC = NULL;
m_spPC = NULL;
m_spPlayer = NULL;
return 0;
}
/***********************************************************************
* OnOK
* User closes the dialog
***********************************************************************/
LRESULT CMediaLibraryDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
/***********************************************************************
* OnCancel
* User closes the dialog
***********************************************************************/
LRESULT CMediaLibraryDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
/***********************************************************************
* OnRemovePlaylist
* Called when menu Playlist > Delete is chosen
* It pops up a dialog using CDelPlaylistDlg
***********************************************************************/
LRESULT CMediaLibraryDlg::OnRemovePlaylist(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CDelPlaylistDlg dlg(m_spPC);
// When a user delete a playlist, it returns PLAYLIST
// then we update the relative part of the tree view
if(dlg.DoModal() == PLAYLIST)
{
ShowPlaylistsTree();
}
return 0;
}
/***********************************************************************
* OnAddURL
* Called when menu Media > Add is chosen
* It pops up a dialog using CAddMediaDlg
***********************************************************************/
LRESULT CMediaLibraryDlg::OnAddURL(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CAddMediaDlg dlg(m_spMC);
// It returns different MEDIATYPE when user adds different type
// of URL. If the added media is playlist (ASX and WPL) then it
// returns PLAYLIST
int iRetCode = dlg.DoModal();
switch(iRetCode)
{
case MUSIC:
ShowAllMusicTree();
break;
case VIDEO:
ShowAllVideoTree();
break;
case PLAYLIST:
ShowPlaylistsTree();
}
return 0;
}
/***********************************************************************
* OnRemoveMedia
* Called when menu Media > Delete is chosen
* It pops up a dialog using CDelMediaDlg
***********************************************************************/
LRESULT CMediaLibraryDlg::OnRemoveMedia(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CDelMediaDlg dlg(m_spMC);
// Return value shows what kind of media is deleted
int iRetCode = dlg.DoModal();
if(iRetCode == MUSIC)
{
ShowAllMusicTree();
}
else if(iRetCode == VIDEO)
{
ShowAllVideoTree();
}
return 0;
}
/***********************************************************************
* ShowMainTree
* Build the tree view of the media library
***********************************************************************/
void CMediaLibraryDlg::ShowMainTree()
{
// Now Playing node
AddNode(_T("Now Playing"), TREE_NOWPLAYING);
// All node
AddNode(_T("All"), TREE_ALL);
// All Music node
m_hAllMusicNode = AddNode(_T("All Music"), TREE_MUSIC);
ShowAllMusicTree();
// All Video node
m_hAllVideoNode = AddNode(_T("All Video"), TREE_VIDEO);
ShowAllVideoTree();
// Other Media node
AddNode(_T("Other Media"), TREE_OTHER);
// My Playlists and auto playlists nodes
m_hMyPlaylistsNode = AddNode(_T("My Playlists"), TREE_MYPLAYLIST);
m_hAutoPlaylistwNode = AddNode(_T("Auto Playlists"), TREE_AUTOPLAYLIST);
ShowPlaylistsTree();
}
/***********************************************************************
* AddNode
* szName: string shown on the added node
* iPara: param value for the added node
* hParent: handler to the parent node
*
* It adds a node under hParent with given text and param
***********************************************************************/
HTREEITEM CMediaLibraryDlg::AddNode(TCHAR* szName, NODENAME iPara, HTREEITEM hParent)
{
TVINSERTSTRUCT tvins;
tvins.item.mask = TVIF_TEXT | TVIF_PARAM;
tvins.hParent = hParent;
tvins.hInsertAfter = TVI_LAST;
// add the node
tvins.item.lParam = (LPARAM)iPara;
tvins.item.pszText = szName;
tvins.item.cchTextMax = _tcslen(szName);
return TreeView_InsertItem(m_hTree, &tvins);
}
/***********************************************************************
* OnClickTree
*
* It is called when a user clicks on the tree
***********************************************************************/
LRESULT CMediaLibraryDlg::OnClickTree(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
HTREEITEM hCurItem = TreeView_GetSelection(m_hTree);
//HTREEITEM hParentItem = TreeView_GetParent(m_hTree, hCurItem);
// Retrieve the text and param of the selected node
TCHAR szPlaylistName[MAX_BSTR_LONG + 1];
TVITEM tvi;
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.hItem = hCurItem;
tvi.pszText = szPlaylistName;
tvi.cchTextMax = MAX_BSTR_LONG;
BOOL bVal;
bVal = TreeView_GetItem(m_hTree, &tvi);
// We use param of the node to tell what kind of node it is
m_iSelectedNode = (NODENAME)(tvi.lParam);
switch(tvi.lParam)
{
case TREE_ALL: // All node
ShowAllMedia();
break;
case TREE_NOWPLAYING: // Now playing node
ShowNowPlaying();
break;
case TREE_MUSIC: // All music node
ShowAllMusic();
break;
case TREE_MUSIC_ARTIST: // Music > Arti