2004-06-13 12:23:26 -05:00
|
|
|
/********************************************************************\
|
Use a normalized uri format internally to refer to data stores.
Data stores for GC can be a file (xml or sqlite3) or a database
one some server (mysql or postgres).
Wherever it makes sense internally, data stores will be referred to
via a normalized uri:
protocol://user:password@host:port/path
Depending on the context and story type some of these parts are optional or unused.
To achieve this, a new utility interface has been setup:
gnc_uri_<xxx>_<yyy>
that can be used to manipulate the uris or convert from non-normalized
formats to normalized and back.
For example, when the user selects a file in the Open or Save As dialog,
gnc_uri_get_normalized_uri will convert the file into a normalized uri.
Or when the actual filename is needed this can be extracted with
gnc_uri_get_path.
You can also test if a uri defines a file or something else with
gnc_uri_is_file_uri.
For the complete documentation, see src/core-utils/gnc-uri-uitls.h
This commit installs gnc-uri-utils and modifies the source where it makes
sense to use its convenience functions. This concerns all functions that
had to deal with file access in some way or another, the history module
and the functions that generate the history menu list and the window titles.
Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases.
xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality.
xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path
is always returned (in case of a file uri, not for db uris). But it has been renamed to
gnc_resolve_file_path to be more consistent with the other functions.
Lastly, this commit also adds a first implementation to work with a keyring to
store and retrieve passwords, althoug
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
|
|
|
* gnc-filepath-utils.h -- file path resolution utilities *
|
2004-06-13 12:23:26 -05:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2004-06-13 12:23:26 -05:00
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file gnc-filepath-utils.h
|
2010-02-28 16:53:02 -06:00
|
|
|
* @brief File path resolution utility functions
|
2004-06-13 12:23:26 -05:00
|
|
|
* @author Copyright (c) 1998-2004 Linas Vepstas <linas@linas.org>
|
|
|
|
* @author Copyright (c) 2000 Dave Peticolas
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GNC_FILEPATH_UTILS_H
|
|
|
|
#define GNC_FILEPATH_UTILS_H
|
|
|
|
|
2010-09-08 02:14:05 -05:00
|
|
|
/** The gnc_resolve_file_path() routine is a utility that will accept
|
2004-06-13 12:23:26 -05:00
|
|
|
* a fragmentary filename as input, and resolve it into a fully
|
|
|
|
* qualified path in the file system, i.e. a path that begins with
|
|
|
|
* a leading slash. First, the current working directory is
|
|
|
|
* searched for the file. Next, the directory $HOME/.gnucash/data,
|
|
|
|
* and finally, a list of other (configurable) paths. If the file
|
|
|
|
* is not found, then the path $HOME/.gnucash/data is used. If
|
|
|
|
* $HOME is not defined, then the current working directory is
|
|
|
|
* used.
|
|
|
|
*/
|
Use a normalized uri format internally to refer to data stores.
Data stores for GC can be a file (xml or sqlite3) or a database
one some server (mysql or postgres).
Wherever it makes sense internally, data stores will be referred to
via a normalized uri:
protocol://user:password@host:port/path
Depending on the context and story type some of these parts are optional or unused.
To achieve this, a new utility interface has been setup:
gnc_uri_<xxx>_<yyy>
that can be used to manipulate the uris or convert from non-normalized
formats to normalized and back.
For example, when the user selects a file in the Open or Save As dialog,
gnc_uri_get_normalized_uri will convert the file into a normalized uri.
Or when the actual filename is needed this can be extracted with
gnc_uri_get_path.
You can also test if a uri defines a file or something else with
gnc_uri_is_file_uri.
For the complete documentation, see src/core-utils/gnc-uri-uitls.h
This commit installs gnc-uri-utils and modifies the source where it makes
sense to use its convenience functions. This concerns all functions that
had to deal with file access in some way or another, the history module
and the functions that generate the history menu list and the window titles.
Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases.
xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality.
xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path
is always returned (in case of a file uri, not for db uris). But it has been renamed to
gnc_resolve_file_path to be more consistent with the other functions.
Lastly, this commit also adds a first implementation to work with a keyring to
store and retrieve passwords, althoug
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
|
|
|
gchar *gnc_resolve_file_path (const gchar *filefrag);
|
2004-06-13 12:23:26 -05:00
|
|
|
|
2017-12-05 16:48:45 -06:00
|
|
|
/** Given a prefix and a path return the relative portion of the path.
|
|
|
|
* @param prefix The prefix that might be the first part of the path
|
|
|
|
* @param path The path from which the prefix might be removed
|
|
|
|
* @return a char* that must be g_freed containing the path without
|
|
|
|
* the prefix if path begins with prefix, otherwise a copy of path.
|
|
|
|
*/
|
|
|
|
gchar *gnc_file_path_relative_part (const gchar *prefix, const gchar *path);
|
|
|
|
|
2019-03-29 12:33:26 -05:00
|
|
|
/** Given a prefix and a relative path, return the absolute path.
|
|
|
|
* @param prefix The prefix that is the head of the path
|
|
|
|
* @param relative The path to add to the prefix to form an absolute path
|
|
|
|
* @return a char* that must be g_freed containing the absolute path.
|
|
|
|
*
|
|
|
|
* If prefix is null, then the gnc_userdata_home is used as the prefix.
|
|
|
|
*/
|
|
|
|
gchar *gnc_file_path_absolute (const gchar *prefix, const gchar *relative);
|
|
|
|
|
2012-12-12 11:42:22 -06:00
|
|
|
/** @brief Find an absolute path to a localized version of a given
|
|
|
|
* relative path to a html or html related file.
|
|
|
|
* If no localized version exists, an absolute path to the file
|
|
|
|
* is searched for. If that file doesn't exist either, returns NULL.
|
|
|
|
*
|
|
|
|
* @warning file_name should be a simple path fragment. It shouldn't
|
|
|
|
* contain xml:// or http:// or <whatever>:// other protocol specifiers.
|
|
|
|
*
|
|
|
|
* If passed a string which g_path_is_absolute declares an absolute
|
|
|
|
* path, return the argument.
|
|
|
|
*
|
|
|
|
* Otherwise, assume that file_name is a well-formed relative path and
|
|
|
|
* try to find a file with its path relative to
|
|
|
|
* \li a localized subdirectory in the html directory
|
|
|
|
* of the user's configuration directory
|
|
|
|
* (e.g. $HOME/.gnucash/html/de_DE, $HOME/.gnucash/html/en,...)
|
|
|
|
* \li a localized subdirectory in the gnucash documentation directory
|
|
|
|
* (e.g. /usr/share/doc/gnucash/C,...)
|
|
|
|
* \li the html directory of the user's configuration directory
|
|
|
|
* (e.g. $HOME/.gnucash/html)
|
|
|
|
* \li the gnucash documentation directory
|
|
|
|
* (e.g. /usr/share/doc/gnucash/)
|
|
|
|
*
|
|
|
|
* The paths are searched for in that order. If a matching file is
|
|
|
|
* found, return the absolute path to it.
|
|
|
|
|
|
|
|
* If one isn't found, return NULL.
|
|
|
|
*
|
|
|
|
* @param file_name The file path to resolve
|
|
|
|
*
|
|
|
|
* @return An absolute file path or NULL if no file is found.
|
|
|
|
*/
|
|
|
|
gchar *gnc_path_find_localized_html_file (const gchar *file_name);
|
|
|
|
|
2017-08-23 10:42:54 -05:00
|
|
|
/** @brief Initializes the gnucash user data directory.
|
|
|
|
* This function should be called very early at startup (before any
|
|
|
|
* other of the user data directory related function gets called).
|
|
|
|
*
|
|
|
|
* @note If the necessary directories did get created this
|
|
|
|
* function will also try to copy files from $HOME/.gnucash
|
|
|
|
* to there if that old location exists.
|
|
|
|
*
|
2018-02-19 17:48:28 -06:00
|
|
|
* @return a migration message when files got copied from the old location, NULL otherwise
|
2017-08-23 10:42:54 -05:00
|
|
|
*/
|
2018-02-19 17:48:28 -06:00
|
|
|
char * gnc_filepath_init (void);
|
2017-08-23 10:42:54 -05:00
|
|
|
|
2017-08-22 09:33:34 -05:00
|
|
|
const gchar *gnc_userdata_dir (void);
|
|
|
|
gchar *gnc_build_userdata_path (const gchar *filename);
|
2005-11-23 16:40:03 -06:00
|
|
|
gchar *gnc_build_book_path (const gchar *filename);
|
2011-03-12 09:44:39 -06:00
|
|
|
gchar *gnc_build_translog_path (const gchar *filename);
|
2010-02-28 16:53:02 -06:00
|
|
|
gchar *gnc_build_data_path (const gchar *filename);
|
2010-09-08 02:14:05 -05:00
|
|
|
gchar *gnc_build_report_path (const gchar *filename);
|
|
|
|
gchar *gnc_build_stdreports_path (const gchar *filename);
|
2005-11-23 16:40:03 -06:00
|
|
|
|
2018-02-01 09:43:10 -06:00
|
|
|
const gchar *gnc_userconfig_dir (void);
|
|
|
|
|
2012-09-10 14:21:38 -05:00
|
|
|
/** 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);
|
|
|
|
|
2004-06-13 12:23:26 -05:00
|
|
|
#endif /* GNC_FILEPATH_UTILS_H */
|