1 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */ 2 /* Balsa E-Mail Client 3 * 4 * Copyright (C) 1997-2013 Stuart Parmenter and others, 5 * See the file AUTHORS for a list. 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, or (at your option) 10 * 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 20 * 02111-1307, USA. 21 */ 22 23 #ifndef __LIBBALSA_ADDRESS_BOOK_H__ 24 #define __LIBBALSA_ADDRESS_BOOK_H__ 25 26 #include "address.h" 27 28 #define LIBBALSA_TYPE_ADDRESS_BOOK (libbalsa_address_book_get_type()) 29 #define LIBBALSA_ADDRESS_BOOK(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, LIBBALSA_TYPE_ADDRESS_BOOK, LibBalsaAddressBook)) 30 #define LIBBALSA_ADDRESS_BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, LIBBALSA_TYPE_ADDRESS_BOOK, LibBalsaAddressBookClass)) 31 #define LIBBALSA_IS_ADDRESS_BOOK(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, LIBBALSA_TYPE_ADDRESS_BOOK)) 32 #define LIBBALSA_IS_ADDRESS_BOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, LIBBALSA_TYPE_ADDRESS_BOOK)) 33 #define LIBBALSA_ADDRESS_BOOK_GET_CLASS(obj) \ 34 (G_TYPE_INSTANCE_GET_CLASS ((obj), LIBBALSA_TYPE_ADDRESS_BOOK, \ 35 LibBalsaAddressBookClass)) 36 37 typedef enum { 38 LBABERR_OK = 0, 39 LBABERR_CANNOT_READ, 40 LBABERR_CANNOT_WRITE, 41 LBABERR_CANNOT_CONNECT, 42 LBABERR_CANNOT_SEARCH, 43 LBABERR_DUPLICATE, 44 LBABERR_ADDRESS_NOT_FOUND 45 } LibBalsaABErr; 46 47 typedef struct _LibBalsaAddressBook LibBalsaAddressBook; 48 typedef struct _LibBalsaAddressBookClass LibBalsaAddressBookClass; 49 50 typedef LibBalsaABErr (*LibBalsaAddressBookLoadFunc)(LibBalsaAddressBook *ab, 51 LibBalsaAddress *address, 52 gpointer closure); 53 54 struct _LibBalsaAddressBook { 55 GObject parent; 56 57 /* The gnome_config prefix where we save this address book */ 58 gchar *config_prefix; 59 gchar *name; 60 gchar *ext_op_code; /* extra description for last operation */ 61 gboolean is_expensive; /* is lookup to the address book expensive? 62 e.g. LDAP address book */ 63 gboolean expand_aliases; 64 65 gboolean dist_list_mode; 66 }; 67 68 struct _LibBalsaAddressBookClass { 69 GObjectClass parent; 70 71 LibBalsaABErr (*load) (LibBalsaAddressBook * ab, 72 const gchar *filter, 73 LibBalsaAddressBookLoadFunc callback, 74 gpointer closure); 75 76 /* adds given address to the address book, updating the permanent 77 * storage. */ 78 LibBalsaABErr (*add_address) (LibBalsaAddressBook * ab, 79 LibBalsaAddress * address); 80 81 /* remove given address to the address book, updating the permanent 82 * storage. */ 83 LibBalsaABErr (*remove_address) (LibBalsaAddressBook * ab, 84 LibBalsaAddress * address); 85 86 /* Sets new entries for given address, copying fields from newval. 87 * Updates the permanent storage. */ 88 LibBalsaABErr (*modify_address) (LibBalsaAddressBook * ab, 89 LibBalsaAddress * address, 90 LibBalsaAddress * newval); 91 92 void (*save_config) (LibBalsaAddressBook * ab, const gchar * prefix); 93 void (*load_config) (LibBalsaAddressBook * ab, const gchar * prefix); 94 95 GList* (*alias_complete) (LibBalsaAddressBook * ab, const gchar *prefix); 96 }; 97 98 GType libbalsa_address_book_get_type(void); 99 100 LibBalsaAddressBook *libbalsa_address_book_new_from_config(const gchar * 101 prefix); 102 103 /* 104 This will call the callback function once for each address in the 105 address book. The recipient should make sure to ref the address if 106 they will be keeping a reference to it around. The callback may 107 occur asynchronously. 108 109 After all addresses are loaded the callback will be called with 110 address==NULL. 111 */ 112 LibBalsaABErr libbalsa_address_book_load(LibBalsaAddressBook * ab, 113 const char *filter, 114 LibBalsaAddressBookLoadFunc callback, 115 gpointer closure); 116 117 LibBalsaABErr libbalsa_address_book_add_address(LibBalsaAddressBook *ab, 118 LibBalsaAddress *address); 119 LibBalsaABErr libbalsa_address_book_remove_address(LibBalsaAddressBook *ab, 120 LibBalsaAddress *address); 121 LibBalsaABErr libbalsa_address_book_modify_address(LibBalsaAddressBook *ab, 122 LibBalsaAddress *address, 123 LibBalsaAddress *newval); 124 125 /* set_status takes over the string ownership */ 126 void libbalsa_address_book_set_status(LibBalsaAddressBook * ab, gchar *str); 127 void libbalsa_address_book_save_config(LibBalsaAddressBook * ab, 128 const gchar * prefix); 129 void libbalsa_address_book_load_config(LibBalsaAddressBook * ab, 130 const gchar * prefix); 131 132 const gchar* libbalsa_address_book_strerror(LibBalsaAddressBook * ab, 133 LibBalsaABErr err); 134 135 /* 136 137 Returns a list of LibBalsaAddress objects. The caller is responsible 138 for unref()ing these address objects when it is finished with them 139 and for freeing the list. 140 141 */ 142 GList *libbalsa_address_book_alias_complete(LibBalsaAddressBook * ab, 143 const gchar *prefix); 144 gboolean libbalsa_address_is_dist_list(const LibBalsaAddressBook *ab, 145 const LibBalsaAddress *address); 146 147 #endif 148 149