summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaE.pro2
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp7
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.h1
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp78
4 files changed, 60 insertions, 28 deletions
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro
index 148da2a..c0aa960 100644
--- a/kabc/plugins/qtopia/qtopiaE.pro
+++ b/kabc/plugins/qtopia/qtopiaE.pro
@@ -1,27 +1,27 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3 3
4TARGET = microkabc_qtopia 4TARGET = microkabc_qtopia
5 5
6INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include 6INCLUDEPATH += $(KDEPIMDIR) $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat $(QPEDIR)/include
7 7
8OBJECTS_DIR = obj/$(PLATFORM) 8OBJECTS_DIR = obj/$(PLATFORM)
9MOC_DIR = moc/$(PLATFORM) 9MOC_DIR = moc/$(PLATFORM)
10DESTDIR = $(QPEDIR)/lib 10DESTDIR = $(QPEDIR)/lib
11LIBS += -lmicrokde 11LIBS += -lmicrokde
12LIBS += -lmicrokabc 12LIBS += -lmicrokabc
13LIBS += -L$(QPEDIR)/lib 13LIBS += -L$(QPEDIR)/lib
14LIBS += -lqpepim 14LIBS += -lqpepim
15LIBS += -lqpe 15LIBS += -lqpe
16 16
17INTERFACES = \ 17INTERFACES = \
18 18
19HEADERS = \ 19HEADERS = \
20 resourceqtopia.h \ 20 resourceqtopia.h \
21 resourceqtopiaconfig.h \ 21 resourceqtopiaconfig.h \
22 qtopiaconverter.h 22 qtopiaconverter.h
23 23
24SOURCES = \ 24SOURCES = \
25 resourceqtopia.cpp \ 25 resourceqtopia.cpp \
26 resourceqtopiaconfig.cpp \ 26 resourceqtopiaconfig.cpp \
27 qtopiaconverter.cpp 27 qtopiaconverter.cpp
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index 7d00a3f..de45e63 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -11,92 +11,96 @@
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//US 28//US
29#include "kglobal.h" 29#include "kglobal.h"
30 30
31 31
32#include "qtopiaconverter.h" 32#include "qtopiaconverter.h"
33 33
34#include <qpe/categories.h> 34#include <qpe/categories.h>
35#include <libkdepim/ksyncprofile.h>
35//US #include <qpe/categoryselect.h> 36//US #include <qpe/categoryselect.h>
36 37
37 38
38using namespace KABC; 39using namespace KABC;
39 40
40QtopiaConverter::QtopiaConverter() : catDB(0) 41QtopiaConverter::QtopiaConverter() : catDB(0)
41{ 42{
42} 43}
43 44
44QtopiaConverter::~QtopiaConverter() 45QtopiaConverter::~QtopiaConverter()
45{ 46{
46 deinit(); 47 deinit();
47} 48}
48 49
49bool QtopiaConverter::init() 50bool QtopiaConverter::init()
50{ 51{
51 catDB = new Categories(); 52 catDB = new Categories();
52 53
53 if (!catDB) 54 if (!catDB)
54 return false; 55 return false;
55 56
56 catDB->load( categoryFileName() ); 57 catDB->load( categoryFileName() );
57 return true; 58 return true;
58} 59}
59 60
60void QtopiaConverter::deinit() 61void QtopiaConverter::deinit()
61{ 62{
62 if (catDB) 63 if (catDB)
63 { 64 {
64 delete catDB; 65 delete catDB;
65 catDB = 0; 66 catDB = 0;
66 } 67 }
67} 68}
68 69
69bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) 70bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr )
70{ 71{
71 // name 72 // name
72 addr.setFormattedName(contact.fileAs()); 73 addr.setFormattedName(contact.fileAs());
73 addr.setFamilyName( contact.lastName() ); 74 addr.setFamilyName( contact.lastName() );
74 addr.setGivenName( contact.firstName() ); 75 addr.setGivenName( contact.firstName() );
75 addr.setAdditionalName( contact.middleName() ); 76 addr.setAdditionalName( contact.middleName() );
76 addr.setPrefix( contact.nameTitle() ); 77 addr.setPrefix( contact.nameTitle() );
77 addr.setSuffix( contact.suffix() ); 78 addr.setSuffix( contact.suffix() );
79
80 addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
78 QString exuid = contact.uid().toString(); 81 QString exuid = contact.uid().toString();
82 addr.setOriginalExternalUID( exuid );
79 int ente = exuid.find( "-0000"); 83 int ente = exuid.find( "-0000");
80 if ( exuid.left(1) == "{" ) 84 if ( exuid.left(1) == "{" )
81 exuid = exuid.mid(1); 85 exuid = exuid.mid(1);
82 if ( ente > -1 ) 86 if ( ente > -1 )
83 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
84 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
85 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); 89 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() );
86 90
87 // email 91 // email
88 QStringList emails = contact.emailList(); 92 QStringList emails = contact.emailList();
89 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 93 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
90 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); 94 addr.insertEmail( *it, ((*it) == contact.defaultEmail()) );
91 } 95 }
92 96
93 if (!contact.defaultEmail().isEmpty()) 97 if (!contact.defaultEmail().isEmpty())
94 addr.insertEmail(contact.defaultEmail(), true); 98 addr.insertEmail(contact.defaultEmail(), true);
95 99
96 // home 100 // home
97 if ((!contact.homeStreet().isEmpty()) || 101 if ((!contact.homeStreet().isEmpty()) ||
98 (!contact.homeCity().isEmpty()) || 102 (!contact.homeCity().isEmpty()) ||
99 (!contact.homeState().isEmpty()) || 103 (!contact.homeState().isEmpty()) ||
100 (!contact.homeZip().isEmpty()) || 104 (!contact.homeZip().isEmpty()) ||
101 (!contact.homeCountry().isEmpty())) 105 (!contact.homeCountry().isEmpty()))
102 { 106 {
@@ -230,48 +234,51 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a
230 234
231 addr.setNote( contact.notes() ); 235 addr.setNote( contact.notes() );
232 236
233 237
234 238
235//US QString groups() const { return find( Qtopia::Groups ); } 239//US QString groups() const { return find( Qtopia::Groups ); }
236//US QStringList groupList() const; 240//US QStringList groupList() const;
237 241
238 QArray<int> catArray = contact.categories(); 242 QArray<int> catArray = contact.categories();
239 QString cat; 243 QString cat;
240 244
241 for ( unsigned int i=0; i < catArray.size(); i++ ) { 245 for ( unsigned int i=0; i < catArray.size(); i++ ) {
242 cat = catDB->label("contact", catArray[i]); 246 cat = catDB->label("contact", catArray[i]);
243 if ( cat.isEmpty() ) 247 if ( cat.isEmpty() )
244 addr.insertCategory(QString::number(catArray[i])); 248 addr.insertCategory(QString::number(catArray[i]));
245 else 249 else
246 addr.insertCategory( cat ); 250 addr.insertCategory( cat );
247 } 251 }
248 252
249 return true; 253 return true;
250} 254}
251 255
252bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) 256bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact )
253{ 257{
258
259
260
254 // name 261 // name
255 contact.setLastName(addr.familyName()); 262 contact.setLastName(addr.familyName());
256 contact.setFirstName(addr.givenName()); 263 contact.setFirstName(addr.givenName());
257 contact.setMiddleName(addr.additionalName()); 264 contact.setMiddleName(addr.additionalName());
258 contact.setNameTitle(addr.prefix()); 265 contact.setNameTitle(addr.prefix());
259 contact.setSuffix(addr.suffix()); 266 contact.setSuffix(addr.suffix());
260 contact.setFileAs(); 267 contact.setFileAs();
261 268
262 269
263 // email 270 // email
264 QStringList emails = addr.emails(); 271 QStringList emails = addr.emails();
265 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 272 for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
266 contact.insertEmail(*it); 273 contact.insertEmail(*it);
267 } 274 }
268 contact.setDefaultEmail( addr.preferredEmail() ); 275 contact.setDefaultEmail( addr.preferredEmail() );
269 276
270 277
271 // home 278 // home
272 const Address homeaddress = addr.address(Address::Home); 279 const Address homeaddress = addr.address(Address::Home);
273 if (!homeaddress.isEmpty()) { 280 if (!homeaddress.isEmpty()) {
274 contact.setHomeStreet(homeaddress.street()); 281 contact.setHomeStreet(homeaddress.street());
275 contact.setHomeCity(homeaddress.locality()); 282 contact.setHomeCity(homeaddress.locality());
276 contact.setHomeState(homeaddress.region()); 283 contact.setHomeState(homeaddress.region());
277 contact.setHomeZip(homeaddress.postalCode()); 284 contact.setHomeZip(homeaddress.postalCode());
diff --git a/kabc/plugins/qtopia/qtopiaconverter.h b/kabc/plugins/qtopia/qtopiaconverter.h
index 8f4c698..012a6e2 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.h
+++ b/kabc/plugins/qtopia/qtopiaconverter.h
@@ -10,48 +10,49 @@
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$Id$ 24$Id$
25*/ 25*/
26 26
27#ifndef KABC_QTOPIACONVERTER_H 27#ifndef KABC_QTOPIACONVERTER_H
28#define KABC_QTOPIACONVERTER_H 28#define KABC_QTOPIACONVERTER_H
29 29
30#include <qstring.h> 30#include <qstring.h>
31 31
32#include "addressee.h" 32#include "addressee.h"
33#include <qpe/pim/contact.h> 33#include <qpe/pim/contact.h>
34#include <qpe/quuid.h>
34 35
35class Categories; 36class Categories;
36 37
37namespace KABC { 38namespace KABC {
38 39
39class QtopiaConverter 40class QtopiaConverter
40{ 41{
41public: 42public:
42 43
43 /** 44 /**
44 * Constructor. 45 * Constructor.
45 */ 46 */
46 QtopiaConverter(); 47 QtopiaConverter();
47 48
48 /** 49 /**
49 * Destructor. 50 * Destructor.
50 */ 51 */
51 virtual ~QtopiaConverter(); 52 virtual ~QtopiaConverter();
52 53
53 bool init(); 54 bool init();
54 void deinit(); 55 void deinit();
55 56
56 /** 57 /**
57 * Converts a vcard string to an addressee. 58 * Converts a vcard string to an addressee.
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 48a9f22..935a1cf 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -31,48 +31,50 @@ $Id$
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h>
55 57
56using namespace KABC; 58using namespace KABC;
57extern "C" 59extern "C"
58{ 60{
59 void *init_microkabc_qtopia() 61 void *init_microkabc_qtopia()
60 { 62 {
61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>();
62 } 64 }
63} 65}
64 66
65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
66 : Resource( config, syncable ), mConverter (0) 68 : Resource( config, syncable ), mConverter (0)
67{ 69{
68 // we can not choose the filename. Therefore use the default to display 70 // we can not choose the filename. Therefore use the default to display
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 init( fileName ); 72 init( fileName );
71} 73}
72 74
73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 75ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
74 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
75{ 77{
76 init( fileName ); 78 init( fileName );
77} 79}
78 80
@@ -168,80 +170,102 @@ bool ResourceQtopia::load()
168 AddressBookIterator it(*mAccess); 170 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 171 const PimContact* contact;
170 bool res; 172 bool res;
171 173
172 for (contact=it.toFirst(); it.current(); ++it) 174 for (contact=it.toFirst(); it.current(); ++it)
173 { 175 {
174 contact = it.current(); 176 contact = it.current();
175 177
176 KABC::Addressee addressee; 178 KABC::Addressee addressee;
177 179
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 180 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 181
180 if ( !addressee.isEmpty() && res ) 182 if ( !addressee.isEmpty() && res )
181 { 183 {
182 addressee.setResource( this ); 184 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 185 addressBook()->insertAddressee( addressee );
184 } 186 }
185 } 187 }
186 188
187 return true; 189 return true;
188} 190}
189 191
190bool ResourceQtopia::save( Ticket *ticket ) 192bool ResourceQtopia::save( Ticket *ticket )
191{ 193{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 194 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 195
194 mDirWatch.stopScan(); 196 mDirWatch.stopScan();
195 197
196 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
197 bool res; 199 bool res;
198 200
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c; 202 //KABC::Addressee addressee = (*it);
201 KABC::Addressee addressee = (*it); 203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
202 204 QUuid uid( (*it).originalExternalUID() );
203 res = mConverter->addresseeToQtopia( *it, c ); 205 bool ok;
204 if (res == true) 206 PimContact c = mAccess->contactForId( uid, &ok );
205 { 207 res = mConverter->addresseeToQtopia( *it, c );
206 mAccess->addContact(c); 208 if (res == true) {
207// if (res == false) 209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
208// qDebug("Unable to append Contact %s", c.fullName().latin1()); 210 mAccess->addContact(c);
211 KABC::Addressee addressee;
212 mConverter->qtopiaToAddressee( c, addressee );
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
214 addressBook()->insertAddressee( addressee );
215
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
217 if ( ok )
218 mAccess->removeContact(c);
219 else
220 qDebug("Error revoe contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) {
223 mAccess->updateContact(c);
224 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee );
228 }
229 else
230 qDebug("Error update contact from qtopia ");
231
232 }
233
234 } else {
235 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
236 }
237 }
209 } 238 }
210 else
211 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 }
214 }
215 239
216// mAccess->addressBookUpdated(); 240 // mAccess->addressBookUpdated();
217 241
218 mDirWatch.startScan(); 242 mDirWatch.startScan();
219 243
220 delete ticket; 244 delete ticket;
221 unlock( fileName() ); 245 unlock( fileName() );
222 246
223 return true; 247 return true;
224} 248}
225 249
226bool ResourceQtopia::lock( const QString &lockfileName ) 250bool ResourceQtopia::lock( const QString &lockfileName )
227{ 251{
228 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 252 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
229 253
230 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 254 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
231 255
232 QString fn = lockfileName; 256 QString fn = lockfileName;
233 257
234 KURL url(fn); 258 KURL url(fn);
235 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 259 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
236 260
237 kdDebug(5700) << "-- lock name: " << lockName << endl; 261 kdDebug(5700) << "-- lock name: " << lockName << endl;
238 262
239 if (QFile::exists( lockName )) 263 if (QFile::exists( lockName ))
240 { 264 {
241 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 265 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
242 return false; 266 return false;
243 } 267 }
244 268
245 QString lockUniqueName; 269 QString lockUniqueName;
246 lockUniqueName = fn + KApplication::randomString( 8 ); 270 lockUniqueName = fn + KApplication::randomString( 8 );
247 271