/// <summary> /// Extracts the part to a new media item /// </summary> /// <param name="part">Part being extracted</param> private void ExtractPart(MediaItemPart part) { try { if (IsOrganising) { GeneralMethods.MessageBoxApplicationError("Please wait for the library to finish organising before extracting the parts of any media items"); return; } CancelMediaItemsOperationEventArgs e = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { SelectedMediaItem }); OnExtractingPartFromMediaItem(e); if (e.Cancel) { GeneralMethods.MessageBoxApplicationError(e.ReasonForCancel); return; } MediaItem extractedFrom = dgMediaItems.SelectedItem as MediaItem; MediaItem extractedTo; switch (extractedFrom.Type) { case MediaItemTypeEnum.Song: extractedTo = new Song(); break; case MediaItemTypeEnum.Video: extractedTo = new Video(); break; default: throw new UnknownEnumValueException(extractedFrom.Type); } extractedTo.Parts.Add(part.Location, part.Size, part.Duration); MediaItemDialog mediaItemDialog = new MediaItemDialog(true, extractedTo); mediaItemDialog.Owner = Application.Current.MainWindow; mediaItemDialog.ShowHidden = Filter.ShowHidden; mediaItemDialog.FileTypeAdded += new FileTypeEventHandler(mediaItemDialog_FileTypeAdded); if (GeneralMethods.GetNullableBoolValue(mediaItemDialog.ShowDialog())) { extractedFrom.Parts.Remove(part.Location); OnMediaItemSaved(extractedFrom); OnMediaItemSaved(extractedTo); } } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not extract part: "); } }
/// <summary> /// Merges the parts of the selected media items into a single media item /// </summary> private void MergePartsOfSelectedMediaItems() { try { if (IsOrganising) { GeneralMethods.MessageBoxApplicationError("Please wait for the library to finish organising before merging the parts of any media items"); return; } CancelMediaItemsOperationEventArgs e = new CancelMediaItemsOperationEventArgs(SelectedMediaItems); OnMergingSelectedMediaItems(e); if (e.Cancel) { GeneralMethods.MessageBoxApplicationError(e.ReasonForCancel); return; } MediaItem mergedMediaItem = SelectedMediaItems[0]; List <MediaItemPart> originalParts = new List <MediaItemPart>(mergedMediaItem.Parts); for (int i = 1; i < SelectedMediaItems.Length; i++) { foreach (MediaItemPart part in SelectedMediaItems[i].Parts) { mergedMediaItem.Parts.Add(part.Location, part.Size, part.Duration); } } MediaItemDialog mediaItemDialog = new MediaItemDialog(true, mergedMediaItem); mediaItemDialog.Owner = Application.Current.MainWindow; mediaItemDialog.ShowHidden = Filter.ShowHidden; mediaItemDialog.FileTypeAdded += new FileTypeEventHandler(mediaItemDialog_FileTypeAdded); if (GeneralMethods.GetNullableBoolValue(mediaItemDialog.ShowDialog())) { DeleteMediaItems(SelectedMediaItems.Where(p => p != mergedMediaItem).ToArray()); OnMediaItemSaved(mergedMediaItem); } else { mergedMediaItem.Parts = new MediaItemPartCollection(originalParts); } } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not merge parts: "); } }
/// <summary> /// Edits the selected videos /// </summary> private void EditSelectedMediaItems() { try { if (IsOrganising) { GeneralMethods.MessageBoxApplicationError("Please wait for the library to finish organising before editing any media items"); return; } if (SelectedMediaItems.Length > 0) { if (SelectedMediaItems.Length == 1) { MediaItemDialog mediaItemDialog = new MediaItemDialog(true, MediaItems.ToArray()); mediaItemDialog.FileTypeAdded += new FileTypeEventHandler(mediaItemDialog_FileTypeAdded); mediaItemDialog.SavedMediaItem += new MediaItemEventHandler(mediaItemDialog_SavedMediaItem); mediaItemDialog.PartExtracted += new MediaItemPartEventHandler(mediaItemDialog_PartExtracted); mediaItemDialog.Owner = Application.Current.MainWindow; mediaItemDialog.ShowHidden = Filter.ShowHidden; mediaItemDialog.SelectedIndex = SelectedIndex; mediaItemDialog.ShowDialog(); } else { MediaItem firstItem = SelectedMediaItems[0]; if (SelectedMediaItems.Any(p => p.Type != firstItem.Type)) { //generic media items throw new NotImplementedException(); } else { switch (firstItem.Type) { case MediaItemTypeEnum.Video: VideosDialog videosDialog = new VideosDialog(SelectedMediaItems.Cast <Video>().ToArray(), Filter.ShowHidden); videosDialog.Owner = Application.Current.MainWindow; if (GeneralMethods.GetNullableBoolValue(videosDialog.ShowDialog())) { OnMediaItemsSaved(videosDialog.Videos); } break; case MediaItemTypeEnum.Song: SongsDialog songsDialog = new SongsDialog(SelectedMediaItems.Cast <Song>().ToArray(), Filter.ShowHidden); songsDialog.Owner = Application.Current.MainWindow; if (GeneralMethods.GetNullableBoolValue(songsDialog.ShowDialog())) { OnMediaItemsSaved(songsDialog.Songs); } break; } } } } } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not edit media items: "); } }