GnuCash 2.3.0
Data Structures | Modules | Files | Defines | Typedefs | Enumerations | Functions | Variables
Import_Export

Data Structures

struct  _accountpickerdialog
struct  _transactioninfo
struct  _matchinfo
struct  _main_matcher_info
struct  _GncImportMatchMap
struct  account_token_count
struct  token_accounts_info
struct  account_probability
struct  account_info
struct  _transpickerdialog
struct  _genimportsettings
struct  _split_record

Modules

 AqBanking

Files

file  import-account-matcher.h
 

Generic and very flexible account matcher/picker.


file  import-backend.h
 

Generic importer backend interface.


file  import-commodity-matcher.h
 

A Generic commodity matcher/picker.


file  import-main-matcher.h
 

Transaction matcher main window.


file  import-match-map.h
 

Generic import mapper service, maps strings->accounts.


file  import-match-picker.h
 

The transaction match picker dialog interface.


file  import-settings.h
 

Import preference handling. User preference interface for transaction matching (for both the gui and the backend)


file  import-utilities.h
 

Utility functions for writing import modules.


Defines

#define GCONF_SECTION   "dialogs/import/generic_matcher/account_matcher"
#define GCONF_SECTION   "dialogs/import/generic_matcher"
#define BAYES_OPTION   "use_bayes"
#define GCONF_SECTION   "dialogs/import/generic_matcher/transaction_list"
#define COLOR_RED   "brown1"
#define COLOR_YELLOW   "gold"
#define COLOR_GREEN   "DarkSeaGreen1"
#define IMAP_FRAME   "import-map"
#define IMAP_FRAME_BAYES   "import-map-bayes"
#define PROBABILITY_FACTOR   100000
#define threshold   (.90 * PROBABILITY_FACTOR)
#define GCONF_SECTION   "dialogs/import/generic_matcher/match_picker"
#define GCONF_IMPORT_SECTION   "dialogs/import/generic_matcher"
#define GCONF_SECTION   "dialogs/log_replay"
#define STRING_FIELD_SIZE   256
#define GCONF_SECTION   "dialogs/import/ofx"

Typedefs

typedef struct _transactioninfo GNCImportTransInfo
typedef struct _matchinfo GNCImportMatchInfo
typedef enum _action GNCImportAction
typedef struct _main_matcher_info GNCImportMainMatcher
typedef void(* GNCTransactionProcessedCB )(GNCImportTransInfo *trans_info, gboolean imported, gpointer user_data)
typedef struct _GncImportMatchMap GncImportMatchMap
typedef struct _transpickerdialog GNCImportMatchPicker
typedef struct _genimportsettings GNCImportSettings
typedef struct _split_record split_record

Enumerations

enum  _action {
  GNCImport_SKIP, GNCImport_ADD, GNCImport_CLEAR, GNCImport_UPDATE,
  GNCImport_LAST_ACTION, GNCImport_INVALID_ACTION
}
enum  downloaded_cols {
  DOWNLOADED_COL_DATE = 0, DOWNLOADED_COL_ACCOUNT, DOWNLOADED_COL_AMOUNT, DOWNLOADED_COL_DESCRIPTION,
  DOWNLOADED_COL_MEMO, DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_CLEAR, DOWNLOADED_COL_ACTION_UPDATE,
  DOWNLOADED_COL_ACTION_INFO, DOWNLOADED_COL_ACTION_PIXBUF, DOWNLOADED_COL_DATA, DOWNLOADED_COL_COLOR,
  NUM_DOWNLOADED_COLS, DOWNLOADED_COL_ACCOUNT = 0, DOWNLOADED_COL_DATE, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_MEMO, DOWNLOADED_COL_BALANCED, DOWNLOADED_COL_INFO_PTR,
  NUM_DOWNLOADED_COLS
}
enum  downloaded_cols {
  DOWNLOADED_COL_DATE = 0, DOWNLOADED_COL_ACCOUNT, DOWNLOADED_COL_AMOUNT, DOWNLOADED_COL_DESCRIPTION,
  DOWNLOADED_COL_MEMO, DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_CLEAR, DOWNLOADED_COL_ACTION_UPDATE,
  DOWNLOADED_COL_ACTION_INFO, DOWNLOADED_COL_ACTION_PIXBUF, DOWNLOADED_COL_DATA, DOWNLOADED_COL_COLOR,
  NUM_DOWNLOADED_COLS, DOWNLOADED_COL_ACCOUNT = 0, DOWNLOADED_COL_DATE, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_MEMO, DOWNLOADED_COL_BALANCED, DOWNLOADED_COL_INFO_PTR,
  NUM_DOWNLOADED_COLS
}
enum  matcher_cols {
  MATCHER_COL_CONFIDENCE = 0, MATCHER_COL_CONFIDENCE_PIXBUF, MATCHER_COL_DATE, MATCHER_COL_AMOUNT,
  MATCHER_COL_DESCRIPTION, MATCHER_COL_MEMO, MATCHER_COL_INFO_PTR, NUM_MATCHER_COLS
}

Functions

char * libgncmod_csv_gnc_module_path (void)
char * libgncmod_csv_gnc_module_description (void)
int libgncmod_csv_gnc_module_init (int refcount)
int libgncmod_csv_gnc_module_end (int refcount)
Accountgnc_import_select_account (GtkWidget *parent, const gchar *account_online_id_value, gboolean auto_create, const gchar *account_human_description, const gnc_commodity *new_account_default_commodity, GNCAccountType new_account_default_type, Account *default_selection, gboolean *ok_pressed)
gnc_commoditygnc_import_select_commodity (const char *cusip, gboolean ask_on_unknown, const char *default_fullname, const char *default_mnemonic)
void on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
void on_matcher_cancel_clicked (GtkButton *button, gpointer user_data)
void on_matcher_help_clicked (GtkButton *button, gpointer user_data)
void on_matcher_help_close_clicked (GtkButton *button, gpointer user_data)
void gnc_gen_trans_list_delete (GNCImportMainMatcher *info)
GNCImportMainMatchergnc_gen_trans_list_new (GtkWidget *parent, const gchar *heading, gboolean all_from_same_account, gint match_date_hardlimit)
void gnc_gen_trans_list_add_tp_cb (GNCImportMainMatcher *info, GNCTransactionProcessedCB trans_processed_cb, gpointer user_data)
gboolean gnc_gen_trans_list_run (GNCImportMainMatcher *info)
void gnc_gen_trans_list_add_trans (GNCImportMainMatcher *gui, Transaction *trans)
void gnc_gen_trans_list_add_trans_with_ref_id (GNCImportMainMatcher *gui, Transaction *trans, guint32 ref_id)
GtkWidget * gnc_gen_trans_list_widget (GNCImportMainMatcher *info)
void gnc_imap_destroy (GncImportMatchMap *imap)
void gnc_imap_clear (GncImportMatchMap *imap)
Accountgnc_imap_find_account (GncImportMatchMap *imap, const char *category, const char *key)
void gnc_imap_add_account (GncImportMatchMap *imap, const char *category, const char *key, Account *acc)
Accountgnc_imap_find_account_bayes (GncImportMatchMap *imap, GList *tokens)
void gnc_imap_add_account_bayes (GncImportMatchMap *imap, GList *tokens, Account *acc)
void gnc_import_match_picker_run_and_close (GNCImportTransInfo *transaction_info)
GNCImportSettingsgnc_import_Settings_new (void)
void gnc_import_Settings_delete (GNCImportSettings *settings)
gboolean gnc_import_trans_has_online_id (Transaction *transaction)
gboolean gnc_import_split_has_online_id (Split *split)
void gnc_file_log_replay (void)
char * libgncmod_log_replay_gnc_module_path (void)
char * libgncmod_log_replay_gnc_module_description (void)
int libgncmod_log_replay_gnc_module_init (int refcount)
int libgncmod_log_replay_gnc_module_end (int refcount)
int ofx_proc_security_cb (const struct OfxSecurityData data, void *security_user_data)
int ofx_proc_transaction_cb (struct OfxTransactionData data, void *transaction_user_data)
int ofx_proc_account_cb (struct OfxAccountData data, void *account_user_data)
void gnc_file_ofx_import (void)
char * libgncmod_ofx_gnc_module_path (void)
char * libgncmod_ofx_gnc_module_description (void)
int libgncmod_ofx_gnc_module_init (int refcount)
int libgncmod_ofx_gnc_module_end (int refcount)

Variables

int libgncmod_csv_gnc_module_system_interface = 0
int libgncmod_csv_gnc_module_current = 0
int libgncmod_csv_gnc_module_revision = 0
int libgncmod_csv_gnc_module_age = 0
int libgncmod_log_replay_gnc_module_system_interface = 0
int libgncmod_log_replay_gnc_module_current = 0
int libgncmod_log_replay_gnc_module_revision = 0
int libgncmod_log_replay_gnc_module_age = 0
GNCImportMainMatchergnc_ofx_importer_gui = NULL
GList * ofx_created_commodites = NULL
int libgncmod_ofx_gnc_module_system_interface = 0
int libgncmod_ofx_gnc_module_current = 0
int libgncmod_ofx_gnc_module_revision = 0
int libgncmod_ofx_gnc_module_age = 0

Non-GUI Functions

GdkPixbuf * gen_probability_pixbuf (gint score_original, GNCImportSettings *settings, GtkWidget *widget)
void gnc_import_find_split_matches (GNCImportTransInfo *trans_info, gint process_threshold, double fuzzy_amount_difference, gint match_date_hardlimit)
gboolean gnc_import_process_trans_item (GncImportMatchMap *matchmap, GNCImportTransInfo *trans_info)
gboolean gnc_import_exists_online_id (Transaction *trans)
void gnc_import_TransInfo_init_matches (GNCImportTransInfo *trans_info, GNCImportSettings *settings)

Getters/Setters for GNCImportTransInfo

