Eliminate gnome dependency in file location functions

As a side effect, they can now be grouped together with
our other file location functions in core-utils. They
no longer depend on any gui library.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22377 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens
2012-09-10 19:21:38 +00:00
parent 05a6a1cc87
commit b3dd4de2a2
12 changed files with 159 additions and 112 deletions

View File

@@ -418,5 +418,67 @@ gnc_build_stdreports_path (const gchar *filename)
return result; 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 ========================== */ /* =============================== END OF FILE ========================== */

View File

@@ -49,4 +49,59 @@ gchar *gnc_build_data_path (const gchar *filename);
gchar *gnc_build_report_path (const gchar *filename); gchar *gnc_build_report_path (const gchar *filename);
gchar *gnc_build_stdreports_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 */ #endif /* GNC_FILEPATH_UTILS_H */

View File

@@ -64,6 +64,19 @@ gchar *gnc_path_get_pkgdatadir()
return result; 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 /** Returns the sysconfdir path, usually
* "$prefix/etc/gnucash". Needed for gnome_program_init(). * "$prefix/etc/gnucash". Needed for gnome_program_init().
* *

View File

@@ -49,6 +49,12 @@ gchar *gnc_path_get_libdir(void);
* @returns A newly allocated string. */ * @returns A newly allocated string. */
gchar *gnc_path_get_pkgdatadir(void); 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 /** Returns the pkgsysconfdir path, usually
* "$prefix/etc/gnucash". Needed for gnome_program_init(void). * "$prefix/etc/gnucash". Needed for gnome_program_init(void).
* *

View File

@@ -30,6 +30,7 @@
#include "dialog-totd.h" #include "dialog-totd.h"
#include "dialog-utils.h" #include "dialog-utils.h"
#include "gnc-component-manager.h" #include "gnc-component-manager.h"
#include "gnc-filepath-utils.h"
#include "gnc-gconf-utils.h" #include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-engine.h" #include "gnc-engine.h"
@@ -178,7 +179,7 @@ gnc_totd_initialize (void)
GError *error; GError *error;
/* Find the file */ /* 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) if (!filename)
return FALSE; return FALSE;

View File

@@ -30,6 +30,7 @@
#include "gnc-embedded-window.h" #include "gnc-embedded-window.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-filepath-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h" #include "gnc-gobject-utils.h"
#include "gnc-gui-query.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); priv = GNC_EMBEDDED_WINDOW_GET_PRIVATE(window);
/* Determine the full pathname of the ui file */ /* 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; priv->parent_window = enclosing_win;

View File

@@ -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 static void
gnc_gtk_add_rc_file (void) gnc_gtk_add_rc_file (void)
{ {
@@ -321,7 +267,7 @@ gnc_gnome_init (int argc, char **argv, const char * version)
{ {
GdkPixbuf *buf = NULL; GdkPixbuf *buf = NULL;
fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]); fullname = gnc_filepath_locate_pixmap(icon_filenames[idx]);
if (fullname == NULL) if (fullname == NULL)
{ {
g_warning("couldn't find icon file [%s]", icon_filenames[idx]); 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); g_return_val_if_fail (name != NULL, NULL);
fullname = gnc_gnome_locate_pixmap (name); fullname = gnc_filepath_locate_pixmap (name);
if (fullname == NULL) if (fullname == NULL)
return NULL; return NULL;
@@ -602,7 +548,7 @@ gnc_gnome_get_gdkpixbuf (const char *name)
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
fullname = gnc_gnome_locate_pixmap (name); fullname = gnc_filepath_locate_pixmap (name);
if (fullname == NULL) if (fullname == NULL)
return NULL; return NULL;

View File

@@ -40,47 +40,6 @@
/** Initialize the Gnome libraries. */ /** Initialize the Gnome libraries. */
void gnc_gnome_init (int argc, char **argv, const char * version); 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 /** Launch the default gnome help browser and open to a given link
* within a given file. This routine will display an error message * 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. * if it can't find the help file or can't open the help browser.

View File

@@ -10,6 +10,7 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "gnc-icons.h" #include "gnc-icons.h"
#include "gnc-filepath-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
static GtkStockItem items[] = static GtkStockItem items[] =
@@ -65,8 +66,8 @@ gnc_add_stock_icon_pair (GtkIconFactory *factory,
char *fullname1, *fullname2; char *fullname1, *fullname2;
/* Find the complete path names for these files */ /* Find the complete path names for these files */
fullname1 = gnc_gnome_locate_pixmap (filename1); fullname1 = gnc_filepath_locate_pixmap (filename1);
fullname2 = gnc_gnome_locate_pixmap (filename2); fullname2 = gnc_filepath_locate_pixmap (filename2);
g_assert (fullname1 && fullname2); g_assert (fullname1 && fullname2);
/* Load the pixbufs */ /* Load the pixbufs */

