[PATCH 1/2] Merging address fields to single field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From 0d3f5dfa332e62257183a1fff1aa6c39e4823caa Mon Sep 17 00:00:00 2001
From: Rafal Michalski <michalski.raf@xxxxxxxxx>
Date: Wed, 1 Sep 2010 11:49:28 +0200
Subject: [PATCH 1/2] Merging address fields to single field

So far in code all seven address fields (pobox, extended, street,
locality, region, postal, country) was represented separately.
In vCard structure address is represented by one field so all
mentioned above fields are merged to single field.
---
 plugins/phonebook-tracker.c |   10 +++-------
 plugins/vcard.c             |   41 ++++++++++++++++-------------------------
 plugins/vcard.h             |    8 +-------
 3 files changed, 20 insertions(+), 39 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 1f1f693..bff85b8 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -803,13 +803,9 @@ add_entry:
 	contact->additional = g_strdup(reply[4]);
 	contact->prefix = g_strdup(reply[5]);
 	contact->suffix = g_strdup(reply[6]);
-	contact->pobox = g_strdup(reply[9]);
-	contact->extended = g_strdup(reply[10]);
-	contact->street = g_strdup(reply[11]);
-	contact->locality = g_strdup(reply[12]);
-	contact->region = g_strdup(reply[13]);
-	contact->postal = g_strdup(reply[14]);
-	contact->country = g_strdup(reply[15]);
+	contact->address = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s",
+				reply[9], reply[10], reply[11], reply[12],
+				reply[13], reply[14], reply[15]);
 	contact->birthday = g_strdup(reply[18]);
 	contact->nickname = g_strdup(reply[19]);
 	contact->website = g_strdup(reply[20]);
diff --git a/plugins/vcard.c b/plugins/vcard.c
index 09f4f40..33a1ede 100644
--- a/plugins/vcard.c
+++ b/plugins/vcard.c
@@ -31,6 +31,7 @@
 
 #include "vcard.h"
 
+#define ADDR_FIELD_AMOUNT 7
 #define LEN_MAX 128
 #define TYPE_INTERNATIONAL 145
 
@@ -157,20 +158,19 @@ static gboolean contact_fields_present(struct phonebook_contact * contact)
 
 static gboolean address_fields_present(struct phonebook_contact *contact)
 {
-	if (contact->pobox && strlen(contact->pobox))
-		return TRUE;
-	if (contact->extended && strlen(contact->extended))
-		return TRUE;
-	if (contact->street && strlen(contact->street))
-		return TRUE;
-	if (contact->locality && strlen(contact->locality))
-		return TRUE;
-	if (contact->region && strlen(contact->region))
-		return TRUE;
-	if (contact->postal && strlen(contact->postal))
-		return TRUE;
-	if (contact->country && strlen(contact->country))
-		return TRUE;
+	gchar **address_fields = g_strsplit(contact->address, ";",
+							ADDR_FIELD_AMOUNT);
+	int i = 0;
+
+	for (; i < ADDR_FIELD_AMOUNT; ++i) {
+
+		if (strlen(address_fields[i]) != 0) {
+			g_strfreev(address_fields);
+			return TRUE;
+		}
+	}
+
+	g_strfreev(address_fields);
 
 	return FALSE;
 }
@@ -384,10 +384,7 @@ static void vcard_printf_adr(GString *vcards,
 		return;
 	}
 
-	vcard_printf(vcards, "ADR:%s;%s;%s;%s;%s;%s;%s", contact->pobox,
-					contact->extended, contact->street,
-					contact->locality, contact->region,
-					contact->postal, contact->country);
+	vcard_printf(vcards, "ADR:%s", contact->address);
 }
 
 static void vcard_printf_datetime(GString *vcards,
@@ -529,13 +526,7 @@ void phonebook_contact_free(struct phonebook_contact *contact)
 	g_free(contact->additional);
 	g_free(contact->prefix);
 	g_free(contact->suffix);
-	g_free(contact->pobox);
-	g_free(contact->extended);
-	g_free(contact->street);
-	g_free(contact->locality);
-	g_free(contact->region);
-	g_free(contact->postal);
-	g_free(contact->country);
+	g_free(contact->address);
 	g_free(contact->birthday);
 	g_free(contact->nickname);
 	g_free(contact->website);
diff --git a/plugins/vcard.h b/plugins/vcard.h
index a22dfc1..b1e971e 100644
--- a/plugins/vcard.h
+++ b/plugins/vcard.h
@@ -59,13 +59,7 @@ struct phonebook_contact {
 	GSList *emails;
 	char *prefix;
 	char *suffix;
-	char *pobox;
-	char *extended;
-	char *street;
-	char *locality;
-	char *region;
-	char *postal;
-	char *country;
+	char *address;
 	char *birthday;
 	char *nickname;
 	char *website;
-- 
1.6.3.3


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux