/// <summary> /// Fires the DeletingPart event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnDeletingPart(CancelMediaItemsOperationEventArgs e) { if (DeletingPart != null) { DeletingPart(this, e); } }
/// <summary> /// Fires the OrganisingMediaItem event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnOrganisingMediaItem(CancelMediaItemsOperationEventArgs e) { if (OrganisingMediaItem != null) { OrganisingMediaItem(this, e); } }
/// <summary> /// Fires the MergingSelectedMediaItems event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnMergingSelectedMediaItems(CancelMediaItemsOperationEventArgs e) { if (MergingSelectedMediaItems != null) { MergingSelectedMediaItems(this, e); } }
/// <summary> /// Fires the Browse event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnBrowse(CancelMediaItemsOperationEventArgs e) { if (Browse != null) { Browse(this, e); } }
/// <summary> /// Fires the ExtractingPartFromMediaItem event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnExtractingPartFromMediaItem(CancelMediaItemsOperationEventArgs e) { if (ExtractingPartFromMediaItem != null) { ExtractingPartFromMediaItem(this, e); } }
/// <summary> /// Fires the MediaItemsDeleting event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnMediaItemsDeleting(CancelMediaItemsOperationEventArgs e) { if (MediaItemsDeleting != null) { MediaItemsDeleting(this, e); } }
/// <summary> /// Fires the OrganisingMediaItem event /// </summary> /// <param name="e">Arguments to pass to the event</param> private void OnOrganisingMediaItem(CancelMediaItemsOperationEventArgs e) { if (OrganisingMediaItem != null) { GeneralMethods.ExecuteDelegateOnGuiThread(Dispatcher, () => OrganisingMediaItem(this, e)); } }
/// <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: "); } }
private void btnBrowse_Click(object sender, RoutedEventArgs e) { Button btnBrowse = sender as Button; MediaItem missingMediaItem = btnBrowse.DataContext as MediaItem; CancelMediaItemsOperationEventArgs cmioea = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { missingMediaItem }); OnBrowse(cmioea); if (!cmioea.Cancel) { MediaItems = MediaItems.Where(p => !p.IsInDatabase); } }
/// <summary> /// Organises the parts /// </summary> private void Organise(object data) { try { timeStarted = DateTime.Now; timeTakenTimer.Start(); OrganisedCount = 0; TotalBytesTransfered = 0; TimeTaken = TimeSpan.FromSeconds(0); OrganisingRootFolder[] rootFolders = data as OrganisingRootFolder[]; //reset progress of parts foreach (OrganisingMediaItemPart part in Parts) { part.Progress = 0; } foreach (OrganisingMediaItemPart part in Parts) { OrganisingRootFolder[] sortedRootFolders = OrganisingRootFolder.SortForMediaItem(part.MediaItem, rootFolders); SelectedPart = part; CancelMediaItemsOperationEventArgs e = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { part.MediaItem }); OnOrganisingMediaItem(e); part.Organise(this, sortedRootFolders, e.Cancel, e.ReasonForCancel); OrganisedCount++; } } catch (ThreadAbortException) { //do nothing } timeTakenTimer.Stop(); SelectedPart = null; IsOrganising = false; OnFinishedOrganising(); }
private static void OnSelectedIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MediaItemPlayer mip = d as MediaItemPlayer; if (!mip.removingMediaItem) { mip.CanSkipPrevious = false; mip.CanSkipNext = false; if (mip.SelectedIndex == -1) { mip.SelectedMediaItem = null; mip.Position = TimeSpan.FromSeconds(0); return; } else { MediaItem selectedMediaItem = mip.MediaItems[mip.SelectedIndex]; CancelMediaItemsOperationEventArgs cmioea = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { selectedMediaItem }); mip.OnOpeningMediaItem(cmioea); if (cmioea.Cancel) { mip.SkipNext(); return; } mip.SelectedMediaItem = selectedMediaItem; } } mip.SetCanSkip(); }
private void mivNowPlaying_ExtractingPartFromMediaItem(object sender, CancelMediaItemsOperationEventArgs e) { OnExtractingPartFromMediaItem(e); }
private void mivNowPlaying_MergingSelectedMediaItems(object sender, CancelMediaItemsOperationEventArgs e) { OnMergingSelectedMediaItems(e); }
private void player_OpeningMediaItem(object sender, CancelMediaItemsOperationEventArgs e) { OnOpeningMediaItem(e); }
private void mivSongs_DeletingPart(object sender, CancelMediaItemsOperationEventArgs e) { OnDeletingPart(e); }
/// <summary> /// Removes the selected parts from the collection /// </summary> private void RemoveSelectedParts() { try { if (IsOrganising) { GeneralMethods.MessageBoxApplicationError("Please wait for the library to finish organising before editing any media items"); return; } if (dgParts.SelectedItems.Count == 0) { GeneralMethods.MessageBoxApplicationError("Please select 1 or more parts to delete"); return; } if (dgParts.SelectedItems.Count == MediaItem.Parts.Count) { GeneralMethods.MessageBoxApplicationError("A media item must have at least 1 part"); return; } CancelMediaItemsOperationEventArgs cea = new CancelMediaItemsOperationEventArgs(new MediaItem[1] { MediaItem }); OnDeletingPart(cea); if (!cea.Cancel) { MessageBoxResult result; if (dgParts.SelectedItems.Count == 1) { result = GeneralMethods.MessageBox("Would you also like to move the physical " + MediaItem.Type.ToString().ToLower() + " file to the recycle bin?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); } else { result = GeneralMethods.MessageBox("Would you also like to move the physical " + MediaItem.Type.ToString().ToLower() + " files to the recycle bin?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); } if (result == MessageBoxResult.Cancel) { return; } if (result == MessageBoxResult.Yes) { foreach (MediaItemPart part in dgParts.SelectedItems) { if (FileSystem.FileExists(part.Location.Value)) { FileSystem.DeleteFile(part.Location.Value, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } } } MediaItemPart[] selectedParts = dgParts.SelectedItems.Cast <MediaItemPart>().ToArray(); List <MediaItemPart> parts = new List <MediaItemPart>(MediaItem.Parts); parts.Sort(); foreach (MediaItemPart part in selectedParts) { parts.Remove(part); } for (int i = 0; i < parts.Count; i++) { parts[i].Index = Convert.ToInt16(i); } MediaItem.Parts = new MediaItemPartCollection(parts); OnPartDeleted(); } } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not delete parts: "); } }
private void mivSongs_MediaItemsDeleting(object sender, CancelMediaItemsOperationEventArgs e) { OnMediaItemsDeleting(e); }
/// <summary> /// Deletes the media items /// </summary> /// <param name="mediaItems">Media items being deleted</param> public void RemoveMediaItems(MediaItem[] mediaItems) { try { if (IsOrganising) { GeneralMethods.MessageBoxApplicationError("Please wait for the library to finish organising before deleting any media items"); return; } CancelMediaItemsOperationEventArgs e = new CancelMediaItemsOperationEventArgs(mediaItems); OnMediaItemsDeleting(e); if (e.Cancel) { GeneralMethods.MessageBoxApplicationError(e.ReasonForCancel); return; } MessageBoxResult result; switch (e.MediaItems.Count) { case 0: //do nothing return; case 1: if (RecycleBinPrompt) { result = GeneralMethods.MessageBox("You are about to delete " + e.MediaItems[0].Name + ". Would you also like to move the physical files to the recycle bin?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); } else { result = GeneralMethods.MessageBox("You are about to delete " + e.MediaItems[0].Name + ".", MessageBoxButton.OKCancel, MessageBoxImage.Question); } break; default: if (RecycleBinPrompt) { result = GeneralMethods.MessageBox("You are about to delete " + e.MediaItems.Count.ToString() + " items. Would you also like to move the physical files to the recycle bin?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); } else { result = GeneralMethods.MessageBox("You are about to delete " + e.MediaItems.Count.ToString() + " items.", MessageBoxButton.OKCancel, MessageBoxImage.Question); } break; } if (result == MessageBoxResult.Cancel) { return; } if (result == MessageBoxResult.Yes) { foreach (MediaItem mediaItem in e.MediaItems) { foreach (MediaItemPart part in mediaItem.Parts) { if (FileSystem.FileExists(part.Location.Value)) { FileSystem.DeleteFile(part.Location.Value, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } } } } DeleteMediaItems(e.MediaItems.ToArray()); } catch (System.Exception e) { GeneralMethods.MessageBoxException(e, "Could not delete items: "); } }