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