4 // Copyright (C) 2004 Christopher Orr
5 // Copyright (C) 2004 Novell, Inc.
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
32 namespace Beagle
.Util
{
34 public abstract class Note
{
37 private string filename
;
38 public string subject
;
40 public DateTime timestamp
;
42 //////////////////////////
44 protected Note (string _type
, string _filename
) {
46 this.filename
= _filename
;
49 // FIXME: this is a mess
52 return BuildNoteUri (filename
, type
);
56 public static Uri
BuildNoteUri (string _filename
, string _type
)
58 string name
= Path
.GetFileNameWithoutExtension (_filename
);
59 string uri
= String
.Format ("note://{0}/{1}", _type
, name
);
60 return new Uri (uri
, true);
64 ///////////////////////////////////////////////////////////////////////////////
70 public class TomboyNote
: Note
{
72 private TomboyNote (string type
, string filename
) : base ("tomboy", filename
)
75 private TomboyNote (string filename
) : base ("tomboy", filename
)
78 public static Note
ParseNote (FileInfo file
)
80 // Tomboy uses .note files.
81 // Don't index the backup folder.
82 if (file
.Extension
!= ".note"
83 || file
.DirectoryName
.EndsWith ("/Backup")) {
87 // Create new note instance
88 Note note
= new TomboyNote(file
.FullName
);
89 note
.timestamp
= file
.LastWriteTime
;
91 // Parse XML info from file
92 StreamReader reader
= new StreamReader (file
.FullName
, System
.Text
.Encoding
.UTF8
);
93 XmlTextReader doc
= new XmlTextReader (reader
);
94 doc
.Namespaces
= false;
97 if (doc
.NodeType
!= XmlNodeType
.Element
)
102 note
.subject
= doc
.ReadString ();
105 // FIXME: don't discard XML style info
106 note
.text
= StripTags (doc
.ReadInnerXml ());
115 private static string StripTags (string line
)
119 i
= line
.IndexOf ('<');
122 j
= line
.IndexOf ('>', i
);
123 line
= line
.Substring (0, i
) + line
.Substring (j
+1);