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

« back to all changes in this revision

Viewing changes to Tomboy/Addins/Bugzilla/BugzillaLink.cs

Tags: upstream-0.7.2
Import upstream version 0.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using Tomboy;
 
3
 
 
4
namespace Tomboy.Bugzilla
 
5
{
 
6
        public class BugzillaLink : DynamicNoteTag
 
7
        {
 
8
                Gdk.Pixbuf Icon;
 
9
 
 
10
                public BugzillaLink ()
 
11
                        : base ()
 
12
                {
 
13
                }
 
14
 
 
15
                public override void Initialize (string element_name)
 
16
                {
 
17
                        base.Initialize (element_name);
 
18
 
 
19
                        Underline = Pango.Underline.Single;
 
20
                        Foreground = "blue";
 
21
                        CanActivate = true;
 
22
                        CanGrow = true;
 
23
                        CanSpellCheck = false;
 
24
                        CanSplit = false;
 
25
                }
 
26
 
 
27
                public string BugUrl
 
28
                {
 
29
                        get { return (string) Attributes ["uri"]; }
 
30
                        set { Attributes ["uri"] = value; }
 
31
                }
 
32
 
 
33
                protected override bool OnActivate (NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end)
 
34
                {
 
35
                        if (BugUrl != string.Empty) {
 
36
                                Logger.Log ("Opening url '{0}'...", BugUrl);
 
37
                                Gnome.Url.Show (BugUrl);
 
38
                        }
 
39
                        return true;
 
40
                }
 
41
 
 
42
                public override Gdk.Pixbuf Image
 
43
                {
 
44
                        get
 
45
                        {
 
46
                                if (Icon != null)
 
47
                                        return Icon;
 
48
 
 
49
                                System.Uri uri = new System.Uri(BugUrl);
 
50
                                if (uri == null)
 
51
                                        return null;
 
52
 
 
53
                                string host = uri.Host;
 
54
                                string imageDir = "~/.tomboy/BugzillaIcons/";
 
55
 
 
56
                                string imagePath = imageDir.Replace ("~", Environment.GetEnvironmentVariable ("HOME")) + host + ".png";
 
57
 
 
58
                                try {
 
59
                                        Icon = new Gdk.Pixbuf (imagePath);
 
60
                                } catch (GLib.GException) {
 
61
                                        Icon = new Gdk.Pixbuf(null, "stock_bug.png");
 
62
                                }
 
63
 
 
64
                                return Icon;
 
65
                        }
 
66
                }
 
67
        }
 
68
}