GList * gnc_import_TransInfo_get_match_list (const GNCImportTransInfo *info)
Transactiongnc_import_TransInfo_get_trans (const GNCImportTransInfo *info)
gboolean gnc_import_TransInfo_is_balanced (const GNCImportTransInfo *info)
Splitgnc_import_TransInfo_get_fsplit (const GNCImportTransInfo *info)
GNCImportMatchInfognc_import_TransInfo_get_selected_match (const GNCImportTransInfo *info)
void gnc_import_TransInfo_set_selected_match (GNCImportTransInfo *info, GNCImportMatchInfo *match, gboolean selected_manually)
gboolean gnc_import_TransInfo_get_match_selected_manually (const GNCImportTransInfo *info)
GNCImportAction gnc_import_TransInfo_get_action (const GNCImportTransInfo *info)
void gnc_import_TransInfo_set_action (GNCImportTransInfo *info, GNCImportAction action)
Accountgnc_import_TransInfo_get_destacc (const GNCImportTransInfo *info)
void gnc_import_TransInfo_set_destacc (GNCImportTransInfo *info, Account *acc, gboolean selected_manually)
gboolean gnc_import_TransInfo_get_destacc_selected_manually (const GNCImportTransInfo *info)
guint32 gnc_import_TransInfo_get_ref_id (const GNCImportTransInfo *info)
void gnc_import_TransInfo_set_ref_id (GNCImportTransInfo *info, guint32 ref_id)
void gnc_import_TransInfo_delete (GNCImportTransInfo *info)
GNCImportTransInfognc_import_TransInfo_new (Transaction *trans, GncImportMatchMap *matchmap)
gboolean gnc_import_TransInfo_refresh_destacc (GNCImportTransInfo *transaction_info, GncImportMatchMap *matchmap)

Getters/Setters for GNCImportMatchInfo

Splitgnc_import_MatchInfo_get_split (const GNCImportMatchInfo *info)
gint gnc_import_MatchInfo_get_probability (const GNCImportMatchInfo *info)
GncImportMatchMapgnc_imap_create_from_account (Account *acc)
GncImportMatchMapgnc_imap_create_from_book (QofBook *book)

Some well-known categories

NOTE: You DO NOT have to use these values in your importer -- these are just "well known" values, not "mandatory" values. You are free to use these if they apply, map your own fields to these labels, or create your own category strings.

#define GNCIMPORT_DESC   "desc"
#define GNCIMPORT_MEMO   "memo"
#define GNCIMPORT_PAYEE   "payee"

Getters/Setters for GNCImportSettings

double gnc_import_Settings_get_fuzzy_amount (GNCImportSettings *settings)
gboolean gnc_import_Settings_get_action_skip_enabled (GNCImportSettings *settings)
gboolean gnc_import_Settings_get_action_add_enabled (GNCImportSettings *settings)
gboolean gnc_import_Settings_get_action_update_enabled (GNCImportSettings *settings)
gboolean gnc_import_Settings_get_action_clear_enabled (GNCImportSettings *settings)
gint gnc_import_Settings_get_clear_threshold (GNCImportSettings *settings)
gint gnc_import_Settings_get_add_threshold (GNCImportSettings *settings)
gint gnc_import_Settings_get_display_threshold (GNCImportSettings *settings)
void gnc_import_Settings_set_match_date_hardlimit (GNCImportSettings *s, gint m)
gint gnc_import_Settings_get_match_date_hardlimit (const GNCImportSettings *s)

Setter-getters

Setter and getter functions for the online_id kvp_frame for Splits.

const gchar * gnc_import_get_acc_online_id (Account *account)
void gnc_import_set_acc_online_id (Account *account, const gchar *string_value)
const gchar * gnc_import_get_trans_online_id (Transaction *transaction)
void gnc_import_set_trans_online_id (Transaction *transaction, const gchar *string_value)
const gchar * gnc_import_get_split_online_id (Split *split)
void gnc_import_set_split_online_id (Split *split, const gchar *string_value)

Define Documentation

#define GCONF_IMPORT_SECTION   "dialogs/import/generic_matcher"

The GConf section of the importer

Definition at line 38 of file import-settings.h.

#define PROBABILITY_FACTOR   100000

convert a hash table of account names and (struct account_probability*) into a hash table of 100000x the percentage match value, ie. 10% would be 0.10 * 100000 = 10000

Definition at line 229 of file import-match-map.c.


Function Documentation

GdkPixbuf * gen_probability_pixbuf ( gint  score,
GNCImportSettings settings,
GtkWidget *  widget 
)

This function generates a new pixmap representing a match score. It is a series of vertical bars of different colors. -Below or at the add_threshold the bars are red -Above or at the clear_threshold the bars are green -Between the two threshold the bars are yellow

Parameters:
scoreThe score for which to generate a pixmap.
settingsThe user settings from which to get the threshold
widgetThe parent widget in which the pixmap will eventually be added. Will be used to generate the colormap.

Definition at line 280 of file import-backend.c.

{
    GdkPixbuf* retval = NULL;
    gint i, j;
    gint score;
    const gint height = 15;
    const gint width_each_bar = 7;
    gchar * green_bar = ("bggggb ");
    gchar * yellow_bar = ("byyyyb ");
    gchar * red_bar = ("brrrrb ");
    gchar * black_bar = ("bbbbbb ");
    const gint width_first_bar = 1;
    gchar * black_first_bar = ("b");
    const gint num_colors = 5;
    gchar * size_str;
    gchar * none_color_str = g_strdup_printf("  c None");
    gchar * green_color_str = g_strdup_printf("g c green");
    gchar * yellow_color_str = g_strdup_printf("y c yellow");
    gchar * red_color_str = g_strdup_printf("r c red");
    gchar * black_color_str = g_strdup_printf("b c black");
    gchar * xpm[2+num_colors+height];
    gint add_threshold, clear_threshold;

    g_assert(settings);
    g_assert(widget);
    if (score_original < 0)
    {
        score = 0;
    }
    else
    {
        score = score_original;
    }
    size_str = g_strdup_printf("%d%s%d%s%d%s", (width_each_bar * score) + width_first_bar/*width*/, " ", height, " ", num_colors, " 1"/*characters per pixel*/);

    /*DEBUG("Begin");*/
    xpm[0] = size_str;
    xpm[1] = none_color_str;
    xpm[2] = green_color_str;
    xpm[3] = yellow_color_str;
    xpm[4] = red_color_str;
    xpm[5] = black_color_str;
    add_threshold = gnc_import_Settings_get_add_threshold(settings);
    clear_threshold = gnc_import_Settings_get_clear_threshold(settings);

    for (i = 0; i < height; i++)
    {
        xpm[num_colors+1+i] = g_new0(char, (width_each_bar * score) + width_first_bar + 1);
        for (j = 0; j <= score; j++)
        {
            if (i == 0 || i == height - 1)
            {
                if (j == 0)
                {
                    strcat(xpm[num_colors+1+i], black_first_bar);
                }
                else
                {
                    strcat(xpm[num_colors+1+i], black_bar);
                }
            }
            else
            {
                if (j == 0)
                {
                    strcat(xpm[num_colors+1+i], black_first_bar);
                }
                else if (j <= add_threshold)
                {
                    strcat(xpm[num_colors+1+i], red_bar);
                }
                else if (j >= clear_threshold)
                {
                    strcat(xpm[num_colors+1+i], green_bar);
                }
                else
                {
                    strcat(xpm[num_colors+1+i], yellow_bar);
                }
            }
        }
    }

    retval =  gdk_pixbuf_new_from_xpm_data((const gchar **)xpm);
    for (i = 0; i <= num_colors + height; i++)
    {
        /*DEBUG("free_loop i=%d%s%s",i,": ",xpm[i]);*/
        g_free(xpm[i]);
    }

    return retval;
}
void gnc_file_log_replay ( void  )

The gnc_file_log_replay() routine will pop up a standard file selection dialogue asking the user to pick a log file to replay. If one is selected the the .log file is opened and read. It's contents are then silently merged in the current log file.

Definition at line 537 of file gnc-log-replay.c.

{
    char *selected_filename;
    char *default_dir;
    char read_buf[256];
    char *read_retval;
    GtkFileFilter *filter;
    FILE *log_file;
    char * record_start_str = "===== START";
    /* NOTE: This string must match src/engine/TransLog.c (sans newline) */
    char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t"
                                  "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t"
                                  "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled";
    static char *expected_header = NULL;

    /* Use g_strdup_printf so we don't get accidental tab -> space conversion */
    if (!expected_header)
        expected_header = g_strdup(expected_header_orig);

    qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
    ENTER(" ");

    /* Don't log the log replay. This would only result in redundant logs */
    xaccLogDisable();

    default_dir = gnc_get_default_directory(GCONF_SECTION);

    filter = gtk_file_filter_new();
    gtk_file_filter_set_name(filter, "*.log");
    gtk_file_filter_add_pattern(filter, "*.[Ll][Oo][Gg]");
    selected_filename = gnc_file_dialog(_("Select a .log file to replay"),
                                        g_list_prepend(NULL, filter),
                                        default_dir,
                                        GNC_FILE_DIALOG_OPEN);
    g_free(default_dir);

    if (selected_filename != NULL)
    {
        /* Remember the directory as the default. */
        default_dir = g_path_get_dirname(selected_filename);
        gnc_set_default_directory(GCONF_SECTION, default_dir);
        g_free(default_dir);

        /*strncpy(file,selected_filename, 255);*/
        DEBUG("Filename found: %s", selected_filename);
        if (xaccFileIsCurrentLog(selected_filename))
        {
            g_warning("Cannot open the current log file: %s", selected_filename);
            gnc_error_dialog(NULL,
                             /* Translators: %s is the file name. */
                             _("Cannot open the current log file: %s"),
                             selected_filename);
        }
        else
        {
            DEBUG("Opening selected file");
            log_file = g_fopen(selected_filename, "r");
            if (!log_file || ferror(log_file) != 0)
            {
                int err = errno;
                perror("File open failed");
                gnc_error_dialog(NULL,
                                 /* Translation note:
                                  * First argument is the filename,
                                  * second argument is the error.
                                  */
                                 _("Failed to open log file: %s: %s"),
                                 selected_filename,
                                 strerror(err));
            }
            else
            {
                if ((read_retval = fgets(read_buf, sizeof(read_buf), log_file)) == NULL)
                {
                    DEBUG("Read error or EOF");
                    gnc_info_dialog(NULL, "%s",
                                    _("The log file you selected was empty."));
                }
                else
                {
                    if (strncmp(expected_header, read_buf, strlen(expected_header)) != 0)
                    {
                        PERR("File header not recognised:\n%s", read_buf);
                        PERR("Expected:\n%s", expected_header);
                        gnc_error_dialog(NULL, "%s",
                                         _("The log file you selected cannot be read.  "
                                           "The file header was not recognized."));
                    }
                    else
                    {
                        do
                        {
                            read_retval = fgets(read_buf, sizeof(read_buf), log_file);
                            /*DEBUG("Chunk read: %s",read_retval);*/
                            if (strncmp(record_start_str, read_buf, strlen(record_start_str)) == 0) /* If a record started */
                            {
                                process_trans_record(log_file);
                            }
                        }
                        while (feof(log_file) == 0);
                    }
                }
                fclose(log_file);
            }
        }
        g_free(selected_filename);
    }
    /* Start logging again */
    xaccLogEnable();

    LEAVE("");
}
void gnc_file_ofx_import ( void  )

