summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 22:33:39 (UTC)
committer zautrix <zautrix>2004-09-18 22:33:39 (UTC)
commitf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (patch) (unidiff)
treec1a9de8b305200a7cec885764a0afb4beb92dabb
parent28f894fd2a0dfbd5f09f9e530f359981efe0198c (diff)
downloadkdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.zip
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.gz
kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp13
-rw-r--r--kabc/address.h1
-rw-r--r--kabc/addressbook.cpp133
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp99
-rw-r--r--kabc/addressee.h2
-rw-r--r--kaddressbook/kabcore.cpp36
7 files changed, 245 insertions, 43 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index c820a6c..5ffe511 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -1,186 +1,199 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
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//US added kglobal.h 28//US added kglobal.h
29#include <kglobal.h> 29#include <kglobal.h>
30 30
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <ksimpleconfig.h> 34#include <ksimpleconfig.h>
35#include <kstandarddirs.h> 35#include <kstandarddirs.h>
36 36
37#include <qfile.h> 37#include <qfile.h>
38 38
39#include "address.h" 39#include "address.h"
40 40
41using namespace KABC; 41using namespace KABC;
42 42
43QMap<QString, QString> Address::mISOMap; 43QMap<QString, QString> Address::mISOMap;
44 44
45Address::Address() : 45Address::Address() :
46 mEmpty( true ), mType( 0 ) 46 mEmpty( true ), mType( 0 )
47{ 47{
48 mId = KApplication::randomString( 10 ); 48 mId = KApplication::randomString( 10 );
49} 49}
50 50
51Address::Address( int type ) : 51Address::Address( int type ) :
52 mEmpty( true ), mType( type ) 52 mEmpty( true ), mType( type )
53{ 53{
54 mId = KApplication::randomString( 10 ); 54 mId = KApplication::randomString( 10 );
55} 55}
56 56
57bool Address::operator==( const Address &a ) const 57bool Address::operator==( const Address &a ) const
58{ 58{
59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false; 59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
60 if ( mExtended != a.mExtended ) return false; 60 if ( mExtended != a.mExtended ) return false;
61 if ( mStreet != a.mStreet ) return false; 61 if ( mStreet != a.mStreet ) return false;
62 if ( mLocality != a.mLocality ) return false; 62 if ( mLocality != a.mLocality ) return false;
63 if ( mRegion != a.mRegion ) return false; 63 if ( mRegion != a.mRegion ) return false;
64 if ( mPostalCode != a.mPostalCode ) return false; 64 if ( mPostalCode != a.mPostalCode ) return false;
65 if ( mCountry != a.mCountry ) return false; 65 if ( mCountry != a.mCountry ) return false;
66 if ( mLabel != a.mLabel ) return false; 66 if ( mLabel != a.mLabel ) return false;
67 67
68 return true; 68 return true;
69} 69}
70 70
71bool Address::operator!=( const Address &a ) const 71bool Address::operator!=( const Address &a ) const
72{ 72{
73 return !( a == *this ); 73 return !( a == *this );
74} 74}
75 75
76bool Address::isEmpty() const 76bool Address::isEmpty() const
77{ 77{
78 if ( mPostOfficeBox.isEmpty() && 78 if ( mPostOfficeBox.isEmpty() &&
79 mExtended.isEmpty() && 79 mExtended.isEmpty() &&
80 mStreet.isEmpty() && 80 mStreet.isEmpty() &&
81 mLocality.isEmpty() && 81 mLocality.isEmpty() &&
82 mRegion.isEmpty() && 82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() && 83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() && 84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) { 85 mLabel.isEmpty() ) {
86 return true; 86 return true;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91QStringList Address::asList()
92{
93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result;
103}
91void Address::clear() 104void Address::clear()
92{ 105{
93 *this = Address(); 106 *this = Address();
94} 107}
95 108
96void Address::setId( const QString &id ) 109void Address::setId( const QString &id )
97{ 110{
98 mEmpty = false; 111 mEmpty = false;
99 112
100 mId = id; 113 mId = id;
101} 114}
102 115
103QString Address::id() const 116QString Address::id() const
104{ 117{
105 return mId; 118 return mId;
106} 119}
107 120
108void Address::setType( int type ) 121void Address::setType( int type )
109{ 122{
110 mEmpty = false; 123 mEmpty = false;
111 124
112 mType = type; 125 mType = type;
113} 126}
114 127
115int Address::type() const 128int Address::type() const
116{ 129{
117 return mType; 130 return mType;
118} 131}
119 132
120QString Address::typeLabel() const 133QString Address::typeLabel() const
121{ 134{
122 QString label; 135 QString label;
123 bool first = true; 136 bool first = true;
124 137
125 TypeList list = typeList(); 138 TypeList list = typeList();
126 139
127 TypeList::Iterator it; 140 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 141 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 142 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 143 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 144 if ( first )
132 first = false; 145 first = false;
133 } 146 }
134 } 147 }
135 148
136 return label; 149 return label;
137} 150}
138 151
139void Address::setPostOfficeBox( const QString &s ) 152void Address::setPostOfficeBox( const QString &s )
140{ 153{
141 mEmpty = false; 154 mEmpty = false;
142 155
143 mPostOfficeBox = s; 156 mPostOfficeBox = s;
144} 157}
145 158
146QString Address::postOfficeBox() const 159QString Address::postOfficeBox() const
147{ 160{
148 return mPostOfficeBox; 161 return mPostOfficeBox;
149} 162}
150 163
151QString Address::postOfficeBoxLabel() 164QString Address::postOfficeBoxLabel()
152{ 165{
153 return i18n("Post Office Box"); 166 return i18n("Post Office Box");
154} 167}
155 168
156 169
157void Address::setExtended( const QString &s ) 170void Address::setExtended( const QString &s )
158{ 171{
159 mEmpty = false; 172 mEmpty = false;
160 173
161 mExtended = s; 174 mExtended = s;
162} 175}
163 176
164QString Address::extended() const 177QString Address::extended() const
165{ 178{
166 return mExtended; 179 return mExtended;
167} 180}
168 181
169QString Address::extendedLabel() 182QString Address::extendedLabel()
170{ 183{
171 return i18n("Extended Address Information"); 184 return i18n("Extended Address Information");
172} 185}
173 186
174 187
175void Address::setStreet( const QString &s ) 188void Address::setStreet( const QString &s )
176{ 189{
177 mEmpty = false; 190 mEmpty = false;
178 191
179 mStreet = s; 192 mStreet = s;
180} 193}
181 194
182QString Address::street() const 195QString Address::street() const
183{ 196{
184 return mStreet; 197 return mStreet;
185} 198}
186 199
diff --git a/kabc/address.h b/kabc/address.h
index ad132a7..6b53c7e 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -14,192 +14,193 @@
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#ifndef KABC_ADDRESS_H 28#ifndef KABC_ADDRESS_H
29#define KABC_ADDRESS_H 29#define KABC_ADDRESS_H
30 30
31#include <qmap.h> 31#include <qmap.h>
32#include <qstring.h> 32#include <qstring.h>
33#include <qvaluelist.h> 33#include <qvaluelist.h>
34 34
35// template tags for address formatting localization 35// template tags for address formatting localization
36#define KABC_FMTTAG_realname QString("%n") 36#define KABC_FMTTAG_realname QString("%n")
37#define KABC_FMTTAG_REALNAME QString("%N") 37#define KABC_FMTTAG_REALNAME QString("%N")
38#define KABC_FMTTAG_company QString("%cm") 38#define KABC_FMTTAG_company QString("%cm")
39#define KABC_FMTTAG_COMPANY QString("%CM") 39#define KABC_FMTTAG_COMPANY QString("%CM")
40#define KABC_FMTTAG_pobox QString("%p") 40#define KABC_FMTTAG_pobox QString("%p")
41#define KABC_FMTTAG_street QString("%s") 41#define KABC_FMTTAG_street QString("%s")
42#define KABC_FMTTAG_STREET QString("%S") 42#define KABC_FMTTAG_STREET QString("%S")
43#define KABC_FMTTAG_zipcode QString("%z") 43#define KABC_FMTTAG_zipcode QString("%z")
44#define KABC_FMTTAG_location QString("%l") 44#define KABC_FMTTAG_location QString("%l")
45#define KABC_FMTTAG_LOCATION QString("%L") 45#define KABC_FMTTAG_LOCATION QString("%L")
46#define KABC_FMTTAG_region QString("%r") 46#define KABC_FMTTAG_region QString("%r")
47#define KABC_FMTTAG_REGION QString("%R") 47#define KABC_FMTTAG_REGION QString("%R")
48#define KABC_FMTTAG_newline QString("\\n") 48#define KABC_FMTTAG_newline QString("\\n")
49#define KABC_FMTTAG_condcomma QString("%,") 49#define KABC_FMTTAG_condcomma QString("%,")
50#define KABC_FMTTAG_condwhite QString("%w") 50#define KABC_FMTTAG_condwhite QString("%w")
51#define KABC_FMTTAG_purgeempty QString("%0") 51#define KABC_FMTTAG_purgeempty QString("%0")
52 52
53namespace KABC { 53namespace KABC {
54 54
55/** 55/**
56 @short Postal address information. 56 @short Postal address information.
57 57
58 This class represents information about a postal address. 58 This class represents information about a postal address.
59*/ 59*/
60class Address 60class Address
61{ 61{
62 friend QDataStream &operator<<( QDataStream &, const Address & ); 62 friend QDataStream &operator<<( QDataStream &, const Address & );
63 friend QDataStream &operator>>( QDataStream &, Address & ); 63 friend QDataStream &operator>>( QDataStream &, Address & );
64 64
65 public: 65 public:
66 /** 66 /**
67 List of addresses. 67 List of addresses.
68 */ 68 */
69 typedef QValueList<Address> List; 69 typedef QValueList<Address> List;
70 typedef QValueList<int> TypeList; 70 typedef QValueList<int> TypeList;
71 71
72 /** 72 /**
73 Address types: 73 Address types:
74 74
75 @li @p Dom - domestic 75 @li @p Dom - domestic
76 @li @p Intl - international 76 @li @p Intl - international
77 @li @p Postal - postal 77 @li @p Postal - postal
78 @li @p Parcel - parcel 78 @li @p Parcel - parcel
79 @li @p Home - home address 79 @li @p Home - home address
80 @li @p Work - address at work 80 @li @p Work - address at work
81 @li @p Pref - preferred address 81 @li @p Pref - preferred address
82 */ 82 */
83 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, 83 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32,
84 Pref = 64 }; 84 Pref = 64 };
85 85
86 /** 86 /**
87 Constructor that creates an empty Address, which is initialized 87 Constructor that creates an empty Address, which is initialized
88 with a unique id (see @ref id()). 88 with a unique id (see @ref id()).
89 */ 89 */
90 Address(); 90 Address();
91 91
92 /** 92 /**
93 This is like @ref Address() just above, with the difference 93 This is like @ref Address() just above, with the difference
94 that you can specify the type. 94 that you can specify the type.
95 */ 95 */
96 Address( int ); 96 Address( int );
97 97
98 bool operator==( const Address & ) const; 98 bool operator==( const Address & ) const;
99 bool operator!=( const Address & ) const; 99 bool operator!=( const Address & ) const;
100 100
101 /** 101 /**
102 Returns true, if the address is empty. 102 Returns true, if the address is empty.
103 */ 103 */
104 bool isEmpty() const; 104 bool isEmpty() const;
105 105
106 /** 106 /**
107 Clears all entries of the address. 107 Clears all entries of the address.
108 */ 108 */
109 void clear(); 109 void clear();
110 QStringList asList();
110 111
111 /** 112 /**
112 Sets the unique id. 113 Sets the unique id.
113 */ 114 */
114 void setId( const QString & ); 115 void setId( const QString & );
115 116
116 /* 117 /*
117 Returns the unique id. 118 Returns the unique id.
118 */ 119 */
119 QString id() const; 120 QString id() const;
120 121
121 /** 122 /**
122 Sets the type of address. See enum for definiton of types. 123 Sets the type of address. See enum for definiton of types.
123 124
124 @param type type, can be a bitwise or of multiple types. 125 @param type type, can be a bitwise or of multiple types.
125 */ 126 */
126 void setType( int type ); 127 void setType( int type );
127 128
128 /** 129 /**
129 Returns the type of address. Can be a bitwise or of multiple types. 130 Returns the type of address. Can be a bitwise or of multiple types.
130 */ 131 */
131 int type() const; 132 int type() const;
132 133
133 /** 134 /**
134 Returns a translated string of all types the address has. 135 Returns a translated string of all types the address has.
135 */ 136 */
136 QString typeLabel() const; 137 QString typeLabel() const;
137 138
138 /** 139 /**
139 Sets the post office box. 140 Sets the post office box.
140 */ 141 */
141 void setPostOfficeBox( const QString & ); 142 void setPostOfficeBox( const QString & );
142 143
143 /** 144 /**
144 Returns the post office box. 145 Returns the post office box.
145 */ 146 */
146 QString postOfficeBox() const; 147 QString postOfficeBox() const;
147 148
148 /** 149 /**
149 Returns the translated label for post office box field. 150 Returns the translated label for post office box field.
150 */ 151 */
151 static QString postOfficeBoxLabel(); 152 static QString postOfficeBoxLabel();
152 153
153 /** 154 /**
154 Sets the extended address information. 155 Sets the extended address information.
155 */ 156 */
156 void setExtended( const QString & ); 157 void setExtended( const QString & );
157 158
158 /** 159 /**
159 Returns the extended address information. 160 Returns the extended address information.
160 */ 161 */
161 QString extended() const; 162 QString extended() const;
162 163
163 /** 164 /**
164 Returns the translated label for extended field. 165 Returns the translated label for extended field.
165 */ 166 */
166 static QString extendedLabel(); 167 static QString extendedLabel();
167 168
168 /** 169 /**
169 Sets the street (including number). 170 Sets the street (including number).
170 */ 171 */
171 void setStreet( const QString & ); 172 void setStreet( const QString & );
172 173
173 /** 174 /**
174 Returns the street. 175 Returns the street.
175 */ 176 */
176 QString street() const; 177 QString street() const;
177 178
178 /** 179 /**
179 Returns the translated label for street field. 180 Returns the translated label for street field.
180 */ 181 */
181 static QString streetLabel(); 182 static QString streetLabel();
182 183
183 /** 184 /**
184 Sets the locality, e.g. city. 185 Sets the locality, e.g. city.
185 */ 186 */
186 void setLocality( const QString & ); 187 void setLocality( const QString & );
187 188
188 /** 189 /**
189 Returns the locality. 190 Returns the locality.
190 */ 191 */
191 QString locality() const; 192 QString locality() const;
192 193
193 /** 194 /**
194 Returns the translated label for locality field. 195 Returns the translated label for locality field.
195 */ 196 */
196 static QString localityLabel(); 197 static QString localityLabel();
197 198
198 /** 199 /**
199 Sets the region, e.g. state. 200 Sets the region, e.g. state.
200 */ 201 */
201 void setRegion( const QString & ); 202 void setRegion( const QString & );
202 203
203 /** 204 /**
204 Returns the region. 205 Returns the region.
205 */ 206 */
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -141,495 +141,556 @@ bool AddressBook::Iterator::operator==( const Iterator &it )
141 141
142bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
143{ 143{
144 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
145} 145}
146 146
147 147
148AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
149{ 149{
150 d = new ConstIteratorData; 150 d = new ConstIteratorData;
151} 151}
152 152
153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
154{ 154{
155 d = new ConstIteratorData; 155 d = new ConstIteratorData;
156 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
157} 157}
158 158
159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
160{ 160{
161 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
162 delete d; // delete the old data because the Iterator was really constructed before 162 delete d; // delete the old data because the Iterator was really constructed before
163 d = new ConstIteratorData; 163 d = new ConstIteratorData;
164 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
165 return *this; 165 return *this;
166} 166}
167 167
168AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
169{ 169{
170 delete d; 170 delete d;
171} 171}
172 172
173const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
174{ 174{
175 return *(d->mIt); 175 return *(d->mIt);
176} 176}
177 177
178const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
179{ 179{
180 return &(*(d->mIt)); 180 return &(*(d->mIt));
181} 181}
182 182
183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
184{ 184{
185 (d->mIt)++; 185 (d->mIt)++;
186 return *this; 186 return *this;
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
196{ 196{
197 (d->mIt)--; 197 (d->mIt)--;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
208{ 208{
209 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
210} 210}
211 211
212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
213{ 213{
214 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
215} 215}
216 216
217 217
218AddressBook::AddressBook() 218AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false;
237 d = new AddressBookData; 238 d = new AddressBookData;
238 QString fami = family; 239 QString fami = family;
239 qDebug("new ab "); 240 qDebug("new ab ");
240 if (config != 0) { 241 if (config != 0) {
241 qDebug("config != 0 "); 242 qDebug("config != 0 ");
242 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
243 qDebug("creating sync config "); 244 qDebug("creating sync config ");
244 fami = "contact"; 245 fami = "contact";
245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
246 con->setGroup( "General" ); 247 con->setGroup( "General" );
247 con->writeEntry( "ResourceKeys", QString("sync") ); 248 con->writeEntry( "ResourceKeys", QString("sync") );
248 con->writeEntry( "Standard", QString("sync") ); 249 con->writeEntry( "Standard", QString("sync") );
249 con->setGroup( "Resource_sync" ); 250 con->setGroup( "Resource_sync" );
250 con->writeEntry( "FileFormat", QString("vcard") ); 251 con->writeEntry( "FileFormat", QString("vcard") );
251 con->writeEntry( "FileName", config ); 252 con->writeEntry( "FileName", config );
252 con->writeEntry( "ResourceIdentifier", QString("sync") ); 253 con->writeEntry( "ResourceIdentifier", QString("sync") );
253 con->writeEntry( "ResourceName", QString("sync_res") ); 254 con->writeEntry( "ResourceName", QString("sync_res") );
254 con->writeEntry( "ResourceType", QString("file") ); 255 con->writeEntry( "ResourceType", QString("file") );
255 //con->sync(); 256 //con->sync();
256 d->mConfig = con; 257 d->mConfig = con;
257 } 258 }
258 else 259 else
259 d->mConfig = new KConfig( locateLocal("config", config) ); 260 d->mConfig = new KConfig( locateLocal("config", config) );
260// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 261// qDebug("AddressBook::init 1 config=%s",config.latin1() );
261 } 262 }
262 else { 263 else {
263 d->mConfig = 0; 264 d->mConfig = 0;
264// qDebug("AddressBook::init 1 config=0"); 265// qDebug("AddressBook::init 1 config=0");
265 } 266 }
266 267
267//US d->mErrorHandler = 0; 268//US d->mErrorHandler = 0;
268 d->mManager = new KRES::Manager<Resource>( fami, false ); 269 d->mManager = new KRES::Manager<Resource>( fami, false );
269 d->mManager->readConfig( d->mConfig ); 270 d->mManager->readConfig( d->mConfig );
270 if ( family == "syncContact" ) { 271 if ( family == "syncContact" ) {
271 KRES::Manager<Resource> *manager = d->mManager; 272 KRES::Manager<Resource> *manager = d->mManager;
272 KRES::Manager<Resource>::ActiveIterator it; 273 KRES::Manager<Resource>::ActiveIterator it;
273 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 274 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
274 (*it)->setAddressBook( this ); 275 (*it)->setAddressBook( this );
275 if ( !(*it)->open() ) 276 if ( !(*it)->open() )
276 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 277 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
277 } 278 }
278 Resource *res = standardResource(); 279 Resource *res = standardResource();
279 if ( !res ) { 280 if ( !res ) {
280 qDebug("ERROR: no standard resource"); 281 qDebug("ERROR: no standard resource");
281 res = manager->createResource( "file" ); 282 res = manager->createResource( "file" );
282 if ( res ) 283 if ( res )
283 { 284 {
284 addResource( res ); 285 addResource( res );
285 } 286 }
286 else 287 else
287 qDebug(" No resource available!!!"); 288 qDebug(" No resource available!!!");
288 } 289 }
289 setStandardResource( res ); 290 setStandardResource( res );
290 manager->writeConfig(); 291 manager->writeConfig();
291 } 292 }
292 addCustomField( i18n( "Department" ), KABC::Field::Organization, 293 addCustomField( i18n( "Department" ), KABC::Field::Organization,
293 "X-Department", "KADDRESSBOOK" ); 294 "X-Department", "KADDRESSBOOK" );
294 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 295 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
295 "X-Profession", "KADDRESSBOOK" ); 296 "X-Profession", "KADDRESSBOOK" );
296 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 297 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
297 "X-AssistantsName", "KADDRESSBOOK" ); 298 "X-AssistantsName", "KADDRESSBOOK" );
298 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 299 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
299 "X-ManagersName", "KADDRESSBOOK" ); 300 "X-ManagersName", "KADDRESSBOOK" );
300 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 301 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
301 "X-SpousesName", "KADDRESSBOOK" ); 302 "X-SpousesName", "KADDRESSBOOK" );
302 addCustomField( i18n( "Office" ), KABC::Field::Personal, 303 addCustomField( i18n( "Office" ), KABC::Field::Personal,
303 "X-Office", "KADDRESSBOOK" ); 304 "X-Office", "KADDRESSBOOK" );
304 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 305 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
305 "X-IMAddress", "KADDRESSBOOK" ); 306 "X-IMAddress", "KADDRESSBOOK" );
306 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 307 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
307 "X-Anniversary", "KADDRESSBOOK" ); 308 "X-Anniversary", "KADDRESSBOOK" );
308 309
309 //US added this field to become compatible with Opie/qtopia addressbook 310 //US added this field to become compatible with Opie/qtopia addressbook
310 // values can be "female" or "male" or "". An empty field represents undefined. 311 // values can be "female" or "male" or "". An empty field represents undefined.
311 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 312 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
312 "X-Gender", "KADDRESSBOOK" ); 313 "X-Gender", "KADDRESSBOOK" );
313 addCustomField( i18n( "Children" ), KABC::Field::Personal, 314 addCustomField( i18n( "Children" ), KABC::Field::Personal,
314 "X-Children", "KADDRESSBOOK" ); 315 "X-Children", "KADDRESSBOOK" );
315 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
316 "X-FreeBusyUrl", "KADDRESSBOOK" ); 317 "X-FreeBusyUrl", "KADDRESSBOOK" );
317 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
318 "X-ExternalID", "KADDRESSBOOK" ); 319 "X-ExternalID", "KADDRESSBOOK" );
319} 320}
320 321
321AddressBook::~AddressBook() 322AddressBook::~AddressBook()
322{ 323{
323 delete d->mConfig; d->mConfig = 0; 324 delete d->mConfig; d->mConfig = 0;
324 delete d->mManager; d->mManager = 0; 325 delete d->mManager; d->mManager = 0;
325//US delete d->mErrorHandler; d->mErrorHandler = 0; 326//US delete d->mErrorHandler; d->mErrorHandler = 0;
326 delete d; d = 0; 327 delete d; d = 0;
327} 328}
328 329
329bool AddressBook::load() 330bool AddressBook::load()
330{ 331{
331 332
332 333
333 clear(); 334 clear();
334 335
335 KRES::Manager<Resource>::ActiveIterator it; 336 KRES::Manager<Resource>::ActiveIterator it;
336 bool ok = true; 337 bool ok = true;
337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
338 if ( !(*it)->load() ) { 339 if ( !(*it)->load() ) {
339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
340 ok = false; 341 ok = false;
341 } 342 }
342 343
343 // mark all addressees as unchanged 344 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
347 348
349 blockLSEchange = true;
348 return ok; 350 return ok;
349} 351}
350 352
351bool AddressBook::save( Ticket *ticket ) 353bool AddressBook::save( Ticket *ticket )
352{ 354{
353 kdDebug(5700) << "AddressBook::save()"<< endl; 355 kdDebug(5700) << "AddressBook::save()"<< endl;
354 356
355 if ( ticket->resource() ) { 357 if ( ticket->resource() ) {
356 deleteRemovedAddressees(); 358 deleteRemovedAddressees();
357 return ticket->resource()->save( ticket ); 359 return ticket->resource()->save( ticket );
358 } 360 }
359 361
360 return false; 362 return false;
361} 363}
362bool AddressBook::saveAB() 364bool AddressBook::saveAB()
363{ 365{
364 bool ok = true; 366 bool ok = true;
365 367
366 deleteRemovedAddressees(); 368 deleteRemovedAddressees();
367 369
368 KRES::Manager<Resource>::ActiveIterator it; 370 KRES::Manager<Resource>::ActiveIterator it;
369 KRES::Manager<Resource> *manager = d->mManager; 371 KRES::Manager<Resource> *manager = d->mManager;
370 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 372 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
371 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 373 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
372 Ticket *ticket = requestSaveTicket( *it ); 374 Ticket *ticket = requestSaveTicket( *it );
373// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 375// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
374 if ( !ticket ) { 376 if ( !ticket ) {
375 error( i18n( "Unable to save to resource '%1'. It is locked." ) 377 error( i18n( "Unable to save to resource '%1'. It is locked." )
376 .arg( (*it)->resourceName() ) ); 378 .arg( (*it)->resourceName() ) );
377 return false; 379 return false;
378 } 380 }
379 381
380 //if ( !save( ticket ) ) 382 //if ( !save( ticket ) )
381 if ( ticket->resource() ) { 383 if ( ticket->resource() ) {
382 if ( ! ticket->resource()->save( ticket ) ) 384 if ( ! ticket->resource()->save( ticket ) )
383 ok = false; 385 ok = false;
384 } else 386 } else
385 ok = false; 387 ok = false;
386 388
387 } 389 }
388 } 390 }
389 return ok; 391 return ok;
390} 392}
391 393
392AddressBook::Iterator AddressBook::begin() 394AddressBook::Iterator AddressBook::begin()
393{ 395{
394 Iterator it = Iterator(); 396 Iterator it = Iterator();
395 it.d->mIt = d->mAddressees.begin(); 397 it.d->mIt = d->mAddressees.begin();
396 return it; 398 return it;
397} 399}
398 400
399AddressBook::ConstIterator AddressBook::begin() const 401AddressBook::ConstIterator AddressBook::begin() const
400{ 402{
401 ConstIterator it = ConstIterator(); 403 ConstIterator it = ConstIterator();
402 it.d->mIt = d->mAddressees.begin(); 404 it.d->mIt = d->mAddressees.begin();
403 return it; 405 return it;
404} 406}
405 407
406AddressBook::Iterator AddressBook::end() 408AddressBook::Iterator AddressBook::end()
407{ 409{
408 Iterator it = Iterator(); 410 Iterator it = Iterator();
409 it.d->mIt = d->mAddressees.end(); 411 it.d->mIt = d->mAddressees.end();
410 return it; 412 return it;
411} 413}
412 414
413AddressBook::ConstIterator AddressBook::end() const 415AddressBook::ConstIterator AddressBook::end() const
414{ 416{
415 ConstIterator it = ConstIterator(); 417 ConstIterator it = ConstIterator();
416 it.d->mIt = d->mAddressees.end(); 418 it.d->mIt = d->mAddressees.end();
417 return it; 419 return it;
418} 420}
419 421
420void AddressBook::clear() 422void AddressBook::clear()
421{ 423{
422 d->mAddressees.clear(); 424 d->mAddressees.clear();
423} 425}
424 426
425Ticket *AddressBook::requestSaveTicket( Resource *resource ) 427Ticket *AddressBook::requestSaveTicket( Resource *resource )
426{ 428{
427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 429 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
428 430
429 if ( !resource ) 431 if ( !resource )
430 { 432 {
431 qDebug("AddressBook::requestSaveTicket no resource" ); 433 qDebug("AddressBook::requestSaveTicket no resource" );
432 resource = standardResource(); 434 resource = standardResource();
433 } 435 }
434 436
435 KRES::Manager<Resource>::ActiveIterator it; 437 KRES::Manager<Resource>::ActiveIterator it;
436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 438 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
437 if ( (*it) == resource ) { 439 if ( (*it) == resource ) {
438 if ( (*it)->readOnly() || !(*it)->isOpen() ) 440 if ( (*it)->readOnly() || !(*it)->isOpen() )
439 return 0; 441 return 0;
440 else 442 else
441 return (*it)->requestSaveTicket(); 443 return (*it)->requestSaveTicket();
442 } 444 }
443 } 445 }
444 446
445 return 0; 447 return 0;
446} 448}
447 449
448void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 450void AddressBook::insertAddressee( const Addressee &a, bool setRev )
449{ 451{
450 Addressee::List::Iterator it; 452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 453 return;
452 if ( a.uid() == (*it).uid() ) { 454 }
453 if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 455 bool found = false;
454 return; 456 Addressee::List::Iterator it;
455 } 457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
456 bool changed = false; 458 if ( a.uid() == (*it).uid() ) {
457 Addressee addr = a; 459
458 if ( addr != (*it) ) 460 bool changed = false;
459 changed = true; 461 Addressee addr = a;
460 462 if ( addr != (*it) )
461 (*it) = a; 463 changed = true;
462 if ( (*it).resource() == 0 ) 464
463 (*it).setResource( standardResource() ); 465 (*it) = a;
464 466 if ( (*it).resource() == 0 )
465 if ( changed ) { 467 (*it).setResource( standardResource() );
466 if ( setRev ) { 468
469 if ( changed ) {
470 if ( setRev ) {
467 471
468 // get rid of micro seconds 472 // get rid of micro seconds
469 QDateTime dt = QDateTime::currentDateTime(); 473 QDateTime dt = QDateTime::currentDateTime();
470 QTime t = dt.time(); 474 QTime t = dt.time();
471 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
472 (*it).setRevision( dt ); 476 (*it).setRevision( dt );
473 } 477 }
474 (*it).setChanged( true ); 478 (*it).setChanged( true );
475 } 479 }
476 480
477 return; 481 found = true;
482 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 );
485 Addressee b = a;
486 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) {
488 QString des = (*it).note();
489 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des );
494 }
495 }
496 }
497 }
478 } 498 }
479 } 499 if ( found )
480 d->mAddressees.append( a ); 500 return;
481 Addressee& addr = d->mAddressees.last(); 501 d->mAddressees.append( a );
482 if ( addr.resource() == 0 ) 502 Addressee& addr = d->mAddressees.last();
483 addr.setResource( standardResource() ); 503 if ( addr.resource() == 0 )
504 addr.setResource( standardResource() );
484 505
485 addr.setChanged( true ); 506 addr.setChanged( true );
486} 507}
487 508
488void AddressBook::removeAddressee( const Addressee &a ) 509void AddressBook::removeAddressee( const Addressee &a )
489{ 510{
490 Iterator it; 511 Iterator it;
512 Iterator it2;
513 bool found = false;
491 for ( it = begin(); it != end(); ++it ) { 514 for ( it = begin(); it != end(); ++it ) {
492 if ( a.uid() == (*it).uid() ) { 515 if ( a.uid() == (*it).uid() ) {
493 removeAddressee( it ); 516 found = true;
494 return; 517 it2 = it;
518 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 );
521 Addressee b = a;
522 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) {
524 QString des = (*it).note();
525 if( des.find( id ) < 0 ) {
526 des += id + ",";
527 (*it).setNote( des );
528 }
529 }
530 }
531
495 } 532 }
496 } 533 }
534
535 if ( found )
536 removeAddressee( it2 );
537
538}
539
540void AddressBook::removeDeletedAddressees()
541{
542 deleteRemovedAddressees();
543 Iterator it = begin();
544 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) {
547 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
549 it2 = it;
550 ++it;
551 removeAddressee( it2 );
552 } else
553 ++it;
554 }
555 deleteRemovedAddressees();
497} 556}
498 557
499void AddressBook::removeAddressee( const Iterator &it ) 558void AddressBook::removeAddressee( const Iterator &it )
500{ 559{
501 d->mRemovedAddressees.append( (*it) ); 560 d->mRemovedAddressees.append( (*it) );
502 d->mAddressees.remove( it.d->mIt ); 561 d->mAddressees.remove( it.d->mIt );
503} 562}
504 563
505AddressBook::Iterator AddressBook::find( const Addressee &a ) 564AddressBook::Iterator AddressBook::find( const Addressee &a )
506{ 565{
507 Iterator it; 566 Iterator it;
508 for ( it = begin(); it != end(); ++it ) { 567 for ( it = begin(); it != end(); ++it ) {
509 if ( a.uid() == (*it).uid() ) { 568 if ( a.uid() == (*it).uid() ) {
510 return it; 569 return it;
511 } 570 }
512 } 571 }
513 return end(); 572 return end();
514} 573}
515 574
516Addressee AddressBook::findByUid( const QString &uid ) 575Addressee AddressBook::findByUid( const QString &uid )
517{ 576{
518 Iterator it; 577 Iterator it;
519 for ( it = begin(); it != end(); ++it ) { 578 for ( it = begin(); it != end(); ++it ) {
520 if ( uid == (*it).uid() ) { 579 if ( uid == (*it).uid() ) {
521 return *it; 580 return *it;
522 } 581 }
523 } 582 }
524 return Addressee(); 583 return Addressee();
525} 584}
585#if 0
526Addressee::List AddressBook::getExternLastSyncAddressees() 586Addressee::List AddressBook::getExternLastSyncAddressees()
527{ 587{
528 Addressee::List results; 588 Addressee::List results;
529 589
530 Iterator it; 590 Iterator it;
531 for ( it = begin(); it != end(); ++it ) { 591 for ( it = begin(); it != end(); ++it ) {
532 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
533 if ( (*it).familyName().left(3) == "E: " ) 593 if ( (*it).familyName().left(4) == "!E: " )
534 results.append( *it ); 594 results.append( *it );
535 } 595 }
536 } 596 }
537 597
538 return results; 598 return results;
539} 599}
600#endif
540void AddressBook::resetTempSyncStat() 601void AddressBook::resetTempSyncStat()
541{ 602{
542 Iterator it; 603 Iterator it;
543 for ( it = begin(); it != end(); ++it ) { 604 for ( it = begin(); it != end(); ++it ) {
544 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 605 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
545 } 606 }
546 607
547} 608}
548 609
549QStringList AddressBook:: uidList() 610QStringList AddressBook:: uidList()
550{ 611{
551 QStringList results; 612 QStringList results;
552 Iterator it; 613 Iterator it;
553 for ( it = begin(); it != end(); ++it ) { 614 for ( it = begin(); it != end(); ++it ) {
554 results.append( (*it).uid() ); 615 results.append( (*it).uid() );
555 } 616 }
556 return results; 617 return results;
557} 618}
558 619
559 620
560Addressee::List AddressBook::allAddressees() 621Addressee::List AddressBook::allAddressees()
561{ 622{
562 return d->mAddressees; 623 return d->mAddressees;
563 624
564} 625}
565 626
566Addressee::List AddressBook::findByName( const QString &name ) 627Addressee::List AddressBook::findByName( const QString &name )
567{ 628{
568 Addressee::List results; 629 Addressee::List results;
569 630
570 Iterator it; 631 Iterator it;
571 for ( it = begin(); it != end(); ++it ) { 632 for ( it = begin(); it != end(); ++it ) {
572 if ( name == (*it).realName() ) { 633 if ( name == (*it).realName() ) {
573 results.append( *it ); 634 results.append( *it );
574 } 635 }
575 } 636 }
576 637
577 return results; 638 return results;
578} 639}
579 640
580Addressee::List AddressBook::findByEmail( const QString &email ) 641Addressee::List AddressBook::findByEmail( const QString &email )
581{ 642{
582 Addressee::List results; 643 Addressee::List results;
583 QStringList mailList; 644 QStringList mailList;
584 645
585 Iterator it; 646 Iterator it;
586 for ( it = begin(); it != end(); ++it ) { 647 for ( it = begin(); it != end(); ++it ) {
587 mailList = (*it).emails(); 648 mailList = (*it).emails();
588 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 649 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
589 if ( email == (*ite) ) { 650 if ( email == (*ite) ) {
590 results.append( *it ); 651 results.append( *it );
591 } 652 }
592 } 653 }
593 } 654 }
594 655
595 return results; 656 return results;
596} 657}
597 658
598Addressee::List AddressBook::findByCategory( const QString &category ) 659Addressee::List AddressBook::findByCategory( const QString &category )
599{ 660{
600 Addressee::List results; 661 Addressee::List results;
601 662
602 Iterator it; 663 Iterator it;
603 for ( it = begin(); it != end(); ++it ) { 664 for ( it = begin(); it != end(); ++it ) {
604 if ( (*it).hasCategory( category) ) { 665 if ( (*it).hasCategory( category) ) {
605 results.append( *it ); 666 results.append( *it );
606 } 667 }
607 } 668 }
608 669
609 return results; 670 return results;
610} 671}
611 672
612void AddressBook::dump() const 673void AddressBook::dump() const
613{ 674{
614 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 675 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
615 676
616 ConstIterator it; 677 ConstIterator it;
617 for( it = begin(); it != end(); ++it ) { 678 for( it = begin(); it != end(); ++it ) {
618 (*it).dump(); 679 (*it).dump();
619 } 680 }
620 681
621 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 682 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
622} 683}
623 684
624QString AddressBook::identifier() 685QString AddressBook::identifier()
625{ 686{
626 QStringList identifier; 687 QStringList identifier;
627 688
628 689
629 KRES::Manager<Resource>::ActiveIterator it; 690 KRES::Manager<Resource>::ActiveIterator it;
630 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 691 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
631 if ( !(*it)->identifier().isEmpty() ) 692 if ( !(*it)->identifier().isEmpty() )
632 identifier.append( (*it)->identifier() ); 693 identifier.append( (*it)->identifier() );
633 } 694 }
634 695
635 return identifier.join( ":" ); 696 return identifier.join( ":" );
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 253de68..2f2678b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -196,139 +196,141 @@ class AddressBook : public QObject
196 Find the entry specified by an unique id. Returns an empty Addressee 196 Find the entry specified by an unique id. Returns an empty Addressee
197 object, if the address book does not contain an entry with this id. 197 object, if the address book does not contain an entry with this id.
198 */ 198 */
199 Addressee findByUid( const QString & ); 199 Addressee findByUid( const QString & );
200 200
201 201
202 /** 202 /**
203 Returns a list of all addressees in the address book. This list can 203 Returns a list of all addressees in the address book. This list can
204 be sorted with @ref KABC::AddresseeList for example. 204 be sorted with @ref KABC::AddresseeList for example.
205 */ 205 */
206 Addressee::List allAddressees(); 206 Addressee::List allAddressees();
207 207
208 /** 208 /**
209 Find all entries with the specified name in the address book. Returns 209 Find all entries with the specified name in the address book. Returns
210 an empty list, if no entries could be found. 210 an empty list, if no entries could be found.
211 */ 211 */
212 Addressee::List findByName( const QString & ); 212 Addressee::List findByName( const QString & );
213 213
214 /** 214 /**
215 Find all entries with the specified email address in the address book. 215 Find all entries with the specified email address in the address book.
216 Returns an empty list, if no entries could be found. 216 Returns an empty list, if no entries could be found.
217 */ 217 */
218 Addressee::List findByEmail( const QString & ); 218 Addressee::List findByEmail( const QString & );
219 219
220 /** 220 /**
221 Find all entries wich have the specified category in the address book. 221 Find all entries wich have the specified category in the address book.
222 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
223 */ 223 */
224 Addressee::List findByCategory( const QString & ); 224 Addressee::List findByCategory( const QString & );
225 225
226 /** 226 /**
227 Return a string identifying this addressbook. 227 Return a string identifying this addressbook.
228 */ 228 */
229 virtual QString identifier(); 229 virtual QString identifier();
230 230
231 /** 231 /**
232 Used for debug output. 232 Used for debug output.
233 */ 233 */
234 void dump() const; 234 void dump() const;
235 235
236 void emitAddressBookLocked() { emit addressBookLocked( this ); } 236 void emitAddressBookLocked() { emit addressBookLocked( this ); }
237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
238 void emitAddressBookChanged() { emit addressBookChanged( this ); } 238 void emitAddressBookChanged() { emit addressBookChanged( this ); }
239 239
240 /** 240 /**
241 Return list of all Fields known to the address book which are associated 241 Return list of all Fields known to the address book which are associated
242 with the given field category. 242 with the given field category.
243 */ 243 */
244 Field::List fields( int category = Field::All ); 244 Field::List fields( int category = Field::All );
245 245
246 /** 246 /**
247 Add custom field to address book. 247 Add custom field to address book.
248 248
249 @param label User visible label of the field. 249 @param label User visible label of the field.
250 @param category Ored list of field categories. 250 @param category Ored list of field categories.
251 @param key Identifier used as key for reading and writing the field. 251 @param key Identifier used as key for reading and writing the field.
252 @param app String used as application key for reading and writing 252 @param app String used as application key for reading and writing
253 the field. 253 the field.
254 */ 254 */
255 bool addCustomField( const QString &label, int category = Field::All, 255 bool addCustomField( const QString &label, int category = Field::All,
256 const QString &key = QString::null, 256 const QString &key = QString::null,
257 const QString &app = QString::null ); 257 const QString &app = QString::null );
258 258
259 259
260 /** 260 /**
261 Add address book resource. 261 Add address book resource.
262 */ 262 */
263 bool addResource( Resource * ); 263 bool addResource( Resource * );
264 264
265 /** 265 /**
266 Remove address book resource. 266 Remove address book resource.
267 */ 267 */
268 bool removeResource( Resource * ); 268 bool removeResource( Resource * );
269 269
270 /** 270 /**
271 Return pointer list of all resources. 271 Return pointer list of all resources.
272 */ 272 */
273 QPtrList<Resource> resources(); 273 QPtrList<Resource> resources();
274 274
275 /** 275 /**
276 Set the @p ErrorHandler, that is used by @ref error() to 276 Set the @p ErrorHandler, that is used by @ref error() to
277 provide gui-independend error messages. 277 provide gui-independend error messages.
278 */ 278 */
279 void setErrorHandler( ErrorHandler * ); 279 void setErrorHandler( ErrorHandler * );
280 280
281 /** 281 /**
282 Shows gui independend error messages. 282 Shows gui independend error messages.
283 */ 283 */
284 void error( const QString& ); 284 void error( const QString& );
285 285
286 /** 286 /**
287 Query all resources to clean up their lock files 287 Query all resources to clean up their lock files
288 */ 288 */
289 void cleanUp(); 289 void cleanUp();
290 290
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 //Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees();
295 296
296 297
297 signals: 298 signals:
298 /** 299 /**
299 Emitted, when the address book has changed on disk. 300 Emitted, when the address book has changed on disk.
300 */ 301 */
301 void addressBookChanged( AddressBook * ); 302 void addressBookChanged( AddressBook * );
302 303
303 /** 304 /**
304 Emitted, when the address book has been locked for writing. 305 Emitted, when the address book has been locked for writing.
305 */ 306 */
306 void addressBookLocked( AddressBook * ); 307 void addressBookLocked( AddressBook * );
307 308
308 /** 309 /**
309 Emitted, when the address book has been unlocked. 310 Emitted, when the address book has been unlocked.
310 */ 311 */
311 void addressBookUnlocked( AddressBook * ); 312 void addressBookUnlocked( AddressBook * );
312 313
313 protected: 314 protected:
314 void deleteRemovedAddressees(); 315 void deleteRemovedAddressees();
315 void setStandardResource( Resource * ); 316 void setStandardResource( Resource * );
316 Resource *standardResource(); 317 Resource *standardResource();
317 KRES::Manager<Resource> *resourceManager(); 318 KRES::Manager<Resource> *resourceManager();
318 319
319 void init(const QString &config, const QString &family); 320 void init(const QString &config, const QString &family);
320 321
321 private: 322 private:
322//US QPtrList<Resource> mDummy; // Remove in KDE 4 323//US QPtrList<Resource> mDummy; // Remove in KDE 4
323 324
324 325
325 struct AddressBookData; 326 struct AddressBookData;
326 AddressBookData *d; 327 AddressBookData *d;
328 bool blockLSEchange;
327}; 329};
328 330
329QDataStream &operator<<( QDataStream &, const AddressBook & ); 331QDataStream &operator<<( QDataStream &, const AddressBook & );
330QDataStream &operator>>( QDataStream &, AddressBook & ); 332QDataStream &operator>>( QDataStream &, AddressBook & );
331 333
332} 334}
333 335
334#endif 336#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7f04d8f..0f5d605 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -81,192 +81,288 @@ struct Addressee::AddresseeData : public KShared
81 QStringList custom; 81 QStringList custom;
82 82
83 Resource *resource; 83 Resource *resource;
84 84
85 bool empty :1; 85 bool empty :1;
86 bool changed :1; 86 bool changed :1;
87}; 87};
88 88
89Addressee::Addressee() 89Addressee::Addressee()
90{ 90{
91 mData = new AddresseeData; 91 mData = new AddresseeData;
92 mData->empty = true; 92 mData->empty = true;
93 mData->changed = false; 93 mData->changed = false;
94 mData->resource = 0; 94 mData->resource = 0;
95 mData->mExternalId = ":"; 95 mData->mExternalId = ":";
96 mData->revision = QDateTime ( QDate( 2004,1,1)); 96 mData->revision = QDateTime ( QDate( 2004,1,1));
97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
98} 98}
99 99
100Addressee::~Addressee() 100Addressee::~Addressee()
101{ 101{
102} 102}
103 103
104Addressee::Addressee( const Addressee &a ) 104Addressee::Addressee( const Addressee &a )
105{ 105{
106 mData = a.mData; 106 mData = a.mData;
107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
108} 108}
109 109
110Addressee &Addressee::operator=( const Addressee &a ) 110Addressee &Addressee::operator=( const Addressee &a )
111{ 111{
112 mData = a.mData; 112 mData = a.mData;
113 return (*this); 113 return (*this);
114} 114}
115 115
116Addressee Addressee::copy() 116Addressee Addressee::copy()
117{ 117{
118 Addressee a; 118 Addressee a;
119 *(a.mData) = *mData; 119 *(a.mData) = *mData;
120 return a; 120 return a;
121} 121}
122 122
123void Addressee::detach() 123void Addressee::detach()
124{ 124{
125 if ( mData.count() == 1 ) return; 125 if ( mData.count() == 1 ) return;
126 *this = copy(); 126 *this = copy();
127} 127}
128 128
129bool Addressee::operator==( const Addressee &a ) const 129bool Addressee::operator==( const Addressee &a ) const
130{ 130{
131 if ( uid() != a.uid() ) return false; 131 if ( uid() != a.uid() ) return false;
132 if ( mData->name != a.mData->name ) return false; 132 if ( mData->name != a.mData->name ) return false;
133 if ( mData->formattedName != a.mData->formattedName ) return false; 133 if ( mData->formattedName != a.mData->formattedName ) return false;
134 if ( mData->familyName != a.mData->familyName ) return false; 134 if ( mData->familyName != a.mData->familyName ) return false;
135 if ( mData->givenName != a.mData->givenName ) return false; 135 if ( mData->givenName != a.mData->givenName ) return false;
136 if ( mData->additionalName != a.mData->additionalName ) return false; 136 if ( mData->additionalName != a.mData->additionalName ) return false;
137 if ( mData->prefix != a.mData->prefix ) return false; 137 if ( mData->prefix != a.mData->prefix ) return false;
138 if ( mData->suffix != a.mData->suffix ) return false; 138 if ( mData->suffix != a.mData->suffix ) return false;
139 if ( mData->nickName != a.mData->nickName ) return false; 139 if ( mData->nickName != a.mData->nickName ) return false;
140 if ( mData->birthday != a.mData->birthday ) return false; 140 if ( mData->birthday != a.mData->birthday ) return false;
141 if ( mData->mailer != a.mData->mailer ) return false; 141 if ( mData->mailer != a.mData->mailer ) return false;
142 if ( mData->timeZone != a.mData->timeZone ) return false; 142 if ( mData->timeZone != a.mData->timeZone ) return false;
143 if ( mData->geo != a.mData->geo ) return false; 143 if ( mData->geo != a.mData->geo ) return false;
144 if ( mData->title != a.mData->title ) return false; 144 if ( mData->title != a.mData->title ) return false;
145 if ( mData->role != a.mData->role ) return false; 145 if ( mData->role != a.mData->role ) return false;
146 if ( mData->organization != a.mData->organization ) return false; 146 if ( mData->organization != a.mData->organization ) return false;
147 if ( mData->note != a.mData->note ) return false; 147 if ( mData->note != a.mData->note ) return false;
148 if ( mData->productId != a.mData->productId ) return false; 148 if ( mData->productId != a.mData->productId ) return false;
149 if ( mData->revision != a.mData->revision ) return false; 149 if ( mData->revision != a.mData->revision ) return false;
150 if ( mData->sortString != a.mData->sortString ) return false; 150 if ( mData->sortString != a.mData->sortString ) return false;
151 if ( mData->secrecy != a.mData->secrecy ) return false; 151 if ( mData->secrecy != a.mData->secrecy ) return false;
152 if ( mData->logo != a.mData->logo ) return false; 152 if ( mData->logo != a.mData->logo ) return false;
153 if ( mData->photo != a.mData->photo ) return false; 153 if ( mData->photo != a.mData->photo ) return false;
154 if ( mData->sound != a.mData->sound ) return false; 154 if ( mData->sound != a.mData->sound ) return false;
155 if ( mData->agent != a.mData->agent ) return false; 155 if ( mData->agent != a.mData->agent ) return false;
156 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 156 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
157 ( mData->url != a.mData->url ) ) return false; 157 ( mData->url != a.mData->url ) ) return false;
158 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 158 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
159 if ( mData->addresses != a.mData->addresses ) return false; 159 if ( mData->addresses != a.mData->addresses ) return false;
160 if ( mData->keys != a.mData->keys ) return false; 160 if ( mData->keys != a.mData->keys ) return false;
161 if ( mData->emails != a.mData->emails ) return false; 161 if ( mData->emails != a.mData->emails ) return false;
162 if ( mData->categories != a.mData->categories ) return false; 162 if ( mData->categories != a.mData->categories ) return false;
163 if ( mData->custom != a.mData->custom ) return false; 163 if ( mData->custom != a.mData->custom ) return false;
164 164
165 return true; 165 return true;
166} 166}
167 167
168bool Addressee::operator!=( const Addressee &a ) const 168bool Addressee::operator!=( const Addressee &a ) const
169{ 169{
170 return !( a == *this ); 170 return !( a == *this );
171} 171}
172 172
173bool Addressee::isEmpty() const 173bool Addressee::isEmpty() const
174{ 174{
175 return mData->empty; 175 return mData->empty;
176} 176}
177ulong Addressee::getCsum4List( const QStringList & attList)
178{
179 int max = attList.count();
180 ulong cSum = 0;
181 int j,k,i;
182 int add;
183 for ( i = 0; i < max ; ++i ) {
184 QString s = attList[i];
185 if ( ! s.isEmpty() ){
186 j = s.length();
187 for ( k = 0; k < j; ++k ) {
188 int mul = k +1;
189 add = s[k].unicode ();
190 if ( k < 16 )
191 mul = mul * mul;
192 int ii = i+1;
193 add = add * mul *ii*ii*ii;
194 cSum += add;
195 }
196 }
197
198 }
199 //QString dump = attList.join(",");
200 //qDebug("csum: %d %s", cSum,dump.latin1());
201
202 return cSum;
203
204}
205void Addressee::computeCsum(const QString &dev)
206{
207 QStringList l;
208 if ( !mData->name.isEmpty() ) l.append(mData->name);
209 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
210 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
211 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
212 if ( !mData->additionalName ) l.append( mData->additionalName );
213 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
214 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
215 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
216 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
217 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
218 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
219 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
220 if ( !mData->title .isEmpty() ) l.append( mData->title );
221 if ( !mData->role.isEmpty() ) l.append( mData->role );
222 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
223 if ( !mData->note.isEmpty() ) l.append( mData->note );
224 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
225 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
226 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
227 // if ( !mData->logo.isEmpty() ) l.append( );
228 //if ( !mData->photo.isEmpty() ) l.append( );
229 //if ( !mData->sound.isEmpty() ) l.append( );
230 //if ( !mData->agent.isEmpty() ) l.append( );
231 //if ( mData->url.isValid() ) l.append( );
232#if 0
233 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
234 if ( !mData->addresses.isEmpty() ) l.append( );
235 //if ( !mData->keys.isEmpty() ) l.append( );
236 if ( !mData->emails.isEmpty() ) l.append( );
237 if ( !mData->categories .isEmpty() ) l.append( );
238 if ( !mData->custom.isEmpty() ) l.append( );
239#endif
240 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter;
242
243 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort();
248 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] );
251 t = mData->emails;
252 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] );
255 t = mData->categories;
256 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] );
259 t = mData->custom;
260 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) {
266 t = (*addressIter).asList();
267 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] );
270 }
271 setCsum( dev, QString::number (getCsum4List(l)) );
272}
177void Addressee::removeID(const QString &prof) 273void Addressee::removeID(const QString &prof)
178{ 274{
179 detach(); 275 detach();
180 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 276 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
181 277
182} 278}
183void Addressee::setID( const QString & prof , const QString & id ) 279void Addressee::setID( const QString & prof , const QString & id )
184{ 280{
185 detach(); 281 detach();
186 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 282 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
187} 283}
188void Addressee::setTempSyncStat( int id ) 284void Addressee::setTempSyncStat( int id )
189{ 285{
190 mTempSyncStat = id; 286 mTempSyncStat = id;
191} 287}
192int Addressee::tempSyncStat() const 288int Addressee::tempSyncStat() const
193{ 289{
194 return mTempSyncStat; 290 return mTempSyncStat;
195} 291}
196 292
197QString Addressee::getID( const QString & prof) 293QString Addressee::getID( const QString & prof)
198{ 294{
199 return KIdManager::getId ( mData->mExternalId, prof ); 295 return KIdManager::getId ( mData->mExternalId, prof );
200} 296}
201 297
202void Addressee::setCsum( const QString & prof , const QString & id ) 298void Addressee::setCsum( const QString & prof , const QString & id )
203{ 299{
204 detach(); 300 detach();
205 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 301 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
206} 302}
207 303
208QString Addressee::getCsum( const QString & prof) 304QString Addressee::getCsum( const QString & prof)
209{ 305{
210 return KIdManager::getCsum ( mData->mExternalId, prof ); 306 return KIdManager::getCsum ( mData->mExternalId, prof );
211} 307}
212 308
213void Addressee::setIDStr( const QString & s ) 309void Addressee::setIDStr( const QString & s )
214{ 310{
215 detach(); 311 detach();
216 mData->mExternalId = s; 312 mData->mExternalId = s;
217} 313}
218 314
219QString Addressee::IDStr() const 315QString Addressee::IDStr() const
220{ 316{
221 return mData->mExternalId; 317 return mData->mExternalId;
222} 318}
223 319
224 320
225void Addressee::setUid( const QString &id ) 321void Addressee::setUid( const QString &id )
226{ 322{
227 if ( id == mData->uid ) return; 323 if ( id == mData->uid ) return;
228 detach(); 324 detach();
229 mData->empty = false; 325 mData->empty = false;
230 mData->uid = id; 326 mData->uid = id;
231} 327}
232 328
233QString Addressee::uid() const 329QString Addressee::uid() const
234{ 330{
235 if ( mData->uid.isEmpty() ) 331 if ( mData->uid.isEmpty() )
236 mData->uid = KApplication::randomString( 10 ); 332 mData->uid = KApplication::randomString( 10 );
237 333
238 return mData->uid; 334 return mData->uid;
239} 335}
240 336
241QString Addressee::uidLabel() 337QString Addressee::uidLabel()
242{ 338{
243 return i18n("Unique Identifier"); 339 return i18n("Unique Identifier");
244} 340}
245 341
246void Addressee::setName( const QString &name ) 342void Addressee::setName( const QString &name )
247{ 343{
248 if ( name == mData->name ) return; 344 if ( name == mData->name ) return;
249 detach(); 345 detach();
250 mData->empty = false; 346 mData->empty = false;
251 mData->name = name; 347 mData->name = name;
252} 348}
253 349
254QString Addressee::name() const 350QString Addressee::name() const
255{ 351{
256 return mData->name; 352 return mData->name;
257} 353}
258 354
259QString Addressee::nameLabel() 355QString Addressee::nameLabel()
260{ 356{
261 return i18n("Name"); 357 return i18n("Name");
262} 358}
263 359
264 360
265void Addressee::setFormattedName( const QString &formattedName ) 361void Addressee::setFormattedName( const QString &formattedName )
266{ 362{
267 if ( formattedName == mData->formattedName ) return; 363 if ( formattedName == mData->formattedName ) return;
268 detach(); 364 detach();
269 mData->empty = false; 365 mData->empty = false;
270 mData->formattedName = formattedName; 366 mData->formattedName = formattedName;
271} 367}
272 368
@@ -1357,197 +1453,196 @@ Address Addressee::address( int type ) const
1357{ 1453{
1358 Address address( type ); 1454 Address address( type );
1359 Address::List::ConstIterator it; 1455 Address::List::ConstIterator it;
1360 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1361 if ( matchBinaryPattern( (*it).type(), type ) ) { 1457 if ( matchBinaryPattern( (*it).type(), type ) ) {
1362 if ( (*it).type() & Address::Pref ) 1458 if ( (*it).type() & Address::Pref )
1363 return (*it); 1459 return (*it);
1364 else if ( address.isEmpty() ) 1460 else if ( address.isEmpty() )
1365 address = (*it); 1461 address = (*it);
1366 } 1462 }
1367 } 1463 }
1368 1464
1369 return address; 1465 return address;
1370} 1466}
1371 1467
1372Address::List Addressee::addresses() const 1468Address::List Addressee::addresses() const
1373{ 1469{
1374 return mData->addresses; 1470 return mData->addresses;
1375} 1471}
1376 1472
1377Address::List Addressee::addresses( int type ) const 1473Address::List Addressee::addresses( int type ) const
1378{ 1474{
1379 Address::List list; 1475 Address::List list;
1380 1476
1381 Address::List::ConstIterator it; 1477 Address::List::ConstIterator it;
1382 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1478 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1383 if ( matchBinaryPattern( (*it).type(), type ) ) { 1479 if ( matchBinaryPattern( (*it).type(), type ) ) {
1384 list.append( *it ); 1480 list.append( *it );
1385 } 1481 }
1386 } 1482 }
1387 1483
1388 return list; 1484 return list;
1389} 1485}
1390 1486
1391Address Addressee::findAddress( const QString &id ) const 1487Address Addressee::findAddress( const QString &id ) const
1392{ 1488{
1393 Address::List::ConstIterator it; 1489 Address::List::ConstIterator it;
1394 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1490 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1395 if ( (*it).id() == id ) { 1491 if ( (*it).id() == id ) {
1396 return *it; 1492 return *it;
1397 } 1493 }
1398 } 1494 }
1399 return Address(); 1495 return Address();
1400} 1496}
1401 1497
1402void Addressee::insertCategory( const QString &c ) 1498void Addressee::insertCategory( const QString &c )
1403{ 1499{
1404 detach(); 1500 detach();
1405 mData->empty = false; 1501 mData->empty = false;
1406 1502
1407 if ( mData->categories.contains( c ) ) return; 1503 if ( mData->categories.contains( c ) ) return;
1408 1504
1409 mData->categories.append( c ); 1505 mData->categories.append( c );
1410} 1506}
1411 1507
1412void Addressee::removeCategory( const QString &c ) 1508void Addressee::removeCategory( const QString &c )
1413{ 1509{
1414 detach(); 1510 detach();
1415 1511
1416 QStringList::Iterator it = mData->categories.find( c ); 1512 QStringList::Iterator it = mData->categories.find( c );
1417 if ( it == mData->categories.end() ) return; 1513 if ( it == mData->categories.end() ) return;
1418 1514
1419 mData->categories.remove( it ); 1515 mData->categories.remove( it );
1420} 1516}
1421 1517
1422bool Addressee::hasCategory( const QString &c ) const 1518bool Addressee::hasCategory( const QString &c ) const
1423{ 1519{
1424 return ( mData->categories.contains( c ) ); 1520 return ( mData->categories.contains( c ) );
1425} 1521}
1426 1522
1427void Addressee::setCategories( const QStringList &c ) 1523void Addressee::setCategories( const QStringList &c )
1428{ 1524{
1429 detach(); 1525 detach();
1430 mData->empty = false; 1526 mData->empty = false;
1431 1527
1432 mData->categories = c; 1528 mData->categories = c;
1433} 1529}
1434 1530
1435QStringList Addressee::categories() const 1531QStringList Addressee::categories() const
1436{ 1532{
1437 return mData->categories; 1533 return mData->categories;
1438} 1534}
1439 1535
1440void Addressee::insertCustom( const QString &app, const QString &name, 1536void Addressee::insertCustom( const QString &app, const QString &name,
1441 const QString &value ) 1537 const QString &value )
1442{ 1538{
1443 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1539 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1444 1540
1445 detach(); 1541 detach();
1446 mData->empty = false; 1542 mData->empty = false;
1447 1543
1448 QString qualifiedName = app + "-" + name + ":"; 1544 QString qualifiedName = app + "-" + name + ":";
1449 1545
1450 QStringList::Iterator it; 1546 QStringList::Iterator it;
1451 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1547 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1452 if ( (*it).startsWith( qualifiedName ) ) { 1548 if ( (*it).startsWith( qualifiedName ) ) {
1453 (*it) = qualifiedName + value; 1549 (*it) = qualifiedName + value;
1454 return; 1550 return;
1455 } 1551 }
1456 } 1552 }
1457
1458 mData->custom.append( qualifiedName + value ); 1553 mData->custom.append( qualifiedName + value );
1459} 1554}
1460 1555
1461void Addressee::removeCustom( const QString &app, const QString &name) 1556void Addressee::removeCustom( const QString &app, const QString &name)
1462{ 1557{
1463 detach(); 1558 detach();
1464 1559
1465 QString qualifiedName = app + "-" + name + ":"; 1560 QString qualifiedName = app + "-" + name + ":";
1466 1561
1467 QStringList::Iterator it; 1562 QStringList::Iterator it;
1468 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1563 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1469 if ( (*it).startsWith( qualifiedName ) ) { 1564 if ( (*it).startsWith( qualifiedName ) ) {
1470 mData->custom.remove( it ); 1565 mData->custom.remove( it );
1471 return; 1566 return;
1472 } 1567 }
1473 } 1568 }
1474} 1569}
1475 1570
1476QString Addressee::custom( const QString &app, const QString &name ) const 1571QString Addressee::custom( const QString &app, const QString &name ) const
1477{ 1572{
1478 QString qualifiedName = app + "-" + name + ":"; 1573 QString qualifiedName = app + "-" + name + ":";
1479 QString value; 1574 QString value;
1480 1575
1481 QStringList::ConstIterator it; 1576 QStringList::ConstIterator it;
1482 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1577 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1483 if ( (*it).startsWith( qualifiedName ) ) { 1578 if ( (*it).startsWith( qualifiedName ) ) {
1484 value = (*it).mid( (*it).find( ":" ) + 1 ); 1579 value = (*it).mid( (*it).find( ":" ) + 1 );
1485 break; 1580 break;
1486 } 1581 }
1487 } 1582 }
1488 1583
1489 return value; 1584 return value;
1490} 1585}
1491 1586
1492void Addressee::setCustoms( const QStringList &l ) 1587void Addressee::setCustoms( const QStringList &l )
1493{ 1588{
1494 detach(); 1589 detach();
1495 mData->empty = false; 1590 mData->empty = false;
1496 1591
1497 mData->custom = l; 1592 mData->custom = l;
1498} 1593}
1499 1594
1500QStringList Addressee::customs() const 1595QStringList Addressee::customs() const
1501{ 1596{
1502 return mData->custom; 1597 return mData->custom;
1503} 1598}
1504 1599
1505void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1600void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1506 QString &email) 1601 QString &email)
1507{ 1602{
1508 int startPos, endPos, len; 1603 int startPos, endPos, len;
1509 QString partA, partB, result; 1604 QString partA, partB, result;
1510 char endCh = '>'; 1605 char endCh = '>';
1511 1606
1512 startPos = rawEmail.find('<'); 1607 startPos = rawEmail.find('<');
1513 if (startPos < 0) 1608 if (startPos < 0)
1514 { 1609 {
1515 startPos = rawEmail.find('('); 1610 startPos = rawEmail.find('(');
1516 endCh = ')'; 1611 endCh = ')';
1517 } 1612 }
1518 if (startPos < 0) 1613 if (startPos < 0)
1519 { 1614 {
1520 // We couldn't find any separators, so we assume the whole string 1615 // We couldn't find any separators, so we assume the whole string
1521 // is the email address 1616 // is the email address
1522 email = rawEmail; 1617 email = rawEmail;
1523 fullName = ""; 1618 fullName = "";
1524 } 1619 }
1525 else 1620 else
1526 { 1621 {
1527 // We have a start position, try to find an end 1622 // We have a start position, try to find an end
1528 endPos = rawEmail.find(endCh, startPos+1); 1623 endPos = rawEmail.find(endCh, startPos+1);
1529 1624
1530 if (endPos < 0) 1625 if (endPos < 0)
1531 { 1626 {
1532 // We couldn't find the end of the email address. We can only 1627 // We couldn't find the end of the email address. We can only
1533 // assume the entire string is the email address. 1628 // assume the entire string is the email address.
1534 email = rawEmail; 1629 email = rawEmail;
1535 fullName = ""; 1630 fullName = "";
1536 } 1631 }
1537 else 1632 else
1538 { 1633 {
1539 // We have a start and end to the email address 1634 // We have a start and end to the email address
1540 1635
1541 // Grab the name part 1636 // Grab the name part
1542 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1637 fullName = rawEmail.left(startPos).stripWhiteSpace();
1543 1638
1544 // grab the email part 1639 // grab the email part
1545 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1640 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1546 1641
1547 // Check that we do not have any extra characters on the end of the 1642 // Check that we do not have any extra characters on the end of the
1548 // strings 1643 // strings
1549 len = fullName.length(); 1644 len = fullName.length();
1550 if (fullName[0]=='"' && fullName[len-1]=='"') 1645 if (fullName[0]=='"' && fullName[len-1]=='"')
1551 fullName = fullName.mid(1, len-2); 1646 fullName = fullName.mid(1, len-2);
1552 else if (fullName[0]=='<' && fullName[len-1]=='>') 1647 else if (fullName[0]=='<' && fullName[len-1]=='>')
1553 fullName = fullName.mid(1, len-2); 1648 fullName = fullName.mid(1, len-2);
diff --git a/kabc/addressee.h b/kabc/addressee.h
index f098371..0805458 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -13,192 +13,194 @@
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#ifndef KABC_ADDRESSEE_H 29#ifndef KABC_ADDRESSEE_H
30#define KABC_ADDRESSEE_H 30#define KABC_ADDRESSEE_H
31 31
32#include <qdatetime.h> 32#include <qdatetime.h>
33#include <qstring.h> 33#include <qstring.h>
34#include <qstringlist.h> 34#include <qstringlist.h>
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36 36
37#include <ksharedptr.h> 37#include <ksharedptr.h>
38#include <kurl.h> 38#include <kurl.h>
39 39
40#include "address.h" 40#include "address.h"
41#include "agent.h" 41#include "agent.h"
42#include "geo.h" 42#include "geo.h"
43#include "key.h" 43#include "key.h"
44#include "phonenumber.h" 44#include "phonenumber.h"
45#include "picture.h" 45#include "picture.h"
46#include "secrecy.h" 46#include "secrecy.h"
47#include "sound.h" 47#include "sound.h"
48#include "timezone.h" 48#include "timezone.h"
49 49
50namespace KABC { 50namespace KABC {
51 51
52class Resource; 52class Resource;
53 53
54/** 54/**
55 @short address book entry 55 @short address book entry
56 56
57 This class represents an entry in the address book. 57 This class represents an entry in the address book.
58 58
59 The data of this class is implicitly shared. You can pass this class by value. 59 The data of this class is implicitly shared. You can pass this class by value.
60 60
61 If you need the name of a field for presenting it to the user you should use 61 If you need the name of a field for presenting it to the user you should use
62 the functions ending in Label(). They return a translated string which can be 62 the functions ending in Label(). They return a translated string which can be
63 used as label for the corresponding field. 63 used as label for the corresponding field.
64 64
65 About the name fields: 65 About the name fields:
66 66
67 givenName() is the first name and familyName() the last name. In some 67 givenName() is the first name and familyName() the last name. In some
68 countries the family name comes first, that's the reason for the 68 countries the family name comes first, that's the reason for the
69 naming. formattedName() is the full name with the correct formatting. 69 naming. formattedName() is the full name with the correct formatting.
70 It is used as an override, when the correct formatting can't be generated 70 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically. 71 from the other name fields automatically.
72 72
73 realName() returns a fully formatted name(). It uses formattedName, if set, 73 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if 74 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name(). 75 nothing else is set it uses name().
76 76
77 name() is the NAME type of RFC2426. It can be used as internal name for the 77 name() is the NAME type of RFC2426. It can be used as internal name for the
78 data enty, but shouldn't be used for displaying the data to the user. 78 data enty, but shouldn't be used for displaying the data to the user.
79 */ 79 */
80class Addressee 80class Addressee
81{ 81{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & ); 82 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & ); 83 friend QDataStream &operator>>( QDataStream &, Addressee & );
84 84
85 public: 85 public:
86 typedef QValueList<Addressee> List; 86 typedef QValueList<Addressee> List;
87 87
88 /** 88 /**
89 Construct an empty address book entry. 89 Construct an empty address book entry.
90 */ 90 */
91 Addressee(); 91 Addressee();
92 ~Addressee(); 92 ~Addressee();
93 93
94 Addressee( const Addressee & ); 94 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & ); 95 Addressee &operator=( const Addressee & );
96 96
97 bool operator==( const Addressee & ) const; 97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 98 bool operator!=( const Addressee & ) const;
99 // sync stuff 99 // sync stuff
100 void setTempSyncStat(int id); 100 void setTempSyncStat(int id);
101 int tempSyncStat() const; 101 int tempSyncStat() const;
102 void setIDStr( const QString & ); 102 void setIDStr( const QString & );
103 QString IDStr() const; 103 QString IDStr() const;
104 void setID( const QString &, const QString & ); 104 void setID( const QString &, const QString & );
105 QString getID( const QString & ); 105 QString getID( const QString & );
106 void setCsum( const QString &, const QString & ); 106 void setCsum( const QString &, const QString & );
107 QString getCsum( const QString & ); 107 QString getCsum( const QString & );
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList);
109 /** 111 /**
110 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
111 */ 113 */
112 bool isEmpty() const; 114 bool isEmpty() const;
113 115
114 /** 116 /**
115 Set unique identifier. 117 Set unique identifier.
116 */ 118 */
117 void setUid( const QString &uid ); 119 void setUid( const QString &uid );
118 /** 120 /**
119 Return unique identifier. 121 Return unique identifier.
120 */ 122 */
121 QString uid() const; 123 QString uid() const;
122 /** 124 /**
123 Return translated label for uid field. 125 Return translated label for uid field.
124 */ 126 */
125 static QString uidLabel(); 127 static QString uidLabel();
126 128
127 /** 129 /**
128 Set name. 130 Set name.
129 */ 131 */
130 void setName( const QString &name ); 132 void setName( const QString &name );
131 /** 133 /**
132 Return name. 134 Return name.
133 */ 135 */
134 QString name() const; 136 QString name() const;
135 /** 137 /**
136 Return translated label for name field. 138 Return translated label for name field.
137 */ 139 */
138 static QString nameLabel(); 140 static QString nameLabel();
139 141
140 /** 142 /**
141 Set formatted name. 143 Set formatted name.
142 */ 144 */
143 void setFormattedName( const QString &formattedName ); 145 void setFormattedName( const QString &formattedName );
144 /** 146 /**
145 Return formatted name. 147 Return formatted name.
146 */ 148 */
147 QString formattedName() const; 149 QString formattedName() const;
148 /** 150 /**
149 Return translated label for formattedName field. 151 Return translated label for formattedName field.
150 */ 152 */
151 static QString formattedNameLabel(); 153 static QString formattedNameLabel();
152 154
153 /** 155 /**
154 Set family name. 156 Set family name.
155 */ 157 */
156 void setFamilyName( const QString &familyName ); 158 void setFamilyName( const QString &familyName );
157 /** 159 /**
158 Return family name. 160 Return family name.
159 */ 161 */
160 QString familyName() const; 162 QString familyName() const;
161 /** 163 /**
162 Return translated label for familyName field. 164 Return translated label for familyName field.
163 */ 165 */
164 static QString familyNameLabel(); 166 static QString familyNameLabel();
165 167
166 /** 168 /**
167 Set given name. 169 Set given name.
168 */ 170 */
169 void setGivenName( const QString &givenName ); 171 void setGivenName( const QString &givenName );
170 /** 172 /**
171 Return given name. 173 Return given name.
172 */ 174 */
173 QString givenName() const; 175 QString givenName() const;
174 /** 176 /**
175 Return translated label for givenName field. 177 Return translated label for givenName field.
176 */ 178 */
177 static QString givenNameLabel(); 179 static QString givenNameLabel();
178 180
179 /** 181 /**
180 Set additional names. 182 Set additional names.
181 */ 183 */
182 void setAdditionalName( const QString &additionalName ); 184 void setAdditionalName( const QString &additionalName );
183 /** 185 /**
184 Return additional names. 186 Return additional names.
185 */ 187 */
186 QString additionalName() const; 188 QString additionalName() const;
187 /** 189 /**
188 Return translated label for additionalName field. 190 Return translated label for additionalName field.
189 */ 191 */
190 static QString additionalNameLabel(); 192 static QString additionalNameLabel();
191 193
192 /** 194 /**
193 Set honorific prefixes. 195 Set honorific prefixes.
194 */ 196 */
195 void setPrefix( const QString &prefix ); 197 void setPrefix( const QString &prefix );
196 /** 198 /**
197 Return honorific prefixes. 199 Return honorific prefixes.
198 */ 200 */
199 QString prefix() const; 201 QString prefix() const;
200 /** 202 /**
201 Return translated label for prefix field. 203 Return translated label for prefix field.
202 */ 204 */
203 static QString prefixLabel(); 205 static QString prefixLabel();
204 206
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index cc8eb52..8776b53 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2576,233 +2576,233 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
2576 if ( mode < SYNC_PREF_ASK ) 2576 if ( mode < SYNC_PREF_ASK )
2577 mode = SYNC_PREF_ASK; 2577 mode = SYNC_PREF_ASK;
2578 } else { 2578 } else {
2579 if ( local->revision() == remote->revision() ) 2579 if ( local->revision() == remote->revision() )
2580 return 0; 2580 return 0;
2581 2581
2582 } 2582 }
2583 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2583 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2584 2584
2585 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 2585 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
2586 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2586 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2587 //full = true; //debug only 2587 //full = true; //debug only
2588 if ( full ) { 2588 if ( full ) {
2589 bool equ = ( (*local) == (*remote) ); 2589 bool equ = ( (*local) == (*remote) );
2590 if ( equ ) { 2590 if ( equ ) {
2591 //qDebug("equal "); 2591 //qDebug("equal ");
2592 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2592 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2593 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2593 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2594 } 2594 }
2595 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2595 if ( mode < SYNC_PREF_FORCE_LOCAL )
2596 return 0; 2596 return 0;
2597 2597
2598 }//else //debug only 2598 }//else //debug only
2599 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2599 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2600 } 2600 }
2601 int result; 2601 int result;
2602 bool localIsNew; 2602 bool localIsNew;
2603 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2603 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2604 2604
2605 if ( full && mode < SYNC_PREF_NEWEST ) 2605 if ( full && mode < SYNC_PREF_NEWEST )
2606 mode = SYNC_PREF_ASK; 2606 mode = SYNC_PREF_ASK;
2607 2607
2608 switch( mode ) { 2608 switch( mode ) {
2609 case SYNC_PREF_LOCAL: 2609 case SYNC_PREF_LOCAL:
2610 if ( lastSync > remote->revision() ) 2610 if ( lastSync > remote->revision() )
2611 return 1; 2611 return 1;
2612 if ( lastSync > local->revision() ) 2612 if ( lastSync > local->revision() )
2613 return 2; 2613 return 2;
2614 return 1; 2614 return 1;
2615 break; 2615 break;
2616 case SYNC_PREF_REMOTE: 2616 case SYNC_PREF_REMOTE:
2617 if ( lastSync > remote->revision() ) 2617 if ( lastSync > remote->revision() )
2618 return 1; 2618 return 1;
2619 if ( lastSync > local->revision() ) 2619 if ( lastSync > local->revision() )
2620 return 2; 2620 return 2;
2621 return 2; 2621 return 2;
2622 break; 2622 break;
2623 case SYNC_PREF_NEWEST: 2623 case SYNC_PREF_NEWEST:
2624 if ( local->revision() > remote->revision() ) 2624 if ( local->revision() > remote->revision() )
2625 return 1; 2625 return 1;
2626 else 2626 else
2627 return 2; 2627 return 2;
2628 break; 2628 break;
2629 case SYNC_PREF_ASK: 2629 case SYNC_PREF_ASK:
2630 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); 2630 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() );
2631 if ( lastSync > remote->revision() ) 2631 if ( lastSync > remote->revision() )
2632 return 1; 2632 return 1;
2633 if ( lastSync > local->revision() ) 2633 if ( lastSync > local->revision() )
2634 return 2; 2634 return 2;
2635 localIsNew = local->revision() >= remote->revision(); 2635 localIsNew = local->revision() >= remote->revision();
2636 //qDebug("conflict! ************************************** "); 2636 //qDebug("conflict! ************************************** ");
2637 { 2637 {
2638 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2638 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2639 result = acd.executeD(localIsNew); 2639 result = acd.executeD(localIsNew);
2640 return result; 2640 return result;
2641 } 2641 }
2642 break; 2642 break;
2643 case SYNC_PREF_FORCE_LOCAL: 2643 case SYNC_PREF_FORCE_LOCAL:
2644 return 1; 2644 return 1;
2645 break; 2645 break;
2646 case SYNC_PREF_FORCE_REMOTE: 2646 case SYNC_PREF_FORCE_REMOTE:
2647 return 2; 2647 return 2;
2648 break; 2648 break;
2649 2649
2650 default: 2650 default:
2651 // SYNC_PREF_TAKE_BOTH not implemented 2651 // SYNC_PREF_TAKE_BOTH not implemented
2652 break; 2652 break;
2653 } 2653 }
2654 return 0; 2654 return 0;
2655} 2655}
2656bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2656bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2657{ 2657{
2658 bool syncOK = true; 2658 bool syncOK = true;
2659 int addedAddressee = 0; 2659 int addedAddressee = 0;
2660 int addedAddresseeR = 0; 2660 int addedAddresseeR = 0;
2661 int deletedAddresseeR = 0; 2661 int deletedAddresseeR = 0;
2662 int deletedAddresseeL = 0; 2662 int deletedAddresseeL = 0;
2663 int changedLocal = 0; 2663 int changedLocal = 0;
2664 int changedRemote = 0; 2664 int changedRemote = 0;
2665 //QPtrList<Addressee> el = local->rawAddressees(); 2665 //QPtrList<Addressee> el = local->rawAddressees();
2666 Addressee addresseeR; 2666 Addressee addresseeR;
2667 QString uid; 2667 QString uid;
2668 int take; 2668 int take;
2669 Addressee addresseeL; 2669 Addressee addresseeL;
2670 Addressee addresseeRSync; 2670 Addressee addresseeRSync;
2671 Addressee addresseeLSync; 2671 Addressee addresseeLSync;
2672 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2672 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2673 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2673 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2674 bool fullDateRange = false; 2674 bool fullDateRange = false;
2675 local->resetTempSyncStat(); 2675 local->resetTempSyncStat();
2676 mLastAddressbookSync = QDateTime::currentDateTime(); 2676 mLastAddressbookSync = QDateTime::currentDateTime();
2677 QDateTime modifiedCalendar = mLastAddressbookSync;; 2677 QDateTime modifiedCalendar = mLastAddressbookSync;;
2678 addresseeLSync = getLastSyncAddressee(); 2678 addresseeLSync = getLastSyncAddressee();
2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2681 if ( !addresseeR.isEmpty() ) { 2681 if ( !addresseeR.isEmpty() ) {
2682 addresseeRSync = addresseeR; 2682 addresseeRSync = addresseeR;
2683 remote->removeAddressee(addresseeR ); 2683 remote->removeAddressee(addresseeR );
2684 2684
2685 } else { 2685 } else {
2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2687 addresseeRSync = addresseeLSync ; 2687 addresseeRSync = addresseeLSync ;
2688 } else { 2688 } else {
2689 qDebug("FULLDATE 1"); 2689 qDebug("FULLDATE 1");
2690 fullDateRange = true; 2690 fullDateRange = true;
2691 Addressee newAdd; 2691 Addressee newAdd;
2692 addresseeRSync = newAdd; 2692 addresseeRSync = newAdd;
2693 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2693 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2694 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2694 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2695 addresseeRSync.setRevision( mLastAddressbookSync ); 2695 addresseeRSync.setRevision( mLastAddressbookSync );
2696 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2696 addresseeRSync.setCategories( i18n("SyncAddressee") );
2697 } 2697 }
2698 } 2698 }
2699 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2699 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2700 qDebug("FULLDATE 2"); 2700 qDebug("FULLDATE 2");
2701 fullDateRange = true; 2701 fullDateRange = true;
2702 } 2702 }
2703 if ( ! fullDateRange ) { 2703 if ( ! fullDateRange ) {
2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2705 2705
2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2708 fullDateRange = true; 2708 fullDateRange = true;
2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2710 } 2710 }
2711 } 2711 }
2712 fullDateRange = true; // debug only! 2712 // fullDateRange = true; // debug only!
2713 if ( fullDateRange ) 2713 if ( fullDateRange )
2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2715 else 2715 else
2716 mLastAddressbookSync = addresseeLSync.revision(); 2716 mLastAddressbookSync = addresseeLSync.revision();
2717 // for resyncing if own file has changed 2717 // for resyncing if own file has changed
2718 // PENDING fixme later when implemented 2718 // PENDING fixme later when implemented
2719#if 0 2719#if 0
2720 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2720 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2721 mLastAddressbookSync = loadedFileVersion; 2721 mLastAddressbookSync = loadedFileVersion;
2722 qDebug("setting mLastAddressbookSync "); 2722 qDebug("setting mLastAddressbookSync ");
2723 } 2723 }
2724#endif 2724#endif
2725 2725
2726 //qDebug("*************************** "); 2726 //qDebug("*************************** ");
2727 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2727 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2728 QStringList er = remote->uidList(); 2728 QStringList er = remote->uidList();
2729 Addressee inR ;//= er.first(); 2729 Addressee inR ;//= er.first();
2730 Addressee inL; 2730 Addressee inL;
2731 QProgressBar bar( er.count(),0 ); 2731 QProgressBar bar( er.count(),0 );
2732 bar.setCaption (i18n("Syncing - close to abort!") ); 2732 bar.setCaption (i18n("Syncing - close to abort!") );
2733 2733
2734 int w = 300; 2734 int w = 300;
2735 if ( QApplication::desktop()->width() < 320 ) 2735 if ( QApplication::desktop()->width() < 320 )
2736 w = 220; 2736 w = 220;
2737 int h = bar.sizeHint().height() ; 2737 int h = bar.sizeHint().height() ;
2738 int dw = QApplication::desktop()->width(); 2738 int dw = QApplication::desktop()->width();
2739 int dh = QApplication::desktop()->height(); 2739 int dh = QApplication::desktop()->height();
2740 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2740 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2741 bar.show(); 2741 bar.show();
2742 int modulo = (er.count()/10)+1; 2742 int modulo = (er.count()/10)+1;
2743 int incCounter = 0; 2743 int incCounter = 0;
2744 while ( incCounter < er.count()) { 2744 while ( incCounter < er.count()) {
2745 if ( ! bar.isVisible() ) 2745 if ( ! bar.isVisible() )
2746 return false; 2746 return false;
2747 if ( incCounter % modulo == 0 ) 2747 if ( incCounter % modulo == 0 )
2748 bar.setProgress( incCounter ); 2748 bar.setProgress( incCounter );
2749 uid = er[ incCounter ]; 2749 uid = er[ incCounter ];
2750 bool skipIncidence = false; 2750 bool skipIncidence = false;
2751 if ( uid.left(19) == QString("last-syncAddressee-") ) 2751 if ( uid.left(19) == QString("last-syncAddressee-") )
2752 skipIncidence = true; 2752 skipIncidence = true;
2753 QString idS; 2753 QString idS;
2754 qApp->processEvents(); 2754 qApp->processEvents();
2755 if ( !skipIncidence ) { 2755 if ( !skipIncidence ) {
2756 inL = local->findByUid( uid ); 2756 inL = local->findByUid( uid );
2757 inR = remote->findByUid( uid ); 2757 inR = remote->findByUid( uid );
2758 //inL.setResource( 0 ); 2758 //inL.setResource( 0 );
2759 //inR.setResource( 0 ); 2759 //inR.setResource( 0 );
2760 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2760 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2761 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2761 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2762 //qDebug("take %d %s ", take, inL.summary().latin1()); 2762 //qDebug("take %d %s ", take, inL.summary().latin1());
2763 if ( take == 3 ) 2763 if ( take == 3 )
2764 return false; 2764 return false;
2765 if ( take == 1 ) {// take local 2765 if ( take == 1 ) {// take local
2766 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2766 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2767 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2767 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2768 local->insertAddressee( inL, false ); 2768 local->insertAddressee( inL, false );
2769 } 2769 }
2770 else 2770 else
2771 idS = inR.IDStr(); 2771 idS = inR.IDStr();
2772 remote->removeAddressee( inR ); 2772 remote->removeAddressee( inR );
2773 inR = inL; 2773 inR = inL;
2774 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2774 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2775 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2775 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2776 inR.setIDStr( idS ); 2776 inR.setIDStr( idS );
2777 inR.setResource( 0 ); 2777 inR.setResource( 0 );
2778 remote->insertAddressee( inR , false); 2778 remote->insertAddressee( inR , false);
2779 ++changedRemote; 2779 ++changedRemote;
2780 } else { 2780 } else {
2781 idS = inL.IDStr(); 2781 idS = inL.IDStr();
2782 local->removeAddressee( inL ); 2782 local->removeAddressee( inL );
2783 inL = inR; 2783 inL = inR;
2784 inL.setIDStr( idS ); 2784 inL.setIDStr( idS );
2785 inL.setResource( 0 ); 2785 inL.setResource( 0 );
2786 local->insertAddressee( inL , false ); 2786 local->insertAddressee( inL , false );
2787 ++changedLocal; 2787 ++changedLocal;
2788 } 2788 }
2789 } 2789 }
2790 } else { // no conflict 2790 } else { // no conflict
2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2792 QString des = addresseeLSync.note(); 2792 QString des = addresseeLSync.note();
2793 QString pref = "a"; 2793 QString pref = "a";
2794 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2794 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2795 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2795 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2796 ++deletedAddresseeR; 2796 ++deletedAddresseeR;
2797 } else { 2797 } else {
2798 inR.setRevision( modifiedCalendar ); 2798 inR.setRevision( modifiedCalendar );
2799 remote->insertAddressee( inR, false ); 2799 remote->insertAddressee( inR, false );
2800 inL = inR; 2800 inL = inR;
2801 inL.setResource( 0 ); 2801 inL.setResource( 0 );
2802 local->insertAddressee( inL , false); 2802 local->insertAddressee( inL , false);
2803 ++addedAddressee; 2803 ++addedAddressee;
2804 } 2804 }
2805 } else { 2805 } else {
2806 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2806 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2807 inR.setRevision( modifiedCalendar ); 2807 inR.setRevision( modifiedCalendar );
2808 remote->insertAddressee( inR, false ); 2808 remote->insertAddressee( inR, false );
@@ -2825,169 +2825,197 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2825 bar.setCaption (i18n("Add / remove addressees") ); 2825 bar.setCaption (i18n("Add / remove addressees") );
2826 bar.setTotalSteps ( el.count() ) ; 2826 bar.setTotalSteps ( el.count() ) ;
2827 bar.show(); 2827 bar.show();
2828 incCounter = 0; 2828 incCounter = 0;
2829 while ( incCounter < el.count()) { 2829 while ( incCounter < el.count()) {
2830 2830
2831 qApp->processEvents(); 2831 qApp->processEvents();
2832 if ( ! bar.isVisible() ) 2832 if ( ! bar.isVisible() )
2833 return false; 2833 return false;
2834 if ( incCounter % modulo == 0 ) 2834 if ( incCounter % modulo == 0 )
2835 bar.setProgress( incCounter ); 2835 bar.setProgress( incCounter );
2836 uid = el[ incCounter ]; 2836 uid = el[ incCounter ];
2837 bool skipIncidence = false; 2837 bool skipIncidence = false;
2838 if ( uid.left(19) == QString("last-syncAddressee-") ) 2838 if ( uid.left(19) == QString("last-syncAddressee-") )
2839 skipIncidence = true; 2839 skipIncidence = true;
2840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2841 skipIncidence = true; 2841 skipIncidence = true;
2842 if ( !skipIncidence ) { 2842 if ( !skipIncidence ) {
2843 inL = local->findByUid( uid ); 2843 inL = local->findByUid( uid );
2844 inR = remote->findByUid( uid ); 2844 inR = remote->findByUid( uid );
2845 if ( inR.isEmpty() ) { 2845 if ( inR.isEmpty() ) {
2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2847 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2847 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2848 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2848 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2849 local->removeAddressee( inL ); 2849 local->removeAddressee( inL );
2850 ++deletedAddresseeL; 2850 ++deletedAddresseeL;
2851 } else { 2851 } else {
2852 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2852 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2853 inL.removeID(mCurrentSyncDevice ); 2853 inL.removeID(mCurrentSyncDevice );
2854 ++addedAddresseeR; 2854 ++addedAddresseeR;
2855 //qDebug("remote added Incidence %s ", inL.summary().latin1()); 2855 //qDebug("remote added Incidence %s ", inL.summary().latin1());
2856 inL.setRevision( modifiedCalendar ); 2856 inL.setRevision( modifiedCalendar );
2857 local->insertAddressee( inL, false ); 2857 local->insertAddressee( inL, false );
2858 inR = inL; 2858 inR = inL;
2859 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2859 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2860 inR.setResource( 0 ); 2860 inR.setResource( 0 );
2861 remote->insertAddressee( inR, false ); 2861 remote->insertAddressee( inR, false );
2862 } 2862 }
2863 } 2863 }
2864 } else { 2864 } else {
2865 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2865 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2866 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2866 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2867 local->removeAddressee( inL ); 2867 local->removeAddressee( inL );
2868 ++deletedAddresseeL; 2868 ++deletedAddresseeL;
2869 } else { 2869 } else {
2870 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2870 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2871 ++addedAddresseeR; 2871 ++addedAddresseeR;
2872 inL.setRevision( modifiedCalendar ); 2872 inL.setRevision( modifiedCalendar );
2873 local->insertAddressee( inL, false ); 2873 local->insertAddressee( inL, false );
2874 inR = inL; 2874 inR = inL;
2875 inR.setResource( 0 ); 2875 inR.setResource( 0 );
2876 remote->insertAddressee( inR, false ); 2876 remote->insertAddressee( inR, false );
2877 } 2877 }
2878 } 2878 }
2879 } 2879 }
2880 } 2880 }
2881 } 2881 }
2882 ++incCounter; 2882 ++incCounter;
2883 } 2883 }
2884 el.clear(); 2884 el.clear();
2885 bar.hide(); 2885 bar.hide();
2886 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2886 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2887 // get rid of micro seconds 2887 // get rid of micro seconds
2888 QTime t = mLastAddressbookSync.time(); 2888 QTime t = mLastAddressbookSync.time();
2889 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2889 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2890 addresseeLSync.setRevision( mLastAddressbookSync ); 2890 addresseeLSync.setRevision( mLastAddressbookSync );
2891 addresseeRSync.setRevision( mLastAddressbookSync ); 2891 addresseeRSync.setRevision( mLastAddressbookSync );
2892 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2892 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2893 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2893 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2894 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2894 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2895 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2895 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2896 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2896 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2897 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2897 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2898 2898
2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2900 remote->insertAddressee( addresseeRSync, false ); 2900 remote->insertAddressee( addresseeRSync, false );
2901 local->insertAddressee( addresseeLSync, false ); 2901 local->insertAddressee( addresseeLSync, false );
2902 QString mes; 2902 QString mes;
2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2904 if ( KABPrefs::instance()->mShowSyncSummary ) { 2904 if ( KABPrefs::instance()->mShowSyncSummary ) {
2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2906 } 2906 }
2907 qDebug( mes ); 2907 qDebug( mes );
2908 return syncOK; 2908 return syncOK;
2909} 2909}
2910 2910
2911bool KABCore::syncAB(QString filename, int mode) 2911bool KABCore::syncAB(QString filename, int mode)
2912{ 2912{
2913 2913
2914 //pending prepare addresseeview for output 2914 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2915 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2916 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2917 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2918 bool syncOK = false;
2919 if ( abLocal.load() ) { 2919 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2921 AddressBook::Iterator it; 2921 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true;
2926 } else {
2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1));
2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) {
2932 found = true;
2933 break;
2934 }
2935 }
2936 external = ! found;
2937 }
2938
2939 if ( external ) {
2940 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2941 AddressBook::Iterator it;
2942 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2943 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2944 (*it).computeCsum( mCurrentSyncDevice );
2945 }
2946 }
2947 //AddressBook::Iterator it;
2922 //QStringList vcards; 2948 //QStringList vcards;
2923 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2949 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2924 // qDebug("Name %s ", (*it).familyName().latin1()); 2950 // qDebug("Name %s ", (*it).familyName().latin1());
2925 //} 2951 //}
2926 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2952 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2927 if ( syncOK ) { 2953 if ( syncOK ) {
2928 if ( KABPrefs::instance()->mWriteBackFile ) 2954 if ( KABPrefs::instance()->mWriteBackFile )
2929 { 2955 {
2956 if ( external )
2957 abLocal.removeDeletedAddressees();
2930 qDebug("saving remote AB "); 2958 qDebug("saving remote AB ");
2931 abLocal.saveAB(); 2959 abLocal.saveAB();
2932 } 2960 }
2933 } 2961 }
2934 setModified(); 2962 setModified();
2935 2963
2936 } 2964 }
2937 if ( syncOK ) 2965 if ( syncOK )
2938 mViewManager->refreshView(); 2966 mViewManager->refreshView();
2939 return syncOK; 2967 return syncOK;
2940#if 0 2968#if 0
2941 2969
2942 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2970 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2943 getEventViewerDialog()->setSyncMode( true ); 2971 getEventViewerDialog()->setSyncMode( true );
2944 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2972 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2945 getEventViewerDialog()->setSyncMode( false ); 2973 getEventViewerDialog()->setSyncMode( false );
2946 if ( syncOK ) { 2974 if ( syncOK ) {
2947 if ( KOPrefs::instance()->mWriteBackFile ) 2975 if ( KOPrefs::instance()->mWriteBackFile )
2948 { 2976 {
2949 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2977 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2950 storage->save(); 2978 storage->save();
2951 } 2979 }
2952 } 2980 }
2953 setModified(); 2981 setModified();
2954 } 2982 }
2955 2983
2956#endif 2984#endif
2957} 2985}
2958 2986
2959void KABCore::confSync() 2987void KABCore::confSync()
2960{ 2988{
2961 static KSyncPrefsDialog* sp = 0; 2989 static KSyncPrefsDialog* sp = 0;
2962 if ( ! sp ) { 2990 if ( ! sp ) {
2963 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2991 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2964 } 2992 }
2965 sp->usrReadConfig(); 2993 sp->usrReadConfig();
2966#ifndef DESKTOP_VERSION 2994#ifndef DESKTOP_VERSION
2967 sp->showMaximized(); 2995 sp->showMaximized();
2968#else 2996#else
2969 sp->show(); 2997 sp->show();
2970#endif 2998#endif
2971 sp->exec(); 2999 sp->exec();
2972 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3000 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
2973 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3001 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
2974 fillSyncMenu(); 3002 fillSyncMenu();
2975} 3003}
2976void KABCore::syncSharp() 3004void KABCore::syncSharp()
2977{ 3005{
2978 if ( mModified ) 3006 if ( mModified )
2979 save(); 3007 save();
2980 qDebug("pending syncSharp() "); 3008 qDebug("pending syncSharp() ");
2981 //mView->syncSharp(); 3009 //mView->syncSharp();
2982 setModified(); 3010 setModified();
2983 3011
2984} 3012}
2985void KABCore::syncPhone() 3013void KABCore::syncPhone()
2986{ 3014{
2987 if ( mModified ) 3015 if ( mModified )
2988 save(); 3016 save();
2989 qDebug("pending syncPhone(); "); 3017 qDebug("pending syncPhone(); ");
2990 //mView->syncPhone(); 3018 //mView->syncPhone();
2991 setModified(); 3019 setModified();
2992 3020
2993} 3021}