KContacts

vcarddrag.cpp
1/*
2 This file is part of the KContacts framework.
3
4 SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "vcarddrag.h"
10
11#include "converter/vcardconverter.h"
12
13#include <QMimeDatabase>
14
15using namespace KContacts;
16
17static QString findCompatibleMimeType(const QMimeData *md)
18{
19 if (!md) {
20 return {};
21 }
22 // check the canonical MIME type first
25 }
26
27 const QStringList mimeTypeOffers = md->formats();
28 const QMimeDatabase db;
29 for (const QString &mimeType : mimeTypeOffers) {
30 const QMimeType mimeTypePtr = db.mimeTypeForName(mimeType);
31 if (mimeTypePtr.isValid() && mimeTypePtr.inherits(KContacts::Addressee::mimeType())) {
32 return mimeType;
33 }
34 }
35
36 return QString();
37}
38
40{
42 return true;
43}
44
46{
48 const QByteArray vcards = converter.createVCards(addressees);
49 if (!vcards.isEmpty()) {
50 return populateMimeData(md, vcards);
51 } else {
52 return false;
53 }
54}
55
57{
58 return !findCompatibleMimeType(md).isEmpty();
59}
60
62{
63 const QString mimeOffer = findCompatibleMimeType(md);
64 if (mimeOffer.isEmpty()) {
65 return false;
66 }
67 content = md->data(mimeOffer);
68 return !content.isEmpty();
69}
70
72{
73 const QString mimeOffer = findCompatibleMimeType(md);
74 if (mimeOffer.isEmpty()) {
75 return false;
76 }
77 addressees = KContacts::VCardConverter().parseVCards(md->data(mimeOffer));
78 return !addressees.isEmpty();
79}
static QString mimeType()
Returns the MIME type used for Addressees.
Class to converting contact objects into vCard format and vice versa.
QByteArray createVCards(const Addressee::List &list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
Addressee::List parseVCards(const QByteArray &vcard) const
Parses a string in vCard format and returns a list of contact objects.
KCALUTILS_EXPORT QString mimeType()
KCONTACTS_EXPORT bool canDecode(const QMimeData *md)
Returns if drag&drop object can be decoded to vCard.
Definition vcarddrag.cpp:56
KCONTACTS_EXPORT bool fromMimeData(const QMimeData *md, QByteArray &content)
Decodes the drag&drop object to vCard component content.
Definition vcarddrag.cpp:61
KCONTACTS_EXPORT bool populateMimeData(QMimeData *md, const QByteArray &content)
Adds the vCard representation as data of the drag object.
Definition vcarddrag.cpp:39
bool isEmpty() const const
bool isEmpty() const const
QByteArray data(const QString &mimeType) const const
virtual QStringList formats() const const
virtual bool hasFormat(const QString &mimeType) const const
void setData(const QString &mimeType, const QByteArray &data)
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
bool inherits(const QString &mimeTypeName) const const
bool isValid() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.