File indexing completed on 2024-05-12 05:15:04

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 "vcaldrag.h"
0010 
0011 #include <KCalendarCore/VCalFormat>
0012 using namespace KCalendarCore;
0013 
0014 #include <QMimeData>
0015 #include <QString>
0016 
0017 using namespace KCalUtils;
0018 using namespace VCalDrag;
0019 
0020 QString VCalDrag::mimeType()
0021 {
0022     return QStringLiteral("text/x-vCalendar");
0023 }
0024 
0025 bool VCalDrag::canDecode(const QMimeData *me)
0026 {
0027     if (me) {
0028         return me->hasFormat(mimeType());
0029     } else {
0030         return false;
0031     }
0032 }
0033 
0034 bool VCalDrag::fromMimeData(const QMimeData *de, const Calendar::Ptr &cal)
0035 {
0036     if (!canDecode(de)) {
0037         return false;
0038     }
0039 
0040     bool success = false;
0041     const QByteArray payload = de->data(mimeType());
0042     if (!payload.isEmpty()) {
0043         const QString txt = QString::fromUtf8(payload.data());
0044 
0045         VCalFormat format;
0046         success = format.fromString(cal, txt);
0047     }
0048 
0049     return success;
0050 }