Esempio n. 1
0
        /// <summary>
        /// this is actually loading a database view not a directory
        /// and this is done via view handler so parameter is not used
        /// but is needed to override method in base class
        /// </summary>
        /// <param name="strNotUsed">Used to implement method in base class but not used</param>
        protected override void LoadDirectory(string strNotUsed)
        {
            GUIWaitCursor.Show();
            GUIListItem SelectedItem = facadeLayout.SelectedListItem;

            int    previousLevel   = ((MusicViewHandler)handler).PreviousLevel;
            string strSelectedItem = string.Empty;

            if (SelectedItem != null)
            {
                // if there is an item selected and we are loading a new view
                // then store the existing value so when we navigate back up through
                // the view levels we can focus on the item we had selected
                // we can not use current level in the name for the directory history
                // as current level gets updated before LoadDirectory is called
                // therefore use previous level which is set by the music view handler
                // when that returns (ie. that will be level of the view user has
                // made selection from as it has not been cleared yet)
                if (SelectedItem.IsFolder && SelectedItem.Label != "..")
                {
                    m_history.Set(SelectedItem.Label, handler.LocalizedCurrentView + "." +
                                  previousLevel.ToString());
                }
            }

            List <Song> songs;

            if (!((MusicViewHandler)handler).Execute(out songs))
            {
                GUIWaitCursor.Hide();
                Action action = new Action();
                action.wID = Action.ActionType.ACTION_PREVIOUS_MENU;
                GUIGraphicsContext.OnAction(action);
                return;
            }

            GUIControl.ClearControl(GetID, facadeLayout.GetID);
            SwitchLayout();

            List <GUIListItem> itemsToAdd = new List <GUIListItem>();

            TimeSpan totalPlayingTime = new TimeSpan();

            if (previousLevel > handler.CurrentLevel)
            {
                // only need to lookup values when navigating back up through the view
                strSelectedItem = m_history.Get(handler.LocalizedCurrentView + "." + handler.CurrentLevel.ToString());
            }

            #region handle pin protected share

            if (songs.Count > 0) // some songs in there?
            {
                Song song = songs[0];
                if (song.FileName.Length > 0) // does a filename exits
                {
                    foreach (Share share in _shareList)
                    {
                        if (song.FileName.Contains(share.Path)) // compare it with shares
                        {
                            if (share.Pincode != string.Empty)  // does it have a pincode?
                            {
                                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GET_PASSWORD, 0, 0, 0, 0, 0, 0);
                                GUIWindowManager.SendMessage(msg); // ask for the userinput

                                if (msg.Label != share.Pincode)
                                {
                                    songs.Clear();
                                }
                                break;
                            }
                        }
                    }
                }
            }

            #endregion

            if (handler.CurrentLevel > 0)
            {
                // add ".." folder item if not at bottom level of view
                GUIListItem pItem = new GUIListItem("..");
                pItem.Path     = string.Empty;
                pItem.IsFolder = true;
                Util.Utils.SetDefaultIcons(pItem);
                itemsToAdd.Add(pItem);
            }

            // Get current Filter used
            var currentFilter = (FilterDefinition)handler.View.Filters[handler.CurrentLevel];

            for (int i = 0; i < songs.Count; ++i)
            {
                Song        song = songs[i];
                GUIListItem item = new GUIListItem();

                MusicTag tag = new MusicTag();
                tag = song.ToMusicTag();
                item.AlbumInfoTag = song;
                item.MusicTag     = tag;

                if (handler.CurrentLevel + 1 < handler.MaxLevels)
                {
                    item.IsFolder = true;
                    item.Label    = MusicViewHandler.GetFieldValue(song, handler.CurrentLevelWhere);

                    // If we are grouping on a specific value, we have in the Duration field the number of items
                    // Use this in the sort field
                    if (currentFilter.SqlOperator == "group")
                    {
                        item.Label2 = tag.Duration.ToString();
                    }
                    else
                    {
                        SetSortLabel(ref item, CurrentSortMethod, handler.CurrentLevelWhere);
                    }
                }
                else
                {
                    item.IsFolder = false;
                    if (!GUIMusicBaseWindow.SetTrackLabels(ref item, CurrentSortMethod))
                    {
                        item.Label = song.Title;
                    }
                }

                if (tag != null)
                {
                    if (tag.Duration > 0)
                    {
                        totalPlayingTime = totalPlayingTime.Add(new TimeSpan(0, 0, tag.Duration));
                    }
                }

                item.Path = song.FileName;

                if (!string.IsNullOrEmpty(_currentPlaying) &&
                    item.Path.Equals(_currentPlaying, StringComparison.OrdinalIgnoreCase))
                {
                    item.Selected = true;
                }

                item.Duration        = song.Duration;
                tag.TimesPlayed      = song.TimesPlayed;
                item.Rating          = song.Rating;
                item.Year            = song.Year;
                item.OnRetrieveArt  += new GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt);
                item.OnItemSelected += new GUIListItem.ItemSelectedHandler(item_OnItemSelected);
                itemsToAdd.Add(item);
            }

            itemsToAdd.Sort(new MusicSort(CurrentSortMethod, CurrentSortAsc));

            int  iItem        = 0; // used to hold index of item to select
            bool itemSelected = false;
            for (int i = 0; i < itemsToAdd.Count; ++i)
            {
                if (!itemSelected && itemsToAdd[i].Label == strSelectedItem)
                {
                    iItem        = i;
                    itemSelected = true;
                }
                facadeLayout.Add(itemsToAdd[i]);
            }

            int iTotalItems = facadeLayout.Count;
            if (iTotalItems > 0)
            {
                GUIListItem rootItem = facadeLayout[0];
                if (rootItem.Label == "..")
                {
                    iTotalItems--;
                }
            }

            //set object count label, total duration
            GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetObjectCountLabel(iTotalItems));

            if (totalPlayingTime.TotalSeconds > 0)
            {
                GUIPropertyManager.SetProperty("#totalduration",
                                               Util.Utils.SecondsToHMSString((int)totalPlayingTime.TotalSeconds));
            }
            else
            {
                GUIPropertyManager.SetProperty("#totalduration", string.Empty);
            }

            if (itemSelected)
            {
                GUIControl.SelectItemControl(GetID, facadeLayout.GetID, iItem);
            }
            else if (m_iItemSelected >= 0)
            {
                GUIControl.SelectItemControl(GetID, facadeLayout.GetID, m_iItemSelected);
            }
            else
            {
                SelectCurrentItem();
            }

            UpdateButtonStates();
            GUIWaitCursor.Hide();
        }
