Ejemplo n.º 1
0
 private void EditList(TraktList list)
 {
     GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
     {
         return(TraktAPI.TraktAPI.ListUpdate(list));
     },
                                                               delegate(bool success, object result)
     {
         if (success)
         {
             TraktResponse response = result as TraktResponse;
             TraktLogger.LogTraktResponse <TraktResponse>(response);
             if (response.Status == "success")
             {
                 // reload with new list
                 TraktLists.ClearCache(TraktSettings.Username);
                 LoadLists();
             }
             else
             {
                 GUIUtils.ShowNotifyDialog(Translation.Lists, response.Error);
             }
         }
     }, Translation.EditingList, true);
 }
Ejemplo n.º 2
0
        private void DeleteList(TraktUserList list)
        {
            if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.ConfirmDeleteList, false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktLogger.Info("Deleting list '{0}'", list.Name);
                TraktList deleteList = new TraktList {
                    UserName = TraktSettings.Username, Password = TraktSettings.Password, Slug = list.Slug
                };
                return(TraktAPI.TraktAPI.ListDelete(deleteList));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    TraktResponse response = result as TraktResponse;
                    TraktLogger.LogTraktResponse <TraktResponse>(response);
                    if (response.Status == "success")
                    {
                        // reload with new list
                        TraktLists.ClearCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, response.Error);
                    }
                }
            }, Translation.DeletingList, true);
        }
Ejemplo n.º 3
0
 private void CreateMovingPicturesFiltersClicked()
 {
     if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
     {
         if (TraktSettings.MovingPicturesFilters)
         {
             // Remove
             if (UpdatingMovingPicturesFiltersMenu)
             {
                 btnCreateMovingPicturesFilters.Selected = true;
                 GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UpdatingFiltersMenuMovingPicsWarning);
                 return;
             }
             TraktSettings.MovingPicturesFilters = false;
             TraktHandlers.MovingPictures.RemoveTraktFromFiltersMenu();
         }
         else
         {
             // Add
             TraktSettings.MovingPicturesFilters = true;
             BackgroundWorker filtersCreator = new BackgroundWorker();
             filtersCreator.DoWork += new DoWorkEventHandler(FiltersCreator_DoWork);
             filtersCreator.RunWorkerAsync();
         }
         btnCreateMovingPicturesFilters.Selected = TraktSettings.MovingPicturesFilters;
     }
     else
     {
         GUIUtils.ShowOKDialog(GUIUtils.PluginName(), Translation.NoMovingPictures);
     }
 }
Ejemplo n.º 4
0
        private bool TestAccount(TraktAuthenticationToken token)
        {
            // test account by requesting the user settings
            var response = TraktAPI.TraktAPI.GetUserSettings();

            if (response == null || response.User == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedOnlineSettings);
                return(false);
            }
            else
            {
                // Save New Account Settings
                TraktSettings.Username       = response.User.Username;
                TraktSettings.OnlineSettings = response;

                TraktSettings.AccountStatus = ConnectionState.Connected;
                InitProperties();

                // clear caches
                // watchlists are stored by user so dont need clearing.
                GUINetwork.ClearCache();
                GUICalendarTV.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();

                // clear any stored user data
                TraktCache.ClearSyncCache();

                // persist settings
                TraktSettings.SaveSettings(false);

                return(true);
            }
        }
Ejemplo n.º 5
0
        private void SendSearchResultsToFacade(IEnumerable <TraktEpisodeSummary> episodes)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (episodes == null || episodes.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Episodes = null;
                return;
            }

            int itemId     = 0;
            var showImages = new List <TraktImage>();

            // Add each show
            foreach (var episodeSummary in episodes)
            {
                // add images for download
                var images = new TraktImage
                {
                    EpisodeImages = episodeSummary.Episode.Images,
                    ShowImages    = episodeSummary.Show.Images
                };
                showImages.Add(images);

                var item = new GUIEpisodeListItem(episodeSummary.ToString(), (int)TraktGUIWindows.SearchEpisodes);

                item.Label2          = episodeSummary.Show.Year.ToString();
                item.TVTag           = episodeSummary;
                item.Images          = images;
                item.IsPlayed        = episodeSummary.Episode.Watched;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultTraktEpisode.png";
                item.IconImageBig    = "defaultTraktEpisodeBig.png";
                item.ThumbnailImage  = "defaultTraktEpisodeBig.png";
                item.OnItemSelected += OnEpisodeSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", episodes.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", episodes.Count().ToString(), episodes.Count() > 1 ? Translation.Episodes : Translation.Episode));

            // Download images Async and set to facade
            GUIEpisodeListItem.GetImages(showImages);
        }
