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_H__
24 #define __LIBBALSA_ADDRESS_H__
25 
26 #include <gtk/gtk.h>
27 #include <gmime/gmime.h>
28 
29 #define LIBBALSA_TYPE_ADDRESS				(libbalsa_address_get_type())
30 #define LIBBALSA_ADDRESS(obj)				(G_TYPE_CHECK_INSTANCE_CAST (obj, LIBBALSA_TYPE_ADDRESS, LibBalsaAddress))
31 #define LIBBALSA_ADDRESS_CLASS(klass)			(G_TYPE_CHECK_CLASS_CAST (klass, LIBBALSA_TYPE_ADDRESS, LibBalsaAddressClass))
32 #define LIBBALSA_IS_ADDRESS(obj)			(G_TYPE_CHECK_INSTANCE_TYPE (obj, LIBBALSA_TYPE_ADDRESS))
33 #define LIBBALSA_IS_ADDRESS_CLASS(klass)		(G_TYPE_CHECK_CLASS_TYPE (klass, LIBBALSA_TYPE_ADDRESS))
34 
35 typedef struct _LibBalsaAddress LibBalsaAddress;
36 typedef struct _LibBalsaAddressClass LibBalsaAddressClass;
37 
38 typedef enum _LibBalsaAddressField LibBalsaAddressField;
39 
40 enum _LibBalsaAddressField {
41     FULL_NAME,
42     FIRST_NAME,
43     LAST_NAME,
44     NICK_NAME,
45     ORGANIZATION,
46     EMAIL_ADDRESS,
47     NUM_FIELDS
48 };
49 
50 /* General address structure to be used with address books.
51 */
52 struct _LibBalsaAddress {
53     GObject parent;
54 
55     /*
56      * ID
57      * VCard FN: Field
58      * LDAP/LDIF: xmozillanickname
59      */
60     gchar *nick_name;
61 
62     /* First and last names
63      * VCard: parsed from N: field
64      * LDAP/LDIF: cn, givenName, surName.
65      */
66     gchar *full_name;
67     gchar *first_name;
68     gchar *last_name;
69 
70     /* Organisation
71      * VCard: ORG: field
72      * ldif: o: attribute.
73      */
74     gchar *organization;
75 
76     /* Email addresses
77      * A list of mailboxes, ie. user@domain.
78      */
79     GList *address_list;
80 };
81 
82 struct _LibBalsaAddressClass {
83     GObjectClass parent_class;
84 };
85 
86 GType libbalsa_address_get_type(void);
87 
88 LibBalsaAddress *libbalsa_address_new(void);
89 LibBalsaAddress *libbalsa_address_new_from_vcard(const gchar *str,
90 						 const gchar *charset);
91 gchar * libbalsa_address_extract_name(const gchar * string,
92                                       gchar ** last_name,
93                                       gchar ** first_name);
94 
95 void libbalsa_address_set_copy(LibBalsaAddress *dest, LibBalsaAddress *src);
96 gchar *libbalsa_address_to_gchar(LibBalsaAddress * address, gint n);
97 
98 const gchar *libbalsa_address_get_name_from_list(InternetAddressList
99                                                  * address_list);
100 const gchar *libbalsa_address_get_mailbox_from_list(InternetAddressList *
101                                                     address_list);
102 gint libbalsa_address_n_mailboxes_in_list(InternetAddressList *
103                                           address_list);
104 
105 /* =================================================================== */
106 /*                                UI PART                              */
107 /* =================================================================== */
108 
109 /** libbalsa_address_set_edit_entries() initializes the GtkEntry widgets
110     in entries with values from address
111 */
112 void libbalsa_address_set_edit_entries(const LibBalsaAddress * address,
113                                        GtkWidget ** entries);
114 /** libbalsa_address_get_edit_widget() returns an widget adapted for a
115     LibBalsaAddress edition, with initial values set if address is
116     provided. The edit entries are set in entries array and enumerated
117     with LibBalsaAddressField constants. The widget accepts drops of
118     type TARGET_ADDRESS and TARGET_STRING.
119 */
120 
121 enum {
122     LIBBALSA_ADDRESS_TRG_STRING,
123     LIBBALSA_ADDRESS_TRG_ADDRESS
124 };
125 
126 extern GtkTargetEntry libbalsa_address_target_list[2];
127 
128 GtkWidget *libbalsa_address_get_edit_widget(const LibBalsaAddress *addr,
129                                             GtkWidget **entries,
130                                             GCallback changed_cb,
131                                             gpointer changed_data);
132 LibBalsaAddress *libbalsa_address_new_from_edit_entries(GtkWidget **widget);
133 #endif				/* __LIBBALSA_ADDRESS_H__ */
134