Change the GC.GetTotalMemory() threshold to 10%; otherwise there are just too many...
[beagle.git] / search / Tiles / IMLog.cs
blob1ac0995c37a99339c8ddee1ffd00fa9e74c81172
1 using System;
2 using System.Diagnostics;
3 using System.Collections;
4 using Mono.Unix;
5 using Beagle.Util;
7 namespace Search.Tiles {
9 public class IMLogActivator : TileActivator {
11 public IMLogActivator () : base ()
13 AddSupportedFlavor (new HitFlavor (null, "IMLog", null));
16 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
18 return new IMLog (hit, query);
22 public class IMLog : TileFlat {
24 private static Hashtable all_icons = new Hashtable ();
26 public IMLog (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
28 Group = TileGroup.Conversations;
30 Subject.LabelProp = Catalog.GetString ("IM Conversation");
32 string alias = hit.GetFirstProperty ("fixme:speakingto_alias");
33 string name = hit.GetFirstProperty ("fixme:speakingto");
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)";
42 try {
43 Timestamp = Utils.ParseTimestamp (hit.GetFirstProperty ("fixme:starttime"));
44 Date.LabelProp = Utils.NiceShortDate (Timestamp);
45 } catch {}
50 private Hashtable IconsForSize (int size)
52 Hashtable icons = new Hashtable ();
54 icons ["aim"] = WidgetFu.LoadThemeIcon ("im-aim", size);
55 icons ["icq"] = WidgetFu.LoadThemeIcon ("im-icq", size);
56 icons ["jabber"] = WidgetFu.LoadThemeIcon ("im-jabber", size);
57 icons ["msn"] = WidgetFu.LoadThemeIcon ("im-msn", size);
58 icons ["novell"] = WidgetFu.LoadThemeIcon ("im-nov", size);
59 icons ["yahoo"] = WidgetFu.LoadThemeIcon ("im-yahoo", size);
61 return icons;
64 protected override void LoadIcon (Gtk.Image image, int size)
66 Hashtable icons = (Hashtable)all_icons[size];
67 if (icons == null)
68 all_icons[size] = icons = IconsForSize (size);
70 string protocol = Hit.GetFirstProperty ("fixme:protocol");
71 if (icons [protocol] != null)
72 image.Pixbuf = (Gdk.Pixbuf)icons [protocol];
73 else
74 image.Pixbuf = WidgetFu.LoadThemeIcon ("im", size);
77 private Gdk.Pixbuf LoadBuddyIcon ()
79 Gdk.Pixbuf icon = null;
81 if (Hit ["fixme:speakingto_icon"] != null && System.IO.File.Exists (Hit ["fixme:speakingto_icon"]))
82 icon = new Gdk.Pixbuf (Hit ["fixme:speakingto_icon"]);
84 return icon;
87 protected override DetailsPane GetDetails ()
89 DetailsPane details = new DetailsPane ();
91 details.Icon.Pixbuf = LoadBuddyIcon ();
92 details.AddLabelPair (Catalog.GetString ("Name:"), FromLabel.Text);
93 details.AddLabelPair (Catalog.GetString ("Date Received:"), Utils.NiceLongDate (Timestamp));
94 #if ENABLE_GALAGO
95 string status = GetBuddyStatus();
96 if (status != null && status != "")
97 details.AddLabelPair (Catalog.GetString ("Status:"), GetBuddyStatus());
98 #endif
99 details.AddSnippet ();
101 GotSnippet += SetSubject;
103 return details;
105 #if ENABLE_GALAGO
106 private string GetBuddyStatus ()
109 GalagoTools.Status stat = Beagle.Util.GalagoTools.GetPresence (Hit.GetFirstProperty ("fixme:protocol"), Hit.GetFirstProperty ("fixme:speakingto"));
110 string str = null;
111 if (stat == GalagoTools.Status.Idle){
112 str = String.Format ("{0} for {1}" , Catalog.GetString ("Idle"),
113 Beagle.Util.GalagoTools.GetIdleTime (Hit.GetFirstProperty ("fixme:protocol"),
114 Hit.GetFirstProperty ("fixme:speakingto")));
116 else {
117 switch (stat) {
118 case GalagoTools.Status.Away :
119 str = Catalog.GetString ("Away");
120 break;
121 case GalagoTools.Status.Offline :
122 str = Catalog.GetString ("Offline");
123 break;
124 case GalagoTools.Status.Available:
125 str = Catalog.GetString ("Available");
126 break;
127 case GalagoTools.Status.NoStatus:
128 str = null;
129 break;
132 return str;
134 #endif
135 private void SetSubject (string snippet)
137 Subject.Markup = snippet;
140 public override void Open ()
142 SafeProcess p = new SafeProcess ();
143 p.Arguments = new string [] { "beagle-imlogviewer",
144 "--client", Hit ["fixme:client"],
145 "--highlight-search", Query.QuotedText,
146 Hit.Uri.LocalPath };
148 try {
149 p.Start ();
150 } catch (Exception e) {
151 Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);