diff --git a/src/core-utils/gnc-filepath-utils.c b/src/core-utils/gnc-filepath-utils.c index 68d78b6cea..c1dc323c51 100644 --- a/src/core-utils/gnc-filepath-utils.c +++ b/src/core-utils/gnc-filepath-utils.c @@ -418,5 +418,67 @@ gnc_build_stdreports_path (const gchar *filename) return result; } +static gchar * +gnc_filepath_locate_file (const gchar *default_path, const gchar *name) +{ + gchar *fullname; + + g_return_val_if_fail (name != NULL, NULL); + + if (g_path_is_absolute (name)) + fullname = g_strdup (name); + else if (default_path) + fullname = g_build_filename (default_path, name, NULL); + else + fullname = gnc_resolve_file_path (name); + + if (!g_file_test (fullname, G_FILE_TEST_IS_REGULAR)) + { + g_error ("Could not locate file %s", name); + g_free (fullname); + return NULL; + } + + return fullname; +} + +gchar * +gnc_filepath_locate_data_file (const gchar *name) +{ + return gnc_filepath_locate_file (gnc_path_get_pkgdatadir(), name); +} + +gchar * +gnc_filepath_locate_pixmap (const gchar *name) +{ + gchar *default_path; + gchar *fullname; + + default_path = g_build_filename (gnc_path_get_pkgdatadir (), "pixmaps", NULL); + fullname = gnc_filepath_locate_file (default_path, name); + g_free(default_path); + + return fullname; +} + +gchar * +gnc_filepath_locate_ui_file (const gchar *name) +{ + gchar *default_path; + gchar *fullname; + + default_path = g_build_filename (gnc_path_get_pkgdatadir (), "ui", NULL); + fullname = gnc_filepath_locate_file (default_path, name); + g_free(default_path); + + return fullname; +} + +gchar * +gnc_filepath_locate_doc_file (const gchar *name) +{ + return gnc_filepath_locate_file (gnc_path_get_pkgdocdir(), name); +} + /* =============================== END OF FILE ========================== */ diff --git a/src/core-utils/gnc-filepath-utils.h b/src/core-utils/gnc-filepath-utils.h index 4e73414ba3..c90aab74f5 100644 --- a/src/core-utils/gnc-filepath-utils.h +++ b/src/core-utils/gnc-filepath-utils.h @@ -49,4 +49,59 @@ gchar *gnc_build_data_path (const gchar *filename); gchar *gnc_build_report_path (const gchar *filename); gchar *gnc_build_stdreports_path (const gchar *filename); +/** 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. + * + * @param name The name of the file to be found. + * + * @return 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. + */ +gchar *gnc_filepath_locate_pixmap (const gchar *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. + * + * @param name The name of the file to be found. + * + * @return 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. + */ +gchar *gnc_filepath_locate_data_file (const gchar *name); + + +/** Given a ui file name, find the file in the ui directory associated + * with this application. This routine will display an error message + * if it can't find the file. + * + * @param name The name of the file to be found. + * + * @return 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. + */ +gchar *gnc_filepath_locate_ui_file (const gchar *name); + + +/** Given a documentation file name, find the file in the doc directory + * associated with this application. This routine will display an error + * message if it can't find the file. + * + * @param name The name of the file to be found. + * + * @return 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. + */ +gchar *gnc_filepath_locate_doc_file (const gchar *name); + #endif /* GNC_FILEPATH_UTILS_H */ diff --git a/src/core-utils/gnc-path.c b/src/core-utils/gnc-path.c index e887576158..c3bcbe11eb 100644 --- a/src/core-utils/gnc-path.c +++ b/src/core-utils/gnc-path.c @@ -64,6 +64,19 @@ gchar *gnc_path_get_pkgdatadir() return result; } +/** Returns the docdir path, usually + * "$prefix/share/doc/gnucash". + * + * @returns A newly allocated string. */ +gchar *gnc_path_get_pkgdocdir() +{ + gchar *docdir = gnc_gbr_find_data_dir (DATADIR); + gchar *result = g_build_filename (docdir, "doc", "gnucash", (char*)NULL); + g_free (docdir); + //printf("Returning pkgdocdir %s\n", result); + return result; +} + /** Returns the sysconfdir path, usually * "$prefix/etc/gnucash". Needed for gnome_program_init(). * diff --git a/src/core-utils/gnc-path.h b/src/core-utils/gnc-path.h index b49a27de82..eff34ee0c0 100644 --- a/src/core-utils/gnc-path.h +++ b/src/core-utils/gnc-path.h @@ -49,6 +49,12 @@ gchar *gnc_path_get_libdir(void); * @returns A newly allocated string. */ gchar *gnc_path_get_pkgdatadir(void); +/** Returns the pkgdocdir path, usually + * "$prefix/share/doc/gnucash". + * + * @returns A newly allocated string. */ +gchar *gnc_path_get_pkgdocdir(void); + /** Returns the pkgsysconfdir path, usually * "$prefix/etc/gnucash". Needed for gnome_program_init(void). * diff --git a/src/gnome-utils/dialog-totd.c b/src/gnome-utils/dialog-totd.c index 0264a2cbe5..51699b24cd 100644 --- a/src/gnome-utils/dialog-totd.c +++ b/src/gnome-utils/dialog-totd.c @@ -30,6 +30,7 @@ #include "dialog-totd.h" #include "dialog-utils.h" #include "gnc-component-manager.h" +#include "gnc-filepath-utils.h" #include "gnc-gconf-utils.h" #include "gnc-gnome-utils.h" #include "gnc-engine.h" @@ -178,7 +179,7 @@ gnc_totd_initialize (void) GError *error; /* Find the file */ - filename = gnc_gnome_locate_data_file("tip_of_the_day.list"); + filename = gnc_filepath_locate_data_file("tip_of_the_day.list"); if (!filename) return FALSE; diff --git a/src/gnome-utils/gnc-embedded-window.c b/src/gnome-utils/gnc-embedded-window.c index 86da77d387..94efe9a309 100644 --- a/src/gnome-utils/gnc-embedded-window.c +++ b/src/gnome-utils/gnc-embedded-window.c @@ -30,6 +30,7 @@ #include "gnc-embedded-window.h" #include "gnc-engine.h" +#include "gnc-filepath-utils.h" #include "gnc-gnome-utils.h" #include "gnc-gobject-utils.h" #include "gnc-gui-query.h" @@ -364,7 +365,7 @@ gnc_embedded_window_new (const gchar *action_group_name, priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window); /* Determine the full pathname of the ui file */ - ui_fullname = gnc_gnome_locate_ui_file(ui_filename); + ui_fullname = gnc_filepath_locate_ui_file (ui_filename); priv->parent_window = enclosing_win; diff --git a/src/gnome-utils/gnc-gnome-utils.c b/src/gnome-utils/gnc-gnome-utils.c index cacd83912b..e8974ff026 100644 --- a/src/gnome-utils/gnc-gnome-utils.c +++ b/src/gnome-utils/gnc-gnome-utils.c @@ -170,60 +170,6 @@ gnc_configure_date_completion (void) } } -char * -gnc_gnome_locate_pixmap (const char *name) -{ - 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_data_file (const char *name) -{ - 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_ui_file (const char *name) -{ - 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; -} - static void gnc_gtk_add_rc_file (void) { @@ -321,7 +267,7 @@ gnc_gnome_init (int argc, char **argv, const char * version) { GdkPixbuf *buf = NULL; - fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]); + fullname = gnc_filepath_locate_pixmap(icon_filenames[idx]); if (fullname == NULL) { g_warning("couldn't find icon file [%s]", icon_filenames[idx]); @@ -570,7 +516,7 @@ gnc_gnome_get_pixmap (const char *name) g_return_val_if_fail (name != NULL, NULL); - fullname = gnc_gnome_locate_pixmap (name); + fullname = gnc_filepath_locate_pixmap (name); if (fullname == NULL) return NULL; @@ -602,7 +548,7 @@ gnc_gnome_get_gdkpixbuf (const char *name) g_return_val_if_fail (name != NULL, NULL); - fullname = gnc_gnome_locate_pixmap (name); + fullname = gnc_filepath_locate_pixmap (name); if (fullname == NULL) return NULL; diff --git a/src/gnome-utils/gnc-gnome-utils.h b/src/gnome-utils/gnc-gnome-utils.h index c830014d08..ee1d9ec156 100644 --- a/src/gnome-utils/gnc-gnome-utils.h +++ b/src/gnome-utils/gnc-gnome-utils.h @@ -40,47 +40,6 @@ /** Initialize the Gnome libraries. */ void gnc_gnome_init (int argc, char **argv, const char * version); -/** 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. - * - * @param name The name of the file to be found. - * - * @return 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. - */ -char *gnc_gnome_locate_pixmap (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. - * - * @param name The name of the file to be found. - * - * @return 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. - */ -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. - * - * @param name The name of the file to be found. - * - * @return 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. - */ -char *gnc_gnome_locate_ui_file (const char *name); - /** 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. diff --git a/src/gnome-utils/gnc-icons.c b/src/gnome-utils/gnc-icons.c index 36bfee4b9c..e799945294 100644 --- a/src/gnome-utils/gnc-icons.c +++ b/src/gnome-utils/gnc-icons.c @@ -10,6 +10,7 @@ #include #include "gnc-icons.h" +#include "gnc-filepath-utils.h" #include "gnc-gnome-utils.h" static GtkStockItem items[] = @@ -65,8 +66,8 @@ gnc_add_stock_icon_pair (GtkIconFactory *factory, char *fullname1, *fullname2; /* Find the complete path names for these files */ - fullname1 = gnc_gnome_locate_pixmap (filename1); - fullname2 = gnc_gnome_locate_pixmap (filename2); + fullname1 = gnc_filepath_locate_pixmap (filename1); + fullname2 = gnc_filepath_locate_pixmap (filename2); g_assert (fullname1 && fullname2); /* Load the pixbufs */ diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c index 1c1047db56..d8703f59dc 100644 --- a/src/gnome-utils/gnc-main-window.c +++ b/src/gnome-utils/gnc-main-window.c @@ -51,6 +51,7 @@ #include "gnc-component-manager.h" #include "gnc-engine.h" #include "gnc-file.h" +#include "gnc-filepath-utils.h" #include "gnc-gkeyfile-utils.h" #include "gnc-gnome-utils.h" #include "gnc-gobject-utils.h" @@ -2894,7 +2895,7 @@ gnc_main_window_merge_actions (GncMainWindow *window, g_return_if_fail (n_actions > 0); g_return_if_fail (filename != NULL); - pathname = gnc_gnome_locate_ui_file (filename); + pathname = gnc_filepath_locate_ui_file (filename); if (pathname == NULL) return; @@ -3304,9 +3305,9 @@ gnc_main_window_window_menu (GncMainWindow *window) { guint merge_id; #ifdef MAC_INTEGRATION - gchar *filename = gnc_gnome_locate_ui_file("gnc-windows-menu-ui-quartz.xml"); + gchar *filename = gnc_filepath_locate_ui_file("gnc-windows-menu-ui-quartz.xml"); #else - gchar *filename = gnc_gnome_locate_ui_file("gnc-windows-menu-ui.xml"); + gchar *filename = gnc_filepath_locate_ui_file("gnc-windows-menu-ui.xml"); GncMainWindowPrivate *priv; #endif GError *error = NULL; @@ -3410,7 +3411,7 @@ gnc_main_window_setup_window (GncMainWindow *window) g_signal_connect (G_OBJECT (window->ui_merge), "connect-proxy", G_CALLBACK (connect_proxy), priv->statusbar); - filename = gnc_gnome_locate_ui_file("gnc-main-window-ui.xml"); + filename = gnc_filepath_locate_ui_file("gnc-main-window-ui.xml"); /* Can't do much without a ui. */ g_assert (filename); @@ -4062,7 +4063,7 @@ get_file (const gchar *partial) { gchar *filename, *text = NULL; - filename = gnc_gnome_locate_data_file(partial); + filename = gnc_filepath_locate_doc_file(partial); g_file_get_contents(filename, &text, NULL, NULL); g_free(filename); @@ -4118,9 +4119,9 @@ gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window) logo = gnc_gnome_get_gdkpixbuf ("gnucash-icon-48x48.png"); - authors = get_file_strsplit("doc/AUTHORS"); - documenters = get_file_strsplit("doc/DOCUMENTERS"); - license = get_file("doc/LICENSE"); + authors = get_file_strsplit("AUTHORS"); + documenters = get_file_strsplit("DOCUMENTERS"); + license = get_file("LICENSE"); #ifdef GNUCASH_SVN /* Development version */ message = g_strdup_printf(_("%s This copy was built from svn r%s on %s."), diff --git a/src/gnome-utils/gnc-plugin.c b/src/gnome-utils/gnc-plugin.c index 6b6b72d4e8..113231da6e 100644 --- a/src/gnome-utils/gnc-plugin.c +++ b/src/gnome-utils/gnc-plugin.c @@ -39,6 +39,7 @@ #include "gnc-plugin.h" #include "gnc-engine.h" +#include "gnc-filepath-utils.h" #include "gnc-gconf-utils.h" #include "gnc-gnome-utils.h" #include "gnc-gobject-utils.h" @@ -381,7 +382,7 @@ gnc_plugin_add_actions (GtkUIManager *ui_merge, ui_merge, action_group, filename); gtk_ui_manager_insert_action_group (ui_merge, action_group, 0); - pathname = gnc_gnome_locate_ui_file (filename); + pathname = gnc_filepath_locate_ui_file (filename); if (pathname == NULL) { LEAVE("fail"); diff --git a/src/gnome/window-reconcile.c b/src/gnome/window-reconcile.c index 5b0d16e927..9aeaed2061 100644 --- a/src/gnome/window-reconcile.c +++ b/src/gnome/window-reconcile.c @@ -46,6 +46,7 @@ #include "gnc-component-manager.h" #include "gnc-date-edit.h" #include "gnc-event.h" +#include "gnc-filepath-utils.h" #include "gnc-gconf-utils.h" #include "gnc-gnome-utils.h" #include "gnc-main-window.h" @@ -1744,7 +1745,7 @@ recnWindowWithBalance (GtkWidget *parent, Account *account, gtk_ui_manager_insert_action_group (recnData->ui_merge, action_group, 0); - filename = gnc_gnome_locate_ui_file("gnc-reconcile-window-ui.xml"); + filename = gnc_filepath_locate_ui_file("gnc-reconcile-window-ui.xml"); /* Can't do much without a ui. */ g_assert (filename);