kmail

util.h
1/*******************************************************************************
2**
3** Filename : util
4** Created on : 03 April, 2005
5** Copyright : (c) 2005 Till Adam
6** Email : <adam@kde.org>
7**
8*******************************************************************************/
9
10/*******************************************************************************
11**
12** This program is free software; you can redistribute it and/or modify
13** it under the terms of the GNU General Public License as published by
14** the Free Software Foundation; either version 2 of the License, or
15** (at your option) any later version.
16**
17** It is distributed in the hope that it will be useful, but
18** WITHOUT ANY WARRANTY; without even the implied warranty of
19** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20** General Public License for more details.
21**
22** You should have received a copy of the GNU General Public License
23** along with this program; if not, write to the Free Software
24** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25**
26** In addition, as a special exception, the copyright holders give
27** permission to link the code of this program with any edition of
28** the TQt library by Trolltech AS, Norway (or with modified versions
29** of TQt that use the same license as TQt), and distribute linked
30** combinations including the two. You must obey the GNU General
31** Public License in all respects for all of the code used other than
32** TQt. If you modify this file, you may extend this exception to
33** your version of the file, but you are not obligated to do so. If
34** you do not wish to do so, delete this exception statement from
35** your version.
36**
37*******************************************************************************/
38#ifndef KMAILUTIL_H
39#define KMAILUTIL_H
40
41#include <stdlib.h>
42
43#include <tqobject.h>
44#include <tqcstring.h>
45
46#include <tdeio/netaccess.h>
47#include <tdemessagebox.h>
48#include <tdelocale.h>
49
50class DwString;
51class KURL;
52class TQWidget;
53
54namespace KMail
55{
60namespace Util {
69 size_t crlf2lf( char* str, const size_t strLen );
70
71
77 TQCString lf2crlf( const TQCString & src );
83 TQByteArray lf2crlf( const TQByteArray & src );
84
88 TQCString CString( const DwString& str );
89
93 TQByteArray ByteArray( const DwString& str );
94
98 DwString dwString( const TQCString& str );
99
103 DwString dwString( const TQByteArray& str );
104
108 void setFromTQCString( TQByteArray& arr, const TQCString& cstr );
109
110 inline void setFromTQCString( TQByteArray& arr, const TQCString& cstr )
111 {
112 if ( cstr.size() )
113 arr.duplicate( cstr.data(), cstr.size()-1 );
114 else
115 arr.resize(0);
116 }
117
123 TQByteArray byteArrayFromTQCStringNoDetach( TQCString& cstr );
124 inline TQByteArray byteArrayFromTQCStringNoDetach( TQCString& cstr )
125 {
126 TQByteArray arr = cstr;
127 if ( arr.size() )
128 arr.resize( arr.size() - 1 );
129 return arr;
130 }
131
135 void restoreTQCString( TQCString& str );
136 inline void restoreTQCString( TQCString& str )
137 {
138 if ( str.data() )
139 str.resize( str.size() + 1 );
140 }
141
145 void setFromByteArray( TQCString& cstr, const TQByteArray& arr );
146
147 inline void setFromByteArray( TQCString& result, const TQByteArray& arr )
148 {
149 const int len = arr.size();
150 result.resize( len + 1 /* trailing NUL */ );
151 memcpy(result.data(), arr.data(), len);
152 result[len] = 0;
153 }
154
158 void append( TQByteArray& that, const TQByteArray& str );
159
163 void append( TQByteArray& that, const char* str );
164
168 void append( TQByteArray& that, const TQCString& str );
169
170 void insert( TQByteArray& that, uint index, const char* s );
171
180 {
181 public:
182 LaterDeleter( TQObject *o)
183 :m_object( o ), m_disabled( false )
184 {
185 }
186 virtual ~LaterDeleter()
187 {
188 if ( !m_disabled ) {
189 m_object->deleteLater();
190 }
191 }
192 void setDisabled( bool v )
193 {
194 m_disabled = v;
195 }
196 protected:
197 TQObject *m_object;
198 bool m_disabled;
199 };
200
201 // return true if we should proceed, false if we should abort
202 inline bool checkOverwrite( const KURL& url, TQWidget* w )
203 {
204 if ( TDEIO::NetAccess::exists( url, false /*dest*/, w ) ) {
205 if ( KMessageBox::Cancel ==
206 KMessageBox::warningContinueCancel(
207 w,
208 i18n( "A file named \"%1\" already exists. "
209 "Are you sure you want to overwrite it?" ).arg( url.prettyURL() ),
210 i18n( "Overwrite File?" ),
211 i18n( "&Overwrite" ) ) )
212 return false;
213 }
214 return true;
215 }
216
217
218
219}
220}
221
222#endif
A LaterDeleter is intended to be used with the RAII ( Resource Acquisition is Initialization ) paradi...
Definition: util.h:180
TQByteArray byteArrayFromTQCStringNoDetach(TQCString &cstr)
Creates a TQByteArray from a TQCString without detaching (duplicating the data).
Definition: util.h:124
void restoreTQCString(TQCString &str)
Restore the TQCString after byteArrayFromTQCStringNoDetach modified it.
Definition: util.h:136
void append(TQByteArray &that, const TQByteArray &str)
Append a bytearray to a bytearray.
Definition: util.cpp:144
TQByteArray ByteArray(const DwString &str)
Construct a TQByteArray from a DwString.
Definition: util.cpp:122
void setFromTQCString(TQByteArray &arr, const TQCString &cstr)
Fills a TQByteArray from a TQCString - removing the trailing null.
Definition: util.h:110
void setFromByteArray(TQCString &cstr, const TQByteArray &arr)
Fills a TQCString from a TQByteArray - adding the trailing null.
Definition: util.h:147
TQCString lf2crlf(const TQCString &src)
Convert "\n" line endings to "\r\n".
Definition: util.cpp:74
TQCString CString(const DwString &str)
Construct a TQCString from a DwString.
Definition: util.cpp:113
DwString dwString(const TQCString &str)
Construct a DwString from a TQCString.
Definition: util.cpp:130
size_t crlf2lf(char *str, const size_t strLen)
Convert all sequences of "\r\n" (carriage return followed by a line feed) to a single "\n" (line feed...
Definition: util.cpp:44
folderdiaquotatab.h
Definition: aboutdata.cpp:40