/// <summary> /// Called when a subtitle search is done on all engines. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void SubtitleSearchDone(object sender = null, EventArgs e = null) { if (ActiveSearch != null) { ActiveSearch.SubtitleSearchDone -= SubtitleSearchDone; ActiveSearch.SubtitleSearchEngineNewLink -= SubtitleSearchEngineNewLink; ActiveSearch.SubtitleSearchEngineDone -= SubtitleSearchEngineDone; ActiveSearch.SubtitleSearchEngineError -= SubtitleSearchEngineError; ActiveSearch = null; } if (!_searching) { return; } _searching = false; Utils.Win7Taskbar(state: TaskbarProgressBarState.NoProgress); Dispatcher.Invoke((Action)(() => { textBox.IsEnabled = true; searchButton.Content = "Search"; if (SubtitlesListViewItemCollection.Count != 0) { SetStatus("Found " + Utils.FormatNumber(SubtitlesListViewItemCollection.Count, "subtitle") + "!"); } else { SetStatus("Couldn't find any subtitles."); } })); }
/// <summary> /// Handles the Click event of the searchButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void SearchButtonClick(object sender = null, RoutedEventArgs e = null) { if (string.IsNullOrWhiteSpace(textBox.Text)) return; if (_searching) { ActiveSearch.CancelAsync(); SubtitleSearchDone(); return; } SubtitlesListViewItemCollection.Clear(); textBox.IsEnabled = false; searchButton.Content = "Cancel"; ActiveSearch = new SubtitleSearch(ActiveSearchEngines, ActiveLangs, filterResults.IsChecked); ActiveSearch.SubtitleSearchDone += SubtitleSearchDone; ActiveSearch.SubtitleSearchEngineNewLink += SubtitleSearchEngineNewLink; ActiveSearch.SubtitleSearchEngineDone += SubtitleSearchEngineDone; ActiveSearch.SubtitleSearchEngineError += SubtitleSearchEngineError; SetStatus("Searching for subtitles on " + (string.Join(", ", ActiveSearch.SearchEngines.Select(engine => engine.Name).ToArray())) + "...", true); _searching = true; ActiveSearch.SearchAsync(textBox.Text); _dbep = FileNames.Parser.ParseFile(textBox.Text, null, false).DbEpisode; Utils.Win7Taskbar(0, TaskbarProgressBarState.Normal); }