Пример #1
0
        private void SetCurrentPage(int pageIndex)
        {
            if (pageIndex > 0 && pageIndex <= MaxPages)
            {
                CurrentPage = pageIndex;

                for (int i = 0; i < CurrentListItems.Count; i++)
                {
                    CurrentListItems[i].Slot = -1;
                }

                CurrentListItems.Clear();

                int startIndex = ItemsPerPage * (CurrentPage - 1);
                int endIndex   = startIndex + ItemsPerPage > ListItems.Count ? ListItems.Count : startIndex + ItemsPerPage;
                int count      = 0;

                for (int i = startIndex; i < endIndex; i++)
                {
                    ListItem item = ListItems[i];
                    item.Slot = count;
                    count++;
                    CurrentListItems.Add(item);
                }
            }
        }
        protected override void OnShowContextMenu()
        {
            var selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            var selectedListItem = selectedItem.TVTag as TraktListItem;

            if (selectedListItem == null)
            {
                return;
            }

            var dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading(GUIUtils.PluginName());

            GUIListItem listItem = null;

            if (SelectedType == TraktItemType.movie || SelectedType == TraktItemType.episode)
            {
                // Mark As Watched
                if (!selectedListItem.IsWatched())
                {
                    listItem = new GUIListItem(Translation.MarkAsWatched);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.MarkAsWatched;
                }

                // Mark As UnWatched
                if (selectedListItem.IsWatched())
                {
                    listItem = new GUIListItem(Translation.MarkAsUnWatched);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.MarkAsUnWatched;
                }
            }

            if (SelectedType != TraktItemType.season && SelectedType != TraktItemType.person)
            {
                // Add/Remove Watchlist
                if (!selectedListItem.IsWatchlisted())
                {
                    listItem = new GUIListItem(Translation.AddToWatchList);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.AddToWatchList;
                }
                else
                {
                    listItem = new GUIListItem(Translation.RemoveFromWatchList);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.RemoveFromWatchList;
                }
            }

            // Add to Custom list
            listItem = new GUIListItem(Translation.AddToList);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.AddToList;

            // Remove from Custom list (only if current user is the active user)
            if (TraktSettings.Username == CurrentUser)
            {
                listItem = new GUIListItem(Translation.RemoveFromList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.RemoveFromList;
            }

            if (SelectedType == TraktItemType.movie || SelectedType == TraktItemType.episode)
            {
                // Add to Collection
                // Don't allow if it will be removed again on next sync
                // movie could be part of a DVD collection
                if (!selectedListItem.IsCollected() && !TraktSettings.KeepTraktLibraryClean)
                {
                    listItem = new GUIListItem(Translation.AddToLibrary);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.AddToLibrary;
                }

                if (selectedListItem.IsCollected())
                {
                    listItem = new GUIListItem(Translation.RemoveFromLibrary);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.RemoveFromLibrary;
                }
            }

            // Related Movies/Shows
            if (SelectedType != TraktItemType.person)
            {
                listItem = new GUIListItem(SelectedType == TraktItemType.movie ? Translation.RelatedMovies : Translation.RelatedShows);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Related;
            }

            if (SelectedType != TraktItemType.season && SelectedType != TraktItemType.person)
            {
                // Rate
                listItem = new GUIListItem(Translation.Rate + "...");
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Rate;

                // Shouts
                listItem = new GUIListItem(Translation.Comments);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Shouts;
            }

            // Cast and Crew
            if (SelectedType == TraktItemType.movie || SelectedType == TraktItemType.show)
            {
                listItem = new GUIListItem(Translation.Cast);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Cast;

                listItem = new GUIListItem(Translation.Crew);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Crew;
            }

            // Trailers
            if (SelectedType != TraktItemType.person)
            {
                if (TraktHelper.IsTrailersAvailableAndEnabled)
                {
                    listItem = new GUIListItem(Translation.Trailers);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Trailers;
                }
            }

            // Search with mpNZB
            if (TraktHelper.IsMpNZBAvailableAndEnabled)
            {
                if ((selectedListItem.Movie != null && !selectedListItem.Movie.IsCollected()) || selectedListItem.Episode != null)
                {
                    listItem = new GUIListItem(Translation.SearchWithMpNZB);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.SearchWithMpNZB;
                }
            }

            // Search with MyTorrents
            if (TraktHelper.IsMyTorrentsAvailableAndEnabled)
            {
                if ((selectedListItem.Movie != null && !selectedListItem.Movie.IsCollected()) || selectedListItem.Episode != null)
                {
                    listItem = new GUIListItem(Translation.SearchTorrent);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.SearchTorrent;
                }
            }

            // Change Layout
            listItem = new GUIListItem(Translation.ChangeLayout);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.ChangeLayout;

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0)
            {
                return;
            }

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.MarkAsWatched):
                AddItemToWatchedHistory(selectedListItem);
                selectedItem.IsPlayed = true;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.MarkAsUnWatched):
                RemoveItemFromWatchedHistory(selectedListItem);
                selectedItem.IsPlayed = false;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.AddToWatchList):
                AddItemToWatchList(selectedListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }

                GUIWatchListMovies.ClearCache(TraktSettings.Username);
                break;

            case ((int)ContextMenuItem.RemoveFromWatchList):
                RemoveItemFromWatchList(selectedListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }

                GUIWatchListMovies.ClearCache(TraktSettings.Username);
                break;

            case ((int)ContextMenuItem.AddToList):
                if (SelectedType == TraktItemType.movie)
                {
                    TraktHelper.AddRemoveMovieInUserList(selectedListItem.Movie, false);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    TraktHelper.AddRemoveShowInUserList(selectedListItem.Show, false);
                }
                else if (SelectedType == TraktItemType.season)
                {
                    TraktHelper.AddRemoveSeasonInUserList(selectedListItem.Season, false);
                }
                else if (SelectedType == TraktItemType.episode)
                {
                    TraktHelper.AddRemoveEpisodeInUserList(selectedListItem.Episode, false);
                }
                else if (SelectedType == TraktItemType.person)
                {
                    TraktHelper.AddRemovePersonInUserList(selectedListItem.Person, false);
                }
                break;

            case ((int)ContextMenuItem.RemoveFromList):
                if (!GUIUtils.ShowYesNoDialog(Translation.DeleteListItem, Translation.ConfirmDeleteListItem))
                {
                    break;
                }

                // Only do remove from current list
                // We could do same as Add (ie remove from multiple lists) but typically you only remove from the current list
                TraktHelper.AddRemoveItemInList((int)CurrentList.Ids.Trakt, GetSyncItems(selectedListItem), true);

                // clear the list item cache
                TraktLists.ClearListItemCache(CurrentUser, CurrentList.Ids.Trakt.ToString());

                // remove item from collection
                CurrentListItems.RemoveAll(l => ListItemMatch(l, selectedListItem));

                // clear the cache
                TraktLists.ClearListItemCache(TraktSettings.Username, CurrentList.Ids.Trakt.ToString());

                // Remove from view
                if (Facade.Count > 1)
                {
                    PreviousSelectedIndex = Facade.SelectedListItemIndex;
                    SendListItemsToFacade(CurrentListItems);
                }
                else
                {
                    // no more items left
                    GUIControl.ClearControl(GetID, Facade.GetID);
                    ClearProperties();
                    GUIWindowManager.Process();

                    // nothing left, exit
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }
                break;

            case ((int)ContextMenuItem.AddToLibrary):
                AddItemToCollection(selectedListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.RemoveFromLibrary):
                RemoveItemFromCollection(selectedListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.Related):
                if (SelectedType == TraktItemType.movie)
                {
                    TraktHelper.ShowRelatedMovies(selectedListItem.Movie);
                }
                else
                {
                    //series, season & episode
                    TraktHelper.ShowRelatedShows(selectedListItem.Show);
                }
                break;

            case ((int)ContextMenuItem.Rate):
                RateItem(selectedListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.Shouts):
                if (SelectedType == TraktItemType.movie)
                {
                    TraktHelper.ShowMovieShouts(selectedListItem.Movie);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    TraktHelper.ShowTVShowShouts(selectedListItem.Show);
                }
                else
                {
                    TraktHelper.ShowEpisodeShouts(selectedListItem.Show, selectedListItem.Episode);
                }
                break;

            case ((int)ContextMenuItem.Cast):
                if (SelectedType == TraktItemType.movie)
                {
                    GUICreditsMovie.Movie  = selectedListItem.Movie;
                    GUICreditsMovie.Type   = GUICreditsMovie.CreditType.Cast;
                    GUICreditsMovie.Fanart = TmdbCache.GetMovieBackdropFilename((selectedItem as GUICustomListItem).Images.MovieImages);
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsMovie);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    GUICreditsShow.Show   = selectedListItem.Show;
                    GUICreditsShow.Type   = GUICreditsShow.CreditType.Cast;
                    GUICreditsShow.Fanart = TmdbCache.GetShowBackdropFilename((selectedItem as GUICustomListItem).Images.ShowImages);
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsShow);
                }
                break;

            case ((int)ContextMenuItem.Crew):
                if (SelectedType == TraktItemType.movie)
                {
                    GUICreditsMovie.Movie  = selectedListItem.Movie;
                    GUICreditsMovie.Type   = GUICreditsMovie.CreditType.Crew;
                    GUICreditsMovie.Fanart = TmdbCache.GetMovieBackdropFilename((selectedItem as GUICustomListItem).Images.MovieImages);
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsMovie);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    GUICreditsShow.Show   = selectedListItem.Show;
                    GUICreditsShow.Type   = GUICreditsShow.CreditType.Crew;
                    GUICreditsShow.Fanart = TmdbCache.GetShowBackdropFilename((selectedItem as GUICustomListItem).Images.ShowImages);
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.CreditsShow);
                }
                break;

            case ((int)ContextMenuItem.Trailers):
                if (SelectedType == TraktItemType.movie)
                {
                    GUICommon.ShowMovieTrailersMenu(selectedListItem.Movie);
                }
                else if (SelectedType == TraktItemType.episode)
                {
                    GUICommon.ShowTVShowTrailersMenu(selectedListItem.Show, selectedListItem.Episode);
                }
                else if (SelectedType == TraktItemType.season && TraktHelper.IsTrailersAvailableAndEnabled)
                {
                    GUICommon.ShowTVSeasonTrailersPluginMenu(selectedListItem.Show, selectedListItem.Season.Number);
                }
                break;

            case ((int)ContextMenuItem.SearchWithMpNZB):
                string loadingParam = String.Empty;
                if (selectedListItem.Movie != null)
                {
                    loadingParam = string.Format("search:{0}", selectedListItem.Movie.Title);
                }
                else if (selectedListItem.Episode != null)
                {
                    loadingParam = string.Format("search:{0} S{1}E{2}", selectedListItem.Show.Title, selectedListItem.Episode.Season.ToString("D2"), selectedListItem.Episode.Number.ToString("D2"));
                }
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MpNZB, loadingParam);
                break;

            case ((int)ContextMenuItem.SearchTorrent):
                string loadPar = String.Empty;
                if (selectedListItem.Movie != null)
                {
                    loadPar = selectedListItem.Movie.Title;
                }
                else if (selectedListItem.Episode != null)
                {
                    loadPar = string.Format("{0} S{1}E{2}", selectedListItem.Show.Title, selectedListItem.Episode.Season.ToString("D2"), selectedListItem.Episode.Number.ToString("D2"));
                }
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MyTorrents, loadPar);
                break;

            case ((int)ContextMenuItem.ChangeLayout):
                CurrentLayout = GUICommon.ShowLayoutMenu(CurrentLayout, PreviousSelectedIndex);
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }