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
;
48 private DateTime start_time
;
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 ()
69 // Defer the actual startup till main_loop starts.
70 // This will improve kill beagle while starting up.
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 ();
82 start_time
= DateTime
.Now
;
83 State
= QueryableState
.Crawling
;
87 // This is the first code which tries to open the
88 // evolution-data-server APIs. Try to catch
89 // DllNotFoundException and bail out if things go
92 new SourcesHandler ("/apps/evolution/addressbook/sources", typeof (BookContainer
), this, Driver
.Fingerprint
);
93 new SourcesHandler ("/apps/evolution/calendar/sources", typeof (CalContainer
), this, Driver
.Fingerprint
);
95 } catch (DllNotFoundException ex
) {
96 Logger
.Log
.Error (ex
, "Unable to start EvolutionDataServer backend: Unable to find or open libraries:");
98 State
= QueryableState
.Idle
;
103 Logger
.Log
.Info ("Scanned addressbooks and calendars in {0}", timer
);
106 public void AddIndexable (Indexable indexable
, Scheduler
.Priority priority
)
109 task
= NewAddTask (indexable
);
110 task
.Priority
= priority
;
111 ThisScheduler
.Add (task
);
114 public void RemoveIndexable (Uri uri
)
117 task
= NewRemoveTask (uri
);
118 task
.Priority
= Scheduler
.Priority
.Immediate
;
119 ThisScheduler
.Add (task
);
122 public void RemovePropertyIndexable (Property prop
)
125 task
= NewRemoveByPropertyTask (prop
);
126 task
.Priority
= Scheduler
.Priority
.Immediate
;
127 ThisScheduler
.Add (task
);