]> git.sur5r.net Git - glabels/blobdiff - src/merge-evolution.c
Imported Upstream version 3.0.0
[glabels] / src / merge-evolution.c
index bf99e1bb8a81565c0f715e95d5fac3b44555b1ae..bd1448338f94bc469599340e4952d162dd51add9 100644 (file)
@@ -1,29 +1,25 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  merge_evolution.c:  evolution merge backend module
- *
- *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
+ *  merge-evolution.h
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *  and
  *  Copyright (C) 2005  Austin Henry <ahenry@users.sourceforge.net>
  *  and
  *  Copyright (C) 2007  Peter Cherriman <glabels-devel2712@bubieyehyeh.me.uk>
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
 #include <glib/gi18n.h>
 #include <stdio.h>
 #include <string.h>
-#include <libglabels/str.h>
+
+#include <libglabels.h>
 
 #include "debug.h"
 
 #define DEFAULT_QUERY "(exists \"full_name\")"
 
+
 /*===========================================*/
 /* Private types                             */
 /*===========================================*/
@@ -60,9 +58,10 @@ enum {
 
 enum {
         ARG_0,
-        ARG_QUERY,
+        ARG_QUERY
 };
 
+
 /*===========================================*/
 /* Private globals                           */
 /*===========================================*/
@@ -83,22 +82,22 @@ static void           gl_merge_evolution_get_property    (GObject          *obje
                                                           GValue           *value,
                                                           GParamSpec       *pspec);
 
-static GList         *gl_merge_evolution_get_key_list    (glMerge          *merge);
-static gchar         *gl_merge_evolution_get_primary_key (glMerge          *merge);
+static GList         *gl_merge_evolution_get_key_list    (const glMerge    *merge);
+static gchar         *gl_merge_evolution_get_primary_key (const glMerge    *merge);
 static void           gl_merge_evolution_open            (glMerge          *merge);
 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);
+                                                          const glMerge    *src_merge);
 
 /* utility function prototypes go here */
 static void           free_field_list                    (GList *fields);
 
-\f
+
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
 /*****************************************************************************/
-G_DEFINE_TYPE (glMergeEvolution, gl_merge_evolution, GL_TYPE_MERGE);
+G_DEFINE_TYPE (glMergeEvolution, gl_merge_evolution, GL_TYPE_MERGE)
 
 static void
 gl_merge_evolution_class_init (glMergeEvolutionClass *class)
@@ -133,6 +132,7 @@ gl_merge_evolution_class_init (glMergeEvolutionClass *class)
         gl_debug (DEBUG_MERGE, "END");
 }
 
+
 static void
 gl_merge_evolution_init (glMergeEvolution *merge_evolution)
 {
@@ -144,6 +144,7 @@ gl_merge_evolution_init (glMergeEvolution *merge_evolution)
         gl_debug (DEBUG_MERGE, "END");
 }
 
