예제 #1
0
        /// <summary>
        /// Displays a yes/no dialog with custom labels for the buttons.
        /// This method may become obsolete in the future if media portal adds more dialogs.
        /// </summary>
        /// <returns>True if yes was clicked, False if no was clicked</returns>
        public static bool ShowCustomYesNoDialog(string heading, string lines, string yesLabel, string noLabel, bool defaultYes)
        {
            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowCustomYesNoDialogDelegate d = ShowCustomYesNoDialog;
                return((bool)GUIGraphicsContext.form.Invoke(d, heading, lines, yesLabel, noLabel, defaultYes));
            }

            GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            try
            {
                dlgYesNo.Reset();
                dlgYesNo.SetHeading(heading);
                string[] linesArray = lines.Split(new string[] { "\\n", "\n" }, StringSplitOptions.None);
                if (linesArray.Length > 0)
                {
                    dlgYesNo.SetLine(1, linesArray[0]);
                }
                if (linesArray.Length > 1)
                {
                    dlgYesNo.SetLine(2, linesArray[1]);
                }
                if (linesArray.Length > 2)
                {
                    dlgYesNo.SetLine(3, linesArray[2]);
                }
                if (linesArray.Length > 3)
                {
                    dlgYesNo.SetLine(4, linesArray[3]);
                }
                dlgYesNo.SetDefaultToYes(defaultYes);

                foreach (GUIControl item in dlgYesNo.Children)
                {
                    if (item is GUIButtonControl)
                    {
                        GUIButtonControl btn = (GUIButtonControl)item;
                        if (btn.GetID == 11 && !string.IsNullOrEmpty(yesLabel)) // Yes button
                        {
                            btn.Label = yesLabel;
                        }
                        else if (btn.GetID == 10 && !string.IsNullOrEmpty(noLabel)) // No button
                        {
                            btn.Label = noLabel;
                        }
                    }
                }
                dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                return(dlgYesNo.IsConfirmed);
            }
            finally
            {
                // set the standard yes/no dialog back to it's original state (yes/no buttons)
                if (dlgYesNo != null)
                {
                    dlgYesNo.ClearAll();
                }
            }
        }
예제 #2
0
        public bool IsStillListening()
        {
            logger.Debug("Idle Time: " + (DateTime.Now - lastButtonPress) + " / " + Core.MusicBox.User.TimeoutInterval);
            if (DateTime.Now - lastButtonPress < Core.MusicBox.User.TimeoutInterval)
            {
                return(true);
            }

            GUIDialogYesNo dialog = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            dialog.Reset();
            dialog.SetHeading("Pandora");
            dialog.SetLine(1, "We pay for each song we play so we try");
            dialog.SetLine(2, "not to play to an empty room.");
            dialog.SetLine(3, " ");
            dialog.SetLine(4, "Are you still listening?");
            dialog.SetDefaultToYes(true);
            dialog.DoModal(GetID);

            if (dialog.IsConfirmed)
            {
                lastButtonPress = DateTime.Now;
                return(true);
            }

            return(false);
        }
