summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Storz <eduard.braun2@gmx.de>2019-09-26 21:03:28 +0000
committerPatrick Storz <eduard.braun2@gmx.de>2019-09-26 21:03:28 +0000
commit01ec4ffba1a2013dee932d0790dd76f9ab393ef7 (patch)
treee50fb6c1469d6ebc66369cb949e537fc9ecb3672 /src
parentRemove pixman_log_error from console (diff)
downloadinkscape-01ec4ffba1a2013dee932d0790dd76f9ab393ef7.tar.gz
inkscape-01ec4ffba1a2013dee932d0790dd76f9ab393ef7.zip
Extensions: Fix filename encoding issues in error logging
(std::ostream is not properly portable unfortunately)
Diffstat (limited to 'src')
-rw-r--r--src/extension/dependency.cpp22
-rw-r--r--src/extension/dependency.h3
-rw-r--r--src/extension/extension.cpp40
-rw-r--r--src/extension/extension.h3
4 files changed, 37 insertions, 31 deletions
diff --git a/src/extension/dependency.cpp b/src/extension/dependency.cpp
index 2a04a030a..0f45d02b5 100644
--- a/src/extension/dependency.cpp
+++ b/src/extension/dependency.cpp
@@ -244,21 +244,19 @@ const gchar* Dependency::get_name()
/**
\brief Print out a dependency to a string.
*/
-std::ostream &
-operator<< (std::ostream &out_file, const Dependency & in_dep)
+Glib::ustring Dependency::info_string()
{
- out_file << _("Dependency:") << '\n';
- out_file << _(" type: ") << _(in_dep._type_str[in_dep._type]) << '\n';
- out_file << _(" location: ") << _(in_dep._location_str[in_dep._location]) << '\n';
- out_file << _(" string: ") << in_dep._string << '\n';
-
- if (in_dep._description != nullptr) {
- out_file << _(" description: ") << _(in_dep._description) << '\n';
+ Glib::ustring str = Glib::ustring::compose("%1:\n\t%2: %3\n\t%4: %5\n\t%6: %7",
+ _("Dependency"),
+ _("type"), _(_type_str[_type]),
+ _("location"), _(_location_str[_location]),
+ _("string"), _string);
+
+ if (_description) {
+ str += Glib::ustring::compose("\n\t%1: %2\n", _(" description: "), _(_description));
}
- out_file << std::flush;
-
- return out_file;
+ return str;
}
} } /* namespace Inkscape, Extension */
diff --git a/src/extension/dependency.h b/src/extension/dependency.h
index 3532eefcb..5ae685e07 100644
--- a/src/extension/dependency.h
+++ b/src/extension/dependency.h
@@ -62,10 +62,9 @@ public:
const gchar* get_name();
Glib::ustring &get_link () const;
- friend std::ostream & operator<< (std::ostream &out_file, const Dependency & in_dep);
+ Glib::ustring info_string();
}; /* class Dependency */
-std::ostream & operator<< (std::ostream &out_file, const Dependency & in_dep);
} } /* namespace Extension, Inkscape */
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp
index b8c3242a5..6ea9337cb 100644
--- a/src/extension/extension.cpp
+++ b/src/extension/extension.cpp
@@ -19,6 +19,9 @@
#include "extension.h"
#include "implementation/implementation.h"
+#include <glib/gstdio.h>
+#include <glib/gprintf.h>
+
#include <glibmm/i18n.h>
#include <gtkmm/box.h>
#include <gtkmm/frame.h>
@@ -31,6 +34,7 @@
#include "timer.h"
#include "io/resource.h"
+#include "io/sys.h"
#include "prefdialog/parameter.h"
#include "prefdialog/widget.h"
@@ -43,7 +47,7 @@ namespace Extension {
/* Inkscape::Extension::Extension */
-std::ofstream Extension::error_file;
+FILE *Extension::error_file = nullptr;
/**
\return none
@@ -294,17 +298,19 @@ Extension::check ()
retval = false;
}
- for (auto & _dep : _deps) {
+ for (auto _dep : _deps) {
if (_dep->check() == FALSE) {
- // std::cout << "Failed: " << *(_deps[i]) << std::endl;
printFailure(Glib::ustring(_("a dependency was not met.")));
- error_file << *_dep << std::endl;
+ error_file_write(_dep->info_string());
retval = false;
}
}
- if (retval)
+ if (retval) {
return imp->check(this);
+ }
+
+ error_file_write("");
return retval;
}
@@ -317,9 +323,7 @@ Extension::check ()
void
Extension::printFailure (Glib::ustring reason)
{
- error_file << _("Extension \"") << _name << _("\" failed to load because ");
- error_file << reason.raw();
- error_file << std::endl;
+ error_file_write(Glib::ustring::compose(_("Extension \"%1\" failed to load because %2"), _name, reason));
return;
}
@@ -685,14 +689,11 @@ Extension::set_param_color(const gchar *name, const guint32 color)
void
Extension::error_file_open ()
{
- gchar * ext_error_file = Inkscape::IO::Resource::log_path(EXTENSION_ERROR_LOG_FILENAME);
- gchar * filename = g_filename_from_utf8( ext_error_file, -1, nullptr, nullptr, nullptr );
- error_file.open(filename);
- if (!error_file.is_open()) {
- g_warning(_("Could not create extension error log file '%s'"),
- filename);
+ gchar *ext_error_file = Inkscape::IO::Resource::log_path(EXTENSION_ERROR_LOG_FILENAME);
+ error_file = Inkscape::IO::fopen_utf8name(ext_error_file, "w+");
+ if (!error_file) {
+ g_warning(_("Could not create extension error log file '%s'"), ext_error_file);
}
- g_free(filename);
g_free(ext_error_file);
};
@@ -700,7 +701,14 @@ Extension::error_file_open ()
void
Extension::error_file_close ()
{
- error_file.close();
+ fclose(error_file);
+};
+
+/** \brief A function to write to the error log file. */
+void
+Extension::error_file_write (Glib::ustring text)
+{
+ g_fprintf(error_file, "%s\n", text.c_str());
};
/** \brief A widget to represent the inside of an AutoGUI widget */
diff --git a/src/extension/extension.h b/src/extension/extension.h
index d28ba2efc..a2f6c19db 100644
--- a/src/extension/extension.h
+++ b/src/extension/extension.h
@@ -113,7 +113,7 @@ private:
gchar *_name = nullptr; /**< A user friendly name for the Extension */
state_t _state = STATE_UNLOADED; /**< Which state the Extension is currently in */
std::vector<Dependency *> _deps; /**< Dependencies for this extension */
- static std::ofstream error_file; /**< This is the place where errors get reported */
+ static FILE *error_file; /**< This is the place where errors get reported */
bool _gui;
protected:
@@ -214,6 +214,7 @@ public:
public:
static void error_file_open ();
static void error_file_close ();
+ static void error_file_write (Glib::ustring text);
public:
Gtk::Widget *autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal = nullptr);