• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

kabc

vcarddrag.cpp
00001 /*
00002   This file is part of libkabc.
00003 
00004   Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015 
00016   You should have received a copy of the GNU Library General Public License
00017   along with this library; see the file COPYING.LIB.  If not, write to
00018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "vcarddrag.h"
00023 
00024 #include "vcardconverter.h"
00025 
00026 #include <KMimeType>
00027 
00028 #include <QMimeData>
00029 
00030 using namespace KABC;
00031 
00032 static QString findCompatibleMimeType( const QMimeData *md )
00033 {
00034   // check the canonical MIME type first
00035   if ( md->hasFormat( KABC::Addressee::mimeType() ) ) {
00036     return KABC::Addressee::mimeType();
00037   }
00038 
00039   const QStringList mimeTypeOffers = md->formats();
00040   Q_FOREACH ( const QString &mimeType, mimeTypeOffers ) {
00041     const KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
00042     if ( !mimeTypePtr.isNull() ) {
00043       if ( mimeTypePtr->is( KABC::Addressee::mimeType() ) ) {
00044         return mimeType;
00045       }
00046     }
00047   }
00048 
00049   return QString();
00050 }
00051 
00052 bool VCardDrag::populateMimeData( QMimeData *md, const QByteArray &content )
00053 {
00054   md->setData( KABC::Addressee::mimeType(), content );
00055   return true;
00056 }
00057 
00058 bool VCardDrag::populateMimeData( QMimeData *md, const KABC::Addressee::List &addressees )
00059 {
00060   KABC::VCardConverter converter;
00061   const QByteArray vcards = converter.createVCards( addressees );
00062   if ( !vcards.isEmpty() ) {
00063     return populateMimeData( md, vcards );
00064   } else {
00065     return false;
00066   }
00067 }
00068 
00069 bool VCardDrag::canDecode( const QMimeData *md )
00070 {
00071   return !findCompatibleMimeType( md ).isEmpty();
00072 }
00073 
00074 bool VCardDrag::fromMimeData( const QMimeData *md, QByteArray &content )
00075 {
00076   const QString mimeOffer = findCompatibleMimeType( md );
00077   if ( mimeOffer.isEmpty() ) {
00078     return false;
00079   }
00080   content = md->data( mimeOffer );
00081   return !content.isEmpty();
00082 }
00083 
00084 bool VCardDrag::fromMimeData( const QMimeData *md, KABC::Addressee::List &addressees )
00085 {
00086   const QString mimeOffer = findCompatibleMimeType( md );
00087   if ( mimeOffer.isEmpty() ) {
00088     return false;
00089   }
00090   addressees = KABC::VCardConverter().parseVCards( md->data( mimeOffer ) );
00091   return !addressees.isEmpty();
00092 }
00093 
00094 // kate: space-indent on; indent-width 2; replace-tabs on;

kabc

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal