~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/Addins/NoteOfTheDay/NoteOfTheDayApplicationAddin.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 10:26:35 UTC
  • mfrom: (1.1.21 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20070716102635-0wzk26jo50csob7b
Tags: 0.7.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections;
 
4
using System.Runtime.InteropServices;
 
5
 
 
6
using Gtk;
 
7
 
 
8
using Tomboy;
 
9
 
 
10
namespace Tomboy.NoteOfTheDay
 
11
{
 
12
        public class NoteOfTheDayApplicationAddin : ApplicationAddin
 
13
        {
 
14
                bool initialized = false;
 
15
                bool timeout_owner;
 
16
                static InterruptableTimeout timeout;
 
17
                NoteManager manager;
 
18
 
 
19
                // Called only by instance with timeout_owner set.
 
20
                void CheckNewDay (object sender, EventArgs args)
 
21
                {
 
22
                        Note notd = NoteOfTheDay.GetNoteByDate (manager, DateTime.Today);
 
23
                        if (notd == null) {
 
24
                                NoteOfTheDay.CleanupOld (manager);
 
25
                                
 
26
                                // Create a new NotD if the day has changed
 
27
                                NoteOfTheDay.Create (manager, DateTime.Now);
 
28
                        }
 
29
 
 
30
                        // Re-run every minute
 
31
                        timeout.Reset (1000 * 60);
 
32
                }
 
33
 
 
34
                public override void Initialize ()
 
35
                {
 
36
                        if (timeout == null) {
 
37
                                timeout = new InterruptableTimeout ();
 
38
                                timeout.Timeout += CheckNewDay;
 
39
                                timeout.Reset (0);
 
40
                                timeout_owner = true;
 
41
                        }
 
42
                        manager = Tomboy.DefaultNoteManager;
 
43
                        initialized = true;
 
44
                }
 
45
 
 
46
                public override void Shutdown ()
 
47
                {
 
48
                        if (timeout_owner) {
 
49
                                NoteOfTheDay.CleanupOld (manager);
 
50
                                timeout.Timeout -= CheckNewDay;
 
51
                                timeout.Cancel();
 
52
                                timeout = null;
 
53
                        }
 
54
                        
 
55
                        initialized = false;
 
56
                }
 
57
                
 
58
                public override bool Initialized
 
59
                {
 
60
                        get { return initialized; }
 
61
                }
 
62
        }
 
63
}