The gnc_file_ofx_import() routine will pop up a standard file selection dialogue asking the user to pick a OFX/QFX file. If one is selected the the OFX file is opened and read. It's contents are merged into the existing session (if any). The current session continues to remain open for editing.

Definition at line 876 of file gnc-ofx-import.c.

{
    extern int ofx_PARSER_msg;
    extern int ofx_DEBUG_msg;
    extern int ofx_WARNING_msg;
    extern int ofx_ERROR_msg;
    extern int ofx_INFO_msg;
    extern int ofx_STATUS_msg;
    char *selected_filename;
    char *default_dir;
    LibofxContextPtr libofx_context = libofx_get_new_context();

    ofx_PARSER_msg = false;
    ofx_DEBUG_msg = false;
    ofx_WARNING_msg = true;
    ofx_ERROR_msg = true;
    ofx_INFO_msg = true;
    ofx_STATUS_msg = false;

    DEBUG("gnc_file_ofx_import(): Begin...\n");

    default_dir = gnc_get_default_directory(GCONF_SECTION);
    selected_filename = gnc_file_dialog(_("Select an OFX/QFX file to process"),
                                        NULL,
                                        default_dir,
                                        GNC_FILE_DIALOG_IMPORT);
    g_free(default_dir);

    if (selected_filename != NULL)
    {
#ifdef G_OS_WIN32
        gchar *conv_name;
#endif

        /* Remember the directory as the default. */
        default_dir = g_path_get_dirname(selected_filename);
        gnc_set_default_directory(GCONF_SECTION, default_dir);
        g_free(default_dir);

        /*strncpy(file,selected_filename, 255);*/
        DEBUG("Filename found: %s", selected_filename);

        /* Create the Generic transaction importer GUI. */
        gnc_ofx_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE, 42);

        /* Look up the needed gconf options */
        auto_create_commodity =
            gnc_gconf_get_bool(GCONF_IMPORT_SECTION, "auto_create_commodity", NULL);

        /* Initialize libofx */

        /*ofx_set_statement_cb(libofx_context, ofx_proc_statement_cb, 0);*/
        ofx_set_account_cb(libofx_context, ofx_proc_account_cb, 0);
        ofx_set_transaction_cb(libofx_context, ofx_proc_transaction_cb, 0);
        ofx_set_security_cb(libofx_context, ofx_proc_security_cb, 0);
        /*ofx_set_status_cb(libofx_context, ofx_proc_status_cb, 0);*/

#ifdef G_OS_WIN32
        conv_name = g_win32_locale_filename_from_utf8(selected_filename);
        g_free(selected_filename);
        selected_filename = conv_name;
#endif

        DEBUG("Opening selected file");
        libofx_proc_file(libofx_context, selected_filename, AUTODETECT);
        g_free(selected_filename);
    }

    if (ofx_created_commodites)
    {
        /* FIXME: Present some result window about the newly created
         * commodities */
        g_warning("Created %d new commodities during import", g_list_length(ofx_created_commodites));
        g_list_free(ofx_created_commodites);
        ofx_created_commodites = NULL;
    }
    else
    {
        //g_warning("No new commodities created");
    }
}
void gnc_gen_trans_list_add_tp_cb ( GNCImportMainMatcher info,
GNCTransactionProcessedCB  trans_processed_cb,
gpointer  user_data 
)

Add transaction processed callback to the transaction importer.

Parameters:
infoThe Transaction Importer to use.
trans_processed_cbThe callback function.

Definition at line 584 of file import-main-matcher.c.

{
    info->user_data = user_data;
    info->transaction_processed_cb = trans_processed_cb;
}
void gnc_gen_trans_list_add_trans ( GNCImportMainMatcher gui,
Transaction trans 
)

Add a newly imported Transaction to the Transaction Importer. The Importer takes over ownership of the passed transaction.

Parameters:
guiThe Transaction Importer to use.
transThe Transaction to add. The must contain at least one split, and this split must have been associated with an account Only the first split will be used for matching. The transaction must NOT be commited. The Importer takes over ownership of the passed transaction.

Definition at line 821 of file import-main-matcher.c.

{
    gnc_gen_trans_list_add_trans_with_ref_id(gui, trans, 0);
    return;
}/* end gnc_import_add_trans() */
void gnc_gen_trans_list_add_trans_with_ref_id ( GNCImportMainMatcher gui,
Transaction trans,
guint32  ref_id 
)

Add a newly imported Transaction to the Transaction Importer and provide an external reference id for it. The Importer takes over ownership of the passed transaction.

Parameters:
guiThe Transaction Importer to use.
transThe Transaction to add. The must contain at least one split, and this split must have been associated with an account Only the first split will be used for matching. The transaction must NOT be commited. The Importer takes over ownership of the passed transaction.
ref_idReference id which links an external object to the transaction.

Definition at line 827 of file import-main-matcher.c.

{
    GNCImportTransInfo * transaction_info = NULL;
    GtkTreeModel *model;
    GtkTreeIter iter;
    g_assert (gui);
    g_assert (trans);


    if (gnc_import_exists_online_id (trans))
        return;
    else
    {
        transaction_info = gnc_import_TransInfo_new(trans, NULL);
        gnc_import_TransInfo_set_ref_id(transaction_info, ref_id);

        gnc_import_TransInfo_init_matches(transaction_info,
                                          gui->user_settings);

        model = gtk_tree_view_get_model(gui->view);
        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        refresh_model_row (gui, model, &iter, transaction_info);
    }
    return;
}/* end gnc_import_add_trans_with_ref_id() */
void gnc_gen_trans_list_delete ( GNCImportMainMatcher info)

Deletes the given object.

Definition at line 98 of file import-main-matcher.c.

{
    GtkTreeModel *model;
    GtkTreeIter iter;
    GNCImportTransInfo *trans_info;

    if (info == NULL)
        return;

    model = gtk_tree_view_get_model(info->view);
    if (gtk_tree_model_get_iter_first(model, &iter))
    {
        do
        {
            gtk_tree_model_get(model, &iter,
                               DOWNLOADED_COL_DATA, &trans_info,
                               -1);

            if (info->transaction_processed_cb)
            {
                info->transaction_processed_cb(trans_info,
                                               FALSE,
                                               info->user_data);
            }

            gnc_import_TransInfo_delete(trans_info);
        }
        while (gtk_tree_model_iter_next (model, &iter));
    }

    gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(info->dialog));
    gnc_import_Settings_delete (info->user_settings);
    gtk_widget_destroy (GTK_WIDGET (info->dialog));
    g_free (info);
}
GNCImportMainMatcher * gnc_gen_trans_list_new ( GtkWidget *  parent,
const gchar *  heading,
gboolean  all_from_same_account,
gint  match_date_hardlimit 
)

Create a new generic transaction dialog window and return it.

Parameters:
parentThe parent GtkWidget. May be NULL.
headingThe heading label in the Importer window. May be NULL.
all_from_same_accountSet this to TRUE if ALL the transaction that will be added with gnc_gen_trans_list_add_trans are from the same source account. This will cause the account column to be hidden.
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.

Definition at line 528 of file import-main-matcher.c.

{
    GNCImportMainMatcher *info;
    GtkBuilder *builder;
    GtkWidget *heading_label;
    GtkWidget *button;
    gboolean show_update;

    info = g_new0 (GNCImportMainMatcher, 1);

    /* Initialize user Settings. */
    info->user_settings = gnc_import_Settings_new ();
    gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit);

    /* Initialize the GtkDialog. */
    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher");

    info->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_matcher"));
    g_assert (info->dialog != NULL);
    info->view = GTK_TREE_VIEW(gtk_builder_get_object (builder, "downloaded_view"));
    g_assert (info->view != NULL);

    show_update = gnc_import_Settings_get_action_update_enabled(info->user_settings);
    gnc_gen_trans_init_view(info, all_from_same_account, show_update);
    heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
    g_assert (heading_label != NULL);

    /* if (parent)
      gtk_window_set_transient_for (GTK_WINDOW (info->dialog),
                          GTK_WINDOW (parent));*/

    /*Initialise the colors */
    gdk_color_parse(COLOR_RED,    &info->color_back_red);
    gdk_color_parse(COLOR_YELLOW, &info->color_back_yellow);
    gdk_color_parse(COLOR_GREEN,  &info->color_back_green);

    if (heading)
        gtk_label_set_text (GTK_LABEL (heading_label), heading);

    gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(info->dialog));
    gtk_widget_show_all (GTK_WIDGET (info->dialog));

    info->transaction_processed_cb = NULL;

    /* Connect the signals */
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, info);

    g_object_unref(G_OBJECT(builder));

    return info;
}
gboolean gnc_gen_trans_list_run ( GNCImportMainMatcher info)

Run this dialog and return only after the user pressed Ok, Cancel, or closed the window. This means that all actual importing will have been finished upon returning.

Definition at line 593 of file import-main-matcher.c.

{
    gboolean result;

    /* DEBUG("Begin"); */
    result = gtk_dialog_run (GTK_DIALOG (info->dialog));
    /* DEBUG("Result was %d", result); */

    /* No destroying here since the dialog was already destroyed through
       the ok_clicked handlers. */

    return result;
}
GtkWidget * gnc_gen_trans_list_widget ( GNCImportMainMatcher info)

Returns the widget of this dialog.

Definition at line 867 of file import-main-matcher.c.

{
    g_assert(info);
    return info->dialog;
}
void gnc_imap_add_account ( GncImportMatchMap imap,
const char *  category,
const char *  key,
Account acc 
)

