Index: /trunk/libraries/libmokojournal/mokojournal/Makefile.am
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/Makefile.am	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/Makefile.am	(revision 2484)
@@ -0,0 +1,13 @@
+lib_LTLIBRARIES=libmokojournal.la
+
+public_headers=moko-journal.h moko-time.h
+sources=moko-journal.c moko-time.c
+
+libmokojournal_la_SOURCES= $(sources) $(public_headers)
+libmokojournal_la_LIBADD=
+libmokojournal_la_LDFLAGS= -version-info 0:0:0
+AM_CFLAGS = -Wall -pedantic -std=c99
+
+libmokojournalheadersdir=$(includedir)/mokojournal
+libmokojournalheaders_DATA=$(public_headers)
+
Index: /trunk/libraries/libmokojournal/mokojournal/moko-journal.c
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/moko-journal.c	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/moko-journal.c	(revision 2484)
@@ -0,0 +1,2076 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <string.h>
+#include <strings.h>
+#include <glib-object.h>
+#include <libical/icaltypes.h>
+#include <libecal/e-cal.h>
+#include <libecal/e-cal-component.h>
+#include "moko-journal.h"
+#include "moko-time-priv.h"
+
+#define WIFI_AP_MAC_ADDR_LEN 48
+
+struct _MokoJournal
+{
+  ECal *ecal ;
+  ECalView *ecal_view ;
+  GList *entries_to_delete ;
+  GArray *entries ;
+  
+  /* Callbacks */
+  MokoJournalEntryAddedFunc added_func ;
+  gpointer added_data ;
+
+  MokoJournalEntryRemovedFunc removed_func ;
+  gpointer removed_data ;  
+};
+
+struct _MokoJournalVoiceInfo
+{
+  gchar *distant_number ;
+  gchar *local_number ;
+  gboolean was_missed ;
+};
+
+struct _MokoJournalFaxInfo
+{
+  int nothing ;
+};
+
+struct _MokoJournalDataInfo
+{
+  int nothing ;
+};
+
+struct _MokoJournalEmailInfo
+{
+  int nothing ;
+};
+
+struct _MokoJournalSMSInfo
+{
+  int nothing ;
+};
+
+struct _MokoJournalEntry
+{
+  enum MokoJournalEntryType type;
+  gchar *uid ;
+  gchar *contact_uid ;
+  gchar *summary ;
+  enum MessageDirection direction ;
+  MokoTime *dtstart ;
+  MokoTime *dtend ;
+  float start_longitude ;
+  float start_latitude ;
+  gchar *source ;
+  MokoGSMLocation gsm_loc ;
+  guchar *wifi_ap_mac ;
+  guchar *bluetooth_ap_mac ;
+  union
+  {
+    MokoJournalEmailInfo *email_info ;
+    MokoJournalVoiceInfo *voice_info ;
+    MokoJournalFaxInfo *fax_info ;
+    MokoJournalDataInfo *data_info ;
+    MokoJournalSMSInfo *sms_info ;
+  } extra ;
+};
+
+struct _MokoJournalEntryInfo
+{
+  enum MokoJournalEntryType type;
+  const gchar *type_as_string ;
+};
+typedef struct _MokoJournalEntryInfo MokoJournalEntryInfo ;
+
+static const MokoJournalEntryInfo entries_info[] =
+{
+  {VOICE_JOURNAL_ENTRY, "VOICEENTRY"},
+  {EMAIL_JOURNAL_ENTRY, "EMAILENTRY"},
+  {SMS_JOURNAL_ENTRY, "SMSENTRY"},
+  {FAX_JOURNAL_ENTRY, "FAXENTRY"},
+  {DATA_JOURNAL_ENTRY, "DATAENTRY"},
+  {0}
+} ;
+
+static MokoJournal* moko_journal_alloc () ;
+static MokoJournalEmailInfo* moko_journal_email_info_new () ;
+static MokoJournalVoiceInfo* moko_journal_voice_info_new () ;
+static MokoJournalFaxInfo* moko_journal_fax_info_new () ;
+static MokoJournalSMSInfo* moko_journal_sms_info_new () ;
+static void moko_journal_voice_info_free (MokoJournalVoiceInfo *a_info) ;
+static void moko_journal_fax_info_free (MokoJournalFaxInfo *a_info) ;
+static void moko_journal_data_info_free (MokoJournalDataInfo *a_info) ;
+static void moko_journal_email_info_free (MokoJournalEmailInfo *a_info) ;
+static void moko_journal_sms_info_free (MokoJournalSMSInfo *a_info) ;
+static MokoJournalDataInfo* moko_journal_data_info_new () ;
+static gboolean moko_journal_find_entry_from_uid (MokoJournal *a_journal,
+                                                  const gchar *a_uid,
+                                                  MokoJournalEntry **a_entry,
+                                                  int *a_offset) ;
+static const gchar* entry_type_to_string (enum MokoJournalEntryType a_type) ;
+static enum MokoJournalEntryType entry_type_from_string (const gchar* a_str) ;
+static gboolean moko_journal_entry_type_is_valid
+                                          (enum MokoJournalEntryType a_type) ;
+static gboolean moko_journal_entry_to_icalcomponent (MokoJournalEntry *a_entry,
+                                                     icalcomponent **a_comp) ;
+static gboolean icalcomponent_to_entry (icalcomponent *a_comp,
+                                          MokoJournalEntry **a_entry) ;
+static gboolean icalcomponent_find_property (const icalcomponent *a_comp,
+                                             const gchar *a_name,
+                                             icalproperty **a_property) ;
+
+static gboolean icalcomponent_find_property_as_string
+                                              (const icalcomponent *a_comp,
+                                               const gchar *a_name,
+                                               gchar **a_property) ;
+static void on_entries_added_cb (ECalView *a_view,
+                                 GList *a_entries,
+                                 MokoJournal *a_journal) ;
+static void on_entries_removed_cb (ECalView *a_view,
+                                   GList *uids,
+                                   MokoJournal *a_journal) ;
+
+
+static void
+notify_entry_added (MokoJournal *a_journal, MokoJournalEntry *entry)
+{
+  if (a_journal->added_func == NULL)
+    return;
+  
+  a_journal->added_func (a_journal, entry, a_journal->added_data);
+}
+
+static void
+notify_entry_removed (MokoJournal *a_journal, MokoJournalEntry *entry)
+{
+  if (a_journal->removed_func == NULL)
+    return;
+  
+  a_journal->removed_func (a_journal, entry, a_journal->removed_data);
+}
+
+static const gchar*
+entry_type_to_string (enum MokoJournalEntryType a_type)
+{
+  MokoJournalEntryInfo *cur ;
+
+  for (cur = (MokoJournalEntryInfo*)entries_info ; cur ; ++cur)
+  {
+    if (cur->type == a_type)
+      return cur->type_as_string ;
+  }
+  return NULL ;
+}
+
+static enum MokoJournalEntryType
+entry_type_from_string (const gchar* a_str)
+{
+  MokoJournalEntryInfo *cur ;
+
+  for (cur = (MokoJournalEntryInfo*)entries_info ; cur ; ++cur)
+  {
+    if (!strcmp (cur->type_as_string, a_str))
+    {
+      return cur->type ;
+    }
+  }
+  return UNDEF_ENTRY ;
+}
+
+/*<private funcs>*/
+static MokoJournal*
+moko_journal_alloc ()
+{
+  MokoJournal *result ;
+  result = g_new0 (MokoJournal, 1) ;
+  result->entries = g_array_new (TRUE, TRUE, sizeof (MokoJournalEntry*)) ;
+  return result ;
+}
+
+static gboolean
+moko_journal_find_entry_from_uid (MokoJournal *a_journal,
+                                  const gchar *a_uid,
+                                  MokoJournalEntry **a_entry,
+                                  int *a_offset)
+{
+  int i=0 ;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->entries, FALSE) ;
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_offset, FALSE) ;
+  g_return_val_if_fail (a_uid, FALSE) ;
+
+  if (!a_journal->entries)
+    return FALSE ;
+
+  for (i = 0 ; i < a_journal->entries->len ; ++i)
+  {
+    if (g_array_index (a_journal->entries, MokoJournalEntry*, i)
+        && g_array_index (a_journal->entries, MokoJournalEntry*, i)->uid
+        && !strcmp (g_array_index (a_journal->entries,
+                                   MokoJournalEntry*, i)->uid,
+                    a_uid))
+    {
+      *a_entry = g_array_index (a_journal->entries, MokoJournalEntry*, i) ;
+      *a_offset = i ;
+      return TRUE ;
+    }
+  }
+  return FALSE ;
+}
+
+static void
+moko_journal_free (MokoJournal *a_journal)
+{
+  g_return_if_fail (a_journal) ;
+  if (a_journal->ecal)
+  {
+    g_object_unref (G_OBJECT (a_journal->ecal)) ;
+    a_journal->ecal = NULL ;
+  }
+  if (a_journal->entries_to_delete)
+  {
+    g_list_free (a_journal->entries_to_delete) ;
+    a_journal->entries_to_delete = NULL ;
+  }
+  if (a_journal->entries)
+  {
+    int i ;
+    for (i=0 ; i < a_journal->entries->len ; ++i)
+    {
+      if (g_array_index (a_journal->entries, MokoJournalEntry*, i))
+      {
+        moko_journal_entry_free (g_array_index (a_journal->entries,
+                                                MokoJournalEntry*, i));
+        g_array_index (a_journal->entries, MokoJournalEntry*, i) = NULL;
+      }
+    }
+    g_array_free (a_journal->entries, TRUE) ;
+    a_journal->entries = NULL ;
+  }
+  g_free (a_journal) ;
+}
+
+static MokoJournalEmailInfo*
+moko_journal_email_info_new ()
+{
+  return g_new0 (MokoJournalEmailInfo, 1) ;
+}
+
+static MokoJournalVoiceInfo*
+moko_journal_voice_info_new ()
+{
+  return g_new0 (MokoJournalVoiceInfo, 1) ;
+}
+
+static MokoJournalFaxInfo*
+moko_journal_fax_info_new ()
+{
+  return g_new0 (MokoJournalFaxInfo, 1) ;
+}
+
+static MokoJournalDataInfo*
+moko_journal_data_info_new ()
+{
+  return g_new0 (MokoJournalDataInfo, 1) ;
+}
+
+static MokoJournalSMSInfo*
+moko_journal_sms_info_new ()
+{
+  return g_new0 (MokoJournalSMSInfo, 1) ;
+}
+
+static void
+moko_journal_email_info_free (MokoJournalEmailInfo *a_info)
+{
+  g_return_if_fail (a_info) ;
+  g_free (a_info) ;
+}
+
+static void
+moko_journal_voice_info_free (MokoJournalVoiceInfo *a_info)
+{
+  g_return_if_fail (a_info) ;
+
+  if (a_info)
+  {
+    if (a_info->distant_number)
+    {
+      g_free (a_info->distant_number) ;
+      a_info->distant_number = NULL ;
+    }
+    if (a_info->local_number)
+    {
+      g_free (a_info->local_number) ;
+      a_info->local_number = NULL ;
+    }
+  }
+  g_free (a_info) ;
+}
+
+static void
+moko_journal_fax_info_free (MokoJournalFaxInfo *a_info)
+{
+  g_return_if_fail (a_info) ;
+  g_free (a_info) ;
+}
+
+static void
+moko_journal_data_info_free (MokoJournalDataInfo *a_info)
+{
+  g_return_if_fail (a_info) ;
+  g_free (a_info) ;
+}
+
+static void
+moko_journal_sms_info_free (MokoJournalSMSInfo *a_info)
+{
+  g_return_if_fail (a_info) ;
+  g_free (a_info) ;
+}
+
+static MokoJournalEntry*
+moko_journal_entry_alloc ()
+{
+  MokoJournalEntry *result ;
+
+  result = g_new0 (MokoJournalEntry, 1) ;
+  return result ;
+}
+
+static void
+moko_journal_entry_free_real (MokoJournalEntry *a_entry)
+{
+  g_return_if_fail (a_entry) ;
+
+  if (a_entry->uid)
+  {
+    g_free (a_entry->uid) ;
+    a_entry->uid = NULL ;
+  }
+  if (a_entry->contact_uid)
+  {
+    g_free (a_entry->contact_uid) ;
+    a_entry->contact_uid = NULL ;
+  }
+  if (a_entry->summary)
+  {
+    g_free (a_entry->summary) ;
+    a_entry->summary = NULL ;
+  }
+  if (a_entry->dtstart)
+  {
+    moko_time_free (a_entry->dtstart) ;
+    a_entry->dtstart = NULL ;
+  }
+  if (a_entry->dtend)
+  {
+    moko_time_free (a_entry->dtend) ;
+    a_entry->dtend = NULL ;
+  }
+  if (a_entry->source)
+  {
+    g_free (a_entry->source) ;
+    a_entry->source = NULL ;
+  }
+  if (a_entry->wifi_ap_mac)
+  {
+    g_free (a_entry->wifi_ap_mac) ;
+    a_entry->wifi_ap_mac = NULL ;
+  }
+  if (a_entry->bluetooth_ap_mac)
+  {
+    g_free (a_entry->bluetooth_ap_mac) ;
+    a_entry->bluetooth_ap_mac = NULL;
+  }
+
+  switch (a_entry->type)
+  {
+    case EMAIL_JOURNAL_ENTRY:
+      if (a_entry->extra.email_info)
+      {
+        moko_journal_email_info_free (a_entry->extra.email_info) ;
+        a_entry->extra.email_info = NULL ;
+      }
+      break ;
+    case VOICE_JOURNAL_ENTRY:
+      if (a_entry->extra.voice_info)
+      {
+        moko_journal_voice_info_free (a_entry->extra.voice_info) ;
+        a_entry->extra.voice_info = NULL ;
+      }
+      break ;
+    case FAX_JOURNAL_ENTRY:
+      if (a_entry->extra.fax_info)
+      {
+        moko_journal_fax_info_free (a_entry->extra.fax_info) ;
+        a_entry->extra.fax_info = NULL;
+      }
+      break ;
+    case DATA_JOURNAL_ENTRY:
+      if (a_entry->extra.data_info)
+      {
+        moko_journal_data_info_free (a_entry->extra.data_info) ;
+        a_entry->extra.data_info = NULL ;
+      }
+      break ;
+    case SMS_JOURNAL_ENTRY:
+      if (a_entry->extra.sms_info)
+      {
+        moko_journal_sms_info_free (a_entry->extra.sms_info) ;
+        a_entry->extra.sms_info = NULL ;
+      }
+      break ;
+    default:
+      g_warning ("unknown journal entry type. This is a leak!\n") ;
+      break ;
+  }
+  g_free (a_entry) ;
+}
+
+static gboolean
+moko_journal_entry_type_is_valid (enum MokoJournalEntryType a_type)
+{
+  if (a_type > 0 && a_type < NB_OF_ENTRY_TYPES)
+    return TRUE ;
+  return FALSE ;
+}
+
+static gboolean
+moko_journal_entry_to_icalcomponent (MokoJournalEntry *a_entry,
+                                     icalcomponent **a_comp)
+{
+  icalcomponent *comp = NULL ;
+  icalproperty *prop = NULL ;
+  gboolean result = FALSE ;
+  gchar *str=NULL ;
+  enum MessageDirection dir = DIRECTION_IN ;
+
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_comp, FALSE) ;
+  g_return_val_if_fail (moko_journal_entry_type_is_valid (a_entry->type),
+                        FALSE) ;
+
+  comp = icalcomponent_new (ICAL_VJOURNAL_COMPONENT) ;
+
+  /*add uid, if it exists*/
+  if (a_entry->uid)
+  {
+    prop = icalproperty_new_uid (a_entry->uid) ;
+    icalcomponent_add_property (comp, prop) ;
+  }
+
+  /*add contact prop*/
+  prop = icalproperty_new_contact
+                          (moko_journal_entry_get_contact_uid (a_entry)) ;
+  icalcomponent_add_property (comp, prop) ;
+
+  /*add summary prop*/
+  prop = icalproperty_new_summary (moko_journal_entry_get_summary (a_entry)) ;
+  icalcomponent_add_property (comp, prop) ;
+
+  /*add direction*/
+  if (!moko_journal_entry_get_direction (a_entry, &dir))
+  {
+    g_warning ("failed to get entry direction") ;
+    goto out ;
+  }
+  if (dir == DIRECTION_IN)
+  {
+    prop = icalproperty_new_x ("IN") ;
+  }
+  else
+  {
+    prop = icalproperty_new_x ("OUT") ;
+  }
+  icalproperty_set_x_name (prop, "X-OPENMOKO-ENTRY-DIRECTION") ;
+  icalcomponent_add_property (comp, prop) ;
+
+  /*add dtstart*/
+  const MokoTime *date = moko_journal_entry_get_dtstart (a_entry) ;
+  if (!date)
+    goto out ;
+  prop = icalproperty_new_dtstart (date->t) ;
+  icalcomponent_add_property (comp, prop) ;
+
+  /*add location start*/
+  struct icalgeotype geo;
+  if (moko_journal_entry_get_start_location (a_entry, (MokoLocation*)&geo))
+  {
+    prop = icalproperty_new_geo (geo) ;
+    icalcomponent_add_property (comp, prop) ;
+  }
+
+  /*add source*/
+  if (moko_journal_entry_get_source (a_entry))
+    prop = icalproperty_new_x (moko_journal_entry_get_source (a_entry)) ;
+  else
+    prop = icalproperty_new_x ("null") ;
+  icalproperty_set_x_name (prop, "X-OPENMOKO-ENTRY-SOURCE") ;
+  icalcomponent_add_property (comp, prop) ;
+
+  /*
+   * add gsm location (pair of "local area code" and "cell id".
+   * gsm location is stored in an
+   * x-property named X-OPENMOKO-ENTRY-GSM-LOCATION that has the form:
+   * X-OPENMOKO-GSMLOCATION;LAC="<int16>";CID=<int 16>: dummy
+   */
+  prop = icalproperty_new_x ("dummy") ;
+  icalproperty_set_x_name (prop, "X-OPENMOKO-ENTRY-GSM-LOCATION") ;
+  str = g_strdup_printf ("%d", a_entry->gsm_loc.lac);
+  icalproperty_set_parameter_from_string (prop, "X-LAC", str) ;
+  g_free (str) ;
+  str = g_strdup_printf ("%d", a_entry->gsm_loc.cid);
+  icalproperty_set_parameter_from_string (prop, "X-CID", str) ;
+  g_free (str) ;
+  icalcomponent_add_property (comp, prop) ;
+  /*add entry type*/
+  prop = icalproperty_new_x
+                (entry_type_to_string (moko_journal_entry_get_type (a_entry))) ;
+  icalproperty_set_x_name (prop, "X-OPENMOKO-ENTRY-TYPE") ;
+  icalcomponent_add_property (comp, prop) ;
+
+  switch (moko_journal_entry_get_type (a_entry))
+  {
+    case UNDEF_ENTRY:
+      g_warning ("entry is of undefined type\n") ;
+      return FALSE ;
+    case EMAIL_JOURNAL_ENTRY:
+      break ;
+    case VOICE_JOURNAL_ENTRY:
+      {
+        MokoJournalVoiceInfo *info = NULL ;
+        gchar *number="NULL" ;
+        gchar *missed=NULL ;
+
+        if (!moko_journal_entry_get_voice_info (a_entry, &info))
+          break ;
+        if (!info)
+          break ;
+
+        /*
+         * serialize caller number
+         */
+        if (moko_journal_voice_info_get_distant_number (info))
+          number = (gchar*)moko_journal_voice_info_get_distant_number (info) ;
+        prop = icalproperty_new_x (number) ;
+        icalproperty_set_x_name (prop, "X-OPENMOKO-VOICE-CALLER-NUMBER") ;
+        icalcomponent_add_property (comp, prop) ;
+
+        /*
+         * serialize the local_number property
+         */
+        if (moko_journal_voice_info_get_local_number (info))
+          number = (gchar*)moko_journal_voice_info_get_distant_number (info) ;
+        prop = icalproperty_new_x (number) ;
+        icalproperty_set_x_name (prop, "X-OPENMOKO-VOICE-CALLEE-NUMBER") ;
+        icalcomponent_add_property (comp, prop) ;
+
+        /*
+         * serialize the "was-missed" property
+         */
+        if (moko_journal_voice_info_get_was_missed (info))
+          missed = "YES" ;
+        else
+          missed = "NO" ;
+        prop = icalproperty_new_x (missed) ;
+        icalproperty_set_x_name (prop, "X-OPENMOKO-VOICE-CALL-WAS-MISSED") ;
+        icalcomponent_add_property (comp, prop) ;
+      }
+      break ;
+    case FAX_JOURNAL_ENTRY:
+      break ;
+    case DATA_JOURNAL_ENTRY:
+      break ;
+    case SMS_JOURNAL_ENTRY:
+      break ;
+    default:
+      break ;
+  }
+
+  *a_comp = comp ;
+  prop = NULL ;
+  comp = NULL ;
+  result = TRUE ;
+out:
+  if (prop)
+    icalproperty_free (prop) ;
+
+  if (comp)
+    icalcomponent_free (comp) ;
+
+  return result ;
+}
+
+static gboolean
+icalcomponent_to_entry (icalcomponent *a_comp,
+                        MokoJournalEntry **a_entry)
+{
+  icalproperty *prop=NULL ;
+  gchar *prop_name=NULL, *prop_value=NULL ;
+  MokoJournalEntry *entry=NULL;
+
+  g_return_val_if_fail (a_comp, FALSE) ;
+  g_return_val_if_fail (icalcomponent_isa (a_comp) == ICAL_VJOURNAL_COMPONENT,
+                        FALSE) ;
+
+  entry = moko_journal_entry_alloc () ;
+
+  /*get the type*/
+  if (icalcomponent_find_property_as_string (a_comp, "X-OPENMOKO-ENTRY-TYPE",
+                                             &prop_value))
+  {
+    enum MokoJournalEntryType entry_type = UNDEF_ENTRY ;
+    if (!prop_value)
+    {
+      g_warning ("could not get entry type") ;
+      goto out ;
+    }
+    entry_type = entry_type_from_string (prop_value) ;
+    if (entry_type == UNDEF_ENTRY)
+    {
+      g_warning ("Could not recognize type of entry from: %s\n", prop_value);
+      goto out ;
+    }
+    entry->type = entry_type ;
+  }
+  /*make sure we got the type*/
+  if (entry->type == UNDEF_ENTRY || entry->type >= NB_OF_ENTRY_TYPES)
+  {
+    g_warning ("bad entry type") ;
+    goto out ;
+  }
+
+  /*look for the x-properties we may have*/
+  if (icalcomponent_find_property_as_string
+                                    (a_comp, "X-OPENMOKO-ENTRY-DIRECTION",
+                                     &prop_value))
+  {
+    if (prop_value && !strcmp (prop_value, "IN"))
+      moko_journal_entry_set_direction (entry, DIRECTION_IN) ;
+    else
+      moko_journal_entry_set_direction (entry, DIRECTION_OUT) ;
+  }
+  if (icalcomponent_find_property_as_string
+                                    (a_comp, "X-OPENMOKO-ENTRY-SOURCE",
+                                     &prop_value))
+  {
+    if (!prop_value || (prop_value && !strcmp (prop_value, "null")))
+    {
+      moko_journal_entry_set_source (entry, NULL) ;
+    }
+    else
+    {
+      moko_journal_entry_set_source (entry, prop_value) ;
+    }
+  }
+
+  if (icalcomponent_find_property (a_comp,
+                                   "X-OPENMOKO-ENTRY-GSM-LOCATION",
+                                   &prop))
+  {
+    if (prop )
+    {
+      gchar *str=NULL ;
+      gint code=0 ;
+      str = (gchar*)icalproperty_get_parameter_as_string (prop, "X-LAC") ;
+      code = atoi (str) ;
+      entry->gsm_loc.lac = (gushort)code ;
+      str = (gchar*)icalproperty_get_parameter_as_string (prop, "X-CID") ;
+      code = atoi (str) ;
+      entry->gsm_loc.cid = (gushort)code ;
+    }
+  }
+
+
+  /*now iterate through properties to scan core properties*/
+  for (prop = icalcomponent_get_first_property (a_comp, ICAL_ANY_PROPERTY);
+       prop ;
+       prop = icalcomponent_get_next_property (a_comp, ICAL_ANY_PROPERTY))
+  {
+    prop_name = (gchar*)icalproperty_get_property_name (prop) ;
+    if (!prop_name)
+      continue ;
+    if (icalproperty_isa (prop) == ICAL_UID_PROPERTY)
+    {
+      if (entry->uid)
+        g_free (entry->uid) ;
+      entry->uid = g_strdup (icalproperty_get_uid (prop)) ;
+    }
+    else if (icalproperty_isa (prop) == ICAL_CONTACT_PROPERTY)
+    {
+      moko_journal_entry_set_contact_uid
+                                  (entry, icalproperty_get_contact (prop)) ;
+    }
+    else if (icalproperty_isa (prop) == ICAL_SUMMARY_PROPERTY)
+    {
+      moko_journal_entry_set_summary (entry, icalproperty_get_summary (prop)) ;
+    }
+    else if (icalproperty_isa (prop) == ICAL_DTSTART_PROPERTY)
+    {
+      moko_journal_entry_set_dtstart
+        (entry,
+         moko_time_new_from_icaltimetype (icalproperty_get_dtstart (prop)));
+    }
+    else if (icalproperty_isa (prop) == ICAL_GEO_PROPERTY)
+    {
+      struct icalgeotype geo = icalproperty_get_geo (prop);
+      moko_journal_entry_set_start_location (entry, (MokoLocation*)&geo) ;
+    }
+  }
+
+  /*scan extra info related properties*/
+  switch (entry->type)
+  {
+    case VOICE_JOURNAL_ENTRY:
+      {
+        MokoJournalVoiceInfo *info = NULL ;
+        prop = NULL ;
+        prop_value = NULL ;
+
+        moko_journal_entry_get_voice_info (entry, &info) ;
+        g_return_val_if_fail (info, FALSE) ;
+
+        /*
+         * deserialize caller number
+         */
+        if (icalcomponent_find_property_as_string
+                                          (a_comp,
+                                           "X-OPENMOKO-VOICE-CALLER-NUMBER",
+                                           &prop_value))
+        {
+          if (prop_value)
+          {
+            moko_journal_voice_info_set_distant_number (info, prop_value) ;
+          }
+        }
+
+        /*
+         * deserialize callee number
+         */
+        if (icalcomponent_find_property_as_string
+                                          (a_comp,
+                                           "X-OPENMOKO-VOICE-CALLEE-NUMBER",
+                                           &prop_value))
+        {
+          if (prop_value)
+          {
+            moko_journal_voice_info_set_local_number (info, prop_value) ;
+          }
+        }
+        prop_value = NULL ;
+        if (icalcomponent_find_property_as_string
+                                        (a_comp,
+                                         "X-OPENMOKO-VOICE-CALL-WAS-MISSED",
+                                         &prop_value))
+        {
+          if (prop_value)
+          {
+            gboolean was_missed = FALSE ;
+            if (!strcmp ("YES", prop_value))
+              was_missed = TRUE ;
+            moko_journal_voice_info_set_was_missed (info, was_missed) ;
+          }
+        }
+      }
+      break ;
+    case FAX_JOURNAL_ENTRY:
+      break ;
+    case DATA_JOURNAL_ENTRY:
+      break ;
+    case SMS_JOURNAL_ENTRY:
+      break ;
+    case EMAIL_JOURNAL_ENTRY:
+      break ;
+    default:
+      break ;
+  }
+
+  *a_entry = entry ;
+  entry = NULL ;
+
+out:
+  if (entry)
+    moko_journal_entry_free (entry) ;
+  return TRUE ;
+}
+
+
+static gboolean
+icalcomponent_find_property (const icalcomponent *a_comp,
+                             const gchar *a_name,
+                             icalproperty **a_property)
+{
+  icalproperty *prop = NULL ;
+
+  g_return_val_if_fail (a_comp, FALSE) ;
+
+  for (prop = icalcomponent_get_first_property ((icalcomponent*)a_comp,
+                                                ICAL_ANY_PROPERTY);
+       prop;
+       prop = icalcomponent_get_next_property ((icalcomponent*)a_comp,
+                                               ICAL_ANY_PROPERTY))
+  {
+    if (icalproperty_get_property_name (prop)
+        && ! strcasecmp (icalproperty_get_property_name (prop), a_name))
+    {
+      *a_property = prop ;
+      return TRUE ;
+    }
+  }
+  return FALSE ;
+}
+
+static gboolean
+icalcomponent_find_property_as_string (const icalcomponent *a_comp,
+                                       const gchar *a_name,
+                                       gchar **a_property)
+{
+  icalproperty *prop = NULL ;
+
+  g_return_val_if_fail (a_comp, FALSE) ;
+  g_return_val_if_fail (a_name, FALSE) ;
+
+  if (icalcomponent_find_property (a_comp, a_name, &prop))
+  {
+    *a_property = (gchar*) icalproperty_get_value_as_string (prop) ;
+    return TRUE ;
+  }
+  return FALSE ;
+}
+
+/*</private funcs>*/
+
+
+/*<public funcs>*/
+
+/**
+ * moko_journal_open_default:
+ *
+ * Opens the default journal.
+ *
+ * Return value: a pointer to the journal object
+ */
+MokoJournal*
+moko_journal_open_default ()
+{
+  ECal *ecal = NULL;
+  gchar *uri = NULL ;
+  MokoJournal *result=NULL, *journal=NULL ;
+  GError *error = NULL ;
+
+  uri = g_build_filename ("file://", g_get_home_dir (),
+                          ".moko", "journal", NULL);
+
+  ecal = e_cal_new_from_uri (uri, E_CAL_SOURCE_TYPE_JOURNAL) ;
+  if (!ecal)
+  {
+    g_warning ("failed to create ecal with uri: %s\n", uri) ;
+    goto out ;
+  }
+
+  if (!e_cal_open (ecal, FALSE, &error))
+  {
+    g_warning ("could not open the journal at uri %s\n", uri) ;
+    goto out ;
+  }
+  if (error)
+  {
+    g_warning ("got error: %s\n", error->message) ;
+    goto out ;
+  }
+  journal = moko_journal_alloc () ;
+  journal->ecal = ecal ;
+  ecal = NULL ;
+
+  result = journal ;
+  journal = NULL ;
+
+out:
+  g_free (uri) ;
+
+  if (ecal)
+    g_object_unref (G_OBJECT (ecal)) ;
+
+  if (journal)
+    moko_journal_free (journal) ;
+
+  if (error)
+    g_error_free (error) ;
+
+  return result ;
+}
+
+/**
+ * moko_journal_close:
+ * @journal: the journal to close
+ *
+ * Close the journal previously opened with moko_journal_open_default().
+ * This function deallocates the memory of the Journal object.
+ */
+void
+moko_journal_close (MokoJournal *a_journal)
+{
+  g_return_if_fail (a_journal) ;
+
+  moko_journal_free (a_journal) ;
+}
+
+/**
+ * moko_journal_set_entry_added_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is added or NULL.
+ * @data: the data you would like to pass to the callback or NULL.
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is added.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_added_callback (MokoJournal *a_journal,  
+                                            MokoJournalEntryAddedFunc func,
+                                            gpointer data)
+{
+  g_return_if_fail (a_journal) ;
+  
+  a_journal->added_func = func;
+  a_journal->added_data = data;
+}
+
+/**
+ * moko_journal_set_entry_removed_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is removed or NULL.
+ * @data: the data you would like to pass to the callback or NULL. 
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is removed.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_removed_callback (MokoJournal *a_journal,  
+                                              MokoJournalEntryRemovedFunc func,
+                                              gpointer data)
+{
+  g_return_if_fail (a_journal) ;
+  
+  a_journal->removed_func = func;
+  a_journal->removed_data = data;
+}
+
+/**
+ * moko_journal_add_entry:
+ * @journal: the current instance of journal
+ * @entry: the new entry to add to the journal. The journal is responsible
+ * of deallocating the memory of the entry object.
+ *
+ * Add a journal entry to the journal
+ *
+ * Return value: TRUE if the entry got successfully added to the journal,
+ * FALSE otherwise
+ */
+gboolean
+moko_journal_add_entry (MokoJournal *a_journal, MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_entry, FALSE) ;
+
+  g_array_append_val (a_journal->entries, a_entry) ;
+  
+  return TRUE ;
+}
+
+/**
+ * moko_journal_get_nb_entries:
+ * @journal: the current instance of journal
+ *
+ * Return value: the number of entries in the journal or a negative value
+ * in case of error.
+ */
+int
+moko_journal_get_nb_entries (MokoJournal *a_journal)
+{
+  g_return_val_if_fail (a_journal, -1) ;
+  if (!a_journal->entries)
+    return 0 ;
+  return a_journal->entries->len ;
+}
+
+/**
+ * moko_journal_get_entry_at:
+ * @journal: the current instance of journal
+ * @index: the index to get the journal entry from
+ * @entry: out parameter. the resulting journal entry
+ *
+ * Get the journal entry at a given index.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise.
+ */
+gboolean
+moko_journal_get_entry_at (MokoJournal *a_journal,
+                           guint a_index,
+                           MokoJournalEntry **a_entry)
+{
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_journal->entries, FALSE) ;
+  g_return_val_if_fail (a_index < a_journal->entries->len, FALSE) ;
+
+  *a_entry = g_array_index (a_journal->entries, MokoJournalEntry*, a_index) ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_remove_entry_at:
+ * @journal: the current instance of journal
+ * @index: the index to remove the entry from
+ *
+ * Remove a journal entry from index #index
+ */
+gboolean
+moko_journal_remove_entry_at (MokoJournal *a_journal,
+                              guint a_index)
+{
+  MokoJournalEntry *entry = NULL ;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->entries, FALSE) ;
+  g_return_val_if_fail (a_index < a_journal->entries->len, FALSE) ;
+
+  entry = g_array_index (a_journal->entries, MokoJournalEntry*, a_index) ;
+  if (entry)
+  {
+    /*
+     * if entry has been persisted already,
+     * queue a removal from storage
+     */
+    if (entry->uid)
+    {
+      a_journal->entries_to_delete =
+        g_list_prepend (a_journal->entries_to_delete, entry);
+    }
+    /*
+     * remove entry from memory cache
+     */
+    g_array_remove_index (a_journal->entries, a_index) ;
+    /*
+     * if entry has not been pushed onto
+     * storage deletion queue,
+     * deallocate its memory
+     */
+    if (!entry->uid)
+    {
+      moko_journal_entry_free (entry) ;
+    }
+    return TRUE ;
+  }
+  return FALSE ;
+}
+
+/**
+ * moko_journal_remove_entry_by_uid:
+ * @journal: the current instance of journal
+ * @uid: the uid of the journal entry to remove
+ *
+ * Remove the journal entry that has a given UID.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean
+moko_journal_remove_entry_by_uid (MokoJournal *a_journal,
+                                  const gchar* a_uid)
+{
+  int i=0 ;
+  MokoJournalEntry *entry=NULL ;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->entries, FALSE) ;
+  g_return_val_if_fail (a_uid, FALSE) ;
+
+  for (i=0 ; i < a_journal->entries->len ; ++i)
+  {
+    entry = g_array_index (a_journal->entries, MokoJournalEntry*, i) ;
+    if (entry && entry->uid && !strcmp (entry->uid, a_uid))
+    {
+      notify_entry_removed (a_journal, entry);
+      return moko_journal_remove_entry_at (a_journal, i) ;
+    }
+  }
+  return FALSE ;
+}
+
+/**
+ * moko_journal_write_to_storage:
+ * @journal: the journal to save to storage
+ *
+ * Saves the journal to persistent storage (e.g disk) using the
+ * appropriate backend. The backend currently used is evolution data server
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean
+moko_journal_write_to_storage (MokoJournal *a_journal)
+{
+  MokoJournalEntry *cur_entry=NULL ;
+  int i=0 ;
+  GList *ecal_comps=NULL, *cur_elem=NULL ;
+  ECalComponent *ecal_comp=NULL ;
+  icalcomponent *ical_comp=NULL ;
+  GError *error=NULL ;
+  gboolean wrote = FALSE;
+  gboolean result = TRUE;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->ecal, FALSE) ;
+
+  /*create ECalComponent objects out of the list of MokoJournalEntry* we have*/
+  for (i=0; a_journal->entries && i<a_journal->entries->len; ++i)
+  {
+    cur_entry = g_array_index (a_journal->entries, MokoJournalEntry*, i) ;
+    if (!cur_entry)
+      break ;
+    if (!moko_journal_entry_to_icalcomponent (cur_entry, &ical_comp))
+    {
+      if (ical_comp)
+      {
+        icalcomponent_free (ical_comp) ;
+        ical_comp = NULL ;
+      }
+      continue ;
+    }
+    ecal_comp = e_cal_component_new () ;
+    e_cal_component_set_icalcomponent (ecal_comp, ical_comp) ;
+    g_object_set_data (G_OBJECT (ecal_comp), "journal-entry", cur_entry) ;
+    ecal_comps = g_list_prepend (ecal_comps, ecal_comp) ;
+    ecal_comp = NULL ;
+    ical_comp = NULL ;
+  }
+
+  /*
+   * walk the list of ECalComponent objects to either add them
+   * to eds or modify them (in eds) if there were already present in eds.
+   */
+  for (cur_elem = ecal_comps ; cur_elem ; cur_elem = cur_elem->next)
+  {
+    if (!cur_elem->data)
+    {
+      g_warning ("Got an empty ECalComponent\n") ;
+      result = FALSE ;
+      continue ;
+    }
+    ical_comp = e_cal_component_get_icalcomponent (cur_elem->data) ;
+    if (!ical_comp)
+    {
+      g_warning ("Got an empty icalcomponent") ;
+      result = FALSE ;
+      continue ;
+    }
+    cur_entry = g_object_get_data (G_OBJECT (cur_elem->data),
+        "journal-entry") ;
+    if (!cur_entry)
+    {
+      g_warning ("could not get journal entry from cur_elem->data") ;
+      continue ;
+    }
+    if (cur_entry->uid)
+    {
+      /*entry exists already in eds, modify it*/
+      if (!e_cal_modify_object (a_journal->ecal, ical_comp,
+                                CALOBJ_MOD_THIS, &error))
+      {
+        g_warning ("Could not modify entry in the journal") ;
+        result = FALSE ;
+      }
+    }
+    else
+    {
+      /*entry did not exist in eds previously, add it*/
+      if (!e_cal_create_object (a_journal->ecal, ical_comp,
+                                &cur_entry->uid, &error))
+      {
+        g_warning ("Could not write the entry to the journal") ;
+        result = FALSE ;
+      }
+      else
+      {
+        e_cal_component_commit_sequence (cur_elem->data) ;
+        wrote = TRUE ;
+      }
+    }
+    if (error)
+    {
+      g_warning ("got error: %s\n", error->message) ;
+      g_error_free (error) ;
+      error = NULL ;
+    }
+  }
+
+  /*
+   * remove entries that have been
+   * queued to be removed
+   */
+  for (cur_elem = a_journal->entries_to_delete ;
+       cur_elem ;
+       cur_elem = cur_elem->next)
+  {
+    if (!cur_elem->data)
+      continue ;
+
+    if (((MokoJournalEntry*)cur_elem->data)->uid)
+    {
+      if (!e_cal_remove_object (a_journal->ecal,
+                                ((MokoJournalEntry*)cur_elem->data)->uid,
+                                &error))
+      {
+        /*
+         * this can happen if another process for instance, has
+         * already deleted the entry. In that case, we just
+         * print message and continue
+         */
+        g_message ("failed to remove object with UID %s\n",
+                   ((MokoJournalEntry*)cur_elem->data)->uid) ;
+      }
+      if (error)
+      {
+        g_warning ("got error %s\n", error->message) ;
+        g_error_free (error) ;
+        error = NULL ;
+      }
+    }
+    moko_journal_entry_free ((MokoJournalEntry*)cur_elem->data) ;
+    cur_elem->data = NULL ;
+  }
+
+  if (a_journal->entries_to_delete)
+  {
+    g_list_free (a_journal->entries_to_delete) ;
+    a_journal->entries_to_delete = NULL ;
+  }
+
+  if (ecal_comps)
+  {
+    GList *cur;
+
+    for (cur = ecal_comps ; cur ; cur = cur->next)
+      g_object_unref (cur->data) ;
+    g_list_free (ecal_comps) ;
+  }
+
+  return result ;
+}
+
+static void
+on_entries_added_cb (ECalView *a_view,
+                     GList *a_entries,
+                     MokoJournal *a_journal)
+{
+  icalcomponent *ical_comp = NULL ;
+  GList *cur_entry = NULL ;
+  int offset=0 ;
+
+  for (cur_entry = a_entries ; cur_entry ; cur_entry = cur_entry->next)
+  {
+    MokoJournalEntry *entry = NULL ;
+
+    /*****************
+     * <sanity checks>
+     *****************/
+    if (!icalcomponent_isa_component (cur_entry->data))
+    {
+      /*hugh ? this does not look like an ical component. ignore it.*/
+      continue ;
+    }
+    if (!icalcomponent_get_uid (cur_entry->data))
+    {
+      /*hugh ? an ical component without uid ? ignore it*/
+      continue ;
+    }
+    if (moko_journal_find_entry_from_uid
+                                    (a_journal,
+                                     icalcomponent_get_uid (cur_entry->data),
+                                     &entry,
+                                     &offset))
+    {
+      /*we already have the component in memory, ignore it*/
+      if (entry)
+        notify_entry_added (a_journal, entry);
+      continue ;
+    }
+    /*****************
+     * </sanity checks>
+     *****************/
+
+    /*
+     * okay, build a journal entry from the ical component and cache it
+     * in memory
+     */
+    ical_comp = cur_entry->data ;
+    if (!icalcomponent_to_entry (ical_comp, &entry) || !entry)
+    {
+      if (entry)
+      {
+        moko_journal_entry_free (entry) ;
+        entry = NULL ;
+      }
+      continue ;
+    }
+    moko_journal_add_entry (a_journal, entry) ;
+    notify_entry_added (a_journal, entry) ;
+  }
+}
+
+static void
+on_entries_removed_cb (ECalView *a_view,
+                       GList *a_uids,
+                       MokoJournal *a_journal)
+{
+  GList *cur = NULL ;
+
+  g_return_if_fail (a_view && E_IS_CAL_VIEW (a_view)) ;
+  g_return_if_fail (a_journal) ;
+
+  /*TODO:
+   * we should notify the world before removing an entry.
+   * Otherwise, client code may hold a reference to
+   * what will become a dangling pointer after we remove it here
+   */
+  for (cur = a_uids ; cur ; cur = cur->next)
+  {
+    if (cur->data)
+    {
+      if (!moko_journal_remove_entry_by_uid (a_journal, cur->data))
+      {
+        g_message ("failed to remove entry of uid %s\n",
+                   (const char*)cur->data) ;
+      }
+    }
+  }
+}
+
+/**
+ * moko_journal_load_from_storage:
+ * @a_journal: the journal to load entries into
+ *
+ * Read the journal entries stored in the persistent storage (filesystem)
+ * and load then into the current instance of MokoJournal.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean
+moko_journal_load_from_storage (MokoJournal *a_journal)
+{
+  GError *error = NULL ;
+  GList *objs = NULL ;
+
+  g_return_val_if_fail (a_journal, FALSE) ;
+  g_return_val_if_fail (a_journal->ecal, FALSE) ;
+
+  if (!a_journal->ecal_view)
+  {
+    /*
+     * first, issue a query to get a view that we can
+     * listen to, to get notified by new objects that get added to eds
+     * during the life time of a_journal
+     */
+    if (!e_cal_get_query (a_journal->ecal, "#t",
+                          &a_journal->ecal_view,
+                          &error)
+        || error)
+    {
+      if (error)
+      {
+        if (error->message)
+        {
+          g_warning ("got error: %s\n", error->message) ;
+        }
+        g_error_free (error) ;
+        error = NULL ;
+      }
+      return FALSE ;
+    }
+    g_signal_connect (G_OBJECT (a_journal->ecal_view),
+                      "objects-added",
+                      G_CALLBACK (on_entries_added_cb),
+                      a_journal) ;
+    g_signal_connect (G_OBJECT (a_journal->ecal_view),
+                      "objects-removed",
+                      G_CALLBACK (on_entries_removed_cb),
+                      a_journal) ;
+
+    e_cal_view_start (a_journal->ecal_view) ;
+  }
+
+  /*
+   * really get the objects from eds to let the caller start working
+   * right after the call completes
+   */
+  if (!e_cal_get_object_list (a_journal->ecal, "#t", &objs, &error))
+  {
+    g_warning ("failed to get ical journal objects from eds") ;
+  }
+  if (error)
+  {
+    g_warning ("got error %s\n", error->message) ;
+    g_error_free (error) ;
+    error = NULL ;
+  }
+  if (objs)
+  {
+    GList *cur=NULL ;
+    MokoJournalEntry *entry = NULL ;
+    for (cur = objs ; cur ; cur = cur->next)
+    {
+      if (!icalcomponent_isa (cur->data))
+        continue ;
+      if (icalcomponent_to_entry (cur->data, &entry) && entry)
+      {
+        moko_journal_add_entry (a_journal, entry) ;
+        entry = NULL ;
+      }
+      if (entry)
+      {
+        g_warning ("entry should be NULL here") ;
+        moko_journal_entry_free (entry) ;
+        entry = NULL ;
+      }
+    }
+    e_cal_free_object_list (objs) ;
+    objs = NULL ;
+  }
+
+  /*give us a chance to get notified by entries arriving ...*/
+  while (g_main_context_pending (g_main_context_default ()))
+  {
+    g_main_context_iteration (g_main_context_default (), FALSE) ;
+  }
+
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_new:
+ *
+ * Create a Journal entry with no properties set.
+ * Use the JEntry accessors to get/set properties.
+ *
+ * Return value: the newly created journal entry object
+ */
+MokoJournalEntry*
+moko_journal_entry_new (enum MokoJournalEntryType a_type)
+{
+  MokoJournalEntry *result ;
+  result = moko_journal_entry_alloc () ;
+  result->type = a_type ;
+  return result ;
+}
+
+/**
+ * moko_journal_entry_free:
+ * @entry: the entry to free
+ *
+ * Deallocate the memory of the journal entry object
+ */
+void
+moko_journal_entry_free (MokoJournalEntry *a_entry)
+{
+  g_return_if_fail (a_entry) ;
+
+  moko_journal_entry_free_real (a_entry) ;
+}
+
+/**
+ * moko_journal_entry_get_type:
+ * @entry: the current journal entry
+ *
+ * get the primary type of the journal entry
+ *
+ * Return value: the type of the journal entry
+ */
+enum MokoJournalEntryType
+moko_journal_entry_get_type (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, UNDEF_ENTRY) ;
+
+  return a_entry->type ;
+}
+
+
+/**
+ * moko_journal_entry_set_type:
+ * @entry: the current instance of journal entry
+ * @type: the new type
+ *
+ * Set the type of the journal entry
+ */
+void
+moko_journal_entry_set_type (MokoJournalEntry *a_entry,
+                             enum MokoJournalEntryType a_type)
+{
+  g_return_if_fail (a_entry) ;
+  g_return_if_fail (a_type != UNDEF_ENTRY) ;
+
+  a_entry->type = a_type ;
+}
+
+/**
+ * moko_journal_entry_get_uid:
+ * @entry: the current instance of journal entry
+ *
+ * Gets the UID of the current entry. This UID is non NULL if and
+ * only if the entry has been persistet at least once.
+ *
+ * Return value: the UID in case the entry has been persisted at least once,
+ * NULL otherwise. The client code must *NOT* free the returned string.
+ */
+const gchar*
+moko_journal_entry_get_uid (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->uid ;
+}
+
+/**
+ * moko_journal_entry_get_contact_uid:
+ * @entry: the current instance of journal entry
+ *
+ * get the contact uid
+ *
+ * Return value: the UID of the contact. It can be NULL. Client code
+ * must not deallocate or attempt to alter it.
+ */
+const gchar*
+moko_journal_entry_get_contact_uid (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->contact_uid ;
+}
+
+void
+moko_journal_entry_set_contact_uid (MokoJournalEntry *a_entry,
+                                    const gchar *a_uid)
+{
+  g_return_if_fail (a_entry) ;
+
+  if (a_entry->contact_uid)
+  {
+    g_free (a_entry->contact_uid) ;
+    a_entry->contact_uid = NULL ;
+  }
+
+  if (a_uid)
+  {
+    a_entry->contact_uid = g_strdup (a_uid) ;
+  }
+}
+
+/**
+ * moko_journal_entry_get_summary:
+ * @entry: the current instance of journal entry
+ *
+ * get the summary of the journal entry
+ *
+ * Return value: the summary of the journal entry. It can be NULL.
+ * Client code must not deallocate or alter it.
+ */
+const gchar*
+moko_journal_entry_get_summary (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->summary ;
+}
+
+/**
+ * moko_journal_entry_set_summary:
+ * @entry: the current instance of journal entry
+ * @summary: the new summary of the journal entry. It is copied
+ * so client code is reponsible of its lifecyle.
+ *
+ * Set the summary of the journal entry
+ */
+void
+moko_journal_entry_set_summary (MokoJournalEntry *a_entry,
+                                const gchar* a_summary)
+{
+  g_return_if_fail (a_entry) ;
+
+  if (a_entry->summary)
+  {
+    g_free (a_entry->summary) ;
+    a_entry->summary = NULL ;
+  }
+  if (a_summary)
+  {
+    a_entry->summary = g_strdup (a_summary) ;
+  }
+}
+
+/**
+ * moko_journal_entry_get_dtdstart:
+ * @entry: the current instance of journal entry
+ *
+ * get the starting date associated to the journal entry
+ *
+ * Return value: an icaltimetype representing the starting date expected.
+ * It can be NULL. Client code must not deallocate it.
+ */
+const MokoTime*
+moko_journal_entry_get_dtstart (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  if (!a_entry->dtstart)
+    a_entry->dtstart = moko_time_new_today () ;
+
+  return a_entry->dtstart ;
+}
+
+/**
+ * moko_journal_entry_get_start_location:
+ * @a_entry: the current instance of journal entry
+ * @a_location: the requested location
+ *
+ * Get the location at which the message got received or sent.
+ *
+ * Returns: TRUE upon sucessful completion, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_get_start_location (MokoJournalEntry *a_entry,
+                                       MokoLocation *a_location)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_location, FALSE) ;
+
+  a_location->longitude = a_entry->start_longitude ;
+  a_location->latitude = a_entry->start_latitude ;
+
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_set_location:
+ * @a_entry: the current intance of journal entry
+ * @a_location: the new location
+ *
+ * Set a new location to the journal entry
+ * Location represents the longitude/latitude at which a call or message
+ * occured.
+ *
+ * Returns: TRUE upon successful completion, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_set_start_location (MokoJournalEntry *a_entry,
+                                       MokoLocation *a_location)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_location, FALSE) ;
+
+  a_entry->start_longitude = a_location->longitude ;
+  a_entry->start_latitude = a_location->latitude ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_get_direction:
+ * @entry: the current instance of journal entry
+ * @direction: either DIRECTION_IN for a received message or DIRECTION_OUT
+ * for a sent message.
+ *
+ * get the direction of the message
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_get_direction (MokoJournalEntry *a_entry,
+                                  enum MessageDirection *a_direction)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_direction, FALSE) ;
+
+  *a_direction = a_entry->direction ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_set_direction:
+ * @entry: the current instance of journal entry
+ * @direction: the new message direction to set
+ *
+ * set message direction
+ *
+ */
+void moko_journal_entry_set_direction (MokoJournalEntry *a_entry,
+                                       enum MessageDirection direction)
+{
+  g_return_if_fail (a_entry) ;
+
+  a_entry->direction = direction ;
+}
+
+/**
+ * moko_journal_entry_set_dtstart:
+ * @entry: the current instance of journal entry
+ * @dtstart: the new starting date associated to the journal entry.
+ */
+void
+moko_journal_entry_set_dtstart (MokoJournalEntry *a_entry, MokoTime* a_dtstart)
+{
+  g_return_if_fail (a_entry) ;
+
+  if (a_entry->dtstart)
+  {
+    moko_time_free (a_entry->dtstart) ;
+    a_entry->dtstart = NULL ;
+  }
+
+  if (a_dtstart)
+    a_entry->dtstart = a_dtstart ;
+}
+
+/**
+ * moko_journal_entry_get_source:
+ * @a_entry: the current instance of journal entry
+ *
+ * Returns: the source property. It is an arbitrary string representing
+ * the application that was the source of the entry (like mokodialer)
+ */
+const gchar*
+moko_journal_entry_get_source (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->source ;
+}
+
+/**
+ * moko_journal_entry_set_source:
+ * @a_entry: the current instance of journal entry
+ * @a_source: the new source to set
+ *
+ * Set the source property. It is an arbitrary string representing
+ * the application that was the source of the entry (like mokodialer)
+ */
+void
+moko_journal_entry_set_source (MokoJournalEntry *a_entry,
+                               const gchar *a_source)
+{
+  g_return_if_fail (a_entry) ;
+
+  if (a_entry->source)
+  {
+    g_free (a_entry->source) ;
+    a_entry->source = NULL ;
+  }
+  if (a_source)
+    a_entry->source = g_strdup (a_source) ;
+}
+
+/**
+ * moko_journal_entry_set_gsm_location:
+ * @a_entry: the current instance of voice call extra properties set
+ * @a_location: the gsm location
+ *
+ * Returns: TRUE upon completion, FALSE otherwise
+ */
+gboolean
+moko_journal_entry_set_gsm_location (MokoJournalEntry *a_entry,
+                                     MokoGSMLocation *a_location)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_location, FALSE) ;
+
+  memcpy (&a_entry->gsm_loc, a_location, sizeof (MokoGSMLocation)) ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_get_gsm_location:
+ * @a_entry: the current instance of voice call extra properties set
+ * @a_location: the gsm location
+ *
+ * Returns TRUE upon completion, FALSE otherwise
+ */
+gboolean
+moko_journal_entry_get_gsm_location (MokoJournalEntry *a_info,
+                                     MokoGSMLocation *a_location)
+{
+  g_return_val_if_fail (a_info, FALSE) ;
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  memcpy (a_location, &a_info->gsm_loc, sizeof (MokoGSMLocation)) ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_set_wifi_ap_mac_address:
+ * @entry: the current instance of journal entry
+ *
+ * the mac address of the wifi access point.
+ * It is must be a 48 bits long string of bytes.
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_set_wifi_ap_mac_address (MokoJournalEntry *a_entry,
+                                            const guchar *a_address)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+
+  if (!a_address)
+  {
+    if (a_entry->wifi_ap_mac)
+    {
+      g_free (a_entry->wifi_ap_mac) ;
+      a_entry->wifi_ap_mac = NULL ;
+    }
+    return TRUE ;
+  }
+
+  if (!a_entry->wifi_ap_mac)
+  {
+    a_entry->wifi_ap_mac = g_new0 (guchar, WIFI_AP_MAC_ADDR_LEN) ;
+  }
+  g_return_val_if_fail (a_entry->wifi_ap_mac, FALSE) ;
+  memcpy (a_entry->wifi_ap_mac, a_address, WIFI_AP_MAC_ADDR_LEN) ;
+
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_get_wifi_ap_mac_address:
+ * @entry: the current instance of journal entry
+ *
+ * Returns: the mac address of the wifi access point.
+ * It is a 48 bits long string of bytes. The calling code must
+ * *NOT* delete this pointer. This function can also return NULL if
+ * no wifi access point mac address has been set in the entry.
+ */
+const guchar*
+moko_journal_entry_get_wifi_ap_mac_address (MokoJournalEntry *a_entry)
+{
+  g_return_val_if_fail (a_entry, NULL) ;
+
+  return a_entry->wifi_ap_mac ;
+}
+
+/**
+ * moko_journal_entry_get_voice_info:
+ * @a_entry: the current instance of journal entry
+ * @a_info: the extra property set or NULL if info is not of type
+ * VOICE_JOURNAL_ENTRY
+ *
+ * Returns the specific property set associated to instance of MokoJournalEntry
+ * of type VOICE_JOURNAL_ENTRY.
+ *
+ * Returns: TRUE upon successful completion, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_get_voice_info (MokoJournalEntry *a_entry,
+                                   MokoJournalVoiceInfo **a_info)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_entry->type == VOICE_JOURNAL_ENTRY, FALSE) ;
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  if (!a_entry->extra.voice_info)
+  {
+    a_entry->extra.voice_info = moko_journal_voice_info_new ();
+  }
+  g_return_val_if_fail (a_entry->extra.voice_info, FALSE) ;
+  *a_info = a_entry->extra.voice_info ;
+  return TRUE ;
+}
+
+void
+moko_journal_voice_info_set_distant_number (MokoJournalVoiceInfo *a_info,
+                                            gchar *a_number)
+{
+  g_return_if_fail (a_info) ;
+
+  if (a_info->distant_number)
+  {
+    g_free (a_info->distant_number) ;
+    a_info->distant_number = NULL ;
+  }
+  if (a_number)
+    a_info->distant_number = g_strdup (a_number) ;
+}
+
+const gchar*
+moko_journal_voice_info_get_distant_number (MokoJournalVoiceInfo *a_info)
+{
+  g_return_val_if_fail (a_info, NULL) ;
+
+  return a_info->distant_number ;
+}
+
+void
+moko_journal_voice_info_set_local_number (MokoJournalVoiceInfo *a_info,
+                                           const gchar *a_number)
+{
+  g_return_if_fail (a_info);
+  g_return_if_fail (a_number) ;
+
+  if (a_info->local_number)
+  {
+    g_free (a_info->local_number) ;
+    a_info->local_number = NULL ;
+  }
+  if (a_number)
+    a_info->local_number = g_strdup (a_number) ;
+}
+
+const gchar*
+moko_journal_voice_info_get_local_number (MokoJournalVoiceInfo *a_info)
+{
+  g_return_val_if_fail (a_info, NULL) ;
+  return a_info->local_number ;
+}
+
+void
+moko_journal_voice_info_set_was_missed (MokoJournalVoiceInfo *a_info,
+                                        gboolean a_flag)
+{
+  g_return_if_fail (a_info) ;
+
+  a_info->was_missed = a_flag ;
+}
+
+gboolean
+moko_journal_voice_info_get_was_missed (MokoJournalVoiceInfo *a_info)
+{
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  return a_info->was_missed ;
+}
+
+/**
+ * moko_journal_entry_get_fax_info:
+ * @entry: the current instance of journal entry
+ * @info: the fax info properties set
+ *
+ * get the extra properties set associated to journal entries of
+ * type FAX_JOURNAL_ENTRY
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_get_fax_info (MokoJournalEntry *a_entry,
+                                 MokoJournalFaxInfo **a_info)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_entry->type == FAX_JOURNAL_ENTRY, FALSE) ;
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  if (!a_entry->extra.fax_info)
+  {
+    a_entry->extra.fax_info = moko_journal_fax_info_new () ;
+  }
+  g_return_val_if_fail (a_entry->extra.fax_info, FALSE) ;
+  *a_info = a_entry->extra.fax_info ;
+  return FALSE ;
+}
+
+/**
+ * moko_journal_entry_get_data_info:
+ * @a_entry: the current instance of journal entry
+ * @a_info: the resulting properties set
+ *
+ * Get the extra properties set associated to journal entries of type
+ * DATA_JOURNAL_ENTRY
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_data_info (MokoJournalEntry *a_entry,
+                                           MokoJournalDataInfo **a_info)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_entry->type == DATA_JOURNAL_ENTRY, FALSE) ;
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  if (!a_entry->extra.data_info)
+  {
+    a_entry->extra.data_info = moko_journal_data_info_new () ;
+  }
+  g_return_val_if_fail (a_entry->extra.data_info, FALSE) ;
+  *a_info = a_entry->extra.data_info ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_get_sms_info:
+ * @a_entry: the current instance of journal entry
+ * @a_info: the resulting properties set
+ *
+ * Get the extra properties set associated to journal entries of type
+ * SMS_JOURNAL_ENTRY
+ */
+gboolean
+moko_journal_entry_get_sms_info (MokoJournalEntry *a_entry,
+                                 MokoJournalSMSInfo **a_info)
+{
+  g_return_val_if_fail (a_entry, FALSE) ;
+  g_return_val_if_fail (a_entry->type == SMS_JOURNAL_ENTRY, FALSE) ;
+  g_return_val_if_fail (a_info, FALSE) ;
+
+  if (a_entry->extra.sms_info)
+  {
+    a_entry->extra.sms_info = moko_journal_sms_info_new () ;
+  }
+  g_return_val_if_fail (a_entry->extra.sms_info, FALSE) ;
+  *a_info = a_entry->extra.sms_info ;
+  return TRUE ;
+}
+
+/**
+ * moko_journal_entry_get_email_info:
+ * @entry: the current instance of journal entry
+ * @info: extra information attached to the email info, or NULL.
+ * Client code must *NOT* of deallocate the returned info.
+ * It is the duty of the MokoJournalEntry code to deallocate it when
+ * necessary
+ *
+ * Return value: TRUE if the call succeeded, FALSE otherwise.
+ */
+gboolean
+moko_journal_entry_get_email_info (MokoJournalEntry *a_entry,
+                                   MokoJournalEmailInfo **a_info)
+{
+  g_return_val_if_fail (a_entry->type == EMAIL_JOURNAL_ENTRY, FALSE) ;
+
+  if (!a_entry->extra.email_info)
+  {
+    a_entry->extra.email_info = moko_journal_email_info_new () ;
+  }
+  g_return_val_if_fail (a_entry->extra.email_info, FALSE) ;
+
+  *a_info = a_entry->extra.email_info ;
+  return TRUE ;
+}
+
+/*</public funcs>*/
Index: /trunk/libraries/libmokojournal/mokojournal/moko-time.c
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/moko-time.c	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/moko-time.c	(revision 2484)
@@ -0,0 +1,88 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <libical/icaltime.h>
+#include <glib.h>
+#include "moko-time.h"
+#include "moko-time-priv.h"
+
+
+MokoTime*
+moko_time_new_today ()
+{
+    MokoTime *result ;
+    result = g_new0 (MokoTime, 1) ;
+    result->t = icaltime_from_timet_with_zone (time (NULL), FALSE, NULL);
+    return result ;
+}
+
+MokoTime*
+moko_time_from_timet (const time_t a_t, gboolean a_is_date)
+{
+    MokoTime *result ;
+
+    result = g_new0 (MokoTime, 1) ;
+    result->t = icaltime_from_timet (a_t, a_is_date) ;
+    return result ;
+}
+
+MokoTime*
+moko_time_from_string (const gchar *a_iso_format_date)
+{
+    MokoTime *result ;
+
+    g_return_val_if_fail (a_iso_format_date, NULL) ;
+
+    result = g_new0 (MokoTime, 1) ;
+    result->t = icaltime_from_string (a_iso_format_date) ;
+    return result ;
+}
+
+MokoTime*
+moko_time_new_from_icaltimetype (icaltimetype a_dt)
+{
+  MokoTime *result ;
+
+  result = g_new0 (MokoTime, 1) ;
+  result->t = a_dt ;
+  return result ;
+}
+
+void
+moko_time_free (MokoTime *a_time)
+{
+    g_return_if_fail (a_time) ;
+
+    g_free (a_time) ;
+}
+
+const gchar*
+moko_time_as_ical_string (MokoTime *a_t)
+{
+    g_return_val_if_fail (a_t, NULL) ;
+    return icaltime_as_ical_string (a_t->t) ;
+}
+
+time_t
+moko_time_as_timet (const MokoTime *time)
+{
+  g_return_val_if_fail (time, 0) ;
+  return icaltime_as_timet (time->t) ;
+}
Index: /trunk/libraries/libmokojournal/mokojournal/moko-journal.h
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/moko-journal.h	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/moko-journal.h	(revision 2484)
@@ -0,0 +1,561 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __MOKO_JOURNAL_H__
+#define  __MOKO_JOURNAL_H__
+
+#include <glib.h>
+#include "moko-time.h" 
+
+/************************************************************
+ * this API abstracts the process of adding
+ * journal entries into the default system
+ * journal. Journal entries contain information
+ * about communation history like calls, sms, or,
+ * emails issued or received.
+ ***********************************************************/
+
+typedef struct _MokoJournal MokoJournal ;
+typedef struct _MokoJournalEntry MokoJournalEntry ;
+typedef struct _MokoJournalVoiceInfo MokoJournalVoiceInfo ;
+typedef struct _MokoJournalDataInfo MokoJournalDataInfo ;
+typedef struct _MokoJournalFaxInfo MokoJournalFaxInfo ;
+typedef struct _MokoJournalSMSInfo MokoJournalSMSInfo ;
+typedef struct _MokoJournalEmailInfo MokoJournalEmailInfo ;
+
+/**
+ * this represents the primary type of
+ * a journal entry.
+ */
+enum MokoJournalEntryType {
+  UNDEF_ENTRY=0,
+  EMAIL_JOURNAL_ENTRY,
+  /*sms calls*/
+  SMS_JOURNAL_ENTRY,
+  /*voice calls*/
+  VOICE_JOURNAL_ENTRY,
+  /*fax call*/
+  FAX_JOURNAL_ENTRY,
+  /*data calls (like modems)*/
+  DATA_JOURNAL_ENTRY,
+  NB_OF_ENTRY_TYPES /*must always be the last*/
+} ;
+
+enum MessageDirection {
+  DIRECTION_IN=0,
+  DIRECTION_OUT
+};
+
+typedef struct
+{
+  float longitude ;
+  float latitude ;
+} MokoLocation ;
+
+typedef struct
+{
+  /*local area code*/
+  gushort lac ;
+  /*cell id*/
+  gushort cid ;
+} MokoGSMLocation ;
+
+/* The 'entry added' callback function */
+typedef void (*MokoJournalEntryAddedFunc) (MokoJournal *journal, 
+                                           MokoJournalEntry *entry,
+                                           gpointer user_data);
+
+/* The 'entry added' callback function */
+typedef void (*MokoJournalEntryRemovedFunc) (MokoJournal *journal, 
+                                             const MokoJournalEntry *entry,
+                                             gpointer user_data);
+
+
+/*<journal management>*/
+/**
+ * moko_journal_open_default:
+ *
+ * Opens the default journal.
+ *
+ * Return value: a pointer to the journal object
+ */
+MokoJournal* moko_journal_open_default () ;
+
+/**
+ * moko_journal_close:
+ * @journal: the journal to close
+ *
+ * Close the journal previously opened with moko_journal_open_default().
+ * This function deallocates the memory of the Journal object.
+ */
+void moko_journal_close (MokoJournal *journal) ;
+
+/**
+ * moko_journal_set_entry_added_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is added or NULL.
+ * @data: the data you would like to pass to the callback or NULL.
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is added.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_added_callback (MokoJournal *journal,  
+                                            MokoJournalEntryAddedFunc func,
+                                            gpointer data) ;
+
+/**
+ * moko_journal_set_entry_removed_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is removed or NULL.
+ * @data: the data you would like to pass to the callback or NULL. 
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is removed.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_removed_callback (MokoJournal *journal,  
+                                              MokoJournalEntryRemovedFunc func,
+                                              gpointer data) ;
+
+
+/**
+ * moko_journal_add_entry:
+ * @journal: the current instance of journal
+ * @entry: the new entry to add to the journal. Must be non NULL.
+ * The journal is responsible
+ * of deallocating the memory of the entry object.
+ *
+ * Add a journal entry to the journal
+ *
+ * Return value: TRUE if the entry got successfully added to the journal,
+ * FALSE otherwise
+ */
+gboolean moko_journal_add_entry (MokoJournal *journal, MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_get_nb_entries:
+ * @journal: the current instance of journal
+ *
+ * Return value: the number of entries in the journal or a negative value
+ * in case of error.
+ */
+int moko_journal_get_nb_entries (MokoJournal *journal) ;
+
+/**
+ * moko_journal_get_entry_at:
+ * @journal: the current instance of journal
+ * @index: the index to get the journal entry from
+ * @entry: out parameter. the resulting journal entry
+ *
+ * Get the journal entry at a given index.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_get_entry_at (MokoJournal *journal,
+                                    guint index,
+                                    MokoJournalEntry **entry) ;
+
+/**
+ * moko_journal_remove_entry_at:
+ * @journal: the current instance of journal
+ * @index: the index to remove the entry from
+ *
+ * Remove a journal entry from index #index
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean moko_journal_remove_entry_at (MokoJournal *journal,
+                                       guint index) ;
+
+/**
+ * moko_journal_remove_entry_by_uid:
+ * @journal: the current instance of journal
+ * @uid: the uid of the journal entry to remove
+ *
+ * Remove the journal entry that has a given UID.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean moko_journal_remove_entry_by_uid (MokoJournal *journal,
+                                           const gchar* uid) ;
+
+/**
+ * moko_journal_write_to_storage:
+ * @journal: the journal to save to storage
+ *
+ * Saves the journal to persistent storage (e.g disk) using the
+ * appropriate backend. The backend currently used is evolution data server
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean moko_journal_write_to_storage (MokoJournal *journal) ;
+
+/**
+ * moko_journal_load_from_storage:
+ * @journal: the journal to load entries into
+ *
+ * Read the journal entries stored in the persistent storage (filesystem)
+ * and load then into the current instance of MokoJournal.
+ *
+ * Return value: TRUE in case of success, FALSE otherwise
+ */
+gboolean moko_journal_load_from_storage (MokoJournal *journal) ;
+
+/*<journal entries querying>*/
+/*</journal entries querying>*/
+
+/*</journal management>*/
+
+
+/*<journal entries management>*/
+
+/**
+ * moko_journal_entry_new:
+ * @type: the type of journal entry
+ *
+ * Create a Journal entry with no properties set.
+ * Use the JEntry accessors to get/set properties.
+ *
+ * Return value: the newly created journal entry object
+ */
+MokoJournalEntry* moko_journal_entry_new (enum MokoJournalEntryType type) ;
+
+/**
+ * moko_journal_entry_free:
+ * @entry: the entry to free
+ *
+ * Deallocate the memory of the journal entry object
+ */
+void moko_journal_entry_free (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_get_type:
+ * @entry: the current journal entry
+ *
+ * get the primary type of the journal entry
+ *
+ * Return value: the type of the journal entry
+ */
+enum MokoJournalEntryType moko_journal_entry_get_type (MokoJournalEntry *entry);
+
+/**
+ * moko_journal_entry_set_type:
+ * @entry: the current instance of journal entry
+ * @type: the new type
+ *
+ * Set the type of the journal entry
+ */
+void moko_journal_entry_set_type (MokoJournalEntry *entry,
+                                  enum MokoJournalEntryType type) ;
+
+/**
+ * moko_journal_entry_get_uid:
+ * @entry: the current instance of journal entry
+ *
+ * Gets the UID of the current entry. This UID is non NULL if and
+ * only if the entry has been persistet at least once.
+ *
+ * Return value: the UID in case the entry has been persisted at least once,
+ * NULL otherwise. The client code must *NOT* free the returned string.
+ */
+const gchar* moko_journal_entry_get_uid (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_get_contact_uid:
+ * @entry: the current instance of journal entry
+ *
+ * get the contact uid
+ *
+ * Return value: the UID of the contact. It can be NULL. Client code
+ * must not deallocate or attempt to alter it.
+ */
+const gchar* moko_journal_entry_get_contact_uid (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_set_contact_uid:
+ * @entry: the current instance of journal entry
+ * @uid: the uid to set. This string is copied so the client code
+ * must free it.
+ *
+ * Associate a new contact UID to the journal entry uid.
+ * The UID is copied by this function so the caller is reponsible of
+ * taking care of the uid string lifecycle.
+ */
+void  moko_journal_entry_set_contact_uid (MokoJournalEntry *entry,
+                                          const gchar *uid) ;
+
+/**
+ * moko_journal_entry_get_summary:
+ * @entry: the current instance of journal entry
+ *
+ * get the summary of the journal entry
+ *
+ * Return value: the summary of the journal entry. It can be NULL.
+ * Client code must not deallocate or alter it.
+ */
+const gchar* moko_journal_entry_get_summary (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_set_summary:
+ * @entry: the current instance of journal entry
+ * @summary: the new summary of the journal entry. It is copied
+ * so client code is reponsible of its lifecyle.
+ *
+ * Set the summary of the journal entry
+ */
+void moko_journal_entry_set_summary (MokoJournalEntry *entry,
+                                     const gchar* summary) ;
+
+/**
+ * moko_journal_entry_get_start_location:
+ * @entry: the current instance of journal entry
+ * @location: the requested location
+ *
+ * Get the location at which the message got received or sent.
+ *
+ * Returns: TRUE upon sucessful completion, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_start_location (MokoJournalEntry *entry,
+                                                MokoLocation *location) ;
+
+/**
+ * moko_journal_entry_set_location:
+ * @entry: the current intance of journal entry
+ * @location: the new location
+ *
+ * Set a new location to the journal entry
+ * Location represents the longitude/latitude at which a call or message
+ * occured.
+ *
+ * Returns: TRUE upon successful completion, FALSE otherwise.
+ */
+gboolean moko_journal_entry_set_start_location (MokoJournalEntry *entry,
+                                                MokoLocation *location) ;
+
+/**
+ * moko_journal_entry_get_direction:
+ * @entry: the current instance of journal entry
+ * @direction: either DIRECTION_IN for a received message or DIRECTION_OUT
+ * for a sent message.
+ *
+ * get the direction of the message
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_direction (MokoJournalEntry *entry,
+                                           enum MessageDirection *direction) ;
+
+/**
+ * moko_journal_entry_set_direction:
+ * @entry: the current instance of journal entry
+ * @direction: the new message direction to set
+ *
+ * set message direction
+ *
+ */
+void moko_journal_entry_set_direction (MokoJournalEntry *entry,
+                                       enum MessageDirection direction) ;
+
+/**
+ * moko_journal_entry_get_dtdstart:
+ * @entry: the current instance of journal entry
+ *
+ * get the starting date associated to the journal entry
+ *
+ * Returns: an icaltimetype representing the starting date expected.
+ * It can be NULL. Client code must not deallocate it.
+ */
+const MokoTime* moko_journal_entry_get_dtstart (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_set_dtstart:
+ * @entry: the current instance of journal entry
+ * @dtstart: the new starting date associated to the journal entry.
+ */
+void moko_journal_entry_set_dtstart (MokoJournalEntry *entry, MokoTime* dtstart);
+
+/**
+ * moko_journal_entry_get_source:
+ * @entry: the current instance of journal entry
+ *
+ * Returns: the source property. It is an arbitrary string representing
+ * the application that was the source of the entry (like mokodialer)
+ */
+const gchar* moko_journal_entry_get_source (MokoJournalEntry *entry) ;
+
+/**
+ * moko_journal_entry_set_source:
+ * @entry: the current instance of journal entry
+ * @source: the new source to set
+ *
+ * Set the source property. It is an arbitrary string representing
+ * the application that was the source of the entry (like mokodialer)
+ */
+void moko_journal_entry_set_source (MokoJournalEntry *entry,
+                                    const gchar *source) ;
+/**
+ * moko_journal_entry_set_gsm_location:
+ * @entry: the current instance of journal entry
+ * @location: the gsm location
+ *
+ * Returns: TRUE upon completion, FALSE otherwise
+ */
+gboolean moko_journal_entry_info_set_gsm_location (MokoJournalEntry *entry,
+                                                   MokoGSMLocation *location) ;
+
+/**
+ * moko_journal_entry_get_gsm_location:
+ * @entry: the current instance of journal entry
+ *
+ * Returns TRUE upon completion, FALSE otherwise
+ */
+gboolean moko_journal_entry_get_gsm_location (MokoJournalEntry *entry,
+                                              MokoGSMLocation *location);
+
+/**
+ * moko_journal_entry_set_wifi_ap_mac_address:
+ * @entry: the current instance of journal entry
+ *
+ * the mac address of the wifi access point.
+ * It is must be a 48 bits long string of bytes.
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_entry_set_wifi_ap_mac_address (MokoJournalEntry *entry,
+                                                     const guchar *address) ;
+
+/**
+ * moko_journal_entry_get_wifi_ap_mac_address:
+ * @entry: the current instance of journal entry
+ *
+ * Returns: the mac address of the wifi access point.
+ * It is a 48 bits long string of bytes. The calling code must
+ * *NOT* delete this pointer. This function can also return NULL if
+ * no wifi access point mac address has been set in the entry.
+ */
+const guchar *moko_journal_entry_get_wifi_ap_mac_address
+                                                  (MokoJournalEntry *entry) ;
+/*<voice call info>*/
+
+/**
+ * moko_journal_entry_get_voice_info:
+ * @entry: the current instance of journal entry
+ * @info: the extra property set or NULL if info is not of type
+ * VOICE_JOURNAL_ENTRY
+ *
+ * Returns the specific property set associated to instance of MokoJournalEntry
+ * of type VOICE_JOURNAL_ENTRY.
+ *
+ * Returns: TRUE upon successful completion, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_voice_info (MokoJournalEntry *entry,
+                                            MokoJournalVoiceInfo **info) ;
+
+
+/**
+ * moko_journal_voice_info_set_distant_number:
+ * @info: the current
+ * @info: the extra property set attached to the voice call
+ */
+void moko_journal_voice_info_set_distant_number (MokoJournalVoiceInfo *info,
+                                                gchar *number) ;
+
+const gchar* moko_journal_voice_info_get_distant_number
+                                                (MokoJournalVoiceInfo *info) ;
+
+void moko_journal_voice_info_set_local_number (MokoJournalVoiceInfo *info,
+                                                const gchar *number) ;
+
+const gchar* moko_journal_voice_info_get_local_number
+                                                (MokoJournalVoiceInfo *info) ;
+
+void moko_journal_voice_info_set_was_missed (MokoJournalVoiceInfo *info,
+                                             gboolean a_flag) ;
+
+gboolean moko_journal_voice_info_get_was_missed (MokoJournalVoiceInfo *info) ;
+
+/*</voice call info>*/
+
+/*<fax call info>*/
+
+/**
+ * moko_journal_entry_get_fax_info:
+ * @entry: the current instance of journal entry
+ * @info: the fax info properties set
+ *
+ * get the extra properties set associated to journal entries of
+ * type FAX_JOURNAL_ENTRY
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_fax_info (MokoJournalEntry *entry,
+                                          MokoJournalFaxInfo **info) ;
+
+/**
+ * moko_journal_entry_get_data_info:
+ * @entry: the current instance of journal entry
+ * @info: the resulting properties set
+ *
+ * Get the extra properties set associated to journal entries of type
+ * DATA_JOURNAL_ENTRY
+ *
+ * Returns: TRUE in case of success, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_data_info (MokoJournalEntry *entry,
+                                           MokoJournalDataInfo **info) ;
+/*</fax call info>*/
+
+/*<sms info>*/
+/**
+ * moko_journal_entry_get_sms_info:
+ * @entry: the current instance of journal entry
+ * @info: the resulting properties set
+ *
+ * Get the extra properties set associated to journal entries of type
+ * SMS_JOURNAL_ENTRY
+ */
+gboolean moko_journal_entry_get_sms_info (MokoJournalEntry *entry,
+                                          MokoJournalSMSInfo **info) ;
+/*</sms info>*/
+
+/*<email info>*/
+
+/**
+ * moko_journal_entry_get_email_info:
+ * @entry: the current instance of journal entry
+ * @info: extra information attached to the email info, or NULL.
+ * Client code must *NOT* of deallocate the returned info.
+ * It is the duty of the MokoJournalEntry code to deallocate it when
+ * necessary
+ *
+ * Return value: TRUE if the call succeeded, FALSE otherwise.
+ */
+gboolean moko_journal_entry_get_email_info (MokoJournalEntry *entry,
+                                            MokoJournalEmailInfo **info) ;
+
+/*</email info>*/
+
+
+/*</journal entries management>*/
+
+#endif /*__MOKO_JOURNAL_H__*/
Index: /trunk/libraries/libmokojournal/mokojournal/moko-time-priv.h
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/moko-time-priv.h	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/moko-time-priv.h	(revision 2484)
@@ -0,0 +1,31 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __MOKO_TIME_PRIV_H__
+#define  __MOKO_TIME_PRIV_H__
+
+struct _MokoTime
+{
+    icaltimetype t ;
+};
+
+MokoTime* moko_time_new_from_icaltimetype (icaltimetype dt) ;
+
+#endif  /*__MOKO_TIME_PRIV_H__*/
Index: /trunk/libraries/libmokojournal/mokojournal/moko-time.h
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal/moko-time.h	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal/moko-time.h	(revision 2484)
@@ -0,0 +1,35 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __MOKO_TIME_H__
+#define  __MOKO_TIME_H__
+
+#include <time.h>
+
+typedef struct _MokoTime MokoTime ;
+
+MokoTime* moko_time_new_today () ;
+MokoTime* moko_time_from_timet (const time_t t, gboolean is_date) ;
+MokoTime* moko_time_from_string (const gchar *iso_format_date) ;
+void moko_time_free (MokoTime *time) ;
+time_t moko_time_as_timet (const MokoTime *time) ;
+
+const gchar* moko_time_as_ical_string (MokoTime *t) ;
+#endif /*__MOKO_TIME_H__*/
Index: /trunk/libraries/libmokojournal/tests/Makefile.am
===================================================================
--- /trunk/libraries/libmokojournal/tests/Makefile.am	(revision 2484)
+++ /trunk/libraries/libmokojournal/tests/Makefile.am	(revision 2484)
@@ -0,0 +1,13 @@
+noinst_PROGRAMS=testcreate testdelete testdeleteuid
+
+testcreate_SOURCES=test-create.c
+testcreate_LDADD=@LIBS@ $(top_srcdir)/mokojournal/libmokojournal.la
+
+testdelete_SOURCES=test-delete.c
+testdelete_LDADD=@LIBS@ $(top_srcdir)/mokojournal/libmokojournal.la
+
+testdeleteuid_SOURCES=test-delete-uid.c
+testdeleteuid_LDADD=@LIBS@ $(top_srcdir)/mokojournal/libmokojournal.la
+
+INCLUDES= -I $(top_srcdir)/mokojournal
+
Index: /trunk/libraries/libmokojournal/tests/test-delete-uid.c
===================================================================
--- /trunk/libraries/libmokojournal/tests/test-delete-uid.c	(revision 2484)
+++ /trunk/libraries/libmokojournal/tests/test-delete-uid.c	(revision 2484)
@@ -0,0 +1,94 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <glib-object.h>
+#include "moko-journal.h"
+
+int
+main ()
+{
+    MokoJournal *journal=NULL ;
+    MokoJournalEntry *entry=NULL ;
+    int result=-1 ;
+
+    g_type_init () ;
+
+    /*open the journal*/
+    journal = moko_journal_open_default () ;
+    g_return_val_if_fail (journal, -1) ;
+
+    if (!moko_journal_load_from_storage (journal))
+    {
+        g_warning ("failed to load journal from storage\n") ;
+        goto out ;
+    }
+    g_message ("initial number of journal entries: %d\n",
+               moko_journal_get_nb_entries (journal)) ;
+
+    /*remove all entries from journal starting from the oldest one*/
+    while (moko_journal_get_nb_entries (journal) > 0)
+    {
+        entry = NULL ;
+        /*get the oldest entry*/
+        if (!moko_journal_get_entry_at (journal, 0, &entry) || !entry)
+        {
+            g_message ("failed to get entry at index 0\n") ;
+            goto out ;
+        }
+        /*make sure it has an UID*/
+        if (!moko_journal_entry_get_uid (entry))
+        {
+            g_message ("error: came accross an entry without UID\n") ;
+            goto out ;
+        }
+        /*remove the entry from the journal, using its UID*/
+        if (!moko_journal_remove_entry_by_uid
+                                        (journal,
+                                         moko_journal_entry_get_uid (entry)))
+        {
+            g_message ("failed to remove entry of UID '%s' from journal\n",
+                       moko_journal_entry_get_uid (entry)) ;
+            goto out ;
+        }
+    }
+    /*write the modifications we did, back to persistent storage*/
+    if (!moko_journal_write_to_storage (journal))
+    {
+        g_message ("failed to write to storage\n") ;
+        goto out ;
+    }
+
+    if (moko_journal_get_nb_entries (journal) != 0)
+    {
+        g_message ("test failed, we still have %d entries left\n",
+                   moko_journal_get_nb_entries (journal)) ;
+        goto out ;
+    }
+
+    /*if we reached this place, the test is prolly successful*/
+    g_message ("test succeeded") ;
+    result = 0 ;
+
+out:
+    if (journal)
+        moko_journal_close (journal) ;
+
+    return result ;
+}
Index: /trunk/libraries/libmokojournal/tests/test-delete.c
===================================================================
--- /trunk/libraries/libmokojournal/tests/test-delete.c	(revision 2484)
+++ /trunk/libraries/libmokojournal/tests/test-delete.c	(revision 2484)
@@ -0,0 +1,77 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <glib-object.h>
+#include "moko-journal.h"
+
+int
+main ()
+{
+    MokoJournal *journal=NULL ;
+    int result=-1 ;
+
+    g_type_init () ;
+
+    /*open the journal*/
+    journal = moko_journal_open_default () ;
+    g_return_val_if_fail (journal, -1) ;
+
+    if (!moko_journal_load_from_storage (journal))
+    {
+        g_warning ("failed to load journal from storage\n") ;
+        goto out ;
+    }
+    g_message ("initial number of journal entries: %d\n",
+               moko_journal_get_nb_entries (journal)) ;
+
+    /*remove all entries from journal starting from the oldest one*/
+    while (moko_journal_get_nb_entries (journal) > 0)
+    {
+        if (!moko_journal_remove_entry_at (journal, 0))
+        {
+            g_message ("failed to remove an entry from journal") ;
+            goto out ;
+        }
+    }
+
+    /*write the modifications we did to persistent storage*/
+    if (!moko_journal_write_to_storage (journal))
+    {
+        g_message ("failed to write to storage\n") ;
+        goto out ;
+    }
+
+    if (moko_journal_get_nb_entries (journal) != 0)
+    {
+        g_message ("test failed, we still have %d entries left\n",
+                   moko_journal_get_nb_entries (journal)) ;
+        goto out ;
+    }
+
+    /*if we reached this place, the test is prolly successful*/
+    g_message ("test succeeded") ;
+    result = 0 ;
+
+out:
+    if (journal)
+        moko_journal_close (journal) ;
+
+    return result ;
+}
Index: /trunk/libraries/libmokojournal/tests/test-create.c
===================================================================
--- /trunk/libraries/libmokojournal/tests/test-create.c	(revision 2484)
+++ /trunk/libraries/libmokojournal/tests/test-create.c	(revision 2484)
@@ -0,0 +1,177 @@
+/* vi: set sw=2: */
+/*
+ * Copyright (C) 2007 by OpenMoko, Inc.
+ * Written by OpenedHand Ltd <info@openedhand.com>
+ * All Rights Reserved
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <unistd.h>
+#include <glib-object.h>
+#include "moko-journal.h"
+
+int
+main ()
+{
+    MokoJournal *journal=NULL ;
+    MokoJournalEntry *entry=NULL ;
+    MokoJournalEmailInfo *email_info=NULL ;
+    MokoJournalVoiceInfo *voice_info=NULL ;
+    MokoLocation loc ;
+    MokoGSMLocation gsm_loc ;
+    int result = 1 ;
+
+    g_type_init () ;
+
+    /*open the journal*/
+    journal = moko_journal_open_default () ;
+    g_return_val_if_fail (journal, 1) ;
+
+    /*load all journal entries from the journal on storage*/
+    if (!moko_journal_load_from_storage (journal))
+    {
+        g_message ("failed to load journal from storage\n") ;
+        goto out ;
+    }
+    g_message ("loaded journal from storage okay\n") ;
+    g_message ("number journal entries: %d\n",
+                moko_journal_get_nb_entries (journal)) ;
+
+    /*create a journal entry of type 'email journal entry'*/
+    entry = moko_journal_entry_new (EMAIL_JOURNAL_ENTRY) ;
+    if (!entry)
+    {
+        g_warning ("failed to create journal entry\n") ;
+        goto out ;
+    }
+
+    /*****************************
+     * <fill the entry with data>
+     *****************************/
+    moko_journal_entry_set_contact_uid (entry, "foobarbazuid") ;
+    moko_journal_entry_set_summary (entry, "back from fostel") ;
+    moko_journal_entry_set_dtstart (entry, moko_time_new_today ()) ;
+    moko_journal_entry_set_direction (entry, DIRECTION_OUT) ;
+    loc.latitude = 37.386013;
+    loc.longitude =  10.082932;
+    moko_journal_entry_set_start_location (entry, &loc) ;
+    gsm_loc.lac = 68 ;
+    gsm_loc.cid = 100 ;
+    moko_journal_entry_set_gsm_location (entry, &gsm_loc) ;
+    if (!moko_journal_entry_get_email_info (entry, &email_info) || !email_info)
+    {
+        g_warning ("failed to get email extra info from journal entry\n") ;
+        goto out ;
+    }
+    /*****************************
+     * </fill the entry with data>
+     *****************************/
+
+    /*add the entry we created to the journal*/
+    if (!moko_journal_add_entry (journal, entry))
+    {
+        g_warning ("could not add entry to journal\n") ;
+        goto out ;
+    }
+    /*
+     * the entry is now owned by the journal, make sure we won't ever
+     * free it ourselves (by accident)
+     */
+    entry = NULL ;
+
+    /*create a journal entry of type 'voice call journal entry'*/
+    entry = moko_journal_entry_new (VOICE_JOURNAL_ENTRY) ;
+    if (!entry)
+    {
+        g_warning ("failed to create journal entry\n") ;
+        goto out ;
+    }
+
+    /*****************************
+     * <fill the entry with data>
+     *****************************/
+    moko_journal_entry_set_contact_uid (entry, "voicejournalentryuid") ;
+    moko_journal_entry_set_summary (entry, "this was a call") ;
+    moko_journal_entry_set_dtstart (entry, moko_time_new_today ()) ;
+    moko_journal_entry_set_direction (entry, DIRECTION_OUT) ;
+    loc.latitude = 43.386013;
+    loc.longitude =  15.082932;
+    moko_journal_entry_set_start_location (entry, &loc) ;
+    gsm_loc.lac = 67 ;
+    gsm_loc.cid = 200 ;
+    moko_journal_entry_set_gsm_location (entry, &gsm_loc) ;
+    if (!moko_journal_entry_get_voice_info (entry, &voice_info) || !voice_info)
+    {
+        g_warning ("failed to get voice extra info from journal entry\n") ;
+        goto out ;
+    }
+    /*****************************
+     * </fill the entry with data>
+     *****************************/
+
+    /*add the entry we created to the journal*/
+    if (!moko_journal_add_entry (journal, entry))
+    {
+        g_warning ("could not add entry to journal\n") ;
+        goto out ;
+    }
+    /*
+     * the entry is now owned by the journal, make sure we won't ever
+     * free it ourselves (by accident)
+     */
+    entry = NULL ;
+
+    /*sync the journal to persistent storage*/
+    if (!moko_journal_write_to_storage (journal))
+    {
+        g_warning ("Could not write journal to storage") ;
+        goto out ;
+    }
+
+    /*
+     * sleep a bit to wait for possible notifications, in case
+     * another process has added new journal entries as well
+     * this is not mandatory, but is there for the sake of testing.
+     */
+    sleep (2) ;
+
+    /*
+     * notifications of new journal entries being added to the journal
+     * is done via dbus, using the glib event loop to dispatch the
+     * notifications. So let's give the event loop a chance to
+     * let us notified of new entries that could have been added.
+     * Note that when using gtk+, you usually don't have to do this,
+     * as gtk+ does it for you magically.
+     */
+    while (g_main_context_pending (g_main_context_default ()))
+    {
+        g_main_context_iteration (g_main_context_default (), FALSE) ;
+    }
+    g_message ("number journal entries after one got added: %d\n",
+                moko_journal_get_nb_entries (journal)) ;
+
+    /*if we reached this point, the test has probably succeeded*/
+    result = 0;
+    g_print ("test succeeded\n") ;
+
+out:
+    if (journal)
+        moko_journal_close (journal) ;
+    if (entry)
+        moko_journal_entry_free (entry) ;
+
+    return result ;
+}
+
Index: /trunk/libraries/libmokojournal/configure.ac
===================================================================
--- /trunk/libraries/libmokojournal/configure.ac	(revision 2484)
+++ /trunk/libraries/libmokojournal/configure.ac	(revision 2484)
@@ -0,0 +1,38 @@
+AC_PREREQ(2.53)
+AC_INIT(libmokojournal, 0.0.4, http://www.openmoko.org/)
+AM_INIT_AUTOMAKE()
+AC_CONFIG_SRCDIR(mokojournal/moko-journal.c)
+AM_CONFIG_HEADER(config.h)
+AM_MAINTAINER_MODE
+
+AC_ISC_POSIX
+AC_PROG_CC
+AC_STDC_HEADERS
+AC_PROG_LIBTOOL
+
+LIBECAL_VERSION=1.4.2
+
+# base deps
+PKG_CHECK_MODULES(DEPS, libecal-1.2 >= $LIBECAL_VERSION)
+
+if test x$MOKO_DEVEL = xon ; then
+    AC_MSG_NOTICE([removing -O2 from CFLAGS])
+    CFLAGS="-g -Wall"
+fi
+
+LIBS="$LIBS $DEPS_LIBS"
+CFLAGS="$CFLAGS $DEPS_CFLAGS"
+
+AC_SUBST(LIBS)
+
+# output stuff
+AC_OUTPUT([
+Makefile
+mokojournal.pc
+mokojournal/Makefile
+tests/Makefile
+])
+
+echo "CFLAGS = $CFLAGS"
+echo "PREFIX = $prefix"
+echo "LIBS   = $LIBS"
Index: /trunk/libraries/libmokojournal/mokojournal.pc.in
===================================================================
--- /trunk/libraries/libmokojournal/mokojournal.pc.in	(revision 2484)
+++ /trunk/libraries/libmokojournal/mokojournal.pc.in	(revision 2484)
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include/mokojournal
+
+Name: libmokojournal
+Description: OpenMoko Journal Development Library
+Version: @VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -lmokojournal
+Requires: gtk+-2.0
Index: /trunk/libraries/libmokojournal/ChangeLog
===================================================================
--- /trunk/libraries/libmokojournal/ChangeLog	(revision 2484)
+++ /trunk/libraries/libmokojournal/ChangeLog	(revision 2484)
@@ -0,0 +1,18 @@
+2007-07-09  Neil J. Patel  <njp@o-hand.com>
+
+	* COPYING:
+	* Makefile.am:
+	* autogen.sh:
+	* configure.ac:
+	* mokojournal.pc.in:
+	* mokojournal/Makefile.am:
+	* mokojournal/moko-journal.c: 
+	* mokojournal/moko-journal.h:
+	* mokojournal/moko-time-priv.h:
+	* mokojournal/moko-time.c:
+	* mokojournal/moko-time.h:
+	* tests/Makefile.am:
+	* tests/test-create.c: (main):
+	* tests/test-delete-uid.c: (main):
+	* tests/test-delete.c: (main):
+	Initial Import from splitting openmoko-libs.
Index: /trunk/libraries/libmokojournal/COPYING
===================================================================
--- /trunk/libraries/libmokojournal/COPYING	(revision 2484)
+++ /trunk/libraries/libmokojournal/COPYING	(revision 2484)
@@ -0,0 +1,504 @@
+		  GNU LESSER GENERAL PUBLIC LICENSE
+		       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+		  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+			    NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
Index: /trunk/libraries/libmokojournal/Makefile.am
===================================================================
--- /trunk/libraries/libmokojournal/Makefile.am	(revision 2484)
+++ /trunk/libraries/libmokojournal/Makefile.am	(revision 2484)
@@ -0,0 +1,10 @@
+SUBDIRS = mokojournal tests
+
+pcdata_DATA= mokojournal.pc
+pcdatadir= $(libdir)/pkgconfig
+
+EXTRA_DIST= $(pcdata_DATA)
+
+# Extra clean files so that maintainer-clean removes *everything*
+MAINTAINERCLEANFILES = aclocal.m4 compile config.guess config.sub configure depcomp install-sh ltmain.sh Makefile.in missing config.h.in
+
Index: /trunk/libraries/libmokojournal/autogen.sh
===================================================================
--- /trunk/libraries/libmokojournal/autogen.sh	(revision 2484)
+++ /trunk/libraries/libmokojournal/autogen.sh	(revision 2484)
@@ -0,0 +1,4 @@
+#! /bin/sh
+autoreconf -v --install || exit 1
+glib-gettextize --force --copy || exit 1
+./configure --enable-maintainer-mode "$@"
