summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/sharpdtm
authorzautrix <zautrix>2004-10-29 19:40:20 (UTC)
committer zautrix <zautrix>2004-10-29 19:40:20 (UTC)
commita7e2fe5bb10af47a239b8b014a210568cc79287a (patch) (unidiff)
treed3f77498134abc97bc48a376e148a8fd8565c6c3 /kabc/plugins/sharpdtm
parentb55890913f4c81bd2fc3719cf7c97e8ab1f47077 (diff)
downloadkdepimpi-a7e2fe5bb10af47a239b8b014a210568cc79287a.zip
kdepimpi-a7e2fe5bb10af47a239b8b014a210568cc79287a.tar.gz
kdepimpi-a7e2fe5bb10af47a239b8b014a210568cc79287a.tar.bz2
fixed dtm resource
Diffstat (limited to 'kabc/plugins/sharpdtm') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp242
1 files changed, 129 insertions, 113 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 48b7d91..7069f5d 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -81,7 +81,17 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
81 81
82void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
83{ 83{
84 setFileName( fileName ); 84 if (mConverter == 0) {
85 mConverter = new SharpDTMConverter();
86 bool res = mConverter->init();
87 if ( !res )
88 {
89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
90 qDebug(msg);
91 return;
92 }
93 }
94 setFileName( fileName );
85} 95}
86 96
87ResourceSharpDTM::~ResourceSharpDTM() 97ResourceSharpDTM::~ResourceSharpDTM()
@@ -109,31 +119,9 @@ Ticket *ResourceSharpDTM::requestSaveTicket()
109 119
110 120
111bool ResourceSharpDTM::doOpen() 121bool ResourceSharpDTM::doOpen()
112{ 122{
113 qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1()); 123 if (!mConverter)
114
115 if ( ! mAccess ) {
116 // the last parameter in the SlZDataBase constructor means "readonly"
117 mAccess = new SlZDataBase(fileName(),
118 SlZDataBase::addressbookItems(),
119 NULL, false);
120 }
121 if ( !mAccess ) {
122 qDebug("Unable to load file() %s", fileName().latin1());
123 return false; 124 return false;
124 }
125 if (mConverter == 0) {
126 mConverter = new SharpDTMConverter();
127 bool res = mConverter->init();
128 if ( !res )
129 {
130 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
131 qDebug(msg);
132 delete mAccess;
133 mAccess = 0;
134 return false;
135 }
136 }
137 return true; 125 return true;
138} 126}
139 127
@@ -144,6 +132,17 @@ void ResourceSharpDTM::doClose()
144 132
145bool ResourceSharpDTM::load() 133bool ResourceSharpDTM::load()
146{ 134{
135 if (!mConverter)
136 return false;
137 QString fileN = SlZDataBase::addressbookFileName();
138 if ( ! mAccess ) {
139 mAccess = new SlZDataBase(fileN,
140 SlZDataBase::addressbookItems(),
141 0, false);
142 }
143 if(mAccess == 0)
144 return false;
145
147 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); 146 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1());
148 bool res = false; 147 bool res = false;
149 CardId id; 148 CardId id;
@@ -158,103 +157,120 @@ bool ResourceSharpDTM::load()
158 addressBook()->insertAddressee( addressee ); 157 addressBook()->insertAddressee( addressee );
159 } 158 }
160 } 159 }
160 if(mAccess != 0)
161 delete mAccess;
162 mAccess = 0;
163
161 return true; 164 return true;
162} 165}
163 166
164bool ResourceSharpDTM::save( Ticket *ticket ) 167bool ResourceSharpDTM::save( Ticket *ticket )
165{ 168{
166 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 169 if (!mConverter)
167 KABC::AddressBook::Iterator it; 170 return false;
168 bool res; 171 QString fileN = SlZDataBase::addressbookFileName();
169 KABC::Addressee::List changedAddressees; 172 if ( ! mAccess ) {
170 typedef QMap<int,QString> AddresseeMap; 173 mAccess = new SlZDataBase(fileN,
171 AddresseeMap map; 174 SlZDataBase::addressbookItems(),
172 CardId id ; 175 0, false);
173 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 176 }
174 177 if(mAccess == 0)
175 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 178 return false;
176 QString uid = (*it).originalExternalUID(); 179 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
177 bool res; 180 KABC::AddressBook::Iterator it;
178 if ( uid.isEmpty() ) 181 bool res;
179 id = 0; 182 KABC::Addressee::List changedAddressees;
180 else 183 typedef QMap<int,QString> AddresseeMap;
181 id = uid.toUInt(); 184 AddresseeMap map;
182 KABC::Addressee addressee = (*it); 185 CardId id ;
183 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 186 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
184 res = mAccess->startEditCard(id); 187
185 if (res == true) 188 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
186 { 189 QString uid = (*it).originalExternalUID();
187 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 190 bool res;
188 if (res == true) 191 if ( uid.isEmpty() )
189 { 192 id = 0;
190 res = mAccess->finishEditCard(&id);; 193 else
191 map.insert(id,(*it).uid()); 194 id = uid.toUInt();
192 if (res == false) 195 KABC::Addressee addressee = (*it);
193 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 196 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
197 res = mAccess->startEditCard(id);
198 if (res == true)
199 {
200 res = mConverter->addresseeToSharp( (*it), mAccess, id );
201 if (res == true)
202 {
203 res = mAccess->finishEditCard(&id);;
204 map.insert(id,(*it).uid());
205 if (res == false)
206 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
194 207
195 } 208 }
196 else 209 else
197 { 210 {
198 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 211 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
199 mAccess->cancelEditCard(); 212 mAccess->cancelEditCard();
200 } 213 }
201 } 214 }
202 215
203 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
204 res = mAccess->deleteCard(&id); 217 res = mAccess->deleteCard(&id);
205 if ( !res ) 218 if ( !res )
206 qDebug("delete error "); 219 qDebug("delete error ");
207 220
208 221
209 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 222 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
210 //changed 223 //changed
211 res = mAccess->startEditCard(id); 224 res = mAccess->startEditCard(id);
212 if (res == true) 225 if (res == true)
213 { 226 {
214 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 227 res = mConverter->addresseeToSharp( (*it), mAccess, id );
215 if (res == true) 228 if (res == true)
216 { 229 {
217 res = mAccess->finishEditCard(&id); 230 res = mAccess->finishEditCard(&id);
218 map.insert(id,(*it).uid()); 231 map.insert(id,(*it).uid());
219 if (res == false) 232 if (res == false)
220 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 233 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
221 } 234 }
222 else 235 else
223 { 236 {
224 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 237 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
225 mAccess->cancelEditCard(); 238 mAccess->cancelEditCard();
226 } 239 }
227 } 240 }
228 } 241 }
229 } 242 }
230 243
231 } 244 }
232 AddresseeMap::Iterator itam; 245 AddresseeMap::Iterator itam;
233 for ( res=mAccess->first(); res == true; res=mAccess->next()) 246 for ( res=mAccess->first(); res == true; res=mAccess->next())
234 { 247 {
235 id = mAccess->cardId(); 248 id = mAccess->cardId();
236 int idint = id; 249 int idint = id;
237 itam = map.find( idint ); 250 itam = map.find( idint );
238 if ( itam != map.end() ) { 251 if ( itam != map.end() ) {
239 KABC::Addressee addressee; 252 KABC::Addressee addressee;
240 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 253 res = mConverter->sharpToAddressee( id, mAccess, addressee );
241 254
242 if ( !addressee.isEmpty() && res ) 255 if ( !addressee.isEmpty() && res )
243 { 256 {
244 addressee.setResource( this ); 257 addressee.setResource( this );
245 addressee.setUid( itam.data() ); 258 addressee.setUid( itam.data() );
246 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 259 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
247 addressBook()->insertAddressee( addressee , false ); 260 addressBook()->insertAddressee( addressee , false );
248 } 261 }
249 } 262 }
250 } 263 }
251 delete ticket; 264 delete ticket;
252 265 if(mAccess != 0)
253 return true; 266 delete mAccess;
267 mAccess = 0;
268 return true;
254} 269}
255 270
256bool ResourceSharpDTM::lock( const QString &lockfileName ) 271bool ResourceSharpDTM::lock( const QString &lockfileName )
257{ 272{
273 return true;
258} 274}
259 275
260void ResourceSharpDTM::unlock( const QString &fileName ) 276void ResourceSharpDTM::unlock( const QString &fileName )
@@ -278,7 +294,7 @@ void ResourceSharpDTM::removeAddressee( const Addressee &addr )
278 294
279void ResourceSharpDTM::cleanUp() 295void ResourceSharpDTM::cleanUp()
280{ 296{
281 unlock( fileName() ); 297
282} 298}
283 299
284 300