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

xap_Strings.h

Go to the documentation of this file.
00001 /* AbiSource Application Framework
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  * Copyright (C) 2009 Hubert Figuiere
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_STRINGS_H
00022 #define XAP_STRINGS_H
00023 
00024 #include <map>
00025 #include <string>
00026 
00027 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00028  * so even if it's commented out in-file that's still a lot of work for
00029  * the preprocessor to do...
00030  */
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034 #include "ut_xml.h"
00035 #include "ut_vector.h"
00036 #include "ut_string.h"
00037 
00038 class XAP_App;
00039 
00041 // build a table of XAP ID values
00043 
00044 #define dcl(id,s)                   XAP_STRING_ID_##id,
00045 
00046 typedef enum _XAP_String_Id_Enum
00047 {
00048     XAP_STRING_ID__FIRST__          = 0,    /* must be first */
00049 #include "xap_String_Id.h"
00050     XAP_STRING_ID__LAST__                   /* must be last */
00051 } XAP_String_Id_Enum;
00052 
00053 #undef dcl
00054 
00056 // Both XAP_ and AP_ enum sets fold into XAP_String_Id
00058 
00059 typedef UT_uint32           XAP_String_Id;
00060 
00062 // base class provides interface regardless of how we got the strings
00064 
00065 class ABI_EXPORT XAP_StringSet
00066 {
00067 public:
00068     XAP_StringSet(XAP_App * pApp, const gchar * szLanguageName);
00069     virtual ~XAP_StringSet(void);
00070 
00071     const gchar *           getLanguageName(void) const;
00072 
00073     virtual const gchar *   getValue(XAP_String_Id id) const = 0;
00074 
00075     bool getValue(XAP_String_Id id, const char * inEncoding, std::string &s) const;
00076     bool getValueUTF8(XAP_String_Id id, std::string &s) const;
00077 
00078     void setEncoding(const char * inEndcoding);
00079     const char * getEncoding() const;
00080 
00081 protected:
00082     XAP_App *                   m_pApp;
00083     const gchar *           m_szLanguageName;
00084 
00085  private:
00086     std::string m_encoding ;
00087 };
00088 
00090 // a sub-class to wrap the compiled-in (english) strings
00092 
00093 class ABI_EXPORT XAP_BuiltinStringSet : public XAP_StringSet
00094 {
00095 public:
00096     XAP_BuiltinStringSet(XAP_App * pApp, const gchar * szLanguageName);
00097     virtual ~XAP_BuiltinStringSet(void);
00098 
00099     virtual const gchar *   getValue(XAP_String_Id id) const;
00100 
00101 private:
00102     const gchar **          m_arrayXAP;
00103 };
00104 
00106 // a sub-class to deal with disk-based string sets (translations)
00108 
00109 class ABI_EXPORT XAP_DiskStringSet : public XAP_StringSet, public UT_XML::Listener
00110 {
00111 public:
00112     XAP_DiskStringSet(XAP_App * pApp);
00113     virtual ~XAP_DiskStringSet(void);
00114 
00115     virtual bool                setValue(XAP_String_Id id, const gchar * szString);
00116     virtual bool                setValue(const gchar * szId, const gchar * szString);
00117     virtual const gchar *   getValue(XAP_String_Id id) const;
00118     virtual bool                loadStringsFromDisk(const char * szFilename);
00119 
00120     bool                        setLanguage(const gchar * szLanguageName);
00121     void                        setFallbackStringSet(XAP_StringSet * pFallback);
00122 
00123 public:
00124     /* Implementation of UT_XML::Listener
00125      */
00126     void                    startElement(const gchar *name, const gchar **atts);
00127     void                    endElement(const gchar *name);
00128     void                    charData(const gchar *s, int len);
00129 
00130 protected:
00131     XAP_StringSet *             m_pFallbackStringSet;
00132 
00133 private:
00134     UT_GenericVector<gchar*>    m_vecStringsXAP;
00135     std::map<std::string, UT_uint32>    m_hash;
00136 
00137     struct
00138     {
00139         bool                m_parserStatus;
00140     } m_parserState;
00141 };
00142 
00143 #endif /* XAP_STRINGS_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1