Ejemplo n.º 6
0
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
        {
            if (control == btnCreateMovingPicturesCategories)
            {
                CreateMovingPicturesCategoriesClicked();
            }

            if (control == btnCreateMovingPicturesFilters)
            {
                CreateMovingPicturesFiltersClicked();
            }

            if (control == btnStartLibrarySync)
            {
                if (TraktPlugin.StartSync())
                {
                    GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.LibraryAndPlaybackSyncStarted);
                }
                else
                {
                    GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.LibraryAndPlaybackSyncAlreadyRunning);
                }
            }

            base.OnClicked(controlId, control, actionType);
        }
Ejemplo n.º 7
0
        private void SendCastToFacade(List <TraktPersonShowCast> cast)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (cast == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // filter Shows
            var filteredCast = FilterCastShows(cast).Where(m => !string.IsNullOrEmpty(m.Show.Title)).ToList();

            // sort Shows
            filteredCast.Sort(new GUIListItemShowSorter(TraktSettings.SortByCreditShows.Field, TraktSettings.SortByCreditShows.Direction));

            int             itemId     = 0;
            GUIShowListItem item       = null;
            var             ShowImages = new List <GUITmdbImage>();

            foreach (var credit in filteredCast)
            {
                // add image for download
                var images = new GUITmdbImage {
                    ShowImages = new TmdbShowImages {
                        Id = credit.Show.Ids.Tmdb
                    }
                };
                ShowImages.Add(images);

                item                 = new GUIShowListItem(credit.Show.Title, (int)TraktGUIWindows.PersonCreditShows);
                item.Label2          = credit.Show.Year == null ? "----" : credit.Show.Year.ToString();
                item.Show            = credit.Show;
                item.TVTag           = credit;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnCastSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.CurrentLayout = CurrentLayout;
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", Facade.Count.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", filteredCast.Count, filteredCast.Count > 1 ? Translation.Shows : Translation.Show));

            // Download Show images Async and set to facade
            GUIShowListItem.GetImages(ShowImages);
        }
Ejemplo n.º 8
0
        private void CreateList(TraktList list)
        {
            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktAPI.TraktAPI.CreateCustomList(list));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    var response = result as TraktListDetail;
                    if (response != null)
                    {
                        // add to MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            // not very thread safe if we tried to add more than one before response!
                            TraktHandlers.MovingPictures.AddCustomListNode(list.Name);
                        }

                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedCreateList);
                    }
                }
            }, Translation.CreatingList, true);
        }
Ejemplo n.º 9
0
        private void SendSearchResultsToFacade(IEnumerable <TraktSearchResult> searchResults)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (searchResults == null || searchResults.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                return;
            }

            // jump directly to results
            if (!TraktSettings.ShowSearchResultsBreakdown && SearchTypes.Count == 1)
            {
                // set the selected search type as we have not clicked on a facade item
                SelectedSearchType = (SearchType)GetSearchTypesID();
                SendSearchResultsToWindow(SearchResults);

                // clear the search term so when we return (press back) we don't go in a loop.
                SearchTerm = null;
                return;
            }

            int itemId = 0;

            // Add each search type to the list
            foreach (var type in SearchTypes)
            {
                GUIListItem item = new GUIListItem(GetSearchListName(type));

                item.Label2          = GetSearchResultCount(searchResults, type).ToString();
                item.ItemId          = Int32.MaxValue - itemId;
                item.TVTag           = type;
                item.IconImage       = "defaultFolder.png";
                item.IconImageBig    = "defaultFolderBig.png";
                item.ThumbnailImage  = "defaultFolderBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout("List");
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= SearchTypes.Count)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", SearchTypes.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", SearchTypes.Count.ToString(), Translation.SearchTypes));
        }
