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

kabc

  • kabc
vcardconverter.cpp
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "vcardconverter.h"
22#include "vcardtool.h"
23
24using namespace KABC;
25
26VCardConverter::VCardConverter()
27 : d( 0 )
28{
29}
30
31VCardConverter::~VCardConverter()
32{
33}
34
35QByteArray VCardConverter::exportVCard( const Addressee &addr, Version version ) const
36{
37 Addressee::List list;
38 list.append( addr );
39
40 return exportVCards( list, version );
41}
42
43QByteArray VCardConverter::exportVCards( const Addressee::List &list, Version version ) const
44{
45 VCardTool tool;
46 QByteArray returnValue;
47 switch (version) {
48 case v2_1:
49 returnValue = tool.exportVCards( list, VCard::v2_1 );
50 break;
51 case v3_0:
52 returnValue = tool.exportVCards( list, VCard::v3_0 );
53 break;
54 case v4_0:
55 returnValue = tool.exportVCards( list, VCard::v4_0 );
56 break;
57 }
58
59 return returnValue;
60}
61
62QByteArray VCardConverter::createVCard( const Addressee &addr, Version version ) const
63{
64 Addressee::List list;
65 list.append( addr );
66
67 return createVCards( list, version );
68}
69
70QByteArray VCardConverter::createVCards( Addressee::List list, Version version ) const
71{
72 VCardTool tool;
73 QByteArray returnValue;
74 switch (version) {
75 case v2_1:
76 returnValue = tool.createVCards( list, VCard::v2_1 );
77 break;
78 case v3_0:
79 returnValue = tool.createVCards( list, VCard::v3_0 );
80 break;
81 case v4_0:
82 returnValue = tool.createVCards( list, VCard::v4_0 );
83 break;
84 }
85
86 return returnValue;
87}
88
89Addressee VCardConverter::parseVCard( const QByteArray &vcard ) const
90{
91 Addressee::List list = parseVCards( vcard );
92
93 return list.isEmpty() ? Addressee() : list[ 0 ];
94}
95
96Addressee::List VCardConverter::parseVCards( const QByteArray &vcard ) const
97{
98 VCardTool tool;
99
100 return tool.parseVCards( vcard );
101}
102
103/* Helper functions */
104
105QString KABC::dateToVCardString( const QDateTime &dateTime )
106{
107 return dateTime.toString( QLatin1String( "yyyyMMddThhmmssZ" ) );
108}
109
110QString KABC::dateToVCardString( const QDate &date )
111{
112 return date.toString( QLatin1String( "yyyyMMdd" ) );
113}
114
115QDateTime KABC::VCardStringToDate( const QString &dateString )
116{
117 QDate date;
118 QTime time;
119 QString d( dateString );
120
121 d = d.remove( QLatin1Char( '-' ) ).remove( QLatin1Char( ':' ) );
122
123 if ( d.length() >= 8 ) {
124 date = QDate( d.mid( 0, 4 ).toUInt(), d.mid( 4, 2 ).toUInt(), d.mid( 6, 2 ).toUInt() );
125 }
126
127 if ( d.length() > 9 && d[ 8 ].toUpper() == QLatin1Char( 'T' ) ) {
128 time = QTime( d.mid( 9, 2 ).toUInt(), d.mid( 11, 2 ).toUInt(), d.mid( 13, 2 ).toUInt() );
129 }
130
131 return QDateTime( date, time );
132}
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition addresseelist.h:289
KABC::Addressee
address book entry
Definition addressee.h:79
KABC::VCardConverter::~VCardConverter
~VCardConverter()
Destructor.
Definition vcardconverter.cpp:31
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:70
KABC::VCardConverter::Version
Version
Definition vcardconverter.h:62
KABC::VCardConverter::exportVCard
QByteArray exportVCard(const Addressee &addr, Version version) const
Definition vcardconverter.cpp:35
KABC::VCardConverter::VCardConverter
VCardConverter()
Constructor.
Definition vcardconverter.cpp:26
KABC::VCardConverter::parseVCard
Addressee parseVCard(const QByteArray &vcard) const
Parses a string in vCard format and returns the first contact.
Definition vcardconverter.cpp:89
KABC::VCardConverter::createVCard
QByteArray createVCard(const Addressee &addr, Version version=v3_0) const
Creates a string in vCard format which contains the given contact.
Definition vcardconverter.cpp:62
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:96
KABC::VCardConverter::exportVCards
QByteArray exportVCards(const Addressee::List &list, Version version) const
Definition vcardconverter.cpp:43
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition address.h:29
KABC::VCardStringToDate
QDateTime VCardStringToDate(const QString &dateString)
Converts a date string as it is used in VCard and LDIF files to a QDateTime value.
Definition vcardconverter.cpp:115
KABC::dateToVCardString
QString dateToVCardString(const QDateTime &dateTime)
Helper functions.
Definition vcardconverter.cpp:105
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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