[tomboy-list] Watching Plugin for Tomboy

José Sánchez Moreno jose at oxigenow.com
Fri Jan 12 07:29:08 PST 2007


Now the plugin works. Detect new files, deleted files and files
changed. 

I can use unison to sync my notes.
Thanks for reply my question.

using System;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using Mono.Unix;

using Tomboy;

public class InotifyPlugin : NotePlugin
{	
	static FileSystemWatcher dir_watcher = null;	
	const string GCONF_ENABLED_KEY = "/apps/tomboy/inotify/enable_inotify";

	protected override void Initialize ()
	{
		// Inotify code. Monitor changes in .notes files
		if(dir_watcher == null) {
			try {
				Logger.Log("Watching " + Path.GetDirectoryName(Note.FilePath));
				dir_watcher = new FileSystemWatcher
(Path.GetDirectoryName(Note.FilePath), "*.note");
				dir_watcher.Changed += OnChangedNote;
				dir_watcher.Deleted += OnDeletedNote;
				dir_watcher.Created += OnCreatedNote;
				dir_watcher.EnableRaisingEvents = true;
			} catch (ArgumentException e) { 
				Console.WriteLine ("Error creating a FileSystemWatcher {0}", e);
			}
		}
			
	}

	void OnCreatedNote(object sender, FileSystemEventArgs args)
	{		
		NoteArchiver archiver =  NoteArchiver.Instance;
		NoteData data =  archiver.ReadFile(args.FullPath,  "note://tomboy/" +
Path.GetFileNameWithoutExtension (args.FullPath));
		Note new_note = Note.Load (args.FullPath, Note.Manager);				
		Note.Manager.Notes.Add(new_note);	
	}
	
	void OnDeletedNote(object sender, FileSystemEventArgs args)
	{
		foreach (Note note in Note.Manager.Notes) {
			if(args.FullPath == note.FilePath) {							
				Note.Manager.Notes.Remove(note);
				note.Delete();
			}
		}					
	}
	
	void OnChangedNote (object sender, FileSystemEventArgs args)
	{		
		foreach (Note note in Note.Manager.Notes) {
			if(args.FullPath == note.FilePath) {
				NoteArchiver archiver =  NoteArchiver.Instance;
				NoteData modified =  archiver.ReadFile(args.FullPath,
"note://tomboy/" + Path.GetFileNameWithoutExtension
(args.FullPath));				
				note.XmlContent = modified.Text;
				note.Title = modified.Title;
			}
		}
	}
	
	protected override void Shutdown ()
	{				
		//Preferences.SettingChanged -= OnSettingChanged;	
	}

	protected override void OnNoteOpened () 
	{
		// Do nothing.
	}
}
-- 
José Sánchez Moreno <jose at oxigenow.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.beatniksoftware.com/pipermail/tomboy-list-beatniksoftware.com/attachments/20070112/9b7b1ad1/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Inotify.cs
Type: text/x-csharp
Size: 2037 bytes
Desc: not available
Url : http://lists.beatniksoftware.com/pipermail/tomboy-list-beatniksoftware.com/attachments/20070112/9b7b1ad1/attachment.bin 


More information about the tomboy-list mailing list