KCalUtils

icaldrag.cpp
1 /*
2  This file is part of the kcalutils library.
3 
4  SPDX-FileCopyrightText: 1998 Preston Brown <[email protected]>
5  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 #include "icaldrag.h"
10 
11 #include <KCalendarCore/ICalFormat>
12 using namespace KCalendarCore;
13 
14 #include <QMimeData>
15 #include <QString>
16 
17 using namespace KCalUtils;
18 using namespace ICalDrag;
19 
20 QString ICalDrag::mimeType()
21 {
22  return QStringLiteral("text/calendar");
23 }
24 
25 bool ICalDrag::populateMimeData(QMimeData *me, const Calendar::Ptr &cal)
26 {
27  ICalFormat icf;
28 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
29  QString scal = icf.toString(cal, QString(), false);
30 #else
31  QString scal = icf.toString(cal, QString());
32 #endif
33 
34  if (me && !scal.isEmpty()) {
35  me->setData(mimeType(), scal.toUtf8());
36  }
37  return canDecode(me);
38 }
39 
40 bool ICalDrag::canDecode(const QMimeData *me)
41 {
42  if (me) {
43  return me->hasFormat(mimeType());
44  } else {
45  return false;
46  }
47 }
48 
49 bool ICalDrag::fromMimeData(const QMimeData *de, const Calendar::Ptr &cal)
50 {
51  if (!canDecode(de)) {
52  return false;
53  }
54  bool success = false;
55 
56  QByteArray payload = de->data(mimeType());
57  if (!payload.isEmpty()) {
58  QString txt = QString::fromUtf8(payload.data());
59 
60  ICalFormat icf;
61  success = icf.fromString(cal, txt);
62  }
63 
64  return success;
65 }
QByteArray data(const QString &mimeType) const const
QString fromUtf8(const char *str, int size)
void setData(const QString &mimeType, const QByteArray &data)
QString toString(const Calendar::Ptr &calendar, const QString &notebook=QString(), bool deleted=false) override
KCALUTILS_EXPORT QString mimeType()
Mime-type of iCalendar.
Definition: icaldrag.cpp:20
bool fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted, const QString &notebook) override
bool isEmpty() const const
QByteArray toUtf8() const const
virtual bool hasFormat(const QString &mimeType) const const
bool isEmpty() const const
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:10:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.