aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/pas/pas-backend-file.c
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2002-07-10 16:47:11 +0800
committerChris Toshok <toshok@src.gnome.org>2002-07-10 16:47:11 +0800
commit35624a9226fbb36f075ed40d1a61369f73570252 (patch)
tree9e7035df9ecb557a7c9c7fedfe46dc17474607d7 /addressbook/backend/pas/pas-backend-file.c
parenteed274191e31adb925555ebbb0fb58b7fb9989e8 (diff)
downloadgsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar.gz
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar.bz2
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar.lz
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar.xz
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.tar.zst
gsoc2013-evolution-35624a9226fbb36f075ed40d1a61369f73570252.zip
add Book.getCompletionView.
2002-07-10 Chris Toshok <toshok@ximian.com> * backend/idl/addressbook.idl: add Book.getCompletionView. * backend/ebook/e-book.c (e_book_get_completion_view): new function, basically c&p of e_book_get_book_view, but call getCompletionView. * backend/ebook/e-book.h: add prototype for e_book_get_completion_view. * backend/pas/pas-backend-ldap.c (pas_backend_ldap_process_client_requests): add a GetCompletionView case here that just calls the same code as GetBookView (since we don't build summaries for the ldap backend.) * backend/pas/pas-backend-file.c (do_summary_query): add @completion_search. If it's TRUE, just create the vcards from the summary using pas_backend_summary_get_summary_vcard instead of looking them up from the db. (pas_backend_file_search): add @completion_search and pass it on to do_summary_query. (pas_backend_file_process_get_book_view): pass FALSE to pas_backend_file_search. (pas_backend_file_process_get_completion_view): new function, basically c&p pas_backend_file_process_get_book_view, but pass TRUE to pas_backend_file_search. (pas_backend_file_process_client_requests): add a case for GetCompletionView. (pas_backend_file_load_uri): track the change to the summary api - create the summary filename * backend/pas/pas-book.c (pas_book_queue_get_completion_view): new function, queue a GetCompletionView request to our queue. (impl_GNOME_Evolution_Addressbook_Book_getCompletionView): new function, call pas_book_queue_get_completion_view. (pas_book_respond_get_completion_view): new function, just call notifyViewRequested. (pas_book_free_request): add a case for GetCompletionView. (pas_book_get_epv): fill in epv->getCompletionView. * backend/pas/pas-book.h: add a GetCompletionView PASOperation, and a new structure (PASGetCompletionViewRequest). Also, add get_completion_view to PASRequest. * backend/pas/pas-backend-summary.c (clear_items): remove the items from the hash table. (pas_backend_summary_new): db_path -> summary_path. (pas_backend_summary_destroy): db_.path -> summary_path, and destroy the hash table. (pas_backend_summary_init): db_path = summary_path, and initialize the id_to_item hashtable. (pas_backend_summary_load_header): handle the upgrading from version 1.0 to version 2.0 (the addition of an mtime field in the header) (pas_backend_summary_load_item): version 1.0 and 2.0 have the same format for items. (pas_backend_summary_open): new function. open the summary so we can load the header (and get the mtime). (pas_backend_summary_load): rework this a bit since the header has already been loaded, and also add the items to the hashtable. (pas_backend_summary_add_card): add the new item to the hashtable. (pas_backend_summary_remove_card): remove the item from the hash table. (pas_backend_summary_is_up_to_date): new function, chekc @t against the summary's mtime. (pas_backend_summary_get_summary_vcard): create a vcard from the fields we have in the summary. * backend/pas/pas-backend-summary.h: add prorotypes for pas_backend_summary_is_up_to_date and pas_backend_summary_get_summary_vcard. svn path=/trunk/; revision=17402
Diffstat (limited to 'addressbook/backend/pas/pas-backend-file.c')
-rw-r--r--addressbook/backend/pas/pas-backend-file.c97
1 files changed, 84 insertions, 13 deletions
diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c
index a6216cf98e..329b919e7d 100644
--- a/addressbook/backend/pas/pas-backend-file.c
+++ b/addressbook/backend/pas/pas-backend-file.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include <time.h>
#include <db.h>
+#include <sys/stat.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
@@ -131,8 +132,9 @@ build_summary (PASBackendFilePrivate *bfpriv)
}
static void
-do_summary_query (PASBackendFile *bf,
- PASBackendFileBookView *view)
+do_summary_query (PASBackendFile *bf,
+ PASBackendFileBookView *view,
+ gboolean completion_search)
{
GPtrArray *ids = pas_backend_summary_search (bf->priv->summary, view->search);
int db_error = 0;
@@ -144,14 +146,24 @@ do_summary_query (PASBackendFile *bf,
for (i = 0; i < ids->len; i ++) {
char *id = g_ptr_array_index (ids, i);
-
- string_to_dbt (id, &id_dbt);
- memset (&vcard_dbt, 0, sizeof (vcard_dbt));
+ char *vcard = NULL;
+
+ if (completion_search) {
+ vcard = pas_backend_summary_get_summary_vcard (bf->priv->summary,
+ id);
+ }
+ else {
+ string_to_dbt (id, &id_dbt);
+ memset (&vcard_dbt, 0, sizeof (vcard_dbt));
- db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0);
+ db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0);
- if (db_error == 0) {
- cards = g_list_prepend (cards, g_strdup (vcard_dbt.data));
+ if (db_error == 0)
+ vcard = g_strdup (vcard_dbt.data);
+ }
+
+ if (vcard) {
+ cards = g_list_prepend (cards, vcard);
card_count ++;
/* If we've accumulated a number of checks, pass them off to the client. */
@@ -326,7 +338,8 @@ vcard_matches_search (const PASBackendFileBookView *view, char *vcard_string)
static void
pas_backend_file_search (PASBackendFile *bf,
PASBook *book,
- const PASBackendFileBookView *cnstview)
+ const PASBackendFileBookView *cnstview,
+ gboolean completion_search)
{
PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview;
gboolean search_needed;
@@ -350,7 +363,7 @@ pas_backend_file_search (PASBackendFile *bf,
}
if (pas_backend_summary_is_summary_query (bf->priv->summary, view->search)) {
- do_summary_query (bf, view);
+ do_summary_query (bf, view, completion_search);
}
else {
gint card_count = 0, card_threshold = 20, card_threshold_max = 3000;
@@ -1000,7 +1013,46 @@ pas_backend_file_process_get_book_view (PASBackend *backend,
iterator = e_list_get_iterator(bf->priv->book_views);
e_iterator_last(iterator);
- pas_backend_file_search (bf, book, e_iterator_get(iterator));
+ pas_backend_file_search (bf, book, e_iterator_get(iterator), FALSE);
+ gtk_object_unref(GTK_OBJECT(iterator));
+}
+
+static void
+pas_backend_file_process_get_completion_view (PASBackend *backend,
+ PASBook *book,
+ PASGetCompletionViewRequest *req)
+{
+ PASBackendFile *bf = PAS_BACKEND_FILE (backend);
+ PASBookView *book_view;
+ PASBackendFileBookView view;
+ EIterator *iterator;
+
+ g_return_if_fail (req->listener != NULL);
+
+ bonobo_object_ref(BONOBO_OBJECT(book));
+
+ book_view = pas_book_view_new (req->listener);
+
+ gtk_signal_connect(GTK_OBJECT(book_view), "destroy",
+ GTK_SIGNAL_FUNC(view_destroy), book);
+
+ view.book_view = book_view;
+ view.search = g_strdup (req->search);
+ view.card_sexp = NULL;
+ view.change_id = NULL;
+ view.change_context = NULL;
+
+ e_list_append(bf->priv->book_views, &view);
+
+ pas_book_respond_get_completion_view (book,
+ (book_view != NULL
+ ? GNOME_Evolution_Addressbook_BookListener_Success
+ : GNOME_Evolution_Addressbook_BookListener_CardNotFound /* XXX */),
+ book_view);
+
+ iterator = e_list_get_iterator(bf->priv->book_views);
+ e_iterator_last(iterator);
+ pas_backend_file_search (bf, book, e_iterator_get(iterator), TRUE);
gtk_object_unref(GTK_OBJECT(iterator));
}
@@ -1145,6 +1197,10 @@ pas_backend_file_process_client_requests (PASBook *book)
pas_backend_file_process_get_book_view (backend, book, (PASGetBookViewRequest*)req);
break;
+ case GetCompletionView:
+ pas_backend_file_process_get_completion_view (backend, book, (PASGetCompletionViewRequest*)req);
+ break;
+
case GetChanges:
pas_backend_file_process_get_changes (backend, book, (PASGetChangesRequest*)req);
break;
@@ -1319,6 +1375,9 @@ pas_backend_file_load_uri (PASBackend *backend,
int db_error;
DB *db;
int major, minor, patch;
+ time_t db_mtime;
+ struct stat sb;
+ char *summary_filename;
g_assert (bf->priv->loaded == FALSE);
@@ -1405,10 +1464,22 @@ pas_backend_file_load_uri (PASBackend *backend,
g_free (bf->priv->filename);
bf->priv->filename = filename;
- bf->priv->summary = pas_backend_summary_new (filename, SUMMARY_FLUSH_TIMEOUT);
+ if (stat (bf->priv->filename, &sb) == -1) {
+ db->close (db, 0);
+ bf->priv->file_db = NULL;
+ bf->priv->writable = FALSE;
+ return GNOME_Evolution_Addressbook_BookListener_OtherError;
+ }
+ db_mtime = sb.st_mtime;
+
+ summary_filename = g_strconcat (bf->priv->filename, ".summary", NULL);
+ bf->priv->summary = pas_backend_summary_new (summary_filename, SUMMARY_FLUSH_TIMEOUT);
+ g_free (summary_filename);
- if (!pas_backend_summary_load (bf->priv->summary))
+ if (pas_backend_summary_is_up_to_date (bf->priv->summary, db_mtime) == FALSE
+ || pas_backend_summary_load (bf->priv->summary) == FALSE ) {
build_summary (bf->priv);
+ }
return GNOME_Evolution_Addressbook_BookListener_Success;
}