2 // EvolutionDataServerQueryable.cs
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.
29 using System
.Collections
;
30 using System
.Globalization
;
32 using System
.Threading
;
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;
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 ()
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 ();
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
91 new SourcesHandler ("/apps/evolution/addressbook/sources", typeof (BookContainer
), this, Driver
.Fingerprint
);
92 new SourcesHandler ("/apps/evolution/calendar/sources", typeof (CalContainer
), this, Driver
.Fingerprint
);
94 } catch (DllNotFoundException ex
) {
95 Logger
.Log
.Error (ex
, "Unable to start EvolutionDataServer backend: Unable to find or open libraries:");
97 initial_crawl
= false;
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
)
112 task
= NewAddTask (indexable
);
113 task
.Priority
= priority
;
114 ThisScheduler
.Add (task
);
117 public void RemoveIndexable (Uri uri
)
120 task
= NewRemoveTask (uri
);
121 task
.Priority
= Scheduler
.Priority
.Immediate
;
122 ThisScheduler
.Add (task
);
125 public void RemovePropertyIndexable (Property prop
)
128 task
= NewRemoveByPropertyTask (prop
);
129 task
.Priority
= Scheduler
.Priority
.Immediate
;
130 ThisScheduler
.Add (task
);