Ejemplo n.º 10
0
        private void SendShowSeasonsToFacade(IEnumerable <TraktShowSeason> seasons)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (seasons == null || seasons.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSeasonsForShow);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // sort ascending or descending order
            if (TraktSettings.SortSeasonsAscending)
            {
                seasons = seasons.OrderBy(s => s.Season);
            }

            int itemId       = 0;
            var seasonImages = new List <TraktImage>();

            foreach (var season in seasons)
            {
                // add image for download
                var images = new TraktImage {
                    SeasonImages = season.Images, ShowImages = Show.Images
                };
                seasonImages.Add(images);

                string itemLabel = season.Season == 0 ? Translation.Specials : string.Format("{0} {1}", Translation.Season, season.Season.ToString());
                var    item      = new GUISeasonListItem(itemLabel, (int)TraktGUIWindows.ShowSeasons);

                item.Label2          = string.Format("{0} {1}", season.EpisodeCount, Translation.Episodes);
                item.TVTag           = season;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnSeasonSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", seasons.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", seasons.Count().ToString(), seasons.Count() > 1 ? Translation.Seasons : Translation.Season));

            // Download show images Async and set to facade
            GUISeasonListItem.GetImages(seasonImages);
        }
Ejemplo n.º 11
0
        private void SendTrendingShowsToFacade(IEnumerable <TraktTrendingShow> shows)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (shows.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoTrendingShows);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // filter shows
            shows = GUICommon.FilterTrendingShows(shows);

            // sort shows
            var showList = shows.ToList();

            showList.Sort(new GUIListItemShowSorter(TraktSettings.SortByTrendingShows.Field, TraktSettings.SortByTrendingShows.Direction));

            int itemId = 0;
            List <TraktShow.ShowImages> showImages = new List <TraktShow.ShowImages>();

            foreach (var show in showList)
            {
                GUITraktTrendingShowListItem item = new GUITraktTrendingShowListItem(show.Title);

                item.Label2          = show.Year.ToString();
                item.TVTag           = show;
                item.Item            = show.Images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultVideo.png";
                item.IconImageBig    = "defaultVideoBig.png";
                item.ThumbnailImage  = "defaultVideoBig.png";
                item.OnItemSelected += OnShowSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;

                // add image for download
                showImages.Add(show.Images);
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", shows.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", shows.Count().ToString(), shows.Count() > 1 ? Translation.SeriesPlural : Translation.Series));
            GUIUtils.SetProperty("#Trakt.Trending.PeopleCount", shows.Sum(s => s.Watchers).ToString());
            GUIUtils.SetProperty("#Trakt.Trending.Description", string.Format(Translation.TrendingTVShowsPeople, shows.Sum(s => s.Watchers).ToString(), shows.Count().ToString()));

            // Download show images Async and set to facade
            GetImages(showImages);
        }
        private void SendRelatedMoviesToFacade(IEnumerable <TraktMovie> movies)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (movies.Count() == 0)
            {
                string title = string.IsNullOrEmpty(relatedMovie.Title) ? relatedMovie.IMDbId : relatedMovie.Title;
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoRelatedMovies, title));
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemId      = 0;
            var movieImages = new List <TraktImage>();

            // Add each movie
            foreach (var movie in movies.Where(m => !string.IsNullOrEmpty(m.Title)))
            {
                var item = new GUIMovieListItem(movie.Title, (int)TraktGUIWindows.RelatedMovies);

                // add image for download
                var image = new TraktImage {
                    MovieImages = movie.Images
                };
                movieImages.Add(image);

                item.Label2   = movie.Year;
                item.TVTag    = movie;
                item.Images   = image;
                item.IsPlayed = movie.Watched;
                item.ItemId   = Int32.MaxValue - itemId;
                // movie in collection doesnt nessararily mean
                // that the movie is locally available on this computer
                // as 'keep library clean' might not be enabled
                //item.IsRemote = !movie.InCollection;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnMovieSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", movies.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", movies.Count().ToString(), movies.Count() > 1 ? Translation.Movies : Translation.Movie));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
        private void SendSearchResultsToFacade(IEnumerable <TraktMovie> movies)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (movies == null || movies.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Movies = null;
                return;
            }

            int itemId      = 0;
            var movieImages = new List <TraktImage>();

            // Add each movie
            foreach (var movie in movies)
            {
                // add image for download
                var images = new TraktImage {
                    MovieImages = movie.Images
                };
                movieImages.Add(images);

                GUIMovieListItem item = new GUIMovieListItem(movie.Title, (int)TraktGUIWindows.SearchMovies);

                item.Label2          = movie.Year == "0" ? "----" : movie.Year;
                item.TVTag           = movie;
                item.Images          = images;
                item.IsPlayed        = movie.Watched;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnMovieSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", movies.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", movies.Count().ToString(), movies.Count() > 1 ? Translation.Movies : Translation.Movie));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
