• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kabc

  • sources
  • kde-4.12
  • kdepimlibs
  • kabc
vcarddrag.cpp
1 /*
2  This file is part of libkabc.
3 
4  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
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 "vcardconverter.h"
25 
26 #include <KMimeType>
27 
28 #include <QMimeData>
29 
30 using namespace KABC;
31 
32 static QString findCompatibleMimeType( const QMimeData *md )
33 {
34  // check the canonical MIME type first
35  if ( md->hasFormat( KABC::Addressee::mimeType() ) ) {
36  return KABC::Addressee::mimeType();
37  }
38 
39  const QStringList mimeTypeOffers = md->formats();
40  Q_FOREACH ( const QString &mimeType, mimeTypeOffers ) {
41  const KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
42  if ( !mimeTypePtr.isNull() ) {
43  if ( mimeTypePtr->is( KABC::Addressee::mimeType() ) ) {
44  return mimeType;
45  }
46  }
47  }
48 
49  return QString();
50 }
51 
52 bool VCardDrag::populateMimeData( QMimeData *md, const QByteArray &content )
53 {
54  md->setData( KABC::Addressee::mimeType(), content );
55  return true;
56 }
57 
58 bool VCardDrag::populateMimeData( QMimeData *md, const KABC::Addressee::List &addressees )
59 {
60  KABC::VCardConverter converter;
61  const QByteArray vcards = converter.createVCards( addressees );
62  if ( !vcards.isEmpty() ) {
63  return populateMimeData( md, vcards );
64  } else {
65  return false;
66  }
67 }
68 
69 bool VCardDrag::canDecode( const QMimeData *md )
70 {
71  return !findCompatibleMimeType( md ).isEmpty();
72 }
73 
74 bool VCardDrag::fromMimeData( const QMimeData *md, QByteArray &content )
75 {
76  const QString mimeOffer = findCompatibleMimeType( md );
77  if ( mimeOffer.isEmpty() ) {
78  return false;
79  }
80  content = md->data( mimeOffer );
81  return !content.isEmpty();
82 }
83 
84 bool VCardDrag::fromMimeData( const QMimeData *md, KABC::Addressee::List &addressees )
85 {
86  const QString mimeOffer = findCompatibleMimeType( md );
87  if ( mimeOffer.isEmpty() ) {
88  return false;
89  }
90  addressees = KABC::VCardConverter().parseVCards( md->data( mimeOffer ) );
91  return !addressees.isEmpty();
92 }
93 
94 // kate: space-indent on; indent-width 2; replace-tabs on;
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition: addresseelist.h:288
KABC::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:72
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:53
KABC::VCardDrag::fromMimeData
bool fromMimeData(const QMimeData *md, QByteArray &content)
Decodes the drag&drop object to vCard component content.
Definition: vcarddrag.cpp:74
KABC::VCardConverter::createVCards
QByteArray createVCards(Addressee::List list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
Definition: vcardconverter.cpp:58
KABC::VCardDrag::populateMimeData
bool populateMimeData(QMimeData *md, const QByteArray &content)
Adds the vCard representation as data of the drag object.
Definition: vcarddrag.cpp:52
KABC::Addressee::mimeType
static QString mimeType()
Returns the MIME type used for Addressees.
Definition: addressee.cpp:1878
KABC::VCardDrag::canDecode
bool canDecode(const QMimeData *md)
Returns if drag&drop object can be decoded to vCard.
Definition: vcarddrag.cpp:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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