GnuCash 2.3.0
Files | Functions
Gnome-specific GUI handling.
GUI

Files

file  gnc-gnome-utils.h
 

Gnome specific utility functions.


Functions

void gnc_gnome_init (int argc, char **argv, const char *version)
char * gnc_gnome_locate_pixmap (const char *name)
char * gnc_gnome_locate_data_file (const char *name)
char * gnc_gnome_locate_ui_file (const char *name)
void gnc_gnome_help (const char *file_name, const char *anchor)
GtkWidget * gnc_gnome_get_pixmap (const char *name)
GdkPixbuf * gnc_gnome_get_gdkpixbuf (const char *name)
void gnc_shutdown (int exit_status)
GncMainWindowgnc_gui_init (void)
int gnc_ui_start_event_loop (void)
gboolean gnucash_ui_is_running (void)

Function Documentation

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

{
    GdkPixbuf *pixbuf;
    GError *error = NULL;
    char *fullname;

    g_return_val_if_fail (name != NULL, NULL);

    fullname = gnc_gnome_locate_pixmap (name);
    if (fullname == NULL)
        return NULL;

    DEBUG ("Loading pixbuf file %s", fullname);
    pixbuf = gdk_pixbuf_new_from_file (fullname, &error);
    if (error != NULL)
    {
        g_assert (pixbuf == NULL);
        PERR ("Could not load pixbuf: %s", error->message);
        g_error_free (error);
    }
    g_free (fullname);

    return pixbuf;
}
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 567 of file gnc-gnome-utils.c.

{
    GtkWidget *pixmap;
    char *fullname;

    g_return_val_if_fail (name != NULL, NULL);

    fullname = gnc_gnome_locate_pixmap (name);
    if (fullname == NULL)
        return NULL;

    DEBUG ("Loading pixmap file %s", fullname);

    pixmap = gtk_image_new_from_file (fullname);
    if (pixmap == NULL)
    {
        PERR ("Could not load pixmap");
    }
    g_free (fullname);

    return pixmap;
}
void gnc_gnome_help ( const char *  file_name,
const char *  anchor 
)

Launch the default gnome help browser 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:
file_nameThe name of the help file.
anchorThe anchor the help browser should scroll to..
Returns:
the full path name of the file, or NULL of the file can't be found.

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

{
    GError *error = NULL;

    DEBUG ("Attempting to opening help file %s", file_name);
    if (gnome_help_display (file_name, anchor, &error))
        return;

    g_assert(error != NULL);
    {
        const gchar *message =
            _("GnuCash could not find the files for the help documentation.  "
              "This is likely because the 'gnucash-docs' package is not installed.");
        gnc_error_dialog(NULL, "%s", message);
    }
    PERR ("%s", error->message);
    g_error_free(error);
}
void gnc_gnome_init ( int  argc,
char **  argv,
const char *  version 
)

Initialize the Gnome libraries.

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

