26 #include <glib/gi18n.h> 27 #include <libxml/xmlIO.h> 36 #include "gnc-hooks.h" 38 #include "gnc-menu-extensions.h" 39 #include "gnc-component-manager.h" 40 #include "gnc-splash.h" 42 #include "gnc-icons.h" 43 #include "dialog-doclink-utils.h" 44 #include "dialog-options.h" 46 #include "dialog-totd.h" 49 #include "gnc-session.h" 50 #include "qofbookslots.h" 53 #include "gnc-help-utils.h" 55 #ifdef MAC_INTEGRATION 56 #import <Cocoa/Cocoa.h> 59 extern SCM scm_init_sw_gnome_utils_module(
void);
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;
67 #define ACCEL_MAP_NAME "accelerator-map" 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.");
74 const gchar *msg_no_help_location = N_(
"Expected location");
76 static void gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat);
81 gnc_component_manager_init ();
82 gnc_options_ui_initialize ();
84 scm_init_sw_gnome_utils_module();
85 scm_c_use_module (
"sw_gnome_utils");
86 scm_c_use_module(
"gnucash gnome-utils");
91 gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
93 gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_GLOBPREFS);
97 gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat)
99 gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_BOOK_OPTIONS);
105 gnc_options_dialog_set_help_cb(win,
106 (GNCOptionWinCallback)gnc_book_options_help_cb,
113 GNCOption *num_source_option;
114 GtkWidget *num_source_is_split_action_button;
115 gboolean num_source_is_split_action;
119 GNC_PREF_NUM_SOURCE);
120 if (num_source_is_split_action)
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);
134 gnc_style_sheet_options_help_cb (GNCOptionWin *win, gpointer dat)
136 gnc_gnome_help (GTK_WINDOW(gnc_options_dialog_widget (win)), HF_HELP, HL_STYLE_SHEET);
142 gnc_options_dialog_set_help_cb (win,
143 (GNCOptionWinCallback)gnc_style_sheet_options_help_cb,
154 gnc_configure_date_format (
void)
157 GNC_PREF_DATE_FORMAT);
164 PERR(
"Incorrect date format");
181 gnc_configure_date_completion (
void)
185 GNC_PREF_DATE_BACKMONTHS);
189 else if (backmonths > 11)
201 GtkCssProvider *provider_user, *provider_app, *provider_fallback;
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);
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);
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");
224 str = g_build_filename (var,
"gtk-3.0.css", (
char *)NULL);
225 gtk_css_provider_load_from_path (provider_user, str, &error);
228 g_object_unref (provider_user);
229 g_object_unref (provider_app);
230 g_object_unref (provider_fallback);
237 gnc_gnome_help_yelp_anchor_fix (GtkWindow *parent,
const char *file_name,
const char *anchor)
239 const gchar *
const *sdatadirs = g_get_system_data_dirs ();
240 const gchar *
const *langs = g_get_language_names ();
241 gchar *lookfor = g_strconcat (
"gnome/help/", file_name, NULL);
242 gchar *help_path = NULL;
243 gchar *help_file = NULL;
244 gchar *full_path = NULL;
247 for (; *sdatadirs; sdatadirs++)
249 gchar *filepath = g_build_filename (*sdatadirs, lookfor, NULL);
250 if (g_file_test (filepath, G_FILE_TEST_EXISTS))
251 help_path = g_strdup (filepath);
258 gnc_error_dialog (parent,
"%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
259 PERR(
"Unable to find 'gnome/help' directory");
264 help_file = g_strconcat (file_name,
".xml", NULL);
266 for (; *langs; langs++)
268 gchar *filename = g_build_filename (help_path, *langs, help_file, NULL);
269 if (g_file_test (filename, G_FILE_TEST_EXISTS))
271 full_path = filename;
280 uri = g_strconcat (
"ghelp:", full_path,
"?", anchor, NULL);
283 gnc_error_dialog (parent,
"%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
284 PERR(
"Unable to find valid help language directory");
291 #ifdef MAC_INTEGRATION 298 gnc_gnome_help (GtkWindow *parent,
const char *dir,
const char *detail)
300 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]
init];
301 NSString *subdir = [NSString stringWithUTF8String: dir];
302 NSString *tag, *subdirectory;
306 tag = [NSString stringWithUTF8String: detail];
307 else if ([subdir compare: @HF_HELP] == NSOrderedSame)
309 else if ([subdir compare: @HF_GUIDE] == NSOrderedSame)
313 PWARN(
"gnc_gnome_help called with unknown subdirectory %s", dir);
317 if (![[NSBundle mainBundle] bundleIdentifier])
326 NSArray *components = [NSArray arrayWithObjects:
@"share",
@"doc",
@"gnucash-docs", nil ];
327 NSString *prefix = [[[NSBundle mainBundle] resourcePath]
328 stringByDeletingLastPathComponent];
329 NSArray *prefix_comps = [[prefix pathComponents]
330 arrayByAddingObjectsFromArray: components];
331 NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
332 NSArray *languages = [[NSUserDefaults standardUserDefaults]
333 objectForKey:
@"AppleLanguages"];
335 subdir = [[[subdir lowercaseString] componentsSeparatedByString:
@" "]
336 componentsJoinedByString:
@"-"];
337 if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir])
339 gnc_error_dialog (parent,
"%s\n%s\n%s: %s", _(msg_no_help_found),
340 _(msg_no_help_reason),
341 _(msg_no_help_location), [docs_dir UTF8String]);
345 if ([languages count] > 0)
347 NSEnumerator *lang_iter = [languages objectEnumerator];
350 while ((this_lang = [lang_iter nextObject]))
354 NSString *completed_path = [NSString alloc];
355 this_lang = [this_lang stringByTrimmingCharactersInSet:
356 [NSCharacterSet characterSetWithCharactersInString:
358 elements = [this_lang componentsSeparatedByString: @"-
"]; 359 this_lang = [elements objectAtIndex: 0]; 360 path = [docs_dir stringByAppendingPathComponent: this_lang]; 361 paths = [path completePathIntoString: &completed_path 363 matchesIntoArray: NULL filterTypes: NULL]; 365 [[NSFileManager defaultManager] 366 fileExistsAtPath: completed_path 372 url = [NSURL fileURLWithPath: 374 stringByAppendingPathComponent: subdir] 375 stringByAppendingPathComponent: tag] 376 stringByAppendingPathExtension: @"html
"]]; 378 @catch (NSException *e) 380 PWARN("fileURLWithPath threw %s: %s
", 381 [[e name] UTF8String], [[e reason] UTF8String]); 386 if ([this_lang compare: @"en
"] == NSOrderedSame) 387 break; /* Special case, forces use of "C
" locale */ 395 fileURLWithPath: [[[[docs_dir 396 stringByAppendingPathComponent: @"C
"] 397 stringByAppendingPathComponent: subdir] 398 stringByAppendingPathComponent: tag] 399 stringByAppendingPathExtension: @"html
"]]; 401 @catch (NSException *e) 403 PWARN("fileURLWithPath threw %s: %s
", 404 [[e name] UTF8String], [[e reason] UTF8String]); 409 /* It's a lot easier in a bundle! OSX finds the best translation for us. */ 414 url = [NSURL fileURLWithPath: [[NSBundle mainBundle] 417 inDirectory: subdir ]]; 419 @catch (NSException *e) 421 PWARN("fileURLWithPath threw %s: %s
", 422 [[e name] UTF8String], [[e reason] UTF8String]); 426 /* Now just open the URL in the default app for opening URLs */ 428 [[NSWorkspace sharedWorkspace] openURL: url]; 431 gnc_error_dialog (parent, "%s\n%s
", _(msg_no_help_found), _(msg_no_help_reason)); 435 #elif defined G_OS_WIN32 /* G_OS_WIN32 */ 437 gnc_gnome_help (GtkWindow *parent, const char *file_name, const char *anchor) 439 const gchar * const *lang; 440 gchar *pkgdatadir, *fullpath, *found = NULL; 442 pkgdatadir = gnc_path_get_pkgdatadir (); 443 for (lang = g_get_language_names (); *lang; lang++) 445 fullpath = g_build_filename (pkgdatadir, "help
", *lang, file_name, 447 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR)) 449 found = g_strdup (fullpath); 459 gnc_error_dialog (parent, "%s\n%s
", _(msg_no_help_found), _(msg_no_help_reason)); 463 gnc_show_htmlhelp (found, anchor); 469 gnc_gnome_help (GtkWindow *parent, const char *file_name, const char *anchor) 471 GError *error = NULL; 473 gboolean success = TRUE; 476 uri = gnc_gnome_help_yelp_anchor_fix (parent, file_name, anchor); 478 uri = g_strconcat ("ghelp:
", file_name, NULL); 480 DEBUG ("Attempting to opening help uri %s
", uri); 483 success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error); 489 g_assert(error != NULL); 491 gnc_error_dialog (parent, "%s\n%s
", _(msg_no_help_found), _(msg_no_help_reason)); 493 PERR ("%s
", error->message); 500 #ifdef MAC_INTEGRATION 502 /* Don't be alarmed if this function looks strange to you: It's 503 * written in Objective-C, the native language of the OSX Cocoa 507 gnc_launch_doclink (GtkWindow *parent, const char *uri) 509 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 510 NSString *uri_str = [NSString stringWithUTF8String: uri]; 511 NSURL *url = [[[NSURL alloc] initWithString: uri_str] autorelease]; 512 const gchar *message = 513 _("GnuCash could not find the linked document.
"); 517 [[NSWorkspace sharedWorkspace] openURL: url]; 522 gnc_error_dialog (parent, "%s
", message); 527 #elif defined G_OS_WIN32 /* G_OS_WIN32 */ 529 gnc_launch_doclink (GtkWindow *parent, const char *uri) 531 wchar_t *winuri = NULL; 532 gchar *filename = NULL; 533 /* ShellExecuteW open doesn't decode http escapes if it's passed a 534 * file URI so we have to do it. */ 535 if (gnc_uri_is_file_uri (uri)) 537 gchar *uri_scheme = gnc_uri_get_scheme (uri); 538 filename = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme); 539 winuri = (wchar_t *)g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); 543 winuri = (wchar_t *)g_utf8_to_utf16(uri, -1, NULL, NULL, NULL); 547 wchar_t *wincmd = (wchar_t *)g_utf8_to_utf16("open
", -1, 549 if ((INT_PTR)ShellExecuteW(NULL, wincmd, winuri, 550 NULL, NULL, SW_SHOWNORMAL) <= 32) 552 const gchar *message = 553 _("GnuCash could not find the linked document.
"); 554 gnc_error_dialog (parent, "%s:\n%s
", message, filename); 564 gnc_launch_doclink (GtkWindow *parent, const char *uri) 566 GError *error = NULL; 572 DEBUG ("Attempting to open uri %s
", uri); 574 success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error); 579 g_assert (error != NULL); 581 gchar *error_uri = NULL; 582 const gchar *message = 583 _("GnuCash could not open the linked document:
"); 585 if (gnc_uri_is_file_uri (uri)) 587 gchar *uri_scheme = gnc_uri_get_scheme (uri); 588 error_uri = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme); 592 error_uri = g_strdup (uri); 594 gnc_error_dialog (parent, "%s\n%s
", message, error_uri); 597 PERR ("%s
", error->message); 598 g_error_free (error); 603 /********************************************************************\ 604 * gnc_gnome_get_pixmap * 605 * returns a GtkWidget given a pixmap filename * 608 * Returns: GtkWidget or NULL if there was a problem * 609 \*******************************************************************/ 611 gnc_gnome_get_pixmap (const char *name) 616 g_return_val_if_fail (name != NULL, NULL); 618 fullname = gnc_filepath_locate_pixmap (name); 619 if (fullname == NULL) 622 DEBUG ("Loading pixmap file %s
", fullname); 624 pixmap = gtk_image_new_from_file (fullname); 627 PERR ("Could not load pixmap
"); 634 /********************************************************************\ 635 * gnc_gnome_get_gdkpixbuf * 636 * returns a GdkImlibImage object given a pixmap filename * 639 * Returns: GdkPixbuf or NULL if there was a problem * 640 \*******************************************************************/ 642 gnc_gnome_get_gdkpixbuf (const char *name) 645 GError *error = NULL; 648 g_return_val_if_fail (name != NULL, NULL); 650 fullname = gnc_filepath_locate_pixmap (name); 651 if (fullname == NULL) 654 DEBUG ("Loading pixbuf file %s
", fullname); 655 pixbuf = gdk_pixbuf_new_from_file (fullname, &error); 658 g_assert (pixbuf == NULL); 659 PERR ("Could not load pixbuf: %s
", error->message); 660 g_error_free (error); 668 gnc_ui_check_events (gpointer not_used) 673 if (gtk_main_level() != 1) 676 if (!gnc_current_session_exist()) 678 session = gnc_get_current_session (); 680 if (gnc_gui_refresh_suspended ()) 683 if (!qof_session_events_pending (session)) 686 gnc_suspend_gui_refresh (); 688 force = qof_session_process_events (session); 690 gnc_resume_gui_refresh (); 693 gnc_gui_refresh_all (); 700 gnc_ui_start_event_loop (void) 704 gnome_is_running = TRUE; 706 id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */ 707 gnc_ui_check_events, NULL, NULL); 709 scm_call_1(scm_c_eval_string("gnc:
set-ui-status
"), SCM_BOOL_T); 711 /* Enter gnome event loop */ 714 g_source_remove (id); 716 scm_call_1(scm_c_eval_string("gnc:
set-ui-status
"), SCM_BOOL_F); 718 gnome_is_running = FALSE; 719 gnome_is_terminating = FALSE; 727 static GncMainWindow *main_window; 729 #ifdef MAC_INTEGRATION 735 if (gnome_is_initialized) 738 /* use custom icon */ 739 gnc_load_app_icons(); 740 gtk_window_set_default_icon_name(GNC_ICON_APP); 742 g_set_application_name(PACKAGE_NAME); 745 gnc_show_splash_screen(); 747 gnome_is_initialized = TRUE; 750 gnc_configure_date_format(); 751 gnc_configure_date_completion(); 753 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, 754 GNC_PREF_DATE_FORMAT, 755 gnc_configure_date_format, 757 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, 758 GNC_PREF_DATE_COMPL_THISYEAR, 759 gnc_configure_date_completion, 761 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, 762 GNC_PREF_DATE_COMPL_SLIDING, 763 gnc_configure_date_completion, 765 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, 766 GNC_PREF_DATE_BACKMONTHS, 767 gnc_configure_date_completion, 769 gnc_prefs_register_group_cb (GNC_PREFS_GROUP_GENERAL, 773 gnc_file_set_shutdown_callback (gnc_shutdown); 775 gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL); 777 main_window = gnc_main_window_new (); 779 // gtk_widget_show (GTK_WIDGET (main_window)); 780 gnc_window_set_progressbar_window (GNC_WINDOW(main_window)); 782 #ifdef MAC_INTEGRATION 783 map = gnc_build_userdata_path(ACCEL_MAP_NAME); 784 if (!g_file_test (map, G_FILE_TEST_EXISTS)) 787 data_dir = gnc_path_get_pkgdatadir(); 788 map = g_build_filename(data_dir, "ui
", "osx_accel_map
", NULL); 792 map = gnc_build_userdata_path(ACCEL_MAP_NAME); 793 #endif /* MAC_INTEGRATION */ 794 gtk_accel_map_load(map); 797 /* Load css configuration file */ 800 gnc_totd_dialog (gnc_get_splash_screen (), TRUE); 807 gnucash_ui_is_running(void) 809 return gnome_is_running; 813 gnc_gui_destroy (void) 815 if (!gnome_is_initialized) 818 if (gnc_prefs_is_set_up()) 820 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, 821 GNC_PREF_DATE_FORMAT, 822 gnc_configure_date_format, 824 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, 825 GNC_PREF_DATE_COMPL_THISYEAR, 826 gnc_configure_date_completion, 828 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, 829 GNC_PREF_DATE_COMPL_SLIDING, 830 gnc_configure_date_completion, 832 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, 833 GNC_PREF_DATE_BACKMONTHS, 834 gnc_configure_date_completion, 836 gnc_prefs_remove_group_cb_by_func (GNC_PREFS_GROUP_GENERAL, 840 gnc_ui_util_remove_registered_prefs (); 841 gnc_prefs_remove_registered (); 843 gnc_extensions_shutdown (); 847 gnc_gui_shutdown (void) 851 if (gnome_is_running && !gnome_is_terminating) 853 gnome_is_terminating = TRUE; 854 map = gnc_build_userdata_path(ACCEL_MAP_NAME); 855 gtk_accel_map_save(map); 857 gnc_component_manager_shutdown (); 862 /* shutdown gnucash. This function will initiate an orderly 863 * shutdown, and when that has finished it will exit the program. 866 gnc_shutdown (int exit_status) 868 if (gnucash_ui_is_running()) 870 if (!gnome_is_terminating) 872 if (gnc_file_query_save (gnc_ui_get_main_window (NULL), FALSE)) 874 gnc_hook_run(HOOK_UI_SHUTDOWN, NULL); 882 gnc_hook_run(HOOK_SHUTDOWN, NULL); 883 gnc_engine_shutdown(); QofDateCompletion
Enum for date completion modes (for dates entered without year)
utility functions for the GnuCash UI
Functions that are supported by all types of windows.
#define PERR(format, args...)
Log a serious error.
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...
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Get an integer value from the preferences backend.
#define PWARN(format, args...)
Log a warning.
use sliding 12-month window
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome'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 'gnc_book_options_help_cb' to open a help browser and point it to the Book O...
Gnome specific utility functions.
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 'gnc_style_sheet_options_help_cb' 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'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.
File path resolution utility functions.
Take from locale information.
void qof_date_format_set(QofDateFormat df)
The qof_date_format_set() routine sets date format to one of US, UK, CE, OR ISO.
QofDateFormat
Enum for determining a date format.
"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.