View File

@@ -51,6 +51,7 @@
#include "gnc-component-manager.h" #include "gnc-component-manager.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-file.h" #include "gnc-file.h"
#include "gnc-filepath-utils.h"
#include "gnc-gkeyfile-utils.h" #include "gnc-gkeyfile-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-gobject-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 (n_actions > 0);
g_return_if_fail (filename != NULL); g_return_if_fail (filename != NULL);
pathname = gnc_gnome_locate_ui_file (filename); pathname = gnc_filepath_locate_ui_file (filename);
if (pathname == NULL) if (pathname == NULL)
return; return;
@@ -3304,9 +3305,9 @@ gnc_main_window_window_menu (GncMainWindow *window)
{ {
guint merge_id; guint merge_id;
#ifdef MAC_INTEGRATION #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 #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; GncMainWindowPrivate *priv;
#endif #endif
GError *error = NULL; 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_signal_connect (G_OBJECT (window->ui_merge), "connect-proxy",
G_CALLBACK (connect_proxy), priv->statusbar); 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. */ /* Can't do much without a ui. */
g_assert (filename); g_assert (filename);
@@ -4062,7 +4063,7 @@ get_file (const gchar *partial)
{ {
gchar *filename, *text = NULL; 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_file_get_contents(filename, &text, NULL, NULL);
g_free(filename); 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"); logo = gnc_gnome_get_gdkpixbuf ("gnucash-icon-48x48.png");
authors = get_file_strsplit("doc/AUTHORS"); authors = get_file_strsplit("AUTHORS");
documenters = get_file_strsplit("doc/DOCUMENTERS"); documenters = get_file_strsplit("DOCUMENTERS");
license = get_file("doc/LICENSE"); license = get_file("LICENSE");
#ifdef GNUCASH_SVN #ifdef GNUCASH_SVN
/* Development version */ /* Development version */
message = g_strdup_printf(_("%s This copy was built from svn r%s on %s."), message = g_strdup_printf(_("%s This copy was built from svn r%s on %s."),

View File

@@ -39,6 +39,7 @@
#include "gnc-plugin.h" #include "gnc-plugin.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-filepath-utils.h"
#include "gnc-gconf-utils.h" #include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h" #include "gnc-gobject-utils.h"
@@ -381,7 +382,7 @@ gnc_plugin_add_actions (GtkUIManager *ui_merge,
ui_merge, action_group, filename); ui_merge, action_group, filename);
gtk_ui_manager_insert_action_group (ui_merge, action_group, 0); 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) if (pathname == NULL)
{ {
LEAVE("fail"); LEAVE("fail");

View File

@@ -46,6 +46,7 @@
#include "gnc-component-manager.h" #include "gnc-component-manager.h"
#include "gnc-date-edit.h" #include "gnc-date-edit.h"
#include "gnc-event.h" #include "gnc-event.h"
#include "gnc-filepath-utils.h"
#include "gnc-gconf-utils.h" #include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-main-window.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); 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. */ /* Can't do much without a ui. */
g_assert (filename); g_assert (filename);