4 // Copyright (C) 2004 Novell, Inc.
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.
28 using System
.Collections
;
29 using System
.Diagnostics
;
34 namespace Beagle
.Tile
{
36 public class SimpleRootTile
: Tile
{
37 private TileHitCollection hit_collection
= new TileHitCollection ();
39 bool offerDaemonRestart
;
43 hit_collection
.Clear ();
47 public TileHitCollection HitCollection
{
48 get { return hit_collection; }
51 public bool OfferDaemonRestart
{
52 get { return offerDaemonRestart; }
53 set { offerDaemonRestart = value; }
58 hit_collection
.Clear ();
61 public void Add (ICollection hits
)
63 foreach (Hit hit
in hits
)
67 public void Add (Hit hit
)
69 HitFlavor flavor
= HitToHitFlavor
.Get (hit
);
73 object[] args
= new object [1];
75 Tile tile
= (Tile
) Activator
.CreateInstance (flavor
.TileType
, args
);
78 tile
.Query
= this.Query
;
80 if (hit_collection
.Add (hit
, tile
))
83 //Console.WriteLine ("+ {0}", hit.Uri);
86 public void Subtract (ICollection uris
)
88 foreach (Uri uri
in uris
)
92 public void Subtract (Uri uri
)
96 if (hit_collection
.Subtract (uri
))
100 Console
.WriteLine ("- {0}", uri
);
105 public void Error (string errorString
)
107 this.errorString
= errorString
;
111 public void StartDaemon ()
113 // If we're running uninstalled (in the source tree), then run
114 // the uninstalled daemon. Otherwise run the installed daemon.
116 string bestpath
= System
.Environment
.GetCommandLineArgs () [0];
117 string bestdir
= System
.IO
.Path
.GetDirectoryName (bestpath
);
119 string beagled_filename
;
120 if (bestdir
.EndsWith ("lib/beagle") || bestdir
.EndsWith ("lib64/beagle")) {
121 Console
.WriteLine ("Running installed daemon...");
122 beagled_filename
= "beagled"; // Running installed
124 Console
.WriteLine ("Running uninstalled daemon...");
125 beagled_filename
= System
.IO
.Path
.Combine (bestdir
, "../beagled/beagled");
129 Process daemon
= new Process ();
130 daemon
.StartInfo
.FileName
= beagled_filename
;
131 daemon
.StartInfo
.UseShellExecute
= false;
135 } catch (System
.ComponentModel
.Win32Exception e
) {
136 Console
.WriteLine ("Unable to start daemon: {0}", e
.Message
);
140 public void SetSource (string querySource
)
142 hit_collection
.SetSource (querySource
);
146 override public void Render (TileRenderContext ctx
)
148 if (errorString
!= null) {
149 ctx
.Write (errorString
);
150 if (offerDaemonRestart
) {
151 ctx
.Write ("<hr noshade>");
152 ctx
.Link ("Click to start the Beagle daemon...", new TileActionHandler (StartDaemon
));
153 offerDaemonRestart
= false;
159 if (hit_collection
!= null)
160 ctx
.Tile (hit_collection
);