4 // Copyright (C) 2004 Novell, Inc.
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.
28 using System
.Collections
;
35 namespace Beagle
.Filters
{
37 public abstract class FilterImage
: Beagle
.Daemon
.Filter
{
42 // 2: Added fspot:IsIndexed field, added width & height properties
43 // 3: Add Digikam tags and caption
47 protected virtual void PullImageProperties () { }
49 private int width
= -1;
50 private int height
= -1;
51 private int depth
= -1;
54 set { width = value; }
58 protected int Height
{
59 set { height = value; }
60 get { return height; }
64 set { depth = value; }
68 protected override void DoPullProperties ()
70 PullImageProperties ();
73 AddProperty (Beagle
.Property
.NewUnsearched ("fixme:width", width
));
76 AddProperty (Beagle
.Property
.NewUnsearched ("fixme:height", height
));
79 AddProperty (Beagle
.Property
.NewUnsearched ("fixme:depth", depth
));
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
);
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)
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
));