kmail

util.h

00001 /*******************************************************************************
00002 **
00003 ** Filename   : util
00004 ** Created on : 03 April, 2005
00005 ** Copyright  : (c) 2005 Till Adam
00006 ** Email      : <adam@kde.org>
00007 **
00008 *******************************************************************************/
00009 
00010 /*******************************************************************************
00011 **
00012 **   This program is free software; you can redistribute it and/or modify
00013 **   it under the terms of the GNU General Public License as published by
00014 **   the Free Software Foundation; either version 2 of the License, or
00015 **   (at your option) any later version.
00016 **
00017 **   It is distributed in the hope that it will be useful, but
00018 **   WITHOUT ANY WARRANTY; without even the implied warranty of
00019 **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 **   General Public License for more details.
00021 **
00022 **   You should have received a copy of the GNU General Public License
00023 **   along with this program; if not, write to the Free Software
00024 **   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025 **
00026 **   In addition, as a special exception, the copyright holders give
00027 **   permission to link the code of this program with any edition of
00028 **   the Qt library by Trolltech AS, Norway (or with modified versions
00029 **   of Qt that use the same license as Qt), and distribute linked
00030 **   combinations including the two.  You must obey the GNU General
00031 **   Public License in all respects for all of the code used other than
00032 **   Qt.  If you modify this file, you may extend this exception to
00033 **   your version of the file, but you are not obligated to do so.  If
00034 **   you do not wish to do so, delete this exception statement from
00035 **   your version.
00036 **
00037 *******************************************************************************/
00038 #ifndef KMAILUTIL_H
00039 #define KMAILUTIL_H
00040 
00041 #include <stdlib.h>
00042 #include <qobject.h>
00043 #include <qcstring.h>
00044 class DwString;
00045 
00046 namespace KMail
00047 {
00052 namespace Util {
00061     size_t crlf2lf( char* str, const size_t strLen );
00062 
00063     
00069     QCString lf2crlf( const QCString & src );
00075     QByteArray lf2crlf( const QByteArray & src );
00076 
00080     QCString CString( const DwString& str );
00081 
00085     QByteArray ByteArray( const DwString& str );
00086 
00090     DwString dwString( const QCString& str );
00091 
00095     DwString dwString( const QByteArray& str );
00096 
00100     void setFromQCString( QByteArray& arr, const QCString& cstr );
00101 
00102     inline void setFromQCString( QByteArray& arr, const QCString& cstr )
00103     {
00104       if ( cstr.size() )
00105         arr.duplicate( cstr.data(), cstr.size()-1 );
00106       else
00107         arr.resize(0);
00108     }
00109 
00115     QByteArray byteArrayFromQCStringNoDetach( QCString& cstr );
00116     inline QByteArray byteArrayFromQCStringNoDetach( QCString& cstr )
00117     {
00118       QByteArray arr = cstr;
00119       if ( arr.size() )
00120         arr.resize( arr.size() - 1 );
00121       return arr;
00122     }
00123 
00127     void restoreQCString( QCString& str );
00128     inline void restoreQCString( QCString& str )
00129     {
00130       if ( str.data() )
00131         str.resize( str.size() + 1 );
00132     }
00133 
00137     void setFromByteArray( QCString& cstr, const QByteArray& arr );
00138 
00139     inline void setFromByteArray( QCString& result, const QByteArray& arr )
00140     {
00141       const int len = arr.size();
00142       result.resize( len + 1 /* trailing NUL */ );
00143       memcpy(result.data(), arr.data(), len);
00144       result[len] = 0;
00145     }
00146 
00150     void append( QByteArray& that, const QByteArray& str );
00151 
00155     void append( QByteArray& that, const char* str );
00156 
00160     void append( QByteArray& that, const QCString& str );
00161 
00162     void insert( QByteArray& that, uint index, const char* s );
00163 
00171     class LaterDeleter
00172     {
00173       public:
00174       LaterDeleter( QObject *o)
00175         :m_object( o ), m_disabled( false )
00176       {
00177       }
00178       virtual ~LaterDeleter()
00179       {
00180         if ( !m_disabled ) {
00181           m_object->deleteLater();
00182         }
00183       }
00184       void setDisabled( bool v )
00185       {
00186         m_disabled = v;
00187       }
00188       protected:
00189       QObject *m_object;
00190       bool m_disabled;
00191     };
00192 }
00193 }
00194 
00195 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys