Esempio n. 1
0
/**************************************************
 * 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);

        if (account == NULL) // if account is NULL, store has not been updated
        {
            account = gnc_csv_account_map_search (map_string); //search the account list for the map_string

            if (account == NULL) // account still NULL, we have no map
            {
                g_free (map_string);
                valid = gtk_tree_model_iter_next (mappings_store, &iter);
                continue;
            }
        }
        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);
    }
}
void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
{
    try
    {
        // Drop any existing error for the prop_type we're about to set
        m_errors.erase(prop_type);

        Account *acct = nullptr;
        switch (prop_type)
        {
            case GncTransPropType::ACTION:
                m_action = boost::none;
                if (!value.empty())
                    m_action = value;
                break;

            case GncTransPropType::TACTION:
                m_taction = boost::none;
                if (!value.empty())
                    m_taction = value;
                break;

            case GncTransPropType::ACCOUNT:
                m_account = boost::none;
                if (value.empty())
                    throw std::invalid_argument (_("Account value can't be empty."));
                acct = gnc_csv_account_map_search (value.c_str());
                if (acct)
                    m_account = acct;
                else
                    throw std::invalid_argument (_(bad_acct));
                break;

            case GncTransPropType::TACCOUNT:
                m_taccount = boost::none;
                if (value.empty())
                    throw std::invalid_argument (_("Transfer account value can't be empty."));

                acct = gnc_csv_account_map_search (value.c_str());
                if (acct)
                    m_taccount = acct;
                else
                    throw std::invalid_argument (_(bad_tacct));
                break;

            case GncTransPropType::MEMO:
                m_memo = boost::none;
                if (!value.empty())
                    m_memo = value;
                break;

            case GncTransPropType::TMEMO:
                m_tmemo = boost::none;
                if (!value.empty())
                    m_tmemo = value;
                break;

            case GncTransPropType::DEPOSIT:
                m_deposit = boost::none;
                m_deposit = parse_amount (value, m_currency_format); // Will throw if parsing fails
                break;
            case GncTransPropType::WITHDRAWAL:
                m_withdrawal = boost::none;
                m_withdrawal = parse_amount (value, m_currency_format); // Will throw if parsing fails
                break;

            case GncTransPropType::PRICE:
                m_price = boost::none;
                m_price = parse_amount (value, m_currency_format); // Will throw if parsing fails
                break;

            case GncTransPropType::REC_STATE:
                m_rec_state = boost::none;
                m_rec_state = parse_reconciled (value); // Throws if parsing fails
                break;

            case GncTransPropType::TREC_STATE:
                m_trec_state = boost::none;
                m_trec_state = parse_reconciled (value); // Throws if parsing fails
                break;

            case GncTransPropType::REC_DATE:
                m_rec_date = boost::none;
                if (!value.empty())
                    m_rec_date = GncDate (value,
                                          GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails
                break;

            case GncTransPropType::TREC_DATE:
                m_trec_date = boost::none;
                if (!value.empty())
                    m_trec_date = GncDate (value,
                                           GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails
                break;

            default:
                /* Issue a warning for all other prop_types. */
                PWARN ("%d is an invalid property for a split", static_cast<int>(prop_type));
                break;
        }
    }
    catch (const std::invalid_argument& e)
    {
        auto err_str = std::string(_(gnc_csv_col_type_strs[prop_type])) +
                       std::string(_(" could not be understood.\n")) +
                       e.what();
        m_errors.emplace(prop_type, err_str);
        throw std::invalid_argument (err_str);
    }
    catch (const std::out_of_range& e)
    {
        auto err_str = std::string(_(gnc_csv_col_type_strs[prop_type])) +
                       std::string(_(" could not be understood.\n")) +
                       e.what();
        m_errors.emplace(prop_type, err_str);
        throw std::invalid_argument (err_str);
    }
}