GnuCash de0bfde+
Loading...
Searching...
No Matches
Gnome-specific GUI handling.

Files

file  gnc-gnome-utils.h
 Gnome specific utility functions.

Functions

void gnc_gnome_utils_init (void)
 Initialize the gnome-utils library Should be run once before using any gnome-utils features.
void gnc_add_css_file (void)
 Load a gtk resource configuration file to customize gtk appearance and behaviour.
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 given file.
void gnc_launch_doclink (GtkWindow *parent, const char *uri)
 Launch the default browser and open the provided URI.
GtkWidget * gnc_gnome_get_pixmap (const char *name)
 Given a file name, find and load the requested pixmap.
GdkPixbuf * gnc_gnome_get_gdkpixbuf (const char *name)
 Given a file name, find and load the requested pixbuf.
void gnc_shutdown (int exit_status)
 Shutdown gnucash.
GncMainWindow * gnc_gui_init (void)
 Initialize the gnucash gui.
int gnc_ui_start_event_loop (void)
gboolean gnucash_ui_is_running (void)

Detailed Description

Function Documentation

◆ gnc_add_css_file()

void gnc_add_css_file ( void )

Load a gtk resource configuration file to customize gtk appearance and behaviour.

Definition at line 138 of file gnc-gnome-utils.c.

139{
140 GtkCssProvider *provider_user, *provider_app, *provider_fallback;
141 GdkDisplay *display;
142 GdkScreen *screen;
143 const gchar *var;
144 GError *error = 0;
145
146 provider_user = gtk_css_provider_new ();
147 provider_app = gtk_css_provider_new ();
148 provider_fallback = gtk_css_provider_new ();
149 display = gdk_display_get_default ();
150 screen = gdk_display_get_default_screen (display);
151
152 gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_fallback), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
153 gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_app), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
154 gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER);
155
156 gtk_css_provider_load_from_resource (provider_app, GNUCASH_RESOURCE_PREFIX "/gnucash.css");
157 gtk_css_provider_load_from_resource (provider_fallback, GNUCASH_RESOURCE_PREFIX "/gnucash-fallback.css");
158
159 var = gnc_userconfig_dir ();
160 if (var)
161 {
162 gchar *str;
163 str = g_build_filename (var, "gtk-3.0.css", (char *)NULL);
164 if (!gtk_css_provider_load_from_path (provider_user, str, &error))
165 {
166 PWARN ("Could not load user CSS '%s': %s", str, error->message);
167 g_clear_error (&error);
168 }
169 g_free (str);
170 }
171 g_object_unref (provider_user);
172 g_object_unref (provider_app);
173 g_object_unref (provider_fallback);
174}
const gchar * gnc_userconfig_dir(void)
Return the user's config directory for gnucash.
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ gnc_gnome_get_gdkpixbuf()

GdkPixbuf * gnc_gnome_get_gdkpixbuf ( const char * name)

Given a file name, find and load the requested pixbuf.

This routine will display an error message if it can't find the file or load the pixbuf.

Parameters
nameThe name of the pixbuf file to load.
Returns
A pointer to the pixbuf, or NULL of the file couldn't be found or loaded..

Definition at line 520 of file gnc-gnome-utils.c.

521{
522 GdkPixbuf *pixbuf;
523 GError *error = NULL;
524 char *fullname;
525
526 g_return_val_if_fail (name != NULL, NULL);
527
528 fullname = gnc_filepath_locate_pixmap (name);
529 if (fullname == NULL)
530 return NULL;
531
532 DEBUG ("Loading pixbuf file %s", fullname);
533 pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
534 if (error != NULL)
535 {
536 g_assert (pixbuf == NULL);
537 PERR ("Could not load pixbuf: %s", error->message);
538 g_error_free (error);
539 }
540 g_free (fullname);
541
542 return pixbuf;
543}
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ gnc_gnome_get_pixmap()

GtkWidget * gnc_gnome_get_pixmap ( const char * name)

Given a file name, find and load the requested pixmap.

This routine will display an error message if it can't find the file or load the pixmap.

Parameters
nameThe name of the pixmap file to load.
Returns
A pointer to the pixmap, or NULL of the file couldn't be found or loaded..

Definition at line 489 of file gnc-gnome-utils.c.

