From: <che...@us...> - 2008-07-17 19:36:18
|
Revision: 1928 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1928&view=rev Author: chef_koch Date: 2008-07-17 19:34:36 +0000 (Thu, 17 Jul 2008) Log Message: ----------- moved MyMusicVideos plugin from MediaPortal svn Added Paths: ----------- trunk/plugins/MyMusicVideos/ trunk/plugins/MyMusicVideos/MyMusicVideos/ trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideo.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoPlaylist.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.designer.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.resx trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupForm.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupForm.designer.cs trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupForm.resx trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/ trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/MVPlayListItem.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/MusicVideoDatabase.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/MusicVideoDatabaseTest.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooFavorites.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooGenres.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooNewVideos.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooSearch.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooSettings.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooSite.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooTopVideos.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooUtil.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MusicVideos/YahooVideo.cs trunk/plugins/MyMusicVideos/MyMusicVideos/MyMusicVideos.csproj trunk/plugins/MyMusicVideos/MyMusicVideos/Properties/ trunk/plugins/MyMusicVideos/MyMusicVideos/Properties/AssemblyInfo.cs trunk/plugins/MyMusicVideos/MyMusicVideos.xmp trunk/plugins/MyMusicVideos/release/ trunk/plugins/MyMusicVideos/release/skin/ trunk/plugins/MyMusicVideos/release/skin/BlueTwo/ trunk/plugins/MyMusicVideos/release/skin/BlueTwo/mymusicvideoplaylist.xml trunk/plugins/MyMusicVideos/release/skin/BlueTwo/mymusicvideos.xml trunk/plugins/MyMusicVideos/release/skin/BlueTwo wide/ trunk/plugins/MyMusicVideos/release/skin/BlueTwo wide/mymusicvideoplaylist.xml trunk/plugins/MyMusicVideos/release/skin/BlueTwo wide/mymusicvideos.xml Added: trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideo.cs =================================================================== --- trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideo.cs (rev 0) +++ trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideo.cs 2008-07-17 19:34:36 UTC (rev 1928) @@ -0,0 +1,975 @@ +#region Copyright (C) 2005-2008 Team MediaPortal + +/* + * Copyright (C) 2005-2008 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; + +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +using MediaPortal.Player; +using MediaPortal.Playlists; +using MediaPortal.MusicVideos.Database; + +namespace MediaPortal.GUI.MusicVideos +{ + public class GUIMusicVideos : GUIWindow, ISetupForm, IShowPlugin + { + #region SkinControlAttributes + [SkinControlAttribute(2)] protected GUIButtonControl btnTop = null; + [SkinControlAttribute(7)] protected GUIButtonControl btnNew = null; + [SkinControlAttribute(8)] protected GUIButtonControl btnPlayAll = null; + [SkinControlAttribute(3)] protected GUIButtonControl btnSearch = null; + [SkinControlAttribute(6)] protected GUIButtonControl btnFavorites = null; + [SkinControlAttribute(9)] protected GUIButtonControl btnBack = null; + [SkinControlAttribute(25)] protected GUIButtonControl btnPlayList = null; + [SkinControlAttribute(34)] protected GUIButtonControl btnNextPage = null; + [SkinControlAttribute(35)] protected GUIButtonControl btnPreviousPage = null; + [SkinControlAttribute(36)] protected GUIImage imgCountry = null; + [SkinControlAttribute(37)] protected GUIButtonControl btnGenre = null; + [SkinControlAttribute(38)] protected GUIButtonControl btnCountry = null; + + [SkinControlAttribute(50)] protected GUIListControl listSongs = null; + + #endregion + + #region Enumerations + enum State + { + HOME = -1, + TOP = 0, + SEARCH = 1, + FAVORITE = 2, + NEW = 3, + GENRE = 4 + }; + + #endregion + + #region variables + private int WINDOW_ID = 4734; + private YahooSettings moSettings; + private YahooTopVideos moTopVideos; + private YahooNewVideos moNewVideos; + private YahooSearch moYahooSearch; + private YahooFavorites moFavoriteManager; + private YahooGenres moGenre; + private int CURRENT_STATE = (int)State.HOME; + private int miSelectedIndex = 0; + private YahooVideo moCurrentPlayingVideo; + private string msSelectedGenre; + #endregion + + public GUIMusicVideos() + { + } + + #region ISetupForm Members + + public bool CanEnable() + { + return true; + } + + public string PluginName() + { + return "My Music Videos "; + } + + public bool DefaultEnabled() + { + return false; + } + + public bool HasSetup() + { + return true; + } + + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = GUILocalizeStrings.Get(30000);// "My MusicVideos"; + strButtonImage = ""; + strButtonImageFocus = ""; + strPictureImage = "hover_musicvideo.png"; + return true; + } + + public string Author() + { + return "Gregmac45"; + } + + public string Description() + { + return "This plugin shows online music videos from Yahoo"; + } + + public bool ShowDefaultHome() + { + return false; + } + + public void ShowPlugin() // show the setup dialog + { + System.Windows.Forms.Form setup = new SetupForm(); + setup.ShowDialog(); + } + + public int GetWindowId() + { + return GetID; + } + + #endregion + + #region GUIWindow Overrides + + public override int GetID + { + get { return WINDOW_ID; } + set { base.GetID = value; } + } + + public override bool Init() + { + return Load(GUIGraphicsContext.Skin + @"\mymusicvideos.xml"); + } + + protected override void OnPageDestroy(int new_windowId) + { + //labelState.Label = ""; + base.OnPageDestroy(new_windowId); + } + + public override void OnAction(Action action) + { + if (action.wID != Action.ActionType.ACTION_MOUSE_MOVE) + { + Log.Info("action wID = {0}", action.wID); + } + if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU && CURRENT_STATE != (int)State.HOME) + { + CURRENT_STATE = (int)State.HOME; + updateButtonStates(); + this.LooseFocus(); + btnTop.Focus = true; + return; + } + + base.OnAction(action); + } + public override bool OnMessage(GUIMessage message) + { + if (GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS_CHANGED != message.Message + && GUIMessage.MessageType.GUI_MSG_SETFOCUS != message.Message) + { + Log.Info("Message = {0}", message.Message); + } + + if (GUIMessage.MessageType.GUI_MSG_SETFOCUS == message.Message) + { + if (message.TargetControlId == listSongs.GetID && listSongs.Count > 0) + { + ////labelSelected.Label = "Press Menu or F9 for more options."; + // todo : show current title here... + //GUIPropertyManager.SetProperty("#title", listSongs.SelectedItem); + } + else + { + //labelSelected.Label = ""; + } + } + + return base.OnMessage(message); + } + protected override void OnPreviousWindow() + { + if (g_Player.Playing) + { + Log.Info("in OnPreviousWindow and g_player is playing"); + + if (moCurrentPlayingVideo != null) + GUIPropertyManager.SetProperty("#Play.Current.Title", moCurrentPlayingVideo.artistName + "-" + moCurrentPlayingVideo.songName); + } + base.OnPreviousWindow(); + } + protected override void OnPageLoad() + { + if (moSettings == null) + { + moSettings = YahooSettings.getInstance(); + } + Log.Info("Image filename = '{0}'", imgCountry.FileName); + if (String.IsNullOrEmpty(imgCountry.FileName)) + { + Log.Info("Updating country image"); + YahooUtil loUtil = YahooUtil.getInstance(); + string lsCountryId = loUtil.getYahooSite(moSettings.msDefaultCountryName).countryId; + Log.Info("country image -country id = {0}", lsCountryId); + string countryFlag = GUIGraphicsContext.Skin + @"\media\" + lsCountryId + ".png"; + if (System.IO.File.Exists(countryFlag)) + imgCountry.SetFileName(countryFlag); + } + + if (CURRENT_STATE == (int)State.HOME) + { + updateButtonStates(); + this.LooseFocus(); + btnTop.Focus = true; + } + else + { + if (CURRENT_STATE == (int)State.TOP) + { + refreshStage2Screen(); + } + else if (CURRENT_STATE == (int)State.NEW) + { + refreshStage2Screen(); + } + else if (CURRENT_STATE == (int)State.FAVORITE) + { + refreshStage2Screen(); + } + else if (CURRENT_STATE == (int)State.SEARCH) + { + refreshStage2Screen(); + } + else if (CURRENT_STATE == (int)State.GENRE) + { + refreshStage2Screen(); + } + this.LooseFocus(); + listSongs.Focus = true; + + } + if (g_Player.Playing) + { + if (moCurrentPlayingVideo != null) + { + GUIPropertyManager.SetProperty("#Play.Current.Title", moCurrentPlayingVideo.artistName + " - " + moCurrentPlayingVideo.songName); + } + } + + } + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + Log.Info("GUIMusicVideo: Clicked"); + if (actionType == Action.ActionType.ACTION_QUEUE_ITEM) + { + Log.Info("Caught on Queue action for list item {0}", listSongs.SelectedListItemIndex); + OnQueueItem(); + return; + } + if (control == listSongs) + { + miSelectedIndex = listSongs.SelectedListItemIndex; + playVideo(getSelectedVideo()); + } + else if (control == btnTop) + { + onClickTopVideos(); + } + else if (control == btnNew) + { + onClickNewVideos(); + } + else if (control == btnSearch) + { + SearchVideos(true, string.Empty); + } + else if (control == btnFavorites) + { + onClickFavorites(); + } + else if (control == btnGenre) + { + onClickGenre(); + } + else if (control == btnBack) + { + CURRENT_STATE = (int)State.HOME; + updateButtonStates(); + this.LooseFocus(); + btnTop.Focus = true; + } + + else if (control == btnPlayAll) + { + OnQueueAllItems(getStateVideoList()); + } + else if (control == btnPlayList) + { + onClickPlaylist(); + } + + else if (control == btnNextPage) + { + OnClickNextPage(); + } + else if (control == btnPreviousPage) + { + OnClickPreviousPage(); + } + else if (control == btnCountry) + { + onClickChangeCountry(); + } + } + public override void Process() + { + base.Process(); + } + protected override void OnShowContextMenu() + { + YahooVideo loVideo = getSelectedVideo(); + if (loVideo == null) + { + return; + } + GUIListItem loSelectVideo = listSongs.SelectedListItem; + int liSelectedIndex = listSongs.SelectedListItemIndex; + if (liSelectedIndex > -1) + { + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + dlgSel.Reset(); + if (dlgSel != null) + { + dlgSel.SetHeading(GUILocalizeStrings.Get(498)); // Menu + + dlgSel.Add(GUILocalizeStrings.Get(208)); // Play + dlgSel.Add(GUILocalizeStrings.Get(926)); // Add to playList + if ((int)State.FAVORITE == CURRENT_STATE) + dlgSel.Add(GUILocalizeStrings.Get(933)); // Remove from favorites + else + dlgSel.Add(GUILocalizeStrings.Get(930)); // Add to favorites + dlgSel.Add(GUILocalizeStrings.Get(30007)); // Search other videos by this artist + + dlgSel.DoModal(GetID); + int liSelectedIdx = dlgSel.SelectedId; + Log.Info("you selected action :{0}", liSelectedIdx); + switch (liSelectedIdx) + { + case 1: + playVideo(loVideo); + break; + case 2: + OnQueueItem(); + break; + case 3: + if (CURRENT_STATE == (int)State.FAVORITE) + { + moFavoriteManager.removeFavorite(loVideo); + DisplayVideoList(moFavoriteManager.getFavoriteVideos()); + } + else + { + //prompt user for favorite list to add to + string lsSelectedFav = promptForFavoriteList(); + Log.Info("adding to favorites."); + if (moFavoriteManager == null) + { + moFavoriteManager = new YahooFavorites(); + } + moFavoriteManager.setSelectedFavorite(lsSelectedFav); + moFavoriteManager.addFavorite(loVideo); + } + break; + case 4: + SearchVideos(false, loVideo.artistName); + break; + } + } + } + } + #endregion + + #region userdefined methods + private void onClickFavorites() + { + if (moFavoriteManager == null) + { + moFavoriteManager = new YahooFavorites(); + } + + string lsSelectedFav = promptForFavoriteList(); + if (String.IsNullOrEmpty(lsSelectedFav)) + { + return; + } + + CURRENT_STATE = (int)State.FAVORITE; + + + if (lsSelectedFav != null || lsSelectedFav.Length > 0) + { + moFavoriteManager.setSelectedFavorite(lsSelectedFav); + } + DisplayVideoList(moFavoriteManager.getFavoriteVideos()); + //labelState.Label = (GUILocalizeStrings.Get(932) + " - " + moFavoriteManager.getSelectedFavorite()); + updateButtonStates(); + if (listSongs.Count == 0) + { + this.LooseFocus(); + btnBack.Focus = true; + } + } + + private void onClickPlaylist() + { + if (GetID == GUIWindowManager.ActiveWindow) + { + GUIWindowManager.ActivateWindow(4735); + } + } + + private string promptForGenre() + { + string lsSelectedGenre = ""; + moGenre = new YahooGenres(); + ArrayList loGenreNames = moGenre.moSortedGenreList; + + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + dlgSel.Reset(); + if (dlgSel != null) + { + foreach (string lsGenreNm in loGenreNames) + dlgSel.Add(lsGenreNm); + + dlgSel.SetHeading(GUILocalizeStrings.Get(496)); // Menu + dlgSel.DoModal(GetID); + if (dlgSel.SelectedLabel == -1) + return ""; + + Log.Info("you selected genre :{0}", dlgSel.SelectedLabelText); + lsSelectedGenre = dlgSel.SelectedLabelText; + } + return lsSelectedGenre; + } + + private string promptForFavoriteList() + { + + string lsSelectedFav = ""; + if (moFavoriteManager == null) + moFavoriteManager = new YahooFavorites(); + + ArrayList loFavNames = moFavoriteManager.getFavoriteNames(); + if (loFavNames.Count > 1) + { + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + dlgSel.Reset(); + if (dlgSel != null) + { + foreach (string lsFavNm in loFavNames) + dlgSel.Add(lsFavNm); + + dlgSel.SetHeading(GUILocalizeStrings.Get(497)); // Menu + dlgSel.DoModal(GetID); + if (dlgSel.SelectedLabel == -1) + return ""; + + Log.Info("you selected favorite :{0}", dlgSel.SelectedLabelText); + lsSelectedFav = dlgSel.SelectedLabelText; + } + } + else + lsSelectedFav = (string)loFavNames[0]; + + return lsSelectedFav; + } + + private void onClickChangeCountry() + { + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + dlgSel.Reset(); + if (dlgSel != null) + { + String[] loCountryArray = new String[moSettings.moYahooSiteTable.Keys.Count]; + moSettings.moYahooSiteTable.Keys.CopyTo(loCountryArray, 0); + Array.Sort(loCountryArray); + + foreach (string country in loCountryArray) + dlgSel.Add(country); + + dlgSel.SetHeading(GUILocalizeStrings.Get(496)); // Menu + dlgSel.DoModal(GetID); + if (dlgSel.SelectedLabel == -1) + return; + + Log.Info("you selected country :{0}", dlgSel.SelectedLabelText); + moSettings.msDefaultCountryName = dlgSel.SelectedLabelText; + moYahooSearch = new YahooSearch(moSettings.msDefaultCountryName); + moTopVideos = new YahooTopVideos(moSettings.msDefaultCountryName); + RefreshPage(); + } + } + + private void onClickNewVideos() + { + miSelectedIndex = 0; + + CURRENT_STATE = (int)State.NEW; + Log.Info("button new clicked"); + if (moNewVideos == null) + { + moNewVideos = new YahooNewVideos(); + } + moNewVideos.loadNewVideos(moSettings.msDefaultCountryName); + Log.Info("The new video page has next video ={0}", moNewVideos.hasNext()); + if (moNewVideos.hasNext()) + btnNextPage.Disabled = false; + else + btnNextPage.Disabled = true; + + btnPreviousPage.Disabled = true; + refreshStage2Screen(); + } + + private void onClickGenre() + { + miSelectedIndex = 0; + if (moGenre == null) + moGenre = new YahooGenres(); + + msSelectedGenre = promptForGenre(); + if (String.IsNullOrEmpty(msSelectedGenre)) + { + return; + } + CURRENT_STATE = (int)State.GENRE; + + Log.Info("button GENRE clicked"); + + moGenre.loadFirstGenreVideos(msSelectedGenre); + + if (moGenre.hasNext()) + btnNextPage.Disabled = false; + else + btnNextPage.Disabled = true; + + btnPreviousPage.Disabled = true; + refreshStage2Screen(); + } + + private void OnQueueItem() + { + + PlayListPlayer loPlaylistPlayer = PlayListPlayer.SingletonPlayer; + loPlaylistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + PlayList loPlaylist = loPlaylistPlayer.GetPlaylist(loPlaylistPlayer.CurrentPlaylistType); + MVPlayListItem loItem; + YahooVideo loVideo = getSelectedVideo(); + + + loItem = new MVPlayListItem(); + loItem.YahooVideo = loVideo; + loPlaylist.Add(loItem); + + + if (listSongs.SelectedListItemIndex + 1 < listSongs.Count) + { + listSongs.SelectedListItemIndex = listSongs.SelectedListItemIndex + 1; + } + //} + } + + private void OnQueueAllItems(List<YahooVideo> foVideoList) + { + Log.Info("in Onqueue All"); + PlayListPlayer loPlaylistPlayer = PlayListPlayer.SingletonPlayer; + loPlaylistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + PlayList loPlaylist = loPlaylistPlayer.GetPlaylist(loPlaylistPlayer.CurrentPlaylistType); + MVPlayListItem loItem; + foreach (YahooVideo loVideo in foVideoList) + { + loItem = new MVPlayListItem(); + loItem.YahooVideo = loVideo; + loItem.Description = loVideo.artistName + "-" + loVideo.songName; + loPlaylist.Add(loItem); + } + Log.Info("current playlist type:{0}", loPlaylistPlayer.CurrentPlaylistType); + Log.Info("playlist count:{0}", loPlaylistPlayer.GetPlaylist(loPlaylistPlayer.CurrentPlaylistType)); + + onClickPlaylist(); + loPlaylistPlayer.PlayNext(); + } + + + private void SearchVideos(bool fbClicked, String fsSearchTxt) + { + + CURRENT_STATE = (int)State.SEARCH; + if (moYahooSearch == null) + { + moYahooSearch = new YahooSearch(moSettings.msDefaultCountryName); + } + + //clear the list + listSongs.Clear(); + if (fbClicked) + { + VirtualKeyboard keyBoard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + if (null == keyBoard) + return; + keyBoard.Reset(); + keyBoard.DoModal(GUIWindowManager.ActiveWindow); + + if (!keyBoard.IsConfirmed) + return; + moYahooSearch.searchVideos(keyBoard.Text); + } + else + { + moYahooSearch.searchVideos(fsSearchTxt); + } + DisplayVideoList(moYahooSearch.moLastSearchResult); + + btnNextPage.Disabled = !moYahooSearch.hasNext(); + btnPreviousPage.Disabled = true; + updateButtonStates(); + } + + private void onClickTopVideos() + { + CURRENT_STATE = (int)State.TOP; + miSelectedIndex = 0; + if (moTopVideos == null) + { + moTopVideos = new YahooTopVideos(moSettings.msDefaultCountryName); + } + moTopVideos.loadFirstPage(); + if (moTopVideos.hasMorePages()) + { + btnNextPage.Disabled = false; + } + else + { + btnNextPage.Disabled = true; + } + btnPreviousPage.Disabled = true; + refreshStage2Screen(); + } + + private void OnClickNextPage() + { + miSelectedIndex = 0; + bool lbNext = false; + bool lbPrevious = false; + switch (CURRENT_STATE) + { + case (int)State.NEW: + moNewVideos.loadNextVideos(moSettings.msDefaultCountryName); + lbNext = moNewVideos.hasNext(); + lbPrevious = moNewVideos.hasPrevious(); + DisplayVideoList(moNewVideos.moNewVideoList); + break; + case (int)State.TOP: + moTopVideos.loadNextPage(); + lbNext = moTopVideos.hasMorePages(); + lbPrevious = moTopVideos.hasPreviousPage(); + DisplayVideoList(moTopVideos.getLastLoadedList()); + break; + case (int)State.SEARCH: + moYahooSearch.loadNextVideos(); + lbNext = moYahooSearch.hasNext(); + lbPrevious = moYahooSearch.hasPrevious(); + DisplayVideoList(moYahooSearch.moLastSearchResult); + break; + case (int)State.GENRE: + moGenre.loadNextVideos(); + lbNext = moGenre.hasNext(); + lbPrevious = moGenre.hasPrevious(); + DisplayVideoList(moGenre.moGenreVideoList); + break; + } + Log.Info("The video page has next video ={0}", lbNext); + Log.Info("The video page has previous video ={0}", lbPrevious); + + btnNextPage.Disabled = !lbNext; + btnPreviousPage.Disabled = !lbPrevious; + updateButtonStates(); + } + + private void OnClickPreviousPage() + { + miSelectedIndex = 0; + bool lbNext = false; + bool lbPrevious = false; + switch (CURRENT_STATE) + { + case (int)State.NEW: + moNewVideos.loadPreviousVideos(moSettings.msDefaultCountryName); + lbNext = moNewVideos.hasNext(); + lbPrevious = moNewVideos.hasPrevious(); + DisplayVideoList(moNewVideos.moNewVideoList); + break; + case (int)State.TOP: + moTopVideos.loadPreviousPage(); + lbNext = moTopVideos.hasMorePages(); + lbPrevious = moTopVideos.hasPreviousPage(); + DisplayVideoList(moTopVideos.getLastLoadedList()); + break; + case (int)State.SEARCH: + moYahooSearch.loadPreviousVideos(); + lbNext = moYahooSearch.hasNext(); + lbPrevious = moYahooSearch.hasPrevious(); + DisplayVideoList(moYahooSearch.moLastSearchResult); + break; + case (int)State.GENRE: + moGenre.loadPreviousVideos(); + lbNext = moGenre.hasNext(); + lbPrevious = moGenre.hasPrevious(); + DisplayVideoList(moGenre.moGenreVideoList); + break; + } + Log.Info("The video page has next video ={0}", lbNext); + Log.Info("The video page has previous video ={0}", lbPrevious); + + btnNextPage.Disabled = !lbNext; + btnPreviousPage.Disabled = !lbPrevious; + updateButtonStates(); + } + + private List<YahooVideo> getStateVideoList() + { + List<YahooVideo> loCurrentDisplayVideoList = null; + switch (CURRENT_STATE) + { + case (int)State.TOP: + loCurrentDisplayVideoList = moTopVideos.getLastLoadedList(); + break; + case (int)State.NEW: + loCurrentDisplayVideoList = moNewVideos.moNewVideoList; + break; + case (int)State.SEARCH: + loCurrentDisplayVideoList = moYahooSearch.moLastSearchResult; + break; + case (int)State.FAVORITE: + loCurrentDisplayVideoList = moFavoriteManager.getFavoriteVideos(); + break; + case (int)State.GENRE: + loCurrentDisplayVideoList = moGenre.moGenreVideoList; + break; + default: break; + } + return loCurrentDisplayVideoList; + } + + private YahooVideo getSelectedVideo() + { + YahooVideo loVideo = null; + + List<YahooVideo> loCurrentDisplayVideoList = getStateVideoList(); + + if (loCurrentDisplayVideoList != null && loCurrentDisplayVideoList.Count > 0) + { + loVideo = loCurrentDisplayVideoList[listSongs.SelectedListItemIndex]; + } + return loVideo; + } + + private string getUserTypedText() + { + string KB_Search_Str = ""; + VirtualKeyboard keyBoard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + keyBoard.Text = ""; + keyBoard.Reset(); + keyBoard.DoModal(GUIWindowManager.ActiveWindow); // show it... + System.GC.Collect(); // collect some garbage + if (keyBoard.Text == "" || keyBoard.Text == null) + { + return ""; + } + KB_Search_Str = keyBoard.Text; + return KB_Search_Str; + } + + private void refreshScreenVideoList() + { + Log.Info("Refreshing video list on screen"); + List<YahooVideo> loCurrentDisplayVideoList = getStateVideoList(); + DisplayVideoList(loCurrentDisplayVideoList); + listSongs.SelectedListItemIndex = miSelectedIndex; + } + + private void DisplayVideoList(List<YahooVideo> foVideoList) + { + if (foVideoList == null && foVideoList.Count < 1) { return; } + listSongs.Clear(); + GUIListItem item = null; + int liVideoListSize = foVideoList.Count; + foreach (YahooVideo loYahooVideo in foVideoList) + { + item = new GUIListItem(); + item.DVDLabel = loYahooVideo.songId; + if (loYahooVideo.artistName == null || loYahooVideo.artistName.Equals("")) + { + item.Label = loYahooVideo.songName; + } + else + { + item.Label = loYahooVideo.artistName + " - " + loYahooVideo.songName; + } + item.IsFolder = false; + //item.MusicTag = true; + listSongs.Add(item); + } + this.LooseFocus(); + listSongs.Focus = true; + if (listSongs.Count > 0) + { + ////labelSelected.Label = "Press Menu or F9 for more options."; + } + else + { + //labelSelected.Label = ""; + } + } + + void playVideo(YahooVideo video) + { + //Log.Info("in playVideo()"); + string lsVideoLink = null; + YahooSite loSite; + YahooUtil loUtil = YahooUtil.getInstance(); + loSite = loUtil.getYahooSiteById(video.countryId); + lsVideoLink = loUtil.getVideoMMSUrl(video, moSettings.msDefaultBitRate); + lsVideoLink = lsVideoLink.Substring(0, lsVideoLink.Length - 2) + "&txe=.wmv"; + if (moSettings.mbUseVMR9) + g_Player.PlayVideoStream(lsVideoLink, video.artistName + " - " + video.songName); + else + g_Player.PlayAudioStream(lsVideoLink, true); + + if (g_Player.Playing) + { + Log.Info("GUIMusicVideo: Playing: {0} with Bitrate: {1}", video.songName, moSettings.msDefaultBitRate); + g_Player.ShowFullScreenWindow(); + moCurrentPlayingVideo = video; + } + else + { + Log.Info("GUIMusicVideo: Unable to play {0}", lsVideoLink); + GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); + dlg.SetHeading("ERROR"); + dlg.SetText("Unable to play the selected music video. Please try again later."); + dlg.DoModal(GUIWindowManager.ActiveWindow); + } + } + + public void refreshStage2Screen() + { + updateButtonStates(); + refreshScreenVideoList(); + } + + void RefreshPage() + { + this.Restore(); + this.Init(); + this.Render(0); + this.OnPageLoad(); + } + + private void updateButtonStates() + { + if ((int)State.HOME == CURRENT_STATE) + { + btnTop.Visible = true; + btnNew.Visible = true; + btnGenre.Visible = true; + btnSearch.Visible = true; + btnFavorites.Visible = true; + btnCountry.Visible = true; + + btnBack.Visible = false; + btnPlayAll.Visible = false; + btnNextPage.Visible = false; + btnPreviousPage.Visible = false; + + btnTop.NavigateUp = btnPlayList.GetID; + btnPlayList.NavigateUp = btnCountry.GetID; + btnPlayList.NavigateDown = btnTop.GetID; + listSongs.NavigateLeft = btnTop.GetID; + listSongs.Clear(); + if (g_Player.Playing) + { + // Temp hack + btnPlayList.NavigateDown = 99; + btnTop.NavigateUp = 99; + } + GUIPropertyManager.SetProperty("#itemcount", ""); + } + else + { + btnNextPage.Visible = true; + btnPreviousPage.Visible = true; + btnBack.Visible = true; + btnPlayAll.Visible = true; + + btnTop.Visible = false; + btnSearch.Visible = false; + btnFavorites.Visible = false; + btnGenre.Visible = false; + btnNew.Visible = false; + btnCountry.Visible = false; + + + btnPlayList.NavigateUp = btnPlayAll.GetID; + btnPlayList.NavigateDown = btnBack.GetID; + + listSongs.NavigateLeft = btnBack.GetID; + miSelectedIndex = 0; + + String lsItemCount = string.Empty; + + switch (CURRENT_STATE) + { + case (int)State.FAVORITE: + lsItemCount = GUILocalizeStrings.Get(932) + " - " + moFavoriteManager.getSelectedFavorite(); + break; + case (int)State.GENRE: + lsItemCount = String.Format("{0} {1} - {2} {3} ", GUILocalizeStrings.Get(174), msSelectedGenre, GUILocalizeStrings.Get(30009), moGenre.getCurrentPageNumber()); + break; + case (int)State.NEW: + lsItemCount = GUILocalizeStrings.Get(30002) + " - " + GUILocalizeStrings.Get(30009) + " " + moNewVideos.getCurrentPageNumber(); + break; + case (int)State.SEARCH: + lsItemCount = String.Format(GUILocalizeStrings.Get(30010), moYahooSearch.getLastSearchText(), moYahooSearch.getCurrentPageNumber()); + break; + case (int)State.TOP: + lsItemCount = GUILocalizeStrings.Get(30001) + " " + GUILocalizeStrings.Get(30008) + " " + moTopVideos.getFirstVideoRank() + "-" + moTopVideos.getLastVideoRank(); + break; + + } + //GUIPropertyManager.SetProperty("#header.label", lsHeaderLbl); + //GUIPropertyManager.SetProperty("#selecteditem", lsSelectedItem); + GUIPropertyManager.SetProperty("#itemcount", lsItemCount); + } + } + #endregion + } +} Added: trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoPlaylist.cs =================================================================== --- trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoPlaylist.cs (rev 0) +++ trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoPlaylist.cs 2008-07-17 19:34:36 UTC (rev 1928) @@ -0,0 +1,792 @@ +#region Copyright (C) 2005-2008 Team MediaPortal + +/* + * Copyright (C) 2005-2008 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; + +using MediaPortal.GUI.Library; +using MediaPortal.Util; +using MediaPortal.Player; +using MediaPortal.Playlists; +using MediaPortal.TagReader; +using MediaPortal.Dialogs; +using MediaPortal.MusicVideos.Database; + + +namespace MediaPortal.GUI.MusicVideos +{ + /// <summary> + /// Summary description for Class1. + /// </summary> + public class GUIMusicVideoPlayList : GUIWindow + { + #region Base variabeles + DirectoryHistory m_history = new DirectoryHistory(); + string m_strDirectory = string.Empty; + int m_iItemSelected = -1; + int m_iLastControl = 0; + + string m_strCurrentFile = string.Empty; + string m_playlist = string.Empty; + PlayListPlayer playlistPlayer; + protected string _currentPlaying; + #endregion + [SkinControlAttribute(39)] + protected GUIButtonControl btnMyPlaylists = null; + [SkinControlAttribute(20)] + protected GUIButtonControl btnShuffle = null; + [SkinControlAttribute(21)] + protected GUIButtonControl btnSave = null; + [SkinControlAttribute(22)] + protected GUIButtonControl btnClear = null; + [SkinControlAttribute(23)] + protected GUIButtonControl btnPlay = null; + [SkinControlAttribute(24)] + protected GUIButtonControl btnNext = null; + [SkinControlAttribute(25)] + protected GUIButtonControl btnPrevious = null; + [SkinControlAttribute(50)] + protected GUIFacadeControl facadeView = null; + + private int WINDOW_ID = 4735; + + public GUIMusicVideoPlayList() + { + GetID = WINDOW_ID; + playlistPlayer = PlayListPlayer.SingletonPlayer; + } + + #region overrides + public override bool Init() + { + m_strDirectory = System.IO.Directory.GetCurrentDirectory(); + GUIWindowManager.Receivers += new SendMessageHandler(OnThreadMessage); + return Load(GUIGraphicsContext.Skin + @"\mymusicvideoplaylist.xml"); + } + public override int GetID + { + get + { + return WINDOW_ID; + } + set + { + base.GetID = value; + } + } + + public override void OnAction(Action action) + { + if (action.wID == Action.ActionType.ACTION_SHOW_PLAYLIST) + { + GUIWindowManager.ShowPreviousWindow(); + return; + } + + else if (action.wID == Action.ActionType.ACTION_MOVE_SELECTED_ITEM_UP) + MovePlayListItemUp(); + + else if (action.wID == Action.ActionType.ACTION_MOVE_SELECTED_ITEM_DOWN) + MovePlayListItemDown(); + + else if (action.wID == Action.ActionType.ACTION_DELETE_SELECTED_ITEM) + DeletePlayListItem(); + + // Handle case where playlist has been stopped and we receive a player action. + // This allows us to restart the playback proccess... + else if (action.wID == Action.ActionType.ACTION_MUSIC_PLAY + || action.wID == Action.ActionType.ACTION_NEXT_ITEM + || action.wID == Action.ActionType.ACTION_PAUSE + || action.wID == Action.ActionType.ACTION_PREV_ITEM + ) + { + if (playlistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_VIDEO) + { + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + + if (g_Player.CurrentFile == "") + { + PlayList playList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + + if (playList != null && playList.Count > 0) + { + playlistPlayer.Play(0); + UpdateButtonStates(); + } + } + } + } + + base.OnAction(action); + } + + protected override void OnPageLoad() + { + base.OnPageLoad(); + facadeView.View = GUIFacadeControl.ViewMode.Playlist; + + // Disable Playlist if no playlists exists + ArrayList loPlayListNames = MusicVideoDatabase.getInstance().getPlaylists(); + if (loPlayListNames.Count == 0) + btnMyPlaylists.Disabled = true; + + // If nothing in list - disable save button + if (facadeView.Count == 0) + btnSave.Disabled = true; + + LoadDirectory(string.Empty); + if (m_iItemSelected >= 0) + { + GUIControl.SelectItemControl(GetID, facadeView.GetID, m_iItemSelected); + } + if ((m_iLastControl == facadeView.GetID) && facadeView.Count <= 0) + { + m_iLastControl = btnShuffle.GetID; + GUIControl.FocusControl(GetID, m_iLastControl); + } + if (facadeView.Count <= 0) + { + GUIControl.FocusControl(GetID, btnShuffle.GetID); + } + SelectCurrentPlayingSong(); + } + + protected override void OnPageDestroy(int newWindowId) + { + m_iItemSelected = facadeView.SelectedListItemIndex; + base.OnPageDestroy(newWindowId); + } + + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + base.OnClicked(controlId, control, actionType); + if (control == btnShuffle) + { + ShufflePlayList(); + } + else if (control == btnSave) + { + SavePlayList(); + } + else if (control == btnClear) + { + ClearPlayList(); + } + else if (control == btnPlay) + { + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + playlistPlayer.Reset(); + playlistPlayer.Play(0); + UpdateButtonStates(); + } + else if (control == btnNext) + { + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + playlistPlayer.PlayNext(); + SelectCurrentPlayingSong(); + } + else if (control == btnPrevious) + { + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + playlistPlayer.PlayPrevious(); + SelectCurrentPlayingSong(); + } + else if (control == facadeView) + { + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + playlistPlayer.Reset(); + playlistPlayer.Play(facadeView.SelectedListItemIndex); + UpdateButtonStates(); + } + else if (control == btnMyPlaylists) + { + LoadPlayList(); + } + } + + public override bool OnMessage(GUIMessage message) + { + switch (message.Message) + { + case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STOPPED: + { + for (int i = 0; i < facadeView.Count; ++i) + { + GUIListItem item = facadeView[i]; + if (item != null && item.Selected) + { + item.Selected = false; + break; + } + } + + UpdateButtonStates(); + } + break; + + case GUIMessage.MessageType.GUI_MSG_PLAYLIST_CHANGED: + { + //global playlist changed outside playlist window + if (m_iLastControl == facadeView.GetID && facadeView.Count <= 0) + { + m_iLastControl = btnShuffle.GetID; + GUIControl.FocusControl(GetID, m_iLastControl); + } + + SelectCurrentPlayingSong(); + } + break; + } + return base.OnMessage(message); + } + + protected void UpdateButtonStates() + { + + if (facadeView.Count > 0) + { + btnShuffle.Disabled = false; + btnSave.Disabled = false; + btnClear.Disabled = false; + btnPlay.Disabled = false; + if (g_Player.Playing && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_VIDEO) + { + btnNext.Disabled = false; + btnPrevious.Disabled = false; + btnPlay.NavigateDown = btnNext.GetID; + // Temp hack + btnPrevious.NavigateDown = 99; + btnMyPlaylists.NavigateUp = 99; + } + else + { + btnNext.Disabled = true; + btnPrevious.Disabled = true; + + btnPlay.NavigateDown = btnMyPlaylists.GetID; + btnMyPlaylists.NavigateUp = btnPlay.GetID; + } + } + else + { + btnShuffle.Disabled = true; + btnSave.Disabled = true; + btnClear.Disabled = true; + btnPlay.Disabled = true; + btnNext.Disabled = true; + btnPrevious.Disabled = true; + } + + //disable shuffle/save/previous if party shuffle is on + } + + protected void OnClick(int iItem) + { + GUIListItem item = facadeView.SelectedListItem; + if (item == null) + return; + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + playlistPlayer.Reset(); + playlistPlayer.Play(iItem); + SelectCurrentPlayingSong(); + UpdateButtonStates(); + } + + protected void OnQueueItem(int iItem) + { + RemovePlayListItem(iItem); + } + + public override void Process() + { + if (!m_strCurrentFile.Equals(g_Player.CurrentFile)) + { + m_strCurrentFile = g_Player.CurrentFile; + GUIMessage msg; + if (g_Player.Playing) + { + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYLIST_CHANGED, GetID, 0, 0, 0, 0, null); + OnMessage(msg); + } + else + { + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STOPPED, GetID, 0, 0, 0, 0, null); + OnMessage(msg); + } + } + } + + #endregion + void OnThreadMessage(GUIMessage message) + { + switch (message.Message) + { + case GUIMessage.MessageType.GUI_MSG_PLAYBACK_ENDED: + break; + + //special case for when the next button is pressed - stopping the prev song does not cause a Playback_Ended event + case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED: + break; + } + } + + + protected void LoadDirectory(string strNewDirectory) + { + GUIWaitCursor.Show(); + TimeSpan totalPlayingTime = new TimeSpan(); + GUIListItem SelectedItem = facadeView.SelectedListItem; + if (SelectedItem != null) + { + if (SelectedItem.IsFolder && SelectedItem.Label != "..") + { + m_history.Set(SelectedItem.Label, m_strDirectory); + } + } + m_strDirectory = strNewDirectory; + GUIControl.ClearControl(GetID, facadeView.GetID); + + List<GUIListItem> itemlist = new List<GUIListItem>(); + + PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + + + string strFileName; + YahooVideo loVideo; + for (int i = 0; i < playlist.Count; ++i) + { + MVPlayListItem loPlayListItem = (MVPlayListItem)playlist[i]; + loVideo = loPlayListItem.YahooVideo; + + GUIListItem pItem = new GUIListItem(loVideo.artistName + " - " + loVideo.songName); + pItem.Path = loVideo.songId; + pItem.MusicTag = loPlayListItem.MusicTag; + pItem.IsFolder = false; + + MediaPortal.Util.Utils.SetDefaultIcons(pItem); + if (loPlayListItem.Played) + { + pItem.Shaded = true; + } + + if (loPlayListItem.Duration > 0) + pItem.Label2 = MediaPortal.Util.Utils.SecondsToHMSString(loPlayListItem.Duration); + else + pItem.Label2 = string.Empty; + + itemlist.Add(pItem); + } + + strFileName = string.Empty; + + string strSelectedItem = m_history.Get(m_strDirectory); + int iItem = 0; + foreach (GUIListItem item in itemlist) + { + MusicTag tag = item.MusicTag as MusicTag; + if (tag != null) + { + if (tag.Duration > 0) + totalPlayingTime = totalPlayingTime.Add(new TimeSpan(0, 0, tag.Duration)); + } + facadeView.Add(item); + // synchronize playlist with current directory + if (strFileName.Length > 0 && item.Path == strFileName) + { + item.Selected = true; + } + } + int iTotalItems = itemlist.Count; + if (itemlist.Count > 0) + { + GUIListItem rootItem = itemlist[0]; + if (rootItem.Label == "..") iTotalItems--; + } + + //set object count label + if (totalPlayingTime.Seconds > 0) + GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetSongCountLabel(iTotalItems, (int)totalPlayingTime.TotalSeconds)); + else + GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetObjectCountLabel(iTotalItems)); + + SetLabels(); + for (int i = 0; i < facadeView.Count; ++i) + { + GUIListItem item = facadeView[i]; + if (item.Label == strSelectedItem) + { + GUIControl.SelectItemControl(GetID, facadeView.GetID, iItem); + break; + } + iItem++; + } + for (int i = 0; i < facadeView.Count; ++i) + { + GUIListItem item = facadeView[i]; + if (item.Path.Equals(_currentPlaying, StringComparison.OrdinalIgnoreCase)) + { + item.Selected = true; + break; + } + } + UpdateButtonStates(); + GUIWaitCursor.Hide(); + } + + + + void LoadPlayList() + { + ArrayList loPlayListNames = MusicVideoDatabase.getInstance().getPlaylists(); + GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + if (dlgSel == null) + return; + dlgSel.Reset(); + + foreach (String lsName in loPlayListNames) + { + dlgSel.Add(lsName); + } + + dlgSel.SetHeading(GUILocalizeStrings.Get(983)); // My Playlists + dlgSel.DoModal(GetID); + int SelectedId = dlgSel.SelectedId; + if (SelectedId == 0) + return; + + Log.Debug("Selected playlist :{0}", loPlayListNames[SelectedId - 1]); + + m_playlist = loPlayListNames[SelectedId - 1].ToString(); + List<YahooVideo> videos = MusicVideoDatabase.getInstance().getPlayListVideos(loPlayListNames[SelectedId - 1].ToString()); + PlayList playList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + playList.Clear(); + MVPlayListItem item; + foreach (YahooVideo video in videos) + { + item = new MVPlayListItem(); + item.YahooVideo = video; + item.Description = video.artistName + "-" + video.songName; + playList.Add(item); + } + LoadDirectory(string.Empty); + + } + + void ClearPlayList() + { + if (m_playlist != string.Empty) + { + GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); + if (null == dlgYesNo) + return; + dlgYesNo.SetHeading(GUILocalizeStrings.Get(117)); + dlgYesNo.SetLine(1, m_playlist); + dlgYesNo.SetDefaultToYes(false); + dlgYesNo.DoModal(GetID); + if (dlgYesNo.IsConfirmed) + { + MusicVideoDatabase.getInstance().DeletePlaylist(m_playlist); + } + m_playlist = string.Empty; + } + GUIControl.ClearControl(GetID, facadeView.GetID); + playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO).Clear(); + if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_VIDEO) + playlistPlayer.Reset(); + LoadDirectory(string.Empty); + UpdateButtonStates(); + GUIControl.FocusControl(GetID, btnMyPlaylists.GetID); + } + + + void RemovePlayListItem(int iItem) + { + + GUIListItem pItem = facadeView[iItem]; + if (pItem == null) return; + //string strFileName = pItem.Path; + + PlayList loPlayList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + string strFileName = string.Empty; + foreach (MVPlayListItem loItem in loPlayList) + { + loItem.UpdateUrl = false; + YahooVideo loVideo = loItem.YahooVideo; + if (loVideo.songId.Equals(pItem.Path)) + { + strFileName = loItem.FileName; + } + } + + playlistPlayer.Remove(PlayListType.PLAYLIST_MUSIC_VIDEO, strFileName); + foreach (MVPlayListItem loItem in loPlayList) + { + loItem.UpdateUrl = true; + } + + LoadDirectory(m_strDirectory); + UpdateButtonStates(); + GUIControl.SelectItemControl(GetID, facadeView.GetID, iItem); + SelectCurrentPlayingSong(); + } + + void ShufflePlayList() + { + + GUIControl.ClearControl(GetID, facadeView.GetID); + PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + + if (playlist.Count <= 0) return; + string strFileName = string.Empty; + if (playlistPlayer.CurrentSong >= 0) + { + if (g_Player.Playing && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_VIDEO) + { + PlayListItem item = playlist[playlistPlayer.CurrentSong]; + strFileName = item.FileName; + } + } + playlist.Shuffle(); + if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_VIDEO) + playlistPlayer.Reset(); + + if (strFileName.Length > 0) + { + for (int i = 0; i < playlist.Count; i++) + { + PlayListItem item = playlist[i]; + if (item.FileName == strFileName) + playlistPlayer.CurrentSong = i; + } + } + + LoadDirectory(m_strDirectory); + + SelectCurrentPlayingSong(); + } + + + void SavePlayList() + { + string newFileName = m_playlist; + if (GetKeyboard(ref newFileName)) + { + Cursor.Current = Cursors.WaitCursor; + PlayList loPlaylist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + YahooVideo loVideo; + MusicVideoDatabase loDatabase = MusicVideoDatabase.getInstance(); + loDatabase.createPlayList(newFileName); + int i = 0; + foreach (MVPlayListItem loPlayListItem in loPlaylist) + { + i++; + loVideo = loPlayListItem.YahooVideo; + loDatabase.addPlayListVideo(newFileName, loVideo, i); + } + Cursor.Current = Cursors.Default; + } + } + + void SelectCurrentPlayingSong() + { + if (g_Player.Playing && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_VIDEO) + { + // delete prev. selected item + for (int i = 0; i < facadeView.Count; ++i) + { + GUIListItem item = facadeView[i]; + if (item != null && item.Selected) + { + item.Selected = false; + break; + } + } + + // set current item selected + int iSong = playlistPlayer.CurrentSong; + if (iSong >= 0 && iSong <= facadeView.Count) + { + GUIControl.SelectItemControl(GetID, facadeView.GetID, iSong); + GUIListItem item = facadeView[iSong]; + if (item != null) item.Selected = true; + } + } + } + + private void MovePlayListItemUp() + { + if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_NONE) + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + + if (playlistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_VIDEO + || facadeView.View != GUIFacadeControl.ViewMode.Playlist + || facadeView.PlayListView == null) + { + return; + } + + int iItem = facadeView.SelectedListItemIndex; + + // Prevent moving backwards past the top song in the list + + PlayList playList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + playList.MovePlayListItemUp(iItem); + int selectedIndex = facadeView.MoveItemUp(iItem, true); + + if (iItem == playlistPlayer.CurrentSong) + playlistPlayer.CurrentSong = selectedIndex; + + facadeView.SelectedListItemIndex = selectedIndex; + UpdateButtonStates(); + + } + + private void MovePlayListItemDown() + { + if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_NONE) + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + + if (playlistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_VIDEO + || facadeView.View != GUIFacadeControl.ViewMode.Playlist + || facadeView.PlayListView == null) + { + return; + } + + int iItem = facadeView.SelectedListItemIndex; + PlayList playList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + + // Prevent moving fowards past the last song in the list + // as this would cause the currently playing song to scroll + // off of the list view... + + playList.MovePlayListItemDown(iItem); + int selectedIndex = facadeView.MoveItemDown(iItem, true); + + if (iItem == playlistPlayer.CurrentSong) + playlistPlayer.CurrentSong = selectedIndex; + + facadeView.SelectedListItemIndex = selectedIndex; + + UpdateButtonStates(); + + } + + private void DeletePlayListItem() + { + if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_NONE) + playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_VIDEO; + + if (playlistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_MUSIC_VIDEO + || facadeView.View != GUIFacadeControl.ViewMode.Playlist + || facadeView.PlayListView == null) + { + return; + } + + int iItem = facadeView.SelectedListItemIndex; + + string currentFile = g_Player.CurrentFile; + GUIListItem item = facadeView[iItem]; + PlayList loPlayList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_VIDEO); + //string strFileName = string.Empty; + MVPlayListItem loItemToDelete = null; + foreach (MVPlayListItem loItem in loPlayList) + { + YahooVideo loVideo = loItem.YahooVideo; + //string lsDesc = loVideo.artistName + " - " + loVideo.songName; + if (loVideo.songId.Equals(item.Path)) + { + loItemToDelete = loItem; + } + } + RemovePlayListItem(iItem); + if (loItemToDelete != null) + { + loItemToDelete.UpdateUrl = false; + if (currentFile.Length > 0 && currentFile == item.Path) + { + string nextTrackPath = PlayListPlayer.SingletonPlayer.GetNext(); + + if (nextTrackPath.Length == 0) + g_Player.Stop(); + + else + { + if (iItem == facadeView.Count) + playlistPlayer.Play(iItem - 1); + + else + playlistPlayer.PlayNext(); + } + } + loItemToDelete.UpdateUrl = true; + } + + if (facadeView.Count == 0) + g_Player.Stop(); + + else + facadeView.PlayListView.SelectedListItemIndex = iItem; + + UpdateButtonStates(); + + } + + protected void SetLabels() + { + for (int i = 0; i < facadeView.Count; ++i) + { + GUIListItem item = facadeView[i]; + MusicTag tag = (MusicTag)item.MusicTag; + if (tag != null) + { + //int playCount = tag.TimesPlayed; + string duration = MediaPortal.Util.Utils.SecondsToHMSString(tag.Duration); + item.Label = string.Format("{0} - {1}", tag.Artist, tag.Title); + item.Label2 = duration; + } + } + } + + protected bool GetKeyboard(ref string strLine) + { + VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)Window.WINDOW_VIRTUAL_KEYBOARD); + if (null == keyboard) return false; + keyboard.Reset(); + keyboard.Text = strLine; + keyboard.DoModal(GetID); + if (keyboard.IsConfirmed) + { + strLine = keyboard.Text; + return true; + } + return false; + } + + } +} \ No newline at end of file Added: trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.cs =================================================================== --- trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.cs (rev 0) +++ trunk/plugins/MyMusicVideos/MyMusicVideos/GUIMusicVideoSetupFavoritesForm.cs 2008-07-17 19:34:36 UTC (rev 1928) @@ -0,0 +1,65 @@ +#region Copyright (C) 2005-2008 Team MediaPortal + +/* + * Copyright (C) 2005-2008 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace MediaPortal.GUI.MusicVideos +{ + public partial class SetupFavoriteForm : MediaPortal.UserInterface.Controls.MPConfigForm + { + + //private int miFavoriteId; + + public SetupFavoriteForm() + { + InitializeComponent(); + //msFavoriteName = ""; + } + + private void SetupFavoriteForm_Load(object sender, EventArgs e) + ... [truncated message content] |