Store an Account in the map

Store an Account in the map. This mapping is immediatly stored in the underlying kvp frame, regardless of whether the MatchMap is destroyed later or not.

Definition at line 142 of file import-match-map.c.

{
    kvp_value *value;

    if (!imap || !key || !acc || (strlen (key) == 0)) return;
    if (!category)
    {
        category = key;
        key = NULL;
    }
    g_return_if_fail (acc != NULL);

    value = kvp_value_new_guid (xaccAccountGetGUID (acc));
    g_return_if_fail (value != NULL);
    xaccAccountBeginEdit (imap->acc);
    kvp_frame_set_slot_path (imap->frame, value, IMAP_FRAME, category, key, NULL);
    qof_instance_set_dirty (QOF_INSTANCE (imap->acc));
    xaccAccountCommitEdit (imap->acc);
    kvp_value_delete (value);

    /* XXX Mark the account (or book) as dirty! */
}
void gnc_imap_add_account_bayes ( GncImportMatchMap imap,
GList *  tokens,
Account acc 
)

Updates the imap for a given account using a list of tokens

Store an Account in the map. This mapping is immediatly stored in the underlying kvp frame, regardless of whether the MatchMap is destroyed later or not.

Definition at line 464 of file import-match-map.c.

{
    GList *current_token;
    kvp_value *value;
    gint64 token_count;
    char* account_fullname;
    kvp_value *new_value; /* the value that will be added back into the kvp tree */

    ENTER(" ");

    /* if imap is null return */
    if (!imap)
    {
        LEAVE(" ");
        return;
    }

    g_return_if_fail (acc != NULL);
    account_fullname = gnc_account_get_full_name(acc);
    xaccAccountBeginEdit (imap->acc);

    PINFO("account name: '%s'\n", account_fullname);

    /* process each token in the list */
    for (current_token = g_list_first(tokens); current_token;
            current_token = current_token->next)
    {
        /* Jump to next iteration if the pointer is not valid or if the
                 string is empty. In HBCI import we almost always get an empty
                 string, which doesn't work in the kvp loopkup later. So we
                 skip this case here. */
        if (!current_token->data || (*((char*)current_token->data) == '\0'))
            continue;

        /* start off with no tokens for this account */
        token_count = 0;

        PINFO("adding token '%s'\n", (char*)current_token->data);

        /* is this token/account_name already in the kvp tree? */
        value = kvp_frame_get_slot_path(imap->frame, IMAP_FRAME_BAYES,
                                        (char*)current_token->data, account_fullname,
                                        NULL);

        /* if the token/account is already in the tree, read the current
         * value from the tree and use this for the basis of the value we
         * are putting back
         */
        if (value)
        {
            PINFO("found existing value of '%ld'\n",
                  (long)kvp_value_get_gint64(value));

            /* convert this value back into an integer */
            token_count += kvp_value_get_gint64(value);
        }

        /* increment the token count */
        token_count++;

        /* create a new value */
        new_value = kvp_value_new_gint64(token_count);

        /* insert the value into the kvp tree at
         * /imap->frame/IMAP_FRAME/token_string/account_name_string
         */
        kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
                                (char*)current_token->data, account_fullname, NULL);
        /* kvp_frame_set_slot_path() copied the value so we
         * need to delete this one ;-) */
        kvp_value_delete(new_value);
    }

    /* free up the account fullname string */
    qof_instance_set_dirty (QOF_INSTANCE (imap->acc));
    xaccAccountCommitEdit (imap->acc);
    g_free(account_fullname);

    LEAVE(" ");
}
void gnc_imap_clear ( GncImportMatchMap imap)

Clear an import map -- this removes ALL entries in the map

Definition at line 107 of file import-match-map.c.

{
    if (!imap) return;

    /* Clear the IMAP_FRAME kvp */
    kvp_frame_set_slot_path (imap->frame, NULL, IMAP_FRAME);

    /* Clear the bayes kvp, IMAP_FRAME_BAYES */
    kvp_frame_set_slot_path (imap->frame, NULL, IMAP_FRAME_BAYES);

    /* XXX: mark the account (or book) as dirty! */
}
GncImportMatchMap * gnc_imap_create_from_account ( Account acc)

Obtain an ImportMatchMap object from an Account or a Book

Definition at line 77 of file import-match-map.c.

{
    kvp_frame * frame;

    if (!acc) return NULL;
    frame = xaccAccountGetSlots (acc);
    g_return_val_if_fail (frame != NULL, NULL);

    return gnc_imap_create_from_frame (frame, acc, NULL);
}
void gnc_imap_destroy ( GncImportMatchMap imap)

Destroy an import map

Destroy an import map. But all stored entries will still continue to exist in the underlying kvp frame of the account or book.

Definition at line 100 of file import-match-map.c.

{
    if (!imap) return;
    g_free (imap);
}
Account * gnc_imap_find_account ( GncImportMatchMap imap,
const char *  category,
const char *  key 
)

Look up an Account in the map

Definition at line 121 of file import-match-map.c.

{
    kvp_value *value;
    GncGUID * guid;

    if (!imap || !key) return NULL;
    if (!category)
    {
        category = key;
        key = NULL;
    }

    value = kvp_frame_get_slot_path (imap->frame, IMAP_FRAME, category, key, NULL);
    if (!value) return NULL;

    guid = kvp_value_get_guid (value);
    return xaccAccountLookup (guid, imap->book);
}
Account * gnc_imap_find_account_bayes ( GncImportMatchMap imap,
GList *  tokens 
)

Look up an Account in the map

Look up an Account in the map from a GList* of pointers to strings(tokens) from the current transaction

< holds the accounts and total token count for a single token

< pointer to the current token from the input GList *tokens

< pointer to the struct account_token_count

< an account name and the number of times a token has appeared for the account

< intermediate storage of values to compute the bayes probability of an account

Definition at line 290 of file import-match-map.c.

{
    struct token_accounts_info tokenInfo; 
    GList *current_token;                       
    GList *current_account_token;               
    struct account_token_count *account_c; 
    struct account_probability *account_p; 
    GHashTable *running_probabilities = g_hash_table_new(g_str_hash, g_str_equal);
    GHashTable *final_probabilities = g_hash_table_new(g_str_hash, g_str_equal);
    struct account_info account_i;
    kvp_value* value;
    kvp_frame* token_frame;

    ENTER(" ");

    /* check to see if the imap is NULL */
    if (!imap)
    {
        PINFO("imap is null, returning null");
        LEAVE(" ");
        return NULL;
    }

    /* find the probability for each account that contains any of the tokens
     * in the input tokens list
     */
    for (current_token = tokens; current_token; current_token = current_token->next)
    {
        /* zero out the token_accounts_info structure */
        memset(&tokenInfo, 0, sizeof(struct token_accounts_info));

        PINFO("token: '%s'", (char*)current_token->data);

        /* find the slot for the given token off of the source account
         * for these tokens, search off of the IMAP_FRAME_BAYES path so
         * we aren't looking from the parent of the entire kvp tree
         */
        value = kvp_frame_get_slot_path(imap->frame, IMAP_FRAME_BAYES,
                                        (char*)current_token->data, NULL);

        /* if value is null we should skip over this token */
        if (!value)
            continue;

        /* convert the slot(value) into a the frame that contains the
         * list of accounts
         */
        token_frame = kvp_value_get_frame(value);

        /* token_frame should NEVER be null */
        if (!token_frame)
        {
            PERR("token '%s' has no accounts", (char*)current_token->data);
            continue; /* skip over this token */
        }

        /* process the accounts for this token, adding the account if it
         * doesn't already exist or adding to the existing accounts token
         * count if it does
         */
        kvp_frame_for_each_slot(token_frame, buildTokenInfo, &tokenInfo);

        /* for each account we have just found, see if the account already exists
         * in the list of account probabilities, if not add it
         */
        for (current_account_token = tokenInfo.accounts; current_account_token;
                current_account_token = current_account_token->next)
        {
            /* get the account name and corresponding token count */
            account_c = (struct account_token_count*)current_account_token->data;

            PINFO("account_c->account_name('%s'), "
                  "account_c->token_count('%ld')/total_count('%ld')",
                  account_c->account_name, (long)account_c->token_count,
                  (long)tokenInfo.total_count);

            account_p = g_hash_table_lookup(running_probabilities,
                                            account_c->account_name);

            /* if the account exists in the list then continue
             * the running probablities
             */
            if (account_p)
            {
                account_p->product =
                    ((double)account_c->token_count / (double)tokenInfo.total_count)
                    * account_p->product;
                account_p->product_difference =
                    ((double)1 - ((double)account_c->token_count /
                                  (double)tokenInfo.total_count))
                    * account_p->product_difference;
                PINFO("product == %f, product_difference == %f",
                      account_p->product, account_p->product_difference);
            }
            else
            {
                /* add a new entry */
                PINFO("adding a new entry for this account");
                account_p = (struct account_probability*)
                            g_new0(struct account_probability, 1);

                /* set the product and product difference values */
                account_p->product = ((double)account_c->token_count /
                                      (double)tokenInfo.total_count);
                account_p->product_difference =
                    (double)1 - ((double)account_c->token_count /
                                 (double)tokenInfo.total_count);

                PINFO("product == %f, product_difference == %f",
                      account_p->product, account_p->product_difference);

                /* add the account name and (struct account_probability*)
                 * to the hash table */
                g_hash_table_insert(running_probabilities,
                                    account_c->account_name, account_p);
            }
        } /* for all accounts in tokenInfo */

        /* free the data in tokenInfo */
        for (current_account_token = tokenInfo.accounts; current_account_token;
                current_account_token = current_account_token->next)
        {
            /* free up each struct account_token_count we allocated */
            g_free((struct account_token_count*)current_account_token->data);
        }

        g_list_free(tokenInfo.accounts); /* free the accounts GList */
    }

    /* build a hash table of account names and their final probabilities
     * from each entry in the running_probabilties hash table
     */
    g_hash_table_foreach(running_probabilities, buildProbabilities,
                         final_probabilities);

    /* find the highest probabilty and the corresponding account */
    memset(&account_i, 0, sizeof(struct account_info));
    g_hash_table_foreach(final_probabilities, highestProbability, &account_i);

    /* free each element of the running_probabilities hash */
    g_hash_table_foreach(running_probabilities, freeProbabilities, NULL);

    /* free the hash tables */
    g_hash_table_destroy(running_probabilities);
    g_hash_table_destroy(final_probabilities);

    PINFO("highest P('%s') = '%d'",
          account_i.account_name ? account_i.account_name : "(null)",
          account_i.probability);

    /* has this probability met our threshold? */
    if (account_i.probability >= threshold)
    {
        PINFO("found match");
        LEAVE(" ");
        return gnc_account_lookup_by_full_name(gnc_book_get_root_account(imap->book),
                                               account_i.account_name);
    }

    PINFO("no match");
    LEAVE(" ");

    return NULL; /* we didn't meet our threshold, return NULL for an account */
}
gboolean gnc_import_exists_online_id ( Transaction trans)

