Merging from head
[beagle.git] / beagled / EvolutionDataServerQueryable / EvolutionDataServerQueryable.cs
blob333327b34853344621f266f1baa7d29cc8ac55bf
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;
49 private bool initial_crawl = false;
51 // Index versions
52 // 1: Original version
53 // 2: Updated URI scheme for Evolution 2.4/EDS 1.4
54 private const int INDEX_VERSION = 2;
56 public EvolutionDataServerQueryable () : base ("EvolutionDataServerIndex", INDEX_VERSION)
58 photo_dir = Path.Combine (Driver.TopDirectory, "Photos");
59 System.IO.Directory.CreateDirectory (photo_dir);
62 public string PhotoDir {
63 get { return photo_dir; }
66 public override void Start ()
68 base.Start ();
70 // Defer the actual startup till main_loop starts.
71 // EDS requires StartWorker to run in mainloop,
72 // hence it is not started in a separate thread.
73 GLib.Idle.Add (new GLib.IdleHandler (delegate () { StartWorker (); return false; }));
76 private void StartWorker ()
78 Logger.Log.Info ("Scanning addressbooks and calendars");
79 Stopwatch timer = new Stopwatch ();
80 timer.Start ();
82 initial_crawl = true;
84 bool success = false;
86 // This is the first code which tries to open the
87 // evolution-data-server APIs. Try to catch
88 // DllNotFoundException and bail out if things go
89 // badly.
90 try {
91 new SourcesHandler ("/apps/evolution/addressbook/sources", typeof (BookContainer), this, Driver.Fingerprint);
92 new SourcesHandler ("/apps/evolution/calendar/sources", typeof (CalContainer), this, Driver.Fingerprint);
93 success = true;
94 } catch (DllNotFoundException ex) {
95 Logger.Log.Error (ex, "Unable to start EvolutionDataServer backend: Unable to find or open libraries:");
96 } finally {
97 initial_crawl = false;
98 timer.Stop ();
101 if (success)
102 Logger.Log.Info ("Scanned addressbooks and calendars in {0}", timer);
105 override protected bool IsIndexing {
106 get { return initial_crawl; }
109 public void AddIndexable (Indexable indexable, Scheduler.Priority priority)
111 Scheduler.Task task;
112 task = NewAddTask (indexable);
113 task.Priority = priority;
114 ThisScheduler.Add (task);
117 public void RemoveIndexable (Uri uri)
119 Scheduler.Task task;
120 task = NewRemoveTask (uri);
121 task.Priority = Scheduler.Priority.Immediate;
122 ThisScheduler.Add (task);
125 public void RemovePropertyIndexable (Property prop)
127 Scheduler.Task task;
128 task = NewRemoveByPropertyTask (prop);
129 task.Priority = Scheduler.Priority.Immediate;
130 ThisScheduler.Add (task);