libtdepim

kvcarddrag.cpp
1/*
2 This file is part of libtdepim.
3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "kvcarddrag.h"
23
24#include <tdeabc/vcardconverter.h>
25
26static const char vcard_mime_string[] = "text/x-vcard";
27
28#if defined(KABC_VCARD_ENCODING_FIX)
29KVCardDrag::KVCardDrag( const TQByteArray &content, TQWidget *dragsource, const char *name )
30#else
31KVCardDrag::KVCardDrag( const TQString &content, TQWidget *dragsource, const char *name )
32#endif
33 : TQStoredDrag( vcard_mime_string, dragsource, name )
34{
35 setVCard( content );
36}
37
38KVCardDrag::KVCardDrag( TQWidget *dragsource, const char *name )
39 : TQStoredDrag( vcard_mime_string, dragsource, name )
40{
41#if defined(KABC_VCARD_ENCODING_FIX)
42 setVCard( TQByteArray() );
43#else
44 setVCard( TQString() );
45#endif
46}
47
48#if defined(KABC_VCARD_ENCODING_FIX)
49void KVCardDrag::setVCard( const TQByteArray &content )
50{
51 setEncodedData( content );
52}
53#else
54void KVCardDrag::setVCard( const TQString &content )
55{
56 setEncodedData( content.utf8() );
57}
58#endif
59
60bool KVCardDrag::canDecode( TQMimeSource *e )
61{
62 return e->provides( vcard_mime_string );
63}
64
65#if defined(KABC_VCARD_ENCODING_FIX)
66bool KVCardDrag::decode( TQMimeSource *e, TQByteArray &content )
67{
68 if ( !canDecode( e ) ) {
69 return false;
70 }
71 content = e->encodedData( vcard_mime_string );
72 return true;
73}
74#else
75bool KVCardDrag::decode( TQMimeSource *e, TQString &content )
76{
77 if ( !canDecode( e ) ) {
78 return false;
79 }
80 content = TQString::fromUtf8( e->encodedData( vcard_mime_string ) );
81 return true;
82}
83#endif
84
85bool KVCardDrag::decode( TQMimeSource *e, TDEABC::Addressee::List& addressees )
86{
87 if ( !canDecode( e ) ) {
88 return false;
89 }
90#if defined(KABC_VCARD_ENCODING_FIX)
91 addressees = TDEABC::VCardConverter().parseVCardsRaw( e->encodedData( vcard_mime_string ).data() );
92#else
93 addressees = TDEABC::VCardConverter().parseVCards( e->encodedData( vcard_mime_string ) );
94#endif
95 return true;
96}
97
98void KVCardDrag::virtual_hook( int, void* )
99{ /*BASE::virtual_hook( id, data );*/ }
100
101#include "kvcarddrag.moc"
KVCardDrag(TQWidget *dragsource=0, const char *name=0)
Constructs an empty vcard drag.
Definition: kvcarddrag.cpp:38
void setVCard(const TQString &content)
Sets the vcard of the drag to content.
Definition: kvcarddrag.cpp:54
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a vcard object.
Definition: kvcarddrag.cpp:60
static bool decode(TQMimeSource *e, TQString &content)
Decodes the MIME source e and puts the resulting vcard into content.
Definition: kvcarddrag.cpp:75