• 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., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, 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 #include "ut_string_class.h"
00038 
00039 class XAP_App;
00040 
00042 // build a table of XAP ID values
00044 
00045 #define dcl(id,s)                   XAP_STRING_ID_##id,
00046 
00047 typedef enum _XAP_String_Id_Enum
00048 {
00049     XAP_STRING_ID__FIRST__          = 0,    /* must be first */
00050 #include "xap_String_Id.h"
00051     XAP_STRING_ID__LAST__                   /* must be last */
00052 } XAP_String_Id_Enum;
00053 
00054 #undef dcl
00055 
00057 // Both XAP_ and AP_ enum sets fold into XAP_String_Id
00059 
00060 typedef UT_uint32           XAP_String_Id;
00061 
00063 // base class provides interface regardless of how we got the strings
00065 
00066 class ABI_EXPORT XAP_StringSet
00067 {
00068 public:
00069     XAP_StringSet(XAP_App * pApp, const gchar * szLanguageName);
00070     virtual ~XAP_StringSet(void);
00071 
00072     const gchar *           getLanguageName(void) const;
00073 
00074     virtual const gchar *   getValue(XAP_String_Id id) const = 0;
00075 
00076     bool getValue(XAP_String_Id id, const char * inEncoding, UT_String &s) const;
00077     bool getValueUTF8(XAP_String_Id id, std::string &s) const;
00078     bool getValueUTF8(XAP_String_Id id, UT_UTF8String &s) const;
00079 
00080     void setEncoding(const char * inEndcoding);
00081     const char * getEncoding() const;
00082 
00083 protected:
00084     XAP_App *                   m_pApp;
00085     const gchar *           m_szLanguageName;
00086 
00087  private:
00088     UT_String m_encoding ;
00089 };
00090 
00092 // a sub-class to wrap the compiled-in (english) strings
00094 
00095 class ABI_EXPORT XAP_BuiltinStringSet : public XAP_StringSet
00096 {
00097 public:
00098     XAP_BuiltinStringSet(XAP_App * pApp, const gchar * szLanguageName);
00099     virtual ~XAP_BuiltinStringSet(void);
00100 
00101     virtual const gchar *   getValue(XAP_String_Id id) const;
00102 
00103 private:
00104     const gchar **          m_arrayXAP;
00105 };
00106 
00108 // a sub-class to deal with disk-based string sets (translations)
00110 
00111 class ABI_EXPORT XAP_DiskStringSet : public XAP_StringSet, public UT_XML::Listener
00112 {
00113 public:
00114     XAP_DiskStringSet(XAP_App * pApp);
00115     virtual ~XAP_DiskStringSet(void);
00116 
00117     virtual bool                setValue(XAP_String_Id id, const gchar * szString);
00118     virtual bool                setValue(const gchar * szId, const gchar * szString);
00119     virtual const gchar *   getValue(XAP_String_Id id) const;
00120     virtual bool                loadStringsFromDisk(const char * szFilename);
00121 
00122     bool                        setLanguage(const gchar * szLanguageName);
00123     void                        setFallbackStringSet(XAP_StringSet * pFallback);
00124 
00125 public:
00126     /* Implementation of UT_XML::Listener
00127      */
00128     void                    startElement(const gchar *name, const gchar **atts);
00129     void                    endElement(const gchar *name);
00130     void                    charData(const gchar *s, int len);
00131 
00132 protected:
00133     XAP_StringSet *             m_pFallbackStringSet;
00134 
00135 private:
00136     UT_GenericVector<gchar*>    m_vecStringsXAP;
00137     std::map<std::string, UT_uint32>    m_hash;
00138 
00139     struct
00140     {
00141         bool                m_parserStatus;
00142     } m_parserState;
00143 };
00144 
00145 #endif /* XAP_STRINGS_H */

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1