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

« back to all changes in this revision

Viewing changes to search/Beagle.Search.Tiles/IMLog.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 System.Diagnostics;
 
3
using System.Collections;
 
4
using Mono.Unix;
 
5
using Beagle.Util;
 
6
 
 
7
namespace Beagle.Search.Tiles {
 
8
 
 
9
        public class IMLogActivator : TileActivator {
 
10
 
 
11
                public IMLogActivator () : base ()
 
12
                {
 
13
                        AddSupportedFlavor (new HitFlavor (null, "IMLog", null));
 
14
                }
 
15
 
 
16
                public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
 
17
                {
 
18
                        return new IMLog (hit, query);
 
19
                }
 
20
        }
 
21
 
 
22
        public class IMLog : TileFlat {
 
23
 
 
24
                private static Hashtable all_icons = new Hashtable ();
 
25
 
 
26
                public IMLog (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
 
27
                {
 
28
                        Group = TileGroup.Conversations;
 
29
 
 
30
                        Subject.LabelProp = Catalog.GetString ("IM Conversation");
 
31
 
 
32
                        string alias = hit.GetFirstProperty ("fixme:speakingto_alias");
 
33
                        string name = hit.GetFirstProperty ("fixme:speakingto");
 
34
 
 
35
                        if (alias != null && alias != "")
 
36
                                From.LabelProp = "<b>" + alias + "</b>";
 
37
                        else if (name != null && name != "")
 
38
                                From.LabelProp = "<b>" + name + "</b>";
 
39
                        else
 
40
                                From.LabelProp = "(unknown)";
 
41
 
 
42
                        try {
 
43
                                string starttime = hit.GetFirstProperty ("fixme:starttime");
 
44
                                
 
45
                                if (!String.IsNullOrEmpty (starttime))
 
46
                                    Timestamp = StringFu.StringToDateTime (starttime);
 
47
                                    
 
48
                                Date.LabelProp = Utils.NiceShortDate (Timestamp);
 
49
                        } catch {}
 
50
                }
 
51
 
 
52
                private Hashtable IconsForSize (int size)
 
53
                {
 
54
                        Hashtable icons = new Hashtable ();
 
55
 
 
56
                        icons ["aim"] = WidgetFu.LoadThemeIcon ("im-aim", size);
 
57
                        icons ["icq"] = WidgetFu.LoadThemeIcon ("im-icq", size);
 
58
                        icons ["jabber"] = WidgetFu.LoadThemeIcon ("im-jabber", size);
 
59
                        icons ["msn"] = WidgetFu.LoadThemeIcon ("im-msn", size);
 
60
                        icons ["novell"] = WidgetFu.LoadThemeIcon ("im-nov", size);
 
61
                        icons ["yahoo"] = WidgetFu.LoadThemeIcon ("im-yahoo", size);
 
62
 
 
63
                        return icons;
 
64
                }
 
65
 
 
66
                protected override void LoadIcon (Gtk.Image image, int size)
 
67
                {
 
68
                        Hashtable icons = (Hashtable)all_icons[size];
 
69
                        if (icons == null)
 
70
                                all_icons[size] = icons = IconsForSize (size);
 
71
 
 
72
                        string protocol = Hit.GetFirstProperty ("fixme:protocol");
 
73
                        if(protocol == null)
 
74
                                protocol = String.Empty;
 
75
                        
 
76
                        if (icons [protocol] != null)
 
77
                                image.Pixbuf = (Gdk.Pixbuf)icons [protocol];
 
78
                        else
 
79
                                image.Pixbuf = WidgetFu.LoadThemeIcon ("im", size);
 
80
                }
 
81
 
 
82
                private Gdk.Pixbuf LoadBuddyIcon ()
 
83
                {
 
84
                        Gdk.Pixbuf icon = null;
 
85
                        try {
 
86
                        if (Hit ["fixme:speakingto_icon"] != null && System.IO.File.Exists (Hit ["fixme:speakingto_icon"]))
 
87
                                icon = new Gdk.Pixbuf (Hit ["fixme:speakingto_icon"]);
 
88
                        } catch (Exception e){
 
89
                                Console.WriteLine(e);
 
90
                        }
 
91
                        return icon;                            
 
92
                }
 
93
 
 
94
                protected override DetailsPane GetDetails ()
 
95
                {
 
96
                        DetailsPane details = new DetailsPane ();
 
97
 
 
98
                        details.Icon.Pixbuf = LoadBuddyIcon ();                 
 
99
                        details.AddLabelPair (Catalog.GetString ("Name:"), FromLabel.Text);
 
100
                        details.AddLabelPair (Catalog.GetString ("Date Received:"), Utils.NiceLongDate (Timestamp));
 
101
#if ENABLE_GALAGO
 
102
                        string status = GetBuddyStatus();
 
103
                        if (status != null && status != "")
 
104
                                details.AddLabelPair (Catalog.GetString ("Status:"), GetBuddyStatus());
 
105
#endif          
 
106
                        details.AddSnippet ();
 
107
                        
 
108
                        GotSnippet += SetSubject;
 
109
 
 
110
                        return details;
 
111
                }
 
112
#if ENABLE_GALAGO               
 
113
                private string GetBuddyStatus ()
 
114
                {
 
115
                        
 
116
                        GalagoTools.Status stat = Beagle.Util.GalagoTools.GetPresence (Hit.GetFirstProperty ("fixme:protocol"), Hit.GetFirstProperty ("fixme:speakingto"));
 
117
                        string str = null;
 
118
                        if (stat == GalagoTools.Status.Idle){
 
119
                                str = String.Format ("{0} for {1}" , Catalog.GetString ("Idle"),
 
120
                                        Beagle.Util.GalagoTools.GetIdleTime (Hit.GetFirstProperty ("fixme:protocol"), 
 
121
                                        Hit.GetFirstProperty ("fixme:speakingto"))); 
 
122
                        }
 
123
                        else {
 
124
                                switch (stat) {
 
125
                                        case GalagoTools.Status.Away : 
 
126
                                                str = Catalog.GetString ("Away");
 
127
                                                break;
 
128
                                        case GalagoTools.Status.Offline :
 
129
                                                str = Catalog.GetString ("Offline");
 
130
                                                break;
 
131
                                        case GalagoTools.Status.Available:
 
132
                                                str = Catalog.GetString ("Available");
 
133
                                                break;
 
134
                                        case GalagoTools.Status.NoStatus:
 
135
                                                str = null;
 
136
                                                break;
 
137
                                }
 
138
                        }
 
139
                        return str;
 
140
                }
 
141
#endif
 
142
                private void SetSubject (string snippet)
 
143
                {
 
144
                        Subject.Markup = snippet;
 
145
                }
 
146
 
 
147
                public override void Open ()
 
148
                {
 
149
                        SafeProcess p = new SafeProcess ();
 
150
 
 
151
                        string log_path = Hit.Uri.LocalPath;
 
152
 
 
153
                        if (Hit.Source == "Konversation")
 
154
                                log_path = Hit.ParentUri.LocalPath;
 
155
 
 
156
                        p.Arguments = new string [] { "beagle-imlogviewer",
 
157
                                                      "--client", Hit ["fixme:client"],
 
158
                                                      "--highlight-search", Query.QuotedText,
 
159
                                                      log_path };
 
160
 
 
161
                        try {
 
162
                                p.Start ();
 
163
                        } catch (Exception e) {
 
164
                                Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);
 
165
                        }
 
166
                }
 
167
        }
 
168
}