• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. The KDE Frameworks
  3. KContacts
  • KDE Home
  • Contact Us

Quick Links

Skip menu "KContacts"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Dependencies
  • Related Pages

Class Picker

About

Address book API for KDE

Maintainer
Laurent Montel
Supported platforms
Android, FreeBSD, iOS, Linux, MacOSX, Windows
Community
IRC: #kde-devel on Freenode
Mailing list: kde-frameworks-devel
Use with CMake
find_package(KF5Contacts)
target_link_libraries(yourapp KF5::Contacts)
Use with QMake
QT += KContacts 
Clone
git clone git://anongit.kde.org/kcontacts.git
Browse source
KContacts on cgit.kde.org

KContacts

  • frameworks
  • frameworks
  • kcontacts
  • src
vcarddrag.cpp
1 /*
2  This file is part of the KContacts framework.
3 
4  Copyright (c) 2002 Tobias Koenig <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "vcarddrag.h"
23 
24 #include "converter/vcardconverter.h"
25 
26 #include <QMimeData>
27 #include <QMimeDatabase>
28 
29 using namespace KContacts;
30 
31 static QString findCompatibleMimeType(const QMimeData *md)
32 {
33  if (!md) {
34  return {};
35  }
36  // check the canonical MIME type first
37  if (md->hasFormat(KContacts::Addressee::mimeType())) {
38  return KContacts::Addressee::mimeType();
39  }
40 
41  const QStringList mimeTypeOffers = md->formats();
42  const QMimeDatabase db;
43  for (const QString &mimeType : mimeTypeOffers) {
44  const QMimeType mimeTypePtr = db.mimeTypeForName(mimeType);
45  if (mimeTypePtr.isValid() && mimeTypePtr.inherits(KContacts::Addressee::mimeType())) {
46  return mimeType;
47  }
48  }
49 
50  return QString();
51 }
52 
53 bool VCardDrag::populateMimeData(QMimeData *md, const QByteArray &content)
54 {
55  md->setData(KContacts::Addressee::mimeType(), content);
56  return true;
57 }
58 
59 bool VCardDrag::populateMimeData(QMimeData *md, const KContacts::Addressee::List &addressees)
60 {
61  KContacts::VCardConverter converter;
62  const QByteArray vcards = converter.createVCards(addressees);
63  if (!vcards.isEmpty()) {
64  return populateMimeData(md, vcards);
65  } else {
66  return false;
67  }
68 }
69 
70 bool VCardDrag::canDecode(const QMimeData *md)
71 {
72  return !findCompatibleMimeType(md).isEmpty();
73 }
74 
75 bool VCardDrag::fromMimeData(const QMimeData *md, QByteArray &content)
76 {
77  const QString mimeOffer = findCompatibleMimeType(md);
78  if (mimeOffer.isEmpty()) {
79  return false;
80  }
81  content = md->data(mimeOffer);
82  return !content.isEmpty();
83 }
84 
85 bool VCardDrag::fromMimeData(const QMimeData *md, KContacts::Addressee::List &addressees)
86 {
87  const QString mimeOffer = findCompatibleMimeType(md);
88  if (mimeOffer.isEmpty()) {
89  return false;
90  }
91  addressees = KContacts::VCardConverter().parseVCards(md->data(mimeOffer));
92  return !addressees.isEmpty();
93 }
KContacts::Addressee::mimeType
static QString mimeType()
Returns the MIME type used for Addressees.
Definition: addressee.cpp:2503
QMimeData::data
QByteArray data(const QString &mimeType) const
QByteArray
QMimeData::hasFormat
virtual bool hasFormat(const QString &mimeType) const
QMimeType::isValid
bool isValid() const
QMimeDatabase
QByteArray::isEmpty
bool isEmpty() const
QMimeType::inherits
bool inherits(const QString &mimeTypeName) const
KContacts::VCardDrag::fromMimeData
KCONTACTS_EXPORT bool fromMimeData(const QMimeData *md, QByteArray &content)
Decodes the drag&drop object to vCard component content.
Definition: vcarddrag.cpp:75
QMimeData
KContacts::VCardConverter::parseVCards
Addressee::List parseVCards(const QByteArray &vcard) const
Parses a string in vCard format and returns a list of contact objects.
Definition: vcardconverter.cpp:96
QMimeType
QString::isEmpty
bool isEmpty() const
QString
QMimeDatabase::mimeTypeForName
QMimeType mimeTypeForName(const QString &nameOrAlias) const
QStringList
KContacts::VCardDrag::canDecode
KCONTACTS_EXPORT bool canDecode(const QMimeData *md)
Returns if drag&drop object can be decoded to vCard.
Definition: vcarddrag.cpp:70
KContacts::VCardDrag::populateMimeData
KCONTACTS_EXPORT bool populateMimeData(QMimeData *md, const QByteArray &content)
Adds the vCard representation as data of the drag object.
Definition: vcarddrag.cpp:53
KContacts::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:52
KContacts
Definition: address.h:32
QVector
QVector::isEmpty
bool isEmpty() const
QMimeData::formats
virtual QStringList formats() const
QMimeData::setData
void setData(const QString &mimeType, const QByteArray &data)
KAlarmCal::CalEvent::mimeType
QString mimeType(Type)
KContacts::VCardConverter::createVCards
QByteArray createVCards(const Addressee::List &list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
Definition: vcardconverter.cpp:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Fri Dec 6 2019 03:47:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal