Difference between revisions of "URIs and Filenames"

From Inkscape Wiki
Jump to navigation Jump to search
(Created page with " Inkscape's handling of URIs and Filenames is a complete mess! * What some variable names claim to be URIs are actually filenames and visa-versa. *There is a lot of code dupli...")
 
(Inkscape::URI, Inkscape::IO::UriInputStream)
Line 2: Line 2:
Inkscape's handling of URIs and Filenames is a complete mess!
Inkscape's handling of URIs and Filenames is a complete mess!
* What some variable names claim to be URIs are actually filenames and visa-versa.
* What some variable names claim to be URIs are actually filenames and visa-versa.
*There is a lot of code duplication. (e.g. src/io/dir-utils.cpp and src/xml/rebase-hrefs.cpp).
* There is a lot of code duplication. (e.g. <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/io/dir-util.cpp src/io/dir-utils.cpp]</code> and <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/xml/rebase-hrefs.cpp src/xml/rebase-hrefs.cpp]</code>).


== To do ==
== To do ==


* Put all our own URI and Filename handling code in src/io (or at least list in README in that directory).
* Put all our own URI and Filename handling code in <code>src/io</code> (or at least list in README in that directory).
* Convert all routines to use:
* Convert all routines to use:
** std::string for file names and paths.
** <code>std::string</code> (byte string) for file names and paths.
** Glib::ustring for URIs
** <code>Glib::ustring</code> (unicode string) for URIs
* Rely on Glib functions where possible. Glib functions handle many of the WIN32/LINUX/MAC issues automatically.
* Rely on Glib functions where possible. Glib functions handle many of the WIN32/LINUX/MAC issues automatically.
** Use [http://manual.freeshell.org/glibmm-2.4/reference/html/classGio_1_1File.html Gio::File] class.
** Use [http://manual.freeshell.org/glibmm-2.4/reference/html/classGio_1_1File.html Gio::File] class.
** Use Glib utility and conversion functions (see below).
** Use Glib utility and conversion functions (see below).
* Remove 'sodipodi-absref' as this leaks user directory information.
* Remove 'sodipodi-absref' as this leaks user directory information.
* Clarify whether/when to use these classes:
** <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/object/uri.h Inkscape::URI]</code>
** <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/io/uristream.h Inkscape::IO::UriInputStream]</code>


== Notes ==
== Notes ==


* URIs should always use '/'. You cannot use Glib filename functions to handle URIs as they will use '/' or '\' depending on operating system.
* 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 where possible as this allows moving documents with resources together.
* Use relative paths (URIs!) where possible as this allows moving documents with resources together.


== glibmm Documentation ==
== glibmm Documentation ==

Revision as of 09:46, 24 October 2018

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

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:

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.