public AudioCdTrackInfo (AudioCdDiscModel model, string deviceNode, int index) { this.model = model; this.index_on_disc = index; Uri = new SafeUri (String.Format ("cdda://{0}#{1}", index_on_disc + 1, deviceNode)); }
bool CreateThumbnail (SafeUri thumbnailUri, ThumbnailSize size, IImageFile imageFile) { var pixels = size == ThumbnailSize.Normal ? 128 : 256; Pixbuf pixbuf; try { pixbuf = imageFile.Load (); } catch (Exception e) { Log.DebugFormat ("Failed loading image for thumbnailing: {0}", imageFile.Uri); Log.DebugException (e); return false; } double scale_x = (double)pixbuf.Width / pixels; double scale_y = (double)pixbuf.Height / pixels; double scale = Math.Max (1.0, Math.Max (scale_x, scale_y)); // Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null // Seems to only happen in rare(?) cases int target_x = Math.Max ((int)(pixbuf.Width / scale), 1); int target_y = Math.Max ((int)(pixbuf.Height / scale), 1); var thumb_pixbuf = pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear); var mtime = fileSystem.File.GetMTime (imageFile.Uri).ToString (); thumb_pixbuf.Savev (thumbnailUri.LocalPath, "png", new string [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null }, new string [] { imageFile.Uri, mtime }); pixbuf.Dispose (); thumb_pixbuf.Dispose (); return true; }
public void CopyIfNeeded (IPhoto item, SafeUri destinationBase) { // remember source uri for copying xmp file SafeUri defaultVersionUri = item.DefaultVersion.Uri; foreach (IPhotoVersion version in item.Versions) { // Copy into photo folder and update IPhotoVersion uri var source = version.Uri; var destination = destinationBase.Append (source.GetFilename ()); if (!source.Equals (destination)) { destination = GetUniqueFilename (destination); file_system.File.Copy (source, destination, false); copied_files.Add (destination); original_files.Add (source); version.Uri = destination; } } // Copy XMP sidecar var xmp_original = defaultVersionUri.ReplaceExtension(".xmp"); if (file_system.File.Exists (xmp_original)) { var xmp_destination = item.DefaultVersion.Uri.ReplaceExtension (".xmp"); file_system.File.Copy (xmp_original, xmp_destination, true); copied_files.Add (xmp_destination); original_files.Add (xmp_original); } }
public DaapTrackInfo(Track track, DaapSource source) : base() { TrackTitle = track.Title; AlbumTitle = track.Album; ArtistName = track.Artist; DateAdded = track.DateAdded; DateUpdated = track.DateModified; Genre = track.Genre; FileSize = track.Size; TrackCount = track.TrackCount; TrackNumber = track.TrackNumber; DiscNumber = track.DiscNumber; DiscCount = track.DiscCount; Year = track.Year; Duration = track.Duration; MimeType = track.Format; BitRate = (int)track.BitRate; ExternalId = track.Id; PrimarySource = source; Uri = new SafeUri (String.Format ( "{0}{1}/{2}", DaapService.ProxyServer.HttpBaseAddress, source.Database.GetHashCode (), track.Id )); //this.IsLive = false; //this.CanSaveToDatabase = false; }
public void Load(string uri, PdfPasswordProvider passwordProvider, bool isAlreadyTmp) { if (isAlreadyTmp) { tmp_uri = new Uri(uri).AbsoluteUri; tmp_path = new Uri(uri).LocalPath; } var safe_uri = new Hyena.SafeUri(uri); var uri_obj = new Uri(safe_uri.AbsoluteUri); Uri = uri_obj.AbsoluteUri; SuggestedSavePath = Path = uri_obj.LocalPath; pdf_document = PdfSharp.Pdf.IO.PdfReader.Open(Path, PdfDocumentOpenMode.Modify, passwordProvider); for (int i = 0; i < pdf_document.PageCount; i++) { var page = new Page(pdf_document.Pages[i]) { Document = this, Index = i }; pages.Add(page); } page_labels = new PageLabels(pdf_document); ExpireThumbnails(pages); OnChanged(); }
public IThumbnailer GetThumbnailerForUri (SafeUri uri) { if (ImageFile.HasLoader (uri)) { return new ImageThumbnailer (uri, fileSystem); } return null; }
public System.IO.Stream OpenWrite (SafeUri uri, bool overwrite) { var file = FileFactory.NewForUri (uri.AbsoluteUri); return new GioStream (overwrite ? file.Replace (null, false, FileCreateFlags.None, null) : file.Create (FileCreateFlags.None, null)); }
public void Load (SafeUri uri) { if (is_disposed) return; //First, send a thumbnail if we have one if ((thumb = App.Instance.Container.Resolve<IThumbnailService> ().TryLoadThumbnail (uri, ThumbnailSize.Large)) != null) { pixbuf_orientation = ImageOrientation.TopLeft; EventHandler<AreaPreparedEventArgs> prep = AreaPrepared; if (prep != null) { prep (this, new AreaPreparedEventArgs (true)); } EventHandler<AreaUpdatedEventArgs> upd = AreaUpdated; if (upd != null) { upd (this, new AreaUpdatedEventArgs (new Rectangle (0, 0, thumb.Width, thumb.Height))); } } using (var image_file = ImageFile.Create (uri)) { image_stream = image_file.PixbufStream (); pixbuf_orientation = image_file.Orientation; } loading = true; // The ThreadPool.QueueUserWorkItem hack is there cause, as the bytes to read are present in the stream, // the Read is CompletedAsynchronously, blocking the mainloop image_stream.BeginRead (buffer, 0, count, delegate (IAsyncResult r) { ThreadPool.QueueUserWorkItem (delegate { HandleReadDone (r);}); }, null); }
public long GetSize(SafeUri uri) { try { return new System.IO.FileInfo (uri.LocalPath).Length; } catch { return -1; } }
public ImageInfo(SafeUri uri) { using (var img = ImageFile.Create (uri)) { Pixbuf pixbuf = img.Load (); SetPixbuf (pixbuf); pixbuf.Dispose (); } }
public static string GenerateMD5(SafeUri uri) { var file = GLib.FileFactory.NewForUri (uri); var stream = new GLib.GioStream (file.Read (null)); var hash = CryptoUtil.Md5EncodeStream (stream); stream.Close (); return hash; }
public static RadioTrackInfo OpenPlay (SafeUri uri) { RadioTrackInfo track = Open (uri); if (track != null) { track.Play (); } return track; }
public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, BatchUserJob job) { if (track.PrimarySource == this && track.Uri.Scheme.StartsWith ("http")) { foreach (double percent in database.DownloadTrack ((int)track.ExternalId, track.MimeType, uri.AbsolutePath)) { job.DetailedProgress = percent; } } }
public BaseImageFile(SafeUri uri) { Uri = uri; Orientation = ImageOrientation.TopLeft; using (var metadata_file = Metadata.Parse (uri)) { ExtractMetadata (metadata_file); } }
public void Copy (SafeUri source, SafeUri destination, bool overwrite) { var source_file = FileFactory.NewForUri (source); var destination_file = FileFactory.NewForUri (destination); var flags = FileCopyFlags.AllMetadata; if (overwrite) flags |= FileCopyFlags.Overwrite; source_file.Copy (destination_file, flags, null, null); }
public bool TryCreateThumbnail (SafeUri thumbnailUri, ThumbnailSize size) { try { var imageFile = ImageFile.Create (fileUri); return CreateThumbnail (thumbnailUri, size, imageFile); } catch { return false; } }
public static SafeUri CopySidecarToTest(SafeUri uri, string filename) { var target = uri.ReplaceExtension (".xmp"); var orig_uri = new SafeUri (Environment.CurrentDirectory + TestDataLocation + filename); var file = GLib.FileFactory.NewForUri (orig_uri); var file2 = GLib.FileFactory.NewForUri (target); file.Copy (file2, GLib.FileCopyFlags.Overwrite, null, null); return target; }
public void TestMissingFile() { XdgThumbnailSpec.DefaultLoader = (u) => { throw new Exception ("not found!"); }; var uri = new SafeUri ("file:///invalid"); var pixbuf = XdgThumbnailSpec.LoadThumbnail (uri, ThumbnailSize.Large); Assert.IsNull (pixbuf); }
public PhotoVersion(IPhoto photo, uint version_id, SafeUri base_uri, string filename, string md5_sum, string name, bool is_protected) { Photo = photo; VersionId = version_id; BaseUri = base_uri; Filename = filename; ImportMD5 = md5_sum; Name = name; IsProtected = is_protected; }
public TranscodeContext (TrackInfo track, SafeUri out_uri, ProfileConfiguration config, TrackTranscodedHandler handler, TranscodeCancelledHandler cancelledHandler, TranscodeErrorHandler errorHandler) { Track = track; OutUri = out_uri; Config = config; Handler = handler; CancelledHandler = cancelledHandler; ErrorHandler = errorHandler; }
public static void TrimEmptyDirectories(SafeUri uri) { try { string old_dir = System.IO.Path.GetDirectoryName (uri.LocalPath); while (old_dir != null && old_dir != String.Empty) { Banshee.IO.Directory.Delete (old_dir); old_dir = System.IO.Path.GetDirectoryName (old_dir); } } catch { } }
public long GetSize (SafeUri uri) { try { var file = FileFactory.NewForUri (uri.AbsoluteUri); using (var file_info = file.QueryInfo ("standard::size", FileQueryInfoFlags.None, null)) { return file_info.Size; } } catch { return -1; } }
public long GetModifiedTime(SafeUri uri) { try { var file = FileFactory.NewForUri (uri.AbsoluteUri); using (var file_info = file.QueryInfo ("time::modified", FileQueryInfoFlags.None, null)) { return (long) file_info.GetAttributeULong ("time::modified"); } } catch { return -1; } }
public bool Exists (SafeUri uri) { var file = FileFactory.NewForUri (uri.AbsoluteUri); if (!file.Exists) { return false; } var type = file.QueryFileType (FileQueryInfoFlags.None, null); return (type & FileType.Regular) != 0 && (type & FileType.Directory) == 0; }
public static SafeUri CreateTempFile(string name) { var uri = new SafeUri (Environment.CurrentDirectory + TestDataLocation + name); var file = GLib.FileFactory.NewForUri (uri); var tmp = System.IO.Path.GetTempFileName ()+".jpg"; // hack! var uri2 = new SafeUri (tmp); var file2 = GLib.FileFactory.NewForUri (uri2); file.Copy (file2, GLib.FileCopyFlags.Overwrite, null, null); return uri2; }
static Mock<IPhoto> CreateMock (SafeUri uri, string name) { var versionMock = new Mock<IPhotoVersion> (); versionMock.Setup (v => v.BaseUri).Returns (uri); versionMock.Setup (v => v.Filename).Returns (Path.GetFileName (uri)); versionMock.Setup (v => v.Name).Returns (name); var photoMock = new Mock<IPhoto> (); photoMock.Setup (p => p.DefaultVersion).Returns (versionMock.Object); return photoMock; }
public void CreateDirectory (SafeUri uri) { var parts = uri.AbsolutePath.Split('/'); var current = new SafeUri (uri.Scheme + ":///", true); for (int i = 0; i < parts.Length; i++) { current = current.Append (parts [i]); var file = FileFactory.NewForUri (current); if (!file.Exists) { file.MakeDirectory (null); } } }
public void FindImportDestinationTest () { var fileUri = new SafeUri ("/path/to/photo.jpg"); var targetBaseUri = new SafeUri ("/photo/store"); var targetUri = new SafeUri ("/photo/store/2016/02/06"); var date = new DateTime (2016, 2, 6); var source = PhotoMock.Create (fileUri, date); var result = ImportController.FindImportDestination (source, targetBaseUri); Assert.AreEqual (targetUri, result); }
public static byte[] CreateThumbnail (SafeUri uri, ulong mTime) { var pixbuf = new Pixbuf (Colorspace.Rgb, false, 8, 1, 1); return pixbuf.SaveToBuffer ("png", new [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null }, new [] { uri, mTime.ToString () }); }
private void Setup () { foo = Uri ("foo"); baz = Uri ("baz"); woo = Path ("woo"); zoo = new SafeUri ("file://" + Path ("foo")); yoo = "file://" + tmp_dir; System.IO.Directory.CreateDirectory (tmp_dir); System.IO.File.WriteAllText (Path ("foo"), "bar"); System.IO.File.WriteAllText (Path ("baz"), "oof"); System.IO.Directory.CreateDirectory (Path ("woo")); }
protected override string OnDownloadRequested (string mimetype, string uri, string suggestedFilename) { switch (mimetype) { case "application/x-miro": var dest_uri_base = "file://" + Paths.Combine (Paths.TempDir, suggestedFilename); var dest_uri = new SafeUri (dest_uri_base); for (int i = 1; File.Exists (dest_uri); dest_uri = new SafeUri (String.Format ("{0} ({1})", dest_uri_base, ++i))); return dest_uri.AbsoluteUri; } return null; }
public static string UriToFilename(SafeUri uri) { return(UriToFilename(uri.AbsoluteUri)); }