Checks whether the given transaction's online_id already exists in its parent account.

Checks whether the given transaction's online_id already exists in its parent account. The given transaction has to be open for editing. If a matching online_id exists, the transaction is destroyed (!) and TRUE is returned, otherwise FALSE is returned.

Parameters:
transThe transaction for which to check for an existing online_id.

Definition at line 1118 of file import-backend.c.

{
    int i;
    gboolean online_id_exists = FALSE;
    Account *dest_acct;
    Split *source_split;

    /* Look for an online_id in the first split */
    source_split = xaccTransGetSplit(trans, 0);
    g_assert(source_split);

    /* DEBUG("%s%d%s","Checking split ",i," for duplicates"); */
    dest_acct = xaccSplitGetAccount(source_split);
    online_id_exists = xaccAccountForEachTransaction(dest_acct,
                       check_trans_online_id,
                       source_split);

    /* If it does, abort the process for this transaction, since it is
       already in the system. */
    if (online_id_exists == TRUE)
    {
        DEBUG("%s", "Transaction with same online ID exists, destroying current transaction");
        xaccTransDestroy(trans);
        xaccTransCommitEdit(trans);
    }
    return online_id_exists;
}
void gnc_import_find_split_matches ( GNCImportTransInfo trans_info,
gint  process_threshold,
double  fuzzy_amount_difference,
gint  match_date_hardlimit 
)

/brief Iterate through all splits of the originating account of the given transaction, and find all matching splits there.

Iterate through all splits of the originating account of the given transaction, find all matching splits there, and store them in the GNCImportTransInfo structure.

Parameters:
trans_infoThe TransInfo for which the corresponding matching existing transactions should be found.
process_thresholdEach match whose heuristics are smaller than this value is totally ignored.
fuzzy_amount_differenceFor fuzzy amount matching, a certain fuzzyness in the matching amount is allowed up to this value. May be e.g. 3.00 dollars for ATM fees, or 0.0 if you only want to allow exact matches.
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.

Definition at line 800 of file import-backend.c.

{
    GList * list_element;
    Query *query = qof_query_create_for(GNC_ID_SPLIT);
    g_assert (trans_info);

    /* Get list of splits of the originating account. */
    {
        /* We used to traverse *all* splits of the account by using
           xaccAccountGetSplitList, which is a bad idea because 90% of these
           splits are outside the date range that is interesting. We should
           rather use a query according to the date region, which is
           implemented here.
        */
        Account *importaccount =
            xaccSplitGetAccount (gnc_import_TransInfo_get_fsplit (trans_info));
        time_t download_time = xaccTransGetDate (gnc_import_TransInfo_get_trans (trans_info));

        qof_query_set_book (query, gnc_get_current_book());
        xaccQueryAddSingleAccountMatch (query, importaccount,
                                        QOF_QUERY_AND);
        xaccQueryAddDateMatchTT (query,
                                 TRUE, download_time - match_date_hardlimit * 86400,
                                 TRUE, download_time + match_date_hardlimit * 86400,
                                 QOF_QUERY_AND);
        list_element = qof_query_run (query);
        /* Sigh. Doesnt help too much. We still create and run one query
           for each imported transaction. Maybe it would improve
           performance further if there is one single (master-)query at
           the beginning, matching the full date range and all accounts in
           question. However, this doesnt quite work because this function
           here is called from each gnc_gen_trans_list_add_trans(), which
           is called one at a time. Therefore the whole importer would
           have to change its behaviour: Accept the imported txns via
           gnc_gen_trans_list_add_trans(), and only when
           gnc_gen_trans_list_run() is called, then calculate all the
           different match candidates. That's too much work for now.
        */
    }

    /* Traverse that list, calling split_find_match on each one. Note
       that xaccAccountForEachSplit is declared in Account.h but
       implemented nowhere :-( */
    while (list_element != NULL)
    {
        split_find_match (trans_info, list_element->data,
                          process_threshold, fuzzy_amount_difference);
        list_element = g_list_next (list_element);
    }

    qof_query_destroy (query);
}
void gnc_import_match_picker_run_and_close ( GNCImportTransInfo transaction_info)

Run a match_picker dialog so that the selected-MatchInfo in the given trans_info is updated accordingly. This functions will only return after the user clicked Ok, Cancel, or Window-Close.

Run a match_picker dialog where the user should pick the best match for 'one' given transaction, so that the selected-MatchInfo in the given trans_info is updated accordingly. This functions will only return after the user clicked Ok, Cancel, or Window-Close.

The dialog uses the same functionality as the one created through gnc_import_add_trans(), except that its two listviews are shown above one another, and the listview of downloaded transactions shows only one transaction, namely, the given trans_info.

This function is used from the gnc-gen-transaction code.

Parameters:
transaction_infoThe TransInfo for which the user is supposed to pick a matching transaction.

Definition at line 443 of file import-match-picker.c.

{
    GNCImportMatchPicker *matcher;
    gint response;
    GNCImportMatchInfo *old;
    g_assert (transaction_info);

    /* Create a new match_picker, even though it's stored in a
       transmatcher struct :-) */
    matcher = g_new0(GNCImportMatchPicker, 1);
    /* DEBUG("Init match_picker"); */
    init_match_picker_gui(matcher);

    /* Append this single transaction to the view and select it */
    downloaded_transaction_append(matcher, transaction_info);

    old = gnc_import_TransInfo_get_selected_match(transaction_info);

    /* Let this dialog run and close. */
    /*DEBUG("Right before run and close");*/
    gtk_window_set_modal(GTK_WINDOW(matcher->transaction_matcher), TRUE);
    response = gtk_dialog_run (GTK_DIALOG (matcher->transaction_matcher));
    gnc_save_window_size(GCONF_SECTION,
                         GTK_WINDOW (matcher->transaction_matcher));
    gtk_widget_destroy (matcher->transaction_matcher);
    /*DEBUG("Right after run and close");*/
    /* DEBUG("Response was %d.", response); */
    if (response == GTK_RESPONSE_OK && matcher->selected_match_info != old)
    {
        /* OK was pressed */
        gnc_import_TransInfo_set_selected_match (transaction_info,
                matcher->selected_match_info,
                TRUE);
    }
}
gint gnc_import_MatchInfo_get_probability ( const GNCImportMatchInfo info)

Get the probability (confidence level) of this MatchInfo.

Parameters:
infoCan be NULL, in which case the function returns 0

Definition at line 244 of file import-backend.c.

{
    if (info)
    {
        return info->probability;
    }
    else
    {
        return 0;
    }
}
Split * gnc_import_MatchInfo_get_split ( const GNCImportMatchInfo info)

Get the split ('this-side split') of this MatchInfo.

Definition at line 237 of file import-backend.c.

{
    g_assert (info);
    return info->split;
}
gboolean gnc_import_process_trans_item ( GncImportMatchMap matchmap,
GNCImportTransInfo trans_info 
)

/brief -- Processes one match according to its selected action.

This function is intended to be called when the importer dialog is finished. It should be called once for each imported transaction and processes each ImportTransInfo according to its selected action: For GNCImport_ADD, the transaction is added etc. etc.

Each succesful match is also stored in the given ImportMatchMap, or, if that argument is NULL, in the ImportMatchMap of each originating account.

Parameters:
matchmapThe ImportMatchMap where each match should be stored. May be NULL, in which case the ImportMatchMap of each account will be used.
trans_infoThe ImportTransInfo item to process.
Returns:
TRUE if the item has been processed.

Definition at line 863 of file import-backend.c.

