mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Eliminate gnc-csv-account-map.[ch]
The code is was only used by the csv import assistant and forced gtk as a dependency on gnc-imp-props-tx Part has been moved to Account, other bits have been moved to the importer code where they were used.
This commit is contained in:
parent
13ec4bb594
commit
d75ab275f1
@ -12,7 +12,6 @@ set(csv_import_SOURCES
|
||||
assistant-csv-trans-import.cpp
|
||||
gnc-plugin-csv-import.c
|
||||
csv-account-import.c
|
||||
gnc-csv-account-map.c
|
||||
gnc-csv-gnumeric-popup.c
|
||||
gnc-imp-props-price.cpp
|
||||
gnc-imp-props-tx.cpp
|
||||
@ -42,7 +41,6 @@ set(csv_import_noinst_HEADERS
|
||||
assistant-csv-trans-import.h
|
||||
gnc-plugin-csv-import.h
|
||||
csv-account-import.h
|
||||
gnc-csv-account-map.h
|
||||
gnc-csv-gnumeric-popup.h
|
||||
gnc-imp-props-price.hpp
|
||||
gnc-imp-props-tx.hpp
|
||||
|
@ -51,7 +51,6 @@
|
||||
#include "import-account-matcher.h"
|
||||
#include "import-main-matcher.h"
|
||||
#include "import-backend.h"
|
||||
#include "gnc-csv-account-map.h"
|
||||
#include "gnc-account-sel.h"
|
||||
|
||||
#include "gnc-csv-gnumeric-popup.h"
|
||||
@ -82,6 +81,11 @@ namespace bl = boost::locale;
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static QofLogModule log_module = GNC_MOD_ASSISTANT;
|
||||
|
||||
enum GncImportColumn {
|
||||
MAPPING_STRING,
|
||||
MAPPING_FULLPATH,
|
||||
MAPPING_ACCOUNT
|
||||
};
|
||||
|
||||
/* A note on memory management
|
||||
*
|
||||
@ -1772,6 +1776,39 @@ void CsvImpTransAssist::acct_match_set_accounts ()
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
csv_tximp_acct_match_load_mappings (GtkTreeModel *mappings_store)
|
||||
{
|
||||
// Set iter to first entry of store
|
||||
GtkTreeIter iter;
|
||||
auto valid = gtk_tree_model_get_iter_first (mappings_store, &iter);
|
||||
|
||||
// Walk through the store trying to match to a map
|
||||
while (valid)
|
||||
{
|
||||
// Walk through the list, reading each row
|
||||
Account *account = nullptr;
|
||||
gchar *map_string;
|
||||
gtk_tree_model_get (GTK_TREE_MODEL(mappings_store), &iter, MAPPING_STRING, &map_string, MAPPING_ACCOUNT, &account, -1);
|
||||
|
||||
// Look for an account matching the map_string
|
||||
// It may already be set in the tree model. If not we try to match the map_string with
|
||||
// - an entry in our saved account maps
|
||||
// - a full name of any of our existing accounts
|
||||
if (account ||
|
||||
(account = gnc_account_imap_find_any (gnc_get_current_book(), IMAP_CAT_CSV, map_string)) ||
|
||||
(account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), map_string)))
|
||||
{
|
||||
auto fullpath = gnc_account_get_full_name (account);
|
||||
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_FULLPATH, fullpath, -1);
|
||||
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_ACCOUNT, account, -1);
|
||||
g_free (fullpath);
|
||||
}
|
||||
|
||||
g_free (map_string);
|
||||
valid = gtk_tree_model_iter_next (mappings_store, &iter);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
csv_tximp_acct_match_check_all (GtkTreeModel *model)
|
||||
@ -1853,7 +1890,11 @@ CsvImpTransAssist::acct_match_select(GtkTreeModel *model, GtkTreeIter* iter)
|
||||
MAPPING_FULLPATH, fullpath, -1);
|
||||
|
||||
// Update the account kvp mappings
|
||||
gnc_csv_account_map_change_mappings (account, gnc_acc, text);
|
||||
if (text && *text)
|
||||
{
|
||||
gnc_account_imap_delete_account (account, IMAP_CAT_CSV, text);
|
||||
gnc_account_imap_add_account (gnc_acc, IMAP_CAT_CSV, text, gnc_acc);
|
||||
}
|
||||
|
||||
// Force reparsing of account columns - may impact multi-currency mode
|
||||
auto col_types = tx_imp->column_types();
|
||||
@ -2001,7 +2042,6 @@ CsvImpTransAssist::assist_preview_page_prepare ()
|
||||
g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CsvImpTransAssist::assist_account_match_page_prepare ()
|
||||
{
|
||||
@ -2011,7 +2051,7 @@ CsvImpTransAssist::assist_account_match_page_prepare ()
|
||||
|
||||
// Match the account strings to account maps from previous imports
|
||||
auto store = gtk_tree_view_get_model (GTK_TREE_VIEW(account_match_view));
|
||||
gnc_csv_account_map_load_mappings (store);
|
||||
csv_tximp_acct_match_load_mappings (store);
|
||||
|
||||
// Enable the view, possibly after an error
|
||||
gtk_widget_set_sensitive (account_match_view, true);
|
||||
|
@ -1,139 +0,0 @@
|
||||
/*******************************************************************\
|
||||
* gnc-csv-account-map.c -- Load and Update Mappings *
|
||||
* *
|
||||
* Copyright (C) 2015 Robert Fewell *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-csv-account-map.c
|
||||
@brief Save and Load Mappings
|
||||
@author Copyright (c) 2015 Robert Fewell
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-csv-account-map.h"
|
||||
|
||||
#define CSV_CATEGORY "csv-account-map"
|
||||
|
||||
#define IMPORT_STRING "String"
|
||||
#define IMPORT_FULL_PATH "FullPath"
|
||||
#define IMPORT_ACCOUNT "Account"
|
||||
|
||||
#define UNUSED_VAR __attribute__ ((unused))
|
||||
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static QofLogModule UNUSED_VAR log_module = G_LOG_DOMAIN;
|
||||
|
||||
/**************************************************
|
||||
* gnc_csv_account_map_search
|
||||
*
|
||||
* search the existing mappings for the account
|
||||
* linked to the import string.
|
||||
**************************************************/
|
||||
Account * gnc_csv_account_map_search (const gchar *map_string)
|
||||
{
|
||||
Account *root, *account = NULL;
|
||||
GList *accts, *ptr;
|
||||
|
||||
/* Get list of Accounts */
|
||||
root = gnc_book_get_root_account (gnc_get_current_book());
|
||||
accts = gnc_account_get_descendants_sorted (root);
|
||||
|
||||
/* Go through list of accounts */
|
||||
for (ptr = accts; ptr; ptr = g_list_next (ptr))
|
||||
{
|
||||
Account *tmp_acc = ptr->data;
|
||||
|
||||
if (gnc_account_imap_find_account (tmp_acc, CSV_CATEGORY, map_string))
|
||||
{
|
||||
account = tmp_acc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free (accts);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************
|
||||
* gnc_csv_account_map_load_mappings
|
||||
*
|
||||
* load the existing mappings
|
||||
**************************************************/
|
||||
void
|
||||
gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
|
||||
// Set iter to first entry of store
|
||||
valid = gtk_tree_model_get_iter_first (mappings_store, &iter);
|
||||
|
||||
// Walk through the store trying to match to a map
|
||||
while (valid)
|
||||
{
|
||||
Account *account = NULL;
|
||||
gchar *map_string;
|
||||
gchar *fullpath;
|
||||
|
||||
// Walk through the list, reading each row
|
||||
gtk_tree_model_get (GTK_TREE_MODEL(mappings_store), &iter, MAPPING_STRING, &map_string, MAPPING_ACCOUNT, &account, -1);
|
||||
|
||||
// Look for an account matching the map_string
|
||||
// It may already be set in the tree model. If not we try to match the map_string with
|
||||
// - an entry in our saved account maps
|
||||
// - a full name of any of our existing accounts
|
||||
if (account ||
|
||||
(account = gnc_csv_account_map_search (map_string)) ||
|
||||
(account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), map_string)))
|
||||
{
|
||||
fullpath = gnc_account_get_full_name (account);
|
||||
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_FULLPATH, fullpath, -1);
|
||||
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_ACCOUNT, account, -1);
|
||||
g_free (fullpath);
|
||||
}
|
||||
|
||||
g_free (map_string);
|
||||
valid = gtk_tree_model_iter_next (mappings_store, &iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************
|
||||
* gnc_csv_account_map_change_mappings
|
||||
*
|
||||
* change the existing mappings
|
||||
**************************************************/
|
||||
void
|
||||
gnc_csv_account_map_change_mappings (Account *old_account, Account *new_account, const gchar *map_string)
|
||||
{
|
||||
if (strlen (map_string) == 0)
|
||||
return;
|
||||
|
||||
if (old_account)
|
||||
gnc_account_imap_delete_account (old_account, CSV_CATEGORY, map_string);
|
||||
|
||||
if (new_account)
|
||||
gnc_account_imap_add_account (new_account, CSV_CATEGORY, map_string, new_account);
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*******************************************************************\
|
||||
* gnc-csv-account-map.h -- Load and Update Mappings *
|
||||
* *
|
||||
* Copyright (C) 2015 Robert Fewell *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-csv-account-map.h
|
||||
@brief Save and Load Mappings
|
||||
@author Copyright (c) 2015 Robert Fewell
|
||||
*/
|
||||
#ifndef GNC_CSV_ACCOUNT_MAP_H
|
||||
#define GNC_CSV_ACCOUNT_MAP_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "Account.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Enumeration for the mappings liststore */
|
||||
enum GncImportColumn {MAPPING_STRING, MAPPING_FULLPATH, MAPPING_ACCOUNT};
|
||||
|
||||
/** Load the import mappings.
|
||||
*
|
||||
* For each mapping string in the tree model, try to find a
|
||||
* corresponding account and account full path.
|
||||
*
|
||||
* - if the account was already set, just update the full path
|
||||
* - if the mapping string matches an account in the account maps,
|
||||
* use that account and its corresponding full name
|
||||
* - otherwise search for an existing account whose full name matches the
|
||||
* mapping string
|
||||
*
|
||||
*/
|
||||
void gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store);
|
||||
|
||||
/** Update the import mappings.
|
||||
*
|
||||
*/
|
||||
void gnc_csv_account_map_change_mappings (Account *old_account, Account *new_account, const gchar *map_string);
|
||||
|
||||
/** Returns a pointer to the account that matches the import string.
|
||||
*
|
||||
* @return A pointer to an account.
|
||||
*/
|
||||
Account * gnc_csv_account_map_search (const gchar *map_string);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -29,7 +29,6 @@
|
||||
#endif
|
||||
|
||||
#include "engine-helpers.h"
|
||||
#include "gnc-csv-account-map.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "Account.h"
|
||||
#include "Transaction.h"
|
||||
@ -446,7 +445,7 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
|
||||
m_account.reset();
|
||||
if (value.empty())
|
||||
throw std::invalid_argument (_("Account value can't be empty."));
|
||||
if ((acct = gnc_csv_account_map_search (value.c_str())) ||
|
||||
if ((acct = gnc_account_imap_find_any (gnc_get_current_book(), IMAP_CAT_CSV, value.c_str())) ||
|
||||
(acct = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), value.c_str())))
|
||||
m_account = acct;
|
||||
else
|
||||
@ -458,7 +457,7 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
|
||||
if (value.empty())
|
||||
throw std::invalid_argument (_("Transfer account value can't be empty."));
|
||||
|
||||
if ((acct = gnc_csv_account_map_search (value.c_str())) ||
|
||||
if ((acct = gnc_account_imap_find_any (gnc_get_current_book(), IMAP_CAT_CSV,value.c_str())) ||
|
||||
(acct = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), value.c_str())))
|
||||
m_taccount = acct;
|
||||
else
|
||||
|
@ -77,6 +77,8 @@ enum class GncTransPropType {
|
||||
SPLIT_PROPS = TREC_DATE
|
||||
};
|
||||
|
||||
#define IMAP_CAT_CSV "csv-account-map"
|
||||
|
||||
using StrVec = std::vector<std::string>;
|
||||
using ErrMap = std::map<GncTransPropType, std::string>;
|
||||
using ErrPair = std::pair<GncTransPropType, std::string>;
|
||||
|
@ -5646,6 +5646,31 @@ gnc_account_imap_find_account (Account *acc,
|
||||
return retval;
|
||||
}
|
||||
|
||||
Account*
|
||||
gnc_account_imap_find_any (QofBook *book, const char* category, const char *key)
|
||||
{
|
||||
Account *account = NULL;
|
||||
|
||||
/* Get list of Accounts */
|
||||
auto root = gnc_book_get_root_account (book);
|
||||
auto accts = gnc_account_get_descendants_sorted (root);
|
||||
|
||||
/* Go through list of accounts */
|
||||
for (auto ptr = accts; ptr; ptr = g_list_next (ptr))
|
||||
{
|
||||
auto tmp_acc = static_cast<Account*> (ptr->data);
|
||||
|
||||
if (gnc_account_imap_find_account (tmp_acc, category, key))
|
||||
{
|
||||
account = tmp_acc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free (accts);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
/* Store an Account in the map */
|
||||
void
|
||||
gnc_account_imap_add_account (Account *acc,
|
||||
|
@ -1575,6 +1575,11 @@ typedef enum
|
||||
Account* gnc_account_imap_find_account (Account* acc, const char* category,
|
||||
const char *key);
|
||||
|
||||
/* Look up an Account in the map non-Baysian, searching through the
|
||||
* import map data of all accounts. Returns first match.
|
||||
*/
|
||||
Account* gnc_account_imap_find_any (QofBook *book, const char* category, const char *key);
|
||||
|
||||
/* Store an Account in the map non Baysian
|
||||
*/
|
||||
void gnc_account_imap_add_account (Account* acc, const char *category,
|
||||
|
@ -333,7 +333,6 @@ gnucash/import-export/csv-imp/assistant-csv-account-import.c
|
||||
gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
|
||||
gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp
|
||||
gnucash/import-export/csv-imp/csv-account-import.c
|
||||
gnucash/import-export/csv-imp/gnc-csv-account-map.c
|
||||
gnucash/import-export/csv-imp/gnc-csv-gnumeric-popup.c
|
||||
gnucash/import-export/csv-imp/gnc-import-price.cpp
|
||||
gnucash/import-export/csv-imp/gnc-import-tx.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user