libtdepim

kvcarddrag.cpp

00001 /*
00002     This file is part of libtdepim.
00003 
00004     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "kvcarddrag.h"
00023 
00024 #include <tdeabc/vcardconverter.h>
00025 
00026 static const char vcard_mime_string[] = "text/x-vcard";
00027 
00028 #if defined(KABC_VCARD_ENCODING_FIX)
00029 KVCardDrag::KVCardDrag( const TQByteArray &content, TQWidget *dragsource, const char *name )
00030 #else
00031 KVCardDrag::KVCardDrag( const TQString &content, TQWidget *dragsource, const char *name )
00032 #endif
00033   : TQStoredDrag( vcard_mime_string, dragsource, name )
00034 {
00035   setVCard( content );
00036 }
00037 
00038 KVCardDrag::KVCardDrag( TQWidget *dragsource, const char *name )
00039   : TQStoredDrag( vcard_mime_string, dragsource, name )
00040 {
00041 #if defined(KABC_VCARD_ENCODING_FIX)
00042   setVCard( TQByteArray() );
00043 #else
00044   setVCard( TQString() );
00045 #endif
00046 }
00047 
00048 #if defined(KABC_VCARD_ENCODING_FIX)
00049 void KVCardDrag::setVCard( const TQByteArray &content )
00050 {
00051   setEncodedData( content );
00052 }
00053 #else
00054 void KVCardDrag::setVCard( const TQString &content )
00055 {
00056   setEncodedData( content.utf8() );
00057 }
00058 #endif
00059 
00060 bool KVCardDrag::canDecode( TQMimeSource *e )
00061 {
00062   return e->provides( vcard_mime_string );
00063 }
00064 
00065 #if defined(KABC_VCARD_ENCODING_FIX)
00066 bool KVCardDrag::decode( TQMimeSource *e, TQByteArray &content )
00067 {
00068   if ( !canDecode( e ) ) {
00069     return false;
00070   }
00071   content = e->encodedData( vcard_mime_string );
00072   return true;
00073 }
00074 #else
00075 bool KVCardDrag::decode( TQMimeSource *e, TQString &content )
00076 {
00077   if ( !canDecode( e ) ) {
00078     return false;
00079   }
00080   content = TQString::fromUtf8( e->encodedData( vcard_mime_string ) );
00081   return true;
00082 }
00083 #endif
00084 
00085 bool KVCardDrag::decode( TQMimeSource *e, TDEABC::Addressee::List& addressees )
00086 {
00087   if ( !canDecode( e ) ) {
00088     return false;
00089   }
00090 #if defined(KABC_VCARD_ENCODING_FIX)
00091   addressees = TDEABC::VCardConverter().parseVCardsRaw( e->encodedData( vcard_mime_string ).data() );
00092 #else
00093   addressees = TDEABC::VCardConverter().parseVCards( e->encodedData( vcard_mime_string ) );
00094 #endif
00095   return true;
00096 }
00097 
00098 void KVCardDrag::virtual_hook( int, void* )
00099 { /*BASE::virtual_hook( id, data );*/ }
00100 
00101 #include "kvcarddrag.moc"