490{
491 GtkWidget *pixmap;
492 char *fullname;
493
494 g_return_val_if_fail (name != NULL, NULL);
495
496 fullname = gnc_filepath_locate_pixmap (name);
497 if (fullname == NULL)
498 return NULL;
499
500 DEBUG ("Loading pixmap file %s", fullname);
501
502 pixmap = gtk_image_new_from_file (fullname);
503 if (pixmap == NULL)
504 {
505 PERR ("Could not load pixmap");
506 }
507 g_free (fullname);
508
509 return pixmap;
510}

◆ gnc_gnome_help()

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 given file.

This routine will display an error message if it can't find the help file or can't open the help browser.

Parameters
parentThe parent window for any dialogs.
file_nameThe name of the help file.
anchorThe anchor the help browser should scroll to.

Definition at line 347 of file gnc-gnome-utils.c.

348{
349 GError *error = NULL;
350 gchar *uri = NULL;
351 gboolean success = TRUE;
352
353 if (anchor)
354 uri = g_strconcat ("help:", file_name, "/", anchor, NULL);
355 else
356 uri = g_strconcat ("help:", file_name, NULL);
357
358 DEBUG ("Attempting to opening help uri %s", uri);
359
360 if (uri)
361 success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error);
362
363 g_free (uri);
364 if (success)
365 return;
366
367 g_assert(error != NULL);
368 {
369 gnc_error_dialog (parent, "%s\n%s", _(msg_no_help_found), _(msg_no_help_reason));
370 }
371 PERR ("%s", error->message);
372 g_error_free(error);
373}

◆ gnc_gnome_utils_init()

void gnc_gnome_utils_init ( void )

Initialize the gnome-utils library Should be run once before using any gnome-utils features.

Definition at line 76 of file gnc-gnome-utils.c.

77{
78 gnc_component_manager_init ();
79
80 scm_init_sw_gnome_utils_module();
81 scm_c_use_module ("sw_gnome_utils");
82 scm_c_use_module("gnucash gnome-utils");
83}

◆ gnc_gui_init()

GncMainWindow * gnc_gui_init ( void )

Initialize the gnucash gui.

Definition at line 603 of file gnc-gnome-utils.c.

604{
605 static GncMainWindow *main_window;
606 gchar *map;
607
608 ENTER ("");
609
610 if (gnome_is_initialized)
611 return main_window;
612
613 /* use custom icon */
614 gnc_load_app_icons();
615 gtk_window_set_default_icon_name(GNC_ICON_APP);
616
617 g_set_application_name(PACKAGE_NAME);
618
620 gnc_show_splash_screen();
621
622 gnome_is_initialized = TRUE;
623
624 gnc_ui_util_init();
625 gnc_configure_date_format();
626 gnc_configure_date_completion();
627
628 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
629 GNC_PREF_DATE_FORMAT,
630 gnc_configure_date_format,
631 NULL);
632 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
633 GNC_PREF_DATE_COMPL_THISYEAR,
634 gnc_configure_date_completion,
635 NULL);
636 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
637 GNC_PREF_DATE_COMPL_SLIDING,
638 gnc_configure_date_completion,
639 NULL);
640 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
641 GNC_PREF_DATE_BACKMONTHS,
642 gnc_configure_date_completion,
643 NULL);
644 gnc_prefs_register_group_cb (GNC_PREFS_GROUP_GENERAL,
645 gnc_gui_refresh_all,
646 NULL);
647
648 gnc_file_set_shutdown_callback (gnc_shutdown);
649
650 main_window = gnc_main_window_new ();
651 // Bug#350993:
652 // gtk_widget_show (GTK_WIDGET (main_window));
653 gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
654
655
656 map = gnc_build_userdata_path(ACCEL_MAP_NAME);
657 if (!g_file_test (map, G_FILE_TEST_EXISTS))
658 {
659 gchar *text = NULL;
660 gsize length;
661 gchar *map_source;
662 gchar *data_dir = gnc_path_get_pkgdatadir();
663#ifdef MAC_INTEGRATION
664 map_source = g_build_filename (data_dir, "ui", "accelerator-map-osx", NULL);
665#else
666 map_source = g_build_filename (data_dir, "ui", "accelerator-map", NULL);
667#endif /* MAC_INTEGRATION */
668
669 if (map_source && g_file_get_contents (map_source, &text, &length, NULL))
670 {
671 if (length)
672 g_file_set_contents (map, text, length, NULL);
673 g_free (text);
674 }
675 g_free (map_source);
676 g_free(data_dir);
677 }
678
679 gtk_accel_map_load(map);
680 g_free(map);
681
682 /* Load css configuration file */
684
685 gnc_totd_dialog (gnc_get_splash_screen (), TRUE);
686
687 LEAVE ("");
688 return main_window;
689}
GncMainWindow * gnc_main_window_new(void)
Create a new gnc main window plugin.
void gnc_add_css_file(void)
Load a gtk resource configuration file to customize gtk appearance and behaviour.
void gnc_shutdown(int exit_status)
Shutdown gnucash.
#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
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
guint gnc_prefs_register_group_cb(const gchar *group, gpointer func, gpointer user_data)
Register a callback for when any preference in the settings group is changed.
void gnc_prefs_init(void)
This function is called early in the load process to preload a number of preferences from the setting...

