void clear() { Filename = ""; ReplaceFilename = ""; Location = ""; Rating = 0; Title = ""; Description = ""; Author = ""; Copyright = ""; Creation = null; IsImported = false; Geotag = new GeoTagCoordinatePair(); lock (itemsLock) { DynamicProperties.Clear(); } SelectedMetaDataPreset = noPresetMetaData; lock (tagsLock) { Tags.Clear(); } lock (addTagsLock) { AddTags.Clear(); } lock (removeTagsLock) { RemoveTags.Clear(); } }
public ImageSearchViewModel() { NrColumns = 4; SearchCommand = new AsyncCommand<int>(async (imageOffset) => { try { if (imageOffset == 0) { CurrentQuery = new ImageSearchQuery(this); } SearchCommand.IsExecutable = false; await doSearch(CurrentQuery, imageOffset); } catch (Exception e) { MessageBox.Show("Image search error\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { SearchCommand.IsExecutable = true; } }); ViewCommand = new Command<SelectableMediaItem>((selectableItem) => { ImageResultItem item = (ImageResultItem)selectableItem.Item; if(item.ImageInfo.ContentType.Equals("image/animatedgif")) { Shell.ShellViewModel.navigateToVideoView(item); } else { Shell.ShellViewModel.navigateToImageView(item); } }); ViewSourceCommand = new Command<SelectableMediaItem>((selectableItem) => { ImageResultItem item = (ImageResultItem)selectableItem.Item; Process.Start(item.ImageInfo.SourceUrl); }); SelectAllCommand = new Command(() => { MediaStateCollectionView.selectAll(); }, false); DeselectAllCommand = new Command(() => { MediaStateCollectionView.deselectAll(); }); CloseCommand = new Command(() => { OnClosingRequest(); }); DownloadCommand = new AsyncCommand<SelectableMediaItem>(async (selectableItem) => { List<MediaItem> items = MediaStateCollectionView.getSelectedItems(); if (items.Count == 0) { items.Add(selectableItem.Item); } String outputPath = null; switch (ImageSearchPlugin.Properties.Settings.Default.ImageSaveMode) { case MediaViewer.Infrastructure.Constants.SaveLocation.Current: { outputPath = MediaFileWatcher.Instance.Path; break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Ask: { DirectoryPickerView directoryPicker = new DirectoryPickerView(); directoryPicker.DirectoryPickerViewModel.InfoString = "Select Output Directory"; directoryPicker.DirectoryPickerViewModel.SelectedPath = MediaFileWatcher.Instance.Path; if (directoryPicker.ShowDialog() == false) { return; } outputPath = directoryPicker.DirectoryPickerViewModel.SelectedPath; break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Fixed: { outputPath = ImageSearchPlugin.Properties.Settings.Default.FixedDownloadPath; break; } default: break; } CancellableOperationProgressView progressView = new CancellableOperationProgressView(); DownloadProgressViewModel vm = new DownloadProgressViewModel(); progressView.DataContext = vm; progressView.Show(); vm.OkCommand.IsExecutable = false; vm.CancelCommand.IsExecutable = true; try { await Task.Factory.StartNew(() => { vm.startDownload(outputPath, items); }, vm.CancellationToken); } catch (Exception) { } vm.OkCommand.IsExecutable = true; vm.CancelCommand.IsExecutable = false; }); SettingsViewModel = (ImageSearchSettingsViewModel)ServiceLocator.Current.GetInstance(typeof(ImageSearchSettingsViewModel)); Size = new ListCollectionView(size); Size.MoveCurrentTo(Settings.Default.Size); SafeSearch = new ListCollectionView(safeSearch); SafeSearch.MoveCurrentTo(Settings.Default.SafeSearch); Layout = new ListCollectionView(layout); Layout.MoveCurrentTo(Settings.Default.Layout); Type = new ListCollectionView(type); Type.MoveCurrentTo(Settings.Default.Type); People = new ListCollectionView(people); People.MoveCurrentTo(Settings.Default.People); Color = new ListCollectionView(color); Color.MoveCurrentTo(Settings.Default.Color); GeoTag = new GeoTagCoordinatePair(); MediaState = new MediaState(); MediaStateCollectionView = new ImageResultCollectionView(MediaState); MediaStateCollectionView.MediaState.MediaStateType = MediaStateType.SearchResult; WeakEventManager<MediaLockedCollection, EventArgs>.AddHandler(MediaStateCollectionView.MediaState.UIMediaCollection, "IsLoadingChanged", mediaCollection_IsLoadingChanged); }
protected virtual void readXMPMetadata(XMPLib.MetaData xmpMetaDataReader, BaseMetadata media) { string title = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", ref title); media.Title = title; string description = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", ref description); media.Description = description; string author = ""; xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "creator", 1, ref author); media.Author = author; string copyright = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", ref copyright); media.Copyright = copyright; string software = ""; xmpMetaDataReader.getProperty(Consts.XMP_NS_XMP, "CreatorTool", ref software); media.Software = software; Nullable <double> rating = new Nullable <double>(); xmpMetaDataReader.getProperty_Float(Consts.XMP_NS_XMP, "Rating", ref rating); media.Rating = rating; Nullable <DateTime> date = new Nullable <DateTime>(); xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", ref date); if (date != null && date < sqlMinDate) { media.MetadataDate = null; } else { media.MetadataDate = date; } xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "CreateDate", ref date); if (date != null && date < sqlMinDate) { media.CreationDate = null; } else { media.CreationDate = date; } xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", ref date); if (date != null && date < sqlMinDate) { media.MetadataModifiedDate = null; } else { media.MetadataModifiedDate = date; } string longitude = null; string latitude = null; xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLatitude", ref latitude); xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLongitude", ref longitude); GeoTagCoordinatePair geoPair = new GeoTagCoordinatePair(latitude, longitude); media.Latitude = geoPair.LatDecimal; media.Longitude = geoPair.LonDecimal; media.Tags.Clear(); int nrTags = xmpMetaDataReader.countArrayItems(Consts.XMP_NS_DC, "subject"); for (int i = 1; i <= nrTags; i++) { string tagName = ""; xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "subject", i, ref tagName); if (tagName != null) { Tag newTag = new Tag(); newTag.Name = tagName.Trim(); media.Tags.Add(newTag); } } /*string imageData = ""; * * bool exists = xmpMetaDataReader.getStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", ref imageData); * if (exists) * { * BitmapSource thumbnail = MediaViewer.Infrastructure.Utils.ImageUtils.jpegBase64StringToImage(imageData); * * }*/ }
void grabData() { if (items.Count == 1 && Items.ElementAt(0).Metadata != null) { MediaFileItem media = Items.ElementAt(0); BaseMetadata metadata = media.Metadata; if (metadata.SupportsXMPMetadata == false) { clear(); } Filename = Path.GetFileNameWithoutExtension(metadata.Name); Location = metadata.Path; DynamicProperties.Clear(); if (metadata is ImageMetadata) { getImageProperties(DynamicProperties, metadata as ImageMetadata); } if (metadata is VideoMetadata) { getVideoProperties(DynamicProperties, metadata as VideoMetadata); } else if (metadata is AudioMetadata) { getAudioProperties(DynamicProperties, metadata as AudioMetadata); } Rating = metadata.Rating == null ? null : new Nullable<double>(metadata.Rating.Value / 5); Title = metadata.Title; Description = metadata.Description; Author = metadata.Author; Copyright = metadata.Copyright; Creation = metadata.CreationDate; IsImported = metadata.IsImported; IsReadOnly = media.IsReadOnly || !metadata.SupportsXMPMetadata || metadata is UnknownMetadata; Geotag = new GeoTagCoordinatePair(metadata.Latitude, metadata.Longitude); lock (tagsLock) { Tags.Clear(); foreach (Tag tag in metadata.Tags) { Tags.Add(tag); } } getExifProperties(DynamicProperties, metadata); SelectedMetaDataPreset = noPresetMetaData; IsEnabled = true; BatchMode = false; } else if (items.Count > 1 && BatchMode == true) { } else { if (items.Count > 1) { IsEnabled = true; BatchMode = true; IsReadOnly = false; clear(); } else if (items.Count == 0) { BatchMode = false; IsEnabled = false; IsReadOnly = true; IsRegexEnabled = false; clear(); } } }
protected virtual void write(XMPLib.MetaData xmpMetaDataWriter, BaseMetadata media) { if (media.Title != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", media.Title); } if (media.Rating != null) { xmpMetaDataWriter.setProperty_Float(Consts.XMP_NS_XMP, "Rating", media.Rating.Value); //xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "Rating", media.Rating.ToString(), Consts.PropOptions.XMP_DeleteExisting); } if (media.Description != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", media.Description); } if (media.Software != null) { xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "CreatorTool", media.Software, Consts.PropOptions.XMP_DeleteExisting); } if (media.Author != null) { if (xmpMetaDataWriter.doesArrayItemExist(Consts.XMP_NS_DC, "creator", 1)) { xmpMetaDataWriter.setArrayItem(Consts.XMP_NS_DC, "creator", 1, media.Author, 0); } else { xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "creator", Consts.PropOptions.XMP_PropArrayIsOrdered, media.Author, 0); } } /*if (media.Thumbnail != null) * { * string imageData = MediaViewer.Infrastructure.Utils.ImageUtils.imageToJpegBase64String(media.Thumbnail.Image); * * xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "format", "JPEG", (uint)Consts.PropOptions.XMP_NoOptions); * xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "width", media.Thumbnail.Image.Width.ToString(), (uint)Consts.PropOptions.XMP_NoOptions); * xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "height", media.Thumbnail.Image.Height.ToString(), (uint)Consts.PropOptions.XMP_NoOptions); * xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", imageData, (uint)Consts.PropOptions.XMP_NoOptions); * }*/ if (media.Copyright != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", media.Copyright); } if (media.CreationDate != null) { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "CreateDate", media.CreationDate.Value); } if (media.MetadataDate == null) { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", DateTime.Now); } else { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", DateTime.Now); } int nrTags = xmpMetaDataWriter.countArrayItems(Consts.XMP_NS_DC, "subject"); for (int i = nrTags; i > 0; i--) { xmpMetaDataWriter.deleteArrayItem(Consts.XMP_NS_DC, "subject", i); } foreach (Tag tag in media.Tags) { xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "subject", Consts.PropOptions.XMP_PropArrayIsUnordered, tag.Name, 0); } GeoTagCoordinatePair geoTag = new GeoTagCoordinatePair(media.Latitude, media.Longitude); if (!geoTag.IsEmpty) { xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLatitude", geoTag.LatCoord, 0); xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLongitude", geoTag.LonCoord, 0); } else { xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLatitude"); xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLongitude"); } if (xmpMetaDataWriter.canPutXMP()) { xmpMetaDataWriter.putXMP(); } else { throw new Exception("Format does not support XMP metadata"); } }
protected virtual void write(XMPLib.MetaData xmpMetaDataWriter, BaseMetadata media) { if (media.Title != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", media.Title); } if (media.Rating != null) { xmpMetaDataWriter.setProperty_Float(Consts.XMP_NS_XMP, "Rating", media.Rating.Value); //xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "Rating", media.Rating.ToString(), Consts.PropOptions.XMP_DeleteExisting); } if (media.Description != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", media.Description); } if (media.Software != null) { xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "CreatorTool", media.Software, Consts.PropOptions.XMP_DeleteExisting); } if (media.Author != null) { if (xmpMetaDataWriter.doesArrayItemExist(Consts.XMP_NS_DC, "creator", 1)) { xmpMetaDataWriter.setArrayItem(Consts.XMP_NS_DC, "creator", 1, media.Author, 0); } else { xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "creator", Consts.PropOptions.XMP_PropArrayIsOrdered, media.Author, 0); } } /*if (media.Thumbnail != null) { string imageData = MediaViewer.Infrastructure.Utils.ImageUtils.imageToJpegBase64String(media.Thumbnail.Image); xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "format", "JPEG", (uint)Consts.PropOptions.XMP_NoOptions); xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "width", media.Thumbnail.Image.Width.ToString(), (uint)Consts.PropOptions.XMP_NoOptions); xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "height", media.Thumbnail.Image.Height.ToString(), (uint)Consts.PropOptions.XMP_NoOptions); xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", imageData, (uint)Consts.PropOptions.XMP_NoOptions); }*/ if (media.Copyright != null) { xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", media.Copyright); } if (media.CreationDate != null) { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "CreateDate", media.CreationDate.Value); } if (media.MetadataDate == null) { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", DateTime.Now); } else { xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", DateTime.Now); } int nrTags = xmpMetaDataWriter.countArrayItems(Consts.XMP_NS_DC, "subject"); for (int i = nrTags; i > 0; i--) { xmpMetaDataWriter.deleteArrayItem(Consts.XMP_NS_DC, "subject", i); } foreach (Tag tag in media.Tags) { xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "subject", Consts.PropOptions.XMP_PropArrayIsUnordered, tag.Name, 0); } GeoTagCoordinatePair geoTag = new GeoTagCoordinatePair(media.Latitude, media.Longitude); if (!geoTag.IsEmpty) { xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLatitude", geoTag.LatCoord, 0); xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLongitude", geoTag.LonCoord, 0); } else { xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLatitude"); xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLongitude"); } if (xmpMetaDataWriter.canPutXMP()) { xmpMetaDataWriter.putXMP(); } else { throw new Exception("Format does not support XMP metadata"); } }
void mapAddItem(SelectableMediaItem media) { MediaItem item = media.Item; item.EnterReadLock(); try { if (item.Metadata == null || item.HasGeoTag == false || mapContainsItem(item)) return; GeoTagCoordinatePair coord = new GeoTagCoordinatePair(item.Metadata.Latitude, item.Metadata.Longitude); if (!coord.IsEmpty) { Location itemLocation = new Location(coord.LatDecimal.Value, coord.LonDecimal.Value); Border border = new Border(); border.BorderThickness = new Thickness(8); border.Tag = item; border.MaxWidth = 100; border.MaxHeight = 100; if (media.IsSelected) { border.Background = selectedImageBackground; } else { border.Background = defaultImageBackground; } Image image = new Image(); image.Tag = item; image.Source = item.Metadata.Thumbnail.Image; image.PreviewMouseDown += item_PreviewMouseDown; image.ToolTip = item.Metadata.DefaultFormatCaption; border.Child = image; imageLayer.AddChild(border, itemLocation, PositionOrigin.Center); Pushpin pin = new Pushpin(); pin.Tag = item; pin.ToolTip = item.Metadata.DefaultFormatCaption; pin.PreviewMouseDown += item_PreviewMouseDown; pin.Location = itemLocation; if (media.IsSelected) { pin.Background = selectedPushpinBackground; } else { pin.Background = defaultPushpinBackground; } pinLayer.AddChild(pin,itemLocation,PositionOrigin.BottomCenter); } } finally { item.ExitReadLock(); } }
protected virtual void readXMPMetadata(XMPLib.MetaData xmpMetaDataReader, BaseMetadata media) { string title = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", ref title); media.Title = title; string description = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", ref description); media.Description = description; string author = ""; xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "creator", 1, ref author); media.Author = author; string copyright = ""; xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", ref copyright); media.Copyright = copyright; string software = ""; xmpMetaDataReader.getProperty(Consts.XMP_NS_XMP, "CreatorTool", ref software); media.Software = software; Nullable<double> rating = new Nullable<double>(); xmpMetaDataReader.getProperty_Float(Consts.XMP_NS_XMP, "Rating", ref rating); media.Rating = rating; Nullable<DateTime> date = new Nullable<DateTime>(); xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", ref date); if (date != null && date < sqlMinDate) { media.MetadataDate = null; } else { media.MetadataDate = date; } xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "CreateDate", ref date); if (date != null && date < sqlMinDate) { media.CreationDate = null; } else { media.CreationDate = date; } xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", ref date); if (date != null && date < sqlMinDate) { media.MetadataModifiedDate = null; } else { media.MetadataModifiedDate = date; } string longitude = null; string latitude = null; xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLatitude", ref latitude); xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLongitude", ref longitude); GeoTagCoordinatePair geoPair = new GeoTagCoordinatePair(latitude, longitude); media.Latitude = geoPair.LatDecimal; media.Longitude = geoPair.LonDecimal; media.Tags.Clear(); int nrTags = xmpMetaDataReader.countArrayItems(Consts.XMP_NS_DC, "subject"); for (int i = 1; i <= nrTags; i++) { string tagName = ""; xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "subject", i, ref tagName); if (tagName != null) { Tag newTag = new Tag(); newTag.Name = tagName.Trim(); media.Tags.Add(newTag); } } /*string imageData = ""; bool exists = xmpMetaDataReader.getStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", ref imageData); if (exists) { BitmapSource thumbnail = MediaViewer.Infrastructure.Utils.ImageUtils.jpegBase64StringToImage(imageData); }*/ }