2006-12-16 Gabor Kelemen <kelemeng@gnome.hu>
[beagle.git] / Filters / FilterImage.cs
blob23406694e809b218221721817e4397649300c967
1 //
2 // FilterImage.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using System;
28 using System.Collections;
29 using System.IO;
30 using System.Text;
32 using Beagle.Util;
33 using SemWeb;
35 namespace Beagle.Filters {
37 [PropertyKeywordMapping (Keyword="imagetag", PropertyName="image:tag", IsKeyword=false, Description="FSpot, Digikam image tags")]
38 [PropertyKeywordMapping (Keyword="comment", PropertyName="fixme:comment", IsKeyword=false, Description="User comments")]
39 public abstract class FilterImage : Beagle.Daemon.Filter {
41 public FilterImage ()
43 // 1: Base
44 // 2: Added fspot:IsIndexed field, added width & height properties
45 // 3: Add Digikam tags and caption
46 SetVersion (3);
49 protected virtual void PullImageProperties () { }
51 private int width = -1;
52 private int height = -1;
53 private int depth = -1;
55 protected int Width {
56 set { width = value; }
57 get { return width; }
60 protected int Height {
61 set { height = value; }
62 get { return height; }
65 protected int Depth {
66 set { depth = value; }
67 get { return depth; }
70 protected override void DoPullProperties ()
72 PullImageProperties ();
74 if (width > 0)
75 AddProperty (Beagle.Property.NewUnsearched ("fixme:width", width));
77 if (height > 0)
78 AddProperty (Beagle.Property.NewUnsearched ("fixme:height", height));
80 if (depth > 0)
81 AddProperty (Beagle.Property.NewUnsearched ("fixme:depth", depth));
83 try {
84 AddFSpotInformation (this.FileInfo.FullName);
85 AddDigikamInformation (this.FileInfo.FullName);
86 } catch (Exception ex) {
87 Logger.Log.Error ("Exception trying to retrieve FSpot/Digikam information:" + ex);
93 private void AddFSpotInformation (string path)
95 FSpotTools.Photo photo = FSpotTools.GetPhoto (this.FileInfo.FullName);
97 if (photo == null)
98 return;
100 AddProperty (Beagle.Property.NewBool ("fspot:IsIndexed", true));
102 AddProperty (Beagle.Property.New ("fspot:Description", photo.Description));
103 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", photo.Description));
105 foreach (FSpotTools.Tag tag in photo.Tags) {
106 AddProperty (Beagle.Property.New ("fspot:Tag", tag.Name));
107 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag.Name));
111 private void AddDigikamInformation (string path)
113 DigikamTags.DigikamData digikam_data = DigikamTags.GetDigikamData (this.FileInfo.FullName);
115 if (digikam_data == null)
116 return;
118 AddProperty (Beagle.Property.NewBool ("digikam:IsIndexed", true));
120 AddProperty (Beagle.Property.New ("digikam:caption", digikam_data.caption));
121 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", digikam_data.caption));
123 foreach (string tag in digikam_data.Tags) {
124 AddProperty (Beagle.Property.New ("digikam:Tag", tag));
125 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag));
129 internal void AddXmpProperties (XmpFile xmp)
131 Resource subject_anon = null;
132 Resource creator_anon = null;
133 Resource rights_anon = null;
135 foreach (Statement stmt in xmp.Store) {
136 if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:subject")) {
137 //Console.WriteLine ("found subject");
138 subject_anon = stmt.Object;
139 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:creator")) {
140 //Console.WriteLine ("found creator");
141 creator_anon = stmt.Object;
142 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:rights")) {
143 rights_anon = stmt.Object;
144 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:title")) {
145 AddProperty (Beagle.Property.New ("dc:title", ((Literal)stmt.Object).Value));
146 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("tiff:Model")) {
147 // NOTE: the namespaces for xmp and beagle don't always match up
148 AddProperty (Beagle.Property.New ("exif:Model", ((Literal)stmt.Object).Value));
152 foreach (Statement stmt in xmp.Store) {
153 if (stmt.Subject == subject_anon &&
154 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
155 AddProperty (Beagle.Property.New ("dc:subject", ((Literal)stmt.Object).Value));
156 } else if (stmt.Subject == creator_anon &&
157 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
158 AddProperty (Beagle.Property.New ("dc:creator", ((Literal)stmt.Object).Value));
159 } else if (stmt.Subject == rights_anon &&
160 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
161 AddProperty (Beagle.Property.New ("dc:rights", ((Literal)stmt.Object).Value));