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  QString scal = icf.toString(cal);
29 
30  if (me && !scal.isEmpty()) {
31  me->setData(mimeType(), scal.toUtf8());
32  }
33  return canDecode(me);
34 }
35 
36 bool ICalDrag::canDecode(const QMimeData *me)
37 {
38  if (me) {
39  return me->hasFormat(mimeType());
40  } else {
41  return false;
42  }
43 }
44 
45 bool ICalDrag::fromMimeData(const QMimeData *de, const Calendar::Ptr &cal)
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 }
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 Fri Sep 29 2023 04:03:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.