• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kabc
 

kabc

  • kabc
vcardformatplugin.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 <tqfile.h>
22 
23 #include "address.h"
24 #include "addressee.h"
25 #include "vcardconverter.h"
26 
27 #include "vcardformatplugin.h"
28 
29 using namespace KABC;
30 
31 VCardFormatPlugin::VCardFormatPlugin()
32 {
33 }
34 
35 VCardFormatPlugin::~VCardFormatPlugin()
36 {
37 }
38 
39 bool VCardFormatPlugin::load( Addressee &addressee, TQFile *file )
40 {
41  TQString data;
42 
43  TQTextStream t( file );
44  t.setEncoding( TQTextStream::Latin1 );
45  data = t.read();
46 
47  VCardConverter converter;
48  Addressee::List l = converter.parseVCards( data );
49 
50  if ( ! l.first().isEmpty() ) {
51  addressee = l.first();
52  return true;
53  }
54 
55  return false;
56 }
57 
58 bool VCardFormatPlugin::loadAll( AddressBook*, Resource *resource, TQFile *file )
59 {
60  TQString data;
61 
62  TQTextStream t( file );
63  t.setEncoding( TQTextStream::Latin1 );
64  data = t.read();
65 
66  VCardConverter converter;
67 
68  Addressee::List l = converter.parseVCards( data );
69 
70  Addressee::List::iterator itr;
71  for ( itr = l.begin(); itr != l.end(); ++itr) {
72  Addressee addressee = *itr;
73  addressee.setResource( resource );
74  addressee.setChanged( false );
75  resource->insertAddressee( addressee );
76  }
77 
78  return true;
79 }
80 
81 void VCardFormatPlugin::save( const Addressee &addressee, TQFile *file )
82 {
83  VCardConverter converter ;
84  Addressee::List vcardlist;
85 
86 
87  vcardlist.append( addressee );
88 
89  TQTextStream t( file );
90  t.setEncoding( TQTextStream::UnicodeUTF8 );
91  t << converter.createVCards( vcardlist );
92 }
93 
94 void VCardFormatPlugin::saveAll( AddressBook*, Resource *resource, TQFile *file )
95 {
96  VCardConverter converter;
97  Addressee::List vcardlist;
98 
99  Resource::Iterator it;
100  for ( it = resource->begin(); it != resource->end(); ++it ) {
101  (*it).setChanged( false );
102  vcardlist.append( *it );
103  }
104 
105  TQTextStream t( file );
106  t.setEncoding( TQTextStream::UnicodeUTF8 );
107  t << converter.createVCards( vcardlist );
108 }
109 
110 bool VCardFormatPlugin::checkFormat( TQFile *file ) const
111 {
112  TQString line;
113 
114  file->readLine( line, 1024 );
115  line = line.stripWhiteSpace();
116  if ( line == "BEGIN:VCARD" )
117  return true;
118  else
119  return false;
120 }

kabc

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

kabc

Skip menu "kabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kabc by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |