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 getValueInt(const gchar * szKey, int& nValue) const;
00125 bool getValueBool(const gchar * szKey, bool * pbValue) const;
00126 bool getNthValue(UT_uint32 k, const gchar ** pszKey, const gchar ** pszValue);
00127
00128 protected:
00129 gchar * m_szName;
00130 UT_GenericStringMap<gchar*> m_hash;
00131 UT_GenericVector<const gchar*> m_sortedKeys;
00132 bool m_bValidSortedKeys;
00133 XAP_Prefs * m_pPrefs;
00134 UT_uint32 m_uTick;
00135 };
00136
00137
00138
00139
00140 class ABI_EXPORT XAP_Prefs : public UT_XML::Listener
00141 {
00142 public:
00143 XAP_Prefs();
00144 virtual ~XAP_Prefs(void);
00145
00146 bool loadPrefsFile(void);
00147 bool loadSystemDefaultPrefsFile(const char * szSystemDefaultPrefsPathname);
00148 bool savePrefsFile(void);
00149
00150 XAP_PrefsScheme * getNthScheme(UT_uint32 k) const;
00151 XAP_PrefsScheme * getNthPluginScheme(UT_uint32 k) const;
00152 XAP_PrefsScheme * getScheme(const gchar * szSchemeName) const;
00153 XAP_PrefsScheme * getPluginScheme(const gchar * szSchemeName) const;
00154 bool addScheme(XAP_PrefsScheme * pNewScheme);
00155 bool addPluginScheme(XAP_PrefsScheme * pNewScheme);
00156 XAP_PrefsScheme * getCurrentScheme(bool bCreate = false);
00157 bool setCurrentScheme(const gchar * szSchemeName);
00158
00159 bool getPrefsValue(const gchar * szKey, const gchar ** pszValue, bool bAllowBuiltin = true) const;
00160 bool getPrefsValue(const UT_String &stKey, UT_String &stValue, bool bAllowBuiltin = true) const;
00161 bool getPrefsValueBool(const gchar * szKey, bool * pbValue, bool bAllowBuiltin = true) const;
00162 bool getPrefsValueInt(const gchar * szKey, int& nValue, bool bAllowBuiltin = true) const;
00163
00164 bool getAutoSavePrefs(void) const;
00165 void setAutoSavePrefs(bool bAuto);
00166
00167 bool getUseEnvLocale(void) const;
00168 void setUseEnvLocale(bool bUse);
00169
00170 UT_sint32 getMaxRecent(void) const;
00171 void setMaxRecent(UT_sint32 k);
00172 UT_sint32 getRecentCount(void) const;
00173 const char * getRecent(UT_sint32 k) const;
00174 void addRecent(const char * szRecent);
00175 void removeRecent(UT_sint32 k);
00176 void setIgnoreNextRecent(void)
00177 { m_bIgnoreThisOne = true;}
00178 bool isIgnoreRecent(void)
00179 { return m_bIgnoreThisOne;}
00180
00181 bool setGeometry(UT_sint32 posx, UT_sint32 posy, UT_uint32 width, UT_uint32 height, UT_uint32 flags = 0);
00182 bool getGeometry(UT_sint32 *posx, UT_sint32 *posy, UT_uint32 *width, UT_uint32 *height, UT_uint32 *flags = 0);
00183
00184 virtual void fullInit(void) = 0;
00185 virtual bool loadBuiltinPrefs(void) = 0;
00186 virtual const gchar * getBuiltinSchemeName(void) const = 0;
00187 virtual const char * getPrefsPathname(void) const = 0;
00188
00189 void addListener ( PrefsListener pFunc, void *data );
00190 void removeListener ( PrefsListener pFunc, void *data = 0 );
00191 void startBlockChange();
00192 void endBlockChange();
00193
00194 void log(const char * where, const char * what, XAPPrefsLog_Level level = Log);
00195
00196 XAP_FontSettings & getFontSettings () {return m_fonts;}
00197
00198
00199 void _markPrefChange ( const gchar *szKey );
00200 protected:
00201 void _pruneRecent(void);
00202 XAP_PrefsScheme * _getNthScheme(UT_uint32 k,
00203 const UT_GenericVector<XAP_PrefsScheme *> &vecSchemes) const;
00204
00205 bool m_bAutoSavePrefs;
00206 bool m_bUseEnvLocale;
00207
00208 UT_GenericVector<XAP_PrefsScheme *> m_vecSchemes;
00209 UT_GenericVector<XAP_PrefsScheme *> m_vecPluginSchemes;
00210 XAP_PrefsScheme * m_currentScheme;
00211 XAP_PrefsScheme * m_builtinScheme;
00212
00213 UT_sint32 m_iMaxRecent;
00214 UT_GenericVector<char*> m_vecRecent;
00215 UT_GenericVector<UT_UTF8String *> m_vecLog;
00216
00217 XAP_FontSettings m_fonts;
00218
00219 typedef struct
00220 {
00221 PrefsListener m_pFunc;
00222 void *m_pData;
00223 } tPrefsListenersPair;
00224
00225 UT_GenericVector<tPrefsListenersPair *> m_vecPrefsListeners;
00226 UT_StringPtrMap m_ahashChanges;
00227 bool m_bInChangeBlock;
00228 void _sendPrefsSignal( UT_StringPtrMap *hash );
00229
00230 typedef struct {
00231 UT_uint32 m_width, m_height;
00232 UT_sint32 m_posx, m_posy;
00233 UT_uint32 m_flags;
00234 } Pref_Geometry;
00235
00236 Pref_Geometry m_geom;
00237
00238
00239
00240 public:
00241 void startElement(const gchar *name, const gchar **atts);
00242 void endElement(const gchar *name);
00243 void charData(const gchar *s, int len);
00244 private:
00245 void _startElement_SystemDefaultFile(const gchar *name,
00246 const gchar **atts);
00247 bool m_bLoadSystemDefaultFile;
00248 bool m_bIgnoreThisOne;
00249 private:
00250 struct
00251 {
00252 bool m_parserStatus;
00253 bool m_bFoundAbiPreferences;
00254 bool m_bFoundSelect;
00255 gchar * m_szSelectedSchemeName;
00256 bool m_bFoundRecent;
00257 bool m_bFoundGeometry;
00258 bool m_bFoundFonts;
00259 } m_parserState;
00260
00261 };
00262
00264
00265
00266
00267 #define XAP_PREF_DEFAULT_AutoSavePrefs "1"
00268 #define XAP_PREF_DEFAULT_MaxRecent "9"
00269 #define XAP_PREF_DEFAULT_UseEnvLocale "1"
00270
00271 #define XAP_PREF_LIMIT_MaxRecent 9
00272
00273 #endif