URIs and Filenames

From Inkscape Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Inkscape's handling of URIs and Filenames is a complete mess!

Done

To do

  • Put all our own URI and Filename handling code in src/io (or at least list in README in that directory).
  • Convert all routines to use:
    • std::string (byte string) for file names and paths.
    • Glib::ustring (unicode string) for URIs
  • Rely on Glib functions where possible. Glib functions handle many of the WIN32/LINUX/MAC issues automatically.
    • Use Gio::File class.
    • Use Glib utility and conversion functions (see below).
  • Remove 'sodipodi-absref' as this leaks user directory information.
  • Clarify whether/when to use these classes (most stuff in Inkscape::IO should probably be removed, Tav):

Notes

  • URIs should always use '/'. You cannot use Glib filename functions to handle URIs as they will use '/' or '\' depending on operating system.
  • Use relative paths (URIs!) where possible as this allows moving documents with resources together.

glibmm Documentation

Misc. Utility Functions

bool Glib::path_is_absolute (const std::string& filename)
Returns true if the given filename is an absolute file name, i.e. it contains a full path from the root directory such as "/usr/local" on UNIX or "C:\\windows" on Windows systems. More...
std::string Glib::path_skip_root (const std::string& filename)
Returns the remaining part of filename after the root component, i.e. after the "/" on UNIX or "C:\\" on Windows. More...
std::string Glib::path_get_basename (const std::string& filename)
Gets the name of the file without any leading directory components. More...
std::string Glib::path_get_dirname (const std::string& filename)
Gets the directory components of a file name. More...
std::string Glib::build_filename (const Glib::ArrayHandle< std::string >& elements)
Creates a filename from a series of elements using the correct separator for filenames. More...
std::string Glib::build_filename (const std::string& elem1, const std::string& elem2)
Creates a filename from two elements using the correct separator for filenames. More...
std::string Glib::build_filename (const std::string& elem1, const std::string& elem2, const std::string& elem3)
Creates a filename from three elements using the correct separator for filenames. More...

etc.

Conversions

Glib::ustring Glib::filename_to_utf8 (const std::string& opsys_string)
Converts a string which is in the encoding used for filenames into a UTF-8 string.
std::string Glib::filename_from_utf8 (const Glib::ustring& utf8_string)
Converts a string from UTF-8 to the encoding used for filenames.
std::string Glib::filename_from_uri (const Glib::ustring& uri, Glib::ustring& hostname)
Converts an escaped UTF-8 encoded URI to a local filename in the encoding used for filenames.
std::string Glib::filename_from_uri (const Glib::ustring& uri)
Converts an escaped UTF-8 encoded URI to a local filename in the encoding used for filenames.
Glib::ustring Glib::filename_to_uri (const std::string& filename, const Glib::ustring& hostname)
Converts an absolute filename to an escaped UTF-8 encoded URI.
Glib::ustring Glib::filename_to_uri (const std::string& filename)
Converts an absolute filename to an escaped UTF-8 encoded URI.
Glib::ustring Glib::filename_display_basename (const std::string& filename)
Returns the display basename for the particular filename, guaranteed to be valid UTF-8.
Glib::ustring Glib::filename_display_name (const std::string& filename)
Converts a filename into a valid UTF-8 string.