aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addressbook/ChangeLog42
-rw-r--r--addressbook/backend/ebook/e-card-simple.c79
-rw-r--r--addressbook/backend/ebook/e-card-simple.h1
-rw-r--r--addressbook/backend/ebook/e-card-types.h15
-rw-r--r--addressbook/backend/ebook/e-card.c212
-rw-r--r--addressbook/backend/ebook/e-card.h15
-rw-r--r--addressbook/gui/component/addressbook-factory.c1
-rw-r--r--addressbook/gui/component/addressbook.c11
-rw-r--r--addressbook/gui/component/select-names/e-select-names-manager.c1
-rw-r--r--addressbook/gui/component/select-names/e-select-names.c1
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor-address.c7
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor-fullname.c7
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c29
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c1
14 files changed, 258 insertions, 164 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 22894f1dc9..2ffea5b70e 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,45 @@
+2001-10-11 Christopher James Lahey <clahey@ximian.com>
+
+ * backend/ebook/e-card-simple.c (e_card_simple_destroy,
+ fill_in_info, e_card_simple_sync_card, e_card_simple_set_phone,
+ e_card_simple_set_address, e_card_simple_set_delivery_address,
+ file_as_get_style, file_as_set_style, e_card_simple_set,
+ e_card_simple_set_arbitrary),
+ gui/contact-editor/e-contact-editor-address.c
+ (e_contact_editor_address_destroy,
+ e_contact_editor_address_set_arg,
+ e_contact_editor_address_get_arg),
+ gui/contact-editor/e-contact-editor-fullname.c
+ (e_contact_editor_fullname_destroy,
+ e_contact_editor_fullname_set_arg,
+ e_contact_editor_fullname_get_arg),
+ gui/contact-editor/e-contact-editor.c (phone_entry_changed,
+ address_text_changed, name_entry_changed, full_name_clicked,
+ full_addr_clicked, fill_in_info): Changed these to use the new ref
+ and unref functions for ECard auxillary types.
+
+ * backend/ebook/e-card-simple.h: Added a comment.
+
+ * backend/ebook/e-card-types.h: Added ref_count field to all the
+ types.
+
+ * backend/ebook/e-card.c, backend/ebook/e-card.h: Added ref and
+ unref functions here for all the ECard auxillary types. Removed
+ the corresponding free functions. Switched to using these
+ functions where appropriate.
+
+ * gui/component/addressbook-factory.c: #include
+ <e-util/e-passwords.h>
+
+ * gui/component/addressbook.c (load_uri_cb): const correctify.
+
+ * gui/component/select-names/e-select-names-manager.c,
+ gui/component/select-names/e-select-names.c: #include
+ <addressbook/gui/component/addressbook.h>
+
+ * gui/widgets/e-addressbook-model.c (modify_card): Removed an
+ unnecessary ref here.
+
2001-10-11 Dan Winship <danw@ximian.com>
* gui/component/select-names/e-select-names.c (update_folder):
diff --git a/addressbook/backend/ebook/e-card-simple.c b/addressbook/backend/ebook/e-card-simple.c
index 1dac48d86d..2ef73e17f6 100644
--- a/addressbook/backend/ebook/e-card-simple.c
+++ b/addressbook/backend/ebook/e-card-simple.c
@@ -345,13 +345,13 @@ e_card_simple_destroy (GtkObject *object)
simple->temp_fields = NULL;
for(i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i++)
- e_card_phone_free (simple->phone[i]);
+ e_card_phone_unref (simple->phone[i]);
for(i = 0; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i++)
g_free(simple->email[i]);
for(i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++)
- e_card_address_label_free(simple->address[i]);
+ e_card_address_label_unref(simple->address[i]);
for(i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++)
- e_card_delivery_address_free(simple->delivery[i]);
+ e_card_delivery_address_unref(simple->delivery[i]);
}
@@ -446,7 +446,7 @@ fill_in_info(ECardSimple *simple)
"email", &email_list,
NULL);
for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i++) {
- e_card_phone_free(simple->phone[i]);
+ e_card_phone_unref(simple->phone[i]);
simple->phone[i] = NULL;
}
for (iterator = e_list_get_iterator(phone_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
@@ -454,7 +454,7 @@ fill_in_info(ECardSimple *simple)
phone = e_iterator_get(iterator);
for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) {
if ((phone->flags == phone_correspondences[i]) && (simple->phone[i] == NULL)) {
- simple->phone[i] = e_card_phone_copy(phone);
+ simple->phone[i] = e_card_phone_ref(phone);
found = TRUE;
break;
}
@@ -463,7 +463,7 @@ fill_in_info(ECardSimple *simple)
continue;
for (i = 0; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) {
if (((phone->flags & phone_correspondences[i]) == phone_correspondences[i]) && (simple->phone[i] == NULL)) {
- simple->phone[i] = e_card_phone_copy(phone);
+ simple->phone[i] = e_card_phone_ref(phone);
break;
}
}
@@ -486,14 +486,14 @@ fill_in_info(ECardSimple *simple)
gtk_object_unref(GTK_OBJECT(iterator));
for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) {
- e_card_address_label_free(simple->address[i]);
+ e_card_address_label_unref(simple->address[i]);
simple->address[i] = NULL;
}
for (iterator = e_list_get_iterator(address_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
address = e_iterator_get(iterator);
for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) {
if (((address->flags & addr_correspondences[i]) == addr_correspondences[i]) && (simple->address[i] == NULL)) {
- simple->address[i] = e_card_address_label_copy(address);
+ simple->address[i] = e_card_address_label_ref(address);
break;
}
}
@@ -501,14 +501,14 @@ fill_in_info(ECardSimple *simple)
gtk_object_unref(GTK_OBJECT(iterator));
for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i++) {
- e_card_delivery_address_free(simple->delivery[i]);
+ e_card_delivery_address_unref(simple->delivery[i]);
simple->delivery[i] = NULL;
}
for (iterator = e_list_get_iterator(delivery_list); e_iterator_is_valid(iterator); e_iterator_next(iterator)) {
delivery = e_iterator_get(iterator);
for (i = 0; i < E_CARD_SIMPLE_ADDRESS_ID_LAST; i ++) {
if (((delivery->flags & addr_correspondences[i]) == addr_correspondences[i]) && (simple->delivery[i] == NULL)) {
- simple->delivery[i] = e_card_delivery_address_copy(delivery);
+ simple->delivery[i] = e_card_delivery_address_ref(delivery);
break;
}
}
@@ -555,7 +555,7 @@ e_card_simple_sync_card(ECardSimple *simple)
} else {
e_iterator_delete(iterator);
}
- e_card_phone_free(simple->phone[i]);
+ e_card_phone_unref(simple->phone[i]);
simple->phone[i] = NULL;
found = TRUE;
break;
@@ -573,7 +573,7 @@ e_card_simple_sync_card(ECardSimple *simple)
} else {
e_iterator_delete(iterator);
}
- e_card_phone_free(simple->phone[i]);
+ e_card_phone_unref(simple->phone[i]);
simple->phone[i] = NULL;
break;
}
@@ -585,7 +585,7 @@ e_card_simple_sync_card(ECardSimple *simple)
if (simple->phone[i]) {
simple->phone[i]->flags = phone_correspondences[i];
e_list_append(phone_list, simple->phone[i]);
- e_card_phone_free(simple->phone[i]);
+ e_card_phone_unref(simple->phone[i]);
simple->phone[i] = NULL;
}
}
@@ -627,7 +627,7 @@ e_card_simple_sync_card(ECardSimple *simple)
} else {
e_iterator_delete(iterator);
}
- e_card_address_label_free(simple->address[i]);
+ e_card_address_label_unref(simple->address[i]);
simple->address[i] = NULL;
break;
}
@@ -639,7 +639,7 @@ e_card_simple_sync_card(ECardSimple *simple)
if (simple->address[i]) {
simple->address[i]->flags = addr_correspondences[i];
e_list_append(address_list, simple->address[i]);
- e_card_address_label_free(simple->address[i]);
+ e_card_address_label_unref(simple->address[i]);
simple->address[i] = NULL;
}
}
@@ -656,7 +656,7 @@ e_card_simple_sync_card(ECardSimple *simple)
} else {
e_iterator_delete(iterator);
}
- e_card_delivery_address_free(simple->delivery[i]);
+ e_card_delivery_address_unref(simple->delivery[i]);
simple->delivery[i] = NULL;
break;
}
@@ -668,7 +668,7 @@ e_card_simple_sync_card(ECardSimple *simple)
if (simple->delivery[i]) {
simple->delivery[i]->flags = addr_correspondences[i];
e_list_append(delivery_list, simple->delivery[i]);
- e_card_delivery_address_free(simple->delivery[i]);
+ e_card_delivery_address_unref(simple->delivery[i]);
simple->delivery[i] = NULL;
}
}
@@ -707,9 +707,8 @@ void e_card_simple_set_phone (ECardSimple *simple,
ECardSimplePhoneId id,
const ECardPhone *phone)
{
- if (simple->phone[id])
- e_card_phone_free(simple->phone[id]);
- simple->phone[id] = e_card_phone_copy(phone);
+ e_card_phone_unref(simple->phone[id]);
+ simple->phone[id] = e_card_phone_ref(phone);
simple->changed = TRUE;
}
@@ -717,21 +716,17 @@ void e_card_simple_set_email (ECardSimple *simple,
ECardSimpleEmailId id,
const char *email)
{
- if (simple->email[id])
- g_free(simple->email[id]);
+ g_free(simple->email[id]);
simple->email[id] = g_strdup(email);
simple->changed = TRUE;
}
-void e_card_simple_set_address (ECardSimple *simple,
- ECardSimpleAddressId id,
- const ECardAddrLabel *address)
+void
+e_card_simple_set_address (ECardSimple *simple, ECardSimpleAddressId id, const ECardAddrLabel *address)
{
- if (simple->address[id])
- e_card_address_label_free(simple->address[id]);
- simple->address[id] = e_card_address_label_copy(address);
- if (simple->delivery[id])
- e_card_delivery_address_free(simple->delivery[id]);
+ e_card_address_label_unref(simple->address[id]);
+ simple->address[id] = e_card_address_label_ref(address);
+ e_card_delivery_address_unref(simple->delivery[id]);
simple->delivery[id] = e_card_delivery_address_from_label(simple->address[id]);
simple->changed = TRUE;
}
@@ -740,9 +735,8 @@ void e_card_simple_set_delivery_address (ECardSimple *simple
ECardSimpleAddressId id,
const ECardDeliveryAddress *delivery)
{
- if (simple->delivery[id])
- e_card_delivery_address_free(simple->delivery[id]);
- simple->delivery[id] = e_card_delivery_address_copy(delivery);
+ e_card_delivery_address_unref(simple->delivery[id]);
+ simple->delivery[id] = e_card_delivery_address_ref(delivery);
simple->changed = TRUE;
}
@@ -954,8 +948,7 @@ file_as_get_style (ECardSimple *simple)
g_free(filestring);
g_free(full_name);
g_free(company);
- if (name)
- e_card_name_free(name);
+ e_card_name_unref(name);
return style;
}
@@ -981,7 +974,7 @@ file_as_set_style(ECardSimple *simple, int style)
}
g_free(full_name);
g_free(company);
- e_card_name_free(name);
+ e_card_name_unref(name);
}
}
@@ -1014,21 +1007,19 @@ void e_card_simple_set (ECardSimple *simple,
break; /* FIXME!!!! */
case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS:
address = e_card_address_label_new();
- address->data = (char *) data;
+ address->data = g_strdup (data);
e_card_simple_set_address(simple,
field_data[field].list_type_index,
address);
- address->data = NULL;
- e_card_address_label_free(address);
+ e_card_address_label_unref(address);
break;
case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE:
phone = e_card_phone_new();
- phone->number = (char *) data;
+ phone->number = g_strdup (data);
e_card_simple_set_phone(simple,
field_data[field].list_type_index,
phone);
- phone->number = NULL;
- e_card_phone_free(phone);
+ e_card_phone_unref(phone);
break;
case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL:
e_card_simple_set_email(simple,
@@ -1141,7 +1132,7 @@ void e_card_simple_set_arbitrary (ECardSimple *sim
new_arb->type = g_strdup(type);
new_arb->value = g_strdup(value);
e_iterator_set(iterator, new_arb);
- e_card_arbitrary_free(new_arb);
+ e_card_arbitrary_unref(new_arb);
return;
}
}
@@ -1150,7 +1141,7 @@ void e_card_simple_set_arbitrary (ECardSimple *sim
new_arb->type = g_strdup(type);
new_arb->value = g_strdup(value);
e_list_append(list, new_arb);
- e_card_arbitrary_free(new_arb);
+ e_card_arbitrary_unref(new_arb);
}
}
diff --git a/addressbook/backend/ebook/e-card-simple.h b/addressbook/backend/ebook/e-card-simple.h
index 0d353f00da..1639e4d71b 100644
--- a/addressbook/backend/ebook/e-card-simple.h
+++ b/addressbook/backend/ebook/e-card-simple.h
@@ -116,6 +116,7 @@ enum _ECardSimpleField {
E_CARD_SIMPLE_FIELD_NOTE,
E_CARD_SIMPLE_FIELD_CALURI,
E_CARD_SIMPLE_FIELD_FBURL,
+ /* If you add after FBURL, make sure to move LAST_SIMPLE_STRING */
E_CARD_SIMPLE_FIELD_LAST_SIMPLE_STRING = E_CARD_SIMPLE_FIELD_FBURL,
E_CARD_SIMPLE_FIELD_ANNIVERSARY,
E_CARD_SIMPLE_FIELD_BIRTH_DATE,
diff --git a/addressbook/backend/ebook/e-card-types.h b/addressbook/backend/ebook/e-card-types.h
index 13854c30e7..588a1f5e68 100644
--- a/addressbook/backend/ebook/e-card-types.h
+++ b/addressbook/backend/ebook/e-card-types.h
@@ -14,11 +14,12 @@
/* IDENTIFICATION PROPERTIES */
typedef struct {
- char *prefix; /* Mr. */
- char *given; /* John */
- char *additional; /* Quinlan */
- char *family; /* Public */
- char *suffix; /* Esq. */
+ gint ref_count;
+ char *prefix; /* Mr. */
+ char *given; /* John */
+ char *additional; /* Quinlan */
+ char *family; /* Public */
+ char *suffix; /* Esq. */
} ECardName;
typedef struct {
@@ -51,6 +52,7 @@ typedef enum {
} ECardPhoneFlags;
typedef struct {
+ gint ref_count;
ECardPhoneFlags flags;
char *number;
} ECardPhone;
@@ -67,6 +69,7 @@ typedef enum {
} ECardAddressFlags;
typedef struct {
+ gint ref_count;
ECardAddressFlags flags;
char *po;
@@ -79,6 +82,7 @@ typedef struct {
} ECardDeliveryAddress;
typedef struct {
+ gint ref_count;
ECardAddressFlags flags;
char *data;
} ECardAddrLabel;
@@ -86,6 +90,7 @@ typedef struct {
/* ARBITRARY PROPERTIES */
typedef struct {
+ gint ref_count;
char *key;
char *type;
char *value;
diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c
index 1b3ef694b6..216971c650 100644
--- a/addressbook/backend/ebook/e-card.c
+++ b/addressbook/backend/ebook/e-card.c
@@ -781,10 +781,9 @@ parse_file_as(ECard *card, VObject *vobj, char *default_charset)
static void
parse_name(ECard *card, VObject *vobj, char *default_charset)
{
- if ( card->name ) {
- e_card_name_free(card->name);
- }
- card->name = g_new(ECardName, 1);
+ e_card_name_unref(card->name);
+
+ card->name = e_card_name_new();
card->name->family = e_v_object_get_child_value (vobj, VCFamilyNameProp, default_charset);
card->name->given = e_v_object_get_child_value (vobj, VCGivenNameProp, default_charset);
@@ -832,7 +831,7 @@ parse_bday(ECard *card, VObject *vobj, char *default_charset)
static void
parse_phone(ECard *card, VObject *vobj, char *default_charset)
{
- ECardPhone *next_phone = g_new(ECardPhone, 1);
+ ECardPhone *next_phone = e_card_phone_new ();
EList *list;
assign_string(vobj, default_charset, &(next_phone->number));
@@ -842,13 +841,13 @@ parse_phone(ECard *card, VObject *vobj, char *default_charset)
"phone", &list,
NULL);
e_list_append(list, next_phone);
- e_card_phone_free (next_phone);
+ e_card_phone_unref (next_phone);
}
static void
parse_address(ECard *card, VObject *vobj, char *default_charset)
{
- ECardDeliveryAddress *next_addr = g_new(ECardDeliveryAddress, 1);
+ ECardDeliveryAddress *next_addr = e_card_delivery_address_new ();
EList *list;
next_addr->flags = get_address_flags (vobj);
@@ -864,13 +863,13 @@ parse_address(ECard *card, VObject *vobj, char *default_charset)
"address", &list,
NULL);
e_list_append(list, next_addr);
- e_card_delivery_address_free (next_addr);
+ e_card_delivery_address_unref (next_addr);
}
static void
parse_address_label(ECard *card, VObject *vobj, char *default_charset)
{
- ECardAddrLabel *next_addr = g_new(ECardAddrLabel, 1);
+ ECardAddrLabel *next_addr = e_card_address_label_new ();
EList *list;
next_addr->flags = get_address_flags (vobj);
@@ -880,7 +879,7 @@ parse_address_label(ECard *card, VObject *vobj, char *default_charset)
"address_label", &list,
NULL);
e_list_append(list, next_addr);
- e_card_address_label_free (next_addr);
+ e_card_address_label_unref (next_addr);
}
static void
@@ -1169,7 +1168,7 @@ parse_arbitrary(ECard *card, VObject *vobj, char *default_charset)
"arbitrary", &list,
NULL);
e_list_append(list, arbitrary);
- e_card_arbitrary_free(arbitrary);
+ e_card_arbitrary_unref(arbitrary);
}
static void
@@ -1337,6 +1336,7 @@ e_card_phone_new (void)
{
ECardPhone *newphone = g_new(ECardPhone, 1);
+ newphone->ref_count = 1;
newphone->number = NULL;
newphone->flags = 0;
@@ -1344,20 +1344,31 @@ e_card_phone_new (void)
}
void
-e_card_phone_free (ECardPhone *phone)
+e_card_phone_unref (ECardPhone *phone)
{
- if ( phone ) {
- g_free(phone->number);
-
- g_free(phone);
+ if (phone) {
+ phone->ref_count --;
+ if (phone->ref_count == 0) {
+ g_free(phone->number);
+ g_free(phone);
+ }
}
}
ECardPhone *
+e_card_phone_ref (const ECardPhone *phone)
+{
+ ECardPhone *phone_mutable = (ECardPhone *) phone;
+ if (phone_mutable)
+ phone_mutable->ref_count ++;
+ return phone_mutable;
+}
+
+ECardPhone *
e_card_phone_copy (const ECardPhone *phone)
{
if ( phone ) {
- ECardPhone *phone_copy = g_new(ECardPhone, 1);
+ ECardPhone *phone_copy = e_card_phone_new();
phone_copy->number = g_strdup(phone->number);
phone_copy->flags = phone->flags;
return phone_copy;
@@ -1370,6 +1381,7 @@ e_card_delivery_address_new (void)
{
ECardDeliveryAddress *newaddr = g_new(ECardDeliveryAddress, 1);
+ newaddr->ref_count = 1;
newaddr->po = NULL;
newaddr->ext = NULL;
newaddr->street = NULL;
@@ -1383,26 +1395,37 @@ e_card_delivery_address_new (void)
}
void
-e_card_delivery_address_free (ECardDeliveryAddress *addr)
+e_card_delivery_address_unref (ECardDeliveryAddress *addr)
{
if ( addr ) {
- g_free(addr->po);
- g_free(addr->ext);
- g_free(addr->street);
- g_free(addr->city);
- g_free(addr->region);
- g_free(addr->code);
- g_free(addr->country);
-
- g_free(addr);
+ addr->ref_count --;
+ if (addr->ref_count == 0) {
+ g_free(addr->po);
+ g_free(addr->ext);
+ g_free(addr->street);
+ g_free(addr->city);
+ g_free(addr->region);
+ g_free(addr->code);
+ g_free(addr->country);
+ g_free(addr);
+ }
}
}
ECardDeliveryAddress *
+e_card_delivery_address_ref (const ECardDeliveryAddress *addr)
+{
+ ECardDeliveryAddress *addr_mutable = (ECardDeliveryAddress *) addr;
+ if (addr_mutable)
+ addr_mutable->ref_count ++;
+ return addr_mutable;
+}
+
+ECardDeliveryAddress *
e_card_delivery_address_copy (const ECardDeliveryAddress *addr)
{
if ( addr ) {
- ECardDeliveryAddress *addr_copy = g_new(ECardDeliveryAddress, 1);
+ ECardDeliveryAddress *addr_copy = e_card_delivery_address_new ();
addr_copy->po = g_strdup(addr->po );
addr_copy->ext = g_strdup(addr->ext );
addr_copy->street = g_strdup(addr->street );
@@ -1431,7 +1454,7 @@ e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr)
ECardDeliveryAddress *
e_card_delivery_address_from_label(const ECardAddrLabel *label)
{
- ECardDeliveryAddress *addr = g_new(ECardDeliveryAddress, 1);
+ ECardDeliveryAddress *addr = e_card_delivery_address_new ();
EAddressWestern *western = e_address_western_parse (label->data);
addr->po = g_strdup (western->po_box );
@@ -1507,6 +1530,7 @@ e_card_address_label_new (void)
{
ECardAddrLabel *newaddr = g_new(ECardAddrLabel, 1);
+ newaddr->ref_count = 1;
newaddr->data = NULL;
newaddr->flags = 0;
@@ -1514,22 +1538,33 @@ e_card_address_label_new (void)
}
void
-e_card_address_label_free (ECardAddrLabel *addr)
+e_card_address_label_unref (ECardAddrLabel *addr)
{
- if ( addr ) {
- g_free(addr->data);
-
- g_free(addr);
+ if (addr) {
+ addr->ref_count --;
+ if (addr->ref_count == 0) {
+ g_free(addr->data);
+ g_free(addr);
+ }
}
}
ECardAddrLabel *
+e_card_address_label_ref (const ECardAddrLabel *addr)
+{
+ ECardAddrLabel *addr_mutable = (ECardAddrLabel *) addr;
+ if (addr_mutable)
+ addr_mutable->ref_count ++;
+ return addr_mutable;
+}
+
+ECardAddrLabel *
e_card_address_label_copy (const ECardAddrLabel *addr)
{
if ( addr ) {
- ECardAddrLabel *addr_copy = g_new(ECardAddrLabel, 1);
- addr_copy->data = g_strdup(addr->data);
- addr_copy->flags = addr->flags;
+ ECardAddrLabel *addr_copy = e_card_address_label_new ();
+ addr_copy->data = g_strdup(addr->data);
+ addr_copy->flags = addr->flags;
return addr_copy;
} else
return NULL;
@@ -1537,8 +1572,9 @@ e_card_address_label_copy (const ECardAddrLabel *addr)
ECardName *e_card_name_new(void)
{
- ECardName *newname = g_new(ECardName, 1);
+ ECardName *newname = g_new(ECardName, 1);
+ newname->ref_count = 1;
newname->prefix = NULL;
newname->given = NULL;
newname->additional = NULL;
@@ -1549,29 +1585,36 @@ ECardName *e_card_name_new(void)
}
void
-e_card_name_free(ECardName *name)
+e_card_name_unref(ECardName *name)
{
if (name) {
- if ( name->prefix )
- g_free(name->prefix);
- if ( name->given )
- g_free(name->given);
- if ( name->additional )
- g_free(name->additional);
- if ( name->family )
- g_free(name->family);
- if ( name->suffix )
- g_free(name->suffix);
- g_free ( name );
+ name->ref_count --;
+ if (name->ref_count == 0) {
+ g_free (name->prefix);
+ g_free (name->given);
+ g_free (name->additional);
+ g_free (name->family);
+ g_free (name->suffix);
+ g_free (name);
+ }
}
}
ECardName *
+e_card_name_ref(const ECardName *name)
+{
+ ECardName *name_mutable = (ECardName *) name;
+ if (name_mutable)
+ name_mutable->ref_count ++;
+ return name_mutable;
+}
+
+ECardName *
e_card_name_copy(const ECardName *name)
{
if (name) {
- ECardName *newname = g_new(ECardName, 1);
-
+ ECardName *newname = e_card_name_new ();
+
newname->prefix = g_strdup(name->prefix);
newname->given = g_strdup(name->given);
newname->additional = g_strdup(name->additional);
@@ -1583,6 +1626,7 @@ e_card_name_copy(const ECardName *name)
return NULL;
}
+
char *
e_card_name_to_string(const ECardName *name)
{
@@ -1607,7 +1651,7 @@ e_card_name_to_string(const ECardName *name)
ECardName *
e_card_name_from_string(const char *full_name)
{
- ECardName *name = g_new(ECardName, 1);
+ ECardName *name = e_card_name_new ();
ENameWestern *western = e_name_western_parse (full_name);
name->prefix = g_strdup (western->prefix);
@@ -1625,17 +1669,32 @@ ECardArbitrary *
e_card_arbitrary_new(void)
{
ECardArbitrary *arbitrary = g_new(ECardArbitrary, 1);
+ arbitrary->ref_count = 1;
arbitrary->key = NULL;
arbitrary->type = NULL;
arbitrary->value = NULL;
return arbitrary;
}
+void
+e_card_arbitrary_unref(ECardArbitrary *arbitrary)
+{
+ if (arbitrary) {
+ arbitrary->ref_count --;
+ if (arbitrary->ref_count == 0) {
+ g_free(arbitrary->key);
+ g_free(arbitrary->type);
+ g_free(arbitrary->value);
+ g_free(arbitrary);
+ }
+ }
+}
+
ECardArbitrary *
e_card_arbitrary_copy(const ECardArbitrary *arbitrary)
{
if (arbitrary) {
- ECardArbitrary *arb_copy = g_new(ECardArbitrary, 1);
+ ECardArbitrary *arb_copy = e_card_arbitrary_new ();
arb_copy->key = g_strdup(arbitrary->key);
arb_copy->type = g_strdup(arbitrary->type);
arb_copy->value = g_strdup(arbitrary->value);
@@ -1644,15 +1703,13 @@ e_card_arbitrary_copy(const ECardArbitrary *arbitrary)
return NULL;
}
-void
-e_card_arbitrary_free(ECardArbitrary *arbitrary)
+ECardArbitrary *
+e_card_arbitrary_ref(const ECardArbitrary *arbitrary)
{
- if (arbitrary) {
- g_free(arbitrary->key);
- g_free(arbitrary->type);
- g_free(arbitrary->value);
- }
- g_free(arbitrary);
+ ECardArbitrary *arbitrary_mutable = (ECardArbitrary *) arbitrary;
+ if (arbitrary_mutable)
+ arbitrary_mutable->ref_count ++;
+ return arbitrary_mutable;
}
/* EMail matching */
@@ -1744,8 +1801,7 @@ e_card_destroy (GtkObject *object)
gtk_object_unref (GTK_OBJECT (card->book));
g_free(card->file_as);
g_free(card->fname);
- if ( card->name )
- e_card_name_free(card->name);
+ e_card_name_unref(card->name);
g_free(card->bday);
g_free(card->url);
@@ -1792,19 +1848,19 @@ e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
if (card->file_as == NULL)
card->file_as = g_strdup("");
break;
+
case ARG_FULL_NAME:
g_free(card->fname);
card->fname = g_strdup(GTK_VALUE_STRING(*arg));
- if (card->name)
- e_card_name_free (card->name);
if (card->fname == NULL)
card->fname = g_strdup("");
+
+ e_card_name_unref (card->name);
card->name = e_card_name_from_string (card->fname);
break;
case ARG_NAME:
- if ( card->name )
- e_card_name_free(card->name);
- card->name = e_card_name_copy(GTK_VALUE_POINTER(*arg));
+ e_card_name_unref (card->name);
+ card->name = e_card_name_ref(GTK_VALUE_POINTER(*arg));
if (card->name == NULL)
card->name = e_card_name_new();
if (card->fname == NULL) {
@@ -1974,22 +2030,22 @@ e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
break;
case ARG_ADDRESS:
if (!card->address)
- card->address = e_list_new((EListCopyFunc) e_card_delivery_address_copy,
- (EListFreeFunc) e_card_delivery_address_free,
+ card->address = e_list_new((EListCopyFunc) e_card_delivery_address_ref,
+ (EListFreeFunc) e_card_delivery_address_unref,
NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->address);
break;
case ARG_ADDRESS_LABEL:
if (!card->address_label)
- card->address_label = e_list_new((EListCopyFunc) e_card_address_label_copy,
- (EListFreeFunc) e_card_address_label_free,
+ card->address_label = e_list_new((EListCopyFunc) e_card_address_label_ref,
+ (EListFreeFunc) e_card_address_label_unref,
NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->address_label);
break;
case ARG_PHONE:
if (!card->phone)
- card->phone = e_list_new((EListCopyFunc) e_card_phone_copy,
- (EListFreeFunc) e_card_phone_free,
+ card->phone = e_list_new((EListCopyFunc) e_card_phone_ref,
+ (EListFreeFunc) e_card_phone_unref,
NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->phone);
break;
@@ -2086,8 +2142,8 @@ e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
break;
case ARG_ARBITRARY:
if (!card->arbitrary)
- card->arbitrary = e_list_new((EListCopyFunc) e_card_arbitrary_copy,
- (EListFreeFunc) e_card_arbitrary_free,
+ card->arbitrary = e_list_new((EListCopyFunc) e_card_arbitrary_ref,
+ (EListFreeFunc) e_card_arbitrary_unref,
NULL);
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(card->arbitrary);
@@ -2731,7 +2787,7 @@ e_card_get_name (VObject *o)
VObject *vo;
char *the_str;
- name = g_new0 (ECardName, 1);
+ name = e_card_name_new ();
name->family = e_card_prop_get_substr (o, VCFamilyNameProp);
name->given = e_card_prop_get_substr (o, VCGivenNameProp);
diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h
index 3f2334023b..242c9738b7 100644
--- a/addressbook/backend/ebook/e-card.h
+++ b/addressbook/backend/ebook/e-card.h
@@ -142,12 +142,14 @@ gboolean e_card_evolution_list_show_addresses (ECard
/* ECardPhone manipulation */
ECardPhone *e_card_phone_new (void);
ECardPhone *e_card_phone_copy (const ECardPhone *phone);
-void e_card_phone_free (ECardPhone *phone);
+ECardPhone *e_card_phone_ref (const ECardPhone *phone);
+void e_card_phone_unref (ECardPhone *phone);
/* ECardDeliveryAddress manipulation */
ECardDeliveryAddress *e_card_delivery_address_new (void);
ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr);
-void e_card_delivery_address_free (ECardDeliveryAddress *addr);
+ECardDeliveryAddress *e_card_delivery_address_ref (const ECardDeliveryAddress *addr);
+void e_card_delivery_address_unref (ECardDeliveryAddress *addr);
gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr);
char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr);
ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label);
@@ -156,19 +158,22 @@ ECardAddrLabel *e_card_delivery_address_to_label (const
/* ECardAddrLabel manipulation */
ECardAddrLabel *e_card_address_label_new (void);
ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr);
-void e_card_address_label_free (ECardAddrLabel *addr);
+ECardAddrLabel *e_card_address_label_ref (const ECardAddrLabel *addr);
+void e_card_address_label_unref (ECardAddrLabel *addr);
/* ECardName manipulation */
ECardName *e_card_name_new (void);
ECardName *e_card_name_copy (const ECardName *name);
-void e_card_name_free (ECardName *name);
+ECardName *e_card_name_ref (const ECardName *name);
+void e_card_name_unref (ECardName *name);
char *e_card_name_to_string (const ECardName *name);
ECardName *e_card_name_from_string (const char *full_name);
/* ECardArbitrary manipulation */
ECardArbitrary *e_card_arbitrary_new (void);
ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary);
-void e_card_arbitrary_free (ECardArbitrary *arbitrary);
+ECardArbitrary *e_card_arbitrary_ref (const ECardArbitrary *arbitrary);
+void e_card_arbitrary_unref (ECardArbitrary *arbitrary);
/* ECard email manipulation */
gboolean e_card_email_match_string (const ECard *card,
diff --git a/addressbook/gui/component/addressbook-factory.c b/addressbook/gui/component/addressbook-factory.c
index 1719c4fd8f..c941cbf24d 100644
--- a/addressbook/gui/component/addressbook-factory.c
+++ b/addressbook/gui/component/addressbook-factory.c
@@ -17,6 +17,7 @@
#include <bonobo/bonobo-main.h>
#include <glade/glade.h>
#include <gal/widgets/e-cursors.h>
+#include <e-util/e-passwords.h>
#include <camel/camel.h>
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index 8dc978f603..41b2ff7396 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -603,7 +603,8 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
if (source &&
source->type == ADDRESSBOOK_SOURCE_LDAP &&
source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE) {
- char *password;
+ const char *password;
+ char *pass_dup = NULL;
password = e_passwords_get_password(load_uri_data->uri);
@@ -613,7 +614,7 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
prompt = g_strdup_printf (_("Enter password for %s (user %s)"), source->name, source->email_addr);
remember = source->remember_passwd;
- password = e_passwords_ask_password (
+ pass_dup = e_passwords_ask_password (
prompt, load_uri_data->uri, prompt, TRUE,
E_PASSWORDS_REMEMBER_FOREVER, &remember,
NULL);
@@ -624,10 +625,10 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure)
g_free (prompt);
}
- if (password) {
- e_book_authenticate_user (book, source->email_addr, password,
+ if (password || pass_dup) {
+ e_book_authenticate_user (book, source->email_addr, password ? password : pass_dup,
load_uri_auth_cb, closure);
- g_free (password);
+ g_free (pass_dup);
return;
}
}
diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c
index 5820a2bf52..d392930570 100644
--- a/addressbook/gui/component/select-names/e-select-names-manager.c
+++ b/addressbook/gui/component/select-names/e-select-names-manager.c
@@ -21,6 +21,7 @@
#include "e-select-names-completion.h"
#include "e-select-names-popup.h"
#include <addressbook/backend/ebook/e-destination.h>
+#include <addressbook/gui/component/addressbook.h>
#include <bonobo-conf/bonobo-config-database.h>
#include <bonobo/bonobo-object.h>
#include <bonobo/bonobo-moniker-util.h>
diff --git a/addressbook/gui/component/select-names/e-select-names.c b/addressbook/gui/component/select-names/e-select-names.c
index de592dc01e..0befe02ffc 100644
--- a/addressbook/gui/component/select-names/e-select-names.c
+++ b/addressbook/gui/component/select-names/e-select-names.c
@@ -38,6 +38,7 @@
#include <addressbook/backend/ebook/e-book.h>
#include <addressbook/gui/component/addressbook-component.h>
#include <addressbook/gui/component/addressbook-storage.h>
+#include <addressbook/gui/component/addressbook.h>
#include <shell/evolution-shell-client.h>
#include "e-select-names.h"
diff --git a/addressbook/gui/contact-editor/e-contact-editor-address.c b/addressbook/gui/contact-editor/e-contact-editor-address.c
index 919fb63acb..f07b483c21 100644
--- a/addressbook/gui/contact-editor/e-contact-editor-address.c
+++ b/addressbook/gui/contact-editor/e-contact-editor-address.c
@@ -123,7 +123,7 @@ e_contact_editor_address_destroy (GtkObject *object)
if (e_contact_editor_address->gui)
gtk_object_unref(GTK_OBJECT(e_contact_editor_address->gui));
- e_card_delivery_address_free(e_contact_editor_address->address);
+ e_card_delivery_address_unref(e_contact_editor_address->address);
}
GtkWidget*
@@ -145,8 +145,7 @@ e_contact_editor_address_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_ADDRESS:
- if (e_contact_editor_address->address)
- e_card_delivery_address_free(e_contact_editor_address->address);
+ e_card_delivery_address_unref(e_contact_editor_address->address);
e_contact_editor_address->address = e_card_delivery_address_copy(GTK_VALUE_POINTER (*arg));
fill_in_info(e_contact_editor_address);
break;
@@ -190,7 +189,7 @@ e_contact_editor_address_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
switch (arg_id) {
case ARG_ADDRESS:
extract_info(e_contact_editor_address);
- GTK_VALUE_POINTER (*arg) = e_card_delivery_address_copy(e_contact_editor_address->address);
+ GTK_VALUE_POINTER (*arg) = e_card_delivery_address_ref(e_contact_editor_address->address);
break;
case ARG_IS_READ_ONLY:
GTK_VALUE_BOOL (*arg) = e_contact_editor_address->editable ? TRUE : FALSE;
diff --git a/addressbook/gui/contact-editor/e-contact-editor-fullname.c b/addressbook/gui/contact-editor/e-contact-editor-fullname.c
index 0af0de3236..ddf69d861c 100644
--- a/addressbook/gui/contact-editor/e-contact-editor-fullname.c
+++ b/addressbook/gui/contact-editor/e-contact-editor-fullname.c
@@ -123,7 +123,7 @@ e_contact_editor_fullname_destroy (GtkObject *object)
if (e_contact_editor_fullname->gui)
gtk_object_unref(GTK_OBJECT(e_contact_editor_fullname->gui));
- e_card_name_free(e_contact_editor_fullname->name);
+ e_card_name_unref(e_contact_editor_fullname->name);
}
GtkWidget*
@@ -145,8 +145,7 @@ e_contact_editor_fullname_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_NAME:
- if (e_contact_editor_fullname->name)
- e_card_name_free(e_contact_editor_fullname->name);
+ e_card_name_unref(e_contact_editor_fullname->name);
e_contact_editor_fullname->name = e_card_name_copy(GTK_VALUE_POINTER (*arg));
fill_in_info(e_contact_editor_fullname);
break;
@@ -188,7 +187,7 @@ e_contact_editor_fullname_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
switch (arg_id) {
case ARG_NAME:
extract_info(e_contact_editor_fullname);
- GTK_VALUE_POINTER (*arg) = e_card_name_copy(e_contact_editor_fullname->name);
+ GTK_VALUE_POINTER (*arg) = e_card_name_ref(e_contact_editor_fullname->name);
break;
case ARG_IS_READ_ONLY:
GTK_VALUE_BOOL (*arg) = e_contact_editor_fullname->editable ? TRUE : FALSE;
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index d34d1589b3..72d49b5908 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -262,7 +262,6 @@ static void
phone_entry_changed (GtkWidget *widget, EContactEditor *editor)
{
int which;
- gchar *string;
GtkEntry *entry = GTK_ENTRY(widget);
ECardPhone *phone;
@@ -276,14 +275,10 @@ phone_entry_changed (GtkWidget *widget, EContactEditor *editor)
which = 4;
} else
return;
- string = e_utf8_gtk_entry_get_text(entry);
phone = e_card_phone_new();
- phone->number = string;
+ phone->number = e_utf8_gtk_entry_get_text(entry);
e_card_simple_set_phone(editor->simple, editor->phone_choice[which - 1], phone);
-#if 0
- phone->number = NULL;
-#endif
- e_card_phone_free(phone);
+ e_card_phone_unref(phone);
set_fields(editor);
widget_changed (widget, editor);
@@ -318,7 +313,7 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor)
address->data = e_utf8_gtk_editable_get_chars(editable, 0, -1);
e_card_simple_set_address(editor->simple, editor->address_choice, address);
- e_card_address_label_free(address);
+ e_card_address_label_unref(address);
widget_changed (widget, editor);
}
@@ -485,7 +480,7 @@ name_entry_changed (GtkWidget *widget, EContactEditor *editor)
style = file_as_get_style(editor);
- e_card_name_free(editor->name);
+ e_card_name_unref(editor->name);
string = e_utf8_gtk_entry_get_text (GTK_ENTRY(widget));
editor->name = e_card_name_from_string(string);
@@ -689,8 +684,8 @@ full_name_clicked(GtkWidget *button, EContactEditor *editor)
g_free(full_name);
}
- e_card_name_free(editor->name);
- editor->name = e_card_name_copy(name);
+ e_card_name_unref(editor->name);
+ editor->name = e_card_name_ref(name);
file_as_set_style(editor, style);
}
@@ -729,12 +724,12 @@ full_addr_clicked(GtkWidget *button, EContactEditor *editor)
} else {
ECardAddrLabel *address = e_card_delivery_address_to_label(new_address);
e_card_simple_set_address(editor->simple, editor->address_choice, address);
- e_card_address_label_free(address);
+ e_card_address_label_unref(address);
}
e_card_simple_set_delivery_address(editor->simple, editor->address_choice, new_address);
- e_card_delivery_address_free(new_address);
+ e_card_delivery_address_unref(new_address);
}
gtk_object_unref(GTK_OBJECT(dialog));
}
@@ -1329,9 +1324,7 @@ e_contact_editor_destroy (GtkObject *object) {
if (e_contact_editor->book)
gtk_object_unref(GTK_OBJECT(e_contact_editor->book));
- if (e_contact_editor->name)
- e_card_name_free(e_contact_editor->name);
-
+ e_card_name_unref(e_contact_editor->name);
g_free (e_contact_editor->company);
gtk_object_unref(GTK_OBJECT(e_contact_editor->gui));
@@ -2332,8 +2325,8 @@ fill_in_info(EContactEditor *editor)
/* File as has to come after company and name or else it'll get messed up when setting them. */
fill_in_field(editor, "entry-file-as", file_as);
- e_card_name_free(editor->name);
- editor->name = e_card_name_copy(name);
+ e_card_name_unref(editor->name);
+ editor->name = e_card_name_ref(name);
widget = glade_xml_get_widget(editor->gui, "dateedit-anniversary");
if (widget && E_IS_DATE_EDIT(widget)) {
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index a93ae6aa28..e43d9e5ec6 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -205,7 +205,6 @@ modify_card(EBookView *book_view,
if ( !strcmp(e_card_get_id(model->data[i]), e_card_get_id(E_CARD(cards->data))) ) {
gtk_object_unref(GTK_OBJECT(model->data[i]));
model->data[i] = e_card_duplicate(E_CARD(cards->data));
- gtk_object_ref(GTK_OBJECT(model->data[i]));
gtk_signal_emit (GTK_OBJECT (model),
e_addressbook_model_signals [CARD_CHANGED],
i);