/// <summary> /// Add current view to the screen navigation stack and optioanlly reset the stack if requested /// </summary> /// <param name="activeView"></param> /// <param name="resetStack"></param> private void addToStack(MvView activeView, bool resetStack) { if (resetStack) screenStack.Clear(); if (TopWindow == MvView.AllAlbums && activeView == MvView.Video) activeView = MvView.VideosOnAlbum; if (TopWindow == MvView.Genres && activeView == MvView.Artist) activeView = MvView.ArtistViaGenre; if (screenStack.Count == 0) { screenStack.Add(activeView); return; } if (!screenStack.Contains(activeView)) screenStack.Add(activeView); }
/// <summary> /// Display Artists that match select genre /// </summary> private void DisplayByGenre(string genre) { _lastViewedGenre = genre; _currentView = MvView.Artist; addToStack(_currentView, false); List<DBArtistInfo> artistList = new List<DBArtistInfo>(); List<DBArtistInfo> artistFullList = DBArtistInfo.GetAll(); logger.Debug("Checking for matches for Genre : " + genre); foreach (DBArtistInfo artistInfo in artistFullList) { if (tagMatched(genre, artistInfo) || string.Equals(genre, artistInfo.Genre,StringComparison.OrdinalIgnoreCase)) { if (!artistList.Contains(artistInfo)) artistList.Add(artistInfo); } } GUIPropertyManager.SetProperty("#mvCentral.Hierachy", Localization.Genre + " | " + genre); GUIPropertyManager.SetProperty("#itemcount", artistList.Count.ToString()); GUIPropertyManager.SetProperty("#itemtype", Localization.Artists); GUIPropertyManager.Changed = true; MvSort sortDirection = MvSort.Ascending; // Sort Artists if (sortDirection == MvSort.Ascending) artistList.Sort(delegate(DBArtistInfo p1, DBArtistInfo p2) { return p1.Artist.CompareTo(p2.Artist); }); else artistList.Sort(delegate(DBArtistInfo p1, DBArtistInfo p2) { return p2.Artist.CompareTo(p1.Artist); }); // Clear the facade and load the artists GUIControl.ClearControl(GetID, facadeLayout.GetID); foreach (DBArtistInfo artistData in artistList) { GUIListItem facadeItem = new GUIListItem(); facadeItem.Label = artistData.Artist; if (string.IsNullOrEmpty(artistData.ArtFullPath.Trim())) facadeItem.ThumbnailImage = artistTrackArt(artistData); else facadeItem.ThumbnailImage = artistData.ArtFullPath; facadeItem.TVTag = mvCentralUtils.bioNoiseFilter(artistData.bioContent); facadeItem.AlbumInfoTag = mvCentralUtils.bioNoiseFilter(artistData.bioContent); facadeItem.ItemId = (int)artistData.ID; facadeItem.IsFolder = true; facadeItem.MusicTag = artistData; facadeItem.OnItemSelected += new GUIListItem.ItemSelectedHandler(onArtistSelected); facadeLayout.Add(facadeItem); foreach (string artistTag in artistData.Tag) { if (!artistTags.Contains(artistTag)) { if (artistTag != artistData.Artist) artistTags.Add(artistTag); } } } artistTags.Sort(delegate(string p1, string p2) { return p1.CompareTo(p2); }); // If first time though set properites to first item in facade if (facadeLayout.Count > 0) { facadeLayout.SelectedListItemIndex = 0; onArtistSelected(facadeLayout.SelectedListItem, facadeLayout); } GUIPropertyManager.SetProperty("#mvCentral.ArtistView", "true"); GUIPropertyManager.SetProperty("#mvCentral.TrackView", "false"); GUIPropertyManager.SetProperty("#mvCentral.AlbumView", "false"); GUIPropertyManager.SetProperty("#mvCentral.GenreView", "false"); GUIPropertyManager.Changed = true; }
/// <summary> /// Initial load of GUI /// </summary> protected override void OnPageLoad() { InitViewSelections(); UpdateButtonStates(); // If we have a video running then chances are we are exiting fullt screen...save the view as we need to go though // the page setup and that would messup the view and window stack. if (_persisting && _currentView != MvView.None) _runningView = _currentView; // Get all Artists and Tracks List<DBArtistInfo> artList = DBArtistInfo.GetAll(); List<DBTrackInfo> vidList = DBTrackInfo.GetAll(); if (artList.Count == 0 && vidList.Count == 0) { GUIPropertyManager.SetProperty("#mvCentral.ViewAs", Localization.Artists); GUIPropertyManager.SetProperty("#mvCentral.Hierachy", "Empty DB"); UserMessage("mvCentral - No Content", "There is no content to view", "", "Please setup plugin and scan in configuration"); _currentView = MvView.None; addToStack(_currentView, true); return; } // Set Total Artists and Video Porperties GUIPropertyManager.SetProperty("#mvCentral.TotalArtists", artList.Count + " " + Localization.Artists); GUIPropertyManager.SetProperty("#mvCentral.TotalVideos", vidList.Count + " " + Localization.Videos); // set initial view to artists - default to artist is issues with reading value try { _currentView = (MvView)int.Parse(mvCentralCore.Settings.DefaultViewAs); } catch { _currentView = MvView.Artist; mvCentralCore.Settings.DefaultViewAs = ((int)_currentView).ToString(); } // Check for invalid view - should actually store the corrected one against checking here...on the todo list :) // // Check for genres view select but none now defined if ((DBGenres.GetSelected().Count == 0 && _currentView == MvView.Genres)) { _currentView = MvView.Artist; mvCentralCore.Settings.DefaultViewAs = ((int)_currentView).ToString(); } // Also check for albums if ((DBAlbumInfo.GetAll().Count == 0 && _currentView == MvView.AllAlbums)) { _currentView = MvView.Artist; mvCentralCore.Settings.DefaultViewAs = ((int)_currentView).ToString(); } // Invalid start up view check - do not the album that was last viewed so set allAlbums if (_currentView == MvView.VideosOnAlbum) _currentView = MvView.AllAlbums; // and dont know what the arist was so default to artist view if (_currentView == MvView.ArtistViaGenre) _currentView = MvView.Artist; // Exit from fullscreen - restore save view and dont re-init window stack if (_persisting && _runningView != MvView.None) _currentView = _runningView; else { addToStack(_currentView, true); } setViewAsProperty(_currentView); logger.Info("GUI - Loaded ViewAs : {0}", _currentView.ToString()); // Read last used layout from and set, default to list if not yet stored if (mvCentralCore.Settings.DefaultView == "lastused") { CurrentLayout = Layout.List; mvCentralCore.Settings.DefaultView = ((int)CurrentLayout).ToString(); } else CurrentLayout = (Layout)int.Parse(mvCentralCore.Settings.DefaultView); logger.Info("GUI - Loaded Layout : {0}", CurrentLayout.ToString()); SwitchLayout(); UpdateButtonStates(); GUIPropertyManager.Changed = true; if (btnSortBy != null) { btnSortBy.SortChanged += new SortEventHandler(SortChanged); } if (_loadParameter != null) processParameter(); _persisting = true; base.OnPageLoad(); }
/// <summary> /// List Available views - Windowsplugin Class override /// </summary> protected override void SetView(int selectedViewId) { // Display Artists, tracks or Albums logger.Debug("SetView Called: View {0}", selectedViewId); _persisting = false; // Bit messy this but only way if (selectedViewId == (int)View.Artists) { _currentView = MvView.Artist; loadArtists(artistSort); addToStack(_currentView, true); } else if (selectedViewId == (int)View.Albums) { _currentView = MvView.AllAlbums; addToStack(_currentView, true); loadAllAlbums(); } else if (selectedViewId == (int)View.Tracks) { _currentView = MvView.AllVideos; addToStack(_currentView, true); loadAllVideos(_videoSort); } else if (selectedViewId == (int)View.Generes) { _currentView = MvView.Genres; addToStack(_currentView, true); loadGenres(); } else if (selectedViewId == (int)View.DvDs) { _currentView = MvView.DvdView; addToStack(_currentView, true); loadDVDs(); } logger.Debug("SwitchLayout: Storing MvView {0} and View {1}", _currentView, selectedViewId); mvCentralCore.Settings.DefaultViewAs = ((int)_currentView).ToString(CultureInfo.InvariantCulture); mvCentralCore.Settings.ViewAs = selectedViewId.ToString(CultureInfo.InvariantCulture); GUIControl.FocusControl(GetID, facadeLayout.GetID); setViewAsProperty(_currentView); }
/// <summary> /// Deal with user input /// </summary> /// <param name="controlId"></param> /// <param name="control"></param> /// <param name="actionType"></param> protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { base.OnClicked(controlId, control, actionType); if (control == btnLayouts) { mvCentralCore.Settings.DefaultView = ((int)CurrentLayout).ToString(); } switch (controlId) { case (int)GuiControls.PlayAllRandom: playRandomAll(); break; case (int)GuiControls.PlaySmart: playSmart(ChooseSmartPlay()); break; case (int)GuiControls.PlayList: GUIWindowManager.ActivateWindow(Player.GetWindowId()); break; case (int)GuiControls.StatsAndInfo: GUIWindowManager.ActivateWindow(GUImvStatsAndInfo.GetWindowId()); break; case (int)GuiControls.GenreConfig: SetFavoriteTags(); break; case (int)GuiControls.Search: DoSearch(); break; case (int)GuiControls.Facade: //Clicked on something in the facade logger.Debug("Hit Key : " + actionType.ToString()); switch (actionType) { case Action.ActionType.ACTION_PLAY: case Action.ActionType.ACTION_PAUSE: case Action.ActionType.ACTION_QUEUE_ITEM: case Action.ActionType.ACTION_MUSIC_PLAY: case Action.ActionType.ACTION_SELECT_ITEM: if (facadeLayout.SelectedListItem.IsFolder && ((actionType == Action.ActionType.ACTION_MUSIC_PLAY) || (actionType == Action.ActionType.ACTION_PLAY) || (actionType == Action.ActionType.ACTION_PAUSE))) { // Are we on an Artist or Album, if Artist add all tracks by artist to playlist else if album add all tracks on album to playlist if (facadeLayout.SelectedListItem.MusicTag != null && facadeLayout.SelectedListItem.MusicTag.GetType() == typeof(DBAlbumInfo)) AlbumActions(actionType); else if (facadeLayout.SelectedListItem.MusicTag != null && facadeLayout.SelectedListItem.MusicTag.GetType() == typeof(DBArtistInfo)) ArtistActions(actionType); else if (facadeLayout.SelectedListItem.MusicTag != null && facadeLayout.SelectedListItem.MusicTag.GetType() == typeof(DBGenres)) GenreActions(actionType); } else { GUIListItem selectedItem = facadeLayout.SelectedListItem; if (selectedItem.MusicTag.GetType() == typeof(DBGenres)) { DisplayByGenre(facadeLayout.SelectedListItem.Label); break; } if (!selectedItem.IsFolder && selectedItem.MusicTag != null) { // we have a track selected so add any other tracks which are on showing on the facade List<DBTrackInfo> list1 = new List<DBTrackInfo>(); for (int i = 0; i < facadeLayout.ListLayout.Count; i++) { GUIListItem trackItem = facadeLayout.ListLayout[i]; if (!trackItem.IsFolder && trackItem.MusicTag != null) { list1.Add((DBTrackInfo)trackItem.MusicTag); } } AddToPlaylist(list1, false, true, false); Player.playlistPlayer.Play(list1.IndexOf((DBTrackInfo)selectedItem.MusicTag)); if (mvCentralCore.Settings.AutoFullscreen) g_Player.ShowFullScreenWindow(); break; } //return to previous level if (facadeLayout.SelectedListItem.Label == "..") { loadCurrent(); } else { artistID = facadeLayout.SelectedListItem.ItemId; _currentView = MvView.Video; addToStack(_currentView, false); loadCurrent(); } } break; } break; } }
/// <summary> /// Handle keyboard/remote action /// </summary> /// <param name="action"></param> public override void OnAction(MediaPortal.GUI.Library.Action action) { MediaPortal.GUI.Library.Action.ActionType wID = action.wID; // Queue video to playlist if (wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_QUEUE_ITEM) { facadeLayout.SelectedListItemIndex = Player.playlistPlayer.CurrentItem; return; } // If on Track screen go back to artists screen if (wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_PREVIOUS_MENU) { artistID = CurrentArtistId; // Go Back to last view _currentView = getPreviousView(); // Have we backed out to the last screen, if so exit otherwise load the previous screen if (_currentView == MvView.None) base.OnAction(action); else loadCurrent(); } else if (wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_CONTEXT_MENU) { string contextChoice = ShowContextMenu(); if (contextChoice == Localization.AddToPlaylist) { //Add to playlist // If on a folder add all Videos for Artist if (facadeLayout.ListLayout.SelectedListItem.IsFolder) { _currArtist = DBArtistInfo.Get(facadeLayout.ListLayout.SelectedListItem.Label); var allTracksByArtist = DBTrackInfo.GetEntriesByArtist(_currArtist); AddToPlaylist(allTracksByArtist, false, mvCentralCore.Settings.ClearPlaylistOnAdd, mvCentralCore.Settings.GeneratedPlaylistAutoShuffle); } else { // Add video to playlist var playlist = Player.playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MVCENTRAL); var filename = facadeLayout.ListLayout.SelectedListItem.Label; var path = facadeLayout.ListLayout.SelectedListItem.Path; var video = (DBTrackInfo)facadeLayout.ListLayout.SelectedListItem.MusicTag; var p1 = new PlayListItem(video); p1.Track = video; playlist.Add(p1); } } else if (contextChoice == Localization.AddAllToPlaylist) { // Add all videos to the playlist var allTracks = DBTrackInfo.GetAll(); AddToPlaylist(allTracks, false, mvCentralCore.Settings.ClearPlaylistOnAdd, mvCentralCore.Settings.GeneratedPlaylistAutoShuffle); } else if (contextChoice == Localization.AddToPlaylistNext) { // Add video as next playlist item addToPlaylistNext(facadeLayout.SelectedListItem); } else if (contextChoice == Localization.RefreshArtwork) { // Refresh the artwork if (facadeLayout.ListLayout.SelectedListItem.IsFolder) { _currArtist = DBArtistInfo.Get(facadeLayout.SelectedListItem.Label); GUIWaitCursor.Show(); mvCentralCore.DataProviderManager.GetArt(_currArtist, false); GUIWaitCursor.Hide(); facadeLayout.SelectedListItem.ThumbnailImage = _currArtist.ArtThumbFullPath; facadeLayout.SelectedListItem.RefreshCoverArt(); facadeLayout.SelectedListItemIndex = facadeLayout.SelectedListItemIndex - 1; facadeLayout.SelectedListItemIndex = facadeLayout.SelectedListItemIndex + 1; } else { var video = (DBTrackInfo)facadeLayout.ListLayout.SelectedListItem.MusicTag; GUIWaitCursor.Show(); mvCentralCore.DataProviderManager.GetArt(video, false); GUIWaitCursor.Hide(); facadeLayout.SelectedListItem.ThumbnailImage = video.ArtFullPath; facadeLayout.SelectedListItem.RefreshCoverArt(); facadeLayout.SelectedListItemIndex = facadeLayout.SelectedListItemIndex - 1; facadeLayout.SelectedListItemIndex = facadeLayout.SelectedListItemIndex + 1; } } else if (contextChoice == Localization.RateVid) { // Allow user rating of video OnSetRating(facadeLayout.SelectedListItemIndex); } } else base.OnAction(action); }
/// <summary> /// Set the localised View As string /// </summary> /// <param name="viewAs"></param> private void setViewAsProperty(MvView viewAs) { switch (viewAs) { case MvView.Artist: GUIPropertyManager.SetProperty("#mvCentral.ViewAs", Localization.Artists); break; case MvView.AllAlbums: GUIPropertyManager.SetProperty("#mvCentral.ViewAs", Localization.Albums); break; case MvView.AllVideos: GUIPropertyManager.SetProperty("#mvCentral.ViewAs", Localization.Videos); break; case MvView.Genres: GUIPropertyManager.SetProperty("#mvCentral.ViewAs", Localization.Genre); break; case MvView.DvdView: GUIPropertyManager.SetProperty("#mvCentral.ViewAs", "Music DVD"); break; } GUIPropertyManager.Changed = true; }
/// <summary> /// Load Videos for this Album /// </summary> /// <param name="AlbumID"></param> private void LoadTracksOnAlbum(int AlbumID) { // Set View _currentView = MvView.VideosOnAlbum; addToStack(_currentView, false); GUIPropertyManager.SetProperty("#mvCentral.Hierachy", Localization.Album + " | " + DBAlbumInfo.Get(AlbumID)); DBAlbumInfo currAlbum = DBAlbumInfo.Get(AlbumID); List<DBTrackInfo> trackList = DBTrackInfo.GetEntriesByAlbum(currAlbum); // this.albumID = AlbumID; // Clear facade and load tracks if we dont already have them loaded GUIControl.ClearControl(GetID, facadeLayout.GetID); foreach (DBTrackInfo track in trackList) { GUIListItem item = new GUIListItem(); if (mvCentralCore.Settings.DisplayRawTrackText) { if (Path.GetFileName(track.LocalMedia[0].File.FullName).Contains("-")) item.Label = Regex.Match(Path.GetFileName(track.LocalMedia[0].File.FullName), @"(?:[\s-:;]{2,}|(?!.+?[\s-:;]{2,})\-)(?<track>[^\\$]*)\.").Groups["track"].Value; else item.Label = (Path.GetFileNameWithoutExtension(track.LocalMedia[0].File.FullName)); item.Label = Regex.Replace(item.Label, @"\s*[{].*?[}]\s*", string.Empty, RegexOptions.IgnoreCase); } else item.Label = track.Track; if (string.IsNullOrEmpty(track.ArtFullPath.Trim())) item.ThumbnailImage = "defaultAlbum.png"; else item.ThumbnailImage = track.ArtFullPath; item.TVTag = mvCentralUtils.bioNoiseFilter(track.bioContent); _selAlbum = currAlbum.Album; item.Path = track.LocalMedia[0].File.FullName; item.IsFolder = false; item.OnItemSelected += new GUIListItem.ItemSelectedHandler(onVideoSelected); item.MusicTag = track; item.ItemId = (int)currAlbum.ID; item.Rating = track.Rating; facadeLayout.Add(item); } // Always set index for first track if (facadeLayout.Count > 0 ) { if (lastItemVid > 0 && lastItemVid < facadeLayout.Count) facadeLayout.SelectedListItemIndex = lastItemVid; else facadeLayout.SelectedListItemIndex = 0; logger.Debug("(LoadTracksOnAlbum) Facade Selected Index set to {0}", facadeLayout.SelectedListItemIndex); onVideoSelected(facadeLayout.SelectedListItem, facadeLayout); } GUIPropertyManager.SetProperty("#itemcount", facadeLayout.Count.ToString()); GUIPropertyManager.SetProperty("#itemtype", Localization.Videos); // Set the view GUIPropertyManager.SetProperty("#mvCentral.ArtistView", "false"); GUIPropertyManager.SetProperty("#mvCentral.AlbumView", "false"); GUIPropertyManager.SetProperty("#mvCentral.TrackView", "true"); GUIPropertyManager.SetProperty("#mvCentral.GenreView", "false"); GUIPropertyManager.SetProperty("#mvCentral.DVDView", "false"); // Tell property manager we have changed something GUIPropertyManager.Changed = true; }
/// <summary> /// Create facade with the artists supplied in the list /// </summary> /// <param name="artistObjectList"></param> private void LoadSearchedArtists(List<DBArtistInfo> artistList, MvSort sortDirection) { // Set View _currentView = MvView.SearchedArtists; addToStack(_currentView, false); GUIPropertyManager.SetProperty("#mvCentral.Hierachy", Localization.Artists); GUIPropertyManager.SetProperty("#itemcount", artistList.Count.ToString()); GUIPropertyManager.SetProperty("#itemtype", Localization.Artists); GUIPropertyManager.Changed = true; // Sort Artists if (sortDirection == MvSort.Ascending) artistList.Sort(delegate(DBArtistInfo p1, DBArtistInfo p2) { return p1.Artist.CompareTo(p2.Artist); }); else artistList.Sort(delegate(DBArtistInfo p1, DBArtistInfo p2) { return p2.Artist.CompareTo(p1.Artist); }); // Clear facade and load tracks if we dont already have them loaded GUIControl.ClearControl(GetID, facadeLayout.GetID); foreach (DBArtistInfo artistData in artistList) { GUIListItem facadeItem = new GUIListItem(); facadeItem.Label = artistData.Artist; if (string.IsNullOrEmpty(artistData.ArtFullPath.Trim())) facadeItem.ThumbnailImage = artistTrackArt(artistData); else facadeItem.ThumbnailImage = artistData.ArtFullPath; facadeItem.TVTag = mvCentralUtils.bioNoiseFilter(artistData.bioContent); facadeItem.AlbumInfoTag = mvCentralUtils.bioNoiseFilter(artistData.bioContent); facadeItem.ItemId = (int)artistData.ID; facadeItem.IsFolder = true; facadeItem.MusicTag = artistData; facadeItem.OnItemSelected += new GUIListItem.ItemSelectedHandler(onArtistSelected); facadeLayout.Add(facadeItem); foreach (string artistTag in artistData.Tag) { if (!artistTags.Contains(artistTag)) { if (artistTag != artistData.Artist) artistTags.Add(artistTag); } } } artistTags.Sort(delegate(string p1, string p2) { return p1.CompareTo(p2); }); // If first time though set properites to first item in facade if (facadeLayout.Count > 0 && !_persisting) { facadeLayout.SelectedListItemIndex = 0; onArtistSelected(facadeLayout.SelectedListItem, facadeLayout); } // Set focus to the facade GUIControl.FocusControl(GetID, facadeLayout.GetID); _persisting = true; GUIPropertyManager.SetProperty("#mvCentral.ArtistView", "true"); GUIPropertyManager.SetProperty("#mvCentral.TrackView", "false"); GUIPropertyManager.SetProperty("#mvCentral.AlbumView", "false"); GUIPropertyManager.SetProperty("#mvCentral.GenreView", "false"); GUIPropertyManager.SetProperty("#mvCentral.DVDView", "false"); clearVideoAudioProps(); GUIPropertyManager.Changed = true; }