summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorzautrix <zautrix>2005-10-27 08:51:03 (UTC)
committer zautrix <zautrix>2005-10-27 08:51:03 (UTC)
commitff68b29b914fc3fbc3aa777d3e3ceeb8a64ecc09 (patch) (unidiff)
tree0ed1f4c783ade8284a016cec611a61c586895261 /kabc/plugins
parent15b9123c6c1f9096a4b1a7729c323433d408c8d7 (diff)
downloadkdepimpi-ff68b29b914fc3fbc3aa777d3e3ceeb8a64ecc09.zip
kdepimpi-ff68b29b914fc3fbc3aa777d3e3ceeb8a64ecc09.tar.gz
kdepimpi-ff68b29b914fc3fbc3aa777d3e3ceeb8a64ecc09.tar.bz2
files added
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/olaccess/olaccess.pro34
-rw-r--r--kabc/plugins/olaccess/olaccessconverter.cpp444
-rw-r--r--kabc/plugins/olaccess/olaccessconverter.h88
-rw-r--r--kabc/plugins/olaccess/resourceolaccess.cpp303
-rw-r--r--kabc/plugins/olaccess/resourceolaccess.h146
-rw-r--r--kabc/plugins/olaccess/resourceolaccessconfig.cpp108
-rw-r--r--kabc/plugins/olaccess/resourceolaccessconfig.h58
7 files changed, 1181 insertions, 0 deletions
diff --git a/kabc/plugins/olaccess/olaccess.pro b/kabc/plugins/olaccess/olaccess.pro
new file mode 100644
index 0000000..ca0a6a8
--- a/dev/null
+++ b/kabc/plugins/olaccess/olaccess.pro
@@ -0,0 +1,34 @@
1 TEMPLATE= lib
2CONFIG += qt warn_on
3TARGET = microkabc_olaccess
4
5include( ../../../variables.pri )
6
7INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat
8
9INTERFACES = \
10
11HEADERS = \
12 resourceolaccess.h \
13 resourceolaccessconfig.h \
14 olaccessconverter.h
15
16SOURCES = \
17 resourceolaccess.cpp \
18 resourceolaccessconfig.cpp \
19 olaccessconverter.cpp
20
21unix : {
22OBJECTS_DIR = obj/unix
23MOC_DIR = moc/unix
24}
25win32: {
26CONFIG += dll
27DEFINES += _WIN32_
28OBJECTS_DIR = obj/win
29MOC_DIR = moc/win
30LIBS += ../../../bin/microkdepim.lib
31LIBS += ../../../bin/microkcal.lib
32LIBS += ../../../bin/microkde.lib
33LIBS += ../../../bin/microkabc.lib
34}
diff --git a/kabc/plugins/olaccess/olaccessconverter.cpp b/kabc/plugins/olaccess/olaccessconverter.cpp
new file mode 100644
index 0000000..4adcae4
--- a/dev/null
+++ b/kabc/plugins/olaccess/olaccessconverter.cpp
@@ -0,0 +1,444 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include "kglobal.h"
29#include <qregexp.h>
30
31
32#include "sharpdtmconverter.h"
33
34#include <sl/slcategories.h>
35#include <libkdepim/ksyncprofile.h>
36//US #include <qpe/categoryselect.h>
37
38
39using namespace KABC;
40using namespace SlCategory;
41
42SharpDTMConverter::SharpDTMConverter() : catDB(0)
43{
44}
45
46SharpDTMConverter::~SharpDTMConverter()
47{
48 deinit();
49}
50
51bool SharpDTMConverter::init()
52{
53 catDB = new SlCategory::SlCategories();
54
55 if (!catDB)
56 return false;
57
58// catDB->load( categoryFileName() );
59 return true;
60}
61
62void SharpDTMConverter::deinit()
63{
64 if (catDB)
65 {
66 delete catDB;
67 catDB = 0;
68 }
69}
70
71bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr )
72{
73 SlZDataBase* db = (SlZDataBase*)database;
74
75 // for syncing: we need setting of the two fields
76 addr.setExternalUID( QString::number( contact ) );
77 addr.setOriginalExternalUID( QString::number( contact ) );
78 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
79
80
81 // name
82 //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!");
83 addr.setFormattedName(db->readField(ZdbAdrs::FileAs));
84 //addr.setName(db->readField(ZdbAdrs::FullName));
85
86 addr.setFamilyName( db->readField(ZdbAdrs::LastName) );
87 addr.setGivenName( db->readField(ZdbAdrs::FirstName) );
88 addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) );
89 addr.setPrefix( db->readField(ZdbAdrs::Title) );
90 addr.setSuffix( db->readField(ZdbAdrs::Suffix) );
91
92
93 QString emailstr = db->readField(ZdbAdrs::Emails);
94 emailstr.replace( QRegExp(","), " " );
95 emailstr.replace( QRegExp(";"), " " );
96 emailstr.replace( QRegExp(":"), " " );
97 //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1());
98 QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace());
99 bool defE = false;
100 bool found = false;
101 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
102 if (found )
103 defE = false;
104 else
105 found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower());
106 addr.insertEmail( *it, defE );
107 }
108 if ( ! found )
109 if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty())
110 addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true);
111
112 // home
113 if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) ||
114 (!db->readField(ZdbAdrs::HomeCity).isEmpty()) ||
115 (!db->readField(ZdbAdrs::HomeState).isEmpty()) ||
116 (!db->readField(ZdbAdrs::HomeZip).isEmpty()) ||
117 (!db->readField(ZdbAdrs::HomeCountry).isEmpty()))
118 {
119 Address homeaddress;
120 homeaddress.setType(Address::Home);
121//US homeaddress.setPostOfficeBox( "" );
122//US homeaddress.setExtended( "" );
123 homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet).replace( QRegExp("\\r"), ""));
124 homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) );
125 homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) );
126 homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) );
127 homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) );
128
129 addr.insertAddress( homeaddress );
130 }
131
132 if (!db->readField(ZdbAdrs::HomePhone).isEmpty())
133 {
134 PhoneNumber homephone;
135 homephone.setType( PhoneNumber::Home );
136 homephone.setNumber( db->readField(ZdbAdrs::HomePhone) );
137 addr.insertPhoneNumber( homephone );
138 }
139
140 if (!db->readField(ZdbAdrs::HomeFax).isEmpty())
141 {
142 PhoneNumber homefax;
143 homefax.setType( PhoneNumber::Home | PhoneNumber::Fax );
144 homefax.setNumber( db->readField(ZdbAdrs::HomeFax) );
145 addr.insertPhoneNumber( homefax );
146 }
147
148 if (!db->readField(ZdbAdrs::HomeMobile).isEmpty())
149 {
150 PhoneNumber homemobile;
151 homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell );
152 homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) );
153 addr.insertPhoneNumber( homemobile );
154 }
155
156 addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) );
157
158
159 // business
160 if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) ||
161 (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) ||
162 (!db->readField(ZdbAdrs::BusinessState).isEmpty()) ||
163 (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) ||
164 (!db->readField(ZdbAdrs::BusinessCountry).isEmpty()))
165 {
166 Address businessaddress;
167 businessaddress.setType(Address::Work);
168//US businessaddress.setPostOfficeBox( "" );
169//US businessaddress.setExtended( "" );
170 businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") );
171 businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) );
172 businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) );
173 businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) );
174 businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) );
175
176 addr.insertAddress( businessaddress );
177 }
178
179
180 if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty())
181 {
182 PhoneNumber businessphone;
183 businessphone.setType( PhoneNumber::Work );
184 businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) );
185 addr.insertPhoneNumber( businessphone );
186 }
187
188 if (!db->readField(ZdbAdrs::BusinessFax).isEmpty())
189 {
190 PhoneNumber businessfax;
191 businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax );
192 businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) );
193 addr.insertPhoneNumber( businessfax );
194 }
195
196 if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty())
197 {
198 PhoneNumber businessmobile;
199 businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell );
200 businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) );
201 addr.insertPhoneNumber( businessmobile );
202 }
203
204 if (!db->readField(ZdbAdrs::BusinessPager).isEmpty())
205 {
206 PhoneNumber businesspager;
207 businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager );
208 businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) );
209 addr.insertPhoneNumber( businesspager );
210 }
211
212 addr.setRole( db->readField(ZdbAdrs::JobTitle) );
213 addr.setOrganization( db->readField(ZdbAdrs::Company) );
214 addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) );
215 addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) );
216 addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) );
217 addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) );
218 addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) );
219
220 //personal
221 addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) );
222
223 QString gen = db->readField(ZdbAdrs::Gender);
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");
226 if (gen == "1")
227 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male");
228 else if (gen == "2")
229 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female");
230 else
231 addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef");
232
233
234 QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) );
235 if (ann.isValid()) {
236 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate);
237 //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1());
238 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
239 } else
240 addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " ");
241
242
243
244 addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) );
245
246
247 QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) );
248 //qDebug("birtd %s ", birthd.toString().latin1());
249 if (birthd.isValid())
250 addr.setBirthday( birthd );
251
252 addr.setNickName( db->readField(ZdbAdrs::Nickname) );
253
254 // others
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);
257 //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n";
258 if ( addr.url().isEmpty() )
259 addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) );
260 addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), ""));
261
262
263
264//US QString groups() const { return find( Qtopia::Groups ); }
265//US QStringList groupList() const;
266
267 //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" );
268 QArray<int> catArray = db->readCategories();
269 QString cat;
270
271 for ( unsigned int i=0; i < catArray.size(); i++ ) {
272 cat = catDB->label(catArray[i]);
273 if ( cat.isEmpty() )
274 addr.insertCategory(QString::number(catArray[i]));
275 else
276 addr.insertCategory( cat );
277 }
278
279 return true;
280}
281
282bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact )
283{
284 bool cellHome = false, cellWork = false;
285 // name
286 database->writeField(ZdbAdrs::LastName, addr.familyName());
287 database->writeField(ZdbAdrs::FirstName, addr.givenName());
288 database->writeField(ZdbAdrs::MiddleName, addr.additionalName());
289 database->writeField(ZdbAdrs::Title, addr.prefix());
290 database->writeField(ZdbAdrs::Suffix, addr.suffix());
291
292 //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() );
293 QString formattedName = addr.formattedName();
294 if ( formattedName.isEmpty() ) {
295 if ( !addr.familyName().isEmpty() ) {
296 formattedName = addr.familyName();
297 if ( !addr.givenName().isEmpty() ) {
298 formattedName += ", ";
299 formattedName += addr.givenName();
300 }
301 } else
302 formattedName = addr.givenName();
303 }
304 database->writeField(ZdbAdrs::FileAs, formattedName);
305 database->writeField(ZdbAdrs::FullName, formattedName);
306
307 // email
308 //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!");
309 //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee");
310 QString emails = addr.emails().join(" ");
311 database->writeField(ZdbAdrs::Emails, emails );
312
313 database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() );
314 // home
315 const Address homeaddress = addr.address(Address::Home);
316 database->writeField(ZdbAdrs::HomeStreet, homeaddress.street());
317 database->writeField(ZdbAdrs::HomeCity, homeaddress.locality());
318 database->writeField(ZdbAdrs::HomeState, homeaddress.region());
319 database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode());
320 database->writeField(ZdbAdrs::HomeCountry, homeaddress.country());
321
322 PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home );
323 database->writeField(ZdbAdrs::HomePhone, homephone.number());
324 PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax );
325 database->writeField(ZdbAdrs::HomeFax, homefax.number());
326 PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell );
327 database->writeField(ZdbAdrs::HomeMobile, homemobile.number());
328 if (!homemobile.number().isEmpty()) {
329 cellHome = true;
330 }
331 database->writeField(ZdbAdrs::HomeWebPage, addr.url().url());
332 // business
333 const Address businessaddress = addr.address(Address::Work);
334 //qDebug("write business address ");
335 database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street());
336 database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality());
337 database->writeField(ZdbAdrs::BusinessState, businessaddress.region());
338 database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode());
339 database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country());
340
341 PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work );
342 database->writeField(ZdbAdrs::BusinessPhone, businessphone.number());
343
344 PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax );
345 database->writeField(ZdbAdrs::BusinessFax, businessfax.number());
346
347 PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell );
348 database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number());
349 if (!businessmobile.number().isEmpty()) {
350 cellWork = true;
351 }
352 PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell );
353 if (! mobile.number().isEmpty()) {
354 if ( ! cellHome )
355 database->writeField(ZdbAdrs::HomeMobile, mobile.number());
356 else if (! cellWork )
357 database->writeField(ZdbAdrs::BusinessMobile, mobile.number());
358 }
359
360 PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager );
361 database->writeField(ZdbAdrs::BusinessPager, businesspager.number());
362
363 database->writeField(ZdbAdrs::JobTitle, addr.role());
364 database->writeField(ZdbAdrs::Company, addr.organization());
365
366 database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" ));
367 database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" ));
368 database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" ));
369 database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" ));
370 database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" ));
371
372 //personal
373 database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" ));
374
375 QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" );
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?");
378 //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee");
379 if (gt == "male")
380 database->writeField(ZdbAdrs::Gender, "1");
381 else if (gt == "female")
382 database->writeField(ZdbAdrs::Gender, "2");
383 else
384 database->writeField(ZdbAdrs::Gender, "");
385
386 QString dateS ;
387 QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate
388 if ( dt.isValid() ) {
389 dateS = KGlobal::locale()->formatDate(dt, true );
390 }
391 database->writeField(ZdbAdrs::Anniversary, dateS );
392 database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" ));
393 dt = addr.birthday().date();
394 dateS = "";
395 if ( dt.isValid() ) {
396 dateS = KGlobal::locale()->formatDate(dt, true );
397 }
398 database->writeField(ZdbAdrs::Birthday, dateS);
399 database->writeField(ZdbAdrs::Nickname, addr.nickName());
400
401 // other
402 database->writeField(ZdbAdrs::Notes, addr.note());
403
404//US QString groups() const { return find( Qtopia::Groups ); }
405//US QStringList groupList() const;
406
407
408 //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works");
409
410 return true;
411}
412
413
414bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact )
415{
416 QStringList list = addr.categories();
417
418 QArray<int> ids(list.count());
419 uint index = 0;
420 for(uint i=0; i<ids.size(); i++){
421 if(catDB->exists(list[i])){
422 ids[index] = catDB->id(list[i]);
423 //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1());
424 index++;
425 } else {
426 ids[index] = catDB->addCategory(list[i]);
427 //qDebug("add new cat %d %s ",ids[index] , list[i].latin1());
428 index++;
429 }
430 }
431 bool res ;
432
433 if ( !(res = database->updateCategories(contact, ids) ))
434 qDebug("SharpDTMConverter::Error updating categories");
435
436 return res;
437}
438
439QDate SharpDTMConverter::convertDate( QString s)
440{
441 QDate dt = KGlobal::locale()->readDate( s );
442 return dt;
443 return QDate ();
444}
diff --git a/kabc/plugins/olaccess/olaccessconverter.h b/kabc/plugins/olaccess/olaccessconverter.h
new file mode 100644
index 0000000..db1bf2d
--- a/dev/null
+++ b/kabc/plugins/olaccess/olaccessconverter.h
@@ -0,0 +1,88 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24$Id$
25*/
26
27#ifndef KABC_SHARPDTMCONVERTER_H
28#define KABC_SHARPDTMCONVERTER_H
29
30#include <qstring.h>
31
32#include <sl/slzdb.h>
33
34#include "addressee.h"
35
36namespace SlCategory {
37 class SlCategories;
38}
39
40class SlZDataBase;
41
42namespace KABC {
43
44class SharpDTMConverter
45{
46public:
47
48 /**
49 * Constructor.
50 */
51 SharpDTMConverter();
52
53 /**
54 * Destructor.
55 */
56 virtual ~SharpDTMConverter();
57
58 bool init();
59 void deinit();
60
61 /**
62 * Converts a given sharp card to an addressee.
63 *
64 * @param contact The sharp card id, eventhough it might be 0, if the contact is a new one.
65 * @param database The sharp database pointer we use for the conversion
66 * @param addr The addressee.
67 */
68 bool sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr );
69
70 /**
71 * Converts an addressee to a sharp dtm contact.
72 *
73 * @param addr The addressee.
74 * @param database The sharp database pointer we use for the conversion
75 * @param contact The sharp card id, eventhough it might be 0, if the contact is a new one.
76 */
77 bool addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact );
78 bool setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact );
79
80 private:
81 SlCategory::SlCategories* catDB;
82 QDate convertDate( QString );
83
84
85};
86
87}
88#endif
diff --git a/kabc/plugins/olaccess/resourceolaccess.cpp b/kabc/plugins/olaccess/resourceolaccess.cpp
new file mode 100644
index 0000000..e8f8bdd
--- a/dev/null
+++ b/kabc/plugins/olaccess/resourceolaccess.cpp
@@ -0,0 +1,303 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <unistd.h>
31
32#include <qdir.h>
33#include <qfile.h>
34#include <qfileinfo.h>
35#include <qregexp.h>
36//US #include <qtimer.h>
37
38#include <kapplication.h>
39#include <kconfig.h>
40#include <kdebug.h>
41#include <klocale.h>
42//US #include <ksavefile.h>
43#include <kstandarddirs.h>
44#include <kmessagebox.h>
45
46#include <sl/slzdb.h>
47
48#include <libkdepim/ksyncprofile.h>
49
50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h"
52
53#include "stdaddressbook.h"
54
55#include "sharpdtmconverter.h"
56//#define ALLOW_LOCKING
57using namespace KABC;
58extern "C"
59{
60 void *init_microkabc_sharpdtm()
61 {
62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
63 }
64}
65
66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67 : Resource( config ), mConverter (0)
68{
69 // we can not choose the filename. Therefore use the default to display
70 mAccess = 0;
71 QString fileName = SlZDataBase::addressbookFileName();
72 init( fileName );
73}
74
75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
76 : Resource( 0 )
77{
78 mAccess = 0;
79 init( fileName );
80}
81
82void ResourceSharpDTM::init( const QString &fileName )
83{
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 );
95}
96
97ResourceSharpDTM::~ResourceSharpDTM()
98{
99 if (mConverter != 0)
100 delete mConverter;
101
102 if(mAccess != 0)
103 delete mAccess;
104}
105
106void ResourceSharpDTM::writeConfig( KConfig *config )
107{
108 Resource::writeConfig( config );
109}
110
111Ticket *ResourceSharpDTM::requestSaveTicket()
112{
113
114 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
115
116 if ( !addressBook() ) return 0;
117 return createTicket( this );
118}
119
120
121bool ResourceSharpDTM::doOpen()
122{
123 if (!mConverter)
124 return false;
125 return true;
126}
127
128void ResourceSharpDTM::doClose()
129{
130 return;
131}
132
133bool ResourceSharpDTM::load()
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, true);
142 }
143 if(mAccess == 0)
144 return false;
145
146 qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1());
147 bool res = false;
148 CardId id;
149 for (bool res=mAccess->first(); res == true; res=mAccess->next())
150 {
151 id = mAccess->cardId();
152 KABC::Addressee addressee;
153 res = mConverter->sharpToAddressee( id, mAccess, addressee );
154 if ( !addressee.isEmpty() && res )
155 {
156 addressee.setResource( this );
157 addressBook()->insertAddressee( addressee );
158 }
159 }
160 if(mAccess != 0)
161 delete mAccess;
162 mAccess = 0;
163
164 return true;
165}
166
167bool ResourceSharpDTM::save( Ticket *ticket )
168{
169 if (!mConverter)
170 return false;
171 QString fileN = SlZDataBase::addressbookFileName();
172 if ( ! mAccess ) {
173 mAccess = new SlZDataBase(fileN,
174 SlZDataBase::addressbookItems(),
175 0, false);
176 }
177 if(mAccess == 0)
178 return false;
179 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
180 KABC::AddressBook::Iterator it;
181 bool res;
182 KABC::Addressee::List changedAddressees;
183 typedef QMap<int,QString> AddresseeMap;
184 AddresseeMap map;
185 CardId id ;
186 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
187
188 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
189 QString uid = (*it).originalExternalUID();
190 bool res;
191 if ( uid.isEmpty() )
192 id = 0;
193 else
194 id = uid.toUInt();
195 KABC::Addressee addressee = (*it);
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 mConverter->setCategories( (*it), mAccess, id );
205 map.insert(id,(*it).uid());
206 if (res == false)
207 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
208
209 }
210 else
211 {
212 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
213 mAccess->cancelEditCard();
214 }
215 }
216
217 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
218 res = mAccess->deleteCard(&id);
219 if ( !res )
220 qDebug("delete error ");
221
222
223 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
224 //changed
225 res = mAccess->startEditCard(id);
226 if (res == true)
227 {
228 res = mConverter->addresseeToSharp( (*it), mAccess, id );
229 if (res == true)
230 {
231 res = mAccess->finishEditCard(&id);
232 mConverter->setCategories( (*it), mAccess, id );
233 map.insert(id,(*it).uid());
234 if (res == false)
235 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
236 }
237 else
238 {
239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
240 mAccess->cancelEditCard();
241 }
242 }
243 }
244 }
245
246 }
247 AddresseeMap::Iterator itam;
248 for ( res=mAccess->first(); res == true; res=mAccess->next())
249 {
250 id = mAccess->cardId();
251 int idint = id;
252 itam = map.find( idint );
253 if ( itam != map.end() ) {
254 KABC::Addressee addressee;
255 res = mConverter->sharpToAddressee( id, mAccess, addressee );
256
257 if ( !addressee.isEmpty() && res )
258 {
259 addressee.setResource( this );
260 addressee.setUid( itam.data() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 addressBook()->insertAddressee( addressee , false );
263 }
264 }
265 }
266 delete ticket;
267 if(mAccess != 0)
268 delete mAccess;
269 mAccess = 0;
270 return true;
271}
272
273bool ResourceSharpDTM::lock( const QString &lockfileName )
274{
275 return true;
276}
277
278void ResourceSharpDTM::unlock( const QString &fileName )
279{
280
281}
282
283void ResourceSharpDTM::setFileName( const QString &newFileName )
284{
285 Resource::setFileName( newFileName );
286}
287
288void ResourceSharpDTM::fileChanged()
289{
290
291}
292
293void ResourceSharpDTM::removeAddressee( const Addressee &addr )
294{
295}
296
297void ResourceSharpDTM::cleanUp()
298{
299
300}
301
302
303
diff --git a/kabc/plugins/olaccess/resourceolaccess.h b/kabc/plugins/olaccess/resourceolaccess.h
new file mode 100644
index 0000000..64d06f9
--- a/dev/null
+++ b/kabc/plugins/olaccess/resourceolaccess.h
@@ -0,0 +1,146 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28
29#ifndef KABC_RESOURCESHARPDTM_H
30#define KABC_RESOURCESHARPDTM_H
31
32#include <kconfig.h>
33#include <kdirwatch.h>
34
35#include <sys/types.h>
36
37#include "resource.h"
38
39
40class SlZDataBase;
41
42namespace KABC {
43
44class ResourceConfigWidget;
45class SharpDTMConverter;
46
47/**
48 @internal
49*/
50class ResourceSharpDTM : public Resource
51{
52 Q_OBJECT
53
54public:
55
56 /**
57 Constructor.
58
59 @param cfg The config object where custom resource settings are stored.
60 */
61 ResourceSharpDTM( const KConfig *cfg );
62
63 /**
64 Construct file resource on file @arg fileName using format @arg formatName.
65 */
66 ResourceSharpDTM( const QString &fileName );
67
68 /**
69 * Destructor.
70 */
71 ~ResourceSharpDTM();
72
73 /**
74 Writes the config back.
75 */
76 virtual void writeConfig( KConfig *cfg );
77
78 /**
79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load().
81 */
82 virtual bool doOpen();
83
84 /**
85 * Closes the file again.
86 */
87 virtual void doClose();
88
89 /**
90 * Requests a save ticket, that is used by @ref save()
91 */
92 virtual Ticket *requestSaveTicket();
93
94 /**
95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false.
97 */
98 virtual bool load();
99
100 /**
101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false.
103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */
106 virtual bool save( Ticket *ticket );
107
108 /**
109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook.
111 */
112 virtual void removeAddressee( const Addressee& addr );
113
114 /**
115 * Set name of file to be used for saving.
116 */
117 virtual void setFileName( const QString & );
118
119 /**
120 * This method is called by an error handler if the application
121 * crashed
122 */
123 virtual void cleanUp();
124
125
126protected slots:
127 void fileChanged();
128
129protected:
130 void init( const QString &fileName );
131
132 bool lock( const QString &fileName );
133 void unlock( const QString &fileName );
134
135private:
136 SlZDataBase* mAccess;
137 SharpDTMConverter* mConverter;
138
139 QString mLockUniqueName;
140
141 KDirWatch mDirWatch;
142};
143
144}
145
146#endif
diff --git a/kabc/plugins/olaccess/resourceolaccessconfig.cpp b/kabc/plugins/olaccess/resourceolaccessconfig.cpp
new file mode 100644
index 0000000..240f1d7
--- a/dev/null
+++ b/kabc/plugins/olaccess/resourceolaccessconfig.cpp
@@ -0,0 +1,108 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qlabel.h>
29#include <qlayout.h>
30
31#include <kdebug.h>
32#include <klocale.h>
33#include <kstandarddirs.h>
34#include <kdialog.h>
35
36#include <unistd.h>
37
38#include <qdir.h>
39#include <qfile.h>
40#include "resourcesharpdtm.h"
41
42#include "resourcesharpdtmconfig.h"
43
44#include <sl/slzdb.h>
45
46using namespace KABC;
47
48ResourceSharpDTMConfig::ResourceSharpDTMConfig( QWidget* parent, const char* name )
49 : ConfigWidget( parent, name )
50{
51 QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0,
52 KDialog::spacingHint() );
53
54 QLabel *label = new QLabel( i18n( "Location:" ), this );
55 mFileNameEdit = new KURLRequester( this );
56
57 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
58 SLOT( checkFilePermissions( const QString & ) ) );
59
60 mainLayout->addWidget( label, 0, 0 );
61 mainLayout->addWidget( mFileNameEdit, 0, 1 );
62
63}
64
65void ResourceSharpDTMConfig::loadSettings( KRES::Resource *res )
66{
67//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
68 ResourceSharpDTM *resource = (ResourceSharpDTM*)( res );
69
70 if ( !resource ) {
71 kdDebug(5700) << "ResourceSharpDTMConfig::loadSettings(): cast failed" << endl;
72 return;
73 }
74
75 mFileNameEdit->setURL( resource->fileName() );
76 if ( mFileNameEdit->url().isEmpty() )
77 mFileNameEdit->setURL( SlZDataBase::addressbookFileName() );
78
79 //US Sharp DTM resources are ReadOnly by definition
80 emit setPersistentReadOnly( true );
81
82 //US we can not choose the filename for the sharp backend => make it readonly.
83 mFileNameEdit->setEnabled( false );
84
85}
86
87void ResourceSharpDTMConfig::saveSettings( KRES::Resource *res )
88{
89//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
90 ResourceSharpDTM *resource = (ResourceSharpDTM*)( res );
91
92 if ( !resource ) {
93 kdDebug(5700) << "ResourceSharpDTMConfig::saveSettings(): cast failed" << endl;
94 return;
95 }
96
97 resource->setFileName( mFileNameEdit->url() );
98}
99
100void ResourceSharpDTMConfig::checkFilePermissions( const QString& fileName )
101{
102 // If file exist but is not writeable...
103/*US
104 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
105 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
106*/
107}
108
diff --git a/kabc/plugins/olaccess/resourceolaccessconfig.h b/kabc/plugins/olaccess/resourceolaccessconfig.h
new file mode 100644
index 0000000..29765c8
--- a/dev/null
+++ b/kabc/plugins/olaccess/resourceolaccessconfig.h
@@ -0,0 +1,58 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef RESOURCESHARPDTMCONFIG_H
30#define RESOURCESHARPDTMCONFIG_H
31
32#include <kurlrequester.h>
33
34#include <kresources/configwidget.h>
35
36namespace KABC {
37
38class ResourceSharpDTMConfig : public KRES::ConfigWidget
39{
40 Q_OBJECT
41
42public:
43 ResourceSharpDTMConfig( QWidget* parent = 0, const char* name = 0 );
44
45public slots:
46 void loadSettings( KRES::Resource *resource );
47 void saveSettings( KRES::Resource *resource );
48
49protected slots:
50 void checkFilePermissions( const QString& fileName );
51
52private:
53 KURLRequester* mFileNameEdit;
54};
55
56}
57
58#endif