Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / Tiles / SimpleRootTile.cs
blob48829568548734b9dc9b121fd4a379d653185ee1
1 //
2 // SimpleRootTile.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using System;
28 using System.Collections;
29 using System.Diagnostics;
31 using Beagle.Tile;
32 using Beagle;
34 namespace Beagle.Tile {
36 public class SimpleRootTile : Tile {
37 private TileHitCollection hit_collection = new TileHitCollection ();
38 string errorString;
39 bool offerDaemonRestart;
41 public void Start ()
43 hit_collection.Clear ();
44 Changed ();
47 public TileHitCollection HitCollection {
48 get { return hit_collection; }
51 public bool OfferDaemonRestart {
52 get { return offerDaemonRestart; }
53 set { offerDaemonRestart = value; }
56 public void Add (ICollection hits)
58 foreach (Hit hit in hits)
59 Add (hit);
62 public void Add (Hit hit)
64 HitFlavor flavor = HitToHitFlavor.Get (hit);
65 if (flavor == null)
66 return;
68 object[] args = new object [1];
69 args[0] = hit;
70 Tile tile = (Tile) Activator.CreateInstance (flavor.TileType, args);
71 tile.Hit = hit;
72 tile.Uri = hit.Uri;
73 tile.Query = this.Query;
75 if (hit_collection.Add (hit, tile))
76 Changed ();
78 //Console.WriteLine ("+ {0}", hit.Uri);
81 public void Subtract (ICollection uris)
83 foreach (Uri uri in uris)
84 Subtract (uri);
87 public void Subtract (Uri uri)
89 bool changed = false;
91 if (hit_collection.Subtract (uri))
92 changed = true;
94 if (changed) {
95 Console.WriteLine ("- {0}", uri);
96 Changed ();
100 public void Error (string errorString)
102 this.errorString = errorString;
103 Changed ();
106 public void StartDaemon ()
108 // If we're running uninstalled (in the source tree), then run
109 // the uninstalled daemon. Otherwise run the installed daemon.
111 string bestpath = System.Environment.GetCommandLineArgs () [0];
112 string bestdir = System.IO.Path.GetDirectoryName (bestpath);
114 string beagled_filename;
115 if (bestdir.EndsWith ("lib/beagle")) {
116 Console.WriteLine ("Running installed daemon...");
117 beagled_filename = "beagled"; // Running installed
118 } else {
119 Console.WriteLine ("Running uninstalled daemon...");
120 beagled_filename = System.IO.Path.Combine (bestdir, "../beagled/beagled");
124 Process daemon = new Process ();
125 daemon.StartInfo.FileName = beagled_filename;
126 daemon.StartInfo.UseShellExecute = false;
128 try {
129 daemon.Start ();
130 } catch (System.ComponentModel.Win32Exception e) {
131 Console.WriteLine ("Unable to start daemon: {0}", e.Message);
135 public void SetSource (string querySource)
137 hit_collection.SetSource (querySource);
138 Changed ();
141 override public void Render (TileRenderContext ctx)
143 if (errorString != null) {
144 ctx.Write (errorString);
145 if (offerDaemonRestart) {
146 ctx.Write ("<hr noshade>");
147 ctx.Link ("Click to start the Beagle daemon...", new TileActionHandler (StartDaemon));
148 offerDaemonRestart = false;
150 errorString = null;
151 return;
154 if (hit_collection != null)
155 ctx.Tile (hit_collection);