• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xap_Prefs.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 /* AbiSource Application Framework
00003  * Copyright (C) 1998 AbiSource, Inc.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 #ifndef XAP_PREFS_H
00022 #define XAP_PREFS_H
00023 
00024 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00025  * so even if it's commented out in-file that's still a lot of work for
00026  * the preprocessor to do...
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 /* For handling the position of windows on the screen, this sets up preferences */
00042 enum {
00043     PREF_FLAG_GEOMETRY_POS = 0x1,     // Position is valid
00044     PREF_FLAG_GEOMETRY_SIZE = 0x2,    // Size is valid
00045     PREF_FLAG_GEOMETRY_NOUPDATE = 0x4, // User specified, don't update it
00046     PREF_FLAG_GEOMETRY_MAXIMIZED = 0x8 // Maximize at start
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 ** XAP_PrefsScheme is a complete set of preferences.  it contains
00059 ** all the info for a UI styling set.  use XAP_Prefs to switch
00060 ** between schemes.
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     // The idea of the tick is that some object can cache a preference
00106     // value if it makes a performance difference.  It should also save
00107     // a copy of the tick count and the scheme pointer.  If the scheme
00108     // pointer and the tick count are the same, the cached preference
00109     // value is current.  If either is changed, the object can refresh
00110     // its cached value.  The scheme pointer can be different because
00111     // the preference scheme has changed.  The tick count bumps up once
00112     // every time any preference value in the scheme is changed.
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     // the get*Value*() functions return the answer in the last
00120     // argument; they return error information as the function
00121     // return value.
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;   // ticks up every time setValue() or setValueBool() is called
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;       // one-based
00175     void                    addRecent(const char * szRecent);
00176     void                    removeRecent(UT_sint32 k);          // one-based
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     // a only-to-be-used-by XAP_PrefsScheme::setValue
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; /* save on any changes or only when user asks */
00207     bool                    m_bUseEnvLocale; /* use POSIX env vars to set locale */
00208 
00209     UT_GenericVector<XAP_PrefsScheme *> m_vecSchemes;       /* vector of XAP_PrefsScheme */
00210     UT_GenericVector<XAP_PrefsScheme *> m_vecPluginSchemes; /* vector of XAP_PrefsScheme */
00211     XAP_PrefsScheme *       m_currentScheme;
00212     XAP_PrefsScheme *       m_builtinScheme;
00213 
00214     UT_sint32               m_iMaxRecent;
00215     UT_GenericVector<char*> m_vecRecent;        /* vector of (char *) */
00216     UT_GenericVector<UT_UTF8String *> m_vecLog; /* vector of UT_UTF8String */
00217 
00218     XAP_FontSettings        m_fonts;
00219 
00220     typedef struct                  /* used to store the listener/data pairs in the vector  */
00221     {
00222         PrefsListener   m_pFunc;
00223         void            *m_pData;
00224     } tPrefsListenersPair;
00225 
00226     UT_GenericVector<tPrefsListenersPair *> m_vecPrefsListeners;    /* vectory of struct PrefListnersPair */
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;  /* Default width and height */
00233         UT_sint32       m_posx, m_posy;     /* Default position */
00234         UT_uint32       m_flags;            /* What is valid, what is not */
00235     } Pref_Geometry;
00236 
00237     Pref_Geometry       m_geom;
00238 
00239 
00240     /* Implementation of UT_XML::Listener */
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 // The following are the default values and limits for various non-scheme-based
00266 // application-independent preferences.
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 /* XAP_PREFS_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1