31static QofLogModule log_module = GNC_MOD_REGISTER;
33static void shared_quickfill_pref_changed (gpointer prefs, gchar* pref,
35static void listen_for_account_events (
QofInstance* entity,
37 gpointer user_data, gpointer event_data);
41#define ACCOUNT_POINTER 1
42#define NUM_ACCOUNT_COLUMNS 2
57 gboolean load_list_store;
58 GtkListStore* list_store;
62 AccountBoolCB dont_add_cb;
63 gpointer dont_add_data;
67shared_quickfill_destroy (
QofBook* book, gpointer key, gpointer user_data)
71 GNC_PREF_ACCOUNT_SEPARATOR,
72 shared_quickfill_pref_changed,
75 GNC_PREF_SHOW_LEAF_ACCT_NAMES,
76 shared_quickfill_pref_changed,
78 gnc_quickfill_destroy (qfb->qf);
79 g_object_unref (qfb->list_store);
92shared_quickfill_find_accounts (GtkTreeModel* model,
99 GtkTreeRowReference* ref;
102 gtk_tree_model_get (model, iter, ACCOUNT_POINTER, &account, -1);
103 for (tmp = data->accounts; tmp; tmp = g_list_next (tmp))
105 if (tmp->data == account)
107 ref = gtk_tree_row_reference_new (model, path);
108 data->refs = g_list_append (data->refs, ref);
109 data->accounts = g_list_delete_link (data->accounts, tmp);
110 return (data->accounts == NULL);
119load_shared_qf_cb (
Account* account, gpointer data)
125 if (qfb->dont_add_cb)
127 gboolean skip = (qfb->dont_add_cb) (account, qfb->dont_add_data);
136 if (qfb->load_list_store)
138 gtk_list_store_append (qfb->list_store, &iter);
139 gtk_list_store_set (qfb->list_store, &iter,
141 ACCOUNT_POINTER, account,
149shared_quickfill_pref_changed (gpointer prefs, gchar* pref, gpointer user_data)
151 QFB* qfb = user_data;
154 gnc_quickfill_purge (qfb->qf);
155 gtk_list_store_clear (qfb->list_store);
156 qfb->load_list_store = TRUE;
157 gnc_account_foreach_descendant (qfb->root, load_shared_qf_cb, qfb);
158 qfb->load_list_store = FALSE;
166build_shared_quickfill (
QofBook* book,
Account* root,
const char* key,
167 AccountBoolCB cb, gpointer data)
171 qfb = g_new0 (
QFB, 1);
172 qfb->qf = gnc_quickfill_new();
176 qfb->dont_add_cb = cb;
177 qfb->dont_add_data = data;
178 qfb->load_list_store = TRUE;
179 qfb->list_store = gtk_list_store_new (NUM_ACCOUNT_COLUMNS,
180 G_TYPE_STRING, G_TYPE_POINTER);
183 GNC_PREF_ACCOUNT_SEPARATOR,
184 shared_quickfill_pref_changed,
188 GNC_PREF_SHOW_LEAF_ACCT_NAMES,
189 shared_quickfill_pref_changed,
192 gnc_account_foreach_descendant (root, load_shared_qf_cb, qfb);
193 qfb->load_list_store = FALSE;
197 qof_book_set_data_fin (book, key, qfb, shared_quickfill_destroy);
204 AccountBoolCB cb, gpointer cb_data)
209 book = gnc_account_get_book (root);
210 qfb = qof_book_get_data (book, key);
215 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
220gnc_get_shared_account_name_list_store (
Account* root,
const char* key,
221 AccountBoolCB cb, gpointer cb_data)
226 book = gnc_account_get_book (root);
227 qfb = qof_book_get_data (book, key);
230 return qfb->list_store;
232 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
233 return qfb->list_store;
242 gpointer user_data, gpointer event_data)
244 QFB* qfb = user_data;
245 QuickFill* qf = qfb->qf;
248 const char* match_str;
255 if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_ADD | QOF_EVENT_REMOVE)))
258 if (!GNC_IS_ACCOUNT (entity))
260 account = GNC_ACCOUNT (entity);
262 ENTER (
"entity %p, event type %x, user data %p, ecent data %p",
263 entity, event_type, user_data, event_data);
267 LEAVE (
"root account mismatch");
274 LEAVE (
"account has no name");
280 case QOF_EVENT_MODIFY:
281 DEBUG (
"modify %s", name);
286 data.accounts = g_list_prepend (data.accounts, account);
287 gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store),
288 shared_quickfill_find_accounts, &data);
294 for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
296 gchar* old_name, *new_name;
297 path = gtk_tree_row_reference_get_path (tmp->data);
298 gtk_tree_row_reference_free (tmp->data);
299 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store),
302 gtk_tree_path_free (path);
305 gtk_tree_path_free (path);
306 gtk_tree_model_get (GTK_TREE_MODEL (qfb->list_store), &iter,
307 ACCOUNT_POINTER, &account,
308 ACCOUNT_NAME, &old_name,
315 if (match && (g_strcmp0 (old_name, new_name) != 0))
316 gnc_quickfill_remove (qf, old_name, QUICKFILL_ALPHA);
318 if (qfb->dont_add_cb &&
319 qfb->dont_add_cb (account, qfb->dont_add_data))
321 gnc_quickfill_remove (qf, new_name, QUICKFILL_ALPHA);
322 gtk_list_store_remove (qfb->list_store, &iter);
327 gtk_list_store_set (qfb->list_store, &iter,
328 ACCOUNT_NAME, new_name,
338 for (tmp = data.accounts; tmp; tmp = g_list_next (tmp))
341 if (qfb->dont_add_cb)
343 if (qfb->dont_add_cb (account, qfb->dont_add_data))
349 gtk_list_store_append (qfb->list_store, &iter);
350 gtk_list_store_set (qfb->list_store, &iter,
352 ACCOUNT_POINTER, account,
357 case QOF_EVENT_REMOVE:
358 DEBUG (
"remove %s", name);
361 gnc_quickfill_remove (qfb->qf, name, QUICKFILL_ALPHA);
364 data.accounts = g_list_append (NULL, account);
365 gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store),
366 shared_quickfill_find_accounts, &data);
369 for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
371 path = gtk_tree_row_reference_get_path (tmp->data);
372 gtk_tree_row_reference_free (tmp->data);
373 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store),
376 gtk_list_store_remove (qfb->list_store, &iter);
378 gtk_tree_path_free (path);
383 DEBUG (
"add %s", name);
385 if (qfb->dont_add_cb &&
386 qfb->dont_add_cb (account, qfb->dont_add_data))
393 if (match_str && (g_strcmp0 (match_str, name) != 0))
395 PINFO (
"got match for %s", name);
400 PINFO (
"insert new account %s into qf=%p", name, qf);
402 gtk_list_store_append (qfb->list_store, &iter);
403 gtk_list_store_set (qfb->list_store, &iter,
405 ACCOUNT_POINTER, account,
410 DEBUG (
"other %s", name);
415 g_list_free (data.accounts);
417 g_list_free (data.refs);
Create an account-name quick-fill.
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
utility functions for the GnuCash UI
QuickFill * gnc_get_shared_account_name_quickfill(Account *root, const char *key, AccountBoolCB cb, gpointer cb_data)
Create/fetch a quickfill of account names.
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
gint QofEventId
Define the type of events allowed.
char * gnc_get_account_name_for_register(const Account *account)
Get either the full name of the account or the simple name, depending on the configuration parameter ...
#define PINFO(format, args...)
Print an informational note.
#define DEBUG(format, args...)
Print a debugging message.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
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.
const char * gnc_quickfill_string(QuickFill *qf)
For the given node 'qf', return the best-guess matching string.
void gnc_quickfill_insert(QuickFill *qf, const char *text, QuickFillSort sort)
Add the string "text" to the collection of searchable strings.