gnucash/libgnucash/core-utils/gnc-filepath-utils.h

173 lines
7.1 KiB
C
Raw Normal View History

/********************************************************************\
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 *
* *
* 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 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
/**
* @file gnc-filepath-utils.h
* @brief File path resolution utility functions
* @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
/** The gnc_resolve_file_path() routine is a utility that will accept
* 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);
Rework directory determination in CMake builds. Sets paths for finding componenents depending on the state of ENABLE_BINRELOC, GNC_UNINSTALLED, GNC_BUILDDIR and whether any install paths have been set outside of CMAKE_INSTALL_PREFIX. GNUInstallDirs changes the name of CMAKE_INSTALL_LIBDIR depending on the operating system and distro. When CMAKE_INSTALL_PREFIX is /usr, /usr/local, or any subdirectory of /opt it also changes CMAKE_INSTALL_FULL_SYSCONFDIR to /etc. An earlier commit by Aaron Laws mirrors the name of CMAKE_INSTALL_LIBDIR to the build library directory. It's possible for builders to set any of the install directories anywhere they please. Setting any directory outside of CMAKE_INSTALL_PREFIX breaks Binreloc so the toplevel CMakeLists.txt now detects that and disables Binreloc. If Binreloc is enabled then all path queries use it to find paths. This works in the build directory because the gnucash executable and all of the test programs are in build_directory/bin and LIBDIR, DATADIR, and SYSCONFDIR can be found in the same root path. If Binreloc is disabled then in order to build or run programs from the build directory one must set GNC_UNINSTALLED and set GNC_BUILDDIR to the absolute path of the build directory. When those are set GNC_BUILDDIR replaces CMAKE_INSTALL_PREFIX in all paths that are subdirectories of CMAKE_INSTALL_PREFIX; paths that are not in CMAKE_INSTALL_PREFIX are appended whole to GNC_BUILDDIR. This process is constent between CMake and gnc_path_get_foo. GnuCash is unlikely to run from a DESTDIR without Binreloc.
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);
/** 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);
/** @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);
/** @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.
*
* @return a migration message when files got copied from the old location, NULL otherwise
*/
char * gnc_filepath_init (void);
const gchar *gnc_userdata_dir (void);
gchar *gnc_build_userdata_path (const gchar *filename);
gchar *gnc_build_book_path (const gchar *filename);
gchar *gnc_build_translog_path (const gchar *filename);
gchar *gnc_build_data_path (const gchar *filename);
gchar *gnc_build_report_path (const gchar *filename);
gchar *gnc_build_stdreports_path (const gchar *filename);
const gchar *gnc_userconfig_dir (void);
/** 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 */