{
    Split * other_split;
    gnc_numeric imbalance_value;

    /* DEBUG("Begin"); */

    g_assert (trans_info);
    /*DEBUG("Iteration %d, action %d, split %s", i,
        trans_info->action,
        xaccTransGetDescription (gnc_import_TransInfo_get_trans
        (trans_info)))*/
    switch (gnc_import_TransInfo_get_action (trans_info))
    {
    case GNCImport_SKIP:
        return FALSE;
    case GNCImport_ADD:
        /* Transaction gets imported. */

        /* Is the transaction not balanced and there is a non-NULL destination account? */
        if (gnc_import_TransInfo_is_balanced(trans_info) == FALSE
                && gnc_import_TransInfo_get_destacc(trans_info) != NULL)
        {
            /* Create the 'other' split. */
            Split *split =
                xaccMallocSplit
                (gnc_account_get_book
                 (gnc_import_TransInfo_get_destacc (trans_info)));
            xaccTransAppendSplit
            (gnc_import_TransInfo_get_trans (trans_info), split);
            xaccAccountInsertSplit
            (gnc_import_TransInfo_get_destacc (trans_info), split);
            /*xaccSplitSetBaseValue
              (split,
               gnc_numeric_neg(xaccTransGetImbalance
                       (gnc_import_TransInfo_get_trans (trans_info))),
               xaccTransGetCurrency
               (gnc_import_TransInfo_get_trans (trans_info)));*/
            {
                /* This is a quick workaround for the bug described in
                                 http://gnucash.org/pipermail/gnucash-devel/2003-August/009982.html
                       Assume that importers won't create transactions involving two or more
                       currencies so we can use xaccTransGetImbalanceValue. */
                imbalance_value =
                    gnc_numeric_neg (xaccTransGetImbalanceValue
                                     (gnc_import_TransInfo_get_trans (trans_info)));
                xaccSplitSetValue (split, imbalance_value);
                xaccSplitSetAmount (split, imbalance_value);
            }
            /*xaccSplitSetMemo (split, _("Auto-Balance split"));
              -- disabled due to popular request */
        }

        xaccSplitSetReconcile(gnc_import_TransInfo_get_fsplit (trans_info), CREC);
        /*Set reconcile date to today*/
        xaccSplitSetDateReconciledSecs(gnc_import_TransInfo_get_fsplit (trans_info),
                                       time(NULL));
        /* Done editing. */
        xaccTransCommitEdit(gnc_import_TransInfo_get_trans (trans_info));
        return TRUE;
    case GNCImport_UPDATE:
    {
        GNCImportMatchInfo *selected_match =
            gnc_import_TransInfo_get_selected_match(trans_info);

        /* If there is no selection, ignore this transaction. */
        if (!selected_match)
        {
            PWARN("No matching translaction to be cleared was chosen. Imported transaction will be ignored.");
            break;
        }

        /* Transaction gets not imported but the matching one gets
           updated and reconciled. */
        if (gnc_import_MatchInfo_get_split(selected_match) == NULL)
        {
            PERR("The split I am trying to update and reconcile is NULL, shouldn't happen!");
        }
        else
        {
            /* Update and reconcile the matching transaction */
            /*DEBUG("BeginEdit selected_match")*/
            xaccTransBeginEdit(selected_match->trans);

            xaccTransSetDatePostedSecs(selected_match->trans,
                                       xaccTransGetDate(xaccSplitGetParent(
                                                   gnc_import_TransInfo_get_fsplit(trans_info))));

            xaccSplitSetAmount(selected_match->split,
                               xaccSplitGetAmount(
                                   gnc_import_TransInfo_get_fsplit(trans_info)));
            xaccSplitSetValue(selected_match->split,
                              xaccSplitGetValue(
                                  gnc_import_TransInfo_get_fsplit(trans_info)));

            imbalance_value = xaccTransGetImbalanceValue(
                                  gnc_import_TransInfo_get_trans(trans_info));
            other_split = xaccSplitGetOtherSplit(selected_match->split);
            if (!gnc_numeric_zero_p(imbalance_value) && other_split)
            {
                if (xaccSplitGetReconcile(other_split) == NREC)
                {
                    imbalance_value = gnc_numeric_neg(imbalance_value);
                    xaccSplitSetValue(other_split, imbalance_value);
                    xaccSplitSetAmount(other_split, imbalance_value);
                }
                /* else GC will automatically insert a split to equity
                   to balance the transaction */
            }

            xaccTransSetDescription(selected_match->trans,
                                    xaccTransGetDescription(
                                        gnc_import_TransInfo_get_trans(trans_info)));

            if (xaccSplitGetReconcile(selected_match->split) == NREC)
            {
                xaccSplitSetReconcile(selected_match->split, CREC);
            }

            /* Set reconcile date to today */
            xaccSplitSetDateReconciledSecs(selected_match->split, time(NULL));

            /* Copy the online id to the reconciled transaction, so
               the match will be remembered */
            if (gnc_import_split_has_online_id(trans_info->first_split))
            {
                gnc_import_set_split_online_id(selected_match->split,
                                               gnc_import_get_split_online_id(trans_info->first_split));
            }

            /* Done editing. */
            /*DEBUG("CommitEdit selected_match")*/
            xaccTransCommitEdit(selected_match->trans);

            /* Store the mapping to the other account in the MatchMap. */
            matchmap_store_destination(matchmap, trans_info, TRUE);

            /* Erase the downloaded transaction */
            xaccTransDestroy(trans_info->trans);
            /*DEBUG("CommitEdit trans")*/
            xaccTransCommitEdit(trans_info->trans);
            /* Very important: Make sure the freed transaction is not freed again! */
            trans_info->trans = NULL;
        }
    }
    return TRUE;
    case GNCImport_CLEAR:
    {
        GNCImportMatchInfo *selected_match =
            gnc_import_TransInfo_get_selected_match (trans_info);

        /* If there is no selection, ignore this transaction. */
        if (!selected_match)
        {
            PWARN("No matching translaction to be cleared was chosen. Imported transaction will be ignored.");
            break;
        }

        /* Transaction gets not imported but the matching one gets
           reconciled. */
        if (gnc_import_MatchInfo_get_split (selected_match) == NULL)
        {
            PERR("The split I am trying to reconcile is NULL, shouldn't happen!");
        }
        else
        {
            /* Reconcile the matching transaction */
            /*DEBUG("BeginEdit selected_match")*/
            xaccTransBeginEdit(selected_match->trans);

            if (xaccSplitGetReconcile
                    (selected_match->split) == NREC)
                xaccSplitSetReconcile
                (selected_match->split, CREC);
            /* Set reconcile date to today */
            xaccSplitSetDateReconciledSecs
            (selected_match->split, time(NULL));

            /* Copy the online id to the reconciled transaction, so
                         the match will be remembered */
            if (gnc_import_split_has_online_id(trans_info->first_split))
                gnc_import_set_split_online_id
                (selected_match->split,
                 gnc_import_get_split_online_id(trans_info->first_split));

            /* Done editing. */
            /*DEBUG("CommitEdit selected_match")*/
            xaccTransCommitEdit
            (selected_match->trans);

            /* Store the mapping to the other account in the MatchMap. */
            matchmap_store_destination (matchmap, trans_info, TRUE);

            /* Erase the downloaded transaction */
            xaccTransDestroy(trans_info->trans);
            /*DEBUG("CommitEdit trans")*/
            xaccTransCommitEdit(trans_info->trans);
            /* Very important: Make sure the freed transaction is not freed again! */
            trans_info->trans = NULL;
        }
    }
    return TRUE;
    default:
        DEBUG("Invalid GNCImportAction for this imported transaction.");
    }
    /*DEBUG("End");*/
    return FALSE;
}
Account * gnc_import_select_account ( GtkWidget *  parent,
const gchar *  account_online_id_value,
gboolean  auto_create,
const gchar *  account_human_description,
const gnc_commodity new_account_default_commodity,
GNCAccountType  new_account_default_type,
Account default_selection,
gboolean *  ok_pressed 
)

Must be called with a string containing a unique identifier for the account. If an account with a matching online_id kvp_frame is found, the function immediately returns with a pointer to that account. Otherwise, the user is prompted to select a GnuCash account or create a new one (in both cases, the unique identifier is written to the account's kvp_frame, so the user won't be prompted again). If the user refuses to select or create an account, NULL is returned.

Parameters:
parentThe parent widget. Can be NULL.
account_online_id_valueThe string containing your unique account_id coming from some string of your module. This is the normal mode of operation. Can be NULL.

If account_online_id_value==NULL, you basically end up with an account selector that allows you to select an account whose GncGUID will be remembered elsewhere. You would fill account_human_description to tell the user what he is looking for. In this mode, the online_id kvp_frame of the found account will not be touched. To use this mode, auto_create must NOT be set to 0.

Parameters:
account_human_descriptionA human-readable description of the account. Can be NULL. If it is not NULL, it will be shown before the id in the account matching dialog. It will also be used as the default account name if a new account is created.
new_account_default_commodityDefault commodity of the new account. Can be NULL. If not NULL, it will be the account's commodity if a new account is created. Also, if not NULL, the function will also warn the user if the found or created account's commodity doesn't match.
new_account_default_typeDefault account type of a new account. Can be NULL. If not ACCT_TYPE_NONE, it will be the account's type if a new account is created. If not ACCT_TYPE_NONE, the function will also warn the user if the found or created account's commodity doesn't match.
auto_createOnly active if no account with the account_online_id_value could be found in gnucash, or if online-id was NULL. In that case, if auto_create is TRUE (nonzero), the user will be asked to create a new account. If auto_create is FALSE (zero), this function will simply return NULL but will neither select nor create any account.
default_selectionIf not NULL, that account will be pre-selected by default.
ok_pressedA pointer to gboolean. If non-NULL, whether or not the picker dialog was closed by the user pressing ok will be stored in the parameter. If no dialog was created by the gnc_import_select_account() call, TRUE is always returned.
Returns:
A pointer to the found or created Account, or NULL if no account was found or created.

Definition at line 144 of file import-account-matcher.c.