Esempio n. 2
0
        protected override void LoadDirectory(string strNewDirectory)
        {
            GUIWaitCursor.Show();

            currentFolder = strNewDirectory;

            GUIControl.ClearControl(GetID, facadeLayout.GetID);

            ArrayList itemlist = new ArrayList();
            ArrayList movies   = ((VideoViewHandler)handler).Execute();

            if (handler.CurrentLevel > 0)
            {
                GUIListItem listItem = new GUIListItem("..");
                listItem.Path     = string.Empty;
                listItem.IsFolder = true;
                Util.Utils.SetDefaultIcons(listItem);
                itemlist.Add(listItem);
            }

            foreach (IMDBMovie movie in movies)
            {
                GUIListItem item = new GUIListItem();
                item.Label = movie.Title;
                if (handler.CurrentLevel + 1 < handler.MaxLevels)
                {
                    item.IsFolder = true;
                }
                else
                {
                    item.IsFolder = false;
                }

                item.Path = movie.File;

                // Protected movies validation, checks item and if it is inside protected shares.
                // If item is inside PIN protected share, checks if user validate PIN with Unlock
                // command from context menu and returns "True" if all is ok and item will be visible
                // in movie list. Non-protected item will skip check and will be always visible.
                if (!string.IsNullOrEmpty(item.Path) && !CheckItem(item))
                {
                    continue;
                }
                //
                item.Duration     = movie.RunTime * 60;
                item.AlbumInfoTag = movie;
                item.Year         = movie.Year;
                item.DVDLabel     = movie.DVDLabel;
                item.Rating       = movie.Rating;
                item.IsPlayed     = movie.Watched > 0 ? true : false;

                item.OnItemSelected += new GUIListItem.ItemSelectedHandler(item_OnItemSelected);

                itemlist.Add(item);
            }

            int itemIndex = 0;

            foreach (GUIListItem item in itemlist)
            {
                facadeLayout.Add(item);
            }
            // Set selected item history
            string viewFolder;

            if (handler.CurrentLevelWhere.ToLower() == "genre")
            {
                viewFolder = "genre";
            }
            else if (handler.CurrentLevelWhere.ToLower() == "actor")
            {
                viewFolder = "actor";
            }
            else if (handler.CurrentLevelWhere.ToLower() == "year")
            {
                viewFolder = "year";
            }
            else
            {
                viewFolder = "title";
            }

            string selectedItemLabel = m_history.Get(viewFolder);

            // Sort
            OnSort();

            if (string.IsNullOrEmpty(selectedItemLabel) && facadeLayout.SelectedListItem != null)
            {
                selectedItemLabel = facadeLayout.SelectedListItem.Label;
            }

            int itemCount = itemlist.Count;

            if (itemlist.Count > 0)
            {
                GUIListItem rootItem = (GUIListItem)itemlist[0];
                if (rootItem.Label == "..")
                {
                    itemCount--;
                }
            }

            //set object count label
            GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetObjectCountLabel(itemCount));

            // Clear info for zero result
            if (itemlist.Count == 0)
            {
                GUIListItem item = new GUIListItem();
                item.Label = GUILocalizeStrings.Get(284);
                IMDBMovie movie = item.AlbumInfoTag as IMDBMovie;
                movie             = new IMDBMovie();
                item.AlbumInfoTag = movie;
                movie.SetProperties(false);
                itemlist.Add(item);
                facadeLayout.Add(item);
            }

            SwitchLayout();
            UpdateButtonStates();

            if (handler.CurrentLevel == 0)
            {
                for (int i = 0; i < facadeLayout.Count; ++i)
                {
                    GUIListItem item = facadeLayout[itemIndex];
                    if (item.Label == selectedItemLabel)
                    {
                        currentSelectedItem = itemIndex;
                        SelectItem();
                        break;
                    }
                    itemIndex++;
                }
            }
            // Set thumbs - also do a Item select
            if (handler.CurrentLevel < handler.MaxLevels)
            {
                if (handler.CurrentLevelWhere.ToLower() == "genre")
                {
                    SetGenreThumbs(itemlist);
                    SelectItem();
                }
                else if (handler.CurrentLevelWhere.ToLower() == "actor")
                {
                    SetActorThumbs(itemlist);
                }
                else if (handler.CurrentLevelWhere.ToLower() == "year")
                {
                    SetYearThumbs(itemlist);
                    SelectItem();
                }
                else
                {
                    // Assign thumbnails also for the custom views. Bugfix for Mantis 0001471:
                    // Cover image thumbs missing in My Videos when view Selection is by "watched"
                    SetIMDBThumbs(itemlist);
                }
            }
            else
            {
                SetIMDBThumbs(itemlist);
            }

            GUIWaitCursor.Hide();
        }
