private void SaveExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = mResultsList.GetSourceAlbumArt(e); if (albumArt != null) { albumArt.Save(this); } }
private void CopyExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = (AlbumArt)AlbumArt; if (albumArt != null) { albumArt.CopyToClipboard(); } }
private void CopyExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = mResultsViewer.GetSourceAlbumArt(e); if (albumArt != null) { albumArt.CopyToClipboard(); } }
/// <summary> /// Removes the album art from the results list. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = mResultsViewer.GetSourceAlbumArt(e); if (albumArt != null) { albumArt.Remove(); } }
private void SaveAsExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = (AlbumArt)AlbumArt; if (albumArt != null) { albumArt.PropertyChanged += AutoCloseOnSave; //No auto-close for SaveAs operation. albumArt.SaveAs(); } }
private void SaveAsExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = mResultsViewer.GetSourceAlbumArt(e); if (albumArt != null) { albumArt.PropertyChanged -= AutoCloseOnSave; //No auto-close for SaveAs operation. albumArt.SaveAs(); } }
private void BindAlbumArtDefaultFilePath(AlbumArt art) { Binding defaultPathBinding = new Binding(); defaultPathBinding.Source = mDefaultSaveFolder; defaultPathBinding.Path = new PropertyPath(ArtPathPatternBox.PathPatternProperty); defaultPathBinding.Mode = BindingMode.OneWay; defaultPathBinding.Converter = new AlbumArtDefaultFilePathPatternSubstitution(); defaultPathBinding.ConverterParameter = new string[] { Artist, Album }; BindingOperations.SetBinding(art, AlbumArt.DefaultFilePathPatternProperty, defaultPathBinding); }
private void AddResultToAutoDownloadFullSizeImage(AlbumArt result) { if (!result.IsDownloading && !result.IsFullSize) //No need to auto-download if it is already downloading, or full sized. { lock (mResultsToAutoDownloadFullSizeImages) { mResultsToAutoDownloadFullSizeImages.Enqueue(result); } mAutoDownloadFullSizeImagesTrigger.Set(); } }
private void SaveExecInternal(AlbumArt albumArt) { if (albumArt != null) { //Always auto-close on save //The save operation is asynchronous, so connect the handler to watch for the save completing albumArt.PropertyChanged += AutoCloseOnSave; albumArt.Save(this); } }
private void OnResultImageDownloaded(object state) { AlbumArt result = (AlbumArt)state; //Check results dimensions int size = (int)Math.Min(result.ImageWidth, result.ImageHeight); if (CheckImageSize(size)) { //Found a valid result! mSearchResult = result; } //Either continue searching for more results, or abort the search, but either way, stop waiting. mWaitForFullSizeImage.Set(); }
private void PreviewExec(object sender, ExecutedRoutedEventArgs e) { AlbumArt albumArt = mResultsViewer.GetSourceAlbumArt(e); if (albumArt != null) { albumArt.RetrieveFullSizeImage(); //Show persistant preview window var previewWindow = Common.NewPreviewWindow(this); previewWindow.AlbumArt = albumArt; //Bind to the presets context menu BindingOperations.SetBinding(previewWindow, ArtPreviewWindow.PresetsContextMenuProperty, new Binding() { Source = this, Path = new PropertyPath(PresetsContextMenuProperty), Mode = BindingMode.OneWay }); } }
private static void OnFilePathChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { AlbumArt albumArt = (AlbumArt)sender; albumArt.IsSaved = false; //Not saved if the file path has changed }
private void SearchWorker() { do { Album album = null; Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate { album = mQueueList.GetNextAlbum(); IsSearching = true; })); if (album == null) { // No more albums break; } album.ArtFileStatus = ArtFileStatus.Searching; Dispatcher.BeginInvoke(DispatcherPriority.DataBind, new ThreadStart(delegate { if (mQueueList.ShouldAutoscroll) { mQueueList.ScrollIntoView(album); } })); try { List <Source> currentSourcesToSearch; lock (mSourcesToSearch) { //Take a copy of the source list so that it doesn't get affected by changes) currentSourcesToSearch = new List <Source>(mSourcesToSearch); } foreach (var source in currentSourcesToSearch) //Try each source in turn { Dispatcher.BeginInvoke(DispatcherPriority.DataBind, new ThreadStart(delegate { ProgressText = String.Format("Searching {0} for {1} / {2}", source.Name, album.Artist, album.Name); })); source.Results.CollectionChanged += OnSourceFoundResult; source.QueryContinueSearch += OnSourceQueryContinue; source.SearchCompleted += OnSourceSearchComplete; mWaitForSourceCompleted.Reset(); System.Diagnostics.Debug.Assert(mSearchResult == null); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(delegate { //source.Search must be done in the main dispatcher thread, as that's the thread which the observable collection will be updated on. source.Search(album.Artist, album.Name); })); //Wait for the source to have finished searching mWaitForSourceCompleted.WaitOne(); System.Diagnostics.Debug.Assert(source.IsSearching == false, "Source is supposed to have completed by now"); //Done with this source - stop listening to its events. source.Results.CollectionChanged -= OnSourceFoundResult; source.QueryContinueSearch -= OnSourceQueryContinue; source.SearchCompleted -= OnSourceSearchComplete; //Was a valid result found in this source? if (mSearchResult != null) { //No need to search other sources. break; } } //Was a valid result found in any source? if (mSearchResult != null) { //Yes, so save it and add it to the results list. Dispatcher.Invoke(DispatcherPriority.DataBind, new ThreadStart(delegate { mSearchResult.DefaultFilePathPattern = album.ArtFile; if (Properties.Settings.Default.Presets.Length > 0) { mSearchResult.Preset = Properties.Settings.Default.Presets[0].Value; } //If the file already exists, overwrite it if (System.IO.File.Exists(mSearchResult.FilePath)) { try { System.IO.File.Delete(mSearchResult.FilePath); } catch (Exception ex) { System.Diagnostics.Trace.TraceError("Could not delete file \"{0}\": {1}", mSearchResult.FilePath, ex.Message); } } mSearchResult.Save(this); mResults.Add(mSearchResult); album.SetArtFile(mSearchResult.FilePath); Progress++; })); mResultsLookup.Add(album, mSearchResult); mReverseLookup.Add(mSearchResult, album); mSearchResult = null; } else { mAlbumsMissingResults.Add(album); album.ArtFileStatus = ArtFileStatus.Missing; } } catch (ThreadAbortException) { album.ArtFileStatus = ArtFileStatus.Queued; return; } } while (true); Dispatcher.BeginInvoke(DispatcherPriority.DataBind, new ThreadStart(delegate { IsSearching = false; System.Diagnostics.Debug.Assert(mQueueList.Items.Count - mResults.Count == mAlbumsMissingResults.Count, "Unexpected albums missing results count"); ProgressText = String.Format("Done. {0} albums found, {1} not found.", mResults.Count, mAlbumsMissingResults.Count); mSearchThread = null; ReEnableStartButton(); })); }