(Back)port some changes from beagle-lucene-1-9-lockfile-branch: allow ext: queries...
[beagle.git] / Filters / FilterKNotes.cs
blobd3fec6c22afa48f5209b1b8cc9c8d6251c4a363d
1 //
2 // FilterKnotes.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;
35 using HtmlAgilityPack;
37 namespace Beagle.Filters {
39 public class FilterKnotes : Beagle.Filters.FilterKCal {
41 public FilterKnotes ()
43 AddSupportedFlavor (FilterFlavor.NewFromMimeType (ICalParser.KnotesMimeType));
44 if (vCard_property_mapping == null)
45 SetupPropertyMapping ();
46 SnippetMode = true;
49 private static Hashtable vCard_property_mapping = null;
50 override protected Hashtable KCalPropertyMapping {
51 get { return vCard_property_mapping; }
54 private void SetupPropertyMapping () {
55 vCard_property_mapping = new Hashtable ();
56 // KCalProperty (name, comma_sep, keyword, text_or_date)
57 vCard_property_mapping ["SUMMARY"] = new KCalProperty ("dc:title", false, false, KCalType.Text);
58 vCard_property_mapping ["PRIORITY"] = new KCalProperty ("fixme:priority", true, false, KCalType.Text);
59 vCard_property_mapping ["DESCRIPTION"] = new KCalProperty (KCalType.Special);
60 vCard_property_mapping ["CLASS"] = new KCalProperty ("fixme:class", false, true, KCalType.Text);
61 vCard_property_mapping ["LAST-MODIFIED"] = new KCalProperty (KCalType.Special);
62 // Open KNotes notes by
63 // dcop knotes KNotesIface text <UID>
64 vCard_property_mapping ["UID"] = new KCalProperty ("fixme:uid", false, true, KCalType.Text);
65 vCard_property_mapping ["X-KDE-KNotes-RichText"] = new KCalProperty (KCalType.Special);
68 private string description = null;
69 private bool is_rich_text = false;
71 override protected void ProcessPropertySpecial (string prop_name,
72 ArrayList paramlist,
73 string prop_value)
75 //Log.Debug ("Handling special property {0}=[{1}]", prop_name, prop_value);
76 if (prop_name == "DESCRIPTION") {
77 prop_value = prop_value.Replace ("\\,", ",");
78 prop_value = prop_value.Replace ("\\\\", "\\");
79 prop_value = prop_value.Replace ("\\n", "\n");
81 description = prop_value;
82 } else if (prop_name == "X-KDE-KNotes-RichText")
83 is_rich_text = (prop_value == "true");
84 else if (prop_name == "LAST-MODIFIED") {
85 DateTime dt = ProcessKCalDate (prop_value);
86 if (dt != DateTime.MinValue)
87 Timestamp = dt;
91 override protected void DoPull ()
93 if (! is_rich_text)
94 AppendText (description);
95 else {
96 FilterHtml.AppendTextCallback append_text_cb = new FilterHtml.AppendTextCallback (AppendText);
97 FilterHtml.AddPropertyCallback add_prop_cb = new FilterHtml.AddPropertyCallback (delegate(Beagle.Property p) {});
98 FilterHtml.AppendSpaceCallback append_white_cb = new FilterHtml.AppendSpaceCallback (AppendWhiteSpace);
99 FilterHtml.AppendSpaceCallback append_break_cb = new FilterHtml.AppendSpaceCallback (AppendStructuralBreak);
100 FilterHtml.HotCallback hot_up_cb = new FilterHtml.HotCallback (HotUp);
101 FilterHtml.HotCallback hot_down_cb = new FilterHtml.HotCallback (HotDown);
103 FilterHtml html_filter = new FilterHtml ();
104 html_filter.ExtractText (description,
105 append_text_cb,
106 add_prop_cb,
107 append_white_cb,
108 append_break_cb,
109 hot_up_cb,
110 hot_down_cb);
113 Finished ();