summaryrefslogtreecommitdiff
path: root/Zeitgeist/BlacklistClient.cs
blob: 475564b32dfd16b28124b0c57fcbcfe0b0e9e58b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/******************************************************************************
 * The MIT/X11/Expat License
 * Copyright (c) 2010 Manish Sinha<mail@manishsinha.net>

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE. 
********************************************************************************/

using System;
using System.Collections.Generic;
using Zeitgeist.Datamodel;
using Zeitgeist.Client;
using DBus;

namespace Zeitgeist
{
	/// <summary>
	/// The Zeitgeist engine maintains a list of event templates that is known as the blacklist. 
	/// </summary>
	/// <remarks>
	/// When inserting events via LogClient.InsertEvents they will be checked against the blacklist templates 
	/// and if they match they will not be inserted in the log, and any matching monitors will not be signalled.
	/// </remarks>
	public class BlacklistClient
	{
		/// <summary>
		/// The constructor for BlacklistClient
		/// </summary>
		/// <remarks>
		/// This constructor gets the DBus object for BlacklistClient which the object's methods use
		/// </remarks>
		public BlacklistClient()
		{
			srcInterface = ZsUtils.GetDBusObject<IBlacklist>(objectPath);
		}
		
		/// <summary>
		/// Get the current blacklist templates.
		/// </summary>
		/// <returns>
		/// A list of <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.Event>"/> Blacklist Event templates 
		/// </returns>
		public List<Event> GetBlacklist()
		{
			RawEvent[] rawBlackLists = srcInterface.GetBlacklist();
			return ZsUtils.FromRawEventList(rawBlackLists);
		}
		
		/// <summary>
		/// Set the blacklist to event_templates. 
		/// </summary>
		/// Events matching any these templates will be blocked from insertion into the log. 
		/// It is still possible to find and look up events matching the blacklist which was inserted before the blacklist banned them.
		/// <remarks>
		/// </remarks>
		/// <param name="eventTemplates">
		/// A List of <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.Event>"/> Event templates 
		/// </param>
		public void SetBlacklist(List<Event> eventTemplates)
		{
			List<RawEvent> events = ZsUtils.ToRawEventList(eventTemplates);
			srcInterface.SetBlacklist(events.ToArray());
		}
		
		private IBlacklist srcInterface;
		
		private static string objectPath = "/org/gnome/zeitgeist/blacklist";
	}
}