[Commits] vcard-extension.c 1.1 1.2 vcard-utils.c 1.1 1.2
miras at claws-mail.org
miras at claws-mail.org
Sun Jan 1 03:07:42 CET 2012
Update of /home/claws-mail/contacts/extensions/vcard/src
In directory claws-mail:/tmp/cvs-serv27019/extensions/vcard/src
Modified Files:
vcard-extension.c vcard-utils.c
Log Message:
2012-01-01 [mir] 0.6.0cvs67
* extensions/vcard/src/vcard-extension.c
* extensions/vcard/src/vcard-utils.c
* extensions/vcard/src/libversit/.cvsignore
Finish vCard import extension.
Fix bug when importing binary encoded data.
Index: vcard-extension.c
===================================================================
RCS file: /home/claws-mail/contacts/extensions/vcard/src/vcard-extension.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- vcard-extension.c 31 Dec 2011 14:41:22 -0000 1.1
+++ vcard-extension.c 1 Jan 2012 02:07:40 -0000 1.2
@@ -43,6 +43,7 @@
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
+#include <errno.h>
#include "extension.h"
#include "plugin-loader.h"
#include "plugin.h"
@@ -56,6 +57,28 @@
static guint my_id;
+static gchar* vcard_file_chooser(MenuItem* item) {
+ GtkWidget* dialog;
+ gchar* filename = NULL;
+
+ dialog = gtk_file_chooser_dialog_new(_("Open file"),
+ GTK_WINDOW(item->mainwindow->window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), get_home());
+/* gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+ gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);*/
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ }
+ gtk_widget_destroy(dialog);
+
+ return filename;
+}
+
static void mime_error_handler(char *s, void* user_data) {
MenuItem* item = (MenuItem *) user_data;
@@ -66,7 +89,7 @@
static void vcard_import(GtkWidget* widget, gpointer data) {
MenuItem* item = (MenuItem *) data;
- FILE* fp = fopen("/home/mir/CDCARDS/list.vcf", "r");
+ FILE* fp;
VObject *t, *v;
gchar* error = NULL;
AddressBook* abook;
@@ -84,6 +107,17 @@
return;
}
+ gchar* file = vcard_file_chooser(item);
+ if (! file)
+ return;
+ fp = fopen(file, "r");
+ if (! fp) {
+ show_message(item->mainwindow->window, GTK_UTIL_MESSAGE_ERROR, strerror(errno));
+ g_free(file);
+ return;
+ }
+ g_free(file);
+
gchar* filename = g_strdup_printf("vcard_rejected.%d", getpid());
leftover = g_build_filename(get_home(), filename, NULL);
g_free(filename);
@@ -93,7 +127,6 @@
total++;
const gchar* name = vObjectName(v);
if (name && strcmp(name,VCCardProp) == 0) {
- // ... do something to v.
t = v;
Contact* c = vcard2contact(t, plugin, &error);
if (c)
@@ -140,7 +173,6 @@
while (v) {
const gchar* name = vObjectName(v);
if (name && strcmp(name,VCCardProp) == 0) {
- // ... do something to v.
t = v;
printVObject(stderr, v);
}
@@ -157,17 +189,28 @@
GtkWidget *menu;
MenuItem* menu_item;
-/* menu = gtk_image_menu_item_new_with_mnemonic("_vCard");
- gtk_widget_set_name(menu, "contextmenu");
+ menu = gtk_image_menu_item_new_with_mnemonic("_vCard");
+ menu_item = menu_item_new();
+ menu_item->menu = CONTACTS_MAIN_MENU;
+ menu_item->parent = "tools";
+ menu_item->sublabel = "_Export";
+ menu_item->submenu = TRUE;
+ menu_item->mainwindow = mainwindow;
g_signal_connect(menu, "activate",
- G_CALLBACK(my_cb), (gpointer) mainwindow);
+ G_CALLBACK(vcard_export), (gpointer) menu_item);
+ add_menu_item(GTK_IMAGE_MENU_ITEM(menu), menu_item);
+
+ menu = gtk_image_menu_item_new_with_mnemonic("_vCard");
menu_item = menu_item_new();
- menu_item->menu = CONTACTS_CONTACT_MENU;
+ menu_item->menu = CONTACTS_MAIN_MENU;
menu_item->parent = "tools";
menu_item->sublabel = "_Import";
- menu_item->submenu = FALSE;
- add_menu_item(GTK_IMAGE_MENU_ITEM(menu), menu_item);*/
-
+ menu_item->submenu = TRUE;
+ menu_item->mainwindow = mainwindow;
+ g_signal_connect(menu, "activate",
+ G_CALLBACK(vcard_import), (gpointer) menu_item);
+ add_menu_item(GTK_IMAGE_MENU_ITEM(menu), menu_item);
+
// Add a menu item into the context menu of contact
menu = gtk_image_menu_item_new_with_mnemonic("_vCard");
menu_item = menu_item_new();
Index: vcard-utils.c
===================================================================
RCS file: /home/claws-mail/contacts/extensions/vcard/src/vcard-utils.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- vcard-utils.c 31 Dec 2011 14:41:22 -0000 1.1
+++ vcard-utils.c 1 Jan 2012 02:07:40 -0000 1.2
@@ -63,6 +63,49 @@
{"mobile phone", "phone", "office phone"} /* XML */
};
+static void strip_whitespace(gchar** s) {
+ gchar *ptr, *token;
+ gchar* tmp = *s;
+ gchar *buf = NULL, *bufptr;
+
+ token = strtok_r(tmp, " ", &ptr);
+ if (token) {
+ do {
+ g_strchug(token);
+ if (buf) {
+ bufptr = g_realloc(buf, strlen(buf) + strlen(token) + 1);
+ if (bufptr)
+ buf = bufptr;
+ else {
+ g_free(buf);
+ return;
+ }
+ }
+ else
+ buf = g_malloc0(strlen(token) + 1);
+ strcat(buf, token);
+ } while ((token = strtok_r(NULL, " ", &ptr)) != NULL);
+ }
+ if (buf) {
+ g_free(*s);
+ *s = buf;
+ }
+}
+
+static long data_size(VObject* o) {
+ VObjectIterator iter;
+ VObject* prop;
+
+ initPropIterator(&iter,o);
+ while (moreIteration(&iter)) {
+ prop = nextVObject(&iter);
+ gchar* name = vObjectName(prop);
+ if (name && strcmp(name, VCDataSizeProp) == 0)
+ return vObjectLongValue(prop);
+ }
+ return -1;
+}
+
static void* vcard_value(VObject* o) {
switch (vObjectValueType(o)) {
case VCVT_USTRINGZ: {
@@ -79,8 +122,16 @@
return GINT_TO_POINTER(vObjectIntegerValue(o));
case VCVT_ULONG:
return GUINT_TO_POINTER(vObjectLongValue(o));
-/* case VCVT_NOVALUE:
- return (void *) 0;*/
+ case VCVT_NOVALUE:
+ return (void *) 0;
+ case VCVT_RAW: {
+ long size = data_size(o);
+ if (size < 0)
+ return (void *) 0;
+ guchar* data = (guchar *) g_memdup(vObjectAnyValue(o), size);
+ gchar* s = g_base64_encode(data, size);
+ return (void *) s;
+ }
default: {
gchar* s;
const wchar_t* u = vObjectUStringZValue(o);
@@ -124,8 +175,47 @@
else if (strcmp(VCCellularProp, name) == 0)
attr = g_strdup("mobile");
else if (strcmp(VCTelephoneProp, name) == 0) {
- if (strcmp("2.1", version) == 0)
- attr = g_strdup("telephoneNumber");
+ if (strcmp("2.1", version) == 0) {
+ printVObject(stderr, v);
+ VObjectIterator iter;
+ initPropIterator(&iter,v);
+ while (moreIteration(&iter) && !attr) {
+ VObject *prop = nextVObject(&iter);
+ gchar* value = vObjectName(prop);/*(gchar *) vcard_value(prop);*/
+ if (value) {
+ if (g_str_has_prefix(plugin_type, "LDAP")) {
+ if (g_strstr_len(value, strlen(value), "CELL"))
+ attr = g_strdup(phone[VCARD2LDAP][PHONEMOBILE]);
+ else if (g_strstr_len(value, strlen(value), "HOME"))
+ attr = g_strdup(phone[VCARD2LDAP][PHONEHOME]);
+ else if (g_strstr_len(value, strlen(value), "WORK"))
+ attr = g_strdup(phone[VCARD2LDAP][PHONEWORK]);
+ else
+ attr = g_strdup(phone[VCARD2LDAP][PHONEHOME]);
+ }
+ else if (g_str_has_prefix(plugin_type, "XML")) {
+ if (g_strstr_len(value, strlen(value), "CELL"))
+ attr = g_strdup(phone[VCARD2XML][PHONEMOBILE]);
+ else if (g_strstr_len(value, strlen(value), "HOME"))
+ attr = g_strdup(phone[VCARD2XML][PHONEHOME]);
+ else if (g_strstr_len(value, strlen(value), "WORK"))
+ attr = g_strdup(phone[VCARD2XML][PHONEWORK]);
+ else
+ attr = g_strdup(phone[VCARD2XML][PHONEHOME]);
+ }
+ else
+ attr = g_strdup("telephoneNumber");
+ }
+ }
+ if (! attr) {
+ if (g_str_has_prefix(plugin_type, "LDAP"))
+ attr = g_strdup(phone[VCARD2LDAP][PHONEHOME]);
+ else if (g_str_has_prefix(plugin_type, "XML"))
+ attr = g_strdup(phone[VCARD2XML][PHONEHOME]);
+ else
+ attr = g_strdup("telephoneNumber");
+ }
+ }
else {
VObjectIterator iter;
initPropIterator(&iter,v);
@@ -152,11 +242,18 @@
}
else
attr = g_strdup("telephoneNumber");
+ g_free(value);
}
}
}
- if (! attr)
- attr = g_strdup("telephoneNumber");
+ if (! attr) {
+ if (g_str_has_prefix(plugin_type, "LDAP"))
+ attr = g_strdup(phone[VCARD2LDAP][PHONEHOME]);
+ else if (g_str_has_prefix(plugin_type, "XML"))
+ attr = g_strdup(phone[VCARD2XML][PHONEHOME]);
+ else
+ attr = g_strdup("telephoneNumber");
+ }
}
}
else if (strcmp(VCEmailAddressProp, name) == 0)
@@ -177,15 +274,12 @@
VObjectIterator iter;
gchar* family = NULL;
void* value;
-/* GSList *attribs, *abook_attribs;
- gboolean found;*/
const gchar* type;
gchar* version;
cm_return_val_if_fail(plugin != NULL, NULL);
cm_return_val_if_fail(vcard != NULL, NULL);
-/* attribs = plugin->attrib_list();*/
type = plugin->name();
version = vcard_version(vcard);
@@ -197,87 +291,61 @@
while (moreIteration(&iter)) {
VObject* prop = nextVObject(&iter);
gchar* attrib = vcard2native(prop, version, type);
-/* if (strcmp(attrib, "mobile") == 0) {
- abook_attribs = attribs;
- found = FALSE;
- while (abook_attribs && !found) {
- AttribDef* attr = (AttribDef *) abook_attribs->data;
- if (attr->type == ATTRIB_TYPE_STRING) {
- if (attr->attrib_name && g_strstr_len(attr->attrib_name,
- strlen(attr->attrib_name), attrib)) {
- value = vcard_value(prop);
- fprintf(stderr, "(mobile) adding: %s -> %s\n", attrib, (gchar *)value);
- swap_data(contact->data, attr->attrib_name, value);
- g_free(value);
- found = TRUE;
- }
- }
- abook_attribs = abook_attribs->next;
- }
- }
- else if (strcmp(attrib, "telephoneNumber") == 0) {
- abook_attribs = attribs;
- found = FALSE;
- while (abook_attribs && !found) {
- AttribDef* attr = (AttribDef *) abook_attribs->data;
- if (attr->type == ATTRIB_TYPE_STRING) {
- if (attr->attrib_name && g_strstr_len(attr->attrib_name,
- strlen(attr->attrib_name), "phone") &&
- ! g_strstr_len(attr->attrib_name,
- strlen(attr->attrib_name), "mobile")) {
- value = vcard_value(prop);
- fprintf(stderr, "(telephone) adding: %s -> %s\n", attrib, (gchar *)value);
- swap_data(contact->data, attr->attrib_name, value);
- g_free(value);
- found = TRUE;
- }
- }
- abook_attribs = abook_attribs->next;
- }
- }
- else*/ if (strcmp(attrib, "last-name") == 0) {
+ if (strcmp(attrib, "last-name") == 0) {
value = vcard_value(prop);
- if (family) {
- gchar* tmp = family;
- g_free(family);
- family = g_strconcat(tmp, " ", value, NULL);
- g_free(tmp);
+ if (value) {
+ if (family) {
+ gchar* tmp = family;
+ g_free(family);
+ family = g_strconcat(tmp, " ", value, NULL);
+ g_free(tmp);
+ }
+ else
+ family = g_strdup(value);
+ g_free(value);
}
- else
- family = g_strdup(value);
- g_free(value);
}
else if (strcmp(attrib, "addn") == 0) {
value = vcard_value(prop);
- if (family) {
- gchar* tmp = family;
- g_free(family);
- family = g_strconcat(value, " ", tmp, NULL);
- g_free(tmp);
+ if (value) {
+ if (family) {
+ gchar* tmp = family;
+ g_free(family);
+ family = g_strconcat(value, " ", tmp, NULL);
+ g_free(tmp);
+ }
+ else
+ family = g_strdup(value);
+ g_free(value);
}
- else
- family = g_strdup(value);
- g_free(value);
}
else if (strcmp(attrib, "email") == 0) {
- Email* e = g_new0(Email, 1);
value = vcard_value(prop);
- e->email = g_strdup(value);
- contact->emails = g_slist_append(contact->emails, e);
- g_free(value);
+ if (value) {
+ Email* e = g_new0(Email, 1);
+ e->email = g_strdup(value);
+ contact->emails = g_slist_append(contact->emails, e);
+ g_free(value);
+ }
}
else if (strcmp(attrib, "image") == 0) {
value = vcard_value(prop);
- gchar* image = jpeg_to_png_base64((guchar *) value, strlen((const gchar *) value));
- swap_data(contact->data, attrib, image);
- g_free(value);
+ if (value) {
+ /* Remove whitespace from badly formated string */
+ strip_whitespace((gchar **) &value);
+ debug_print("adding: %s -> %s\n", attrib, value);
+ swap_data(contact->data, attrib, value);
+ g_free(value);
+ }
}
else {
value = vcard_value(prop);
- debug_print("adding: %s -> %s\n", attrib, value);
- fprintf(stderr, "(catch all) adding: %s -> %s\n", attrib, (gchar *)value);
- swap_data(contact->data, attrib, value);
- g_free(value);
+ if (value) {
+ debug_print("adding: %s -> %s\n", attrib, value);
+ fprintf(stderr, "(catch all) adding: %s -> %s\n", attrib, (gchar *)value);
+ swap_data(contact->data, attrib, value);
+ g_free(value);
+ }
}
g_free(attrib);
}
@@ -303,7 +371,5 @@
}
}
-/* gslist_free(&attribs, attrib_def_free);*/
-
return contact;
}
More information about the Commits
mailing list