~ubuntu-branches/debian/jessie/f-spot/jessie

« back to all changes in this revision

Viewing changes to extensions/Tools/LiveWebGallery/PhotoRequestHandler.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-08-11 22:17:42 UTC
  • mfrom: (2.4.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100811221742-2qv3a5uya7gfe1t1
* New upstream release 0.7.2 "Retooled"
  + Third release of the unstable 0.7 development series. Features a
    fully restructured source tree with full Monodevelop build
    support. Solves some of the regressions introduced in 0.7.1.
  + Reorganized source tree for clarity, builds with Monodevelop.
  + Switched from QueuedSqliteDatabase to HyenaSqliteConnection (Mike
    Gemünde)
  + Build tweaks (Christian Krause)
  + More GtkBuilder transition (Eric Faehnrich) 
  + Reliability improvements (lots of them) for metadata handling (Mike
    Gemünde, Ruben Vermeersch)
  + Prune empty directories when deleting photos, import usability
    enhancements (Mike Wallick)
  + Big race-condition fix in import (Paul Wellner Bou)
  + Loads of improvements to Taglib#, in terms of handling broken files,
    extra format support (Pentax, Panasonic, Leica), stability and
    correctness (Ruben Vermeersch)
    - Runs out of memory Importing photo with suspect EXIF data
      (LP: #272822)
    - Metadata parsing of broken file causes large memory allocation
      (LP: #597720)
    - Photo import: cancel & copy have same keyboard shortcut (LP: #244423)
    - Facebook export will not create new album (LP: #563495)
    - Allow export to iPod (LP: #518344)
  + Reporting of import errors.
  + Speedups to repeated imports of the same directory.
  + Piles of cleanups and general stability improvements.
  + Over 50 bugs closed (http://bit.ly/cqpC3y)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * LiveWebGalleryExtension.PhotoRequestHandler.cs
3
 
 *
4
 
 * Author(s):
5
 
 *      Anton Keks  <anton@azib.net>
6
 
 *
7
 
 * This is free software. See COPYING for details
8
 
 */
9
 
 
10
 
using System;
11
 
using System.IO;
12
 
using System.Text;
13
 
 
14
 
using FSpot;
15
 
using FSpot.Filters;
16
 
using FSpot.Utils;
17
 
using Hyena;
18
 
 
19
 
namespace LiveWebGalleryExtension
20
 
{       
21
 
        public class PhotoRequestHandler : RequestHandler
22
 
        {       
23
 
                private LiveWebGalleryStats stats;
24
 
                
25
 
                public PhotoRequestHandler (LiveWebGalleryStats stats)
26
 
                {
27
 
                        this.stats = stats;
28
 
                }
29
 
                
30
 
                public override void Handle (string requested, Stream stream)
31
 
                {
32
 
                        uint photo_id = uint.Parse (requested);
33
 
                        Photo photo = App.Instance.Database.Photos.Get (photo_id);
34
 
                        
35
 
                        SendImage (photo, stream);
36
 
                                        }
37
 
                
38
 
                protected virtual void SendImage (Photo photo, Stream stream) 
39
 
                {
40
 
                        string path = photo.DefaultVersion.Uri.LocalPath;
41
 
                        FileInfo file_info = new FileInfo(path);
42
 
                        if (!file_info.Exists) {
43
 
                                SendError (stream, "404 The file is not on the disk");
44
 
                                return;
45
 
                        }
46
 
 
47
 
                        FilterSet filters = new FilterSet ();
48
 
                        filters.Add (new JpegFilter ());
49
 
                        filters.Add (new ResizeFilter (1600));
50
 
 
51
 
                        using (FilterRequest request = new FilterRequest (photo.DefaultVersion.Uri)) {
52
 
                                filters.Convert (request);
53
 
                                file_info = new FileInfo (request.Current.LocalPath);
54
 
                                SendFile (file_info, photo, stream);
55
 
                        }
56
 
 
57
 
                        if (stats != null)
58
 
                                stats.PhotoViews++;
59
 
                }
60
 
                
61
 
                protected void SendFile (FileInfo file, Photo photo, Stream dest)
62
 
                {
63
 
                        stats.BytesSent += (int)file.Length;                    
64
 
                        Log.DebugFormat ("Sending {0}, {1} kb", file.FullName, file.Length / 1024);
65
 
                        SendHeadersAndStartContent(dest, "Content-Type: " + MimeTypeForExt (file.Extension),
66
 
                                                                                         "Content-Length: " + file.Length,
67
 
                                                                 "Last-Modified: " + photo.Time.ToString ("r"));
68
 
                        using (Stream src = file.OpenRead ()) {
69
 
                                byte[] buf = new byte[10240];
70
 
                                int read;
71
 
                                while((read = src.Read(buf, 0, buf.Length)) != 0) {
72
 
                                        dest.Write (buf, 0, read);
73
 
                                }
74
 
                        }
75
 
                }
76
 
        }
77
 
        
78
 
        public class ThumbnailRequestHandler : PhotoRequestHandler
79
 
        {       
80
 
                public ThumbnailRequestHandler (LiveWebGalleryStats stats) 
81
 
                        : base (stats) {}
82
 
                
83
 
                protected override void SendImage (Photo photo, Stream dest) 
84
 
                {
85
 
                        Gdk.Pixbuf thumb = XdgThumbnailSpec.LoadThumbnail (photo.DefaultVersion.Uri, ThumbnailSize.Large);
86
 
                        byte[] buf = thumb.SaveToBuffer ("png");
87
 
                        SendHeadersAndStartContent(dest, "Content-Type: " + MimeTypeForExt (".png"),
88
 
                                                                                         "Content-Length: " + buf.Length,
89
 
                                                                 "Last-Modified: " + photo.Time.ToString ("r"));
90
 
                        dest.Write (buf, 0, buf.Length);
91
 
                }
92
 
        }
93
 
}