Esempio n. 3
0
        protected override void LoadDirectory(string strNewDirectory)
        {
            if (facadeLayout != null)
            {
                GUIWaitCursor.Show();
                try
                {
                    GUIListItem SelectedItem = facadeLayout.SelectedListItem;
                    if (SelectedItem != null)
                    {
                        if (SelectedItem.IsFolder && SelectedItem.Label != "..")
                        {
                            m_history.Set(SelectedItem.Label, currentFolder);
                        }
                    }
                    currentFolder = strNewDirectory;
                    facadeLayout.Clear();

                    string strObjects = string.Empty;

                    ArrayList itemlist = new ArrayList();

                    PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO);
                    /* copy playlist from general playlist*/
                    int iCurrentSong = -1;
                    if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_VIDEO)
                    {
                        iCurrentSong = playlistPlayer.CurrentSong;
                    }

                    string strFileName;
                    for (int i = 0; i < playlist.Count; ++i)
                    {
                        PlayListItem item = playlist[i];
                        strFileName = item.FileName;

                        GUIListItem pItem = new GUIListItem(item.Description);
                        pItem.Path     = strFileName;
                        pItem.IsFolder = false;
                        //pItem.m_bIsShareOrDrive = false;

                        if (item.Duration > 0)
                        {
                            int nDuration = item.Duration;
                            if (nDuration > 0)
                            {
                                string str = Util.Utils.SecondsToHMSString(nDuration);
                                pItem.Label2 = str;
                            }
                            else
                            {
                                pItem.Label2 = string.Empty;
                            }
                        }
                        pItem.OnItemSelected += OnItemSelected;
                        itemlist.Add(pItem);
                        Util.Utils.SetDefaultIcons(pItem);
                    }

                    iCurrentSong = 0;
                    strFileName  = string.Empty;
                    //	Search current playlist item
                    if ((m_nTempPlayListWindow == GetID && m_strTempPlayListDirectory.IndexOf(currentFolder) >= 0 &&
                         g_Player.Playing &&
                         playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_VIDEO_TEMP)
                        ||
                        (GetID == (int)Window.WINDOW_VIDEO_PLAYLIST &&
                         playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_VIDEO &&
                         g_Player.Playing))
                    {
                        iCurrentSong = playlistPlayer.CurrentSong;
                        if (iCurrentSong >= 0)
                        {
                            playlist = playlistPlayer.GetPlaylist(playlistPlayer.CurrentPlaylistType);
                            if (iCurrentSong < playlist.Count)
                            {
                                PlayListItem item = playlist[iCurrentSong];
                                strFileName = item.FileName;
                            }
                        }
                    }

                    SetIMDBThumbs(itemlist);

                    string strSelectedItem = m_history.Get(currentFolder);
                    int    iItem           = 0;
                    foreach (GUIListItem item in itemlist)
                    {
                        facadeLayout.Add(item);

                        //	synchronize playlist with current directory
                        if (strFileName.Length > 0 && item.Path == strFileName)
                        {
                            item.Selected = true;
                        }
                    }
                    for (int i = 0; i < facadeLayout.Count; ++i)
                    {
                        GUIListItem item = facadeLayout[i];
                        if (item.Label == strSelectedItem)
                        {
                            GUIControl.SelectItemControl(GetID, facadeLayout.GetID, iItem);
                            break;
                        }
                        iItem++;
                    }
                    int iTotalItems = itemlist.Count;
                    if (itemlist.Count > 0)
                    {
                        GUIListItem rootItem = (GUIListItem)itemlist[0];
                        if (rootItem.Label == "..")
                        {
                            iTotalItems--;
                        }
                    }

                    //set object count label
                    GUIPropertyManager.SetProperty("#itemcount", Util.Utils.GetObjectCountLabel(iTotalItems));

                    if (currentSelectedItem >= 0)
                    {
                        GUIControl.SelectItemControl(GetID, facadeLayout.GetID, currentSelectedItem);
                    }
                    else if (itemlist.Count > 0)
                    {
                        GUIControl.SelectItemControl(GetID, facadeLayout.GetID, 0);
                    }
                    else
                    {
                        IMDBMovie movie = new IMDBMovie();
                        movie.SetProperties(false, string.Empty);
                    }
                    UpdateButtonStates();
                    GUIWaitCursor.Hide();
                }
                catch (Exception ex)
                {
                    GUIWaitCursor.Hide();
                    Log.Error("GUIVideoPlaylist: An error occured while loading the directory - {0}", ex.Message);
                }
            }
        }
        protected void LoadDirectory(string strNewDirectory)
        {
            if (m_Facade == null)
            {
                return;
            }

            GUIWaitCursor.Show();
            try
            {
                GUIListItem SelectedItem = m_Facade.SelectedListItem;
                if (SelectedItem != null)
                {
                    if (SelectedItem.IsFolder && SelectedItem.Label != "..")
                    {
                        m_history.Set(SelectedItem.Label, currentFolder);
                    }
                }
                currentFolder = strNewDirectory;
                m_Facade.Clear();

                string strObjects = string.Empty;

                ArrayList itemlist = new ArrayList();

                PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES);
                /* copy playlist from general playlist*/
                int iCurrentItem = -1;
                if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES)
                {
                    iCurrentItem = playlistPlayer.CurrentItem;
                }

                string strFileName;
                for (int i = 0; i < playlist.Count; ++i)
                {
                    PlayListItem item = playlist[i];
                    strFileName = item.FileName;

                    GUIListItem pItem = new GUIListItem(item.EpisodeName);
                    pItem.Path     = strFileName;
                    pItem.IsFolder = false;
                    pItem.TVTag    = item.Episode;

                    // update images
                    pItem.ThumbnailImage = item.EpisodeThumb;
                    //pItem.IconImageBig = item.EpisodeThumb;
                    //pItem.IconImage = item.EpisodeThumb;

                    if (item.IsWatched)
                    {
                        pItem.IsPlayed  = true; // facade colours...dont seem to work!
                        pItem.IconImage = Helper.GetThemedSkinFile(ThemeType.Image, "tvseries_Watched.png");
                    }
                    else
                    {
                        pItem.IsPlayed  = false;
                        pItem.IconImage = Helper.GetThemedSkinFile(ThemeType.Image, "tvseries_UnWatched.png");
                    }

                    if (item.Duration > 0)
                    {
                        double nDuration = item.Duration;
                        if (nDuration > 0)
                        {
                            string str = Helper.MSToMMSS(nDuration);
                            pItem.Label2 = str;
                        }
                        else
                        {
                            pItem.Label2 = string.Empty;
                        }
                    }

                    itemlist.Add(pItem);
                    //MediaPortal.Util.Utils.SetDefaultIcons(pItem);
                }

                iCurrentItem = 0;
                strFileName  = string.Empty;
                //	Search current playlist item
                if ((m_nTempPlayListWindow == GetID && m_strTempPlayListDirectory.IndexOf(currentFolder) >= 0 && g_Player.Playing) ||
                    (GetID == (int)Window.WINDOW_VIDEO_PLAYLIST && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES &&
                     g_Player.Playing))
                {
                    iCurrentItem = playlistPlayer.CurrentItem;
                    if (iCurrentItem >= 0)
                    {
                        playlist = playlistPlayer.GetPlaylist(playlistPlayer.CurrentPlaylistType);
                        if (iCurrentItem < playlist.Count)
                        {
                            PlayListItem item = playlist[iCurrentItem];
                            strFileName = item.FileName;
                        }
                    }
                }

                string strSelectedItem = m_history.Get(currentFolder);
                int    iItem           = 0;
                foreach (GUIListItem item in itemlist)
                {
                    m_Facade.Add(item);
                    item.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected);

                    //	synchronize playlist with current directory
                    if (strFileName.Length > 0 && item.Path == strFileName)
                    {
                        item.Selected = true;
                    }
                }
                for (int i = 0; i < m_Facade.Count; ++i)
                {
                    GUIListItem item = m_Facade[i];
                    if (item.Label == strSelectedItem)
                    {
                        GUIControl.SelectItemControl(GetID, m_Facade.GetID, iItem);
                        break;
                    }
                    iItem++;
                }

                //set object count label
                int iTotalItems = itemlist.Count;
                GUIPropertyManager.SetProperty("#itemcount", Translation.Episodes + ": " + iTotalItems.ToString());
                GUIPropertyManager.SetProperty("#TVSeries.Playlist.Count", iTotalItems.ToString());

                if (currentSelectedItem >= 0)
                {
                    GUIControl.SelectItemControl(GetID, m_Facade.GetID, currentSelectedItem);
                }
                UpdateButtonStates();
                GUIWaitCursor.Hide();
            }
            catch (Exception ex)
            {
                GUIWaitCursor.Hide();
                MPTVSeriesLog.Write(string.Format("GUITVSeriesPlaylist: An error occured while loading the directory - {0}", ex.Message));
            }
        }