r19941 - gnucash/trunk/src - Implement prerequisites for full auto-completion in the entry ledger.

Christian Stimming cstim at code.gnucash.org
Tue Dec 14 16:25:52 EST 2010


Author: cstim
Date: 2010-12-14 16:25:52 -0500 (Tue, 14 Dec 2010)
New Revision: 19941
Trac: http://svn.gnucash.org/trac/changeset/19941

Added:
   gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
   gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
Modified:
   gnucash/trunk/src/gnome-utils/Makefile.am
   gnucash/trunk/src/register/register-core/quickfillcell.c
   gnucash/trunk/src/register/register-core/quickfillcell.h
Log:
Implement prerequisites for full auto-completion in the entry ledger.

Added a cached quickfill for GncEntry description lines. Extend QuickFillCell
interface to be able to use a common cached quickfill.

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2010-12-14 20:32:56 UTC (rev 19940)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2010-12-14 21:25:52 UTC (rev 19941)
@@ -63,6 +63,7 @@
   gnc-druid-provider-file-gnome.c \
   gnc-druid-provider-multifile-gnome.c \
   gnc-embedded-window.c \
+  gnc-entry-quickfill.c \
   gnc-file.c \
   gnc-frequency.c \
   gnc-recurrence.c \
@@ -135,6 +136,7 @@
   gnc-dense-cal-store.h \
   gnc-druid-gnome-ui.h \
   gnc-embedded-window.h \
+  gnc-entry-quickfill.h \
   gnc-file.h \
   gnc-frequency.h \
   gnc-recurrence.h \

Added: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c	2010-12-14 21:25:52 UTC (rev 19941)
@@ -0,0 +1,98 @@
+/********************************************************************\
+ * gnc-entry-quickfill.c -- Create an entry description quick-fill  *
+ * Copyright (C) 2010 Christian Stimming <christian at cstimming.de>   *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+#include "gnc-entry-quickfill.h"
+
+typedef struct
+{
+    QuickFill *qf;
+    QuickFillSort qf_sort;
+    QofBook *book;
+} EntryQF;
+
+static void
+shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
+{
+    EntryQF *qfb = user_data;
+    gnc_quickfill_destroy (qfb->qf);
+    /* qof_event_unregister_handler (qfb->listener); */
+    g_free (qfb);
+}
+
+static void entry_cb(gpointer data, gpointer user_data)
+{
+    const GncEntry* entry = data;
+    EntryQF *s = (EntryQF *) user_data;
+    gnc_quickfill_insert (s->qf, gncEntryGetDescription(entry), s->qf_sort);
+}
+
+/** Creates a new query that searches for all GncEntry items in the
+ * current book. */
+static QofQuery *new_query_for_entrys(QofBook *book)
+{
+    QofQuery *query = qof_query_create_for (GNC_ID_ENTRY);
+    g_assert(book);
+    qof_query_set_book (query, book);
+    return query;
+}
+
+static EntryQF* build_shared_quickfill (QofBook *book, const char * key)
+{
+    EntryQF *result;
+    QofQuery *query = new_query_for_entrys(book);
+    GList *entries = qof_query_run(query);
+
+/*     g_warning("Found %d GncEntry items", g_list_length (entries)); */
+
+    result = g_new0(EntryQF, 1);
+
+    result->qf = gnc_quickfill_new();
+    result->qf_sort = QUICKFILL_LIFO;
+    result->book = book;
+
+    g_list_foreach (entries, entry_cb, result);
+
+    qof_query_destroy(query);
+
+    qof_book_set_data_fin (book, key, result, shared_quickfill_destroy);
+
+    return result;
+}
+
+QuickFill * gnc_get_shared_entry_desc_quickfill (QofBook *book,
+        const char * key)
+{
+    EntryQF *qfb;
+
+    g_assert(book);
+    g_assert(key);
+
+    qfb = qof_book_get_data (book, key);
+
+    if (qfb)
+        return qfb->qf;
+
+    qfb = build_shared_quickfill(book, key);
+    return qfb->qf;
+}


