r20176 - gnucash/trunk/src - Move quickfill and gnc-entry-quickfill files from gnome-utils to app-utils because they don't require gtk/gnome.

Christian Stimming cstim at code.gnucash.org
Thu Jan 27 14:22:17 EST 2011


Author: cstim
Date: 2011-01-27 14:22:16 -0500 (Thu, 27 Jan 2011)
New Revision: 20176
Trac: http://svn.gnucash.org/trac/changeset/20176

Added:
   gnucash/trunk/src/app-utils/QuickFill.c
   gnucash/trunk/src/app-utils/QuickFill.h
   gnucash/trunk/src/app-utils/gnc-entry-quickfill.c
   gnucash/trunk/src/app-utils/gnc-entry-quickfill.h
Removed:
   gnucash/trunk/src/gnome-utils/QuickFill.c
   gnucash/trunk/src/gnome-utils/QuickFill.h
   gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
   gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
Modified:
   gnucash/trunk/src/app-utils/CMakeLists.txt
   gnucash/trunk/src/app-utils/Makefile.am
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
   gnucash/trunk/src/gnome-utils/Makefile.am
Log:
Move quickfill and gnc-entry-quickfill files from gnome-utils to app-utils because they don't require gtk/gnome.

(account-quickfill can't be moved because it also works with a GtkListStore.)

Modified: gnucash/trunk/src/app-utils/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/app-utils/CMakeLists.txt	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/app-utils/CMakeLists.txt	2011-01-27 19:22:16 UTC (rev 20176)
@@ -20,6 +20,7 @@
 INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}) # for <option-util.h>
 
 SET (app_utils_HEADERS
+  QuickFill.h
   file-utils.h
   gfec.h
   gnc-basic-gobject.h
@@ -34,6 +35,7 @@
   gnc-druid-provider-desc-file.h
   gnc-druid-provider-desc-multifile.h
   gnc-druid-provider-file-cb.h
+  gnc-entry-quickfill.h
   gnc-euro.h
   gnc-exp-parser.h
   gnc-gettext-util.h
@@ -51,6 +53,7 @@
 GNC_ADD_SWIG_COMMAND (${SWIG_APP_UTILS_C} ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i)
 
 SET (app_utils_SOURCES
+  QuickFill.c
   file-utils.c
   gfec.c
   gnc-account-merge.c
@@ -64,6 +67,7 @@
   gnc-druid-provider-desc-file.c
   gnc-druid-provider-desc-multifile.c
   gnc-druid-provider-file-cb.c
+  gnc-entry-quickfill.c
   gnc-euro.c
   gnc-exp-parser.c
   gnc-gettext-util.c

Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/app-utils/Makefile.am	2011-01-27 19:22:16 UTC (rev 20176)
@@ -35,6 +35,7 @@
 
 libgncmod_app_utils_la_SOURCES = \
   swig-app-utils.c \
+  QuickFill.c \
   file-utils.c \
   gfec.c \
   gnc-account-merge.c \
@@ -48,6 +49,7 @@
   gnc-druid-provider-desc-file.c \
   gnc-druid-provider-desc-multifile.c \
   gnc-druid-provider-file-cb.c \
+  gnc-entry-quickfill.c \
   gnc-euro.c \
   gnc-exp-parser.c \
   gnc-gettext-util.c \
@@ -60,6 +62,7 @@
 
 gncincludedir = ${GNC_INCLUDE_DIR}
 gncinclude_HEADERS = \
+  QuickFill.h \
   file-utils.h \
   gfec.h \
   gnc-basic-gobject.h \
@@ -74,6 +77,7 @@
   gnc-druid-provider-desc-file.h \
   gnc-druid-provider-desc-multifile.h \
   gnc-druid-provider-file-cb.h \
+  gnc-entry-quickfill.h \
   gnc-euro.h \
   gnc-exp-parser.h \
   gnc-gettext-util.h \

Copied: gnucash/trunk/src/app-utils/QuickFill.c (from rev 20174, gnucash/trunk/src/gnome-utils/QuickFill.c)
===================================================================
--- gnucash/trunk/src/app-utils/QuickFill.c	                        (rev 0)
+++ gnucash/trunk/src/app-utils/QuickFill.c	2011-01-27 19:22:16 UTC (rev 20176)
@@ -0,0 +1,453 @@
+/********************************************************************\
+ * QuickFill.h -- the quickfill tree data structure                 *
+ * Copyright (C) 1997 Robin D. Clark                                *
+ * Copyright (C) 1998 Linas Vepstas                                 *
+ * Copyright (C) 2000 Dave Peticolas                                *
+ *                                                                  *
+ * 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 <string.h>
+
+#include "QuickFill.h"
+#include "gnc-engine.h"
+#include "gnc-ui-util.h"
+
+
+struct _QuickFill
+{
+    char *text;          /* the first matching text string     */
+    int len;             /* number of chars in text string     */
+    GHashTable *matches; /* array of children in the tree      */
+};
+
+
+/** PROTOTYPES ******************************************************/
+static void quickfill_insert_recursive (QuickFill *qf, const char *text,
+                                        int depth, QuickFillSort sort);
+
+static void gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text,
+        gint depth, QuickFillSort sort);
+
+/* This static indicates the debugging module that this .o belongs to.  */
+static QofLogModule log_module = GNC_MOD_REGISTER;
+
+/********************************************************************\
+\********************************************************************/
+
+QuickFill *
+gnc_quickfill_new (void)
+{
+    QuickFill *qf;
+
+    if (sizeof (guint) < sizeof (gunichar))
+    {
+        PWARN ("Can't use quickfill");
+        return NULL;
+    }
+
+    qf = g_new (QuickFill, 1);
+
+    qf->text = NULL;
+    qf->len = 0;
+
+    qf->matches = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+    return qf;
+}
+
+/********************************************************************\
+\********************************************************************/
+
+static gboolean
+destroy_helper (gpointer key, gpointer value, gpointer data)
+{
+    gnc_quickfill_destroy (value);
+    return TRUE;
+}
+
+void
+gnc_quickfill_destroy (QuickFill *qf)
+{
+    if (qf == NULL)
+        return;
+
+    g_hash_table_foreach (qf->matches, (GHFunc)destroy_helper, NULL);
+    g_hash_table_destroy (qf->matches);
+    qf->matches = NULL;
+
+    if (qf->text)
+        CACHE_REMOVE(qf->text);
+    qf->text = NULL;
+    qf->len = 0;
+
+    g_free (qf);
+}
+
+void
+gnc_quickfill_purge (QuickFill *qf)
+{
+    if (qf == NULL)
+        return;
+
+    g_hash_table_foreach_remove (qf->matches, destroy_helper, NULL);
+
+    if (qf->text)
+        CACHE_REMOVE (qf->text);
+    qf->text = NULL;
+    qf->len = 0;
+}
+
+/********************************************************************\
+\********************************************************************/
+
+const char *
+gnc_quickfill_string (QuickFill *qf)
+{
+    if (qf == NULL)
+        return NULL;
+
+    return qf->text;
+}
+
+/********************************************************************\
+\********************************************************************/
+
+QuickFill *
+gnc_quickfill_get_char_match (QuickFill *qf, gunichar uc)
+{
+    guint key = g_unichar_toupper (uc);
+
+    if (NULL == qf) return NULL;
+
+    DEBUG ("xaccGetQuickFill(): index = %u\n", key);
+
+    return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
+}
+
+/********************************************************************\
+\********************************************************************/
+
+QuickFill *
+gnc_quickfill_get_string_len_match (QuickFill *qf,
+                                    const char *str, int len)
+{
+    const char *c;
+    gunichar uc;
+
+    if (NULL == qf) return NULL;
+    if (NULL == str) return NULL;
+
+    c = str;
+    while (*c && (len > 0))
+    {
+        if (qf == NULL)
+            return NULL;
+
+        uc = g_utf8_get_char (c);
+        qf = gnc_quickfill_get_char_match (qf, uc);
+
+        c = g_utf8_next_char (c);
+        len--;
+    }
+
+    return qf;
+}
+
+/********************************************************************\
+\********************************************************************/
+
+QuickFill *
+gnc_quickfill_get_string_match (QuickFill *qf, const char *str)
+{
+    if (NULL == qf) return NULL;
+    if (NULL == str) return NULL;
+
+    return gnc_quickfill_get_string_len_match (qf, str, g_utf8_strlen (str, -1));
+}
+
+/********************************************************************\
+\********************************************************************/
+
+static void
+unique_len_helper (gpointer key, gpointer value, gpointer data)
+{
+    QuickFill **qf_p = data;
+
+    *qf_p = value;
+}
+
+QuickFill *
+gnc_quickfill_get_unique_len_match (QuickFill *qf, int *length)
+{
+    if (length != NULL)
+        *length = 0;
+
+    if (qf == NULL)
+        return NULL;
+
+    while (1)
+    {
+        guint count;
+
+        count = g_hash_table_size (qf->matches);
+
+        if (count != 1)
+        {
+            return qf;
+        }
+
+        g_hash_table_foreach (qf->matches, unique_len_helper, &qf);
+
+        if (length != NULL)
+            (*length)++;
+    }
+}
+
+/********************************************************************\
+\********************************************************************/
+
+void
+gnc_quickfill_insert (QuickFill *qf, const char *text, QuickFillSort sort)
+{
+    gchar *normalized_str;
+
+    if (NULL == qf) return;
+    if (NULL == text) return;
+
+
+    normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
+    quickfill_insert_recursive (qf, normalized_str, 0, sort);
+    g_free (normalized_str);
+}
+
+/********************************************************************\
+\********************************************************************/
+
+static void
+quickfill_insert_recursive (QuickFill *qf, const char *text, int depth,
+                            QuickFillSort sort)
+{
+    guint key;
+    char *old_text;
+    QuickFill *match_qf;
+    int len;
+    char *key_char;
+    gunichar key_char_uc;
+
+    if (qf == NULL)
+        return;
+
+    if ((text == NULL) || (g_utf8_strlen (text, -1) <= depth))
+        return;
+
+    key_char = g_utf8_offset_to_pointer (text, depth);
+
+    key_char_uc = g_utf8_get_char (key_char);
+    key = g_unichar_toupper (key_char_uc);
+
+    match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
+    if (match_qf == NULL)
+    {
+        match_qf = gnc_quickfill_new ();
+        g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf);
+    }
+
+    old_text = match_qf->text;
+
+    switch (sort)
+    {
+    case QUICKFILL_ALPHA:
+        if (old_text && (g_utf8_collate (text, old_text) >= 0))
+            break;
+
+    case QUICKFILL_LIFO:
+    default:
+        len = g_utf8_strlen (text, -1);
+
+        /* If there's no string there already, just put the new one in. */
+        if (old_text == NULL)
+        {
+            match_qf->text = CACHE_INSERT((gpointer) text);
+            match_qf->len = len;
+            break;
+        }
+
+        /* Leave prefixes in place */
+        if ((len > match_qf->len) &&
+                (strncmp(text, old_text, strlen(old_text)) == 0))
+            break;
+
+        CACHE_REMOVE(old_text);
+        match_qf->text = CACHE_INSERT((gpointer) text);
+        match_qf->len = len;
+        break;
+    }
+
+    quickfill_insert_recursive (match_qf, text, ++depth, sort);
+}
+
+/********************************************************************\
+\********************************************************************/
+
+void
+gnc_quickfill_remove (QuickFill *qf, const gchar *text, QuickFillSort sort)
+{
+    gchar *normalized_str;
+
+    if (qf == NULL) return;
+    if (text == NULL) return;
+
+    normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
+    gnc_quickfill_remove_recursive (qf, normalized_str, 0, sort);
+    g_free (normalized_str);
+}
+
+/********************************************************************\
+\********************************************************************/
+
+struct _BestText
+{
+    gchar *text;
+    QuickFillSort sort;
+};
+
+static void
+best_text_helper (gpointer key, gpointer value, gpointer user_data)
+{
+    QuickFill *qf = value;
+    struct _BestText *best = user_data;
+
+    if (best->text == NULL)
+    {
+        /* start with the first text */
+        best->text = qf->text;
+
+    }
+    else if (best->text == QUICKFILL_LIFO)
+    {
+        /* we do not track history, so ignore it */
+        return;
+
+    }
+    else if (g_utf8_collate (qf->text, best->text) < 0)
+    {
+        /* even better text */
+        best->text = qf->text;
+    }
+}
+
+
+
+static void
+gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text, gint depth,
+                                QuickFillSort sort)
+{
+    QuickFill *match_qf;
+    gchar *child_text;
+    gint child_len;
+
+    child_text = NULL;
+    child_len = 0;
+
+    if (depth < g_utf8_strlen (text, -1))
+    {
+        /* process next letter */
+
+        gchar *key_char;
+        gunichar key_char_uc;
+        guint key;
+
+        key_char = g_utf8_offset_to_pointer (text, depth);
+        key_char_uc = g_utf8_get_char (key_char);
+        key = g_unichar_toupper (key_char_uc);
+
+        match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
+        if (match_qf)
+        {
+            /* remove text from child qf */
+            gnc_quickfill_remove_recursive (match_qf, text, depth + 1, sort);
+
+            if (match_qf->text == NULL)
+            {
+                /* text was the only word with a prefix up to match_qf */
+                g_hash_table_remove (qf->matches, GUINT_TO_POINTER (key));
+                gnc_quickfill_destroy (match_qf);
+
+            }
+            else
+            {
+                /* remember remaining best child string */
+                child_text = match_qf->text;
+                child_len = match_qf->len;
+            }
+        }
+    }
+
+    if (qf->text == NULL)
+        return;
+
+    if (strcmp (text, qf->text) == 0)
+    {
+        /* the currently best text is about to be removed */
+
+        gchar *best_text = NULL;
+        gint best_len = 0;
+
+        if (child_text != NULL)
+        {
+            /* other children are pretty good as well */
+            best_text = child_text;
+            best_len = child_len;
+
+        }
+        else
+        {
+            if (g_hash_table_size (qf->matches) != 0)
+            {
+                /* otherwise search for another good text */
+                struct _BestText bts;
+                bts.text = NULL;
+                bts.sort = sort;
+
+                g_hash_table_foreach (qf->matches, (GHFunc) best_text_helper, &bts);
+                best_text = bts.text;
+                best_len = (best_text == NULL) ? 0 : g_utf8_strlen (best_text, -1);
+            }
+        }
+
+        /* now replace or clear text */
+        CACHE_REMOVE(qf->text);
+        if (best_text != NULL)
+        {
+            qf->text = CACHE_INSERT((gpointer) best_text);
+            qf->len = best_len;
+        }
+        else
+        {
+            qf->text = NULL;
+            qf->len = 0;
+        }
+    }
+}
+
+/********************** END OF FILE *********************************   \
+\********************************************************************/


