~psgenfan/do-plugins/TomboyInsertText

« back to all changes in this revision

Viewing changes to Tomboy/src/TomboyDBus.cs

  • Committer: Marcus
  • Date: 2010-03-27 17:53:23 UTC
  • Revision ID: marcus@marcus-desktop-20100327175323-zryvim7tt6384n3n
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
                        string[] ListAllNotes ();
43
43
                        void DisplaySearchWithText (string search_text);
44
44
                        string Version ();
 
45
                        string GetNoteContents (string uri);
 
46
                        string GetNoteContentsXml (string uri);
 
47
                        bool SetNoteContentsXml (string uri, string xml);
45
48
                        bool SetNoteContents (string uri, string text_contents);
46
49
                        event DBusNoteAddedHandler NoteAdded;
47
50
                        event DBusNoteRemovedHandler NoteRemoved;
52
55
 
53
56
        class TomboyDBus        
54
57
        {
 
58
                string[] dateformats = {
 
59
                        "yyyy/MM/dd HH:mm",
 
60
                        "yyyy/MM/dd hh:mm tt",
 
61
                        "yyyy/MM/dd",
 
62
                        "MM/dd/yyyy HH:mm",
 
63
                        "MM/dd/yyyy hh:mm tt",
 
64
                        "MM/dd/yyyy",
 
65
                        "MM/dd HH:mm",
 
66
                        "MM/dd hh:mm tt",
 
67
                        "MM/dd",
 
68
                        "HH:mm",
 
69
                        "hh:mm tt"};
 
70
                
55
71
#region Constants
56
72
 
57
73
                private const string OBJECT_PATH = "/org/gnome/Tomboy/RemoteControl";
203
219
                                        i++;
204
220
                                }
205
221
                        }
 
222
                        
206
223
 
207
224
                        note_title = TomboyInstance.GetNoteTitle (uri);
208
225
                        TomboyInstance.DisplayNote (uri);
211
228
                                TomboyInstance.SetNoteContents (uri, note_title + "\n\n" + note_content);
212
229
                        return uri;
213
230
                }
214
 
 
 
231
                
 
232
                public string GetNoteText(string note_title){
 
233
                        EnsureTomboyInstance();
 
234
                        string uri = TomboyInstance.FindNote(note_title);
 
235
                        try{
 
236
                                return TomboyInstance.GetNoteContents(uri);
 
237
                        } catch (Exception) {
 
238
                                Console.Error.WriteLine ("Could not open the note: {0}", note_title);
 
239
                                return "";
 
240
                        }
 
241
                }
 
242
                public void AppendNote(string note_title, string text){
 
243
                        EnsureTomboyInstance();
 
244
                        string uri = TomboyInstance.FindNote(note_title);
 
245
                        string note;
 
246
                        try{
 
247
                                note = TomboyInstance.GetNoteContentsXml(uri);
 
248
                        } catch (Exception) {
 
249
                                Console.Error.WriteLine ("Could not open the note: {0}", note_title);
 
250
                                return;
 
251
                        }
 
252
                        if(TomboyConfiguration.DateInsertion)
 
253
                        {
 
254
                                text = "<bold>"+System.DateTime.Now.ToString(dateformats[TomboyConfiguration.DateFormat])+"</bold> " + text;
 
255
                        }
 
256
                        if(TomboyConfiguration.PrependInsertion)
 
257
                        {
 
258
                                while(note.Substring(note.IndexOfAny("\n".ToCharArray())+2).StartsWith("\n")) //This Works Somehow
 
259
                                        note = note.Remove(note.IndexOfAny("\n".ToCharArray())+2, 2); //Removies Trailing Line Breaks
 
260
                                note = note.Insert(note.IndexOfAny("\n".ToCharArray())+2, text+"\n\n"); //First Line is note's title so after first break
 
261
                        }       
 
262
                        else
 
263
                        {
 
264
                                while(note.Substring(note.LastIndexOf("<")-2).StartsWith("\n")) 
 
265
                                        note = note.Remove(note.LastIndexOf("<")-2, 2); //This is Magic, Make it Better
 
266
                                note = note.Insert(note.LastIndexOf("<"), "\n\n"+text); //insert before last end tag 
 
267
                        }
 
268
                        Console.Error.WriteLine ("Sending Note: {0}", note);
 
269
                        if(!TomboyInstance.SetNoteContentsXml(uri,note))
 
270
                                Console.Error.WriteLine("Could not append note: {0}", note_title);
 
271
                        
 
272
                }
215
273
                /// <summary>
216
274
                /// Open the Tomboy search window with the search string entered
217
275
                /// </summary>