KCalUtils

icaldrag.cpp
1/*
2 This file is part of the kcalutils library.
3
4 SPDX-FileCopyrightText: 1998 Preston Brown <pbrown@kde.org>
5 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9#include "icaldrag.h"
10
11#include <KCalendarCore/ICalFormat>
12using namespace KCalendarCore;
13
14#include <QMimeData>
15#include <QString>
16
17using namespace KCalUtils;
18using namespace ICalDrag;
19
21{
22 return QStringLiteral("text/calendar");
23}
24
26{
27 ICalFormat icf;
28 QString scal = icf.toString(cal);
29
30 if (me && !scal.isEmpty()) {
31 me->setData(mimeType(), scal.toUtf8());
32 }
33 return canDecode(me);
34}
35
37{
38 if (me) {
39 return me->hasFormat(mimeType());
40 } else {
41 return false;
42 }
43}
44
46{
47 if (!canDecode(de)) {
48 return false;
49 }
50 bool success = false;
51
52 QByteArray payload = de->data(mimeType());
53 if (!payload.isEmpty()) {
54 QString txt = QString::fromUtf8(payload.data());
55
56 ICalFormat icf;
57 success = icf.fromString(cal, txt);
58 }
59
60 return success;
61}
QString toString(const Calendar::Ptr &calendar) override
bool fromString(const Calendar::Ptr &calendar, const QString &string)
KCALUTILS_EXPORT QString mimeType()
Mime-type of iCalendar.
Definition icaldrag.cpp:20
KCALUTILS_EXPORT bool fromMimeData(const QMimeData *e, const KCalendarCore::Calendar::Ptr &cal)
Decode drag&drop object to iCalendar component cal.
Definition icaldrag.cpp:45
KCALUTILS_EXPORT bool canDecode(const QMimeData *)
Return, if drag&drop object can be decode to iCalendar.
Definition icaldrag.cpp:36
KCALUTILS_EXPORT bool populateMimeData(QMimeData *e, const KCalendarCore::Calendar::Ptr &cal)
Sets the iCalendar representation as data of the drag object.
Definition icaldrag.cpp:25
char * data()
bool isEmpty() const const
QByteArray data(const QString &mimeType) const const
virtual bool hasFormat(const QString &mimeType) const const
void setData(const QString &mimeType, const QByteArray &data)
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.