◆ gnc_launch_doclink()

void gnc_launch_doclink ( GtkWindow * parent,
const char * uri )

Launch the default browser and open the provided URI.

Definition at line 442 of file gnc-gnome-utils.c.

443{
444 GError *error = NULL;
445 gboolean success;
446
447 if (!uri)
448 return;
449
450 DEBUG ("Attempting to open uri %s", uri);
451
452 success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error);
453
454 if (success)
455 return;
456
457 g_assert (error != NULL);
458 {
459 gchar *error_uri = NULL;
460 const gchar *message =
461 _("GnuCash could not open the linked document:");
462
463 if (gnc_uri_is_file_uri (uri))
464 {
465 gchar *uri_scheme = gnc_uri_get_scheme (uri);
466 error_uri = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme);
467 g_free (uri_scheme);
468 }
469 else
470 error_uri = g_strdup (uri);
471
472 gnc_error_dialog (parent, "%s\n%s", message, error_uri);
473 g_free (error_uri);
474 }
475 PERR ("%s", error->message);
476 g_error_free (error);
477}
gchar * gnc_uri_get_scheme(const gchar *uri)
Extracts the scheme from a uri.
gboolean gnc_uri_is_file_uri(const gchar *uri)
Checks if the given uri defines a file (as opposed to a network service like a database or web url).

◆ gnc_shutdown()

void gnc_shutdown ( int exit_status)

Shutdown gnucash.

This function will initiate an orderly shutdown, and when that has finished it will exit the program.

Parameters
exit_statusThe exit status for the program.

Definition at line 751 of file gnc-gnome-utils.c.

752{
753 if (gnucash_ui_is_running())
754 {
755 if (!gnome_is_terminating)
756 {
757 if (gnc_file_query_save (gnc_ui_get_main_window (NULL), FALSE))
758 {
759 gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
760 gnc_gui_shutdown();
761 }
762 }
763 }
764 else
765 {
766 gnc_gui_destroy();
767 gnc_hook_run(HOOK_SHUTDOWN, NULL);
769 exit(exit_status);
770 }
771}
void gnc_engine_shutdown(void)
Called to shutdown the engine.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.

◆ gnc_ui_start_event_loop()

int gnc_ui_start_event_loop ( void )

Definition at line 578 of file gnc-gnome-utils.c.

579{
580 guint id;
581
582 gnome_is_running = TRUE;
583
584 id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 10000, /* 10 secs */
585 gnc_ui_check_events, NULL, NULL);
586
587 scm_call_1(scm_c_eval_string("gnc:set-ui-status"), SCM_BOOL_T);
588
589 /* Enter gnome event loop */
590 gtk_main ();
591
592 g_source_remove (id);
593
594 scm_call_1(scm_c_eval_string("gnc:set-ui-status"), SCM_BOOL_F);
595
596 gnome_is_running = FALSE;
597 gnome_is_terminating = FALSE;
598
599 return 0;
600}

◆ gnucash_ui_is_running()

gboolean gnucash_ui_is_running ( void )

Definition at line 692 of file gnc-gnome-utils.c.

693{
694 return gnome_is_running;
695}