Ejemplo n.º 14
0
        private void FiltersCreator_DoWork(object sender, DoWorkEventArgs e)
        {
            UpdatingMovingPicturesFiltersMenu = true;

            GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UpdatingFiltersMenuMovingPics);
            TraktHandlers.MovingPictures.UpdateFiltersMenu();

            UpdatingMovingPicturesFiltersMenu = false;
        }
        private void TestAccount(TraktAccount account)
        {
            TraktResponse response = null;

            if (NewAccount)
            {
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount);
                }

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.CreateAccount(account);
            }
            else
            {
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount);
                }

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.TestAccount(account);
            }

            if (response.Status == "failure")
            {
                string errorMessage = string.IsNullOrEmpty(response.Error) ? response.Message : response.Error;
                GUIUtils.ShowNotifyDialog(Translation.Error, errorMessage);
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty);
                }
            }
            else
            {
                // Save New Account Settings
                TraktSettings.Username = account.Username;
                TraktSettings.Password = account.Password;
                if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username))
                {
                    TraktSettings.UserLogins.Add(new TraktAuthentication {
                        Username = TraktSettings.Username, Password = TraktSettings.Password
                    });
                }
                TraktSettings.AccountStatus = ConnectionState.Connected;
                HideAccountControls();
                InitProperties();

                // clear caches
                // watch lists are stored by user so dont need clearing.
                GUITraktFriends.ClearCache();
                GUICalendar.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();
            }
        }
Ejemplo n.º 16
0
        private void SendSearchResultsToFacade(IEnumerable <TraktUser> users)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (users == null || users.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                Users = null;
                return;
            }

            int itemId     = 0;
            var userImages = new List <TraktImage>();

            // Add each user
            foreach (var user in users)
            {
                // add image to download
                var images = new TraktImage {
                    Avatar = user.Avatar
                };
                userImages.Add(images);

                var item = new GUIUserListItem(user.Username, (int)TraktGUIWindows.SearchUsers);

                item.Images          = images;
                item.TVTag           = user;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultTraktUser.png";
                item.IconImageBig    = "defaultTraktUserBig.png";
                item.ThumbnailImage  = "defaultTraktUserBig.png";
                item.OnItemSelected += OnUserSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", users.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", users.Count().ToString(), users.Count() > 1 ? Translation.Users : Translation.User));

            // Download images Async and set to facade
            GUIUserListItem.GetImages(userImages);
        }
        private void SendCrewToFacade(List<TraktPersonMovieJob> crew)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (crew == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // filter movies
            var filteredCrew = FilterCrewMovies(crew).Where(m => !string.IsNullOrEmpty(m.Movie.Title)).ToList();

            // sort movies
            filteredCrew.Sort(new GUIListItemMovieSorter(TraktSettings.SortByCreditMovies.Field, TraktSettings.SortByCreditMovies.Direction));

            int itemId = 0;
            GUIMovieListItem item = null;
            var movieImages = new List<GUITmdbImage>();

            foreach (var job in filteredCrew)
            {
                // add image for download
                var images = new GUITmdbImage { MovieImages = new TmdbMovieImages { Id = job.Movie.Ids.Tmdb } };
                movieImages.Add(images);

                item = new GUIMovieListItem(job.Movie.Title, (int)TraktGUIWindows.PersonCreditMovies);
                item.Label2 = job.Movie.Year == null ? "----" : job.Movie.Year.ToString();
                item.Movie = job.Movie;
                item.TVTag = job;
                item.Images = images;
                item.ItemId = Int32.MaxValue - itemId;
                item.IconImage = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnCrewSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", Facade.Count.ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", filteredCrew.Count, filteredCrew.Count > 1 ? Translation.Movies : Translation.Movie));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
        private void SendSearchResultsToFacade(IEnumerable <TraktPersonSummary> people)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (people == null || people.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                GUIWindowManager.ShowPreviousWindow();
                People = null;
                return;
            }

            int itemId       = 0;
            var personImages = new List <TraktImage>();

            // Add each movie
            foreach (var person in people)
            {
                // add image for download
                var images = new TraktImage {
                    PoepleImages = person.Images
                };
                personImages.Add(images);

                var item = new GUIPersonListItem(person.Name.Trim(), (int)TraktGUIWindows.SearchPeople);

                item.TVTag           = person;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnPersonSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (SearchTermChanged)
            {
                PreviousSelectedIndex = 0;
            }
            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", people.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", people.Count().ToString(), people.Count() > 1 ? Translation.People : Translation.Person));

            // Download images Async and set to facade
            GUIPersonListItem.GetImages(personImages);
        }
