static void assistant_instert_book_options_page (hierarchy_data *data) { kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ()); GtkWidget *vbox = gtk_vbox_new (FALSE, 0); data->options = gnc_option_db_new_for_type (QOF_ID_BOOK); gnc_option_db_load_from_kvp (data->options, slots); gnc_option_db_clean (data->options); data->optionwin = gnc_options_dialog_new_modal (TRUE, _("New Book Options")); gnc_options_dialog_build_contents_full (data->optionwin, data->options, FALSE); gnc_options_dialog_set_close_cb (data->optionwin, book_options_dialog_close_cb, (gpointer)data->options); gnc_options_dialog_set_new_book_option_values (data->options); gtk_widget_reparent (gnc_options_dialog_notebook (data->optionwin), vbox); gtk_widget_show_all (vbox); gtk_assistant_insert_page (GTK_ASSISTANT(data->dialog), vbox, 2); gtk_assistant_set_page_title (GTK_ASSISTANT(data->dialog), vbox, _("New Book Options")); gtk_assistant_set_page_complete (GTK_ASSISTANT(data->dialog), vbox, TRUE); }
gint64 qof_book_get_counter (QofBook *book, const char *counter_name) { QofBackend *be; KvpFrame *kvp; KvpValue *value; gint64 counter; if (!book) { PWARN ("No book!!!"); return -1; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return -1; } /* If we've got a backend with a counter method, call it */ be = book->backend; if (be && be->counter) return ((be->counter)(be, counter_name)); /* If not, then use the KVP in the book */ kvp = qof_book_get_slots (book); if (!kvp) { PWARN ("Book has no KVP_Frame"); return -1; } value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL); if (value) { /* found it */ counter = kvp_value_get_gint64 (value); } else { /* New counter */ counter = 0; } /* Counter is now valid; increment it */ counter++; /* Save off the new counter */ qof_book_begin_edit(book); value = kvp_value_new_gint64 (counter); kvp_frame_set_slot_path (kvp, value, "counters", counter_name, NULL); kvp_value_delete (value); qof_book_mark_dirty(book); qof_book_commit_edit(book); /* and return the value */ return counter; }
void gnc_features_set_used (QofBook *book, const gchar *feature) { KvpFrame *frame; const gchar *description; gchar *kvp_path; g_return_if_fail (book); g_return_if_fail (feature); gnc_features_init(); /* Can't set an unknown feature */ description = g_hash_table_lookup (features_table, feature); if (!description) { PWARN("Tried to set unknown feature as used."); return; } frame = qof_book_get_slots (book); kvp_path = g_strconcat ("/features/", feature, NULL); kvp_frame_set_string (frame, kvp_path, description); qof_book_kvp_changed (book); }
void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val) { qof_book_begin_edit(book); kvp_frame_set_string(qof_book_get_slots(book), opt_name, opt_val); qof_book_mark_dirty(book); qof_book_commit_edit(book); }
static GDate * get_fy_end(void) { QofBook *book; KvpFrame *book_frame; gint64 month, day; book = gnc_get_current_book(); book_frame = qof_book_get_slots(book); month = kvp_frame_get_gint64(book_frame, "/book/fyear_end/month"); day = kvp_frame_get_gint64(book_frame, "/book/fyear_end/day"); if (g_date_valid_dmy(day, month, 2005 /* not leap year */)) return g_date_new_dmy(day, month, G_DATE_BAD_YEAR); return NULL; }
/* Check if the session requires features unknown to this version of GnuCash. * * Returns a message to display if we found unknown features, NULL if we're okay. */ gchar *gnc_features_test_unknown (QofBook *book) { KvpFrame *frame = qof_book_get_slots (book); KvpValue *value; /* Setup the known_features hash table */ gnc_features_init(); g_assert(frame); value = kvp_frame_get_value(frame, "features"); if (value) { GList* features_list = NULL; frame = kvp_value_get_frame(value); g_assert(frame); /* Iterate over the members of this frame for unknown features */ kvp_frame_for_each_slot(frame, &gnc_features_test_one, &features_list); if (features_list) { GList *i; char* msg = g_strdup( _("This Dataset contains features not supported by this " "version of GnuCash. You must use a newer version of " "GnuCash in order to support the following features:" )); for (i = features_list; i; i = i->next) { char *tmp = g_strconcat(msg, "\n* ", i->data, NULL); g_free (msg); msg = tmp; } g_list_free(features_list); return msg; } } return NULL; }
static void finish_book_options_helper(GNCOptionWin * optionwin, gpointer user_data) { GNCOptionDB * options = user_data; kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ()); gboolean use_split_action_for_num_before = qof_book_use_split_action_for_num_field (gnc_get_current_book ()); gboolean use_split_action_for_num_after; if (!options) return; gnc_option_db_commit (options); gnc_option_db_save_to_kvp (options, slots, TRUE); qof_book_kvp_changed (gnc_get_current_book()); use_split_action_for_num_after = qof_book_use_split_action_for_num_field (gnc_get_current_book ()); if (use_split_action_for_num_before != use_split_action_for_num_after) gnc_book_option_num_field_source_change_cb (use_split_action_for_num_after); }
/* Determine whether this book uses trading accounts */ gboolean qof_book_use_trading_accounts (const QofBook *book) { const char *opt; kvp_value *kvp_val; kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS, OPTION_NAME_TRADING_ACCOUNTS, NULL); if (kvp_val == NULL) return FALSE; opt = kvp_value_get_string (kvp_val); if (opt && opt[0] == 't' && opt[1] == 0) return TRUE; return FALSE; }
const char* qof_book_get_string_option(const QofBook* book, const char* opt_name) { return kvp_frame_get_string(qof_book_get_slots(book), opt_name); }
static gboolean ap_close_period (GnomeDruidPage *druidpage, GtkWidget *druid, gpointer user_data) { AcctPeriodInfo *info = user_data; QofBook *closed_book = NULL, *current_book; const char *btitle; char *bnotes; Timespec closing_date; KvpFrame *book_frame; gboolean really_do_close_books = FALSE; ENTER("info=%p", info); current_book = gnc_get_current_book (); btitle = gtk_entry_get_text (info->book_title); bnotes = xxxgtk_textview_get_text (info->book_notes); PINFO("book title=%s\n", btitle); timespecFromTime_t (&closing_date, gnc_timet_get_day_end_gdate (&info->closing_date)); #define REALLY_DO_CLOSE_BOOKS #ifdef REALLY_DO_CLOSE_BOOKS really_do_close_books = TRUE; #endif /* REALLY_DO_CLOSE_BOOKS */ if (really_do_close_books) { /* Close the books ! */ qof_event_suspend (); gnc_suspend_gui_refresh (); scrub_all(); closed_book = gnc_book_close_period (current_book, closing_date, NULL, btitle); book_frame = qof_book_get_slots(closed_book); kvp_frame_set_str (book_frame, "/book/title", btitle); kvp_frame_set_str (book_frame, "/book/notes", bnotes); qof_session_add_book (gnc_get_current_session(), closed_book); /* We must save now; if we don't, and the user bails without saving, * then opening account balances will be incorrect, and this can only * lead to unhappiness. */ gnc_file_save (); gnc_resume_gui_refresh (); qof_event_resume (); gnc_gui_refresh_all (); /* resume above should have been enough ??? */ } g_free(bnotes); /* Report the status back to the user. */ info->close_status = 0; /* XXX fixme success or failure? */ /* Find the next closing date ... */ info->prev_closing_date = info->closing_date; recurrenceListNextInstance(info->period, &info->prev_closing_date, &info->closing_date); /* If the next closing date is in the future, then we are done. */ if (time(NULL) < gnc_timet_get_day_end_gdate (&info->closing_date)) { return FALSE; } /* Load up the GUI for the next closing period. */ gnc_frequency_setup_recurrence(info->period_menu, NULL, &info->closing_date); show_book_details (info); return TRUE; }