author | zautrix <zautrix> | 2004-09-21 11:42:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-21 11:42:03 (UTC) |
commit | 6a40d65ddd6657e34c69d839da458810a8d8ff98 (patch) (unidiff) | |
tree | eba8aaa135d7a33a15527a38c95fcf0adb3bceaa | |
parent | 4f0afab535db2e66f2ba8121e624782a70a3d409 (diff) | |
download | kdepimpi-6a40d65ddd6657e34c69d839da458810a8d8ff98.zip kdepimpi-6a40d65ddd6657e34c69d839da458810a8d8ff98.tar.gz kdepimpi-6a40d65ddd6657e34c69d839da458810a8d8ff98.tar.bz2 |
cleanup
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 39 |
2 files changed, 4 insertions, 37 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 430c7b3..5eab1be 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -1,376 +1,376 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | //US | 28 | //US |
29 | #include "kglobal.h" | 29 | #include "kglobal.h" |
30 | 30 | ||
31 | 31 | ||
32 | #include "qtopiaconverter.h" | 32 | #include "qtopiaconverter.h" |
33 | 33 | ||
34 | #include <qpe/categories.h> | 34 | #include <qpe/categories.h> |
35 | #include <libkdepim/ksyncprofile.h> | 35 | #include <libkdepim/ksyncprofile.h> |
36 | //US #include <qpe/categoryselect.h> | 36 | //US #include <qpe/categoryselect.h> |
37 | 37 | ||
38 | 38 | ||
39 | using namespace KABC; | 39 | using namespace KABC; |
40 | 40 | ||
41 | QtopiaConverter::QtopiaConverter() : catDB(0) | 41 | QtopiaConverter::QtopiaConverter() : catDB(0) |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | QtopiaConverter::~QtopiaConverter() | 45 | QtopiaConverter::~QtopiaConverter() |
46 | { | 46 | { |
47 | deinit(); | 47 | deinit(); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool QtopiaConverter::init() | 50 | bool QtopiaConverter::init() |
51 | { | 51 | { |
52 | catDB = new Categories(); | 52 | catDB = new Categories(); |
53 | 53 | ||
54 | if (!catDB) | 54 | if (!catDB) |
55 | return false; | 55 | return false; |
56 | 56 | ||
57 | catDB->load( categoryFileName() ); | 57 | catDB->load( categoryFileName() ); |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | 60 | ||
61 | void QtopiaConverter::deinit() | 61 | void QtopiaConverter::deinit() |
62 | { | 62 | { |
63 | if (catDB) | 63 | if (catDB) |
64 | { | 64 | { |
65 | delete catDB; | 65 | delete catDB; |
66 | catDB = 0; | 66 | catDB = 0; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) | 70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) |
71 | { | 71 | { |
72 | // name | 72 | // name |
73 | addr.setFormattedName(contact.fileAs()); | 73 | addr.setFormattedName(contact.fileAs()); |
74 | addr.setFamilyName( contact.lastName() ); | 74 | addr.setFamilyName( contact.lastName() ); |
75 | addr.setGivenName( contact.firstName() ); | 75 | addr.setGivenName( contact.firstName() ); |
76 | addr.setAdditionalName( contact.middleName() ); | 76 | addr.setAdditionalName( contact.middleName() ); |
77 | addr.setPrefix( contact.nameTitle() ); | 77 | addr.setPrefix( contact.nameTitle() ); |
78 | addr.setSuffix( contact.suffix() ); | 78 | addr.setSuffix( contact.suffix() ); |
79 | 79 | ||
80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
81 | QString exuid = contact.uid().toString(); | 81 | QString exuid = contact.uid().toString(); |
82 | addr.setOriginalExternalUID( exuid ); | 82 | addr.setOriginalExternalUID( exuid ); |
83 | int ente = exuid.find( "-0000"); | 83 | int ente = exuid.find( "-0000"); |
84 | if ( exuid.left(1) == "{" ) | 84 | if ( exuid.left(1) == "{" ) |
85 | exuid = exuid.mid(1); | 85 | exuid = exuid.mid(1); |
86 | if ( ente > -1 ) | 86 | if ( ente > -1 ) |
87 | exuid = exuid.left( ente-1 ); | 87 | exuid = exuid.left( ente-1 ); |
88 | addr.setExternalUID( exuid ); | 88 | addr.setExternalUID( exuid ); |
89 | qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); | 89 | // qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); |
90 | 90 | ||
91 | 91 | ||
92 | QStringList emails = contact.emailList(); | 92 | QStringList emails = contact.emailList(); |
93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); | 94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | if (!contact.defaultEmail().isEmpty()) | 97 | if (!contact.defaultEmail().isEmpty()) |
98 | addr.insertEmail(contact.defaultEmail(), true); | 98 | addr.insertEmail(contact.defaultEmail(), true); |
99 | 99 | ||
100 | // home | 100 | // home |
101 | if ((!contact.homeStreet().isEmpty()) || | 101 | if ((!contact.homeStreet().isEmpty()) || |
102 | (!contact.homeCity().isEmpty()) || | 102 | (!contact.homeCity().isEmpty()) || |
103 | (!contact.homeState().isEmpty()) || | 103 | (!contact.homeState().isEmpty()) || |
104 | (!contact.homeZip().isEmpty()) || | 104 | (!contact.homeZip().isEmpty()) || |
105 | (!contact.homeCountry().isEmpty())) | 105 | (!contact.homeCountry().isEmpty())) |
106 | { | 106 | { |
107 | Address homeaddress; | 107 | Address homeaddress; |
108 | homeaddress.setType(Address::Home); | 108 | homeaddress.setType(Address::Home); |
109 | //US homeaddress.setPostOfficeBox( "" ); | 109 | //US homeaddress.setPostOfficeBox( "" ); |
110 | //US homeaddress.setExtended( "" ); | 110 | //US homeaddress.setExtended( "" ); |
111 | homeaddress.setStreet( contact.homeStreet() ); | 111 | homeaddress.setStreet( contact.homeStreet() ); |
112 | homeaddress.setLocality( contact.homeCity() ); | 112 | homeaddress.setLocality( contact.homeCity() ); |
113 | homeaddress.setRegion( contact.homeState() ); | 113 | homeaddress.setRegion( contact.homeState() ); |
114 | homeaddress.setPostalCode( contact.homeZip() ); | 114 | homeaddress.setPostalCode( contact.homeZip() ); |
115 | homeaddress.setCountry( contact.homeCountry() ); | 115 | homeaddress.setCountry( contact.homeCountry() ); |
116 | 116 | ||
117 | addr.insertAddress( homeaddress ); | 117 | addr.insertAddress( homeaddress ); |
118 | } | 118 | } |
119 | 119 | ||
120 | if (!contact.homePhone().isEmpty()) | 120 | if (!contact.homePhone().isEmpty()) |
121 | { | 121 | { |
122 | PhoneNumber homephone; | 122 | PhoneNumber homephone; |
123 | homephone.setType( PhoneNumber::Home ); | 123 | homephone.setType( PhoneNumber::Home ); |
124 | homephone.setNumber( contact.homePhone() ); | 124 | homephone.setNumber( contact.homePhone() ); |
125 | addr.insertPhoneNumber( homephone ); | 125 | addr.insertPhoneNumber( homephone ); |
126 | } | 126 | } |
127 | 127 | ||
128 | if (!contact.homeFax().isEmpty()) | 128 | if (!contact.homeFax().isEmpty()) |
129 | { | 129 | { |
130 | PhoneNumber homefax; | 130 | PhoneNumber homefax; |
131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
132 | homefax.setNumber( contact.homeFax() ); | 132 | homefax.setNumber( contact.homeFax() ); |
133 | addr.insertPhoneNumber( homefax ); | 133 | addr.insertPhoneNumber( homefax ); |
134 | } | 134 | } |
135 | 135 | ||
136 | if (!contact.homeMobile().isEmpty()) | 136 | if (!contact.homeMobile().isEmpty()) |
137 | { | 137 | { |
138 | PhoneNumber homemobile; | 138 | PhoneNumber homemobile; |
139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
140 | homemobile.setNumber( contact.homeMobile() ); | 140 | homemobile.setNumber( contact.homeMobile() ); |
141 | addr.insertPhoneNumber( homemobile ); | 141 | addr.insertPhoneNumber( homemobile ); |
142 | } | 142 | } |
143 | 143 | ||
144 | addr.setUrl( contact.homeWebpage() ); | 144 | addr.setUrl( contact.homeWebpage() ); |
145 | 145 | ||
146 | 146 | ||
147 | // business | 147 | // business |
148 | if ((!contact.businessStreet().isEmpty()) || | 148 | if ((!contact.businessStreet().isEmpty()) || |
149 | (!contact.businessCity().isEmpty()) || | 149 | (!contact.businessCity().isEmpty()) || |
150 | (!contact.businessState().isEmpty()) || | 150 | (!contact.businessState().isEmpty()) || |
151 | (!contact.businessZip().isEmpty()) || | 151 | (!contact.businessZip().isEmpty()) || |
152 | (!contact.businessCountry().isEmpty())) | 152 | (!contact.businessCountry().isEmpty())) |
153 | { | 153 | { |
154 | Address businessaddress; | 154 | Address businessaddress; |
155 | businessaddress.setType(Address::Work); | 155 | businessaddress.setType(Address::Work); |
156 | //US businessaddress.setPostOfficeBox( "" ); | 156 | //US businessaddress.setPostOfficeBox( "" ); |
157 | //US businessaddress.setExtended( "" ); | 157 | //US businessaddress.setExtended( "" ); |
158 | businessaddress.setStreet( contact.businessStreet() ); | 158 | businessaddress.setStreet( contact.businessStreet() ); |
159 | businessaddress.setLocality( contact.businessCity() ); | 159 | businessaddress.setLocality( contact.businessCity() ); |
160 | businessaddress.setRegion( contact.businessState() ); | 160 | businessaddress.setRegion( contact.businessState() ); |
161 | businessaddress.setPostalCode( contact.businessZip() ); | 161 | businessaddress.setPostalCode( contact.businessZip() ); |
162 | businessaddress.setCountry( contact.businessCountry() ); | 162 | businessaddress.setCountry( contact.businessCountry() ); |
163 | 163 | ||
164 | addr.insertAddress( businessaddress ); | 164 | addr.insertAddress( businessaddress ); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | if (!contact.businessPhone().isEmpty()) | 168 | if (!contact.businessPhone().isEmpty()) |
169 | { | 169 | { |
170 | PhoneNumber businessphone; | 170 | PhoneNumber businessphone; |
171 | businessphone.setType( PhoneNumber::Work ); | 171 | businessphone.setType( PhoneNumber::Work ); |
172 | businessphone.setNumber( contact.businessPhone() ); | 172 | businessphone.setNumber( contact.businessPhone() ); |
173 | addr.insertPhoneNumber( businessphone ); | 173 | addr.insertPhoneNumber( businessphone ); |
174 | } | 174 | } |
175 | 175 | ||
176 | if (!contact.businessFax().isEmpty()) | 176 | if (!contact.businessFax().isEmpty()) |
177 | { | 177 | { |
178 | PhoneNumber businessfax; | 178 | PhoneNumber businessfax; |
179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
180 | businessfax.setNumber( contact.businessFax() ); | 180 | businessfax.setNumber( contact.businessFax() ); |
181 | addr.insertPhoneNumber( businessfax ); | 181 | addr.insertPhoneNumber( businessfax ); |
182 | } | 182 | } |
183 | 183 | ||
184 | if (!contact.businessMobile().isEmpty()) | 184 | if (!contact.businessMobile().isEmpty()) |
185 | { | 185 | { |
186 | PhoneNumber businessmobile; | 186 | PhoneNumber businessmobile; |
187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
188 | businessmobile.setNumber( contact.businessMobile() ); | 188 | businessmobile.setNumber( contact.businessMobile() ); |
189 | addr.insertPhoneNumber( businessmobile ); | 189 | addr.insertPhoneNumber( businessmobile ); |
190 | } | 190 | } |
191 | 191 | ||
192 | if (!contact.businessPager().isEmpty()) | 192 | if (!contact.businessPager().isEmpty()) |
193 | { | 193 | { |
194 | PhoneNumber businesspager; | 194 | PhoneNumber businesspager; |
195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
196 | businesspager.setNumber( contact.businessPager() ); | 196 | businesspager.setNumber( contact.businessPager() ); |
197 | addr.insertPhoneNumber( businesspager ); | 197 | addr.insertPhoneNumber( businesspager ); |
198 | } | 198 | } |
199 | 199 | ||
200 | addr.setRole( contact.jobTitle() ); //? | 200 | addr.setRole( contact.jobTitle() ); //? |
201 | addr.setOrganization( contact.company() ); | 201 | addr.setOrganization( contact.company() ); |
202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); | 202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); |
203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); | 203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); |
204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); | 204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); |
205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); | 205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); |
206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); | 206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); |
207 | 207 | ||
208 | //personal | 208 | //personal |
209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); | 209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); |
210 | // qtopia uses this categorization: | 210 | // qtopia uses this categorization: |
211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
212 | if (contact.gender() == PimContact::Male) | 212 | if (contact.gender() == PimContact::Male) |
213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
214 | else if (contact.gender() == PimContact::Female) | 214 | else if (contact.gender() == PimContact::Female) |
215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
216 | 216 | ||
217 | if (contact.anniversary().isValid()) { | 217 | if (contact.anniversary().isValid()) { |
218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); | 218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); |
219 | //US | 219 | //US |
220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); | 220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); |
221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
222 | } | 222 | } |
223 | 223 | ||
224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); | 224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); |
225 | if (contact.birthday().isValid()) | 225 | if (contact.birthday().isValid()) |
226 | addr.setBirthday( contact.birthday() ); | 226 | addr.setBirthday( contact.birthday() ); |
227 | 227 | ||
228 | addr.setNickName( contact.nickname() ); | 228 | addr.setNickName( contact.nickname() ); |
229 | 229 | ||
230 | // others | 230 | // others |
231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
232 | QString notes = contact.notes(); | 232 | QString notes = contact.notes(); |
233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; | 233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; |
234 | 234 | ||
235 | addr.setNote( contact.notes() ); | 235 | addr.setNote( contact.notes() ); |
236 | 236 | ||
237 | 237 | ||
238 | 238 | ||
239 | //US QString groups() const { return find( Qtopia::Groups ); } | 239 | //US QString groups() const { return find( Qtopia::Groups ); } |
240 | //US QStringList groupList() const; | 240 | //US QStringList groupList() const; |
241 | 241 | ||
242 | QArray<int> catArray = contact.categories(); | 242 | QArray<int> catArray = contact.categories(); |
243 | QString cat; | 243 | QString cat; |
244 | 244 | ||
245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
246 | cat = catDB->label("contact", catArray[i]); | 246 | cat = catDB->label("contact", catArray[i]); |
247 | if ( cat.isEmpty() ) | 247 | if ( cat.isEmpty() ) |
248 | addr.insertCategory(QString::number(catArray[i])); | 248 | addr.insertCategory(QString::number(catArray[i])); |
249 | else | 249 | else |
250 | addr.insertCategory( cat ); | 250 | addr.insertCategory( cat ); |
251 | } | 251 | } |
252 | 252 | ||
253 | return true; | 253 | return true; |
254 | } | 254 | } |
255 | 255 | ||
256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) | 256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) |
257 | { | 257 | { |
258 | 258 | ||
259 | 259 | ||
260 | 260 | ||
261 | // name | 261 | // name |
262 | contact.setLastName(addr.familyName()); | 262 | contact.setLastName(addr.familyName()); |
263 | contact.setFirstName(addr.givenName()); | 263 | contact.setFirstName(addr.givenName()); |
264 | contact.setMiddleName(addr.additionalName()); | 264 | contact.setMiddleName(addr.additionalName()); |
265 | contact.setNameTitle(addr.prefix()); | 265 | contact.setNameTitle(addr.prefix()); |
266 | contact.setSuffix(addr.suffix()); | 266 | contact.setSuffix(addr.suffix()); |
267 | contact.setFileAs(); | 267 | contact.setFileAs(); |
268 | 268 | ||
269 | 269 | ||
270 | 270 | ||
271 | QStringList emails = addr.emails(); | 271 | QStringList emails = addr.emails(); |
272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
273 | contact.insertEmail(*it); | 273 | contact.insertEmail(*it); |
274 | } | 274 | } |
275 | contact.setDefaultEmail( addr.preferredEmail() ); | 275 | contact.setDefaultEmail( addr.preferredEmail() ); |
276 | 276 | ||
277 | 277 | ||
278 | // home | 278 | // home |
279 | const Address homeaddress = addr.address(Address::Home); | 279 | const Address homeaddress = addr.address(Address::Home); |
280 | if (!homeaddress.isEmpty()) { | 280 | if (!homeaddress.isEmpty()) { |
281 | contact.setHomeStreet(homeaddress.street()); | 281 | contact.setHomeStreet(homeaddress.street()); |
282 | contact.setHomeCity(homeaddress.locality()); | 282 | contact.setHomeCity(homeaddress.locality()); |
283 | contact.setHomeState(homeaddress.region()); | 283 | contact.setHomeState(homeaddress.region()); |
284 | contact.setHomeZip(homeaddress.postalCode()); | 284 | contact.setHomeZip(homeaddress.postalCode()); |
285 | contact.setHomeCountry(homeaddress.country()); | 285 | contact.setHomeCountry(homeaddress.country()); |
286 | } | 286 | } |
287 | 287 | ||
288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
289 | if (!homephone.number().isEmpty()) | 289 | if (!homephone.number().isEmpty()) |
290 | contact.setHomePhone(homephone.number()); | 290 | contact.setHomePhone(homephone.number()); |
291 | 291 | ||
292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
293 | if (!homefax.number().isEmpty()) | 293 | if (!homefax.number().isEmpty()) |
294 | contact.setHomeFax(homefax.number()); | 294 | contact.setHomeFax(homefax.number()); |
295 | 295 | ||
296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
297 | if (!homemobile.number().isEmpty()) | 297 | if (!homemobile.number().isEmpty()) |
298 | contact.setHomeMobile(homemobile.number()); | 298 | contact.setHomeMobile(homemobile.number()); |
299 | 299 | ||
300 | contact.setHomeWebpage(addr.url().url()); | 300 | contact.setHomeWebpage(addr.url().url()); |
301 | 301 | ||
302 | 302 | ||
303 | // business | 303 | // business |
304 | const Address businessaddress = addr.address(Address::Work); | 304 | const Address businessaddress = addr.address(Address::Work); |
305 | if (!businessaddress.isEmpty()) { | 305 | if (!businessaddress.isEmpty()) { |
306 | contact.setBusinessStreet(businessaddress.street()); | 306 | contact.setBusinessStreet(businessaddress.street()); |
307 | contact.setBusinessCity(businessaddress.locality()); | 307 | contact.setBusinessCity(businessaddress.locality()); |
308 | contact.setBusinessState(businessaddress.region()); | 308 | contact.setBusinessState(businessaddress.region()); |
309 | contact.setBusinessZip(businessaddress.postalCode()); | 309 | contact.setBusinessZip(businessaddress.postalCode()); |
310 | contact.setBusinessCountry(businessaddress.country()); | 310 | contact.setBusinessCountry(businessaddress.country()); |
311 | } | 311 | } |
312 | 312 | ||
313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
314 | if (!businessphone.number().isEmpty()) | 314 | if (!businessphone.number().isEmpty()) |
315 | contact.setBusinessPhone(businessphone.number()); | 315 | contact.setBusinessPhone(businessphone.number()); |
316 | 316 | ||
317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
318 | if (!businessfax.number().isEmpty()) | 318 | if (!businessfax.number().isEmpty()) |
319 | contact.setBusinessFax(businessfax.number()); | 319 | contact.setBusinessFax(businessfax.number()); |
320 | 320 | ||
321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
322 | if (!businessmobile.number().isEmpty()) | 322 | if (!businessmobile.number().isEmpty()) |
323 | contact.setBusinessMobile(businessmobile.number()); | 323 | contact.setBusinessMobile(businessmobile.number()); |
324 | 324 | ||
325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
326 | if (!businesspager.number().isEmpty()) | 326 | if (!businesspager.number().isEmpty()) |
327 | contact.setBusinessPager(businesspager.number()); | 327 | contact.setBusinessPager(businesspager.number()); |
328 | 328 | ||
329 | contact.setJobTitle(addr.role()); | 329 | contact.setJobTitle(addr.role()); |
330 | contact.setCompany(addr.organization()); | 330 | contact.setCompany(addr.organization()); |
331 | 331 | ||
332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); | 332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); |
333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); | 334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); |
335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); | 336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); |
337 | 337 | ||
338 | //personal | 338 | //personal |
339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
340 | // qtopia uses this categorization: | 340 | // qtopia uses this categorization: |
341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
343 | if (gt = "male") | 343 | if (gt = "male") |
344 | contact.setGender(PimContact::Male); | 344 | contact.setGender(PimContact::Male); |
345 | else if (gt = "female") | 345 | else if (gt = "female") |
346 | contact.setGender(PimContact::Female); | 346 | contact.setGender(PimContact::Female); |
347 | else | 347 | else |
348 | contact.setGender(PimContact::UnspecifiedGender); | 348 | contact.setGender(PimContact::UnspecifiedGender); |
349 | 349 | ||
350 | 350 | ||
351 | QDate dt = KGlobal::locale()->readDate( | 351 | QDate dt = KGlobal::locale()->readDate( |
352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
353 | contact.setAnniversary( dt ); | 353 | contact.setAnniversary( dt ); |
354 | 354 | ||
355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); | 355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); |
356 | 356 | ||
357 | contact.setBirthday(addr.birthday().date()); | 357 | contact.setBirthday(addr.birthday().date()); |
358 | contact.setNickname(addr.nickName()); | 358 | contact.setNickname(addr.nickName()); |
359 | 359 | ||
360 | // other | 360 | // other |
361 | contact.setNotes(addr.note()); | 361 | contact.setNotes(addr.note()); |
362 | 362 | ||
363 | //US QString groups() const { return find( Qtopia::Groups ); } | 363 | //US QString groups() const { return find( Qtopia::Groups ); } |
364 | //US QStringList groupList() const; | 364 | //US QStringList groupList() const; |
365 | 365 | ||
366 | 366 | ||
367 | QStringList cats = addr.categories(); | 367 | QStringList cats = addr.categories(); |
368 | 368 | ||
369 | QArray<int> iar; | 369 | QArray<int> iar; |
370 | if ( !cats.isEmpty() ) { | 370 | if ( !cats.isEmpty() ) { |
371 | QArray<int> iar = catDB->ids("contact", cats); | 371 | QArray<int> iar = catDB->ids("contact", cats); |
372 | contact.setCategories(iar); | 372 | contact.setCategories(iar); |
373 | } | 373 | } |
374 | 374 | ||
375 | return true; | 375 | return true; |
376 | } | 376 | } |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index adc7256..c013f52 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,441 +1,408 @@ | |||
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 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (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 "syncprefwidget.h" | 53 | #include "syncprefwidget.h" |
54 | 54 | ||
55 | #include "stdaddressbook.h" | 55 | #include "stdaddressbook.h" |
56 | 56 | ||
57 | #include "sharpdtmconverter.h" | 57 | #include "sharpdtmconverter.h" |
58 | //#define ALLOW_LOCKING | 58 | //#define ALLOW_LOCKING |
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_sharpdtm() | 62 | void *init_microkabc_sharpdtm() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); | 64 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 68 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
69 | : Resource( config, syncable ), mConverter (0) | 69 | : Resource( config, syncable ), mConverter (0) |
70 | { | 70 | { |
71 | // we can not choose the filename. Therefore use the default to display | 71 | // we can not choose the filename. Therefore use the default to display |
72 | 72 | ||
73 | QString fileName = SlZDataBase::addressbookFileName(); | 73 | QString fileName = SlZDataBase::addressbookFileName(); |
74 | init( fileName ); | 74 | init( fileName ); |
75 | } | 75 | } |
76 | 76 | ||
77 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 77 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) |
78 | : Resource( 0, syncable ) | 78 | : Resource( 0, syncable ) |
79 | { | 79 | { |
80 | init( fileName ); | 80 | init( fileName ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void ResourceSharpDTM::init( const QString &fileName ) | 83 | void ResourceSharpDTM::init( const QString &fileName ) |
84 | { | 84 | { |
85 | 85 | ||
86 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
87 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 87 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
88 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 88 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
89 | 89 | ||
90 | setFileName( fileName ); | 90 | setFileName( fileName ); |
91 | } | 91 | } |
92 | 92 | ||
93 | ResourceSharpDTM::~ResourceSharpDTM() | 93 | ResourceSharpDTM::~ResourceSharpDTM() |
94 | { | 94 | { |
95 | if (mConverter != 0) | 95 | if (mConverter != 0) |
96 | delete mConverter; | 96 | delete mConverter; |
97 | 97 | ||
98 | if(mAccess != 0) | 98 | if(mAccess != 0) |
99 | delete mAccess; | 99 | delete mAccess; |
100 | } | 100 | } |
101 | 101 | ||
102 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 102 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
103 | { | 103 | { |
104 | Resource::writeConfig( config ); | 104 | Resource::writeConfig( config ); |
105 | } | 105 | } |
106 | 106 | ||
107 | Ticket *ResourceSharpDTM::requestSaveTicket() | 107 | Ticket *ResourceSharpDTM::requestSaveTicket() |
108 | { | 108 | { |
109 | 109 | ||
110 | 110 | ||
111 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 111 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
112 | 112 | ||
113 | if ( !addressBook() ) return 0; | 113 | if ( !addressBook() ) return 0; |
114 | 114 | ||
115 | #ifdef ALLOW_LOCKING | 115 | #ifdef ALLOW_LOCKING |
116 | if ( !lock( fileName() ) ) { | 116 | if ( !lock( fileName() ) ) { |
117 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); | 117 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); |
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
120 | #endif | 120 | #endif |
121 | return createTicket( this ); | 121 | return createTicket( this ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | bool ResourceSharpDTM::doOpen() | 125 | bool ResourceSharpDTM::doOpen() |
126 | { | 126 | { |
127 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); | 127 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
128 | 128 | ||
129 | // the last parameter in the SlZDataBase constructor means "readonly" | 129 | // the last parameter in the SlZDataBase constructor means "readonly" |
130 | mAccess = new SlZDataBase(fileName(), | 130 | mAccess = new SlZDataBase(fileName(), |
131 | SlZDataBase::addressbookItems(), | 131 | SlZDataBase::addressbookItems(), |
132 | NULL, false); | 132 | NULL, false); |
133 | 133 | ||
134 | if ( !mAccess ) { | 134 | if ( !mAccess ) { |
135 | qDebug("Unable to load file() %s", fileName().latin1()); | 135 | qDebug("Unable to load file() %s", fileName().latin1()); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | 138 | ||
139 | if (mConverter == 0) | 139 | if (mConverter == 0) |
140 | { | 140 | { |
141 | mConverter = new SharpDTMConverter(); | 141 | mConverter = new SharpDTMConverter(); |
142 | bool res = mConverter->init(); | 142 | bool res = mConverter->init(); |
143 | if ( !res ) | 143 | if ( !res ) |
144 | { | 144 | { |
145 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 145 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
146 | 146 | ||
147 | qDebug(msg); | 147 | qDebug(msg); |
148 | delete mAccess; | 148 | delete mAccess; |
149 | mAccess = 0; | 149 | mAccess = 0; |
150 | return false; | 150 | return false; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | return true; | 154 | return true; |
155 | } | 155 | } |
156 | 156 | ||
157 | void ResourceSharpDTM::doClose() | 157 | void ResourceSharpDTM::doClose() |
158 | { | 158 | { |
159 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | 159 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); |
160 | 160 | ||
161 | if(mAccess) | 161 | if(mAccess) |
162 | { | 162 | { |
163 | delete mAccess; | 163 | delete mAccess; |
164 | mAccess = 0; | 164 | mAccess = 0; |
165 | } | 165 | } |
166 | // it seems so, that deletion of access deletes backend as well | 166 | // it seems so, that deletion of access deletes backend as well |
167 | //delete backend; | 167 | //delete backend; |
168 | 168 | ||
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool ResourceSharpDTM::load() | 172 | bool ResourceSharpDTM::load() |
173 | { | 173 | { |
174 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | 174 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); |
175 | 175 | ||
176 | bool res = false; | 176 | bool res = false; |
177 | 177 | ||
178 | CardId id; | 178 | CardId id; |
179 | 179 | ||
180 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 180 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
181 | { | 181 | { |
182 | id = mAccess->cardId(); | 182 | id = mAccess->cardId(); |
183 | 183 | ||
184 | KABC::Addressee addressee; | 184 | KABC::Addressee addressee; |
185 | 185 | ||
186 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 186 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
187 | 187 | ||
188 | if ( !addressee.isEmpty() && res ) | 188 | if ( !addressee.isEmpty() && res ) |
189 | { | 189 | { |
190 | addressee.setResource( this ); | 190 | addressee.setResource( this ); |
191 | addressBook()->insertAddressee( addressee ); | 191 | addressBook()->insertAddressee( addressee ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | return true; | 195 | return true; |
196 | } | 196 | } |
197 | 197 | ||
198 | bool ResourceSharpDTM::save( Ticket *ticket ) | 198 | bool ResourceSharpDTM::save( Ticket *ticket ) |
199 | { | 199 | { |
200 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 200 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
201 | 201 | ||
202 | mDirWatch.stopScan(); | 202 | mDirWatch.stopScan(); |
203 | 203 | ||
204 | KABC::AddressBook::Iterator it; | 204 | KABC::AddressBook::Iterator it; |
205 | bool res; | 205 | bool res; |
206 | KABC::Addressee::List changedAddressees; | 206 | KABC::Addressee::List changedAddressees; |
207 | typedef QMap<int,QString> AddresseeMap; | 207 | typedef QMap<int,QString> AddresseeMap; |
208 | AddresseeMap map; | 208 | AddresseeMap map; |
209 | CardId id ; | 209 | CardId id ; |
210 | 210 | ||
211 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 211 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
212 | 212 | ||
213 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 213 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
214 | QString uid = (*it).originalExternalUID(); | 214 | QString uid = (*it).originalExternalUID(); |
215 | bool res; | 215 | bool res; |
216 | if ( uid.isEmpty() ) | 216 | if ( uid.isEmpty() ) |
217 | id = 0; | 217 | id = 0; |
218 | else | 218 | else |
219 | id = uid.toUInt(); | 219 | id = uid.toUInt(); |
220 | KABC::Addressee addressee = (*it); | 220 | KABC::Addressee addressee = (*it); |
221 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 221 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
222 | res = mAccess->startEditCard(id); | 222 | res = mAccess->startEditCard(id); |
223 | if (res == true) | 223 | if (res == true) |
224 | { | 224 | { |
225 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 225 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
226 | if (res == true) | 226 | if (res == true) |
227 | { | 227 | { |
228 | res = mAccess->finishEditCard(&id); | 228 | res = mAccess->finishEditCard(&id); |
229 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 229 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
230 | //(*it).setExternalUID( QString::number( id ) ); | 230 | //(*it).setExternalUID( QString::number( id ) ); |
231 | //(*it).setOriginalExternalUID( QString::number( id ) ); | 231 | //(*it).setOriginalExternalUID( QString::number( id ) ); |
232 | map.insert(id,(*it).uid()); | 232 | map.insert(id,(*it).uid()); |
233 | |||
234 | #if 0 | ||
235 | KABC::Addressee addressee; | ||
236 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | ||
237 | addressee.setUid((*it).uid() ); | ||
238 | (it*).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
239 | res = mAccess->finishEditCard(&id); | ||
240 | //qDebug("2NEW id is %d", id); | ||
241 | addressee.setExternalUID( QString::number( id ) ); | ||
242 | addressee.setOriginalExternalUID( QString::number( id ) ); | ||
243 | changedAddressees.append( addressee ); | ||
244 | #endif | ||
245 | |||
246 | if (res == false) | 233 | if (res == false) |
247 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 234 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
248 | 235 | ||
249 | } | 236 | } |
250 | else | 237 | else |
251 | { | 238 | { |
252 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 239 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
253 | mAccess->cancelEditCard(); | 240 | mAccess->cancelEditCard(); |
254 | } | 241 | } |
255 | } | 242 | } |
256 | 243 | ||
257 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 244 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
258 | res = mAccess->deleteCard(&id); | 245 | res = mAccess->deleteCard(&id); |
259 | if ( res ) | 246 | if ( !res ) |
260 | qDebug("delete success "); | ||
261 | else | ||
262 | qDebug("delete error "); | 247 | qDebug("delete error "); |
263 | 248 | ||
264 | 249 | ||
265 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 250 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
266 | //changed | 251 | //changed |
267 | qDebug("changed ****"); | ||
268 | res = mAccess->startEditCard(id); | 252 | res = mAccess->startEditCard(id); |
269 | if (res == true) | 253 | if (res == true) |
270 | { | 254 | { |
271 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 255 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
272 | if (res == true) | 256 | if (res == true) |
273 | { | 257 | { |
274 | res = mAccess->finishEditCard(&id); | 258 | res = mAccess->finishEditCard(&id); |
275 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 259 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); |
276 | map.insert(id,(*it).uid()); | 260 | map.insert(id,(*it).uid()); |
277 | |||
278 | #if 0 | ||
279 | KABC::Addressee addressee; | ||
280 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | ||
281 | addressee.setUid((*it).uid() ); | ||
282 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | ||
283 | changedAddressees.append( addressee ); | ||
284 | res = mAccess->finishEditCard(&id); | ||
285 | #endif | ||
286 | if (res == false) | 261 | if (res == false) |
287 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 262 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
288 | 263 | ||
289 | } | 264 | } |
290 | else | 265 | else |
291 | { | 266 | { |
292 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 267 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
293 | mAccess->cancelEditCard(); | 268 | mAccess->cancelEditCard(); |
294 | } | 269 | } |
295 | } | 270 | } |
296 | } | 271 | } |
297 | } | 272 | } |
298 | 273 | ||
299 | } | 274 | } |
300 | AddresseeMap::Iterator itam; | 275 | AddresseeMap::Iterator itam; |
301 | for ( res=mAccess->first(); res == true; res=mAccess->next()) | 276 | for ( res=mAccess->first(); res == true; res=mAccess->next()) |
302 | { | 277 | { |
303 | id = mAccess->cardId(); | 278 | id = mAccess->cardId(); |
304 | int idint = id; | 279 | int idint = id; |
305 | itam = map.find( idint ); | 280 | itam = map.find( idint ); |
306 | if ( itam != map.end() ) { | 281 | if ( itam != map.end() ) { |
307 | KABC::Addressee addressee; | 282 | KABC::Addressee addressee; |
308 | qDebug("found change %d %s ", idint, itam.data().latin1()); | ||
309 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 283 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
310 | 284 | ||
311 | if ( !addressee.isEmpty() && res ) | 285 | if ( !addressee.isEmpty() && res ) |
312 | { | 286 | { |
313 | addressee.setResource( this ); | 287 | addressee.setResource( this ); |
314 | addressee.setUid( itam.data() ); | 288 | addressee.setUid( itam.data() ); |
315 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 289 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
316 | addressBook()->insertAddressee( addressee , false ); | 290 | addressBook()->insertAddressee( addressee , false ); |
317 | } | 291 | } |
318 | } | 292 | } |
319 | } | 293 | } |
320 | #if 0 | 294 | |
321 | KABC::Addressee::List::Iterator it2; | ||
322 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) { | ||
323 | (*it2).computeCsum( "Sharp_DTM" ); | ||
324 | qDebug("CSUM: %s ",(*it2).getCsum( "Sharp_DTM" ).latin1() ); | ||
325 | addressBook()->insertAddressee((*it2)); | ||
326 | } | ||
327 | #endif | ||
328 | //US mAccess->save(); | 295 | //US mAccess->save(); |
329 | 296 | ||
330 | mDirWatch.startScan(); | 297 | mDirWatch.startScan(); |
331 | delete ticket; | 298 | delete ticket; |
332 | unlock( fileName() ); | 299 | unlock( fileName() ); |
333 | 300 | ||
334 | return true; | 301 | return true; |
335 | } | 302 | } |
336 | 303 | ||
337 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 304 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
338 | { | 305 | { |
339 | #ifdef ALLOW_LOCKING | 306 | #ifdef ALLOW_LOCKING |
340 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | 307 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
341 | 308 | ||
342 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 309 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
343 | 310 | ||
344 | QString fn = lockfileName; | 311 | QString fn = lockfileName; |
345 | 312 | ||
346 | KURL url(fn); | 313 | KURL url(fn); |
347 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 314 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
348 | 315 | ||
349 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 316 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
350 | 317 | ||
351 | if (QFile::exists( lockName )) | 318 | if (QFile::exists( lockName )) |
352 | { | 319 | { |
353 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); | 320 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); |
354 | return false; | 321 | return false; |
355 | } | 322 | } |
356 | 323 | ||
357 | 324 | ||
358 | QString lockUniqueName; | 325 | QString lockUniqueName; |
359 | lockUniqueName = fn + KApplication::randomString( 8 ); | 326 | lockUniqueName = fn + KApplication::randomString( 8 ); |
360 | 327 | ||
361 | url = lockUniqueName; | 328 | url = lockUniqueName; |
362 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 329 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
363 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 330 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
364 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 331 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
365 | 332 | ||
366 | // Create unique file | 333 | // Create unique file |
367 | QFile file( mLockUniqueName ); | 334 | QFile file( mLockUniqueName ); |
368 | file.open( IO_WriteOnly ); | 335 | file.open( IO_WriteOnly ); |
369 | file.close(); | 336 | file.close(); |
370 | 337 | ||
371 | // Create lock file | 338 | // Create lock file |
372 | int result = 0; | 339 | int result = 0; |
373 | #ifndef _WIN32_ | 340 | #ifndef _WIN32_ |
374 | result = ::link( QFile::encodeName( mLockUniqueName ), | 341 | result = ::link( QFile::encodeName( mLockUniqueName ), |
375 | QFile::encodeName( lockName ) ); | 342 | QFile::encodeName( lockName ) ); |
376 | #endif | 343 | #endif |
377 | if ( result == 0 ) { | 344 | if ( result == 0 ) { |
378 | addressBook()->emitAddressBookLocked(); | 345 | addressBook()->emitAddressBookLocked(); |
379 | return true; | 346 | return true; |
380 | } | 347 | } |
381 | 348 | ||
382 | // TODO: check stat | 349 | // TODO: check stat |
383 | 350 | ||
384 | return false; | 351 | return false; |
385 | #else | 352 | #else |
386 | return true; | 353 | return true; |
387 | #endif | 354 | #endif |
388 | } | 355 | } |
389 | 356 | ||
390 | void ResourceSharpDTM::unlock( const QString &fileName ) | 357 | void ResourceSharpDTM::unlock( const QString &fileName ) |
391 | { | 358 | { |
392 | #ifdef ALLOW_LOCKING | 359 | #ifdef ALLOW_LOCKING |
393 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | 360 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); |
394 | 361 | ||
395 | QString fn = fileName; | 362 | QString fn = fileName; |
396 | KURL url(fn); | 363 | KURL url(fn); |
397 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 364 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
398 | 365 | ||
399 | QFile::remove( lockName ); | 366 | QFile::remove( lockName ); |
400 | QFile::remove( mLockUniqueName ); | 367 | QFile::remove( mLockUniqueName ); |
401 | addressBook()->emitAddressBookUnlocked(); | 368 | addressBook()->emitAddressBookUnlocked(); |
402 | #endif | 369 | #endif |
403 | } | 370 | } |
404 | 371 | ||
405 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 372 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
406 | { | 373 | { |
407 | mDirWatch.stopScan(); | 374 | mDirWatch.stopScan(); |
408 | mDirWatch.removeFile( fileName() ); | 375 | mDirWatch.removeFile( fileName() ); |
409 | 376 | ||
410 | Resource::setFileName( newFileName ); | 377 | Resource::setFileName( newFileName ); |
411 | 378 | ||
412 | mDirWatch.addFile( fileName() ); | 379 | mDirWatch.addFile( fileName() ); |
413 | mDirWatch.startScan(); | 380 | mDirWatch.startScan(); |
414 | 381 | ||
415 | } | 382 | } |
416 | 383 | ||
417 | void ResourceSharpDTM::fileChanged() | 384 | void ResourceSharpDTM::fileChanged() |
418 | { | 385 | { |
419 | // There is a small theoretical chance that KDirWatch calls us before | 386 | // There is a small theoretical chance that KDirWatch calls us before |
420 | // we are fully constructed | 387 | // we are fully constructed |
421 | if (!addressBook()) | 388 | if (!addressBook()) |
422 | return; | 389 | return; |
423 | 390 | ||
424 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 391 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
425 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 392 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
426 | load(); | 393 | load(); |
427 | addressBook()->emitAddressBookChanged(); | 394 | addressBook()->emitAddressBookChanged(); |
428 | } | 395 | } |
429 | } | 396 | } |
430 | 397 | ||
431 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 398 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
432 | { | 399 | { |
433 | } | 400 | } |
434 | 401 | ||
435 | void ResourceSharpDTM::cleanUp() | 402 | void ResourceSharpDTM::cleanUp() |
436 | { | 403 | { |
437 | unlock( fileName() ); | 404 | unlock( fileName() ); |
438 | } | 405 | } |
439 | 406 | ||
440 | 407 | ||
441 | 408 | ||