private void InfoLoaded(Gnome.Vfs.Result result, Gnome.Vfs.FileInfo [] info, uint entries_read) { if (result != Gnome.Vfs.Result.Ok && result != Gnome.Vfs.Result.ErrorEof) { return; } ArrayList items = new ArrayList(); for (int i = 0; i < entries_read; i++) { Gnome.Vfs.Uri vfs = new Gnome.Vfs.Uri(uri.ToString()); vfs = vfs.AppendFileName(info [i].Name); Uri file = new Uri(vfs.ToString()); System.Console.WriteLine("tesing uri = {0}", file.ToString()); if (FSpot.ImageFile.HasLoader(file)) { items.Add(new FileBrowsableItem(file)); } } Gtk.Application.Invoke(items, System.EventArgs.Empty, delegate(object sender, EventArgs args) { collection.Add(items.ToArray(typeof(FileBrowsableItem)) as FileBrowsableItem []); }); }
private void InfoLoaded (Gnome.Vfs.Result result, Gnome.Vfs.FileInfo []info, uint entries_read) { if (result != Gnome.Vfs.Result.Ok && result != Gnome.Vfs.Result.ErrorEof) return; ArrayList items = new ArrayList (); for (int i = 0; i < entries_read; i++) { Gnome.Vfs.Uri vfs = new Gnome.Vfs.Uri (uri.ToString ()); vfs = vfs.AppendFileName (info [i].Name); Uri file = new Uri (vfs.ToString ()); System.Console.WriteLine ("tesing uri = {0}", file.ToString ()); if (FSpot.ImageFile.HasLoader (file)) items.Add (new FileBrowsableItem (file)); } Gtk.Application.Invoke (items, System.EventArgs.Empty, delegate (object sender, EventArgs args) { collection.Add (items.ToArray (typeof (FileBrowsableItem)) as FileBrowsableItem []); }); }
public void Upload () { // FIXME use mkstemp Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; try { Dialog.Hide (); Gnome.Vfs.Uri source = new Gnome.Vfs.Uri (Path.Combine (gallery_path, gallery_name)); Gnome.Vfs.Uri target = dest.Clone(); target = target.AppendFileName(source.ExtractShortName ()); if (dest.IsLocal) gallery_path = Gnome.Vfs.Uri.GetLocalPathFromUri (dest.ToString ()); progress_dialog.Message = Catalog.GetString ("Building Gallery"); progress_dialog.Fraction = 0.0; FolderGallery gallery; if (static_radio.Active) { gallery = new HtmlGallery (selection, gallery_path, gallery_name); } else if (original_radio.Active) { gallery = new OriginalGallery (selection, gallery_path, gallery_name); } else { gallery = new FolderGallery (selection, gallery_path, gallery_name); } if (scale) { System.Console.WriteLine ("setting scale to {0}", size); gallery.SetScale (size); } else { System.Console.WriteLine ("Exporting full size image"); } if (rotate) { System.Console.WriteLine ("Exporting rotated image"); gallery.SetRotate(); } gallery.Description = description; gallery.GenerateLayout (); Filters.FilterSet filter_set = new Filters.FilterSet (); if (scale) filter_set.Add (new Filters.ResizeFilter ((uint) size)); else if (rotate) filter_set.Add (new Filters.OrientationFilter ()); filter_set.Add (new Filters.ChmodFilter ()); filter_set.Add (new Filters.UniqueNameFilter (gallery_path)); for (int photo_index = 0; photo_index < selection.Count; photo_index++) { try { progress_dialog.Message = System.String.Format (Catalog.GetString ("Uploading picture \"{0}\""), selection[photo_index].Name); progress_dialog.Fraction = photo_index / (double) selection.Count; gallery.ProcessImage (photo_index, filter_set); progress_dialog.ProgressText = System.String.Format (Catalog.GetString ("{0} of {1}"), photo_index, selection.Count); } catch (Exception e) { progress_dialog.Message = String.Format (Catalog.GetString ("Error uploading picture \"{0}\" to Gallery:{2}{1}"), selection[photo_index].Name, e.Message, Environment.NewLine); progress_dialog.ProgressText = Catalog.GetString ("Error"); if (progress_dialog.PerformRetrySkip ()) photo_index--; } } //create the zip tarballs for original if (gallery is OriginalGallery && (bool)Preferences.Get(Preferences.EXPORT_FOLDER_INCLUDE_TARBALLS)) (gallery as OriginalGallery).CreateZip (); // we've created the structure, now if the destination was local we are done // otherwise we xfer if (!dest.IsLocal) { Console.WriteLine(target); System.Console.WriteLine ("Xfering {0} to {1}", source.ToString (), target.ToString ()); result = Gnome.Vfs.Xfer.XferUri (source, target, Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, Progress); } 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; } else { progress_dialog.ProgressText = result.ToString (); progress_dialog.Message = Catalog.GetString ("Error While Transferring"); } if (open) { GnomeUtil.UrlShow (null, target.ToString ()); } // Save these settings for next time Preferences.Set (Preferences.EXPORT_FOLDER_SCALE, scale); Preferences.Set (Preferences.EXPORT_FOLDER_SIZE, size); Preferences.Set (Preferences.EXPORT_FOLDER_OPEN, open); Preferences.Set (Preferences.EXPORT_FOLDER_ROTATE, rotate); Preferences.Set (Preferences.EXPORT_FOLDER_METHOD, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder" ); Preferences.Set (Preferences.EXPORT_FOLDER_URI, uri_chooser.Uri); } catch (System.Exception e) { // Console.WriteLine (e); progress_dialog.Message = e.ToString (); progress_dialog.ProgressText = Catalog.GetString ("Error Transferring"); } finally { // if the destination isn't local then we want to remove the temp directory we // created. if (!dest.IsLocal) System.IO.Directory.Delete (gallery_path, true); Gtk.Application.Invoke (delegate { Dialog.Destroy(); }); } }
void zip () { Gnome.Vfs.Uri dest = new Gnome.Vfs.Uri (uri_chooser.Uri); Crc32 crc = new Crc32 (); string filedest = Gnome.Vfs.Uri.GetLocalPathFromUri (dest.ToString ()) + "/" + filename.Text; Console.WriteLine ("Creating zip file {0}", filedest); ZipOutputStream s = new ZipOutputStream (File.Create(filedest)); if (scale_check.Active) Console.WriteLine ("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; 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].DefaultVersionUri); filters.Convert (freq); f = freq.Current.LocalPath; } else { f = photos [i].DefaultVersionUri.LocalPath; } FileStream fs = File.OpenRead (f); byte [] buffer = new byte [fs.Length]; fs.Read (buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry (photos [i].Name); 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 (); }
void HandleBrowseExisting(object sender, System.EventArgs args) { GnomeUtil.UrlShow(null, dest.ToString()); }
public void Upload() { // FIXME use mkstemp Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; try { Dialog.Hide(); Gnome.Vfs.Uri source = new Gnome.Vfs.Uri(Path.Combine(gallery_path, gallery_name)); Gnome.Vfs.Uri target = dest.Clone(); target = target.AppendFileName(source.ExtractShortName()); if (dest.IsLocal) { gallery_path = Gnome.Vfs.Uri.GetLocalPathFromUri(dest.ToString()); } progress_dialog.Message = Catalog.GetString("Building Gallery"); progress_dialog.Fraction = 0.0; FolderGallery gallery; if (static_radio.Active) { gallery = new HtmlGallery(selection, gallery_path, gallery_name); } else if (original_radio.Active) { gallery = new OriginalGallery(selection, gallery_path, gallery_name); } else { gallery = new FolderGallery(selection, gallery_path, gallery_name); } if (scale) { System.Console.WriteLine("setting scale to {0}", size); gallery.SetScale(size); } else { System.Console.WriteLine("Exporting full size image"); } if (rotate) { System.Console.WriteLine("Exporting rotated image"); gallery.SetRotate(); } gallery.Description = description; gallery.GenerateLayout(); Filters.FilterSet filter_set = new Filters.FilterSet(); if (scale) { filter_set.Add(new Filters.ResizeFilter((uint)size)); } else if (rotate) { filter_set.Add(new Filters.OrientationFilter()); } filter_set.Add(new Filters.ChmodFilter()); filter_set.Add(new Filters.UniqueNameFilter(gallery_path)); for (int photo_index = 0; photo_index < selection.Count; photo_index++) { try { progress_dialog.Message = System.String.Format(Catalog.GetString("Uploading picture \"{0}\""), selection[photo_index].Name); progress_dialog.Fraction = photo_index / (double)selection.Count; gallery.ProcessImage(photo_index, filter_set); progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, selection.Count); } catch (Exception e) { progress_dialog.Message = String.Format(Catalog.GetString("Error uploading picture \"{0}\" to Gallery:{2}{1}"), selection[photo_index].Name, e.Message, Environment.NewLine); progress_dialog.ProgressText = Catalog.GetString("Error"); if (progress_dialog.PerformRetrySkip()) { photo_index--; } } } //create the zip tarballs for original if (gallery is OriginalGallery && (bool)Preferences.Get(Preferences.EXPORT_FOLDER_INCLUDE_TARBALLS)) { (gallery as OriginalGallery).CreateZip(); } // we've created the structure, now if the destination was local we are done // otherwise we xfer if (!dest.IsLocal) { Console.WriteLine(target); System.Console.WriteLine("Xfering {0} to {1}", source.ToString(), target.ToString()); result = Gnome.Vfs.Xfer.XferUri(source, target, Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, Progress); } 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; } else { progress_dialog.ProgressText = result.ToString(); progress_dialog.Message = Catalog.GetString("Error While Transferring"); } if (open) { GnomeUtil.UrlShow(null, target.ToString()); } // Save these settings for next time Preferences.Set(Preferences.EXPORT_FOLDER_SCALE, scale); Preferences.Set(Preferences.EXPORT_FOLDER_SIZE, size); Preferences.Set(Preferences.EXPORT_FOLDER_OPEN, open); Preferences.Set(Preferences.EXPORT_FOLDER_ROTATE, rotate); Preferences.Set(Preferences.EXPORT_FOLDER_METHOD, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder"); Preferences.Set(Preferences.EXPORT_FOLDER_URI, uri_chooser.Uri); } catch (System.Exception e) { // Console.WriteLine (e); progress_dialog.Message = e.ToString(); progress_dialog.ProgressText = Catalog.GetString("Error Transferring"); } finally { // if the destination isn't local then we want to remove the temp directory we // created. if (!dest.IsLocal) { System.IO.Directory.Delete(gallery_path, true); } Gtk.Application.Invoke(delegate { Dialog.Destroy(); }); } }
void zip() { Gnome.Vfs.Uri dest = new Gnome.Vfs.Uri(uri_chooser.Uri); Crc32 crc = new Crc32(); string filedest = Gnome.Vfs.Uri.GetLocalPathFromUri(dest.ToString()) + "/" + filename.Text; Console.WriteLine("Creating zip file {0}", filedest); ZipOutputStream s = new ZipOutputStream(File.Create(filedest)); if (scale_check.Active) { Console.WriteLine("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; 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].DefaultVersionUri); filters.Convert(freq); f = freq.Current.LocalPath; } else { f = photos [i].DefaultVersionUri.LocalPath; } FileStream fs = File.OpenRead(f); byte [] buffer = new byte [fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(photos [i].Name); 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(); } }