GnuCash  5.6-150-g038405b370+
Modules | Files | Enumerations | Functions
Auto-complete typed user input.

QuickFill is meant to be used by the GUI to auto-complete (e.g. More...

Modules

 

Files

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

Enumerations

enum  QuickFillSort { QUICKFILL_LIFO, QUICKFILL_ALPHA }
 

Functions

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. More...
 
QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book, const char *key)
 Create/fetch a quickfill GncAddress description strings on the Addr3 part. More...
 
QuickFill * gnc_get_shared_address_addr4_quickfill (QofBook *book, const char *key)
 Create/fetch a quickfill GncAddress description strings on the Addr4 part. More...
 
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. More...
 
QuickFill * gnc_quickfill_new (void)
 
void gnc_quickfill_destroy (QuickFill *qf)
 
void gnc_quickfill_purge (QuickFill *qf)
 
const char * gnc_quickfill_string (QuickFill *qf)
 For the given node 'qf', return the best-guess matching string.
 
QuickFill * gnc_quickfill_get_char_match (QuickFill *qf, gunichar c)
 Return the subnode of the tree whose strings all hold 'c' as the next letter. More...
 
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. More...
 
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.
 
QuickFill * gnc_quickfill_get_unique_len_match (QuickFill *qf, int *len)
 Walk a 'unique' part of the QuickFill tree. More...
 
void gnc_quickfill_insert (QuickFill *root, const char *text, QuickFillSort sort_code)
 Add the string "text" to the collection of searchable strings. More...
 
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

◆ gnc_get_shared_address_addr2_quickfill()

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)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.

◆ gnc_get_shared_address_addr3_quickfill()

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)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.

◆ gnc_get_shared_address_addr4_quickfill()

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)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.

◆ gnc_get_shared_entry_desc_quickfill()

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)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.

◆ gnc_quickfill_get_char_match()

QuickFill* gnc_quickfill_get_char_match ( QuickFill *  qf,
gunichar  c 
)

Return the subnode of the tree whose strings all hold 'c' 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...)
Print a debugging message.
Definition: qoflog.h:264

◆ gnc_quickfill_get_string_match()

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)
Same as gnc_quickfill_get_string_match(), except that the string length is explicitly specified...
Definition: QuickFill.c:150

◆ gnc_quickfill_get_unique_len_match()

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 }

◆ gnc_quickfill_insert()

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  int len;
233 
234  if (NULL == qf) return;
235  if (NULL == text) return;
236 
237 
238  normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
239  len = g_utf8_strlen (text, -1);
240  quickfill_insert_recursive (qf, normalized_str, len, normalized_str, sort);
241  g_free (normalized_str);
242 }