GnuCash c935c2f+
Loading...
Searching...
No Matches
csv-tree-export.cpp
1/*******************************************************************\
2 * csv-tree-export.cpp -- Export Account Tree to a file *
3 * *
4 * Copyright (C) 2012 Robert Fewell *
5 * *
6 * This program is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU General Public License as *
8 * published by the Free Software Foundation; either version 2 of *
9 * the License, or (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License*
17 * along with this program; if not, contact: *
18 * *
19 * Free Software Foundation Voice: +1-617-542-5942 *
20 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21 * Boston, MA 02110-1301, USA gnu@gnu.org *
22\********************************************************************/
27#include <config.h>
28
29#include <cstdio>
30#include <fstream>
31#include <string>
32#include <vector>
33#include <algorithm>
34
35#include <gnc-filepath-utils.h>
36#include "gnc-commodity.h"
37#include "gnc-ui-util.h"
38#include "csv-tree-export.h"
39#include "csv-export-helpers.hpp"
40
41/* This static indicates the debugging module that this .o belongs to. */
42static QofLogModule log_module = GNC_MOD_ASSISTANT;
43
44/*******************************************************
45 * csv_tree_export
46 *
47 * write a list of accounts settings to a text file
48 *******************************************************/
49void
50csv_tree_export (CsvExportInfo *info)
51{
52 ENTER("");
53 DEBUG("File name is : %s", info->file_name);
54
55 /* Open File for writing */
56 auto ss{gnc_open_filestream(info->file_name)};
57
58 /* Header string */
59 StringVec headervec = {
60 _("Type"), _("Full Account Name"), _("Account Name"),
61 _("Account Code"), _("Description"), _("Account Color"),
62 _("Notes"), _("Symbol"), _("Namespace"),
63 _("Hidden"), _("Tax Info"), _("Placeholder")
64 };
65
66 /* Write header line */
67 info->failed = ss.fail() ||
68 !gnc_csv_add_line (ss, headervec, info->use_quotes, info->separator_str);
69
70 /* Get list of Accounts */
71 auto root{gnc_book_get_root_account (gnc_get_current_book())};
72 auto accts{gnc_account_get_descendants_sorted (root)};
73 auto str_or_empty = [](const char* a){ return a ? a : ""; };
74 auto bool_to_char = [](bool b){ return b ? "T" : "F"; };
75
76 /* Go through list of accounts */
77 for (GList *ptr = accts; !info->failed && ptr; ptr = g_list_next (ptr))
78 {
79 auto acc{static_cast<Account*>(ptr->data)};
80 DEBUG("Account being processed is : %s", xaccAccountGetName (acc));
81
82 StringVec line = {
84 account_get_fullname_str (acc),
86 str_or_empty (xaccAccountGetCode (acc)),
87 str_or_empty (xaccAccountGetDescription (acc)),
88 str_or_empty (xaccAccountGetColor (acc)),
89 str_or_empty (xaccAccountGetNotes (acc)),
92 bool_to_char (xaccAccountGetHidden (acc)),
93 bool_to_char (xaccAccountGetTaxRelated (acc)),
94 bool_to_char (xaccAccountGetPlaceholder (acc)),
95 };
96 info->failed = !gnc_csv_add_line (ss, line, info->use_quotes, info->separator_str);
97 }
98
99 g_list_free (accts);
100 LEAVE("");
101}
102
103
104
CSV Export Account Tree.
Commodity handling public routines.
File path resolution utility functions.
utility functions for the GnuCash UI
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3289
const char * xaccAccountGetDescription(const Account *acc)
Get the account's description.
Definition Account.cpp:3343
const char * xaccAccountGetColor(const Account *acc)
Get the account's color.
Definition Account.cpp:3350
GList * gnc_account_get_descendants_sorted(const Account *account)
This function returns a GList containing all the descendants of the specified account,...
Definition Account.cpp:3052
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
Definition Account.cpp:3267
const char * xaccAccountGetNotes(const Account *acc)
Get the account's notes.
Definition Account.cpp:3374
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Definition Account.cpp:3336
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Definition Account.cpp:3408
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gboolean xaccAccountGetHidden(const Account *acc)
Get the "hidden" flag for an account.
Definition Account.cpp:4190
gboolean xaccAccountGetPlaceholder(const Account *acc)
Get the "placeholder" flag for an account.
Definition Account.cpp:4119
const char * xaccAccountTypeEnumAsString(GNCAccountType type)
Conversion routines for the account types to/from strings that are used in persistent storage,...
Definition Account.cpp:4247
gboolean xaccAccountGetTaxRelated(const Account *acc)
DOCUMENT ME!
Definition Account.cpp:4035
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272
STRUCTS.