{
#define ACCOUNT_DESCRIPTION_MAX_SIZE 255
    struct _accountpickerdialog * picker;
    gint response;
    Account * retval = NULL;
    const gchar *retval_name = NULL;
    GtkBuilder *builder;
    GtkWidget * online_id_label, *button;
    gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE] = "";
    gboolean ok_pressed_retval = FALSE;

    ENTER("Default commodity received: %s", gnc_commodity_get_fullname( new_account_default_commodity));
    DEBUG("Default account type received: %s", xaccAccountGetTypeStr( new_account_default_type));
    picker = g_new0(struct _accountpickerdialog, 1);

    picker->account_online_id_value = account_online_id_value;
    picker->account_human_description =  account_human_description;
    picker->new_account_default_commodity = new_account_default_commodity;
    picker->new_account_default_type = new_account_default_type;

    /*DEBUG("Looking for account with online_id: %s", account_online_id_value);*/
    if (account_online_id_value != NULL)
    {
        retval =
            gnc_account_foreach_descendant_until(gnc_get_current_root_account (),
                    test_acct_online_id_match,
                    /* This argument will only be
                                                          used as a "const char*" */
                    (void*)account_online_id_value);
    }
    if (retval == NULL && auto_create != 0)
    {
        /* load the interface */
        builder = gtk_builder_new();
        gnc_builder_add_from_file (builder,"dialog-import.glade", "Generic Import Account Picker");
        /* connect the signals in the interface */
        if (builder == NULL)
        {
            PERR("Error opening the glade builder interface");
        }

        picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Generic Import Account Picker"));
        if (parent)
            gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
                                          GTK_WINDOW (parent));
        picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder, "account_tree_sw"));
        online_id_label = GTK_WIDGET(gtk_builder_get_object (builder, "online_id_label"));
        button = GTK_WIDGET(gtk_builder_get_object (builder, "newbutton"));
        gtk_button_set_use_stock (GTK_BUTTON(button), TRUE);

        //printf("gnc_import_select_account(): Fin get widget\n");

        if (account_human_description != NULL)
        {
            strncat(account_description_text, account_human_description,
                    ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
            strncat(account_description_text, "\n",
                    ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
        }
        if (account_online_id_value != NULL)
        {
            strncat(account_description_text, _("(Full account ID: "),
                    ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
            strncat(account_description_text, account_online_id_value,
                    ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
            strncat(account_description_text, ")",
                    ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
        }
        gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
        build_acct_tree(picker);
        gnc_tree_view_account_set_selected_account(picker->account_tree, default_selection);

        gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
        g_signal_connect(picker->account_tree, "row-activated",
                         G_CALLBACK(account_tree_row_activated_cb), picker);
        do
        {
            response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
            switch (response)
            {
            case GTK_RESPONSE_OK:
                retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
                if (retval)
                    retval_name = xaccAccountGetName(retval);
                if (!retval_name)
                    retval_name = "(null)";
                DEBUG("Selected account %p, %s", retval, retval_name);

                /* See if the selected account is a placeholder. */
                if (retval && xaccAccountGetPlaceholder (retval))
                {
                    gnc_error_dialog
                    (picker->dialog,
                     _("The account %s is a placeholder account and does not allow "
                       "transactions. Please choose a different account."),
                     retval_name);
                    response = GNC_RESPONSE_NEW;
                    break;
                }

                if ( account_online_id_value != NULL)
                {
                    gnc_import_set_acc_online_id(retval, account_online_id_value);
                }
                ok_pressed_retval = TRUE;
                break;
            case GNC_RESPONSE_NEW:
                gnc_import_add_account(picker);
                ok_pressed_retval = TRUE;
                break;
            default:
                ok_pressed_retval = FALSE;
                break;
            }
        }
        while (response == GNC_RESPONSE_NEW);

        g_object_unref(G_OBJECT(builder));
        gtk_widget_destroy(picker->dialog);
    }
    else
    {
        retval_name = retval ? xaccAccountGetName(retval) : NULL;
        ok_pressed_retval = TRUE; /* There was no dialog involved, so the computer "pressed" ok */
    }
    /*FIXME: DEBUG("WRITEME: gnc_import_select_account() Here we should check if account type is compatible, currency matches, etc.\n"); */
    g_free(picker);
    /*DEBUG("Return value: %p%s%s%s",retval,", account name:",xaccAccountGetName(retval),"\n");*/
    if (ok_pressed != NULL)
    {
        *ok_pressed = ok_pressed_retval;
    }
    LEAVE("Selected account %p, %s", retval, retval_name ? retval_name : "(null)");
    return retval;
}
gnc_commodity * gnc_import_select_commodity ( const char *  cusip,
gboolean  ask_on_unknown,
const char *  default_fullname,
const char *  default_mnemonic 
)

Must be called with a string containing a unique identifier for the commodity. If an commodity with a matching cusip is found, the function immediately returns with a pointer to that commodity. Otherwise, the user may be prompted to select a GnuCash commodity or create a new one (in both cases, the cusip is written to the commodity's cusip field, overwriting anything that was there before.

Parameters:
cusipThe string containing the code for which you want a matching commodity. A CUISP code or similar UNIQUE code. The stock ticker is NOT appropriate, unless you have no other option. Must be non-NULL.
ask_on_unknownIf the cusip value is unknown and this parameter is false (zero), the function returns NULL. Otherwise the user will be asked to select an existing or create a new commodity.
default_fullnameA human-readable description of the commodity, such as the stock name. Can be NULL. If it is not NULL, it will be shown to the user when selecting a commodity. It will also be used as the default if a new commodity is created.
default_mnemonicUsually the stock ticker or similar. Can be NULL. If it is not NULL, it will be shown to the user when selecting a commodity. It will also be used as the default if a new commodity is created.
Returns:
A pointer to the found or created commodity, or NULL if no commodity was found or created.

Definition at line 53 of file import-commodity-matcher.c.

{
    const gnc_commodity_table * commodity_table = gnc_get_current_commodities ();
    gnc_commodity * retval = NULL;
    gnc_commodity * tmp_commodity = NULL;
    char * tmp_namespace = NULL;
    GList * commodity_list = NULL;
    GList * namespace_list = NULL;
    DEBUG("Default fullname received: %s",
          default_fullname ? default_fullname : "(null)");
    DEBUG("Default mnemonic received: %s",
          default_mnemonic ? default_mnemonic : "(null)");

    g_return_val_if_fail(cusip, NULL);
    DEBUG("Looking for commodity with exchange_code: %s", cusip);

    g_assert(commodity_table);
    namespace_list = gnc_commodity_table_get_namespaces(commodity_table);


    namespace_list = g_list_first(namespace_list);
    while ( namespace_list != NULL && retval == NULL)
    {
        tmp_namespace = namespace_list->data;
        DEBUG("Looking at namespace %s", tmp_namespace);


        /*Nested loop*/
        commodity_list = gnc_commodity_table_get_commodities(commodity_table,
                         tmp_namespace);
        commodity_list  = g_list_first(commodity_list);
        while ( commodity_list != NULL && retval == NULL)
        {
            tmp_commodity = commodity_list->data;
            DEBUG("Looking at commodity %s", gnc_commodity_get_fullname(tmp_commodity));

            if (gnc_commodity_get_cusip(tmp_commodity) != NULL &&
                    cusip != NULL &&
                    strncmp(gnc_commodity_get_cusip(tmp_commodity), cusip, strlen(cusip)) == 0)
            {
                retval = tmp_commodity;
                DEBUG("Commodity %s%s", gnc_commodity_get_fullname(retval), " matches.");
            }
            commodity_list = g_list_next(commodity_list);
        }
        /*End nested loop*/

        namespace_list = g_list_next(namespace_list);
    }




    g_list_free(commodity_list);
    g_list_free(namespace_list);

    if (retval == NULL && ask_on_unknown != 0)
    {
        const gchar *message =
            _("Please select a commodity to match the following exchange "
              "specific code. Please note that the exchange code of the "
              "commodity you select will be overwritten.");
        retval = gnc_ui_select_commodity_modal_full(NULL,
                 NULL,
                 DIAG_COMM_ALL,
                 message,
                 cusip,
                 default_fullname,
                 default_mnemonic);

    }
    /* There seems to be a problem here - if the matched commodity does not
       have a cusip defined (gnc_commodity_get_cusip returns NULL) then
       it does not get overwritten - which is not consistent with the
       message - so Im adding it to do this.  Looks like this is all
       that was needed to fix the cash value used as stock units problem
       for pre-defined commodities which didnt have the cusip defined! */
    if (retval != NULL &&
            gnc_commodity_get_cusip(retval) != NULL &&
            cusip != NULL &&
            (strncmp(gnc_commodity_get_cusip(retval), cusip, strlen(cusip)) != 0))
    {
        gnc_commodity_set_cusip(retval, cusip);
    }
    else if (gnc_commodity_get_cusip(retval) == NULL && cusip != NULL)
    {
        gnc_commodity_set_cusip(retval, cusip);
    }
    return retval;
};
void gnc_import_Settings_delete ( GNCImportSettings settings)

Destructor

Definition at line 106 of file import-settings.c.

{
    if (settings)
    {
        g_free(settings);
    }
}
gboolean gnc_import_Settings_get_action_add_enabled ( GNCImportSettings settings)

Return the selected action is enable state.

Definition at line 127 of file import-settings.c.

{
    g_assert (settings);
    return settings->action_add_enabled;
};
gboolean gnc_import_Settings_get_action_clear_enabled ( GNCImportSettings settings)

Return the selected action is enable state.

Definition at line 139 of file import-settings.c.

{
    g_assert (settings);
    return settings->action_clear_enabled;
};
gboolean gnc_import_Settings_get_action_skip_enabled ( GNCImportSettings settings)

Return the selected action is enable state.

Definition at line 121 of file import-settings.c.

{
    g_assert (settings);
    return settings->action_skip_enabled;
};
gboolean gnc_import_Settings_get_action_update_enabled ( GNCImportSettings settings)

Return the selected action is enable state.

Definition at line 133 of file import-settings.c.

{
    g_assert (settings);
    return settings->action_update_enabled;
};
gint gnc_import_Settings_get_add_threshold ( GNCImportSettings settings)

Return the selected threshold.

Definition at line 151 of file import-settings.c.

{
    g_assert (settings);
    return settings->add_threshold;
};
gint gnc_import_Settings_get_clear_threshold ( GNCImportSettings settings)

Return the selected threshold.

Definition at line 145 of file import-settings.c.

{
    g_assert (settings);
    return settings->clear_threshold;
};
gint gnc_import_Settings_get_display_threshold ( GNCImportSettings settings)

Return the selected threshold.

Definition at line 157 of file import-settings.c.

{
    g_assert (settings);
    return settings->display_threshold;
};
double gnc_import_Settings_get_fuzzy_amount ( GNCImportSettings settings)

Return the allowed amount range for fuzzy amount matching.

Returns:
The allowed amount range for fuzzy amount matching, in the users default commodity.

Definition at line 115 of file import-settings.c.

{
    g_assert (settings);
    return settings->fuzzy_amount;
};
gint gnc_import_Settings_get_match_date_hardlimit ( const GNCImportSettings settings)

Returns the hard-limiting number of days that a matching split may differ.

Definition at line 168 of file import-settings.c.

{
    g_assert(s);
    return s->match_date_hardlimit;
}
GNCImportSettings * gnc_import_Settings_new ( void  )

Allocates a new GNCImportSettings object, and initialize it with the appropriate user prefs.

Definition at line 78 of file import-settings.c.

{
    GNCImportSettings * settings;

    settings = g_new0 ( GNCImportSettings, 1);


    settings->action_skip_enabled =
        gnc_gconf_get_bool(GCONF_IMPORT_SECTION, "enable_skip", NULL);
    settings->action_update_enabled =
        gnc_gconf_get_bool(GCONF_IMPORT_SECTION, "enable_update", NULL);
    settings->action_add_enabled = DEFAULT_ACTION_ADD_ENABLED;
    settings->action_clear_enabled = DEFAULT_ACTION_CLEAR_ENABLED;
    settings->clear_threshold =
        (int)gnc_gconf_get_float(GCONF_IMPORT_SECTION, "auto_clear_threshold", NULL);
    settings->add_threshold =
        (int)gnc_gconf_get_float(GCONF_IMPORT_SECTION, "auto_add_threshold", NULL);
    settings->display_threshold =
        (int)gnc_gconf_get_float(GCONF_IMPORT_SECTION, "match_threshold", NULL);

    settings->fuzzy_amount =
        gnc_gconf_get_float(GCONF_IMPORT_SECTION, "atm_fee_threshold", NULL);

    settings->match_date_hardlimit = 42; /* 6 weeks */
    return settings;
}
void gnc_import_Settings_set_match_date_hardlimit ( GNCImportSettings settings,
gint  match_date_hardlimit 
)
Parameters:
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.

Definition at line 163 of file import-settings.c.

{
    g_assert(s);
    s->match_date_hardlimit = m;
}
void gnc_import_TransInfo_delete ( GNCImportTransInfo info)

Destructor

Definition at line 256 of file import-backend.c.

{
    if (info)
    {
        g_list_free (info->match_list);
        /*If the transaction exists and is still open, it must be destroyed*/
        if (info->trans && xaccTransIsOpen(info->trans))
        {
            xaccTransDestroy(info->trans);
            xaccTransCommitEdit(info->trans);
        }
        if (info->match_tokens)
        {
            GList *node;

            for (node = info->match_tokens; node; node = node->next)
                g_free (node->data);

            g_list_free (info->match_tokens);
        }
        g_free(info);
    }
}
GNCImportAction gnc_import_TransInfo_get_action ( const GNCImportTransInfo info)

Returns the currently selected action for this TransInfo.

Definition at line 174 of file import-backend.c.

{
    g_assert (info);
    return info->action;
}
Account * gnc_import_TransInfo_get_destacc ( const GNCImportTransInfo info)

Returns the 'other account' of this transaction. May return NULL.

Definition at line 193 of file import-backend.c.

{
    g_assert (info);
    return info->dest_acc;
}
gboolean gnc_import_TransInfo_get_destacc_selected_manually ( const GNCImportTransInfo info)

Returns if the currently selected destination account for auto-matching was selected by the user.

Definition at line 214 of file import-backend.c.

{
    g_assert (info);
    return info->dest_acc_selected_manually;
}
Split * gnc_import_TransInfo_get_fsplit ( const GNCImportTransInfo info)

Returns the first split of the transaction of this TransInfo.

Definition at line 143 of file import-backend.c.

{
    g_assert (info);
    return info->first_split;
}
GList * gnc_import_TransInfo_get_match_list ( const GNCImportTransInfo info)

Returns the stored list of possible matches.

Definition at line 112 of file import-backend.c.

{
    g_assert (info);
    return info->match_list;
}
gboolean gnc_import_TransInfo_get_match_selected_manually ( const GNCImportTransInfo info)

Returns if the currently selected match was selected by the user.

Definition at line 167 of file import-backend.c.

{
    g_assert (info);
    return info->match_selected_manually;
}
guint32 gnc_import_TransInfo_get_ref_id ( const GNCImportTransInfo info)

Returns the reference id for this TransInfo.

Definition at line 221 of file import-backend.c.

{
    g_assert (info);
    return info->ref_id;
}
GNCImportMatchInfo * gnc_import_TransInfo_get_selected_match ( const GNCImportTransInfo info)

Returns the currently selected match in this TransInfo.

Definition at line 150 of file import-backend.c.

{
    g_assert (info);
    return info->selected_match_info;
}
Transaction * gnc_import_TransInfo_get_trans ( const GNCImportTransInfo info)

Returns the transaction of this TransInfo.

Definition at line 119 of file import-backend.c.

{
    g_assert (info);
    return info->trans;
}
void gnc_import_TransInfo_init_matches ( GNCImportTransInfo trans_info,
GNCImportSettings settings 
)

Iterates through all splits of the originating account of trans_info. Sorts the resulting list and sets the selected_match and action fields in the trans_info.

Iterates through all splits of the originating account of trans_info. Sorts the resulting list and sets the selected_match and action fields in the trans_info.

Parameters:
trans_infoThe TransInfo for which the matches should be found, sorted, and selected.
settingsThe structure that holds all the user preferences.

Definition at line 1188 of file import-backend.c.

{
    GNCImportMatchInfo * best_match = NULL;
    g_assert (trans_info);


    /* Find all split matches in originating account. */
    gnc_import_find_split_matches(trans_info,
                                  gnc_import_Settings_get_display_threshold (settings),
                                  gnc_import_Settings_get_fuzzy_amount (settings),
                                  gnc_import_Settings_get_match_date_hardlimit (settings));

    if (trans_info->match_list != NULL)
    {
        trans_info->match_list = g_list_sort(trans_info->match_list,
                                             compare_probability);
        best_match = g_list_nth_data(trans_info->match_list, 0);
        gnc_import_TransInfo_set_selected_match (trans_info,
                best_match,
                FALSE);
        if (best_match != NULL &&
                best_match->probability >= gnc_import_Settings_get_clear_threshold(settings))
        {
            trans_info->action = GNCImport_CLEAR;
            trans_info->selected_match_info = best_match;
        }
        else if (best_match == NULL ||
                 best_match->probability <= gnc_import_Settings_get_add_threshold(settings))
        {
            trans_info->action = GNCImport_ADD;
        }
        else if (gnc_import_Settings_get_action_skip_enabled(settings))
        {
            trans_info->action = GNCImport_SKIP;
        }
        else if (gnc_import_Settings_get_action_update_enabled(settings))
        {
            trans_info->action = GNCImport_UPDATE;
        }
        else
        {
            trans_info->action = GNCImport_ADD;
        }
    }
    else
    {
        trans_info->action = GNCImport_ADD;
    }
    if (best_match &&
            trans_info->action == GNCImport_CLEAR &&
            gnc_import_Settings_get_action_update_enabled(settings))
    {
        if (best_match->update_proposed)
        {
            trans_info->action = GNCImport_UPDATE;
        }
    }

    trans_info->previous_action = trans_info->action;
}
gboolean gnc_import_TransInfo_is_balanced ( const GNCImportTransInfo info)

Returns if the transaction stored in the TransInfo is currently balanced.

Definition at line 126 of file import-backend.c.

{
    g_assert (info);
    /* Assume that the importer won't create a transaction that involves two or more
       currencies and no non-currency commodity.  In that case can use the simpler
       value imbalance check. */
    if (gnc_numeric_zero_p(xaccTransGetImbalanceValue(gnc_import_TransInfo_get_trans(info))))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
GNCImportTransInfo * gnc_import_TransInfo_new ( Transaction trans,
GncImportMatchMap matchmap 
)

Create a new object of GNCImportTransInfo here.

Allocates a new TransInfo object, with the Transaction 'trans' already stored in there. Also, this already checks the ImportMatchMap for automated destination account matching. The given MatchMap may be NULL, in which case the ImportMatchMap of the originating account will be used.

Parameters:
transThe transaction that this TransInfo should work with.
matchmapMatchMap used for automated destination account choosing. This may be NULL, in which case the MatchMap of the originating account will be used.

Definition at line 1152 of file import-backend.c.

{
    GNCImportTransInfo *transaction_info;
    Split *split;
    g_assert (trans);

    transaction_info = g_new0(GNCImportTransInfo, 1);

    transaction_info->trans = trans;
    /* Only use first split, the source split */
    split = xaccTransGetSplit(trans, 0);
    g_assert(split);
    transaction_info->first_split = split;

    /* Try to find a previously selected destination account
       string match for the ADD action */
    gnc_import_TransInfo_set_destacc (transaction_info,
                                      matchmap_find_destination (matchmap, transaction_info),
                                      FALSE);
    return transaction_info;
}
gboolean gnc_import_TransInfo_refresh_destacc ( GNCImportTransInfo transaction_info,
GncImportMatchMap matchmap 
)

Try to automatch a given transaction to a destination account

Definition at line 1254 of file import-backend.c.

{
    Account *orig_destacc;
    Account *new_destacc = NULL;
    g_assert(transaction_info);

    orig_destacc = gnc_import_TransInfo_get_destacc(transaction_info);

    /* if we haven't manually selected a destination account for this transaction */
    if (gnc_import_TransInfo_get_destacc_selected_manually(transaction_info) == FALSE)
    {
        /* Try to find the destination account for this transaction based on prior ones */
        new_destacc = matchmap_find_destination(matchmap, transaction_info);
        gnc_import_TransInfo_set_destacc(transaction_info, new_destacc, FALSE);
    }
    else
    {
        new_destacc = orig_destacc;
    }

    /* account has changed */
    if (new_destacc != orig_destacc)
    {
        return TRUE;
    }
    else   /* account is the same */
    {
        return FALSE;
    }
}
void gnc_import_TransInfo_set_action ( GNCImportTransInfo info,
GNCImportAction  action 
)

Set the action for this TransInfo. Also sets the previous action.

Definition at line 181 of file import-backend.c.

{
    g_assert (info);
    if (action != info->action)
    {
        info->previous_action = info->action;
        info->action = action;
    }
}
void gnc_import_TransInfo_set_destacc ( GNCImportTransInfo info,
Account acc,
gboolean  selected_manually 
)

Set the 'other account' of this transaction (used for auto-balance if needed). May be set to NULL.

Parameters:
selected_manuallyTRUE or FALSE; Was this account set as a result of a selection by the user or by an algorithm?

Definition at line 198 of file import-backend.c.

{
    g_assert (info);
    info->dest_acc = acc;
    info->dest_acc_selected_manually = selected_manually;

    /* Store the mapping to the other account in the MatchMap. */
    if (selected_manually)
    {
        matchmap_store_destination (NULL, info, FALSE);
    }
}
void gnc_import_TransInfo_set_ref_id ( GNCImportTransInfo info,
guint32  ref_id 
)

Set the reference id for this TransInfo.

Definition at line 228 of file import-backend.c.

{
    g_assert (info);
    info->ref_id = ref_id;
}
void gnc_import_TransInfo_set_selected_match ( GNCImportTransInfo info,
GNCImportMatchInfo match,
gboolean  selected_manually 
)

Sets the currently selected match in this TransInfo.

Parameters:
selected_manuallyTRUE or FALSE; Was this match set as a result of a selection by the user or by an algorithm?

Definition at line 157 of file import-backend.c.

{
    g_assert (info);
    info->selected_match_info = match;
    info->match_selected_manually = selected_manually;
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines