GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Files | Typedefs | Enumerations | Functions
Auto-complete typed user input.

Modules

 

Files

file  QuickFill.h
 QuickFill is used to auto-complete typed user entries.
 

Typedefs

typedef struct _QuickFill QuickFill
 

Enumerations

enum  QuickFillSort { QUICKFILL_LIFO, QUICKFILL_ALPHA }
 

Functions

QuickFillgnc_get_shared_address_addr2_quickfill (QofBook *book, const char *key)
 
QuickFillgnc_get_shared_address_addr3_quickfill (QofBook *book, const char *key)
 
QuickFillgnc_get_shared_address_addr4_quickfill (QofBook *book, const char *key)
 
QuickFillgnc_get_shared_entry_desc_quickfill (QofBook *book, const char *key, gboolean use_invoices)
 
QuickFillgnc_quickfill_new (void)
 
void gnc_quickfill_destroy (QuickFill *qf)
 
void gnc_quickfill_purge (QuickFill *qf)
 
const char * gnc_quickfill_string (QuickFill *qf)
 
QuickFillgnc_quickfill_get_char_match (QuickFill *qf, gunichar c)
 
QuickFillgnc_quickfill_get_string_match (QuickFill *qf, const char *str)
 
QuickFillgnc_quickfill_get_string_len_match (QuickFill *qf, const char *str, int len)
 
QuickFillgnc_quickfill_get_unique_len_match (QuickFill *qf, int *len)
 
void gnc_quickfill_insert (QuickFill *root, const char *text, QuickFillSort sort_code)
 
void gnc_quickfill_remove (QuickFill *root, const gchar *text, QuickFillSort sort_code)
 

Detailed Description

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.

Function Documentation

QuickFill* gnc_get_shared_address_addr2_quickfill ( QofBook book,
const char *  key 
)

Similar to the Account Names account name quickfill, we create a cached quickfill with the address lines of all GncAddress. 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.

Parameters
bookThe book
keyThe identifier to look up the shared object in the book
Returns
The shared QuickFill object which is created on first calling of this function and subsequently looked up in the book by using the key.

Definition at line 177 of file gnc-addr-quickfill.c.

178 {
179  AddressQF *qfb;
180 
181  g_assert(book);
182  g_assert(key);
183 
184  qfb = qof_book_get_data (book, key);
185 
186  if (!qfb)
187  {
188  qfb = build_shared_quickfill(book, key);
189  }
190 
191  return qfb->qf_addr2;
192 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
QuickFill* gnc_get_shared_address_addr3_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.

Definition at line 194 of file gnc-addr-quickfill.c.

195 {
196  AddressQF *qfb;
197 
198  g_assert(book);
199  g_assert(key);
200 
201  qfb = qof_book_get_data (book, key);
202 
203  if (!qfb)
204  {
205  qfb = build_shared_quickfill(book, key);
206  }
207 
208  return qfb->qf_addr3;
209 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
QuickFill* gnc_get_shared_address_addr4_quickfill ( QofBook book,
const char *  key 
)

Create/fetch a quickfill GncAddress description strings on the Addr4 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.

Definition at line 211 of file gnc-addr-quickfill.c.

212 {
213  AddressQF *qfb;
214 
215  g_assert(book);
216  g_assert(key);
217 
218  qfb = qof_book_get_data (book, key);
219 
220  if (!qfb)
221  {
222  qfb = build_shared_quickfill(book, key);
223  }
224 
225  return qfb->qf_addr4;
226 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
QuickFill* gnc_get_shared_entry_desc_quickfill ( QofBook book,
const char *  key,
gboolean  use_invoices 
)

Similar to the Account Names account name quickfill, we create a cached quickfill with the description of all entries. 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.

Parameters
bookThe book
keyThe identifier to look up the shared object in the book
use_invoicesIf 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.
Returns
The shared QuickFill object which is created on first calling of this function and subsequently looked up in the book by using the key.

Definition at line 150 of file gnc-entry-quickfill.c.

152 {
153  EntryQF *qfb;
154 
155  g_assert(book);
156  g_assert(key);
157 
158  qfb = qof_book_get_data (book, key);
159 
160  if (!qfb)
161  {
162  qfb = build_shared_quickfill(book, key, use_invoices);
163  }
164 
165  g_assert(use_invoices == qfb->using_invoices);
166  return qfb->qf;
167 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
QuickFill* gnc_quickfill_get_char_match ( QuickFill qf,
gunichar  c 
)

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().

Definition at line 135 of file QuickFill.c.

136 {
137  guint key = g_unichar_toupper (uc);
138 
139  if (NULL == qf) return NULL;
140 
141  DEBUG ("xaccGetQuickFill(): index = %u\n", key);
142 
143  return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key));
144 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
QuickFill* gnc_quickfill_get_string_len_match ( QuickFill qf,
const char *  str,
int  len 
)

Same as gnc_quickfill_get_string_match(), except that the string length is explicitly specified.

Definition at line 150 of file QuickFill.c.

152 {
153  const char *c;
154  gunichar uc;
155 
156  if (NULL == qf) return NULL;
157  if (NULL == str) return NULL;
158 
159  c = str;
160  while (*c && (len > 0))
161  {
162  if (qf == NULL)
163  return NULL;
164 
165  uc = g_utf8_get_char (c);
166  qf = gnc_quickfill_get_char_match (qf, uc);
167 
168  c = g_utf8_next_char (c);
169  len--;
170  }
171 
172  return qf;
173 }
QuickFill * gnc_quickfill_get_char_match(QuickFill *qf, gunichar uc)
Definition: QuickFill.c:135
QuickFill* gnc_quickfill_get_string_match ( QuickFill qf,
const char *  str 
)

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.

Definition at line 179 of file QuickFill.c.

180 {
181  if (NULL == qf) return NULL;
182  if (NULL == str) return NULL;
183 
184  return gnc_quickfill_get_string_len_match (qf, str, g_utf8_strlen (str, -1));
185 }
QuickFill * gnc_quickfill_get_string_len_match(QuickFill *qf, const char *str, int len)
Definition: QuickFill.c:150
QuickFill* gnc_quickfill_get_unique_len_match ( QuickFill qf,
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".

Definition at line 199 of file QuickFill.c.

200 {
201  if (length != NULL)
202  *length = 0;
203 
204  if (qf == NULL)
205  return NULL;
206 
207  while (1)
208  {
209  guint count;
210 
211  count = g_hash_table_size (qf->matches);
212 
213  if (count != 1)
214  break;
215 
216  g_hash_table_foreach (qf->matches, unique_len_helper, &qf);
217 
218  if (length != NULL)
219  (*length)++;
220  }
221 
222  return qf;
223 }
void gnc_quickfill_insert ( QuickFill root,
const char *  text,
QuickFillSort  sort_code 
)

Add the string "text" to the collection of searchable strings.

Definition at line 229 of file QuickFill.c.

230 {
231  gchar *normalized_str;
232 
233  if (NULL == qf) return;
234  if (NULL == text) return;
235 
236 
237  normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
238  quickfill_insert_recursive (qf, normalized_str, 0, sort);
239  g_free (normalized_str);
240 }
const char* gnc_quickfill_string ( QuickFill qf)

For the given node 'qf', return the best-guess matching string.

Definition at line 123 of file QuickFill.c.

124 {
125  if (qf == NULL)
126  return NULL;
127 
128  return qf->text;
129 }