Property changes on: gnucash/trunk/src/app-utils/QuickFill.c
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + LF

Copied: gnucash/trunk/src/app-utils/QuickFill.h (from rev 20174, gnucash/trunk/src/gnome-utils/QuickFill.h)
===================================================================
--- gnucash/trunk/src/app-utils/QuickFill.h	                        (rev 0)
+++ gnucash/trunk/src/app-utils/QuickFill.h	2011-01-27 19:22:16 UTC (rev 20176)
@@ -0,0 +1,130 @@
+/********************************************************************\
+ * QuickFill.h -- the quickfill tree data structure                 *
+ *                                                                  *
+ * 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 GUI
+@{
+*/
+/** @addtogroup QuickFill
+
+   QuickFill is meant to be used by the GUI to auto-complete
+   (e.g. tab-complete) typed user input.
+   QuickFill is implemented as a hierarchical tree
+   of partial matching strings.  The root of the tree contains
+   all of the strings that user input should be matched to.
+   Then, given a short string segment, QuickFill will return
+   a subtree containing only those strings that start with desired
+   substring.  As additional letters are added to the substring,
+   QuickFill will thus narrow down to the unique matching string
+   (or to nothing if no match).
+
+   QuickFill works with national-language i18n'ed/l10n'ed multi-byte
+   and wide-char strings, as well as plain-old C-locale strings.
+   @{
+*/
+/**
+   @file QuickFill.h
+   @brief QuickFill is used to auto-complete typed user entries.
+   @author Copyright (C) 1997 Robin D. Clark
+   @author Copyright (C) 1998,2004 Linas Vepstas <linas at linas.org>
+   @author Copyright (C) 2000 Dave Peticolas
+ */
+
+#ifndef QUICKFILL_H
+#define QUICKFILL_H
+
+#include <glib.h>
+
+typedef enum
+{
+    QUICKFILL_LIFO,
+    QUICKFILL_ALPHA
+} QuickFillSort;
+
+typedef struct _QuickFill QuickFill;
+
+
+/* PROTOTYPES ******************************************************/
+
+QuickFill *  gnc_quickfill_new (void);
+void         gnc_quickfill_destroy (QuickFill *qf);
+void         gnc_quickfill_purge (QuickFill *qf);
+
+/** For the given node 'qf', return the best-guess matching string.
+ */
+const char * gnc_quickfill_string (QuickFill *qf);
+
+/** Return the subnode of the tree whose strings all hold 'wc' as
+ *  the next letter.  That is, if 'qf' holds all strings starting
+ *  with the letter 'a', and we ask for the letter 'b', then this
+ *  routine will return the node holding all strings that start
+ *  with "ab".
+ *
+ *  The best-guess matching string can be retrieved with
+ *  gnc_quickfill_string().
+ */
+QuickFill *  gnc_quickfill_get_char_match (QuickFill *qf, gunichar c);
+
+/** Return a subnode in the tree whose strings all match the
+ *  string 'str' as the next substring.  Thus, for example, if
+ *  the argument 'qf' holds strings that start with "abc", and
+ *  this routine is called with "def", then the returned node
+ *  will hold strings that start with "abcdef".
+ *
+ *  The best-guess matching string can be retrieved with
+ *  gnc_quickfill_string().
+ *
+ *  To convert a plain C-locale char * string to GdkWChar *,
+ *  use the gnc_mbstowcs() routine.
+ */
+QuickFill *  gnc_quickfill_get_string_match (QuickFill *qf,
+        const char *str);
+
+/** Same as gnc_quickfill_get_string_match(), except that the
+ *  string length is explicitly specified.
+ */
+QuickFill *  gnc_quickfill_get_string_len_match (QuickFill *qf,
+        const char *str, int len);
+
+/** Walk a 'unique' part of the QuickFill tree.  This routine is
+ *  typically used to assist in the tab-completion of strings.
+ *  If the initial portion of the string is unique, but some later
+ *  portion is not, this routine will advance to the first non-unique
+ *  part of the string.  If len is non-NULL, then *len will be set
+ *  to the length of the unique portion of the string.
+ *
+ *  Thus, for example, if the root node contains the strings
+ *  "The Book" and "The Movie", then the returned len will be 4,
+ *  and the returned node will distinguish "Book" and "Movie".
+ *  Thus, for example, gnc_quickfill_get_char_match(.., 'B') on
+ *  the result will identify "The Book".
+ */
+QuickFill *  gnc_quickfill_get_unique_len_match (QuickFill *qf, int *len);
+
+/** Add the string "text" to the collection of searchable strings. */
+void         gnc_quickfill_insert (QuickFill *root, const char *text,
+                                   QuickFillSort sort_code);
+
+void         gnc_quickfill_remove (QuickFill *root, const gchar *text,
+                                   QuickFillSort sort_code);
+
+/** @} */
+/** @} */
+#endif /* QUICKFILL_H */


