Hi! Please find attached to this mail and also online at http://askwar.pastebin.ca/1331616 a (first) attempt of fixing this issue.
I tested this with Zip Export, Flickr and Picasa and there it works reasonably well. There's still one issue, though - a string like C%C3%A9dric is decoded as something like C├Г┬йdric (Zip) or CÃ(c)dric (Flickr). Both things are wrong - it should be decoded as Cédric. I guess the UnescapeString method in UriUtils needs to be made UTF-8 capable. How would that be done? Alexander 2009/2/8 Alexander Skwar <alexanders.mailinglists+nos...@gmail.com>: > Hi! > > A short while ago, I submitted Bug 569460 – Unescape special > charcters in filenames when doing (Flickr, Picasa Web, Zip, ...) export. > I now had a look at the source at ZipExport.cs, as that's the shortest > export source. And as all the exporters show the same problem, I thought > that one might be as good as another one... > > In the ZipExport.cs of f-spot 0.5.0.3, I think that the method zip() > is the interesting one. In there, I'd guess that the line 126 > > ZipEntry entry = new ZipEntry (photos [i].Name); > > is interesting. Here, the name of the ZipEntry is taken to be the Name > of the photo. I haven't checked, but I suppose that this Name string > contains the escaped version of the filename, doesn't it? Ie., if > the filename is > > [2008-11-12--10.40.37] (IMG_0017) Cédric, Photoshooting, Petra, Fotograf.jpg > > then Name would be > > %5B2008-11-12--10.40.37%5D%20(IMG_0017)%20C%C3%A9dric%2C%20Photoshooting%2C%20Petra%2C%20Fotograf.jpg > > Correct? > > I've got no knowledge at all about C#, but I think that what would > be required here is, that instead of photos[i].Name, the unescaped > version of the name is to be used. > > In C#, is there a method which allows to easily unescape a > string? Ie. something, which translates stuff like "C%C3%A9dric" > to "Cédric"? > > I guess that something like this already needs to be used in f-spot, > in order for f-spot to decode a file uri to a path, as only a file uri > (ie. file:///home/askwar/.......) is stored in the f-spot database. I > "browsed" the f-spot source, but haven't found the spot, where > f-spot tries to load a file from disk. I guess that's where f-spot > would do a decoding of the string stored in the database to get > the proper path name. > > The reason why I bring that topic also here to the mailinglist > is, that this bug makes f-spot pretty much useless for me, as > it's certainly nice to be able to manage pictures locally - but > from time to time, an export to some public site, like Flickr, > PicasaWeb or whatever, would be good as well. And with > picturenames like > "%5B2008-11-12--10.40.37%5D%20(IMG_0017)%20C%C3%A9dric%2C%20Photoshooting%2C%20Petra%2C%20Fotograf.jpg" > that looks very bad. > > I'd be very happy if one of you could give me a hand :) > > Thanks a lot, > > Alexander > -- > [ Soc. => http://twitter.com/alexs77 | http://www.plurk.com/alexs77 ] > [ Mehr => http://zyb.com/alexws77 ] > [ Chat => Jabber: alexw...@jabber80.com | Google Talk: a.sk...@gmail.com ] > [ Mehr => MSN: alexw...@live.de | Yahoo!: askwar | ICQ: 350677419 ] > -- Alexander -- [ Soc. => http://twitter.com/alexs77 | http://www.plurk.com/alexs77 ] [ Mehr => http://zyb.com/alexws77 ] [ Chat => Jabber: alexw...@jabber80.com | Google Talk: a.sk...@gmail.com ] [ Mehr => MSN: alexw...@live.de | Yahoo!: askwar | ICQ: 350677419 ]
Index: src/Utils/UriUtils.cs =================================================================== --- src/Utils/UriUtils.cs (Revision 4702) +++ src/Utils/UriUtils.cs (Arbeitskopie) @@ -94,6 +94,25 @@ } return s.ToString (); - } + } + // NOTE: Copied from dbus-sharp/Address.cs: Unescape, which isn't public + // This is the reverse function of EscapeString + public static string UnescapeString (string str) + { + if (str == null) + return String.Empty; + + StringBuilder sb = new StringBuilder (); + int len = str.Length; + int i = 0; + while (i != len) { + if (Uri.IsHexEncoding (str, i)) + sb.Append (Uri.HexUnescape (str, ref i)); + else + sb.Append (str[i++]); + } + + return sb.ToString (); + } } } Index: extensions/Exporters/PicasaWebExport/PicasaWebExport.cs =================================================================== --- extensions/Exporters/PicasaWebExport/PicasaWebExport.cs (Revision 4702) +++ extensions/Exporters/PicasaWebExport/PicasaWebExport.cs (Arbeitskopie) @@ -654,12 +654,15 @@ while (photo_index < items.Length) { try { IBrowsableItem item = items[photo_index]; + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (item.Name); FileInfo file_info; Console.WriteLine ("uploading {0}", photo_index); + /* Bug #569460 */ progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), - item.Name, photo_index+1, items.Length); + prettyname, photo_index+1, items.Length); photo_index++; PicasaPicture picture; @@ -672,7 +675,8 @@ else approx_size = sent_bytes * items.Length / (photo_index - 1); - picture = album.UploadPicture (request.Current.LocalPath, Path.ChangeExtension (item.Name, "jpg"), item.Description); + /* Bug #569460 */ + picture = album.UploadPicture (request.Current.LocalPath, Path.ChangeExtension (prettyname, "jpg"), item.Description); sent_bytes += file_info.Length; } if (Core.Database != null && item is Photo) Index: extensions/Exporters/GalleryExport/GalleryRemote.cs =================================================================== --- extensions/Exporters/GalleryExport/GalleryRemote.cs (Revision 4702) +++ extensions/Exporters/GalleryExport/GalleryRemote.cs (Arbeitskopie) @@ -7,6 +7,7 @@ using System.Web; using Mono.Unix; using FSpot; +using FSpot.Utils; using FSpot.UI.Dialog; /* These classes are based off the documentation at @@ -85,6 +86,11 @@ public void Add (FSpot.IBrowsableItem item) { + /* Bug #569460 */ + // error CS0200: Property or indexer `FSpot.IBrowsableItem.Name' cannot be assigned to (it is read only) + // How to set Name? + // item.Name = UriUtils.UnescapeString (item.Name); + Add (item, item.DefaultVersionUri.LocalPath); } Index: extensions/Exporters/GalleryExport/GalleryExport.cs =================================================================== --- extensions/Exporters/GalleryExport/GalleryExport.cs (Revision 4702) +++ extensions/Exporters/GalleryExport/GalleryExport.cs (Arbeitskopie) @@ -773,10 +773,13 @@ while (photo_index < items.Length) { IBrowsableItem item = items [photo_index]; + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (item.Name); System.Console.WriteLine ("uploading {0}", photo_index); - progress_dialog.Message = System.String.Format (Catalog.GetString ("Uploading picture \"{0}\""), item.Name); + /* Bug #569460 */ + progress_dialog.Message = System.String.Format (Catalog.GetString ("Uploading picture \"{0}\""), prettyname); progress_dialog.Fraction = photo_index / (double) items.Length; photo_index++; Index: extensions/Exporters/ZipExport/ZipExport.cs =================================================================== --- extensions/Exporters/ZipExport/ZipExport.cs (Revision 4702) +++ extensions/Exporters/ZipExport/ZipExport.cs (Arbeitskopie) @@ -24,6 +24,7 @@ using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.GZip; +using FSpot.Utils; namespace ZipExport { public class Zip : IExporter { @@ -104,7 +105,9 @@ //Pack up for (int i = 0; i < photos.Length; i ++) { - if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), photos[i].Name))) { + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (photos [i].Name); + if (progress_dialog.Update (String.Format (Catalog.GetString ("Preparing photo \"{0}\""), prettyname))) { progress_dialog.Destroy (); return; } @@ -123,7 +126,8 @@ byte [] buffer = new byte [fs.Length]; fs.Read (buffer, 0, buffer.Length); - ZipEntry entry = new ZipEntry (photos [i].Name); + /* Bug #569460 */ + ZipEntry entry = new ZipEntry (prettyname); entry.DateTime = DateTime.Now; Index: extensions/Exporters/SmugMugExport/SmugMugExport.cs =================================================================== --- extensions/Exporters/SmugMugExport/SmugMugExport.cs (Revision 4702) +++ extensions/Exporters/SmugMugExport/SmugMugExport.cs (Arbeitskopie) @@ -558,12 +558,15 @@ while (photo_index < items.Length) { try { IBrowsableItem item = items[photo_index]; + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (item.Name); FileInfo file_info; Console.WriteLine ("uploading {0}", photo_index); + /* Bug #569460 */ progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), - item.Name, photo_index+1, items.Length); + prettyname, photo_index+1, items.Length); progress_dialog.ProgressText = string.Empty; progress_dialog.Fraction = ((photo_index) / (double) items.Length); photo_index++; Index: extensions/Exporters/CDExport/CDExport.cs =================================================================== --- extensions/Exporters/CDExport/CDExport.cs (Revision 4702) +++ extensions/Exporters/CDExport/CDExport.cs (Arbeitskopie) @@ -200,6 +200,8 @@ //FIXME need to implement the uniquename as a filter using (FilterRequest request = new FilterRequest (photo.DefaultVersionUri)) { + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (photo.Name); if (rotate) new OrientationFilter ().Convert (request); @@ -210,14 +212,17 @@ Gnome.Vfs.Uri target = dest.Clone (); #endif #if GIO_2_16 - GLib.File target = UniqueName (dest, photo.Name); + /* Bug #569460 */ + GLib.File target = UniqueName (dest, prettyname); FileProgressCallback cb = Progress; #else - target = UniqueName (target, photo.Name); + /* Bug #569460 */ + target = UniqueName (target, prettyname); Gnome.Vfs.XferProgressCallback cb = new Gnome.Vfs.XferProgressCallback (Progress); #endif - progress_dialog.Message = System.String.Format (Catalog.GetString ("Transferring picture \"{0}\" To CD"), photo.Name); + /* Bug #569460 */ + progress_dialog.Message = System.String.Format (Catalog.GetString ("Transferring picture \"{0}\" To CD"), prettyname); progress_dialog.Fraction = photo_index / (double) selection.Count; progress_dialog.ProgressText = System.String.Format (Catalog.GetString ("{0} of {1}"), photo_index, selection.Count); Index: extensions/Exporters/FacebookExport/FacebookExport.cs =================================================================== --- extensions/Exporters/FacebookExport/FacebookExport.cs (Revision 4702) +++ extensions/Exporters/FacebookExport/FacebookExport.cs (Arbeitskopie) @@ -521,11 +521,14 @@ for (int i = 0; i < items.Length; i++) { try { IBrowsableItem item = items [i]; + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (item.Name); FileInfo file_info; Console.WriteLine ("uploading {0}", i); - progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length); + /* Bug #569460 */ + progress_dialog.Message = String.Format (Catalog.GetString ("Uploading picture \"{0}\" ({1} of {2})"), prettyname, i + 1, items.Length); progress_dialog.ProgressText = string.Empty; progress_dialog.Fraction = i / (double) items.Length; Index: extensions/Exporters/FlickrExport/FlickrExport.cs =================================================================== --- extensions/Exporters/FlickrExport/FlickrExport.cs (Revision 4702) +++ extensions/Exporters/FlickrExport/FlickrExport.cs (Arbeitskopie) @@ -340,8 +340,10 @@ for (int index = 0; index < photos.Length; index++) { try { IBrowsableItem photo = photos [index]; + /* Bug #569460 */ + string prettyname = UriUtils.UnescapeString (photo.Name); progress_dialog.Message = System.String.Format ( - Catalog.GetString ("Uploading picture \"{0}\""), photo.Name); + Catalog.GetString ("Uploading picture \"{0}\""), prettyname); progress_dialog.Fraction = photo_index / (double)selection.Count; photo_index++; Index: extensions/Exporters/FlickrExport/FlickrRemote.cs =================================================================== --- extensions/Exporters/FlickrExport/FlickrRemote.cs (Revision 4702) +++ extensions/Exporters/FlickrExport/FlickrRemote.cs (Arbeitskopie) @@ -177,8 +177,9 @@ tags = taglist.ToString (); } try { + /* Bug #569460 */ string photoid = - flickr.UploadPicture (path, photo.Name, photo.Description, tags, is_public, is_family, is_friend); + flickr.UploadPicture (path, UriUtils.UnescapeString (photo.Name), photo.Description, tags, is_public, is_family, is_friend); return photoid; } catch (FlickrNet.FlickrException ex) { Console.WriteLine ("Problems uploading picture: " + ex.ToString());
_______________________________________________ F-spot-list mailing list F-spot-list@gnome.org http://mail.gnome.org/mailman/listinfo/f-spot-list