GnuCash c935c2f+
Loading...
Searching...
No Matches
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.
 
QuickFill * gnc_get_shared_address_addr3_quickfill (QofBook *book, const char *key)
 Create/fetch a quickfill GncAddress description strings on the Addr3 part.
 
QuickFill * gnc_get_shared_address_addr4_quickfill (QofBook *book, const char *key)
 Create/fetch a quickfill GncAddress description strings on the Addr4 part.
 
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.
 
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.
 
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.
 
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.
 
void gnc_quickfill_insert (QuickFill *root, const char *text, QuickFillSort sort_code)
 Add the string "text" to the collection of searchable strings.
 
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.

Enumeration Type Documentation

◆ QuickFillSort

enum QuickFillSort

Definition at line 59 of file QuickFill.h.

60{
61 QUICKFILL_LIFO,
62 QUICKFILL_ALPHA
63} QuickFillSort;

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}

◆ 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}

◆ 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}

◆ 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}

◆ gnc_quickfill_destroy()

void gnc_quickfill_destroy ( QuickFill *  qf)

Definition at line 88 of file QuickFill.c.

89{
90 if (qf == NULL)
91 return;
92
93 g_hash_table_foreach (qf->matches, (GHFunc)destroy_helper, NULL);
94 g_hash_table_destroy (qf->matches);
95 qf->matches = NULL;
96
97 if (qf->text)
98 g_free(qf->text);
99 qf->text = NULL;
100 qf->len = 0;
101
102 g_free (qf);
103}

◆ 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_len_match()

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)
Return the subnode of the tree whose strings all hold 'c' as the next letter.
Definition QuickFill.c:135

◆ 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}

◆ gnc_quickfill_new()

QuickFill * gnc_quickfill_new ( void  )

Definition at line 57 of file QuickFill.c.

58{
59 QuickFill *qf;
60
61 if (sizeof (guint) < sizeof (gunichar))
62 {
63 PWARN ("Can't use quickfill");
64 return NULL;
65 }
66
67 qf = g_new (QuickFill, 1);
68
69 qf->text = NULL;
70 qf->len = 0;
71
72 qf->matches = g_hash_table_new (g_direct_hash, g_direct_equal);
73
74 return qf;
75}
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ gnc_quickfill_purge()

void gnc_quickfill_purge ( QuickFill *  qf)

Definition at line 106 of file QuickFill.c.

107{
108 if (qf == NULL)
109 return;
110
111 g_hash_table_foreach_remove (qf->matches, destroy_helper, NULL);
112
113 if (qf->text)
114 g_free (qf->text);
115 qf->text = NULL;
116 qf->len = 0;
117}

◆ gnc_quickfill_remove()

void gnc_quickfill_remove ( QuickFill *  root,
const gchar *  text,
QuickFillSort  sort_code 
)

Definition at line 310 of file QuickFill.c.

311{
312 gchar *normalized_str;
313
314 if (qf == NULL) return;
315 if (text == NULL) return;
316
317 normalized_str = g_utf8_normalize (text, -1, G_NORMALIZE_NFC);
318 gnc_quickfill_remove_recursive (qf, normalized_str, 0, sort);
319 g_free (normalized_str);
320}

◆ gnc_quickfill_string()

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}