Ejemplo n.º 19
0
        private void SendListItemsToFacade(TraktUserList list)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (list.Items == null || list.Items.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoListItemsFound);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemId     = 1;
            var listImages = new List <TraktImage>();

            // Add each list item
            foreach (var listItem in list.Items.Where(l => !string.IsNullOrEmpty(l.Title)))
            {
                // add image for download
                var images = GetTraktImage(listItem);
                listImages.Add(images);

                string itemName = list.ShowNumbers ? string.Format("{0}. {1}", itemId, GetListItemName(listItem)) : GetListItemName(listItem);

                var item = new GUICustomListItem(itemName, (int)TraktGUIWindows.ListItems);

                item.Label2          = listItem.Year;
                item.TVTag           = listItem;
                item.Images          = images;
                item.IsPlayed        = listItem.Watched;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", list.Items.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", list.Items.Count().ToString(), list.Items.Count() > 1 ? Translation.Items : Translation.Item));

            // Download images Async and set to facade
            GUICustomListItem.GetImages(listImages);
        }
Ejemplo n.º 20
0
        private void SendRelatedShowsToFacade(IEnumerable <TraktShow> shows)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (shows.Count() == 0)
            {
                string title = string.IsNullOrEmpty(relatedShow.Title) ? relatedShow.TVDbId : relatedShow.Title;
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoRelatedShows, title));
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemId     = 0;
            var showImages = new List <TraktImage>();

            foreach (var show in shows)
            {
                var item = new GUIShowListItem(show.Title, (int)TraktGUIWindows.RelatedShows);

                // add image for download
                var images = new TraktImage {
                    ShowImages = show.Images
                };
                showImages.Add(images);

                item.Label2          = show.Year.ToString();
                item.TVTag           = show;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnShowSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", shows.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", shows.Count().ToString(), shows.Count() > 1 ? Translation.SeriesPlural : Translation.Series));

            // Download show images Async and set to facade
            GUIShowListItem.GetImages(showImages);
        }
Ejemplo n.º 21
0
        private void SendListItemsToFacade(TraktUserList list)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (list.Items == null || list.Items.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoListItemsFound);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int           itemId = 0;
            List <object> images = new List <object>();

            // Add each list item
            foreach (var listItem in list.Items)
            {
                GUITraktCustomListItem item = new GUITraktCustomListItem(listItem.ToString());

                item.Label2          = listItem.Year;
                item.TVTag           = listItem;
                item.Item            = listItem.Images;
                item.IsPlayed        = listItem.Watched;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = "defaultVideo.png";
                item.IconImageBig    = "defaultVideoBig.png";
                item.ThumbnailImage  = "defaultVideoBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;

                // add image for download
                images.Add(listItem.Images);
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", list.Items.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", list.Items.Count().ToString(), list.Items.Count() > 1 ? Translation.Items : Translation.Item));

            // Download images Async and set to facade
            GetImages(images);
        }
Ejemplo n.º 22
0
        private void SendLikedListsToFacade(IEnumerable <TraktLike> likedItems)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (likedItems == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemId = 0;

            // Add each list
            foreach (var likedItem in likedItems)
            {
                var item = new GUIListItem(likedItem.List.Name.RemapHighOrderChars());

                item.Label2          = string.Format("{0} {1}", likedItem.List.ItemCount, likedItem.List.ItemCount != 1 ? Translation.Items : Translation.Item);
                item.TVTag           = likedItem;
                item.ItemId          = Int32.MaxValue - itemId;
                item.PinImage        = TraktLists.GetPrivacyLevelIcon(likedItem.List.Privacy);
                item.IconImage       = "defaultFolder.png";
                item.IconImageBig    = "defaultFolderBig.png";
                item.ThumbnailImage  = "defaultFolderBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.CurrentLayout = GUIFacadeControl.Layout.List;
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= likedItems.Count())
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", likedItems.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", likedItems.Count().ToString(), likedItems.Count() > 1 ? Translation.Lists : Translation.List));
        }
