GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Functions
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 gtk_css_provider_load_from_path (provider_user, str, &error);
165 g_free (str);
166 }
167 g_object_unref (provider_user);
168 g_object_unref (provider_app);
169 g_object_unref (provider_fallback);
170}

◆ 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 516 of file gnc-gnome-utils.c.

517{
518 GdkPixbuf *pixbuf;
519 GError *error = NULL;
520 char *fullname;
521
522 g_return_val_if_fail (name != NULL, NULL);
523
524 fullname = gnc_filepath_locate_pixmap (name);
525 if (fullname == NULL)
526 return NULL;
527
528 DEBUG ("Loading pixbuf file %s", fullname);
529 pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
530 if (error != NULL)
531 {
532 g_assert (pixbuf == NULL);
533 PERR ("Could not load pixbuf: %s", error->message);
534 g_error_free (error);
535 }
536 g_free (fullname);
537
538 return pixbuf;
539}
#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 485 of file gnc-gnome-utils.c.

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

◆ 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 343 of file gnc-gnome-utils.c.

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

◆ 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 599 of file gnc-gnome-utils.c.

600{
601 static GncMainWindow *main_window;
602 gchar *map;
603
604 ENTER ("");
605
606 if (gnome_is_initialized)
607 return main_window;
608
609 /* use custom icon */
610 gnc_load_app_icons();
611 gtk_window_set_default_icon_name(GNC_ICON_APP);
612
613 g_set_application_name(PACKAGE_NAME);
614
616 gnc_show_splash_screen();
617
618 gnome_is_initialized = TRUE;
619
620 gnc_ui_util_init();
621 gnc_configure_date_format();
622 gnc_configure_date_completion();
623
624 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
625 GNC_PREF_DATE_FORMAT,
626 gnc_configure_date_format,
627 NULL);
628 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
629 GNC_PREF_DATE_COMPL_THISYEAR,
630 gnc_configure_date_completion,
631 NULL);
632 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
633 GNC_PREF_DATE_COMPL_SLIDING,
634 gnc_configure_date_completion,
635 NULL);
636 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
637 GNC_PREF_DATE_BACKMONTHS,
638 gnc_configure_date_completion,
639 NULL);
640 gnc_prefs_register_group_cb (GNC_PREFS_GROUP_GENERAL,
641 gnc_gui_refresh_all,
642 NULL);
643
644 gnc_file_set_shutdown_callback (gnc_shutdown);
645
646 main_window = gnc_main_window_new ();
647 // Bug#350993:
648 // gtk_widget_show (GTK_WIDGET (main_window));
649 gnc_window_set_progressbar_window (GNC_WINDOW(main_window));
650
651
652 map = gnc_build_userdata_path(ACCEL_MAP_NAME);
653 if (!g_file_test (map, G_FILE_TEST_EXISTS))
654 {
655 gchar *text = NULL;
656 gsize length;
657 gchar *map_source;
658 gchar *data_dir = gnc_path_get_pkgdatadir();
659#ifdef MAC_INTEGRATION
660 map_source = g_build_filename (data_dir, "ui", "accelerator-map-osx", NULL);
661#else
662 map_source = g_build_filename (data_dir, "ui", "accelerator-map", NULL);
663#endif /* MAC_INTEGRATION */
664
665 if (map_source && g_file_get_contents (map_source, &text, &length, NULL))
666 {
667 if (length)
668 g_file_set_contents (map, text, length, NULL);
669 g_free (text);
670 }
671 g_free (map_source);
672 g_free(data_dir);
673 }
674
675 gtk_accel_map_load(map);
676 g_free(map);
677
678 /* Load css configuration file */
680
681 gnc_totd_dialog (gnc_get_splash_screen (), TRUE);
682
683 LEAVE ("");
684 return main_window;
685}
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 438 of file gnc-gnome-utils.c.

439{
440 GError *error = NULL;
441 gboolean success;
442
443 if (!uri)
444 return;
445
446 DEBUG ("Attempting to open uri %s", uri);
447
448 success = gtk_show_uri_on_window (NULL, uri, gtk_get_current_event_time (), &error);
449
450 if (success)
451 return;
452
453 g_assert (error != NULL);
454 {
455 gchar *error_uri = NULL;
456 const gchar *message =
457 _("GnuCash could not open the linked document:");
458
459 if (gnc_uri_is_file_uri (uri))
460 {
461 gchar *uri_scheme = gnc_uri_get_scheme (uri);
462 error_uri = gnc_doclink_get_unescape_uri (NULL, uri, uri_scheme);
463 g_free (uri_scheme);
464 }
465 else
466 error_uri = g_strdup (uri);
467
468 gnc_error_dialog (parent, "%s\n%s", message, error_uri);
469 g_free (error_uri);
470 }
471 PERR ("%s", error->message);
472 g_error_free (error);
473}
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 747 of file gnc-gnome-utils.c.

748{
749 if (gnucash_ui_is_running())
750 {
751 if (!gnome_is_terminating)
752 {
753 if (gnc_file_query_save (gnc_ui_get_main_window (NULL), FALSE))
754 {
755 gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
756 gnc_gui_shutdown();
757 }
758 }
759 }
760 else
761 {
762 gnc_gui_destroy();
763 gnc_hook_run(HOOK_SHUTDOWN, NULL);
765 exit(exit_status);
766 }
767}
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 574 of file gnc-gnome-utils.c.

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

◆ gnucash_ui_is_running()

gboolean gnucash_ui_is_running ( void  )

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

689{
690 return gnome_is_running;
691}