Property changes on: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Added: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h	2010-12-14 21:25:52 UTC (rev 19941)
@@ -0,0 +1,49 @@
+/********************************************************************\
+ * gnc-entry-quickfill.h -- Create an entry description quick-fill  *
+ * Copyright (C) 2010 Christian Stimming <christian at cstimming.de>   *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup QuickFill Auto-complete typed user input.
+   @{
+*/
+/** Similar to the @ref Account_QuickFill account name quickfill, we
+ * create a cached quickfill with the description of all entries.
+*/
+
+#ifndef GNC_ENTRY_QUICKFILL_H
+#define GNC_ENTRY_QUICKFILL_H
+
+#include "qof.h"
+#include "engine/gncEntry.h"
+#include "gnome-utils/QuickFill.h"
+
+/** Create/fetch a quickfill GncEntry description strings.
+ *
+ *  Multiple, distinct quickfills, for different uses, are allowed.
+ *  Each is identified with the 'key'.  Be sure to use distinct,
+ *  unique keys that don't conflict with other users of QofBook.
+ */
+QuickFill * gnc_get_shared_entry_desc_quickfill (QofBook *book,
+        const char * key);
+
+#endif
+
+/** @} */
+/** @} */


Property changes on: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
___________________________________________________________________
Added: svn:eol-style
   + LF

Modified: gnucash/trunk/src/register/register-core/quickfillcell.c
===================================================================
--- gnucash/trunk/src/register/register-core/quickfillcell.c	2010-12-14 20:32:56 UTC (rev 19940)
+++ gnucash/trunk/src/register/register-core/quickfillcell.c	2010-12-14 21:25:52 UTC (rev 19941)
@@ -259,7 +259,10 @@
 {
     QuickFillCell *cell = (QuickFillCell *) bcell;
 
-    gnc_quickfill_destroy (cell->qf);
+    if (!cell->use_quickfill_cache)
+    {
+        gnc_quickfill_destroy (cell->qf);
+    }
     cell->qf = NULL;
 
     g_free (cell->original);
@@ -277,6 +280,7 @@
     gnc_basic_cell_init (&(cell->cell));
 
     cell->qf = gnc_quickfill_new ();
+    cell->use_quickfill_cache = FALSE;
     cell->sort = QUICKFILL_LIFO;
     cell->original = NULL;
 
@@ -341,3 +345,17 @@
 
     gnc_quickfill_insert (cell->qf, completion, cell->sort);
 }
+
+void
+gnc_quickfill_cell_use_quickfill_cache (QuickFillCell *cell, QuickFill *shared_qf)
+{
+    g_assert(cell);
+    g_assert(shared_qf);
+
+    if (!cell->use_quickfill_cache)
+    {
+        cell->use_quickfill_cache = TRUE;
+        gnc_quickfill_destroy (cell->qf);
+    }
+    cell->qf = shared_qf;
+}

Modified: gnucash/trunk/src/register/register-core/quickfillcell.h
===================================================================
--- gnucash/trunk/src/register/register-core/quickfillcell.h	2010-12-14 20:32:56 UTC (rev 19940)
+++ gnucash/trunk/src/register/register-core/quickfillcell.h	2010-12-14 21:25:52 UTC (rev 19941)
@@ -59,6 +59,8 @@
                         * default is QUICKFILL_LIFO. */
 
     char *original;  /* original string entered in original case */
+
+    gboolean use_quickfill_cache;  /* If TRUE, we don't own the qf */
 } QuickFillCell;
 
 BasicCell *      gnc_quickfill_cell_new (void);
@@ -72,4 +74,10 @@
 void             gnc_quickfill_cell_add_completion (QuickFillCell *cell,
         const char *completion);
 
+/** Lets the cell use the given shared quickfill object instead of the
+ * one it owns internally. The cell will not delete the shared
+ * quickfill upon destruction. */
+void
+gnc_quickfill_cell_use_quickfill_cache (QuickFillCell *cell, QuickFill *shared_qf);
+
 #endif



More information about the gnucash-changes mailing list