Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / Tiles / MailAttachment.cs
blob01844cc4e71d22b119a2c786dfd59536b7d2a653
1 using System;
2 using System.Diagnostics;
3 using Mono.Unix;
4 using Beagle.Util;
6 namespace Search.Tiles {
8 public class MailAttachmentActivator : TileActivator {
10 public MailAttachmentActivator () : base ()
12 AddSupportedFlavor (new HitFlavor (null, "MailMessage", null));
15 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
17 return new MailAttachment (hit, query);
20 public override bool Validate (Beagle.Hit hit)
22 if (! base.Validate (hit))
23 return false;
25 string str = hit.GetFirstProperty ("parent:fixme:hasAttachments");
26 if (hit.ParentUri == null || str == null || str == "false")
27 return false;
29 str = hit.GetFirstProperty ("fixme:attachment_title");
30 if (str == null || str == "")
31 return false;
33 Weight += 1;
35 return true;
39 public class MailAttachment : TileTemplate {
41 public MailAttachment (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
43 Group = TileGroup.Documents;
44 Title = Hit ["fixme:attachment_title"];
45 Description = Catalog.GetString ("Mail attachment");
48 // FIXME: This needs better handling in the daemon, attachments
49 // architecture sucks
50 private static bool IsAttachment (Beagle.Hit hit)
52 // check if there is parent and parent has attachments
53 string str = hit ["parent:fixme:hasAttachments"];
54 return (hit.ParentUri != null && str != null && (str == "true"));
57 private static string GetHitProperty (Beagle.Hit hit, string name)
59 // FIXME: We should handle this case better, but
60 // for now, if we match an attachment, we just want
61 // to display the properties for the parent message.
62 if (!IsAttachment (hit))
63 return hit [name];
64 else
65 return hit ["parent:" + name];
68 public override void Open ()
70 SafeProcess p;
72 if (Hit.ParentUri != null)
73 p = MailMessage.GetClientProcess (GetHitProperty (Hit, "fixme:client"), Hit.EscapedParentUri);
74 else
75 p = MailMessage.GetClientProcess (GetHitProperty (Hit, "fixme:client"), Hit.EscapedUri);
76 if (p == null) {
77 OpenFromMime (Hit);
78 return;
81 try {
82 p.Start ();
83 } catch (SafeProcessException e) {
84 Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);