2006-07-31 [wwp] 2.4.0cvs3
[claws.git] / src / addrindex.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include "addrcache.h"
31 #include "addrquery.h"
32
33 #define ADDRESSBOOK_MAX_IFACE  4
34 #define ADDRESSBOOK_INDEX_FILE "addrbook--index.xml"
35 #define ADDRESSBOOK_OLD_FILE   "addressbook.xml"
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         GHashTable *hashCache;
60         gboolean loadedFlag;
61         GList *searchOrder;
62 };
63
64 typedef struct _AddressInterface AddressInterface;
65 struct _AddressInterface {
66         AddrItemObject obj;
67         AddressIfType type;
68         gchar *name;
69         gchar *listTag;
70         gchar *itemTag;
71         gboolean legacyFlag;
72         gboolean useInterface;
73         gboolean haveLibrary;
74         gboolean readOnly;
75         GList *listSource;
76         gboolean (*getModifyFlag)( void * );
77         gboolean (*getAccessFlag)( void * );
78         gboolean (*getReadFlag)( void * );
79         gint (*getStatusCode)( void * );
80         gint (*getReadData)( void * );
81         ItemFolder *(*getRootFolder)( void * );
82         GList *(*getListFolder)( void * );
83         GList *(*getListPerson)( void * );
84         GList *(*getAllPersons)( void * );
85         GList *(*getAllGroups)( void * );
86         gchar *(*getName)( void * );
87         void (*setAccessFlag)( void *, void * );
88         gboolean externalQuery;
89         gint searchOrder;
90         void (*startSearch)( void * );
91         void (*stopSearch)( void * );
92 };
93
94 typedef struct _AddressDataSource AddressDataSource;
95 struct _AddressDataSource {
96         AddrItemObject obj;
97         AddressIfType type;
98         AddressInterface *interface;
99         gpointer rawDataSource;
100 };
101
102 void addrindex_initialize               ( void );
103 void addrindex_teardown                 ( void );
104
105 AddressIndex *addrindex_create_index    ( void );
106 AddressIndex *addrindex_get_object      ( void );
107 void addrindex_set_file_path            ( AddressIndex *addrIndex,
108                                           const gchar *value );
109 void addrindex_set_file_name            ( AddressIndex *addrIndex,
110                                           const gchar *value );
111 void addrindex_set_dirty                ( AddressIndex *addrIndex,
112                                           const gboolean value );
113 gboolean addrindex_get_loaded           ( AddressIndex *addrIndex );
114
115 GList *addrindex_get_interface_list     ( AddressIndex *addrIndex );
116 void addrindex_free_index               ( AddressIndex *addrIndex );
117 void addrindex_print_index              ( AddressIndex *addrIndex, FILE *stream );
118
119 AddressInterface *addrindex_get_interface       ( AddressIndex *addrIndex,
120                                                   AddressIfType ifType );
121
122 AddressDataSource *addrindex_create_datasource  ( AddressIfType ifType );
123
124 AddressDataSource *addrindex_index_add_datasource       ( AddressIndex *addrIndex,
125                                                           AddressIfType ifType,
126                                                           gpointer dataSource );
127 AddressDataSource *addrindex_index_remove_datasource    ( AddressIndex *addrIndex,
128                                                           AddressDataSource *dataSource );
129
130 void addrindex_free_datasource          ( AddressDataSource *ds );
131 gchar *addrindex_get_cache_id           ( AddressIndex *addrIndex,
132                                           AddressDataSource *ds );
133 AddressDataSource *addrindex_get_datasource     ( AddressIndex *addrIndex,
134                                                   const gchar *cacheID );
135 AddressCache *addrindex_get_cache       ( AddressIndex *addrIndex,
136                                           const gchar *cacheID );
137
138 gint addrindex_read_data                ( AddressIndex *addrIndex );
139 gint addrindex_write_to                 ( AddressIndex *addrIndex,
140                                           const gchar *newFile );
141 gint addrindex_save_data                ( AddressIndex *addrIndex );
142 gint addrindex_create_new_books         ( AddressIndex *addrIndex );
143 gint addrindex_save_all_books           ( AddressIndex *addrIndex );
144
145 gboolean addrindex_ds_get_modify_flag   ( AddressDataSource *ds );
146 gboolean addrindex_ds_get_access_flag   ( AddressDataSource *ds );
147 gboolean addrindex_ds_get_read_flag     ( AddressDataSource *ds );
148 gint addrindex_ds_get_status_code       ( AddressDataSource *ds );
149 gint addrindex_ds_read_data             ( AddressDataSource *ds );
150 ItemFolder *addrindex_ds_get_root_folder( AddressDataSource *ds );
151 GList *addrindex_ds_get_list_folder     ( AddressDataSource *ds );
152 GList *addrindex_ds_get_list_person     ( AddressDataSource *ds );
153 gchar *addrindex_ds_get_name            ( AddressDataSource *ds );
154 void addrindex_ds_set_access_flag       ( AddressDataSource *ds,
155                                           gboolean *value );
156 gboolean addrindex_ds_get_readonly      ( AddressDataSource *ds );
157 GList *addrindex_ds_get_all_persons     ( AddressDataSource *ds );
158 GList *addrindex_ds_get_all_groups      ( AddressDataSource *ds );
159
160 /* Search support */
161 gint addrindex_setup_search             ( const gchar *searchTerm,
162                                           void *callBackEnd,
163                                           void *callBackEntry );
164
165 gint addrindex_setup_static_search      ( AddressDataSource *ds,
166                                           const gchar *searchTerm,
167                                           ItemFolder *folder,
168                                           void *callBackEnd,
169                                           void *callBackEntry );
170
171 gboolean addrindex_start_search         ( const gint queryID );
172 void addrindex_stop_search              ( const gint queryID );
173 gint addrindex_setup_explicit_search    ( AddressDataSource *ds, 
174                                           const gchar *searchTerm, 
175                                           ItemFolder *folder,
176                                           void *callBackEnd,
177                                           void *callBackEntry );
178 void addrindex_remove_results           ( AddressDataSource *ds,
179                                           ItemFolder *folder );
180
181 gboolean addrindex_load_completion(
182                 gint (*callBackFunc)
183                         ( const gchar *, const gchar *, 
184                           const gchar *, const gchar * ),
185                         gchar *folderpath );
186
187 gboolean addrindex_load_person_attribute( const gchar *attr,
188                 gint (*callBackFunc)
189                         ( ItemPerson *, const gchar * ) );
190
191 #endif /* __ADDRINDEX_H__ */
192
193 /*
194 * End of Source.
195 */