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

ie_mailmerge.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 /* Abiword
00003  * Copyright (C) 2003 Dom Lachowicz
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 IE_MAILMERGE_H
00022 #define IE_MAILMERGE_H
00023 
00024 #include <map>
00025 #include <memory>
00026 #include <string>
00027 #include <vector>
00028 
00029 #include "ut_types.h"
00030 
00031 typedef UT_sint32 IEMergeType;
00032 #define IEMT_Unknown ((IEMergeType)-1)
00033 
00034 class IE_MailMerge;
00035 class PD_Document;
00036 
00037 typedef std::unique_ptr<IE_MailMerge> IE_MailMergePtr;
00038 
00039 class ABI_EXPORT IE_MergeSniffer
00040 {
00041   friend class IE_MailMerge;
00042 
00043 public:
00044 
00045     virtual ~IE_MergeSniffer();
00046 
00047     // these you get for free
00048     inline bool supportsFileType (IEMergeType type) {return m_type == type;}
00049     inline IEMergeType getFileType() const {return m_type;}
00050 
00051     // these you must override these next methods!!!
00052 
00058     virtual UT_Confidence_t recognizeContents (const char * szBuf,
00059                                                UT_uint32 iNumbytes) = 0;
00065     virtual UT_Confidence_t recognizeSuffix (const char * szSuffix) = 0;
00066 
00067     virtual bool getDlgLabels (const char ** szDesc,
00068                                const char ** szSuffixList,
00069                                IEMergeType * ft) = 0;
00070 
00071     virtual UT_Error constructMerger (IE_MailMergePtr & pie) = 0;
00072 
00073     // test helper.
00074     friend class IE_MergeSniffer_TH;
00075 protected:
00076 
00077     IE_MergeSniffer() {}
00078 
00079 private:
00080 
00081     // only IE_MailMerge ever calls this
00082     inline void setFileType (IEMergeType type) {m_type = type;}
00083     IEMergeType m_type;
00084 };
00085 
00086 class ABI_EXPORT IE_MailMerge
00087 {
00088 
00089 public:
00090     // Test helper
00091     friend class IE_MailMerge_TH;
00092 
00093     virtual ~IE_MailMerge ();
00094 
00095     // constructs an importer of the right type based upon
00096     // either the filename or sniffing the file.  caller is
00097     // responsible for destroying the importer when finished
00098     // with it.
00099 
00100     virtual UT_Error    mergeFile(const char * szFilename) = 0;
00101     virtual UT_Error getHeaders (const char * szFilename, std::vector<std::string> & out_vec) = 0;
00102 
00103     static IEMergeType  fileTypeForContents(const char * szBuf,
00104                                                 UT_uint32 iNumbytes);
00105 
00106     static IEMergeType  fileTypeForSuffix(const char * szSuffix);
00107     static IEMergeType  fileTypeForDescription(const char * szSuffix);
00108 
00109     static IEMergeType fileTypeForSuffixes(const char * suffixList);
00110 
00111     static IE_MergeSniffer * snifferForFileType(IEMergeType ieft);
00112     static const char * suffixesForFileType(IEMergeType ieft);
00113     static const char * descriptionForFileType(IEMergeType ieft);
00114 
00115     static UT_Error constructMerger(const char * szFilename,
00116                                     IEMergeType ieft,
00117                                     IE_MailMergePtr & pie,
00118                                     IEMergeType * pieft = NULL);
00119 
00120     static bool     enumerateDlgLabels(UT_uint32 ndx,
00121                                            const char ** pszDesc,
00122                                            const char ** pszSuffixList,
00123                                            IEMergeType * ft);
00124 
00125     static UT_uint32    getMergerCount(void);
00126     static void registerMerger (IE_MergeSniffer * sniffer);
00127     static void unregisterAllMergers ();
00128 
00129     class ABI_EXPORT IE_MailMerge_Listener
00130     {
00131     public:
00132         virtual ~IE_MailMerge_Listener ()
00133             {
00134             }
00135 
00136         virtual PD_Document* getMergeDocument () const = 0;
00137         virtual bool fireUpdate () = 0;
00138 
00139     protected:
00140 
00141         IE_MailMerge_Listener ()
00142             {
00143             }
00144     };
00145 
00146     void setListener (IE_MailMerge_Listener * listener);
00147 
00148     const std::map<std::string, std::string> & getCurrentMapping() const
00149     { return m_map; }
00150 
00151 protected:
00152 
00153     IE_MailMerge ();
00154 
00155     bool fireMergeSet ();
00156     void addMergePair (const std::string & key,
00157                const std::string & value);
00158 
00159 private:
00160 
00161     static std::vector<IE_MergeSniffer *> & getSniffers();
00162 
00163     IE_MailMerge_Listener * m_pListener;
00164     std::map<std::string, std::string> m_map;
00165 };
00166 
00167 void IE_MailMerge_RegisterXP ();
00168 void IE_MailMerge_UnRegisterXP ();
00169 
00170 #endif

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1