1 /*******************************************************************************
4 ** Created on : 03 April, 2005
5 ** Copyright : (c) 2005 Till Adam
6 ** Email : <adam@kde.org>
8 *******************************************************************************/
10 /*******************************************************************************
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.
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.
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
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 Qt library by Trolltech AS, Norway (or with modified versions
29 ** of Qt that use the same license as Qt), 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 ** Qt. 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
37 *******************************************************************************/
43 #include <mimelib/string.h>
45 void KMail::Util::reconnectSignalSlotPair( QObject
*src
, const char *signal
, QObject
*dst
, const char *slot
)
47 QObject::disconnect( src
, signal
, dst
, slot
);
48 QObject::connect( src
, signal
, dst
, slot
);
52 size_t KMail::Util::crlf2lf( char* str
, const size_t strLen
)
54 if ( !str
|| strLen
== 0 )
57 const char* source
= str
;
58 const char* sourceEnd
= source
+ strLen
;
60 // search the first occurrence of "\r\n"
61 for ( ; source
< sourceEnd
- 1; ++source
) {
62 if ( *source
== '\r' && *( source
+ 1 ) == '\n' )
66 if ( source
== sourceEnd
- 1 ) {
71 // replace all occurrences of "\r\n" with "\n" (in place)
72 char* target
= const_cast<char*>( source
); // target points to '\r'
73 ++source
; // source points to '\n'
74 for ( ; source
< sourceEnd
; ++source
) {
75 if ( *source
!= '\r' || *( source
+ 1 ) != '\n' )
78 *target
= '\0'; // terminate result
82 QByteArray
KMail::Util::lf2crlf( const QByteArray
& src
)
85 result
.resize( 2*src
.size() ); // maximal possible length
87 QByteArray::ConstIterator s
= src
.begin();
88 QByteArray::Iterator d
= result
.begin();
89 // we use cPrev to make sure we insert '\r' only there where it is missing
91 const char* end
= src
.end();
93 if ( ('\n' == *s
) && ('\r' != cPrev
) )
98 result
.truncate( d
- result
.begin() );
102 QByteArray
KMail::Util::ByteArray( const DwString
& str
)
104 const int strLen
= str
.size();
106 arr
.resize( strLen
);
107 memcpy( arr
.data(), str
.data(), strLen
);
111 DwString
KMail::Util::dwString( const QByteArray
& str
)
113 if ( !str
.data() ) // DwString doesn't like char*=0
115 return DwString( str
.data(), str
.size() );
118 bool KMail::Util::checkOverwrite( const KUrl
&url
, QWidget
*w
)
120 if ( KIO::NetAccess::exists( url
, KIO::NetAccess::DestinationSide
, w
) ) {
121 if ( KMessageBox::Cancel
== KMessageBox::warningContinueCancel(
123 i18n( "A file named \"%1\" already exists. "
124 "Are you sure you want to overwrite it?", url
.prettyUrl() ),
125 i18n( "Overwrite File?" ),
126 KStandardGuiItem::overwrite() ) )
133 #include <QDesktopServices>
136 bool KMail::Util::handleUrlOnMac( const KUrl
& url
)
139 QDesktopServices::openUrl( url
);