Property changes on: gnucash/trunk/src/app-utils/QuickFill.h
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + LF

Copied: gnucash/trunk/src/app-utils/gnc-entry-quickfill.c (from rev 20174, gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c)
===================================================================
--- gnucash/trunk/src/app-utils/gnc-entry-quickfill.c	                        (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-entry-quickfill.c	2011-01-27 19:22:16 UTC (rev 20176)
@@ -0,0 +1,167 @@
+/********************************************************************\
+ * 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"
+#include "engine/gnc-event.h"
+
+/* This static indicates the debugging module that this .o belongs to. */
+static QofLogModule log_module = GNC_MOD_REGISTER;
+
+typedef struct
+{
+    QuickFill *qf;
+    QuickFillSort qf_sort;
+    QofBook *book;
+    gint  listener;
+    gboolean using_invoices;
+} EntryQF;
+
+static void
+listen_for_gncentry_events(QofInstance *entity,  QofEventId event_type,
+                           gpointer user_data, gpointer event_data)
+{
+    EntryQF *qfb = user_data;
+    QuickFill *qf = qfb->qf;
+    const char *desc;
+
+    /* We only listen for GncEntry events */
+    if (!GNC_IS_ENTRY (entity))
+        return;
+
+    /* We listen for MODIFY (if the description was changed into
+     * something non-empty, so we add the string to the quickfill) and
+     * DESTROY (to remove the description from the quickfill). */
+    if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_DESTROY)))
+        return;
+
+    /*     g_warning("entity %p, entity type %s, event type %s, user data %p, ecent data %p", */
+    /*               entity, entity->e_type, qofeventid_to_string(event_type), user_data, event_data); */
+
+    desc = gncEntryGetDescription(GNC_ENTRY(entity));
+    if (event_type & QOF_EVENT_MODIFY)
+    {
+        /* If the description was changed into something non-empty, so
+         * we add the string to the quickfill */
+        if (!desc || strlen(desc) == 0)
+            return;
+
+        /* Add the new string to the quickfill */
+        gnc_quickfill_insert (qf, desc, QUICKFILL_LIFO);
+    }
+    else if (event_type & QOF_EVENT_DESTROY)
+    {
+        if (!desc || strlen(desc) == 0)
+            return;
+
+        /* Remove the description from the quickfill */
+        gnc_quickfill_insert (qf, desc, QUICKFILL_LIFO);
+    }
+}
+
+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;
+    if (s->using_invoices == (gncEntryGetInvAccount(entry) != NULL))
+    {
+        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)
+{
+    GSList *primary_sort_params = NULL;
+    QofQuery *query = qof_query_create_for (GNC_ID_ENTRY);
+    g_assert(book);
+    qof_query_set_book (query, book);
+
+    /* Set the sort order: By DATE_ENTERED, increasing, and returning
+     * only one single resulting item. */
+    primary_sort_params = qof_query_build_param_list(ENTRY_DATE_ENTERED, NULL);
+    qof_query_set_sort_order (query, primary_sort_params, NULL, NULL);
+    qof_query_set_sort_increasing (query, TRUE, TRUE, TRUE);
+
+    return query;
+}
+
+static EntryQF* build_shared_quickfill (QofBook *book, const char * key, gboolean use_invoices)
+{
+    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->using_invoices = use_invoices;
+    result->qf = gnc_quickfill_new();
+    result->qf_sort = QUICKFILL_LIFO;
+    result->book = book;
+
+    g_list_foreach (entries, entry_cb, result);
+
+    qof_query_destroy(query);
+
+    result->listener =
+        qof_event_register_handler (listen_for_gncentry_events,
+                                    result);
+
+    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, gboolean use_invoices)
+{
+    EntryQF *qfb;
+
+    g_assert(book);
+    g_assert(key);
+
+    qfb = qof_book_get_data (book, key);
+
+    if (qfb)
+    {
+        g_assert(use_invoices == qfb->using_invoices);
+        return qfb->qf;
+    }
+
+    qfb = build_shared_quickfill(book, key, use_invoices);
+    return qfb->qf;
+}


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

