-rw-r--r-- | kabc/addressbook.cpp | 44 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 65 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 3 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 12 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 24 | ||||
-rw-r--r-- | libkdepim/phoneaccess.h | 2 |
7 files changed, 123 insertions, 30 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16927e2..d037d2f 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,241 +1,242 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
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 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | ||
50 | #include "addressbook.h" | 51 | #include "addressbook.h" |
51 | #include "resource.h" | 52 | #include "resource.h" |
52 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
53 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
54 | 55 | ||
55 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
56 | 57 | ||
57 | using namespace KABC; | 58 | using namespace KABC; |
58 | 59 | ||
59 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
60 | { | 61 | { |
61 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
62 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
63 | Field::List mAllFields; | 64 | Field::List mAllFields; |
64 | KConfig *mConfig; | 65 | KConfig *mConfig; |
65 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
66 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
67 | }; | 68 | }; |
68 | 69 | ||
69 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
70 | { | 71 | { |
71 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
72 | }; | 73 | }; |
73 | 74 | ||
74 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
75 | { | 76 | { |
76 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
77 | }; | 78 | }; |
78 | 79 | ||
79 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
80 | { | 81 | { |
81 | d = new IteratorData; | 82 | d = new IteratorData; |
82 | } | 83 | } |
83 | 84 | ||
84 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
85 | { | 86 | { |
86 | d = new IteratorData; | 87 | d = new IteratorData; |
87 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
88 | } | 89 | } |
89 | 90 | ||
90 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
91 | { | 92 | { |
92 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
93 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
94 | d = new IteratorData; | 95 | d = new IteratorData; |
95 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
96 | return *this; | 97 | return *this; |
97 | } | 98 | } |
98 | 99 | ||
99 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
100 | { | 101 | { |
101 | delete d; | 102 | delete d; |
102 | } | 103 | } |
103 | 104 | ||
104 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
105 | { | 106 | { |
106 | return *(d->mIt); | 107 | return *(d->mIt); |
107 | } | 108 | } |
108 | 109 | ||
109 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
110 | { | 111 | { |
111 | return *(d->mIt); | 112 | return *(d->mIt); |
112 | } | 113 | } |
113 | 114 | ||
114 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
115 | { | 116 | { |
116 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
117 | } | 118 | } |
118 | 119 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
120 | { | 121 | { |
121 | (d->mIt)++; | 122 | (d->mIt)++; |
122 | return *this; | 123 | return *this; |
123 | } | 124 | } |
124 | 125 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
126 | { | 127 | { |
127 | (d->mIt)++; | 128 | (d->mIt)++; |
128 | return *this; | 129 | return *this; |
129 | } | 130 | } |
130 | 131 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
132 | { | 133 | { |
133 | (d->mIt)--; | 134 | (d->mIt)--; |
134 | return *this; | 135 | return *this; |
135 | } | 136 | } |
136 | 137 | ||
137 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
138 | { | 139 | { |
139 | (d->mIt)--; | 140 | (d->mIt)--; |
140 | return *this; | 141 | return *this; |
141 | } | 142 | } |
142 | 143 | ||
143 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
144 | { | 145 | { |
145 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
146 | } | 147 | } |
147 | 148 | ||
148 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
149 | { | 150 | { |
150 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
151 | } | 152 | } |
152 | 153 | ||
153 | 154 | ||
154 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
155 | { | 156 | { |
156 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
157 | } | 158 | } |
158 | 159 | ||
159 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
160 | { | 161 | { |
161 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
162 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
163 | } | 164 | } |
164 | 165 | ||
165 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
166 | { | 167 | { |
167 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
168 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
169 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
170 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
171 | return *this; | 172 | return *this; |
172 | } | 173 | } |
173 | 174 | ||
174 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
175 | { | 176 | { |
176 | delete d; | 177 | delete d; |
177 | } | 178 | } |
178 | 179 | ||
179 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
180 | { | 181 | { |
181 | return *(d->mIt); | 182 | return *(d->mIt); |
182 | } | 183 | } |
183 | 184 | ||
184 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
185 | { | 186 | { |
186 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
187 | } | 188 | } |
188 | 189 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
190 | { | 191 | { |
191 | (d->mIt)++; | 192 | (d->mIt)++; |
192 | return *this; | 193 | return *this; |
193 | } | 194 | } |
194 | 195 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
196 | { | 197 | { |
197 | (d->mIt)++; | 198 | (d->mIt)++; |
198 | return *this; | 199 | return *this; |
199 | } | 200 | } |
200 | 201 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
202 | { | 203 | { |
203 | (d->mIt)--; | 204 | (d->mIt)--; |
204 | return *this; | 205 | return *this; |
205 | } | 206 | } |
206 | 207 | ||
207 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
208 | { | 209 | { |
209 | (d->mIt)--; | 210 | (d->mIt)--; |
210 | return *this; | 211 | return *this; |
211 | } | 212 | } |
212 | 213 | ||
213 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
214 | { | 215 | { |
215 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
216 | } | 217 | } |
217 | 218 | ||
218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
219 | { | 220 | { |
220 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
221 | } | 222 | } |
222 | 223 | ||
223 | 224 | ||
224 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
225 | { | 226 | { |
226 | init(0, "contact"); | 227 | init(0, "contact"); |
227 | } | 228 | } |
228 | 229 | ||
229 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
230 | { | 231 | { |
231 | init(config, "contact"); | 232 | init(config, "contact"); |
232 | } | 233 | } |
233 | 234 | ||
234 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
235 | { | 236 | { |
236 | init(config, family); | 237 | init(config, family); |
237 | 238 | ||
238 | } | 239 | } |
239 | 240 | ||
240 | // the default family is "contact" | 241 | // the default family is "contact" |
241 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
@@ -270,384 +271,427 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
270 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
272 | } | 273 | } |
273 | else { | 274 | else { |
274 | d->mConfig = 0; | 275 | d->mConfig = 0; |
275 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
276 | } | 277 | } |
277 | 278 | ||
278 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
279 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 280 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
280 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
281 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
282 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
283 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
285 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
286 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
288 | } | 289 | } |
289 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
290 | if ( !res ) { | 291 | if ( !res ) { |
291 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
292 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
293 | if ( res ) | 294 | if ( res ) |
294 | { | 295 | { |
295 | addResource( res ); | 296 | addResource( res ); |
296 | } | 297 | } |
297 | else | 298 | else |
298 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
299 | } | 300 | } |
300 | setStandardResource( res ); | 301 | setStandardResource( res ); |
301 | manager->writeConfig(); | 302 | manager->writeConfig(); |
302 | } | 303 | } |
303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
304 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
306 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
308 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
310 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
312 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
314 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
316 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
318 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
319 | 320 | ||
320 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
321 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
323 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
325 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
329 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
330 | } | 331 | } |
331 | 332 | ||
332 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
333 | { | 334 | { |
334 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
335 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
337 | delete d; d = 0; | 338 | delete d; d = 0; |
338 | } | 339 | } |
339 | 340 | ||
340 | bool AddressBook::load() | 341 | bool AddressBook::load() |
341 | { | 342 | { |
342 | 343 | ||
343 | 344 | ||
344 | clear(); | 345 | clear(); |
345 | 346 | ||
346 | KRES::Manager<Resource>::ActiveIterator it; | 347 | KRES::Manager<Resource>::ActiveIterator it; |
347 | bool ok = true; | 348 | bool ok = true; |
348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 349 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
349 | if ( !(*it)->load() ) { | 350 | if ( !(*it)->load() ) { |
350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 351 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
351 | ok = false; | 352 | ok = false; |
352 | } | 353 | } |
353 | 354 | ||
354 | // mark all addressees as unchanged | 355 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 356 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 357 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 358 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 359 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 360 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 361 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 362 | (*addrIt).setIDStr(id ); |
362 | } | 363 | } |
363 | } | 364 | } |
364 | blockLSEchange = true; | 365 | blockLSEchange = true; |
365 | return ok; | 366 | return ok; |
366 | } | 367 | } |
367 | 368 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 369 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 370 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 371 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 372 | ||
372 | if ( ticket->resource() ) { | 373 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 374 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 375 | return ticket->resource()->save( ticket ); |
375 | } | 376 | } |
376 | 377 | ||
377 | return false; | 378 | return false; |
378 | } | 379 | } |
379 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
380 | { | 381 | { |
381 | 382 | ||
382 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
383 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
385 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
386 | return ; | 387 | return ; |
387 | } | 388 | } |
388 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
389 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
390 | Iterator it; | 391 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 395 | if ( !(*it).IDStr().isEmpty() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 396 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
396 | } | 397 | } |
397 | KABC::VCardConverter converter; | 398 | KABC::VCardConverter converter; |
398 | QString vcard; | 399 | QString vcard; |
399 | //Resource *resource() const; | 400 | //Resource *resource() const; |
400 | converter.addresseeToVCard( *it, vcard, version ); | 401 | converter.addresseeToVCard( *it, vcard, version ); |
401 | t << vcard << "\r\n"; | 402 | t << vcard << "\r\n"; |
402 | } | 403 | } |
403 | t << "\r\n\r\n"; | 404 | t << "\r\n\r\n"; |
404 | outFile.close(); | 405 | outFile.close(); |
405 | } | 406 | } |
406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 407 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
407 | { | 408 | { |
408 | 409 | ||
409 | if ( removeOld ) | 410 | if ( removeOld ) |
410 | setUntagged(); | 411 | setUntagged(); |
411 | KABC::Addressee::List list; | 412 | KABC::Addressee::List list; |
412 | QFile file( fileName ); | 413 | QFile file( fileName ); |
413 | file.open( IO_ReadOnly ); | 414 | file.open( IO_ReadOnly ); |
414 | QByteArray rawData = file.readAll(); | 415 | QByteArray rawData = file.readAll(); |
415 | file.close(); | 416 | file.close(); |
416 | QString data; | 417 | QString data; |
417 | if ( replaceLabel ) { | 418 | if ( replaceLabel ) { |
418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 419 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
419 | data.replace ( QRegExp("LABEL") , "ADR" ); | 420 | data.replace ( QRegExp("LABEL") , "ADR" ); |
420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 421 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
421 | } else | 422 | } else |
422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 423 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
423 | KABC::VCardTool tool; | 424 | KABC::VCardTool tool; |
424 | list = tool.parseVCards( data ); | 425 | list = tool.parseVCards( data ); |
425 | KABC::Addressee::List::Iterator it; | 426 | KABC::Addressee::List::Iterator it; |
426 | for ( it = list.begin(); it != list.end(); ++it ) { | 427 | for ( it = list.begin(); it != list.end(); ++it ) { |
427 | (*it).setResource( 0 ); | 428 | (*it).setResource( 0 ); |
428 | if ( replaceLabel ) | 429 | if ( replaceLabel ) |
429 | (*it).removeVoice(); | 430 | (*it).removeVoice(); |
430 | if ( removeOld ) | 431 | if ( removeOld ) |
431 | (*it).setTagged( true ); | 432 | (*it).setTagged( true ); |
432 | insertAddressee( (*it), false, true ); | 433 | insertAddressee( (*it), false, true ); |
433 | } | 434 | } |
434 | if ( removeOld ) | 435 | if ( removeOld ) |
435 | removeUntagged(); | 436 | removeUntagged(); |
436 | } | 437 | } |
437 | void AddressBook::setUntagged() | 438 | void AddressBook::setUntagged() |
438 | { | 439 | { |
439 | Iterator ait; | 440 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 441 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | (*ait).setTagged( false ); | 442 | (*ait).setTagged( false ); |
442 | } | 443 | } |
443 | } | 444 | } |
444 | void AddressBook::removeUntagged() | 445 | void AddressBook::removeUntagged() |
445 | { | 446 | { |
446 | Iterator ait; | 447 | Iterator ait; |
447 | bool todelete = false; | 448 | bool todelete = false; |
448 | Iterator todel; | 449 | Iterator todel; |
449 | for ( ait = begin(); ait != end(); ++ait ) { | 450 | for ( ait = begin(); ait != end(); ++ait ) { |
450 | if ( todelete ) | 451 | if ( todelete ) |
451 | removeAddressee( todel ); | 452 | removeAddressee( todel ); |
452 | if (!(*ait).tagged()) { | 453 | if (!(*ait).tagged()) { |
453 | todelete = true; | 454 | todelete = true; |
454 | todel = ait; | 455 | todel = ait; |
455 | } else | 456 | } else |
456 | todelete = false; | 457 | todelete = false; |
457 | } | 458 | } |
458 | if ( todelete ) | 459 | if ( todelete ) |
459 | removeAddressee( todel ); | 460 | removeAddressee( todel ); |
460 | deleteRemovedAddressees(); | 461 | deleteRemovedAddressees(); |
461 | } | 462 | } |
463 | void AddressBook::smplifyAddressees() | ||
464 | { | ||
465 | Iterator ait; | ||
466 | for ( ait = begin(); ait != end(); ++ait ) { | ||
467 | (*ait).simplifyEmails(); | ||
468 | (*ait).simplifyPhoneNumbers(); | ||
469 | (*ait).simplifyPhoneNumberTypes(); | ||
470 | (*ait).simplifyAddresses(); | ||
471 | } | ||
472 | } | ||
473 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | ||
474 | { | ||
475 | Iterator ait; | ||
476 | for ( ait = begin(); ait != end(); ++ait ) { | ||
477 | QString id = (*ait).IDStr(); | ||
478 | (*ait).setIDStr( ":"); | ||
479 | (*ait).setExternalUID( id ); | ||
480 | (*ait).setOriginalExternalUID( id ); | ||
481 | if ( isPreSync ) | ||
482 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
483 | else | ||
484 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
485 | } | ||
486 | } | ||
487 | bool AddressBook::saveABphone( QString fileName ) | ||
488 | { | ||
489 | smplifyAddressees(); | ||
490 | qDebug("saveABphone:: saving AB... "); | ||
491 | if ( ! saveAB() ) | ||
492 | return false; | ||
493 | qDebug("saveABphone:: writing to phone... "); | ||
494 | if ( !PhoneAccess::writeToPhone( fileName) ) { | ||
495 | return false; | ||
496 | } | ||
497 | qDebug("saveABphone:: re-reading from phone... "); | ||
498 | if ( !PhoneAccess::readFromPhone( fileName) ) { | ||
499 | return false; | ||
500 | } | ||
501 | qDebug("reloading phone book... "); | ||
502 | if ( !load() ) | ||
503 | return false; | ||
504 | return true; | ||
505 | } | ||
462 | bool AddressBook::saveAB() | 506 | bool AddressBook::saveAB() |
463 | { | 507 | { |
464 | bool ok = true; | 508 | bool ok = true; |
465 | 509 | ||
466 | deleteRemovedAddressees(); | 510 | deleteRemovedAddressees(); |
467 | Iterator ait; | 511 | Iterator ait; |
468 | for ( ait = begin(); ait != end(); ++ait ) { | 512 | for ( ait = begin(); ait != end(); ++ait ) { |
469 | if ( !(*ait).IDStr().isEmpty() ) { | 513 | if ( !(*ait).IDStr().isEmpty() ) { |
470 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 514 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
471 | } | 515 | } |
472 | } | 516 | } |
473 | KRES::Manager<Resource>::ActiveIterator it; | 517 | KRES::Manager<Resource>::ActiveIterator it; |
474 | KRES::Manager<Resource> *manager = d->mManager; | 518 | KRES::Manager<Resource> *manager = d->mManager; |
475 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 519 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
476 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 520 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
477 | Ticket *ticket = requestSaveTicket( *it ); | 521 | Ticket *ticket = requestSaveTicket( *it ); |
478 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 522 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
479 | if ( !ticket ) { | 523 | if ( !ticket ) { |
480 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 524 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
481 | .arg( (*it)->resourceName() ) ); | 525 | .arg( (*it)->resourceName() ) ); |
482 | return false; | 526 | return false; |
483 | } | 527 | } |
484 | 528 | ||
485 | //if ( !save( ticket ) ) | 529 | //if ( !save( ticket ) ) |
486 | if ( ticket->resource() ) { | 530 | if ( ticket->resource() ) { |
487 | if ( ! ticket->resource()->save( ticket ) ) | 531 | if ( ! ticket->resource()->save( ticket ) ) |
488 | ok = false; | 532 | ok = false; |
489 | } else | 533 | } else |
490 | ok = false; | 534 | ok = false; |
491 | 535 | ||
492 | } | 536 | } |
493 | } | 537 | } |
494 | return ok; | 538 | return ok; |
495 | } | 539 | } |
496 | 540 | ||
497 | AddressBook::Iterator AddressBook::begin() | 541 | AddressBook::Iterator AddressBook::begin() |
498 | { | 542 | { |
499 | Iterator it = Iterator(); | 543 | Iterator it = Iterator(); |
500 | it.d->mIt = d->mAddressees.begin(); | 544 | it.d->mIt = d->mAddressees.begin(); |
501 | return it; | 545 | return it; |
502 | } | 546 | } |
503 | 547 | ||
504 | AddressBook::ConstIterator AddressBook::begin() const | 548 | AddressBook::ConstIterator AddressBook::begin() const |
505 | { | 549 | { |
506 | ConstIterator it = ConstIterator(); | 550 | ConstIterator it = ConstIterator(); |
507 | it.d->mIt = d->mAddressees.begin(); | 551 | it.d->mIt = d->mAddressees.begin(); |
508 | return it; | 552 | return it; |
509 | } | 553 | } |
510 | 554 | ||
511 | AddressBook::Iterator AddressBook::end() | 555 | AddressBook::Iterator AddressBook::end() |
512 | { | 556 | { |
513 | Iterator it = Iterator(); | 557 | Iterator it = Iterator(); |
514 | it.d->mIt = d->mAddressees.end(); | 558 | it.d->mIt = d->mAddressees.end(); |
515 | return it; | 559 | return it; |
516 | } | 560 | } |
517 | 561 | ||
518 | AddressBook::ConstIterator AddressBook::end() const | 562 | AddressBook::ConstIterator AddressBook::end() const |
519 | { | 563 | { |
520 | ConstIterator it = ConstIterator(); | 564 | ConstIterator it = ConstIterator(); |
521 | it.d->mIt = d->mAddressees.end(); | 565 | it.d->mIt = d->mAddressees.end(); |
522 | return it; | 566 | return it; |
523 | } | 567 | } |
524 | 568 | ||
525 | void AddressBook::clear() | 569 | void AddressBook::clear() |
526 | { | 570 | { |
527 | d->mAddressees.clear(); | 571 | d->mAddressees.clear(); |
528 | } | 572 | } |
529 | 573 | ||
530 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 574 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
531 | { | 575 | { |
532 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 576 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
533 | 577 | ||
534 | if ( !resource ) | 578 | if ( !resource ) |
535 | { | 579 | { |
536 | qDebug("AddressBook::requestSaveTicket no resource" ); | 580 | qDebug("AddressBook::requestSaveTicket no resource" ); |
537 | resource = standardResource(); | 581 | resource = standardResource(); |
538 | } | 582 | } |
539 | 583 | ||
540 | KRES::Manager<Resource>::ActiveIterator it; | 584 | KRES::Manager<Resource>::ActiveIterator it; |
541 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 585 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
542 | if ( (*it) == resource ) { | 586 | if ( (*it) == resource ) { |
543 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 587 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
544 | return 0; | 588 | return 0; |
545 | else | 589 | else |
546 | return (*it)->requestSaveTicket(); | 590 | return (*it)->requestSaveTicket(); |
547 | } | 591 | } |
548 | } | 592 | } |
549 | 593 | ||
550 | return 0; | 594 | return 0; |
551 | } | 595 | } |
552 | 596 | ||
553 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 597 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
554 | { | 598 | { |
555 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 599 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
556 | //qDebug("block insert "); | 600 | //qDebug("block insert "); |
557 | return; | 601 | return; |
558 | } | 602 | } |
559 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 603 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
560 | bool found = false; | 604 | bool found = false; |
561 | Addressee::List::Iterator it; | 605 | Addressee::List::Iterator it; |
562 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 606 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
563 | if ( a.uid() == (*it).uid() ) { | 607 | if ( a.uid() == (*it).uid() ) { |
564 | 608 | ||
565 | bool changed = false; | 609 | bool changed = false; |
566 | Addressee addr = a; | 610 | Addressee addr = a; |
567 | if ( addr != (*it) ) | 611 | if ( addr != (*it) ) |
568 | changed = true; | 612 | changed = true; |
569 | 613 | ||
570 | if ( takeResource ) { | 614 | if ( takeResource ) { |
571 | Resource * res = (*it).resource(); | 615 | Resource * res = (*it).resource(); |
572 | (*it) = a; | 616 | (*it) = a; |
573 | (*it).setResource( res ); | 617 | (*it).setResource( res ); |
574 | } else { | 618 | } else { |
575 | (*it) = a; | 619 | (*it) = a; |
576 | if ( (*it).resource() == 0 ) | 620 | if ( (*it).resource() == 0 ) |
577 | (*it).setResource( standardResource() ); | 621 | (*it).setResource( standardResource() ); |
578 | } | 622 | } |
579 | if ( changed ) { | 623 | if ( changed ) { |
580 | if ( setRev ) { | 624 | if ( setRev ) { |
581 | 625 | ||
582 | // get rid of micro seconds | 626 | // get rid of micro seconds |
583 | QDateTime dt = QDateTime::currentDateTime(); | 627 | QDateTime dt = QDateTime::currentDateTime(); |
584 | QTime t = dt.time(); | 628 | QTime t = dt.time(); |
585 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 629 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
586 | (*it).setRevision( dt ); | 630 | (*it).setRevision( dt ); |
587 | } | 631 | } |
588 | (*it).setChanged( true ); | 632 | (*it).setChanged( true ); |
589 | } | 633 | } |
590 | 634 | ||
591 | found = true; | 635 | found = true; |
592 | } else { | 636 | } else { |
593 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 637 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
594 | QString name = (*it).uid().mid( 19 ); | 638 | QString name = (*it).uid().mid( 19 ); |
595 | Addressee b = a; | 639 | Addressee b = a; |
596 | QString id = b.getID( name ); | 640 | QString id = b.getID( name ); |
597 | if ( ! id.isEmpty() ) { | 641 | if ( ! id.isEmpty() ) { |
598 | QString des = (*it).note(); | 642 | QString des = (*it).note(); |
599 | int startN; | 643 | int startN; |
600 | if( (startN = des.find( id ) ) >= 0 ) { | 644 | if( (startN = des.find( id ) ) >= 0 ) { |
601 | int endN = des.find( ",", startN+1 ); | 645 | int endN = des.find( ",", startN+1 ); |
602 | des = des.left( startN ) + des.mid( endN+1 ); | 646 | des = des.left( startN ) + des.mid( endN+1 ); |
603 | (*it).setNote( des ); | 647 | (*it).setNote( des ); |
604 | } | 648 | } |
605 | } | 649 | } |
606 | } | 650 | } |
607 | } | 651 | } |
608 | } | 652 | } |
609 | if ( found ) | 653 | if ( found ) |
610 | return; | 654 | return; |
611 | d->mAddressees.append( a ); | 655 | d->mAddressees.append( a ); |
612 | Addressee& addr = d->mAddressees.last(); | 656 | Addressee& addr = d->mAddressees.last(); |
613 | if ( addr.resource() == 0 ) | 657 | if ( addr.resource() == 0 ) |
614 | addr.setResource( standardResource() ); | 658 | addr.setResource( standardResource() ); |
615 | 659 | ||
616 | addr.setChanged( true ); | 660 | addr.setChanged( true ); |
617 | } | 661 | } |
618 | 662 | ||
619 | void AddressBook::removeAddressee( const Addressee &a ) | 663 | void AddressBook::removeAddressee( const Addressee &a ) |
620 | { | 664 | { |
621 | Iterator it; | 665 | Iterator it; |
622 | Iterator it2; | 666 | Iterator it2; |
623 | bool found = false; | 667 | bool found = false; |
624 | for ( it = begin(); it != end(); ++it ) { | 668 | for ( it = begin(); it != end(); ++it ) { |
625 | if ( a.uid() == (*it).uid() ) { | 669 | if ( a.uid() == (*it).uid() ) { |
626 | found = true; | 670 | found = true; |
627 | it2 = it; | 671 | it2 = it; |
628 | } else { | 672 | } else { |
629 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 673 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
630 | QString name = (*it).uid().mid( 19 ); | 674 | QString name = (*it).uid().mid( 19 ); |
631 | Addressee b = a; | 675 | Addressee b = a; |
632 | QString id = b.getID( name ); | 676 | QString id = b.getID( name ); |
633 | if ( ! id.isEmpty() ) { | 677 | if ( ! id.isEmpty() ) { |
634 | QString des = (*it).note(); | 678 | QString des = (*it).note(); |
635 | if( des.find( id ) < 0 ) { | 679 | if( des.find( id ) < 0 ) { |
636 | des += id + ","; | 680 | des += id + ","; |
637 | (*it).setNote( des ); | 681 | (*it).setNote( des ); |
638 | } | 682 | } |
639 | } | 683 | } |
640 | } | 684 | } |
641 | 685 | ||
642 | } | 686 | } |
643 | } | 687 | } |
644 | 688 | ||
645 | if ( found ) | 689 | if ( found ) |
646 | removeAddressee( it2 ); | 690 | removeAddressee( it2 ); |
647 | 691 | ||
648 | } | 692 | } |
649 | 693 | ||
650 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 694 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
651 | { | 695 | { |
652 | Iterator it = begin(); | 696 | Iterator it = begin(); |
653 | Iterator it2 ; | 697 | Iterator it2 ; |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 532e05d..cc755d1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,336 +1,339 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
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 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
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 ); | ||
146 | void smplifyAddressees(); | ||
147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | ||
145 | void export2File( QString fileName ); | 148 | void export2File( QString fileName ); |
146 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 149 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
147 | void setUntagged(); | 150 | void setUntagged(); |
148 | void removeUntagged(); | 151 | void removeUntagged(); |
149 | /** | 152 | /** |
150 | Returns a iterator for first entry of address book. | 153 | Returns a iterator for first entry of address book. |
151 | */ | 154 | */ |
152 | Iterator begin(); | 155 | Iterator begin(); |
153 | 156 | ||
154 | /** | 157 | /** |
155 | Returns a const iterator for first entry of address book. | 158 | Returns a const iterator for first entry of address book. |
156 | */ | 159 | */ |
157 | ConstIterator begin() const; | 160 | ConstIterator begin() const; |
158 | 161 | ||
159 | /** | 162 | /** |
160 | Returns a iterator for first entry of address book. | 163 | Returns a iterator for first entry of address book. |
161 | */ | 164 | */ |
162 | Iterator end(); | 165 | Iterator end(); |
163 | 166 | ||
164 | /** | 167 | /** |
165 | Returns a const iterator for first entry of address book. | 168 | Returns a const iterator for first entry of address book. |
166 | */ | 169 | */ |
167 | ConstIterator end() const; | 170 | ConstIterator end() const; |
168 | 171 | ||
169 | /** | 172 | /** |
170 | Removes all entries from address book. | 173 | Removes all entries from address book. |
171 | */ | 174 | */ |
172 | void clear(); | 175 | void clear(); |
173 | 176 | ||
174 | /** | 177 | /** |
175 | Insert an Addressee object into address book. If an object with the same | 178 | Insert an Addressee object into address book. If an object with the same |
176 | unique id already exists in the address book it it replaced by the new | 179 | unique id already exists in the address book it it replaced by the new |
177 | one. If not the new object is appended to the address book. | 180 | one. If not the new object is appended to the address book. |
178 | */ | 181 | */ |
179 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 182 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
180 | 183 | ||
181 | /** | 184 | /** |
182 | Removes entry from the address book. | 185 | Removes entry from the address book. |
183 | */ | 186 | */ |
184 | void removeAddressee( const Addressee & ); | 187 | void removeAddressee( const Addressee & ); |
185 | 188 | ||
186 | /** | 189 | /** |
187 | This is like @ref removeAddressee() just above, with the difference that | 190 | This is like @ref removeAddressee() just above, with the difference that |
188 | the first element is a iterator, returned by @ref begin(). | 191 | the first element is a iterator, returned by @ref begin(). |
189 | */ | 192 | */ |
190 | void removeAddressee( const Iterator & ); | 193 | void removeAddressee( const Iterator & ); |
191 | 194 | ||
192 | /** | 195 | /** |
193 | Find the specified entry in address book. Returns end(), if the entry | 196 | Find the specified entry in address book. Returns end(), if the entry |
194 | couldn't be found. | 197 | couldn't be found. |
195 | */ | 198 | */ |
196 | Iterator find( const Addressee & ); | 199 | Iterator find( const Addressee & ); |
197 | 200 | ||
198 | /** | 201 | /** |
199 | Find the entry specified by an unique id. Returns an empty Addressee | 202 | Find the entry specified by an unique id. Returns an empty Addressee |
200 | object, if the address book does not contain an entry with this id. | 203 | object, if the address book does not contain an entry with this id. |
201 | */ | 204 | */ |
202 | Addressee findByUid( const QString & ); | 205 | Addressee findByUid( const QString & ); |
203 | 206 | ||
204 | 207 | ||
205 | /** | 208 | /** |
206 | Returns a list of all addressees in the address book. This list can | 209 | Returns a list of all addressees in the address book. This list can |
207 | be sorted with @ref KABC::AddresseeList for example. | 210 | be sorted with @ref KABC::AddresseeList for example. |
208 | */ | 211 | */ |
209 | Addressee::List allAddressees(); | 212 | Addressee::List allAddressees(); |
210 | 213 | ||
211 | /** | 214 | /** |
212 | Find all entries with the specified name in the address book. Returns | 215 | Find all entries with the specified name in the address book. Returns |
213 | an empty list, if no entries could be found. | 216 | an empty list, if no entries could be found. |
214 | */ | 217 | */ |
215 | Addressee::List findByName( const QString & ); | 218 | Addressee::List findByName( const QString & ); |
216 | 219 | ||
217 | /** | 220 | /** |
218 | Find all entries with the specified email address in the address book. | 221 | Find all entries with the specified email address in the address book. |
219 | Returns an empty list, if no entries could be found. | 222 | Returns an empty list, if no entries could be found. |
220 | */ | 223 | */ |
221 | Addressee::List findByEmail( const QString & ); | 224 | Addressee::List findByEmail( const QString & ); |
222 | 225 | ||
223 | /** | 226 | /** |
224 | Find all entries wich have the specified category in the address book. | 227 | Find all entries wich have the specified category in the address book. |
225 | Returns an empty list, if no entries could be found. | 228 | Returns an empty list, if no entries could be found. |
226 | */ | 229 | */ |
227 | Addressee::List findByCategory( const QString & ); | 230 | Addressee::List findByCategory( const QString & ); |
228 | 231 | ||
229 | /** | 232 | /** |
230 | Return a string identifying this addressbook. | 233 | Return a string identifying this addressbook. |
231 | */ | 234 | */ |
232 | virtual QString identifier(); | 235 | virtual QString identifier(); |
233 | 236 | ||
234 | /** | 237 | /** |
235 | Used for debug output. | 238 | Used for debug output. |
236 | */ | 239 | */ |
237 | void dump() const; | 240 | void dump() const; |
238 | 241 | ||
239 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 242 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
240 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 243 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
241 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 244 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
242 | 245 | ||
243 | /** | 246 | /** |
244 | Return list of all Fields known to the address book which are associated | 247 | Return list of all Fields known to the address book which are associated |
245 | with the given field category. | 248 | with the given field category. |
246 | */ | 249 | */ |
247 | Field::List fields( int category = Field::All ); | 250 | Field::List fields( int category = Field::All ); |
248 | 251 | ||
249 | /** | 252 | /** |
250 | Add custom field to address book. | 253 | Add custom field to address book. |
251 | 254 | ||
252 | @param label User visible label of the field. | 255 | @param label User visible label of the field. |
253 | @param category Ored list of field categories. | 256 | @param category Ored list of field categories. |
254 | @param key Identifier used as key for reading and writing the field. | 257 | @param key Identifier used as key for reading and writing the field. |
255 | @param app String used as application key for reading and writing | 258 | @param app String used as application key for reading and writing |
256 | the field. | 259 | the field. |
257 | */ | 260 | */ |
258 | bool addCustomField( const QString &label, int category = Field::All, | 261 | bool addCustomField( const QString &label, int category = Field::All, |
259 | const QString &key = QString::null, | 262 | const QString &key = QString::null, |
260 | const QString &app = QString::null ); | 263 | const QString &app = QString::null ); |
261 | 264 | ||
262 | 265 | ||
263 | /** | 266 | /** |
264 | Add address book resource. | 267 | Add address book resource. |
265 | */ | 268 | */ |
266 | bool addResource( Resource * ); | 269 | bool addResource( Resource * ); |
267 | 270 | ||
268 | /** | 271 | /** |
269 | Remove address book resource. | 272 | Remove address book resource. |
270 | */ | 273 | */ |
271 | bool removeResource( Resource * ); | 274 | bool removeResource( Resource * ); |
272 | 275 | ||
273 | /** | 276 | /** |
274 | Return pointer list of all resources. | 277 | Return pointer list of all resources. |
275 | */ | 278 | */ |
276 | QPtrList<Resource> resources(); | 279 | QPtrList<Resource> resources(); |
277 | 280 | ||
278 | /** | 281 | /** |
279 | Set the @p ErrorHandler, that is used by @ref error() to | 282 | Set the @p ErrorHandler, that is used by @ref error() to |
280 | provide gui-independend error messages. | 283 | provide gui-independend error messages. |
281 | */ | 284 | */ |
282 | void setErrorHandler( ErrorHandler * ); | 285 | void setErrorHandler( ErrorHandler * ); |
283 | 286 | ||
284 | /** | 287 | /** |
285 | Shows gui independend error messages. | 288 | Shows gui independend error messages. |
286 | */ | 289 | */ |
287 | void error( const QString& ); | 290 | void error( const QString& ); |
288 | 291 | ||
289 | /** | 292 | /** |
290 | Query all resources to clean up their lock files | 293 | Query all resources to clean up their lock files |
291 | */ | 294 | */ |
292 | void cleanUp(); | 295 | void cleanUp(); |
293 | 296 | ||
294 | // sync stuff | 297 | // sync stuff |
295 | //Addressee::List getExternLastSyncAddressees(); | 298 | //Addressee::List getExternLastSyncAddressees(); |
296 | void resetTempSyncStat(); | 299 | void resetTempSyncStat(); |
297 | QStringList uidList(); | 300 | QStringList uidList(); |
298 | void removeSyncAddressees( bool removeDeleted = false ); | 301 | void removeSyncAddressees( bool removeDeleted = false ); |
299 | void mergeAB( AddressBook *aBook, const QString& profile ); | 302 | void mergeAB( AddressBook *aBook, const QString& profile ); |
300 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 303 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
301 | bool containsExternalUid( const QString& uid ); | 304 | bool containsExternalUid( const QString& uid ); |
302 | 305 | ||
303 | void preExternSync( AddressBook* aBook, const QString& csd ); | 306 | void preExternSync( AddressBook* aBook, const QString& csd ); |
304 | void postExternSync( AddressBook* aBook, const QString& csd ); | 307 | void postExternSync( AddressBook* aBook, const QString& csd ); |
305 | signals: | 308 | signals: |
306 | /** | 309 | /** |
307 | Emitted, when the address book has changed on disk. | 310 | Emitted, when the address book has changed on disk. |
308 | */ | 311 | */ |
309 | void addressBookChanged( AddressBook * ); | 312 | void addressBookChanged( AddressBook * ); |
310 | 313 | ||
311 | /** | 314 | /** |
312 | Emitted, when the address book has been locked for writing. | 315 | Emitted, when the address book has been locked for writing. |
313 | */ | 316 | */ |
314 | void addressBookLocked( AddressBook * ); | 317 | void addressBookLocked( AddressBook * ); |
315 | 318 | ||
316 | /** | 319 | /** |
317 | Emitted, when the address book has been unlocked. | 320 | Emitted, when the address book has been unlocked. |
318 | */ | 321 | */ |
319 | void addressBookUnlocked( AddressBook * ); | 322 | void addressBookUnlocked( AddressBook * ); |
320 | 323 | ||
321 | protected: | 324 | protected: |
322 | void deleteRemovedAddressees(); | 325 | void deleteRemovedAddressees(); |
323 | void setStandardResource( Resource * ); | 326 | void setStandardResource( Resource * ); |
324 | Resource *standardResource(); | 327 | Resource *standardResource(); |
325 | KRES::Manager<Resource> *resourceManager(); | 328 | KRES::Manager<Resource> *resourceManager(); |
326 | 329 | ||
327 | void init(const QString &config, const QString &family); | 330 | void init(const QString &config, const QString &family); |
328 | 331 | ||
329 | private: | 332 | private: |
330 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 333 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
331 | 334 | ||
332 | 335 | ||
333 | struct AddressBookData; | 336 | struct AddressBookData; |
334 | AddressBookData *d; | 337 | AddressBookData *d; |
335 | bool blockLSEchange; | 338 | bool blockLSEchange; |
336 | }; | 339 | }; |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 452f1bc..a7967cb 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2634,266 +2634,291 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2634 | } | 2634 | } |
2635 | } else { // no conflict | 2635 | } else { // no conflict |
2636 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2636 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2637 | QString des = addresseeLSync.note(); | 2637 | QString des = addresseeLSync.note(); |
2638 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2638 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2639 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2639 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2640 | remote->insertAddressee( inR, false ); | 2640 | remote->insertAddressee( inR, false ); |
2641 | ++deletedAddresseeR; | 2641 | ++deletedAddresseeR; |
2642 | } else { | 2642 | } else { |
2643 | inR.setRevision( modifiedCalendar ); | 2643 | inR.setRevision( modifiedCalendar ); |
2644 | remote->insertAddressee( inR, false ); | 2644 | remote->insertAddressee( inR, false ); |
2645 | inL = inR; | 2645 | inL = inR; |
2646 | inL.setResource( 0 ); | 2646 | inL.setResource( 0 ); |
2647 | local->insertAddressee( inL , false); | 2647 | local->insertAddressee( inL , false); |
2648 | ++addedAddressee; | 2648 | ++addedAddressee; |
2649 | } | 2649 | } |
2650 | } else { | 2650 | } else { |
2651 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2651 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2652 | inR.setRevision( modifiedCalendar ); | 2652 | inR.setRevision( modifiedCalendar ); |
2653 | remote->insertAddressee( inR, false ); | 2653 | remote->insertAddressee( inR, false ); |
2654 | inR.setResource( 0 ); | 2654 | inR.setResource( 0 ); |
2655 | local->insertAddressee( inR, false ); | 2655 | local->insertAddressee( inR, false ); |
2656 | ++addedAddressee; | 2656 | ++addedAddressee; |
2657 | } else { | 2657 | } else { |
2658 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2658 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2659 | remote->removeAddressee( inR ); | 2659 | remote->removeAddressee( inR ); |
2660 | ++deletedAddresseeR; | 2660 | ++deletedAddresseeR; |
2661 | } | 2661 | } |
2662 | } | 2662 | } |
2663 | } | 2663 | } |
2664 | } | 2664 | } |
2665 | ++incCounter; | 2665 | ++incCounter; |
2666 | } | 2666 | } |
2667 | er.clear(); | 2667 | er.clear(); |
2668 | QStringList el = local->uidList(); | 2668 | QStringList el = local->uidList(); |
2669 | modulo = (el.count()/10)+1; | 2669 | modulo = (el.count()/10)+1; |
2670 | 2670 | ||
2671 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2671 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2672 | incCounter = 0; | 2672 | incCounter = 0; |
2673 | while ( incCounter < el.count()) { | 2673 | while ( incCounter < el.count()) { |
2674 | qApp->processEvents(); | 2674 | qApp->processEvents(); |
2675 | if (syncManager->isProgressBarCanceled()) | 2675 | if (syncManager->isProgressBarCanceled()) |
2676 | return false; | 2676 | return false; |
2677 | if ( incCounter % modulo == 0 ) | 2677 | if ( incCounter % modulo == 0 ) |
2678 | syncManager->showProgressBar(incCounter); | 2678 | syncManager->showProgressBar(incCounter); |
2679 | uid = el[ incCounter ]; | 2679 | uid = el[ incCounter ]; |
2680 | bool skipIncidence = false; | 2680 | bool skipIncidence = false; |
2681 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2681 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2682 | skipIncidence = true; | 2682 | skipIncidence = true; |
2683 | if ( !skipIncidence ) { | 2683 | if ( !skipIncidence ) { |
2684 | inL = local->findByUid( uid ); | 2684 | inL = local->findByUid( uid ); |
2685 | inR = remote->findByUid( uid ); | 2685 | inR = remote->findByUid( uid ); |
2686 | if ( inR.isEmpty() ) { | 2686 | if ( inR.isEmpty() ) { |
2687 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2687 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2688 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2688 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2689 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2689 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2690 | local->removeAddressee( inL ); | 2690 | local->removeAddressee( inL ); |
2691 | ++deletedAddresseeL; | 2691 | ++deletedAddresseeL; |
2692 | } else { | 2692 | } else { |
2693 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2693 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2694 | inL.removeID(mCurrentSyncDevice ); | 2694 | inL.removeID(mCurrentSyncDevice ); |
2695 | ++addedAddresseeR; | 2695 | ++addedAddresseeR; |
2696 | inL.setRevision( modifiedCalendar ); | 2696 | inL.setRevision( modifiedCalendar ); |
2697 | local->insertAddressee( inL, false ); | 2697 | local->insertAddressee( inL, false ); |
2698 | inR = inL; | 2698 | inR = inL; |
2699 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2699 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2700 | inR.setResource( 0 ); | 2700 | inR.setResource( 0 ); |
2701 | remote->insertAddressee( inR, false ); | 2701 | remote->insertAddressee( inR, false ); |
2702 | } | 2702 | } |
2703 | } | 2703 | } |
2704 | } else { | 2704 | } else { |
2705 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2705 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2706 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2706 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2707 | local->removeAddressee( inL ); | 2707 | local->removeAddressee( inL ); |
2708 | ++deletedAddresseeL; | 2708 | ++deletedAddresseeL; |
2709 | } else { | 2709 | } else { |
2710 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2710 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2711 | ++addedAddresseeR; | 2711 | ++addedAddresseeR; |
2712 | inL.setRevision( modifiedCalendar ); | 2712 | inL.setRevision( modifiedCalendar ); |
2713 | local->insertAddressee( inL, false ); | 2713 | local->insertAddressee( inL, false ); |
2714 | inR = inL; | 2714 | inR = inL; |
2715 | inR.setResource( 0 ); | 2715 | inR.setResource( 0 ); |
2716 | remote->insertAddressee( inR, false ); | 2716 | remote->insertAddressee( inR, false ); |
2717 | } | 2717 | } |
2718 | } | 2718 | } |
2719 | } | 2719 | } |
2720 | } | 2720 | } |
2721 | } | 2721 | } |
2722 | ++incCounter; | 2722 | ++incCounter; |
2723 | } | 2723 | } |
2724 | el.clear(); | 2724 | el.clear(); |
2725 | syncManager->hideProgressBar(); | 2725 | syncManager->hideProgressBar(); |
2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2727 | // get rid of micro seconds | 2727 | // get rid of micro seconds |
2728 | QTime t = mLastAddressbookSync.time(); | 2728 | QTime t = mLastAddressbookSync.time(); |
2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2730 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2730 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2731 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2731 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2738 | addresseeRSync.setNote( "" ) ; | 2738 | addresseeRSync.setNote( "" ) ; |
2739 | addresseeLSync.setNote( "" ); | 2739 | addresseeLSync.setNote( "" ); |
2740 | 2740 | ||
2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2742 | remote->insertAddressee( addresseeRSync, false ); | 2742 | remote->insertAddressee( addresseeRSync, false ); |
2743 | local->insertAddressee( addresseeLSync, false ); | 2743 | local->insertAddressee( addresseeLSync, false ); |
2744 | QString mes; | 2744 | QString mes; |
2745 | 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 ); | 2745 | 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 ); |
2746 | if ( syncManager->mShowSyncSummary ) { | 2746 | if ( syncManager->mShowSyncSummary ) { |
2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2748 | } | 2748 | } |
2749 | qDebug( mes ); | 2749 | qDebug( mes ); |
2750 | return syncOK; | 2750 | return syncOK; |
2751 | } | 2751 | } |
2752 | 2752 | ||
2753 | 2753 | ||
2754 | //this is a overwritten callbackmethods from the syncinterface | 2754 | //this is a overwritten callbackmethods from the syncinterface |
2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2756 | { | 2756 | { |
2757 | 2757 | ||
2758 | //pending prepare addresseeview for output | 2758 | //pending prepare addresseeview for output |
2759 | //pending detect, if remote file has REV field. if not switch to external sync | 2759 | //pending detect, if remote file has REV field. if not switch to external sync |
2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2762 | 2762 | ||
2763 | AddressBook abLocal(filename,"syncContact"); | 2763 | AddressBook abLocal(filename,"syncContact"); |
2764 | bool syncOK = false; | 2764 | bool syncOK = false; |
2765 | if ( abLocal.load() ) { | 2765 | if ( abLocal.load() ) { |
2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2767 | bool external = false; | 2767 | bool external = false; |
2768 | bool isXML = false; | 2768 | bool isXML = false; |
2769 | if ( filename.right(4) == ".xml") { | 2769 | if ( filename.right(4) == ".xml") { |
2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2771 | isXML = true; | 2771 | isXML = true; |
2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2773 | } else { | 2773 | } else { |
2774 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2774 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2775 | if ( ! lse.isEmpty() ) { | 2775 | if ( ! lse.isEmpty() ) { |
2776 | if ( lse.familyName().left(4) == "!E: " ) | 2776 | if ( lse.familyName().left(4) == "!E: " ) |
2777 | external = true; | 2777 | external = true; |
2778 | } else { | 2778 | } else { |
2779 | bool found = false; | 2779 | bool found = false; |
2780 | AddressBook::Iterator it; | 2780 | AddressBook::Iterator it; |
2781 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2781 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2782 | if ( (*it).revision().date().year() > 2003 ) { | 2782 | if ( (*it).revision().date().year() > 2003 ) { |
2783 | found = true; | 2783 | found = true; |
2784 | break; | 2784 | break; |
2785 | } | 2785 | } |
2786 | } | 2786 | } |
2787 | external = ! found; | 2787 | external = ! found; |
2788 | } | 2788 | } |
2789 | 2789 | ||
2790 | if ( external ) { | 2790 | if ( external ) { |
2791 | qDebug("Setting vcf mode to external "); | 2791 | qDebug("Setting vcf mode to external "); |
2792 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2792 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2793 | AddressBook::Iterator it; | 2793 | AddressBook::Iterator it; |
2794 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2794 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2795 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2795 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2796 | (*it).computeCsum( mCurrentSyncDevice ); | 2796 | (*it).computeCsum( mCurrentSyncDevice ); |
2797 | } | 2797 | } |
2798 | } | 2798 | } |
2799 | } | 2799 | } |
2800 | //AddressBook::Iterator it; | 2800 | //AddressBook::Iterator it; |
2801 | //QStringList vcards; | 2801 | //QStringList vcards; |
2802 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2802 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2803 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2803 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2804 | //} | 2804 | //} |
2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2806 | if ( syncOK ) { | 2806 | if ( syncOK ) { |
2807 | if ( syncManager->mWriteBackFile ) | 2807 | if ( syncManager->mWriteBackFile ) |
2808 | { | 2808 | { |
2809 | if ( external ) | 2809 | if ( external ) |
2810 | abLocal.removeSyncAddressees( !isXML); | 2810 | abLocal.removeSyncAddressees( !isXML); |
2811 | qDebug("Saving remote AB "); | 2811 | qDebug("Saving remote AB "); |
2812 | if ( ! abLocal.saveAB()) | 2812 | if ( ! abLocal.saveAB()) |
2813 | qDebug("Error writing back AB to file "); | 2813 | qDebug("Error writing back AB to file "); |
2814 | if ( isXML ) { | 2814 | if ( isXML ) { |
2815 | // afterwrite processing | 2815 | // afterwrite processing |
2816 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2816 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2817 | } | 2817 | } |
2818 | } | 2818 | } |
2819 | } | 2819 | } |
2820 | setModified(); | 2820 | setModified(); |
2821 | 2821 | ||
2822 | } | 2822 | } |
2823 | if ( syncOK ) | 2823 | if ( syncOK ) |
2824 | mViewManager->refreshView(); | 2824 | mViewManager->refreshView(); |
2825 | return syncOK; | 2825 | return syncOK; |
2826 | #if 0 | ||
2827 | 2826 | ||
2828 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | ||
2829 | getEventViewerDialog()->setSyncMode( true ); | ||
2830 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | ||
2831 | getEventViewerDialog()->setSyncMode( false ); | ||
2832 | if ( syncOK ) { | ||
2833 | if ( KOPrefs::instance()->mWriteBackFile ) | ||
2834 | { | ||
2835 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | ||
2836 | storage->save(); | ||
2837 | } | ||
2838 | } | ||
2839 | setModified(); | ||
2840 | } | ||
2841 | |||
2842 | #endif | ||
2843 | } | 2827 | } |
2844 | 2828 | ||
2845 | 2829 | ||
2846 | //this is a overwritten callbackmethods from the syncinterface | 2830 | //this is a overwritten callbackmethods from the syncinterface |
2847 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2831 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2848 | { | 2832 | { |
2833 | if ( resource == "phone" ) | ||
2834 | return syncPhone(); | ||
2849 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2835 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2850 | 2836 | ||
2851 | AddressBook abLocal( resource,"syncContact"); | 2837 | AddressBook abLocal( resource,"syncContact"); |
2852 | bool syncOK = false; | 2838 | bool syncOK = false; |
2853 | if ( abLocal.load() ) { | 2839 | if ( abLocal.load() ) { |
2854 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2840 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2855 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2841 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2856 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2842 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2857 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2843 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2858 | if ( syncOK ) { | 2844 | if ( syncOK ) { |
2859 | if ( syncManager->mWriteBackFile ) { | 2845 | if ( syncManager->mWriteBackFile ) { |
2860 | abLocal.saveAB(); | 2846 | abLocal.saveAB(); |
2861 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2847 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2862 | } | 2848 | } |
2863 | } | 2849 | } |
2864 | setModified(); | 2850 | setModified(); |
2865 | } | 2851 | } |
2866 | if ( syncOK ) | 2852 | if ( syncOK ) |
2867 | mViewManager->refreshView(); | 2853 | mViewManager->refreshView(); |
2868 | return syncOK; | 2854 | return syncOK; |
2869 | 2855 | ||
2870 | } | 2856 | } |
2871 | 2857 | void KABCore::message( QString m ) | |
2872 | void KABCore::getFile( bool success ) | ||
2873 | { | 2858 | { |
2859 | |||
2860 | topLevelWidget()->setCaption( m ); | ||
2874 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); | 2861 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); |
2862 | } | ||
2863 | bool KABCore::syncPhone() | ||
2864 | { | ||
2865 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
2866 | QString fileName; | ||
2867 | #ifdef _WIN32_ | ||
2868 | fileName = locateLocal("tmp", "phonefile.vcf"); | ||
2869 | #else | ||
2870 | fileName = "/tmp/phonefile.vcf"; | ||
2871 | #endif | ||
2872 | if ( !PhoneAccess::readFromPhone( fileName) ) { | ||
2873 | message(i18n("Phone access failed!")); | ||
2874 | return false; | ||
2875 | } | ||
2876 | AddressBook abLocal( fileName,"syncContact"); | ||
2877 | bool syncOK = false; | ||
2878 | if ( abLocal.load() ) { | ||
2879 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | ||
2880 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | ||
2881 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | ||
2882 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | ||
2883 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | ||
2884 | if ( syncOK ) { | ||
2885 | if ( syncManager->mWriteBackFile ) { | ||
2886 | abLocal.saveABphone( fileName ); | ||
2887 | abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | ||
2888 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | ||
2889 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | ||
2890 | } | ||
2891 | } | ||
2892 | setModified(); | ||
2893 | } | ||
2894 | if ( syncOK ) | ||
2895 | mViewManager->refreshView(); | ||
2896 | return syncOK; | ||
2897 | } | ||
2898 | void KABCore::getFile( bool success ) | ||
2899 | { | ||
2875 | if ( ! success ) { | 2900 | if ( ! success ) { |
2876 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 2901 | message( i18n("Error receiving file. Nothing changed!") ); |
2877 | return; | 2902 | return; |
2878 | } | 2903 | } |
2879 | mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2904 | mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2880 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 2905 | message( i18n("Pi-Sync successful!") ); |
2881 | mViewManager->refreshView(); | 2906 | mViewManager->refreshView(); |
2882 | } | 2907 | } |
2883 | void KABCore::syncFileRequest() | 2908 | void KABCore::syncFileRequest() |
2884 | { | 2909 | { |
2885 | mAddressBook->export2File( sentSyncFile() ); | 2910 | mAddressBook->export2File( sentSyncFile() ); |
2886 | } | 2911 | } |
2887 | QString KABCore::sentSyncFile() | 2912 | QString KABCore::sentSyncFile() |
2888 | { | 2913 | { |
2889 | #ifdef _WIN32_ | 2914 | #ifdef _WIN32_ |
2890 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2915 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2891 | #else | 2916 | #else |
2892 | return QString( "/tmp/copysyncab.vcf" ); | 2917 | return QString( "/tmp/copysyncab.vcf" ); |
2893 | #endif | 2918 | #endif |
2894 | } | 2919 | } |
2895 | 2920 | ||
2896 | void KABCore::setCaptionBack() | 2921 | void KABCore::setCaptionBack() |
2897 | { | 2922 | { |
2898 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2923 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2899 | } | 2924 | } |
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 43c5f99..04ce33d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -275,209 +275,210 @@ class KABCore : public QWidget, public KSyncInterface | |||
275 | DCOP METHODS. | 275 | DCOP METHODS. |
276 | */ | 276 | */ |
277 | void addEmail( QString addr ); | 277 | void addEmail( QString addr ); |
278 | void importVCard( const KURL& url, bool showPreview ); | 278 | void importVCard( const KURL& url, bool showPreview ); |
279 | void importVCard( const QString& vCard, bool showPreview ); | 279 | void importVCard( const QString& vCard, bool showPreview ); |
280 | void newContact(); | 280 | void newContact(); |
281 | QString getNameByPhone( const QString& phone ); | 281 | QString getNameByPhone( const QString& phone ); |
282 | /** | 282 | /** |
283 | END DCOP METHODS | 283 | END DCOP METHODS |
284 | */ | 284 | */ |
285 | 285 | ||
286 | /** | 286 | /** |
287 | Saves the contents of the AddressBook back to disk. | 287 | Saves the contents of the AddressBook back to disk. |
288 | */ | 288 | */ |
289 | void save(); | 289 | void save(); |
290 | 290 | ||
291 | /** | 291 | /** |
292 | Undos the last command using the undo stack. | 292 | Undos the last command using the undo stack. |
293 | */ | 293 | */ |
294 | void undo(); | 294 | void undo(); |
295 | 295 | ||
296 | /** | 296 | /** |
297 | Redos the last command that was undone, using the redo stack. | 297 | Redos the last command that was undone, using the redo stack. |
298 | */ | 298 | */ |
299 | void redo(); | 299 | void redo(); |
300 | 300 | ||
301 | /** | 301 | /** |
302 | Shows the edit dialog for the given uid. If the uid is QString::null, | 302 | Shows the edit dialog for the given uid. If the uid is QString::null, |
303 | the method will try to find a selected addressee in the view. | 303 | the method will try to find a selected addressee in the view. |
304 | */ | 304 | */ |
305 | void editContact( const QString &uid /*US = QString::null*/ ); | 305 | void editContact( const QString &uid /*US = QString::null*/ ); |
306 | //US added a second method without defaultparameter | 306 | //US added a second method without defaultparameter |
307 | void editContact2(); | 307 | void editContact2(); |
308 | 308 | ||
309 | /** | 309 | /** |
310 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 310 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
311 | the method will try to find a selected addressee in the view. | 311 | the method will try to find a selected addressee in the view. |
312 | */ | 312 | */ |
313 | void executeContact( const QString &uid /*US = QString::null*/ ); | 313 | void executeContact( const QString &uid /*US = QString::null*/ ); |
314 | 314 | ||
315 | /** | 315 | /** |
316 | Launches the configuration dialog. | 316 | Launches the configuration dialog. |
317 | */ | 317 | */ |
318 | void openConfigDialog(); | 318 | void openConfigDialog(); |
319 | 319 | ||
320 | /** | 320 | /** |
321 | Launches the ldap search dialog. | 321 | Launches the ldap search dialog. |
322 | */ | 322 | */ |
323 | void openLDAPDialog(); | 323 | void openLDAPDialog(); |
324 | 324 | ||
325 | /** | 325 | /** |
326 | Creates a KAddressBookPrinter, which will display the print | 326 | Creates a KAddressBookPrinter, which will display the print |
327 | dialog and do the printing. | 327 | dialog and do the printing. |
328 | */ | 328 | */ |
329 | void print(); | 329 | void print(); |
330 | 330 | ||
331 | /** | 331 | /** |
332 | Registers a new GUI client, so plugins can register its actions. | 332 | Registers a new GUI client, so plugins can register its actions. |
333 | */ | 333 | */ |
334 | void addGUIClient( KXMLGUIClient *client ); | 334 | void addGUIClient( KXMLGUIClient *client ); |
335 | 335 | ||
336 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); | 336 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); |
337 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); | 337 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); |
338 | void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); | 338 | void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); |
339 | 339 | ||
340 | 340 | ||
341 | signals: | 341 | signals: |
342 | void contactSelected( const QString &name ); | 342 | void contactSelected( const QString &name ); |
343 | void contactSelected( const QPixmap &pixmap ); | 343 | void contactSelected( const QPixmap &pixmap ); |
344 | public slots: | 344 | public slots: |
345 | void recieve(QString cmsg ); | 345 | void recieve(QString cmsg ); |
346 | void getFile( bool success ); | 346 | void getFile( bool success ); |
347 | void syncFileRequest(); | 347 | void syncFileRequest(); |
348 | void setDetailsVisible( bool visible ); | 348 | void setDetailsVisible( bool visible ); |
349 | void setDetailsToState(); | 349 | void setDetailsToState(); |
350 | // void slotSyncMenu( int ); | 350 | // void slotSyncMenu( int ); |
351 | private slots: | 351 | private slots: |
352 | void setJumpButtonBarVisible( bool visible ); | 352 | void setJumpButtonBarVisible( bool visible ); |
353 | void setCaptionBack(); | 353 | void setCaptionBack(); |
354 | void importFromOL(); | 354 | void importFromOL(); |
355 | void extensionModified( const KABC::Addressee::List &list ); | 355 | void extensionModified( const KABC::Addressee::List &list ); |
356 | void extensionChanged( int id ); | 356 | void extensionChanged( int id ); |
357 | void clipboardDataChanged(); | 357 | void clipboardDataChanged(); |
358 | void updateActionMenu(); | 358 | void updateActionMenu(); |
359 | void configureKeyBindings(); | 359 | void configureKeyBindings(); |
360 | void removeVoice(); | 360 | void removeVoice(); |
361 | #ifdef KAB_EMBEDDED | 361 | #ifdef KAB_EMBEDDED |
362 | void configureResources(); | 362 | void configureResources(); |
363 | #endif //KAB_EMBEDDED | 363 | #endif //KAB_EMBEDDED |
364 | 364 | ||
365 | void slotEditorDestroyed( const QString &uid ); | 365 | void slotEditorDestroyed( const QString &uid ); |
366 | void configurationChanged(); | 366 | void configurationChanged(); |
367 | void addressBookChanged(); | 367 | void addressBookChanged(); |
368 | 368 | ||
369 | private: | 369 | private: |
370 | void initGUI(); | 370 | void initGUI(); |
371 | void initActions(); | 371 | void initActions(); |
372 | 372 | ||
373 | AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, | 373 | AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, |
374 | const char *name = 0 ); | 374 | const char *name = 0 ); |
375 | 375 | ||
376 | KXMLGUIClient *mGUIClient; | 376 | KXMLGUIClient *mGUIClient; |
377 | 377 | ||
378 | KABC::AddressBook *mAddressBook; | 378 | KABC::AddressBook *mAddressBook; |
379 | 379 | ||
380 | ViewManager *mViewManager; | 380 | ViewManager *mViewManager; |
381 | // QSplitter *mDetailsSplitter; | 381 | // QSplitter *mDetailsSplitter; |
382 | KDGanttMinimizeSplitter *mExtensionBarSplitter; | 382 | KDGanttMinimizeSplitter *mExtensionBarSplitter; |
383 | ViewContainer *mDetails; | 383 | ViewContainer *mDetails; |
384 | KDGanttMinimizeSplitter* mMiniSplitter; | 384 | KDGanttMinimizeSplitter* mMiniSplitter; |
385 | XXPortManager *mXXPortManager; | 385 | XXPortManager *mXXPortManager; |
386 | JumpButtonBar *mJumpButtonBar; | 386 | JumpButtonBar *mJumpButtonBar; |
387 | IncSearchWidget *mIncSearchWidget; | 387 | IncSearchWidget *mIncSearchWidget; |
388 | ExtensionManager *mExtensionManager; | 388 | ExtensionManager *mExtensionManager; |
389 | 389 | ||
390 | KCMultiDialog *mConfigureDialog; | 390 | KCMultiDialog *mConfigureDialog; |
391 | 391 | ||
392 | #ifndef KAB_EMBEDDED | 392 | #ifndef KAB_EMBEDDED |
393 | LDAPSearchDialog *mLdapSearchDialog; | 393 | LDAPSearchDialog *mLdapSearchDialog; |
394 | #endif //KAB_EMBEDDED | 394 | #endif //KAB_EMBEDDED |
395 | // QDict<AddresseeEditorDialog> mEditorDict; | 395 | // QDict<AddresseeEditorDialog> mEditorDict; |
396 | AddresseeEditorDialog *mEditorDialog; | 396 | AddresseeEditorDialog *mEditorDialog; |
397 | bool mReadWrite; | 397 | bool mReadWrite; |
398 | bool mModified; | 398 | bool mModified; |
399 | bool mIsPart; | 399 | bool mIsPart; |
400 | bool mMultipleViewsAtOnce; | 400 | bool mMultipleViewsAtOnce; |
401 | 401 | ||
402 | 402 | ||
403 | //US file menu | 403 | //US file menu |
404 | KAction *mActionMail; | 404 | KAction *mActionMail; |
405 | KAction *mActionBeam; | 405 | KAction *mActionBeam; |
406 | KAction *mActionExport2phone; | 406 | KAction *mActionExport2phone; |
407 | KAction* mActionPrint; | 407 | KAction* mActionPrint; |
408 | KAction* mActionNewContact; | 408 | KAction* mActionNewContact; |
409 | KAction *mActionSave; | 409 | KAction *mActionSave; |
410 | KAction *mActionEditAddressee; | 410 | KAction *mActionEditAddressee; |
411 | KAction *mActionMailVCard; | 411 | KAction *mActionMailVCard; |
412 | KAction *mActionBeamVCard; | 412 | KAction *mActionBeamVCard; |
413 | 413 | ||
414 | KAction *mActionQuit; | 414 | KAction *mActionQuit; |
415 | 415 | ||
416 | //US edit menu | 416 | //US edit menu |
417 | KAction *mActionCopy; | 417 | KAction *mActionCopy; |
418 | KAction *mActionCut; | 418 | KAction *mActionCut; |
419 | KAction *mActionPaste; | 419 | KAction *mActionPaste; |
420 | KAction *mActionSelectAll; | 420 | KAction *mActionSelectAll; |
421 | KAction *mActionUndo; | 421 | KAction *mActionUndo; |
422 | KAction *mActionRedo; | 422 | KAction *mActionRedo; |
423 | KAction *mActionDelete; | 423 | KAction *mActionDelete; |
424 | 424 | ||
425 | //US settings menu | 425 | //US settings menu |
426 | KAction *mActionConfigResources; | 426 | KAction *mActionConfigResources; |
427 | KAction *mActionConfigKAddressbook; | 427 | KAction *mActionConfigKAddressbook; |
428 | KAction *mActionConfigShortcuts; | 428 | KAction *mActionConfigShortcuts; |
429 | KAction *mActionConfigureToolbars; | 429 | KAction *mActionConfigureToolbars; |
430 | KAction *mActionKeyBindings; | 430 | KAction *mActionKeyBindings; |
431 | KToggleAction *mActionJumpBar; | 431 | KToggleAction *mActionJumpBar; |
432 | KToggleAction *mActionDetails; | 432 | KToggleAction *mActionDetails; |
433 | KAction *mActionWhoAmI; | 433 | KAction *mActionWhoAmI; |
434 | KAction *mActionCategories; | 434 | KAction *mActionCategories; |
435 | KAction *mActionAboutKAddressbook; | 435 | KAction *mActionAboutKAddressbook; |
436 | KAction *mActionLicence; | 436 | KAction *mActionLicence; |
437 | KAction *mActionFaq; | 437 | KAction *mActionFaq; |
438 | 438 | ||
439 | KAction *mActionDeleteView; | 439 | KAction *mActionDeleteView; |
440 | 440 | ||
441 | QPopupMenu *viewMenu; | 441 | QPopupMenu *viewMenu; |
442 | QPopupMenu *filterMenu; | 442 | QPopupMenu *filterMenu; |
443 | QPopupMenu *settingsMenu; | 443 | QPopupMenu *settingsMenu; |
444 | QPopupMenu *changeMenu; | 444 | QPopupMenu *changeMenu; |
445 | //US QAction *mActionSave; | 445 | //US QAction *mActionSave; |
446 | QPopupMenu *ImportMenu; | 446 | QPopupMenu *ImportMenu; |
447 | QPopupMenu *ExportMenu; | 447 | QPopupMenu *ExportMenu; |
448 | //LR additional methods | 448 | //LR additional methods |
449 | KAction *mActionRemoveVoice; | 449 | KAction *mActionRemoveVoice; |
450 | KAction * mActionImportOL; | 450 | KAction * mActionImportOL; |
451 | 451 | ||
452 | #ifndef KAB_EMBEDDED | 452 | #ifndef KAB_EMBEDDED |
453 | KAddressBookService *mAddressBookService; | 453 | KAddressBookService *mAddressBookService; |
454 | #endif //KAB_EMBEDDED | 454 | #endif //KAB_EMBEDDED |
455 | 455 | ||
456 | class KABCorePrivate; | 456 | class KABCorePrivate; |
457 | KABCorePrivate *d; | 457 | KABCorePrivate *d; |
458 | //US bool mBlockSaveFlag; | 458 | //US bool mBlockSaveFlag; |
459 | 459 | ||
460 | #ifdef KAB_EMBEDDED | 460 | #ifdef KAB_EMBEDDED |
461 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient | 461 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient |
462 | #endif //KAB_EMBEDDED | 462 | #endif //KAB_EMBEDDED |
463 | 463 | ||
464 | //this are the overwritten callbackmethods from the syncinterface | 464 | //this are the overwritten callbackmethods from the syncinterface |
465 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 465 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
466 | virtual bool syncExternal(KSyncManager* manager, QString resource); | 466 | virtual bool syncExternal(KSyncManager* manager, QString resource); |
467 | 467 | bool syncPhone(); | |
468 | void message( QString m ); | ||
468 | 469 | ||
469 | // LR ******************************* | 470 | // LR ******************************* |
470 | // sync stuff! | 471 | // sync stuff! |
471 | QString sentSyncFile(); | 472 | QString sentSyncFile(); |
472 | QPopupMenu *syncMenu; | 473 | QPopupMenu *syncMenu; |
473 | KSyncManager* syncManager; | 474 | KSyncManager* syncManager; |
474 | int mGlobalSyncMode; | 475 | int mGlobalSyncMode; |
475 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); | 476 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); |
476 | KABC::Addressee getLastSyncAddressee(); | 477 | KABC::Addressee getLastSyncAddressee(); |
477 | QDateTime mLastAddressbookSync; | 478 | QDateTime mLastAddressbookSync; |
478 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); | 479 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); |
479 | // ********************* | 480 | // ********************* |
480 | 481 | ||
481 | }; | 482 | }; |
482 | 483 | ||
483 | #endif | 484 | #endif |
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index c39413e..3555dc6 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -102,394 +102,390 @@ int PhoneFormat::initDevice(GSM_StateMachine *s) | |||
102 | cfg->Connection = strdup(mConnection.latin1()); | 102 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 103 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 104 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 105 | ||
106 | } | 106 | } |
107 | if ( ! mDevice.isEmpty() ) { | 107 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 108 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 109 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 110 | qDebug("Device set %s ", cfg->Device); |
111 | 111 | ||
112 | } | 112 | } |
113 | if ( ! mModel.isEmpty() ) { | 113 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 114 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 115 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 116 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 117 | } |
118 | int error=GSM_InitConnection(s,3); | 118 | int error=GSM_InitConnection(s,3); |
119 | return error; | 119 | return error; |
120 | } | 120 | } |
121 | #endif | 121 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 123 | { |
124 | QStringList attList; | 124 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 125 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 126 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 127 | attList << todo->summary(); |
128 | QString completedString = "no"; | 128 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 129 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 130 | completedString = "yes"; |
131 | attList << completedString; | 131 | attList << completedString; |
132 | int prio = todo->priority(); | 132 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | 133 | if( prio == 2 ) prio = 1; |
134 | if (prio == 4 ) prio = 5 ; | 134 | if (prio == 4 ) prio = 5 ; |
135 | attList << QString::number( prio ); | 135 | attList << QString::number( prio ); |
136 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
137 | Alarm *alarm; | 137 | Alarm *alarm; |
138 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
139 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
140 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
141 | alarmString = QString::number(alarm->offset() ); | 141 | alarmString = QString::number(alarm->offset() ); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | attList << alarmString; | 144 | attList << alarmString; |
145 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
146 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
147 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
148 | 148 | ||
149 | } | 149 | } |
150 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
151 | { | 151 | { |
152 | QStringList attList; | 152 | QStringList attList; |
153 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
154 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
155 | attList << event->summary(); | 155 | attList << event->summary(); |
156 | attList << event->location(); | 156 | attList << event->location(); |
157 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
158 | Alarm *alarm; | 158 | Alarm *alarm; |
159 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
160 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
161 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
162 | alarmString = QString::number( alarm->offset() ); | 162 | alarmString = QString::number( alarm->offset() ); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | attList << alarmString; | 165 | attList << alarmString; |
166 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
167 | QStringList list; | 167 | QStringList list; |
168 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
169 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
170 | { | 170 | { |
171 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
172 | list.append( "0" ); | 172 | list.append( "0" ); |
173 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
174 | list.append( "0" ); | 174 | list.append( "0" ); |
175 | list.append( "0" ); | 175 | list.append( "0" ); |
176 | writeEndDate = true; | 176 | writeEndDate = true; |
177 | break; | 177 | break; |
178 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
179 | list.append( "1" ); | 179 | list.append( "1" ); |
180 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
181 | list.append( "0" ); | 181 | list.append( "0" ); |
182 | { | 182 | { |
183 | int days = 0; | 183 | int days = 0; |
184 | QBitArray weekDays = rec->days(); | 184 | QBitArray weekDays = rec->days(); |
185 | int i; | 185 | int i; |
186 | for( i = 1; i <= 7; ++i ) { | 186 | for( i = 1; i <= 7; ++i ) { |
187 | if ( weekDays[i-1] ) { | 187 | if ( weekDays[i-1] ) { |
188 | days += 1 << (i-1); | 188 | days += 1 << (i-1); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | list.append( QString::number( days ) ); | 191 | list.append( QString::number( days ) ); |
192 | } | 192 | } |
193 | //pending weekdays | 193 | //pending weekdays |
194 | writeEndDate = true; | 194 | writeEndDate = true; |
195 | 195 | ||
196 | break; | 196 | break; |
197 | case Recurrence::rMonthlyPos:// 2 | 197 | case Recurrence::rMonthlyPos:// 2 |
198 | list.append( "2" ); | 198 | list.append( "2" ); |
199 | list.append( QString::number( rec->frequency()) );//12 | 199 | list.append( QString::number( rec->frequency()) );//12 |
200 | 200 | ||
201 | writeEndDate = true; | 201 | writeEndDate = true; |
202 | { | 202 | { |
203 | int count = 1; | 203 | int count = 1; |
204 | QPtrList<Recurrence::rMonthPos> rmp; | 204 | QPtrList<Recurrence::rMonthPos> rmp; |
205 | rmp = rec->monthPositions(); | 205 | rmp = rec->monthPositions(); |
206 | if ( rmp.first()->negative ) | 206 | if ( rmp.first()->negative ) |
207 | count = 5 - rmp.first()->rPos - 1; | 207 | count = 5 - rmp.first()->rPos - 1; |
208 | else | 208 | else |
209 | count = rmp.first()->rPos - 1; | 209 | count = rmp.first()->rPos - 1; |
210 | list.append( QString::number( count ) ); | 210 | list.append( QString::number( count ) ); |
211 | 211 | ||
212 | } | 212 | } |
213 | 213 | ||
214 | list.append( "0" ); | 214 | list.append( "0" ); |
215 | break; | 215 | break; |
216 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
217 | list.append( "3" ); | 217 | list.append( "3" ); |
218 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
219 | list.append( "0" ); | 219 | list.append( "0" ); |
220 | list.append( "0" ); | 220 | list.append( "0" ); |
221 | writeEndDate = true; | 221 | writeEndDate = true; |
222 | break; | 222 | break; |
223 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
224 | list.append( "4" ); | 224 | list.append( "4" ); |
225 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
226 | list.append( "0" ); | 226 | list.append( "0" ); |
227 | list.append( "0" ); | 227 | list.append( "0" ); |
228 | writeEndDate = true; | 228 | writeEndDate = true; |
229 | break; | 229 | break; |
230 | 230 | ||
231 | default: | 231 | default: |
232 | list.append( "255" ); | 232 | list.append( "255" ); |
233 | list.append( QString() ); | 233 | list.append( QString() ); |
234 | list.append( "0" ); | 234 | list.append( "0" ); |
235 | list.append( QString() ); | 235 | list.append( QString() ); |
236 | list.append( "0" ); | 236 | list.append( "0" ); |
237 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
241 | 241 | ||
242 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
243 | list.append( "1" ); | 243 | list.append( "1" ); |
244 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
245 | } else { | 245 | } else { |
246 | list.append( "0" ); | 246 | list.append( "0" ); |
247 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
248 | } | 248 | } |
249 | 249 | ||
250 | } | 250 | } |
251 | attList << list.join(""); | 251 | attList << list.join(""); |
252 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
254 | 254 | ||
255 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
256 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
257 | } | 257 | } |
258 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
259 | { | 259 | { |
260 | int max = attList.count(); | 260 | int max = attList.count(); |
261 | ulong cSum = 0; | 261 | ulong cSum = 0; |
262 | int j,k,i; | 262 | int j,k,i; |
263 | int add; | 263 | int add; |
264 | for ( i = 0; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
265 | QString s = attList[i]; | 265 | QString s = attList[i]; |
266 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
267 | j = s.length(); | 267 | j = s.length(); |
268 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
269 | int mul = k +1; | 269 | int mul = k +1; |
270 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
271 | if ( k < 16 ) | 271 | if ( k < 16 ) |
272 | mul = mul * mul; | 272 | mul = mul * mul; |
273 | int ii = i+1; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | 274 | add = add * mul *ii*ii*ii; |
275 | cSum += add; | 275 | cSum += add; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | //QString dump = attList.join(","); | 280 | //QString dump = attList.join(","); |
281 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 281 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
282 | 282 | ||
283 | return cSum; | 283 | return cSum; |
284 | 284 | ||
285 | } | 285 | } |
286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
287 | #include <stdlib.h> | 287 | #include <stdlib.h> |
288 | #define DEBUGMODE false | 288 | #define DEBUGMODE false |
289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
290 | { | 290 | { |
291 | 291 | ||
292 | QString fileName; | 292 | QString fileName; |
293 | #ifdef _WIN32_ | 293 | #ifdef _WIN32_ |
294 | fileName = locateLocal("tmp", "tempfile.vcs"); | 294 | fileName = locateLocal("tmp", "phonefile.vcs"); |
295 | #else | 295 | #else |
296 | fileName = "/tmp/kdepimtemp.vcs"; | 296 | fileName = "/tmp/phonefile.vcs"; |
297 | #endif | 297 | #endif |
298 | #ifdef DESKTOP_VERSION | 298 | QString command; |
299 | QString command ="./kammu --backup " + fileName + " -yes" ; | 299 | int ret = PhoneAccess::readFromPhone( fileName ); |
300 | #else | ||
301 | QString command ="kammu --backup " + fileName + " -yes" ; | ||
302 | #endif | ||
303 | int ret = system ( command.latin1() ); | ||
304 | if ( ret != 0 ) { | 300 | if ( ret != 0 ) { |
305 | qDebug("Error::command returned %d", ret); | 301 | qDebug("Error::command returned %d", ret); |
306 | return false; | 302 | return false; |
307 | } | 303 | } |
308 | VCalFormat vfload; | 304 | VCalFormat vfload; |
309 | vfload.setLocalTime ( true ); | 305 | vfload.setLocalTime ( true ); |
310 | qDebug("loading file ..."); | 306 | qDebug("loading file ..."); |
311 | 307 | ||
312 | if ( ! vfload.load( calendar, fileName ) ) | 308 | if ( ! vfload.load( calendar, fileName ) ) |
313 | return false; | 309 | return false; |
314 | QPtrList<Event> er = calendar->rawEvents(); | 310 | QPtrList<Event> er = calendar->rawEvents(); |
315 | Event* ev = er.first(); | 311 | Event* ev = er.first(); |
316 | qDebug("reading events... "); | 312 | qDebug("reading events... "); |
317 | while ( ev ) { | 313 | while ( ev ) { |
318 | QStringList cat = ev->categories(); | 314 | QStringList cat = ev->categories(); |
319 | if ( cat.contains( "MeetingDEF" )) { | 315 | if ( cat.contains( "MeetingDEF" )) { |
320 | ev->setCategories( QStringList() ); | 316 | ev->setCategories( QStringList() ); |
321 | } | 317 | } |
322 | int id = ev->pilotId(); | 318 | int id = ev->pilotId(); |
323 | Event *event; | 319 | Event *event; |
324 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 320 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
325 | if ( event ) { | 321 | if ( event ) { |
326 | event = (Event*)event->clone(); | 322 | event = (Event*)event->clone(); |
327 | copyEvent( event, ev ); | 323 | copyEvent( event, ev ); |
328 | calendar->deleteEvent( ev ); | 324 | calendar->deleteEvent( ev ); |
329 | calendar->addEvent( event); | 325 | calendar->addEvent( event); |
330 | } | 326 | } |
331 | else | 327 | else |
332 | event = ev; | 328 | event = ev; |
333 | uint cSum; | 329 | uint cSum; |
334 | cSum = PhoneFormat::getCsumEvent( event ); | 330 | cSum = PhoneFormat::getCsumEvent( event ); |
335 | event->setCsum( mProfileName, QString::number( cSum )); | 331 | event->setCsum( mProfileName, QString::number( cSum )); |
336 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 332 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
337 | event->setID( mProfileName,QString::number( id ) ); | 333 | event->setID( mProfileName,QString::number( id ) ); |
338 | ev = er.next(); | 334 | ev = er.next(); |
339 | } | 335 | } |
340 | { | 336 | { |
341 | qDebug("reading todos... "); | 337 | qDebug("reading todos... "); |
342 | QPtrList<Todo> tr = calendar->rawTodos(); | 338 | QPtrList<Todo> tr = calendar->rawTodos(); |
343 | Todo* ev = tr.first(); | 339 | Todo* ev = tr.first(); |
344 | while ( ev ) { | 340 | while ( ev ) { |
345 | 341 | ||
346 | QStringList cat = ev->categories(); | 342 | QStringList cat = ev->categories(); |
347 | if ( cat.contains( "MeetingDEF" )) { | 343 | if ( cat.contains( "MeetingDEF" )) { |
348 | ev->setCategories( QStringList() ); | 344 | ev->setCategories( QStringList() ); |
349 | } | 345 | } |
350 | int id = ev->pilotId(); | 346 | int id = ev->pilotId(); |
351 | Todo *event; | 347 | Todo *event; |
352 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 348 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
353 | if ( event ) { | 349 | if ( event ) { |
354 | //qDebug("copy todo %s ", event->summary().latin1()); | 350 | //qDebug("copy todo %s ", event->summary().latin1()); |
355 | 351 | ||
356 | event = (Todo*)event->clone(); | 352 | event = (Todo*)event->clone(); |
357 | copyTodo( event, ev ); | 353 | copyTodo( event, ev ); |
358 | calendar->deleteTodo( ev ); | 354 | calendar->deleteTodo( ev ); |
359 | calendar->addTodo( event); | 355 | calendar->addTodo( event); |
360 | } | 356 | } |
361 | else | 357 | else |
362 | event = ev; | 358 | event = ev; |
363 | uint cSum; | 359 | uint cSum; |
364 | cSum = PhoneFormat::getCsumTodo( event ); | 360 | cSum = PhoneFormat::getCsumTodo( event ); |
365 | event->setCsum( mProfileName, QString::number( cSum )); | 361 | event->setCsum( mProfileName, QString::number( cSum )); |
366 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 362 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
367 | event->setID( mProfileName,QString::number( id ) ); | 363 | event->setID( mProfileName,QString::number( id ) ); |
368 | ev = tr.next(); | 364 | ev = tr.next(); |
369 | } | 365 | } |
370 | } | 366 | } |
371 | return true; | 367 | return true; |
372 | } | 368 | } |
373 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 369 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
374 | { | 370 | { |
375 | if ( from->dtStart().isValid() ) | 371 | if ( from->dtStart().isValid() ) |
376 | to->setDtStart( from->dtStart() ); | 372 | to->setDtStart( from->dtStart() ); |
377 | if ( from->dtEnd().isValid() ) | 373 | if ( from->dtEnd().isValid() ) |
378 | to->setDtEnd( from->dtEnd() ); | 374 | to->setDtEnd( from->dtEnd() ); |
379 | if ( !from->location().isEmpty() ) | 375 | if ( !from->location().isEmpty() ) |
380 | to->setLocation( from->location() ); | 376 | to->setLocation( from->location() ); |
381 | if ( !from->description().isEmpty() ) | 377 | if ( !from->description().isEmpty() ) |
382 | to->setDescription( from->description() ); | 378 | to->setDescription( from->description() ); |
383 | if ( !from->summary().isEmpty() ) | 379 | if ( !from->summary().isEmpty() ) |
384 | to->setSummary( from->summary() ); | 380 | to->setSummary( from->summary() ); |
385 | 381 | ||
386 | if ( from->alarms().count() ) { | 382 | if ( from->alarms().count() ) { |
387 | to->clearAlarms(); | 383 | to->clearAlarms(); |
388 | Alarm *a = from->alarms().first(); | 384 | Alarm *a = from->alarms().first(); |
389 | Alarm *b = to->newAlarm( ); | 385 | Alarm *b = to->newAlarm( ); |
390 | b->setEnabled( a->enabled() ); | 386 | b->setEnabled( a->enabled() ); |
391 | if ( a->hasStartOffset() ) { | 387 | if ( a->hasStartOffset() ) { |
392 | b->setStartOffset( a->startOffset() ); | 388 | b->setStartOffset( a->startOffset() ); |
393 | } | 389 | } |
394 | if ( a->hasTime() ) | 390 | if ( a->hasTime() ) |
395 | b->setTime( a->time() ); | 391 | b->setTime( a->time() ); |
396 | 392 | ||
397 | } | 393 | } |
398 | QStringList cat = to->categories(); | 394 | QStringList cat = to->categories(); |
399 | QStringList catFrom = from->categories(); | 395 | QStringList catFrom = from->categories(); |
400 | QString nCat; | 396 | QString nCat; |
401 | int iii; | 397 | int iii; |
402 | for ( iii = 0; iii < catFrom.count();++iii ) { | 398 | for ( iii = 0; iii < catFrom.count();++iii ) { |
403 | nCat = catFrom[iii]; | 399 | nCat = catFrom[iii]; |
404 | if ( !nCat.isEmpty() ) | 400 | if ( !nCat.isEmpty() ) |
405 | if ( !cat.contains( nCat )) { | 401 | if ( !cat.contains( nCat )) { |
406 | cat << nCat; | 402 | cat << nCat; |
407 | } | 403 | } |
408 | } | 404 | } |
409 | to->setCategories( cat ); | 405 | to->setCategories( cat ); |
410 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 406 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
411 | to->setRecurrence( r ) ; | 407 | to->setRecurrence( r ) ; |
412 | 408 | ||
413 | 409 | ||
414 | } | 410 | } |
415 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 411 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
416 | { | 412 | { |
417 | if ( from->dtStart().isValid() ) | 413 | if ( from->dtStart().isValid() ) |
418 | to->setDtStart( from->dtStart() ); | 414 | to->setDtStart( from->dtStart() ); |
419 | if ( from->dtDue().isValid() ) | 415 | if ( from->dtDue().isValid() ) |
420 | to->setDtDue( from->dtDue() ); | 416 | to->setDtDue( from->dtDue() ); |
421 | if ( !from->location().isEmpty() ) | 417 | if ( !from->location().isEmpty() ) |
422 | to->setLocation( from->location() ); | 418 | to->setLocation( from->location() ); |
423 | if ( !from->description().isEmpty() ) | 419 | if ( !from->description().isEmpty() ) |
424 | to->setDescription( from->description() ); | 420 | to->setDescription( from->description() ); |
425 | if ( !from->summary().isEmpty() ) | 421 | if ( !from->summary().isEmpty() ) |
426 | to->setSummary( from->summary() ); | 422 | to->setSummary( from->summary() ); |
427 | 423 | ||
428 | if ( from->alarms().count() ) { | 424 | if ( from->alarms().count() ) { |
429 | to->clearAlarms(); | 425 | to->clearAlarms(); |
430 | Alarm *a = from->alarms().first(); | 426 | Alarm *a = from->alarms().first(); |
431 | Alarm *b = to->newAlarm( ); | 427 | Alarm *b = to->newAlarm( ); |
432 | b->setEnabled( a->enabled() ); | 428 | b->setEnabled( a->enabled() ); |
433 | if ( a->hasStartOffset() ) | 429 | if ( a->hasStartOffset() ) |
434 | b->setStartOffset( a->startOffset() ); | 430 | b->setStartOffset( a->startOffset() ); |
435 | if ( a->hasTime() ) | 431 | if ( a->hasTime() ) |
436 | b->setTime( a->time() ); | 432 | b->setTime( a->time() ); |
437 | } | 433 | } |
438 | 434 | ||
439 | QStringList cat = to->categories(); | 435 | QStringList cat = to->categories(); |
440 | QStringList catFrom = from->categories(); | 436 | QStringList catFrom = from->categories(); |
441 | QString nCat; | 437 | QString nCat; |
442 | int iii; | 438 | int iii; |
443 | for ( iii = 0; iii < catFrom.count();++iii ) { | 439 | for ( iii = 0; iii < catFrom.count();++iii ) { |
444 | nCat = catFrom[iii]; | 440 | nCat = catFrom[iii]; |
445 | if ( !nCat.isEmpty() ) | 441 | if ( !nCat.isEmpty() ) |
446 | if ( !cat.contains( nCat )) { | 442 | if ( !cat.contains( nCat )) { |
447 | cat << nCat; | 443 | cat << nCat; |
448 | } | 444 | } |
449 | } | 445 | } |
450 | to->setCategories( cat ); | 446 | to->setCategories( cat ); |
451 | if ( from->isCompleted() ) { | 447 | if ( from->isCompleted() ) { |
452 | to->setCompleted( true ); | 448 | to->setCompleted( true ); |
453 | if( from->completed().isValid() ) | 449 | if( from->completed().isValid() ) |
454 | to->setCompleted( from->completed() ); | 450 | to->setCompleted( from->completed() ); |
455 | } else { | 451 | } else { |
456 | // set percentcomplete only, if to->isCompleted() | 452 | // set percentcomplete only, if to->isCompleted() |
457 | if ( to->isCompleted() ) | 453 | if ( to->isCompleted() ) |
458 | to->setPercentComplete(from->percentComplete()); | 454 | to->setPercentComplete(from->percentComplete()); |
459 | } | 455 | } |
460 | if( to->priority() == 2 && from->priority() == 1 ) | 456 | if( to->priority() == 2 && from->priority() == 1 ) |
461 | ; //skip | 457 | ; //skip |
462 | else if (to->priority() == 4 && from->priority() == 5 ) | 458 | else if (to->priority() == 4 && from->priority() == 5 ) |
463 | ; | 459 | ; |
464 | else | 460 | else |
465 | to->setPriority(from->priority()); | 461 | to->setPriority(from->priority()); |
466 | 462 | ||
467 | } | 463 | } |
468 | #include <qcstring.h> | 464 | #include <qcstring.h> |
469 | 465 | ||
470 | void PhoneFormat::afterSave( Incidence* inc) | 466 | void PhoneFormat::afterSave( Incidence* inc) |
471 | { | 467 | { |
472 | uint csum; | 468 | uint csum; |
473 | inc->removeID( mProfileName ); | 469 | inc->removeID( mProfileName ); |
474 | if ( inc->type() == "Event") | 470 | if ( inc->type() == "Event") |
475 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 471 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
476 | else | 472 | else |
477 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 473 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
478 | inc->setCsum( mProfileName, QString::number( csum )); | 474 | inc->setCsum( mProfileName, QString::number( csum )); |
479 | 475 | ||
480 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 476 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
481 | 477 | ||
482 | } | 478 | } |
483 | 479 | ||
484 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 480 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
485 | { | 481 | { |
486 | #ifdef _WIN32_ | 482 | #ifdef _WIN32_ |
487 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | 483 | QString fileName = locateLocal("tmp", "tempfile.vcs"); |
488 | #else | 484 | #else |
489 | QString fileName = "/tmp/kdepimtemp.vcs"; | 485 | QString fileName = "/tmp/kdepimtemp.vcs"; |
490 | #endif | 486 | #endif |
491 | 487 | ||
492 | VCalFormat vfsave; | 488 | VCalFormat vfsave; |
493 | vfsave.setLocalTime ( true ); | 489 | vfsave.setLocalTime ( true ); |
494 | if ( ! vfsave.save( calendar, fileName ) ) | 490 | if ( ! vfsave.save( calendar, fileName ) ) |
495 | return false; | 491 | return false; |
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index fe914dd..5fafa1f 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp | |||
@@ -1,151 +1,173 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include <kmessagebox.h> | 31 | #include <kmessagebox.h> |
32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
33 | #include "phoneaccess.h" | 33 | #include "phoneaccess.h" |
34 | 34 | ||
35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) | 35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) |
36 | { | 36 | { |
37 | #ifdef _WIN32_ | 37 | #ifdef _WIN32_ |
38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; | 38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; |
39 | #else | 39 | #else |
40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; | 40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; |
41 | #endif | 41 | #endif |
42 | //qDebug("save %d ", load ); | 42 | //qDebug("save %d ", load ); |
43 | QString content = "[gammu]\n";; | 43 | QString content = "[gammu]\n";; |
44 | bool write = false; | 44 | bool write = false; |
45 | bool addPort = true, addConnection = true, addModel = true; | 45 | bool addPort = true, addConnection = true, addModel = true; |
46 | QFile file( fileName ); | 46 | QFile file( fileName ); |
47 | if ( QFile::exists( fileName) ) { | 47 | if ( QFile::exists( fileName) ) { |
48 | if (!file.open( IO_ReadOnly ) ) { | 48 | if (!file.open( IO_ReadOnly ) ) { |
49 | qDebug("Error: cannot open %s ", fileName.latin1() ); | 49 | qDebug("Error: cannot open %s ", fileName.latin1() ); |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | QString line; | 52 | QString line; |
53 | while ( file.readLine( line, 1024 ) > 0 ) { | 53 | while ( file.readLine( line, 1024 ) > 0 ) { |
54 | //qDebug("*%s* ", line.latin1() ); | 54 | //qDebug("*%s* ", line.latin1() ); |
55 | if ( line.left(7 ) == "[gammu]" ) { | 55 | if ( line.left(7 ) == "[gammu]" ) { |
56 | ; | 56 | ; |
57 | } else | 57 | } else |
58 | if ( line.left(4 ) == "port" ) { | 58 | if ( line.left(4 ) == "port" ) { |
59 | if ( line == "port = " + device+"\n" ) { | 59 | if ( line == "port = " + device+"\n" ) { |
60 | content += line ; | 60 | content += line ; |
61 | addPort = false; | 61 | addPort = false; |
62 | //qDebug("port found" ); | 62 | //qDebug("port found" ); |
63 | } | 63 | } |
64 | 64 | ||
65 | } else if ( line.left(5 ) == "model" ) { | 65 | } else if ( line.left(5 ) == "model" ) { |
66 | if ( line == "model = " + model +"\n") { | 66 | if ( line == "model = " + model +"\n") { |
67 | content += line ; | 67 | content += line ; |
68 | addModel = false; | 68 | addModel = false; |
69 | //qDebug("model found" ); | 69 | //qDebug("model found" ); |
70 | } | 70 | } |
71 | 71 | ||
72 | } else if ( line.left( 10 ) == "connection" ) { | 72 | } else if ( line.left( 10 ) == "connection" ) { |
73 | if ( line == "connection = " + connection +"\n") { | 73 | if ( line == "connection = " + connection +"\n") { |
74 | addConnection = false; | 74 | addConnection = false; |
75 | content += line ; | 75 | content += line ; |
76 | //qDebug("con found" ); | 76 | //qDebug("con found" ); |
77 | } | 77 | } |
78 | 78 | ||
79 | } else { | 79 | } else { |
80 | content += line ; | 80 | content += line ; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | file.close(); | 83 | file.close(); |
84 | } else { | 84 | } else { |
85 | if ( ! connection.isEmpty() ) { | 85 | if ( ! connection.isEmpty() ) { |
86 | addConnection = true; | 86 | addConnection = true; |
87 | } | 87 | } |
88 | if ( ! device.isEmpty() ) { | 88 | if ( ! device.isEmpty() ) { |
89 | addPort = true; | 89 | addPort = true; |
90 | 90 | ||
91 | } | 91 | } |
92 | if ( ! model.isEmpty() ) { | 92 | if ( ! model.isEmpty() ) { |
93 | addModel = true; | 93 | addModel = true; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | if ( addConnection ) { | 97 | if ( addConnection ) { |
98 | write = true; | 98 | write = true; |
99 | content += "connection = "; | 99 | content += "connection = "; |
100 | content += connection; | 100 | content += connection; |
101 | content += "\n"; | 101 | content += "\n"; |
102 | } | 102 | } |
103 | if ( addPort ) { | 103 | if ( addPort ) { |
104 | write = true; | 104 | write = true; |
105 | content += "port = "; | 105 | content += "port = "; |
106 | content += device; | 106 | content += device; |
107 | content += "\n"; | 107 | content += "\n"; |
108 | 108 | ||
109 | } | 109 | } |
110 | if ( addModel ) { | 110 | if ( addModel ) { |
111 | write = true; | 111 | write = true; |
112 | content += "model = "; | 112 | content += "model = "; |
113 | content += model; | 113 | content += model; |
114 | content += "\n"; | 114 | content += "\n"; |
115 | } | 115 | } |
116 | if ( write ) { | 116 | if ( write ) { |
117 | if (!file.open( IO_WriteOnly ) ) { | 117 | if (!file.open( IO_WriteOnly ) ) { |
118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); | 118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | qDebug("Writing file %s ", fileName.latin1() ); | 121 | qDebug("Writing file %s ", fileName.latin1() ); |
122 | QTextStream ts( &file ); | 122 | QTextStream ts( &file ); |
123 | ts << content ; | 123 | ts << content ; |
124 | file.close(); | 124 | file.close(); |
125 | } | 125 | } |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | bool PhoneAccess::writeToPhone( QString fileName) | 130 | bool PhoneAccess::writeToPhone( QString fileName) |
131 | { | 131 | { |
132 | 132 | ||
133 | #ifdef DESKTOP_VERSION | 133 | #ifdef DESKTOP_VERSION |
134 | #ifdef _WIN32_ | 134 | #ifdef _WIN32_ |
135 | QString command ="kammu --restore " + fileName ; | 135 | QString command ="kammu --restore " + fileName ; |
136 | #else | 136 | #else |
137 | QString command ="./kammu --restore " + fileName ; | 137 | QString command ="./kammu --restore " + fileName ; |
138 | #endif | 138 | #endif |
139 | #else | 139 | #else |
140 | QString command ="kammu --restore " + fileName ; | 140 | QString command ="kammu --restore " + fileName ; |
141 | #endif | 141 | #endif |
142 | int ret; | 142 | int ret; |
143 | while ( (ret = system ( command.latin1())) != 0 ) { | 143 | while ( (ret = system ( command.latin1())) != 0 ) { |
144 | qDebug("Error S::command returned %d.", ret); | 144 | qDebug("Error S::command returned %d.", ret); |
145 | int retval = KMessageBox::warningContinueCancel(0, | 145 | int retval = KMessageBox::warningContinueCancel(0, |
146 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); | 146 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); |
147 | if ( retval != KMessageBox::Continue ) | ||
148 | return false; | ||
149 | } | ||
150 | return true; | ||
151 | } | ||
152 | bool PhoneAccess::readFromPhone( QString fileName) | ||
153 | { | ||
154 | |||
155 | #ifdef DESKTOP_VERSION | ||
156 | #ifdef _WIN32_ | ||
157 | QString command ="kammu --backup " + fileName + " -yes" ; | ||
158 | #else | ||
159 | QString command ="./kammu --backup " + fileName + " -yes" ; | ||
160 | #endif | ||
161 | #else | ||
162 | QString command ="kammu --backup " + fileName + " -yes" ; | ||
163 | #endif | ||
164 | int ret; | ||
165 | while ( (ret = system ( command.latin1())) != 0 ) { | ||
166 | qDebug("Error S::command returned %d.", ret); | ||
167 | int retval = KMessageBox::warningContinueCancel(0, | ||
168 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); | ||
147 | if ( retval != KMessageBox::Continue ) | 169 | if ( retval != KMessageBox::Continue ) |
148 | return false; | 170 | return false; |
149 | } | 171 | } |
150 | return true; | 172 | return true; |
151 | } | 173 | } |
diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h index b7c4732..80840e2 100644 --- a/libkdepim/phoneaccess.h +++ b/libkdepim/phoneaccess.h | |||
@@ -1,42 +1,44 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | #ifndef PHONEACCESS_H | 21 | #ifndef PHONEACCESS_H |
22 | #define PHONEACCESS_H | 22 | #define PHONEACCESS_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qobject.h> | ||
25 | 26 | ||
26 | 27 | ||
27 | 28 | ||
28 | /** | 29 | /** |
29 | This class implements the calendar format used by Phone. | 30 | This class implements the calendar format used by Phone. |
30 | */ | 31 | */ |
31 | 32 | ||
32 | class PhoneAccess : public QObject { | 33 | class PhoneAccess : public QObject { |
33 | public: | 34 | public: |
34 | 35 | ||
35 | static void writeConfig( QString device,QString connection, QString model ); | 36 | static void writeConfig( QString device,QString connection, QString model ); |
36 | static bool writeToPhone( QString fileName ); | 37 | static bool writeToPhone( QString fileName ); |
38 | static bool readFromPhone( QString fileName ); | ||
37 | 39 | ||
38 | }; | 40 | }; |
39 | 41 | ||
40 | 42 | ||
41 | 43 | ||
42 | #endif | 44 | #endif |