summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp4
-rw-r--r--kabc/plugins/sharpdtm/sharpdtmconverter.cpp52
2 files changed, 7 insertions, 49 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 6413b42..e8f8bdd 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,303 +1,303 @@
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/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (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> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57using namespace KABC; 57using namespace KABC;
58extern "C" 58extern "C"
59{ 59{
60 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
61 { 61 {
62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
63 } 63 }
64} 64}
65 65
66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67 : Resource( config ), mConverter (0) 67 : Resource( config ), mConverter (0)
68{ 68{
69 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
70 mAccess = 0; 70 mAccess = 0;
71 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
76 : Resource( 0 ) 76 : Resource( 0 )
77{ 77{
78 mAccess = 0; 78 mAccess = 0;
79 init( fileName ); 79 init( fileName );
80} 80}
81 81
82void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
83{ 83{
84 if (mConverter == 0) { 84 if (mConverter == 0) {
85 mConverter = new SharpDTMConverter(); 85 mConverter = new SharpDTMConverter();
86 bool res = mConverter->init(); 86 bool res = mConverter->init();
87 if ( !res ) 87 if ( !res )
88 { 88 {
89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
90 qDebug(msg); 90 qDebug(msg);
91 return; 91 return;
92 } 92 }
93 } 93 }
94 setFileName( fileName ); 94 setFileName( fileName );
95} 95}
96 96
97ResourceSharpDTM::~ResourceSharpDTM() 97ResourceSharpDTM::~ResourceSharpDTM()
98{ 98{
99 if (mConverter != 0) 99 if (mConverter != 0)
100 delete mConverter; 100 delete mConverter;
101 101
102 if(mAccess != 0) 102 if(mAccess != 0)
103 delete mAccess; 103 delete mAccess;
104} 104}
105 105
106void ResourceSharpDTM::writeConfig( KConfig *config ) 106void ResourceSharpDTM::writeConfig( KConfig *config )
107{ 107{
108 Resource::writeConfig( config ); 108 Resource::writeConfig( config );
109} 109}
110 110
111Ticket *ResourceSharpDTM::requestSaveTicket() 111Ticket *ResourceSharpDTM::requestSaveTicket()
112{ 112{
113 113
114 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 114 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
115 115
116 if ( !addressBook() ) return 0; 116 if ( !addressBook() ) return 0;
117 return createTicket( this ); 117 return createTicket( this );
118} 118}
119 119
120 120
121bool ResourceSharpDTM::doOpen() 121bool ResourceSharpDTM::doOpen()
122{ 122{
123 if (!mConverter) 123 if (!mConverter)
124 return false; 124 return false;
125 return true; 125 return true;
126} 126}
127 127
128void ResourceSharpDTM::doClose() 128void ResourceSharpDTM::doClose()
129{ 129{
130 return; 130 return;
131} 131}
132 132
133bool ResourceSharpDTM::load() 133bool ResourceSharpDTM::load()
134{ 134{
135 if (!mConverter) 135 if (!mConverter)
136 return false; 136 return false;
137 QString fileN = SlZDataBase::addressbookFileName(); 137 QString fileN = SlZDataBase::addressbookFileName();
138 if ( ! mAccess ) { 138 if ( ! mAccess ) {
139 mAccess = new SlZDataBase(fileN, 139 mAccess = new SlZDataBase(fileN,
140 SlZDataBase::addressbookItems(), 140 SlZDataBase::addressbookItems(),
141 0, false); 141 0, true);
142 } 142 }
143 if(mAccess == 0) 143 if(mAccess == 0)
144 return false; 144 return false;
145 145
146 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); 146 qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1());
147 bool res = false; 147 bool res = false;
148 CardId id; 148 CardId id;
149 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 149 for (bool res=mAccess->first(); res == true; res=mAccess->next())
150 { 150 {
151 id = mAccess->cardId(); 151 id = mAccess->cardId();
152 KABC::Addressee addressee; 152 KABC::Addressee addressee;
153 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 153 res = mConverter->sharpToAddressee( id, mAccess, addressee );
154 if ( !addressee.isEmpty() && res ) 154 if ( !addressee.isEmpty() && res )
155 { 155 {
156 addressee.setResource( this ); 156 addressee.setResource( this );
157 addressBook()->insertAddressee( addressee ); 157 addressBook()->insertAddressee( addressee );
158 } 158 }
159 } 159 }
160 if(mAccess != 0) 160 if(mAccess != 0)
161 delete mAccess; 161 delete mAccess;
162 mAccess = 0; 162 mAccess = 0;
163 163
164 return true; 164 return true;
165} 165}
166 166
167bool ResourceSharpDTM::save( Ticket *ticket ) 167bool ResourceSharpDTM::save( Ticket *ticket )
168{ 168{
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("ResourceSharpDTM::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 return true; 270 return true;
271} 271}
272 272
273bool ResourceSharpDTM::lock( const QString &lockfileName ) 273bool ResourceSharpDTM::lock( const QString &lockfileName )
274{ 274{
275 return true; 275 return true;
276} 276}
277 277
278void ResourceSharpDTM::unlock( const QString &fileName ) 278void ResourceSharpDTM::unlock( const QString &fileName )
279{ 279{
280 280
281} 281}
282 282
283void ResourceSharpDTM::setFileName( const QString &newFileName ) 283void ResourceSharpDTM::setFileName( const QString &newFileName )
284{ 284{
285 Resource::setFileName( newFileName ); 285 Resource::setFileName( newFileName );
286} 286}
287 287
288void ResourceSharpDTM::fileChanged() 288void ResourceSharpDTM::fileChanged()
289{ 289{
290 290
291} 291}
292 292
293void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 293void ResourceSharpDTM::removeAddressee( const Addressee &addr )
294{ 294{
295} 295}
296 296
297void ResourceSharpDTM::cleanUp() 297void ResourceSharpDTM::cleanUp()
298{ 298{
299 299
300} 300}
301 301
302 302
303 303
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
index 95e16b6..4adcae4 100644
--- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
+++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp
@@ -167,320 +167,278 @@ bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBa
167 businessaddress.setType(Address::Work); 167 businessaddress.setType(Address::Work);
168//US businessaddress.setPostOfficeBox( "" ); 168//US businessaddress.setPostOfficeBox( "" );
169//US businessaddress.setExtended( "" ); 169//US businessaddress.setExtended( "" );
170 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") ); 170 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") );
171 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); 171 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) );
172 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); 172 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) );
173 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); 173 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) );
174 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); 174 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) );
175 175
176 addr.insertAddress( businessaddress ); 176 addr.insertAddress( businessaddress );
177 } 177 }
178 178
179 179
180 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) 180 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty())
181 { 181 {
182 PhoneNumber businessphone; 182 PhoneNumber businessphone;
183 businessphone.setType( PhoneNumber::Work ); 183 businessphone.setType( PhoneNumber::Work );
184 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); 184 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) );
185 addr.insertPhoneNumber( businessphone ); 185 addr.insertPhoneNumber( businessphone );
186 } 186 }
187 187
188 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) 188 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty())
189 { 189 {
190 PhoneNumber businessfax; 190 PhoneNumber businessfax;
191 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); 191 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
192 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); 192 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) );
193 addr.insertPhoneNumber( businessfax ); 193 addr.insertPhoneNumber( businessfax );
194 } 194 }
195 195
196 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) 196 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty())
197 { 197 {
198 PhoneNumber businessmobile; 198 PhoneNumber businessmobile;
199 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); 199 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
200 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); 200 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) );
201 addr.insertPhoneNumber( businessmobile ); 201 addr.insertPhoneNumber( businessmobile );
202 } 202 }
203 203
204 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) 204 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty())
205 { 205 {
206 PhoneNumber businesspager; 206 PhoneNumber businesspager;
207 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); 207 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
208 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); 208 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) );
209 addr.insertPhoneNumber( businesspager ); 209 addr.insertPhoneNumber( businesspager );
210 } 210 }
211 211
212 addr.setRole( db->readField(ZdbAdrs::JobTitle) ); 212 addr.setRole( db->readField(ZdbAdrs::JobTitle) );
213 addr.setOrganization( db->readField(ZdbAdrs::Company) ); 213 addr.setOrganization( db->readField(ZdbAdrs::Company) );
214 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); 214 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) );
215 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); 215 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) );
216 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); 216 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) );
217 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); 217 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) );
218 addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); 218 addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) );
219 219
220 //personal 220 //personal
221 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); 221 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) );
222 222
223 QString gen = db->readField(ZdbAdrs::Gender); 223 QString gen = db->readField(ZdbAdrs::Gender);
224 //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); 224 //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1());
225 //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); 225 //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited");
226 if (gen == "1") 226 if (gen == "1")
227 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); 227 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
228 else if (gen == "2") 228 else if (gen == "2")
229 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); 229 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
230 else 230 else
231 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef"); 231 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef");
232 232
233 233
234 QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); 234 QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) );
235 if (ann.isValid()) { 235 if (ann.isValid()) {
236 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); 236 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate);
237 //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); 237 //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1());
238 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); 238 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
239 } else 239 } else
240 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " "); 240 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " ");
241 241
242 242
243 243
244 addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); 244 addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) );
245 245
246 246
247 QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); 247 QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) );
248 //qDebug("birtd %s ", birthd.toString().latin1()); 248 //qDebug("birtd %s ", birthd.toString().latin1());
249 if (birthd.isValid()) 249 if (birthd.isValid())
250 addr.setBirthday( birthd ); 250 addr.setBirthday( birthd );
251 251
252 addr.setNickName( db->readField(ZdbAdrs::Nickname) ); 252 addr.setNickName( db->readField(ZdbAdrs::Nickname) );
253 253
254 // others 254 // others
255 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. 255 //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available.
256 //QString notes = db->readField(ZdbAdrs::Notes); 256 //QString notes = db->readField(ZdbAdrs::Notes);
257 //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; 257 //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n";
258 if ( addr.url().isEmpty() ) 258 if ( addr.url().isEmpty() )
259 addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); 259 addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) );
260 addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), "")); 260 addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), ""));
261 261
262 262
263 263
264//US QString groups() const { return find( Qtopia::Groups ); } 264//US QString groups() const { return find( Qtopia::Groups ); }
265//US QStringList groupList() const; 265//US QStringList groupList() const;
266 266
267 //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); 267 //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" );
268 QArray<int> catArray = db->readCategories(); 268 QArray<int> catArray = db->readCategories();
269 QString cat; 269 QString cat;
270 270
271 for ( unsigned int i=0; i < catArray.size(); i++ ) { 271 for ( unsigned int i=0; i < catArray.size(); i++ ) {
272 cat = catDB->label(catArray[i]); 272 cat = catDB->label(catArray[i]);
273 if ( cat.isEmpty() ) 273 if ( cat.isEmpty() )
274 addr.insertCategory(QString::number(catArray[i])); 274 addr.insertCategory(QString::number(catArray[i]));
275 else 275 else
276 addr.insertCategory( cat ); 276 addr.insertCategory( cat );
277 } 277 }
278 278
279 return true; 279 return true;
280} 280}
281 281
282bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) 282bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact )
283{ 283{
284 bool cellHome = false, cellWork = false; 284 bool cellHome = false, cellWork = false;
285 // name 285 // name
286 database->writeField(ZdbAdrs::LastName, addr.familyName()); 286 database->writeField(ZdbAdrs::LastName, addr.familyName());
287 database->writeField(ZdbAdrs::FirstName, addr.givenName()); 287 database->writeField(ZdbAdrs::FirstName, addr.givenName());
288 database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); 288 database->writeField(ZdbAdrs::MiddleName, addr.additionalName());
289 database->writeField(ZdbAdrs::Title, addr.prefix()); 289 database->writeField(ZdbAdrs::Title, addr.prefix());
290 database->writeField(ZdbAdrs::Suffix, addr.suffix()); 290 database->writeField(ZdbAdrs::Suffix, addr.suffix());
291 291
292 //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); 292 //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() );
293 QString formattedName = addr.formattedName(); 293 QString formattedName = addr.formattedName();
294 if ( formattedName.isEmpty() ) { 294 if ( formattedName.isEmpty() ) {
295 if ( !addr.familyName().isEmpty() ) { 295 if ( !addr.familyName().isEmpty() ) {
296 formattedName = addr.familyName(); 296 formattedName = addr.familyName();
297 if ( !addr.givenName().isEmpty() ) { 297 if ( !addr.givenName().isEmpty() ) {
298 formattedName += ", "; 298 formattedName += ", ";
299 formattedName += addr.givenName(); 299 formattedName += addr.givenName();
300 } 300 }
301 } else 301 } else
302 formattedName = addr.givenName(); 302 formattedName = addr.givenName();
303 } 303 }
304 database->writeField(ZdbAdrs::FileAs, formattedName); 304 database->writeField(ZdbAdrs::FileAs, formattedName);
305 database->writeField(ZdbAdrs::FullName, formattedName); 305 database->writeField(ZdbAdrs::FullName, formattedName);
306 306
307 // email 307 // email
308 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); 308 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!");
309 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); 309 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee");
310 QString emails = addr.emails().join(" "); 310 QString emails = addr.emails().join(" ");
311 database->writeField(ZdbAdrs::Emails, emails ); 311 database->writeField(ZdbAdrs::Emails, emails );
312 312
313 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); 313 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() );
314 // home 314 // home
315 const Address homeaddress = addr.address(Address::Home); 315 const Address homeaddress = addr.address(Address::Home);
316 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); 316 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street());
317 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); 317 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality());
318 database->writeField(ZdbAdrs::HomeState, homeaddress.region()); 318 database->writeField(ZdbAdrs::HomeState, homeaddress.region());
319 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); 319 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode());
320 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); 320 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country());
321 321
322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); 322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
323 database->writeField(ZdbAdrs::HomePhone, homephone.number()); 323 database->writeField(ZdbAdrs::HomePhone, homephone.number());
324 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); 324 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
325 database->writeField(ZdbAdrs::HomeFax, homefax.number()); 325 database->writeField(ZdbAdrs::HomeFax, homefax.number());
326 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); 326 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
327 database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); 327 database->writeField(ZdbAdrs::HomeMobile, homemobile.number());
328 if (!homemobile.number().isEmpty()) { 328 if (!homemobile.number().isEmpty()) {
329 cellHome = true; 329 cellHome = true;
330 } 330 }
331 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); 331 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url());
332 // business 332 // business
333 const Address businessaddress = addr.address(Address::Work); 333 const Address businessaddress = addr.address(Address::Work);
334 //qDebug("write business address "); 334 //qDebug("write business address ");
335 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); 335 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street());
336 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); 336 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality());
337 database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); 337 database->writeField(ZdbAdrs::BusinessState, businessaddress.region());
338 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); 338 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode());
339 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); 339 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country());
340 340
341 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); 341 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
342 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); 342 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number());
343 343
344 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); 344 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
345 database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); 345 database->writeField(ZdbAdrs::BusinessFax, businessfax.number());
346 346
347 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); 347 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
348 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); 348 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number());
349 if (!businessmobile.number().isEmpty()) { 349 if (!businessmobile.number().isEmpty()) {
350 cellWork = true; 350 cellWork = true;
351 } 351 }
352 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); 352 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell );
353 if (! mobile.number().isEmpty()) { 353 if (! mobile.number().isEmpty()) {
354 if ( ! cellHome ) 354 if ( ! cellHome )
355 database->writeField(ZdbAdrs::HomeMobile, mobile.number()); 355 database->writeField(ZdbAdrs::HomeMobile, mobile.number());
356 else if (! cellWork ) 356 else if (! cellWork )
357 database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); 357 database->writeField(ZdbAdrs::BusinessMobile, mobile.number());
358 } 358 }
359 359
360 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); 360 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); 361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number());
362 362
363 database->writeField(ZdbAdrs::JobTitle, addr.role()); 363 database->writeField(ZdbAdrs::JobTitle, addr.role());
364 database->writeField(ZdbAdrs::Company, addr.organization()); 364 database->writeField(ZdbAdrs::Company, addr.organization());
365 365
366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); 366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" ));
367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); 367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); 368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" ));
369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); 369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); 370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" ));
371 371
372 //personal 372 //personal
373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); 373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" ));
374 374
375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); 375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" );
376 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); 376 //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1());
377 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); 377 //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?");
378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); 378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee");
379 if (gt == "male") 379 if (gt == "male")
380 database->writeField(ZdbAdrs::Gender, "1"); 380 database->writeField(ZdbAdrs::Gender, "1");
381 else if (gt == "female") 381 else if (gt == "female")
382 database->writeField(ZdbAdrs::Gender, "2"); 382 database->writeField(ZdbAdrs::Gender, "2");
383 else 383 else
384 database->writeField(ZdbAdrs::Gender, ""); 384 database->writeField(ZdbAdrs::Gender, "");
385 385
386 QString dateS ; 386 QString dateS ;
387 QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate 387 QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
388 if ( dt.isValid() ) { 388 if ( dt.isValid() ) {
389 dateS = KGlobal::locale()->formatDate(dt, true ); 389 dateS = KGlobal::locale()->formatDate(dt, true );
390 } 390 }
391 database->writeField(ZdbAdrs::Anniversary, dateS ); 391 database->writeField(ZdbAdrs::Anniversary, dateS );
392 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); 392 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" ));
393 dt = addr.birthday().date(); 393 dt = addr.birthday().date();
394 dateS = ""; 394 dateS = "";
395 if ( dt.isValid() ) { 395 if ( dt.isValid() ) {
396 dateS = KGlobal::locale()->formatDate(dt, true ); 396 dateS = KGlobal::locale()->formatDate(dt, true );
397 } 397 }
398 database->writeField(ZdbAdrs::Birthday, dateS); 398 database->writeField(ZdbAdrs::Birthday, dateS);
399 database->writeField(ZdbAdrs::Nickname, addr.nickName()); 399 database->writeField(ZdbAdrs::Nickname, addr.nickName());
400 400
401 // other 401 // other
402 database->writeField(ZdbAdrs::Notes, addr.note()); 402 database->writeField(ZdbAdrs::Notes, addr.note());
403 403
404//US QString groups() const { return find( Qtopia::Groups ); } 404//US QString groups() const { return find( Qtopia::Groups ); }
405//US QStringList groupList() const; 405//US QStringList groupList() const;
406 406
407 407
408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); 408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works");
409 409
410 return true; 410 return true;
411} 411}
412 412
413 413
414bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) 414bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact )
415{ 415{
416 QStringList list = addr.categories(); 416 QStringList list = addr.categories();
417 417
418 QArray<int> ids(list.count()); 418 QArray<int> ids(list.count());
419 uint index = 0; 419 uint index = 0;
420 for(uint i=0; i<ids.size(); i++){ 420 for(uint i=0; i<ids.size(); i++){
421 if(catDB->exists(list[i])){ 421 if(catDB->exists(list[i])){
422 ids[index] = catDB->id(list[i]); 422 ids[index] = catDB->id(list[i]);
423 qDebug("set ex cat %d %s ",ids[index] , list[i].latin1()); 423 //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1());
424 index++; 424 index++;
425 } else { 425 } else {
426 ids[index] = catDB->addCategory(list[i]); 426 ids[index] = catDB->addCategory(list[i]);
427 qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); 427 //qDebug("add new cat %d %s ",ids[index] , list[i].latin1());
428 index++; 428 index++;
429 } 429 }
430 } 430 }
431 bool res ; 431 bool res ;
432 if ( res = database->updateCategories(contact, ids) ) 432
433 qDebug("cat updated "); 433 if ( !(res = database->updateCategories(contact, ids) ))
434 else 434 qDebug("SharpDTMConverter::Error updating categories");
435 qDebug("error cat updating ");
436 435
437 return res; 436 return res;
438} 437}
439 438
440#if 0
441 m_pCategories = new SlCategories;
442catDB
443
444 if(categories == QString::null) return true;
445 QStringList list = CSVParser::parse(categories);
446 QArray<int> ids(list.count());
447 uint index = 0;
448 for(uint i=0; i<ids.size(); i++){
449#if 0
450 bool ok;
451 ids[index] = list[i].toInt(&ok);
452 if(ok){
453 index++;
454 } else {
455 if(m_pCategories->exists(list[i])){
456 ids[index] = m_pCategories->id(list[i]);
457 index++;
458 }
459 }
460#else
461 if(m_pCategories->exists(list[i])){
462 ids[index] = m_pCategories->id(list[i]);
463 index++;
464 } else if(m_addCategory){
465 ids[index] = m_pCategories->addCategory(list[i]);
466 index++;
467 }
468#endif
469 }
470 if(ids.size() > 0 && index == 0){
471 return true;
472 } else if(index != ids.size()){
473 ids.resize(index);
474 }
475 if(!m_pZdb->updateCategories(id, ids)){
476 return false;
477 }
478 return true;
479#endif
480
481QDate SharpDTMConverter::convertDate( QString s) 439QDate SharpDTMConverter::convertDate( QString s)
482{ 440{
483 QDate dt = KGlobal::locale()->readDate( s ); 441 QDate dt = KGlobal::locale()->readDate( s );
484 return dt; 442 return dt;
485 return QDate (); 443 return QDate ();
486} 444}