KCalUtils Library
icaldrag.cpp
00001 /* 00002 This file is part of the kcalutils library. 00003 00004 Copyright (c) 1998 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #include "icaldrag.h" 00023 00024 #include <kcalcore/icalformat.h> 00025 using namespace KCalCore; 00026 00027 #include <QtCore/QMimeData> 00028 #include <QtCore/QString> 00029 00030 using namespace KCalUtils; 00031 using namespace ICalDrag; 00032 00033 QString ICalDrag::mimeType() 00034 { 00035 return "text/calendar"; 00036 } 00037 00038 bool ICalDrag::populateMimeData( QMimeData *me, const MemoryCalendar::Ptr &cal ) 00039 { 00040 ICalFormat icf; 00041 QString scal = icf.toString( cal, QString(), false ); 00042 00043 if ( scal.length()>0 ){ 00044 me->setData( mimeType(), scal.toUtf8() ); 00045 } 00046 return canDecode( me ); 00047 } 00048 00049 bool ICalDrag::canDecode( const QMimeData *me ) 00050 { 00051 return me->hasFormat( mimeType() ); 00052 } 00053 00054 bool ICalDrag::fromMimeData( const QMimeData *de, const MemoryCalendar::Ptr &cal ) 00055 { 00056 if ( !canDecode( de ) ) { 00057 return false; 00058 } 00059 bool success = false; 00060 00061 QByteArray payload = de->data( mimeType() ); 00062 if ( payload.size() ) { 00063 QString txt = QString::fromUtf8( payload.data() ); 00064 00065 ICalFormat icf; 00066 success = icf.fromString( cal, txt ); 00067 } 00068 00069 return success; 00070 } 00071
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:01 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:01 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.