File indexing completed on 2024-05-12 05:15:01
0001 /* 0002 This file is part of the kcalutils library. 0003 0004 SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org> 0005 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 #include "icaldrag.h" 0010 0011 #include <KCalendarCore/ICalFormat> 0012 using namespace KCalendarCore; 0013 0014 #include <QMimeData> 0015 #include <QString> 0016 0017 using namespace KCalUtils; 0018 using namespace ICalDrag; 0019 0020 QString ICalDrag::mimeType() 0021 { 0022 return QStringLiteral("text/calendar"); 0023 } 0024 0025 bool ICalDrag::populateMimeData(QMimeData *me, const Calendar::Ptr &cal) 0026 { 0027 ICalFormat icf; 0028 QString scal = icf.toString(cal); 0029 0030 if (me && !scal.isEmpty()) { 0031 me->setData(mimeType(), scal.toUtf8()); 0032 } 0033 return canDecode(me); 0034 } 0035 0036 bool ICalDrag::canDecode(const QMimeData *me) 0037 { 0038 if (me) { 0039 return me->hasFormat(mimeType()); 0040 } else { 0041 return false; 0042 } 0043 } 0044 0045 bool ICalDrag::fromMimeData(const QMimeData *de, const Calendar::Ptr &cal) 0046 { 0047 if (!canDecode(de)) { 0048 return false; 0049 } 0050 bool success = false; 0051 0052 QByteArray payload = de->data(mimeType()); 0053 if (!payload.isEmpty()) { 0054 QString txt = QString::fromUtf8(payload.data()); 0055 0056 ICalFormat icf; 0057 success = icf.fromString(cal, txt); 0058 } 0059 0060 return success; 0061 }