33 static void shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer qfb);
35 gpointer user_data, gpointer event_data);
38 #define ACCOUNT_NAME 0
39 #define ACCOUNT_POINTER 1
40 #define NUM_ACCOUNT_COLUMNS 2
55 gboolean load_list_store;
56 GtkListStore *list_store;
60 AccountBoolCB dont_add_cb;
61 gpointer dont_add_data;
65 shared_quickfill_destroy (
QofBook *book, gpointer key, gpointer user_data)
69 GNC_PREF_ACCOUNT_SEPARATOR,
70 shared_quickfill_pref_changed,
73 GNC_PREF_SHOW_LEAF_ACCT_NAMES,
74 shared_quickfill_pref_changed,
76 gnc_quickfill_destroy (qfb->qf);
77 g_object_unref(qfb->list_store);
90 shared_quickfill_find_accounts (GtkTreeModel *model,
97 GtkTreeRowReference* ref;
100 gtk_tree_model_get(model, iter, ACCOUNT_POINTER, &account, -1);
101 for (tmp = data->accounts; tmp; tmp = g_list_next(tmp))
103 if (tmp->data == account)
105 ref = gtk_tree_row_reference_new(model, path);
106 data->refs = g_list_append(data->refs, ref);
107 data->accounts = g_list_remove_link(data->accounts, tmp);
108 return (data->accounts == NULL);
118 load_shared_qf_cb (
Account *account, gpointer data)
124 if (qfb->dont_add_cb)
126 gboolean skip = (qfb->dont_add_cb) (account, qfb->dont_add_data);
131 if (NULL == name)
return;
133 if (qfb->load_list_store)
135 gtk_list_store_append (qfb->list_store, &iter);
136 gtk_list_store_set (qfb->list_store, &iter,
138 ACCOUNT_POINTER, account,
146 shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer user_data)
148 QFB *qfb = user_data;
151 gnc_quickfill_purge(qfb->qf);
152 gtk_list_store_clear(qfb->list_store);
153 qfb->load_list_store = TRUE;
155 qfb->load_list_store = FALSE;
163 build_shared_quickfill (
QofBook *book,
Account *root,
const char * key,
164 AccountBoolCB cb, gpointer data)
168 qfb = g_new0(
QFB, 1);
169 qfb->qf = gnc_quickfill_new ();
173 qfb->dont_add_cb = cb;
174 qfb->dont_add_data = data;
175 qfb->load_list_store = TRUE;
177 gtk_list_store_new (NUM_ACCOUNT_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);
180 GNC_PREF_ACCOUNT_SEPARATOR,
181 shared_quickfill_pref_changed,
185 GNC_PREF_SHOW_LEAF_ACCT_NAMES,
186 shared_quickfill_pref_changed,
190 qfb->load_list_store = FALSE;
203 AccountBoolCB cb, gpointer cb_data)
208 book = gnc_account_get_book (root);
211 if (qfb)
return qfb->qf;
213 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
218 gnc_get_shared_account_name_list_store (
Account *root,
220 AccountBoolCB cb, gpointer cb_data)
225 book = gnc_account_get_book (root);
228 if (qfb)
return qfb->list_store;
230 qfb = build_shared_quickfill (book, root, key, cb, cb_data);
231 return qfb->list_store;
240 gpointer user_data, gpointer event_data)
242 QFB *qfb = user_data;
246 const char *match_str;
253 if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_ADD | QOF_EVENT_REMOVE)))
256 if (!GNC_IS_ACCOUNT (entity))
258 account = GNC_ACCOUNT (entity);
260 ENTER(
"entity %p, event type %x, user data %p, ecent data %p",
261 entity, event_type, user_data, event_data);
265 LEAVE(
"root account mismatch");
272 LEAVE(
"account has no name");
278 case QOF_EVENT_MODIFY:
279 DEBUG(
"modify %s", name);
284 data.accounts = g_list_prepend(data.accounts, account);
285 gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
286 shared_quickfill_find_accounts, &data);
292 for (tmp = data.refs; tmp; tmp = g_list_next(tmp))
294 path = gtk_tree_row_reference_get_path(tmp->data);
295 gtk_tree_row_reference_free(tmp->data);
296 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(qfb->list_store),
299 gtk_tree_path_free(path);
302 gtk_tree_path_free(path);
303 gtk_tree_model_get(GTK_TREE_MODEL(qfb->list_store), &iter,
304 ACCOUNT_POINTER, &account,
306 if (qfb->dont_add_cb &&
307 qfb->dont_add_cb(account, qfb->dont_add_data))
309 gtk_list_store_remove(qfb->list_store, &iter);
314 gtk_list_store_set(qfb->list_store, &iter,
324 for (tmp = data.accounts; tmp; tmp = g_list_next(tmp))
327 if (qfb->dont_add_cb)
329 if (qfb->dont_add_cb(account, qfb->dont_add_data))
334 gtk_list_store_append (qfb->list_store, &iter);
335 gtk_list_store_set (qfb->list_store, &iter,
337 ACCOUNT_POINTER, account,
342 case QOF_EVENT_REMOVE:
343 DEBUG(
"remove %s", name);
346 gnc_quickfill_remove(qfb->qf, name, QUICKFILL_ALPHA);
349 data.accounts = g_list_append(NULL, account);
350 gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
351 shared_quickfill_find_accounts, &data);
354 for (tmp = data.refs; tmp; tmp = g_list_next(tmp))
356 path = gtk_tree_row_reference_get_path (tmp->data);
357 gtk_tree_row_reference_free (tmp->data);
358 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(qfb->list_store),
361 gtk_list_store_remove(qfb->list_store, &iter);
363 gtk_tree_path_free(path);
368 DEBUG(
"add %s", name);
369 if (qfb->dont_add_cb &&
370 qfb->dont_add_cb(account, qfb->dont_add_data))
377 if (match_str && (g_strcmp0(match_str, name) != 0))
379 PINFO (
"got match for %s", name);
384 PINFO (
"insert new account %s into qf=%p", name, qf);
386 gtk_list_store_append (qfb->list_store, &iter);
387 gtk_list_store_set (qfb->list_store, &iter,
389 ACCOUNT_POINTER, account,
394 DEBUG(
"other %s", name);
399 g_list_free(data.accounts);
401 g_list_free(data.refs);
void gnc_quickfill_insert(QuickFill *qf, const char *text, QuickFillSort sort)
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
utility functions for the GnuCash UI
#define PINFO(format, args...)
#define DEBUG(format, args...)
Create an account-name quick-fill.
#define ENTER(format, args...)
QuickFill * gnc_get_shared_account_name_quickfill(Account *root, const char *key, AccountBoolCB cb, gpointer cb_data)
gint qof_event_register_handler(QofEventHandler handler, gpointer handler_data)
Register a handler for events.
gchar * gnc_get_account_name_for_register(const Account *account)
void qof_book_set_data_fin(QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
QuickFill * gnc_quickfill_get_string_match(QuickFill *qf, const char *str)
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
GList * gnc_account_get_descendants(const Account *account)
const char * gnc_quickfill_string(QuickFill *qf)
#define LEAVE(format, args...)
Account * gnc_account_get_root(Account *acc)
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
const gchar * QofLogModule
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)