Ejemplo n.º 23
0
        private void EditList(TraktListDetail list)
        {
            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktAPI.TraktAPI.UpdateCustomList(list));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    var response = result as TraktListDetail;
                    if (response == null)
                    {
                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();

                        var thread = new Thread((o) =>
                        {
                            TraktCache.ClearCustomListCache();

                            // updated MovingPictures categories and filters menu
                            if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                            {
                                TraktHandlers.MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                                TraktHandlers.MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                            }
                        })
                        {
                            Name         = "EditList",
                            IsBackground = true
                        };
                        thread.Start();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedUpdateList);
                    }
                }
            }, Translation.EditingList, true);
        }
Ejemplo n.º 24
0
        internal static void FollowUser(TraktUser user)
        {
            Thread followUserThread = new Thread(delegate(object obj)
            {
                var currUser = obj as TraktUser;

                var response = TraktAPI.TraktAPI.NetworkFollow(CreateNetworkData(currUser));
                TraktLogger.LogTraktResponse <TraktNetworkFollowResponse>(response);

                // notify user if follow is pending approval by user
                if (response.Pending)
                {
                    GUIUtils.ShowNotifyDialog(Translation.Follow, string.Format(Translation.FollowPendingApproval, currUser.Username));
                }
            })
            {
                IsBackground = true,
                Name         = "FollowUser"
            };

            followUserThread.Start(user);
        }
Ejemplo n.º 25
0
        public static bool ShowPinCodeDialog(string masterCode)
        {
            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowPinCodeDialogDelegate d = ShowPinCodeDialog;
                return((bool)GUIGraphicsContext.form.Invoke(d, masterCode));
            }

            if (!File.Exists(GUIGraphicsContext.Skin + @"\Trakt.PinCodeDialog.xml"))
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.SkinOutOfDate);
                return(false);
            }

            var pinCodeDlg = (GUIDialogPinCode)GUIWindowManager.GetWindow(GUIDialogPinCode.ID);

            pinCodeDlg.Reset();

            pinCodeDlg.MasterCode     = masterCode;
            pinCodeDlg.EnteredPinCode = string.Empty;
            pinCodeDlg.DoModal(GUIWindowManager.ActiveWindow);
            return(pinCodeDlg.IsCorrect);
        }
Ejemplo n.º 26
0
        internal static void FollowUser(TraktUser user)
        {
            var followUserThread = new Thread(obj =>
            {
                var currUser = obj as TraktUser;

                var response = TraktAPI.TraktAPI.NetworkFollowUser(currUser.Username);
                TraktLogger.LogTraktResponse <TraktNetworkApproval>(response);

                // notify user if follow is pending approval by user
                // approved date will be null if user is marked as private
                if (response != null && response.ApprovedAt == null)
                {
                    GUIUtils.ShowNotifyDialog(Translation.Follow, string.Format(Translation.FollowPendingApproval, currUser.Username));
                }
            })
            {
                IsBackground = true,
                Name         = "FollowUser"
            };

            followUserThread.Start(user);
        }
