author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/formats/vcardformatplugin2.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'kabc/formats/vcardformatplugin2.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/formats/vcardformatplugin2.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/kabc/formats/vcardformatplugin2.cpp b/kabc/formats/vcardformatplugin2.cpp new file mode 100644 index 0000000..2a772b4 --- a/dev/null +++ b/kabc/formats/vcardformatplugin2.cpp | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | Enhanced Version of the file for platform independent KDE tools. | ||
3 | Copyright (c) 2004 Ulf Schenk | ||
4 | |||
5 | $Id$ | ||
6 | */ | ||
7 | |||
8 | #include "vcardformatplugin2.h" | ||
9 | |||
10 | #include "address.h" | ||
11 | #include "addressee.h" | ||
12 | #include "vcardparser/vcardtool.h" | ||
13 | |||
14 | #include <qtextstream.h> | ||
15 | #include <qfile.h> | ||
16 | |||
17 | using namespace KABC; | ||
18 | |||
19 | /*US | ||
20 | extern "C" | ||
21 | { | ||
22 | FormatPlugin *format() | ||
23 | { | ||
24 | qDebug(" VCardFormatPlugin2::format = new VCardFormatPlugin2"); | ||
25 | return new VCardFormatPlugin2(); | ||
26 | } | ||
27 | } | ||
28 | */ | ||
29 | |||
30 | VCardFormatPlugin2::VCardFormatPlugin2() | ||
31 | { | ||
32 | } | ||
33 | |||
34 | VCardFormatPlugin2::~VCardFormatPlugin2() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | bool VCardFormatPlugin2::load( Addressee &addressee, QFile *file ) | ||
39 | { | ||
40 | QString data; | ||
41 | |||
42 | QTextStream t( file ); | ||
43 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
44 | data = t.read(); | ||
45 | |||
46 | VCardTool tool; | ||
47 | |||
48 | Addressee::List l = tool.parseVCards( data ); | ||
49 | |||
50 | if ( ! l.first().isEmpty() ) { | ||
51 | addressee = l.first(); | ||
52 | return true; | ||
53 | } | ||
54 | |||
55 | return false; | ||
56 | } | ||
57 | |||
58 | bool VCardFormatPlugin2::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | ||
59 | { | ||
60 | QString data; | ||
61 | |||
62 | QTextStream t( file ); | ||
63 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
64 | data = t.read(); | ||
65 | |||
66 | VCardTool tool; | ||
67 | |||
68 | Addressee::List l = tool.parseVCards( data ); | ||
69 | |||
70 | Addressee::List::Iterator itr; | ||
71 | |||
72 | for ( itr = l.begin(); itr != l.end(); ++itr) { | ||
73 | Addressee addressee = *itr; | ||
74 | addressee.setResource( resource ); | ||
75 | addressBook->insertAddressee( addressee ); | ||
76 | } | ||
77 | |||
78 | return true; | ||
79 | } | ||
80 | |||
81 | void VCardFormatPlugin2::save( const Addressee &addressee, QFile *file ) | ||
82 | { | ||
83 | VCardTool tool; | ||
84 | Addressee::List vcardlist; | ||
85 | |||
86 | |||
87 | vcardlist.append( addressee ); | ||
88 | |||
89 | QTextStream t( file ); | ||
90 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
91 | t << tool.createVCards( vcardlist ); | ||
92 | } | ||
93 | |||
94 | void VCardFormatPlugin2::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | ||
95 | { | ||
96 | VCardTool tool; | ||
97 | Addressee::List vcardlist; | ||
98 | |||
99 | AddressBook::Iterator it; | ||
100 | for ( it = ab->begin(); it != ab->end(); ++it ) { | ||
101 | if ( (*it).resource() == resource ) { | ||
102 | (*it).setChanged( false ); | ||
103 | vcardlist.append( *it ); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | QTextStream t( file ); | ||
108 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
109 | t << tool.createVCards( vcardlist ); | ||
110 | } | ||
111 | |||
112 | bool VCardFormatPlugin2::checkFormat( QFile *file ) const | ||
113 | { | ||
114 | QString line; | ||
115 | |||
116 | file->readLine( line, 1024 ); | ||
117 | line = line.stripWhiteSpace(); | ||
118 | if ( line == "BEGIN:VCARD" ) | ||
119 | return true; | ||
120 | else | ||
121 | return false; | ||
122 | } | ||
123 | |||