/// <summary>
        /// Loads an Image from memory into a facade item
        /// </summary>
        /// <param name="imageFilePath">Filename of image</param>
        protected void SetImageToGui(string imageFilePath)
        {
            if (string.IsNullOrEmpty(imageFilePath))
            {
                return;
            }

            // determine the overlay to add to poster
            var episode = TVTag as TraktEpisodeSummary;
            MainOverlayImage mainOverlay = MainOverlayImage.None;

            // don't show watchlist overlay in personal watchlist window
            if (WindowID == (int)TraktGUIWindows.WatchedListEpisodes)
            {
                if ((GUIWatchListEpisodes.CurrentUser != TraktSettings.Username) && episode.Episode.InWatchList)
                {
                    mainOverlay = MainOverlayImage.Watchlist;
                }
                else if (episode.Episode.Watched)
                {
                    mainOverlay = MainOverlayImage.Seenit;
                }
            }
            else
            {
                if (episode.Episode.InWatchList)
                {
                    mainOverlay = MainOverlayImage.Watchlist;
                }
                else if (episode.Episode.Watched)
                {
                    mainOverlay = MainOverlayImage.Seenit;
                }
            }

            // add additional overlay if applicable
            if (episode.Episode.InCollection)
            {
                mainOverlay |= MainOverlayImage.Library;
            }

            RatingOverlayImage ratingOverlay = GUIImageHandler.GetRatingOverlay(episode.Episode.RatingAdvanced);

            // get a reference to a MediaPortal Texture Identifier
            string suffix  = mainOverlay.ToString().Replace(", ", string.Empty) + Enum.GetName(typeof(RatingOverlayImage), ratingOverlay);
            string texture = GUIImageHandler.GetTextureIdentFromFile(imageFilePath, suffix);

            // build memory image, resize thumbnail incase its a fanart
            Image memoryImage = null;

            if (mainOverlay != MainOverlayImage.None || ratingOverlay != RatingOverlayImage.None)
            {
                memoryImage = GUIImageHandler.DrawOverlayOnEpisodeThumb(imageFilePath, mainOverlay, ratingOverlay, new Size(400, 225));
                if (memoryImage == null)
                {
                    return;
                }

                // load texture into facade item
                if (GUITextureManager.LoadFromMemory(memoryImage, texture, 0, 0, 0) > 0)
                {
                    ThumbnailImage = texture;
                    IconImage      = texture;
                    IconImageBig   = texture;
                }
            }
            else
            {
                ThumbnailImage = imageFilePath;
                IconImage      = imageFilePath;
                IconImageBig   = imageFilePath;
            }

            // if selected and is current window force an update of thumbnail
            this.UpdateItemIfSelected(WindowID, ItemId);
        }
Ejemplo n.º 2
0
        private void SendRecentlyWatchedToFacade(IEnumerable <TraktMovieHistory> recentlyWatched)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            // protected profiles might return null
            if (recentlyWatched == null || recentlyWatched.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNotWatchedMovies);
                PreviousUser = CurrentUser;
                CurrentUser  = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

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

            // Add each item watched
            foreach (var recent in recentlyWatched)
            {
                // bad data in API
                if (recent.Movie == null)
                {
                    continue;
                }

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

                var item = new GUIMovieListItem(recent.Movie.Title, (int)TraktGUIWindows.RecentWatchedMovies);

                // add user watched date as second label
                item.Label2          = recent.WatchedAt.ToPrettyDateTime();
                item.Date            = recent.WatchedAt.FromISO8601().ToLongDateString();
                item.Action          = recent.Action;
                item.TVTag           = recent.Movie;
                item.Movie           = recent.Movie;
                item.Images          = images;
                item.ItemId          = Int32.MaxValue - itemId;
                item.IsPlayed        = CurrentUser != TraktSettings.Username ? recent.Movie.IsWatched() : false;
                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.CurrentLayout = CurrentLayout;
            GUIControl.FocusControl(GetID, Facade.GetID);

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

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

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

            if (movies.Count() == 0)
            {
                // try again
                if (genreButton == null)
                {
                    // restore defaults for next time so we can get recommendations
                    if (CurrentGenre != "All")
                    {
                        CurrentGenre = "All";
                    }

                    _RecommendedMovies = null;
                    GUIWindowManager.ShowPreviousWindow();
                }
                else
                {
                    GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoMovieRecommendations);
                    GUIControl.FocusControl(GetID, genreButton.GetID);
                }
                return;
            }

            // sort movies
            var movieList = movies.ToList();

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

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

            // Add each movie
            foreach (var movie in movieList)
            {
                var item = new GUIMovieListItem(movie.Title, (int)TraktGUIWindows.RecommendationsMovies);

                // 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.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);

            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);
        }
