Filenames

From Inkscape Wiki
Jump to navigation Jump to search

Filenames should be std::strings but presented as Glib::ustings (UTF8) in GUI elements. Glib has functions to convert back and forth. All Glib file utility functions take and return std::strings (other than those converting between types). We use these functions throughout our code, often ignoring implicit conversions between std::string and Glib::ustring (or UTF8 encoded and not-encoded strings of type char*).

Gtk4 Changes

Gtk4 makes several changes that impact our use of strings:

Use of Glib::StdStringView and Glib::UStringView

Many functions take these types as arguments. It's an error to mix them.

  1. Glib::StdStringView : Different from std::string_view in that only holds null-terminated strings. One can pass in a Glib::ustring via Glib::ustring::c_str().
  2. Glib::UStringView : UTF8 encoded string. One can pass in a std::string using std::string::c_str().

Return Gio::File rather than filenames (std::strings) in File dialogs

Gio::Files handle std::string/Glib::ustrings properly. We should be using them and have some code that already does.

Updating Our Code

This is quite messy. Our code file handling code is divided over many file:

  • src/file.h: Several file opening functions (that should be removed). Calls document_new in inkscape-application.h. Also contains Import dialog (should be moved). Calls Extension::Open.
  • src/inkscape-application.h: Functions for opening documents and creating windows. Calls ink_file_new, ink_file_open(data), ink_file_open(Gio::File) in io/file.h.
  • src/io/file.h: Functions ink_file_new, ink_file_open. Calls SPDocument::createNewDoc() or SPDocument::createNewDocFromMem() in src/document.h
  • src/document.h: Functions for creating documents by first creating the XML via calling sp_rper_read_file(filename, SP_SVG_NS_URI), sp_repr_document_new("svg:svg"), sp_repr_read_mem(char const* buffer...)
  • src/xml/repr.h (repr-io.cpp): Functions that use libxml2 to extract out the XML tree from files.
  • src/extension/internal/xxx: Functions to open various file types.
  • src/extension/internal.svg.h: Open SVG files: calls functions in src/document.h.
  • src/io/sys.h: Various functions that assume filenames are in UTF8. Most functions in this file should be removed.