Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAP_PREFS_H
00022 #define XAP_PREFS_H
00023
00024
00025
00026
00027
00028 #ifndef UT_TYPES_H
00029 #include "ut_types.h"
00030 #endif
00031 #include "ut_vector.h"
00032 #include "ut_hash.h"
00033 #include "ut_string.h"
00034 #include "ut_string_class.h"
00035 #include "ut_xml.h"
00036
00037 #include "xap_Prefs_SchemeIds.h"
00038
00039 #include <vector>
00040
00041
00042 enum {
00043 PREF_FLAG_GEOMETRY_POS = 0x1,
00044 PREF_FLAG_GEOMETRY_SIZE = 0x2,
00045 PREF_FLAG_GEOMETRY_NOUPDATE = 0x4,
00046 PREF_FLAG_GEOMETRY_MAXIMIZED = 0x8
00047 };
00048
00049 class XAP_Prefs;
00050
00051 typedef void (*PrefsListener) (
00052 XAP_Prefs *pPrefs,
00053 UT_StringPtrMap *phChanges,
00054 void *data
00055 );
00056
00057
00058
00059
00060
00061
00062
00063 enum XAPPrefsLog_Level
00064 {
00065 Log,
00066 Warning,
00067 Error
00068 };
00069
00070 class ABI_EXPORT XAP_FontSettings
00071 {
00072 public:
00073 XAP_FontSettings()
00074 :m_bInclude(false){};
00075
00076 const std::vector<UT_UTF8String> & getFonts() const
00077 {return m_vecFonts;}
00078
00079 void addFont (const char * pFace)
00080 {
00081 m_vecFonts.push_back (pFace);
00082 }
00083
00084 bool haveFontsToExclude () const {return (!m_bInclude && m_vecFonts.size());}
00085 bool haveFontsToInclude () const {return (m_bInclude && m_vecFonts.size());}
00086
00087 bool isOnExcludeList (const char * name) const;
00088
00089 void setIncludeFlag (bool bInclude) {m_bInclude = bInclude;}
00090 bool getIncludeFlag () const {return m_bInclude;}
00091
00092 private:
00093 std::vector<UT_UTF8String> m_vecFonts;
00094 bool m_bInclude;
00095 };
00096
00097 class ABI_EXPORT XAP_PrefsScheme
00098 {
00099 public:
00100 XAP_PrefsScheme(XAP_Prefs *pPrefs, const gchar * szSchemeName);
00101 ~XAP_PrefsScheme(void);
00102
00103 const gchar * getSchemeName(void) const;
00104 bool setSchemeName(const gchar * szNewSchemeName);
00105
00106
00107
00108
00109
00110
00111
00112
00113 UT_uint32 getTickCount() {return m_uTick;}
00114
00115 bool setValue(const gchar * szKey, const gchar * szValue);
00116 bool setValueBool(const gchar * szKey, bool bValue);
00117 bool setValueInt(const gchar * szKey, const int nValue);
00118
00119
00120
00121
00122 bool getValue(const gchar * szKey, const gchar ** pszValue) const;
00123 bool getValue(const UT_String &szKey, UT_String &szValue) const;
00124 bool getValue(const char* szKey, std::string &szValue) const;
00125 bool getValueInt(const gchar * szKey, int& nValue) const;
00126 bool getValueBool(const gchar * szKey, bool * pbValue) const;
00127 bool getNthValue(UT_uint32 k, const gchar ** pszKey, const gchar ** pszValue);
00128
00129 protected:
00130 gchar * m_szName;
00131 UT_GenericStringMap<gchar*> m_hash;
00132 UT_GenericVector<const gchar*> m_sortedKeys;
00133 bool m_bValidSortedKeys;
00134 XAP_Prefs * m_pPrefs;
00135 UT_uint32 m_uTick;
00136 };
00137
00138
00139
00140
00141 class ABI_EXPORT XAP_Prefs : public UT_XML::Listener
00142 {
00143 public:
00144 XAP_Prefs();
00145 virtual ~XAP_Prefs(void);
00146
00147 bool loadPrefsFile(void);
00148 bool loadSystemDefaultPrefsFile(const char * szSystemDefaultPrefsPathname);
00149 bool savePrefsFile(void);
00150
00151 XAP_PrefsScheme * getNthScheme(UT_uint32 k) const;
00152 XAP_PrefsScheme * getNthPluginScheme(UT_uint32 k) const;
00153 XAP_PrefsScheme * getScheme(const gchar * szSchemeName) const;
00154 XAP_PrefsScheme * getPluginScheme(const gchar * szSchemeName) const;
00155 bool addScheme(XAP_PrefsScheme * pNewScheme);
00156 bool addPluginScheme(XAP_PrefsScheme * pNewScheme);
00157 XAP_PrefsScheme * getCurrentScheme(bool bCreate = false);
00158 bool setCurrentScheme(const gchar * szSchemeName);
00159
00160 bool getPrefsValue(const gchar * szKey, const gchar ** pszValue, bool bAllowBuiltin = true) const;
00161 bool getPrefsValue(const UT_String &stKey, UT_String &stValue, bool bAllowBuiltin = true) const;
00162 bool getPrefsValueBool(const gchar * szKey, bool * pbValue, bool bAllowBuiltin = true) const;
00163 bool getPrefsValueInt(const gchar * szKey, int& nValue, bool bAllowBuiltin = true) const;
00164
00165 bool getAutoSavePrefs(void) const;
00166 void setAutoSavePrefs(bool bAuto);
00167
00168 bool getUseEnvLocale(void) const;
00169 void setUseEnvLocale(bool bUse);
00170
00171 UT_sint32 getMaxRecent(void) const;
00172 void setMaxRecent(UT_sint32 k);
00173 UT_sint32 getRecentCount(void) const;
00174 const char * getRecent(UT_sint32 k) const;
00175 void addRecent(const char * szRecent);
00176 void removeRecent(UT_sint32 k);
00177 void setIgnoreNextRecent(void)
00178 { m_bIgnoreThisOne = true;}
00179 bool isIgnoreRecent(void)
00180 { return m_bIgnoreThisOne;}
00181
00182 bool setGeometry(UT_sint32 posx, UT_sint32 posy, UT_uint32 width, UT_uint32 height, UT_uint32 flags = 0);
00183 bool getGeometry(UT_sint32 *posx, UT_sint32 *posy, UT_uint32 *width, UT_uint32 *height, UT_uint32 *flags = 0);
00184
00185 virtual void fullInit(void) = 0;
00186 virtual bool loadBuiltinPrefs(void) = 0;
00187 virtual const gchar * getBuiltinSchemeName(void) const = 0;
00188 virtual const char * getPrefsPathname(void) const = 0;
00189
00190 void addListener ( PrefsListener pFunc, void *data );
00191 void removeListener ( PrefsListener pFunc, void *data = 0 );
00192 void startBlockChange();
00193 void endBlockChange();
00194
00195 void log(const char * where, const char * what, XAPPrefsLog_Level level = Log);
00196
00197 XAP_FontSettings & getFontSettings () {return m_fonts;}
00198
00199
00200 void _markPrefChange ( const gchar *szKey );
00201 protected:
00202 void _pruneRecent(void);
00203 XAP_PrefsScheme * _getNthScheme(UT_uint32 k,
00204 const UT_GenericVector<XAP_PrefsScheme *> &vecSchemes) const;
00205
00206 bool m_bAutoSavePrefs;
00207 bool m_bUseEnvLocale;
00208
00209 UT_GenericVector<XAP_PrefsScheme *> m_vecSchemes;
00210 UT_GenericVector<XAP_PrefsScheme *> m_vecPluginSchemes;
00211 XAP_PrefsScheme * m_currentScheme;
00212 XAP_PrefsScheme * m_builtinScheme;
00213
00214 UT_sint32 m_iMaxRecent;
00215 UT_GenericVector<char*> m_vecRecent;
00216 UT_GenericVector<UT_UTF8String *> m_vecLog;
00217
00218 XAP_FontSettings m_fonts;
00219
00220 typedef struct
00221 {
00222 PrefsListener m_pFunc;
00223 void *m_pData;
00224 } tPrefsListenersPair;
00225
00226 UT_GenericVector<tPrefsListenersPair *> m_vecPrefsListeners;
00227 UT_StringPtrMap m_ahashChanges;
00228 bool m_bInChangeBlock;
00229 void _sendPrefsSignal( UT_StringPtrMap *hash );
00230
00231 typedef struct {
00232 UT_uint32 m_width, m_height;
00233 UT_sint32 m_posx, m_posy;
00234 UT_uint32 m_flags;
00235 } Pref_Geometry;
00236
00237 Pref_Geometry m_geom;
00238
00239
00240
00241 public:
00242 void startElement(const gchar *name, const gchar **atts);
00243 void endElement(const gchar *name);
00244 void charData(const gchar *s, int len);
00245 private:
00246 void _startElement_SystemDefaultFile(const gchar *name,
00247 const gchar **atts);
00248 bool m_bLoadSystemDefaultFile;
00249 bool m_bIgnoreThisOne;
00250 private:
00251 struct
00252 {
00253 bool m_parserStatus;
00254 bool m_bFoundAbiPreferences;
00255 bool m_bFoundSelect;
00256 gchar * m_szSelectedSchemeName;
00257 bool m_bFoundRecent;
00258 bool m_bFoundGeometry;
00259 bool m_bFoundFonts;
00260 } m_parserState;
00261
00262 };
00263
00265
00266
00267
00268 #define XAP_PREF_DEFAULT_AutoSavePrefs "1"
00269 #define XAP_PREF_DEFAULT_MaxRecent "9"
00270 #define XAP_PREF_DEFAULT_UseEnvLocale "1"
00271
00272 #define XAP_PREF_LIMIT_MaxRecent 9
00273
00274 #endif