2006-04-25 Hendrik Brandt <heb@gnome-de.org>
[beagle.git] / Filters / FilterImage.cs
blob51e4b3fb3a9521ee5222b6c6b92af714d2e4c84f
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 public abstract class FilterImage : Beagle.Daemon.Filter {
39 public FilterImage ()
41 // 1: Base
42 // 2: Added fspot:IsIndexed field, added width & height properties
43 // 3: Add Digikam tags and caption
44 SetVersion (3);
47 protected virtual void PullImageProperties () { }
49 private int width = -1;
50 private int height = -1;
51 private int depth = -1;
53 protected int Width {
54 set { width = value; }
55 get { return width; }
58 protected int Height {
59 set { height = value; }
60 get { return height; }
63 protected int Depth {
64 set { depth = value; }
65 get { return depth; }
68 protected override void DoPullProperties ()
70 PullImageProperties ();
72 if (width > 0)
73 AddProperty (Beagle.Property.NewUnsearched ("fixme:width", width));
75 if (height > 0)
76 AddProperty (Beagle.Property.NewUnsearched ("fixme:height", height));
78 if (depth > 0)
79 AddProperty (Beagle.Property.NewUnsearched ("fixme:depth", depth));
81 try {
82 AddFSpotInformation (this.FileInfo.FullName);
83 AddDigikamInformation (this.FileInfo.FullName);
84 } catch (Exception ex) {
85 Logger.Log.Error ("Exception trying to retrieve FSpot/Digikam information:" + ex);
91 private void AddFSpotInformation (string path)
93 FSpotTools.Photo photo = FSpotTools.GetPhoto (this.FileInfo.FullName);
95 if (photo == null)
96 return;
98 AddProperty (Beagle.Property.NewBool ("fspot:IsIndexed", true));
100 if (photo.Description != null && photo.Description != "") {
101 AddProperty (Beagle.Property.New ("fspot:Description", photo.Description));
102 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", photo.Description));
105 foreach (FSpotTools.Tag tag in photo.Tags) {
106 if (tag.Name != null && tag.Name != "") {
107 AddProperty (Beagle.Property.New ("fspot:Tag", tag.Name));
108 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag.Name));
113 private void AddDigikamInformation (string path)
115 DigikamTags.DigikamData digikam_data = DigikamTags.GetDigikamData (this.FileInfo.FullName);
117 if (digikam_data == null)
118 return;
120 AddProperty (Beagle.Property.NewBool ("digikam:IsIndexed", true));
122 if (digikam_data.caption != null && digikam_data.caption != "") {
123 AddProperty (Beagle.Property.New ("digikam:caption", digikam_data.caption));
124 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", digikam_data.caption));
127 foreach (string tag in digikam_data.Tags) {
128 AddProperty (Beagle.Property.New ("digikam:Tag", tag));
129 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag));
133 internal void AddXmpProperties (XmpFile xmp)
135 Resource subject_anon = null;
136 Resource creator_anon = null;
137 Resource rights_anon = null;
139 foreach (Statement stmt in xmp.Store) {
140 if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:subject")) {
141 //Console.WriteLine ("found subject");
142 subject_anon = stmt.Object;
143 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:creator")) {
144 //Console.WriteLine ("found creator");
145 creator_anon = stmt.Object;
146 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:rights")) {
147 rights_anon = stmt.Object;
148 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:title")) {
149 AddProperty (Beagle.Property.New ("dc:title", ((Literal)stmt.Object).Value));
150 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("tiff:Model")) {
151 // NOTE: the namespaces for xmp and beagle don't always match up
152 AddProperty (Beagle.Property.New ("exif:Model", ((Literal)stmt.Object).Value));
156 foreach (Statement stmt in xmp.Store) {
157 if (stmt.Subject == subject_anon &&
158 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
159 AddProperty (Beagle.Property.New ("dc:subject", ((Literal)stmt.Object).Value));
160 } else if (stmt.Subject == creator_anon &&
161 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
162 AddProperty (Beagle.Property.New ("dc:creator", ((Literal)stmt.Object).Value));
163 } else if (stmt.Subject == rights_anon &&
164 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
165 AddProperty (Beagle.Property.New ("dc:rights", ((Literal)stmt.Object).Value));