/// <summary> /// Searches for the specified show on the specified guide. /// </summary> /// <param name="guide">The guide.</param> /// <param name="show">The show.</param> /// <param name="lang">The language.</param> /// <param name="done">The method to call when finished.</param> public void Search(Guide guide, string show, string lang, Action<string, string, string> done) { _g = guide; var showmbp = false; var mthd = new Thread(() => TaskDialog.Show(new TaskDialogOptions { Title = "Searching...", MainInstruction = show.ToUppercaseWords(), Content = "Searching on " + guide.Name + "...", CustomButtons = new[] { "Cancel" }, ShowMarqueeProgressBar = true, EnableCallbackTimer = true, AllowDialogCancellation = true, Callback = (dialog, args, data) => { if (!showmbp) { dialog.SetProgressBarMarquee(true, 0); showmbp = true; } if (args.ButtonId != 0) { if (_thd != null && _thd.IsAlive && !_cancel) { _thd.Abort(); } return false; } if (_cancel) { dialog.ClickButton(500); return false; } return true; } })); mthd.SetApartmentState(ApartmentState.STA); mthd.Start(); _thd = new Thread(() => { try { _ids = _g.GetID(show, lang).ToList(); } catch (Exception ex) { _cancel = true; TaskDialog.Show(new TaskDialogOptions { MainIcon = VistaTaskDialogIcon.Error, Title = "Search error", MainInstruction = show.ToUppercaseWords(), Content = "Error while searching on " + _g.Name + ".", ExpandedInfo = ex.Message, AllowDialogCancellation = true, CustomButtons = new[] { "OK" } }); done(null, null, null); return; } _cancel = true; if (_ids.Count == 0) { TaskDialog.Show(new TaskDialogOptions { MainIcon = VistaTaskDialogIcon.Warning, Title = "Search result", MainInstruction = show.ToUppercaseWords(), Content = "Couldn't find the specified show on " + _g.Name + ".", AllowDialogCancellation = true, CustomButtons = new[] { "OK" } }); done(null, null, null); return; } if (_ids.Count == 1) { done(_ids[0].ID, _ids[0].Title, _ids[0].Language); return; } if (_ids.Count > 1) { if (_ids.Count > 5) { _ids = _ids.Take(5).ToList(); } var td = new TaskDialogOptions { Title = "Search result", MainInstruction = show.ToUppercaseWords(), Content = "More than one show matched the search criteria on " + _g.Name + ":", AllowDialogCancellation = true, CommandButtons = new string[_ids.Count + 1] }; var i = 0; for (; i < _ids.Count; i++) { td.CommandButtons[i] = _ids[i].Title; } td.CommandButtons[i] = "None of the above"; var res = TaskDialog.Show(td); if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value < _ids.Count) { done(_ids[res.CommandButtonResult.Value].ID, _ids[res.CommandButtonResult.Value].Title, _ids[res.CommandButtonResult.Value].Language); } else { done(null, null, null); } } }); _thd.SetApartmentState(ApartmentState.STA); _thd.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="AddNewWindow"/> class. /// </summary> public EditShowWindow(int id, string show) { InitializeComponent(); _id = id; _show = show; nameTextBox.Text = _show; var release = Database.TVShows[_id]; if (!string.IsNullOrWhiteSpace(release.Data.Get("regex"))) { customReleaseName.IsChecked = releaseTextBox.IsEnabled = true; releaseTextBox.Text = release.Data.Get("regex"); } else { customReleaseName.IsChecked = releaseTextBox.IsEnabled = false; releaseTextBox.Text = ShowNames.Parser.GenerateTitleRegex(show, release).ToString(); } if (!string.IsNullOrWhiteSpace(release.Data.Get("scene"))) { customSceneName.IsChecked = sceneTextBox.IsEnabled = true; sceneTextBox.Text = release.Data.Get("scene"); } else { customSceneName.IsChecked = sceneTextBox.IsEnabled = false; sceneTextBox.Text = ShowNames.Regexes.Exclusions.ContainsKey(show) ? ShowNames.Regexes.Exclusions[show] : show; } switch (Database.TVShows[_id].Source) { case "TVRage": database.SelectedIndex = 1; break; case "TVDB": database.SelectedIndex = 2; break; case "TVcom": database.SelectedIndex = 3; break; case "EPisodeWorld": database.SelectedIndex = 4; break; case "IMDb": database.SelectedIndex = 5; break; case "AniDB": database.SelectedIndex = 6; break; case "AnimeNewsNetwork": database.SelectedIndex = 7; break; case "EPGuides": database.SelectedIndex = 10; break; } _sidx = database.SelectedIndex; _guide = CreateGuide((((database.SelectedValue as ComboBoxItem).Content as StackPanel).Children[1] as Label).Content.ToString().Trim()); _lang = Database.TVShows[_id].Language; var sel = 0; foreach (var lang in _guide.SupportedLanguages) { var sp = new StackPanel { Orientation = Orientation.Horizontal, Tag = lang }; sp.Children.Add(new Image { Source = new BitmapImage(new Uri("/RSTVShowTracker;component/Images/flag-" + lang + ".png", UriKind.Relative)), Height = 16, Width = 16, Margin = new Thickness(0, 0, 0, 0) }); sp.Children.Add(new Label { Content = " " + Languages.List[lang], Padding = new Thickness(0) }); language.Items.Add(sp); if (lang == _lang) { sel = language.Items.Count - 1; } } language.SelectedIndex = sel; switch (_not = FileNames.Parser.GetEpisodeNotationType(_id)) { default: case "standard": standardRadioButton.IsChecked = true; break; case "airdate": dateRadioButton.IsChecked = true; if (FileNames.Parser.AirdateNotationShows.Contains(Utils.CreateSlug(show))) { standardRadioButton.IsEnabled = false; } break; } }
/// <summary> /// Handles the SelectionChanged event of the database control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param> private void DatabaseSelectionChanged(object sender, SelectionChangedEventArgs e) { if ((database.SelectedValue as ComboBoxItem).Content == null) return; _guide = CreateGuide((((database.SelectedValue as ComboBoxItem).Content as StackPanel).Children[1] as Label).Content.ToString().Trim()); language.Items.Clear(); foreach (var lang in _guide.SupportedLanguages) { var sp = new StackPanel { Orientation = Orientation.Horizontal, Tag = lang }; sp.Children.Add(new Image { Source = new BitmapImage(new Uri("/RSTVShowTracker;component/Images/flag-" + lang + ".png", UriKind.Relative)), Height = 16, Width = 16, Margin = new Thickness(0, 1, 0, 0) }); sp.Children.Add(new Label { Content = " " + Languages.List[lang], Padding = new Thickness(0) }); language.Items.Add(sp); } language.SelectedIndex = 0; }