1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001 Match Grun
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 /*
21  * General functions for accessing address index file.
22  */
23 
24 #ifndef __ADDRINDEX_H__
25 #define __ADDRINDEX_H__
26 
27 #include <stdio.h>
28 #include <glib.h>
29 #include "addritem.h"
30 
31 #define ADDRESSBOOK_MAX_IFACE  4
32 #define ADDRESSBOOK_INDEX_FILE "addrbook--index.xml"
33 #define ADDRESSBOOK_OLD_FILE   "addressbook.xml"
34 
35 #define ADDR_DS_AUTOREG "@Auto-registered"
36 
37 typedef enum {
38 	ADDR_IF_NONE,
39 	ADDR_IF_BOOK,
40 	ADDR_IF_VCARD,
41 	ADDR_IF_JPILOT,
42 	ADDR_IF_LDAP,
43 	ADDR_IF_COMMON,
44 	ADDR_IF_PERSONAL
45 } AddressIfType;
46 
47 typedef struct _AddressIndex AddressIndex;
48 struct _AddressIndex {
49 	AddrItemObject obj;
50 	gchar *filePath;
51 	gchar *fileName;
52 	gint  retVal;
53 	gboolean needsConversion;
54 	gboolean wasConverted;
55 	gboolean conversionError;
56 	AddressIfType lastType;
57 	gboolean dirtyFlag;
58 	GList *interfaceList;
59 };
60 
61 typedef struct _AddressInterface AddressInterface;
62 struct _AddressInterface {
63 	AddrItemObject obj;
64 	AddressIfType type;
65 	gchar *name;
66 	gchar *listTag;
67 	gchar *itemTag;
68 	gboolean legacyFlag;
69 	gboolean useInterface;
70 	gboolean haveLibrary;
71 	gboolean readOnly;
72 	GList *listSource;
73 	gboolean (*getModifyFlag)( void * );
74 	gboolean (*getAccessFlag)( void * );
75 	gboolean (*getReadFlag)( void * );
76 	gint (*getStatusCode)( void * );
77 	gint (*getReadData)( void * );
78 	ItemFolder *(*getRootFolder)( void * );
79 	GList *(*getListFolder)( void * );
80 	GList *(*getListPerson)( void * );
81 	GList *(*getAllPersons)( void * );
82 	GList *(*getAllGroups)( void * );
83 	gchar *(*getName)( void * );
84 	void (*setAccessFlag)( void *, void * );
85 };
86 
87 typedef struct _AddressDataSource AddressDataSource;
88 struct _AddressDataSource {
89 	AddrItemObject obj;
90 	AddressIfType type;
91 	AddressInterface *iface;
92 	gpointer rawDataSource;
93 };
94 
95 AddressIndex *addrindex_create_index	();
96 void addrindex_set_file_path		( AddressIndex *addrIndex, const gchar *value );
97 void addrindex_set_file_name		( AddressIndex *addrIndex, const gchar *value );
98 void addrindex_set_dirty		( AddressIndex *addrIndex, const gboolean value );
99 GList *addrindex_get_interface_list	( AddressIndex *addrIndex );
100 void addrindex_free_index		( AddressIndex *addrIndex );
101 void addrindex_print_index		( AddressIndex *addrIndex, FILE *stream );
102 
103 AddressInterface *addrindex_get_interface		( AddressIndex *addrIndex, AddressIfType ifType );
104 AddressDataSource *addrindex_index_add_datasource	( AddressIndex *addrIndex, AddressIfType ifType, gpointer dataSource );
105 AddressDataSource *addrindex_index_remove_datasource	( AddressIndex *addrIndex, AddressDataSource *dataSource );
106 void addrindex_free_datasource				( AddressIndex *addrIndex, AddressDataSource *ds );
107 
108 gint addrindex_read_data		( AddressIndex *addrIndex );
109 gint addrindex_write_to			( AddressIndex *addrIndex, const gchar *newFile );
110 gint addrindex_save_data		( AddressIndex *addrIndex );
111 gint addrindex_create_new_books		( AddressIndex *addrIndex );
112 gint addrindex_save_all_books		( AddressIndex *addrIndex );
113 gint addrindex_create_extra_books	( AddressIndex *addrIndex );
114 
115 gboolean addrindex_ds_get_modify_flag	( AddressDataSource *ds );
116 gboolean addrindex_ds_get_access_flag	( AddressDataSource *ds );
117 gboolean addrindex_ds_get_read_flag	( AddressDataSource *ds );
118 gint addrindex_ds_get_status_code	( AddressDataSource *ds );
119 gint addrindex_ds_read_data		( AddressDataSource *ds );
120 ItemFolder *addrindex_ds_get_root_folder( AddressDataSource *ds );
121 GList *addrindex_ds_get_list_folder	( AddressDataSource *ds );
122 GList *addrindex_ds_get_list_person	( AddressDataSource *ds );
123 gchar *addrindex_ds_get_name		( AddressDataSource *ds );
124 void addrindex_ds_set_access_flag	( AddressDataSource *ds, gboolean *value );
125 gboolean addrindex_ds_get_readonly	( AddressDataSource *ds );
126 GList *addrindex_ds_get_all_persons	( AddressDataSource *ds );
127 GList *addrindex_ds_get_all_groups	( AddressDataSource *ds );
128 
129 #endif /* __ADDRINDEX_H__ */
130 
131 /*
132 * End of Source.
133 */
134