+
 static void
 gl_merge_evolution_finalize (GObject *object)
 {
@@ -162,6 +163,7 @@ gl_merge_evolution_finalize (GObject *object)
         gl_debug (DEBUG_MERGE, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Set argument.                                                            */
 /*--------------------------------------------------------------------------*/
@@ -192,6 +194,7 @@ gl_merge_evolution_set_property (GObject      *object,
 
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Get argument.                                                            */
 /*--------------------------------------------------------------------------*/
@@ -219,11 +222,12 @@ gl_merge_evolution_get_property (GObject     *object,
 
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Get key list.                                                            */
 /*--------------------------------------------------------------------------*/
 static GList *
-gl_merge_evolution_get_key_list (glMerge *merge)
+gl_merge_evolution_get_key_list (const glMerge *merge)
 {
         glMergeEvolution   *merge_evolution;
         GList              *key_list = NULL;
@@ -250,43 +254,46 @@ gl_merge_evolution_get_key_list (glMerge *merge)
         return key_list;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Get "primary" key.                                                       */
 /*--------------------------------------------------------------------------*/
 static gchar *
-gl_merge_evolution_get_primary_key (glMerge *merge)
+gl_merge_evolution_get_primary_key (const glMerge *merge)
 {
         return g_strdup (e_contact_pretty_name(E_CONTACT_FILE_AS));
 }
 
+
 /* Sort compare function for sorting contacts by file-as element
  * by Peter Cherriman (PJC)
  * called by GList* g_list_sort(GList *list, sort_contact_by_file_as);
  */
 static gint sort_contact_by_file_as(gconstpointer *a, gconstpointer *b)
 {
-  /* 
-   * Returns :         negative value if a < b; zero if a = b; positive value if a > b 
-   */
+        /*
+         * Returns :   negative value if a < b; zero if a = b; positive value if a > b 
+         */
 
-  // Check and cast a and b to EContact
-  EContact *contact_a = E_CONTACT(a);
-  EContact *contact_b = E_CONTACT(b);
+        /* Check and cast a and b to EContact */
+        EContact *contact_a = E_CONTACT(a);
+        EContact *contact_b = E_CONTACT(b);
 
-  // Extract file_as for each contact and compare...
-  gchar *a_file_as = e_contact_get (contact_a, E_CONTACT_FILE_AS);
-  gchar *b_file_as = e_contact_get (contact_b, E_CONTACT_FILE_AS);
-  gint res = lgl_str_utf8_casecmp(a_file_as, b_file_as);
+        /* Extract file_as for each contact and compare... */
+        gchar *a_file_as = e_contact_get (contact_a, E_CONTACT_FILE_AS);
+        gchar *b_file_as = e_contact_get (contact_b, E_CONTACT_FILE_AS);
+        gint res = lgl_str_utf8_casecmp(a_file_as, b_file_as);
 
-  gl_debug(DEBUG_MERGE, "Sort comparing contacts '%s' and '%s' = %d", a_file_as, b_file_as, res);
+        gl_debug(DEBUG_MERGE, "Sort comparing contacts '%s' and '%s' = %d", a_file_as, b_file_as, res);
 
-  // free file_as strings created earlier....
-  g_free (a_file_as);
-  g_free (b_file_as);
+        /* free file_as strings created earlier.... */
+        g_free (a_file_as);
+        g_free (b_file_as);
 
-  return res;
+        return res;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Open merge source.                                                       */
 /*--------------------------------------------------------------------------*/
@@ -306,13 +313,13 @@ gl_merge_evolution_open (glMerge *merge)
 
         query = e_book_query_from_string(merge_evolution->priv->query);
         if (!query) {
-                g_warning (_("Couldn't construct query"));
+                g_warning ("Couldn't construct query");
                 return;
         }
 
         merge_evolution->priv->book = e_book_new_system_addressbook(&error);
         if (!merge_evolution->priv->book) {
-                g_warning (_("Couldn't open addressbook."));
+                g_warning ("Couldn't open addressbook.");
                 if (error)
                 {
                         g_warning ("e_book_new_system_addressbook: %s", error->message);
@@ -323,7 +330,7 @@ gl_merge_evolution_open (glMerge *merge)
         }
 
         if (!e_book_open(merge_evolution->priv->book, FALSE, &error)) {
-                g_warning (_("Couldn't open addressbook."));
+                g_warning ("Couldn't open addressbook.");
                 if (error)
                 {
                         g_warning ("e_book_open: %s", error->message);
@@ -338,7 +345,7 @@ gl_merge_evolution_open (glMerge *merge)
         /* fetch the list of fields supported by this address book */
         status = e_book_get_supported_fields(merge_evolution->priv->book, &fields, &error);
         if (status == FALSE) {
-                g_warning (_("Couldn't list available fields."));
+                g_warning ("Couldn't list available fields.");
                 if (error)
                 {
                         g_warning ("e_book_get_supported_fields: %s", error->message);
@@ -356,7 +363,7 @@ gl_merge_evolution_open (glMerge *merge)
                 *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) {
+                if (*field_id > E_CONTACT_LAST_SIMPLE_STRING) {
                         g_free (field_id);
                         continue;
                 }
@@ -374,7 +381,7 @@ gl_merge_evolution_open (glMerge *merge)
                                       &merge_evolution->priv->contacts,
                                       &error);
         if (status == FALSE) {
-                g_warning (_("Couldn't get contacts."));
+                g_warning ("Couldn't get contacts.");
                 if (error)
                 {
                         g_warning ("e_book_get_contacts: %s", error->message);
@@ -402,6 +409,7 @@ gl_merge_evolution_open (glMerge *merge)
         return;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Close merge source.                                                      */
 /*--------------------------------------------------------------------------*/
@@ -429,6 +437,7 @@ gl_merge_evolution_close (glMerge *merge)
         merge_evolution->priv->contacts = NULL;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* Get next record from merge source, NULL if no records left (i.e EOF)     */
 /*--------------------------------------------------------------------------*/
@@ -486,20 +495,21 @@ gl_merge_evolution_get_record (glMerge *merge)
         return record;
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* Copy merge_evolution specific fields.                                     */
 /*---------------------------------------------------------------------------*/
 static void
-gl_merge_evolution_copy (glMerge *dst_merge,
-                    glMerge *src_merge)
+gl_merge_evolution_copy (glMerge       *dst_merge,
+                         const glMerge *src_merge)
 {
         GList *src_iter, *dst_iter;
 
-        gl_debug (DEBUG_MERGE, "BEGIN");
-
         glMergeEvolution *dst_merge_evolution;
         glMergeEvolution *src_merge_evolution;
 
+        gl_debug (DEBUG_MERGE, "BEGIN");
+
         dst_merge_evolution = GL_MERGE_EVOLUTION (dst_merge);
         src_merge_evolution = GL_MERGE_EVOLUTION (src_merge);
 
@@ -524,6 +534,7 @@ gl_merge_evolution_copy (glMerge *dst_merge,
         gl_debug (DEBUG_MERGE, "END");
 }
 
+
 /*---------------------------------------------------------------------------*/
 /* Free the list of supported fields                                         */
 /*---------------------------------------------------------------------------*/
@@ -544,3 +555,14 @@ free_field_list (GList *fields)
 
 
 #endif /* HAVE_LIBEBOOK */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */