X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fpreferences.h;h=5e1ccf9d6f7a451f48fd3d97b328e618035cc1a3;hb=42382dfb4164b919ffcdf03766da9f8be4e43b42;hp=3c25a520fdd9eb8bb3228a5e92458adac7225832;hpb=b50bd4043d21611cc8301b731f60b4b0cd27bfb8;p=inkscape.git diff --git a/src/preferences.h b/src/preferences.h index 3c25a520f..5e1ccf9d6 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -2,7 +2,7 @@ * @brief Singleton class to access the preferences file in a convenient way. */ /* Authors: - * Krzysztof Kosiński + * Krzysztof Kosi_ski * Jon A. Cruz * * Copyright (C) 2008,2009 Authors @@ -28,6 +28,7 @@ namespace Inkscape { class ErrorReporter { public: + virtual ~ErrorReporter() {} virtual void handleError(Glib::ustring const& primary, Glib::ustring const& secondary ) const = 0; }; @@ -57,13 +58,13 @@ public: // ############################# // ## inner class definitions ## // ############################# - + class Entry; class Observer; - + /** * @brief Base class for preference observers - * + * * If you want to watch for changes in the preferences, you'll have to * derive a class from this one and override the notify() method. */ @@ -98,13 +99,13 @@ public: * the modified preference */ virtual void notify(Preferences::Entry const &new_val) = 0; - + Glib::ustring const observed_path; ///< Path which the observer watches private: void *_data; ///< additional data used by the implementation while the observer is active }; - - + + /** * @brief Data type representing a typeless value of a preference * @@ -125,7 +126,7 @@ public: * @return If false, the default value will be returned by the getters. */ bool isValid() const { return _value != NULL; } - + /** * @brief Interpret the preference as a Boolean value. * @param def Default value if the preference is not set @@ -176,6 +177,11 @@ public: */ inline Glib::ustring getString() const; + /** + * @brief Interpret the preference as an RGBA color value. + */ + inline guint32 getColor(guint32 def) const; + /** * @brief Interpret the preference as a CSS style. * @return A CSS style that has to be unrefed when no longer necessary. Never NULL. @@ -192,7 +198,7 @@ public: * @return Inherited CSS style that has to be unrefed after use. Never NULL. */ inline SPCSSAttr *getInheritedStyle() const; - + /** * @brief Get the full path of the preference described by this Entry. */ @@ -206,13 +212,13 @@ public: Glib::ustring getEntryName() const; private: Entry(Glib::ustring const &path, void const *v) : _pref_path(path), _value(v) {} - + Glib::ustring _pref_path; void const *_value; }; // utility methods - + /** * @brief Save all preferences to the hard disk. * @@ -228,6 +234,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. * @{ @@ -249,7 +269,7 @@ public: */ std::vector getAllDirs(Glib::ustring const &path); /*@}*/ - + /** * @name Retrieve data from the preference storage. * @{ @@ -314,6 +334,10 @@ public: return getEntry(pref_path).getString(); } + guint32 getColor(Glib::ustring const &pref_path, guint32 def=0x000000ff) { + return getEntry(pref_path).getColor(def); + } + /** * @brief Retrieve a CSS style * @param pref_path Path to the retrieved preference @@ -342,7 +366,7 @@ public: */ Entry const getEntry(Glib::ustring const &pref_path); /*@}*/ - + /** * @name Update preference values. * @{ @@ -368,6 +392,11 @@ public: */ void setString(Glib::ustring const &pref_path, Glib::ustring const &value); + /** + * @brief Set an RGBA color value + */ + void setColor(Glib::ustring const &pref_path, guint32 value); + /** * @brief Set a CSS style */ @@ -404,12 +433,20 @@ public: * @name Access and manipulate the Preferences object. * @{ */ - + + + /** + * Copies values from old location to new. + */ + static void migrate( std::string const& legacyDir, std::string const& prefdir ); + /** * @brief Access the singleton Preferences object. */ static Preferences *get() { - if (!_instance) _instance = new Preferences(); + if (!_instance) { + _instance = new Preferences(); + } return _instance; } @@ -425,7 +462,7 @@ public: */ static void unload(bool save=true); /*@}*/ - + protected: /* helper methods used by Entry * This will enable using the same Entry class with different backends. @@ -436,9 +473,10 @@ protected: int _extractInt(Entry const &v); double _extractDouble(Entry const &v); Glib::ustring _extractString(Entry const &v); + guint32 _extractColor(Entry const &v); SPCSSAttr *_extractStyle(Entry const &v); SPCSSAttr *_extractInheritedStyle(Entry const &v); - + private: Preferences(); ~Preferences(); @@ -450,31 +488,34 @@ private: void _keySplit(Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key); XML::Node *_getNode(Glib::ustring const &pref_path, bool create=false); XML::Node *_findObserverNode(Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key, bool create); - + // disable copying Preferences(Preferences const &); Preferences operator=(Preferences const &); - + 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; - + typedef std::map _ObsMap; /// Map that keeps track of wrappers assigned to PrefObservers _ObsMap _observer_map; - + // privilege escalation methods for PrefNodeObserver static Entry const _create_pref_value(Glib::ustring const &, void const *ptr); static void *_get_pref_observer_data(Observer &o) { return o._data; } - + static Preferences *_instance; - + friend class PrefNodeObserver; friend class Entry; }; @@ -487,52 +528,85 @@ friend class Entry; inline bool Preferences::Entry::getBool(bool def) const { - if (!this->isValid()) return def; - return Inkscape::Preferences::get()->_extractBool(*this); + if (!this->isValid()) { + return def; + } else { + return Inkscape::Preferences::get()->_extractBool(*this); + } } inline int Preferences::Entry::getInt(int def) const { - if (!this->isValid()) return def; - return Inkscape::Preferences::get()->_extractInt(*this); + if (!this->isValid()) { + return def; + } else { + return Inkscape::Preferences::get()->_extractInt(*this); + } } inline int Preferences::Entry::getIntLimited(int def, int min, int max) const { - if (!this->isValid()) return def; - int val = Inkscape::Preferences::get()->_extractInt(*this); - return ( val >= min && val <= max ? val : def ); + if (!this->isValid()) { + return def; + } else { + int val = Inkscape::Preferences::get()->_extractInt(*this); + return ( val >= min && val <= max ? val : def ); + } } inline double Preferences::Entry::getDouble(double def) const { - if (!this->isValid()) return def; - return Inkscape::Preferences::get()->_extractDouble(*this); + if (!this->isValid()) { + return def; + } else { + return Inkscape::Preferences::get()->_extractDouble(*this); + } } inline double Preferences::Entry::getDoubleLimited(double def, double min, double max) const { - if (!this->isValid()) return def; - double val = Inkscape::Preferences::get()->_extractDouble(*this); - return ( val >= min && val <= max ? val : def ); + if (!this->isValid()) { + return def; + } else { + double val = Inkscape::Preferences::get()->_extractDouble(*this); + return ( val >= min && val <= max ? val : def ); + } } inline Glib::ustring Preferences::Entry::getString() const { - if (!this->isValid()) return ""; - return Inkscape::Preferences::get()->_extractString(*this); + if (!this->isValid()) { + return ""; + } else { + return Inkscape::Preferences::get()->_extractString(*this); + } +} + +inline guint32 Preferences::Entry::getColor(guint32 def) const +{ + if (!this->isValid()) { + return def; + } else { + return Inkscape::Preferences::get()->_extractColor(*this); + } } inline SPCSSAttr *Preferences::Entry::getStyle() const { - if (!this->isValid()) return sp_repr_css_attr_new(); - return Inkscape::Preferences::get()->_extractStyle(*this); + if (!this->isValid()) { + return sp_repr_css_attr_new(); + } else { + return Inkscape::Preferences::get()->_extractStyle(*this); + } } inline SPCSSAttr *Preferences::Entry::getInheritedStyle() const { - if (!this->isValid()) return sp_repr_css_attr_new(); - return Inkscape::Preferences::get()->_extractInheritedStyle(*this); + if (!this->isValid()) { + return sp_repr_css_attr_new(); + } else { + return Inkscape::Preferences::get()->_extractInheritedStyle(*this); + } } inline Glib::ustring Preferences::Entry::getEntryName() const