public bool Convert (FilterRequest req) { Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (req.Current.LocalPath)); using (ImageFile img = ImageFile.Create (req.Current)) { using (Pixbuf in_pixbuf = img.Load ()) { using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask (in_pixbuf, radius, amount, threshold)) { string destination_extension = Path.GetExtension (dest_uri.LocalPath); if (Path.GetExtension (req.Current.LocalPath).ToLower () == Path.GetExtension (dest_uri.LocalPath).ToLower ()) { using (Stream output = File.OpenWrite (dest_uri.LocalPath)) { img.Save (out_pixbuf, output); } } else if (destination_extension == ".jpg") { // FIXME this is a bit of a nasty hack to work around // the lack of being able to change the path in this filter // and the lack of proper metadata copying yuck Exif.ExifData exif_data; exif_data = new Exif.ExifData (req.Current.LocalPath); PixbufUtils.SaveJpeg (out_pixbuf, dest_uri.LocalPath, 90, exif_data); } else throw new NotImplementedException (String.Format (Catalog.GetString ("No way to save files of type \"{0}\""), destination_extension)); } } } req.Current = dest_uri; return true; }
public void TestNoop () { string path = CreateFile ("test.jpg", 50); FilterRequest req = new FilterRequest (path); IFilter filter = new OrientationFilter (); Assert.IsFalse (filter.Convert (req), "Orientation Filter changed a normal file"); }
public bool Convert (FilterRequest req) { // FIXME this should copy metadata from the original // even when the source is not a jpeg string source = req.Current.LocalPath; using (ImageFile img = ImageFile.Create (source)) { if (img is JpegFile) return false; req.Current = req.TempUri ("jpg"); string dest = req.Current.LocalPath; Exif.ExifData exif_data; try { exif_data = new Exif.ExifData (source); } catch (Exception) { exif_data = new Exif.ExifData(); } PixbufUtils.SaveJpeg (img.Load(), dest, (int) quality, exif_data); } return true; }
public bool Convert (FilterRequest req) { string source = req.Current.LocalPath; Uri dest = req.TempUri (Path.GetExtension (source)); using (ImageFile img = ImageFile.Create (source)) { using (Pixbuf pixbuf = img.Load ()) { using (ImageInfo info = new ImageInfo (pixbuf)) { MemorySurface surface = new MemorySurface (Format.Argb32, pixbuf.Width, pixbuf.Height); Context ctx = new Context (surface); ctx.Matrix = info.Fill (info.Bounds, angle); Pattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); ((IDisposable)ctx).Dispose (); p.Destroy (); using (Pixbuf result = CairoUtils.CreatePixbuf (surface)) { using (Stream output = File.OpenWrite (dest.LocalPath)) { img.Save (result, output); } } surface.Flush (); info.Dispose (); req.Current = dest; return true; } } } }
public bool Convert(FilterRequest req) { Uri source = req.Current; using (ImageFile img = ImageFile.Create(source)) { pixbuf = img.Load(); profile = img.GetProfile(); // If the image doesn't have an embedded profile assume it is sRGB if (profile == null) { profile = Profile.CreateStandardRgb(); } if (destination == null) { destination = profile; } Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, pixbuf.Width, pixbuf.Height); Profile [] list = Prepare(pixbuf); if (pixbuf.HasAlpha) { Gdk.Pixbuf alpha = PixbufUtils.Flatten(pixbuf); Transform transform = new Transform(list, PixbufUtils.PixbufCmsFormat(alpha), PixbufUtils.PixbufCmsFormat(final), rendering_intent, 0x0000); PixbufUtils.ColorAdjust(alpha, final, transform); PixbufUtils.ReplaceColor(final, pixbuf); alpha.Dispose(); final.Dispose(); final = pixbuf; } else { Transform transform = new Transform(list, PixbufUtils.PixbufCmsFormat(pixbuf), PixbufUtils.PixbufCmsFormat(final), rendering_intent, 0x0000); PixbufUtils.ColorAdjust(pixbuf, final, transform); pixbuf.Dispose(); } Uri dest_uri = req.TempUri(Path.GetExtension(source.LocalPath)); using (Stream output = File.OpenWrite(dest_uri.LocalPath)) { img.Save(final, output); } final.Dispose(); req.Current = dest_uri; return(true); } }
public void TestNoop() { string path = CreateFile("test.jpg", 50); FilterRequest req = new FilterRequest(path); IFilter filter = new OrientationFilter(); Assert.IsFalse(filter.Convert(req), "Orientation Filter changed a normal file"); }
public bool Convert (FilterRequest req) { bool changed = false; foreach (IFilter filter in list) { changed |= filter.Convert (req); } return changed; }
public void StretchRealFile () { string path = "/home/lewing/Desktop/img_0081.jpg"; FilterRequest req = new FilterRequest (path); FilterSet set = new FilterSet (); set.Add (new AutoStretch ()); set.Add (new UniqueNameFilter (Path.GetDirectoryName (path))); set.Convert (req); req.Preserve (req.Current); }
public bool Convert(FilterRequest req) { bool changed = false; foreach (IFilter filter in ifilters) { changed |= filter.Convert(req); } return(changed); }
public void StretchRealFile() { string path = "/home/lewing/Desktop/img_0081.jpg"; FilterRequest req = new FilterRequest(path); FilterSet set = new FilterSet(); set.Add(new AutoStretch()); set.Add(new UniqueNameFilter(Path.GetDirectoryName(path))); set.Convert(req); req.Preserve(req.Current); }
public void ResultIsJpeg (string name) { string path = CreateFile (name, 48); IFilter filter = new JpegFilter (); FilterRequest req = new FilterRequest (path); filter.Convert (req); using (ImageFile img = new JpegFile (req.Current)) { Assert.IsTrue (img != null, "result is null"); Assert.IsTrue (img is JpegFile, "result is not a jpg"); } System.IO.File.Delete (path); }
public void ExtensionIsJPG(string name) { string path = CreateFile(name, 48); IFilter filter = new JpegFilter(); FilterRequest req = new FilterRequest(path); filter.Convert(req); string extension = System.IO.Path.GetExtension(req.Current.LocalPath).ToLower(); Assert.IsTrue(extension == ".jpg" || extension == ".jpeg", String.Format("{0} is not a valid extension for Jpeg", extension)); System.IO.File.Delete(path); }
public bool Convert(FilterRequest req) { if ( valid_extensions.Contains (System.IO.Path.GetExtension(req.Current.LocalPath).ToLower ()) ) return false; // FIXME: Should we add the other jpeg extensions? if ( !valid_extensions.Contains (".jpg") && !valid_extensions.Contains (".jpeg")) throw new System.NotImplementedException ("can only save jpeg :("); return (new JpegFilter ()).Convert (req); }
public bool Convert(FilterRequest req) { if (req.Current == req.Source) { var uri = req.TempUri (); System.IO.File.Copy (req.Current.LocalPath, uri.LocalPath, true); req.Current = uri; } Syscall.chmod (req.Current.LocalPath, mode); return true; }
public bool Convert (FilterRequest req) { string source = req.Current.LocalPath; System.Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (source)); string dest = dest_uri.LocalPath; using (ImageFile img = ImageFile.Create (source)) { bool changed = false; if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile) { JpegFile jimg = img as JpegFile; if (img.Orientation == PixbufOrientation.RightTop) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate90); changed = true; } else if (img.Orientation == PixbufOrientation.LeftBottom) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate270); changed = true; } else if (img.Orientation == PixbufOrientation.BottomRight) { JpegUtils.Transform (source, dest, JpegUtils.TransformType.Rotate180); changed = true; } int width, height; jimg = ImageFile.Create (dest) as JpegFile; PixbufUtils.GetSize (dest, out width, out height); jimg.SetOrientation (PixbufOrientation.TopLeft); jimg.SetDimensions (width, height); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (dest, 160, 120, true); jimg.SetThumbnail (pixbuf); pixbuf.Dispose (); jimg.SaveMetaData (dest); jimg.Dispose (); } if (changed) req.Current = dest_uri; return changed; } }
public void ResultIsJpeg(string name) { string path = CreateFile(name, 48); IFilter filter = new JpegFilter(); FilterRequest req = new FilterRequest(path); filter.Convert(req); using (ImageFile img = new JpegFile(req.Current)) { Assert.IsTrue(img != null, "result is null"); Assert.IsTrue(img is JpegFile, "result is not a jpg"); } System.IO.File.Delete(path); }
public void Basic(string name) { string path = CreateFile(name, 120); using (FilterRequest req = new FilterRequest(path)) { IFilter filter = new TiltFilter(Math.PI / 4); filter.Convert(req); Assert.IsTrue(System.IO.File.Exists(req.Current.LocalPath), "Error: Did not create " + req.Current.LocalPath); Assert.IsTrue(new FileInfo(req.Current.LocalPath).Length > 0, "Error: " + req.Current.LocalPath + "is Zero length"); } }
public bool Convert(FilterRequest req) { if (req.Current == req.Source) { var uri = req.TempUri(); System.IO.File.Copy(req.Current.LocalPath, uri.LocalPath, true); req.Current = uri; } Syscall.chmod(req.Current.LocalPath, mode); return(true); }
public void Process(string name, Profile profile) { string path = CreateFile(name, 120); using (FilterRequest req = new FilterRequest(path)) { IFilter filter = new ColorFilter(profile); Assert.IsTrue(filter.Convert(req), "Filter failed to operate"); Assert.IsTrue(System.IO.File.Exists(req.Current.LocalPath), "Error: Did not create " + req.Current.LocalPath); Assert.IsTrue(new FileInfo(req.Current.LocalPath).Length > 0, "Error: " + req.Current.LocalPath + "is Zero length"); } }
public void OriginalUntouched(string name) { string path = CreateFile(name, 48); IFilter filter = new JpegFilter(); FilterRequest req = new FilterRequest(path); long original_size = new System.IO.FileInfo(path).Length; filter.Convert(req); long final_size = new System.IO.FileInfo(req.Source.LocalPath).Length; Assert.IsTrue(original_size == final_size, "original is modified !!!"); System.IO.File.Delete(path); }
public bool Convert(FilterRequest req) { if (valid_extensions.Contains(Path.GetExtension(req.Current.LocalPath).ToLower())) { return(false); } // FIXME: Should we add the other jpeg extensions? if (!valid_extensions.Contains(".jpg") && !valid_extensions.Contains(".jpeg")) { throw new System.NotImplementedException("can only save jpeg :("); } return((new JpegFilter()).Convert(req)); }
public bool Convert(FilterRequest req) { var dest_uri = req.TempUri (req.Current.GetExtension ()); using (var img = ImageFile.Create (req.Current)) { using (Pixbuf in_pixbuf = img.Load ()) { using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask (in_pixbuf, radius, amount, threshold, null)) { PixbufUtils.CreateDerivedVersion (req.Current, dest_uri, 95, out_pixbuf); } } } req.Current = dest_uri; return true; }
public bool Convert(FilterRequest req) { var dest_uri = req.TempUri(req.Current.GetExtension()); using (var img = App.Instance.Container.Resolve <IImageFileFactory> ().Create(req.Current)) { using (Pixbuf in_pixbuf = img.Load()) { using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask(in_pixbuf, radius, amount, threshold, null)) { FSpot.Utils.PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, out_pixbuf); } } } req.Current = dest_uri; return(true); }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source)); string dest = dest_uri.LocalPath; using (ImageFile img = ImageFile.Create(source)) { using (Pixbuf pixbuf = img.Load()) { if (pixbuf.Width < size && pixbuf.Height < size) { return(false); } } using (Pixbuf pixbuf = img.Load((int)size, (int)size)) { string destination_extension = Path.GetExtension(dest); if (Path.GetExtension(source).ToLower() == Path.GetExtension(dest).ToLower()) { using (Stream output = File.OpenWrite(dest)) { img.Save(pixbuf, output); } } else if (destination_extension == ".jpg") { // FIXME this is a bit of a nasty hack to work around // the lack of being able to change the path in this filter // and the lack of proper metadata copying yuck Exif.ExifData exif_data; exif_data = new Exif.ExifData(source); PixbufUtils.SaveJpeg(pixbuf, dest, 95, exif_data); } else { throw new NotImplementedException(String.Format(Catalog.GetString("No way to save files of type \"{0}\""), destination_extension)); } } } req.Current = dest_uri; return(true); }
public void Process(string name) { string path = CreateFile(name, 120); using (FilterRequest req = new FilterRequest(path)) { IFilter filter = new AutoStretch(); Assert.IsTrue(filter.Convert(req), "Filter failed to operate"); Assert.IsTrue(System.IO.File.Exists(req.Current.LocalPath), "Error: Did not create " + req.Current.LocalPath); Assert.IsTrue(new FileInfo(req.Current.LocalPath).Length > 0, "Error: " + req.Current.LocalPath + "is Zero length"); //req.Preserve (req.Current); using (ImageFile img = ImageFile.Create(req.Current)) { Pixbuf pixbuf = img.Load(); Assert.IsNotNull(pixbuf); } } }
public bool Convert(FilterRequest request) { //FIXME: make it works for uri (and use it in CDExport) int i = 1; string path = destination.LocalPath; string filename = Path.GetFileName(request.Source.LocalPath); string dest = Path.Combine(path, filename); while (File.Exists(dest)) { string numbered_name = $"{Path.GetFileNameWithoutExtension (filename)}-{i++}{Path.GetExtension (filename)}"; dest = Path.Combine(path, numbered_name); } File.Copy(request.Current.LocalPath, dest); request.Current = new Uri(dest); return(true); }
public bool Convert(FilterRequest request) { //FIXME: make it works for uri (and use it in CDExport) int i = 1; string path = destination.LocalPath; string filename = System.IO.Path.GetFileName (request.Source.LocalPath); string dest = System.IO.Path.Combine (path, filename); while (System.IO.File.Exists (dest)) { string numbered_name = String.Format ("{0}-{1}{2}", System.IO.Path.GetFileNameWithoutExtension (filename), i++, System.IO.Path.GetExtension (filename)); dest = System.IO.Path.Combine (path, numbered_name); } System.IO.File.Copy (request.Current.LocalPath, dest); request.Current = new SafeUri (dest); return true; }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; var dest_uri = req.TempUri (System.IO.Path.GetExtension (source)); using (var img = ImageFile.Create (req.Current)) { using (Pixbuf pixbuf = img.Load ()) { if (pixbuf.Width < size && pixbuf.Height < size) return false; } using (Pixbuf pixbuf = img.Load ((int)size, (int)size)) { PixbufUtils.CreateDerivedVersion (req.Current, dest_uri, 95, pixbuf); } } req.Current = dest_uri; return true; }
public bool Convert(FilterRequest req) { Uri source = req.Current; using (ImageFile img = ImageFile.Create(source)) { Pixbuf pixbuf = img.Load(); Profile profile = img.GetProfile(); Adjustment adjustment = CreateAdjustment(pixbuf, profile); Gdk.Pixbuf final = adjustment.Adjust(); Uri dest_uri = req.TempUri(Path.GetExtension(source.LocalPath)); using (Stream output = File.OpenWrite(dest_uri.LocalPath)) { img.Save(final, output); } final.Dispose(); req.Current = dest_uri; return(true); } }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; var dest_uri = req.TempUri(System.IO.Path.GetExtension(source)); using (var img = App.Instance.Container.Resolve <IImageFileFactory> ().Create(req.Current)) { using (Pixbuf pixbuf = img.Load()) { if (pixbuf.Width < Size && pixbuf.Height < Size) { return(false); } } using (Pixbuf pixbuf = img.Load((int)Size, (int)Size)) { FSpot.Utils.PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, pixbuf); } } req.Current = dest_uri; return(true); }
public bool Convert(FilterRequest request) { //FIXME: make it works for uri (and use it in CDExport) int i = 1; string path = destination.LocalPath; string filename = System.IO.Path.GetFileName(request.Source.LocalPath); string dest = System.IO.Path.Combine(path, filename); while (System.IO.File.Exists(dest)) { string numbered_name = String.Format("{0}-{1}{2}", System.IO.Path.GetFileNameWithoutExtension(filename), i++, System.IO.Path.GetExtension(filename)); dest = System.IO.Path.Combine(path, numbered_name); } System.IO.File.Copy(request.Current.LocalPath, dest); request.Current = new SafeUri(dest); return(true); }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; var dest_uri = req.TempUri(System.IO.Path.GetExtension(source)); using (var img = ImageFile.Create(req.Current)) { using (Pixbuf pixbuf = img.Load()) { if (pixbuf.Width < size && pixbuf.Height < size) { return(false); } } using (Pixbuf pixbuf = img.Load((int)size, (int)size)) { PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, pixbuf); } } req.Current = dest_uri; return(true); }
protected virtual void SendImage (Photo photo, Stream stream) { string path = photo.DefaultVersion.Uri.LocalPath; FileInfo file_info = new FileInfo(path); if (!file_info.Exists) { SendError (stream, "404 The file is not on the disk"); return; } FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); filters.Add (new ResizeFilter (1600)); using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) { filters.Convert (request); file_info = new FileInfo (request.Current.LocalPath); SendFile (file_info, photo, stream); } if (stats != null) stats.PhotoViews++; }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; System.Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (source)); string dest = dest_uri.LocalPath; using (ImageFile img = ImageFile.Create (req.Current)) { using (Pixbuf pixbuf = img.Load ()) { if (pixbuf.Width < size && pixbuf.Height < size) return false; } using (Pixbuf pixbuf = img.Load ((int)size, (int)size)) { string destination_extension = Path.GetExtension (dest); if (Path.GetExtension (source).ToLower () == Path.GetExtension (dest).ToLower ()) { using (Stream output = File.OpenWrite (dest)) { img.Save (pixbuf, output); } } else if (destination_extension == ".jpg") { // FIXME this is a bit of a nasty hack to work around // the lack of being able to change the path in this filter // and the lack of proper metadata copying yuck Exif.ExifData exif_data; exif_data = new Exif.ExifData (source); PixbufUtils.SaveJpeg (pixbuf, dest, 95, exif_data); } else throw new NotImplementedException (String.Format (Catalog.GetString ("No way to save files of type \"{0}\""), destination_extension)); } } req.Current = dest_uri; return true; }
public bool Convert(FilterRequest req) { Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(req.Current.LocalPath)); using (ImageFile img = ImageFile.Create(req.Current)) { using (Pixbuf in_pixbuf = img.Load()) { using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask(in_pixbuf, radius, amount, threshold)) { string destination_extension = Path.GetExtension(dest_uri.LocalPath); if (Path.GetExtension(req.Current.LocalPath).ToLower() == Path.GetExtension(dest_uri.LocalPath).ToLower()) { using (Stream output = File.OpenWrite(dest_uri.LocalPath)) { img.Save(out_pixbuf, output); } } else if (destination_extension == ".jpg") { // FIXME this is a bit of a nasty hack to work around // the lack of being able to change the path in this filter // and the lack of proper metadata copying yuck Exif.ExifData exif_data; exif_data = new Exif.ExifData(req.Current.LocalPath); PixbufUtils.SaveJpeg(out_pixbuf, dest_uri.LocalPath, 90, exif_data); } else { throw new NotImplementedException(String.Format(Catalog.GetString("No way to save files of type \"{0}\""), destination_extension)); } } } } req.Current = dest_uri; return(true); }
public void Linearize(string name) { GammaTable table = new GammaTable(new ushort [] { 0x0000, 0x0000, 0x0000, 0x0000 }); Profile link = new Profile(IccColorSpace.Rgb, new GammaTable [] { table, table, table }); string path = CreateFile(name, 32); using (FilterRequest req = new FilterRequest(path)) { ColorFilter filter = new ColorFilter(); filter.DeviceLink = link; Assert.IsTrue(filter.Convert(req), "Filter failed to operate"); req.Preserve(req.Current); Assert.IsTrue(System.IO.File.Exists(req.Current.LocalPath), "Error: Did not create " + req.Current); Assert.IsTrue(new FileInfo(req.Current.LocalPath).Length > 0, "Error: " + req.Current + "is Zero length"); using (ImageFile img = ImageFile.Create(req.Current)) { Pixbuf pixbuf = img.Load(); Assert.IsNotNull(pixbuf); // We linearized to all black so this should pass the gray test Assert.IsTrue(PixbufUtils.IsGray(pixbuf, 1), "failed to linearize" + req.Current); } } }
public void ProcessImage(int image_num, FilterSet filter_set) { IPhoto photo = Collection [image_num]; string path; ScaleRequest req; req = requests [0]; MakeDir (SubdirPath (req.Name)); path = SubdirPath (req.Name, ImageName (image_num)); using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) { filter_set.Convert (request); if (request.Current.LocalPath == path) request.Preserve (request.Current); else System.IO.File.Copy (request.Current.LocalPath, path, true); if (photo != null && photo is Photo && App.Instance.Database != null) App.Instance.Database.Exports.Create ((photo as Photo).Id, (photo as Photo).DefaultVersionId, ExportStore.FolderExportType, // FIXME this is wrong, the final path is the one // after the Xfer. new SafeUri (path).ToString ()); for (int i = 1; i < requests.Length; i++) { req = requests [i]; if (scale && req.AvoidScale (Size)) continue; FilterSet req_set = new FilterSet (); req_set.Add (new ResizeFilter ((uint)Math.Max (req.Width, req.Height))); bool sharpen; try { sharpen = Preferences.Get<bool> (FolderExport.SHARPEN_KEY); } catch (NullReferenceException) { sharpen = true; Preferences.Set (FolderExport.SHARPEN_KEY, true); } if (sharpen) { if (req.Name == "lq") req_set.Add (new SharpFilter (0.1, 2, 4)); if (req.Name == "thumbs") req_set.Add (new SharpFilter (0.1, 2, 5)); } using (FilterRequest tmp_req = new FilterRequest (photo.DefaultVersion.Uri)) { req_set.Convert (tmp_req); MakeDir (SubdirPath (req.Name)); path = SubdirPath (req.Name, ImageName (image_num)); System.IO.File.Copy (tmp_req.Current.LocalPath, path, true); } } } }
void zip() { System.Uri dest = new System.Uri (uri_chooser.Uri); Crc32 crc = new Crc32 (); string filedest = dest.LocalPath + "/" + filename.Text; Log.DebugFormat ("Creating zip file {0}", filedest); ZipOutputStream s = new ZipOutputStream (File.Create(filedest)); if (scale_check.Active) Log.DebugFormat ("Scaling to {0}", scale_size.ValueAsInt); ProgressDialog progress_dialog = new ProgressDialog (Catalog.GetString ("Exporting files"), ProgressDialog.CancelButtonType.Stop, photos.Length, zipdiag); //Pack up for (int i = 0; i < photos.Length; i ++) { if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), photos[i].Name))) { progress_dialog.Destroy (); return; } string f = null; // FIXME: embed in a try/catch if (scale_check.Active) { FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); filters.Add (new ResizeFilter ((uint) scale_size.ValueAsInt)); FilterRequest freq = new FilterRequest (photos [i].DefaultVersion.Uri); filters.Convert (freq); f = freq.Current.LocalPath; } else { f = photos [i].DefaultVersion.Uri.LocalPath; } FileStream fs = File.OpenRead (f); byte [] buffer = new byte [fs.Length]; fs.Read (buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry (System.IO.Path.GetFileName (photos [i].DefaultVersion.Uri.LocalPath)); entry.DateTime = DateTime.Now; entry.Size = fs.Length; fs.Close (); crc.Reset (); crc.Update (buffer); entry.Crc = crc.Value; s.PutNextEntry (entry); s.Write (buffer, 0, buffer.Length); } s.Finish (); s.Close (); if (progress_dialog != null) progress_dialog.Destroy (); }
public void Transfer() { try { bool result = true; if (clean) Clean (dest); foreach (IBrowsableItem photo in selection.Items) { //FIXME need to implement the uniquename as a filter using (FilterRequest request = new FilterRequest (photo.DefaultVersionUri)) { if (rotate) new OrientationFilter ().Convert (request); GLib.File source = FileFactory.NewForUri (request.Current.ToString ()); GLib.File target = UniqueName (dest, photo.Name); FileProgressCallback cb = Progress; progress_dialog.Message = System.String.Format (Catalog.GetString ("Transferring picture \"{0}\" To CD"), photo.Name); progress_dialog.Fraction = photo_index / (double) selection.Count; progress_dialog.ProgressText = System.String.Format (Catalog.GetString ("{0} of {1}"), photo_index, selection.Count); result &= source.Copy (target, FileCopyFlags.None, null, cb); } photo_index++; } // FIXME the error dialog here is ugly and needs improvement when strings are not frozen. if (result) { progress_dialog.Message = Catalog.GetString ("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString ("Transfer Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; progress_dialog.Hide (); system ("brasero -n"); } else { throw new System.Exception (System.String.Format ("{0}{3}{1}{3}{2}", progress_dialog.Message, Catalog.GetString ("Error While Transferring"), result.ToString (), System.Environment.NewLine)); } } catch (System.Exception e) { FSpot.Utils.Log.DebugException (e); progress_dialog.Message = e.ToString (); progress_dialog.ProgressText = Catalog.GetString ("Error Transferring"); return; } Gtk.Application.Invoke (this.Destroy); }
void create_mosaics() { //Prepare the query Db db = App.Instance.Database; FSpot.PhotoQuery mini_query = new FSpot.PhotoQuery (db.Photos); Photo [] photos; if (tags_radio.Active) { //Build tag array List<Tag> taglist = new List<Tag> (); foreach (string tag_name in miniatures_tags.GetTypedTagNames ()) { Tag t = db.Tags.GetTagByName (tag_name); if (t != null) taglist.Add(t); } mini_query.Terms = FSpot.OrTerm.FromTags (taglist.ToArray ()); photos = mini_query.Photos; } else { photos = App.Instance.Organizer.Query.Photos; } if (photos.Length == 0) { //There is no photo for the selected tags! :( InfoDialog (Catalog.GetString ("No photos for the selection"), Catalog.GetString ("The tags selected provided no pictures. Please select different tags"), Gtk.MessageType.Error); return; } //Create minis ProgressDialog progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Creating miniatures"), ProgressDialog.CancelButtonType.Stop, photos.Length, metapixel_dialog); minidir_tmp = System.IO.Path.GetTempFileName (); System.IO.File.Delete (minidir_tmp); System.IO.Directory.CreateDirectory (minidir_tmp); minidir_tmp += "/"; //Call MetaPixel to create the minis foreach (Photo p in photos) { if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), p.Name))) { progress_dialog.Destroy (); DeleteTmp (); return; } //FIXME should switch to retry/skip if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) { Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating miniatures", p.DefaultVersion.Uri.LocalPath)); continue; } //FIXME Check if the picture's format is supproted (jpg, gif) FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri); filters.Convert (freq); //We use photo id for minis, instead of photo names, to avoid duplicates string minifile = minidir_tmp + p.Id.ToString() + System.IO.Path.GetExtension (p.DefaultVersion.Uri.ToString ()); string prepare_command = String.Format ("--prepare -w {0} -h {1} {2} {3} {4}tables.mxt", icon_x_size.Text, //Minis width icon_y_size.Text, //Minis height GLib.Shell.Quote (freq.Current.LocalPath), //Source image GLib.Shell.Quote (minifile), //Dest image minidir_tmp); //Table file Log.Debug ("Executing: metapixel " + prepare_command); System.Diagnostics.Process mp_prep = System.Diagnostics.Process.Start ("metapixel", prepare_command); mp_prep.WaitForExit (); if (!System.IO.File.Exists (minifile)) { Log.DebugFormat ("No mini? No party! {0}", minifile); continue; } } //Finished preparing! if (progress_dialog != null) progress_dialog.Destroy (); progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Creating photomosaics"), ProgressDialog.CancelButtonType.Stop, App.Instance.Organizer.SelectedPhotos ().Length, metapixel_dialog); //Now create the mosaics! uint error_count = 0; foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) { if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) { progress_dialog.Destroy (); DeleteTmp (); return; } //FIXME should switch to retry/skip if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) { Log.WarningFormat (String.Format ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath)); error_count ++; continue; } //FIXME Check if the picture's format is supproted (jpg, gif) FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri); filters.Convert (freq); string name = GetVersionName (p); System.Uri mosaic = GetUriForVersionName (p, name); string mosaic_command = String.Format ("--metapixel -l {0} {1} {2}", minidir_tmp, GLib.Shell.Quote (freq.Current.LocalPath), GLib.Shell.Quote (mosaic.LocalPath)); Log.Debug ("Executing: metapixel " + mosaic_command); System.Diagnostics.Process mp_exe = System.Diagnostics.Process.Start ("metapixel", mosaic_command); mp_exe.WaitForExit (); if (!GLib.FileFactory.NewForUri (mosaic).Exists) { Log.Warning ("Error in processing image " + p.Name); error_count ++; continue; } p.DefaultVersionId = p.AddVersion (mosaic, name, true); p.Changes.DataChanged = true; Core.Database.Photos.Commit (p); } //Finished creating mosaics if (progress_dialog != null) progress_dialog.Destroy (); string final_message = "Your mosaics have been generated as new versions of the pictures you selected"; if (error_count > 0) final_message += String.Format (".\n{0} images out of {1} had errors", error_count, App.Instance.Organizer.SelectedPhotos ().Length); InfoDialog (Catalog.GetString ("PhotoMosaics generated!"), Catalog.GetString (final_message), (error_count == 0 ? Gtk.MessageType.Info : Gtk.MessageType.Warning)); DeleteTmp (); }
void Upload() { IPhoto [] items = dialog.Items; string [] captions = dialog.Captions; dialog.StoreCaption (); long sent_bytes = 0; FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); filters.Add (new ResizeFilter ((uint) size)); for (int i = 0; i < items.Length; i++) { try { IPhoto item = items [i]; FileInfo file_info; Log.DebugFormat ("uploading {0}", i); progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length); progress_dialog.ProgressText = string.Empty; progress_dialog.Fraction = i / (double) items.Length; FilterRequest request = new FilterRequest (item.DefaultVersion.Uri); filters.Convert (request); file_info = new FileInfo (request.Current.LocalPath); album.Upload (captions [i] ?? "", request.Current.LocalPath); sent_bytes += file_info.Length; } catch (Exception e) { progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To Facebook: {0}"), e.Message); progress_dialog.ProgressText = Catalog.GetString ("Error"); Log.DebugException (e); if (progress_dialog.PerformRetrySkip ()) i--; } } progress_dialog.Message = Catalog.GetString ("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString ("Upload Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; var li = new LinkButton ("http://www.facebook.com/group.php?gid=158960179844&ref=mf", Catalog.GetString ("Visit F-Spot group on Facebook")); progress_dialog.VBoxPackEnd (li); li.ShowAll (); }
public void Transfer() { try { Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; if (clean) { Clean(); } foreach (IBrowsableItem photo in selection.Items) { //FIXME need to implement the uniquename as a filter using (Filters.FilterRequest request = new Filters.FilterRequest(photo.DefaultVersionUri)) { if (rotate) { new Filters.OrientationFilter().Convert(request); } Gnome.Vfs.Uri source = new Gnome.Vfs.Uri(request.Current.ToString()); Gnome.Vfs.Uri target = dest.Clone(); target = UniqueName(target, source.ExtractShortName()); Gnome.Vfs.XferProgressCallback cb = new Gnome.Vfs.XferProgressCallback(Progress); progress_dialog.Message = System.String.Format(Catalog.GetString("Transferring picture \"{0}\" To CD"), photo.Name); progress_dialog.Fraction = photo_index / (double)selection.Count; progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, selection.Count); result = Gnome.Vfs.Xfer.XferUri(source, target, Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, cb); } photo_index++; } // FIXME the error dialog here is ugly and needs improvement when strings are not frozen. if (result == Gnome.Vfs.Result.Ok) { progress_dialog.Message = Catalog.GetString("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString("Transfer Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; progress_dialog.Hide(); system("nautilus-cd-burner"); } else { throw new System.Exception(System.String.Format("{0}{3}{1}{3}{2}", progress_dialog.Message, Catalog.GetString("Error While Transferring"), result.ToString(), System.Environment.NewLine)); } } catch (System.Exception e) { progress_dialog.Message = e.ToString(); progress_dialog.ProgressText = Catalog.GetString("Error Transferring"); return; } Gtk.Application.Invoke(this.Destroy); }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source)); string dest = dest_uri.LocalPath; using (ImageFile img = ImageFile.Create(source)) { bool changed = false; if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile) { JpegFile jimg = img as JpegFile; if (img.Orientation == PixbufOrientation.RightTop) { JpegUtils.Transform(source, dest, JpegUtils.TransformType.Rotate90); changed = true; } else if (img.Orientation == PixbufOrientation.LeftBottom) { JpegUtils.Transform(source, dest, JpegUtils.TransformType.Rotate270); changed = true; } else if (img.Orientation == PixbufOrientation.BottomRight) { JpegUtils.Transform(source, dest, JpegUtils.TransformType.Rotate180); changed = true; } int width, height; jimg = ImageFile.Create(dest) as JpegFile; PixbufUtils.GetSize(dest, out width, out height); jimg.SetOrientation(PixbufOrientation.TopLeft); jimg.SetDimensions(width, height); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(dest, 160, 120, true); jimg.SetThumbnail(pixbuf); pixbuf.Dispose(); jimg.SaveMetaData(dest); jimg.Dispose(); } if (changed) { req.Current = dest_uri; } return(changed); } }
private void Upload() { account.Gallery.Progress = new ProgressItem (); account.Gallery.Progress.Changed += HandleProgressChanged; Log.Debug ("Starting upload"); FilterSet filters = new FilterSet (); if (account.Version == GalleryVersion.Version1) filters.Add (new WhiteListFilter (new string []{".jpg", ".jpeg", ".png", ".gif"})); if (scale) filters.Add (new ResizeFilter ((uint)size)); while (photo_index < items.Length) { IPhoto item = items [photo_index]; Log.DebugFormat ("uploading {0}", photo_index); progress_dialog.Message = System.String.Format (Catalog.GetString ("Uploading picture \"{0}\""), item.Name); progress_dialog.Fraction = photo_index / (double)items.Length; photo_index++; progress_dialog.ProgressText = System.String.Format (Catalog.GetString ("{0} of {1}"), photo_index, items.Length); FilterRequest req = new FilterRequest (item.DefaultVersion.Uri); filters.Convert (req); try { int id = album.Add (item, req.Current.LocalPath); if (item != null && item is Photo && App.Instance.Database != null && id != 0) App.Instance.Database.Exports.Create ((item as Photo).Id, (item as Photo).DefaultVersionId, ExportStore.Gallery2ExportType, String.Format("{0}:{1}",album.Gallery.Uri.ToString (), id.ToString ())); } catch (System.Exception e) { progress_dialog.Message = String.Format (Catalog.GetString ("Error uploading picture \"{0}\" to Gallery: {1}"), item.Name, e.Message); progress_dialog.ProgressText = Catalog.GetString ("Error"); Log.Exception (e); if (progress_dialog.PerformRetrySkip ()) photo_index--; } } progress_dialog.Message = Catalog.GetString ("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString ("Upload Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; if (browser) GtkBeans.Global.ShowUri (export_dialog.Screen, album.GetUrl()); }
private void Upload() { sent_bytes = 0; approx_size = 0; System.Uri album_uri = null; Log.Debug ("Starting Upload to Smugmug, album " + album.Title + " - " + album.AlbumID); FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); if (scale) filters.Add (new ResizeFilter ((uint)size)); while (photo_index < items.Length) { try { IPhoto item = items[photo_index]; FileInfo file_info; Log.Debug ("uploading " + photo_index); progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, photo_index+1, items.Length); progress_dialog.ProgressText = string.Empty; progress_dialog.Fraction = ((photo_index) / (double) items.Length); photo_index++; FilterRequest request = new FilterRequest (item.DefaultVersion.Uri); filters.Convert (request); file_info = new FileInfo (request.Current.LocalPath); if (approx_size == 0) //first image approx_size = file_info.Length * items.Length; else approx_size = sent_bytes * items.Length / (photo_index - 1); int image_id = account.SmugMug.Upload (request.Current.LocalPath, album.AlbumID); if (App.Instance.Database != null && item is Photo && image_id >= 0) App.Instance.Database.Exports.Create ((item as Photo).Id, (item as Photo).DefaultVersionId, ExportStore.SmugMugExportType, account.SmugMug.GetAlbumUrl (image_id).ToString ()); sent_bytes += file_info.Length; if (album_uri == null) album_uri = account.SmugMug.GetAlbumUrl (image_id); } catch (System.Exception e) { progress_dialog.Message = String.Format (Mono.Unix.Catalog.GetString ("Error Uploading To Gallery: {0}"), e.Message); progress_dialog.ProgressText = Mono.Unix.Catalog.GetString ("Error"); Log.DebugException (e); if (progress_dialog.PerformRetrySkip ()) { photo_index--; if (photo_index == 0) approx_size = 0; } } } progress_dialog.Message = Catalog.GetString ("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Mono.Unix.Catalog.GetString ("Upload Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; if (browser && album_uri != null) { GtkBeans.Global.ShowUri (Dialog.Screen, album_uri.ToString ()); } }
private void HandleResponse (object sender, Gtk.ResponseArgs args) { int size = 0; bool UserCancelled = false; bool rotate = true; // Lets remove the mail "create mail" dialog Dialog.Destroy(); if (args.ResponseId != Gtk.ResponseType.Ok) { return; } ProgressDialog progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"), ProgressDialog.CancelButtonType.Stop, selection.Count, parent_window); size = GetScaleSize(); // Which size should we scale to. 0 --> Original // evaluate mailto command and define attachment args for cli System.Text.StringBuilder attach_arg = new System.Text.StringBuilder (); switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) { case "thunderbird %s": case "mozilla-thunderbird %s": case "seamonkey -mail -compose %s": case "icedove %s": attach_arg.Append(","); break; case "kmail %s": attach_arg.Append(" --attach "); break; default: //evolution falls into default, since it supports mailto uri correctly attach_arg.Append("&attach="); break; } rotate = rotate_check.Active; // Should we automatically rotate original photos. Preferences.Set (Preferences.EXPORT_EMAIL_ROTATE, rotate); // Initiate storage for temporary files to be deleted later tmp_paths = new System.Collections.ArrayList(); // Create a tmp directory. tmp_mail_dir = System.IO.Path.GetTempFileName (); // Create a tmp file System.IO.File.Delete (tmp_mail_dir); // Delete above tmp file System.IO.Directory.CreateDirectory (tmp_mail_dir); // Create a directory with above tmp name System.Text.StringBuilder mail_attach = new System.Text.StringBuilder (); FilterSet filters = new FilterSet (); if (size != 0) filters.Add (new ResizeFilter ((uint) size)); else if (rotate) filters.Add (new OrientationFilter ()); filters.Add (new UniqueNameFilter (tmp_mail_dir)); for (int i = 0; i < selection.Count; i++) { Photo photo = selection [i] as Photo; if ( (photo != null) && (!UserCancelled) ) { if (progress_dialog != null) UserCancelled = progress_dialog.Update (String.Format (Catalog.GetString ("Exporting picture \"{0}\""), photo.Name)); if (UserCancelled) break; try { // Prepare a tmp_mail file name FilterRequest request = new FilterRequest (photo.DefaultVersionUri); filters.Convert (request); request.Preserve(request.Current); mail_attach.Append(attach_arg.ToString() + request.Current.ToString ()); // Mark the path for deletion tmp_paths.Add (request.Current.LocalPath); } catch (Exception e) { Console.WriteLine("Error preparing {0}: {1}", selection[photo_index].Name, e.Message); HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, Catalog.GetString("Error processing image"), String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[photo_index].Name, e.Message)); md.Run(); md.Destroy(); UserCancelled = true; } } } // foreach if (progress_dialog != null) progress_dialog.Destroy (); // No need to keep this window if (UserCancelled) DeleteTempFile(); else { // Send the mail :) string mail_subject = Catalog.GetString("my photos"); switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) { // openSuSE case "thunderbird %s": System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "icedove %s": System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "mozilla-thunderbird %s": System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "seamonkey -mail -compose %s": System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "kmail %s": System.Diagnostics.Process.Start("kmail", " --composer --subject \"" + mail_subject + "\"" + mail_attach); break; default: GnomeUtil.UrlShow ("mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach); break; } // Check if we have any temporary files to be deleted if (tmp_paths.Count > 0) { // Fetch timeout value from preferences. In seconds. Needs to be multiplied with 1000 to get msec uint delete_timeout; delete_timeout = (uint) (Preferences.Get<int> (Preferences.EXPORT_EMAIL_DELETE_TIMEOUT_SEC)); delete_timeout = delete_timeout * 1000; // to get milliseconds. // Start a timer and when it occurs, delete the temp files. GLib.Timeout.Add (delete_timeout, new GLib.TimeoutHandler (DeleteTempFile)); } } }
public void ProcessImage(int image_num, Filters.FilterSet filter_set) { IBrowsableItem photo = collection [image_num]; string photo_path = photo.DefaultVersionUri.LocalPath; string path; ScaleRequest req; req = requests [0]; MakeDir(SubdirPath(req.Name)); path = SubdirPath(req.Name, ImageName(image_num)); using (Filters.FilterRequest request = new Filters.FilterRequest(photo.DefaultVersionUri)) { filter_set.Convert(request); if (request.Current.LocalPath == path) { request.Preserve(request.Current); } else { File.Copy(request.Current.LocalPath, path, true); } if (photo != null && photo is Photo && Core.Database != null) { Core.Database.Exports.Create((photo as Photo).Id, (photo as Photo).DefaultVersionId, ExportStore.FolderExportType, // FIXME this is wrong, the final path is the one // after the Xfer. UriList.PathToFileUriEscaped(path).ToString()); } using (Exif.ExifData data = new Exif.ExifData(photo_path)) { for (int i = 1; i < requests.Length; i++) { req = requests [i]; if (scale && req.AvoidScale(size)) { continue; } Filters.FilterSet req_set = new Filters.FilterSet(); req_set.Add(new Filters.ResizeFilter((uint)Math.Max(req.Width, req.Height))); if ((bool)Preferences.Get(Preferences.EXPORT_FOLDER_SHARPEN)) { if (req.Name == "lq") { req_set.Add(new Filters.SharpFilter(0.1, 2, 4)); } if (req.Name == "thumbs") { req_set.Add(new Filters.SharpFilter(0.1, 2, 5)); } } using (Filters.FilterRequest tmp_req = new Filters.FilterRequest(photo.DefaultVersionUri)) { req_set.Convert(tmp_req); MakeDir(SubdirPath(req.Name)); path = SubdirPath(req.Name, ImageName(image_num)); System.IO.File.Copy(tmp_req.Current.LocalPath, path, true); } } } } }
private void Upload() { account.Gallery.Progress = new ProgressItem(); account.Gallery.Progress.Changed += HandleProgressChanged; System.Console.WriteLine("Starting upload"); FilterSet filters = new FilterSet(); if (account.Version == GalleryVersion.Version1) { filters.Add(new WhiteListFilter(new string [] { ".jpg", ".jpeg", ".png", ".gif" })); } if (scale) { filters.Add(new ResizeFilter((uint)size)); } else if (rotate) { filters.Add(new OrientationFilter()); } while (photo_index < items.Length) { IBrowsableItem item = items [photo_index]; System.Console.WriteLine("uploading {0}", photo_index); progress_dialog.Message = System.String.Format(Catalog.GetString("Uploading picture \"{0}\""), item.Name); progress_dialog.Fraction = photo_index / (double)items.Length; photo_index++; progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, items.Length); Filters.FilterRequest req = new Filters.FilterRequest(item.DefaultVersionUri); filters.Convert(req); try { int id = album.Add(item, req.Current.LocalPath); if (item != null && item is Photo && Core.Database != null && id != 0) { Core.Database.Exports.Create((item as Photo).Id, (item as Photo).DefaultVersionId, ExportStore.Gallery2ExportType, String.Format("{0}:{1}", album.Gallery.Uri.ToString(), id.ToString())); } } catch (System.Exception e) { progress_dialog.Message = String.Format(Catalog.GetString("Error uploading picture \"{0}\" to Gallery: {1}"), item.Name, e.Message); progress_dialog.ProgressText = Catalog.GetString("Error"); if (progress_dialog.PerformRetrySkip()) { photo_index--; } } } progress_dialog.Message = Catalog.GetString("Done Sending Photos"); progress_dialog.Fraction = 1.0; progress_dialog.ProgressText = Catalog.GetString("Upload Complete"); progress_dialog.ButtonLabel = Gtk.Stock.Ok; if (browser) { GnomeUtil.UrlShow(null, album.GetUrl()); } }
public string Upload(IPhoto photo, IFilter filter, bool is_public, bool is_family, bool is_friend) { if (token == null) { throw new Exception ("Must Login First"); } // FIXME flickr needs rotation string error_verbose; using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) { try { string tags = null; filter.Convert (request); string path = request.Current.LocalPath; if (ExportTags && photo.Tags != null) { StringBuilder taglist = new StringBuilder (); FSpot.Core.Tag [] t = photo.Tags; FSpot.Core.Tag tag_iter = null; for (int i = 0; i < t.Length; i++) { if (i > 0) taglist.Append (","); taglist.Append (String.Format ("\"{0}\"", t[i].Name)); // Go through the tag parents if (ExportTagHierarchy) { tag_iter = t[i].Category; while (tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null) { // Skip top level tags because they have no meaning in a linear tag database if (ExportIgnoreTopLevel && tag_iter.Category == App.Instance.Database.Tags.RootCategory) { break; } // FIXME Look if the tag is already there! taglist.Append (","); taglist.Append (String.Format ("\"{0}\"", tag_iter.Name)); tag_iter = tag_iter.Category; } } } tags = taglist.ToString (); } try { string photoid = flickr.UploadPicture (path, photo.Name, photo.Description, tags, is_public, is_family, is_friend); return photoid; } catch (FlickrNet.FlickrException ex) { Log.Error ("Problems uploading picture: " + ex.ToString()); error_verbose = ex.ToString(); } } catch (Exception e) { // FIXME we need to distinguish between file IO errors and xml errors here throw new System.Exception ("Error while uploading", e); } } throw new System.Exception (error_verbose); }
public void ProcessImage (int image_num, Filters.FilterSet filter_set) { IBrowsableItem photo = collection [image_num]; string photo_path = photo.DefaultVersionUri.LocalPath; string path; ScaleRequest req; req = requests [0]; MakeDir (SubdirPath (req.Name)); path = SubdirPath (req.Name, ImageName (image_num)); using (Filters.FilterRequest request = new Filters.FilterRequest (photo.DefaultVersionUri)) { filter_set.Convert (request); if (request.Current.LocalPath == path) request.Preserve(request.Current); else File.Copy (request.Current.LocalPath, path, true); if (photo != null && photo is Photo && Core.Database != null) { Core.Database.Exports.Create ((photo as Photo).Id, (photo as Photo).DefaultVersionId, ExportStore.FolderExportType, // FIXME this is wrong, the final path is the one // after the Xfer. UriList.PathToFileUriEscaped (path).ToString ()); } using (Exif.ExifData data = new Exif.ExifData (photo_path)) { for (int i = 1; i < requests.Length; i++) { req = requests [i]; if (scale && req.AvoidScale (size)) continue; Filters.FilterSet req_set = new Filters.FilterSet (); req_set.Add (new Filters.ResizeFilter ((uint)Math.Max (req.Width, req.Height))); if ((bool)Preferences.Get (Preferences.EXPORT_FOLDER_SHARPEN)) { if (req.Name == "lq") req_set.Add (new Filters.SharpFilter (0.1, 2, 4)); if (req.Name == "thumbs") req_set.Add (new Filters.SharpFilter (0.1, 2, 5)); } using (Filters.FilterRequest tmp_req = new Filters.FilterRequest (photo.DefaultVersionUri)) { req_set.Convert (tmp_req); MakeDir (SubdirPath (req.Name)); path = SubdirPath (req.Name, ImageName (image_num)); System.IO.File.Copy (tmp_req.Current.LocalPath, path, true); } } } } }
void CreatePhotoWall() { dir_tmp = System.IO.Path.GetTempFileName (); System.IO.File.Delete (dir_tmp); System.IO.Directory.CreateDirectory (dir_tmp); dir_tmp += "/"; //Prepare the pictures ProgressDialog progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing selected pictures"), ProgressDialog.CancelButtonType.Stop, App.Instance.Organizer.SelectedPhotos ().Length, picturetile_dialog); FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); uint counter = 0; List<Tag> all_tags = new List<Tag> (); foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) { if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) { progress_dialog.Destroy (); DeleteTmp (); return; } //Store photo tags, to attach them later on import foreach (Tag tag in p.Tags) { if (! all_tags.Contains (tag)) all_tags.Add (tag); } //FIXME should switch to retry/skip if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) { Log.WarningFormat ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath); continue; } using (FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri)) { filters.Convert (freq); File.Copy (freq.Current.LocalPath, String.Format ("{0}{1}.jpg", dir_tmp, counter ++)); } } if (progress_dialog != null) progress_dialog.Destroy (); photo_tags = all_tags.ToArray (); string uniform = ""; if (uniform_images.Active) uniform = "--uniform"; string output_format = "jpeg"; if (tiff_radio.Active) output_format = "tiff"; string scale = String.Format (CultureInfo.InvariantCulture, "{0,4}", (double) image_scale.Value / (double) 100); destfile_tmp = String.Format ("{0}.{1}", System.IO.Path.GetTempFileName (), output_format); //Execute picturetile string picturetile_command = String.Format ("--size {0}x{1} " + "--directory {2} " + "--scale {3} " + "--margin {4} " + "--border {5} " + "--background {6} " + "--pages {7} " + "{8} " + "{9}", x_max_size.Text, y_max_size.Text, dir_tmp, scale, space_between_images.Text, outside_border.Text, colors [background_color.Active], pages.Text, uniform, destfile_tmp); Log.Debug ("Executing: picturetile.pl " + picturetile_command); System.Diagnostics.Process pt_exe = System.Diagnostics.Process.Start ("picturetile.pl", picturetile_command); pt_exe.WaitForExit (); // Handle multiple files generation (pages). // If the user wants 2 pages (images), and the output filename is out.jpg, picturetile will create // /tmp/out1.jpg and /tmp/out2.jpg. System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (System.IO.Path.GetDirectoryName (destfile_tmp)); string filemask = System.IO.Path.GetFileNameWithoutExtension (destfile_tmp) + "*" + System.IO.Path.GetExtension (destfile_tmp); FileInfo [] fi = di.GetFiles (filemask); // Move generated files to f-spot photodir string [] photo_import_list = new string [fi.Length]; counter = 0; foreach (FileInfo f in fi) { string orig = System.IO.Path.Combine (f.DirectoryName, f.Name); photo_import_list [counter ++] = MoveFile (orig); } //Add the pic(s) to F-Spot! Db db = App.Instance.Database; ImportCommand command = new ImportCommand (null); if (command.ImportFromPaths (db.Photos, photo_import_list, photo_tags) > 0) { InfoDialog (Catalog.GetString ("PhotoWall generated!"), Catalog.GetString ("Your photo wall have been generated and imported in F-Spot. Select the last roll to see it"), Gtk.MessageType.Info); } else { InfoDialog (Catalog.GetString ("Error importing photowall"), Catalog.GetString ("An error occurred while importing the newly generated photowall to F-Spot"), Gtk.MessageType.Error); } DeleteTmp (); }
public SendEmail (IBrowsableCollection selection) : base ("mail_dialog") { this.selection = selection; for (int i = 0; i < selection.Count; i++) { Photo p = selection[i] as Photo; if (Gnome.Vfs.MimeType.GetMimeTypeForUri (p.DefaultVersionUri.ToString ()) != "image/jpeg") force_original = true; } if (force_original) { original_size.Active = true; tiny_size.Sensitive = false; small_size.Sensitive = false; medium_size.Sensitive = false; large_size.Sensitive = false; x_large_size.Sensitive = false; } else switch (Preferences.Get<int> (Preferences.EXPORT_EMAIL_SIZE)) { case 0 : original_size.Active = true; break; case 1 : tiny_size.Active = true; break; case 2 : small_size.Active = true; break; case 3 : medium_size.Active = true; break; case 4 : large_size.Active = true; break; case 5 : x_large_size.Active = true; break; default: break; } rotate_check.Active = Preferences.Get<bool> (Preferences.EXPORT_EMAIL_ROTATE); rotate_check.Sensitive = original_size.Active && tiny_size.Sensitive; tray_scrolled.Add (new TrayView (selection)); Dialog.Modal = false; // Calculate total original filesize for (int i = 0; i < selection.Count; i++) { Photo photo = selection[i] as Photo; try { Orig_Photo_Size += (new Gnome.Vfs.FileInfo (photo.DefaultVersionUri.ToString ())).Size; } catch { } } for (int k = 0; k < avg_scale_ref.Length; k++) avg_scale[k] = avg_scale_ref[k]; // Calculate approximate size shrinking, use first photo, and shrink to medium size as base. Photo scalephoto = selection [0] as Photo; if (scalephoto != null && !force_original) { // Get first photos file size long orig_size = (new Gnome.Vfs.FileInfo (scalephoto.DefaultVersionUri.ToString ())).Size; FilterSet filters = new FilterSet (); filters.Add (new ResizeFilter ((uint)(sizes [3]))); long new_size; using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersionUri)) { filters.Convert (request); new_size = (new Gnome.Vfs.FileInfo (request.Current.ToString ())).Size; } if (orig_size > 0) { // Get the factor (scale) between original and resized medium size. scale_percentage = 1 - ( (float) (orig_size - new_size) / orig_size); // What is the relation between the estimated medium scale factor, and reality? double scale_scale = scale_percentage / avg_scale_ref[3]; //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", // scale_percentage, avg_scale_ref[3], scale_scale ); // Re-Calculate the proper relation per size for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k] * scale_scale; // System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", // k, avg_scale[k], avg_scale_ref[k] ); } } } NumberOfPictures.Text = selection.Count.ToString(); TotalOriginalSize.Text = SizeUtil.ToHumanReadable (Orig_Photo_Size); UpdateEstimatedSize(); Dialog.ShowAll (); //LoadHistory (); Dialog.Response += HandleResponse; }
private void HandleResponse (object sender, Gtk.ResponseArgs args) { int size = 0; bool UserCancelled = false; // Lets remove the mail "create mail" dialog Destroy(); if (args.ResponseId != Gtk.ResponseType.Ok) { return; } ProgressDialog progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing email"), ProgressDialog.CancelButtonType.Stop, selection.Count, parent_window); size = GetScaleSize(); // Which size should we scale to. 0 --> Original // evaluate mailto command and define attachment args for cli System.Text.StringBuilder attach_arg = new System.Text.StringBuilder (); switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) { case "thunderbird %s": case "mozilla-thunderbird %s": case "seamonkey -mail -compose %s": case "icedove %s": attach_arg.Append(","); break; case "kmail %s": attach_arg.Append(" --attach "); break; default://evolution falls into default, since it supports mailto uri correctly attach_arg.Append("&attach="); break; } // Create a tmp directory. tmp_mail_dir = System.IO.Path.GetTempFileName (); // Create a tmp file System.IO.File.Delete (tmp_mail_dir); // Delete above tmp file System.IO.Directory.CreateDirectory (tmp_mail_dir); // Create a directory with above tmp name System.Text.StringBuilder mail_attach = new System.Text.StringBuilder (); FilterSet filters = new FilterSet (); if (size != 0) filters.Add (new ResizeFilter ((uint) size)); filters.Add (new UniqueNameFilter (new SafeUri (tmp_mail_dir))); for (int i = 0; i < selection.Count; i++) { var photo = selection [i]; if ( (photo != null) && (!UserCancelled) ) { if (progress_dialog != null) UserCancelled = progress_dialog.Update (String.Format (Catalog.GetString ("Exporting picture \"{0}\""), photo.Name)); if (UserCancelled) break; try { // Prepare a tmp_mail file name FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri); filters.Convert (request); request.Preserve(request.Current); mail_attach.Append(((i == 0 && attach_arg.ToString () == ",") ? "" : attach_arg.ToString()) + request.Current.ToString ()); } catch (Exception e) { Hyena.Log.ErrorFormat ("Error preparing {0}: {1}", selection[i].Name, e.Message); HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, Catalog.GetString("Error processing image"), String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[i].Name, e.Message)); md.Run(); md.Destroy(); UserCancelled = true; } } } // foreach if (progress_dialog != null) progress_dialog.Destroy (); // No need to keep this window if (UserCancelled) return; // Send the mail :) string mail_subject = Catalog.GetString("My Photos"); switch (Preferences.Get<string> (Preferences.GNOME_MAILTO_COMMAND)) { // openSuSE case "thunderbird %s": System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "icedove %s": System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "mozilla-thunderbird %s": System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "seamonkey -mail -compose %s": System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\""); break; case "kmail %s": System.Diagnostics.Process.Start("kmail", " --composer --subject \"" + mail_subject + "\"" + mail_attach); break; case "evolution %s": //evo doesn't urldecode the subject GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + mail_subject + mail_attach); break; default: GtkBeans.Global.ShowUri (Screen, "mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach); break; } }
protected override void OnActivated () { try { if (!item.IsValid) throw new ApplicationException ("attempt to filter invalid item"); using (FilterRequest req = new FilterRequest (item.Current.DefaultVersionUri)) { IFilter filter = BuildFilter (); if (filter.Convert (req)) { // The filter did something so lets ve EditTarget target = new EditTarget (item); Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; result = Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (req.Current.ToString ()), new Gnome.Vfs.Uri (target.Uri.ToString ()), Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, delegate { System.Console.WriteLine ("progress"); return 1; }); if (result == Gnome.Vfs.Result.Ok) { System.Console.WriteLine ("Done modifying image"); target.Commit (); } else { target.Delete (); throw new ApplicationException (String.Format ( "{0}: error moving to destination {1}", this, target.ToString ())); } } } } catch (Exception e) { Dialog d = new EditExceptionDialog (null, e, item.Current); d.Show (); d.Run (); d.Destroy (); } }
public SendEmail (IBrowsableCollection selection, Window parent_window) : base ("mail_dialog.ui", "mail_dialog") { this.selection = selection; this.parent_window = parent_window; foreach (var p in selection.Items) { if (FileFactory.NewForUri (p.DefaultVersion.Uri).QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null).ContentType != "image/jpeg") force_original = true; } if (force_original) { original_size.Active = true; tiny_size.Sensitive = false; small_size.Sensitive = false; medium_size.Sensitive = false; large_size.Sensitive = false; x_large_size.Sensitive = false; } else switch (Preferences.Get<int> (Preferences.EXPORT_EMAIL_SIZE)) { case 0 : original_size.Active = true; break; case 1 : tiny_size.Active = true; break; case 2 : small_size.Active = true; break; case 3 : medium_size.Active = true; break; case 4 : large_size.Active = true; break; case 5 : x_large_size.Active = true; break; default: break; } tray_scrolled.Add (new TrayView (selection)); Modal = false; // Calculate total original filesize foreach (var photo in selection.Items) { try { Orig_Photo_Size += FileFactory.NewForUri (photo.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size; } catch { } } for (int k = 0; k < avg_scale_ref.Length; k++) avg_scale[k] = avg_scale_ref[k]; // Calculate approximate size shrinking, use first photo, and shrink to medium size as base. var scalephoto = selection [0]; if (scalephoto != null && !force_original) { // Get first photos file size long orig_size = FileFactory.NewForUri (scalephoto.DefaultVersion.Uri).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size; FilterSet filters = new FilterSet (); filters.Add (new ResizeFilter ((uint)(sizes [3]))); long new_size; using (FilterRequest request = new FilterRequest (scalephoto.DefaultVersion.Uri)) { filters.Convert (request); new_size = FileFactory.NewForUri (request.Current).QueryInfo ("standard::size", FileQueryInfoFlags.None, null).Size; } if (orig_size > 0) { // Get the factor (scale) between original and resized medium size. scale_percentage = 1 - ( (float) (orig_size - new_size) / orig_size); // What is the relation between the estimated medium scale factor, and reality? double scale_scale = scale_percentage / avg_scale_ref[3]; //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", // scale_percentage, avg_scale_ref[3], scale_scale ); // Re-Calculate the proper relation per size for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k] * scale_scale; // System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", // k, avg_scale[k], avg_scale_ref[k] ); } } } NumberOfPictures.Text = selection.Count.ToString(); TotalOriginalSize.Text = GLib.Format.SizeForDisplay (Orig_Photo_Size); UpdateEstimatedSize(); ShowAll (); //LoadHistory (); Response += HandleResponse; }