Diffstat (limited to 'kabc/plugins/olaccess/resourceolaccess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/olaccess/resourceolaccess.cpp | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/kabc/plugins/olaccess/resourceolaccess.cpp b/kabc/plugins/olaccess/resourceolaccess.cpp index e8f8bdd..7113e0e 100644 --- a/kabc/plugins/olaccess/resourceolaccess.cpp +++ b/kabc/plugins/olaccess/resourceolaccess.cpp | |||
@@ -1,303 +1,304 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #include <unistd.h> | ||
31 | 30 | ||
32 | #include <qdir.h> | 31 | #include <qdir.h> |
33 | #include <qfile.h> | 32 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 34 | #include <qregexp.h> |
36 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
37 | 36 | ||
38 | #include <kapplication.h> | 37 | #include <kapplication.h> |
39 | #include <kconfig.h> | 38 | #include <kconfig.h> |
40 | #include <kdebug.h> | 39 | #include <kdebug.h> |
41 | #include <klocale.h> | 40 | #include <klocale.h> |
42 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
43 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
44 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
45 | 44 | ||
46 | #include <sl/slzdb.h> | ||
47 | 45 | ||
48 | #include <libkdepim/ksyncprofile.h> | 46 | #include <libkdepim/ksyncprofile.h> |
49 | 47 | ||
50 | #include "resourcesharpdtmconfig.h" | 48 | #include "resourceolaccessconfig.h" |
51 | #include "resourcesharpdtm.h" | 49 | #include "resourceolaccess.h" |
52 | 50 | ||
53 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
54 | 52 | ||
55 | #include "sharpdtmconverter.h" | 53 | #include "olaccessconverter.h" |
56 | //#define ALLOW_LOCKING | 54 | //#define ALLOW_LOCKING |
57 | using namespace KABC; | 55 | using namespace KABC; |
58 | extern "C" | 56 | extern "C" |
59 | { | 57 | { |
60 | void *init_microkabc_sharpdtm() | 58 | void *init_microkabc_olaccess() |
61 | { | 59 | { |
62 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 60 | return new KRES::PluginFactory<Resourceolaccess,ResourceolaccessConfig>(); |
63 | } | 61 | } |
64 | } | 62 | } |
65 | 63 | ||
66 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) | 64 | Resourceolaccess::Resourceolaccess( const KConfig *config ) |
67 | : Resource( config ), mConverter (0) | 65 | : Resource( config ), mConverter (0) |
68 | { | 66 | { |
69 | // we can not choose the filename. Therefore use the default to display | 67 | // we can not choose the filename. Therefore use the default to display |
70 | mAccess = 0; | 68 | //mAccess = 0; |
71 | QString fileName = SlZDataBase::addressbookFileName(); | 69 | QString fileName;// = SlZDataBase::addressbookFileName(); |
72 | init( fileName ); | 70 | init( fileName ); |
73 | } | 71 | } |
74 | 72 | ||
75 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) | 73 | Resourceolaccess::Resourceolaccess( const QString &fileName ) |
76 | : Resource( 0 ) | 74 | : Resource( 0 ) |
77 | { | 75 | { |
78 | mAccess = 0; | 76 | //mAccess = 0; |
79 | init( fileName ); | 77 | init( fileName ); |
80 | } | 78 | } |
81 | 79 | ||
82 | void ResourceSharpDTM::init( const QString &fileName ) | 80 | void Resourceolaccess::init( const QString &fileName ) |
83 | { | 81 | { |
84 | if (mConverter == 0) { | 82 | if (mConverter == 0) { |
85 | mConverter = new SharpDTMConverter(); | 83 | mConverter = new OlaccessConverter(); |
86 | bool res = mConverter->init(); | 84 | bool res = mConverter->init(); |
87 | if ( !res ) | 85 | if ( !res ) |
88 | { | 86 | { |
89 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 87 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
90 | qDebug(msg); | 88 | qDebug(msg); |
91 | return; | 89 | return; |
92 | } | 90 | } |
93 | } | 91 | } |
94 | setFileName( fileName ); | 92 | setFileName( fileName ); |
95 | } | 93 | } |
96 | 94 | ||
97 | ResourceSharpDTM::~ResourceSharpDTM() | 95 | Resourceolaccess::~Resourceolaccess() |
98 | { | 96 | { |
99 | if (mConverter != 0) | 97 | if (mConverter != 0) |
100 | delete mConverter; | 98 | delete mConverter; |
101 | 99 | ||
102 | if(mAccess != 0) | 100 | //if(mAccess != 0) |
103 | delete mAccess; | 101 | //delete mAccess; |
104 | } | 102 | } |
105 | 103 | ||
106 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 104 | void Resourceolaccess::writeConfig( KConfig *config ) |
107 | { | 105 | { |
108 | Resource::writeConfig( config ); | 106 | Resource::writeConfig( config ); |
109 | } | 107 | } |
110 | 108 | ||
111 | Ticket *ResourceSharpDTM::requestSaveTicket() | 109 | Ticket *Resourceolaccess::requestSaveTicket() |
112 | { | 110 | { |
113 | 111 | ||
114 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 112 | qDebug("Resourceolaccess::requestSaveTicket: %s", fileName().latin1()); |
115 | 113 | ||
116 | if ( !addressBook() ) return 0; | 114 | if ( !addressBook() ) return 0; |
117 | return createTicket( this ); | 115 | return createTicket( this ); |
118 | } | 116 | } |
119 | 117 | ||
120 | 118 | ||
121 | bool ResourceSharpDTM::doOpen() | 119 | bool Resourceolaccess::doOpen() |
122 | { | 120 | { |
123 | if (!mConverter) | 121 | if (!mConverter) |
124 | return false; | 122 | return false; |
125 | return true; | 123 | return true; |
126 | } | 124 | } |
127 | 125 | ||
128 | void ResourceSharpDTM::doClose() | 126 | void Resourceolaccess::doClose() |
129 | { | 127 | { |
130 | return; | 128 | return; |
131 | } | 129 | } |
132 | 130 | ||
133 | bool ResourceSharpDTM::load() | 131 | bool Resourceolaccess::load() |
134 | { | 132 | { |
135 | if (!mConverter) | 133 | if (!mConverter) |
136 | return false; | 134 | return false; |
137 | QString fileN = SlZDataBase::addressbookFileName(); | 135 | QString fileN ;//= SlZDataBase::addressbookFileName(); |
136 | #if 0 | ||
138 | if ( ! mAccess ) { | 137 | if ( ! mAccess ) { |
139 | mAccess = new SlZDataBase(fileN, | 138 | mAccess = new SlZDataBase(fileN, |
140 | SlZDataBase::addressbookItems(), | 139 | SlZDataBase::addressbookItems(), |
141 | 0, true); | 140 | 0, true); |
142 | } | 141 | } |
143 | if(mAccess == 0) | 142 | if(mAccess == 0) |
144 | return false; | 143 | return false; |
145 | 144 | ||
146 | qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1()); | 145 | qDebug("Resourceolaccess:: %x load: %s",this, fileName().latin1()); |
147 | bool res = false; | 146 | bool res = false; |
148 | CardId id; | 147 | CardId id; |
149 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 148 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
150 | { | 149 | { |
151 | id = mAccess->cardId(); | 150 | id = mAccess->cardId(); |
152 | KABC::Addressee addressee; | 151 | KABC::Addressee addressee; |
153 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 152 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
154 | if ( !addressee.isEmpty() && res ) | 153 | if ( !addressee.isEmpty() && res ) |
155 | { | 154 | { |
156 | addressee.setResource( this ); | 155 | addressee.setResource( this ); |
157 | addressBook()->insertAddressee( addressee ); | 156 | addressBook()->insertAddressee( addressee ); |
158 | } | 157 | } |
159 | } | 158 | } |
160 | if(mAccess != 0) | 159 | if(mAccess != 0) |
161 | delete mAccess; | 160 | delete mAccess; |
162 | mAccess = 0; | 161 | mAccess = 0; |
163 | 162 | #endif | |
164 | return true; | 163 | return true; |
165 | } | 164 | } |
166 | 165 | ||
167 | bool ResourceSharpDTM::save( Ticket *ticket ) | 166 | bool Resourceolaccess::save( Ticket *ticket ) |
168 | { | 167 | { |
168 | #if 0 | ||
169 | if (!mConverter) | 169 | if (!mConverter) |
170 | return false; | 170 | return false; |
171 | QString fileN = SlZDataBase::addressbookFileName(); | 171 | QString fileN = SlZDataBase::addressbookFileName(); |
172 | if ( ! mAccess ) { | 172 | if ( ! mAccess ) { |
173 | mAccess = new SlZDataBase(fileN, | 173 | mAccess = new SlZDataBase(fileN, |
174 | SlZDataBase::addressbookItems(), | 174 | SlZDataBase::addressbookItems(), |
175 | 0, false); | 175 | 0, false); |
176 | } | 176 | } |
177 | if(mAccess == 0) | 177 | if(mAccess == 0) |
178 | return false; | 178 | return false; |
179 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 179 | qDebug("Resourceolaccess::save: %s", fileName().latin1()); |
180 | KABC::AddressBook::Iterator it; | 180 | KABC::AddressBook::Iterator it; |
181 | bool res; | 181 | bool res; |
182 | KABC::Addressee::List changedAddressees; | 182 | KABC::Addressee::List changedAddressees; |
183 | typedef QMap<int,QString> AddresseeMap; | 183 | typedef QMap<int,QString> AddresseeMap; |
184 | AddresseeMap map; | 184 | AddresseeMap map; |
185 | CardId id ; | 185 | CardId id ; |
186 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 186 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
187 | 187 | ||
188 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 188 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
189 | QString uid = (*it).originalExternalUID(); | 189 | QString uid = (*it).originalExternalUID(); |
190 | bool res; | 190 | bool res; |
191 | if ( uid.isEmpty() ) | 191 | if ( uid.isEmpty() ) |
192 | id = 0; | 192 | id = 0; |
193 | else | 193 | else |
194 | id = uid.toUInt(); | 194 | id = uid.toUInt(); |
195 | KABC::Addressee addressee = (*it); | 195 | KABC::Addressee addressee = (*it); |
196 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 196 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
197 | res = mAccess->startEditCard(id); | 197 | res = mAccess->startEditCard(id); |
198 | if (res == true) | 198 | if (res == true) |
199 | { | 199 | { |
200 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 200 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
201 | if (res == true) | 201 | if (res == true) |
202 | { | 202 | { |
203 | res = mAccess->finishEditCard(&id);; | 203 | res = mAccess->finishEditCard(&id);; |
204 | mConverter->setCategories( (*it), mAccess, id ); | 204 | mConverter->setCategories( (*it), mAccess, id ); |
205 | map.insert(id,(*it).uid()); | 205 | map.insert(id,(*it).uid()); |
206 | if (res == false) | 206 | if (res == false) |
207 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 207 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
208 | 208 | ||
209 | } | 209 | } |
210 | else | 210 | else |
211 | { | 211 | { |
212 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 212 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
213 | mAccess->cancelEditCard(); | 213 | mAccess->cancelEditCard(); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 217 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
218 | res = mAccess->deleteCard(&id); | 218 | res = mAccess->deleteCard(&id); |
219 | if ( !res ) | 219 | if ( !res ) |
220 | qDebug("delete error "); | 220 | qDebug("delete error "); |
221 | 221 | ||
222 | 222 | ||
223 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 223 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
224 | //changed | 224 | //changed |
225 | res = mAccess->startEditCard(id); | 225 | res = mAccess->startEditCard(id); |
226 | if (res == true) | 226 | if (res == true) |
227 | { | 227 | { |
228 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 228 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
229 | if (res == true) | 229 | if (res == true) |
230 | { | 230 | { |
231 | res = mAccess->finishEditCard(&id); | 231 | res = mAccess->finishEditCard(&id); |
232 | mConverter->setCategories( (*it), mAccess, id ); | 232 | mConverter->setCategories( (*it), mAccess, id ); |
233 | map.insert(id,(*it).uid()); | 233 | map.insert(id,(*it).uid()); |
234 | if (res == false) | 234 | if (res == false) |
235 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 235 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
236 | } | 236 | } |
237 | else | 237 | else |
238 | { | 238 | { |
239 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 239 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
240 | mAccess->cancelEditCard(); | 240 | mAccess->cancelEditCard(); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | } | 246 | } |
247 | AddresseeMap::Iterator itam; | 247 | AddresseeMap::Iterator itam; |
248 | for ( res=mAccess->first(); res == true; res=mAccess->next()) | 248 | for ( res=mAccess->first(); res == true; res=mAccess->next()) |
249 | { | 249 | { |
250 | id = mAccess->cardId(); | 250 | id = mAccess->cardId(); |
251 | int idint = id; | 251 | int idint = id; |
252 | itam = map.find( idint ); | 252 | itam = map.find( idint ); |
253 | if ( itam != map.end() ) { | 253 | if ( itam != map.end() ) { |
254 | KABC::Addressee addressee; | 254 | KABC::Addressee addressee; |
255 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 255 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
256 | 256 | ||
257 | if ( !addressee.isEmpty() && res ) | 257 | if ( !addressee.isEmpty() && res ) |
258 | { | 258 | { |
259 | addressee.setResource( this ); | 259 | addressee.setResource( this ); |
260 | addressee.setUid( itam.data() ); | 260 | addressee.setUid( itam.data() ); |
261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
262 | addressBook()->insertAddressee( addressee , false ); | 262 | addressBook()->insertAddressee( addressee , false ); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | } | 265 | } |
266 | delete ticket; | 266 | delete ticket; |
267 | if(mAccess != 0) | 267 | if(mAccess != 0) |
268 | delete mAccess; | 268 | delete mAccess; |
269 | mAccess = 0; | 269 | mAccess = 0; |
270 | #endif | ||
270 | return true; | 271 | return true; |
271 | } | 272 | } |
272 | 273 | ||
273 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 274 | bool Resourceolaccess::lock( const QString &lockfileName ) |
274 | { | 275 | { |
275 | return true; | 276 | return true; |
276 | } | 277 | } |
277 | 278 | ||
278 | void ResourceSharpDTM::unlock( const QString &fileName ) | 279 | void Resourceolaccess::unlock( const QString &fileName ) |
279 | { | 280 | { |
280 | 281 | ||
281 | } | 282 | } |
282 | 283 | ||
283 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 284 | void Resourceolaccess::setFileName( const QString &newFileName ) |
284 | { | 285 | { |
285 | Resource::setFileName( newFileName ); | 286 | Resource::setFileName( newFileName ); |
286 | } | 287 | } |
287 | 288 | ||
288 | void ResourceSharpDTM::fileChanged() | 289 | void Resourceolaccess::fileChanged() |
289 | { | 290 | { |
290 | 291 | ||
291 | } | 292 | } |
292 | 293 | ||
293 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 294 | void Resourceolaccess::removeAddressee( const Addressee &addr ) |
294 | { | 295 | { |
295 | } | 296 | } |
296 | 297 | ||
297 | void ResourceSharpDTM::cleanUp() | 298 | void Resourceolaccess::cleanUp() |
298 | { | 299 | { |
299 | 300 | ||
300 | } | 301 | } |
301 | 302 | ||
302 | 303 | ||
303 | 304 | ||