예제 #3
0
        private void OnRestoreDefaults()
        {
            GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            if (dlgYesNo != null)
            {
                dlgYesNo.Reset();
                dlgYesNo.SetHeading(927);
                dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.RestoreDefaults));
                dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                dlgYesNo.SetLine(3, string.Empty);
                dlgYesNo.SetDefaultToYes(false);
                dlgYesNo.DoModal(GetID);

                if (dlgYesNo.IsConfirmed)
                {
                    Proxies.ConfigurationService.SetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.CreateVideoThumbnails, null).Wait();
                    Proxies.ConfigurationService.SetBooleanValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.AlwaysCreateMetadataFiles, null).Wait();
                    Proxies.ConfigurationService.SetStringValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PreferredGuideSource, null).Wait();
                    Proxies.ConfigurationService.SetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PreRecordsSeconds, null).Wait();
                    Proxies.ConfigurationService.SetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.PostRecordsSeconds, null).Wait();
                    Proxies.ConfigurationService.SetStringValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.DefaultKeepUntilMode, null).Wait();
                    Proxies.ConfigurationService.SetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.DefaultKeepUntilValue, null).Wait();
                    Proxies.ConfigurationService.SetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.FreeDiskSpaceInMB, null).Wait();
                    Proxies.ConfigurationService.SetIntValue(ConfigurationModule.Scheduler, ConfigurationKey.Scheduler.MinimumFreeDiskSpaceInMB, null).Wait();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Show a yes/no dialog and if the user accepts, show a select dialog. After that, send the result to the sender.
        /// </summary>
        /// <param name="dialogId">Id of dialog</param>
        /// <param name="title">Dialog title</param>
        /// <param name="text">Dialog text</param>
        /// <param name="options">Options for the user to choose from</param>
        /// <param name="socketServer">Server</param>
        /// <param name="sender">Sender of the request</param>
        internal static void ShowYesNoThenSelectDialog(string dialogId, string title, string text, List <string> options, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            GUIDialogYesNo      dlg    = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
            MessageDialogResult result = new MessageDialogResult();

            result.DialogId    = dialogId;
            result.YesNoResult = false;

            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(title);
                dlg.SetLine(1, text);
                dlg.DoModal(GUIWindowManager.ActiveWindow);
            }

            if (dlg.IsConfirmed && options != null && options.Count > 0)
            {
                if (options.Count == 1)
                {
                    //only one option, no need to show select dialog
                    result.SelectedOption = options[0];
                    result.YesNoResult    = true;
                }
                else
                {
                    //multiple options available, show select menu to user
                    GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                    if (dlgMenu != null)
                    {
                        dlgMenu.Reset();

                        dlgMenu.SetHeading(title);

                        if (options != null)
                        {
                            foreach (string o in options)
                            {
                                dlgMenu.Add(o);
                            }
                        }


                        //dlg.SetLine(1, text);
                        dlgMenu.DoModal(GUIWindowManager.ActiveWindow);

                        if (dlgMenu.SelectedId != -1)
                        {
                            result.YesNoResult    = true;
                            result.SelectedOption = dlgMenu.SelectedLabelText;
                        }
                    }
                }
            }

            socketServer.SendMessageToClient(result, sender);
        }
예제 #5
0
        /// <summary>
        /// Displays a yes/no dialog with custom labels for the buttons
        /// This method may become obsolete in the future if media portal adds more dialogs
        /// </summary>
        /// <returns>True if yes was clicked, False if no was clicked</returns>
        /// This has been taken (stolen really) from the wonderful MovingPictures Plugin -Anthrax.
        public bool ShowCustomYesNo(int parentWindowID, string heading, string lines, string yesLabel, string noLabel, bool defaultYes)
        {
            GUIDialogYesNo dialog = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            try {
                dialog.Reset();
                dialog.SetHeading(heading);
                string[] linesArray = lines.Split(new string[] { "\\n" }, StringSplitOptions.None);
                if (linesArray.Length > 0)
                {
                    dialog.SetLine(1, linesArray[0]);
                }
                if (linesArray.Length > 1)
                {
                    dialog.SetLine(2, linesArray[1]);
                }
                if (linesArray.Length > 2)
                {
                    dialog.SetLine(3, linesArray[2]);
                }
                if (linesArray.Length > 3)
                {
                    dialog.SetLine(4, linesArray[3]);
                }
                dialog.SetDefaultToYes(defaultYes);

                foreach (var item in dialog.Children)
                {
                    if (item is GUIButtonControl)
                    {
                        GUIButtonControl btn = (GUIButtonControl)item;
                        if (btn.GetID == 11 && !String.IsNullOrEmpty(yesLabel)) // Yes button
                        {
                            btn.Label = yesLabel;
                        }
                        else if (btn.GetID == 10 && !String.IsNullOrEmpty(noLabel)) // No button
                        {
                            btn.Label = noLabel;
                        }
                    }
                }
                dialog.DoModal(parentWindowID);
                return(dialog.IsConfirmed);
            } finally {
                // set the standard yes/no dialog back to it's original state (yes/no buttons)
                if (dialog != null)
                {
                    dialog.ClearAll();
                }
            }
        }
