~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to search/Beagle.Search.Tiles/Contact.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using Mono.Unix;
 
3
using Beagle.Util;
 
4
 
 
5
namespace Beagle.Search.Tiles {
 
6
 
 
7
        public class ContactActivator : TileActivator {
 
8
 
 
9
                public ContactActivator () : base ()
 
10
                {
 
11
                        AddSupportedFlavor (new HitFlavor (null, "Contact", null));
 
12
                }
 
13
 
 
14
                public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
 
15
                {
 
16
                        return new Contact (hit, query);
 
17
                }
 
18
        }
 
19
 
 
20
        public class Contact : TileTemplate {
 
21
 
 
22
                public Contact (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
 
23
                {
 
24
                        Group = TileGroup.Contact;
 
25
 
 
26
                        Title = hit.GetFirstProperty ("fixme:Name");
 
27
                        Description = hit.GetFirstProperty ("fixme:Email");
 
28
 
 
29
                        if (Hit.GetFirstProperty ("fixme:Email") != null)
 
30
                                AddAction (new TileAction (Catalog.GetString ("Send Mail"), SendMail));
 
31
                }
 
32
 
 
33
                private Gdk.Pixbuf GetIcon (int size)
 
34
                {
 
35
                        if (Hit.GetFirstProperty ("beagle:Photo") != null) {
 
36
                                Gdk.Pixbuf icon = new Gdk.Pixbuf (Hit.GetFirstProperty ("beagle:Photo"));
 
37
                                return icon.ScaleSimple (size, size, Gdk.InterpType.Bilinear);
 
38
                        } else
 
39
                                return WidgetFu.LoadThemeIcon ("stock_person", size);
 
40
                }
 
41
 
 
42
                protected override void LoadIcon (Gtk.Image image, int size)
 
43
                {
 
44
                        image.Pixbuf = GetIcon (size);
 
45
                }
 
46
 
 
47
                protected override DetailsPane GetDetails ()
 
48
                {
 
49
                        DetailsPane details = new DetailsPane ();
 
50
                                
 
51
                        details.AddTitleLabel (Title);
 
52
                        
 
53
                        string org = Hit.GetFirstProperty ("fixme:Org");
 
54
                        string title = Hit.GetFirstProperty ("fixme:Title");
 
55
                        string email = Hit.GetFirstProperty ("fixme:Email");
 
56
                        string mobile_phone = Hit.GetFirstProperty ("fixme:MobilePhone");
 
57
                        string work_phone = Hit.GetFirstProperty ("fixme:BusinessPhone");
 
58
                        string home_phone = Hit.GetFirstProperty ("fixme:HomePhone");
 
59
                        
 
60
                        if (org != null && org != "")
 
61
                                details.AddTextLabel (org);
 
62
                        if (title != null && title != "")
 
63
                                details.AddTextLabel (title);
 
64
 
 
65
                        details.AddNewLine ();
 
66
 
 
67
                        if (email != null && email != "")
 
68
                                details.AddLabelPair (Catalog.GetString ("E-Mail:"), email);
 
69
                        if (mobile_phone != null && mobile_phone != "")
 
70
                                details.AddLabelPair (Catalog.GetString ("Mobile Phone:"), mobile_phone);
 
71
                        if (work_phone != null && work_phone != "")
 
72
                                details.AddLabelPair (Catalog.GetString ("Work Phone:"), work_phone);
 
73
                        if (home_phone != null && home_phone != "")
 
74
                                details.AddLabelPair (Catalog.GetString ("Home Phone:"), home_phone);
 
75
                        
 
76
                        return details;
 
77
                }
 
78
 
 
79
                public static SafeProcess GetClientProcess (string client, string uri)
 
80
                {
 
81
                        SafeProcess p = null;
 
82
 
 
83
                        if (client == "evolution" || (client == null && uri.StartsWith ("contacts:"))) {
 
84
                                p = new SafeProcess ();
 
85
                                p.Arguments = new string [2];
 
86
                                p.Arguments [0] = "evolution";
 
87
                                p.Arguments [1] = uri;
 
88
                        } else if (client == "thunderbird") {
 
89
                                p = new SafeProcess ();
 
90
                                p.Arguments = new string [4];
 
91
                                p.Arguments [0] = "beagle-contactviewer";
 
92
                                p.Arguments [1] = "--manager";
 
93
                                p.Arguments [2] = "Thunderbird";
 
94
                                p.Arguments [3] = uri;
 
95
                        }
 
96
 
 
97
                        return p;
 
98
                }
 
99
 
 
100
 
 
101
                public override void Open ()
 
102
                {
 
103
                        SafeProcess p = GetClientProcess (Hit.GetFirstProperty ("fixme:client"), Hit.EscapedUri);
 
104
 
 
105
                        if (p == null) {
 
106
                                Console.WriteLine ("Opening contact '{0}' is unsupported!", Hit.EscapedUri);
 
107
                                return;
 
108
                        }
 
109
                        
 
110
                        try {
 
111
                                p.Start ();
 
112
                        } catch (SafeProcessException e) {
 
113
                                Console.WriteLine (e.Message);
 
114
                        }
 
115
                }
 
116
 
 
117
                private void SendMail ()
 
118
                {
 
119
                        OpenFromUri ("mailto:" + Hit.GetFirstProperty ("fixme:Email"));
 
120
                }
 
121
        }
 
122
}