31 static QofLogModule log_module = GNC_MOD_REGISTER;
33 static void shared_quickfill_pref_changed (gpointer prefs, gchar* pref,
35 static void listen_for_account_events (QofInstance* entity,
37 gpointer user_data, gpointer event_data);
40 #define ACCOUNT_NAME 0 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;
67 shared_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);
92 shared_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_remove_link (data->accounts, tmp);
110 return (data->accounts == NULL);
119 load_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,
149 shared_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;
158 qfb->load_list_store = FALSE;
166 build_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,
193 qfb->load_list_store = FALSE;
204 AccountBoolCB cb, gpointer cb_data)
209 book = gnc_account_get_book (root);
215 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
220 gnc_get_shared_account_name_list_store (
Account* root,
const char* key,
221 AccountBoolCB cb, gpointer cb_data)
226 book = gnc_account_get_book (root);
230 return qfb->list_store;
232 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
233 return qfb->list_store;
241 listen_for_account_events (QofInstance* entity,
QofEventId event_type,
242 gpointer user_data, gpointer event_data)
244 QFB* qfb = user_data;
245 QuickFill* qf = qfb->qf;
248 const char* match_str;
256 if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_ADD | QOF_EVENT_REMOVE)))
259 if (!GNC_IS_ACCOUNT (entity))
261 account = GNC_ACCOUNT (entity);
263 ENTER (
"entity %p, event type %x, user data %p, ecent data %p",
264 entity, event_type, user_data, event_data);
268 LEAVE (
"root account mismatch");
275 LEAVE (
"account has no name");
281 case QOF_EVENT_MODIFY:
282 DEBUG (
"modify %s", name);
287 data.accounts = g_list_prepend (data.accounts, account);
288 gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store),
289 shared_quickfill_find_accounts, &data);
295 for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
297 gchar* old_name, *new_name;
298 path = gtk_tree_row_reference_get_path (tmp->data);
299 gtk_tree_row_reference_free (tmp->data);
300 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store),
303 gtk_tree_path_free (path);
306 gtk_tree_path_free (path);
307 gtk_tree_model_get (GTK_TREE_MODEL (qfb->list_store), &iter,
308 ACCOUNT_POINTER, &account,
309 ACCOUNT_NAME, &old_name,
316 if (match && (g_strcmp0 (old_name, new_name) != 0))
317 gnc_quickfill_remove (qf, old_name, QUICKFILL_ALPHA);
319 if (qfb->dont_add_cb &&
320 qfb->dont_add_cb (account, qfb->dont_add_data))
322 gnc_quickfill_remove (qf, new_name, QUICKFILL_ALPHA);
323 gtk_list_store_remove (qfb->list_store, &iter);
328 gtk_list_store_set (qfb->list_store, &iter,
329 ACCOUNT_NAME, new_name,
339 for (tmp = data.accounts; tmp; tmp = g_list_next (tmp))
342 if (qfb->dont_add_cb)
344 if (qfb->dont_add_cb (account, qfb->dont_add_data))
350 gtk_list_store_append (qfb->list_store, &iter);
351 gtk_list_store_set (qfb->list_store, &iter,
353 ACCOUNT_POINTER, account,
358 case QOF_EVENT_REMOVE:
359 DEBUG (
"remove %s", name);
362 gnc_quickfill_remove (qfb->qf, name, QUICKFILL_ALPHA);
365 data.accounts = g_list_append (NULL, account);
366 gtk_tree_model_foreach (GTK_TREE_MODEL (qfb->list_store),
367 shared_quickfill_find_accounts, &data);
370 for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
372 path = gtk_tree_row_reference_get_path (tmp->data);
373 gtk_tree_row_reference_free (tmp->data);
374 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (qfb->list_store),
377 gtk_list_store_remove (qfb->list_store, &iter);
379 gtk_tree_path_free (path);
384 DEBUG (
"add %s", name);
386 if (qfb->dont_add_cb &&
387 qfb->dont_add_cb (account, qfb->dont_add_data))
394 if (match_str && (g_strcmp0 (match_str, name) != 0))
396 PINFO (
"got match for %s", name);
401 PINFO (
"insert new account %s into qf=%p", name, qf);
403 gtk_list_store_append (qfb->list_store, &iter);
404 gtk_list_store_set (qfb->list_store, &iter,
406 ACCOUNT_POINTER, account,
411 DEBUG (
"other %s", name);
416 g_list_free (data.accounts);
418 g_list_free (data.refs);
void gnc_quickfill_insert(QuickFill *qf, const char *text, QuickFillSort sort)
Add the string "text" to the collection of searchable strings.
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.
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
utility functions for the GnuCash UI
#define PINFO(format, args...)
Print an informational note.
#define DEBUG(format, args...)
Print a debugging message.
Create an account-name quick-fill.
#define ENTER(format, args...)
Print a function entry debugging message.
QuickFill * gnc_get_shared_account_name_quickfill(Account *root, const char *key, AccountBoolCB cb, gpointer cb_data)
Create/fetch a quickfill of account names.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
gchar * 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 ...
gint QofEventId
Define the type of events allowed.
void qof_book_set_data_fin(QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
Same as qof_book_set_data(), except that the callback will be called when the book is destroyed...
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
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...
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
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...
const char * gnc_quickfill_string(QuickFill *qf)
For the given node 'qf', return the best-guess matching string.
#define LEAVE(format, args...)
Print a function exit debugging message.
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to...
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.
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.