예제 #6
0
        public static bool DialogConfirm(string msg)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            if (dlg == null)
            {
                return(false);
            }

            dlg.Reset();
            dlg.SetHeading("Confirm");
            dlg.SetLine(2, msg);
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            return(dlg.IsConfirmed);
        }
예제 #7
0
        protected override void OnPageDestroy(int new_windowId)
        {
            SaveSettings(false);
            GUIWaitCursor.Hide();

            if (_mpRestartNeeded)
            {
                GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_YES_NO);
                if (dlgYesNo != null)
                {
                    dlgYesNo.Reset();
                    dlgYesNo.SetHeading(927);
                    dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.RecommendedToRestartMP));
                    dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.RestartMPNow));
                    dlgYesNo.SetDefaultToYes(true);
                    dlgYesNo.DoModal(GetID);

                    if (dlgYesNo.IsConfirmed)
                    {
                        Utility.RestartMP();
                    }
                }
            }
            else if (_restartPlayerNeeded)
            {
                if (g_Player.Playing && (g_Player.IsTV || g_Player.IsRadio || g_Player.IsTVRecording))
                {
                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_YES_NO);
                    if (dlgYesNo != null)
                    {
                        dlgYesNo.Reset();
                        dlgYesNo.SetHeading(927);
                        dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.RecommendedToStopPlayback));
                        dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.StopPlayBackNow));
                        dlgYesNo.SetDefaultToYes(true);
                        dlgYesNo.DoModal(GetID);

                        if (dlgYesNo.IsConfirmed)
                        {
                            g_Player.Stop();
                        }
                    }
                }
            }
            base.OnPageDestroy(new_windowId);
        }
예제 #8
0
        /// <summary>
        /// Show a yes no dialog in MediaPortal and send the result to the sender
        /// </summary>
        /// <param name="dialogId">Id of dialog</param>
        /// <param name="title">Dialog title</param>
        /// <param name="text">Dialog text</param>
        /// <param name="socketServer">Server</param>
        /// <param name="sender">Sender of the request</param>
        internal static void ShowYesNoDialog(string dialogId, string title, string text, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(title);
                dlg.SetLine(1, text);
                dlg.DoModal(GUIWindowManager.ActiveWindow);

                MessageDialogResult result = new MessageDialogResult();
                result.YesNoResult = dlg.IsConfirmed;
                result.DialogId    = dialogId;

                socketServer.SendMessageToClient(result, sender);
            }
        }
예제 #9
0
        private void OnDeleteAllGuideData()
        {
            GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            if (dlgYesNo != null)
            {
                dlgYesNo.Reset();
                dlgYesNo.SetHeading(927);
                dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.DeleteAllGuideData));
                dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                dlgYesNo.SetLine(3, string.Empty);
                dlgYesNo.SetDefaultToYes(false);
                dlgYesNo.DoModal(GetID);

                if (dlgYesNo.IsConfirmed)
                {
                    Proxies.GuideService.DeleteAllPrograms().Wait();
                }
            }
        }
예제 #10
0
        private bool OnDeleteChannel(Channel channel)
        {
            GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

            if (dlgYesNo != null)
            {
                dlgYesNo.Reset();
                dlgYesNo.SetHeading(channel.DisplayName);
                dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.DeleteChannel));
                dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                dlgYesNo.SetLine(3, string.Empty);
                dlgYesNo.SetDefaultToYes(false);
                dlgYesNo.DoModal(GetID);

                if (dlgYesNo.IsConfirmed)
                {
                    Proxies.SchedulerService.DeleteChannel(channel.ChannelId, true).Wait();
                    return(true);
                }
            }
            return(false);
        }
예제 #11
0
        public void TorrentsContextMenu(Torrent uTorrent)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading("Torrent details menu");
            if (uTorrent.Started())
            {
                dlg.Add("Stop");
            }
            else
            {
                dlg.Add("Start");
            }

            if (uTorrent.Paused())
            {
                dlg.Add("Resume");
            }
            else
            {
                dlg.Add("Pause");
            }


            dlg.Add("Remove");
            dlg.Add("Start All");
            dlg.Add("Stop All");
            dlg.Add("Pause All");
            dlg.Add("Resume All");

            dlg.DoModal(GUIWindowManager.ActiveWindow);

            Menu menu = new Menu();

            switch (dlg.SelectedLabelText)
            {
            case "Start":
            {
                TorrentEngine.Instance().TorrentSession.Start(uTorrent.Hash);;
                break;
            };

            case "Stop":
            {
                TorrentEngine.Instance().TorrentSession.Stop(uTorrent.Hash);;
                break;
            };

            case "Resume":
            {
                TorrentEngine.Instance().TorrentSession.Resume(uTorrent.Hash);
                break;
            };

            case "Pause":
            {
                TorrentEngine.Instance().TorrentSession.Pause(uTorrent.Hash);
                break;
            };

            case "Remove":
            {
                GUIDialogYesNo ask = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                ask.Reset();
                ask.SetHeading("Remove also files?");
                ask.SetLine(1, "Files are removed permanently.");
                ask.SetLine(2, "Cannot be undone.");
                ask.SetDefaultToYes(false);
                ask.DoModal(GUIWindowManager.ActiveWindow);

                if (ask.IsConfirmed)
                {
                    TorrentEngine.Instance().TorrentSession.Remove(uTorrent.Hash, true);
                }
                else
                {
                    TorrentEngine.Instance().TorrentSession.Remove(uTorrent.Hash, false);
                }
                break;
            };

            case "Start All":
            {
                TorrentEngine.Instance().TorrentSession.Start(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Stop All":
            {
                TorrentEngine.Instance().TorrentSession.Stop(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Pause All":
            {
                TorrentEngine.Instance().TorrentSession.Pause(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };

            case "Resume All":
            {
                TorrentEngine.Instance().TorrentSession.Resume(TorrentEngine.Instance().TorrentSession.TorrentsAll);
                break;
            };
            }
        }
예제 #12
0
 void DoSubsequentLoad()
 {
     if (PreviousWindowId != OnlineVideos.MediaPortal1.Player.GUIOnlineVideoFullscreen.WINDOW_FULLSCREEN_ONLINEVIDEO &&
         PluginConfiguration.Instance.updateOnStart != false &&
         PluginConfiguration.Instance.lastFirstRun.AddHours(PluginConfiguration.Instance.updatePeriod) < DateTime.Now)
     {
         bool?doUpdate = PluginConfiguration.Instance.updateOnStart;
         if (!PluginConfiguration.Instance.updateOnStart.HasValue && !preventDialogOnLoad)
         {
             GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
             if (dlg != null)
             {
                 dlg.Reset();
                 dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlg.SetLine(1, Translation.Instance.PerformAutomaticUpdate);
                 dlg.SetLine(2, Translation.Instance.UpdateAllYourSites);
                 dlg.DoModal(GUIWindowManager.ActiveWindow);
                 doUpdate = dlg.IsConfirmed;
             }
         }
         PluginConfiguration.Instance.lastFirstRun = DateTime.Now;
         if (doUpdate == true || PluginConfiguration.Instance.ThumbsAge >= 0)
         {
             GUIDialogProgress dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
             if (dlgPrgrs != null)
             {
                 dlgPrgrs.Reset();
                 dlgPrgrs.DisplayProgressBar = true;
                 dlgPrgrs.ShowWaitCursor     = false;
                 dlgPrgrs.DisableCancel(true);
                 dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlgPrgrs.StartModal(GUIWindowManager.ActiveWindow);
             }
             else
             {
                 GUIWaitCursor.Init(); GUIWaitCursor.Show();
             }
             new System.Threading.Thread(delegate()
             {
                 if (doUpdate == true)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(string.Format("{0} - {1}", PluginConfiguration.Instance.BasicHomeScreenName, Translation.Instance.AutomaticUpdate));
                     }
                     var onlineVersion = Sites.Updater.VersionOnline;
                     if (OnlineVideos.Sites.Updater.VersionCompatible)
                     {
                         bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites((m, p) =>
                         {
                             if (dlgPrgrs != null)
                             {
                                 if (!string.IsNullOrEmpty(m))
                                 {
                                     dlgPrgrs.SetLine(1, m);
                                 }
                                 if (p != null)
                                 {
                                     dlgPrgrs.SetPercentage(p.Value);
                                 }
                                 return(dlgPrgrs.ShouldRenderLayer());
                             }
                             else
                             {
                                 return(true);
                             }
                         }
                                                                                    );
                         if (updateResult == true && OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             GUISiteUpdater.ReloadDownloadedDlls();
                         }
                         else if (updateResult == null || OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             OnlineVideoSettings.Instance.BuildSiteUtilsList();
                         }
                         if (updateResult != false)
                         {
                             PluginConfiguration.Instance.BuildAutomaticSitesGroups();
                             SiteImageExistenceCache.ClearCache();
                         }
                     }
                     else
                     {
                         // inform the user that autoupdate is disabled due to outdated version!
                         dlgPrgrs.SetLine(1, Translation.Instance.AutomaticUpdateDisabled);
                         dlgPrgrs.SetLine(2, onlineVersion != null ? string.Format(Translation.Instance.LatestVersionRequired, onlineVersion) : "Check your Internet Connection!");
                         Thread.Sleep(5000);
                         dlgPrgrs.SetLine(2, string.Empty);
                     }
                 }
                 if (PluginConfiguration.Instance.ThumbsAge >= 0)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                         dlgPrgrs.SetLine(1, Translation.Instance.DeletingOldThumbs);
                         dlgPrgrs.Percentage = 0;
                     }
                     ImageDownloader.DeleteOldThumbs(PluginConfiguration.Instance.ThumbsAge, r =>
                     {
                         if (dlgPrgrs != null)
                         {
                             dlgPrgrs.Percentage = r;
                         }
                         return(dlgPrgrs != null ? dlgPrgrs.ShouldRenderLayer() : true);
                     });
                 }
                 if (dlgPrgrs != null)
                 {
                     dlgPrgrs.Percentage = 100; dlgPrgrs.SetLine(1, Translation.Instance.Done); dlgPrgrs.Close();
                 }
                 else
                 {
                     GUIWaitCursor.Hide();
                 }
                 GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) =>
                 {
                     DoPageLoad();
                     return(0);
                 }, 0, 0, null);
             })
             {
                 Name = "OVLoad", IsBackground = true
             }.Start();
             return;
         }
     }
     DoPageLoad();
 }
예제 #13
0
        public bool Scrobble(string filename)
        {
            StopScrobble();
            istStoppingScrobble = false;

            if (!g_Player.IsTV)
            {
                return(false);
            }

            EbasicHandler.setCurrentProgram(GetCurrentProgram());

            if (EbasicHandler.getCurrentProgram() == null)
            {
                return(false);
            }
            EbasicHandler.SetCurrentProgramIsScrobbling(true);

            TVJustTurnedOn = true;
            if (EbasicHandler.getCurrentProgramType() == VideoType.Series)
            {
                TraktLogger.Info("Detected tv show playing on Live TV. Title = '{0}'", EbasicHandler.getCurrentProgram().Title.ToString());
            }
            else
            {
                TraktLogger.Info("Detected movie playing on Live TV. Title = '{0}'", EbasicHandler.getCurrentProgram().Title.ToString());
            }

            #region Scrobble Timer

            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                // get the current program airing on tv now
                // this may have changed since last status update on trakt
                EVideoInfo videoInfo = GetCurrentProgram();

                //Reinit all variables
                item     = new TraktEPGCacheRecord();
                response = new TraktScrobbleResponse();

                // I have problems with GUI rendering most of the times. If i set the thread to sleep it really helps with GUI rendering.
                // This might also work well to handle zapping correctly.
                Thread.Sleep((TraktSettings.ETVScrobbleDelay) * 1000);

                try
                {
                    if (videoInfo != null)
                    {
                        // if we are watching something different,
                        // check if we should mark previous as watched
                        //if (!videoInfo.Equals(CurrentProgram))

                        if (!videoInfo.Equals(EbasicHandler.getCurrentProgram()))
                        {
                            TraktLogger.Info("Detected new tv program has started. Previous Program = '{0}', New Program = '{1}'", EbasicHandler.getCurrentProgram().ToString(), videoInfo.ToString());
                            //The new program has changed. I should check if the active window is GUIShowSelect and eventually close it.
                            if (GUIWindowManager.ActiveWindow.Equals((int)TraktGUIWindows.EPGShowSelect))
                            {
                                GUIShowSelectGUI.exitGUI();
                            }
                            if (IsProgramWatched(EbasicHandler.getCurrentProgram()) && EbasicHandler.IsCurrentProgramScrobbling())
                            {
                                TraktLogger.Info("Playback of program on Live TV is considered watched. Title = '{0}'", EbasicHandler.getCurrentProgram().ToString());
                                BasicHandler.StopScrobble(EbasicHandler.getCurrentProgram(), true);
                            }
                            //The programs are different so we should start the whole scrobbling process.
                            //For that we set the new videoInfo scrobbling status to true
                            //later we're checking if videoInfo is scrobbling, and it should be false if we don't set it true here.
                            videoInfo.IsScrobbling = true;
                            //EbasicHandler.SetCurrentProgramIsScrobbling(true);
                        }

                        // continue watching new program
                        // dont try to scrobble if previous attempt failed
                        // If the current program is scrobbling, according to the APIARY there's no need to resend every 15 minutes,
                        // it will expire after runtime has elapsed.

                        if ((videoInfo.IsScrobbling) | (TVJustTurnedOn))
                        {
                            TVJustTurnedOn = false;
                            //Starts the scrobble of the new program because it changed
                            //cache should search here because some shows have no name and could be in cache.

                            #region CACHE CHECK and SCROBBLE from CACHE
                            if (EPGCache.searchOnCache(videoInfo.Title, out item))
                            {
                                if (item.Type.Equals("nullRecord"))
                                {
                                    response.Code        = 901;
                                    response.Description = "Manually set don't scrobble";
                                }
                                else if ((item.Type.Equals("movie")) & (videoInfo.Type == VideoType.Movie))
                                {
                                    EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Movie);
                                    response = EbasicHandler.StartScrobbleMovie(videoInfo);
                                }
                                else if ((item.Type.Equals("show")) & (videoInfo.Type == VideoType.Series))
                                {
                                    EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Show);
                                    response = EbasicHandler.StartScrobbleEpisode(videoInfo);
                                }
                                else
                                //The item type is different from the videoinfo type. Cache is authoritative here so overriding videoInfo with the cache.
                                //It's most likely that a show is detected wrong as a movie, because a movie with episode and season number is totally nonsense, but handles both.
                                {
                                    response.Code = 904; //This code will be used later.
                                    if (item.Type.Equals("show"))
                                    {
                                        EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Show);
                                        response.Description = item.Show.Ids.Slug;
                                    }
                                    else
                                    {
                                        EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Movie);
                                    }
                                }
                            }// end cache thingy if it was successful it should be scrobbled.
                            #endregion
                            #region CACHE MATCH UNSUCCESSFUL: TRY RETRIEVE ORIGINAL LANGUAGE AND SCROBBLE
                            else
                            {
                                #region FOUND ORIGINAL LANGUAGE TITLE WITH A SINGLE MATCH
                                // Try first to scrobble without changing anything. This is to avoid problems with shows that uses
                                // real non translated shows. In this case the name of the show usually is enough to succesfully scrobble.
                                if (videoInfo.Type == VideoType.Series)
                                {
                                    response = EbasicHandler.StartScrobbleEpisode(videoInfo);
                                }
                                else
                                {
                                    response = EbasicHandler.StartScrobbleMovie(videoInfo);
                                }
                                if (!(response.Code == 0) && EbasicHandler.setOriginalTitle(ref videoInfo))
                                {
                                    if ((videoInfo.Type == VideoType.Series))
                                    {
                                        response = EbasicHandler.StartScrobbleEpisode(videoInfo);
                                    }
                                    else
                                    {
                                        response = EbasicHandler.StartScrobbleMovie(videoInfo);
                                    }
                                }
                                #endregion
                                #region NO CACHE, NO ORIGINAL LANGUAGE SINGLE MATCH FOUND everything is very likely to fail.
                                else if (!response.Code.Equals(0))
                                {
                                    response.Code        = 404;
                                    response.Description = "Not Found";
                                }
                                #endregion
                            }
                            #endregion
                            EbasicHandler.setCurrentProgram(videoInfo);
                            if (response.Code.Equals(901))
                            {
                                TraktLogger.Info("Program {0} skipped because manually marked to skip on cache", videoInfo.Title);
                            }
                            else if (response.Code.Equals(0))
                            {
                                if (TraktSettings.AllowPopUPOnSuccessfulScrobbling)
                                {
                                    GUIDialogNotify notification = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                                    notification.Reset();
                                    notification.SetHeading(string.Format("{0} scrobbled!", EbasicHandler.getCurrentProgram().Type.ToString()));
                                    notification.SetText(string.Format("Scrobbling '{0}' as '{1}'", EbasicHandler.getCurrentProgram().getOriginalTitle(), EbasicHandler.getCurrentProgram().Title));
                                    notification.SetImage(Path.Combine(Config.GetFolder(Config.Dir.Skin), string.Format(@"{0}\Media\Logos\trakt.png", Config.SkinName)));
                                    notification.DoModal(GUIWindowManager.ActiveWindow);
                                }
                            }
                            else // the response was bad! Everything gone worse than ever, again open the GUI
                            {
                                GUIDialogYesNo askManualSelection = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                if (askManualSelection != null)
                                {
                                    askManualSelection.Reset();
                                    askManualSelection.SetHeading("Start manual matching?");
                                    askManualSelection.SetLine(1, string.Format("Cannot find a match for '{0}'", videoInfo.Title));
                                    askManualSelection.SetDefaultToYes(true);
                                    askManualSelection.DoModal(GUIWindowManager.ActiveWindow);
                                    if (askManualSelection.IsConfirmed)
                                    {
                                        if (!istStoppingScrobble) //maybe we can handle this better. If the user stops the program right before this the plugin crashes.
                                        {
                                            EbasicHandler.StartGui(response.Code, item, TraktSettings.GUIAsDialog);
                                        }
                                    }
                                    else
                                    {
                                        // Need to handle cancel button with a null on cache to avoid future scrobbling.
                                        EPGCache.addOnCache(videoInfo.Title);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (NullReferenceException exception)
                {
                    //handle the worst. This usually happens when the user stops the player during a dialog.
                    //We should at least log this in the mediaportal error.
                }
            }), null, 1000, 300000);

            #endregion
            return(true);
        }