Ejemplo n.º 27
0
        private void DeleteList(TraktListDetail list)
        {
            if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.ConfirmDeleteList, false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktLogger.Info("Deleting list from online. Name = '{0}', Id = '{1}'", list.Name, list.Ids.Trakt);
                return(TraktAPI.TraktAPI.DeleteUserList("me", list.Ids.Trakt.ToString()));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    if ((result as bool?) == true)
                    {
                        // remove from MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            // not very thread safe if we tried to delete more than one before response!
                            TraktHandlers.MovingPictures.RemoveCustomListNode(list.Name);
                        }

                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedDeleteList);
                    }
                }
            }, Translation.DeletingList, true);
        }
        private void SendWatchListMoviesToFacade(IEnumerable <TraktWatchListMovie> movies)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (movies.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoMovieWatchList, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // sort movies
            var movieList = movies.Where(m => !string.IsNullOrEmpty(m.Title)).ToList();

            movieList.Sort(new GUIListItemMovieSorter(TraktSettings.SortByWatchListMovies.Field, TraktSettings.SortByWatchListMovies.Direction));

            int itemId      = 0;
            var movieImages = new List <TraktImage>();

            // Add each movie
            foreach (var movie in movieList)
            {
                // add image for download
                var images = new TraktImage {
                    MovieImages = movie.Images
                };
                movieImages.Add(images);

                var item = new GUIMovieListItem(movie.Title, (int)TraktGUIWindows.WatchedListMovies);

                item.Label2          = movie.Year;
                item.TVTag           = movie;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IsPlayed        = movie.Watched;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnMovieSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= movies.Count())
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", movies.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", movies.Count().ToString(), movies.Count() > 1 ? Translation.Movies : Translation.Movie));

            // Download movie images Async and set to facade
            GUIMovieListItem.GetImages(movieImages);
        }
        protected override void OnShowContextMenu()
        {
            var selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            var selectedMovie = selectedItem.TVTag as TraktWatchListMovie;

            if (selectedMovie == 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;

            // only allow removal if viewing your own watch list
            if (CurrentUser == TraktSettings.Username)
            {
                listItem = new GUIListItem(Translation.RemoveFromWatchList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.RemoveFromWatchList;
            }
            else if (!selectedMovie.InWatchList)
            {
                // viewing someone else's watch list and not in yours
                listItem = new GUIListItem(Translation.AddToWatchList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.AddToWatchList;
            }

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

            // Mark As Watched
            if (!selectedMovie.Watched)
            {
                listItem = new GUIListItem(Translation.MarkAsWatched);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.MarkAsWatched;
            }

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

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

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

            // Related Movies
            listItem = new GUIListItem(Translation.RelatedMovies + "...");
            dlg.Add(listItem);

            listItem.ItemId = (int)ContextMenuItem.Related;
            // Rate Movie
            listItem = new GUIListItem(Translation.RateMovie);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.Rate;

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

            if (TraktHelper.IsOnlineVideosAvailableAndEnabled)
            {
                // Trailers
                listItem = new GUIListItem(Translation.Trailers);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Trailers;
            }

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

            if (!selectedMovie.InCollection && TraktHelper.IsMpNZBAvailableAndEnabled)
            {
                // Search for movie with mpNZB
                listItem = new GUIListItem(Translation.SearchWithMpNZB);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.SearchWithMpNZB;
            }

            if (!selectedMovie.InCollection && TraktHelper.IsMyTorrentsAvailableAndEnabled)
            {
                // Search for movie with MyTorrents
                listItem = new GUIListItem(Translation.SearchTorrent);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.SearchTorrent;
            }

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

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.MarkAsWatched):
                TraktHelper.MarkMovieAsWatched(selectedMovie);
                if (CurrentUser != TraktSettings.Username)
                {
                    if (selectedMovie.Plays == 0)
                    {
                        selectedMovie.Plays = 1;
                    }
                    selectedMovie.Watched = true;
                    selectedItem.IsPlayed = true;
                    OnMovieSelected(selectedItem, Facade);
                    (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                    GUIWatchListMovies.ClearCache(TraktSettings.Username);
                }
                else
                {
                    // when marking a movie as seen via API, it will remove from watch list
                    // we should do the same in GUI
                    PreviousSelectedIndex = this.Facade.SelectedListItemIndex;
                    if (_WatchListMovies.Count() >= 1)
                    {
                        // remove from list
                        var moviesToExcept = new List <TraktWatchListMovie>();
                        moviesToExcept.Add(selectedMovie);
                        _WatchListMovies           = WatchListMovies.Except(moviesToExcept);
                        userWatchList[CurrentUser] = _WatchListMovies;
                        LoadWatchListMovies();
                    }
                    else
                    {
                        // no more movies left
                        ClearProperties();
                        GUIControl.ClearControl(GetID, Facade.GetID);
                        _WatchListMovies = null;
                        userWatchList.Remove(CurrentUser);
                        // notify and exit
                        GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoMovieWatchList);
                        GUIWindowManager.ShowPreviousWindow();
                        return;
                    }
                }
                break;

            case ((int)ContextMenuItem.MarkAsUnWatched):
                TraktHelper.MarkMovieAsUnWatched(selectedMovie);
                selectedMovie.Watched = false;
                selectedItem.IsPlayed = false;
                OnMovieSelected(selectedItem, Facade);
                (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                break;

            case ((int)ContextMenuItem.AddToWatchList):
                TraktHelper.AddMovieToWatchList(selectedMovie, true);
                selectedMovie.InWatchList = true;
                OnMovieSelected(selectedItem, Facade);
                (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                break;

            case ((int)ContextMenuItem.RemoveFromWatchList):
                PreviousSelectedIndex = this.Facade.SelectedListItemIndex;
                TraktHelper.RemoveMovieFromWatchList(selectedMovie, true);
                if (_WatchListMovies.Count() >= 1)
                {
                    // remove from list
                    var moviesToExcept = new List <TraktWatchListMovie>();
                    moviesToExcept.Add(selectedMovie);
                    _WatchListMovies           = WatchListMovies.Except(moviesToExcept);
                    userWatchList[CurrentUser] = _WatchListMovies;
                    LoadWatchListMovies();
                }
                else
                {
                    // no more movies left
                    ClearProperties();
                    GUIControl.ClearControl(GetID, Facade.GetID);
                    _WatchListMovies = null;
                    userWatchList.Remove(CurrentUser);
                    // notify and exit
                    GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoMovieWatchList);
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }
                break;

            case ((int)ContextMenuItem.AddToList):
                TraktHelper.AddRemoveMovieInUserList(selectedMovie.Title, selectedMovie.Year, selectedMovie.IMDBID, false);
                break;

            case ((int)ContextMenuItem.Trailers):
                GUICommon.ShowMovieTrailersMenu(selectedMovie);
                break;

            case ((int)ContextMenuItem.AddToLibrary):
                TraktHelper.AddMovieToLibrary(selectedMovie);
                selectedMovie.InCollection = true;
                OnMovieSelected(selectedItem, Facade);
                (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                if (CurrentUser != TraktSettings.Username)
                {
                    GUIWatchListMovies.ClearCache(TraktSettings.Username);
                }
                break;

            case ((int)ContextMenuItem.RemoveFromLibrary):
                TraktHelper.RemoveMovieFromLibrary(selectedMovie);
                selectedMovie.InCollection = false;
                OnMovieSelected(selectedItem, Facade);
                (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                if (CurrentUser != TraktSettings.Username)
                {
                    GUIWatchListMovies.ClearCache(TraktSettings.Username);
                }
                break;

            case ((int)ContextMenuItem.Related):
                TraktHelper.ShowRelatedMovies(selectedMovie);
                break;

            case ((int)ContextMenuItem.Rate):
                GUICommon.RateMovie(selectedMovie);
                OnMovieSelected(selectedItem, Facade);
                (Facade.SelectedListItem as GUIMovieListItem).Images.NotifyPropertyChanged("Poster");
                if (CurrentUser != TraktSettings.Username)
                {
                    GUIWatchListMovies.ClearCache(TraktSettings.Username);
                }
                break;

            case ((int)ContextMenuItem.Shouts):
                TraktHelper.ShowMovieShouts(selectedMovie);
                break;

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

            case ((int)ContextMenuItem.SearchWithMpNZB):
                string loadingParam = string.Format("search:{0}", selectedMovie.Title);
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MpNZB, loadingParam);
                break;

            case ((int)ContextMenuItem.SearchTorrent):
                string loadPar = selectedMovie.Title;
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MyTorrents, loadPar);
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }
Ejemplo n.º 30
0
        private void SendWatchListShowsToFacade(IEnumerable <TraktWatchListShow> shows)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (shows.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoShowWatchList, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // sort shows
            var showList = shows.ToList();

            showList.Sort(new GUIListItemShowSorter(TraktSettings.SortByWatchListShows.Field, TraktSettings.SortByWatchListShows.Direction));

            int itemId     = 0;
            var showImages = new List <TraktImage>();

            // Add each show
            foreach (var show in showList)
            {
                // add image for download
                var images = new TraktImage {
                    ShowImages = show.Images
                };
                showImages.Add(images);

                GUIShowListItem item = new GUIShowListItem(show.Title, (int)TraktGUIWindows.WatchedListShows);

                item.Label2          = show.Year.ToString();
                item.TVTag           = show;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IconImage       = GUIImageHandler.GetDefaultPoster(false);
                item.IconImageBig    = GUIImageHandler.GetDefaultPoster();
                item.ThumbnailImage  = GUIImageHandler.GetDefaultPoster();
                item.OnItemSelected += OnShowSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= shows.Count())
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", shows.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", shows.Count().ToString(), shows.Count() > 1 ? Translation.SeriesPlural : Translation.Series));

            // Download show images Async and set to facade
            GUIShowListItem.GetImages(showImages);
        }