Esempio n. 1
0
        /// <summary>
        /// Shows a Trakt Rate Dialog
        /// </summary>
        /// <param name="rateObject">Type of object being rated</param>
        public static int ShowRateDialog <T>(T rateObject)
        {
            if (!GUICommon.CheckLogin(false))
            {
                return(-1);
            }

            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowRateDialogDelegate <T> d = ShowRateDialog <T>;
                return((int)GUIGraphicsContext.form.Invoke(d, rateObject));
            }

            TraktRateValue currentRating = TraktRateValue.unrate;

            var ratingDlg = (GUIRateDialog)GUIWindowManager.GetWindow(GUIRateDialog.ID);

            ratingDlg.Reset();

            ratingDlg.SetHeading(Translation.RateHeading);

            // if item is not rated, it will default to seven
            if (rateObject is TraktSyncEpisodeRated)
            {
                var item = rateObject as TraktSyncEpisodeRated;
                ratingDlg.SetLine(1, string.Format("{0}x{1} - {2}", item.Season, item.Number, item.Title));
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }
            else if (rateObject is TraktSyncShowRatedEx)
            {
                // for when episode ids are not available we need to sync with both episode and show details
                var item = rateObject as TraktSyncShowRatedEx;
                ratingDlg.SetLine(1, string.Format("{0} - {1}x{2}", item.Title, item.Seasons[0].Number, item.Seasons[0].Episodes[0].Number));
                ratingDlg.Rated = item.Seasons[0].Episodes[0].Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Seasons[0].Episodes[0].Rating);
            }
            else if (rateObject is TraktSyncShowRated)
            {
                var item = rateObject as TraktSyncShowRated;
                ratingDlg.SetLine(1, item.Title);
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }
            else if (rateObject is TraktSyncSeasonRatedEx)
            {
                // for when season ids are not available we need to sync with both season and show details
                var item = rateObject as TraktSyncSeasonRatedEx;
                ratingDlg.SetLine(1, string.Format("{0} - {1} {2}", item.Title, Translation.Season, item.Seasons[0].Number));
                ratingDlg.Rated = item.Seasons[0].Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Seasons[0].Rating);
            }
            else
            {
                var item = rateObject as TraktSyncMovieRated;
                ratingDlg.SetLine(1, item.Title);
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }

            // show dialog
            ratingDlg.DoModal(ratingDlg.GetID);

            if (!ratingDlg.IsSubmitted)
            {
                return(-1);
            }

            TraktSyncResponse response = null;

            if (rateObject is TraktSyncEpisodeRated)
            {
                var item = rateObject as TraktSyncEpisodeRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncEpisodeRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddEpisodeToRatings(obj as TraktSyncEpisodeRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveEpisodeFromRatings(obj as TraktEpisode);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncShowRatedEx)
            {
                // for when episode ids are not available we need to sync with both episode and show details
                var item = rateObject as TraktSyncShowRatedEx;
                currentRating = ratingDlg.Rated;
                item.Seasons[0].Episodes[0].Rating = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncShowRatedEx).Seasons[0].Episodes[0].Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddEpisodeToRatingsEx(obj as TraktSyncShowRatedEx);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveEpisodeFromRatingsEx(obj as TraktSyncShowRatedEx);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncShowRated)
            {
                var item = rateObject as TraktSyncShowRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncShowRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddShowToRatings(obj as TraktSyncShowRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveShowFromRatings(obj as TraktShow);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncSeasonRatedEx)
            {
                // for when season ids are not available we need to sync with both season and show details
                var item = rateObject as TraktSyncSeasonRatedEx;
                currentRating          = ratingDlg.Rated;
                item.Seasons[0].Rating = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncSeasonRatedEx).Seasons[0].Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddSeasonToRatingsEx(obj as TraktSyncSeasonRatedEx);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveSeasonFromRatingsEx(obj as TraktSyncSeasonRatedEx);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else
            {
                var item = rateObject as TraktSyncMovieRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncMovieRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddMovieToRatings(obj as TraktSyncMovieRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveMovieFromRatings(obj as TraktMovie);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }

            return((int)currentRating);
        }
Esempio n. 2
0
        /// <summary>
        /// Shows a Trakt Rate Dialog (Love/Hate) or 10-Heart based on settings
        /// </summary>
        /// <param name="rateObject">Type of object being rated</param>
        public static string ShowRateDialog <T>(T rateObject)
        {
            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowRateDialogDelegate <T> d = ShowRateDialog <T>;
                return((string)GUIGraphicsContext.form.Invoke(d, rateObject));
            }

            TraktRateValue currentRating = TraktRateValue.unrate;

            GUIRateDialog ratingDlg = (GUIRateDialog)GUIWindowManager.GetWindow(GUIRateDialog.ID);

            ratingDlg.Reset();

            ratingDlg.SetHeading(Translation.RateHeading);

            // show simple love/hate icons or 10-heart icons
            ratingDlg.ShowAdvancedRatings = TraktSettings.ShowAdvancedRatingsDialog;

            // if item is not rated, it will default to love
            if (rateObject is TraktRateEpisode)
            {
                TraktRateEpisode item = rateObject as TraktRateEpisode;
                ratingDlg.SetLine(1, string.Format("{0} - {1}x{2}", item.Title, item.Season, item.Episode));
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }
            else if (rateObject is TraktRateSeries)
            {
                TraktRateSeries item = rateObject as TraktRateSeries;
                ratingDlg.SetLine(1, item.Title);
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }
            else
            {
                TraktRateMovie item = rateObject as TraktRateMovie;
                ratingDlg.SetLine(1, item.Title);
                if (ratingDlg.ShowAdvancedRatings)
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
                else
                {
                    ratingDlg.Rated = item.Rating == "0" || !item.Rating.IsNumber() ? TraktRateValue.ten : (TraktRateValue)Convert.ToInt32(item.Rating);
                }
            }

            // show dialog
            ratingDlg.DoModal(ratingDlg.GetID);

            if (!ratingDlg.IsSubmitted)
            {
                return("-1");
            }

            if (rateObject is TraktRateEpisode)
            {
                TraktRateEpisode item = rateObject as TraktRateEpisode;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateEpisode(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktRateSeries)
            {
                TraktRateSeries item = rateObject as TraktRateSeries;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateSeries(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else
            {
                TraktRateMovie item = rateObject as TraktRateMovie;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating != 0 ? ((int)currentRating).ToString() : "unrate";
                Thread rateThread = new Thread(delegate(object obj)
                {
                    TraktRateResponse response = TraktAPI.TraktAPI.RateMovie(item);
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }

            // return new rating (0 - 10)
            // old love / hate enum values are deprecated
            // if using basic ratings 1 = hate and 10 = love
            // 0 is unrate
            return(((int)currentRating).ToString());
        }
        /// <summary>
        /// Shows a Trakt Rate Dialog
        /// </summary>
        /// <param name="rateObject">Type of object being rated</param>
        public static int ShowRateDialog <T>(T rateObject)
        {
            // Wait playback is fully stopped to avoid loop on stop
            while (g_Player.FullScreen || GUIGraphicsContext.Vmr9Active)
            {
                Thread.Sleep(10);
            }

            if (!GUICommon.CheckLogin(false))
            {
                return(-1);
            }

            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowRateDialogDelegate <T> d = ShowRateDialog <T>;
                return((int)GUIGraphicsContext.form.Invoke(d, rateObject));
            }

            // The WiFi Remote is using an older version of the API which causes a conflict after recent refactoring
            // This check is put in place so it does not cripple users experience when rate dialog is invoked
            if (!TraktHelper.IsWifiRemotePluginCompatible)
            {
                GUIUtils.ShowOKDialog(Translation.Error, Translation.WifiRemotePluginInCompatible);
                return(-1);
            }

            TraktRateValue currentRating = TraktRateValue.unrate;

            var ratingDlg = (GUIRateDialog)GUIWindowManager.GetWindow(GUIRateDialog.ID);

            ratingDlg.Reset();

            ratingDlg.SetHeading(Translation.RateHeading);

            // if item is not rated, it will default to seven
            if (rateObject is TraktSyncEpisodeRated)
            {
                var item = rateObject as TraktSyncEpisodeRated;
                ratingDlg.SetLine(1, string.Format("{0}x{1} - {2}", item.Season, item.Number, item.Title));
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }
            else if (rateObject is TraktSyncShowRatedEx)
            {
                // for when episode ids are not available we need to sync with both episode and show details
                var item = rateObject as TraktSyncShowRatedEx;
                ratingDlg.SetLine(1, string.Format("{0} - {1}x{2}", item.Title, item.Seasons[0].Number, item.Seasons[0].Episodes[0].Number));
                ratingDlg.Rated = item.Seasons[0].Episodes[0].Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Seasons[0].Episodes[0].Rating);
            }
            else if (rateObject is TraktSyncShowRated)
            {
                var item = rateObject as TraktSyncShowRated;
                ratingDlg.SetLine(1, item.Title);
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }
            else if (rateObject is TraktSyncSeasonRatedEx)
            {
                // for when season ids are not available we need to sync with both season and show details
                var item = rateObject as TraktSyncSeasonRatedEx;
                ratingDlg.SetLine(1, string.Format("{0} - {1} {2}", item.Title, Translation.Season, item.Seasons[0].Number));
                ratingDlg.Rated = item.Seasons[0].Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Seasons[0].Rating);
            }
            else
            {
                var item = rateObject as TraktSyncMovieRated;
                ratingDlg.SetLine(1, item.Title);
                ratingDlg.Rated = item.Rating == 0 ? TraktRateValue.seven : (TraktRateValue)Convert.ToInt32(item.Rating);
            }

            // show dialog
            ratingDlg.DoModal(ratingDlg.GetID);

            if (!ratingDlg.IsSubmitted)
            {
                return(-1);
            }

            TraktSyncResponse response = null;

            if (rateObject is TraktSyncEpisodeRated)
            {
                var item = rateObject as TraktSyncEpisodeRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncEpisodeRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddEpisodeToRatings(obj as TraktSyncEpisodeRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveEpisodeFromRatings(obj as TraktEpisode);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncShowRatedEx)
            {
                // for when episode ids are not available we need to sync with both episode and show details
                var item = rateObject as TraktSyncShowRatedEx;
                currentRating = ratingDlg.Rated;
                item.Seasons[0].Episodes[0].Rating = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncShowRatedEx).Seasons[0].Episodes[0].Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddEpisodeToRatingsEx(obj as TraktSyncShowRatedEx);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveEpisodeFromRatingsEx(obj as TraktSyncShowRatedEx);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncShowRated)
            {
                var item = rateObject as TraktSyncShowRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncShowRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddShowToRatings(obj as TraktSyncShowRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveShowFromRatings(obj as TraktShow);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else if (rateObject is TraktSyncSeasonRatedEx)
            {
                // for when season ids are not available we need to sync with both season and show details
                var item = rateObject as TraktSyncSeasonRatedEx;
                currentRating          = ratingDlg.Rated;
                item.Seasons[0].Rating = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncSeasonRatedEx).Seasons[0].Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddSeasonToRatingsEx(obj as TraktSyncSeasonRatedEx);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveSeasonFromRatingsEx(obj as TraktSyncSeasonRatedEx);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }
            else
            {
                var item = rateObject as TraktSyncMovieRated;
                currentRating = ratingDlg.Rated;
                item.Rating   = (int)currentRating;
                var rateThread = new Thread((obj) =>
                {
                    if ((obj as TraktSyncMovieRated).Rating > 0)
                    {
                        response = TraktAPI.TraktAPI.AddMovieToRatings(obj as TraktSyncMovieRated);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.RemoveMovieFromRatings(obj as TraktMovie);
                    }
                    TraktLogger.LogTraktResponse(response);
                })
                {
                    IsBackground = true,
                    Name         = "Rate"
                };
                rateThread.Start(item);
            }

            return((int)currentRating);
        }