r20271 - gnucash/trunk/src/app-utils - Add a common shared quickfill object for the addr2/addr3 lines of a GncAddress.
Christian Stimming
cstim at code.gnucash.org
Thu Feb 10 16:49:12 EST 2011
Author: cstim
Date: 2011-02-10 16:49:12 -0500 (Thu, 10 Feb 2011)
New Revision: 20271
Trac: http://svn.gnucash.org/trac/changeset/20271
Added:
gnucash/trunk/src/app-utils/gnc-addr-quickfill.c
gnucash/trunk/src/app-utils/gnc-addr-quickfill.h
Modified:
gnucash/trunk/src/app-utils/CMakeLists.txt
gnucash/trunk/src/app-utils/Makefile.am
Log:
Add a common shared quickfill object for the addr2/addr3 lines of a GncAddress.
Modified: gnucash/trunk/src/app-utils/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/app-utils/CMakeLists.txt 2011-02-10 21:48:58 UTC (rev 20270)
+++ gnucash/trunk/src/app-utils/CMakeLists.txt 2011-02-10 21:49:12 UTC (rev 20271)
@@ -26,6 +26,7 @@
gnc-basic-gobject.h
gnc-account-merge.h
gnc-accounting-period.h
+ gnc-addr-quickfill.h
gnc-component-manager.h
gnc-druid.h
gnc-druid-cb.h
@@ -57,6 +58,7 @@
gfec.c
gnc-account-merge.c
gnc-accounting-period.c
+ gnc-addr-quickfill.c
gnc-component-manager.c
gnc-druid.c
gnc-druid-cb.c
Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am 2011-02-10 21:48:58 UTC (rev 20270)
+++ gnucash/trunk/src/app-utils/Makefile.am 2011-02-10 21:49:12 UTC (rev 20271)
@@ -40,6 +40,7 @@
gfec.c \
gnc-account-merge.c \
gnc-accounting-period.c \
+ gnc-addr-quickfill.c \
gnc-component-manager.c \
gnc-druid.c \
gnc-druid-cb.c \
@@ -68,6 +69,7 @@
gnc-basic-gobject.h \
gnc-account-merge.h \
gnc-accounting-period.h \
+ gnc-addr-quickfill.h \
gnc-component-manager.h \
gnc-druid.h \
gnc-druid-cb.h \
Added: gnucash/trunk/src/app-utils/gnc-addr-quickfill.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-addr-quickfill.c (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-addr-quickfill.c 2011-02-10 21:49:12 UTC (rev 20271)
@@ -0,0 +1,192 @@
+/********************************************************************\
+ * gnc-addr-quickfill.c -- Create an address line quick-fill *
+ * Copyright (C) 2011 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-addr-quickfill.h"
+#include "engine/gnc-event.h"
+#include "engine/gnc-engine.h"
+#include "engine/gncAddress.h"
+
+/* This static indicates the debugging module that this .o belongs to. */
+static QofLogModule log_module = GNC_MOD_REGISTER;
+
+typedef struct
+{
+ QuickFill *qf_addr2;
+ QuickFill *qf_addr3;
+ QuickFillSort qf_sort;
+ QofBook *book;
+ gint listener;
+} AddressQF;
+
+static void
+listen_for_gncaddress_events(QofInstance *entity, QofEventId event_type,
+ gpointer user_data, gpointer event_data)
+{
+ AddressQF *qfb = user_data;
+ const char *addr2, *addr3;
+
+ /* We only listen for GncAddress events */
+ if (!GNC_IS_ADDRESS (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); */
+
+ addr2 = gncAddressGetAddr2(GNC_ADDRESS(entity));
+ addr3 = gncAddressGetAddr3(GNC_ADDRESS(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 (addr2 && strlen(addr2) > 0)
+ {
+ /* Add the new string to the quickfill */
+ gnc_quickfill_insert (qfb->qf_addr2, addr2, QUICKFILL_LIFO);
+ }
+ if (addr3 && strlen(addr3) > 0)
+ {
+ /* Add the new string to the quickfill */
+ gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
+ }
+ }
+ else if (event_type & QOF_EVENT_DESTROY)
+ {
+ if (addr2 && strlen(addr2) > 0)
+ {
+ /* Remove the description from the quickfill */
+ gnc_quickfill_insert (qfb->qf_addr2, addr2, QUICKFILL_LIFO);
+ }
+ if (addr3 && strlen(addr3) > 0)
+ {
+ /* Remove the description from the quickfill */
+ gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
+ }
+ }
+}
+
+static void
+shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
+{
+ AddressQF *qfb = user_data;
+ gnc_quickfill_destroy (qfb->qf_addr2);
+ gnc_quickfill_destroy (qfb->qf_addr3);
+ qof_event_unregister_handler (qfb->listener);
+ g_free (qfb);
+}
+
+static void address_cb(gpointer data, gpointer user_data)
+{
+ const GncAddress* address = data;
+ AddressQF *s = (AddressQF *) user_data;
+
+ gnc_quickfill_insert (s->qf_addr2,
+ gncAddressGetAddr2(address),
+ s->qf_sort);
+
+ gnc_quickfill_insert (s->qf_addr3,
+ gncAddressGetAddr3(address),
+ s->qf_sort);
+}
+
+/** Creates a new query that searches for all GncAddress items in the
+ * current book. */
+static QofQuery *new_query_for_addresss(QofBook *book)
+{
+ GSList *primary_sort_params = NULL;
+ QofQuery *query = qof_query_create_for (GNC_ID_ADDRESS);
+ g_assert(book);
+ qof_query_set_book (query, book);
+
+ /* No particular sort order here. */
+
+ return query;
+}
+
+static AddressQF* build_shared_quickfill (QofBook *book, const char * key)
+{
+ AddressQF *result;
+ QofQuery *query = new_query_for_addresss(book);
+ GList *entries = qof_query_run(query);
+
+ /* g_warning("Found %d GncAddress items", g_list_length (entries)); */
+
+ result = g_new0(AddressQF, 1);
+
+ result->qf_addr2 = gnc_quickfill_new();
+ result->qf_addr3 = gnc_quickfill_new();
+ result->qf_sort = QUICKFILL_LIFO;
+ result->book = book;
+
+ g_list_foreach (entries, address_cb, result);
+
+ qof_query_destroy(query);
+
+ result->listener =
+ qof_event_register_handler (listen_for_gncaddress_events,
+ result);
+
+ qof_book_set_data_fin (book, key, result, shared_quickfill_destroy);
+
+ return result;
+}
+
+QuickFill * gnc_get_shared_address_addr2_quickfill (QofBook *book, const char * key)
+{
+ AddressQF *qfb;
+
+ g_assert(book);
+ g_assert(key);
+
+ qfb = qof_book_get_data (book, key);
+
+ if (!qfb)
+ {
+ qfb = build_shared_quickfill(book, key);
+ }
+
+ return qfb->qf_addr2;
+}
+
+QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book, const char * key)
+{
+ AddressQF *qfb;
+
+ g_assert(book);
+ g_assert(key);
+
+ qfb = qof_book_get_data (book, key);
+
+ if (!qfb)
+ {
+ qfb = build_shared_quickfill(book, key);
+ }
+
+ return qfb->qf_addr3;
+}
Property changes on: gnucash/trunk/src/app-utils/gnc-addr-quickfill.c
___________________________________________________________________
Added: svn:eol-style
+ LF
Added: gnucash/trunk/src/app-utils/gnc-addr-quickfill.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-addr-quickfill.h (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-addr-quickfill.h 2011-02-10 21:49:12 UTC (rev 20271)
@@ -0,0 +1,71 @@
+/********************************************************************\
+ * gnc-addr-quickfill.h -- Create an address line quick-fill *
+ * Copyright (C) 2011 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 address lines of all GncAddress.
+*/
+
+#ifndef GNC_ADDR_QUICKFILL_H
+#define GNC_ADDR_QUICKFILL_H
+
+#include "qof.h"
+#include "app-utils/QuickFill.h"
+
+/** Create/fetch a quickfill GncAddress description strings on the Addr2 part.
+ *
+ * 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 GncAddress creation events, and automatically
+ * adds new items to the quickfill list. This code also listens to
+ * the item deletion events and removes those entries 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
+ *
+ * \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_address_addr2_quickfill (QofBook *book,
+ const char * key);
+
+/** Create/fetch a quickfill GncAddress description strings on the
+ * Addr3 part.
+ *
+ * Identical to gnc_get_shared_address_addr2_quickfill(). You should
+ * also use the same key as for the other function because the
+ * internal quickfills are updated simultaneously.
+ */
+QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book,
+ const char * key);
+
+#endif
+
+/** @} */
+/** @} */
Property changes on: gnucash/trunk/src/app-utils/gnc-addr-quickfill.h
___________________________________________________________________
Added: svn:eol-style
+ LF
More information about the gnucash-changes
mailing list