| Trees | Indices | Help |
|
|---|
|
|
1 import dbus
2 import dbus.glib
3 import logging
4 import string
5 log = logging.getLogger("modules.Tomboy")
6
7 import conduit
8 import conduit.TypeConverter as TypeConverter
9 import conduit.dataproviders.DataProvider as DataProvider
10 import conduit.dataproviders.AutoSync as AutoSync
11 import conduit.Exceptions as Exceptions
12 import conduit.datatypes.Note as Note
13 import conduit.datatypes.File as File
14 import conduit.utils as Utils
15
16 MODULES = {
17 "TomboyNoteTwoWay" : { "type": "dataprovider" },
18 "TomboyNoteConverter" : { "type": "converter" }
19 }
20
40
42 NOTE_EXTENSION = ".xml"
43 ILLEGAL_TITLE_CHARS = " /"
45 self.conversions = {
46 "note,note/tomboy" : self.note_to_tomboy_note,
47 "note/tomboy,file" : self.tomboy_note_to_file,
48 "file,note/tomboy" : self.file_to_tomboy_note,
49 }
50
52 n = TomboyNote(
53 title=note.get_title(),
54 contents=note.get_contents(),
55 xml=None
56 )
57 return n
58
60 content = note.get_xml()
61 #Old tomboy made this note, fallback to plain text
62 if content == None:
63 content = note.get_contents()
64
65 #replace the following characters in the note
66 #title with an underscore
67 filename = note.get_title().translate(
68 string.maketrans(
69 self.ILLEGAL_TITLE_CHARS,
70 "_"*len(self.ILLEGAL_TITLE_CHARS)
71 )
72 )
73 f = File.TempFile(content)
74 f.force_new_filename(filename)
75 f.force_new_file_extension(self.NOTE_EXTENSION)
76 return f
77
79 title,ext = f.get_filename_and_extension()
80 text = f.get_contents_as_text()
81 #A tomboy formatted XML file
82 if text.startswith('<?xml version="1.0" encoding="utf-8"?>') and text.find('xmlns="http://beatniksoftware.com/tomboy">') > 0:
83 note = TomboyNote(
84 title=Utils.xml_extract_value_from_tag("title", text),
85 contents=None,
86 xml=text
87 )
88 #A bog standard text file
89 else:
90 note = TomboyNote(
91 title=title,
92 contents=text,
93 xml=None
94 )
95 return note
96
98 """
99 LUID is the tomboy uid string
100 """
101 _name_ = "Tomboy Notes"
102 _description_ = "Sync your Tomboy notes"
103 _category_ = conduit.dataproviders.CATEGORY_NOTES
104 _module_type_ = "twoway"
105 _in_type_ = "note/tomboy"
106 _out_type_ = "note/tomboy"
107