26 #include <glib/gi18n.h>
27 #ifdef HAVE_X11_XLIB_H
28 # include <X11/Xlib.h>
30 #include <libxml/xmlIO.h>
40 #include "gnc-hooks.h"
42 #include "gnc-menu-extensions.h"
43 #include "gnc-component-manager.h"
44 #include "gnc-splash.h"
46 #include "gnc-icons.h"
47 #include "dialog-options.h"
49 #include "dialog-totd.h"
51 #include "gnc-session.h"
52 #include "qofbookslots.h"
55 #include "gnc-help-utils.h"
57 #ifdef MAC_INTEGRATION
58 #import <Cocoa/Cocoa.h>
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 static void gnc_book_options_help_cb (
GNCOptionWin *win, gpointer dat);
72 gnc_global_options_help_cb (
GNCOptionWin *win, gpointer dat)
78 gnc_book_options_help_cb (
GNCOptionWin *win, gpointer dat)
86 gnc_options_dialog_set_help_cb(win,
87 (GNCOptionWinCallback)gnc_book_options_help_cb,
95 GtkWidget *num_source_is_split_action_button;
96 gboolean num_source_is_split_action;
100 GNC_PREF_NUM_SOURCE);
101 if (num_source_is_split_action)
103 num_source_option = gnc_option_db_get_option_by_name(odb,
104 OPTION_SECTION_ACCOUNTS,
105 OPTION_NAME_NUM_FIELD_SOURCE);
106 num_source_is_split_action_button =
107 gnc_option_get_gtk_widget (num_source_option);
108 gtk_toggle_button_set_active
109 (GTK_TOGGLE_BUTTON (num_source_is_split_action_button),
110 num_source_is_split_action);
115 gnc_commodity_help_cb (
void)
127 gnc_configure_date_format (
void)
130 GNC_PREF_DATE_FORMAT);
138 PERR(
"Incorrect date format");
155 gnc_configure_date_completion (
void)
159 GNC_PREF_DATE_BACKMONTHS);
163 else if (backmonths > 11)
178 var = g_get_home_dir ();
181 str = g_build_filename (var,
".gtkrc-2.0.gnucash", (
char *)NULL);
182 gtk_rc_add_default_file (str);
187 #ifdef MAC_INTEGRATION
196 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
197 NSString *subdir = [NSString stringWithUTF8String: dir];
198 NSString *tag, *subdirectory;
202 tag = [NSString stringWithUTF8String: detail];
203 else if ([subdir compare: @HF_HELP] == NSOrderedSame)
205 else if ([subdir compare: @HF_GUIDE] == NSOrderedSame)
209 PWARN(
"gnc_gnome_help called with unknown subdirectory %s", dir);
213 if (![[NSBundle mainBundle] bundleIdentifier])
222 NSArray *components = [NSArray arrayWithObjects:
@"share",
@"doc",
@"gnucash-docs", nil ];
223 NSString *prefix = [[[NSBundle mainBundle] resourcePath]
224 stringByDeletingLastPathComponent];
225 NSArray *prefix_comps = [[prefix pathComponents]
226 arrayByAddingObjectsFromArray: components];
227 NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
228 NSArray *languages = [[NSUserDefaults standardUserDefaults]
229 objectForKey:
@"AppleLanguages"];
231 subdir = [[[subdir lowercaseString] componentsSeparatedByString:
@" "]
232 componentsJoinedByString:
@"-"];
233 if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir])
235 const gchar *message =
236 _(
"GnuCash could not find the files for the help documentation. "
237 "This is likely because the 'gnucash-docs' package is not installed");
238 gnc_error_dialog(NULL,
"%s at %s", message, [docs_dir UTF8String]);
242 if ([languages count] > 0)
244 NSEnumerator *lang_iter = [languages objectEnumerator];
247 while ((this_lang = [lang_iter nextObject]))
251 NSString *completed_path = [NSString alloc];
252 this_lang = [this_lang stringByTrimmingCharactersInSet:
253 [NSCharacterSet characterSetWithCharactersInString:
255 elements = [this_lang componentsSeparatedByString: @"-
"];
256 this_lang = [elements objectAtIndex: 0];
257 path = [docs_dir stringByAppendingPathComponent: this_lang];
258 paths = [path completePathIntoString: &completed_path
260 matchesIntoArray: NULL filterTypes: NULL];
262 [[NSFileManager defaultManager]
263 fileExistsAtPath: completed_path
269 url = [NSURL fileURLWithPath:
271 stringByAppendingPathComponent: subdir]
272 stringByAppendingPathComponent: tag]
273 stringByAppendingPathExtension: @"html
"]];
275 @catch (NSException *e)
277 PWARN("fileURLWithPath threw %s: %s
",
278 [[e name] UTF8String], [[e reason] UTF8String]);
283 if ([this_lang compare: @"en
"] == NSOrderedSame)
284 break; /* Special case, forces use of "C
" locale */
292 fileURLWithPath: [[[[docs_dir
293 stringByAppendingPathComponent: @"C
"]
294 stringByAppendingPathComponent: subdir]
295 stringByAppendingPathComponent: tag]
296 stringByAppendingPathExtension: @"html
"]];
298 @catch (NSException *e)
300 PWARN("fileURLWithPath threw %s: %s
",
301 [[e name] UTF8String], [[e reason] UTF8String]);
306 /* It's a lot easier in a bundle! OSX finds the best translation for us. */
311 url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
314 inDirectory: subdir ]];
316 @catch (NSException *e)
318 PWARN("fileURLWithPath threw %s: %s
",
319 [[e name] UTF8String], [[e reason] UTF8String]);
323 /* Now just open the URL in the default app for opening URLs */
325 [[NSWorkspace sharedWorkspace] openURL: url];
328 const gchar *message =
329 _("GnuCash could not find the files
for the help documentation.
"
330 "This is likely because the
'gnucash-docs' package is not installed.");
331 gnc_error_dialog(NULL,
"%s", message);
335 #elif defined G_OS_WIN32
339 const gchar *
const *lang;
340 gchar *pkgdatadir, *fullpath, *found = NULL;
342 pkgdatadir = gnc_path_get_pkgdatadir ();
343 for (lang = g_get_language_names (); *lang; lang++)
345 fullpath = g_build_filename (pkgdatadir,
"help", *lang, file_name,
347 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
349 found = g_strdup (fullpath);
359 const gchar *message =
360 _(
"GnuCash could not find the files for the help documentation.");
361 gnc_error_dialog (NULL, message);
365 gnc_show_htmlhelp (found, anchor);
373 GError *error = NULL;
378 uri = g_strconcat (
"ghelp:", file_name,
"?", anchor, NULL);
380 uri = g_strconcat (
"ghelp:", file_name, NULL);
382 DEBUG (
"Attempting to opening help uri %s", uri);
383 success = gtk_show_uri (NULL, uri, gtk_get_current_event_time (), &error);
388 g_assert(error != NULL);
390 const gchar *message =
391 _(
"GnuCash could not find the files for the help documentation. "
392 "This is likely because the 'gnucash-docs' package is not installed.");
393 gnc_error_dialog(NULL,
"%s", message);
395 PERR (
"%s", error->message);
402 #ifdef MAC_INTEGRATION
411 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
412 NSString *uri_str = [NSString stringWithUTF8String: uri];
413 NSURL *url = [[[NSURL alloc] initWithString: uri_str] autorelease];
414 const gchar *message =
415 _(
"GnuCash could not find the associated file.");
419 [[NSWorkspace sharedWorkspace] openURL: url];
424 gnc_error_dialog(NULL,
"%s", message);
429 #elif defined G_OS_WIN32
433 wchar_t *winuri = (
wchar_t *)g_utf8_to_utf16(uri, -1, NULL, NULL, NULL);
434 wchar_t *wincmd = (
wchar_t *)g_utf8_to_utf16(
"open", -1, NULL, NULL, NULL);
437 if ((INT_PTR)ShellExecuteW(NULL, wincmd, winuri, NULL, NULL, SW_SHOWNORMAL) <= 32)
439 const gchar *message =
440 _(
"GnuCash could not find the associated file.");
441 gnc_error_dialog(NULL,
"%s", message);
452 GError *error = NULL;
458 DEBUG (
"Attempting to open uri %s", uri);
459 success = gtk_show_uri (NULL, uri, gtk_get_current_event_time (), &error);
463 g_assert(error != NULL);
465 const gchar *message =
466 _(
"GnuCash could not open the associated URI:");
467 gnc_error_dialog(NULL,
"%s\n%s", message, uri);
469 PERR (
"%s", error->message);
488 g_return_val_if_fail (name != NULL, NULL);
491 if (fullname == NULL)
494 DEBUG (
"Loading pixmap file %s", fullname);
496 pixmap = gtk_image_new_from_file (fullname);
499 PERR (
"Could not load pixmap");
517 GError *error = NULL;
520 g_return_val_if_fail (name != NULL, NULL);
523 if (fullname == NULL)
526 DEBUG (
"Loading pixbuf file %s", fullname);
527 pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
530 g_assert (pixbuf == NULL);
531 PERR (
"Could not load pixbuf: %s", error->message);
532 g_error_free (error);
540 gnc_ui_check_events (gpointer not_used)
545 if (gtk_main_level() != 1)
548 if (!gnc_current_session_exist())
550 session = gnc_get_current_session ();
552 if (gnc_gui_refresh_suspended ())
558 gnc_suspend_gui_refresh ();
562 gnc_resume_gui_refresh ();
565 gnc_gui_refresh_all ();
570 #ifdef HAVE_X11_XLIB_H
572 gnc_x_error (Display *display, XErrorEvent *error)
574 if (error->error_code)
578 XGetErrorText (display, error->error_code, buf, 63);
580 g_warning (
"X-ERROR **: %s\n serial %ld error_code %d "
581 "request_code %d minor_code %d\n",
594 gnc_ui_start_event_loop (
void)
598 gnome_is_running = TRUE;
600 id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000,
601 gnc_ui_check_events, NULL, NULL);
603 #ifdef HAVE_X11_XLIB_H
604 XSetErrorHandler (gnc_x_error);
610 g_source_remove (
id);
612 gnome_is_running = FALSE;
613 gnome_is_terminating = FALSE;
623 #ifdef MAC_INTEGRATION
627 char *icon_filenames[] = {
"gnucash-icon-16x16.png",
628 "gnucash-icon-32x32.png",
629 "gnucash-icon-48x48.png",
637 if (gnome_is_initialized)
641 for (idx = 0; icon_filenames[idx] != NULL; idx++)
643 GdkPixbuf *buf = NULL;
646 if (fullname == NULL)
648 g_warning(
"couldn't find icon file [%s]", icon_filenames[idx]);
655 g_warning(
"error loading image from [%s]", fullname);
660 icons = g_list_append(icons, buf);
663 gtk_window_set_default_icon_list(icons);
664 g_list_foreach(icons, (GFunc)g_object_unref, NULL);
668 gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
670 g_set_application_name(PACKAGE_NAME);
673 gnc_show_splash_screen();
675 gnome_is_initialized = TRUE;
678 gnc_configure_date_format();
679 gnc_configure_date_completion();
682 GNC_PREF_DATE_FORMAT,
683 gnc_configure_date_format,
686 GNC_PREF_DATE_COMPL_THISYEAR,
687 gnc_configure_date_completion,
690 GNC_PREF_DATE_COMPL_SLIDING,
691 gnc_configure_date_completion,
694 GNC_PREF_DATE_BACKMONTHS,
695 gnc_configure_date_completion,
704 gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL);
709 gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
711 #ifdef MAC_INTEGRATION
713 if (!g_file_test (map, G_FILE_TEST_EXISTS))
716 data_dir = gnc_path_get_pkgdatadir();
717 map = g_build_filename(data_dir,
"ui",
"osx_accel_map", NULL);
723 gtk_accel_map_load(map);
726 gnc_load_stock_icons();
727 gnc_totd_dialog(GTK_WINDOW(main_window), TRUE);
734 gnucash_ui_is_running(
void)
736 return gnome_is_running;
740 gnc_gui_destroy (
void)
742 if (!gnome_is_initialized)
745 gnc_extensions_shutdown ();
749 gnc_gui_shutdown (
void)
753 if (gnome_is_running && !gnome_is_terminating)
755 gnome_is_terminating = TRUE;
757 gtk_accel_map_save(map);
769 if (gnucash_ui_is_running())
771 if (!gnome_is_terminating)
773 if (gnc_file_query_save(FALSE))
775 gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
783 gnc_hook_run(HOOK_SHUTDOWN, NULL);
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
utility functions for the GnuCash UI
GtkWidget * gnc_gnome_get_pixmap(const char *name)
void gnc_engine_shutdown(void)
void gnc_ui_commodity_set_help_callback(gnc_commodity_help_callback cb)
#define DEBUG(format, args...)
Functions that are supported by all types of windows.
gboolean qof_session_events_pending(const QofSession *session)
void gnc_shutdown(int exit_status)
gchar * gnc_build_dotgnucash_path(const gchar *filename)
Make a path to filename in the user's configuration directory.
#define PERR(format, args...)
#define ENTER(format, args...)
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
#define PWARN(format, args...)
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
Preferences initialization function.
void gnc_options_dialog_set_book_options_help_cb(GNCOptionWin *win)
Gnome specific utility functions.
void gnc_gnome_help(const char *file_name, const char *anchor)
gchar * gnc_filepath_locate_pixmap(const gchar *name)
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
gboolean qof_session_process_events(QofSession *session)
guint gnc_prefs_register_group_cb(const gchar *group, gpointer func, gpointer user_data)
void gnc_launch_assoc(const char *uri)
GncMainWindow * gnc_main_window_new(void)
void gnc_prefs_init(void)
void gnc_gtk_add_rc_file(void)
void gnc_options_dialog_set_new_book_option_values(GNCOptionDB *odb)
GdkPixbuf * gnc_gnome_get_gdkpixbuf(const char *name)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
GncMainWindow * gnc_gui_init(void)
#define LEAVE(format, args...)
void qof_date_format_set(QofDateFormat df)
File path resolution utility functions.
"select" and "new" commodity windows
const gchar * QofLogModule
gdouble gnc_prefs_get_float(const gchar *group, const gchar *pref_name)