Ejemplo n.º 4
0
        private void SendCreditResultsToFacade(TraktCredits credits)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

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

            // Add each character
            if (Type == CreditType.Cast && credits.Cast != null)
            {
                foreach (var person in credits.Cast)
                {
                    // add image for download
                    var images = new GUITmdbImage {
                        PeopleImages = new TmdbPeopleImages {
                            Id = person.Person.Ids.TmdbId
                        }
                    };
                    personImages.Add(images);

                    var item = new GUIPersonListItem(string.IsNullOrEmpty(person.Character) ? person.Person.Name : string.Format(Translation.ActorAndRole, person.Person.Name, person.Character), (int)TraktGUIWindows.CreditsShow);

                    item.Person          = person.Person;
                    item.CreditType      = Credit.Cast;
                    item.Character       = person;
                    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++;
                }
            }

            // add each crew member
            if (Type == CreditType.Crew && credits.Crew != null)
            {
                if (credits.Crew.Directing != null)
                {
                    foreach (var person in credits.Crew.Directing)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Directing;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.Writing != null)
                {
                    foreach (var person in credits.Crew.Writing)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Writing;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.Production != null)
                {
                    foreach (var person in credits.Crew.Production)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Production;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.Art != null)
                {
                    foreach (var person in credits.Crew.Art)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Art;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.Camera != null)
                {
                    foreach (var person in credits.Crew.Camera)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Camera;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.CostumeAndMakeUp != null)
                {
                    foreach (var person in credits.Crew.CostumeAndMakeUp)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.CostumeAndMakeUp;
                        item.Job             = person;
                        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++;
                    }
                }

                if (credits.Crew.Sound != null)
                {
                    foreach (var person in credits.Crew.Sound)
                    {
                        // add image for download
                        var images = new GUITmdbImage {
                            PeopleImages = new TmdbPeopleImages {
                                Id = person.Person.Ids.TmdbId
                            }
                        };
                        personImages.Add(images);

                        var item = new GUIPersonListItem(person.Person.Name, (int)TraktGUIWindows.CreditsShow);
                        item.Label2          = GUICommon.GetTranslatedCreditJob(person.Job);
                        item.Person          = person.Person;
                        item.CreditType      = Credit.Sound;
                        item.Job             = person;
                        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++;
                    }
                }
            }

            // if nothing to display exit
            if (Facade.Count == 0)
            {
                GUIUtils.ShowNotifyDialog(Type == CreditType.Crew ? Translation.Crew : Translation.Cast, Translation.NoCreditsFound);
                GUIWindowManager.ShowPreviousWindow();
                Show = null;
                return;
            }

            // 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}", Facade.Count.ToString(), Facade.Count > 1 ? Translation.People : Translation.Person));

            // Download images Async and set to facade
            GUIPersonListItem.GetImages(personImages, false);
        }
Ejemplo n.º 5
0
        private void SendListItemsToFacade(IEnumerable <TraktListItem> listItems)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

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

            CurrentListItems = listItems.ToList();

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

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

            // Add each list item
            foreach (var listItem in listItems)
            {
                // add image for download
                var images = GetTmdbImage(listItem);
                listImages.Add(images);

                string itemName = CurrentList.DisplayNumbers ? string.Format("{0}. {1}", itemId, GetListItemLabel(listItem)) : GetListItemLabel(listItem);

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

                item.Label2          = GetListItemSecondLabel(listItem);
                item.TVTag           = listItem;
                item.Type            = (TraktItemType)Enum.Parse(typeof(TraktItemType), listItem.Type, true);
                item.Movie           = listItem.Movie;
                item.Show            = listItem.Show;
                item.Episode         = listItem.Episode;
                item.Season          = listItem.Season;
                item.Person          = listItem.Person;
                item.Images          = images;
                item.IsPlayed        = listItem.IsWatched();
                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", listItems.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", listItems.Count().ToString(), listItems.Count() > 1 ? Translation.Items : Translation.Item));

            // Download images Async and set to facade
            GUICustomListItem.GetImages(listImages);
        }
Ejemplo n.º 6
0
        private void OnItemSelected(GUIListItem item, GUIControl parent)
        {
            if (item == null)
            {
                return;
            }

            var listItem = item.TVTag as TraktListItem;

            if (listItem == null)
            {
                return;
            }

            PreviousSelectedIndex = Facade.SelectedListItemIndex;

            switch (listItem.Type)
            {
            case "movie":
                SelectedType = TraktItemType.movie;
                PublishMovieSkinProperties(listItem);
                string fanart = TmdbCache.GetMovieBackdropFilename((item as GUICustomListItem).Images.MovieImages);
                if (!string.IsNullOrEmpty(fanart))
                {
                    GUIImageHandler.LoadFanart(backdrop, fanart);
                }
                break;

            case "show":
                SelectedType = TraktItemType.show;
                PublishShowSkinProperties(listItem);
                fanart = TmdbCache.GetShowBackdropFilename((item as GUICustomListItem).Images.ShowImages);
                if (!string.IsNullOrEmpty(fanart))
                {
                    GUIImageHandler.LoadFanart(backdrop, fanart);
                }
                break;

            case "season":
                SelectedType = TraktItemType.season;
                PublishSeasonSkinProperties(listItem);
                fanart = TmdbCache.GetShowBackdropFilename((item as GUICustomListItem).Images.ShowImages);
                if (!string.IsNullOrEmpty(fanart))
                {
                    GUIImageHandler.LoadFanart(backdrop, fanart);
                }
                break;

            case "episode":
                SelectedType = TraktItemType.episode;
                PublishEpisodeSkinProperties(listItem);
                fanart = TmdbCache.GetShowBackdropFilename((item as GUICustomListItem).Images.ShowImages);
                if (!string.IsNullOrEmpty(fanart))
                {
                    GUIImageHandler.LoadFanart(backdrop, fanart);
                }
                break;

            case "person":
                SelectedType = TraktItemType.person;
                PublishPersonSkinProperties(listItem);
                break;
            }
            GUIUtils.SetProperty("#Trakt.List.ItemType", SelectedType.ToString());
        }