Use trac icon for trac bugs to diff from bugzilla
[tomboy-trac.git] / src / TracLink.cs
blobaa0aecd42ad4632b6fedbeeb4266d17ae85e9b8f
1 using System;
2 using Tomboy;
4 namespace Tomboy.Trac
6 public class TracLink : DynamicNoteTag
8 private const string UriAttributeName = "uri";
9 private const string StockIconFilename = "stock_bug.png";
11 public override void Initialize (string element_name)
13 base.Initialize (element_name);
15 Underline = Pango.Underline.Single;
16 Foreground = "blue";
17 CanActivate = true;
18 CanGrow = true;
19 CanSpellCheck = false;
20 CanSplit = false;
23 public string BugUrl
25 get {
26 return (string) Attributes [UriAttributeName];
28 set {
29 Attributes [UriAttributeName] = value;
30 SetImage ();
34 private void SetImage()
36 System.Uri uri = null;
37 try {
38 uri = new System.Uri(BugUrl);
39 } catch {}
41 if (uri == null) {
42 Image = new Gdk.Pixbuf(null, StockIconFilename);
43 return;
46 string host = uri.Host;
47 // TODO: Get this in a safer way
48 string imageDir = "~/.tomboy/TracIcons/";
49 string imagePath = imageDir.Replace ("~", Environment.GetEnvironmentVariable ("HOME")) + host + ".png";
51 try {
52 Image = new Gdk.Pixbuf (imagePath);
53 } catch (GLib.GException) {
54 Image = new Gdk.Pixbuf(null, StockIconFilename);
58 protected override bool OnActivate (NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end)
60 if (BugUrl != string.Empty) {
61 Logger.Log ("Opening url '{0}'...", BugUrl);
62 Gnome.Url.Show (BugUrl);
64 return true;
67 protected override void OnAttributeRead (string attributeName)
69 base.OnAttributeRead (attributeName);
71 if (attributeName == UriAttributeName)
72 SetImage ();