2
using System.Collections;
6
namespace Tomboy.NoteOfTheDay
8
public class NoteOfTheDay
10
public static string TemplateTitle = Catalog.GetString ("Today: Template");
12
static string title_prefix = Catalog.GetString ("Today: ");
14
public static string GetTitle (DateTime day)
16
// Format: "Today: Friday, July 01 2005"
17
return title_prefix + day.ToString (Catalog.GetString ("dddd, MMMM d yyyy"));
20
public static string GetContent (DateTime day, NoteManager manager)
22
string title = GetTitle (day);
24
// Attempt to load content from template
25
Note templateNote = manager.Find (TemplateTitle);
26
if (templateNote != null)
27
return templateNote.XmlContent.Replace (TemplateTitle, title);
29
return GetTemplateContent (title);
32
public static string GetTemplateContent (string title)
34
const string base_xml =
36
"<note-title>{0}</note-title>\n\n\n\n" +
37
"<size:huge>{1}</size:huge>\n\n\n" +
38
"<size:huge>{2}</size:huge>\n\n\n" +
41
return string.Format (base_xml,
43
Catalog.GetString ("Tasks"),
44
Catalog.GetString ("Appointments"));
47
public static Note Create (NoteManager manager, DateTime day)
49
string title = GetTitle (day);
50
string xml = GetContent (day, manager);
54
notd = manager.Create (title, xml);
55
} catch (Exception e) {
56
// Prevent blowup if note creation fails
58
"NoteOfTheDay could not create \"{0}\": {1}",
65
// Automatically tag all new Note of the Day notes
66
Tag notd_tag = TagManager.GetOrCreateTag (
67
Catalog.GetString ("Note of the Day"));
68
notd.AddTag (notd_tag);
70
// notd.AddTag queues a save so the following is no longer necessary
77
static string GetContentWithoutTitle (string content)
79
return content.Substring (content.IndexOf ("\n"));
82
public static bool HasChanged (Note note)
84
string original_xml = GetContent(note.CreateDate, note.Manager);
85
if (GetContentWithoutTitle (note.TextContent) ==
86
GetContentWithoutTitle (XmlDecoder.Decode (original_xml))) {
92
public static void CleanupOld (NoteManager manager)
94
ArrayList kill_list = new ArrayList();
95
DateTime date_today = DateTime.Today; // time set to 00:00:00
97
foreach (Note note in manager.Notes) {
98
if (note.Title.StartsWith (title_prefix) &&
99
note.Title != TemplateTitle &&
100
note.CreateDate.Date != date_today &&
101
!HasChanged (note)) {
102
kill_list.Add (note);
106
foreach (Note note in kill_list) {
107
Logger.Log ("NoteOfTheDay: Deleting old unmodified '{0}'",
109
manager.Delete (note);
114
/// Returns the NotD note for the specified date
116
public static Note GetNoteByDate (NoteManager manager, DateTime date)
118
DateTime normalized_date = date.Date; // same date with time set to 00:00:00
119
Note found_note = null;
121
// Go through all the NotD notes and look for the one that was
122
// created on the date specified.
123
foreach (Note note in manager.Notes) {
124
if (note.Title.StartsWith (title_prefix) &&
125
note.Title != TemplateTitle) {
126
DateTime note_date = note.CreateDate.Date;
127
if (note_date == normalized_date) {