{
    GError *error = NULL;
    gchar *prefix = gnc_path_get_prefix ();
    gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
    gchar *pkglibdir = gnc_path_get_pkglibdir ();
    gboolean installation_ok = TRUE;

    /* Verify all the various directory before proceeding */
    if (!g_file_test(pkgdatadir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation data directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgdatadir);
        installation_ok = FALSE;
    }
    if (!g_file_test(pkglibdir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation lib directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkglibdir);
        installation_ok = FALSE;
    }

    if (!g_file_test(pkgsysconfdir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation sysconf directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgsysconfdir);
        installation_ok = FALSE;
    }

    gnc_gtk_add_rc_file();
    gnucash_program = gnome_program_init(
                          "gnucash", version, LIBGNOMEUI_MODULE,
                          argc, argv,
                          GNOME_PARAM_APP_PREFIX, prefix,
                          GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
                          GNOME_PARAM_APP_DATADIR, pkgdatadir,
                          GNOME_PARAM_APP_LIBDIR, pkglibdir,
                          GNOME_PARAM_NONE);
    if (!installation_ok)
    {
        /* The following string does not need translation because if
         * it shows up, the program is unusable anyway. */
        gnc_error_dialog(NULL, "The installation directories were not found.\n\ndatadir=%s\nlibdir=%s\nsysconfdir=%s\n\nYour installation is incomplete and cannot be run.",
                         pkgdatadir, pkglibdir, pkgsysconfdir);
        /* gnc_error_dialog must not be called before gnome_program_init. */
    }

    g_free (prefix);
    g_free (pkgsysconfdir);
    g_free (pkgdatadir);
    g_free (pkglibdir);

    /* Did the installation directory check fail? Terminate
     * immediately because it will inevitably fail in the glade file
     * lookup. */
    if (!installation_ok)
    {
        /* No correct installation? Shut down immediately. */
        exit(-1);
    }

#ifdef G_OS_WIN32
    /* workaround for bug #421792 */
    xmlCleanupInputCallbacks();
#endif

    /* initialization required for gtkhtml (is it also needed for webkit?) */
    gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

    /* use custom icon */
    {
        int idx;
        char *icon_filenames[] = {"gnucash-icon-16x16.png",
                                  "gnucash-icon-32x32.png",
                                  "gnucash-icon-48x48.png",
                                  NULL
                                 };
        GList *icons = NULL;
        char *fullname, *name_iter;

        for (idx = 0; icon_filenames[idx] != NULL; idx++)
        {
            GdkPixbuf *buf = NULL;

            fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]);
            if (fullname == NULL)
            {
                g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
                continue;
            }

            buf = gnc_gnome_get_gdkpixbuf(fullname);
            if (buf == NULL)
            {
                g_warning("error loading image from [%s]", fullname);
                g_free(fullname);
                continue;
            }
            g_free(fullname);
            icons = g_list_append(icons, buf);
        }

        gtk_window_set_default_icon_list(icons);
        g_list_foreach(icons, (GFunc)g_object_unref, NULL);
        g_list_free(icons);
    }

    assistant_gconf_install_check_schemas();

    return;
}
char* gnc_gnome_locate_data_file ( const char *  name)

Given a file name, find the file in the directories associated with this application. This routine will display an error message if it can't find the file.

Parameters:
nameThe name of the file to be found.
Returns:
the full path name of the file, or NULL of the file can't be found.
Note:
It is the caller's responsibility to free the returned string.

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

{
    char *fullname;

    g_return_val_if_fail (name != NULL, NULL);

    fullname = gnome_program_locate_file (gnucash_program,
                                          GNOME_FILE_DOMAIN_APP_DATADIR,
                                          name, TRUE, NULL);

    if (fullname == NULL)
    {
        PERR ("Could not locate file %s", name);
        return NULL;
    }

    return fullname;
}
char* gnc_gnome_locate_pixmap ( const char *  name)

Given a pixmap/pixbuf file name, find the file in the pixmap directory associated with this application. This routine will display an error message if it can't find the file.

Parameters:
nameThe name of the file to be found.
Returns:
the full path name of the file, or NULL of the file can't be found.
Note:
It is the caller's responsibility to free the returned string.

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

{
    char *fullname;

    g_return_val_if_fail (name != NULL, NULL);

    fullname = gnome_program_locate_file (gnucash_program,
                                          GNOME_FILE_DOMAIN_APP_PIXMAP,
                                          name, TRUE, NULL);
    if (fullname == NULL)
    {
        PERR ("Could not locate pixmap/pixbuf file %s", name);
        return NULL;
    }

    return fullname;
}
char* gnc_gnome_locate_ui_file ( const char *  name)

Given a file name, find the file in the directories associated with this application. This routine will display an error message if it can't find the file.

Parameters:
nameThe name of the file to be found.
Returns:
the full path name of the file, or NULL of the file can't be found.
Note:
It is the caller's responsibility to free the returned string.

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

{
    char *partial;
    char *fullname;

    g_return_val_if_fail (name != NULL, NULL);

    partial = g_strdup_printf("ui/%s", name);
    fullname = gnc_gnome_locate_data_file(partial);
    g_free(partial);

    return fullname;
}
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 798 of file gnc-gnome-utils.c.

{
    if (gnucash_ui_is_running())
    {
        if (!gnome_is_terminating)
        {
            if (gnc_file_query_save(FALSE))
            {
                gnc_hook_run(HOOK_UI_SHUTDOWN, NULL);
                gnc_gui_shutdown();
            }
        }
    }
    else
    {
        gnc_gui_destroy();
        gnc_hook_run(HOOK_SHUTDOWN, NULL);
        gnc_engine_shutdown();
        exit(exit_status);
    }
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines