From 006405dc77fafe2d0aec0975bd882d24998d1545 Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 4 May 2009 05:20:54 +0000 Subject: [PATCH] Implement warning of prior errors. --- src/application/editor.cpp | 3 +-- src/inkscape.cpp | 7 +++++++ src/inkview.cpp | 2 +- src/preferences.cpp | 21 ++++++++++++++++++++- src/preferences.h | 17 +++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/application/editor.cpp b/src/application/editor.cpp index c0501389f..49010efdc 100644 --- a/src/application/editor.cpp +++ b/src/application/editor.cpp @@ -65,8 +65,7 @@ Editor::Editor (gint /*argc*/, char **argv) sp_object_type_register ("sodipodi:namedview", SP_TYPE_NAMEDVIEW); sp_object_type_register ("sodipodi:guide", SP_TYPE_GUIDE); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->load(true, false); + Inkscape::Preferences::get(); // Ensure preferences are loaded } bool diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 5d9e217a8..abfffefc2 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -787,6 +787,13 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); InkErrorHandler* handler = new InkErrorHandler(use_gui); prefs->setErrorHandler(handler); + { + Glib::ustring msg; + Glib::ustring secondary; + if (prefs->getLastError( msg, secondary )) { + handler->handleError(msg, secondary); + } + } inkscape_load_menus(inkscape); sp_input_load_from_preferences(); diff --git a/src/inkview.cpp b/src/inkview.cpp index cd9d5524b..5cfde2c81 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -213,7 +213,7 @@ main (int argc, const char **argv) LIBXML_TEST_VERSION Inkscape::GC::init(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::Preferences::get(); // ensure preferences are initialized gtk_init (&argc, (char ***) &argv); diff --git a/src/preferences.cpp b/src/preferences.cpp index a6409b5ba..071dbf91e 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -54,7 +54,8 @@ Preferences::Preferences() : _prefs_filename(""), _prefs_doc(0), _errorHandler(0), - _writable(false) + _writable(false), + _hasError(false) { // profile_path essentailly returns the argument prefixed by the profile directory. gchar *path = profile_path(NULL); @@ -224,6 +225,21 @@ void Preferences::save() sp_repr_save_file(_prefs_doc, utf8name.data()); } +bool Preferences::getLastError( Glib::ustring& primary, Glib::ustring& secondary ) +{ + bool result = _hasError; + if ( _hasError ) { + primary = _lastErrPrimary; + secondary = _lastErrSecondary; + _hasError = false; + _lastErrPrimary.clear(); + _lastErrSecondary.clear(); + } else { + primary.clear(); + secondary.clear(); + } + return result; +} // Now for the meat. @@ -610,6 +626,9 @@ void Preferences::_keySplit(Glib::ustring const &pref_path, Glib::ustring &node_ void Preferences::_reportError(Glib::ustring const &msg, Glib::ustring const &secondary) { + _hasError = true; + _lastErrPrimary = msg; + _lastErrSecondary = secondary; if (_errorHandler) { _errorHandler->handleError(msg, secondary); } diff --git a/src/preferences.h b/src/preferences.h index 3c25a520f..7aded5a03 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -228,6 +228,20 @@ public: bool isWritable() { return _writable; } /*@}*/ + /** + * @brief Return details of the last encountered error, if any. + * + * This method will return true if an error has been encountered, and fill + * in the primary and secondary error strings of the last error. If an error + * had been encountered, this will reset it. + * + * @param string to set to the primary error message. + * @param string to set to the secondary error message. + * + * @return True if an error has occurred since last checking, false otherwise. + */ + bool getLastError( Glib::ustring& primary, Glib::ustring& secondary ); + /** * @name Iterate over directories and entries. * @{ @@ -458,9 +472,12 @@ private: std::string _prefs_basename; ///< Basename of the prefs file std::string _prefs_dir; ///< Directory in which to look for the prefs file std::string _prefs_filename; ///< Full filename (with directory) of the prefs file + Glib::ustring _lastErrPrimary; ///< Last primary error message, if any. + Glib::ustring _lastErrSecondary; ///< Last secondary error message, if any. XML::Document *_prefs_doc; ///< XML document storing all the preferences ErrorReporter* _errorHandler; ///< Pointer to object reporting errors. bool _writable; ///< Will the preferences be saved at exit? + bool _hasError; ///< Indication that some error has occurred; /// Wrapper class for XML node observers class PrefNodeObserver; -- 2.30.2