libkmime
kmime_util.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __KMIME_UTIL_H__
00017 #define __KMIME_UTIL_H__
00018
00019 #include "qdatetime.h"
00020 #include "qstring.h"
00021 #include "qcstring.h"
00022 #include "qvaluelist.h"
00023 #include "time.h"
00024 #include <kdepimmacros.h>
00025
00026 typedef QValueList<QCString> QCStringList;
00027
00028 namespace KMime {
00029
00032 extern const char* cachedCharset(const QCString &name) KDE_EXPORT;
00033
00036 extern const char* cachedLanguage(const QCString &name) KDE_EXPORT;
00037
00039 extern bool isUsAscii(const QString &s) KDE_EXPORT;
00040
00041 inline bool isOfSet(const uchar map[16], unsigned char ch) {
00042 Q_ASSERT( ch < 128 );
00043 return ( map[ ch/8 ] & 0x80 >> ch%8 );
00044 }
00045
00046 extern const uchar specialsMap[16];
00047 extern const uchar tSpecialsMap[16];
00048 extern const uchar aTextMap[16];
00049 extern const uchar tTextMap[16];
00050 extern const uchar eTextMap[16];
00051
00052 inline bool isSpecial(char ch) {
00053 return isOfSet( specialsMap, ch );
00054 }
00055 inline bool isTSpecial(char ch) {
00056 return isOfSet( tSpecialsMap, ch );
00057 }
00058 inline bool isAText(char ch) {
00059 return isOfSet( aTextMap, ch );
00060 }
00061 inline bool isTText(char ch) {
00062 return isOfSet( tTextMap, ch );
00063 }
00064 inline bool isEText(char ch) {
00065 return isOfSet( eTextMap, ch );
00066 }
00067
00077 extern QString decodeRFC2047String(const QCString &src, const char **usedCS,
00078 const QCString &defaultCS, bool forceCS) KDE_EXPORT;
00079
00090 extern QCString encodeRFC2047String(const QString &src, const char *charset,
00091 bool addressHeader=false, bool allow8bitHeaders=false) KDE_EXPORT;
00092
00099 extern QCString uniqueString() KDE_EXPORT;
00100
00107 extern QCString multiPartBoundary() KDE_EXPORT;
00108
00116 extern QCString extractHeader(const QCString &src, const char *name) KDE_EXPORT;
00126 extern QCString CRLFtoLF(const QCString &s) KDE_EXPORT;
00136 extern QCString CRLFtoLF(const char *s) KDE_EXPORT;
00148 extern QCString LFtoCRLF(const QCString &s) KDE_EXPORT;
00149
00155 KDE_EXPORT extern void removeQuots(QCString &str);
00161 KDE_EXPORT extern void removeQuots(QString &str);
00168 KDE_EXPORT extern void addQuotes(QCString &str, bool forceQuotes);
00169
00170
00187 class KDE_EXPORT DateFormatter {
00188 public:
00189 enum FormatType {
00190 CTime,
00191 Localized,
00192 Fancy,
00193 Iso,
00194 Custom
00195 };
00196
00201 DateFormatter(FormatType fType = DateFormatter::Fancy);
00202
00203 ~DateFormatter();
00204
00208 FormatType getFormat() const;
00212 void setFormat(FormatType t);
00213
00222 QString dateString(time_t otime, const QString& lang = QString::null,
00223 bool shortFormat = true, bool includeSecs=false) const;
00227 QString dateString(const QDateTime& dtime, const QString& lang = QString::null,
00228 bool shortFormat = true, bool includeSecs=false) const;
00229
00230
00240 void setCustomFormat(const QString& format);
00241 QString getCustomFormat() const;
00242
00247 QCString rfc2822(time_t otime) const;
00251 void reset();
00252
00253
00262 static QString formatDate( DateFormatter::FormatType t, time_t time,
00263 const QString& data = QString::null,
00264 bool shortFormat = true, bool includeSecs=false);
00265
00274 static QString formatCurrentDate( DateFormatter::FormatType t,
00275 const QString& data = QString::null,
00276 bool shortFormat = true, bool includeSecs=false);
00277
00279 static QCString rfc2822FormatDate( time_t time );
00280 static bool isDaylight();
00281 protected:
00287 QString fancy(time_t otime) const ;
00296 QString localized(time_t otime, bool shortFormat = true, bool includeSecs = false,
00297 const QString& localeLanguage=QString::null ) const;
00302 QString cTime(time_t otime) const;
00307 QString isoDate(time_t otime) const;
00308
00315 QString custom(time_t t) const;
00320 QCString zone(time_t otime) const;
00321
00322 time_t qdateToTimeT(const QDateTime& dt) const;
00323 private:
00324 FormatType mFormat;
00325 mutable time_t mCurrentTime;
00326 mutable QDateTime mDate;
00327 QString mCustomFormat;
00328 static int mDaylight;
00329 };
00330
00331 }
00332
00333 #endif
|