r19958 - gnucash/trunk/src/gnome-utils - Improve the cached quickfill for GncEntry description lines of r19941.
Christian Stimming
cstim at code.gnucash.org
Fri Dec 17 16:31:22 EST 2010
Author: cstim
Date: 2010-12-17 16:31:22 -0500 (Fri, 17 Dec 2010)
New Revision: 19958
Trac: http://svn.gnucash.org/trac/changeset/19958
Modified:
gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
Log:
Improve the cached quickfill for GncEntry description lines of r19941.
Modified: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c 2010-12-17 21:31:11 UTC (rev 19957)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.c 2010-12-17 21:31:22 UTC (rev 19958)
@@ -23,20 +23,67 @@
#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;
} 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); */
+ qof_event_unregister_handler (qfb->listener);
g_free (qfb);
}
@@ -75,6 +122,10 @@
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;
Modified: gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h 2010-12-17 21:31:11 UTC (rev 19957)
+++ gnucash/trunk/src/gnome-utils/gnc-entry-quickfill.h 2010-12-17 21:31:22 UTC (rev 19958)
@@ -39,6 +39,12 @@
* 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.
*/
QuickFill * gnc_get_shared_entry_desc_quickfill (QofBook *book,
const char * key);
More information about the gnucash-changes
mailing list