GnuCash  4.14+
gnc-gnome-utils.c
1 /********************************************************************\
2  * gnc-gnome-utils.c -- utility functions for gnome for GnuCash *
3  * Copyright (C) 2001 Linux Developers Group *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21  * *
22 \********************************************************************/
23 
24 #include <config.h>
25 
26 #include <glib/gi18n.h>
27 #include <libxml/xmlIO.h>
28 
29 #include "gnc-prefs-utils.h"
30 #include "gnc-prefs.h"
31 #include "gnc-gnome-utils.h"
32 #include "gnc-engine.h"
33 #include "gnc-path.h"
34 #include "gnc-ui.h"
35 #include "gnc-file.h"
36 #include "gnc-hooks.h"
37 #include "gnc-filepath-utils.h"
38 #include "gnc-menu-extensions.h"
39 #include "gnc-component-manager.h"
40 #include "gnc-splash.h"
41 #include "gnc-window.h"
42 #include "gnc-icons.h"
43 #include "dialog-doclink-utils.h"
44 #include "dialog-options.h"
45 #include "dialog-commodity.h"
46 #include "dialog-totd.h"
47 #include "gnc-ui-util.h"
48 #include "gnc-uri-utils.h"
49 #include "gnc-session.h"
50 #include "qofbookslots.h"
51 #ifdef G_OS_WIN32
52 #include <windows.h>
53 #include "gnc-help-utils.h"
54 #endif
55 #ifdef MAC_INTEGRATION
56 #import <Cocoa/Cocoa.h>
57 #endif
58 
59 extern SCM scm_init_sw_gnome_utils_module(void);
60 
61 static QofLogModule log_module = GNC_MOD_GUI;
62 static int gnome_is_running = FALSE;
63 static int gnome_is_terminating = FALSE;
64 static int gnome_is_initialized = FALSE;
65 
66 
67 #define ACCEL_MAP_NAME "accelerator-map"
68 
69 const gchar *msg_no_help_found =
70  N_("GnuCash could not find the files of the help documentation.");
71 const gchar *msg_no_help_reason =
72  N_("This is likely because the \"gnucash-docs\" package is not properly installed.");
73  /* Translators: URI of missing help files */
74 const gchar *msg_no_help_location = N_("Expected location");
75 
76 static void gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat);
77 
78 void
80 {
81  gnc_component_manager_init ();
82  gnc_options_ui_initialize ();
83 
84  scm_init_sw_gnome_utils_module();
85  scm_c_use_module ("sw_gnome_utils");
86  scm_c_use_module("gnucash gnome-utils");
87 }
88 
89 
90 static void
91 gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
92 {
93  gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_GLOBPREFS);
94 }
95 
96 static void
97 gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat)
98 {
99  gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_BOOK_OPTIONS);
100 }
101 
102 void
104 {
105  gnc_options_dialog_set_help_cb(win,
106  (GNCOptionWinCallback)gnc_book_options_help_cb,
107  NULL);
108 }
109 
110 void
112 {
113  GNCOption *num_source_option;
114  GtkWidget *num_source_is_split_action_button;
115  gboolean num_source_is_split_action;
116 
117  if (!odb) return;
118  num_source_is_split_action = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL,
119  GNC_PREF_NUM_SOURCE);
120  if (num_source_is_split_action)
121  {
122  num_source_option = gnc_option_db_get_option_by_name(odb,
123  OPTION_SECTION_ACCOUNTS,
124  OPTION_NAME_NUM_FIELD_SOURCE);
125  num_source_is_split_action_button =
126  gnc_option_get_gtk_widget (num_source_option);
127  gtk_toggle_button_set_active
128  (GTK_TOGGLE_BUTTON (num_source_is_split_action_button),
129  num_source_is_split_action);
130  }
131 }
132 
133 static void
134 gnc_style_sheet_options_help_cb (GNCOptionWin *win, gpointer dat)
135 {
136  gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_STYLE_SHEET);
137 }
138 
139 void
141 {
142  gnc_options_dialog_set_help_cb (win,
143  (GNCOptionWinCallback)gnc_style_sheet_options_help_cb,
144  NULL);
145 }
146 
147 /* gnc_configure_date_format
148  * sets dateFormat to the current value on the scheme side
149  *
150  * Args: Nothing
151  * Returns: Nothing
152  */
153 static void
154 gnc_configure_date_format (void)
155 {
156  QofDateFormat df = gnc_prefs_get_int(GNC_PREFS_GROUP_GENERAL,
157  GNC_PREF_DATE_FORMAT);
158 
159  /* Only a subset of the qof date formats is currently
160  * supported for date entry.
161  */
162  if (df > QOF_DATE_FORMAT_LOCALE)
163  {
164  PERR("Incorrect date format");
165  return;
166  }
167 
169 }
170 
171 /* gnc_configure_date_completion
172  * sets dateCompletion to the current value on the scheme side.
173  * QOF_DATE_COMPLETION_THISYEAR: use current year
174  * QOF_DATE_COMPLETION_SLIDING: use a sliding 12-month window
175  * backmonths 0-11: windows starts this many months before current month
176  *
177  * Args: Nothing
178  * Returns: Nothing
179  */
180 static void
181 gnc_configure_date_completion (void)
182 {
184  int backmonths = gnc_prefs_get_float(GNC_PREFS_GROUP_GENERAL,
185  GNC_PREF_DATE_BACKMONTHS);
186 
187  if (backmonths < 0)
188  backmonths = 0;
189  else if (backmonths > 11)
190  backmonths = 11;
191 
192  if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_DATE_COMPL_SLIDING))
194 
195  qof_date_completion_set(dc, backmonths);
196 }
197 
198 void
200 {
201  GtkCssProvider *provider_user, *provider_app, *provider_fallback;
202  GdkDisplay *display;
203  GdkScreen *screen;
204  const gchar *var;
205  GError *error = 0;
206 
207  provider_user = gtk_css_provider_new ();
208  provider_app = gtk_css_provider_new ();
209  provider_fallback = gtk_css_provider_new ();
210  display = gdk_display_get_default ();
211  screen = gdk_display_get_default_screen (display);
212 
213  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_fallback), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
214  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_app), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
215  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER);
216 
217  gtk_css_provider_load_from_resource (provider_app, "/org/gnucash/gnucash.css");
218  gtk_css_provider_load_from_resource (provider_fallback, "/org/gnucash/gnucash-fallback.css");
219 
220  var = gnc_userconfig_dir ();
221  if (var)
222  {
223  gchar *str;
224  str = g_build_filename (var, "gtk-3.0.css", (char *)NULL);
225  gtk_css_provider_load_from_path (provider_user, str, &error);
226  g_free (str);
227  }
228  g_object_unref (provider_user);
229  g_object_unref (provider_app);
230  g_object_unref (provider_fallback);
231 }
232 
233 #ifdef MAC_INTEGRATION
234 
235 /* Don't be alarmed if this function looks strange to you: It's
236  * written in Objective-C, the native language of the OSX Cocoa
237  * toolkit.
238  */
239 void
240 gnc_gnome_help (GtkWindow *parent, const char *dir, const char *detail)
241 {
242  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
243  NSString *subdir = [NSString stringWithUTF8String: dir];
244  NSString *tag;
245  NSURL *url = NULL;
246 
247  if (detail)
248  tag = [NSString stringWithUTF8String: detail];
249  else
250  tag = @"index";
251 
252  if (![[NSBundle mainBundle] bundleIdentifier])
253  {
254  /* If bundleIdentifier is NULL, then we're running from the
255  * commandline and must construct a file path to the resource. We can
256  * still get the resource path, but it will point to the "bin"
257  * directory so we chop that off, break up what's left into pieces,
258  * add some more pieces, and put it all back together again. Then,
259  * because the gettext way of handling localizations is different from
260  * OSX's, we have to figure out which translation to use. */
261  NSArray *components = [NSArray arrayWithObjects: @"share", @"doc", @"gnucash-docs", nil ];
262  NSString *prefix = [[[NSBundle mainBundle] resourcePath]
263  stringByDeletingLastPathComponent];
264  NSArray *prefix_comps = [[prefix pathComponents]
265  arrayByAddingObjectsFromArray: components];
266  NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
267  NSArray *languages = [[NSUserDefaults standardUserDefaults]
268  objectForKey: @"AppleLanguages"];
269  BOOL dir;
270  subdir = [[[subdir lowercaseString] componentsSeparatedByString: @" "]
271  componentsJoinedByString: @"-"];
272  if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir])
273  {
274  gnc_error_dialog (parent, "%s\n%s\n%s: %s", _(msg_no_help_found),
275  _(msg_no_help_reason),
276  _(msg_no_help_location), [docs_dir UTF8String]);
277  [pool release];
278  return;
279  }
280  if ([languages count] > 0)
281  {
282  NSEnumerator *lang_iter = [languages objectEnumerator];
283  NSString *path;
284  NSString *this_lang;
285  while ((this_lang = [lang_iter nextObject]))
286  {
287  NSArray *elements;
288  unsigned int paths;
289  NSString *completed_path = [NSString alloc];
290  this_lang = [this_lang stringByTrimmingCharactersInSet:
291  [NSCharacterSet characterSetWithCharactersInString:
292  @"\""]];
293  elements = [this_lang componentsSeparatedByString: @"-"];
294  this_lang = [elements objectAtIndex: 0];
295  path = [docs_dir stringByAppendingPathComponent: this_lang];
296  paths = [path completePathIntoString: &completed_path
297  caseSensitive: FALSE
298  matchesIntoArray: NULL filterTypes: NULL];
299  if (paths > 1 &&
300  [[NSFileManager defaultManager]
301  fileExistsAtPath: completed_path
302  isDirectory: &dir])
303  if (dir)
304  {
305  @try
306  {
307  url = [NSURL fileURLWithPath:
308  [[[completed_path
309  stringByAppendingPathComponent: subdir]
310  stringByAppendingPathComponent: tag]
311  stringByAppendingPathExtension: @"html"]];
312  }
313  @catch (NSException *e)
314  {
315  PWARN("fileURLWithPath threw %s: %s",
316  [[e name] UTF8String], [[e reason] UTF8String]);
317  return;
318  }
319  break;
320  }
321  if ([this_lang compare: @"en"] == NSOrderedSame)
322  break; /* Special case, forces use of "C" locale */
323  }
324  }
325  if (!url)
326  {
327  @try
328  {
329  url = [NSURL
330  fileURLWithPath: [[[[docs_dir
331  stringByAppendingPathComponent: @"C"]
332  stringByAppendingPathComponent: subdir]
333  stringByAppendingPathComponent: tag]
334  stringByAppendingPathExtension: @"html"]];
335  }
336  @catch (NSException *e)
337  {
338  PWARN("fileURLWithPath threw %s: %s",
339  [[e name] UTF8String], [[e reason] UTF8String]);
340  return;
341  }
342  }
343  }
344  /* It's a lot easier in a bundle! OSX finds the best translation for us. */
345  else
346  {
347  @try
348  {
349  url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
350  pathForResource: tag
351  ofType: @"html"
352  inDirectory: subdir ]];
353  }
354  @catch (NSException *e)
355  {
356  PWARN("fileURLWithPath threw %s: %s",
357  [[e name] UTF8String], [[e reason] UTF8String]);
358  return;
359  }
360  }
361  /* Now just open the URL in the default app for opening URLs */
362  if (url)
363  [[NSWorkspace sharedWorkspace] openURL: url];
364  else
365  {
366  gnc_error_dialog (parent, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
367  }
368  [pool release];
369 }
370 #elif defined G_OS_WIN32 /* G_OS_WIN32 */
371 void
372 gnc_gnome_help (GtkWindow *parent, const char *file_name, const char *anchor)
373 {
374  const gchar * const *lang;
375  gchar *pkgdatadir, *fullpath, *found = NULL;
376 
377  pkgdatadir = gnc_path_get_pkgdatadir ();
378  for (lang = g_get_language_names (); *lang; lang++)
379  {
380  fullpath = g_build_filename (pkgdatadir, "help", *lang, file_name,
381  (gchar*) NULL);
382  if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
383  {
384  found = g_strdup (fullpath);
385  g_free (fullpath);
386  break;
387  }
388  g_free (fullpath);
389  }
390  g_free (pkgdatadir);
391 
392  if (!found)
393  {
394  gnc_error_dialog (parent, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
395  }
396  else
397  {
398  gnc_show_htmlhelp (found, anchor);
399  }
400  g_free (found);
401 }
402 #else
403 void
404 gnc_gnome_help (GtkWindow *parent, const char *file_name, const char *anchor)
405 {
406  GError *error = NULL;
407  gchar *uri = NULL;
408  gboolean success = TRUE;
409 
410  if (anchor)
411  uri = g_strconcat ("help:", file_name, "/", anchor, NULL);
412  else
413  uri = g_strconcat ("help:", file_name, NULL);
414 
415  DEBUG ("Attempting to opening help uri %s", uri);
416 
417  if (uri)
418  success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error);
419 
420  g_free (uri);
421  if (success)
422  return;
423 
424  g_assert(error != NULL);
425  {
426  gnc_error_dialog (parent, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
427  }
428  PERR ("%s", error->message);
429  g_error_free(error);
430 }
431 
432 
433 #endif
434 
435 #ifdef MAC_INTEGRATION
436 
437 /* Don't be alarmed if this function looks strange to you: It's
438  * written in Objective-C, the native language of the OSX Cocoa
439  * toolkit.
440  */
441 void
442 gnc_launch_doclink (GtkWindow *parent, const char *uri)
443 {
444  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
445  NSString *uri_str = [NSString stringWithUTF8String: uri];
446  NSURL *url = [[[NSURL alloc] initWithString: uri_str] autorelease];
447  const gchar *message =
448  _("GnuCash could not find the linked document.");
449 
450  if (url)
451  {
452  [[NSWorkspace sharedWorkspace] openURL: url];
453  [pool release];
454  return;
455  }
456 
457  gnc_error_dialog (parent, "%s", message);
458 
459  [pool release];
460  return;
461 }
462 #elif defined G_OS_WIN32 /* G_OS_WIN32 */
463 void
464 gnc_launch_doclink (GtkWindow *parent, const char *uri)
465 {
466  wchar_t *winuri = NULL;
467  gchar *filename = NULL;
468  /* ShellExecuteW open doesn't decode http escapes if it's passed a
469  * file URI so we have to do it. */
470  if (gnc_uri_is_file_uri (uri))
471  {
472  gchar *uri_scheme = gnc_uri_get_scheme (uri);
473  filename = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme);
474  winuri = (wchar_t *)g_utf8_to_utf16(filename, -1, NULL, NULL, NULL);
475  g_free (uri_scheme);
476  }
477  else
478  winuri = (wchar_t *)g_utf8_to_utf16(uri, -1, NULL, NULL, NULL);
479 
480  if (winuri)
481  {
482  wchar_t *wincmd = (wchar_t *)g_utf8_to_utf16("open", -1,
483  NULL, NULL, NULL);
484  if ((INT_PTR)ShellExecuteW(NULL, wincmd, winuri,
485  NULL, NULL, SW_SHOWNORMAL) <= 32)
486  {
487  const gchar *message =
488  _("GnuCash could not find the linked document.");
489  gnc_error_dialog (parent, "%s:\n%s", message, filename);
490  }
491  g_free (wincmd);
492  g_free (winuri);
493  g_free (filename);
494  }
495 }
496 
497 #else
498 void
499 gnc_launch_doclink (GtkWindow *parent, const char *uri)
500 {
501  GError *error = NULL;
502  gboolean success;
503 
504  if (!uri)
505  return;
506 
507  DEBUG ("Attempting to open uri %s", uri);
508 
509  success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error);
510 
511  if (success)
512  return;
513 
514  g_assert (error != NULL);
515  {
516  gchar *error_uri = NULL;
517  const gchar *message =
518  _("GnuCash could not open the linked document:");
519 
520  if (gnc_uri_is_file_uri (uri))
521  {
522  gchar *uri_scheme = gnc_uri_get_scheme (uri);
523  error_uri = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme);
524  g_free (uri_scheme);
525  }
526  else
527  error_uri = g_strdup (uri);
528 
529  gnc_error_dialog (parent, "%s\n%s", message, error_uri);
530  g_free (error_uri);
531  }
532  PERR ("%s", error->message);
533  g_error_free (error);
534 }
535 
536 #endif
537 
538 /********************************************************************\
539  * gnc_gnome_get_pixmap *
540  * returns a GtkWidget given a pixmap filename *
541  * *
542  * Args: none *
543  * Returns: GtkWidget or NULL if there was a problem *
544  \*******************************************************************/
545 GtkWidget *
546 gnc_gnome_get_pixmap (const char *name)
547 {
548  GtkWidget *pixmap;
549  char *fullname;
550 
551  g_return_val_if_fail (name != NULL, NULL);
552 
553  fullname = gnc_filepath_locate_pixmap (name);
554  if (fullname == NULL)
555  return NULL;
556 
557  DEBUG ("Loading pixmap file %s", fullname);
558 
559  pixmap = gtk_image_new_from_file (fullname);
560  if (pixmap == NULL)
561  {
562  PERR ("Could not load pixmap");
563  }
564  g_free (fullname);
565 
566  return pixmap;
567 }
568 
569 /********************************************************************\
570  * gnc_gnome_get_gdkpixbuf *
571  * returns a GdkImlibImage object given a pixmap filename *
572  * *
573  * Args: none *
574  * Returns: GdkPixbuf or NULL if there was a problem *
575  \*******************************************************************/
576 GdkPixbuf *
577 gnc_gnome_get_gdkpixbuf (const char *name)
578 {
579  GdkPixbuf *pixbuf;
580  GError *error = NULL;
581  char *fullname;
582 
583  g_return_val_if_fail (name != NULL, NULL);
584 
585  fullname = gnc_filepath_locate_pixmap (name);
586  if (fullname == NULL)
587  return NULL;
588 
589  DEBUG ("Loading pixbuf file %s", fullname);
590  pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
591  if (error != NULL)
592  {
593  g_assert (pixbuf == NULL);
594  PERR ("Could not load pixbuf: %s", error->message);
595  g_error_free (error);
596  }
597  g_free (fullname);
598 
599  return pixbuf;
600 }
601 
602 static gboolean
603 gnc_ui_check_events (gpointer not_used)
604 {
605  QofSession *session;
606  gboolean force;
607 
608  if (gtk_main_level() != 1)
609  return TRUE;
610 
611  if (!gnc_current_session_exist())
612  return TRUE;
613  session = gnc_get_current_session ();
614 
615  if (gnc_gui_refresh_suspended ())
616  return TRUE;
617 
618  if (!qof_session_events_pending (session))
619  return TRUE;
620 
621  gnc_suspend_gui_refresh ();
622 
623  force = qof_session_process_events (session);
624 
625  gnc_resume_gui_refresh ();
626 
627  if (force)
628  gnc_gui_refresh_all ();
629 
630  return TRUE;
631 }
632 
633 
634 int
635 gnc_ui_start_event_loop (void)
636 {
637  guint id;
638 
639  gnome_is_running = TRUE;
640 
641  id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */
642  gnc_ui_check_events, NULL, NULL);
643 
644  scm_call_1(scm_c_eval_string("gnc:set-ui-status"), SCM_BOOL_T);
645 
646  /* Enter gnome event loop */
647  gtk_main ();
648 
649  g_source_remove (id);
650 
651  scm_call_1(scm_c_eval_string("gnc:set-ui-status"), SCM_BOOL_F);
652 
653  gnome_is_running = FALSE;
654  gnome_is_terminating = FALSE;
655 
656  return 0;
657 }
658 
659 GncMainWindow *
660 gnc_gui_init(void)
661 {
662  static GncMainWindow *main_window;
663  gchar *map;
664 #ifdef MAC_INTEGRATION
665  gchar *data_dir;
666 #endif
667 
668  ENTER ("");
669 
670  if (gnome_is_initialized)
671  return main_window;
672 
673  /* use custom icon */
674  gnc_load_app_icons();
675  gtk_window_set_default_icon_name(GNC_ICON_APP);
676 
677  g_set_application_name(PACKAGE_NAME);
678 
679  gnc_prefs_init();
680  gnc_show_splash_screen();
681 
682  gnome_is_initialized = TRUE;
683 
684  gnc_ui_util_init();
685  gnc_configure_date_format();
686  gnc_configure_date_completion();
687 
688  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
689  GNC_PREF_DATE_FORMAT,
690  gnc_configure_date_format,
691  NULL);
692  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
693  GNC_PREF_DATE_COMPL_THISYEAR,
694  gnc_configure_date_completion,
695  NULL);
696  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
697  GNC_PREF_DATE_COMPL_SLIDING,
698  gnc_configure_date_completion,
699  NULL);
700  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
701  GNC_PREF_DATE_BACKMONTHS,
702  gnc_configure_date_completion,
703  NULL);
704  gnc_prefs_register_group_cb (GNC_PREFS_GROUP_GENERAL,
705  gnc_gui_refresh_all,
706  NULL);
707 
708  gnc_file_set_shutdown_callback (gnc_shutdown);
709 
710  gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL);
711 
712  main_window = gnc_main_window_new ();
713  // Bug#350993:
714  // gtk_widget_show (GTK_WIDGET (main_window));
715  gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
716 
717 #ifdef MAC_INTEGRATION
718  map = gnc_build_userdata_path(ACCEL_MAP_NAME);
719  if (!g_file_test (map, G_FILE_TEST_EXISTS))
720  {
721  g_free (map);
722  data_dir = gnc_path_get_pkgdatadir();
723  map = g_build_filename(data_dir, "ui", "osx_accel_map", NULL);
724  g_free(data_dir);
725  }
726 #else
727  map = gnc_build_userdata_path(ACCEL_MAP_NAME);
728 #endif /* MAC_INTEGRATION */
729  gtk_accel_map_load(map);
730  g_free(map);
731 
732  /* Load css configuration file */
733  gnc_add_css_file ();
734 
735  gnc_totd_dialog (gnc_get_splash_screen (), TRUE);
736 
737  LEAVE ("");
738  return main_window;
739 }
740 
741 gboolean
742 gnucash_ui_is_running(void)
743 {
744  return gnome_is_running;
745 }
746 
747 static void
748 gnc_gui_destroy (void)
749 {
750  if (!gnome_is_initialized)
751  return;
752 
753  if (gnc_prefs_is_set_up())
754  {
755  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
756  GNC_PREF_DATE_FORMAT,
757  gnc_configure_date_format,
758  NULL);
759  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
760  GNC_PREF_DATE_COMPL_THISYEAR,
761  gnc_configure_date_completion,
762  NULL);
763  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
764  GNC_PREF_DATE_COMPL_SLIDING,
765  gnc_configure_date_completion,
766  NULL);
767  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
768  GNC_PREF_DATE_BACKMONTHS,
769  gnc_configure_date_completion,
770  NULL);
771  gnc_prefs_remove_group_cb_by_func (GNC_PREFS_GROUP_GENERAL,
772  gnc_gui_refresh_all,
773  NULL);
774 
775  gnc_ui_util_remove_registered_prefs ();
776  gnc_prefs_remove_registered ();
777  }
778  gnc_extensions_shutdown ();
779 }
780 
781 static void
782 gnc_gui_shutdown (void)
783 {
784  gchar *map;
785 
786  if (gnome_is_running && !gnome_is_terminating)
787  {
788  gnome_is_terminating = TRUE;
789  map = gnc_build_userdata_path(ACCEL_MAP_NAME);
790  gtk_accel_map_save(map);
791  g_free(map);
792  gnc_component_manager_shutdown ();
793  gtk_main_quit();
794  }
795 }
796 
797 /* shutdown gnucash. This function will initiate an orderly
798  * shutdown, and when that has finished it will exit the program.
799  */
800 void
801 gnc_shutdown (int exit_status)
802 {
803  if (gnucash_ui_is_running())
804  {
805  if (!gnome_is_terminating)
806  {
807  if (gnc_file_query_save (gnc_ui_get_main_window (NULL), FALSE))
808  {
809  gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
810  gnc_gui_shutdown();
811  }
812  }
813  }
814  else
815  {
816  gnc_gui_destroy();
817  gnc_hook_run(HOOK_SHUTDOWN, NULL);
818  gnc_engine_shutdown();
819  exit(exit_status);
820  }
821 }
822 
QofDateCompletion
Enum for date completion modes (for dates entered without year)
Definition: gnc-date.h:144
utility functions for the GnuCash UI
Functions that are supported by all types of windows.
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
The qof_date_completion_set() routing sets the date completion method to one of QOF_DATE_COMPLETION_T...
Definition: gnc-date.cpp:475
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Get an integer value from the preferences backend.
use sliding 12-month window
Definition: gnc-date.h:147
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome&#39;s yelp for linux, and open to a given link within a gi...
Preferences initialization function.
void gnc_options_dialog_set_book_options_help_cb(GNCOptionWin *win)
Set the help callback to &#39;gnc_book_options_help_cb&#39; to open a help browser and point it to the Book O...
Gnome specific utility functions.
Definition: init.py:1
void gnc_add_css_file(void)
Load a gtk resource configuration file to customize gtk appearance and behaviour. ...
All type declarations for the whole Gnucash engine.
void gnc_gnome_utils_init(void)
Initialize the gnome-utils library Should be run once before using any gnome-utils features...
Generic api to store and retrieve preferences.
void gnc_options_dialog_set_style_sheet_options_help_cb(GNCOptionWin *win)
Set the help callback to &#39;gnc_style_sheet_options_help_cb&#39; to open a help browser and point it to the...
void gnc_options_dialog_set_new_book_option_values(GNCOptionDB *odb)
Set the initial values of new book options to values specified in user preferences.
const gchar * gnc_userconfig_dir(void)
Return the user&#39;s config directory for gnucash.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
Utility functions for convert uri in separate components and back.
use current year
Definition: gnc-date.h:146
File path resolution utility functions.
Take from locale information.
Definition: gnc-date.h:134
void qof_date_format_set(QofDateFormat df)
The qof_date_format_set() routine sets date format to one of US, UK, CE, OR ISO.
Definition: gnc-date.cpp:442
QofDateFormat
Enum for determining a date format.
Definition: gnc-date.h:128
"select" and "new" commodity windows
gdouble gnc_prefs_get_float(const gchar *group, const gchar *pref_name)
Get an float value from the preferences backend.