From: Jim Evins Date: Sat, 10 Dec 2005 16:26:13 +0000 (+0000) Subject: 2005-12-10 Jim Evins X-Git-Tag: glabels-2_3_0~390 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fc0b866a373a89285aa1d507d412b5a9d8e9d12d;p=glabels 2005-12-10 Jim Evins * src/merge-evolution.c: * src/merge-vcard.c: Fixed indentation. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@565 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 9d1b5ddd..bc1cc733 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,9 @@ +2005-12-10 Jim Evins + + * src/merge-evolution.c: + * src/merge-vcard.c: + Fixed indentation. + 2005-12-08 Jim Evins * libglabels/paper.c: (read_paper_files_from_dir): diff --git a/glabels2/src/merge-evolution.c b/glabels2/src/merge-evolution.c index af48eee8..a8c31c27 100644 --- a/glabels2/src/merge-evolution.c +++ b/glabels2/src/merge-evolution.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -43,19 +45,19 @@ /*===========================================*/ struct _glMergeEvolutionPrivate { - gchar *query; - EBook *book; - GList *contacts; - GList *fields; /* the fields supported by the addressbook */ + gchar *query; + EBook *book; + GList *contacts; + GList *fields; /* the fields supported by the addressbook */ }; enum { - LAST_SIGNAL + LAST_SIGNAL }; enum { - ARG_0, - ARG_QUERY, + ARG_0, + ARG_QUERY, }; /*===========================================*/ @@ -74,14 +76,14 @@ static void gl_merge_evolution_instance_init (glMergeEvolution static void gl_merge_evolution_finalize (GObject *object); static void gl_merge_evolution_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); + guint param_id, + const GValue *value, + GParamSpec *pspec); static void gl_merge_evolution_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); + guint param_id, + GValue *value, + GParamSpec *pspec); static GList *gl_merge_evolution_get_key_list (glMerge *merge); static gchar *gl_merge_evolution_get_primary_key (glMerge *merge); @@ -89,7 +91,7 @@ static void gl_merge_evolution_open (glMerge *merg static void gl_merge_evolution_close (glMerge *merge); static glMergeRecord *gl_merge_evolution_get_record (glMerge *merge); static void gl_merge_evolution_copy (glMerge *dst_merge, - glMerge *src_merge); + glMerge *src_merge); /* utility function prototypes go here */ static void free_field_list (GList *fields); @@ -101,90 +103,90 @@ static void free_field_list (GList *fields); GType gl_merge_evolution_get_type (void) { - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (glMergeEvolutionClass), - NULL, - NULL, - (GClassInitFunc) gl_merge_evolution_class_init, - NULL, - NULL, - sizeof (glMergeEvolution), - 0, - (GInstanceInitFunc) gl_merge_evolution_instance_init, - NULL - }; - - type = g_type_register_static (GL_TYPE_MERGE, - "glMergeEvolution", &info, 0); - } - - return type; + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (glMergeEvolutionClass), + NULL, + NULL, + (GClassInitFunc) gl_merge_evolution_class_init, + NULL, + NULL, + sizeof (glMergeEvolution), + 0, + (GInstanceInitFunc) gl_merge_evolution_instance_init, + NULL + }; + + type = g_type_register_static (GL_TYPE_MERGE, + "glMergeEvolution", &info, 0); + } + + return type; } static void gl_merge_evolution_class_init (glMergeEvolutionClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - glMergeClass *merge_class = (glMergeClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glMergeClass *merge_class = (glMergeClass *) klass; - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - parent_class = g_type_class_peek_parent (klass); + parent_class = g_type_class_peek_parent (klass); - object_class->set_property = gl_merge_evolution_set_property; - object_class->get_property = gl_merge_evolution_get_property; + object_class->set_property = gl_merge_evolution_set_property; + object_class->get_property = gl_merge_evolution_get_property; - g_object_class_install_property + g_object_class_install_property (object_class, ARG_QUERY, g_param_spec_string ("query", NULL, - "Query used to select records from the addressbook", - "(exists \"full_name\")", - (G_PARAM_READABLE | G_PARAM_WRITABLE))); + "Query used to select records from the addressbook", + "(exists \"full_name\")", + (G_PARAM_READABLE | G_PARAM_WRITABLE))); - object_class->finalize = gl_merge_evolution_finalize; + object_class->finalize = gl_merge_evolution_finalize; - merge_class->get_key_list = gl_merge_evolution_get_key_list; - merge_class->get_primary_key = gl_merge_evolution_get_primary_key; - merge_class->open = gl_merge_evolution_open; - merge_class->close = gl_merge_evolution_close; - merge_class->get_record = gl_merge_evolution_get_record; - merge_class->copy = gl_merge_evolution_copy; + merge_class->get_key_list = gl_merge_evolution_get_key_list; + merge_class->get_primary_key = gl_merge_evolution_get_primary_key; + merge_class->open = gl_merge_evolution_open; + merge_class->close = gl_merge_evolution_close; + merge_class->get_record = gl_merge_evolution_get_record; + merge_class->copy = gl_merge_evolution_copy; - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } static void gl_merge_evolution_instance_init (glMergeEvolution *merge_evolution) { - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - merge_evolution->private = g_new0 (glMergeEvolutionPrivate, 1); - merge_evolution->private->query = g_strdup(DEFAULT_QUERY); + merge_evolution->private = g_new0 (glMergeEvolutionPrivate, 1); + merge_evolution->private->query = g_strdup(DEFAULT_QUERY); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } static void gl_merge_evolution_finalize (GObject *object) { - glMergeEvolution *merge_evolution; + glMergeEvolution *merge_evolution; - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - g_return_if_fail (object && GL_IS_MERGE_EVOLUTION (object)); + g_return_if_fail (object && GL_IS_MERGE_EVOLUTION (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); - merge_evolution = GL_MERGE_EVOLUTION (object); - free_field_list(merge_evolution->private->fields); - g_free (merge_evolution->private->query); - g_free (merge_evolution->private); + merge_evolution = GL_MERGE_EVOLUTION (object); + free_field_list(merge_evolution->private->fields); + g_free (merge_evolution->private->query); + g_free (merge_evolution->private); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } /*--------------------------------------------------------------------------*/ @@ -192,26 +194,26 @@ gl_merge_evolution_finalize (GObject *object) /*--------------------------------------------------------------------------*/ static void gl_merge_evolution_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) + guint param_id, + const GValue *value, + GParamSpec *pspec) { - glMergeEvolution *merge_evolution; + glMergeEvolution *merge_evolution; - merge_evolution = GL_MERGE_EVOLUTION (object); + merge_evolution = GL_MERGE_EVOLUTION (object); - switch (param_id) { + switch (param_id) { - case ARG_QUERY: - g_free (merge_evolution->private->query); - merge_evolution->private->query = g_value_dup_string (value); - gl_debug (DEBUG_MERGE, "ARG \"query\" = \"%s\"", - merge_evolution->private->query); - break; + case ARG_QUERY: + g_free (merge_evolution->private->query); + merge_evolution->private->query = g_value_dup_string (value); + gl_debug (DEBUG_MERGE, "ARG \"query\" = \"%s\"", + merge_evolution->private->query); + break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; } @@ -222,19 +224,19 @@ gl_merge_evolution_set_property (GObject *object, /*--------------------------------------------------------------------------*/ static void gl_merge_evolution_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) + guint param_id, + GValue *value, + GParamSpec *pspec) { - glMergeEvolution *merge_evolution; + glMergeEvolution *merge_evolution; - merge_evolution = GL_MERGE_EVOLUTION (object); + merge_evolution = GL_MERGE_EVOLUTION (object); - switch (param_id) { + switch (param_id) { - case ARG_QUERY: - g_value_set_string (value, merge_evolution->private->query); - break; + case ARG_QUERY: + g_value_set_string (value, merge_evolution->private->query); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -250,28 +252,28 @@ gl_merge_evolution_get_property (GObject *object, static GList * gl_merge_evolution_get_key_list (glMerge *merge) { - glMergeEvolution *merge_evolution; - GList *key_list, *iter; - - gl_debug (DEBUG_MERGE, "BEGIN"); - - merge_evolution = GL_MERGE_EVOLUTION (merge); - - /* for the previously retrieved supported fileds, go through them and find - * their pretty names */ - for (iter = merge_evolution->private->fields; - iter != NULL; - iter = g_list_next(iter)) - { - key_list = g_list_prepend (key_list, - g_strdup (e_contact_pretty_name (*(EContactField *)iter->data))); - } + glMergeEvolution *merge_evolution; + GList *key_list, *iter; + + gl_debug (DEBUG_MERGE, "BEGIN"); + + merge_evolution = GL_MERGE_EVOLUTION (merge); + + /* for the previously retrieved supported fileds, go through them and find + * their pretty names */ + for (iter = merge_evolution->private->fields; + iter != NULL; + iter = g_list_next(iter)) + { + key_list = g_list_prepend (key_list, + g_strdup (e_contact_pretty_name (*(EContactField *)iter->data))); + } - key_list = g_list_reverse (key_list); + key_list = g_list_reverse (key_list); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); - return key_list; + return key_list; } /*--------------------------------------------------------------------------*/ @@ -280,7 +282,7 @@ gl_merge_evolution_get_key_list (glMerge *merge) static gchar * gl_merge_evolution_get_primary_key (glMerge *merge) { - return g_strdup (e_contact_pretty_name(E_CONTACT_FILE_AS)); + return g_strdup (e_contact_pretty_name(E_CONTACT_FILE_AS)); } /*--------------------------------------------------------------------------*/ @@ -289,92 +291,92 @@ gl_merge_evolution_get_primary_key (glMerge *merge) static void gl_merge_evolution_open (glMerge *merge) { - glMergeEvolution *merge_evolution; - EBookQuery *query; - gboolean status; - GList *fields, *iter; - EContactField *field_id; - GError *error; - - gl_debug (DEBUG_MERGE, "BEGIN"); - - merge_evolution = GL_MERGE_EVOLUTION (merge); - - query = e_book_query_from_string(merge_evolution->private->query); - if (!query) { - g_warning (_("Couldn't construct query")); - return; - } - - merge_evolution->private->book = e_book_new_system_addressbook(&error); - if (!merge_evolution->private->book) { - g_warning (_("Couldn't open addressbook: %s"), error->message); - e_book_query_unref(query); - g_error_free (error); - return; - } - - if (!e_book_open(merge_evolution->private->book, TRUE, &error)) { - g_warning (_("Couldn't open addressbook: %s"), error->message); - g_error_free (error); - e_book_query_unref(query); - g_object_unref(merge_evolution->private->book); - merge_evolution->private->book = NULL; - return; - } - - /* fetch the list of fields supported by this address book */ - status = e_book_get_supported_fields(merge_evolution->private->book, - &fields, &error); - if (status == FALSE) { - g_warning (_("Couldn't list available fields: %s"), error->message); - g_error_free (error); - e_book_query_unref(query); - g_object_unref(merge_evolution->private->book); - merge_evolution->private->book = NULL; - return; - } - - /* generate a list of field_ids, and put that into private->fields */ - for (iter = fields; iter != NULL; iter = g_list_next(iter)) { - field_id = g_new(EContactField, 1); - *field_id = e_contact_field_id(iter->data); - - /* above this value, the data aren't strings anymore */ - if (*field_id >= E_CONTACT_LAST_SIMPLE_STRING) { - g_free (field_id); - continue; - } - - merge_evolution->private->fields = - g_list_prepend(merge_evolution->private->fields, field_id); - } - free_field_list(fields); /* don't need the list of names anymore */ - - gl_debug(DEBUG_MERGE, "Field list length: %d", g_list_length(merge_evolution->private->fields)); - - /* finally retrieve the contacts */ - status = e_book_get_contacts (merge_evolution->private->book, - query, - &merge_evolution->private->contacts, - &error); - if (status == FALSE) { - g_warning (_("Couldn't get contacts: %s"), error->message); - g_error_free (error); - e_book_query_unref(query); - free_field_list(merge_evolution->private->fields); - g_object_unref(merge_evolution->private->book); - merge_evolution->private->book = NULL; - - return; - } - - e_book_query_unref(query); - - gl_debug (DEBUG_MERGE, "END"); - - return; - /* XXX I should probably sort the list by name (or the file-as element)*/ + glMergeEvolution *merge_evolution; + EBookQuery *query; + gboolean status; + GList *fields, *iter; + EContactField *field_id; + GError *error; + + gl_debug (DEBUG_MERGE, "BEGIN"); + + merge_evolution = GL_MERGE_EVOLUTION (merge); + + query = e_book_query_from_string(merge_evolution->private->query); + if (!query) { + g_warning (_("Couldn't construct query")); + return; + } + + merge_evolution->private->book = e_book_new_system_addressbook(&error); + if (!merge_evolution->private->book) { + g_warning (_("Couldn't open addressbook: %s"), error->message); + e_book_query_unref(query); + g_error_free (error); + return; + } + + if (!e_book_open(merge_evolution->private->book, TRUE, &error)) { + g_warning (_("Couldn't open addressbook: %s"), error->message); + g_error_free (error); + e_book_query_unref(query); + g_object_unref(merge_evolution->private->book); + merge_evolution->private->book = NULL; + return; + } + + /* fetch the list of fields supported by this address book */ + status = e_book_get_supported_fields(merge_evolution->private->book, + &fields, &error); + if (status == FALSE) { + g_warning (_("Couldn't list available fields: %s"), error->message); + g_error_free (error); + e_book_query_unref(query); + g_object_unref(merge_evolution->private->book); + merge_evolution->private->book = NULL; + return; + } + + /* generate a list of field_ids, and put that into private->fields */ + for (iter = fields; iter != NULL; iter = g_list_next(iter)) { + field_id = g_new(EContactField, 1); + *field_id = e_contact_field_id(iter->data); + + /* above this value, the data aren't strings anymore */ + if (*field_id >= E_CONTACT_LAST_SIMPLE_STRING) { + g_free (field_id); + continue; + } + + merge_evolution->private->fields = + g_list_prepend(merge_evolution->private->fields, field_id); + } + free_field_list(fields); /* don't need the list of names anymore */ + + gl_debug(DEBUG_MERGE, "Field list length: %d", g_list_length(merge_evolution->private->fields)); + + /* finally retrieve the contacts */ + status = e_book_get_contacts (merge_evolution->private->book, + query, + &merge_evolution->private->contacts, + &error); + if (status == FALSE) { + g_warning (_("Couldn't get contacts: %s"), error->message); + g_error_free (error); + e_book_query_unref(query); + free_field_list(merge_evolution->private->fields); + g_object_unref(merge_evolution->private->book); + merge_evolution->private->book = NULL; + + return; + } + + e_book_query_unref(query); + + gl_debug (DEBUG_MERGE, "END"); + + return; + /* XXX I should probably sort the list by name (or the file-as element)*/ } /*--------------------------------------------------------------------------*/ @@ -383,25 +385,25 @@ gl_merge_evolution_open (glMerge *merge) static void gl_merge_evolution_close (glMerge *merge) { - glMergeEvolution *merge_evolution; - GList *iter; + glMergeEvolution *merge_evolution; + GList *iter; - merge_evolution = GL_MERGE_EVOLUTION (merge); + merge_evolution = GL_MERGE_EVOLUTION (merge); - /* unref all of the objects created in _open */ - g_object_unref(merge_evolution->private->book); - merge_evolution->private->book = NULL; + /* unref all of the objects created in _open */ + g_object_unref(merge_evolution->private->book); + merge_evolution->private->book = NULL; - for (iter = merge_evolution->private->contacts; - iter != NULL; - iter = g_list_next(iter)) - { - EContact *contact = E_CONTACT (iter->data); + for (iter = merge_evolution->private->contacts; + iter != NULL; + iter = g_list_next(iter)) + { + EContact *contact = E_CONTACT (iter->data); - g_object_unref(contact); - } - g_list_free(merge_evolution->private->contacts); - merge_evolution->private->contacts = NULL; + g_object_unref(contact); + } + g_list_free(merge_evolution->private->contacts); + merge_evolution->private->contacts = NULL; } /*--------------------------------------------------------------------------*/ @@ -410,55 +412,55 @@ gl_merge_evolution_close (glMerge *merge) static glMergeRecord * gl_merge_evolution_get_record (glMerge *merge) { - glMergeEvolution *merge_evolution; - glMergeRecord *record; - glMergeField *field; - EContactField field_id; - - GList *head, *iter; - EContact *contact; - - merge_evolution = GL_MERGE_EVOLUTION (merge); - - head = merge_evolution->private->contacts; - if (head == NULL) { - return NULL; /* past the last record */ - } - contact = E_CONTACT(head->data); - - record = g_new0 (glMergeRecord, 1); - record->select_flag = TRUE; - - /* Take the interesting fields one by one from the contact, and put them - * into the glMergeRecord structure. When done, free up the resources for - * that contact */ - - /* iterate through the supported fields, and add them to the list */ - for (iter = merge_evolution->private->fields; - iter != NULL; - iter = g_list_next(iter)) - { - gchar *value; - field_id = *(EContactField *)iter->data; - value = g_strdup (e_contact_get_const (contact, field_id)); - - if (value) { - field = g_new0 (glMergeField, 1); - field->key = g_strdup (e_contact_pretty_name (field_id)); - field->value = value; - record->field_list = g_list_prepend (record->field_list, field); - } - } - - record->field_list = g_list_reverse (record->field_list); - - /* do a destructive read */ - g_object_unref (contact); - merge_evolution->private->contacts = - g_list_remove_link (merge_evolution->private->contacts, head); - g_list_free_1 (head); - - return record; + glMergeEvolution *merge_evolution; + glMergeRecord *record; + glMergeField *field; + EContactField field_id; + + GList *head, *iter; + EContact *contact; + + merge_evolution = GL_MERGE_EVOLUTION (merge); + + head = merge_evolution->private->contacts; + if (head == NULL) { + return NULL; /* past the last record */ + } + contact = E_CONTACT(head->data); + + record = g_new0 (glMergeRecord, 1); + record->select_flag = TRUE; + + /* Take the interesting fields one by one from the contact, and put them + * into the glMergeRecord structure. When done, free up the resources for + * that contact */ + + /* iterate through the supported fields, and add them to the list */ + for (iter = merge_evolution->private->fields; + iter != NULL; + iter = g_list_next(iter)) + { + gchar *value; + field_id = *(EContactField *)iter->data; + value = g_strdup (e_contact_get_const (contact, field_id)); + + if (value) { + field = g_new0 (glMergeField, 1); + field->key = g_strdup (e_contact_pretty_name (field_id)); + field->value = value; + record->field_list = g_list_prepend (record->field_list, field); + } + } + + record->field_list = g_list_reverse (record->field_list); + + /* do a destructive read */ + g_object_unref (contact); + merge_evolution->private->contacts = + g_list_remove_link (merge_evolution->private->contacts, head); + g_list_free_1 (head); + + return record; } /*---------------------------------------------------------------------------*/ @@ -466,37 +468,37 @@ gl_merge_evolution_get_record (glMerge *merge) /*---------------------------------------------------------------------------*/ static void gl_merge_evolution_copy (glMerge *dst_merge, - glMerge *src_merge) + glMerge *src_merge) { - GList *src_iter, *dst_iter; + GList *src_iter, *dst_iter; - gl_debug (DEBUG_MERGE, "BEGIN"); + gl_debug (DEBUG_MERGE, "BEGIN"); - glMergeEvolution *dst_merge_evolution; - glMergeEvolution *src_merge_evolution; + glMergeEvolution *dst_merge_evolution; + glMergeEvolution *src_merge_evolution; - dst_merge_evolution = GL_MERGE_EVOLUTION (dst_merge); - src_merge_evolution = GL_MERGE_EVOLUTION (src_merge); + dst_merge_evolution = GL_MERGE_EVOLUTION (dst_merge); + src_merge_evolution = GL_MERGE_EVOLUTION (src_merge); - dst_merge_evolution->private->query = g_strdup(src_merge_evolution->private->query); + dst_merge_evolution->private->query = g_strdup(src_merge_evolution->private->query); - dst_merge_evolution->private->fields = g_list_copy(src_merge_evolution->private->fields); - for (src_iter = src_merge_evolution->private->fields, - dst_iter = dst_merge_evolution->private->fields; - src_iter != NULL && dst_iter != NULL; - src_iter = g_list_next(src_iter), dst_iter = g_list_next(dst_iter)) - { - dst_iter->data = g_new(EContactField, 1); - if (src_iter->data) { /* this better not be null, but... */ - memcpy(dst_iter->data, src_iter->data, sizeof(EContactField)); - } - } + dst_merge_evolution->private->fields = g_list_copy(src_merge_evolution->private->fields); + for (src_iter = src_merge_evolution->private->fields, + dst_iter = dst_merge_evolution->private->fields; + src_iter != NULL && dst_iter != NULL; + src_iter = g_list_next(src_iter), dst_iter = g_list_next(dst_iter)) + { + dst_iter->data = g_new(EContactField, 1); + if (src_iter->data) { /* this better not be null, but... */ + memcpy(dst_iter->data, src_iter->data, sizeof(EContactField)); + } + } - /* I don't know that there's a good way to do a deep copy of the various - * libebook structures/objects, so I'm just going to leave them out. They - * are all regenerated on gl_merge_evolution_open, anyway */ + /* I don't know that there's a good way to do a deep copy of the various + * libebook structures/objects, so I'm just going to leave them out. They + * are all regenerated on gl_merge_evolution_open, anyway */ - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } /*---------------------------------------------------------------------------*/ @@ -505,16 +507,16 @@ gl_merge_evolution_copy (glMerge *dst_merge, static void free_field_list (GList *fields) { - GList *iter; - - for (iter = fields; iter != NULL; iter = g_list_next(iter)) - { - if (iter->data) { - g_free(iter->data); - } - } - g_list_free(fields); - fields = NULL; + GList *iter; + + for (iter = fields; iter != NULL; iter = g_list_next(iter)) + { + if (iter->data) { + g_free(iter->data); + } + } + g_list_free(fields); + fields = NULL; } diff --git a/glabels2/src/merge-vcard.c b/glabels2/src/merge-vcard.c index 490d29a7..3ab663d6 100644 --- a/glabels2/src/merge-vcard.c +++ b/glabels2/src/merge-vcard.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + /* * (GLABELS) Label and Business Card Creation program for GNOME * @@ -41,15 +43,15 @@ /*===========================================*/ struct _glMergeVCardPrivate { - FILE *fp; + FILE *fp; }; enum { - LAST_SIGNAL + LAST_SIGNAL }; enum { - ARG_0, + ARG_0, }; /*===========================================*/ @@ -68,14 +70,14 @@ static void gl_merge_vcard_instance_init (glMergeVCard *object) static void gl_merge_vcard_finalize (GObject *object); static void gl_merge_vcard_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); + guint param_id, + const GValue *value, + GParamSpec *pspec); static void gl_merge_vcard_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); + guint param_id, + GValue *value, + GParamSpec *pspec); static GList *gl_merge_vcard_get_key_list (glMerge *merge); static gchar *gl_merge_vcard_get_primary_key (glMerge *merge); @@ -83,7 +85,7 @@ static void gl_merge_vcard_open (glMerge *merge); static void gl_merge_vcard_close (glMerge *merge); static glMergeRecord *gl_merge_vcard_get_record (glMerge *merge); static void gl_merge_vcard_copy (glMerge *dst_merge, - glMerge *src_merge); + glMerge *src_merge); static char * parse_next_vcard (FILE *fp); /* utility function prototypes go here */ @@ -94,79 +96,79 @@ static char * parse_next_vcard (FILE *fp); GType gl_merge_vcard_get_type (void) { - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (glMergeVCardClass), - NULL, - NULL, - (GClassInitFunc) gl_merge_vcard_class_init, - NULL, - NULL, - sizeof (glMergeVCard), - 0, - (GInstanceInitFunc) gl_merge_vcard_instance_init, - NULL - }; - - type = g_type_register_static (GL_TYPE_MERGE, - "glMergeVCard", &info, 0); - } - - return type; + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (glMergeVCardClass), + NULL, + NULL, + (GClassInitFunc) gl_merge_vcard_class_init, + NULL, + NULL, + sizeof (glMergeVCard), + 0, + (GInstanceInitFunc) gl_merge_vcard_instance_init, + NULL + }; + + type = g_type_register_static (GL_TYPE_MERGE, + "glMergeVCard", &info, 0); + } + + return type; } static void gl_merge_vcard_class_init (glMergeVCardClass *klass) { - GObjectClass *object_class = (GObjectClass *) klass; - glMergeClass *merge_class = (glMergeClass *) klass; + GObjectClass *object_class = (GObjectClass *) klass; + glMergeClass *merge_class = (glMergeClass *) klass; - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - parent_class = g_type_class_peek_parent (klass); + parent_class = g_type_class_peek_parent (klass); - object_class->set_property = gl_merge_vcard_set_property; - object_class->get_property = gl_merge_vcard_get_property; + object_class->set_property = gl_merge_vcard_set_property; + object_class->get_property = gl_merge_vcard_get_property; - object_class->finalize = gl_merge_vcard_finalize; + object_class->finalize = gl_merge_vcard_finalize; - merge_class->get_key_list = gl_merge_vcard_get_key_list; - merge_class->get_primary_key = gl_merge_vcard_get_primary_key; - merge_class->open = gl_merge_vcard_open; - merge_class->close = gl_merge_vcard_close; - merge_class->get_record = gl_merge_vcard_get_record; - merge_class->copy = gl_merge_vcard_copy; + merge_class->get_key_list = gl_merge_vcard_get_key_list; + merge_class->get_primary_key = gl_merge_vcard_get_primary_key; + merge_class->open = gl_merge_vcard_open; + merge_class->close = gl_merge_vcard_close; + merge_class->get_record = gl_merge_vcard_get_record; + merge_class->copy = gl_merge_vcard_copy; - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } static void gl_merge_vcard_instance_init (glMergeVCard *merge_vcard) { - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - merge_vcard->private = g_new0 (glMergeVCardPrivate, 1); + merge_vcard->private = g_new0 (glMergeVCardPrivate, 1); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } static void gl_merge_vcard_finalize (GObject *object) { - glMergeVCard *merge_vcard; + glMergeVCard *merge_vcard; - gl_debug (DEBUG_MERGE, "START"); + gl_debug (DEBUG_MERGE, "START"); - g_return_if_fail (object && GL_IS_MERGE_VCARD (object)); + g_return_if_fail (object && GL_IS_MERGE_VCARD (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (parent_class)->finalize (object); - merge_vcard = GL_MERGE_VCARD (object); - g_free (merge_vcard->private); + merge_vcard = GL_MERGE_VCARD (object); + g_free (merge_vcard->private); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); } /*--------------------------------------------------------------------------*/ @@ -174,19 +176,19 @@ gl_merge_vcard_finalize (GObject *object) /*--------------------------------------------------------------------------*/ static void gl_merge_vcard_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) + guint param_id, + const GValue *value, + GParamSpec *pspec) { - glMergeVCard *merge_vcard; + glMergeVCard *merge_vcard; - merge_vcard = GL_MERGE_VCARD (object); + merge_vcard = GL_MERGE_VCARD (object); - switch (param_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } + switch (param_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } } /*--------------------------------------------------------------------------*/ @@ -194,19 +196,19 @@ gl_merge_vcard_set_property (GObject *object, /*--------------------------------------------------------------------------*/ static void gl_merge_vcard_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) + guint param_id, + GValue *value, + GParamSpec *pspec) { - glMergeVCard *merge_vcard; + glMergeVCard *merge_vcard; - merge_vcard = GL_MERGE_VCARD (object); + merge_vcard = GL_MERGE_VCARD (object); - switch (param_id) { + switch (param_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; - } + } } @@ -217,23 +219,23 @@ gl_merge_vcard_get_property (GObject *object, static GList * gl_merge_vcard_get_key_list (glMerge *merge) { - glMergeVCard *merge_vcard; - GList *key_list; - - gl_debug (DEBUG_MERGE, "BEGIN"); + glMergeVCard *merge_vcard; + GList *key_list; + + gl_debug (DEBUG_MERGE, "BEGIN"); - merge_vcard = GL_MERGE_VCARD (merge); + merge_vcard = GL_MERGE_VCARD (merge); - /* extremely simple approach until I can list the available keys from the - * server, and return them. */ - key_list = NULL; - key_list = g_list_append (key_list, g_strdup ("full_name")); - key_list = g_list_append (key_list, g_strdup ("home_address")); - key_list = g_list_append (key_list, g_strdup ("work_address")); + /* extremely simple approach until I can list the available keys from the + * server, and return them. */ + key_list = NULL; + key_list = g_list_append (key_list, g_strdup ("full_name")); + key_list = g_list_append (key_list, g_strdup ("home_address")); + key_list = g_list_append (key_list, g_strdup ("work_address")); - gl_debug (DEBUG_MERGE, "END"); + gl_debug (DEBUG_MERGE, "END"); - return key_list; + return key_list; } /* TODO? */ @@ -243,8 +245,8 @@ gl_merge_vcard_get_key_list (glMerge *merge) static gchar * gl_merge_vcard_get_primary_key (glMerge *merge) { - /* For now, let's always assume the full name is the primary key. */ - return g_strdup ("full_name"); + /* For now, let's always assume the full name is the primary key. */ + return g_strdup ("full_name"); } /*--------------------------------------------------------------------------*/ @@ -253,20 +255,20 @@ gl_merge_vcard_get_primary_key (glMerge *merge) static void gl_merge_vcard_open (glMerge *merge) { - glMergeVCard *merge_vcard; - gchar *src; + glMergeVCard *merge_vcard; + gchar *src; - merge_vcard = GL_MERGE_VCARD (merge); + merge_vcard = GL_MERGE_VCARD (merge); - src = gl_merge_get_src (merge); + src = gl_merge_get_src (merge); - if (src != NULL) { - merge_vcard->private->fp = fopen (src, "r"); - } + if (src != NULL) { + merge_vcard->private->fp = fopen (src, "r"); + } - g_free (src); + g_free (src); - return; + return; } /*--------------------------------------------------------------------------*/ @@ -275,14 +277,14 @@ gl_merge_vcard_open (glMerge *merge) static void gl_merge_vcard_close (glMerge *merge) { - glMergeVCard *merge_vcard; + glMergeVCard *merge_vcard; - merge_vcard = GL_MERGE_VCARD (merge); + merge_vcard = GL_MERGE_VCARD (merge); - if (merge_vcard->private->fp != NULL) { - fclose (merge_vcard->private->fp); - merge_vcard->private->fp = NULL; - } + if (merge_vcard->private->fp != NULL) { + fclose (merge_vcard->private->fp); + merge_vcard->private->fp = NULL; + } } /*--------------------------------------------------------------------------*/ @@ -291,57 +293,57 @@ gl_merge_vcard_close (glMerge *merge) static glMergeRecord * gl_merge_vcard_get_record (glMerge *merge) { - glMergeVCard *merge_vcard; - glMergeRecord *record; - glMergeField *field; + glMergeVCard *merge_vcard; + glMergeRecord *record; + glMergeField *field; - char *vcard; - EContact *contact; + char *vcard; + EContact *contact; - merge_vcard = GL_MERGE_VCARD (merge); + merge_vcard = GL_MERGE_VCARD (merge); - vcard = parse_next_vcard(merge_vcard->private->fp); - if (vcard == NULL || vcard[0] == '\0') { - return NULL; /* EOF */ - } - contact = e_contact_new_from_vcard(vcard); - if (contact == NULL) { - return NULL; /* invalid vcard */ - } + vcard = parse_next_vcard(merge_vcard->private->fp); + if (vcard == NULL || vcard[0] == '\0') { + return NULL; /* EOF */ + } + contact = e_contact_new_from_vcard(vcard); + if (contact == NULL) { + return NULL; /* invalid vcard */ + } - record = g_new0 (glMergeRecord, 1); - record->select_flag = TRUE; + record = g_new0 (glMergeRecord, 1); + record->select_flag = TRUE; - /* Take the interesting fields one by one from the contact, and put them - * into the glMergeRecord structure. When done, free up the resources for - * that contact */ + /* Take the interesting fields one by one from the contact, and put them + * into the glMergeRecord structure. When done, free up the resources for + * that contact */ - /* get the full name */ - field = g_new0 (glMergeField, 1); - field->key = g_strdup ("full_name"); - field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_FULL_NAME)); + /* get the full name */ + field = g_new0 (glMergeField, 1); + field->key = g_strdup ("full_name"); + field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_FULL_NAME)); - record->field_list = g_list_append (record->field_list, field); + record->field_list = g_list_append (record->field_list, field); - /* get the home address */ - field = g_new0 (glMergeField, 1); - field->key = g_strdup ("home_address"); - field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_ADDRESS_LABEL_HOME)); + /* get the home address */ + field = g_new0 (glMergeField, 1); + field->key = g_strdup ("home_address"); + field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_ADDRESS_LABEL_HOME)); - record->field_list = g_list_append (record->field_list, field); + record->field_list = g_list_append (record->field_list, field); - /* get the work address */ - field = g_new0 (glMergeField, 1); - field->key = g_strdup ("work_address"); - field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_ADDRESS_LABEL_WORK)); + /* get the work address */ + field = g_new0 (glMergeField, 1); + field->key = g_strdup ("work_address"); + field->value = g_strdup (e_contact_get_const(contact, E_CONTACT_ADDRESS_LABEL_WORK)); - record->field_list = g_list_append (record->field_list, field); + record->field_list = g_list_append (record->field_list, field); - /* free the contact */ - g_object_unref (contact); - g_free(vcard); + /* free the contact */ + g_object_unref (contact); + g_free(vcard); - return record; + return record; } /*---------------------------------------------------------------------------*/ @@ -349,13 +351,13 @@ gl_merge_vcard_get_record (glMerge *merge) /*---------------------------------------------------------------------------*/ static void gl_merge_vcard_copy (glMerge *dst_merge, - glMerge *src_merge) + glMerge *src_merge) { - glMergeVCard *dst_merge_vcard; - glMergeVCard *src_merge_vcard; + glMergeVCard *dst_merge_vcard; + glMergeVCard *src_merge_vcard; - dst_merge_vcard = GL_MERGE_VCARD (dst_merge); - src_merge_vcard = GL_MERGE_VCARD (src_merge); + dst_merge_vcard = GL_MERGE_VCARD (dst_merge); + src_merge_vcard = GL_MERGE_VCARD (src_merge); } /*---------------------------------------------------------------------------*/ @@ -363,44 +365,46 @@ gl_merge_vcard_copy (glMerge *dst_merge, /* Arguments: */ /* fp - an open stream to parse in put from */ /* Returns: */ -/* a pointer to the buffer containing the vcard, the empty string on */ -/* end-of-file or error, this buffer needs to be free by the caller */ +/* a pointer to the buffer containing the vcard, the empty string on */ +/* end-of-file or error, this buffer needs to be free by the caller */ /*---------------------------------------------------------------------------*/ static char * parse_next_vcard (FILE *fp) { - gboolean found_begin = FALSE, found_end = FALSE; - char *vcard; - char line[512]; - int size = 2048, cursize = 0; - - /* if no source has been set up, don't try to read from the file */ - if (!fp) { - return NULL; - } - - vcard = g_malloc0(size); - - while (fgets(line, sizeof(line), fp) && found_end == FALSE) { - if (found_begin == TRUE) { - if (g_str_has_prefix(line, "END:VCARD")) { found_end = TRUE; } - } else { - if (g_str_has_prefix(line, "BEGIN:VCARD")) { found_begin = TRUE; } - else { continue; }/* skip lines not in a vcard */ - } - - /* if the buffer passed us isn't big enough, reallocate it */ - cursize += strlen(line); - if (cursize >= size) { - size *= 2; - vcard = (char *)g_realloc(vcard, size); /* aborts program on error */ - } - - /* add the line (or portion thereof) to the vcard */ - strncat(vcard, line, size); - } - - return vcard; + gboolean found_begin = FALSE; + gboolean found_end = FALSE; + char *vcard; + char line[512]; + int size = 2048; + int cursize = 0; + + /* if no source has been set up, don't try to read from the file */ + if (!fp) { + return NULL; + } + + vcard = g_malloc0(size); + + while (fgets(line, sizeof(line), fp) && found_end == FALSE) { + if (found_begin == TRUE) { + if (g_str_has_prefix(line, "END:VCARD")) { found_end = TRUE; } + } else { + if (g_str_has_prefix(line, "BEGIN:VCARD")) { found_begin = TRUE; } + else { continue; }/* skip lines not in a vcard */ + } + + /* if the buffer passed us isn't big enough, reallocate it */ + cursize += strlen(line); + if (cursize >= size) { + size *= 2; + vcard = (char *)g_realloc(vcard, size); /* aborts program on error */ + } + + /* add the line (or portion thereof) to the vcard */ + strncat(vcard, line, size); + } + + return vcard; }