GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes
Gnucash::CoreApp Class Reference
Inheritance diagram for Gnucash::CoreApp:
Gnucash::Gnucash Gnucash::GnucashCli

Public Member Functions

 CoreApp (const char *app_name)
 
void parse_command_line (int argc, char **argv)
 
void start (void)
 

Protected Attributes

std::string m_app_name
 
std::string m_tagline
 
boost::optional< std::string > m_log_to_filename
 
boost::optional< std::string > m_file_to_load
 
bpo::options_description m_opt_desc_all
 
std::unique_ptr< bpo::options_description > m_opt_desc_display
 
bpo::variables_map m_opt_map
 
bpo::positional_options_description m_pos_opt_desc
 

Detailed Description

Definition at line 44 of file gnucash-core-app.hpp.

Constructor & Destructor Documentation

◆ CoreApp()

Gnucash::CoreApp::CoreApp ( const char *  app_name)

Definition at line 161 of file gnucash-core-app.cpp.

161 : m_app_name {app_name}
162{
163 #ifdef ENABLE_BINRELOC
164 {
165 GError *binreloc_error = NULL;
166 if (!gnc_gbr_init(&binreloc_error))
167 {
168 std::cerr << "main: Error on gnc_gbr_init: " << binreloc_error->message << "\n";
169 g_error_free(binreloc_error);
170 }
171 }
172 #endif
173
174 /* This should be called before gettext is initialized
175 * The user may have configured a different language via
176 * the environment file.
177 */
179 #if defined MAC_INTEGRATION || defined __MINGW32__
180 sys_locale = set_platform_locale();
181 #endif
182 #if ! defined MAC_INTEGRATION && ! defined __MINGW32__/* setlocale already done */
183 sys_locale = g_strdup (setlocale (LC_ALL, ""));
184 if (!sys_locale)
185 {
186 std::cerr << "The locale defined in the environment isn't supported. "
187 << "Falling back to the 'C' (US English) locale\n";
188 g_setenv ("LC_ALL", "C", TRUE);
189 setlocale (LC_ALL, "C");
190 }
191 #endif
192
193 auto localedir = gnc_path_get_localedir ();
194 bindtextdomain(PROJECT_NAME, localedir);
195 bindtextdomain("iso_4217", localedir); // For win32 to find currency name translations
196 bind_textdomain_codeset("iso_4217", "UTF-8");
197 textdomain(PROJECT_NAME);
198 bind_textdomain_codeset(PROJECT_NAME, "UTF-8");
199
200 gnc_init_boost_locale (localedir);
201 std::cerr.imbue (gnc_get_boost_locale());
202 std::cout.imbue (gnc_get_boost_locale());
203 g_free(localedir);
204
205 // Now that gettext is properly initialized, set our help tagline.
206 m_tagline = _("- GnuCash, accounting for personal and small business finance");
207 m_opt_desc_display = std::make_unique<bpo::options_description>
208 ((bl::format (std::string{_("{1} [options] [datafile]")}) % m_app_name).str() + std::string(" ") + m_tagline);
209 add_common_program_options();
210}
void gnc_environment_setup(void)
Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that fi...

Member Function Documentation

◆ parse_command_line()

void Gnucash::CoreApp::parse_command_line ( int  argc,
char **  argv 
)

Definition at line 218 of file gnucash-core-app.cpp.

219{
220 try
221 {
222 bpo::store (bpo::command_line_parser (argc, argv).
223 options (m_opt_desc_all).positional(m_pos_opt_desc).run(), m_opt_map);
224 bpo::notify (m_opt_map);
225 }
226 catch (std::exception &e)
227 {
228 std::cerr << e.what() << "\n\n";
229 std::cerr << *m_opt_desc_display.get() << std::endl;
230
231 exit(1);
232 }
233
234 if (m_show_paths)
235 {
236 std::cout << _("GnuCash Paths") << '\n';
237 for (const auto& ep : gnc_list_all_paths ())
238 {
239 std::cout << ep.env_name << ": " << ep.env_path;
240 if (ep.modifiable)
241 std::cout << ' ' << _("(user modifiable)");
242 std::cout << '\n';
243 }
244 exit (0);
245 }
246
247 if (m_show_version)
248 {
249 bl::format rel_fmt (std::string{_("GnuCash {1}")});
250 bl::format dev_fmt (std::string{_("GnuCash {1} development version")});
251
252 if (is_development_version)
253 std::cout << dev_fmt % gnc_version () << "\n";
254 else
255 std::cout << rel_fmt % gnc_version () << "\n";
256
257 std::cout << _("Build ID") << ": " << gnc_build_id () << "\n";
258 exit(0);
259 }
260
261 if (m_show_help)
262 {
263 std::cout << *m_opt_desc_display.get() << std::endl;
264 exit(0);
265 }
266
267 gnc_prefs_set_debugging (m_debug);
268 gnc_prefs_set_extra (m_extra);
269}
const char * gnc_version(void)
Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that fi...
Definition gnc-version.c:35

◆ start()

void Gnucash::CoreApp::start ( void  )

Definition at line 306 of file gnucash-core-app.cpp.

307{
308 gnc_print_unstable_message();
309
310 /* Make sure gnucash' user data directory is properly set up
311 * This must be done before any guile code is called as that would
312 * fail the migration message */
313 userdata_migration_msg = gnc_filepath_init();
314 if (userdata_migration_msg)
315 g_print("\n\n%s\n", userdata_migration_msg);
316
317 gnc_log_init (m_log_flags, m_log_to_filename);
318 gnc_engine_init (0, NULL);
319
320 /* Write some locale details to the log to simplify debugging */
321 PINFO ("System locale returned %s", sys_locale ? sys_locale : "(null)");
322 PINFO ("Effective locale set to %s.", setlocale (LC_ALL, NULL));
323 g_free (sys_locale);
324 sys_locale = NULL;
325}
void gnc_engine_init(int argc, char **argv)
PROTOTYPES.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256

Field Documentation

◆ m_app_name

std::string Gnucash::CoreApp::m_app_name
protected

Definition at line 53 of file gnucash-core-app.hpp.

◆ m_file_to_load

boost::optional<std::string> Gnucash::CoreApp::m_file_to_load
protected

Definition at line 56 of file gnucash-core-app.hpp.

◆ m_log_to_filename

boost::optional<std::string> Gnucash::CoreApp::m_log_to_filename
protected

Definition at line 55 of file gnucash-core-app.hpp.

◆ m_opt_desc_all

bpo::options_description Gnucash::CoreApp::m_opt_desc_all
protected

Definition at line 58 of file gnucash-core-app.hpp.

◆ m_opt_desc_display

std::unique_ptr<bpo::options_description> Gnucash::CoreApp::m_opt_desc_display
protected

Definition at line 59 of file gnucash-core-app.hpp.

◆ m_opt_map

bpo::variables_map Gnucash::CoreApp::m_opt_map
protected

Definition at line 60 of file gnucash-core-app.hpp.

◆ m_pos_opt_desc

bpo::positional_options_description Gnucash::CoreApp::m_pos_opt_desc
protected

Definition at line 61 of file gnucash-core-app.hpp.

◆ m_tagline

std::string Gnucash::CoreApp::m_tagline
protected

Definition at line 54 of file gnucash-core-app.hpp.


The documentation for this class was generated from the following files: