• 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
vcardformat.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@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 "vcardformat.h"
22 #include "vcardconverter.h"
23 #include "address.h"
24 #include "addressee.h"
25 
26 #include <QtCore/QFile>
27 
28 using namespace KABC;
29 
30 VCardFormat::VCardFormat()
31  : d( 0 )
32 {
33 }
34 
35 VCardFormat::~VCardFormat()
36 {
37  //delete d;
38 }
39 
40 bool VCardFormat::load( Addressee &addressee, QFile *file )
41 {
42  QByteArray data;
43 
44  data = file->readAll();
45 
46  VCardConverter converter;
47  Addressee::List l = converter.parseVCards( data );
48 
49  if ( ! l.first().isEmpty() ) {
50  addressee = l.first();
51  return true;
52  }
53 
54  return false;
55 }
56 
57 bool VCardFormat::loadAll( AddressBook *, Resource *resource, QFile *file )
58 {
59  QByteArray data;
60 
61  data = file->readAll();
62 
63  VCardConverter converter;
64 
65  Addressee::List l = converter.parseVCards( data );
66 
67  Addressee::List::iterator itr;
68  for ( itr = l.begin(); itr != l.end(); ++itr ) {
69  Addressee addressee = *itr;
70  addressee.setResource( resource );
71  addressee.setChanged( false );
72  resource->insertAddressee( addressee );
73  }
74 
75  return true;
76 }
77 
78 void VCardFormat::save( const Addressee &addressee, QFile *file )
79 {
80  VCardConverter converter;
81  Addressee::List vcardlist;
82 
83  vcardlist.append( addressee );
84 
85  QByteArray data = converter.createVCards( vcardlist );
86 
87  file->write( data );
88 }
89 
90 void VCardFormat::saveAll( AddressBook *, Resource *resource, QFile *file )
91 {
92  VCardConverter converter;
93  Addressee::List vcardlist;
94 
95  Resource::Iterator it;
96  Resource::Iterator end( resource->end() );
97  for ( it = resource->begin(); it != end; ++it ) {
98  ( *it ).setChanged( false );
99  vcardlist.append( *it );
100  }
101 
102  QByteArray data = converter.createVCards( vcardlist );
103 
104  file->write( data );
105 }
106 
107 bool VCardFormat::checkFormat( QFile *file ) const
108 {
109  QByteArray line = file->readLine();
110  line = line.trimmed();
111  if ( line == "BEGIN:VCARD" ) {
112  return true;
113  } else {
114  return false;
115  }
116 }
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition: addresseelist.h:288
KABC::Addressee::setResource
void setResource(Resource *resource)
Set resource where the addressee is from.
Definition: addressee.cpp:1844
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::VCardFormat::loadAll
bool loadAll(AddressBook *, Resource *, QFile *file)
Load whole addressbook from file.
Definition: vcardformat.cpp:57
KABC::Resource::insertAddressee
virtual void insertAddressee(const Addressee &addr)
Insert an addressee into the resource.
Definition: resource.cpp:284
KABC::Addressee::setChanged
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.cpp:1855
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:53
KABC::Resource::end
virtual ConstIterator end() const
Returns an iterator pointing to the last addressee in the resource.
Definition: resource.cpp:257
KABC::VCardFormat::saveAll
void saveAll(AddressBook *, Resource *, QFile *file)
Save whole addressbook to file.
Definition: vcardformat.cpp:90
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::VCardFormat::save
void save(const Addressee &, QFile *file)
Save a single Addressee to file.
Definition: vcardformat.cpp:78
KABC::Resource::begin
virtual ConstIterator begin() const
Returns an iterator pointing to the first addressee in the resource.
Definition: resource.cpp:242
KABC::VCardFormat::checkFormat
bool checkFormat(QFile *file) const
Checks if given file contains the right format.
Definition: vcardformat.cpp:107
KABC::Addressee
address book entry
Definition: addressee.h:74
KABC::Resource
Definition: resource.h:64
KABC::VCardFormat::load
bool load(Addressee &, QFile *file)
Load single addressee from file.
Definition: vcardformat.cpp:40
KABC::AddressBook
Address Book.
Definition: addressbook.h:46
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