1/*
2 This file is part of the kcal library.
3
4 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "vcaldrag.h"
24
25#include "vcalformat.h"
26#include <QtCore/QMimeData>
27
28using namespace KCal;
29
30QString VCalDrag::mimeType()
31{
32 return "text/x-vCalendar";
33}
34
35bool VCalDrag::populateMimeData( QMimeData *e, Calendar *cal )
36{
37 VCalFormat format;
38 QString calstr( format.toString( cal ) );
39 if ( calstr.length() > 0 ) {
40 e->setData( mimeType(), calstr.toUtf8() );
41 }
42 return canDecode( e );
43}
44
45bool VCalDrag::canDecode( const QMimeData *me )
46{
47 return me->hasFormat( mimeType() );
48}
49
50bool VCalDrag::fromMimeData( const QMimeData *de, Calendar *cal )
51{
52 if ( !canDecode( de ) ) {
53 return false;
54 }
55
56 bool success = false;
57 QByteArray payload = de->data( mimeType() );
58 if ( payload.size() ) {
59 QString txt = QString::fromUtf8( payload.data() );
60
61 VCalFormat format;
62 success = format.fromString( cal, txt );
63 }
64
65 return success;
66}
67
68