KCalUtils

vcaldrag.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 "vcaldrag.h"
10 
11 #include <KCalendarCore/VCalFormat>
12 using namespace KCalendarCore;
13 
14 #include <QMimeData>
15 #include <QString>
16 
17 using namespace KCalUtils;
18 using namespace VCalDrag;
19 
20 QString VCalDrag::mimeType()
21 {
22  return QStringLiteral("text/x-vCalendar");
23 }
24 
25 bool VCalDrag::canDecode(const QMimeData *me)
26 {
27  if (me) {
28  return me->hasFormat(mimeType());
29  } else {
30  return false;
31  }
32 }
33 
34 bool VCalDrag::fromMimeData(const QMimeData *de, const Calendar::Ptr &cal)
35 {
36  if (!canDecode(de)) {
37  return false;
38  }
39 
40  bool success = false;
41  const QByteArray payload = de->data(mimeType());
42  if (!payload.isEmpty()) {
43  const QString txt = QString::fromUtf8(payload.data());
44 
45  VCalFormat format;
46  success = format.fromString(cal, txt);
47  }
48 
49  return success;
50 }
QByteArray data(const QString &mimeType) const const
QString fromUtf8(const char *str, int size)
virtual bool hasFormat(const QString &mimeType) const const
bool fromString(const Calendar::Ptr &calendar, const QString &string, bool deleted, const QString &notebook=QString()) override
bool isEmpty() const const
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:09:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.