2006-12-16 Gabor Kelemen <kelemeng@gnome.hu>
[beagle.git] / Filters / FilterKAddressBook.cs
blob0ffe83527b6f97ba5d69f9101e92edf119b64062
1 //
2 // FilterKAddressBook.cs
3 //
4 // Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
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.
28 using System;
29 using System.Collections;
30 using System.IO;
31 using System.Text;
33 using Beagle.Daemon;
34 using Beagle.Util;
36 namespace Beagle.Filters {
38 [PropertyKeywordMapping (Keyword="email", PropertyName="vCard:EMAIL", IsKeyword=false)]
39 public class FilterKAddressBook : Beagle.Filters.FilterKCal {
41 public FilterKAddressBook ()
43 // 1: Store a prefemail as well, store URL as text.
44 SetVersion (1);
45 AddSupportedFlavor (FilterFlavor.NewFromMimeType (ICalParser.KabcMimeType));
46 SnippetMode = false;
47 if (vCard_property_mapping == null)
48 SetupPropertyMapping ();
51 private static Hashtable vCard_property_mapping = null;
52 override protected Hashtable KCalPropertyMapping {
53 get { return vCard_property_mapping; }
56 private void SetupPropertyMapping () {
57 vCard_property_mapping = new Hashtable ();
58 // KCalProperty (name, comma_sep, keyword, text_or_date)
59 vCard_property_mapping ["FN"] = new KCalProperty ("vCard:FN", false, false, KCalType.Text);
60 vCard_property_mapping ["NICKNAME"] = new KCalProperty ("vCard:NICKNAME", true, false,KCalType.Text);
61 vCard_property_mapping ["BDAY"] = new KCalProperty ("vCard:BDAY", true, false, KCalType.Date);
62 vCard_property_mapping ["TITLE"] = new KCalProperty ("vCard:TITLE", false, false, KCalType.Text);
63 vCard_property_mapping ["ROLE"] = new KCalProperty ("vCard:ROLE", false, false, KCalType.Text);
64 vCard_property_mapping ["CATEGORIES"] = new KCalProperty ("vCard:CATEGORIES", false, false, KCalType.Text);
65 vCard_property_mapping ["NAME"] = new KCalProperty ("vCard:NAME", false, false, KCalType.Text);
66 vCard_property_mapping ["NOTE"] = new KCalProperty ("vCard:NOTE", false, false, KCalType.Text);
67 vCard_property_mapping ["REV"] = new KCalProperty ("dc:date", true, false, KCalType.Date);
68 vCard_property_mapping ["CLASS"] = new KCalProperty ("vCard:CLASS", false, true, KCalType.Text);
69 vCard_property_mapping ["UID"] = new KCalProperty ("vCard:UID", false, true, KCalType.Text);
70 vCard_property_mapping ["EMAIL"] = new KCalProperty ("vCard:EMAIL", false, false, KCalType.Special);
71 vCard_property_mapping ["TEL"] = new KCalProperty ("vCard:TEL", false, true, KCalType.Text);
72 vCard_property_mapping ["URL"] = new KCalProperty ("vCard:URL", false, false, KCalType.Text);
75 override protected string GetPropertyName (string prop_name, ArrayList paramlist)
77 string mapped_prop_name =
78 ((KCalProperty)vCard_property_mapping [prop_name]).property_name;
80 switch (prop_name) {
81 case "TEL":
82 foreach (KCalPropertyParameter vcpp in paramlist) {
83 if (vcpp.param_name == "TYPE") {
84 if (vcpp.param_value == "WORK")
85 return mapped_prop_name + ":WORK";
86 else if (vcpp.param_value == "HOME")
87 return mapped_prop_name + ":HOME";
88 else if (vcpp.param_value == "CELL")
89 return mapped_prop_name + ":CELL";
92 break;
95 return mapped_prop_name;
98 private string pref_email;
99 private bool pref_email_set;
101 override protected void DoPullProperties ()
103 pref_email_set = false;
104 base.DoPullProperties ();
105 AddProperty (Beagle.Property.New ("vCard:PREFEMAIL", pref_email));
108 override protected void ProcessPropertySpecial (string prop_name,
109 ArrayList paramlist,
110 string prop_value)
112 if (prop_name == "EMAIL") {
113 foreach (KCalPropertyParameter vcpp in paramlist) {
114 if (vcpp.param_name == "TYPE" &&
115 vcpp.param_value == "PREF") {
116 // Default email
117 pref_email = prop_value;
118 pref_email_set = true;
121 AddProperty (Beagle.Property.New ("vCard:EMAIL", prop_value));
122 if (! pref_email_set)
123 pref_email = prop_value;