* tools/Info.cs: Add --list-backends, --list-static-indexes to
[beagle.git] / beagled / EvolutionDataServerQueryable / EvolutionDataServerQueryable.cs
blob9630b2b1b2a59e31e4b8754ee0f9eb262dac2203
1 //
2 // EvolutionDataServerQueryable.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.
28 using System;
29 using System.Collections;
30 using System.Globalization;
31 using System.Text;
32 using System.Threading;
33 using System.IO;
35 using Beagle.Daemon;
36 using Beagle.Util;
38 using Evolution;
40 namespace Beagle.Daemon.EvolutionDataServerQueryable {
42 [QueryableFlavor (Name="EvolutionDataServer", Domain=QueryDomain.Local, RequireInotify=false)]
43 public class EvolutionDataServerQueryable : LuceneQueryable {
44 //private Scheduler.Priority priority = Scheduler.Priority.Immediate;
45 private Scheduler.Priority priority = Scheduler.Priority.Delayed;
47 private string photo_dir;
48 private DateTime start_time;
50 // Index versions
51 // 1: Original version
52 // 2: Updated URI scheme for Evolution 2.4/EDS 1.4
53 private const int INDEX_VERSION = 2;
55 public EvolutionDataServerQueryable () : base ("EvolutionDataServerIndex", INDEX_VERSION)
57 photo_dir = Path.Combine (Driver.TopDirectory, "Photos");
58 System.IO.Directory.CreateDirectory (photo_dir);
61 public string PhotoDir {
62 get { return photo_dir; }
65 public override void Start ()
67 base.Start ();
69 Logger.Log.Info ("Scanning addressbooks and calendars");
70 Stopwatch timer = new Stopwatch ();
71 timer.Start ();
73 start_time = DateTime.Now;
74 State = QueryableState.Crawling;
76 bool success = false;
78 // This is the first code which tries to open the
79 // evolution-data-server APIs. Try to catch
80 // DllNotFoundException and bail out if things go
81 // badly.
82 try {
83 new SourcesHandler ("/apps/evolution/addressbook/sources", typeof (BookContainer), this, Driver.Fingerprint);
84 new SourcesHandler ("/apps/evolution/calendar/sources", typeof (CalContainer), this, Driver.Fingerprint);
85 success = true;
86 } catch (DllNotFoundException ex) {
87 Logger.Log.Error ("Unable to start EvolutionDataServer backend: Unable to find or open {0}", ex.Message);
88 } finally {
89 State = QueryableState.Idle;
90 timer.Stop ();
93 if (success)
94 Logger.Log.Info ("Scanned addressbooks and calendars in {0}", timer);
97 public void AddIndexable (Indexable indexable, Scheduler.Priority priority)
99 Scheduler.Task task;
100 task = NewAddTask (indexable);
101 task.Priority = priority;
102 ThisScheduler.Add (task);
105 public void RemoveIndexable (Uri uri)
107 Scheduler.Task task;
108 task = NewRemoveTask (uri);
109 task.Priority = Scheduler.Priority.Immediate;
110 ThisScheduler.Add (task);
113 public void RemovePropertyIndexable (Property prop)
115 Scheduler.Task task;
116 task = NewRemoveByPropertyTask (prop);
117 task.Priority = Scheduler.Priority.Immediate;
118 ThisScheduler.Add (task);