• 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., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, 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                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;   // ticks up every time setValue() or setValueBool() is called
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;       // one-based
00174     void                    addRecent(const char * szRecent);
00175     void                    removeRecent(UT_sint32 k);          // one-based
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     // a only-to-be-used-by XAP_PrefsScheme::setValue
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; /* save on any changes or only when user asks */
00206     bool                    m_bUseEnvLocale; /* use POSIX env vars to set locale */
00207 
00208     UT_GenericVector<XAP_PrefsScheme *> m_vecSchemes;       /* vector of XAP_PrefsScheme */
00209     UT_GenericVector<XAP_PrefsScheme *> m_vecPluginSchemes; /* vector of XAP_PrefsScheme */
00210     XAP_PrefsScheme *       m_currentScheme;
00211     XAP_PrefsScheme *       m_builtinScheme;
00212 
00213     UT_sint32               m_iMaxRecent;
00214     UT_GenericVector<char*> m_vecRecent;        /* vector of (char *) */
00215     UT_GenericVector<UT_UTF8String *> m_vecLog; /* vector of UT_UTF8String */
00216 
00217     XAP_FontSettings        m_fonts;
00218 
00219     typedef struct                  /* used to store the listener/data pairs in the vector  */
00220     {
00221         PrefsListener   m_pFunc;
00222         void            *m_pData;
00223     } tPrefsListenersPair;
00224 
00225     UT_GenericVector<tPrefsListenersPair *> m_vecPrefsListeners;    /* vectory of struct PrefListnersPair */
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;  /* Default width and height */
00232         UT_sint32       m_posx, m_posy;     /* Default position */
00233         UT_uint32       m_flags;            /* What is valid, what is not */
00234     } Pref_Geometry;
00235 
00236     Pref_Geometry       m_geom;
00237 
00238 
00239     /* Implementation of UT_XML::Listener */
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 // The following are the default values and limits for various non-scheme-based
00265 // application-independent preferences.
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 /* XAP_PREFS_H */

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1