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 MemoryCalendar::Ptr &cal)
26 {
27  ICalFormat icf;
28  QString scal = icf.toString(cal, QString(), false);
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 MemoryCalendar::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
virtual bool hasFormat(const QString &mimeType) const const
bool isEmpty() const const
QString fromUtf8(const char *str, int size)
bool isEmpty() const const
QString toString(const Calendar::Ptr &calendar, const QString &notebook=QString(), bool deleted=false) override
char * data()
void setData(const QString &mimeType, const QByteArray &data)
bool fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted=false, const QString &notebook=QString()) override
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 23:12:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.