Difference between revisions of "URIs and Filenames"

From Inkscape Wiki
Jump to navigation Jump to search
(Inkscape::URI, Inkscape::IO::UriInputStream)
(Done section)
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
* 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. <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>).
* 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>).
== Done ==
* [https://gitlab.com/inkscape/inkscape/merge_requests/364 Merge Request !364] (<code>Inkscape::URI</code> refactoring)
* [https://gitlab.com/inkscape/inkscape/merge_requests/437 Merge Request !437] (<code>Inkscape::URI</code> complete documentation and testing)


== To do ==
== To do ==
Line 14: Line 19:
** 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:
* Clarify whether/when to use these classes (most stuff in Inkscape::IO should probably be removed, Tav):
** <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/object/uri.h Inkscape::URI]</code>
** <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>
** <code>[https://gitlab.com/inkscape/inkscape/blob/master/src/io/uristream.h Inkscape::IO::UriInputStream]</code>
*** Why does <code>UriInputStream</code> not decode <code>data:</code> URIs?


== Notes ==
== Notes ==

Latest revision as of 14:39, 8 December 2018

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.