From f699f9902b5e374070e8dd2c0fe43028f8dfb89f Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Tue, 5 Jun 2001 23:49:59 +0000 Subject: Copy dates as they come in. 2001-06-05 Christopher James Lahey * backend/ebook/e-card.c (e_card_set_arg): Copy dates as they come in. * backend/pas/pas-backend-file.c (pas_backend_file_changes_foreach_key, pas_backend_file_changes, pas_backend_file_process_remove_card, pas_backend_file_process_modify_card, pas_backend_file_build_all_cards_list, pas_backend_file_get_vcard, pas_backend_file_maybe_upgrade_db): memset DBTs to 0 before using them. (pas_backend_file_build_all_cards_list): Reindented. * contact-editor/contact-editor.glade: Replaced GnomeDateEdits with a custom widget that creates an EDateEdit. * contact-editor/e-contact-editor.c: Use an EDateEdit here instead of a GnomeDateEdit. svn path=/trunk/; revision=10125 --- addressbook/backend/ebook/e-card.c | 14 ++++++- addressbook/backend/pas/pas-backend-file.c | 62 +++++++++++++++++------------- 2 files changed, 48 insertions(+), 28 deletions(-) (limited to 'addressbook/backend') diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 55b91e26d7..59fa211d39 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -1688,7 +1688,12 @@ e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) break; case ARG_BIRTH_DATE: g_free(card->bday); - card->bday = GTK_VALUE_POINTER(*arg); + if (GTK_VALUE_POINTER (*arg)) { + card->bday = g_new (ECardDate, 1); + memcpy (card->bday, GTK_VALUE_POINTER (*arg), sizeof (ECardDate)); + } else { + card->bday = NULL; + } break; case ARG_URL: g_free(card->url); @@ -1732,7 +1737,12 @@ e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) break; case ARG_ANNIVERSARY: g_free(card->anniversary); - card->anniversary = GTK_VALUE_POINTER(*arg); + if (GTK_VALUE_POINTER (*arg)) { + card->anniversary = g_new (ECardDate, 1); + memcpy (card->anniversary, GTK_VALUE_POINTER (*arg), sizeof (ECardDate)); + } else { + card->anniversary = NULL; + } break; case ARG_MAILER: g_free(card->mailer); diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 0c0cd5c7db..222f72b74b 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -597,6 +597,7 @@ pas_backend_file_changes_foreach_key (const char *key, gpointer user_data) int db_error = 0; string_to_dbt (key, &id_dbt); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error == 1) { @@ -621,6 +622,9 @@ pas_backend_file_changes (PASBackendFile *bf, PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview; PASBackendFileChangeContext *ctx = cnstview->change_context; + memset (&id_dbt, 0, sizeof (id_dbt)); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); + if (!bf->priv->loaded) return; @@ -805,6 +809,7 @@ pas_backend_file_process_remove_card (PASBackend *backend, char *vcard_string; string_to_dbt (req->id, &id_dbt); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (0 != db_error) { @@ -865,6 +870,7 @@ pas_backend_file_process_modify_card (PASBackend *backend, id = e_card_get_id(card); string_to_dbt (id, &id_dbt); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); /* get the old ecard - the one that's presently in the db */ db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); @@ -929,43 +935,45 @@ static void pas_backend_file_build_all_cards_list(PASBackend *backend, PASBackendFileCursorPrivate *cursor_data) { - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - DBC *dbc; - int db_error; - DBT id_dbt, vcard_dbt; + PASBackendFile *bf = PAS_BACKEND_FILE (backend); + DB *db = bf->priv->file_db; + DBC *dbc; + int db_error; + DBT id_dbt, vcard_dbt; - cursor_data->elements = NULL; + cursor_data->elements = NULL; - db_error = db->cursor (db, NULL, &dbc, 0); + db_error = db->cursor (db, NULL, &dbc, 0); - if (db_error != 0) { - g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); - } + if (db_error != 0) { + g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); + } - db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); + memset (&id_dbt, 0, sizeof (id_dbt)); + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST); - while (db_error == 0) { + while (db_error == 0) { - /* don't include the version in the list of cards */ - if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { + /* don't include the version in the list of cards */ + if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 + || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - cursor_data->elements = g_list_append(cursor_data->elements, - g_strdup(vcard_dbt.data)); + cursor_data->elements = g_list_append(cursor_data->elements, + g_strdup(vcard_dbt.data)); - } + } - db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); - } + } - if (db_error != DB_NOTFOUND) { - g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); - } - else { - cursor_data->num_elements = g_list_length (cursor_data->elements); - } + if (db_error != DB_NOTFOUND) { + g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); + } + else { + cursor_data->num_elements = g_list_length (cursor_data->elements); + } } static void @@ -1290,6 +1298,7 @@ pas_backend_file_get_vcard (PASBook *book, const char *id) db = bf->priv->file_db; string_to_dbt (id, &id_dbt); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error == 0) { @@ -1341,6 +1350,7 @@ pas_backend_file_maybe_upgrade_db (PASBackendFile *bf) gboolean ret_val = TRUE; string_to_dbt (PAS_BACKEND_FILE_VERSION_NAME, &version_name_dbt); + memset (&version_dbt, 0, sizeof (version_dbt)); db_error = db->get (db, NULL, &version_name_dbt, &version_dbt, 0); if (db_error == 0) { -- cgit