ItemsList GetUserReports(OnlineSiteViewModel item) { var items = new ItemsList(); OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); var reports = ws.GetReports(item.Site.Name); foreach (var report in reports.OrderByDescending(r => r.Date)) { items.Add(new ReportViewModel(report)); } return(items); }
void ReportSite(string userReason, OnlineVideosWebservice.Site site) { if (userReason.Length < 15) { ServiceRegistration.Get <IDialogManager>().ShowDialog("[OnlineVideos.ReportBroken]", "[OnlineVideos.PleaseEnterDescription]", DialogType.OkDialog, false, DialogButtonType.Ok); } else { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); string message = ""; bool success = ws.SubmitReport(site.Name, userReason, OnlineVideosWebservice.ReportType.Broken, out message); ServiceRegistration.Get <IDialogManager>().ShowDialog(success ? "[OnlineVideos.Done]" : "[OnlineVideos.Error]", message, DialogType.OkDialog, false, DialogButtonType.Ok); if (success) { // reload online sites OnlineVideos.Sites.Updater.GetRemoteOverviews(true); GetFilteredAndSortedSites(); } } }
void ShowOptionsForSite(OnlineVideosWebservice.Site site) { SiteSettings localSite = null; int localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(site.Name, out localSite); GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); dlgSel.ShowQuickNumbers = false; if (dlgSel != null) { dlgSel.Reset(); dlgSel.SetHeading(Translation.Instance.Actions); if (localSiteIndex == -1) { if (site.State != OnlineVideosWebservice.SiteState.Broken) { dlgSel.Add(Translation.Instance.AddToMySites); } } else { if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 2 && site.State != OnlineVideosWebservice.SiteState.Broken) { dlgSel.Add(Translation.Instance.UpdateMySite); dlgSel.Add(Translation.Instance.UpdateMySiteSkipCategories); } dlgSel.Add(Translation.Instance.RemoveFromMySites); } if (GUI_infoList.Count > 1) { dlgSel.Add(Translation.Instance.RemoveAllFromMySites); dlgSel.Add(Translation.Instance.UpdateAll); dlgSel.Add(Translation.Instance.UpdateAllSkipCategories); } if (!string.IsNullOrEmpty(site.Owner_FK) && localSiteIndex >= 0) // !only local && ! only global { dlgSel.Add(Translation.Instance.ShowReports); if (site.State != OnlineVideosWebservice.SiteState.Broken) { dlgSel.Add(Translation.Instance.ReportBroken); } } } dlgSel.DoModal(GUIWindowManager.ActiveWindow); if (dlgSel.SelectedId == -1) { return; // ESC used, nothing selected } if (dlgSel.SelectedLabelText == Translation.Instance.AddToMySites || dlgSel.SelectedLabelText == Translation.Instance.UpdateMySite || dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories) { if (CheckOnlineVideosVersion()) { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( () => { bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites(null, new List <OnlineVideosWebservice.Site> { site }, false, dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories); if (updateResult == true) { newDllsDownloaded = true; } else if (updateResult == null) { newDataSaved = true; } return(updateResult != false); }, (success, result) => { if (success && (bool)result) { SiteImageExistenceCache.UnCacheImageForSite(site.Name); RefreshDisplayedOnlineSites(); } }, Translation.Instance.GettingSiteXml, true); } } else if (dlgSel.SelectedLabelText == Translation.Instance.UpdateAll || dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories) { if (CheckOnlineVideosVersion()) { GUIDialogProgress dlgPrgrs = PrepareProgressDialog(Translation.Instance.FullUpdate); new System.Threading.Thread(delegate() { 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); } }, GUI_infoList.ListItems.Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList(), dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories); if (updateResult == true) { newDllsDownloaded = true; } else if (updateResult == null) { newDataSaved = true; } if (updateResult != false) { SiteImageExistenceCache.ClearCache(); } if (dlgPrgrs != null) { dlgPrgrs.Close(); } GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) => { RefreshDisplayedOnlineSites(); return(0); }, 0, 0, null); }) { Name = "OVSelectUpdate", IsBackground = true }.Start(); } } else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveFromMySites) { OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex); OnlineVideoSettings.Instance.SaveSites(); newDataSaved = true; RefreshDisplayedOnlineSites(GUI_infoList.SelectedListItemIndex); } else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveAllFromMySites) { bool needRefresh = false; foreach (var siteToRemove in GUI_infoList.ListItems.Where(g => g.IsPlayed).Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList()) { localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(siteToRemove.Name, out localSite); if (localSiteIndex >= 0) { OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex); needRefresh = true; } } if (needRefresh) { OnlineVideoSettings.Instance.SaveSites(); newDataSaved = true; RefreshDisplayedOnlineSites(); } } else if (dlgSel.SelectedLabelText == Translation.Instance.ShowReports) { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( () => { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); return(ws.GetReports(site.Name)); }, (success, result) => { if (success) { OnlineVideosWebservice.Report[] reports = result as OnlineVideosWebservice.Report[]; if (reports == null || reports.Length == 0) { GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlg != null) { dlg.Reset(); dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetText(Translation.Instance.NoReportsForSite); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { selectedSite = site.Name; GUIControl.ClearControl(GetID, GUI_infoList.GetID); Array.Sort(reports, new Comparison <OnlineVideosWebservice.Report>(delegate(OnlineVideosWebservice.Report a, OnlineVideosWebservice.Report b) { return(b.Date.CompareTo(a.Date)); })); foreach (OnlineVideosWebservice.Report report in reports) { string shortMsg = report.Message.Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " "); GUIListItem loListItem = new GUIListItem(shortMsg.Length > 44 ? shortMsg.Substring(0, 40) + " ..." : shortMsg); loListItem.TVTag = report; loListItem.Label2 = report.Type.ToString(); loListItem.Label3 = report.Date.ToString("g", OnlineVideoSettings.Instance.Locale); loListItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnReportSelected); GUI_infoList.Add(loListItem); } GUIControl.SelectItemControl(GetID, GUI_infoList.GetID, 0); GUIPropertyManager.SetProperty("#itemcount", GUI_infoList.Count.ToString()); GUIPropertyManager.SetProperty("#itemtype", Translation.Instance.Reports); } } }, Translation.Instance.GettingReports, true); } else if (dlgSel.SelectedLabelText == Translation.Instance.ReportBroken) { if (CheckOnlineVideosVersion()) { if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 1) { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(site.Name); dlg.SetLine(1, Translation.Instance.PleaseUpdateLocalSite); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { string userReason = ""; if (GUIOnlineVideos.GetUserInputString(ref userReason, false)) { if (userReason.Length < 15) { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetLine(1, Translation.Instance.PleaseEnterDescription); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); string message = ""; bool success = ws.SubmitReport(site.Name, userReason, OnlineVideosWebservice.ReportType.Broken, out message); GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetLine(1, success ? Translation.Instance.Done : Translation.Instance.Error); dlg.SetLine(2, message); dlg.DoModal(GUIWindowManager.ActiveWindow); } if (success) { // reload online sites OnlineVideos.Sites.Updater.GetRemoteOverviews(true); RefreshDisplayedOnlineSites(); } } } } } } }
void ShowOptionsForSite(OnlineVideosWebservice.Site site) { SiteSettings localSite = null; int localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(site.Name, out localSite); GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); dlgSel.ShowQuickNumbers = false; if (dlgSel != null) { dlgSel.Reset(); dlgSel.SetHeading(Translation.Instance.Actions); if (localSiteIndex == -1) { if (site.State != OnlineVideosWebservice.SiteState.Broken) dlgSel.Add(Translation.Instance.AddToMySites); } else { if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 2 && site.State != OnlineVideosWebservice.SiteState.Broken) { dlgSel.Add(Translation.Instance.UpdateMySite); dlgSel.Add(Translation.Instance.UpdateMySiteSkipCategories); } dlgSel.Add(Translation.Instance.RemoveFromMySites); } if (GUI_infoList.Count > 1) { dlgSel.Add(Translation.Instance.RemoveAllFromMySites); dlgSel.Add(Translation.Instance.UpdateAll); dlgSel.Add(Translation.Instance.UpdateAllSkipCategories); } if (!string.IsNullOrEmpty(site.Owner_FK) && localSiteIndex >= 0) // !only local && ! only global { dlgSel.Add(Translation.Instance.ShowReports); if (site.State != OnlineVideosWebservice.SiteState.Broken) dlgSel.Add(Translation.Instance.ReportBroken); } } dlgSel.DoModal(GUIWindowManager.ActiveWindow); if (dlgSel.SelectedId == -1) return; // ESC used, nothing selected if (dlgSel.SelectedLabelText == Translation.Instance.AddToMySites || dlgSel.SelectedLabelText == Translation.Instance.UpdateMySite || dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories) { if (CheckOnlineVideosVersion()) { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( () => { bool? updateResult = OnlineVideos.Sites.Updater.UpdateSites(null, new List<OnlineVideosWebservice.Site> { site }, false, dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories); if (updateResult == true) newDllsDownloaded = true; else if (updateResult == null) newDataSaved = true; return updateResult != false; }, (success, result) => { if (success && (bool)result) { SiteImageExistenceCache.UnCacheImageForSite(site.Name); RefreshDisplayedOnlineSites(); } }, Translation.Instance.GettingSiteXml, true); } } else if (dlgSel.SelectedLabelText == Translation.Instance.UpdateAll || dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories) { if (CheckOnlineVideosVersion()) { GUIDialogProgress dlgPrgrs = PrepareProgressDialog(Translation.Instance.FullUpdate); new System.Threading.Thread(delegate() { 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; }, GUI_infoList.ListItems.Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList(), dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories); if (updateResult == true) newDllsDownloaded = true; else if (updateResult == null) newDataSaved = true; if (updateResult != false) SiteImageExistenceCache.ClearCache(); if (dlgPrgrs != null) dlgPrgrs.Close(); GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) => { RefreshDisplayedOnlineSites(); return 0; }, 0, 0, null); }) { Name = "OVSelectUpdate", IsBackground = true }.Start(); } } else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveFromMySites) { OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex); OnlineVideoSettings.Instance.SaveSites(); newDataSaved = true; RefreshDisplayedOnlineSites(GUI_infoList.SelectedListItemIndex); } else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveAllFromMySites) { bool needRefresh = false; foreach (var siteToRemove in GUI_infoList.ListItems.Where(g => g.IsPlayed).Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList()) { localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(siteToRemove.Name, out localSite); if (localSiteIndex >= 0) { OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex); needRefresh = true; } } if (needRefresh) { OnlineVideoSettings.Instance.SaveSites(); newDataSaved = true; RefreshDisplayedOnlineSites(); } } else if (dlgSel.SelectedLabelText == Translation.Instance.ShowReports) { Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback( () => { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); return ws.GetReports(site.Name); }, (success, result) => { if (success) { OnlineVideosWebservice.Report[] reports = result as OnlineVideosWebservice.Report[]; if (reports == null || reports.Length == 0) { GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlg != null) { dlg.Reset(); dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetText(Translation.Instance.NoReportsForSite); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { selectedSite = site.Name; GUIControl.ClearControl(GetID, GUI_infoList.GetID); Array.Sort(reports, new Comparison<OnlineVideosWebservice.Report>(delegate(OnlineVideosWebservice.Report a, OnlineVideosWebservice.Report b) { return b.Date.CompareTo(a.Date); })); foreach (OnlineVideosWebservice.Report report in reports) { string shortMsg = report.Message.Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " "); GUIListItem loListItem = new GUIListItem(shortMsg.Length > 44 ? shortMsg.Substring(0, 40) + " ..." : shortMsg); loListItem.TVTag = report; loListItem.Label2 = report.Type.ToString(); loListItem.Label3 = report.Date.ToString("g", OnlineVideoSettings.Instance.Locale); loListItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnReportSelected); GUI_infoList.Add(loListItem); } GUIControl.SelectItemControl(GetID, GUI_infoList.GetID, 0); GUIPropertyManager.SetProperty("#itemcount", GUI_infoList.Count.ToString()); GUIPropertyManager.SetProperty("#itemtype", Translation.Instance.Reports); } } }, Translation.Instance.GettingReports, true); } else if (dlgSel.SelectedLabelText == Translation.Instance.ReportBroken) { if (CheckOnlineVideosVersion()) { if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 1) { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(site.Name); dlg.SetLine(1, Translation.Instance.PleaseUpdateLocalSite); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { string userReason = ""; if (GUIOnlineVideos.GetUserInputString(ref userReason, false)) { if (userReason.Length < 15) { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetLine(1, Translation.Instance.PleaseEnterDescription); dlg.DoModal(GUIWindowManager.ActiveWindow); } } else { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); string message = ""; bool success = ws.SubmitReport(site.Name, userReason, OnlineVideosWebservice.ReportType.Broken, out message); GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); if (dlg != null) { dlg.Reset(); dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg.SetLine(1, success ? Translation.Instance.Done : Translation.Instance.Error); dlg.SetLine(2, message); dlg.DoModal(GUIWindowManager.ActiveWindow); } if (success) { // reload online sites OnlineVideos.Sites.Updater.GetRemoteOverviews(true); RefreshDisplayedOnlineSites(); } } } } } } }
void ReportSite(string userReason, OnlineVideosWebservice.Site site) { if (userReason.Length < 15) { ServiceRegistration.Get<IDialogManager>().ShowDialog("[OnlineVideos.ReportBroken]", "[OnlineVideos.PleaseEnterDescription]", DialogType.OkDialog, false, DialogButtonType.Ok); } else { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); string message = ""; bool success = ws.SubmitReport(site.Name, userReason, OnlineVideosWebservice.ReportType.Broken, out message); ServiceRegistration.Get<IDialogManager>().ShowDialog(success ? "[OnlineVideos.Done]" : "[OnlineVideos.Error]", message, DialogType.OkDialog, false, DialogButtonType.Ok); if (success) { // reload online sites OnlineVideos.Sites.Updater.GetRemoteOverviews(true); GetFilteredAndSortedSites(); } } }
ItemsList GetUserReports(OnlineSiteViewModel item) { var items = new ItemsList(); OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService(); var reports = ws.GetReports(item.Site.Name); foreach (var report in reports.OrderByDescending(r => r.Date)) { items.Add(new ReportViewModel(report)); } return items; }