1 /*
2  * @file itemset.h  interface to handle sets of items
3  *
4  * Copyright (C) 2005-2012 Lars Windolf <lars.windolf@gmx.de>
5  * Copyright (C) 2005-2006 Nathan J. Conrad <t98502@users.sourceforge.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 
22 #ifndef _ITEMSET_H
23 #define _ITEMSET_H
24 
25 #include "item.h"
26 #include "rule.h"
27 
28 /*
29  * The itemset interface processes item list actions
30  * based on the item set type specified by the node
31  * the item set belongs to.
32  */
33 
34 typedef struct itemSet {
35 	GSList		*rules;		/*<< list of rules each item matches */
36 	gboolean	anyMatch;	/*<< TRUE means only one of the rules must match for item inclusion */
37 
38 	GList		*ids;		/*<< the list of item ids */
39 	gchar		*nodeId;	/*<< the feed list node id this item set belongs to */
40 } *itemSetPtr;
41 
42 /* item set iterating interface */
43 
44 typedef void 	(*itemActionFunc)	(itemPtr item);
45 
46 /**
47  * itemset_foreach: (skip)
48  * @itemSet:	the item set
49  * @callback:	the callback
50  *
51  * Calls the given callback for each of the items in the item set.
52  */
53 void itemset_foreach (itemSetPtr itemSet, itemActionFunc callback);
54 
55 /**
56  * itemset_merge_items: (skip)
57  * @itemSet:		the item set to merge into
58  * @items:		a list of items to merge
59  * @allowUpdates:	TRUE if older items may be replaced
60  * @markAsRead:		TRUE if all new items should be marked as read
61  *
62  * Merges the given item set into the item set of
63  * the given node. Used for node updating.
64  *
65  * Returns: the number of new merged items
66  */
67 guint itemset_merge_items(itemSetPtr itemSet, GList *items, gboolean allowUpdates, gboolean markAsRead);
68 
69 /**
70  * itemset_check_item: (skip)
71  * @itemSet:	the itemSet
72  * @item:	the item
73  *
74  * Checks if the given item matches the rules of the given item set.
75  *
76  * Returns: TRUE if the item matches the rules of the item set
77  */
78 gboolean itemset_check_item (itemSetPtr itemSet, itemPtr item);
79 
80 /**
81  * itemset_add_rule: (skip)
82  * @itemSet:	the item set
83  * @ruleId:	id string for this rule type
84  * @value:	argument string for this rule
85  * @additive:	indicates positive or negative logic
86  *
87  * Method that creates and adds a rule to an item set. To be used
88  * on loading time, when creating searches or when editing
89  * search folder properties.
90  */
91 void itemset_add_rule (itemSetPtr itemSet, const gchar *ruleId, const gchar *value, gboolean additive);
92 
93 /**
94  * itemset_free: (skip)
95  * @itemSet:	the item set to free
96  *
97  * Frees the given item set and all items it contains.
98  */
99 void itemset_free(itemSetPtr itemSet);
100 
101 #endif
102