Copied: gnucash/trunk/src/app-utils/gnc-entry-quickfill.h (from rev 20174, gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h)
===================================================================
--- gnucash/trunk/src/app-utils/gnc-entry-quickfill.h	                        (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-entry-quickfill.h	2011-01-27 19:22:16 UTC (rev 20176)
@@ -0,0 +1,68 @@
+/********************************************************************\
+ * 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 "app-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.
+ *
+ *  This code listens to entry creation events, and automatically adds
+ *  new entry's descriptions to the quickfill list.  This code also
+ *  listens to the entry's deletion events and removes those
+ *  descriptions from the quickfill; however, this does not yet seem
+ *  to fully remove them from the GUI.
+ *
+ * \param book The book
+ * \param key The identifier to look up the shared object in the book
+ *
+ * \param use_invoices If TRUE, this quickfill considers only the
+ * entries from GncInvoice objects. If FALSE, this quickfill considers
+ * only the entries from bills/expense vouchers. Watch out: This
+ * parameter must be identical each time the same key is used for
+ * lookup, or otherwise an assertion will fail.
+ *
+ * \return The shared QuickFill object which is created on first
+ * calling of this function and subsequently looked up in the book by
+ * using the key.
+ */
+QuickFill * gnc_get_shared_entry_desc_quickfill (QofBook *book,
+        const char * key, gboolean use_invoices);
+
+#endif
+
+/** @} */
+/** @} */


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

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2011-01-27 19:22:16 UTC (rev 20176)
@@ -41,7 +41,7 @@
 #include "gncEntryLedger.h"
 #include "gncEntryLedgerP.h"
 #include "quickfillcell.h"
-#include "gnome-utils/gnc-entry-quickfill.h"
+#include "app-utils/gnc-entry-quickfill.h"
 
 
 /* XXX: This should go elsewhere */

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2011-01-27 19:22:16 UTC (rev 20176)
@@ -26,7 +26,6 @@
   ${IGE_MAC_CFLAGS}
 
 libgncmod_gnome_utils_la_SOURCES = \
-  QuickFill.c \
   account-quickfill.c \
   cursors.c \
   dialog-account.c \
@@ -62,7 +61,6 @@
   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 \
@@ -106,7 +104,6 @@
 
 gncincludedir = ${GNC_INCLUDE_DIR}
 gncinclude_HEADERS = \
-  QuickFill.h \
   account-quickfill.h \
   dialog-account.h \
   dialog-book-close.h \
@@ -135,7 +132,6 @@
   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 \

Deleted: gnucash/trunk/src/gnome-utils/QuickFill.c
===================================================================
--- gnucash/trunk/src/gnome-utils/QuickFill.c	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/gnome-utils/QuickFill.c	2011-01-27 19:22:16 UTC (rev 20176)
@@ -1,453 +0,0 @@
-/********************************************************************\
- * QuickFill.h -- the quickfill tree data structure                 *
- * Copyright (C) 1997 Robin D. Clark                                *
- * Copyright (C) 1998 Linas Vepstas                                 *
- * Copyright (C) 2000 Dave Peticolas                                *
- *                                                                  *
- * 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 <string.h>
-
-#include "QuickFill.h"
-#include "gnc-engine.h"
-#include "gnc-ui-util.h"
-
-
-struct _QuickFill
-{
-    char *text;          /* the first matching text string     */
-    int len;             /* number of chars in text string     */
-    GHashTable *matches; /* array of children in the tree      */
-};
-
-
-/** PROTOTYPES ******************************************************/
-static void quickfill_insert_recursive (QuickFill *qf, const char *text,
-                                        int depth, QuickFillSort sort);
-
-static void gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text,
-        gint depth, QuickFillSort sort);
-
-/* This static indicates the debugging module that this .o belongs to.  */
-static QofLogModule log_module = GNC_MOD_REGISTER;
-
-/********************************************************************\
-\********************************************************************/
-
-QuickFill *
-gnc_quickfill_new (void)
-{
-    QuickFill *qf;
-
-    if (sizeof (guint) < sizeof (gunichar))
-    {
-        PWARN ("Can't use quickfill");
-        return NULL;
-    }
-
-    qf = g_new (QuickFill, 1);
-
-    qf->text = NULL;
-    qf->len = 0;
-
-    qf->matches = g_hash_table_new (g_direct_hash, g_direct_equal);
-
-    return qf;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-static gboolean
-destroy_helper (gpointer key, gpointer value, gpointer data)
-{
-    gnc_quickfill_destroy (value);
-    return TRUE;
-}
-
-void
-gnc_quickfill_destroy (QuickFill *qf)
-{
-    if (qf == NULL)
-        return;
-
-    g_hash_table_foreach (qf->matches, (GHFunc)destroy_helper, NULL);
-    g_hash_table_destroy (qf->matches);
-    qf->matches = NULL;
-
-    if (qf->text)
-        CACHE_REMOVE(qf->text);
-    qf->text = NULL;
-    qf->len = 0;
-
-    g_free (qf);
-}
-
-void
-gnc_quickfill_purge (QuickFill *qf)
-{
-    if (qf == NULL)
-        return;
-
-    g_hash_table_foreach_remove (qf->matches, destroy_helper, NULL);
-
-    if (qf->text)
-        CACHE_REMOVE (qf->text);
-    qf->text = NULL;
-    qf->len = 0;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-const char *
-gnc_quickfill_string (QuickFill *qf)
-{
-    if (qf == NULL)
-        return NULL;
-
-    return qf->text;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-QuickFill *
-gnc_quickfill_get_char_match (QuickFill *qf, gunichar uc)
-{
-    guint key = g_unichar_toupper (uc);
-
-    if (NULL == qf) return NULL;
-
-    DEBUG ("xaccGetQuickFill(): index = %u\n", key);
-
-    return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
-}
-
-/********************************************************************\
-\********************************************************************/
-
-QuickFill *
-gnc_quickfill_get_string_len_match (QuickFill *qf,
-                                    const char *str, int len)
-{
-    const char *c;
-    gunichar uc;
-
-    if (NULL == qf) return NULL;
-    if (NULL == str) return NULL;
-
-    c = str;
-    while (*c && (len > 0))
-    {
-        if (qf == NULL)
-            return NULL;
-
-        uc = g_utf8_get_char (c);
-        qf = gnc_quickfill_get_char_match (qf, uc);
-
-        c = g_utf8_next_char (c);
-        len--;
-    }
-
-    return qf;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-QuickFill *
-gnc_quickfill_get_string_match (QuickFill *qf, const char *str)
-{
-    if (NULL == qf) return NULL;
-    if (NULL == str) return NULL;
-
-    return gnc_quickfill_get_string_len_match (qf, str, g_utf8_strlen (str, -1));
-}
-
-/********************************************************************\
-\********************************************************************/
-
-static void
-unique_len_helper (gpointer key, gpointer value, gpointer data)
-{
-    QuickFill **qf_p = data;
-
-    *qf_p = value;
-}
-
-QuickFill *
-gnc_quickfill_get_unique_len_match (QuickFill *qf, int *length)
-{
-    if (length != NULL)
-        *length = 0;
-
-    if (qf == NULL)
-        return NULL;
-
-    while (1)
-    {
-        guint count;
-
-        count = g_hash_table_size (qf->matches);
-
-        if (count != 1)
-        {
-            return qf;
-        }
-
-        g_hash_table_foreach (qf->matches, unique_len_helper, &qf);
-
-        if (length != NULL)
-            (*length)++;
-    }
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-gnc_quickfill_insert (QuickFill *qf, const char *text, QuickFillSort sort)
-{
-    gchar *normalized_str;
-
-    if (NULL == qf) return;
-    if (NULL == text) return;
-
-
-    normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
-    quickfill_insert_recursive (qf, normalized_str, 0, sort);
-    g_free (normalized_str);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-static void
-quickfill_insert_recursive (QuickFill *qf, const char *text, int depth,
-                            QuickFillSort sort)
-{
-    guint key;
-    char *old_text;
-    QuickFill *match_qf;
-    int len;
-    char *key_char;
-    gunichar key_char_uc;
-
-    if (qf == NULL)
-        return;
-
-    if ((text == NULL) || (g_utf8_strlen (text, -1) <= depth))
-        return;
-
-    key_char = g_utf8_offset_to_pointer (text, depth);
-
-    key_char_uc = g_utf8_get_char (key_char);
-    key = g_unichar_toupper (key_char_uc);
-
-    match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
-    if (match_qf == NULL)
-    {
-        match_qf = gnc_quickfill_new ();
-        g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf);
-    }
-
-    old_text = match_qf->text;
-
-    switch (sort)
-    {
-    case QUICKFILL_ALPHA:
-        if (old_text && (g_utf8_collate (text, old_text) >= 0))
-            break;
-
-    case QUICKFILL_LIFO:
-    default:
-        len = g_utf8_strlen (text, -1);
-
-        /* If there's no string there already, just put the new one in. */
-        if (old_text == NULL)
-        {
-            match_qf->text = CACHE_INSERT((gpointer) text);
-            match_qf->len = len;
-            break;
-        }
-
-        /* Leave prefixes in place */
-        if ((len > match_qf->len) &&
-                (strncmp(text, old_text, strlen(old_text)) == 0))
-            break;
-
-        CACHE_REMOVE(old_text);
-        match_qf->text = CACHE_INSERT((gpointer) text);
-        match_qf->len = len;
-        break;
-    }
-
-    quickfill_insert_recursive (match_qf, text, ++depth, sort);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-gnc_quickfill_remove (QuickFill *qf, const gchar *text, QuickFillSort sort)
-{
-    gchar *normalized_str;
-
-    if (qf == NULL) return;
-    if (text == NULL) return;
-
-    normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
-    gnc_quickfill_remove_recursive (qf, normalized_str, 0, sort);
-    g_free (normalized_str);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-struct _BestText
-{
-    gchar *text;
-    QuickFillSort sort;
-};
-
-static void
-best_text_helper (gpointer key, gpointer value, gpointer user_data)
-{
-    QuickFill *qf = value;
-    struct _BestText *best = user_data;
-
-    if (best->text == NULL)
-    {
-        /* start with the first text */
-        best->text = qf->text;
-
-    }
-    else if (best->text == QUICKFILL_LIFO)
-    {
-        /* we do not track history, so ignore it */
-        return;
-
-    }
-    else if (g_utf8_collate (qf->text, best->text) < 0)
-    {
-        /* even better text */
-        best->text = qf->text;
-    }
-}
-
-
-
-static void
-gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text, gint depth,
-                                QuickFillSort sort)
-{
-    QuickFill *match_qf;
-    gchar *child_text;
-    gint child_len;
-
-    child_text = NULL;
-    child_len = 0;
-
-    if (depth < g_utf8_strlen (text, -1))
-    {
-        /* process next letter */
-
-        gchar *key_char;
-        gunichar key_char_uc;
-        guint key;
-
-        key_char = g_utf8_offset_to_pointer (text, depth);
-        key_char_uc = g_utf8_get_char (key_char);
-        key = g_unichar_toupper (key_char_uc);
-
-        match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
-        if (match_qf)
-        {
-            /* remove text from child qf */
-            gnc_quickfill_remove_recursive (match_qf, text, depth + 1, sort);
-
-            if (match_qf->text == NULL)
-            {
-                /* text was the only word with a prefix up to match_qf */
-                g_hash_table_remove (qf->matches, GUINT_TO_POINTER (key));
-                gnc_quickfill_destroy (match_qf);
-
-            }
-            else
-            {
-                /* remember remaining best child string */
-                child_text = match_qf->text;
-                child_len = match_qf->len;
-            }
-        }
-    }
-
-    if (qf->text == NULL)
-        return;
-
-    if (strcmp (text, qf->text) == 0)
-    {
-        /* the currently best text is about to be removed */
-
-        gchar *best_text = NULL;
-        gint best_len = 0;
-
-        if (child_text != NULL)
-        {
-            /* other children are pretty good as well */
-            best_text = child_text;
-            best_len = child_len;
-
-        }
-        else
-        {
-            if (g_hash_table_size (qf->matches) != 0)
-            {
-                /* otherwise search for another good text */
-                struct _BestText bts;
-                bts.text = NULL;
-                bts.sort = sort;
-
-                g_hash_table_foreach (qf->matches, (GHFunc) best_text_helper, &bts);
-                best_text = bts.text;
-                best_len = (best_text == NULL) ? 0 : g_utf8_strlen (best_text, -1);
-            }
-        }
-
-        /* now replace or clear text */
-        CACHE_REMOVE(qf->text);
-        if (best_text != NULL)
-        {
-            qf->text = CACHE_INSERT((gpointer) best_text);
-            qf->len = best_len;
-        }
-        else
-        {
-            qf->text = NULL;
-            qf->len = 0;
-        }
-    }
-}
-
-/********************** END OF FILE *********************************   \
-\********************************************************************/

Deleted: gnucash/trunk/src/gnome-utils/QuickFill.h
===================================================================
--- gnucash/trunk/src/gnome-utils/QuickFill.h	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/gnome-utils/QuickFill.h	2011-01-27 19:22:16 UTC (rev 20176)
@@ -1,130 +0,0 @@
-/********************************************************************\
- * QuickFill.h -- the quickfill tree data structure                 *
- *                                                                  *
- * 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 GUI
-@{
-*/
-/** @addtogroup QuickFill
-
-   QuickFill is meant to be used by the GUI to auto-complete
-   (e.g. tab-complete) typed user input.
-   QuickFill is implemented as a hierarchical tree
-   of partial matching strings.  The root of the tree contains
-   all of the strings that user input should be matched to.
-   Then, given a short string segment, QuickFill will return
-   a subtree containing only those strings that start with desired
-   substring.  As additional letters are added to the substring,
-   QuickFill will thus narrow down to the unique matching string
-   (or to nothing if no match).
-
-   QuickFill works with national-language i18n'ed/l10n'ed multi-byte
-   and wide-char strings, as well as plain-old C-locale strings.
-   @{
-*/
-/**
-   @file QuickFill.h
-   @brief QuickFill is used to auto-complete typed user entries.
-   @author Copyright (C) 1997 Robin D. Clark
-   @author Copyright (C) 1998,2004 Linas Vepstas <linas at linas.org>
-   @author Copyright (C) 2000 Dave Peticolas
- */
-
-#ifndef QUICKFILL_H
-#define QUICKFILL_H
-
-#include <glib.h>
-
-typedef enum
-{
-    QUICKFILL_LIFO,
-    QUICKFILL_ALPHA
-} QuickFillSort;
-
-typedef struct _QuickFill QuickFill;
-
-
-/* PROTOTYPES ******************************************************/
-
-QuickFill *  gnc_quickfill_new (void);
-void         gnc_quickfill_destroy (QuickFill *qf);
-void         gnc_quickfill_purge (QuickFill *qf);
-
-/** For the given node 'qf', return the best-guess matching string.
- */
-const char * gnc_quickfill_string (QuickFill *qf);
-
-/** Return the subnode of the tree whose strings all hold 'wc' as
- *  the next letter.  That is, if 'qf' holds all strings starting
- *  with the letter 'a', and we ask for the letter 'b', then this
- *  routine will return the node holding all strings that start
- *  with "ab".
- *
- *  The best-guess matching string can be retrieved with
- *  gnc_quickfill_string().
- */
-QuickFill *  gnc_quickfill_get_char_match (QuickFill *qf, gunichar c);
-
-/** Return a subnode in the tree whose strings all match the
- *  string 'str' as the next substring.  Thus, for example, if
- *  the argument 'qf' holds strings that start with "abc", and
- *  this routine is called with "def", then the returned node
- *  will hold strings that start with "abcdef".
- *
- *  The best-guess matching string can be retrieved with
- *  gnc_quickfill_string().
- *
- *  To convert a plain C-locale char * string to GdkWChar *,
- *  use the gnc_mbstowcs() routine.
- */
-QuickFill *  gnc_quickfill_get_string_match (QuickFill *qf,
-        const char *str);
-
-/** Same as gnc_quickfill_get_string_match(), except that the
- *  string length is explicitly specified.
- */
-QuickFill *  gnc_quickfill_get_string_len_match (QuickFill *qf,
-        const char *str, int len);
-
-/** Walk a 'unique' part of the QuickFill tree.  This routine is
- *  typically used to assist in the tab-completion of strings.
- *  If the initial portion of the string is unique, but some later
- *  portion is not, this routine will advance to the first non-unique
- *  part of the string.  If len is non-NULL, then *len will be set
- *  to the length of the unique portion of the string.
- *
- *  Thus, for example, if the root node contains the strings
- *  "The Book" and "The Movie", then the returned len will be 4,
- *  and the returned node will distinguish "Book" and "Movie".
- *  Thus, for example, gnc_quickfill_get_char_match(.., 'B') on
- *  the result will identify "The Book".
- */
-QuickFill *  gnc_quickfill_get_unique_len_match (QuickFill *qf, int *len);
-
-/** Add the string "text" to the collection of searchable strings. */
-void         gnc_quickfill_insert (QuickFill *root, const char *text,
-                                   QuickFillSort sort_code);
-
-void         gnc_quickfill_remove (QuickFill *root, const gchar *text,
-                                   QuickFillSort sort_code);
-
-/** @} */
-/** @} */
-#endif /* QUICKFILL_H */

Deleted: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c	2011-01-27 19:22:16 UTC (rev 20176)
@@ -1,167 +0,0 @@
-/********************************************************************\
- * 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"
-#include "engine/gnc-event.h"
-
-/* This static indicates the debugging module that this .o belongs to. */
-static QofLogModule log_module = GNC_MOD_REGISTER;
-
-typedef struct
-{
-    QuickFill *qf;
-    QuickFillSort qf_sort;
-    QofBook *book;
-    gint  listener;
-    gboolean using_invoices;
-} EntryQF;
-
-static void
-listen_for_gncentry_events(QofInstance *entity,  QofEventId event_type,
-                           gpointer user_data, gpointer event_data)
-{
-    EntryQF *qfb = user_data;
-    QuickFill *qf = qfb->qf;
-    const char *desc;
-
-    /* We only listen for GncEntry events */
-    if (!GNC_IS_ENTRY (entity))
-        return;
-
-    /* We listen for MODIFY (if the description was changed into
-     * something non-empty, so we add the string to the quickfill) and
-     * DESTROY (to remove the description from the quickfill). */
-    if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_DESTROY)))
-        return;
-
-    /*     g_warning("entity %p, entity type %s, event type %s, user data %p, ecent data %p", */
-    /*               entity, entity->e_type, qofeventid_to_string(event_type), user_data, event_data); */
-
-    desc = gncEntryGetDescription(GNC_ENTRY(entity));
-    if (event_type & QOF_EVENT_MODIFY)
-    {
-        /* If the description was changed into something non-empty, so
-         * we add the string to the quickfill */
-        if (!desc || strlen(desc) == 0)
-            return;
-
-        /* Add the new string to the quickfill */
-        gnc_quickfill_insert (qf, desc, QUICKFILL_LIFO);
-    }
-    else if (event_type & QOF_EVENT_DESTROY)
-    {
-        if (!desc || strlen(desc) == 0)
-            return;
-
-        /* Remove the description from the quickfill */
-        gnc_quickfill_insert (qf, desc, QUICKFILL_LIFO);
-    }
-}
-
-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;
-    if (s->using_invoices == (gncEntryGetInvAccount(entry) != NULL))
-    {
-        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)
-{
-    GSList *primary_sort_params = NULL;
-    QofQuery *query = qof_query_create_for (GNC_ID_ENTRY);
-    g_assert(book);
-    qof_query_set_book (query, book);
-
-    /* Set the sort order: By DATE_ENTERED, increasing, and returning
-     * only one single resulting item. */
-    primary_sort_params = qof_query_build_param_list(ENTRY_DATE_ENTERED, NULL);
-    qof_query_set_sort_order (query, primary_sort_params, NULL, NULL);
-    qof_query_set_sort_increasing (query, TRUE, TRUE, TRUE);
-
-    return query;
-}
-
-static EntryQF* build_shared_quickfill (QofBook *book, const char * key, gboolean use_invoices)
-{
-    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->using_invoices = use_invoices;
-    result->qf = gnc_quickfill_new();
-    result->qf_sort = QUICKFILL_LIFO;
-    result->book = book;
-
-    g_list_foreach (entries, entry_cb, result);
-
-    qof_query_destroy(query);
-
-    result->listener =
-        qof_event_register_handler (listen_for_gncentry_events,
-                                    result);
-
-    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, gboolean use_invoices)
-{
-    EntryQF *qfb;
-
-    g_assert(book);
-    g_assert(key);
-
-    qfb = qof_book_get_data (book, key);
-
-    if (qfb)
-    {
-        g_assert(use_invoices == qfb->using_invoices);
-        return qfb->qf;
-    }
-
-    qfb = build_shared_quickfill(book, key, use_invoices);
-    return qfb->qf;
-}

Deleted: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h	2011-01-27 19:16:47 UTC (rev 20175)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h	2011-01-27 19:22:16 UTC (rev 20176)
@@ -1,68 +0,0 @@
-/********************************************************************\
- * 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.
- *
- *  This code listens to entry creation events, and automatically adds
- *  new entry's descriptions to the quickfill list.  This code also
- *  listens to the entry's deletion events and removes those
- *  descriptions from the quickfill; however, this does not yet seem
- *  to fully remove them from the GUI.
- *
- * \param book The book
- * \param key The identifier to look up the shared object in the book
- *
- * \param use_invoices If TRUE, this quickfill considers only the
- * entries from GncInvoice objects. If FALSE, this quickfill considers
- * only the entries from bills/expense vouchers. Watch out: This
- * parameter must be identical each time the same key is used for
- * lookup, or otherwise an assertion will fail.
- *
- * \return The shared QuickFill object which is created on first
- * calling of this function and subsequently looked up in the book by
- * using the key.
- */
-QuickFill * gnc_get_shared_entry_desc_quickfill (QofBook *book,
-        const char * key, gboolean use_invoices);
-
-#endif
-
-/** @} */
-/** @} */



More information about the gnucash-changes mailing list