1 /**
2  * @file node_type.h  node type interface
3  *
4  * Copyright (C) 2007-2012 Lars Windolf <lars.windolf@gmx.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 #ifndef _NODE_TYPE_H
22 #define _NODE_TYPE_H
23 
24 #include "node.h"
25 
26 #include <libxml/xmlmemory.h>
27 #include <gtk/gtk.h>
28 
29 /** node type capabilities */
30 enum {
31 	NODE_CAPABILITY_SHOW_ITEM_FAVICONS	= (1<<0),	/**< display favicons in item list (useful for recursively viewed leaf node) */
32 	NODE_CAPABILITY_ADD_CHILDS		= (1<<1),	/**< allows adding new childs */
33 	NODE_CAPABILITY_REMOVE_CHILDS		= (1<<2),	/**< allows removing it's childs */
34 	NODE_CAPABILITY_SUBFOLDERS		= (1<<3),	/**< allows creating/removing sub folders */
35 	NODE_CAPABILITY_REMOVE_ITEMS		= (1<<5),	/**< allows removing of single items */
36 	NODE_CAPABILITY_RECEIVE_ITEMS		= (1<<6),	/**< is a DnD target for item copies */
37 	NODE_CAPABILITY_REORDER			= (1<<7),	/**< allows DnD to reorder childs */
38 	NODE_CAPABILITY_SHOW_UNREAD_COUNT	= (1<<8),	/**< display the unread item count in the feed list */
39 	NODE_CAPABILITY_SHOW_ITEM_COUNT		= (1<<9),	/**< display the absolute item count in the feed list */
40 	NODE_CAPABILITY_UPDATE			= (1<<10),	/**< node type always has a subscription and can be updated */
41 	NODE_CAPABILITY_UPDATE_CHILDS		= (1<<11),	/**< childs of this node type can be updated */
42 	NODE_CAPABILITY_UPDATE_FAVICON		= (1<<12),	/**< this node allows downloading a favicon */
43 	NODE_CAPABILITY_EXPORT			= (1<<13)	/**< nodes of this type can be exported safely to OPML */
44 };
45 
46 /**
47  * Liferea supports different types of nodes in the feed
48  * list. The type of a feed list node determines how the user
49  * can interact with it.
50  */
51 
52 /** node type interface */
53 typedef struct nodeType {
54 	gulong		capabilities;	/**< bitmask of node type capabilities */
55 	const gchar	*id;		/**< type id (used for type attribute in OPML export) */
56 	const GIcon	*icon;		/**< default icon for nodes of this type (if no favicon available) */
57 
58 	/* For method documentation see the wrappers defined below!
59 	   All methods are mandatory for each node type. */
60 	void    	(*import)		(nodePtr node, nodePtr parent, xmlNodePtr cur, gboolean trusted);
61 	void    	(*export)		(nodePtr node, xmlNodePtr cur, gboolean trusted);
62 	itemSetPtr	(*load)			(nodePtr node);
63 	void 		(*save)			(nodePtr node);
64 	void		(*update_counters)	(nodePtr node);
65 	void		(*remove)		(nodePtr node);
66 	gchar *		(*render)		(nodePtr node);
67 	gboolean	(*request_add)		(void);
68 	void		(*request_properties)	(nodePtr node);
69 
70 	/**
71 	 * Called to allow node type to clean up it's specific data.
72 	 * The node structure itself is destroyed after this call.
73 	 *
74 	 * @param node		the node
75 	 */
76 	void		(*free)			(nodePtr node);
77 } *nodeTypePtr;
78 
79 #define NODE_TYPE(node)	(node->type)
80 
81 /**
82  * Maps node type to string. For feed nodes
83  * it maps to the feed type string.
84  *
85  * @param node	the node
86  *
87  * @returns type string (or NULL if unknown)
88  */
89 const gchar *node_type_to_str (nodePtr node);
90 
91 /**
92  * Maps node type string to type constant.
93  *
94  * @param type str	the node type as string
95  *
96  * @returns node type
97  */
98 nodeTypePtr node_str_to_type (const gchar *str);
99 
100 /**
101  * Interactive node adding (e.g. feed menu->new subscription),
102  * launches some dialog that upon success adds a feed of the
103  * given type.
104  *
105  * @param nodeType		the node type
106  *
107  * @returns TRUE on success
108  */
109 gboolean node_type_request_interactive_add (nodeTypePtr nodeType);
110 
111 #endif
112