summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp11
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp215
-rw-r--r--kabc/tmpaddressbook.cpp9
-rw-r--r--kaddressbook/kabcore.cpp31
6 files changed, 78 insertions, 191 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 4c4ae09..8487ff3 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -971,278 +971,289 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool is
971 if ( !ad.isEmpty() ) { 971 if ( !ad.isEmpty() ) {
972 (*it).mergeContact( ad ,isSubset); 972 (*it).mergeContact( ad ,isSubset);
973 } 973 }
974 } 974 }
975#if 0 975#if 0
976 // test only 976 // test only
977 for ( it = begin(); it != end(); ++it ) { 977 for ( it = begin(); it != end(); ++it ) {
978 978
979 qDebug("uid %s ", (*it).uid().latin1()); 979 qDebug("uid %s ", (*it).uid().latin1());
980 } 980 }
981#endif 981#endif
982} 982}
983 983
984#if 0 984#if 0
985Addressee::List AddressBook::getExternLastSyncAddressees() 985Addressee::List AddressBook::getExternLastSyncAddressees()
986{ 986{
987 Addressee::List results; 987 Addressee::List results;
988 988
989 Iterator it; 989 Iterator it;
990 for ( it = begin(); it != end(); ++it ) { 990 for ( it = begin(); it != end(); ++it ) {
991 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 991 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
992 if ( (*it).familyName().left(4) == "!E: " ) 992 if ( (*it).familyName().left(4) == "!E: " )
993 results.append( *it ); 993 results.append( *it );
994 } 994 }
995 } 995 }
996 996
997 return results; 997 return results;
998} 998}
999#endif 999#endif
1000void AddressBook::resetTempSyncStat() 1000void AddressBook::resetTempSyncStat()
1001{ 1001{
1002 Iterator it; 1002 Iterator it;
1003 for ( it = begin(); it != end(); ++it ) { 1003 for ( it = begin(); it != end(); ++it ) {
1004 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 1004 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
1005 } 1005 }
1006 1006
1007} 1007}
1008 1008
1009QStringList AddressBook:: uidList() 1009QStringList AddressBook:: uidList()
1010{ 1010{
1011 QStringList results; 1011 QStringList results;
1012 Iterator it; 1012 Iterator it;
1013 for ( it = begin(); it != end(); ++it ) { 1013 for ( it = begin(); it != end(); ++it ) {
1014 results.append( (*it).uid() ); 1014 results.append( (*it).uid() );
1015 } 1015 }
1016 return results; 1016 return results;
1017} 1017}
1018 1018
1019 1019
1020Addressee::List AddressBook::allAddressees() 1020Addressee::List AddressBook::allAddressees()
1021{ 1021{
1022 return d->mAddressees; 1022 return d->mAddressees;
1023 1023
1024} 1024}
1025 1025
1026Addressee::List AddressBook::findByName( const QString &name ) 1026Addressee::List AddressBook::findByName( const QString &name )
1027{ 1027{
1028 Addressee::List results; 1028 Addressee::List results;
1029 1029
1030 Iterator it; 1030 Iterator it;
1031 for ( it = begin(); it != end(); ++it ) { 1031 for ( it = begin(); it != end(); ++it ) {
1032 if ( name == (*it).realName() ) { 1032 if ( name == (*it).realName() ) {
1033 results.append( *it ); 1033 results.append( *it );
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 return results; 1037 return results;
1038} 1038}
1039 1039
1040Addressee::List AddressBook::findByEmail( const QString &email ) 1040Addressee::List AddressBook::findByEmail( const QString &email )
1041{ 1041{
1042 Addressee::List results; 1042 Addressee::List results;
1043 QStringList mailList; 1043 QStringList mailList;
1044 1044
1045 Iterator it; 1045 Iterator it;
1046 for ( it = begin(); it != end(); ++it ) { 1046 for ( it = begin(); it != end(); ++it ) {
1047 mailList = (*it).emails(); 1047 mailList = (*it).emails();
1048 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1048 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1049 if ( email == (*ite) ) { 1049 if ( email == (*ite) ) {
1050 results.append( *it ); 1050 results.append( *it );
1051 } 1051 }
1052 } 1052 }
1053 } 1053 }
1054 1054
1055 return results; 1055 return results;
1056} 1056}
1057 1057
1058Addressee::List AddressBook::findByCategory( const QString &category ) 1058Addressee::List AddressBook::findByCategory( const QString &category )
1059{ 1059{
1060 Addressee::List results; 1060 Addressee::List results;
1061 1061
1062 Iterator it; 1062 Iterator it;
1063 for ( it = begin(); it != end(); ++it ) { 1063 for ( it = begin(); it != end(); ++it ) {
1064 if ( (*it).hasCategory( category) ) { 1064 if ( (*it).hasCategory( category) ) {
1065 results.append( *it ); 1065 results.append( *it );
1066 } 1066 }
1067 } 1067 }
1068 1068
1069 return results; 1069 return results;
1070} 1070}
1071 1071
1072void AddressBook::dump() const 1072void AddressBook::dump() const
1073{ 1073{
1074 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1074 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1075 1075
1076 ConstIterator it; 1076 ConstIterator it;
1077 for( it = begin(); it != end(); ++it ) { 1077 for( it = begin(); it != end(); ++it ) {
1078 (*it).dump(); 1078 (*it).dump();
1079 } 1079 }
1080 1080
1081 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1081 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1082} 1082}
1083 1083
1084QString AddressBook::identifier() 1084QString AddressBook::identifier()
1085{ 1085{
1086 QStringList identifier; 1086 QStringList identifier;
1087 1087
1088 1088
1089 KRES::Manager<Resource>::ActiveIterator it; 1089 KRES::Manager<Resource>::ActiveIterator it;
1090 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1090 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1091 if ( !(*it)->identifier().isEmpty() ) 1091 if ( !(*it)->identifier().isEmpty() )
1092 identifier.append( (*it)->identifier() ); 1092 identifier.append( (*it)->identifier() );
1093 } 1093 }
1094 1094
1095 return identifier.join( ":" ); 1095 return identifier.join( ":" );
1096} 1096}
1097 1097
1098Field::List AddressBook::fields( int category ) 1098Field::List AddressBook::fields( int category )
1099{ 1099{
1100 if ( d->mAllFields.isEmpty() ) { 1100 if ( d->mAllFields.isEmpty() ) {
1101 d->mAllFields = Field::allFields(); 1101 d->mAllFields = Field::allFields();
1102 } 1102 }
1103 1103
1104 if ( category == Field::All ) return d->mAllFields; 1104 if ( category == Field::All ) return d->mAllFields;
1105 1105
1106 Field::List result; 1106 Field::List result;
1107 Field::List::ConstIterator it; 1107 Field::List::ConstIterator it;
1108 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1108 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1109 if ( (*it)->category() & category ) result.append( *it ); 1109 if ( (*it)->category() & category ) result.append( *it );
1110 } 1110 }
1111 1111
1112 return result; 1112 return result;
1113} 1113}
1114 1114
1115bool AddressBook::addCustomField( const QString &label, int category, 1115bool AddressBook::addCustomField( const QString &label, int category,
1116 const QString &key, const QString &app ) 1116 const QString &key, const QString &app )
1117{ 1117{
1118 if ( d->mAllFields.isEmpty() ) { 1118 if ( d->mAllFields.isEmpty() ) {
1119 d->mAllFields = Field::allFields(); 1119 d->mAllFields = Field::allFields();
1120 } 1120 }
1121//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1121//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1122 QString a = app.isNull() ? KGlobal::getAppName() : app; 1122 QString a = app.isNull() ? KGlobal::getAppName() : app;
1123 1123
1124 QString k = key.isNull() ? label : key; 1124 QString k = key.isNull() ? label : key;
1125 1125
1126 Field *field = Field::createCustomField( label, category, k, a ); 1126 Field *field = Field::createCustomField( label, category, k, a );
1127 1127
1128 if ( !field ) return false; 1128 if ( !field ) return false;
1129 1129
1130 d->mAllFields.append( field ); 1130 d->mAllFields.append( field );
1131 1131
1132 return true; 1132 return true;
1133} 1133}
1134 1134
1135QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1135QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1136{ 1136{
1137 if (!ab.d) return s; 1137 if (!ab.d) return s;
1138 1138
1139 return s << ab.d->mAddressees; 1139 return s << ab.d->mAddressees;
1140} 1140}
1141 1141
1142QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1142QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1143{ 1143{
1144 if (!ab.d) return s; 1144 if (!ab.d) return s;
1145 1145
1146 s >> ab.d->mAddressees; 1146 s >> ab.d->mAddressees;
1147 1147
1148 return s; 1148 return s;
1149} 1149}
1150 1150
1151bool AddressBook::addResource( Resource *resource ) 1151bool AddressBook::addResource( Resource *resource )
1152{ 1152{
1153 if ( !resource->open() ) { 1153 if ( !resource->open() ) {
1154 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1154 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1155 return false; 1155 return false;
1156 } 1156 }
1157 1157
1158 resource->setAddressBook( this ); 1158 resource->setAddressBook( this );
1159 1159
1160 d->mManager->add( resource ); 1160 d->mManager->add( resource );
1161 return true; 1161 return true;
1162} 1162}
1163void AddressBook::removeResources()
1164{
1165 //remove all possible resources. This should cleanup the configfile.
1166 QPtrList<KABC::Resource> mResources = resources();
1167
1168 QPtrListIterator<KABC::Resource> it(mResources);
1169 for ( ; it.current(); ++it ) {
1170 KABC::Resource *res = it.current();
1171 removeResource(res);
1172 }
1173}
1163 1174
1164bool AddressBook::removeResource( Resource *resource ) 1175bool AddressBook::removeResource( Resource *resource )
1165{ 1176{
1166 resource->close(); 1177 resource->close();
1167 1178
1168 if ( resource == standardResource() ) 1179 if ( resource == standardResource() )
1169 d->mManager->setStandardResource( 0 ); 1180 d->mManager->setStandardResource( 0 );
1170 1181
1171 resource->setAddressBook( 0 ); 1182 resource->setAddressBook( 0 );
1172 1183
1173 d->mManager->remove( resource ); 1184 d->mManager->remove( resource );
1174 return true; 1185 return true;
1175} 1186}
1176 1187
1177QPtrList<Resource> AddressBook::resources() 1188QPtrList<Resource> AddressBook::resources()
1178{ 1189{
1179 QPtrList<Resource> list; 1190 QPtrList<Resource> list;
1180 1191
1181// qDebug("AddressBook::resources() 1"); 1192// qDebug("AddressBook::resources() 1");
1182 1193
1183 KRES::Manager<Resource>::ActiveIterator it; 1194 KRES::Manager<Resource>::ActiveIterator it;
1184 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1195 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1185 list.append( *it ); 1196 list.append( *it );
1186 1197
1187 return list; 1198 return list;
1188} 1199}
1189 1200
1190/*US 1201/*US
1191void AddressBook::setErrorHandler( ErrorHandler *handler ) 1202void AddressBook::setErrorHandler( ErrorHandler *handler )
1192{ 1203{
1193 delete d->mErrorHandler; 1204 delete d->mErrorHandler;
1194 d->mErrorHandler = handler; 1205 d->mErrorHandler = handler;
1195} 1206}
1196*/ 1207*/
1197 1208
1198void AddressBook::error( const QString& msg ) 1209void AddressBook::error( const QString& msg )
1199{ 1210{
1200/*US 1211/*US
1201 if ( !d->mErrorHandler ) // create default error handler 1212 if ( !d->mErrorHandler ) // create default error handler
1202 d->mErrorHandler = new ConsoleErrorHandler; 1213 d->mErrorHandler = new ConsoleErrorHandler;
1203 1214
1204 if ( d->mErrorHandler ) 1215 if ( d->mErrorHandler )
1205 d->mErrorHandler->error( msg ); 1216 d->mErrorHandler->error( msg );
1206 else 1217 else
1207 kdError(5700) << "no error handler defined" << endl; 1218 kdError(5700) << "no error handler defined" << endl;
1208*/ 1219*/
1209 kdDebug(5700) << "msg" << endl; 1220 kdDebug(5700) << "msg" << endl;
1210 qDebug(msg); 1221 qDebug(msg);
1211} 1222}
1212 1223
1213void AddressBook::deleteRemovedAddressees() 1224void AddressBook::deleteRemovedAddressees()
1214{ 1225{
1215 Addressee::List::Iterator it; 1226 Addressee::List::Iterator it;
1216 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1227 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1217 Resource *resource = (*it).resource(); 1228 Resource *resource = (*it).resource();
1218 if ( resource && !resource->readOnly() && resource->isOpen() ) 1229 if ( resource && !resource->readOnly() && resource->isOpen() )
1219 resource->removeAddressee( *it ); 1230 resource->removeAddressee( *it );
1220 } 1231 }
1221 1232
1222 d->mRemovedAddressees.clear(); 1233 d->mRemovedAddressees.clear();
1223} 1234}
1224 1235
1225void AddressBook::setStandardResource( Resource *resource ) 1236void AddressBook::setStandardResource( Resource *resource )
1226{ 1237{
1227// qDebug("AddressBook::setStandardResource 1"); 1238// qDebug("AddressBook::setStandardResource 1");
1228 d->mManager->setStandardResource( resource ); 1239 d->mManager->setStandardResource( resource );
1229} 1240}
1230 1241
1231Resource *AddressBook::standardResource() 1242Resource *AddressBook::standardResource()
1232{ 1243{
1233 return d->mManager->standardResource(); 1244 return d->mManager->standardResource();
1234} 1245}
1235 1246
1236KRES::Manager<Resource> *AddressBook::resourceManager() 1247KRES::Manager<Resource> *AddressBook::resourceManager()
1237{ 1248{
1238 return d->mManager; 1249 return d->mManager;
1239} 1250}
1240 1251
1241void AddressBook::cleanUp() 1252void AddressBook::cleanUp()
1242{ 1253{
1243 KRES::Manager<Resource>::ActiveIterator it; 1254 KRES::Manager<Resource>::ActiveIterator it;
1244 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1255 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1245 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1256 if ( !(*it)->readOnly() && (*it)->isOpen() )
1246 (*it)->cleanUp(); 1257 (*it)->cleanUp();
1247 } 1258 }
1248} 1259}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 75f8b51..2351add 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -85,265 +85,266 @@ class AddressBook : public QObject
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void removeSyncInfo( QString syncProfile); 147 void removeSyncInfo( QString syncProfile);
148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
149 void export2File( QString fileName ); 149 void export2File( QString fileName );
150 bool export2PhoneFormat( QStringList uids ,QString fileName ); 150 bool export2PhoneFormat( QStringList uids ,QString fileName );
151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
152 void setUntagged( bool setNonSyncTagged = false ); 152 void setUntagged( bool setNonSyncTagged = false );
153 void removeUntagged(); 153 void removeUntagged();
154 void findNewExtIds( QString fileName, QString currentSyncDevice ); 154 void findNewExtIds( QString fileName, QString currentSyncDevice );
155 /** 155 /**
156 Returns a iterator for first entry of address book. 156 Returns a iterator for first entry of address book.
157 */ 157 */
158 Iterator begin(); 158 Iterator begin();
159 159
160 /** 160 /**
161 Returns a const iterator for first entry of address book. 161 Returns a const iterator for first entry of address book.
162 */ 162 */
163 ConstIterator begin() const; 163 ConstIterator begin() const;
164 164
165 /** 165 /**
166 Returns a iterator for first entry of address book. 166 Returns a iterator for first entry of address book.
167 */ 167 */
168 Iterator end(); 168 Iterator end();
169 169
170 /** 170 /**
171 Returns a const iterator for first entry of address book. 171 Returns a const iterator for first entry of address book.
172 */ 172 */
173 ConstIterator end() const; 173 ConstIterator end() const;
174 174
175 /** 175 /**
176 Removes all entries from address book. 176 Removes all entries from address book.
177 */ 177 */
178 void clear(); 178 void clear();
179 179
180 /** 180 /**
181 Insert an Addressee object into address book. If an object with the same 181 Insert an Addressee object into address book. If an object with the same
182 unique id already exists in the address book it it replaced by the new 182 unique id already exists in the address book it it replaced by the new
183 one. If not the new object is appended to the address book. 183 one. If not the new object is appended to the address book.
184 */ 184 */
185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
186 186
187 /** 187 /**
188 Removes entry from the address book. 188 Removes entry from the address book.
189 */ 189 */
190 void removeAddressee( const Addressee & ); 190 void removeAddressee( const Addressee & );
191 191
192 /** 192 /**
193 This is like @ref removeAddressee() just above, with the difference that 193 This is like @ref removeAddressee() just above, with the difference that
194 the first element is a iterator, returned by @ref begin(). 194 the first element is a iterator, returned by @ref begin().
195 */ 195 */
196 void removeAddressee( const Iterator & ); 196 void removeAddressee( const Iterator & );
197 197
198 /** 198 /**
199 Find the specified entry in address book. Returns end(), if the entry 199 Find the specified entry in address book. Returns end(), if the entry
200 couldn't be found. 200 couldn't be found.
201 */ 201 */
202 Iterator find( const Addressee & ); 202 Iterator find( const Addressee & );
203 203
204 /** 204 /**
205 Find the entry specified by an unique id. Returns an empty Addressee 205 Find the entry specified by an unique id. Returns an empty Addressee
206 object, if the address book does not contain an entry with this id. 206 object, if the address book does not contain an entry with this id.
207 */ 207 */
208 Addressee findByUid( const QString & ); 208 Addressee findByUid( const QString & );
209 209
210 210
211 /** 211 /**
212 Returns a list of all addressees in the address book. This list can 212 Returns a list of all addressees in the address book. This list can
213 be sorted with @ref KABC::AddresseeList for example. 213 be sorted with @ref KABC::AddresseeList for example.
214 */ 214 */
215 Addressee::List allAddressees(); 215 Addressee::List allAddressees();
216 216
217 /** 217 /**
218 Find all entries with the specified name in the address book. Returns 218 Find all entries with the specified name in the address book. Returns
219 an empty list, if no entries could be found. 219 an empty list, if no entries could be found.
220 */ 220 */
221 Addressee::List findByName( const QString & ); 221 Addressee::List findByName( const QString & );
222 222
223 /** 223 /**
224 Find all entries with the specified email address in the address book. 224 Find all entries with the specified email address in the address book.
225 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
226 */ 226 */
227 Addressee::List findByEmail( const QString & ); 227 Addressee::List findByEmail( const QString & );
228 228
229 /** 229 /**
230 Find all entries wich have the specified category in the address book. 230 Find all entries wich have the specified category in the address book.
231 Returns an empty list, if no entries could be found. 231 Returns an empty list, if no entries could be found.
232 */ 232 */
233 Addressee::List findByCategory( const QString & ); 233 Addressee::List findByCategory( const QString & );
234 234
235 /** 235 /**
236 Return a string identifying this addressbook. 236 Return a string identifying this addressbook.
237 */ 237 */
238 virtual QString identifier(); 238 virtual QString identifier();
239 239
240 /** 240 /**
241 Used for debug output. 241 Used for debug output.
242 */ 242 */
243 void dump() const; 243 void dump() const;
244 244
245 void emitAddressBookLocked() { emit addressBookLocked( this ); } 245 void emitAddressBookLocked() { emit addressBookLocked( this ); }
246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
247 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
248 248
249 /** 249 /**
250 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
251 with the given field category. 251 with the given field category.
252 */ 252 */
253 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
254 254
255 /** 255 /**
256 Add custom field to address book. 256 Add custom field to address book.
257 257
258 @param label User visible label of the field. 258 @param label User visible label of the field.
259 @param category Ored list of field categories. 259 @param category Ored list of field categories.
260 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
261 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
262 the field. 262 the field.
263 */ 263 */
264 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
265 const QString &key = QString::null, 265 const QString &key = QString::null,
266 const QString &app = QString::null ); 266 const QString &app = QString::null );
267 267
268 268
269 /** 269 /**
270 Add address book resource. 270 Add address book resource.
271 */ 271 */
272 bool addResource( Resource * ); 272 bool addResource( Resource * );
273 273
274 /** 274 /**
275 Remove address book resource. 275 Remove address book resource.
276 */ 276 */
277 void removeResources();
277 bool removeResource( Resource * ); 278 bool removeResource( Resource * );
278 279
279 /** 280 /**
280 Return pointer list of all resources. 281 Return pointer list of all resources.
281 */ 282 */
282 QPtrList<Resource> resources(); 283 QPtrList<Resource> resources();
283 284
284 /** 285 /**
285 Set the @p ErrorHandler, that is used by @ref error() to 286 Set the @p ErrorHandler, that is used by @ref error() to
286 provide gui-independend error messages. 287 provide gui-independend error messages.
287 */ 288 */
288 void setErrorHandler( ErrorHandler * ); 289 void setErrorHandler( ErrorHandler * );
289 290
290 /** 291 /**
291 Shows gui independend error messages. 292 Shows gui independend error messages.
292 */ 293 */
293 void error( const QString& ); 294 void error( const QString& );
294 295
295 /** 296 /**
296 Query all resources to clean up their lock files 297 Query all resources to clean up their lock files
297 */ 298 */
298 void cleanUp(); 299 void cleanUp();
299 300
300 // sync stuff 301 // sync stuff
301 //Addressee::List getExternLastSyncAddressees(); 302 //Addressee::List getExternLastSyncAddressees();
302 void resetTempSyncStat(); 303 void resetTempSyncStat();
303 QStringList uidList(); 304 QStringList uidList();
304 void removeSyncAddressees( bool removeDeleted = false ); 305 void removeSyncAddressees( bool removeDeleted = false );
305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 306 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
306 Addressee findByExternUid( const QString& uid , const QString& profile ); 307 Addressee findByExternUid( const QString& uid , const QString& profile );
307 bool containsExternalUid( const QString& uid ); 308 bool containsExternalUid( const QString& uid );
308 309
309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 310 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
310 void postExternSync( AddressBook* aBook, const QString& csd , bool setID ); 311 void postExternSync( AddressBook* aBook, const QString& csd , bool setID );
311 signals: 312 signals:
312 /** 313 /**
313 Emitted, when the address book has changed on disk. 314 Emitted, when the address book has changed on disk.
314 */ 315 */
315 void addressBookChanged( AddressBook * ); 316 void addressBookChanged( AddressBook * );
316 317
317 /** 318 /**
318 Emitted, when the address book has been locked for writing. 319 Emitted, when the address book has been locked for writing.
319 */ 320 */
320 void addressBookLocked( AddressBook * ); 321 void addressBookLocked( AddressBook * );
321 322
322 /** 323 /**
323 Emitted, when the address book has been unlocked. 324 Emitted, when the address book has been unlocked.
324 */ 325 */
325 void addressBookUnlocked( AddressBook * ); 326 void addressBookUnlocked( AddressBook * );
326 327
327 protected: 328 protected:
328 void deleteRemovedAddressees(); 329 void deleteRemovedAddressees();
329 void setStandardResource( Resource * ); 330 void setStandardResource( Resource * );
330 Resource *standardResource(); 331 Resource *standardResource();
331 KRES::Manager<Resource> *resourceManager(); 332 KRES::Manager<Resource> *resourceManager();
332 333
333 void init(const QString &config, const QString &family); 334 void init(const QString &config, const QString &family);
334 335
335 private: 336 private:
336//US QPtrList<Resource> mDummy; // Remove in KDE 4 337//US QPtrList<Resource> mDummy; // Remove in KDE 4
337 338
338 339
339 struct AddressBookData; 340 struct AddressBookData;
340 AddressBookData *d; 341 AddressBookData *d;
341 bool blockLSEchange; 342 bool blockLSEchange;
342}; 343};
343 344
344QDataStream &operator<<( QDataStream &, const AddressBook & ); 345QDataStream &operator<<( QDataStream &, const AddressBook & );
345QDataStream &operator>>( QDataStream &, AddressBook & ); 346QDataStream &operator>>( QDataStream &, AddressBook & );
346 347
347} 348}
348 349
349#endif 350#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3d4992c..028d3bb 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -83,385 +83,385 @@ struct Addressee::AddresseeData : public KShared
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 //if ( !mData->name.isEmpty() ) l.append(mData->name); 212 //if ( !mData->name.isEmpty() ) l.append(mData->name);
213 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); 216 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { 259 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
260 int find = t[iii].find (':')+1; 260 int find = t[iii].find (':')+1;
261 //qDebug("lennnn %d %d ", find, t[iii].length()); 261 //qDebug("lennnn %d %d ", find, t[iii].length());
262 if ( find < t[iii].length()) 262 if ( find < t[iii].length())
263 l.append( t[iii] ); 263 l.append( t[iii] );
264 264
265 } 265 }
266 KABC::Address::List::Iterator addressIter; 266 KABC::Address::List::Iterator addressIter;
267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
268 ++addressIter ) { 268 ++addressIter ) {
269 t = (*addressIter).asList(); 269 t = (*addressIter).asList();
270 t.sort(); 270 t.sort();
271 for ( iii = 0; iii < t.count(); ++iii) 271 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 272 l.append( t[iii] );
273 } 273 }
274 uint cs = getCsum4List(l); 274 uint cs = getCsum4List(l);
275#if 1 275#if 0
276 for ( iii = 0; iii < l.count(); ++iii) 276 for ( iii = 0; iii < l.count(); ++iii)
277 qDebug("%d***%s***",iii,l[iii].latin1()); 277 qDebug("%d***%s***",iii,l[iii].latin1());
278 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 278 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
279#endif 279#endif
280 setCsum( dev, QString::number (cs )); 280 setCsum( dev, QString::number (cs ));
281} 281}
282 282
283void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 283void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
284{ 284{
285 285
286 detach(); 286 detach();
287 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 287 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
288 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 288 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
289 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 289 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
290 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 290 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
291 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 291 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
292 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 292 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
293 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 293 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
294 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 294 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
295 if ( !mData->birthday.isValid() ) 295 if ( !mData->birthday.isValid() )
296 if ( ad.mData->birthday.isValid()) 296 if ( ad.mData->birthday.isValid())
297 mData->birthday = ad.mData->birthday; 297 mData->birthday = ad.mData->birthday;
298 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 298 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
299 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 299 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
300 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 300 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
301 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 301 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
302 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 302 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
303 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 303 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
304 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 304 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
305 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 305 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
306 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 306 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
307 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 307 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
308 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 308 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
309 QStringList t; 309 QStringList t;
310 QStringList tAD; 310 QStringList tAD;
311 uint iii; 311 uint iii;
312 312
313 // ********** phone numbers 313 // ********** phone numbers
314 PhoneNumber::List phoneAD = ad.phoneNumbers(); 314 PhoneNumber::List phoneAD = ad.phoneNumbers();
315 PhoneNumber::List::Iterator phoneItAD; 315 PhoneNumber::List::Iterator phoneItAD;
316 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 316 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
317 bool found = false; 317 bool found = false;
318 PhoneNumber::List::Iterator it; 318 PhoneNumber::List::Iterator it;
319 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 319 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
320 if ( ( *phoneItAD ).contains( (*it) ) ) { 320 if ( ( *phoneItAD ).contains( (*it) ) ) {
321 found = true; 321 found = true;
322 (*it).setType( ( *phoneItAD ).type() ); 322 (*it).setType( ( *phoneItAD ).type() );
323 (*it).setNumber( ( *phoneItAD ).number() ); 323 (*it).setNumber( ( *phoneItAD ).number() );
324 break; 324 break;
325 } 325 }
326 } 326 }
327 if ( isSubSet && ! found ) 327 if ( isSubSet && ! found )
328 mData->phoneNumbers.append( *phoneItAD ); 328 mData->phoneNumbers.append( *phoneItAD );
329 } 329 }
330 if ( isSubSet ) { 330 if ( isSubSet ) {
331 // ************* emails; 331 // ************* emails;
332 t = mData->emails; 332 t = mData->emails;
333 tAD = ad.mData->emails; 333 tAD = ad.mData->emails;
334 for ( iii = 0; iii < tAD.count(); ++iii) 334 for ( iii = 0; iii < tAD.count(); ++iii)
335 if ( !t.contains(tAD[iii] ) ) 335 if ( !t.contains(tAD[iii] ) )
336 mData->emails.append( tAD[iii] ); 336 mData->emails.append( tAD[iii] );
337 } 337 }
338 338
339 // ************* categories; 339 // ************* categories;
340 t = mData->categories; 340 t = mData->categories;
341 tAD = ad.mData->categories; 341 tAD = ad.mData->categories;
342 for ( iii = 0; iii < tAD.count(); ++iii) 342 for ( iii = 0; iii < tAD.count(); ++iii)
343 if ( !t.contains(tAD[iii] ) ) 343 if ( !t.contains(tAD[iii] ) )
344 mData->categories.append( tAD[iii] ); 344 mData->categories.append( tAD[iii] );
345 QStringList::ConstIterator it; 345 QStringList::ConstIterator it;
346 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 346 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
347 QString qualifiedName = (*it).left( (*it).find( ":" )); 347 QString qualifiedName = (*it).left( (*it).find( ":" ));
348 bool found = false; 348 bool found = false;
349 QStringList::ConstIterator itL; 349 QStringList::ConstIterator itL;
350 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 350 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
351 if ( (*itL).startsWith( qualifiedName ) ) { 351 if ( (*itL).startsWith( qualifiedName ) ) {
352 found = true; 352 found = true;
353 break; 353 break;
354 } 354 }
355 } 355 }
356 if ( ! found ) { 356 if ( ! found ) {
357 mData->custom.append( *it ); 357 mData->custom.append( *it );
358 } 358 }
359 } 359 }
360 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 360 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
361 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 361 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
362 if ( !mData->sound.isIntern() ) { 362 if ( !mData->sound.isIntern() ) {
363 if ( mData->sound.url().isEmpty() ) { 363 if ( mData->sound.url().isEmpty() ) {
364 mData->sound = ad.mData->sound; 364 mData->sound = ad.mData->sound;
365 } 365 }
366 } 366 }
367 if ( !mData->agent.isIntern() ) { 367 if ( !mData->agent.isIntern() ) {
368 if ( mData->agent.url().isEmpty() ) { 368 if ( mData->agent.url().isEmpty() ) {
369 mData->agent = ad.mData->agent; 369 mData->agent = ad.mData->agent;
370 } 370 }
371 } 371 }
372 { 372 {
373 Key::List::Iterator itA; 373 Key::List::Iterator itA;
374 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 374 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
375 bool found = false; 375 bool found = false;
376 Key::List::Iterator it; 376 Key::List::Iterator it;
377 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 377 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
378 if ( (*it) == (*itA)) { 378 if ( (*it) == (*itA)) {
379 found = true; 379 found = true;
380 break; 380 break;
381 381
382 } 382 }
383 } 383 }
384 if ( ! found ) { 384 if ( ! found ) {
385 mData->keys.append( *itA ); 385 mData->keys.append( *itA );
386 } 386 }
387 } 387 }
388 } 388 }
389 KABC::Address::List::Iterator addressIterA; 389 KABC::Address::List::Iterator addressIterA;
390 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 390 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
391 bool found = false; 391 bool found = false;
392 KABC::Address::List::Iterator addressIter; 392 KABC::Address::List::Iterator addressIter;
393 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 393 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
394 ++addressIter ) { 394 ++addressIter ) {
395 if ( (*addressIter) == (*addressIterA)) { 395 if ( (*addressIter) == (*addressIterA)) {
396 found = true; 396 found = true;
397 (*addressIter).setType( (*addressIterA).type() ); 397 (*addressIter).setType( (*addressIterA).type() );
398 break; 398 break;
399 } 399 }
400 400
401 } 401 }
402 if ( isSubSet && ! found ) { 402 if ( isSubSet && ! found ) {
403 mData->addresses.append( *addressIterA ); 403 mData->addresses.append( *addressIterA );
404 } 404 }
405 } 405 }
406 //qDebug("merge contact %s ", ad.uid().latin1()); 406 //qDebug("merge contact %s ", ad.uid().latin1());
407 setUid( ad.uid() ); 407 setUid( ad.uid() );
408 setRevision( ad.revision() ); 408 setRevision( ad.revision() );
409} 409}
410 410
411bool Addressee::removeVoice() 411bool Addressee::removeVoice()
412{ 412{
413 PhoneNumber::List phoneN = phoneNumbers(); 413 PhoneNumber::List phoneN = phoneNumbers();
414 PhoneNumber::List::Iterator phoneIt; 414 PhoneNumber::List::Iterator phoneIt;
415 bool found = false; 415 bool found = false;
416 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 416 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
417 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 417 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
418 if ((*phoneIt).type() - PhoneNumber::Voice ) { 418 if ((*phoneIt).type() - PhoneNumber::Voice ) {
419 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 419 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
420 insertPhoneNumber( (*phoneIt) ); 420 insertPhoneNumber( (*phoneIt) );
421 found = true; 421 found = true;
422 } 422 }
423 } 423 }
424 424
425 } 425 }
426 return found; 426 return found;
427} 427}
428 428
429bool Addressee::containsAdr(const Addressee& ad ) 429bool Addressee::containsAdr(const Addressee& ad )
430{ 430{
431 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 431 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
432 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 432 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
433 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 433 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
434 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 434 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
435 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 435 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
436 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 436 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
437 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 437 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
438 438
439 // compare phone numbers 439 // compare phone numbers
440 PhoneNumber::List phoneN = ad.phoneNumbers(); 440 PhoneNumber::List phoneN = ad.phoneNumbers();
441 PhoneNumber::List::Iterator phoneIt; 441 PhoneNumber::List::Iterator phoneIt;
442 bool found = false; 442 bool found = false;
443 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 443 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
444 bool found = false; 444 bool found = false;
445 PhoneNumber::List phoneL = ad.phoneNumbers(); 445 PhoneNumber::List phoneL = ad.phoneNumbers();
446 PhoneNumber::List::Iterator phoneItL; 446 PhoneNumber::List::Iterator phoneItL;
447 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 447 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
448 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 448 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
449 found = true; 449 found = true;
450 break; 450 break;
451 } 451 }
452 } 452 }
453 if ( ! found ) 453 if ( ! found )
454 return false; 454 return false;
455 } 455 }
456 return true; 456 return true;
457 457
458} 458}
459void Addressee::simplifyAddresses() 459void Addressee::simplifyAddresses()
460{ 460{
461 461
462 462
463 Address::List list; 463 Address::List list;
464 Address::List::Iterator it; 464 Address::List::Iterator it;
465 Address::List::Iterator it2; 465 Address::List::Iterator it2;
466 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 466 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
467 it2 = it; 467 it2 = it;
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index ba17c50..48b7d91 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,406 +1,285 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57using namespace KABC; 57using namespace KABC;
58extern "C" 58extern "C"
59{ 59{
60 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
61 { 61 {
62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
63 } 63 }
64} 64}
65 65
66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67 : Resource( config ), mConverter (0) 67 : Resource( config ), mConverter (0)
68{ 68{
69 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
70 70 mAccess = 0;
71 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
76 : Resource( 0 ) 76 : Resource( 0 )
77{ 77{
78 init( fileName ); 78 mAccess = 0;
79 init( fileName );
79} 80}
80 81
81void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
82{ 83{
83
84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
87
88 setFileName( fileName ); 84 setFileName( fileName );
89} 85}
90 86
91ResourceSharpDTM::~ResourceSharpDTM() 87ResourceSharpDTM::~ResourceSharpDTM()
92{ 88{
93 if (mConverter != 0) 89 if (mConverter != 0)
94 delete mConverter; 90 delete mConverter;
95 91
96 if(mAccess != 0) 92 if(mAccess != 0)
97 delete mAccess; 93 delete mAccess;
98} 94}
99 95
100void ResourceSharpDTM::writeConfig( KConfig *config ) 96void ResourceSharpDTM::writeConfig( KConfig *config )
101{ 97{
102 Resource::writeConfig( config ); 98 Resource::writeConfig( config );
103} 99}
104 100
105Ticket *ResourceSharpDTM::requestSaveTicket() 101Ticket *ResourceSharpDTM::requestSaveTicket()
106{ 102{
107
108 103
109 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 104 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
110 105
111 if ( !addressBook() ) return 0; 106 if ( !addressBook() ) return 0;
112
113#ifdef ALLOW_LOCKING
114 if ( !lock( fileName() ) ) {
115 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
116 return 0;
117 }
118#endif
119 return createTicket( this ); 107 return createTicket( this );
120} 108}
121 109
122 110
123bool ResourceSharpDTM::doOpen() 111bool ResourceSharpDTM::doOpen()
124{ 112{
125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 113 qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1());
126
127 // the last parameter in the SlZDataBase constructor means "readonly"
128 mAccess = new SlZDataBase(fileName(),
129 SlZDataBase::addressbookItems(),
130 NULL, false);
131 114
132 if ( !mAccess ) { 115 if ( ! mAccess ) {
133 qDebug("Unable to load file() %s", fileName().latin1()); 116 // the last parameter in the SlZDataBase constructor means "readonly"
134 return false; 117 mAccess = new SlZDataBase(fileName(),
135 } 118 SlZDataBase::addressbookItems(),
136 119 NULL, false);
137 if (mConverter == 0)
138 {
139 mConverter = new SharpDTMConverter();
140 bool res = mConverter->init();
141 if ( !res )
142 {
143 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
144
145 qDebug(msg);
146 delete mAccess;
147 mAccess = 0;
148 return false;
149 } 120 }
150 } 121 if ( !mAccess ) {
151 122 qDebug("Unable to load file() %s", fileName().latin1());
152 return true; 123 return false;
124 }
125 if (mConverter == 0) {
126 mConverter = new SharpDTMConverter();
127 bool res = mConverter->init();
128 if ( !res )
129 {
130 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
131 qDebug(msg);
132 delete mAccess;
133 mAccess = 0;
134 return false;
135 }
136 }
137 return true;
153} 138}
154 139
155void ResourceSharpDTM::doClose() 140void ResourceSharpDTM::doClose()
156{ 141{
157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
158
159 if(mAccess)
160 {
161 delete mAccess;
162 mAccess = 0;
163 }
164 // it seems so, that deletion of access deletes backend as well
165 //delete backend;
166
167 return; 142 return;
168} 143}
169 144
170bool ResourceSharpDTM::load() 145bool ResourceSharpDTM::load()
171{ 146{
172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 147 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1());
173 148 bool res = false;
174 bool res = false; 149 CardId id;
175 150 for (bool res=mAccess->first(); res == true; res=mAccess->next())
176 CardId id; 151 {
177 152 id = mAccess->cardId();
178 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 153 KABC::Addressee addressee;
179 { 154 res = mConverter->sharpToAddressee( id, mAccess, addressee );
180 id = mAccess->cardId(); 155 if ( !addressee.isEmpty() && res )
181 156 {
182 KABC::Addressee addressee; 157 addressee.setResource( this );
183 158 addressBook()->insertAddressee( addressee );
184 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 159 }
185 160 }
186 if ( !addressee.isEmpty() && res ) 161 return true;
187 {
188 addressee.setResource( this );
189 addressBook()->insertAddressee( addressee );
190 }
191 }
192
193 return true;
194} 162}
195 163
196bool ResourceSharpDTM::save( Ticket *ticket ) 164bool ResourceSharpDTM::save( Ticket *ticket )
197{ 165{
198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 166 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
199
200 mDirWatch.stopScan();
201
202 KABC::AddressBook::Iterator it; 167 KABC::AddressBook::Iterator it;
203 bool res; 168 bool res;
204 KABC::Addressee::List changedAddressees; 169 KABC::Addressee::List changedAddressees;
205 typedef QMap<int,QString> AddresseeMap; 170 typedef QMap<int,QString> AddresseeMap;
206 AddresseeMap map; 171 AddresseeMap map;
207 CardId id ; 172 CardId id ;
208
209 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 173 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
210 174
211 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 175 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
212 QString uid = (*it).originalExternalUID(); 176 QString uid = (*it).originalExternalUID();
213 bool res; 177 bool res;
214 if ( uid.isEmpty() ) 178 if ( uid.isEmpty() )
215 id = 0; 179 id = 0;
216 else 180 else
217 id = uid.toUInt(); 181 id = uid.toUInt();
218 KABC::Addressee addressee = (*it); 182 KABC::Addressee addressee = (*it);
219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 183 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
220 res = mAccess->startEditCard(id); 184 res = mAccess->startEditCard(id);
221 if (res == true) 185 if (res == true)
222 { 186 {
223 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 187 res = mConverter->addresseeToSharp( (*it), mAccess, id );
224 if (res == true) 188 if (res == true)
225 { 189 {
226 res = mAccess->finishEditCard(&id); 190 res = mAccess->finishEditCard(&id);;
227 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
228 //(*it).setExternalUID( QString::number( id ) );
229 //(*it).setOriginalExternalUID( QString::number( id ) );
230 map.insert(id,(*it).uid()); 191 map.insert(id,(*it).uid());
231 if (res == false) 192 if (res == false)
232 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 193 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
233 194
234 } 195 }
235 else 196 else
236 { 197 {
237 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 198 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
238 mAccess->cancelEditCard(); 199 mAccess->cancelEditCard();
239 } 200 }
240 } 201 }
241 202
242 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 203 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
243 res = mAccess->deleteCard(&id); 204 res = mAccess->deleteCard(&id);
244 if ( !res ) 205 if ( !res )
245 qDebug("delete error "); 206 qDebug("delete error ");
246 207
247 208
248 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 209 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
249 //changed 210 //changed
250 res = mAccess->startEditCard(id); 211 res = mAccess->startEditCard(id);
251 if (res == true) 212 if (res == true)
252 { 213 {
253 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 214 res = mConverter->addresseeToSharp( (*it), mAccess, id );
254 if (res == true) 215 if (res == true)
255 { 216 {
256 res = mAccess->finishEditCard(&id); 217 res = mAccess->finishEditCard(&id);
257 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
258 map.insert(id,(*it).uid()); 218 map.insert(id,(*it).uid());
259 if (res == false) 219 if (res == false)
260 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 220 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
261
262 } 221 }
263 else 222 else
264 { 223 {
265 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 224 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
266 mAccess->cancelEditCard(); 225 mAccess->cancelEditCard();
267 } 226 }
268 } 227 }
269 } 228 }
270 } 229 }
271 230
272 } 231 }
273 AddresseeMap::Iterator itam; 232 AddresseeMap::Iterator itam;
274 for ( res=mAccess->first(); res == true; res=mAccess->next()) 233 for ( res=mAccess->first(); res == true; res=mAccess->next())
275 { 234 {
276 id = mAccess->cardId(); 235 id = mAccess->cardId();
277 int idint = id; 236 int idint = id;
278 itam = map.find( idint ); 237 itam = map.find( idint );
279 if ( itam != map.end() ) { 238 if ( itam != map.end() ) {
280 KABC::Addressee addressee; 239 KABC::Addressee addressee;
281 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 240 res = mConverter->sharpToAddressee( id, mAccess, addressee );
282 241
283 if ( !addressee.isEmpty() && res ) 242 if ( !addressee.isEmpty() && res )
284 { 243 {
285 addressee.setResource( this ); 244 addressee.setResource( this );
286 addressee.setUid( itam.data() ); 245 addressee.setUid( itam.data() );
287 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 246 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
288 addressBook()->insertAddressee( addressee , false ); 247 addressBook()->insertAddressee( addressee , false );
289 } 248 }
290 } 249 }
291 } 250 }
292
293 //US mAccess->save();
294
295 mDirWatch.startScan();
296 delete ticket; 251 delete ticket;
297 unlock( fileName() );
298 252
299 return true; 253 return true;
300} 254}
301 255
302bool ResourceSharpDTM::lock( const QString &lockfileName ) 256bool ResourceSharpDTM::lock( const QString &lockfileName )
303{ 257{
304#ifdef ALLOW_LOCKING
305 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
306
307 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
308
309 QString fn = lockfileName;
310
311 KURL url(fn);
312 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
313
314 kdDebug(5700) << "-- lock name: " << lockName << endl;
315
316 if (QFile::exists( lockName ))
317 {
318 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
319 return false;
320 }
321
322
323 QString lockUniqueName;
324 lockUniqueName = fn + KApplication::randomString( 8 );
325
326 url = lockUniqueName;
327//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
328 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
329 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
330
331 // Create unique file
332 QFile file( mLockUniqueName );
333 file.open( IO_WriteOnly );
334 file.close();
335
336 // Create lock file
337 int result = 0;
338#ifndef _WIN32_
339 result = ::link( QFile::encodeName( mLockUniqueName ),
340 QFile::encodeName( lockName ) );
341#endif
342 if ( result == 0 ) {
343 addressBook()->emitAddressBookLocked();
344 return true;
345 }
346
347 // TODO: check stat
348
349 return false;
350#else
351 return true;
352#endif
353} 258}
354 259
355void ResourceSharpDTM::unlock( const QString &fileName ) 260void ResourceSharpDTM::unlock( const QString &fileName )
356{ 261{
357#ifdef ALLOW_LOCKING
358 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
359 262
360 QString fn = fileName;
361 KURL url(fn);
362 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
363
364 QFile::remove( lockName );
365 QFile::remove( mLockUniqueName );
366 addressBook()->emitAddressBookUnlocked();
367#endif
368} 263}
369 264
370void ResourceSharpDTM::setFileName( const QString &newFileName ) 265void ResourceSharpDTM::setFileName( const QString &newFileName )
371{ 266{
372 mDirWatch.stopScan(); 267 Resource::setFileName( newFileName );
373 mDirWatch.removeFile( fileName() );
374
375 Resource::setFileName( newFileName );
376
377 mDirWatch.addFile( fileName() );
378 mDirWatch.startScan();
379
380} 268}
381 269
382void ResourceSharpDTM::fileChanged() 270void ResourceSharpDTM::fileChanged()
383{ 271{
384 // There is a small theoretical chance that KDirWatch calls us before 272
385 // we are fully constructed
386 if (!addressBook())
387 return;
388
389 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
391 load();
392 addressBook()->emitAddressBookChanged();
393 }
394} 273}
395 274
396void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 275void ResourceSharpDTM::removeAddressee( const Addressee &addr )
397{ 276{
398} 277}
399 278
400void ResourceSharpDTM::cleanUp() 279void ResourceSharpDTM::cleanUp()
401{ 280{
402 unlock( fileName() ); 281 unlock( fileName() );
403} 282}
404 283
405 284
406 285
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp
index 6e24302..cfa57e3 100644
--- a/kabc/tmpaddressbook.cpp
+++ b/kabc/tmpaddressbook.cpp
@@ -1,56 +1,49 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#include <qptrlist.h> 27#include <qptrlist.h>
28 28
29#include "tmpaddressbook.h" 29#include "tmpaddressbook.h"
30 30
31using namespace KABC; 31using namespace KABC;
32 32
33#include "resource.h" 33#include "resource.h"
34 34
35TmpAddressBook::TmpAddressBook() 35TmpAddressBook::TmpAddressBook()
36 : AddressBook(0, "tmpcontact") 36 : AddressBook(0, "tmpcontact")
37{ 37{
38} 38}
39 39
40TmpAddressBook::TmpAddressBook( const QString &config ) 40TmpAddressBook::TmpAddressBook( const QString &config )
41 : AddressBook( config, "tmpcontact" ) 41 : AddressBook( config, "tmpcontact" )
42{ 42{
43} 43}
44 44
45TmpAddressBook::~TmpAddressBook() 45TmpAddressBook::~TmpAddressBook()
46{ 46{
47 //remove all possible resources. This should cleanup the configfile. 47 removeResources();
48 QPtrList<KABC::Resource> mResources = resources();
49
50 QPtrListIterator<KABC::Resource> it(mResources);
51 for ( ; it.current(); ++it ) {
52 KABC::Resource *res = it.current();
53 removeResource(res);
54 }
55} 48}
56 49
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 6e482b5..e6bdde9 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2053,920 +2053,923 @@ void KABCore::addActionsManually()
2053 mActionFaq->plug( helpMenu ); 2053 mActionFaq->plug( helpMenu );
2054 mActionLicence->plug( helpMenu ); 2054 mActionLicence->plug( helpMenu );
2055 mActionAboutKAddressbook->plug( helpMenu ); 2055 mActionAboutKAddressbook->plug( helpMenu );
2056 2056
2057 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2057 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2058 2058
2059 mActionSave->plug( tb ); 2059 mActionSave->plug( tb );
2060 mViewManager->getFilterAction()->plug ( tb); 2060 mViewManager->getFilterAction()->plug ( tb);
2061 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2061 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2062 mActionUndo->plug( tb ); 2062 mActionUndo->plug( tb );
2063 mActionDelete->plug( tb ); 2063 mActionDelete->plug( tb );
2064 mActionRedo->plug( tb ); 2064 mActionRedo->plug( tb );
2065 } 2065 }
2066 } else { 2066 } else {
2067 mActionSave->plug( tb ); 2067 mActionSave->plug( tb );
2068 tb->enableMoving(false); 2068 tb->enableMoving(false);
2069 } 2069 }
2070 //mActionQuit->plug ( tb ); 2070 //mActionQuit->plug ( tb );
2071 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2071 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2072 2072
2073 //US link the searchwidget first to this. 2073 //US link the searchwidget first to this.
2074 // The real linkage to the toolbar happens later. 2074 // The real linkage to the toolbar happens later.
2075//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2075//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2076//US tb->insertItem( mIncSearchWidget ); 2076//US tb->insertItem( mIncSearchWidget );
2077/*US 2077/*US
2078 mIncSearchWidget = new IncSearchWidget( tb ); 2078 mIncSearchWidget = new IncSearchWidget( tb );
2079 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2079 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2080 SLOT( incrementalSearch( const QString& ) ) ); 2080 SLOT( incrementalSearch( const QString& ) ) );
2081 2081
2082 mJumpButtonBar = new JumpButtonBar( this, this ); 2082 mJumpButtonBar = new JumpButtonBar( this, this );
2083 2083
2084//US topLayout->addWidget( mJumpButtonBar ); 2084//US topLayout->addWidget( mJumpButtonBar );
2085 this->layout()->add( mJumpButtonBar ); 2085 this->layout()->add( mJumpButtonBar );
2086*/ 2086*/
2087 2087
2088#endif //KAB_EMBEDDED 2088#endif //KAB_EMBEDDED
2089 2089
2090 mActionExport2phone->plug( ExportMenu ); 2090 mActionExport2phone->plug( ExportMenu );
2091 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2091 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2092 syncManager->fillSyncMenu(); 2092 syncManager->fillSyncMenu();
2093 2093
2094} 2094}
2095void KABCore::showLicence() 2095void KABCore::showLicence()
2096{ 2096{
2097 KApplication::showLicence(); 2097 KApplication::showLicence();
2098} 2098}
2099void KABCore::removeVoice() 2099void KABCore::removeVoice()
2100{ 2100{
2101 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 2101 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
2102 return; 2102 return;
2103 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2103 KABC::Addressee::List list = mViewManager->selectedAddressees();
2104 KABC::Addressee::List::Iterator it; 2104 KABC::Addressee::List::Iterator it;
2105 for ( it = list.begin(); it != list.end(); ++it ) { 2105 for ( it = list.begin(); it != list.end(); ++it ) {
2106 2106
2107 if ( (*it).removeVoice() ) 2107 if ( (*it).removeVoice() )
2108 contactModified((*it) ); 2108 contactModified((*it) );
2109 } 2109 }
2110} 2110}
2111 2111
2112 2112
2113 2113
2114void KABCore::clipboardDataChanged() 2114void KABCore::clipboardDataChanged()
2115{ 2115{
2116 2116
2117 if ( mReadWrite ) 2117 if ( mReadWrite )
2118 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2118 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2119 2119
2120} 2120}
2121 2121
2122void KABCore::updateActionMenu() 2122void KABCore::updateActionMenu()
2123{ 2123{
2124 UndoStack *undo = UndoStack::instance(); 2124 UndoStack *undo = UndoStack::instance();
2125 RedoStack *redo = RedoStack::instance(); 2125 RedoStack *redo = RedoStack::instance();
2126 2126
2127 if ( undo->isEmpty() ) 2127 if ( undo->isEmpty() )
2128 mActionUndo->setText( i18n( "Undo" ) ); 2128 mActionUndo->setText( i18n( "Undo" ) );
2129 else 2129 else
2130 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2130 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2131 2131
2132 mActionUndo->setEnabled( !undo->isEmpty() ); 2132 mActionUndo->setEnabled( !undo->isEmpty() );
2133 2133
2134 if ( !redo->top() ) 2134 if ( !redo->top() )
2135 mActionRedo->setText( i18n( "Redo" ) ); 2135 mActionRedo->setText( i18n( "Redo" ) );
2136 else 2136 else
2137 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2137 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2138 2138
2139 mActionRedo->setEnabled( !redo->isEmpty() ); 2139 mActionRedo->setEnabled( !redo->isEmpty() );
2140} 2140}
2141 2141
2142void KABCore::configureKeyBindings() 2142void KABCore::configureKeyBindings()
2143{ 2143{
2144#ifndef KAB_EMBEDDED 2144#ifndef KAB_EMBEDDED
2145 KKeyDialog::configure( actionCollection(), true ); 2145 KKeyDialog::configure( actionCollection(), true );
2146#else //KAB_EMBEDDED 2146#else //KAB_EMBEDDED
2147 qDebug("KABCore::configureKeyBindings() not implemented"); 2147 qDebug("KABCore::configureKeyBindings() not implemented");
2148#endif //KAB_EMBEDDED 2148#endif //KAB_EMBEDDED
2149} 2149}
2150 2150
2151#ifdef KAB_EMBEDDED 2151#ifdef KAB_EMBEDDED
2152void KABCore::configureResources() 2152void KABCore::configureResources()
2153{ 2153{
2154 KRES::KCMKResources dlg( this, "" , 0 ); 2154 KRES::KCMKResources dlg( this, "" , 0 );
2155 2155
2156 if ( !dlg.exec() ) 2156 if ( !dlg.exec() )
2157 return; 2157 return;
2158 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2158 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2159} 2159}
2160#endif //KAB_EMBEDDED 2160#endif //KAB_EMBEDDED
2161 2161
2162 2162
2163/* this method will be called through the QCop interface from Ko/Pi to select addresses 2163/* this method will be called through the QCop interface from Ko/Pi to select addresses
2164 * for the attendees list of an event. 2164 * for the attendees list of an event.
2165 */ 2165 */
2166void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2166void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2167{ 2167{
2168 QStringList nameList; 2168 QStringList nameList;
2169 QStringList emailList; 2169 QStringList emailList;
2170 QStringList uidList; 2170 QStringList uidList;
2171 2171
2172 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2172 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2173 uint i=0; 2173 uint i=0;
2174 for (i=0; i < list.count(); i++) 2174 for (i=0; i < list.count(); i++)
2175 { 2175 {
2176 nameList.append(list[i].realName()); 2176 nameList.append(list[i].realName());
2177 emailList.append(list[i].preferredEmail()); 2177 emailList.append(list[i].preferredEmail());
2178 uidList.append(list[i].uid()); 2178 uidList.append(list[i].uid());
2179 } 2179 }
2180 2180
2181 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2181 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2182 2182
2183} 2183}
2184 2184
2185/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2185/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2186 * to put them into the calendar. 2186 * to put them into the calendar.
2187 */ 2187 */
2188void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2188void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2189{ 2189{
2190 // qDebug("KABCore::requestForBirthdayList"); 2190 // qDebug("KABCore::requestForBirthdayList");
2191 QStringList birthdayList; 2191 QStringList birthdayList;
2192 QStringList anniversaryList; 2192 QStringList anniversaryList;
2193 QStringList realNameList; 2193 QStringList realNameList;
2194 QStringList preferredEmailList; 2194 QStringList preferredEmailList;
2195 QStringList assembledNameList; 2195 QStringList assembledNameList;
2196 QStringList uidList; 2196 QStringList uidList;
2197 2197
2198 KABC::AddressBook::Iterator it; 2198 KABC::AddressBook::Iterator it;
2199 2199
2200 int count = 0; 2200 int count = 0;
2201 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2201 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2202 ++count; 2202 ++count;
2203 } 2203 }
2204 QProgressBar bar(count,0 ); 2204 QProgressBar bar(count,0 );
2205 int w = 300; 2205 int w = 300;
2206 if ( QApplication::desktop()->width() < 320 ) 2206 if ( QApplication::desktop()->width() < 320 )
2207 w = 220; 2207 w = 220;
2208 int h = bar.sizeHint().height() ; 2208 int h = bar.sizeHint().height() ;
2209 int dw = QApplication::desktop()->width(); 2209 int dw = QApplication::desktop()->width();
2210 int dh = QApplication::desktop()->height(); 2210 int dh = QApplication::desktop()->height();
2211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2212 bar.show(); 2212 bar.show();
2213 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2213 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2214 qApp->processEvents(); 2214 qApp->processEvents();
2215 2215
2216 QDate bday; 2216 QDate bday;
2217 QString anni; 2217 QString anni;
2218 QString formattedbday; 2218 QString formattedbday;
2219 2219
2220 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2220 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2221 { 2221 {
2222 if ( ! bar.isVisible() ) 2222 if ( ! bar.isVisible() )
2223 return; 2223 return;
2224 bar.setProgress( count++ ); 2224 bar.setProgress( count++ );
2225 qApp->processEvents(); 2225 qApp->processEvents();
2226 bday = (*it).birthday().date(); 2226 bday = (*it).birthday().date();
2227 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2227 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2228 2228
2229 if ( bday.isValid() || !anni.isEmpty()) 2229 if ( bday.isValid() || !anni.isEmpty())
2230 { 2230 {
2231 if (bday.isValid()) 2231 if (bday.isValid())
2232 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2232 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2233 else 2233 else
2234 formattedbday = "NOTVALID"; 2234 formattedbday = "NOTVALID";
2235 if (anni.isEmpty()) 2235 if (anni.isEmpty())
2236 anni = "INVALID"; 2236 anni = "INVALID";
2237 2237
2238 birthdayList.append(formattedbday); 2238 birthdayList.append(formattedbday);
2239 anniversaryList.append(anni); //should be ISODate 2239 anniversaryList.append(anni); //should be ISODate
2240 realNameList.append((*it).realName()); 2240 realNameList.append((*it).realName());
2241 preferredEmailList.append((*it).preferredEmail()); 2241 preferredEmailList.append((*it).preferredEmail());
2242 assembledNameList.append((*it).assembledName()); 2242 assembledNameList.append((*it).assembledName());
2243 uidList.append((*it).uid()); 2243 uidList.append((*it).uid());
2244 2244
2245 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2245 //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2246 } 2246 }
2247 } 2247 }
2248 2248
2249 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2249 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2250 2250
2251} 2251}
2252 2252
2253/* this method will be called through the QCop interface from other apps to show details of a contact. 2253/* this method will be called through the QCop interface from other apps to show details of a contact.
2254 */ 2254 */
2255void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2255void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2256{ 2256{
2257 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2257 //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2258 2258
2259 QString foundUid = QString::null; 2259 QString foundUid = QString::null;
2260 if ( ! uid.isEmpty() ) { 2260 if ( ! uid.isEmpty() ) {
2261 Addressee adrr = mAddressBook->findByUid( uid ); 2261 Addressee adrr = mAddressBook->findByUid( uid );
2262 if ( !adrr.isEmpty() ) { 2262 if ( !adrr.isEmpty() ) {
2263 foundUid = uid; 2263 foundUid = uid;
2264 } 2264 }
2265 if ( email == "sendbacklist" ) { 2265 if ( email == "sendbacklist" ) {
2266 //qDebug("ssssssssssssssssssssssend "); 2266 //qDebug("ssssssssssssssssssssssend ");
2267 QStringList nameList; 2267 QStringList nameList;
2268 QStringList emailList; 2268 QStringList emailList;
2269 QStringList uidList; 2269 QStringList uidList;
2270 nameList.append(adrr.realName()); 2270 nameList.append(adrr.realName());
2271 emailList = adrr.emails(); 2271 emailList = adrr.emails();
2272 uidList.append( adrr.preferredEmail()); 2272 uidList.append( adrr.preferredEmail());
2273 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2273 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2274 return; 2274 return;
2275 } 2275 }
2276 2276
2277 } 2277 }
2278 2278
2279 if ( email == "sendbacklist" ) 2279 if ( email == "sendbacklist" )
2280 return; 2280 return;
2281 if (foundUid.isEmpty()) 2281 if (foundUid.isEmpty())
2282 { 2282 {
2283 //find the uid of the person first 2283 //find the uid of the person first
2284 Addressee::List namelist; 2284 Addressee::List namelist;
2285 Addressee::List emaillist; 2285 Addressee::List emaillist;
2286 2286
2287 if (!name.isEmpty()) 2287 if (!name.isEmpty())
2288 namelist = mAddressBook->findByName( name ); 2288 namelist = mAddressBook->findByName( name );
2289 2289
2290 if (!email.isEmpty()) 2290 if (!email.isEmpty())
2291 emaillist = mAddressBook->findByEmail( email ); 2291 emaillist = mAddressBook->findByEmail( email );
2292 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2292 //qDebug("count %d %d ", namelist.count(),emaillist.count() );
2293 //check if we have a match in Namelist and Emaillist 2293 //check if we have a match in Namelist and Emaillist
2294 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2294 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2295 foundUid = emaillist[0].uid(); 2295 foundUid = emaillist[0].uid();
2296 } 2296 }
2297 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2297 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2298 foundUid = namelist[0].uid(); 2298 foundUid = namelist[0].uid();
2299 else 2299 else
2300 { 2300 {
2301 for (int i = 0; i < namelist.count(); i++) 2301 for (int i = 0; i < namelist.count(); i++)
2302 { 2302 {
2303 for (int j = 0; j < emaillist.count(); j++) 2303 for (int j = 0; j < emaillist.count(); j++)
2304 { 2304 {
2305 if (namelist[i] == emaillist[j]) 2305 if (namelist[i] == emaillist[j])
2306 { 2306 {
2307 foundUid = namelist[i].uid(); 2307 foundUid = namelist[i].uid();
2308 } 2308 }
2309 } 2309 }
2310 } 2310 }
2311 } 2311 }
2312 } 2312 }
2313 else 2313 else
2314 { 2314 {
2315 foundUid = uid; 2315 foundUid = uid;
2316 } 2316 }
2317 2317
2318 if (!foundUid.isEmpty()) 2318 if (!foundUid.isEmpty())
2319 { 2319 {
2320 2320
2321 // raise Ka/Pi if it is in the background 2321 // raise Ka/Pi if it is in the background
2322#ifndef DESKTOP_VERSION 2322#ifndef DESKTOP_VERSION
2323#ifndef KORG_NODCOP 2323#ifndef KORG_NODCOP
2324 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2324 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2325#endif 2325#endif
2326#endif 2326#endif
2327 2327
2328 mMainWindow->showMaximized(); 2328 mMainWindow->showMaximized();
2329 mMainWindow-> raise(); 2329 mMainWindow-> raise();
2330 2330
2331 mViewManager->setSelected( "", false); 2331 mViewManager->setSelected( "", false);
2332 mViewManager->refreshView( "" ); 2332 mViewManager->refreshView( "" );
2333 mViewManager->setSelected( foundUid, true ); 2333 mViewManager->setSelected( foundUid, true );
2334 mViewManager->refreshView( foundUid ); 2334 mViewManager->refreshView( foundUid );
2335 2335
2336 if ( !mMultipleViewsAtOnce ) 2336 if ( !mMultipleViewsAtOnce )
2337 { 2337 {
2338 setDetailsVisible( true ); 2338 setDetailsVisible( true );
2339 mActionDetails->setChecked(true); 2339 mActionDetails->setChecked(true);
2340 } 2340 }
2341 } 2341 }
2342} 2342}
2343 2343
2344void KABCore::whatsnew() 2344void KABCore::whatsnew()
2345{ 2345{
2346 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2346 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2347} 2347}
2348void KABCore::synchowto() 2348void KABCore::synchowto()
2349{ 2349{
2350 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2350 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2351} 2351}
2352void KABCore::kdesynchowto() 2352void KABCore::kdesynchowto()
2353{ 2353{
2354 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); 2354 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" );
2355} 2355}
2356void KABCore::multisynchowto() 2356void KABCore::multisynchowto()
2357{ 2357{
2358 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); 2358 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" );
2359} 2359}
2360void KABCore::faq() 2360void KABCore::faq()
2361{ 2361{
2362 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2362 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2363} 2363}
2364 2364
2365#include <libkcal/syncdefines.h> 2365#include <libkcal/syncdefines.h>
2366 2366
2367KABC::Addressee KABCore::getLastSyncAddressee() 2367KABC::Addressee KABCore::getLastSyncAddressee()
2368{ 2368{
2369 Addressee lse; 2369 Addressee lse;
2370 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2370 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2371 2371
2372 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2372 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2373 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2373 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2374 if (lse.isEmpty()) { 2374 if (lse.isEmpty()) {
2375 qDebug("Creating new last-syncAddressee "); 2375 qDebug("Creating new last-syncAddressee ");
2376 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2376 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2377 QString sum = ""; 2377 QString sum = "";
2378 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2378 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2379 sum = "E: "; 2379 sum = "E: ";
2380 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2380 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2381 lse.setRevision( mLastAddressbookSync ); 2381 lse.setRevision( mLastAddressbookSync );
2382 lse.setCategories( i18n("SyncEvent") ); 2382 lse.setCategories( i18n("SyncEvent") );
2383 mAddressBook->insertAddressee( lse ); 2383 mAddressBook->insertAddressee( lse );
2384 } 2384 }
2385 return lse; 2385 return lse;
2386} 2386}
2387int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2387int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2388{ 2388{
2389 2389
2390 //void setZaurusId(int id); 2390 //void setZaurusId(int id);
2391 // int zaurusId() const; 2391 // int zaurusId() const;
2392 // void setZaurusUid(int id); 2392 // void setZaurusUid(int id);
2393 // int zaurusUid() const; 2393 // int zaurusUid() const;
2394 // void setZaurusStat(int id); 2394 // void setZaurusStat(int id);
2395 // int zaurusStat() const; 2395 // int zaurusStat() const;
2396 // 0 equal 2396 // 0 equal
2397 // 1 take local 2397 // 1 take local
2398 // 2 take remote 2398 // 2 take remote
2399 // 3 cancel 2399 // 3 cancel
2400 QDateTime lastSync = mLastAddressbookSync; 2400 QDateTime lastSync = mLastAddressbookSync;
2401 QDateTime localMod = local->revision(); 2401 QDateTime localMod = local->revision();
2402 QDateTime remoteMod = remote->revision(); 2402 QDateTime remoteMod = remote->revision();
2403 2403
2404 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2404 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2405 2405
2406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2407 bool remCh, locCh; 2407 bool remCh, locCh;
2408 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2408 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2409 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2409 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2410 locCh = ( localMod > mLastAddressbookSync ); 2410 locCh = ( localMod > mLastAddressbookSync );
2411 if ( !remCh && ! locCh ) { 2411 if ( !remCh && ! locCh ) {
2412 qDebug("both not changed "); 2412 //qDebug("both not changed ");
2413 lastSync = localMod.addDays(1); 2413 lastSync = localMod.addDays(1);
2414 if ( mode <= SYNC_PREF_ASK ) 2414 if ( mode <= SYNC_PREF_ASK )
2415 return 0; 2415 return 0;
2416 } else { 2416 } else {
2417 if ( locCh ) { 2417 if ( locCh ) {
2418 qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2418 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2419 lastSync = localMod.addDays( -1 ); 2419 lastSync = localMod.addDays( -1 );
2420 if ( !remCh ) 2420 if ( !remCh )
2421 remoteMod =( lastSync.addDays( -1 ) ); 2421 remoteMod =( lastSync.addDays( -1 ) );
2422 } else { 2422 } else {
2423 qDebug(" not loc changed "); 2423 //qDebug(" not loc changed ");
2424 lastSync = localMod.addDays( 1 ); 2424 lastSync = localMod.addDays( 1 );
2425 if ( remCh ) { 2425 if ( remCh ) {
2426 qDebug("rem changed "); 2426 //qDebug("rem changed ");
2427 remoteMod =( lastSync.addDays( 1 ) ); 2427 remoteMod =( lastSync.addDays( 1 ) );
2428 } 2428 }
2429 2429
2430 } 2430 }
2431 } 2431 }
2432 full = true; 2432 full = true;
2433 if ( mode < SYNC_PREF_ASK ) 2433 if ( mode < SYNC_PREF_ASK )
2434 mode = SYNC_PREF_ASK; 2434 mode = SYNC_PREF_ASK;
2435 } else { 2435 } else {
2436 if ( localMod == remoteMod ) 2436 if ( localMod == remoteMod )
2437 return 0; 2437 return 0;
2438 2438
2439 } 2439 }
2440 qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); 2440 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
2441 qDebug("lastsync %s ", lastSync.toString().latin1() ); 2441 //qDebug("lastsync %s ", lastSync.toString().latin1() );
2442 //full = true; //debug only 2442 //full = true; //debug only
2443 if ( full ) { 2443 if ( full ) {
2444 bool equ = ( (*local) == (*remote) ); 2444 bool equ = ( (*local) == (*remote) );
2445 if ( equ ) { 2445 if ( equ ) {
2446 qDebug("equal "); 2446 //qDebug("equal ");
2447 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2447 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2448 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2448 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2449 } 2449 }
2450 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2450 if ( mode < SYNC_PREF_FORCE_LOCAL )
2451 return 0; 2451 return 0;
2452 2452
2453 }//else //debug only 2453 }//else //debug only
2454 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2454 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2455 } 2455 }
2456 int result; 2456 int result;
2457 bool localIsNew; 2457 bool localIsNew;
2458 //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() ); 2458 //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() );
2459 2459
2460 if ( full && mode < SYNC_PREF_NEWEST ) 2460 if ( full && mode < SYNC_PREF_NEWEST )
2461 mode = SYNC_PREF_ASK; 2461 mode = SYNC_PREF_ASK;
2462 2462
2463 switch( mode ) { 2463 switch( mode ) {
2464 case SYNC_PREF_LOCAL: 2464 case SYNC_PREF_LOCAL:
2465 if ( lastSync > remoteMod ) 2465 if ( lastSync > remoteMod )
2466 return 1; 2466 return 1;
2467 if ( lastSync > localMod ) 2467 if ( lastSync > localMod )
2468 return 2; 2468 return 2;
2469 return 1; 2469 return 1;
2470 break; 2470 break;
2471 case SYNC_PREF_REMOTE: 2471 case SYNC_PREF_REMOTE:
2472 if ( lastSync > remoteMod ) 2472 if ( lastSync > remoteMod )
2473 return 1; 2473 return 1;
2474 if ( lastSync > localMod ) 2474 if ( lastSync > localMod )
2475 return 2; 2475 return 2;
2476 return 2; 2476 return 2;
2477 break; 2477 break;
2478 case SYNC_PREF_NEWEST: 2478 case SYNC_PREF_NEWEST:
2479 if ( localMod > remoteMod ) 2479 if ( localMod > remoteMod )
2480 return 1; 2480 return 1;
2481 else 2481 else
2482 return 2; 2482 return 2;
2483 break; 2483 break;
2484 case SYNC_PREF_ASK: 2484 case SYNC_PREF_ASK:
2485 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2485 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2486 if ( lastSync > remoteMod ) 2486 if ( lastSync > remoteMod )
2487 return 1; 2487 return 1;
2488 if ( lastSync > localMod ) 2488 if ( lastSync > localMod )
2489 return 2; 2489 return 2;
2490 localIsNew = localMod >= remoteMod; 2490 localIsNew = localMod >= remoteMod;
2491 //qDebug("conflict! ************************************** "); 2491 //qDebug("conflict! ************************************** ");
2492 { 2492 {
2493 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2493 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2494 result = acd.executeD(localIsNew); 2494 result = acd.executeD(localIsNew);
2495 return result; 2495 return result;
2496 } 2496 }
2497 break; 2497 break;
2498 case SYNC_PREF_FORCE_LOCAL: 2498 case SYNC_PREF_FORCE_LOCAL:
2499 return 1; 2499 return 1;
2500 break; 2500 break;
2501 case SYNC_PREF_FORCE_REMOTE: 2501 case SYNC_PREF_FORCE_REMOTE:
2502 return 2; 2502 return 2;
2503 break; 2503 break;
2504 2504
2505 default: 2505 default:
2506 // SYNC_PREF_TAKE_BOTH not implemented 2506 // SYNC_PREF_TAKE_BOTH not implemented
2507 break; 2507 break;
2508 } 2508 }
2509 return 0; 2509 return 0;
2510} 2510}
2511 2511
2512 2512
2513bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2513bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2514{ 2514{
2515 bool syncOK = true; 2515 bool syncOK = true;
2516 int addedAddressee = 0; 2516 int addedAddressee = 0;
2517 int addedAddresseeR = 0; 2517 int addedAddresseeR = 0;
2518 int deletedAddresseeR = 0; 2518 int deletedAddresseeR = 0;
2519 int deletedAddresseeL = 0; 2519 int deletedAddresseeL = 0;
2520 int changedLocal = 0; 2520 int changedLocal = 0;
2521 int changedRemote = 0; 2521 int changedRemote = 0;
2522 2522
2523 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2523 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2524 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2524 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2525 2525
2526 //QPtrList<Addressee> el = local->rawAddressees(); 2526 //QPtrList<Addressee> el = local->rawAddressees();
2527 Addressee addresseeR; 2527 Addressee addresseeR;
2528 QString uid; 2528 QString uid;
2529 int take; 2529 int take;
2530 Addressee addresseeL; 2530 Addressee addresseeL;
2531 Addressee addresseeRSync; 2531 Addressee addresseeRSync;
2532 Addressee addresseeLSync; 2532 Addressee addresseeLSync;
2533 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2533 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2534 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2534 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2535 bool fullDateRange = false; 2535 bool fullDateRange = false;
2536 local->resetTempSyncStat(); 2536 local->resetTempSyncStat();
2537 mLastAddressbookSync = QDateTime::currentDateTime(); 2537 mLastAddressbookSync = QDateTime::currentDateTime();
2538 if ( syncManager->syncWithDesktop() ) { 2538 if ( syncManager->syncWithDesktop() ) {
2539 // remote->removeSyncInfo( QString());//remove all info 2539 // remote->removeSyncInfo( QString());//remove all info
2540 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2540 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2541 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2541 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2542 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2542 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2543 } else { 2543 } else {
2544 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 2544 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2545 } 2545 }
2546 } 2546 }
2547 QDateTime modifiedCalendar = mLastAddressbookSync; 2547 QDateTime modifiedCalendar = mLastAddressbookSync;
2548 addresseeLSync = getLastSyncAddressee(); 2548 addresseeLSync = getLastSyncAddressee();
2549 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2549 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2550 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2550 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2551 if ( !addresseeR.isEmpty() ) { 2551 if ( !addresseeR.isEmpty() ) {
2552 addresseeRSync = addresseeR; 2552 addresseeRSync = addresseeR;
2553 remote->removeAddressee(addresseeR ); 2553 remote->removeAddressee(addresseeR );
2554 2554
2555 } else { 2555 } else {
2556 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2556 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2557 addresseeRSync = addresseeLSync ; 2557 addresseeRSync = addresseeLSync ;
2558 } else { 2558 } else {
2559 qDebug("FULLDATE 1"); 2559 //qDebug("FULLDATE 1");
2560 fullDateRange = true; 2560 fullDateRange = true;
2561 Addressee newAdd; 2561 Addressee newAdd;
2562 addresseeRSync = newAdd; 2562 addresseeRSync = newAdd;
2563 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2563 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2564 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2564 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2565 addresseeRSync.setRevision( mLastAddressbookSync ); 2565 addresseeRSync.setRevision( mLastAddressbookSync );
2566 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2566 addresseeRSync.setCategories( i18n("SyncAddressee") );
2567 } 2567 }
2568 } 2568 }
2569 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2569 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2570 qDebug("FULLDATE 2"); 2570 // qDebug("FULLDATE 2");
2571 fullDateRange = true; 2571 fullDateRange = true;
2572 } 2572 }
2573 if ( ! fullDateRange ) { 2573 if ( ! fullDateRange ) {
2574 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2574 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2575 2575
2576 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2576 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2577 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2577 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2578 fullDateRange = true; 2578 fullDateRange = true;
2579 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2579 //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2580 } 2580 }
2581 } 2581 }
2582 // fullDateRange = true; // debug only! 2582 // fullDateRange = true; // debug only!
2583 if ( fullDateRange ) 2583 if ( fullDateRange )
2584 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2584 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2585 else 2585 else
2586 mLastAddressbookSync = addresseeLSync.revision(); 2586 mLastAddressbookSync = addresseeLSync.revision();
2587 // for resyncing if own file has changed 2587 // for resyncing if own file has changed
2588 // PENDING fixme later when implemented 2588 // PENDING fixme later when implemented
2589#if 0 2589#if 0
2590 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2590 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2591 mLastAddressbookSync = loadedFileVersion; 2591 mLastAddressbookSync = loadedFileVersion;
2592 qDebug("setting mLastAddressbookSync "); 2592 qDebug("setting mLastAddressbookSync ");
2593 } 2593 }
2594#endif 2594#endif
2595 2595
2596 //qDebug("*************************** "); 2596 //qDebug("*************************** ");
2597 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2597 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2598 QStringList er = remote->uidList(); 2598 QStringList er = remote->uidList();
2599 Addressee inR ;//= er.first(); 2599 Addressee inR ;//= er.first();
2600 Addressee inL; 2600 Addressee inL;
2601 2601
2602 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2602 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2603 2603
2604 int modulo = (er.count()/10)+1; 2604 int modulo = (er.count()/10)+1;
2605 int incCounter = 0; 2605 int incCounter = 0;
2606 while ( incCounter < er.count()) { 2606 while ( incCounter < er.count()) {
2607 if (syncManager->isProgressBarCanceled()) 2607 if (syncManager->isProgressBarCanceled())
2608 return false; 2608 return false;
2609 if ( incCounter % modulo == 0 ) 2609 if ( incCounter % modulo == 0 )
2610 syncManager->showProgressBar(incCounter); 2610 syncManager->showProgressBar(incCounter);
2611 2611
2612 uid = er[ incCounter ]; 2612 uid = er[ incCounter ];
2613 bool skipIncidence = false; 2613 bool skipIncidence = false;
2614 if ( uid.left(19) == QString("last-syncAddressee-") ) 2614 if ( uid.left(19) == QString("last-syncAddressee-") )
2615 skipIncidence = true; 2615 skipIncidence = true;
2616 QString idS,OidS; 2616 QString idS,OidS;
2617 qApp->processEvents(); 2617 qApp->processEvents();
2618 if ( !skipIncidence ) { 2618 if ( !skipIncidence ) {
2619 inL = local->findByUid( uid ); 2619 inL = local->findByUid( uid );
2620 inR = remote->findByUid( uid ); 2620 inR = remote->findByUid( uid );
2621 //inL.setResource( 0 ); 2621 //inL.setResource( 0 );
2622 //inR.setResource( 0 ); 2622 //inR.setResource( 0 );
2623 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2623 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2624 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2624 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2625 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2625 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2626 //qDebug("take %d %s ", take, inL.summary().latin1()); 2626 //qDebug("take %d %s ", take, inL.summary().latin1());
2627 if ( take == 3 ) 2627 if ( take == 3 )
2628 return false; 2628 return false;
2629 if ( take == 1 ) {// take local ********************** 2629 if ( take == 1 ) {// take local **********************
2630 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2630 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2631 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2631 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2632 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2632 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2633 local->insertAddressee( inL, false ); 2633 local->insertAddressee( inL, false );
2634 idS = inR.externalUID(); 2634 idS = inR.externalUID();
2635 OidS = inR.originalExternalUID(); 2635 OidS = inR.originalExternalUID();
2636 } 2636 }
2637 else 2637 else
2638 idS = inR.IDStr(); 2638 idS = inR.IDStr();
2639 remote->removeAddressee( inR ); 2639 remote->removeAddressee( inR );
2640 inR = inL; 2640 inR = inL;
2641 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2641 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2643 inR.setOriginalExternalUID( OidS ); 2643 inR.setOriginalExternalUID( OidS );
2644 inR.setExternalUID( idS ); 2644 inR.setExternalUID( idS );
2645 if ( syncManager->syncWithDesktop() ) { 2645 if ( syncManager->syncWithDesktop() ) {
2646 inR.setIDStr("changed" ); 2646 inR.setIDStr("changed" );
2647 } 2647 }
2648 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); 2648 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2649 } else { 2649 } else {
2650 inR.setIDStr( idS ); 2650 inR.setIDStr( idS );
2651 } 2651 }
2652 inR.setResource( 0 ); 2652 inR.setResource( 0 );
2653 remote->insertAddressee( inR , false); 2653 remote->insertAddressee( inR , false);
2654 ++changedRemote; 2654 ++changedRemote;
2655 } else { // take == 2 take remote ********************** 2655 } else { // take == 2 take remote **********************
2656 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2656 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2657 if ( inR.revision().date().year() < 2004 ) 2657 if ( inR.revision().date().year() < 2004 )
2658 inR.setRevision( modifiedCalendar ); 2658 inR.setRevision( modifiedCalendar );
2659 } 2659 }
2660 idS = inL.IDStr(); 2660 idS = inL.IDStr();
2661 local->removeAddressee( inL ); 2661 local->removeAddressee( inL );
2662 inL = inR; 2662 inL = inR;
2663 inL.setIDStr( idS ); 2663 inL.setIDStr( idS );
2664 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2664 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2665 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2665 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2666 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2666 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2667 } 2667 }
2668 inL.setResource( 0 ); 2668 inL.setResource( 0 );
2669 local->insertAddressee( inL , false ); 2669 local->insertAddressee( inL , false );
2670 ++changedLocal; 2670 ++changedLocal;
2671 } 2671 }
2672 } 2672 }
2673 } 2673 }
2674 } else { // no conflict ********** add or delete remote 2674 } else { // no conflict ********** add or delete remote
2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2676 QString des = addresseeLSync.note(); 2676 QString des = addresseeLSync.note();
2677 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2677 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2678 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2678 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2679 remote->insertAddressee( inR, false ); 2679 remote->insertAddressee( inR, false );
2680 ++deletedAddresseeR; 2680 ++deletedAddresseeR;
2681 } else { 2681 } else {
2682 inR.setRevision( modifiedCalendar ); 2682 inR.setRevision( modifiedCalendar );
2683 remote->insertAddressee( inR, false ); 2683 remote->insertAddressee( inR, false );
2684 inL = inR; 2684 inL = inR;
2685 inL.setIDStr( ":" ); 2685 inL.setIDStr( ":" );
2686 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2686 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2687 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2687 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2688 inL.setResource( 0 ); 2688 inL.setResource( 0 );
2689 local->insertAddressee( inL , false); 2689 local->insertAddressee( inL , false);
2690 ++addedAddressee; 2690 ++addedAddressee;
2691 } 2691 }
2692 } else { 2692 } else {
2693 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2693 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2694 inR.setRevision( modifiedCalendar ); 2694 inR.setRevision( modifiedCalendar );
2695 remote->insertAddressee( inR, false ); 2695 remote->insertAddressee( inR, false );
2696 inR.setResource( 0 ); 2696 inR.setResource( 0 );
2697 local->insertAddressee( inR, false ); 2697 local->insertAddressee( inR, false );
2698 ++addedAddressee; 2698 ++addedAddressee;
2699 } else { 2699 } else {
2700 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2700 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2701 remote->removeAddressee( inR ); 2701 remote->removeAddressee( inR );
2702 ++deletedAddresseeR; 2702 ++deletedAddresseeR;
2703 } 2703 }
2704 } 2704 }
2705 } 2705 }
2706 } 2706 }
2707 ++incCounter; 2707 ++incCounter;
2708 } 2708 }
2709 er.clear(); 2709 er.clear();
2710 QStringList el = local->uidList(); 2710 QStringList el = local->uidList();
2711 modulo = (el.count()/10)+1; 2711 modulo = (el.count()/10)+1;
2712 2712
2713 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2713 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2714 incCounter = 0; 2714 incCounter = 0;
2715 while ( incCounter < el.count()) { 2715 while ( incCounter < el.count()) {
2716 qApp->processEvents(); 2716 qApp->processEvents();
2717 if (syncManager->isProgressBarCanceled()) 2717 if (syncManager->isProgressBarCanceled())
2718 return false; 2718 return false;
2719 if ( incCounter % modulo == 0 ) 2719 if ( incCounter % modulo == 0 )
2720 syncManager->showProgressBar(incCounter); 2720 syncManager->showProgressBar(incCounter);
2721 uid = el[ incCounter ]; 2721 uid = el[ incCounter ];
2722 bool skipIncidence = false; 2722 bool skipIncidence = false;
2723 if ( uid.left(19) == QString("last-syncAddressee-") ) 2723 if ( uid.left(19) == QString("last-syncAddressee-") )
2724 skipIncidence = true; 2724 skipIncidence = true;
2725 if ( !skipIncidence ) { 2725 if ( !skipIncidence ) {
2726 inL = local->findByUid( uid ); 2726 inL = local->findByUid( uid );
2727 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2727 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2728 inR = remote->findByUid( uid ); 2728 inR = remote->findByUid( uid );
2729 if ( inR.isEmpty() ) { // no conflict ********** add or delete local 2729 if ( inR.isEmpty() ) { // no conflict ********** add or delete local
2730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2731 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2731 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2732 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2732 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2733 local->removeAddressee( inL ); 2733 local->removeAddressee( inL );
2734 ++deletedAddresseeL; 2734 ++deletedAddresseeL;
2735 } else { 2735 } else {
2736 if ( ! syncManager->mWriteBackExistingOnly ) { 2736 if ( ! syncManager->mWriteBackExistingOnly ) {
2737 inL.removeID(mCurrentSyncDevice ); 2737 inL.removeID(mCurrentSyncDevice );
2738 ++addedAddresseeR; 2738 ++addedAddresseeR;
2739 inL.setRevision( modifiedCalendar ); 2739 inL.setRevision( modifiedCalendar );
2740 local->insertAddressee( inL, false ); 2740 local->insertAddressee( inL, false );
2741 inR = inL; 2741 inR = inL;
2742 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2742 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2743 inR.setResource( 0 ); 2743 inR.setResource( 0 );
2744 remote->insertAddressee( inR, false ); 2744 remote->insertAddressee( inR, false );
2745 } 2745 }
2746 } 2746 }
2747 } else { 2747 } else {
2748 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2748 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2749 //qDebug("data %s ", inL.revision().toString().latin1()); 2749 //qDebug("data %s ", inL.revision().toString().latin1());
2750 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2750 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2751 local->removeAddressee( inL ); 2751 local->removeAddressee( inL );
2752 ++deletedAddresseeL; 2752 ++deletedAddresseeL;
2753 } else { 2753 } else {
2754 if ( ! syncManager->mWriteBackExistingOnly ) { 2754 if ( ! syncManager->mWriteBackExistingOnly ) {
2755 ++addedAddresseeR; 2755 ++addedAddresseeR;
2756 inL.setRevision( modifiedCalendar ); 2756 inL.setRevision( modifiedCalendar );
2757 local->insertAddressee( inL, false ); 2757 local->insertAddressee( inL, false );
2758 inR = inL; 2758 inR = inL;
2759 inR.setIDStr( ":" ); 2759 inR.setIDStr( ":" );
2760 inR.setResource( 0 ); 2760 inR.setResource( 0 );
2761 remote->insertAddressee( inR, false ); 2761 remote->insertAddressee( inR, false );
2762 } 2762 }
2763 } 2763 }
2764 } 2764 }
2765 } 2765 }
2766 } 2766 }
2767 } 2767 }
2768 ++incCounter; 2768 ++incCounter;
2769 } 2769 }
2770 el.clear(); 2770 el.clear();
2771 syncManager->hideProgressBar(); 2771 syncManager->hideProgressBar();
2772 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2772 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2773 // get rid of micro seconds 2773 // get rid of micro seconds
2774 QTime t = mLastAddressbookSync.time(); 2774 QTime t = mLastAddressbookSync.time();
2775 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2775 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2776 addresseeLSync.setRevision( mLastAddressbookSync ); 2776 addresseeLSync.setRevision( mLastAddressbookSync );
2777 addresseeRSync.setRevision( mLastAddressbookSync ); 2777 addresseeRSync.setRevision( mLastAddressbookSync );
2778 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2778 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2779 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2779 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2780 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2780 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2781 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2781 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2782 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2782 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2783 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2783 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2784 addresseeRSync.setNote( "" ) ; 2784 addresseeRSync.setNote( "" ) ;
2785 addresseeLSync.setNote( "" ); 2785 addresseeLSync.setNote( "" );
2786 2786
2787 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2787 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2788 remote->insertAddressee( addresseeRSync, false ); 2788 remote->insertAddressee( addresseeRSync, false );
2789 local->insertAddressee( addresseeLSync, false ); 2789 local->insertAddressee( addresseeLSync, false );
2790 QString mes; 2790 QString mes;
2791 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 ); 2791 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 );
2792 qDebug( mes ); 2792 qDebug( mes );
2793 mes = i18n("Local addressbook changed!\n") +mes; 2793 mes = i18n("Local addressbook changed!\n") +mes;
2794 if ( syncManager->mShowSyncSummary ) { 2794 if ( syncManager->mShowSyncSummary ) {
2795 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 2795 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
2796 i18n("KA/Pi Synchronization"),i18n("Write back"))) { 2796 i18n("KA/Pi Synchronization"),i18n("Write back"))) {
2797 qDebug("cancelled "); 2797 qDebug("cancelled ");
2798 return false; 2798 return false;
2799 } 2799 }
2800 } 2800 }
2801 return syncOK; 2801 return syncOK;
2802} 2802}
2803 2803
2804 2804
2805//this is a overwritten callbackmethods from the syncinterface 2805//this is a overwritten callbackmethods from the syncinterface
2806bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2806bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2807{ 2807{
2808 2808
2809 //pending prepare addresseeview for output 2809 //pending prepare addresseeview for output
2810 //pending detect, if remote file has REV field. if not switch to external sync 2810 //pending detect, if remote file has REV field. if not switch to external sync
2811 mGlobalSyncMode = SYNC_MODE_NORMAL; 2811 mGlobalSyncMode = SYNC_MODE_NORMAL;
2812 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2812 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2813 2813
2814 AddressBook abLocal(filename,"syncContact"); 2814 AddressBook abLocal(filename,"syncContact");
2815 bool syncOK = false; 2815 bool syncOK = false;
2816 if ( abLocal.load() ) { 2816 if ( abLocal.load() ) {
2817 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2817 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2818 bool external = false; 2818 bool external = false;
2819 bool isXML = false; 2819 bool isXML = false;
2820 if ( filename.right(4) == ".xml") { 2820 if ( filename.right(4) == ".xml") {
2821 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2821 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2822 isXML = true; 2822 isXML = true;
2823 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2823 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2824 } else { 2824 } else {
2825 external = !manager->mIsKapiFile; 2825 external = !manager->mIsKapiFile;
2826 if ( external ) { 2826 if ( external ) {
2827 qDebug("Setting vcf mode to external "); 2827 qDebug("Setting vcf mode to external ");
2828 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2828 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2829 AddressBook::Iterator it; 2829 AddressBook::Iterator it;
2830 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2830 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2831 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2831 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2832 (*it).computeCsum( mCurrentSyncDevice ); 2832 (*it).computeCsum( mCurrentSyncDevice );
2833 } 2833 }
2834 } 2834 }
2835 } 2835 }
2836 //AddressBook::Iterator it; 2836 //AddressBook::Iterator it;
2837 //QStringList vcards; 2837 //QStringList vcards;
2838 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2838 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2839 // qDebug("Name %s ", (*it).familyName().latin1()); 2839 // qDebug("Name %s ", (*it).familyName().latin1());
2840 //} 2840 //}
2841 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2841 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2842 if ( syncOK ) { 2842 if ( syncOK ) {
2843 if ( syncManager->mWriteBackFile ) 2843 if ( syncManager->mWriteBackFile )
2844 { 2844 {
2845 if ( external ) 2845 if ( external )
2846 abLocal.removeSyncAddressees( !isXML); 2846 abLocal.removeSyncAddressees( !isXML);
2847 qDebug("Saving remote AB "); 2847 qDebug("Saving remote AB ");
2848 if ( ! abLocal.saveAB()) 2848 if ( ! abLocal.saveAB())
2849 qDebug("Error writing back AB to file "); 2849 qDebug("Error writing back AB to file ");
2850 if ( external ) { 2850 if ( external ) {
2851 // afterwrite processing 2851 // afterwrite processing
2852 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); 2852 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
2853 } 2853 }
2854 } 2854 }
2855 } 2855 }
2856 setModified(); 2856 setModified();
2857 2857
2858 } 2858 }
2859 abLocal.removeResources();
2859 if ( syncOK ) 2860 if ( syncOK )
2860 mViewManager->refreshView(); 2861 mViewManager->refreshView();
2861 return syncOK; 2862 return syncOK;
2862 2863
2863} 2864}
2864void KABCore::removeSyncInfo( QString syncProfile) 2865void KABCore::removeSyncInfo( QString syncProfile)
2865{ 2866{
2866 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2867 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2867 mAddressBook->removeSyncInfo( syncProfile ); 2868 mAddressBook->removeSyncInfo( syncProfile );
2868 setModified(); 2869 setModified();
2869} 2870}
2870 2871
2871 2872
2872//this is a overwritten callbackmethods from the syncinterface 2873//this is a overwritten callbackmethods from the syncinterface
2873bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2874bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2874{ 2875{
2875 if ( resource == "phone" ) 2876 if ( resource == "phone" )
2876 return syncPhone(); 2877 return syncPhone();
2877 disableBR( true ); 2878 disableBR( true );
2878 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2879 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2879 2880
2880 AddressBook abLocal( resource,"syncContact"); 2881 AddressBook abLocal( resource,"syncContact");
2881 bool syncOK = false; 2882 bool syncOK = false;
2882 if ( abLocal.load() ) { 2883 if ( abLocal.load() ) {
2883 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2884 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2884 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2885 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2885 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2886 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2886 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2887 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2887 if ( syncOK ) { 2888 if ( syncOK ) {
2888 if ( syncManager->mWriteBackFile ) { 2889 if ( syncManager->mWriteBackFile ) {
2889 abLocal.removeSyncAddressees( false ); 2890 abLocal.removeSyncAddressees( false );
2890 abLocal.saveAB(); 2891 abLocal.saveAB();
2891 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2892 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2892 } 2893 }
2893 } else 2894 } else
2894 message( i18n("Sync cancelled or failed.") ); 2895 message( i18n("Sync cancelled or failed.") );
2895 setModified(); 2896 setModified();
2896 } 2897 }
2898 abLocal.removeResources();
2897 if ( syncOK ) 2899 if ( syncOK )
2898 mViewManager->refreshView(); 2900 mViewManager->refreshView();
2899 disableBR( false ); 2901 disableBR( false );
2900 return syncOK; 2902 return syncOK;
2901 2903
2902} 2904}
2903void KABCore::message( QString m ) 2905void KABCore::message( QString m )
2904{ 2906{
2905 topLevelWidget()->setCaption( m ); 2907 topLevelWidget()->setCaption( m );
2906 mMessageTimer->start( 15000, true ); 2908 mMessageTimer->start( 15000, true );
2907} 2909}
2908bool KABCore::syncPhone() 2910bool KABCore::syncPhone()
2909{ 2911{
2910 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2912 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2911 QString fileName = getPhoneFile(); 2913 QString fileName = getPhoneFile();
2912 if ( !PhoneAccess::readFromPhone( fileName) ) { 2914 if ( !PhoneAccess::readFromPhone( fileName) ) {
2913 message(i18n("Phone access failed!")); 2915 message(i18n("Phone access failed!"));
2914 return false; 2916 return false;
2915 } 2917 }
2916 AddressBook abLocal( fileName,"syncContact"); 2918 AddressBook abLocal( fileName,"syncContact");
2917 bool syncOK = false; 2919 bool syncOK = false;
2918 { 2920 {
2919 abLocal.importFromFile( fileName ); 2921 abLocal.importFromFile( fileName );
2920 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2922 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2921 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2923 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2922 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2924 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2923 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2925 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2924 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2926 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2925 if ( syncOK ) { 2927 if ( syncOK ) {
2926 if ( syncManager->mWriteBackFile ) { 2928 if ( syncManager->mWriteBackFile ) {
2927 abLocal.removeSyncAddressees( true ); 2929 abLocal.removeSyncAddressees( true );
2928 abLocal.saveABphone( fileName ); 2930 abLocal.saveABphone( fileName );
2929 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2931 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2930 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2932 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2931 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2933 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2932 } 2934 }
2933 } 2935 }
2934 setModified(); 2936 setModified();
2935 } 2937 }
2938 abLocal.removeResources();
2936 if ( syncOK ) 2939 if ( syncOK )
2937 mViewManager->refreshView(); 2940 mViewManager->refreshView();
2938 return syncOK; 2941 return syncOK;
2939} 2942}
2940void KABCore::getFile( bool success ) 2943void KABCore::getFile( bool success )
2941{ 2944{
2942 if ( ! success ) { 2945 if ( ! success ) {
2943 message( i18n("Error receiving file. Nothing changed!") ); 2946 message( i18n("Error receiving file. Nothing changed!") );
2944 return; 2947 return;
2945 } 2948 }
2946 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2949 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2947 if ( count ) 2950 if ( count )
2948 setModified( true ); 2951 setModified( true );
2949 message( i18n("Pi-Sync successful!") ); 2952 message( i18n("Pi-Sync successful!") );
2950 mViewManager->refreshView(); 2953 mViewManager->refreshView();
2951} 2954}
2952void KABCore::syncFileRequest() 2955void KABCore::syncFileRequest()
2953{ 2956{
2954 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 2957 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2955 syncManager->slotSyncMenu( 999 ); 2958 syncManager->slotSyncMenu( 999 );
2956 } 2959 }
2957 mAddressBook->export2File( sentSyncFile() ); 2960 mAddressBook->export2File( sentSyncFile() );
2958} 2961}
2959QString KABCore::sentSyncFile() 2962QString KABCore::sentSyncFile()
2960{ 2963{
2961#ifdef DESKTOP_VERSION 2964#ifdef DESKTOP_VERSION
2962 return locateLocal( "tmp", "copysyncab.vcf" ); 2965 return locateLocal( "tmp", "copysyncab.vcf" );
2963#else 2966#else
2964 return QString( "/tmp/copysyncab.vcf" ); 2967 return QString( "/tmp/copysyncab.vcf" );
2965#endif 2968#endif
2966} 2969}
2967 2970
2968void KABCore::setCaptionBack() 2971void KABCore::setCaptionBack()
2969{ 2972{
2970 mMessageTimer->stop(); 2973 mMessageTimer->stop();
2971 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2974 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2972} 2975}