예제 #14
0
        protected override void OnShowContextMenu()
        {
            int         iItem = GetSelectedItemNo();
            GUIListItem pItem = GetItem(iItem);

            if (pItem == null)
            {
                return;
            }
            if (pItem.IsFolder)
            {
                ScheduleSummary schedule = pItem.TVTag as ScheduleSummary;
                if (schedule != null)
                {
                    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                    if (dlg == null)
                    {
                        return;
                    }
                    dlg.Reset();
                    dlg.SetHeading(schedule.Name ?? string.Empty);
                    dlg.Add(Utility.GetLocalizedText(TextId.Settings));
                    if (schedule.IsActive)
                    {
                        dlg.Add(Utility.GetLocalizedText(TextId.CancelThisSchedule));
                    }
                    else
                    {
                        dlg.Add(Utility.GetLocalizedText(TextId.UnCancelThisSchedule));
                    }

                    dlg.Add(Utility.GetLocalizedText(TextId.DeleteThisSchedule));
                    dlg.DoModal(GetID);

                    Schedule _sched = Proxies.SchedulerService.GetScheduleById(schedule.ScheduleId).Result;
                    switch (dlg.SelectedLabel)
                    {
                    case 0:
                        if (_sched != null)
                        {
                            var programs = Proxies.SchedulerService.GetUpcomingPrograms(_sched, true).Result;
                            if (programs != null && programs.Count > 0)
                            {
                                OnEditSchedule(programs[0]);
                            }
                        }
                        break;

                    case 1:
                        if (_sched != null)
                        {
                            if (_sched.IsActive)
                            {
                                _sched.IsActive = false;
                                Proxies.SchedulerService.SaveSchedule(_sched).Wait();
                            }
                            else
                            {
                                _sched.IsActive = true;
                                Proxies.SchedulerService.SaveSchedule(_sched).Wait();
                            }
                        }
                        break;

                    case 2:
                    {
                        GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                        if (dlgYesNo != null)
                        {
                            dlgYesNo.Reset();
                            dlgYesNo.SetHeading(schedule.Name);
                            dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.DeleteThisSchedule));
                            dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                            dlgYesNo.SetLine(3, string.Empty);
                            dlgYesNo.SetDefaultToYes(false);
                            dlgYesNo.DoModal(GetID);

                            if (dlgYesNo.IsConfirmed)
                            {
                                Proxies.SchedulerService.DeleteSchedule(schedule.ScheduleId).Wait();
                                _selectedSchedule = null;
                            }
                        }
                    }
                    break;
                    }
                    m_iSelectedItem = GetSelectedItemNo();
                    LoadUpcomingPrograms(null);
                }
            }
            else
            {
                UpcomingProgram upcoming = pItem.TVTag as UpcomingProgram;
                if (upcoming != null)
                {
                    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                    if (dlg == null)
                    {
                        return;
                    }
                    dlg.Reset();
                    dlg.SetHeading(upcoming.Title);
                    dlg.Add(Utility.GetLocalizedText(TextId.Settings));
                    dlg.Add(Utility.GetLocalizedText(TextId.Priority));
                    if (upcoming.IsCancelled)
                    {
                        if (upcoming.CancellationReason == UpcomingCancellationReason.Manual)
                        {
                            dlg.Add(Utility.GetLocalizedText(TextId.UncancelThisShow));
                        }
                    }
                    else
                    {
                        dlg.Add(Utility.GetLocalizedText(TextId.CancelThisShow));
                    }
                    dlg.DoModal(GetID);

                    switch (dlg.SelectedLabel)
                    {
                    case 0:     // settings/information
                        OnEditSchedule(upcoming);
                        break;

                    case 1:     // Priority
                        OnChangePriority(upcoming);
                        break;

                    case 2:     // (Un)Cancel
                        if (upcoming.IsCancelled)
                        {
                            Proxies.SchedulerService.UncancelUpcomingProgram(upcoming.ScheduleId, upcoming.GuideProgramId, upcoming.Channel.ChannelId, upcoming.StartTime).Wait();
                        }
                        else
                        {
                            Proxies.SchedulerService.CancelUpcomingProgram(upcoming.ScheduleId, upcoming.GuideProgramId, upcoming.Channel.ChannelId, upcoming.StartTime).Wait();
                        }
                        m_iSelectedItem = GetSelectedItemNo();
                        LoadUpcomingPrograms(null);
                        break;
                    }
                }
            }
        }