-rw-r--r-- | kabc/addressbook.cpp | 27 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kabc/addressee.cpp | 6 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 79 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 58 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 44 |
7 files changed, 153 insertions, 66 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 86dc7c2..17b9ba2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,922 +1,937 @@ | |||
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 | 41 | ||
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kdebug.h> | 44 | #include <kdebug.h> |
45 | #include <libkcal/syncdefines.h> | 45 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 46 | #include "addressbook.h" |
47 | #include "resource.h" | 47 | #include "resource.h" |
48 | 48 | ||
49 | //US #include "addressbook.moc" | 49 | //US #include "addressbook.moc" |
50 | 50 | ||
51 | using namespace KABC; | 51 | using namespace KABC; |
52 | 52 | ||
53 | struct AddressBook::AddressBookData | 53 | struct AddressBook::AddressBookData |
54 | { | 54 | { |
55 | Addressee::List mAddressees; | 55 | Addressee::List mAddressees; |
56 | Addressee::List mRemovedAddressees; | 56 | Addressee::List mRemovedAddressees; |
57 | Field::List mAllFields; | 57 | Field::List mAllFields; |
58 | KConfig *mConfig; | 58 | KConfig *mConfig; |
59 | KRES::Manager<Resource> *mManager; | 59 | KRES::Manager<Resource> *mManager; |
60 | //US ErrorHandler *mErrorHandler; | 60 | //US ErrorHandler *mErrorHandler; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | struct AddressBook::Iterator::IteratorData | 63 | struct AddressBook::Iterator::IteratorData |
64 | { | 64 | { |
65 | Addressee::List::Iterator mIt; | 65 | Addressee::List::Iterator mIt; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct AddressBook::ConstIterator::ConstIteratorData | 68 | struct AddressBook::ConstIterator::ConstIteratorData |
69 | { | 69 | { |
70 | Addressee::List::ConstIterator mIt; | 70 | Addressee::List::ConstIterator mIt; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | AddressBook::Iterator::Iterator() | 73 | AddressBook::Iterator::Iterator() |
74 | { | 74 | { |
75 | d = new IteratorData; | 75 | d = new IteratorData; |
76 | } | 76 | } |
77 | 77 | ||
78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
79 | { | 79 | { |
80 | d = new IteratorData; | 80 | d = new IteratorData; |
81 | d->mIt = i.d->mIt; | 81 | d->mIt = i.d->mIt; |
82 | } | 82 | } |
83 | 83 | ||
84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
85 | { | 85 | { |
86 | if( this == &i ) return *this; // guard against self assignment | 86 | if( this == &i ) return *this; // guard against self assignment |
87 | delete d; // delete the old data the Iterator was completely constructed before | 87 | delete d; // delete the old data the Iterator was completely constructed before |
88 | d = new IteratorData; | 88 | d = new IteratorData; |
89 | d->mIt = i.d->mIt; | 89 | d->mIt = i.d->mIt; |
90 | return *this; | 90 | return *this; |
91 | } | 91 | } |
92 | 92 | ||
93 | AddressBook::Iterator::~Iterator() | 93 | AddressBook::Iterator::~Iterator() |
94 | { | 94 | { |
95 | delete d; | 95 | delete d; |
96 | } | 96 | } |
97 | 97 | ||
98 | const Addressee &AddressBook::Iterator::operator*() const | 98 | const Addressee &AddressBook::Iterator::operator*() const |
99 | { | 99 | { |
100 | return *(d->mIt); | 100 | return *(d->mIt); |
101 | } | 101 | } |
102 | 102 | ||
103 | Addressee &AddressBook::Iterator::operator*() | 103 | Addressee &AddressBook::Iterator::operator*() |
104 | { | 104 | { |
105 | return *(d->mIt); | 105 | return *(d->mIt); |
106 | } | 106 | } |
107 | 107 | ||
108 | Addressee *AddressBook::Iterator::operator->() | 108 | Addressee *AddressBook::Iterator::operator->() |
109 | { | 109 | { |
110 | return &(*(d->mIt)); | 110 | return &(*(d->mIt)); |
111 | } | 111 | } |
112 | 112 | ||
113 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 113 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
114 | { | 114 | { |
115 | (d->mIt)++; | 115 | (d->mIt)++; |
116 | return *this; | 116 | return *this; |
117 | } | 117 | } |
118 | 118 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
120 | { | 120 | { |
121 | (d->mIt)++; | 121 | (d->mIt)++; |
122 | return *this; | 122 | return *this; |
123 | } | 123 | } |
124 | 124 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 125 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
126 | { | 126 | { |
127 | (d->mIt)--; | 127 | (d->mIt)--; |
128 | return *this; | 128 | return *this; |
129 | } | 129 | } |
130 | 130 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
132 | { | 132 | { |
133 | (d->mIt)--; | 133 | (d->mIt)--; |
134 | return *this; | 134 | return *this; |
135 | } | 135 | } |
136 | 136 | ||
137 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 137 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
138 | { | 138 | { |
139 | return ( d->mIt == it.d->mIt ); | 139 | return ( d->mIt == it.d->mIt ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
143 | { | 143 | { |
144 | return ( d->mIt != it.d->mIt ); | 144 | return ( d->mIt != it.d->mIt ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | AddressBook::ConstIterator::ConstIterator() | 148 | AddressBook::ConstIterator::ConstIterator() |
149 | { | 149 | { |
150 | d = new ConstIteratorData; | 150 | d = new ConstIteratorData; |
151 | } | 151 | } |
152 | 152 | ||
153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
154 | { | 154 | { |
155 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
156 | d->mIt = i.d->mIt; | 156 | d->mIt = i.d->mIt; |
157 | } | 157 | } |
158 | 158 | ||
159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
160 | { | 160 | { |
161 | if( this == &i ) return *this; // guard for self assignment | 161 | if( this == &i ) return *this; // guard for self assignment |
162 | delete d; // delete the old data because the Iterator was really constructed before | 162 | delete d; // delete the old data because the Iterator was really constructed before |
163 | d = new ConstIteratorData; | 163 | d = new ConstIteratorData; |
164 | d->mIt = i.d->mIt; | 164 | d->mIt = i.d->mIt; |
165 | return *this; | 165 | return *this; |
166 | } | 166 | } |
167 | 167 | ||
168 | AddressBook::ConstIterator::~ConstIterator() | 168 | AddressBook::ConstIterator::~ConstIterator() |
169 | { | 169 | { |
170 | delete d; | 170 | delete d; |
171 | } | 171 | } |
172 | 172 | ||
173 | const Addressee &AddressBook::ConstIterator::operator*() const | 173 | const Addressee &AddressBook::ConstIterator::operator*() const |
174 | { | 174 | { |
175 | return *(d->mIt); | 175 | return *(d->mIt); |
176 | } | 176 | } |
177 | 177 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 178 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 179 | { |
180 | return &(*(d->mIt)); | 180 | return &(*(d->mIt)); |
181 | } | 181 | } |
182 | 182 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 184 | { |
185 | (d->mIt)++; | 185 | (d->mIt)++; |
186 | return *this; | 186 | return *this; |
187 | } | 187 | } |
188 | 188 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 190 | { |
191 | (d->mIt)++; | 191 | (d->mIt)++; |
192 | return *this; | 192 | return *this; |
193 | } | 193 | } |
194 | 194 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 196 | { |
197 | (d->mIt)--; | 197 | (d->mIt)--; |
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 202 | { |
203 | (d->mIt)--; | 203 | (d->mIt)--; |
204 | return *this; | 204 | return *this; |
205 | } | 205 | } |
206 | 206 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 208 | { |
209 | return ( d->mIt == it.d->mIt ); | 209 | return ( d->mIt == it.d->mIt ); |
210 | } | 210 | } |
211 | 211 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 213 | { |
214 | return ( d->mIt != it.d->mIt ); | 214 | return ( d->mIt != it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | AddressBook::AddressBook() | 218 | AddressBook::AddressBook() |
219 | { | 219 | { |
220 | init(0, "contact"); | 220 | init(0, "contact"); |
221 | } | 221 | } |
222 | 222 | ||
223 | AddressBook::AddressBook( const QString &config ) | 223 | AddressBook::AddressBook( const QString &config ) |
224 | { | 224 | { |
225 | init(config, "contact"); | 225 | init(config, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 228 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 229 | { |
230 | init(config, family); | 230 | init(config, family); |
231 | 231 | ||
232 | } | 232 | } |
233 | 233 | ||
234 | // the default family is "contact" | 234 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 235 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | blockLSEchange = false; | 237 | blockLSEchange = false; |
238 | d = new AddressBookData; | 238 | d = new AddressBookData; |
239 | QString fami = family; | 239 | QString fami = family; |
240 | qDebug("new ab "); | 240 | qDebug("new ab "); |
241 | if (config != 0) { | 241 | if (config != 0) { |
242 | qDebug("config != 0 "); | 242 | qDebug("config != 0 "); |
243 | if ( family == "syncContact" ) { | 243 | if ( family == "syncContact" ) { |
244 | qDebug("creating sync config "); | 244 | qDebug("creating sync config "); |
245 | fami = "contact"; | 245 | fami = "contact"; |
246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
247 | con->setGroup( "General" ); | 247 | con->setGroup( "General" ); |
248 | con->writeEntry( "ResourceKeys", QString("sync") ); | 248 | con->writeEntry( "ResourceKeys", QString("sync") ); |
249 | con->writeEntry( "Standard", QString("sync") ); | 249 | con->writeEntry( "Standard", QString("sync") ); |
250 | con->setGroup( "Resource_sync" ); | 250 | con->setGroup( "Resource_sync" ); |
251 | con->writeEntry( "FileName", config ); | 251 | con->writeEntry( "FileName", config ); |
252 | con->writeEntry( "FileFormat", QString("vcard") ); | 252 | con->writeEntry( "FileFormat", QString("vcard") ); |
253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
254 | con->writeEntry( "ResourceName", QString("sync_res") ); | 254 | con->writeEntry( "ResourceName", QString("sync_res") ); |
255 | if ( config.right(4) == ".xml" ) | 255 | if ( config.right(4) == ".xml" ) |
256 | con->writeEntry( "ResourceType", QString("qtopia") ); | 256 | con->writeEntry( "ResourceType", QString("qtopia") ); |
257 | else | 257 | else |
258 | con->writeEntry( "ResourceType", QString("file") ); | 258 | con->writeEntry( "ResourceType", QString("file") ); |
259 | //con->sync(); | 259 | //con->sync(); |
260 | d->mConfig = con; | 260 | d->mConfig = con; |
261 | } | 261 | } |
262 | else | 262 | else |
263 | d->mConfig = new KConfig( locateLocal("config", config) ); | 263 | d->mConfig = new KConfig( locateLocal("config", config) ); |
264 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 264 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
265 | } | 265 | } |
266 | else { | 266 | else { |
267 | d->mConfig = 0; | 267 | d->mConfig = 0; |
268 | // qDebug("AddressBook::init 1 config=0"); | 268 | // qDebug("AddressBook::init 1 config=0"); |
269 | } | 269 | } |
270 | 270 | ||
271 | //US d->mErrorHandler = 0; | 271 | //US d->mErrorHandler = 0; |
272 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 272 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
273 | d->mManager->readConfig( d->mConfig ); | 273 | d->mManager->readConfig( d->mConfig ); |
274 | if ( family == "syncContact" ) { | 274 | if ( family == "syncContact" ) { |
275 | KRES::Manager<Resource> *manager = d->mManager; | 275 | KRES::Manager<Resource> *manager = d->mManager; |
276 | KRES::Manager<Resource>::ActiveIterator it; | 276 | KRES::Manager<Resource>::ActiveIterator it; |
277 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 277 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
278 | (*it)->setAddressBook( this ); | 278 | (*it)->setAddressBook( this ); |
279 | if ( !(*it)->open() ) | 279 | if ( !(*it)->open() ) |
280 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 280 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
281 | } | 281 | } |
282 | Resource *res = standardResource(); | 282 | Resource *res = standardResource(); |
283 | if ( !res ) { | 283 | if ( !res ) { |
284 | qDebug("ERROR: no standard resource"); | 284 | qDebug("ERROR: no standard resource"); |
285 | res = manager->createResource( "file" ); | 285 | res = manager->createResource( "file" ); |
286 | if ( res ) | 286 | if ( res ) |
287 | { | 287 | { |
288 | addResource( res ); | 288 | addResource( res ); |
289 | } | 289 | } |
290 | else | 290 | else |
291 | qDebug(" No resource available!!!"); | 291 | qDebug(" No resource available!!!"); |
292 | } | 292 | } |
293 | setStandardResource( res ); | 293 | setStandardResource( res ); |
294 | manager->writeConfig(); | 294 | manager->writeConfig(); |
295 | } | 295 | } |
296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
297 | "X-Department", "KADDRESSBOOK" ); | 297 | "X-Department", "KADDRESSBOOK" ); |
298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
299 | "X-Profession", "KADDRESSBOOK" ); | 299 | "X-Profession", "KADDRESSBOOK" ); |
300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
301 | "X-AssistantsName", "KADDRESSBOOK" ); | 301 | "X-AssistantsName", "KADDRESSBOOK" ); |
302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
303 | "X-ManagersName", "KADDRESSBOOK" ); | 303 | "X-ManagersName", "KADDRESSBOOK" ); |
304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
305 | "X-SpousesName", "KADDRESSBOOK" ); | 305 | "X-SpousesName", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
307 | "X-Office", "KADDRESSBOOK" ); | 307 | "X-Office", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
309 | "X-IMAddress", "KADDRESSBOOK" ); | 309 | "X-IMAddress", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
311 | "X-Anniversary", "KADDRESSBOOK" ); | 311 | "X-Anniversary", "KADDRESSBOOK" ); |
312 | 312 | ||
313 | //US added this field to become compatible with Opie/qtopia addressbook | 313 | //US added this field to become compatible with Opie/qtopia addressbook |
314 | // values can be "female" or "male" or "". An empty field represents undefined. | 314 | // values can be "female" or "male" or "". An empty field represents undefined. |
315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
316 | "X-Gender", "KADDRESSBOOK" ); | 316 | "X-Gender", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
318 | "X-Children", "KADDRESSBOOK" ); | 318 | "X-Children", "KADDRESSBOOK" ); |
319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
322 | "X-ExternalID", "KADDRESSBOOK" ); | 322 | "X-ExternalID", "KADDRESSBOOK" ); |
323 | } | 323 | } |
324 | 324 | ||
325 | AddressBook::~AddressBook() | 325 | AddressBook::~AddressBook() |
326 | { | 326 | { |
327 | delete d->mConfig; d->mConfig = 0; | 327 | delete d->mConfig; d->mConfig = 0; |
328 | delete d->mManager; d->mManager = 0; | 328 | delete d->mManager; d->mManager = 0; |
329 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 329 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
330 | delete d; d = 0; | 330 | delete d; d = 0; |
331 | } | 331 | } |
332 | 332 | ||
333 | bool AddressBook::load() | 333 | bool AddressBook::load() |
334 | { | 334 | { |
335 | 335 | ||
336 | 336 | ||
337 | clear(); | 337 | clear(); |
338 | 338 | ||
339 | KRES::Manager<Resource>::ActiveIterator it; | 339 | KRES::Manager<Resource>::ActiveIterator it; |
340 | bool ok = true; | 340 | bool ok = true; |
341 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 341 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
342 | if ( !(*it)->load() ) { | 342 | if ( !(*it)->load() ) { |
343 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 343 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
344 | ok = false; | 344 | ok = false; |
345 | } | 345 | } |
346 | 346 | ||
347 | // mark all addressees as unchanged | 347 | // mark all addressees as unchanged |
348 | Addressee::List::Iterator addrIt; | 348 | Addressee::List::Iterator addrIt; |
349 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 349 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
350 | (*addrIt).setChanged( false ); | 350 | (*addrIt).setChanged( false ); |
351 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 351 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
352 | if ( !id.isEmpty() ) { | 352 | if ( !id.isEmpty() ) { |
353 | //qDebug("setId aa %s ", id.latin1()); | 353 | //qDebug("setId aa %s ", id.latin1()); |
354 | (*addrIt).setIDStr(id ); | 354 | (*addrIt).setIDStr(id ); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | blockLSEchange = true; | 357 | blockLSEchange = true; |
358 | return ok; | 358 | return ok; |
359 | } | 359 | } |
360 | 360 | ||
361 | bool AddressBook::save( Ticket *ticket ) | 361 | bool AddressBook::save( Ticket *ticket ) |
362 | { | 362 | { |
363 | kdDebug(5700) << "AddressBook::save()"<< endl; | 363 | kdDebug(5700) << "AddressBook::save()"<< endl; |
364 | 364 | ||
365 | if ( ticket->resource() ) { | 365 | if ( ticket->resource() ) { |
366 | deleteRemovedAddressees(); | 366 | deleteRemovedAddressees(); |
367 | return ticket->resource()->save( ticket ); | 367 | return ticket->resource()->save( ticket ); |
368 | } | 368 | } |
369 | 369 | ||
370 | return false; | 370 | return false; |
371 | } | 371 | } |
372 | bool AddressBook::saveAB() | 372 | bool AddressBook::saveAB() |
373 | { | 373 | { |
374 | bool ok = true; | 374 | bool ok = true; |
375 | 375 | ||
376 | deleteRemovedAddressees(); | 376 | deleteRemovedAddressees(); |
377 | Iterator ait; | 377 | Iterator ait; |
378 | for ( ait = begin(); ait != end(); ++ait ) { | 378 | for ( ait = begin(); ait != end(); ++ait ) { |
379 | if ( !(*ait).IDStr().isEmpty() ) { | 379 | if ( !(*ait).IDStr().isEmpty() ) { |
380 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 380 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
381 | } | 381 | } |
382 | } | 382 | } |
383 | KRES::Manager<Resource>::ActiveIterator it; | 383 | KRES::Manager<Resource>::ActiveIterator it; |
384 | KRES::Manager<Resource> *manager = d->mManager; | 384 | KRES::Manager<Resource> *manager = d->mManager; |
385 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 385 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
386 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 386 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
387 | Ticket *ticket = requestSaveTicket( *it ); | 387 | Ticket *ticket = requestSaveTicket( *it ); |
388 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 388 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
389 | if ( !ticket ) { | 389 | if ( !ticket ) { |
390 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 390 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
391 | .arg( (*it)->resourceName() ) ); | 391 | .arg( (*it)->resourceName() ) ); |
392 | return false; | 392 | return false; |
393 | } | 393 | } |
394 | 394 | ||
395 | //if ( !save( ticket ) ) | 395 | //if ( !save( ticket ) ) |
396 | if ( ticket->resource() ) { | 396 | if ( ticket->resource() ) { |
397 | if ( ! ticket->resource()->save( ticket ) ) | 397 | if ( ! ticket->resource()->save( ticket ) ) |
398 | ok = false; | 398 | ok = false; |
399 | } else | 399 | } else |
400 | ok = false; | 400 | ok = false; |
401 | 401 | ||
402 | } | 402 | } |
403 | } | 403 | } |
404 | return ok; | 404 | return ok; |
405 | } | 405 | } |
406 | 406 | ||
407 | AddressBook::Iterator AddressBook::begin() | 407 | AddressBook::Iterator AddressBook::begin() |
408 | { | 408 | { |
409 | Iterator it = Iterator(); | 409 | Iterator it = Iterator(); |
410 | it.d->mIt = d->mAddressees.begin(); | 410 | it.d->mIt = d->mAddressees.begin(); |
411 | return it; | 411 | return it; |
412 | } | 412 | } |
413 | 413 | ||
414 | AddressBook::ConstIterator AddressBook::begin() const | 414 | AddressBook::ConstIterator AddressBook::begin() const |
415 | { | 415 | { |
416 | ConstIterator it = ConstIterator(); | 416 | ConstIterator it = ConstIterator(); |
417 | it.d->mIt = d->mAddressees.begin(); | 417 | it.d->mIt = d->mAddressees.begin(); |
418 | return it; | 418 | return it; |
419 | } | 419 | } |
420 | 420 | ||
421 | AddressBook::Iterator AddressBook::end() | 421 | AddressBook::Iterator AddressBook::end() |
422 | { | 422 | { |
423 | Iterator it = Iterator(); | 423 | Iterator it = Iterator(); |
424 | it.d->mIt = d->mAddressees.end(); | 424 | it.d->mIt = d->mAddressees.end(); |
425 | return it; | 425 | return it; |
426 | } | 426 | } |
427 | 427 | ||
428 | AddressBook::ConstIterator AddressBook::end() const | 428 | AddressBook::ConstIterator AddressBook::end() const |
429 | { | 429 | { |
430 | ConstIterator it = ConstIterator(); | 430 | ConstIterator it = ConstIterator(); |
431 | it.d->mIt = d->mAddressees.end(); | 431 | it.d->mIt = d->mAddressees.end(); |
432 | return it; | 432 | return it; |
433 | } | 433 | } |
434 | 434 | ||
435 | void AddressBook::clear() | 435 | void AddressBook::clear() |
436 | { | 436 | { |
437 | d->mAddressees.clear(); | 437 | d->mAddressees.clear(); |
438 | } | 438 | } |
439 | 439 | ||
440 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 440 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
441 | { | 441 | { |
442 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 442 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
443 | 443 | ||
444 | if ( !resource ) | 444 | if ( !resource ) |
445 | { | 445 | { |
446 | qDebug("AddressBook::requestSaveTicket no resource" ); | 446 | qDebug("AddressBook::requestSaveTicket no resource" ); |
447 | resource = standardResource(); | 447 | resource = standardResource(); |
448 | } | 448 | } |
449 | 449 | ||
450 | KRES::Manager<Resource>::ActiveIterator it; | 450 | KRES::Manager<Resource>::ActiveIterator it; |
451 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 451 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
452 | if ( (*it) == resource ) { | 452 | if ( (*it) == resource ) { |
453 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 453 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
454 | return 0; | 454 | return 0; |
455 | else | 455 | else |
456 | return (*it)->requestSaveTicket(); | 456 | return (*it)->requestSaveTicket(); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | return 0; | 460 | return 0; |
461 | } | 461 | } |
462 | 462 | ||
463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
464 | { | 464 | { |
465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
466 | //qDebug("block insert "); | 466 | //qDebug("block insert "); |
467 | return; | 467 | return; |
468 | } | 468 | } |
469 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 469 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
470 | bool found = false; | 470 | bool found = false; |
471 | Addressee::List::Iterator it; | 471 | Addressee::List::Iterator it; |
472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
473 | if ( a.uid() == (*it).uid() ) { | 473 | if ( a.uid() == (*it).uid() ) { |
474 | 474 | ||
475 | bool changed = false; | 475 | bool changed = false; |
476 | Addressee addr = a; | 476 | Addressee addr = a; |
477 | if ( addr != (*it) ) | 477 | if ( addr != (*it) ) |
478 | changed = true; | 478 | changed = true; |
479 | 479 | ||
480 | (*it) = a; | 480 | (*it) = a; |
481 | if ( (*it).resource() == 0 ) | 481 | if ( (*it).resource() == 0 ) |
482 | (*it).setResource( standardResource() ); | 482 | (*it).setResource( standardResource() ); |
483 | 483 | ||
484 | if ( changed ) { | 484 | if ( changed ) { |
485 | if ( setRev ) { | 485 | if ( setRev ) { |
486 | 486 | ||
487 | // get rid of micro seconds | 487 | // get rid of micro seconds |
488 | QDateTime dt = QDateTime::currentDateTime(); | 488 | QDateTime dt = QDateTime::currentDateTime(); |
489 | QTime t = dt.time(); | 489 | QTime t = dt.time(); |
490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
491 | (*it).setRevision( dt ); | 491 | (*it).setRevision( dt ); |
492 | } | 492 | } |
493 | (*it).setChanged( true ); | 493 | (*it).setChanged( true ); |
494 | } | 494 | } |
495 | 495 | ||
496 | found = true; | 496 | found = true; |
497 | } else { | 497 | } else { |
498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
499 | QString name = (*it).uid().mid( 19 ); | 499 | QString name = (*it).uid().mid( 19 ); |
500 | Addressee b = a; | 500 | Addressee b = a; |
501 | QString id = b.getID( name ); | 501 | QString id = b.getID( name ); |
502 | if ( ! id.isEmpty() ) { | 502 | if ( ! id.isEmpty() ) { |
503 | QString des = (*it).note(); | 503 | QString des = (*it).note(); |
504 | int startN; | 504 | int startN; |
505 | if( (startN = des.find( id ) ) >= 0 ) { | 505 | if( (startN = des.find( id ) ) >= 0 ) { |
506 | int endN = des.find( ",", startN+1 ); | 506 | int endN = des.find( ",", startN+1 ); |
507 | des = des.left( startN ) + des.mid( endN+1 ); | 507 | des = des.left( startN ) + des.mid( endN+1 ); |
508 | (*it).setNote( des ); | 508 | (*it).setNote( des ); |
509 | } | 509 | } |
510 | } | 510 | } |
511 | } | 511 | } |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if ( found ) | 514 | if ( found ) |
515 | return; | 515 | return; |
516 | d->mAddressees.append( a ); | 516 | d->mAddressees.append( a ); |
517 | Addressee& addr = d->mAddressees.last(); | 517 | Addressee& addr = d->mAddressees.last(); |
518 | if ( addr.resource() == 0 ) | 518 | if ( addr.resource() == 0 ) |
519 | addr.setResource( standardResource() ); | 519 | addr.setResource( standardResource() ); |
520 | 520 | ||
521 | addr.setChanged( true ); | 521 | addr.setChanged( true ); |
522 | } | 522 | } |
523 | 523 | ||
524 | void AddressBook::removeAddressee( const Addressee &a ) | 524 | void AddressBook::removeAddressee( const Addressee &a ) |
525 | { | 525 | { |
526 | Iterator it; | 526 | Iterator it; |
527 | Iterator it2; | 527 | Iterator it2; |
528 | bool found = false; | 528 | bool found = false; |
529 | for ( it = begin(); it != end(); ++it ) { | 529 | for ( it = begin(); it != end(); ++it ) { |
530 | if ( a.uid() == (*it).uid() ) { | 530 | if ( a.uid() == (*it).uid() ) { |
531 | found = true; | 531 | found = true; |
532 | it2 = it; | 532 | it2 = it; |
533 | } else { | 533 | } else { |
534 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 534 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
535 | QString name = (*it).uid().mid( 19 ); | 535 | QString name = (*it).uid().mid( 19 ); |
536 | Addressee b = a; | 536 | Addressee b = a; |
537 | QString id = b.getID( name ); | 537 | QString id = b.getID( name ); |
538 | if ( ! id.isEmpty() ) { | 538 | if ( ! id.isEmpty() ) { |
539 | QString des = (*it).note(); | 539 | QString des = (*it).note(); |
540 | if( des.find( id ) < 0 ) { | 540 | if( des.find( id ) < 0 ) { |
541 | des += id + ","; | 541 | des += id + ","; |
542 | (*it).setNote( des ); | 542 | (*it).setNote( des ); |
543 | } | 543 | } |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | if ( found ) | 550 | if ( found ) |
551 | removeAddressee( it2 ); | 551 | removeAddressee( it2 ); |
552 | 552 | ||
553 | } | 553 | } |
554 | 554 | ||
555 | void AddressBook::removeDeletedAddressees() | 555 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
556 | { | 556 | { |
557 | deleteRemovedAddressees(); | ||
558 | Iterator it = begin(); | 557 | Iterator it = begin(); |
559 | Iterator it2 ; | 558 | Iterator it2 ; |
560 | QDateTime dt ( QDate( 2004,1,1) ); | 559 | QDateTime dt ( QDate( 2004,1,1) ); |
561 | while ( it != end() ) { | 560 | while ( it != end() ) { |
562 | (*it).setRevision( dt ); | 561 | (*it).setRevision( dt ); |
563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 562 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
564 | (*it).setIDStr(""); | 563 | (*it).setIDStr(""); |
565 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 564 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
566 | it2 = it; | 565 | it2 = it; |
567 | //qDebug("removing %s ",(*it).uid().latin1() ); | 566 | //qDebug("removing %s ",(*it).uid().latin1() ); |
568 | ++it; | 567 | ++it; |
569 | removeAddressee( it2 ); | 568 | removeAddressee( it2 ); |
570 | } else { | 569 | } else { |
571 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 570 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
572 | ++it; | 571 | ++it; |
573 | } | 572 | } |
574 | } | 573 | } |
575 | deleteRemovedAddressees(); | 574 | deleteRemovedAddressees(); |
576 | } | 575 | } |
577 | 576 | ||
578 | void AddressBook::removeAddressee( const Iterator &it ) | 577 | void AddressBook::removeAddressee( const Iterator &it ) |
579 | { | 578 | { |
580 | d->mRemovedAddressees.append( (*it) ); | 579 | d->mRemovedAddressees.append( (*it) ); |
581 | d->mAddressees.remove( it.d->mIt ); | 580 | d->mAddressees.remove( it.d->mIt ); |
582 | } | 581 | } |
583 | 582 | ||
584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 583 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
585 | { | 584 | { |
586 | Iterator it; | 585 | Iterator it; |
587 | for ( it = begin(); it != end(); ++it ) { | 586 | for ( it = begin(); it != end(); ++it ) { |
588 | if ( a.uid() == (*it).uid() ) { | 587 | if ( a.uid() == (*it).uid() ) { |
589 | return it; | 588 | return it; |
590 | } | 589 | } |
591 | } | 590 | } |
592 | return end(); | 591 | return end(); |
593 | } | 592 | } |
594 | 593 | ||
595 | Addressee AddressBook::findByUid( const QString &uid ) | 594 | Addressee AddressBook::findByUid( const QString &uid ) |
596 | { | 595 | { |
597 | Iterator it; | 596 | Iterator it; |
598 | for ( it = begin(); it != end(); ++it ) { | 597 | for ( it = begin(); it != end(); ++it ) { |
599 | if ( uid == (*it).uid() ) { | 598 | if ( uid == (*it).uid() ) { |
600 | return *it; | 599 | return *it; |
601 | } | 600 | } |
602 | } | 601 | } |
603 | return Addressee(); | 602 | return Addressee(); |
604 | } | 603 | } |
605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 604 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
606 | { | 605 | { |
607 | qDebug("AddressBook::preExternSync "); | 606 | qDebug("AddressBook::preExternSync "); |
608 | AddressBook::Iterator it; | 607 | AddressBook::Iterator it; |
609 | for ( it = begin(); it != end(); ++it ) { | 608 | for ( it = begin(); it != end(); ++it ) { |
610 | (*it).setID( csd, (*it).externalUID() ); | 609 | (*it).setID( csd, (*it).externalUID() ); |
611 | (*it).computeCsum( csd ); | 610 | (*it).computeCsum( csd ); |
612 | } | 611 | } |
613 | mergeAB( aBook ,csd ); | 612 | mergeAB( aBook ,csd ); |
614 | } | 613 | } |
615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 614 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
616 | { | 615 | { |
617 | qDebug("AddressBook::postExternSync "); | 616 | qDebug("AddressBook::postExternSync "); |
618 | AddressBook::Iterator it; | 617 | AddressBook::Iterator it; |
619 | for ( it = begin(); it != end(); ++it ) { | 618 | for ( it = begin(); it != end(); ++it ) { |
619 | qDebug("check uid %s ", (*it).uid().latin1() ); | ||
620 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 620 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
621 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 621 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
622 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 622 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
623 | if ( ad.isEmpty() ) { | 623 | if ( ad.isEmpty() ) { |
624 | qDebug("ERROR ad empty "); | 624 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
625 | } else { | 625 | } else { |
626 | (*it).computeCsum( csd ); | 626 | (*it).computeCsum( csd ); |
627 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 627 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
628 | ad.setID( csd, (*it).externalUID() ); | 628 | ad.setID( csd, (*it).externalUID() ); |
629 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 629 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
630 | aBook->insertAddressee( ad ); | 630 | aBook->insertAddressee( ad ); |
631 | } | 631 | } |
632 | } | 632 | } |
633 | } | 633 | } |
634 | } | 634 | } |
635 | 635 | ||
636 | 636 | bool AddressBook::containsExternalUid( const QString& uid ) | |
637 | { | ||
638 | Iterator it; | ||
639 | for ( it = begin(); it != end(); ++it ) { | ||
640 | if ( uid == (*it).externalUID( ) ) | ||
641 | return true; | ||
642 | } | ||
643 | return false; | ||
644 | } | ||
637 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 645 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
638 | { | 646 | { |
639 | Iterator it; | 647 | Iterator it; |
640 | for ( it = begin(); it != end(); ++it ) { | 648 | for ( it = begin(); it != end(); ++it ) { |
641 | if ( uid == (*it).getID( profile ) ) | 649 | if ( uid == (*it).getID( profile ) ) |
642 | return (*it); | 650 | return (*it); |
643 | } | 651 | } |
644 | return Addressee(); | 652 | return Addressee(); |
645 | } | 653 | } |
646 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 654 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
647 | { | 655 | { |
648 | Iterator it; | 656 | Iterator it; |
649 | Addressee ad; | 657 | Addressee ad; |
650 | for ( it = begin(); it != end(); ++it ) { | 658 | for ( it = begin(); it != end(); ++it ) { |
651 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 659 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
652 | if ( !ad.isEmpty() ) { | 660 | if ( !ad.isEmpty() ) { |
653 | (*it).mergeContact( ad ); | 661 | (*it).mergeContact( ad ); |
654 | } | 662 | } |
655 | } | 663 | } |
664 | #if 0 | ||
665 | // test only | ||
666 | for ( it = begin(); it != end(); ++it ) { | ||
667 | |||
668 | qDebug("uid %s ", (*it).uid().latin1()); | ||
669 | } | ||
670 | #endif | ||
656 | } | 671 | } |
657 | 672 | ||
658 | #if 0 | 673 | #if 0 |
659 | Addressee::List AddressBook::getExternLastSyncAddressees() | 674 | Addressee::List AddressBook::getExternLastSyncAddressees() |
660 | { | 675 | { |
661 | Addressee::List results; | 676 | Addressee::List results; |
662 | 677 | ||
663 | Iterator it; | 678 | Iterator it; |
664 | for ( it = begin(); it != end(); ++it ) { | 679 | for ( it = begin(); it != end(); ++it ) { |
665 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 680 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
666 | if ( (*it).familyName().left(4) == "!E: " ) | 681 | if ( (*it).familyName().left(4) == "!E: " ) |
667 | results.append( *it ); | 682 | results.append( *it ); |
668 | } | 683 | } |
669 | } | 684 | } |
670 | 685 | ||
671 | return results; | 686 | return results; |
672 | } | 687 | } |
673 | #endif | 688 | #endif |
674 | void AddressBook::resetTempSyncStat() | 689 | void AddressBook::resetTempSyncStat() |
675 | { | 690 | { |
676 | Iterator it; | 691 | Iterator it; |
677 | for ( it = begin(); it != end(); ++it ) { | 692 | for ( it = begin(); it != end(); ++it ) { |
678 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 693 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
679 | } | 694 | } |
680 | 695 | ||
681 | } | 696 | } |
682 | 697 | ||
683 | QStringList AddressBook:: uidList() | 698 | QStringList AddressBook:: uidList() |
684 | { | 699 | { |
685 | QStringList results; | 700 | QStringList results; |
686 | Iterator it; | 701 | Iterator it; |
687 | for ( it = begin(); it != end(); ++it ) { | 702 | for ( it = begin(); it != end(); ++it ) { |
688 | results.append( (*it).uid() ); | 703 | results.append( (*it).uid() ); |
689 | } | 704 | } |
690 | return results; | 705 | return results; |
691 | } | 706 | } |
692 | 707 | ||
693 | 708 | ||
694 | Addressee::List AddressBook::allAddressees() | 709 | Addressee::List AddressBook::allAddressees() |
695 | { | 710 | { |
696 | return d->mAddressees; | 711 | return d->mAddressees; |
697 | 712 | ||
698 | } | 713 | } |
699 | 714 | ||
700 | Addressee::List AddressBook::findByName( const QString &name ) | 715 | Addressee::List AddressBook::findByName( const QString &name ) |
701 | { | 716 | { |
702 | Addressee::List results; | 717 | Addressee::List results; |
703 | 718 | ||
704 | Iterator it; | 719 | Iterator it; |
705 | for ( it = begin(); it != end(); ++it ) { | 720 | for ( it = begin(); it != end(); ++it ) { |
706 | if ( name == (*it).realName() ) { | 721 | if ( name == (*it).realName() ) { |
707 | results.append( *it ); | 722 | results.append( *it ); |
708 | } | 723 | } |
709 | } | 724 | } |
710 | 725 | ||
711 | return results; | 726 | return results; |
712 | } | 727 | } |
713 | 728 | ||
714 | Addressee::List AddressBook::findByEmail( const QString &email ) | 729 | Addressee::List AddressBook::findByEmail( const QString &email ) |
715 | { | 730 | { |
716 | Addressee::List results; | 731 | Addressee::List results; |
717 | QStringList mailList; | 732 | QStringList mailList; |
718 | 733 | ||
719 | Iterator it; | 734 | Iterator it; |
720 | for ( it = begin(); it != end(); ++it ) { | 735 | for ( it = begin(); it != end(); ++it ) { |
721 | mailList = (*it).emails(); | 736 | mailList = (*it).emails(); |
722 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 737 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
723 | if ( email == (*ite) ) { | 738 | if ( email == (*ite) ) { |
724 | results.append( *it ); | 739 | results.append( *it ); |
725 | } | 740 | } |
726 | } | 741 | } |
727 | } | 742 | } |
728 | 743 | ||
729 | return results; | 744 | return results; |
730 | } | 745 | } |
731 | 746 | ||
732 | Addressee::List AddressBook::findByCategory( const QString &category ) | 747 | Addressee::List AddressBook::findByCategory( const QString &category ) |
733 | { | 748 | { |
734 | Addressee::List results; | 749 | Addressee::List results; |
735 | 750 | ||
736 | Iterator it; | 751 | Iterator it; |
737 | for ( it = begin(); it != end(); ++it ) { | 752 | for ( it = begin(); it != end(); ++it ) { |
738 | if ( (*it).hasCategory( category) ) { | 753 | if ( (*it).hasCategory( category) ) { |
739 | results.append( *it ); | 754 | results.append( *it ); |
740 | } | 755 | } |
741 | } | 756 | } |
742 | 757 | ||
743 | return results; | 758 | return results; |
744 | } | 759 | } |
745 | 760 | ||
746 | void AddressBook::dump() const | 761 | void AddressBook::dump() const |
747 | { | 762 | { |
748 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 763 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
749 | 764 | ||
750 | ConstIterator it; | 765 | ConstIterator it; |
751 | for( it = begin(); it != end(); ++it ) { | 766 | for( it = begin(); it != end(); ++it ) { |
752 | (*it).dump(); | 767 | (*it).dump(); |
753 | } | 768 | } |
754 | 769 | ||
755 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 770 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
756 | } | 771 | } |
757 | 772 | ||
758 | QString AddressBook::identifier() | 773 | QString AddressBook::identifier() |
759 | { | 774 | { |
760 | QStringList identifier; | 775 | QStringList identifier; |
761 | 776 | ||
762 | 777 | ||
763 | KRES::Manager<Resource>::ActiveIterator it; | 778 | KRES::Manager<Resource>::ActiveIterator it; |
764 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 779 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
765 | if ( !(*it)->identifier().isEmpty() ) | 780 | if ( !(*it)->identifier().isEmpty() ) |
766 | identifier.append( (*it)->identifier() ); | 781 | identifier.append( (*it)->identifier() ); |
767 | } | 782 | } |
768 | 783 | ||
769 | return identifier.join( ":" ); | 784 | return identifier.join( ":" ); |
770 | } | 785 | } |
771 | 786 | ||
772 | Field::List AddressBook::fields( int category ) | 787 | Field::List AddressBook::fields( int category ) |
773 | { | 788 | { |
774 | if ( d->mAllFields.isEmpty() ) { | 789 | if ( d->mAllFields.isEmpty() ) { |
775 | d->mAllFields = Field::allFields(); | 790 | d->mAllFields = Field::allFields(); |
776 | } | 791 | } |
777 | 792 | ||
778 | if ( category == Field::All ) return d->mAllFields; | 793 | if ( category == Field::All ) return d->mAllFields; |
779 | 794 | ||
780 | Field::List result; | 795 | Field::List result; |
781 | Field::List::ConstIterator it; | 796 | Field::List::ConstIterator it; |
782 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 797 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
783 | if ( (*it)->category() & category ) result.append( *it ); | 798 | if ( (*it)->category() & category ) result.append( *it ); |
784 | } | 799 | } |
785 | 800 | ||
786 | return result; | 801 | return result; |
787 | } | 802 | } |
788 | 803 | ||
789 | bool AddressBook::addCustomField( const QString &label, int category, | 804 | bool AddressBook::addCustomField( const QString &label, int category, |
790 | const QString &key, const QString &app ) | 805 | const QString &key, const QString &app ) |
791 | { | 806 | { |
792 | if ( d->mAllFields.isEmpty() ) { | 807 | if ( d->mAllFields.isEmpty() ) { |
793 | d->mAllFields = Field::allFields(); | 808 | d->mAllFields = Field::allFields(); |
794 | } | 809 | } |
795 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 810 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
796 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 811 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
797 | 812 | ||
798 | QString k = key.isNull() ? label : key; | 813 | QString k = key.isNull() ? label : key; |
799 | 814 | ||
800 | Field *field = Field::createCustomField( label, category, k, a ); | 815 | Field *field = Field::createCustomField( label, category, k, a ); |
801 | 816 | ||
802 | if ( !field ) return false; | 817 | if ( !field ) return false; |
803 | 818 | ||
804 | d->mAllFields.append( field ); | 819 | d->mAllFields.append( field ); |
805 | 820 | ||
806 | return true; | 821 | return true; |
807 | } | 822 | } |
808 | 823 | ||
809 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 824 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
810 | { | 825 | { |
811 | if (!ab.d) return s; | 826 | if (!ab.d) return s; |
812 | 827 | ||
813 | return s << ab.d->mAddressees; | 828 | return s << ab.d->mAddressees; |
814 | } | 829 | } |
815 | 830 | ||
816 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 831 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
817 | { | 832 | { |
818 | if (!ab.d) return s; | 833 | if (!ab.d) return s; |
819 | 834 | ||
820 | s >> ab.d->mAddressees; | 835 | s >> ab.d->mAddressees; |
821 | 836 | ||
822 | return s; | 837 | return s; |
823 | } | 838 | } |
824 | 839 | ||
825 | bool AddressBook::addResource( Resource *resource ) | 840 | bool AddressBook::addResource( Resource *resource ) |
826 | { | 841 | { |
827 | if ( !resource->open() ) { | 842 | if ( !resource->open() ) { |
828 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 843 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
829 | return false; | 844 | return false; |
830 | } | 845 | } |
831 | 846 | ||
832 | resource->setAddressBook( this ); | 847 | resource->setAddressBook( this ); |
833 | 848 | ||
834 | d->mManager->add( resource ); | 849 | d->mManager->add( resource ); |
835 | return true; | 850 | return true; |
836 | } | 851 | } |
837 | 852 | ||
838 | bool AddressBook::removeResource( Resource *resource ) | 853 | bool AddressBook::removeResource( Resource *resource ) |
839 | { | 854 | { |
840 | resource->close(); | 855 | resource->close(); |
841 | 856 | ||
842 | if ( resource == standardResource() ) | 857 | if ( resource == standardResource() ) |
843 | d->mManager->setStandardResource( 0 ); | 858 | d->mManager->setStandardResource( 0 ); |
844 | 859 | ||
845 | resource->setAddressBook( 0 ); | 860 | resource->setAddressBook( 0 ); |
846 | 861 | ||
847 | d->mManager->remove( resource ); | 862 | d->mManager->remove( resource ); |
848 | return true; | 863 | return true; |
849 | } | 864 | } |
850 | 865 | ||
851 | QPtrList<Resource> AddressBook::resources() | 866 | QPtrList<Resource> AddressBook::resources() |
852 | { | 867 | { |
853 | QPtrList<Resource> list; | 868 | QPtrList<Resource> list; |
854 | 869 | ||
855 | // qDebug("AddressBook::resources() 1"); | 870 | // qDebug("AddressBook::resources() 1"); |
856 | 871 | ||
857 | KRES::Manager<Resource>::ActiveIterator it; | 872 | KRES::Manager<Resource>::ActiveIterator it; |
858 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 873 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
859 | list.append( *it ); | 874 | list.append( *it ); |
860 | 875 | ||
861 | return list; | 876 | return list; |
862 | } | 877 | } |
863 | 878 | ||
864 | /*US | 879 | /*US |
865 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 880 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
866 | { | 881 | { |
867 | delete d->mErrorHandler; | 882 | delete d->mErrorHandler; |
868 | d->mErrorHandler = handler; | 883 | d->mErrorHandler = handler; |
869 | } | 884 | } |
870 | */ | 885 | */ |
871 | 886 | ||
872 | void AddressBook::error( const QString& msg ) | 887 | void AddressBook::error( const QString& msg ) |
873 | { | 888 | { |
874 | /*US | 889 | /*US |
875 | if ( !d->mErrorHandler ) // create default error handler | 890 | if ( !d->mErrorHandler ) // create default error handler |
876 | d->mErrorHandler = new ConsoleErrorHandler; | 891 | d->mErrorHandler = new ConsoleErrorHandler; |
877 | 892 | ||
878 | if ( d->mErrorHandler ) | 893 | if ( d->mErrorHandler ) |
879 | d->mErrorHandler->error( msg ); | 894 | d->mErrorHandler->error( msg ); |
880 | else | 895 | else |
881 | kdError(5700) << "no error handler defined" << endl; | 896 | kdError(5700) << "no error handler defined" << endl; |
882 | */ | 897 | */ |
883 | kdDebug(5700) << "msg" << endl; | 898 | kdDebug(5700) << "msg" << endl; |
884 | qDebug(msg); | 899 | qDebug(msg); |
885 | } | 900 | } |
886 | 901 | ||
887 | void AddressBook::deleteRemovedAddressees() | 902 | void AddressBook::deleteRemovedAddressees() |
888 | { | 903 | { |
889 | Addressee::List::Iterator it; | 904 | Addressee::List::Iterator it; |
890 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 905 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
891 | Resource *resource = (*it).resource(); | 906 | Resource *resource = (*it).resource(); |
892 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 907 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
893 | resource->removeAddressee( *it ); | 908 | resource->removeAddressee( *it ); |
894 | } | 909 | } |
895 | 910 | ||
896 | d->mRemovedAddressees.clear(); | 911 | d->mRemovedAddressees.clear(); |
897 | } | 912 | } |
898 | 913 | ||
899 | void AddressBook::setStandardResource( Resource *resource ) | 914 | void AddressBook::setStandardResource( Resource *resource ) |
900 | { | 915 | { |
901 | // qDebug("AddressBook::setStandardResource 1"); | 916 | // qDebug("AddressBook::setStandardResource 1"); |
902 | d->mManager->setStandardResource( resource ); | 917 | d->mManager->setStandardResource( resource ); |
903 | } | 918 | } |
904 | 919 | ||
905 | Resource *AddressBook::standardResource() | 920 | Resource *AddressBook::standardResource() |
906 | { | 921 | { |
907 | return d->mManager->standardResource(); | 922 | return d->mManager->standardResource(); |
908 | } | 923 | } |
909 | 924 | ||
910 | KRES::Manager<Resource> *AddressBook::resourceManager() | 925 | KRES::Manager<Resource> *AddressBook::resourceManager() |
911 | { | 926 | { |
912 | return d->mManager; | 927 | return d->mManager; |
913 | } | 928 | } |
914 | 929 | ||
915 | void AddressBook::cleanUp() | 930 | void AddressBook::cleanUp() |
916 | { | 931 | { |
917 | KRES::Manager<Resource>::ActiveIterator it; | 932 | KRES::Manager<Resource>::ActiveIterator it; |
918 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 933 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
919 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 934 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
920 | (*it)->cleanUp(); | 935 | (*it)->cleanUp(); |
921 | } | 936 | } |
922 | } | 937 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 157dc56..8f62f0d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,339 +1,340 @@ | |||
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 | 145 | ||
146 | /** | 146 | /** |
147 | Returns a iterator for first entry of address book. | 147 | Returns a iterator for first entry of address book. |
148 | */ | 148 | */ |
149 | Iterator begin(); | 149 | Iterator begin(); |
150 | 150 | ||
151 | /** | 151 | /** |
152 | Returns a const iterator for first entry of address book. | 152 | Returns a const iterator for first entry of address book. |
153 | */ | 153 | */ |
154 | ConstIterator begin() const; | 154 | ConstIterator begin() const; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | Returns a iterator for first entry of address book. | 157 | Returns a iterator for first entry of address book. |
158 | */ | 158 | */ |
159 | Iterator end(); | 159 | Iterator end(); |
160 | 160 | ||
161 | /** | 161 | /** |
162 | Returns a const iterator for first entry of address book. | 162 | Returns a const iterator for first entry of address book. |
163 | */ | 163 | */ |
164 | ConstIterator end() const; | 164 | ConstIterator end() const; |
165 | 165 | ||
166 | /** | 166 | /** |
167 | Removes all entries from address book. | 167 | Removes all entries from address book. |
168 | */ | 168 | */ |
169 | void clear(); | 169 | void clear(); |
170 | 170 | ||
171 | /** | 171 | /** |
172 | Insert an Addressee object into address book. If an object with the same | 172 | Insert an Addressee object into address book. If an object with the same |
173 | unique id already exists in the address book it it replaced by the new | 173 | unique id already exists in the address book it it replaced by the new |
174 | one. If not the new object is appended to the address book. | 174 | one. If not the new object is appended to the address book. |
175 | */ | 175 | */ |
176 | void insertAddressee( const Addressee &, bool setRev = true ); | 176 | void insertAddressee( const Addressee &, bool setRev = true ); |
177 | 177 | ||
178 | /** | 178 | /** |
179 | Removes entry from the address book. | 179 | Removes entry from the address book. |
180 | */ | 180 | */ |
181 | void removeAddressee( const Addressee & ); | 181 | void removeAddressee( const Addressee & ); |
182 | 182 | ||
183 | /** | 183 | /** |
184 | This is like @ref removeAddressee() just above, with the difference that | 184 | This is like @ref removeAddressee() just above, with the difference that |
185 | the first element is a iterator, returned by @ref begin(). | 185 | the first element is a iterator, returned by @ref begin(). |
186 | */ | 186 | */ |
187 | void removeAddressee( const Iterator & ); | 187 | void removeAddressee( const Iterator & ); |
188 | 188 | ||
189 | /** | 189 | /** |
190 | Find the specified entry in address book. Returns end(), if the entry | 190 | Find the specified entry in address book. Returns end(), if the entry |
191 | couldn't be found. | 191 | couldn't be found. |
192 | */ | 192 | */ |
193 | Iterator find( const Addressee & ); | 193 | Iterator find( const Addressee & ); |
194 | 194 | ||
195 | /** | 195 | /** |
196 | Find the entry specified by an unique id. Returns an empty Addressee | 196 | Find the entry specified by an unique id. Returns an empty Addressee |
197 | object, if the address book does not contain an entry with this id. | 197 | object, if the address book does not contain an entry with this id. |
198 | */ | 198 | */ |
199 | Addressee findByUid( const QString & ); | 199 | Addressee findByUid( const QString & ); |
200 | 200 | ||
201 | 201 | ||
202 | /** | 202 | /** |
203 | Returns a list of all addressees in the address book. This list can | 203 | Returns a list of all addressees in the address book. This list can |
204 | be sorted with @ref KABC::AddresseeList for example. | 204 | be sorted with @ref KABC::AddresseeList for example. |
205 | */ | 205 | */ |
206 | Addressee::List allAddressees(); | 206 | Addressee::List allAddressees(); |
207 | 207 | ||
208 | /** | 208 | /** |
209 | Find all entries with the specified name in the address book. Returns | 209 | Find all entries with the specified name in the address book. Returns |
210 | an empty list, if no entries could be found. | 210 | an empty list, if no entries could be found. |
211 | */ | 211 | */ |
212 | Addressee::List findByName( const QString & ); | 212 | Addressee::List findByName( const QString & ); |
213 | 213 | ||
214 | /** | 214 | /** |
215 | Find all entries with the specified email address in the address book. | 215 | Find all entries with the specified email address in the address book. |
216 | Returns an empty list, if no entries could be found. | 216 | Returns an empty list, if no entries could be found. |
217 | */ | 217 | */ |
218 | Addressee::List findByEmail( const QString & ); | 218 | Addressee::List findByEmail( const QString & ); |
219 | 219 | ||
220 | /** | 220 | /** |
221 | Find all entries wich have the specified category in the address book. | 221 | Find all entries wich have the specified category in the address book. |
222 | Returns an empty list, if no entries could be found. | 222 | Returns an empty list, if no entries could be found. |
223 | */ | 223 | */ |
224 | Addressee::List findByCategory( const QString & ); | 224 | Addressee::List findByCategory( const QString & ); |
225 | 225 | ||
226 | /** | 226 | /** |
227 | Return a string identifying this addressbook. | 227 | Return a string identifying this addressbook. |
228 | */ | 228 | */ |
229 | virtual QString identifier(); | 229 | virtual QString identifier(); |
230 | 230 | ||
231 | /** | 231 | /** |
232 | Used for debug output. | 232 | Used for debug output. |
233 | */ | 233 | */ |
234 | void dump() const; | 234 | void dump() const; |
235 | 235 | ||
236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
239 | 239 | ||
240 | /** | 240 | /** |
241 | Return list of all Fields known to the address book which are associated | 241 | Return list of all Fields known to the address book which are associated |
242 | with the given field category. | 242 | with the given field category. |
243 | */ | 243 | */ |
244 | Field::List fields( int category = Field::All ); | 244 | Field::List fields( int category = Field::All ); |
245 | 245 | ||
246 | /** | 246 | /** |
247 | Add custom field to address book. | 247 | Add custom field to address book. |
248 | 248 | ||
249 | @param label User visible label of the field. | 249 | @param label User visible label of the field. |
250 | @param category Ored list of field categories. | 250 | @param category Ored list of field categories. |
251 | @param key Identifier used as key for reading and writing the field. | 251 | @param key Identifier used as key for reading and writing the field. |
252 | @param app String used as application key for reading and writing | 252 | @param app String used as application key for reading and writing |
253 | the field. | 253 | the field. |
254 | */ | 254 | */ |
255 | bool addCustomField( const QString &label, int category = Field::All, | 255 | bool addCustomField( const QString &label, int category = Field::All, |
256 | const QString &key = QString::null, | 256 | const QString &key = QString::null, |
257 | const QString &app = QString::null ); | 257 | const QString &app = QString::null ); |
258 | 258 | ||
259 | 259 | ||
260 | /** | 260 | /** |
261 | Add address book resource. | 261 | Add address book resource. |
262 | */ | 262 | */ |
263 | bool addResource( Resource * ); | 263 | bool addResource( Resource * ); |
264 | 264 | ||
265 | /** | 265 | /** |
266 | Remove address book resource. | 266 | Remove address book resource. |
267 | */ | 267 | */ |
268 | bool removeResource( Resource * ); | 268 | bool removeResource( Resource * ); |
269 | 269 | ||
270 | /** | 270 | /** |
271 | Return pointer list of all resources. | 271 | Return pointer list of all resources. |
272 | */ | 272 | */ |
273 | QPtrList<Resource> resources(); | 273 | QPtrList<Resource> resources(); |
274 | 274 | ||
275 | /** | 275 | /** |
276 | Set the @p ErrorHandler, that is used by @ref error() to | 276 | Set the @p ErrorHandler, that is used by @ref error() to |
277 | provide gui-independend error messages. | 277 | provide gui-independend error messages. |
278 | */ | 278 | */ |
279 | void setErrorHandler( ErrorHandler * ); | 279 | void setErrorHandler( ErrorHandler * ); |
280 | 280 | ||
281 | /** | 281 | /** |
282 | Shows gui independend error messages. | 282 | Shows gui independend error messages. |
283 | */ | 283 | */ |
284 | void error( const QString& ); | 284 | void error( const QString& ); |
285 | 285 | ||
286 | /** | 286 | /** |
287 | Query all resources to clean up their lock files | 287 | Query all resources to clean up their lock files |
288 | */ | 288 | */ |
289 | void cleanUp(); | 289 | void cleanUp(); |
290 | 290 | ||
291 | // sync stuff | 291 | // sync stuff |
292 | //Addressee::List getExternLastSyncAddressees(); | 292 | //Addressee::List getExternLastSyncAddressees(); |
293 | void resetTempSyncStat(); | 293 | void resetTempSyncStat(); |
294 | QStringList uidList(); | 294 | QStringList uidList(); |
295 | void removeDeletedAddressees(); | 295 | void removeSyncAddressees( bool removeDeleted = false ); |
296 | void mergeAB( AddressBook *aBook, const QString& profile ); | 296 | void mergeAB( AddressBook *aBook, const QString& profile ); |
297 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 297 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
298 | bool containsExternalUid( const QString& uid ); | ||
298 | 299 | ||
299 | void preExternSync( AddressBook* aBook, const QString& csd ); | 300 | void preExternSync( AddressBook* aBook, const QString& csd ); |
300 | void postExternSync( AddressBook* aBook, const QString& csd ); | 301 | void postExternSync( AddressBook* aBook, const QString& csd ); |
301 | signals: | 302 | signals: |
302 | /** | 303 | /** |
303 | Emitted, when the address book has changed on disk. | 304 | Emitted, when the address book has changed on disk. |
304 | */ | 305 | */ |
305 | void addressBookChanged( AddressBook * ); | 306 | void addressBookChanged( AddressBook * ); |
306 | 307 | ||
307 | /** | 308 | /** |
308 | Emitted, when the address book has been locked for writing. | 309 | Emitted, when the address book has been locked for writing. |
309 | */ | 310 | */ |
310 | void addressBookLocked( AddressBook * ); | 311 | void addressBookLocked( AddressBook * ); |
311 | 312 | ||
312 | /** | 313 | /** |
313 | Emitted, when the address book has been unlocked. | 314 | Emitted, when the address book has been unlocked. |
314 | */ | 315 | */ |
315 | void addressBookUnlocked( AddressBook * ); | 316 | void addressBookUnlocked( AddressBook * ); |
316 | 317 | ||
317 | protected: | 318 | protected: |
318 | void deleteRemovedAddressees(); | 319 | void deleteRemovedAddressees(); |
319 | void setStandardResource( Resource * ); | 320 | void setStandardResource( Resource * ); |
320 | Resource *standardResource(); | 321 | Resource *standardResource(); |
321 | KRES::Manager<Resource> *resourceManager(); | 322 | KRES::Manager<Resource> *resourceManager(); |
322 | 323 | ||
323 | void init(const QString &config, const QString &family); | 324 | void init(const QString &config, const QString &family); |
324 | 325 | ||
325 | private: | 326 | private: |
326 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 327 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
327 | 328 | ||
328 | 329 | ||
329 | struct AddressBookData; | 330 | struct AddressBookData; |
330 | AddressBookData *d; | 331 | AddressBookData *d; |
331 | bool blockLSEchange; | 332 | bool blockLSEchange; |
332 | }; | 333 | }; |
333 | 334 | ||
334 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 335 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
335 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 336 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
336 | 337 | ||
337 | } | 338 | } |
338 | 339 | ||
339 | #endif | 340 | #endif |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fda62f1..e241281 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,1847 +1,1851 @@ | |||
1 | /*** Warning! This file has been generated by the script makeaddressee ***/ | 1 | /*** Warning! This file has been generated by the script makeaddressee ***/ |
2 | /* | 2 | /* |
3 | This file is part of libkabc. | 3 | This file is part of libkabc. |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 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 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> |
30 | 30 | ||
31 | #include <ksharedptr.h> | 31 | #include <ksharedptr.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kidmanager.h> | 35 | #include <kidmanager.h> |
36 | //US | 36 | //US |
37 | #include <kstandarddirs.h> | 37 | #include <kstandarddirs.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | //US #include "resource.h" | 40 | //US #include "resource.h" |
41 | #include "addressee.h" | 41 | #include "addressee.h" |
42 | 42 | ||
43 | using namespace KABC; | 43 | using namespace KABC; |
44 | 44 | ||
45 | static bool matchBinaryPattern( int value, int pattern ); | 45 | static bool matchBinaryPattern( int value, int pattern ); |
46 | 46 | ||
47 | struct Addressee::AddresseeData : public KShared | 47 | struct Addressee::AddresseeData : public KShared |
48 | { | 48 | { |
49 | QString uid; | 49 | QString uid; |
50 | QString name; | 50 | QString name; |
51 | QString formattedName; | 51 | QString formattedName; |
52 | QString familyName; | 52 | QString familyName; |
53 | QString givenName; | 53 | QString givenName; |
54 | QString additionalName; | 54 | QString additionalName; |
55 | QString prefix; | 55 | QString prefix; |
56 | QString suffix; | 56 | QString suffix; |
57 | QString nickName; | 57 | QString nickName; |
58 | QDateTime birthday; | 58 | QDateTime birthday; |
59 | QString mailer; | 59 | QString mailer; |
60 | TimeZone timeZone; | 60 | TimeZone timeZone; |
61 | Geo geo; | 61 | Geo geo; |
62 | QString title; | 62 | QString title; |
63 | QString role; | 63 | QString role; |
64 | QString organization; | 64 | QString organization; |
65 | QString note; | 65 | QString note; |
66 | QString productId; | 66 | QString productId; |
67 | QDateTime revision; | 67 | QDateTime revision; |
68 | QString sortString; | 68 | QString sortString; |
69 | QString externalUID; | 69 | QString externalUID; |
70 | QString originalExternalUID; | 70 | QString originalExternalUID; |
71 | KURL url; | 71 | KURL url; |
72 | Secrecy secrecy; | 72 | Secrecy secrecy; |
73 | Picture logo; | 73 | Picture logo; |
74 | Picture photo; | 74 | Picture photo; |
75 | Sound sound; | 75 | Sound sound; |
76 | Agent agent; | 76 | Agent agent; |
77 | QString mExternalId; | 77 | QString mExternalId; |
78 | PhoneNumber::List phoneNumbers; | 78 | PhoneNumber::List phoneNumbers; |
79 | Address::List addresses; | 79 | Address::List addresses; |
80 | Key::List keys; | 80 | Key::List keys; |
81 | QStringList emails; | 81 | QStringList emails; |
82 | QStringList categories; | 82 | QStringList categories; |
83 | QStringList custom; | 83 | QStringList custom; |
84 | int mTempSyncStat; | 84 | int mTempSyncStat; |
85 | Resource *resource; | 85 | Resource *resource; |
86 | 86 | ||
87 | bool empty :1; | 87 | bool empty :1; |
88 | bool changed :1; | 88 | bool changed :1; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | Addressee::Addressee() | 91 | Addressee::Addressee() |
92 | { | 92 | { |
93 | mData = new AddresseeData; | 93 | mData = new AddresseeData; |
94 | mData->empty = true; | 94 | mData->empty = true; |
95 | mData->changed = false; | 95 | mData->changed = false; |
96 | mData->resource = 0; | 96 | mData->resource = 0; |
97 | mData->mExternalId = ":"; | 97 | mData->mExternalId = ":"; |
98 | mData->revision = QDateTime ( QDate( 2004,1,1)); | 98 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
99 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 99 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
100 | } | 100 | } |
101 | 101 | ||
102 | Addressee::~Addressee() | 102 | Addressee::~Addressee() |
103 | { | 103 | { |
104 | } | 104 | } |
105 | 105 | ||
106 | Addressee::Addressee( const Addressee &a ) | 106 | Addressee::Addressee( const Addressee &a ) |
107 | { | 107 | { |
108 | mData = a.mData; | 108 | mData = a.mData; |
109 | } | 109 | } |
110 | 110 | ||
111 | Addressee &Addressee::operator=( const Addressee &a ) | 111 | Addressee &Addressee::operator=( const Addressee &a ) |
112 | { | 112 | { |
113 | mData = a.mData; | 113 | mData = a.mData; |
114 | return (*this); | 114 | return (*this); |
115 | } | 115 | } |
116 | 116 | ||
117 | Addressee Addressee::copy() | 117 | Addressee Addressee::copy() |
118 | { | 118 | { |
119 | Addressee a; | 119 | Addressee a; |
120 | *(a.mData) = *mData; | 120 | *(a.mData) = *mData; |
121 | return a; | 121 | return a; |
122 | } | 122 | } |
123 | 123 | ||
124 | void Addressee::detach() | 124 | void Addressee::detach() |
125 | { | 125 | { |
126 | if ( mData.count() == 1 ) return; | 126 | if ( mData.count() == 1 ) return; |
127 | *this = copy(); | 127 | *this = copy(); |
128 | } | 128 | } |
129 | 129 | ||
130 | bool Addressee::operator==( const Addressee &a ) const | 130 | bool Addressee::operator==( const Addressee &a ) const |
131 | { | 131 | { |
132 | if ( uid() != a.uid() ) return false; | 132 | if ( uid() != a.uid() ) return false; |
133 | if ( mData->name != a.mData->name ) return false; | 133 | if ( mData->name != a.mData->name ) return false; |
134 | if ( mData->formattedName != a.mData->formattedName ) return false; | 134 | if ( mData->formattedName != a.mData->formattedName ) return false; |
135 | if ( mData->familyName != a.mData->familyName ) return false; | 135 | if ( mData->familyName != a.mData->familyName ) return false; |
136 | if ( mData->givenName != a.mData->givenName ) return false; | 136 | if ( mData->givenName != a.mData->givenName ) return false; |
137 | if ( mData->additionalName != a.mData->additionalName ) return false; | 137 | if ( mData->additionalName != a.mData->additionalName ) return false; |
138 | if ( mData->prefix != a.mData->prefix ) return false; | 138 | if ( mData->prefix != a.mData->prefix ) return false; |
139 | if ( mData->suffix != a.mData->suffix ) return false; | 139 | if ( mData->suffix != a.mData->suffix ) return false; |
140 | if ( mData->nickName != a.mData->nickName ) return false; | 140 | if ( mData->nickName != a.mData->nickName ) return false; |
141 | if ( mData->birthday != a.mData->birthday ) return false; | 141 | if ( mData->birthday != a.mData->birthday ) return false; |
142 | if ( mData->mailer != a.mData->mailer ) return false; | 142 | if ( mData->mailer != a.mData->mailer ) return false; |
143 | if ( mData->timeZone != a.mData->timeZone ) return false; | 143 | if ( mData->timeZone != a.mData->timeZone ) return false; |
144 | if ( mData->geo != a.mData->geo ) return false; | 144 | if ( mData->geo != a.mData->geo ) return false; |
145 | if ( mData->title != a.mData->title ) return false; | 145 | if ( mData->title != a.mData->title ) return false; |
146 | if ( mData->role != a.mData->role ) return false; | 146 | if ( mData->role != a.mData->role ) return false; |
147 | if ( mData->organization != a.mData->organization ) return false; | 147 | if ( mData->organization != a.mData->organization ) return false; |
148 | if ( mData->note != a.mData->note ) return false; | 148 | if ( mData->note != a.mData->note ) return false; |
149 | if ( mData->productId != a.mData->productId ) return false; | 149 | if ( mData->productId != a.mData->productId ) return false; |
150 | //if ( mData->revision != a.mData->revision ) return false; | 150 | //if ( mData->revision != a.mData->revision ) return false; |
151 | if ( mData->sortString != a.mData->sortString ) return false; | 151 | if ( mData->sortString != a.mData->sortString ) return false; |
152 | if ( mData->secrecy != a.mData->secrecy ) return false; | 152 | if ( mData->secrecy != a.mData->secrecy ) return false; |
153 | if ( mData->logo != a.mData->logo ) return false; | 153 | if ( mData->logo != a.mData->logo ) return false; |
154 | if ( mData->photo != a.mData->photo ) return false; | 154 | if ( mData->photo != a.mData->photo ) return false; |
155 | if ( mData->sound != a.mData->sound ) return false; | 155 | if ( mData->sound != a.mData->sound ) return false; |
156 | if ( mData->agent != a.mData->agent ) return false; | 156 | if ( mData->agent != a.mData->agent ) return false; |
157 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 157 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
158 | ( mData->url != a.mData->url ) ) return false; | 158 | ( mData->url != a.mData->url ) ) return false; |
159 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 159 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
160 | if ( mData->addresses != a.mData->addresses ) return false; | 160 | if ( mData->addresses != a.mData->addresses ) return false; |
161 | if ( mData->keys != a.mData->keys ) return false; | 161 | if ( mData->keys != a.mData->keys ) return false; |
162 | if ( mData->emails != a.mData->emails ) return false; | 162 | if ( mData->emails != a.mData->emails ) return false; |
163 | if ( mData->categories != a.mData->categories ) return false; | 163 | if ( mData->categories != a.mData->categories ) return false; |
164 | if ( mData->custom != a.mData->custom ) return false; | 164 | if ( mData->custom != a.mData->custom ) return false; |
165 | 165 | ||
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | bool Addressee::operator!=( const Addressee &a ) const | 169 | bool Addressee::operator!=( const Addressee &a ) const |
170 | { | 170 | { |
171 | return !( a == *this ); | 171 | return !( a == *this ); |
172 | } | 172 | } |
173 | 173 | ||
174 | bool Addressee::isEmpty() const | 174 | bool Addressee::isEmpty() const |
175 | { | 175 | { |
176 | return mData->empty; | 176 | return mData->empty; |
177 | } | 177 | } |
178 | ulong Addressee::getCsum4List( const QStringList & attList) | 178 | ulong Addressee::getCsum4List( const QStringList & attList) |
179 | { | 179 | { |
180 | int max = attList.count(); | 180 | int max = attList.count(); |
181 | ulong cSum = 0; | 181 | ulong cSum = 0; |
182 | int j,k,i; | 182 | int j,k,i; |
183 | int add; | 183 | int add; |
184 | for ( i = 0; i < max ; ++i ) { | 184 | for ( i = 0; i < max ; ++i ) { |
185 | QString s = attList[i]; | 185 | QString s = attList[i]; |
186 | if ( ! s.isEmpty() ){ | 186 | if ( ! s.isEmpty() ){ |
187 | j = s.length(); | 187 | j = s.length(); |
188 | for ( k = 0; k < j; ++k ) { | 188 | for ( k = 0; k < j; ++k ) { |
189 | int mul = k +1; | 189 | int mul = k +1; |
190 | add = s[k].unicode (); | 190 | add = s[k].unicode (); |
191 | if ( k < 16 ) | 191 | if ( k < 16 ) |
192 | mul = mul * mul; | 192 | mul = mul * mul; |
193 | int ii = i+1; | 193 | int ii = i+1; |
194 | add = add * mul *ii*ii*ii; | 194 | add = add * mul *ii*ii*ii; |
195 | cSum += add; | 195 | cSum += add; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | } | 199 | } |
200 | //QString dump = attList.join(","); | 200 | //QString dump = attList.join(","); |
201 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 201 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
202 | 202 | ||
203 | return cSum; | 203 | return cSum; |
204 | 204 | ||
205 | } | 205 | } |
206 | void Addressee::computeCsum(const QString &dev) | 206 | void Addressee::computeCsum(const QString &dev) |
207 | { | 207 | { |
208 | QStringList l; | 208 | QStringList l; |
209 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 209 | if ( !mData->name.isEmpty() ) l.append(mData->name); |
210 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 210 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
211 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 211 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
212 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 212 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
213 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 213 | if ( !mData->additionalName ) l.append( mData->additionalName ); |
214 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 214 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
215 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 215 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
216 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 216 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
217 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 217 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
218 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 218 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
219 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 219 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
220 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 220 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
221 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 221 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
222 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 222 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
223 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 223 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
224 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 224 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
225 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 225 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
226 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 226 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
227 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 227 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
228 | // if ( !mData->logo.isEmpty() ) l.append( ); | 228 | // if ( !mData->logo.isEmpty() ) l.append( ); |
229 | //if ( !mData->photo.isEmpty() ) l.append( ); | 229 | //if ( !mData->photo.isEmpty() ) l.append( ); |
230 | //if ( !mData->sound.isEmpty() ) l.append( ); | 230 | //if ( !mData->sound.isEmpty() ) l.append( ); |
231 | //if ( !mData->agent.isEmpty() ) l.append( ); | 231 | //if ( !mData->agent.isEmpty() ) l.append( ); |
232 | //if ( mData->url.isValid() ) l.append( ); | 232 | //if ( mData->url.isValid() ) l.append( ); |
233 | #if 0 | 233 | #if 0 |
234 | if ( !mData->phoneNumbers.isEmpty() ) l.append( ); | 234 | if ( !mData->phoneNumbers.isEmpty() ) l.append( ); |
235 | if ( !mData->addresses.isEmpty() ) l.append( ); | 235 | if ( !mData->addresses.isEmpty() ) l.append( ); |
236 | //if ( !mData->keys.isEmpty() ) l.append( ); | 236 | //if ( !mData->keys.isEmpty() ) l.append( ); |
237 | if ( !mData->emails.isEmpty() ) l.append( ); | 237 | if ( !mData->emails.isEmpty() ) l.append( ); |
238 | if ( !mData->categories .isEmpty() ) l.append( ); | 238 | if ( !mData->categories .isEmpty() ) l.append( ); |
239 | if ( !mData->custom.isEmpty() ) l.append( ); | 239 | if ( !mData->custom.isEmpty() ) l.append( ); |
240 | #endif | 240 | #endif |
241 | KABC::PhoneNumber::List phoneNumbers; | 241 | KABC::PhoneNumber::List phoneNumbers; |
242 | KABC::PhoneNumber::List::Iterator phoneIter; | 242 | KABC::PhoneNumber::List::Iterator phoneIter; |
243 | 243 | ||
244 | QStringList t; | 244 | QStringList t; |
245 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 245 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
246 | ++phoneIter ) | 246 | ++phoneIter ) |
247 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 247 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
248 | t.sort(); | 248 | t.sort(); |
249 | uint iii; | 249 | uint iii; |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->emails; | 252 | t = mData->emails; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->categories; | 256 | t = mData->categories; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | l.append( t[iii] ); | 259 | l.append( t[iii] ); |
260 | t = mData->custom; | 260 | t = mData->custom; |
261 | t.sort(); | 261 | t.sort(); |
262 | for ( iii = 0; iii < t.count(); ++iii) | 262 | for ( iii = 0; iii < t.count(); ++iii) |
263 | l.append( t[iii] ); | 263 | l.append( t[iii] ); |
264 | KABC::Address::List::Iterator addressIter; | 264 | KABC::Address::List::Iterator addressIter; |
265 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 265 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
266 | ++addressIter ) { | 266 | ++addressIter ) { |
267 | t = (*addressIter).asList(); | 267 | t = (*addressIter).asList(); |
268 | t.sort(); | 268 | t.sort(); |
269 | for ( iii = 0; iii < t.count(); ++iii) | 269 | for ( iii = 0; iii < t.count(); ++iii) |
270 | l.append( t[iii] ); | 270 | l.append( t[iii] ); |
271 | } | 271 | } |
272 | uint cs = getCsum4List(l); | 272 | uint cs = getCsum4List(l); |
273 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 273 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
274 | setCsum( dev, QString::number (cs )); | 274 | setCsum( dev, QString::number (cs )); |
275 | } | 275 | } |
276 | 276 | ||
277 | void Addressee::mergeContact( const Addressee& ad ) | 277 | void Addressee::mergeContact( const Addressee& ad ) |
278 | { | 278 | { |
279 | 279 | ||
280 | detach(); | 280 | detach(); |
281 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 281 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
282 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 282 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
283 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 283 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
284 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 284 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
285 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 285 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
286 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 286 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
287 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 287 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
288 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 288 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
289 | if ( !mData->birthday.isValid() ) | 289 | if ( !mData->birthday.isValid() ) |
290 | if ( ad.mData->birthday.isValid()) | 290 | if ( ad.mData->birthday.isValid()) |
291 | mData->birthday = ad.mData->birthday; | 291 | mData->birthday = ad.mData->birthday; |
292 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 292 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
293 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 293 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
294 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 294 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
295 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 295 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
296 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 296 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
297 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 297 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
298 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 298 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
299 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 299 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
300 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 300 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
301 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 301 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
302 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 302 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
303 | 303 | ||
304 | // pending: | 304 | // pending: |
305 | // merging phonenumbers | 305 | // merging phonenumbers |
306 | // merging addresses | 306 | // merging addresses |
307 | // merging emails; | 307 | // merging emails; |
308 | // merging categories; | 308 | // merging categories; |
309 | // merging custom; | 309 | // merging custom; |
310 | // merging keys | 310 | // merging keys |
311 | qDebug("merge contact %s ", ad.uid().latin1()); | ||
312 | setUid( ad.uid() ); | ||
311 | } | 313 | } |
312 | 314 | ||
313 | void Addressee::removeID(const QString &prof) | 315 | void Addressee::removeID(const QString &prof) |
314 | { | 316 | { |
315 | detach(); | 317 | detach(); |
316 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 318 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
317 | 319 | ||
318 | } | 320 | } |
319 | void Addressee::setID( const QString & prof , const QString & id ) | 321 | void Addressee::setID( const QString & prof , const QString & id ) |
320 | { | 322 | { |
321 | detach(); | 323 | detach(); |
322 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 324 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
323 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 325 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
324 | } | 326 | } |
325 | void Addressee::setTempSyncStat( int id ) | 327 | void Addressee::setTempSyncStat( int id ) |
326 | { | 328 | { |
327 | if ( mData->mTempSyncStat == id ) return; | 329 | if ( mData->mTempSyncStat == id ) return; |
328 | detach(); | 330 | detach(); |
329 | mData->mTempSyncStat = id; | 331 | mData->mTempSyncStat = id; |
330 | } | 332 | } |
331 | int Addressee::tempSyncStat() const | 333 | int Addressee::tempSyncStat() const |
332 | { | 334 | { |
333 | return mData->mTempSyncStat; | 335 | return mData->mTempSyncStat; |
334 | } | 336 | } |
335 | 337 | ||
336 | QString Addressee::getID( const QString & prof) | 338 | QString Addressee::getID( const QString & prof) |
337 | { | 339 | { |
338 | return KIdManager::getId ( mData->mExternalId, prof ); | 340 | return KIdManager::getId ( mData->mExternalId, prof ); |
339 | } | 341 | } |
340 | 342 | ||
341 | void Addressee::setCsum( const QString & prof , const QString & id ) | 343 | void Addressee::setCsum( const QString & prof , const QString & id ) |
342 | { | 344 | { |
343 | detach(); | 345 | detach(); |
344 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 346 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
345 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 347 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
346 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 348 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
347 | } | 349 | } |
348 | 350 | ||
349 | QString Addressee::getCsum( const QString & prof) | 351 | QString Addressee::getCsum( const QString & prof) |
350 | { | 352 | { |
351 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 353 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
352 | } | 354 | } |
353 | 355 | ||
354 | void Addressee::setIDStr( const QString & s ) | 356 | void Addressee::setIDStr( const QString & s ) |
355 | { | 357 | { |
356 | detach(); | 358 | detach(); |
357 | mData->mExternalId = s; | 359 | mData->mExternalId = s; |
358 | } | 360 | } |
359 | 361 | ||
360 | QString Addressee::IDStr() const | 362 | QString Addressee::IDStr() const |
361 | { | 363 | { |
362 | return mData->mExternalId; | 364 | return mData->mExternalId; |
363 | } | 365 | } |
364 | 366 | ||
365 | void Addressee::setExternalUID( const QString &id ) | 367 | void Addressee::setExternalUID( const QString &id ) |
366 | { | 368 | { |
367 | if ( id == mData->externalUID ) return; | 369 | if ( id == mData->externalUID ) return; |
368 | detach(); | 370 | detach(); |
369 | mData->empty = false; | 371 | mData->empty = false; |
370 | mData->externalUID = id; | 372 | mData->externalUID = id; |
371 | } | 373 | } |
372 | 374 | ||
373 | QString Addressee::externalUID() const | 375 | QString Addressee::externalUID() const |
374 | { | 376 | { |
375 | return mData->externalUID; | 377 | return mData->externalUID; |
376 | } | 378 | } |
377 | void Addressee::setOriginalExternalUID( const QString &id ) | 379 | void Addressee::setOriginalExternalUID( const QString &id ) |
378 | { | 380 | { |
379 | if ( id == mData->originalExternalUID ) return; | 381 | if ( id == mData->originalExternalUID ) return; |
380 | detach(); | 382 | detach(); |
381 | mData->empty = false; | 383 | mData->empty = false; |
384 | qDebug("*******Set orig uid %s ", id.latin1()); | ||
382 | mData->originalExternalUID = id; | 385 | mData->originalExternalUID = id; |
383 | } | 386 | } |
384 | 387 | ||
385 | QString Addressee::originalExternalUID() const | 388 | QString Addressee::originalExternalUID() const |
386 | { | 389 | { |
387 | return mData->originalExternalUID; | 390 | return mData->originalExternalUID; |
388 | } | 391 | } |
389 | 392 | ||
390 | void Addressee::setUid( const QString &id ) | 393 | void Addressee::setUid( const QString &id ) |
391 | { | 394 | { |
392 | if ( id == mData->uid ) return; | 395 | if ( id == mData->uid ) return; |
393 | detach(); | 396 | detach(); |
397 | qDebug("****setuid %s ", id.latin1()); | ||
394 | mData->empty = false; | 398 | mData->empty = false; |
395 | mData->uid = id; | 399 | mData->uid = id; |
396 | } | 400 | } |
397 | 401 | ||
398 | QString Addressee::uid() const | 402 | QString Addressee::uid() const |
399 | { | 403 | { |
400 | if ( mData->uid.isEmpty() ) | 404 | if ( mData->uid.isEmpty() ) |
401 | mData->uid = KApplication::randomString( 10 ); | 405 | mData->uid = KApplication::randomString( 10 ); |
402 | 406 | ||
403 | return mData->uid; | 407 | return mData->uid; |
404 | } | 408 | } |
405 | 409 | ||
406 | QString Addressee::uidLabel() | 410 | QString Addressee::uidLabel() |
407 | { | 411 | { |
408 | return i18n("Unique Identifier"); | 412 | return i18n("Unique Identifier"); |
409 | } | 413 | } |
410 | 414 | ||
411 | void Addressee::setName( const QString &name ) | 415 | void Addressee::setName( const QString &name ) |
412 | { | 416 | { |
413 | if ( name == mData->name ) return; | 417 | if ( name == mData->name ) return; |
414 | detach(); | 418 | detach(); |
415 | mData->empty = false; | 419 | mData->empty = false; |
416 | mData->name = name; | 420 | mData->name = name; |
417 | } | 421 | } |
418 | 422 | ||
419 | QString Addressee::name() const | 423 | QString Addressee::name() const |
420 | { | 424 | { |
421 | return mData->name; | 425 | return mData->name; |
422 | } | 426 | } |
423 | 427 | ||
424 | QString Addressee::nameLabel() | 428 | QString Addressee::nameLabel() |
425 | { | 429 | { |
426 | return i18n("Name"); | 430 | return i18n("Name"); |
427 | } | 431 | } |
428 | 432 | ||
429 | 433 | ||
430 | void Addressee::setFormattedName( const QString &formattedName ) | 434 | void Addressee::setFormattedName( const QString &formattedName ) |
431 | { | 435 | { |
432 | if ( formattedName == mData->formattedName ) return; | 436 | if ( formattedName == mData->formattedName ) return; |
433 | detach(); | 437 | detach(); |
434 | mData->empty = false; | 438 | mData->empty = false; |
435 | mData->formattedName = formattedName; | 439 | mData->formattedName = formattedName; |
436 | } | 440 | } |
437 | 441 | ||
438 | QString Addressee::formattedName() const | 442 | QString Addressee::formattedName() const |
439 | { | 443 | { |
440 | return mData->formattedName; | 444 | return mData->formattedName; |
441 | } | 445 | } |
442 | 446 | ||
443 | QString Addressee::formattedNameLabel() | 447 | QString Addressee::formattedNameLabel() |
444 | { | 448 | { |
445 | return i18n("Formatted Name"); | 449 | return i18n("Formatted Name"); |
446 | } | 450 | } |
447 | 451 | ||
448 | 452 | ||
449 | void Addressee::setFamilyName( const QString &familyName ) | 453 | void Addressee::setFamilyName( const QString &familyName ) |
450 | { | 454 | { |
451 | if ( familyName == mData->familyName ) return; | 455 | if ( familyName == mData->familyName ) return; |
452 | detach(); | 456 | detach(); |
453 | mData->empty = false; | 457 | mData->empty = false; |
454 | mData->familyName = familyName; | 458 | mData->familyName = familyName; |
455 | } | 459 | } |
456 | 460 | ||
457 | QString Addressee::familyName() const | 461 | QString Addressee::familyName() const |
458 | { | 462 | { |
459 | return mData->familyName; | 463 | return mData->familyName; |
460 | } | 464 | } |
461 | 465 | ||
462 | QString Addressee::familyNameLabel() | 466 | QString Addressee::familyNameLabel() |
463 | { | 467 | { |
464 | return i18n("Family Name"); | 468 | return i18n("Family Name"); |
465 | } | 469 | } |
466 | 470 | ||
467 | 471 | ||
468 | void Addressee::setGivenName( const QString &givenName ) | 472 | void Addressee::setGivenName( const QString &givenName ) |
469 | { | 473 | { |
470 | if ( givenName == mData->givenName ) return; | 474 | if ( givenName == mData->givenName ) return; |
471 | detach(); | 475 | detach(); |
472 | mData->empty = false; | 476 | mData->empty = false; |
473 | mData->givenName = givenName; | 477 | mData->givenName = givenName; |
474 | } | 478 | } |
475 | 479 | ||
476 | QString Addressee::givenName() const | 480 | QString Addressee::givenName() const |
477 | { | 481 | { |
478 | return mData->givenName; | 482 | return mData->givenName; |
479 | } | 483 | } |
480 | 484 | ||
481 | QString Addressee::givenNameLabel() | 485 | QString Addressee::givenNameLabel() |
482 | { | 486 | { |
483 | return i18n("Given Name"); | 487 | return i18n("Given Name"); |
484 | } | 488 | } |
485 | 489 | ||
486 | 490 | ||
487 | void Addressee::setAdditionalName( const QString &additionalName ) | 491 | void Addressee::setAdditionalName( const QString &additionalName ) |
488 | { | 492 | { |
489 | if ( additionalName == mData->additionalName ) return; | 493 | if ( additionalName == mData->additionalName ) return; |
490 | detach(); | 494 | detach(); |
491 | mData->empty = false; | 495 | mData->empty = false; |
492 | mData->additionalName = additionalName; | 496 | mData->additionalName = additionalName; |
493 | } | 497 | } |
494 | 498 | ||
495 | QString Addressee::additionalName() const | 499 | QString Addressee::additionalName() const |
496 | { | 500 | { |
497 | return mData->additionalName; | 501 | return mData->additionalName; |
498 | } | 502 | } |
499 | 503 | ||
500 | QString Addressee::additionalNameLabel() | 504 | QString Addressee::additionalNameLabel() |
501 | { | 505 | { |
502 | return i18n("Additional Names"); | 506 | return i18n("Additional Names"); |
503 | } | 507 | } |
504 | 508 | ||
505 | 509 | ||
506 | void Addressee::setPrefix( const QString &prefix ) | 510 | void Addressee::setPrefix( const QString &prefix ) |
507 | { | 511 | { |
508 | if ( prefix == mData->prefix ) return; | 512 | if ( prefix == mData->prefix ) return; |
509 | detach(); | 513 | detach(); |
510 | mData->empty = false; | 514 | mData->empty = false; |
511 | mData->prefix = prefix; | 515 | mData->prefix = prefix; |
512 | } | 516 | } |
513 | 517 | ||
514 | QString Addressee::prefix() const | 518 | QString Addressee::prefix() const |
515 | { | 519 | { |
516 | return mData->prefix; | 520 | return mData->prefix; |
517 | } | 521 | } |
518 | 522 | ||
519 | QString Addressee::prefixLabel() | 523 | QString Addressee::prefixLabel() |
520 | { | 524 | { |
521 | return i18n("Honorific Prefixes"); | 525 | return i18n("Honorific Prefixes"); |
522 | } | 526 | } |
523 | 527 | ||
524 | 528 | ||
525 | void Addressee::setSuffix( const QString &suffix ) | 529 | void Addressee::setSuffix( const QString &suffix ) |
526 | { | 530 | { |
527 | if ( suffix == mData->suffix ) return; | 531 | if ( suffix == mData->suffix ) return; |
528 | detach(); | 532 | detach(); |
529 | mData->empty = false; | 533 | mData->empty = false; |
530 | mData->suffix = suffix; | 534 | mData->suffix = suffix; |
531 | } | 535 | } |
532 | 536 | ||
533 | QString Addressee::suffix() const | 537 | QString Addressee::suffix() const |
534 | { | 538 | { |
535 | return mData->suffix; | 539 | return mData->suffix; |
536 | } | 540 | } |
537 | 541 | ||
538 | QString Addressee::suffixLabel() | 542 | QString Addressee::suffixLabel() |
539 | { | 543 | { |
540 | return i18n("Honorific Suffixes"); | 544 | return i18n("Honorific Suffixes"); |
541 | } | 545 | } |
542 | 546 | ||
543 | 547 | ||
544 | void Addressee::setNickName( const QString &nickName ) | 548 | void Addressee::setNickName( const QString &nickName ) |
545 | { | 549 | { |
546 | if ( nickName == mData->nickName ) return; | 550 | if ( nickName == mData->nickName ) return; |
547 | detach(); | 551 | detach(); |
548 | mData->empty = false; | 552 | mData->empty = false; |
549 | mData->nickName = nickName; | 553 | mData->nickName = nickName; |
550 | } | 554 | } |
551 | 555 | ||
552 | QString Addressee::nickName() const | 556 | QString Addressee::nickName() const |
553 | { | 557 | { |
554 | return mData->nickName; | 558 | return mData->nickName; |
555 | } | 559 | } |
556 | 560 | ||
557 | QString Addressee::nickNameLabel() | 561 | QString Addressee::nickNameLabel() |
558 | { | 562 | { |
559 | return i18n("Nick Name"); | 563 | return i18n("Nick Name"); |
560 | } | 564 | } |
561 | 565 | ||
562 | 566 | ||
563 | void Addressee::setBirthday( const QDateTime &birthday ) | 567 | void Addressee::setBirthday( const QDateTime &birthday ) |
564 | { | 568 | { |
565 | if ( birthday == mData->birthday ) return; | 569 | if ( birthday == mData->birthday ) return; |
566 | detach(); | 570 | detach(); |
567 | mData->empty = false; | 571 | mData->empty = false; |
568 | mData->birthday = birthday; | 572 | mData->birthday = birthday; |
569 | } | 573 | } |
570 | 574 | ||
571 | QDateTime Addressee::birthday() const | 575 | QDateTime Addressee::birthday() const |
572 | { | 576 | { |
573 | return mData->birthday; | 577 | return mData->birthday; |
574 | } | 578 | } |
575 | 579 | ||
576 | QString Addressee::birthdayLabel() | 580 | QString Addressee::birthdayLabel() |
577 | { | 581 | { |
578 | return i18n("Birthday"); | 582 | return i18n("Birthday"); |
579 | } | 583 | } |
580 | 584 | ||
581 | 585 | ||
582 | QString Addressee::homeAddressStreetLabel() | 586 | QString Addressee::homeAddressStreetLabel() |
583 | { | 587 | { |
584 | return i18n("Home Address Street"); | 588 | return i18n("Home Address Street"); |
585 | } | 589 | } |
586 | 590 | ||
587 | 591 | ||
588 | QString Addressee::homeAddressLocalityLabel() | 592 | QString Addressee::homeAddressLocalityLabel() |
589 | { | 593 | { |
590 | return i18n("Home Address Locality"); | 594 | return i18n("Home Address Locality"); |
591 | } | 595 | } |
592 | 596 | ||
593 | 597 | ||
594 | QString Addressee::homeAddressRegionLabel() | 598 | QString Addressee::homeAddressRegionLabel() |
595 | { | 599 | { |
596 | return i18n("Home Address Region"); | 600 | return i18n("Home Address Region"); |
597 | } | 601 | } |
598 | 602 | ||
599 | 603 | ||
600 | QString Addressee::homeAddressPostalCodeLabel() | 604 | QString Addressee::homeAddressPostalCodeLabel() |
601 | { | 605 | { |
602 | return i18n("Home Address Postal Code"); | 606 | return i18n("Home Address Postal Code"); |
603 | } | 607 | } |
604 | 608 | ||
605 | 609 | ||
606 | QString Addressee::homeAddressCountryLabel() | 610 | QString Addressee::homeAddressCountryLabel() |
607 | { | 611 | { |
608 | return i18n("Home Address Country"); | 612 | return i18n("Home Address Country"); |
609 | } | 613 | } |
610 | 614 | ||
611 | 615 | ||
612 | QString Addressee::homeAddressLabelLabel() | 616 | QString Addressee::homeAddressLabelLabel() |
613 | { | 617 | { |
614 | return i18n("Home Address Label"); | 618 | return i18n("Home Address Label"); |
615 | } | 619 | } |
616 | 620 | ||
617 | 621 | ||
618 | QString Addressee::businessAddressStreetLabel() | 622 | QString Addressee::businessAddressStreetLabel() |
619 | { | 623 | { |
620 | return i18n("Business Address Street"); | 624 | return i18n("Business Address Street"); |
621 | } | 625 | } |
622 | 626 | ||
623 | 627 | ||
624 | QString Addressee::businessAddressLocalityLabel() | 628 | QString Addressee::businessAddressLocalityLabel() |
625 | { | 629 | { |
626 | return i18n("Business Address Locality"); | 630 | return i18n("Business Address Locality"); |
627 | } | 631 | } |
628 | 632 | ||
629 | 633 | ||
630 | QString Addressee::businessAddressRegionLabel() | 634 | QString Addressee::businessAddressRegionLabel() |
631 | { | 635 | { |
632 | return i18n("Business Address Region"); | 636 | return i18n("Business Address Region"); |
633 | } | 637 | } |
634 | 638 | ||
635 | 639 | ||
636 | QString Addressee::businessAddressPostalCodeLabel() | 640 | QString Addressee::businessAddressPostalCodeLabel() |
637 | { | 641 | { |
638 | return i18n("Business Address Postal Code"); | 642 | return i18n("Business Address Postal Code"); |
639 | } | 643 | } |
640 | 644 | ||
641 | 645 | ||
642 | QString Addressee::businessAddressCountryLabel() | 646 | QString Addressee::businessAddressCountryLabel() |
643 | { | 647 | { |
644 | return i18n("Business Address Country"); | 648 | return i18n("Business Address Country"); |
645 | } | 649 | } |
646 | 650 | ||
647 | 651 | ||
648 | QString Addressee::businessAddressLabelLabel() | 652 | QString Addressee::businessAddressLabelLabel() |
649 | { | 653 | { |
650 | return i18n("Business Address Label"); | 654 | return i18n("Business Address Label"); |
651 | } | 655 | } |
652 | 656 | ||
653 | 657 | ||
654 | QString Addressee::homePhoneLabel() | 658 | QString Addressee::homePhoneLabel() |
655 | { | 659 | { |
656 | return i18n("Home Phone"); | 660 | return i18n("Home Phone"); |
657 | } | 661 | } |
658 | 662 | ||
659 | 663 | ||
660 | QString Addressee::businessPhoneLabel() | 664 | QString Addressee::businessPhoneLabel() |
661 | { | 665 | { |
662 | return i18n("Business Phone"); | 666 | return i18n("Business Phone"); |
663 | } | 667 | } |
664 | 668 | ||
665 | 669 | ||
666 | QString Addressee::mobilePhoneLabel() | 670 | QString Addressee::mobilePhoneLabel() |
667 | { | 671 | { |
668 | return i18n("Mobile Phone"); | 672 | return i18n("Mobile Phone"); |
669 | } | 673 | } |
670 | 674 | ||
671 | 675 | ||
672 | QString Addressee::homeFaxLabel() | 676 | QString Addressee::homeFaxLabel() |
673 | { | 677 | { |
674 | return i18n("Home Fax"); | 678 | return i18n("Home Fax"); |
675 | } | 679 | } |
676 | 680 | ||
677 | 681 | ||
678 | QString Addressee::businessFaxLabel() | 682 | QString Addressee::businessFaxLabel() |
679 | { | 683 | { |
680 | return i18n("Business Fax"); | 684 | return i18n("Business Fax"); |
681 | } | 685 | } |
682 | 686 | ||
683 | 687 | ||
684 | QString Addressee::carPhoneLabel() | 688 | QString Addressee::carPhoneLabel() |
685 | { | 689 | { |
686 | return i18n("Car Phone"); | 690 | return i18n("Car Phone"); |
687 | } | 691 | } |
688 | 692 | ||
689 | 693 | ||
690 | QString Addressee::isdnLabel() | 694 | QString Addressee::isdnLabel() |
691 | { | 695 | { |
692 | return i18n("ISDN"); | 696 | return i18n("ISDN"); |
693 | } | 697 | } |
694 | 698 | ||
695 | 699 | ||
696 | QString Addressee::pagerLabel() | 700 | QString Addressee::pagerLabel() |
697 | { | 701 | { |
698 | return i18n("Pager"); | 702 | return i18n("Pager"); |
699 | } | 703 | } |
700 | 704 | ||
701 | QString Addressee::sipLabel() | 705 | QString Addressee::sipLabel() |
702 | { | 706 | { |
703 | return i18n("SIP"); | 707 | return i18n("SIP"); |
704 | } | 708 | } |
705 | 709 | ||
706 | QString Addressee::emailLabel() | 710 | QString Addressee::emailLabel() |
707 | { | 711 | { |
708 | return i18n("Email Address"); | 712 | return i18n("Email Address"); |
709 | } | 713 | } |
710 | 714 | ||
711 | 715 | ||
712 | void Addressee::setMailer( const QString &mailer ) | 716 | void Addressee::setMailer( const QString &mailer ) |
713 | { | 717 | { |
714 | if ( mailer == mData->mailer ) return; | 718 | if ( mailer == mData->mailer ) return; |
715 | detach(); | 719 | detach(); |
716 | mData->empty = false; | 720 | mData->empty = false; |
717 | mData->mailer = mailer; | 721 | mData->mailer = mailer; |
718 | } | 722 | } |
719 | 723 | ||
720 | QString Addressee::mailer() const | 724 | QString Addressee::mailer() const |
721 | { | 725 | { |
722 | return mData->mailer; | 726 | return mData->mailer; |
723 | } | 727 | } |
724 | 728 | ||
725 | QString Addressee::mailerLabel() | 729 | QString Addressee::mailerLabel() |
726 | { | 730 | { |
727 | return i18n("Mail Client"); | 731 | return i18n("Mail Client"); |
728 | } | 732 | } |
729 | 733 | ||
730 | 734 | ||
731 | void Addressee::setTimeZone( const TimeZone &timeZone ) | 735 | void Addressee::setTimeZone( const TimeZone &timeZone ) |
732 | { | 736 | { |
733 | if ( timeZone == mData->timeZone ) return; | 737 | if ( timeZone == mData->timeZone ) return; |
734 | detach(); | 738 | detach(); |
735 | mData->empty = false; | 739 | mData->empty = false; |
736 | mData->timeZone = timeZone; | 740 | mData->timeZone = timeZone; |
737 | } | 741 | } |
738 | 742 | ||
739 | TimeZone Addressee::timeZone() const | 743 | TimeZone Addressee::timeZone() const |
740 | { | 744 | { |
741 | return mData->timeZone; | 745 | return mData->timeZone; |
742 | } | 746 | } |
743 | 747 | ||
744 | QString Addressee::timeZoneLabel() | 748 | QString Addressee::timeZoneLabel() |
745 | { | 749 | { |
746 | return i18n("Time Zone"); | 750 | return i18n("Time Zone"); |
747 | } | 751 | } |
748 | 752 | ||
749 | 753 | ||
750 | void Addressee::setGeo( const Geo &geo ) | 754 | void Addressee::setGeo( const Geo &geo ) |
751 | { | 755 | { |
752 | if ( geo == mData->geo ) return; | 756 | if ( geo == mData->geo ) return; |
753 | detach(); | 757 | detach(); |
754 | mData->empty = false; | 758 | mData->empty = false; |
755 | mData->geo = geo; | 759 | mData->geo = geo; |
756 | } | 760 | } |
757 | 761 | ||
758 | Geo Addressee::geo() const | 762 | Geo Addressee::geo() const |
759 | { | 763 | { |
760 | return mData->geo; | 764 | return mData->geo; |
761 | } | 765 | } |
762 | 766 | ||
763 | QString Addressee::geoLabel() | 767 | QString Addressee::geoLabel() |
764 | { | 768 | { |
765 | return i18n("Geographic Position"); | 769 | return i18n("Geographic Position"); |
766 | } | 770 | } |
767 | 771 | ||
768 | 772 | ||
769 | void Addressee::setTitle( const QString &title ) | 773 | void Addressee::setTitle( const QString &title ) |
770 | { | 774 | { |
771 | if ( title == mData->title ) return; | 775 | if ( title == mData->title ) return; |
772 | detach(); | 776 | detach(); |
773 | mData->empty = false; | 777 | mData->empty = false; |
774 | mData->title = title; | 778 | mData->title = title; |
775 | } | 779 | } |
776 | 780 | ||
777 | QString Addressee::title() const | 781 | QString Addressee::title() const |
778 | { | 782 | { |
779 | return mData->title; | 783 | return mData->title; |
780 | } | 784 | } |
781 | 785 | ||
782 | QString Addressee::titleLabel() | 786 | QString Addressee::titleLabel() |
783 | { | 787 | { |
784 | return i18n("Title"); | 788 | return i18n("Title"); |
785 | } | 789 | } |
786 | 790 | ||
787 | 791 | ||
788 | void Addressee::setRole( const QString &role ) | 792 | void Addressee::setRole( const QString &role ) |
789 | { | 793 | { |
790 | if ( role == mData->role ) return; | 794 | if ( role == mData->role ) return; |
791 | detach(); | 795 | detach(); |
792 | mData->empty = false; | 796 | mData->empty = false; |
793 | mData->role = role; | 797 | mData->role = role; |
794 | } | 798 | } |
795 | 799 | ||
796 | QString Addressee::role() const | 800 | QString Addressee::role() const |
797 | { | 801 | { |
798 | return mData->role; | 802 | return mData->role; |
799 | } | 803 | } |
800 | 804 | ||
801 | QString Addressee::roleLabel() | 805 | QString Addressee::roleLabel() |
802 | { | 806 | { |
803 | return i18n("Role"); | 807 | return i18n("Role"); |
804 | } | 808 | } |
805 | 809 | ||
806 | 810 | ||
807 | void Addressee::setOrganization( const QString &organization ) | 811 | void Addressee::setOrganization( const QString &organization ) |
808 | { | 812 | { |
809 | if ( organization == mData->organization ) return; | 813 | if ( organization == mData->organization ) return; |
810 | detach(); | 814 | detach(); |
811 | mData->empty = false; | 815 | mData->empty = false; |
812 | mData->organization = organization; | 816 | mData->organization = organization; |
813 | } | 817 | } |
814 | 818 | ||
815 | QString Addressee::organization() const | 819 | QString Addressee::organization() const |
816 | { | 820 | { |
817 | return mData->organization; | 821 | return mData->organization; |
818 | } | 822 | } |
819 | 823 | ||
820 | QString Addressee::organizationLabel() | 824 | QString Addressee::organizationLabel() |
821 | { | 825 | { |
822 | return i18n("Organization"); | 826 | return i18n("Organization"); |
823 | } | 827 | } |
824 | 828 | ||
825 | 829 | ||
826 | void Addressee::setNote( const QString ¬e ) | 830 | void Addressee::setNote( const QString ¬e ) |
827 | { | 831 | { |
828 | if ( note == mData->note ) return; | 832 | if ( note == mData->note ) return; |
829 | detach(); | 833 | detach(); |
830 | mData->empty = false; | 834 | mData->empty = false; |
831 | mData->note = note; | 835 | mData->note = note; |
832 | } | 836 | } |
833 | 837 | ||
834 | QString Addressee::note() const | 838 | QString Addressee::note() const |
835 | { | 839 | { |
836 | return mData->note; | 840 | return mData->note; |
837 | } | 841 | } |
838 | 842 | ||
839 | QString Addressee::noteLabel() | 843 | QString Addressee::noteLabel() |
840 | { | 844 | { |
841 | return i18n("Note"); | 845 | return i18n("Note"); |
842 | } | 846 | } |
843 | 847 | ||
844 | 848 | ||
845 | void Addressee::setProductId( const QString &productId ) | 849 | void Addressee::setProductId( const QString &productId ) |
846 | { | 850 | { |
847 | if ( productId == mData->productId ) return; | 851 | if ( productId == mData->productId ) return; |
848 | detach(); | 852 | detach(); |
849 | mData->empty = false; | 853 | mData->empty = false; |
850 | mData->productId = productId; | 854 | mData->productId = productId; |
851 | } | 855 | } |
852 | 856 | ||
853 | QString Addressee::productId() const | 857 | QString Addressee::productId() const |
854 | { | 858 | { |
855 | return mData->productId; | 859 | return mData->productId; |
856 | } | 860 | } |
857 | 861 | ||
858 | QString Addressee::productIdLabel() | 862 | QString Addressee::productIdLabel() |
859 | { | 863 | { |
860 | return i18n("Product Identifier"); | 864 | return i18n("Product Identifier"); |
861 | } | 865 | } |
862 | 866 | ||
863 | 867 | ||
864 | void Addressee::setRevision( const QDateTime &revision ) | 868 | void Addressee::setRevision( const QDateTime &revision ) |
865 | { | 869 | { |
866 | if ( revision == mData->revision ) return; | 870 | if ( revision == mData->revision ) return; |
867 | detach(); | 871 | detach(); |
868 | mData->empty = false; | 872 | mData->empty = false; |
869 | mData->revision = revision; | 873 | mData->revision = revision; |
870 | } | 874 | } |
871 | 875 | ||
872 | QDateTime Addressee::revision() const | 876 | QDateTime Addressee::revision() const |
873 | { | 877 | { |
874 | return mData->revision; | 878 | return mData->revision; |
875 | } | 879 | } |
876 | 880 | ||
877 | QString Addressee::revisionLabel() | 881 | QString Addressee::revisionLabel() |
878 | { | 882 | { |
879 | return i18n("Revision Date"); | 883 | return i18n("Revision Date"); |
880 | } | 884 | } |
881 | 885 | ||
882 | 886 | ||
883 | void Addressee::setSortString( const QString &sortString ) | 887 | void Addressee::setSortString( const QString &sortString ) |
884 | { | 888 | { |
885 | if ( sortString == mData->sortString ) return; | 889 | if ( sortString == mData->sortString ) return; |
886 | detach(); | 890 | detach(); |
887 | mData->empty = false; | 891 | mData->empty = false; |
888 | mData->sortString = sortString; | 892 | mData->sortString = sortString; |
889 | } | 893 | } |
890 | 894 | ||
891 | QString Addressee::sortString() const | 895 | QString Addressee::sortString() const |
892 | { | 896 | { |
893 | return mData->sortString; | 897 | return mData->sortString; |
894 | } | 898 | } |
895 | 899 | ||
896 | QString Addressee::sortStringLabel() | 900 | QString Addressee::sortStringLabel() |
897 | { | 901 | { |
898 | return i18n("Sort String"); | 902 | return i18n("Sort String"); |
899 | } | 903 | } |
900 | 904 | ||
901 | 905 | ||
902 | void Addressee::setUrl( const KURL &url ) | 906 | void Addressee::setUrl( const KURL &url ) |
903 | { | 907 | { |
904 | if ( url == mData->url ) return; | 908 | if ( url == mData->url ) return; |
905 | detach(); | 909 | detach(); |
906 | mData->empty = false; | 910 | mData->empty = false; |
907 | mData->url = url; | 911 | mData->url = url; |
908 | } | 912 | } |
909 | 913 | ||
910 | KURL Addressee::url() const | 914 | KURL Addressee::url() const |
911 | { | 915 | { |
912 | return mData->url; | 916 | return mData->url; |
913 | } | 917 | } |
914 | 918 | ||
915 | QString Addressee::urlLabel() | 919 | QString Addressee::urlLabel() |
916 | { | 920 | { |
917 | return i18n("URL"); | 921 | return i18n("URL"); |
918 | } | 922 | } |
919 | 923 | ||
920 | 924 | ||
921 | void Addressee::setSecrecy( const Secrecy &secrecy ) | 925 | void Addressee::setSecrecy( const Secrecy &secrecy ) |
922 | { | 926 | { |
923 | if ( secrecy == mData->secrecy ) return; | 927 | if ( secrecy == mData->secrecy ) return; |
924 | detach(); | 928 | detach(); |
925 | mData->empty = false; | 929 | mData->empty = false; |
926 | mData->secrecy = secrecy; | 930 | mData->secrecy = secrecy; |
927 | } | 931 | } |
928 | 932 | ||
929 | Secrecy Addressee::secrecy() const | 933 | Secrecy Addressee::secrecy() const |
930 | { | 934 | { |
931 | return mData->secrecy; | 935 | return mData->secrecy; |
932 | } | 936 | } |
933 | 937 | ||
934 | QString Addressee::secrecyLabel() | 938 | QString Addressee::secrecyLabel() |
935 | { | 939 | { |
936 | return i18n("Security Class"); | 940 | return i18n("Security Class"); |
937 | } | 941 | } |
938 | 942 | ||
939 | 943 | ||
940 | void Addressee::setLogo( const Picture &logo ) | 944 | void Addressee::setLogo( const Picture &logo ) |
941 | { | 945 | { |
942 | if ( logo == mData->logo ) return; | 946 | if ( logo == mData->logo ) return; |
943 | detach(); | 947 | detach(); |
944 | mData->empty = false; | 948 | mData->empty = false; |
945 | mData->logo = logo; | 949 | mData->logo = logo; |
946 | } | 950 | } |
947 | 951 | ||
948 | Picture Addressee::logo() const | 952 | Picture Addressee::logo() const |
949 | { | 953 | { |
950 | return mData->logo; | 954 | return mData->logo; |
951 | } | 955 | } |
952 | 956 | ||
953 | QString Addressee::logoLabel() | 957 | QString Addressee::logoLabel() |
954 | { | 958 | { |
955 | return i18n("Logo"); | 959 | return i18n("Logo"); |
956 | } | 960 | } |
957 | 961 | ||
958 | 962 | ||
959 | void Addressee::setPhoto( const Picture &photo ) | 963 | void Addressee::setPhoto( const Picture &photo ) |
960 | { | 964 | { |
961 | if ( photo == mData->photo ) return; | 965 | if ( photo == mData->photo ) return; |
962 | detach(); | 966 | detach(); |
963 | mData->empty = false; | 967 | mData->empty = false; |
964 | mData->photo = photo; | 968 | mData->photo = photo; |
965 | } | 969 | } |
966 | 970 | ||
967 | Picture Addressee::photo() const | 971 | Picture Addressee::photo() const |
968 | { | 972 | { |
969 | return mData->photo; | 973 | return mData->photo; |
970 | } | 974 | } |
971 | 975 | ||
972 | QString Addressee::photoLabel() | 976 | QString Addressee::photoLabel() |
973 | { | 977 | { |
974 | return i18n("Photo"); | 978 | return i18n("Photo"); |
975 | } | 979 | } |
976 | 980 | ||
977 | 981 | ||
978 | void Addressee::setSound( const Sound &sound ) | 982 | void Addressee::setSound( const Sound &sound ) |
979 | { | 983 | { |
980 | if ( sound == mData->sound ) return; | 984 | if ( sound == mData->sound ) return; |
981 | detach(); | 985 | detach(); |
982 | mData->empty = false; | 986 | mData->empty = false; |
983 | mData->sound = sound; | 987 | mData->sound = sound; |
984 | } | 988 | } |
985 | 989 | ||
986 | Sound Addressee::sound() const | 990 | Sound Addressee::sound() const |
987 | { | 991 | { |
988 | return mData->sound; | 992 | return mData->sound; |
989 | } | 993 | } |
990 | 994 | ||
991 | QString Addressee::soundLabel() | 995 | QString Addressee::soundLabel() |
992 | { | 996 | { |
993 | return i18n("Sound"); | 997 | return i18n("Sound"); |
994 | } | 998 | } |
995 | 999 | ||
996 | 1000 | ||
997 | void Addressee::setAgent( const Agent &agent ) | 1001 | void Addressee::setAgent( const Agent &agent ) |
998 | { | 1002 | { |
999 | if ( agent == mData->agent ) return; | 1003 | if ( agent == mData->agent ) return; |
1000 | detach(); | 1004 | detach(); |
1001 | mData->empty = false; | 1005 | mData->empty = false; |
1002 | mData->agent = agent; | 1006 | mData->agent = agent; |
1003 | } | 1007 | } |
1004 | 1008 | ||
1005 | Agent Addressee::agent() const | 1009 | Agent Addressee::agent() const |
1006 | { | 1010 | { |
1007 | return mData->agent; | 1011 | return mData->agent; |
1008 | } | 1012 | } |
1009 | 1013 | ||
1010 | QString Addressee::agentLabel() | 1014 | QString Addressee::agentLabel() |
1011 | { | 1015 | { |
1012 | return i18n("Agent"); | 1016 | return i18n("Agent"); |
1013 | } | 1017 | } |
1014 | 1018 | ||
1015 | 1019 | ||
1016 | 1020 | ||
1017 | void Addressee::setNameFromString( const QString &str ) | 1021 | void Addressee::setNameFromString( const QString &str ) |
1018 | { | 1022 | { |
1019 | setFormattedName( str ); | 1023 | setFormattedName( str ); |
1020 | setName( str ); | 1024 | setName( str ); |
1021 | 1025 | ||
1022 | static bool first = true; | 1026 | static bool first = true; |
1023 | static QStringList titles; | 1027 | static QStringList titles; |
1024 | static QStringList suffixes; | 1028 | static QStringList suffixes; |
1025 | static QStringList prefixes; | 1029 | static QStringList prefixes; |
1026 | 1030 | ||
1027 | if ( first ) { | 1031 | if ( first ) { |
1028 | first = false; | 1032 | first = false; |
1029 | titles += i18n( "Dr." ); | 1033 | titles += i18n( "Dr." ); |
1030 | titles += i18n( "Miss" ); | 1034 | titles += i18n( "Miss" ); |
1031 | titles += i18n( "Mr." ); | 1035 | titles += i18n( "Mr." ); |
1032 | titles += i18n( "Mrs." ); | 1036 | titles += i18n( "Mrs." ); |
1033 | titles += i18n( "Ms." ); | 1037 | titles += i18n( "Ms." ); |
1034 | titles += i18n( "Prof." ); | 1038 | titles += i18n( "Prof." ); |
1035 | 1039 | ||
1036 | suffixes += i18n( "I" ); | 1040 | suffixes += i18n( "I" ); |
1037 | suffixes += i18n( "II" ); | 1041 | suffixes += i18n( "II" ); |
1038 | suffixes += i18n( "III" ); | 1042 | suffixes += i18n( "III" ); |
1039 | suffixes += i18n( "Jr." ); | 1043 | suffixes += i18n( "Jr." ); |
1040 | suffixes += i18n( "Sr." ); | 1044 | suffixes += i18n( "Sr." ); |
1041 | 1045 | ||
1042 | prefixes += "van"; | 1046 | prefixes += "van"; |
1043 | prefixes += "von"; | 1047 | prefixes += "von"; |
1044 | prefixes += "de"; | 1048 | prefixes += "de"; |
1045 | 1049 | ||
1046 | KConfig config( locateLocal( "config", "kabcrc") ); | 1050 | KConfig config( locateLocal( "config", "kabcrc") ); |
1047 | config.setGroup( "General" ); | 1051 | config.setGroup( "General" ); |
1048 | titles += config.readListEntry( "Prefixes" ); | 1052 | titles += config.readListEntry( "Prefixes" ); |
1049 | titles.remove( "" ); | 1053 | titles.remove( "" ); |
1050 | prefixes += config.readListEntry( "Inclusions" ); | 1054 | prefixes += config.readListEntry( "Inclusions" ); |
1051 | prefixes.remove( "" ); | 1055 | prefixes.remove( "" ); |
1052 | suffixes += config.readListEntry( "Suffixes" ); | 1056 | suffixes += config.readListEntry( "Suffixes" ); |
1053 | suffixes.remove( "" ); | 1057 | suffixes.remove( "" ); |
1054 | } | 1058 | } |
1055 | 1059 | ||
1056 | // clear all name parts | 1060 | // clear all name parts |
1057 | setPrefix( "" ); | 1061 | setPrefix( "" ); |
1058 | setGivenName( "" ); | 1062 | setGivenName( "" ); |
1059 | setAdditionalName( "" ); | 1063 | setAdditionalName( "" ); |
1060 | setFamilyName( "" ); | 1064 | setFamilyName( "" ); |
1061 | setSuffix( "" ); | 1065 | setSuffix( "" ); |
1062 | 1066 | ||
1063 | if ( str.isEmpty() ) | 1067 | if ( str.isEmpty() ) |
1064 | return; | 1068 | return; |
1065 | 1069 | ||
1066 | int i = str.find(','); | 1070 | int i = str.find(','); |
1067 | if( i < 0 ) { | 1071 | if( i < 0 ) { |
1068 | QStringList parts = QStringList::split( " ", str ); | 1072 | QStringList parts = QStringList::split( " ", str ); |
1069 | int leftOffset = 0; | 1073 | int leftOffset = 0; |
1070 | int rightOffset = parts.count() - 1; | 1074 | int rightOffset = parts.count() - 1; |
1071 | 1075 | ||
1072 | QString suffix; | 1076 | QString suffix; |
1073 | while ( rightOffset >= 0 ) { | 1077 | while ( rightOffset >= 0 ) { |
1074 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1078 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1075 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1079 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1076 | rightOffset--; | 1080 | rightOffset--; |
1077 | } else | 1081 | } else |
1078 | break; | 1082 | break; |
1079 | } | 1083 | } |
1080 | setSuffix( suffix ); | 1084 | setSuffix( suffix ); |
1081 | 1085 | ||
1082 | if ( rightOffset < 0 ) | 1086 | if ( rightOffset < 0 ) |
1083 | return; | 1087 | return; |
1084 | 1088 | ||
1085 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1089 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1086 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1090 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1087 | rightOffset--; | 1091 | rightOffset--; |
1088 | } else | 1092 | } else |
1089 | setFamilyName( parts[ rightOffset ] ); | 1093 | setFamilyName( parts[ rightOffset ] ); |
1090 | 1094 | ||
1091 | QString prefix; | 1095 | QString prefix; |
1092 | while ( leftOffset < rightOffset ) { | 1096 | while ( leftOffset < rightOffset ) { |
1093 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1097 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1094 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1098 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1095 | leftOffset++; | 1099 | leftOffset++; |
1096 | } else | 1100 | } else |
1097 | break; | 1101 | break; |
1098 | } | 1102 | } |
1099 | setPrefix( prefix ); | 1103 | setPrefix( prefix ); |
1100 | 1104 | ||
1101 | if ( leftOffset < rightOffset ) { | 1105 | if ( leftOffset < rightOffset ) { |
1102 | setGivenName( parts[ leftOffset ] ); | 1106 | setGivenName( parts[ leftOffset ] ); |
1103 | leftOffset++; | 1107 | leftOffset++; |
1104 | } | 1108 | } |
1105 | 1109 | ||
1106 | QString additionalName; | 1110 | QString additionalName; |
1107 | while ( leftOffset < rightOffset ) { | 1111 | while ( leftOffset < rightOffset ) { |
1108 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1112 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1109 | leftOffset++; | 1113 | leftOffset++; |
1110 | } | 1114 | } |
1111 | setAdditionalName( additionalName ); | 1115 | setAdditionalName( additionalName ); |
1112 | } else { | 1116 | } else { |
1113 | QString part1 = str.left( i ); | 1117 | QString part1 = str.left( i ); |
1114 | QString part2 = str.mid( i + 1 ); | 1118 | QString part2 = str.mid( i + 1 ); |
1115 | 1119 | ||
1116 | QStringList parts = QStringList::split( " ", part1 ); | 1120 | QStringList parts = QStringList::split( " ", part1 ); |
1117 | int leftOffset = 0; | 1121 | int leftOffset = 0; |
1118 | int rightOffset = parts.count() - 1; | 1122 | int rightOffset = parts.count() - 1; |
1119 | 1123 | ||
1120 | QString suffix; | 1124 | QString suffix; |
1121 | while ( rightOffset >= 0 ) { | 1125 | while ( rightOffset >= 0 ) { |
1122 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1126 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1123 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1127 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1124 | rightOffset--; | 1128 | rightOffset--; |
1125 | } else | 1129 | } else |
1126 | break; | 1130 | break; |
1127 | } | 1131 | } |
1128 | setSuffix( suffix ); | 1132 | setSuffix( suffix ); |
1129 | 1133 | ||
1130 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1134 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1131 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1135 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1132 | rightOffset--; | 1136 | rightOffset--; |
1133 | } else | 1137 | } else |
1134 | setFamilyName( parts[ rightOffset ] ); | 1138 | setFamilyName( parts[ rightOffset ] ); |
1135 | 1139 | ||
1136 | QString prefix; | 1140 | QString prefix; |
1137 | while ( leftOffset < rightOffset ) { | 1141 | while ( leftOffset < rightOffset ) { |
1138 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1142 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1139 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1143 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1140 | leftOffset++; | 1144 | leftOffset++; |
1141 | } else | 1145 | } else |
1142 | break; | 1146 | break; |
1143 | } | 1147 | } |
1144 | 1148 | ||
1145 | parts = QStringList::split( " ", part2 ); | 1149 | parts = QStringList::split( " ", part2 ); |
1146 | 1150 | ||
1147 | leftOffset = 0; | 1151 | leftOffset = 0; |
1148 | rightOffset = parts.count(); | 1152 | rightOffset = parts.count(); |
1149 | 1153 | ||
1150 | while ( leftOffset < rightOffset ) { | 1154 | while ( leftOffset < rightOffset ) { |
1151 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1155 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1152 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1156 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1153 | leftOffset++; | 1157 | leftOffset++; |
1154 | } else | 1158 | } else |
1155 | break; | 1159 | break; |
1156 | } | 1160 | } |
1157 | setPrefix( prefix ); | 1161 | setPrefix( prefix ); |
1158 | 1162 | ||
1159 | if ( leftOffset < rightOffset ) { | 1163 | if ( leftOffset < rightOffset ) { |
1160 | setGivenName( parts[ leftOffset ] ); | 1164 | setGivenName( parts[ leftOffset ] ); |
1161 | leftOffset++; | 1165 | leftOffset++; |
1162 | } | 1166 | } |
1163 | 1167 | ||
1164 | QString additionalName; | 1168 | QString additionalName; |
1165 | while ( leftOffset < rightOffset ) { | 1169 | while ( leftOffset < rightOffset ) { |
1166 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1170 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1167 | leftOffset++; | 1171 | leftOffset++; |
1168 | } | 1172 | } |
1169 | setAdditionalName( additionalName ); | 1173 | setAdditionalName( additionalName ); |
1170 | } | 1174 | } |
1171 | } | 1175 | } |
1172 | 1176 | ||
1173 | QString Addressee::realName() const | 1177 | QString Addressee::realName() const |
1174 | { | 1178 | { |
1175 | if ( !formattedName().isEmpty() ) | 1179 | if ( !formattedName().isEmpty() ) |
1176 | return formattedName(); | 1180 | return formattedName(); |
1177 | 1181 | ||
1178 | QString n = assembledName(); | 1182 | QString n = assembledName(); |
1179 | 1183 | ||
1180 | if ( n.isEmpty() ) | 1184 | if ( n.isEmpty() ) |
1181 | n = name(); | 1185 | n = name(); |
1182 | 1186 | ||
1183 | return n; | 1187 | return n; |
1184 | } | 1188 | } |
1185 | 1189 | ||
1186 | QString Addressee::assembledName() const | 1190 | QString Addressee::assembledName() const |
1187 | { | 1191 | { |
1188 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + | 1192 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + |
1189 | familyName() + " " + suffix(); | 1193 | familyName() + " " + suffix(); |
1190 | 1194 | ||
1191 | return name.simplifyWhiteSpace(); | 1195 | return name.simplifyWhiteSpace(); |
1192 | } | 1196 | } |
1193 | 1197 | ||
1194 | QString Addressee::fullEmail( const QString &email ) const | 1198 | QString Addressee::fullEmail( const QString &email ) const |
1195 | { | 1199 | { |
1196 | QString e; | 1200 | QString e; |
1197 | if ( email.isNull() ) { | 1201 | if ( email.isNull() ) { |
1198 | e = preferredEmail(); | 1202 | e = preferredEmail(); |
1199 | } else { | 1203 | } else { |
1200 | e = email; | 1204 | e = email; |
1201 | } | 1205 | } |
1202 | if ( e.isEmpty() ) return QString::null; | 1206 | if ( e.isEmpty() ) return QString::null; |
1203 | 1207 | ||
1204 | QString text; | 1208 | QString text; |
1205 | if ( realName().isEmpty() ) | 1209 | if ( realName().isEmpty() ) |
1206 | text = e; | 1210 | text = e; |
1207 | else | 1211 | else |
1208 | text = assembledName() + " <" + e + ">"; | 1212 | text = assembledName() + " <" + e + ">"; |
1209 | 1213 | ||
1210 | return text; | 1214 | return text; |
1211 | } | 1215 | } |
1212 | 1216 | ||
1213 | void Addressee::insertEmail( const QString &email, bool preferred ) | 1217 | void Addressee::insertEmail( const QString &email, bool preferred ) |
1214 | { | 1218 | { |
1215 | detach(); | 1219 | detach(); |
1216 | 1220 | ||
1217 | QStringList::Iterator it = mData->emails.find( email ); | 1221 | QStringList::Iterator it = mData->emails.find( email ); |
1218 | 1222 | ||
1219 | if ( it != mData->emails.end() ) { | 1223 | if ( it != mData->emails.end() ) { |
1220 | if ( !preferred || it == mData->emails.begin() ) return; | 1224 | if ( !preferred || it == mData->emails.begin() ) return; |
1221 | mData->emails.remove( it ); | 1225 | mData->emails.remove( it ); |
1222 | mData->emails.prepend( email ); | 1226 | mData->emails.prepend( email ); |
1223 | } else { | 1227 | } else { |
1224 | if ( preferred ) { | 1228 | if ( preferred ) { |
1225 | mData->emails.prepend( email ); | 1229 | mData->emails.prepend( email ); |
1226 | } else { | 1230 | } else { |
1227 | mData->emails.append( email ); | 1231 | mData->emails.append( email ); |
1228 | } | 1232 | } |
1229 | } | 1233 | } |
1230 | } | 1234 | } |
1231 | 1235 | ||
1232 | void Addressee::removeEmail( const QString &email ) | 1236 | void Addressee::removeEmail( const QString &email ) |
1233 | { | 1237 | { |
1234 | detach(); | 1238 | detach(); |
1235 | 1239 | ||
1236 | QStringList::Iterator it = mData->emails.find( email ); | 1240 | QStringList::Iterator it = mData->emails.find( email ); |
1237 | if ( it == mData->emails.end() ) return; | 1241 | if ( it == mData->emails.end() ) return; |
1238 | 1242 | ||
1239 | mData->emails.remove( it ); | 1243 | mData->emails.remove( it ); |
1240 | } | 1244 | } |
1241 | 1245 | ||
1242 | QString Addressee::preferredEmail() const | 1246 | QString Addressee::preferredEmail() const |
1243 | { | 1247 | { |
1244 | if ( mData->emails.count() == 0 ) return QString::null; | 1248 | if ( mData->emails.count() == 0 ) return QString::null; |
1245 | else return mData->emails.first(); | 1249 | else return mData->emails.first(); |
1246 | } | 1250 | } |
1247 | 1251 | ||
1248 | QStringList Addressee::emails() const | 1252 | QStringList Addressee::emails() const |
1249 | { | 1253 | { |
1250 | return mData->emails; | 1254 | return mData->emails; |
1251 | } | 1255 | } |
1252 | void Addressee::setEmails( const QStringList& emails ) { | 1256 | void Addressee::setEmails( const QStringList& emails ) { |
1253 | detach(); | 1257 | detach(); |
1254 | mData->emails = emails; | 1258 | mData->emails = emails; |
1255 | } | 1259 | } |
1256 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) | 1260 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) |
1257 | { | 1261 | { |
1258 | detach(); | 1262 | detach(); |
1259 | mData->empty = false; | 1263 | mData->empty = false; |
1260 | 1264 | ||
1261 | PhoneNumber::List::Iterator it; | 1265 | PhoneNumber::List::Iterator it; |
1262 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1266 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1263 | if ( (*it).id() == phoneNumber.id() ) { | 1267 | if ( (*it).id() == phoneNumber.id() ) { |
1264 | *it = phoneNumber; | 1268 | *it = phoneNumber; |
1265 | return; | 1269 | return; |
1266 | } | 1270 | } |
1267 | } | 1271 | } |
1268 | mData->phoneNumbers.append( phoneNumber ); | 1272 | mData->phoneNumbers.append( phoneNumber ); |
1269 | } | 1273 | } |
1270 | 1274 | ||
1271 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) | 1275 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) |
1272 | { | 1276 | { |
1273 | detach(); | 1277 | detach(); |
1274 | 1278 | ||
1275 | PhoneNumber::List::Iterator it; | 1279 | PhoneNumber::List::Iterator it; |
1276 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1280 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1277 | if ( (*it).id() == phoneNumber.id() ) { | 1281 | if ( (*it).id() == phoneNumber.id() ) { |
1278 | mData->phoneNumbers.remove( it ); | 1282 | mData->phoneNumbers.remove( it ); |
1279 | return; | 1283 | return; |
1280 | } | 1284 | } |
1281 | } | 1285 | } |
1282 | } | 1286 | } |
1283 | 1287 | ||
1284 | PhoneNumber Addressee::phoneNumber( int type ) const | 1288 | PhoneNumber Addressee::phoneNumber( int type ) const |
1285 | { | 1289 | { |
1286 | PhoneNumber phoneNumber( "", type ); | 1290 | PhoneNumber phoneNumber( "", type ); |
1287 | PhoneNumber::List::ConstIterator it; | 1291 | PhoneNumber::List::ConstIterator it; |
1288 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1292 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1289 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1293 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1290 | if ( (*it).type() & PhoneNumber::Pref ) | 1294 | if ( (*it).type() & PhoneNumber::Pref ) |
1291 | return (*it); | 1295 | return (*it); |
1292 | else if ( phoneNumber.number().isEmpty() ) | 1296 | else if ( phoneNumber.number().isEmpty() ) |
1293 | phoneNumber = (*it); | 1297 | phoneNumber = (*it); |
1294 | } | 1298 | } |
1295 | } | 1299 | } |
1296 | 1300 | ||
1297 | return phoneNumber; | 1301 | return phoneNumber; |
1298 | } | 1302 | } |
1299 | 1303 | ||
1300 | PhoneNumber::List Addressee::phoneNumbers() const | 1304 | PhoneNumber::List Addressee::phoneNumbers() const |
1301 | { | 1305 | { |
1302 | return mData->phoneNumbers; | 1306 | return mData->phoneNumbers; |
1303 | } | 1307 | } |
1304 | 1308 | ||
1305 | PhoneNumber::List Addressee::phoneNumbers( int type ) const | 1309 | PhoneNumber::List Addressee::phoneNumbers( int type ) const |
1306 | { | 1310 | { |
1307 | PhoneNumber::List list; | 1311 | PhoneNumber::List list; |
1308 | 1312 | ||
1309 | PhoneNumber::List::ConstIterator it; | 1313 | PhoneNumber::List::ConstIterator it; |
1310 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1314 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1311 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1315 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1312 | list.append( *it ); | 1316 | list.append( *it ); |
1313 | } | 1317 | } |
1314 | } | 1318 | } |
1315 | return list; | 1319 | return list; |
1316 | } | 1320 | } |
1317 | 1321 | ||
1318 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const | 1322 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const |
1319 | { | 1323 | { |
1320 | PhoneNumber::List::ConstIterator it; | 1324 | PhoneNumber::List::ConstIterator it; |
1321 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1325 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1322 | if ( (*it).id() == id ) { | 1326 | if ( (*it).id() == id ) { |
1323 | return *it; | 1327 | return *it; |
1324 | } | 1328 | } |
1325 | } | 1329 | } |
1326 | return PhoneNumber(); | 1330 | return PhoneNumber(); |
1327 | } | 1331 | } |
1328 | 1332 | ||
1329 | void Addressee::insertKey( const Key &key ) | 1333 | void Addressee::insertKey( const Key &key ) |
1330 | { | 1334 | { |
1331 | detach(); | 1335 | detach(); |
1332 | mData->empty = false; | 1336 | mData->empty = false; |
1333 | 1337 | ||
1334 | Key::List::Iterator it; | 1338 | Key::List::Iterator it; |
1335 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1339 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1336 | if ( (*it).id() == key.id() ) { | 1340 | if ( (*it).id() == key.id() ) { |
1337 | *it = key; | 1341 | *it = key; |
1338 | return; | 1342 | return; |
1339 | } | 1343 | } |
1340 | } | 1344 | } |
1341 | mData->keys.append( key ); | 1345 | mData->keys.append( key ); |
1342 | } | 1346 | } |
1343 | 1347 | ||
1344 | void Addressee::removeKey( const Key &key ) | 1348 | void Addressee::removeKey( const Key &key ) |
1345 | { | 1349 | { |
1346 | detach(); | 1350 | detach(); |
1347 | 1351 | ||
1348 | Key::List::Iterator it; | 1352 | Key::List::Iterator it; |
1349 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1353 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1350 | if ( (*it).id() == key.id() ) { | 1354 | if ( (*it).id() == key.id() ) { |
1351 | mData->keys.remove( key ); | 1355 | mData->keys.remove( key ); |
1352 | return; | 1356 | return; |
1353 | } | 1357 | } |
1354 | } | 1358 | } |
1355 | } | 1359 | } |
1356 | 1360 | ||
1357 | Key Addressee::key( int type, QString customTypeString ) const | 1361 | Key Addressee::key( int type, QString customTypeString ) const |
1358 | { | 1362 | { |
1359 | Key::List::ConstIterator it; | 1363 | Key::List::ConstIterator it; |
1360 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1364 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1361 | if ( (*it).type() == type ) { | 1365 | if ( (*it).type() == type ) { |
1362 | if ( type == Key::Custom ) { | 1366 | if ( type == Key::Custom ) { |
1363 | if ( customTypeString.isEmpty() ) { | 1367 | if ( customTypeString.isEmpty() ) { |
1364 | return *it; | 1368 | return *it; |
1365 | } else { | 1369 | } else { |
1366 | if ( (*it).customTypeString() == customTypeString ) | 1370 | if ( (*it).customTypeString() == customTypeString ) |
1367 | return (*it); | 1371 | return (*it); |
1368 | } | 1372 | } |
1369 | } else { | 1373 | } else { |
1370 | return *it; | 1374 | return *it; |
1371 | } | 1375 | } |
1372 | } | 1376 | } |
1373 | } | 1377 | } |
1374 | return Key( QString(), type ); | 1378 | return Key( QString(), type ); |
1375 | } | 1379 | } |
1376 | void Addressee::setKeys( const Key::List& list ) { | 1380 | void Addressee::setKeys( const Key::List& list ) { |
1377 | detach(); | 1381 | detach(); |
1378 | mData->keys = list; | 1382 | mData->keys = list; |
1379 | } | 1383 | } |
1380 | 1384 | ||
1381 | Key::List Addressee::keys() const | 1385 | Key::List Addressee::keys() const |
1382 | { | 1386 | { |
1383 | return mData->keys; | 1387 | return mData->keys; |
1384 | } | 1388 | } |
1385 | 1389 | ||
1386 | Key::List Addressee::keys( int type, QString customTypeString ) const | 1390 | Key::List Addressee::keys( int type, QString customTypeString ) const |
1387 | { | 1391 | { |
1388 | Key::List list; | 1392 | Key::List list; |
1389 | 1393 | ||
1390 | Key::List::ConstIterator it; | 1394 | Key::List::ConstIterator it; |
1391 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1395 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1392 | if ( (*it).type() == type ) { | 1396 | if ( (*it).type() == type ) { |
1393 | if ( type == Key::Custom ) { | 1397 | if ( type == Key::Custom ) { |
1394 | if ( customTypeString.isEmpty() ) { | 1398 | if ( customTypeString.isEmpty() ) { |
1395 | list.append(*it); | 1399 | list.append(*it); |
1396 | } else { | 1400 | } else { |
1397 | if ( (*it).customTypeString() == customTypeString ) | 1401 | if ( (*it).customTypeString() == customTypeString ) |
1398 | list.append(*it); | 1402 | list.append(*it); |
1399 | } | 1403 | } |
1400 | } else { | 1404 | } else { |
1401 | list.append(*it); | 1405 | list.append(*it); |
1402 | } | 1406 | } |
1403 | } | 1407 | } |
1404 | } | 1408 | } |
1405 | return list; | 1409 | return list; |
1406 | } | 1410 | } |
1407 | 1411 | ||
1408 | Key Addressee::findKey( const QString &id ) const | 1412 | Key Addressee::findKey( const QString &id ) const |
1409 | { | 1413 | { |
1410 | Key::List::ConstIterator it; | 1414 | Key::List::ConstIterator it; |
1411 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1415 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1412 | if ( (*it).id() == id ) { | 1416 | if ( (*it).id() == id ) { |
1413 | return *it; | 1417 | return *it; |
1414 | } | 1418 | } |
1415 | } | 1419 | } |
1416 | return Key(); | 1420 | return Key(); |
1417 | } | 1421 | } |
1418 | 1422 | ||
1419 | QString Addressee::asString() const | 1423 | QString Addressee::asString() const |
1420 | { | 1424 | { |
1421 | return "Smith, agent Smith..."; | 1425 | return "Smith, agent Smith..."; |
1422 | } | 1426 | } |
1423 | 1427 | ||
1424 | void Addressee::dump() const | 1428 | void Addressee::dump() const |
1425 | { | 1429 | { |
1426 | return; | 1430 | return; |
1427 | kdDebug(5700) << "Addressee {" << endl; | 1431 | kdDebug(5700) << "Addressee {" << endl; |
1428 | 1432 | ||
1429 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; | 1433 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; |
1430 | 1434 | ||
1431 | kdDebug(5700) << " Name: '" << name() << "'" << endl; | 1435 | kdDebug(5700) << " Name: '" << name() << "'" << endl; |
1432 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; | 1436 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; |
1433 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; | 1437 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; |
1434 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; | 1438 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; |
1435 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; | 1439 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; |
1436 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; | 1440 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; |
1437 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; | 1441 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; |
1438 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; | 1442 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; |
1439 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; | 1443 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; |
1440 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; | 1444 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; |
1441 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; | 1445 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; |
1442 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; | 1446 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; |
1443 | kdDebug(5700) << " Title: '" << title() << "'" << endl; | 1447 | kdDebug(5700) << " Title: '" << title() << "'" << endl; |
1444 | kdDebug(5700) << " Role: '" << role() << "'" << endl; | 1448 | kdDebug(5700) << " Role: '" << role() << "'" << endl; |
1445 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; | 1449 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; |
1446 | kdDebug(5700) << " Note: '" << note() << "'" << endl; | 1450 | kdDebug(5700) << " Note: '" << note() << "'" << endl; |
1447 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; | 1451 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; |
1448 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; | 1452 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; |
1449 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; | 1453 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; |
1450 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; | 1454 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; |
1451 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; | 1455 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; |
1452 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; | 1456 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; |
1453 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; | 1457 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; |
1454 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; | 1458 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; |
1455 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; | 1459 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; |
1456 | 1460 | ||
1457 | kdDebug(5700) << " Emails {" << endl; | 1461 | kdDebug(5700) << " Emails {" << endl; |
1458 | QStringList e = emails(); | 1462 | QStringList e = emails(); |
1459 | QStringList::ConstIterator it; | 1463 | QStringList::ConstIterator it; |
1460 | for( it = e.begin(); it != e.end(); ++it ) { | 1464 | for( it = e.begin(); it != e.end(); ++it ) { |
1461 | kdDebug(5700) << " " << (*it) << endl; | 1465 | kdDebug(5700) << " " << (*it) << endl; |
1462 | } | 1466 | } |
1463 | kdDebug(5700) << " }" << endl; | 1467 | kdDebug(5700) << " }" << endl; |
1464 | 1468 | ||
1465 | kdDebug(5700) << " PhoneNumbers {" << endl; | 1469 | kdDebug(5700) << " PhoneNumbers {" << endl; |
1466 | PhoneNumber::List p = phoneNumbers(); | 1470 | PhoneNumber::List p = phoneNumbers(); |
1467 | PhoneNumber::List::ConstIterator it2; | 1471 | PhoneNumber::List::ConstIterator it2; |
1468 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { | 1472 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { |
1469 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; | 1473 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; |
1470 | } | 1474 | } |
1471 | kdDebug(5700) << " }" << endl; | 1475 | kdDebug(5700) << " }" << endl; |
1472 | 1476 | ||
1473 | Address::List a = addresses(); | 1477 | Address::List a = addresses(); |
1474 | Address::List::ConstIterator it3; | 1478 | Address::List::ConstIterator it3; |
1475 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { | 1479 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { |
1476 | (*it3).dump(); | 1480 | (*it3).dump(); |
1477 | } | 1481 | } |
1478 | 1482 | ||
1479 | kdDebug(5700) << " Keys {" << endl; | 1483 | kdDebug(5700) << " Keys {" << endl; |
1480 | Key::List k = keys(); | 1484 | Key::List k = keys(); |
1481 | Key::List::ConstIterator it4; | 1485 | Key::List::ConstIterator it4; |
1482 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { | 1486 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { |
1483 | kdDebug(5700) << " Type: " << int((*it4).type()) << | 1487 | kdDebug(5700) << " Type: " << int((*it4).type()) << |
1484 | " Key: " << (*it4).textData() << | 1488 | " Key: " << (*it4).textData() << |
1485 | " CustomString: " << (*it4).customTypeString() << endl; | 1489 | " CustomString: " << (*it4).customTypeString() << endl; |
1486 | } | 1490 | } |
1487 | kdDebug(5700) << " }" << endl; | 1491 | kdDebug(5700) << " }" << endl; |
1488 | 1492 | ||
1489 | kdDebug(5700) << "}" << endl; | 1493 | kdDebug(5700) << "}" << endl; |
1490 | } | 1494 | } |
1491 | 1495 | ||
1492 | 1496 | ||
1493 | void Addressee::insertAddress( const Address &address ) | 1497 | void Addressee::insertAddress( const Address &address ) |
1494 | { | 1498 | { |
1495 | detach(); | 1499 | detach(); |
1496 | mData->empty = false; | 1500 | mData->empty = false; |
1497 | 1501 | ||
1498 | Address::List::Iterator it; | 1502 | Address::List::Iterator it; |
1499 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1503 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1500 | if ( (*it).id() == address.id() ) { | 1504 | if ( (*it).id() == address.id() ) { |
1501 | *it = address; | 1505 | *it = address; |
1502 | return; | 1506 | return; |
1503 | } | 1507 | } |
1504 | } | 1508 | } |
1505 | mData->addresses.append( address ); | 1509 | mData->addresses.append( address ); |
1506 | } | 1510 | } |
1507 | 1511 | ||
1508 | void Addressee::removeAddress( const Address &address ) | 1512 | void Addressee::removeAddress( const Address &address ) |
1509 | { | 1513 | { |
1510 | detach(); | 1514 | detach(); |
1511 | 1515 | ||
1512 | Address::List::Iterator it; | 1516 | Address::List::Iterator it; |
1513 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1517 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1514 | if ( (*it).id() == address.id() ) { | 1518 | if ( (*it).id() == address.id() ) { |
1515 | mData->addresses.remove( it ); | 1519 | mData->addresses.remove( it ); |
1516 | return; | 1520 | return; |
1517 | } | 1521 | } |
1518 | } | 1522 | } |
1519 | } | 1523 | } |
1520 | 1524 | ||
1521 | Address Addressee::address( int type ) const | 1525 | Address Addressee::address( int type ) const |
1522 | { | 1526 | { |
1523 | Address address( type ); | 1527 | Address address( type ); |
1524 | Address::List::ConstIterator it; | 1528 | Address::List::ConstIterator it; |
1525 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1529 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1526 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1530 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1527 | if ( (*it).type() & Address::Pref ) | 1531 | if ( (*it).type() & Address::Pref ) |
1528 | return (*it); | 1532 | return (*it); |
1529 | else if ( address.isEmpty() ) | 1533 | else if ( address.isEmpty() ) |
1530 | address = (*it); | 1534 | address = (*it); |
1531 | } | 1535 | } |
1532 | } | 1536 | } |
1533 | 1537 | ||
1534 | return address; | 1538 | return address; |
1535 | } | 1539 | } |
1536 | 1540 | ||
1537 | Address::List Addressee::addresses() const | 1541 | Address::List Addressee::addresses() const |
1538 | { | 1542 | { |
1539 | return mData->addresses; | 1543 | return mData->addresses; |
1540 | } | 1544 | } |
1541 | 1545 | ||
1542 | Address::List Addressee::addresses( int type ) const | 1546 | Address::List Addressee::addresses( int type ) const |
1543 | { | 1547 | { |
1544 | Address::List list; | 1548 | Address::List list; |
1545 | 1549 | ||
1546 | Address::List::ConstIterator it; | 1550 | Address::List::ConstIterator it; |
1547 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1551 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1548 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1552 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1549 | list.append( *it ); | 1553 | list.append( *it ); |
1550 | } | 1554 | } |
1551 | } | 1555 | } |
1552 | 1556 | ||
1553 | return list; | 1557 | return list; |
1554 | } | 1558 | } |
1555 | 1559 | ||
1556 | Address Addressee::findAddress( const QString &id ) const | 1560 | Address Addressee::findAddress( const QString &id ) const |
1557 | { | 1561 | { |
1558 | Address::List::ConstIterator it; | 1562 | Address::List::ConstIterator it; |
1559 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1563 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1560 | if ( (*it).id() == id ) { | 1564 | if ( (*it).id() == id ) { |
1561 | return *it; | 1565 | return *it; |
1562 | } | 1566 | } |
1563 | } | 1567 | } |
1564 | return Address(); | 1568 | return Address(); |
1565 | } | 1569 | } |
1566 | 1570 | ||
1567 | void Addressee::insertCategory( const QString &c ) | 1571 | void Addressee::insertCategory( const QString &c ) |
1568 | { | 1572 | { |
1569 | detach(); | 1573 | detach(); |
1570 | mData->empty = false; | 1574 | mData->empty = false; |
1571 | 1575 | ||
1572 | if ( mData->categories.contains( c ) ) return; | 1576 | if ( mData->categories.contains( c ) ) return; |
1573 | 1577 | ||
1574 | mData->categories.append( c ); | 1578 | mData->categories.append( c ); |
1575 | } | 1579 | } |
1576 | 1580 | ||
1577 | void Addressee::removeCategory( const QString &c ) | 1581 | void Addressee::removeCategory( const QString &c ) |
1578 | { | 1582 | { |
1579 | detach(); | 1583 | detach(); |
1580 | 1584 | ||
1581 | QStringList::Iterator it = mData->categories.find( c ); | 1585 | QStringList::Iterator it = mData->categories.find( c ); |
1582 | if ( it == mData->categories.end() ) return; | 1586 | if ( it == mData->categories.end() ) return; |
1583 | 1587 | ||
1584 | mData->categories.remove( it ); | 1588 | mData->categories.remove( it ); |
1585 | } | 1589 | } |
1586 | 1590 | ||
1587 | bool Addressee::hasCategory( const QString &c ) const | 1591 | bool Addressee::hasCategory( const QString &c ) const |
1588 | { | 1592 | { |
1589 | return ( mData->categories.contains( c ) ); | 1593 | return ( mData->categories.contains( c ) ); |
1590 | } | 1594 | } |
1591 | 1595 | ||
1592 | void Addressee::setCategories( const QStringList &c ) | 1596 | void Addressee::setCategories( const QStringList &c ) |
1593 | { | 1597 | { |
1594 | detach(); | 1598 | detach(); |
1595 | mData->empty = false; | 1599 | mData->empty = false; |
1596 | 1600 | ||
1597 | mData->categories = c; | 1601 | mData->categories = c; |
1598 | } | 1602 | } |
1599 | 1603 | ||
1600 | QStringList Addressee::categories() const | 1604 | QStringList Addressee::categories() const |
1601 | { | 1605 | { |
1602 | return mData->categories; | 1606 | return mData->categories; |
1603 | } | 1607 | } |
1604 | 1608 | ||
1605 | void Addressee::insertCustom( const QString &app, const QString &name, | 1609 | void Addressee::insertCustom( const QString &app, const QString &name, |
1606 | const QString &value ) | 1610 | const QString &value ) |
1607 | { | 1611 | { |
1608 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; | 1612 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; |
1609 | 1613 | ||
1610 | detach(); | 1614 | detach(); |
1611 | mData->empty = false; | 1615 | mData->empty = false; |
1612 | 1616 | ||
1613 | QString qualifiedName = app + "-" + name + ":"; | 1617 | QString qualifiedName = app + "-" + name + ":"; |
1614 | 1618 | ||
1615 | QStringList::Iterator it; | 1619 | QStringList::Iterator it; |
1616 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1620 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1617 | if ( (*it).startsWith( qualifiedName ) ) { | 1621 | if ( (*it).startsWith( qualifiedName ) ) { |
1618 | (*it) = qualifiedName + value; | 1622 | (*it) = qualifiedName + value; |
1619 | return; | 1623 | return; |
1620 | } | 1624 | } |
1621 | } | 1625 | } |
1622 | mData->custom.append( qualifiedName + value ); | 1626 | mData->custom.append( qualifiedName + value ); |
1623 | } | 1627 | } |
1624 | 1628 | ||
1625 | void Addressee::removeCustom( const QString &app, const QString &name) | 1629 | void Addressee::removeCustom( const QString &app, const QString &name) |
1626 | { | 1630 | { |
1627 | detach(); | 1631 | detach(); |
1628 | 1632 | ||
1629 | QString qualifiedName = app + "-" + name + ":"; | 1633 | QString qualifiedName = app + "-" + name + ":"; |
1630 | 1634 | ||
1631 | QStringList::Iterator it; | 1635 | QStringList::Iterator it; |
1632 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1636 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1633 | if ( (*it).startsWith( qualifiedName ) ) { | 1637 | if ( (*it).startsWith( qualifiedName ) ) { |
1634 | mData->custom.remove( it ); | 1638 | mData->custom.remove( it ); |
1635 | return; | 1639 | return; |
1636 | } | 1640 | } |
1637 | } | 1641 | } |
1638 | } | 1642 | } |
1639 | 1643 | ||
1640 | QString Addressee::custom( const QString &app, const QString &name ) const | 1644 | QString Addressee::custom( const QString &app, const QString &name ) const |
1641 | { | 1645 | { |
1642 | QString qualifiedName = app + "-" + name + ":"; | 1646 | QString qualifiedName = app + "-" + name + ":"; |
1643 | QString value; | 1647 | QString value; |
1644 | 1648 | ||
1645 | QStringList::ConstIterator it; | 1649 | QStringList::ConstIterator it; |
1646 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1650 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1647 | if ( (*it).startsWith( qualifiedName ) ) { | 1651 | if ( (*it).startsWith( qualifiedName ) ) { |
1648 | value = (*it).mid( (*it).find( ":" ) + 1 ); | 1652 | value = (*it).mid( (*it).find( ":" ) + 1 ); |
1649 | break; | 1653 | break; |
1650 | } | 1654 | } |
1651 | } | 1655 | } |
1652 | 1656 | ||
1653 | return value; | 1657 | return value; |
1654 | } | 1658 | } |
1655 | 1659 | ||
1656 | void Addressee::setCustoms( const QStringList &l ) | 1660 | void Addressee::setCustoms( const QStringList &l ) |
1657 | { | 1661 | { |
1658 | detach(); | 1662 | detach(); |
1659 | mData->empty = false; | 1663 | mData->empty = false; |
1660 | 1664 | ||
1661 | mData->custom = l; | 1665 | mData->custom = l; |
1662 | } | 1666 | } |
1663 | 1667 | ||
1664 | QStringList Addressee::customs() const | 1668 | QStringList Addressee::customs() const |
1665 | { | 1669 | { |
1666 | return mData->custom; | 1670 | return mData->custom; |
1667 | } | 1671 | } |
1668 | 1672 | ||
1669 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, | 1673 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, |
1670 | QString &email) | 1674 | QString &email) |
1671 | { | 1675 | { |
1672 | int startPos, endPos, len; | 1676 | int startPos, endPos, len; |
1673 | QString partA, partB, result; | 1677 | QString partA, partB, result; |
1674 | char endCh = '>'; | 1678 | char endCh = '>'; |
1675 | 1679 | ||
1676 | startPos = rawEmail.find('<'); | 1680 | startPos = rawEmail.find('<'); |
1677 | if (startPos < 0) | 1681 | if (startPos < 0) |
1678 | { | 1682 | { |
1679 | startPos = rawEmail.find('('); | 1683 | startPos = rawEmail.find('('); |
1680 | endCh = ')'; | 1684 | endCh = ')'; |
1681 | } | 1685 | } |
1682 | if (startPos < 0) | 1686 | if (startPos < 0) |
1683 | { | 1687 | { |
1684 | // We couldn't find any separators, so we assume the whole string | 1688 | // We couldn't find any separators, so we assume the whole string |
1685 | // is the email address | 1689 | // is the email address |
1686 | email = rawEmail; | 1690 | email = rawEmail; |
1687 | fullName = ""; | 1691 | fullName = ""; |
1688 | } | 1692 | } |
1689 | else | 1693 | else |
1690 | { | 1694 | { |
1691 | // We have a start position, try to find an end | 1695 | // We have a start position, try to find an end |
1692 | endPos = rawEmail.find(endCh, startPos+1); | 1696 | endPos = rawEmail.find(endCh, startPos+1); |
1693 | 1697 | ||
1694 | if (endPos < 0) | 1698 | if (endPos < 0) |
1695 | { | 1699 | { |
1696 | // We couldn't find the end of the email address. We can only | 1700 | // We couldn't find the end of the email address. We can only |
1697 | // assume the entire string is the email address. | 1701 | // assume the entire string is the email address. |
1698 | email = rawEmail; | 1702 | email = rawEmail; |
1699 | fullName = ""; | 1703 | fullName = ""; |
1700 | } | 1704 | } |
1701 | else | 1705 | else |
1702 | { | 1706 | { |
1703 | // We have a start and end to the email address | 1707 | // We have a start and end to the email address |
1704 | 1708 | ||
1705 | // Grab the name part | 1709 | // Grab the name part |
1706 | fullName = rawEmail.left(startPos).stripWhiteSpace(); | 1710 | fullName = rawEmail.left(startPos).stripWhiteSpace(); |
1707 | 1711 | ||
1708 | // grab the email part | 1712 | // grab the email part |
1709 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); | 1713 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); |
1710 | 1714 | ||
1711 | // Check that we do not have any extra characters on the end of the | 1715 | // Check that we do not have any extra characters on the end of the |
1712 | // strings | 1716 | // strings |
1713 | len = fullName.length(); | 1717 | len = fullName.length(); |
1714 | if (fullName[0]=='"' && fullName[len-1]=='"') | 1718 | if (fullName[0]=='"' && fullName[len-1]=='"') |
1715 | fullName = fullName.mid(1, len-2); | 1719 | fullName = fullName.mid(1, len-2); |
1716 | else if (fullName[0]=='<' && fullName[len-1]=='>') | 1720 | else if (fullName[0]=='<' && fullName[len-1]=='>') |
1717 | fullName = fullName.mid(1, len-2); | 1721 | fullName = fullName.mid(1, len-2); |
1718 | else if (fullName[0]=='(' && fullName[len-1]==')') | 1722 | else if (fullName[0]=='(' && fullName[len-1]==')') |
1719 | fullName = fullName.mid(1, len-2); | 1723 | fullName = fullName.mid(1, len-2); |
1720 | } | 1724 | } |
1721 | } | 1725 | } |
1722 | } | 1726 | } |
1723 | 1727 | ||
1724 | void Addressee::setResource( Resource *resource ) | 1728 | void Addressee::setResource( Resource *resource ) |
1725 | { | 1729 | { |
1726 | detach(); | 1730 | detach(); |
1727 | mData->resource = resource; | 1731 | mData->resource = resource; |
1728 | } | 1732 | } |
1729 | 1733 | ||
1730 | Resource *Addressee::resource() const | 1734 | Resource *Addressee::resource() const |
1731 | { | 1735 | { |
1732 | return mData->resource; | 1736 | return mData->resource; |
1733 | } | 1737 | } |
1734 | 1738 | ||
1735 | //US | 1739 | //US |
1736 | QString Addressee::resourceLabel() | 1740 | QString Addressee::resourceLabel() |
1737 | { | 1741 | { |
1738 | return i18n("Resource"); | 1742 | return i18n("Resource"); |
1739 | } | 1743 | } |
1740 | 1744 | ||
1741 | void Addressee::setChanged( bool value ) | 1745 | void Addressee::setChanged( bool value ) |
1742 | { | 1746 | { |
1743 | detach(); | 1747 | detach(); |
1744 | mData->changed = value; | 1748 | mData->changed = value; |
1745 | } | 1749 | } |
1746 | 1750 | ||
1747 | bool Addressee::changed() const | 1751 | bool Addressee::changed() const |
1748 | { | 1752 | { |
1749 | return mData->changed; | 1753 | return mData->changed; |
1750 | } | 1754 | } |
1751 | 1755 | ||
1752 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 1756 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
1753 | { | 1757 | { |
1754 | if (!a.mData) return s; | 1758 | if (!a.mData) return s; |
1755 | 1759 | ||
1756 | s << a.uid(); | 1760 | s << a.uid(); |
1757 | 1761 | ||
1758 | s << a.mData->name; | 1762 | s << a.mData->name; |
1759 | s << a.mData->formattedName; | 1763 | s << a.mData->formattedName; |
1760 | s << a.mData->familyName; | 1764 | s << a.mData->familyName; |
1761 | s << a.mData->givenName; | 1765 | s << a.mData->givenName; |
1762 | s << a.mData->additionalName; | 1766 | s << a.mData->additionalName; |
1763 | s << a.mData->prefix; | 1767 | s << a.mData->prefix; |
1764 | s << a.mData->suffix; | 1768 | s << a.mData->suffix; |
1765 | s << a.mData->nickName; | 1769 | s << a.mData->nickName; |
1766 | s << a.mData->birthday; | 1770 | s << a.mData->birthday; |
1767 | s << a.mData->mailer; | 1771 | s << a.mData->mailer; |
1768 | s << a.mData->timeZone; | 1772 | s << a.mData->timeZone; |
1769 | s << a.mData->geo; | 1773 | s << a.mData->geo; |
1770 | s << a.mData->title; | 1774 | s << a.mData->title; |
1771 | s << a.mData->role; | 1775 | s << a.mData->role; |
1772 | s << a.mData->organization; | 1776 | s << a.mData->organization; |
1773 | s << a.mData->note; | 1777 | s << a.mData->note; |
1774 | s << a.mData->productId; | 1778 | s << a.mData->productId; |
1775 | s << a.mData->revision; | 1779 | s << a.mData->revision; |
1776 | s << a.mData->sortString; | 1780 | s << a.mData->sortString; |
1777 | s << a.mData->url; | 1781 | s << a.mData->url; |
1778 | s << a.mData->secrecy; | 1782 | s << a.mData->secrecy; |
1779 | s << a.mData->logo; | 1783 | s << a.mData->logo; |
1780 | s << a.mData->photo; | 1784 | s << a.mData->photo; |
1781 | s << a.mData->sound; | 1785 | s << a.mData->sound; |
1782 | s << a.mData->agent; | 1786 | s << a.mData->agent; |
1783 | s << a.mData->phoneNumbers; | 1787 | s << a.mData->phoneNumbers; |
1784 | s << a.mData->addresses; | 1788 | s << a.mData->addresses; |
1785 | s << a.mData->emails; | 1789 | s << a.mData->emails; |
1786 | s << a.mData->categories; | 1790 | s << a.mData->categories; |
1787 | s << a.mData->custom; | 1791 | s << a.mData->custom; |
1788 | s << a.mData->keys; | 1792 | s << a.mData->keys; |
1789 | return s; | 1793 | return s; |
1790 | } | 1794 | } |
1791 | 1795 | ||
1792 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) | 1796 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) |
1793 | { | 1797 | { |
1794 | if (!a.mData) return s; | 1798 | if (!a.mData) return s; |
1795 | 1799 | ||
1796 | s >> a.mData->uid; | 1800 | s >> a.mData->uid; |
1797 | 1801 | ||
1798 | s >> a.mData->name; | 1802 | s >> a.mData->name; |
1799 | s >> a.mData->formattedName; | 1803 | s >> a.mData->formattedName; |
1800 | s >> a.mData->familyName; | 1804 | s >> a.mData->familyName; |
1801 | s >> a.mData->givenName; | 1805 | s >> a.mData->givenName; |
1802 | s >> a.mData->additionalName; | 1806 | s >> a.mData->additionalName; |
1803 | s >> a.mData->prefix; | 1807 | s >> a.mData->prefix; |
1804 | s >> a.mData->suffix; | 1808 | s >> a.mData->suffix; |
1805 | s >> a.mData->nickName; | 1809 | s >> a.mData->nickName; |
1806 | s >> a.mData->birthday; | 1810 | s >> a.mData->birthday; |
1807 | s >> a.mData->mailer; | 1811 | s >> a.mData->mailer; |
1808 | s >> a.mData->timeZone; | 1812 | s >> a.mData->timeZone; |
1809 | s >> a.mData->geo; | 1813 | s >> a.mData->geo; |
1810 | s >> a.mData->title; | 1814 | s >> a.mData->title; |
1811 | s >> a.mData->role; | 1815 | s >> a.mData->role; |
1812 | s >> a.mData->organization; | 1816 | s >> a.mData->organization; |
1813 | s >> a.mData->note; | 1817 | s >> a.mData->note; |
1814 | s >> a.mData->productId; | 1818 | s >> a.mData->productId; |
1815 | s >> a.mData->revision; | 1819 | s >> a.mData->revision; |
1816 | s >> a.mData->sortString; | 1820 | s >> a.mData->sortString; |
1817 | s >> a.mData->url; | 1821 | s >> a.mData->url; |
1818 | s >> a.mData->secrecy; | 1822 | s >> a.mData->secrecy; |
1819 | s >> a.mData->logo; | 1823 | s >> a.mData->logo; |
1820 | s >> a.mData->photo; | 1824 | s >> a.mData->photo; |
1821 | s >> a.mData->sound; | 1825 | s >> a.mData->sound; |
1822 | s >> a.mData->agent; | 1826 | s >> a.mData->agent; |
1823 | s >> a.mData->phoneNumbers; | 1827 | s >> a.mData->phoneNumbers; |
1824 | s >> a.mData->addresses; | 1828 | s >> a.mData->addresses; |
1825 | s >> a.mData->emails; | 1829 | s >> a.mData->emails; |
1826 | s >> a.mData->categories; | 1830 | s >> a.mData->categories; |
1827 | s >> a.mData->custom; | 1831 | s >> a.mData->custom; |
1828 | s >> a.mData->keys; | 1832 | s >> a.mData->keys; |
1829 | 1833 | ||
1830 | a.mData->empty = false; | 1834 | a.mData->empty = false; |
1831 | 1835 | ||
1832 | return s; | 1836 | return s; |
1833 | } | 1837 | } |
1834 | 1838 | ||
1835 | bool matchBinaryPattern( int value, int pattern ) | 1839 | bool matchBinaryPattern( int value, int pattern ) |
1836 | { | 1840 | { |
1837 | /** | 1841 | /** |
1838 | We want to match all telephonnumbers/addresses which have the bits in the | 1842 | We want to match all telephonnumbers/addresses which have the bits in the |
1839 | pattern set. More are allowed. | 1843 | pattern set. More are allowed. |
1840 | if pattern == 0 we have a special handling, then we want only those with | 1844 | if pattern == 0 we have a special handling, then we want only those with |
1841 | exactly no bit set. | 1845 | exactly no bit set. |
1842 | */ | 1846 | */ |
1843 | if ( pattern == 0 ) | 1847 | if ( pattern == 0 ) |
1844 | return ( value == 0 ); | 1848 | return ( value == 0 ); |
1845 | else | 1849 | else |
1846 | return ( pattern == ( pattern & value ) ); | 1850 | return ( pattern == ( pattern & value ) ); |
1847 | } | 1851 | } |
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index de45e63..430c7b3 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -1,376 +1,376 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | //US | 28 | //US |
29 | #include "kglobal.h" | 29 | #include "kglobal.h" |
30 | 30 | ||
31 | 31 | ||
32 | #include "qtopiaconverter.h" | 32 | #include "qtopiaconverter.h" |
33 | 33 | ||
34 | #include <qpe/categories.h> | 34 | #include <qpe/categories.h> |
35 | #include <libkdepim/ksyncprofile.h> | 35 | #include <libkdepim/ksyncprofile.h> |
36 | //US #include <qpe/categoryselect.h> | 36 | //US #include <qpe/categoryselect.h> |
37 | 37 | ||
38 | 38 | ||
39 | using namespace KABC; | 39 | using namespace KABC; |
40 | 40 | ||
41 | QtopiaConverter::QtopiaConverter() : catDB(0) | 41 | QtopiaConverter::QtopiaConverter() : catDB(0) |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | QtopiaConverter::~QtopiaConverter() | 45 | QtopiaConverter::~QtopiaConverter() |
46 | { | 46 | { |
47 | deinit(); | 47 | deinit(); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool QtopiaConverter::init() | 50 | bool QtopiaConverter::init() |
51 | { | 51 | { |
52 | catDB = new Categories(); | 52 | catDB = new Categories(); |
53 | 53 | ||
54 | if (!catDB) | 54 | if (!catDB) |
55 | return false; | 55 | return false; |
56 | 56 | ||
57 | catDB->load( categoryFileName() ); | 57 | catDB->load( categoryFileName() ); |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | 60 | ||
61 | void QtopiaConverter::deinit() | 61 | void QtopiaConverter::deinit() |
62 | { | 62 | { |
63 | if (catDB) | 63 | if (catDB) |
64 | { | 64 | { |
65 | delete catDB; | 65 | delete catDB; |
66 | catDB = 0; | 66 | catDB = 0; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) | 70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) |
71 | { | 71 | { |
72 | // name | 72 | // name |
73 | addr.setFormattedName(contact.fileAs()); | 73 | addr.setFormattedName(contact.fileAs()); |
74 | addr.setFamilyName( contact.lastName() ); | 74 | addr.setFamilyName( contact.lastName() ); |
75 | addr.setGivenName( contact.firstName() ); | 75 | addr.setGivenName( contact.firstName() ); |
76 | addr.setAdditionalName( contact.middleName() ); | 76 | addr.setAdditionalName( contact.middleName() ); |
77 | addr.setPrefix( contact.nameTitle() ); | 77 | addr.setPrefix( contact.nameTitle() ); |
78 | addr.setSuffix( contact.suffix() ); | 78 | addr.setSuffix( contact.suffix() ); |
79 | 79 | ||
80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
81 | QString exuid = contact.uid().toString(); | 81 | QString exuid = contact.uid().toString(); |
82 | addr.setOriginalExternalUID( exuid ); | 82 | addr.setOriginalExternalUID( exuid ); |
83 | int ente = exuid.find( "-0000"); | 83 | int ente = exuid.find( "-0000"); |
84 | if ( exuid.left(1) == "{" ) | 84 | if ( exuid.left(1) == "{" ) |
85 | exuid = exuid.mid(1); | 85 | exuid = exuid.mid(1); |
86 | if ( ente > -1 ) | 86 | if ( ente > -1 ) |
87 | exuid = exuid.left( ente-1 ); | 87 | exuid = exuid.left( ente-1 ); |
88 | addr.setExternalUID( exuid ); | 88 | addr.setExternalUID( exuid ); |
89 | //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); | 89 | qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); |
90 | 90 | ||
91 | 91 | ||
92 | QStringList emails = contact.emailList(); | 92 | QStringList emails = contact.emailList(); |
93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); | 94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | if (!contact.defaultEmail().isEmpty()) | 97 | if (!contact.defaultEmail().isEmpty()) |
98 | addr.insertEmail(contact.defaultEmail(), true); | 98 | addr.insertEmail(contact.defaultEmail(), true); |
99 | 99 | ||
100 | // home | 100 | // home |
101 | if ((!contact.homeStreet().isEmpty()) || | 101 | if ((!contact.homeStreet().isEmpty()) || |
102 | (!contact.homeCity().isEmpty()) || | 102 | (!contact.homeCity().isEmpty()) || |
103 | (!contact.homeState().isEmpty()) || | 103 | (!contact.homeState().isEmpty()) || |
104 | (!contact.homeZip().isEmpty()) || | 104 | (!contact.homeZip().isEmpty()) || |
105 | (!contact.homeCountry().isEmpty())) | 105 | (!contact.homeCountry().isEmpty())) |
106 | { | 106 | { |
107 | Address homeaddress; | 107 | Address homeaddress; |
108 | homeaddress.setType(Address::Home); | 108 | homeaddress.setType(Address::Home); |
109 | //US homeaddress.setPostOfficeBox( "" ); | 109 | //US homeaddress.setPostOfficeBox( "" ); |
110 | //US homeaddress.setExtended( "" ); | 110 | //US homeaddress.setExtended( "" ); |
111 | homeaddress.setStreet( contact.homeStreet() ); | 111 | homeaddress.setStreet( contact.homeStreet() ); |
112 | homeaddress.setLocality( contact.homeCity() ); | 112 | homeaddress.setLocality( contact.homeCity() ); |
113 | homeaddress.setRegion( contact.homeState() ); | 113 | homeaddress.setRegion( contact.homeState() ); |
114 | homeaddress.setPostalCode( contact.homeZip() ); | 114 | homeaddress.setPostalCode( contact.homeZip() ); |
115 | homeaddress.setCountry( contact.homeCountry() ); | 115 | homeaddress.setCountry( contact.homeCountry() ); |
116 | 116 | ||
117 | addr.insertAddress( homeaddress ); | 117 | addr.insertAddress( homeaddress ); |
118 | } | 118 | } |
119 | 119 | ||
120 | if (!contact.homePhone().isEmpty()) | 120 | if (!contact.homePhone().isEmpty()) |
121 | { | 121 | { |
122 | PhoneNumber homephone; | 122 | PhoneNumber homephone; |
123 | homephone.setType( PhoneNumber::Home ); | 123 | homephone.setType( PhoneNumber::Home ); |
124 | homephone.setNumber( contact.homePhone() ); | 124 | homephone.setNumber( contact.homePhone() ); |
125 | addr.insertPhoneNumber( homephone ); | 125 | addr.insertPhoneNumber( homephone ); |
126 | } | 126 | } |
127 | 127 | ||
128 | if (!contact.homeFax().isEmpty()) | 128 | if (!contact.homeFax().isEmpty()) |
129 | { | 129 | { |
130 | PhoneNumber homefax; | 130 | PhoneNumber homefax; |
131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
132 | homefax.setNumber( contact.homeFax() ); | 132 | homefax.setNumber( contact.homeFax() ); |
133 | addr.insertPhoneNumber( homefax ); | 133 | addr.insertPhoneNumber( homefax ); |
134 | } | 134 | } |
135 | 135 | ||
136 | if (!contact.homeMobile().isEmpty()) | 136 | if (!contact.homeMobile().isEmpty()) |
137 | { | 137 | { |
138 | PhoneNumber homemobile; | 138 | PhoneNumber homemobile; |
139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
140 | homemobile.setNumber( contact.homeMobile() ); | 140 | homemobile.setNumber( contact.homeMobile() ); |
141 | addr.insertPhoneNumber( homemobile ); | 141 | addr.insertPhoneNumber( homemobile ); |
142 | } | 142 | } |
143 | 143 | ||
144 | addr.setUrl( contact.homeWebpage() ); | 144 | addr.setUrl( contact.homeWebpage() ); |
145 | 145 | ||
146 | 146 | ||
147 | // business | 147 | // business |
148 | if ((!contact.businessStreet().isEmpty()) || | 148 | if ((!contact.businessStreet().isEmpty()) || |
149 | (!contact.businessCity().isEmpty()) || | 149 | (!contact.businessCity().isEmpty()) || |
150 | (!contact.businessState().isEmpty()) || | 150 | (!contact.businessState().isEmpty()) || |
151 | (!contact.businessZip().isEmpty()) || | 151 | (!contact.businessZip().isEmpty()) || |
152 | (!contact.businessCountry().isEmpty())) | 152 | (!contact.businessCountry().isEmpty())) |
153 | { | 153 | { |
154 | Address businessaddress; | 154 | Address businessaddress; |
155 | businessaddress.setType(Address::Work); | 155 | businessaddress.setType(Address::Work); |
156 | //US businessaddress.setPostOfficeBox( "" ); | 156 | //US businessaddress.setPostOfficeBox( "" ); |
157 | //US businessaddress.setExtended( "" ); | 157 | //US businessaddress.setExtended( "" ); |
158 | businessaddress.setStreet( contact.businessStreet() ); | 158 | businessaddress.setStreet( contact.businessStreet() ); |
159 | businessaddress.setLocality( contact.businessCity() ); | 159 | businessaddress.setLocality( contact.businessCity() ); |
160 | businessaddress.setRegion( contact.businessState() ); | 160 | businessaddress.setRegion( contact.businessState() ); |
161 | businessaddress.setPostalCode( contact.businessZip() ); | 161 | businessaddress.setPostalCode( contact.businessZip() ); |
162 | businessaddress.setCountry( contact.businessCountry() ); | 162 | businessaddress.setCountry( contact.businessCountry() ); |
163 | 163 | ||
164 | addr.insertAddress( businessaddress ); | 164 | addr.insertAddress( businessaddress ); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | if (!contact.businessPhone().isEmpty()) | 168 | if (!contact.businessPhone().isEmpty()) |
169 | { | 169 | { |
170 | PhoneNumber businessphone; | 170 | PhoneNumber businessphone; |
171 | businessphone.setType( PhoneNumber::Work ); | 171 | businessphone.setType( PhoneNumber::Work ); |
172 | businessphone.setNumber( contact.businessPhone() ); | 172 | businessphone.setNumber( contact.businessPhone() ); |
173 | addr.insertPhoneNumber( businessphone ); | 173 | addr.insertPhoneNumber( businessphone ); |
174 | } | 174 | } |
175 | 175 | ||
176 | if (!contact.businessFax().isEmpty()) | 176 | if (!contact.businessFax().isEmpty()) |
177 | { | 177 | { |
178 | PhoneNumber businessfax; | 178 | PhoneNumber businessfax; |
179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
180 | businessfax.setNumber( contact.businessFax() ); | 180 | businessfax.setNumber( contact.businessFax() ); |
181 | addr.insertPhoneNumber( businessfax ); | 181 | addr.insertPhoneNumber( businessfax ); |
182 | } | 182 | } |
183 | 183 | ||
184 | if (!contact.businessMobile().isEmpty()) | 184 | if (!contact.businessMobile().isEmpty()) |
185 | { | 185 | { |
186 | PhoneNumber businessmobile; | 186 | PhoneNumber businessmobile; |
187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
188 | businessmobile.setNumber( contact.businessMobile() ); | 188 | businessmobile.setNumber( contact.businessMobile() ); |
189 | addr.insertPhoneNumber( businessmobile ); | 189 | addr.insertPhoneNumber( businessmobile ); |
190 | } | 190 | } |
191 | 191 | ||
192 | if (!contact.businessPager().isEmpty()) | 192 | if (!contact.businessPager().isEmpty()) |
193 | { | 193 | { |
194 | PhoneNumber businesspager; | 194 | PhoneNumber businesspager; |
195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
196 | businesspager.setNumber( contact.businessPager() ); | 196 | businesspager.setNumber( contact.businessPager() ); |
197 | addr.insertPhoneNumber( businesspager ); | 197 | addr.insertPhoneNumber( businesspager ); |
198 | } | 198 | } |
199 | 199 | ||
200 | addr.setRole( contact.jobTitle() ); //? | 200 | addr.setRole( contact.jobTitle() ); //? |
201 | addr.setOrganization( contact.company() ); | 201 | addr.setOrganization( contact.company() ); |
202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); | 202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); |
203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); | 203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); |
204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); | 204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); |
205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); | 205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); |
206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); | 206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); |
207 | 207 | ||
208 | //personal | 208 | //personal |
209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); | 209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); |
210 | // qtopia uses this categorization: | 210 | // qtopia uses this categorization: |
211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
212 | if (contact.gender() == PimContact::Male) | 212 | if (contact.gender() == PimContact::Male) |
213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
214 | else if (contact.gender() == PimContact::Female) | 214 | else if (contact.gender() == PimContact::Female) |
215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
216 | 216 | ||
217 | if (contact.anniversary().isValid()) { | 217 | if (contact.anniversary().isValid()) { |
218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); | 218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); |
219 | //US | 219 | //US |
220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); | 220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); |
221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
222 | } | 222 | } |
223 | 223 | ||
224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); | 224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); |
225 | if (contact.birthday().isValid()) | 225 | if (contact.birthday().isValid()) |
226 | addr.setBirthday( contact.birthday() ); | 226 | addr.setBirthday( contact.birthday() ); |
227 | 227 | ||
228 | addr.setNickName( contact.nickname() ); | 228 | addr.setNickName( contact.nickname() ); |
229 | 229 | ||
230 | // others | 230 | // others |
231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
232 | QString notes = contact.notes(); | 232 | QString notes = contact.notes(); |
233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; | 233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; |
234 | 234 | ||
235 | addr.setNote( contact.notes() ); | 235 | addr.setNote( contact.notes() ); |
236 | 236 | ||
237 | 237 | ||
238 | 238 | ||
239 | //US QString groups() const { return find( Qtopia::Groups ); } | 239 | //US QString groups() const { return find( Qtopia::Groups ); } |
240 | //US QStringList groupList() const; | 240 | //US QStringList groupList() const; |
241 | 241 | ||
242 | QArray<int> catArray = contact.categories(); | 242 | QArray<int> catArray = contact.categories(); |
243 | QString cat; | 243 | QString cat; |
244 | 244 | ||
245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
246 | cat = catDB->label("contact", catArray[i]); | 246 | cat = catDB->label("contact", catArray[i]); |
247 | if ( cat.isEmpty() ) | 247 | if ( cat.isEmpty() ) |
248 | addr.insertCategory(QString::number(catArray[i])); | 248 | addr.insertCategory(QString::number(catArray[i])); |
249 | else | 249 | else |
250 | addr.insertCategory( cat ); | 250 | addr.insertCategory( cat ); |
251 | } | 251 | } |
252 | 252 | ||
253 | return true; | 253 | return true; |
254 | } | 254 | } |
255 | 255 | ||
256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) | 256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) |
257 | { | 257 | { |
258 | 258 | ||
259 | 259 | ||
260 | 260 | ||
261 | // name | 261 | // name |
262 | contact.setLastName(addr.familyName()); | 262 | contact.setLastName(addr.familyName()); |
263 | contact.setFirstName(addr.givenName()); | 263 | contact.setFirstName(addr.givenName()); |
264 | contact.setMiddleName(addr.additionalName()); | 264 | contact.setMiddleName(addr.additionalName()); |
265 | contact.setNameTitle(addr.prefix()); | 265 | contact.setNameTitle(addr.prefix()); |
266 | contact.setSuffix(addr.suffix()); | 266 | contact.setSuffix(addr.suffix()); |
267 | contact.setFileAs(); | 267 | contact.setFileAs(); |
268 | 268 | ||
269 | 269 | ||
270 | 270 | ||
271 | QStringList emails = addr.emails(); | 271 | QStringList emails = addr.emails(); |
272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
273 | contact.insertEmail(*it); | 273 | contact.insertEmail(*it); |
274 | } | 274 | } |
275 | contact.setDefaultEmail( addr.preferredEmail() ); | 275 | contact.setDefaultEmail( addr.preferredEmail() ); |
276 | 276 | ||
277 | 277 | ||
278 | // home | 278 | // home |
279 | const Address homeaddress = addr.address(Address::Home); | 279 | const Address homeaddress = addr.address(Address::Home); |
280 | if (!homeaddress.isEmpty()) { | 280 | if (!homeaddress.isEmpty()) { |
281 | contact.setHomeStreet(homeaddress.street()); | 281 | contact.setHomeStreet(homeaddress.street()); |
282 | contact.setHomeCity(homeaddress.locality()); | 282 | contact.setHomeCity(homeaddress.locality()); |
283 | contact.setHomeState(homeaddress.region()); | 283 | contact.setHomeState(homeaddress.region()); |
284 | contact.setHomeZip(homeaddress.postalCode()); | 284 | contact.setHomeZip(homeaddress.postalCode()); |
285 | contact.setHomeCountry(homeaddress.country()); | 285 | contact.setHomeCountry(homeaddress.country()); |
286 | } | 286 | } |
287 | 287 | ||
288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
289 | if (!homephone.number().isEmpty()) | 289 | if (!homephone.number().isEmpty()) |
290 | contact.setHomePhone(homephone.number()); | 290 | contact.setHomePhone(homephone.number()); |
291 | 291 | ||
292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
293 | if (!homefax.number().isEmpty()) | 293 | if (!homefax.number().isEmpty()) |
294 | contact.setHomeFax(homefax.number()); | 294 | contact.setHomeFax(homefax.number()); |
295 | 295 | ||
296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
297 | if (!homemobile.number().isEmpty()) | 297 | if (!homemobile.number().isEmpty()) |
298 | contact.setHomeMobile(homemobile.number()); | 298 | contact.setHomeMobile(homemobile.number()); |
299 | 299 | ||
300 | contact.setHomeWebpage(addr.url().url()); | 300 | contact.setHomeWebpage(addr.url().url()); |
301 | 301 | ||
302 | 302 | ||
303 | // business | 303 | // business |
304 | const Address businessaddress = addr.address(Address::Work); | 304 | const Address businessaddress = addr.address(Address::Work); |
305 | if (!businessaddress.isEmpty()) { | 305 | if (!businessaddress.isEmpty()) { |
306 | contact.setBusinessStreet(businessaddress.street()); | 306 | contact.setBusinessStreet(businessaddress.street()); |
307 | contact.setBusinessCity(businessaddress.locality()); | 307 | contact.setBusinessCity(businessaddress.locality()); |
308 | contact.setBusinessState(businessaddress.region()); | 308 | contact.setBusinessState(businessaddress.region()); |
309 | contact.setBusinessZip(businessaddress.postalCode()); | 309 | contact.setBusinessZip(businessaddress.postalCode()); |
310 | contact.setBusinessCountry(businessaddress.country()); | 310 | contact.setBusinessCountry(businessaddress.country()); |
311 | } | 311 | } |
312 | 312 | ||
313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
314 | if (!businessphone.number().isEmpty()) | 314 | if (!businessphone.number().isEmpty()) |
315 | contact.setBusinessPhone(businessphone.number()); | 315 | contact.setBusinessPhone(businessphone.number()); |
316 | 316 | ||
317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
318 | if (!businessfax.number().isEmpty()) | 318 | if (!businessfax.number().isEmpty()) |
319 | contact.setBusinessFax(businessfax.number()); | 319 | contact.setBusinessFax(businessfax.number()); |
320 | 320 | ||
321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
322 | if (!businessmobile.number().isEmpty()) | 322 | if (!businessmobile.number().isEmpty()) |
323 | contact.setBusinessMobile(businessmobile.number()); | 323 | contact.setBusinessMobile(businessmobile.number()); |
324 | 324 | ||
325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
326 | if (!businesspager.number().isEmpty()) | 326 | if (!businesspager.number().isEmpty()) |
327 | contact.setBusinessPager(businesspager.number()); | 327 | contact.setBusinessPager(businesspager.number()); |
328 | 328 | ||
329 | contact.setJobTitle(addr.role()); | 329 | contact.setJobTitle(addr.role()); |
330 | contact.setCompany(addr.organization()); | 330 | contact.setCompany(addr.organization()); |
331 | 331 | ||
332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); | 332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); |
333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); | 334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); |
335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); | 336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); |
337 | 337 | ||
338 | //personal | 338 | //personal |
339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
340 | // qtopia uses this categorization: | 340 | // qtopia uses this categorization: |
341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
343 | if (gt = "male") | 343 | if (gt = "male") |
344 | contact.setGender(PimContact::Male); | 344 | contact.setGender(PimContact::Male); |
345 | else if (gt = "female") | 345 | else if (gt = "female") |
346 | contact.setGender(PimContact::Female); | 346 | contact.setGender(PimContact::Female); |
347 | else | 347 | else |
348 | contact.setGender(PimContact::UnspecifiedGender); | 348 | contact.setGender(PimContact::UnspecifiedGender); |
349 | 349 | ||
350 | 350 | ||
351 | QDate dt = KGlobal::locale()->readDate( | 351 | QDate dt = KGlobal::locale()->readDate( |
352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
353 | contact.setAnniversary( dt ); | 353 | contact.setAnniversary( dt ); |
354 | 354 | ||
355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); | 355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); |
356 | 356 | ||
357 | contact.setBirthday(addr.birthday().date()); | 357 | contact.setBirthday(addr.birthday().date()); |
358 | contact.setNickname(addr.nickName()); | 358 | contact.setNickname(addr.nickName()); |
359 | 359 | ||
360 | // other | 360 | // other |
361 | contact.setNotes(addr.note()); | 361 | contact.setNotes(addr.note()); |
362 | 362 | ||
363 | //US QString groups() const { return find( Qtopia::Groups ); } | 363 | //US QString groups() const { return find( Qtopia::Groups ); } |
364 | //US QStringList groupList() const; | 364 | //US QStringList groupList() const; |
365 | 365 | ||
366 | 366 | ||
367 | QStringList cats = addr.categories(); | 367 | QStringList cats = addr.categories(); |
368 | 368 | ||
369 | QArray<int> iar; | 369 | QArray<int> iar; |
370 | if ( !cats.isEmpty() ) { | 370 | if ( !cats.isEmpty() ) { |
371 | QArray<int> iar = catDB->ids("contact", cats); | 371 | QArray<int> iar = catDB->ids("contact", cats); |
372 | contact.setCategories(iar); | 372 | contact.setCategories(iar); |
373 | } | 373 | } |
374 | 374 | ||
375 | return true; | 375 | return true; |
376 | } | 376 | } |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 935a1cf..1f90fcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,346 +1,405 @@ | |||
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 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
46 | 46 | ||
47 | 47 | ||
48 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
49 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
50 | 50 | ||
51 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
52 | #include "syncprefwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | #include <libkdepim/ksyncprofile.h> | 55 | #include <libkdepim/ksyncprofile.h> |
56 | #include <qpe/quuid.h> | 56 | #include <qpe/quuid.h> |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | extern "C" | 59 | extern "C" |
60 | { | 60 | { |
61 | void *init_microkabc_qtopia() | 61 | void *init_microkabc_qtopia() |
62 | { | 62 | { |
63 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); | 63 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 67 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
68 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
69 | { | 69 | { |
70 | // we can not choose the filename. Therefore use the default to display | 70 | // we can not choose the filename. Therefore use the default to display |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | init( fileName ); | 72 | init( fileName ); |
73 | } | 73 | } |
74 | 74 | ||
75 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 75 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
76 | : Resource( 0, syncable ) | 76 | : Resource( 0, syncable ) |
77 | { | 77 | { |
78 | init( fileName ); | 78 | init( fileName ); |
79 | } | 79 | } |
80 | 80 | ||
81 | void ResourceQtopia::init( const QString &fileName ) | 81 | void ResourceQtopia::init( const QString &fileName ) |
82 | { | 82 | { |
83 | 83 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 87 | ||
88 | setFileName( fileName ); | 88 | setFileName( fileName ); |
89 | } | 89 | } |
90 | 90 | ||
91 | ResourceQtopia::~ResourceQtopia() | 91 | ResourceQtopia::~ResourceQtopia() |
92 | { | 92 | { |
93 | if (mConverter != 0) | 93 | if (mConverter != 0) |
94 | delete mConverter; | 94 | delete mConverter; |
95 | 95 | ||
96 | if(mAccess != 0) | 96 | if(mAccess != 0) |
97 | delete mAccess; | 97 | delete mAccess; |
98 | } | 98 | } |
99 | 99 | ||
100 | void ResourceQtopia::writeConfig( KConfig *config ) | 100 | void ResourceQtopia::writeConfig( KConfig *config ) |
101 | { | 101 | { |
102 | Resource::writeConfig( config ); | 102 | Resource::writeConfig( config ); |
103 | } | 103 | } |
104 | 104 | ||
105 | Ticket *ResourceQtopia::requestSaveTicket() | 105 | Ticket *ResourceQtopia::requestSaveTicket() |
106 | { | 106 | { |
107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
108 | 108 | ||
109 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | 109 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); |
110 | 110 | ||
111 | if ( !addressBook() ) return 0; | 111 | if ( !addressBook() ) return 0; |
112 | 112 | ||
113 | if ( !lock( fileName() ) ) { | 113 | if ( !lock( fileName() ) ) { |
114 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 114 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
115 | << fileName() << "'" << endl; | 115 | << fileName() << "'" << endl; |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | return createTicket( this ); | 118 | return createTicket( this ); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | bool ResourceQtopia::doOpen() | 122 | bool ResourceQtopia::doOpen() |
123 | { | 123 | { |
124 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 124 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
125 | 125 | ||
126 | mAccess = new AddressBookAccess(); | 126 | mAccess = new AddressBookAccess(); |
127 | 127 | ||
128 | if ( !mAccess ) { | 128 | if ( !mAccess ) { |
129 | qDebug("Unable to load file() %s", fileName().latin1()); | 129 | qDebug("Unable to load file() %s", fileName().latin1()); |
130 | return false; | 130 | return false; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | if (mConverter == 0) | 134 | if (mConverter == 0) |
135 | { | 135 | { |
136 | mConverter = new QtopiaConverter(); | 136 | mConverter = new QtopiaConverter(); |
137 | bool res = mConverter->init(); | 137 | bool res = mConverter->init(); |
138 | if ( !res ) | 138 | if ( !res ) |
139 | { | 139 | { |
140 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 140 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
141 | qDebug(msg); | 141 | qDebug(msg); |
142 | delete mAccess; | 142 | delete mAccess; |
143 | mAccess = 0; | 143 | mAccess = 0; |
144 | return false; | 144 | return false; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | return true; | 148 | return true; |
149 | } | 149 | } |
150 | 150 | ||
151 | void ResourceQtopia::doClose() | 151 | void ResourceQtopia::doClose() |
152 | { | 152 | { |
153 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 153 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
154 | 154 | ||
155 | if(mAccess) | 155 | if(mAccess) |
156 | { | 156 | { |
157 | delete mAccess; | 157 | delete mAccess; |
158 | mAccess = 0; | 158 | mAccess = 0; |
159 | } | 159 | } |
160 | // it seems so, that deletion of access deletes backend as well | 160 | // it seems so, that deletion of access deletes backend as well |
161 | //delete backend; | 161 | //delete backend; |
162 | 162 | ||
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | 165 | ||
166 | bool ResourceQtopia::load() | 166 | bool ResourceQtopia::load() |
167 | { | 167 | { |
168 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 168 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
169 | 169 | ||
170 | AddressBookIterator it(*mAccess); | 170 | AddressBookIterator it(*mAccess); |
171 | const PimContact* contact; | 171 | const PimContact* contact; |
172 | bool res; | 172 | bool res; |
173 | 173 | ||
174 | for (contact=it.toFirst(); it.current(); ++it) | 174 | for (contact=it.toFirst(); it.current(); ++it) |
175 | { | 175 | { |
176 | contact = it.current(); | 176 | contact = it.current(); |
177 | 177 | ||
178 | KABC::Addressee addressee; | 178 | KABC::Addressee addressee; |
179 | 179 | ||
180 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 180 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
181 | 181 | ||
182 | if ( !addressee.isEmpty() && res ) | 182 | if ( !addressee.isEmpty() && res ) |
183 | { | 183 | { |
184 | addressee.setResource( this ); | 184 | addressee.setResource( this ); |
185 | addressBook()->insertAddressee( addressee ); | 185 | addressBook()->insertAddressee( addressee ); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | 191 | ||
192 | bool ResourceQtopia::save( Ticket *ticket ) | 192 | bool ResourceQtopia::save( Ticket *ticket ) |
193 | { | 193 | { |
194 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | 194 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
195 | 195 | ||
196 | mDirWatch.stopScan(); | 196 | mDirWatch.stopScan(); |
197 | 197 | ||
198 | KABC::AddressBook::Iterator it; | 198 | KABC::AddressBook::Iterator it; |
199 | bool res; | 199 | bool res; |
200 | 200 | KABC::Addressee::List changedAddressees; | |
201 | QStringList addedUID; | ||
201 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 202 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
202 | //KABC::Addressee addressee = (*it); | 203 | //KABC::Addressee addressee = (*it); |
204 | // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() ); | ||
203 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 205 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
204 | QUuid uid( (*it).originalExternalUID() ); | 206 | QUuid uid( (*it).originalExternalUID() ); |
205 | bool ok; | 207 | bool ok; |
206 | PimContact c = mAccess->contactForId( uid, &ok ); | 208 | PimContact c = mAccess->contactForId( uid, &ok ); |
209 | qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); | ||
207 | res = mConverter->addresseeToQtopia( *it, c ); | 210 | res = mConverter->addresseeToQtopia( *it, c ); |
208 | if (res == true) { | 211 | if (res == true) { |
209 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 212 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
210 | mAccess->addContact(c); | 213 | qDebug("skipping adding of contact "); |
211 | KABC::Addressee addressee; | 214 | continue; |
212 | mConverter->qtopiaToAddressee( c, addressee ); | 215 | PimContact e; |
213 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 216 | AddressBookAccess Access2; |
214 | addressBook()->insertAddressee( addressee ); | 217 | Access2.addContact(e); |
218 | const PimContact* contact; | ||
219 | bool res; | ||
220 | QString uid2, Ouid; | ||
221 | AddressBookIterator itt(Access2); | ||
222 | for (contact=itt.toFirst(); itt.current(); ++itt) | ||
223 | { | ||
224 | contact = itt.current(); | ||
225 | QString exuid = contact->uid().toString(); | ||
226 | Ouid =exuid; | ||
227 | int ente = exuid.find( "-0000"); | ||
228 | if ( exuid.left(1) == "{" ) | ||
229 | exuid = exuid.mid(1); | ||
230 | if ( ente > -1 ) | ||
231 | exuid = exuid.left( ente-1 ); | ||
232 | uid2 = exuid; | ||
233 | qDebug("trying find uid "); | ||
234 | if ( !addressBook()->containsExternalUid( uid2 ) ) { | ||
235 | qDebug("ab not contains "); | ||
236 | if ( !addedUID.contains( uid2 )) { | ||
237 | qDebug("list not contains "); | ||
238 | break; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | } | ||
243 | if ( !itt.current()) { | ||
244 | qDebug("ERROR uid "); | ||
245 | continue; | ||
246 | } | ||
247 | else | ||
248 | qDebug("ADD uid detected "); | ||
249 | |||
250 | |||
251 | QUuid uid3( Ouid); | ||
252 | PimContact d = Access2.contactForId( uid3, &ok ); | ||
253 | if ( ! ok ) { | ||
254 | qDebug("ADD: Error getting new uid "); | ||
255 | } else { | ||
256 | qDebug("NEW UID found "); | ||
257 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
258 | KABC::Addressee addressee; | ||
259 | mConverter->qtopiaToAddressee( g, addressee ); | ||
260 | addressee.setUid((*it).uid() ); | ||
261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
262 | changedAddressees.append( addressee ); | ||
263 | addedUID.append( uid2 ); | ||
264 | } | ||
265 | |||
215 | 266 | ||
216 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 267 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
268 | qDebug("Remove contact "); | ||
217 | if ( ok ) | 269 | if ( ok ) |
218 | mAccess->removeContact(c); | 270 | mAccess->removeContact(c); |
219 | else | 271 | else |
220 | qDebug("Error revoe contact from qtopia "); | 272 | qDebug("Error remove contact from qtopia "); |
221 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 273 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
222 | if ( ok ) { | 274 | if ( ok ) { |
275 | qDebug("Update contact "); | ||
223 | mAccess->updateContact(c); | 276 | mAccess->updateContact(c); |
277 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
224 | KABC::Addressee addressee; | 278 | KABC::Addressee addressee; |
225 | mConverter->qtopiaToAddressee( c, addressee ); | 279 | mConverter->qtopiaToAddressee( g, addressee ); |
280 | addressee.setUid((*it).uid() ); | ||
226 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 281 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); |
227 | addressBook()->insertAddressee( addressee ); | 282 | changedAddressees.append( addressee ); |
228 | } | 283 | } |
229 | else | 284 | else |
230 | qDebug("Error update contact from qtopia "); | 285 | qDebug("Error update contact from qtopia "); |
231 | 286 | ||
232 | } | 287 | } |
233 | 288 | ||
234 | } else { | 289 | } else { |
235 | qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); | 290 | qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); |
236 | } | 291 | } |
237 | } | 292 | } |
238 | } | 293 | } |
239 | 294 | ||
240 | // mAccess->addressBookUpdated(); | 295 | KABC::Addressee::List::Iterator it2; |
296 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) | ||
297 | addressBook()->insertAddressee((*it2)); | ||
298 | |||
299 | |||
241 | 300 | ||
242 | mDirWatch.startScan(); | 301 | mDirWatch.startScan(); |
243 | 302 | ||
244 | delete ticket; | 303 | delete ticket; |
245 | unlock( fileName() ); | 304 | unlock( fileName() ); |
246 | 305 | ||
247 | return true; | 306 | return true; |
248 | } | 307 | } |
249 | 308 | ||
250 | bool ResourceQtopia::lock( const QString &lockfileName ) | 309 | bool ResourceQtopia::lock( const QString &lockfileName ) |
251 | { | 310 | { |
252 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 311 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
253 | 312 | ||
254 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 313 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
255 | 314 | ||
256 | QString fn = lockfileName; | 315 | QString fn = lockfileName; |
257 | 316 | ||
258 | KURL url(fn); | 317 | KURL url(fn); |
259 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 318 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
260 | 319 | ||
261 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 320 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
262 | 321 | ||
263 | if (QFile::exists( lockName )) | 322 | if (QFile::exists( lockName )) |
264 | { | 323 | { |
265 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 324 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
266 | return false; | 325 | return false; |
267 | } | 326 | } |
268 | 327 | ||
269 | QString lockUniqueName; | 328 | QString lockUniqueName; |
270 | lockUniqueName = fn + KApplication::randomString( 8 ); | 329 | lockUniqueName = fn + KApplication::randomString( 8 ); |
271 | 330 | ||
272 | url = lockUniqueName; | 331 | url = lockUniqueName; |
273 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 332 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
274 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 333 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
275 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 334 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
276 | 335 | ||
277 | // Create unique file | 336 | // Create unique file |
278 | QFile file( mLockUniqueName ); | 337 | QFile file( mLockUniqueName ); |
279 | file.open( IO_WriteOnly ); | 338 | file.open( IO_WriteOnly ); |
280 | file.close(); | 339 | file.close(); |
281 | 340 | ||
282 | // Create lock file | 341 | // Create lock file |
283 | int result = 0; | 342 | int result = 0; |
284 | #ifndef _WIN32_ | 343 | #ifndef _WIN32_ |
285 | result = ::link( QFile::encodeName( mLockUniqueName ), | 344 | result = ::link( QFile::encodeName( mLockUniqueName ), |
286 | QFile::encodeName( lockName ) ); | 345 | QFile::encodeName( lockName ) ); |
287 | #endif | 346 | #endif |
288 | if ( result == 0 ) { | 347 | if ( result == 0 ) { |
289 | addressBook()->emitAddressBookLocked(); | 348 | addressBook()->emitAddressBookLocked(); |
290 | return true; | 349 | return true; |
291 | } | 350 | } |
292 | 351 | ||
293 | // TODO: check stat | 352 | // TODO: check stat |
294 | 353 | ||
295 | return false; | 354 | return false; |
296 | } | 355 | } |
297 | 356 | ||
298 | void ResourceQtopia::unlock( const QString &fileName ) | 357 | void ResourceQtopia::unlock( const QString &fileName ) |
299 | { | 358 | { |
300 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 359 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
301 | 360 | ||
302 | QString fn = fileName; | 361 | QString fn = fileName; |
303 | KURL url(fn); | 362 | KURL url(fn); |
304 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 363 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
305 | 364 | ||
306 | QFile::remove( lockName ); | 365 | QFile::remove( lockName ); |
307 | QFile::remove( mLockUniqueName ); | 366 | QFile::remove( mLockUniqueName ); |
308 | addressBook()->emitAddressBookUnlocked(); | 367 | addressBook()->emitAddressBookUnlocked(); |
309 | } | 368 | } |
310 | 369 | ||
311 | void ResourceQtopia::setFileName( const QString &newFileName ) | 370 | void ResourceQtopia::setFileName( const QString &newFileName ) |
312 | { | 371 | { |
313 | mDirWatch.stopScan(); | 372 | mDirWatch.stopScan(); |
314 | mDirWatch.removeFile( fileName() ); | 373 | mDirWatch.removeFile( fileName() ); |
315 | 374 | ||
316 | Resource::setFileName( newFileName ); | 375 | Resource::setFileName( newFileName ); |
317 | 376 | ||
318 | mDirWatch.addFile( fileName() ); | 377 | mDirWatch.addFile( fileName() ); |
319 | mDirWatch.startScan(); | 378 | mDirWatch.startScan(); |
320 | } | 379 | } |
321 | 380 | ||
322 | 381 | ||
323 | void ResourceQtopia::fileChanged() | 382 | void ResourceQtopia::fileChanged() |
324 | { | 383 | { |
325 | // There is a small theoretical chance that KDirWatch calls us before | 384 | // There is a small theoretical chance that KDirWatch calls us before |
326 | // we are fully constructed | 385 | // we are fully constructed |
327 | if (!addressBook()) | 386 | if (!addressBook()) |
328 | return; | 387 | return; |
329 | 388 | ||
330 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 389 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
331 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
332 | load(); | 391 | load(); |
333 | addressBook()->emitAddressBookChanged(); | 392 | addressBook()->emitAddressBookChanged(); |
334 | } | 393 | } |
335 | } | 394 | } |
336 | 395 | ||
337 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 396 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
338 | { | 397 | { |
339 | } | 398 | } |
340 | 399 | ||
341 | void ResourceQtopia::cleanUp() | 400 | void ResourceQtopia::cleanUp() |
342 | { | 401 | { |
343 | unlock( fileName() ); | 402 | unlock( fileName() ); |
344 | } | 403 | } |
345 | 404 | ||
346 | //US #include "resourceqtopia.moc" | 405 | //US #include "resourceqtopia.moc" |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 8f3ca9b..f8683e7 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -504,2535 +504,2541 @@ void KABCore::setContactSelected( const QString &uid ) | |||
504 | //if (mActionBeam) | 504 | //if (mActionBeam) |
505 | //mActionBeam->setEnabled( selected ); | 505 | //mActionBeam->setEnabled( selected ); |
506 | 506 | ||
507 | if (mActionBeamVCard) | 507 | if (mActionBeamVCard) |
508 | mActionBeamVCard->setEnabled( selected ); | 508 | mActionBeamVCard->setEnabled( selected ); |
509 | 509 | ||
510 | mActionWhoAmI->setEnabled( selected ); | 510 | mActionWhoAmI->setEnabled( selected ); |
511 | mActionCategories->setEnabled( selected ); | 511 | mActionCategories->setEnabled( selected ); |
512 | } | 512 | } |
513 | 513 | ||
514 | void KABCore::sendMail() | 514 | void KABCore::sendMail() |
515 | { | 515 | { |
516 | sendMail( mViewManager->selectedEmails().join( ", " ) ); | 516 | sendMail( mViewManager->selectedEmails().join( ", " ) ); |
517 | } | 517 | } |
518 | 518 | ||
519 | void KABCore::sendMail( const QString& emaillist ) | 519 | void KABCore::sendMail( const QString& emaillist ) |
520 | { | 520 | { |
521 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " | 521 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " |
522 | if (emaillist.contains(",") > 0) | 522 | if (emaillist.contains(",") > 0) |
523 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); | 523 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); |
524 | else | 524 | else |
525 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); | 525 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); |
526 | } | 526 | } |
527 | 527 | ||
528 | 528 | ||
529 | 529 | ||
530 | void KABCore::mailVCard() | 530 | void KABCore::mailVCard() |
531 | { | 531 | { |
532 | QStringList uids = mViewManager->selectedUids(); | 532 | QStringList uids = mViewManager->selectedUids(); |
533 | if ( !uids.isEmpty() ) | 533 | if ( !uids.isEmpty() ) |
534 | mailVCard( uids ); | 534 | mailVCard( uids ); |
535 | } | 535 | } |
536 | 536 | ||
537 | void KABCore::mailVCard( const QStringList& uids ) | 537 | void KABCore::mailVCard( const QStringList& uids ) |
538 | { | 538 | { |
539 | QStringList urls; | 539 | QStringList urls; |
540 | 540 | ||
541 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 541 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
542 | 542 | ||
543 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); | 543 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); |
544 | 544 | ||
545 | 545 | ||
546 | 546 | ||
547 | QDir().mkdir( dirName, true ); | 547 | QDir().mkdir( dirName, true ); |
548 | 548 | ||
549 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 549 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
550 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 550 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
551 | 551 | ||
552 | if ( a.isEmpty() ) | 552 | if ( a.isEmpty() ) |
553 | continue; | 553 | continue; |
554 | 554 | ||
555 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; | 555 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; |
556 | 556 | ||
557 | QString fileName = dirName + "/" + name; | 557 | QString fileName = dirName + "/" + name; |
558 | 558 | ||
559 | QFile outFile(fileName); | 559 | QFile outFile(fileName); |
560 | 560 | ||
561 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | 561 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully |
562 | KABC::VCardConverter converter; | 562 | KABC::VCardConverter converter; |
563 | QString vcard; | 563 | QString vcard; |
564 | 564 | ||
565 | converter.addresseeToVCard( a, vcard ); | 565 | converter.addresseeToVCard( a, vcard ); |
566 | 566 | ||
567 | QTextStream t( &outFile ); // use a text stream | 567 | QTextStream t( &outFile ); // use a text stream |
568 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 568 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
569 | t << vcard; | 569 | t << vcard; |
570 | 570 | ||
571 | outFile.close(); | 571 | outFile.close(); |
572 | 572 | ||
573 | urls.append( fileName ); | 573 | urls.append( fileName ); |
574 | } | 574 | } |
575 | } | 575 | } |
576 | 576 | ||
577 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); | 577 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); |
578 | 578 | ||
579 | 579 | ||
580 | /*US | 580 | /*US |
581 | kapp->invokeMailer( QString::null, QString::null, QString::null, | 581 | kapp->invokeMailer( QString::null, QString::null, QString::null, |
582 | QString::null, // subject | 582 | QString::null, // subject |
583 | QString::null, // body | 583 | QString::null, // body |
584 | QString::null, | 584 | QString::null, |
585 | urls ); // attachments | 585 | urls ); // attachments |
586 | */ | 586 | */ |
587 | 587 | ||
588 | } | 588 | } |
589 | 589 | ||
590 | /** | 590 | /** |
591 | Beams the "WhoAmI contact. | 591 | Beams the "WhoAmI contact. |
592 | */ | 592 | */ |
593 | void KABCore::beamMySelf() | 593 | void KABCore::beamMySelf() |
594 | { | 594 | { |
595 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | 595 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); |
596 | if (!a.isEmpty()) | 596 | if (!a.isEmpty()) |
597 | { | 597 | { |
598 | QStringList uids; | 598 | QStringList uids; |
599 | uids << a.uid(); | 599 | uids << a.uid(); |
600 | 600 | ||
601 | beamVCard(uids); | 601 | beamVCard(uids); |
602 | } else { | 602 | } else { |
603 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 603 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
604 | 604 | ||
605 | 605 | ||
606 | } | 606 | } |
607 | } | 607 | } |
608 | 608 | ||
609 | void KABCore::beamVCard() | 609 | void KABCore::beamVCard() |
610 | { | 610 | { |
611 | QStringList uids = mViewManager->selectedUids(); | 611 | QStringList uids = mViewManager->selectedUids(); |
612 | if ( !uids.isEmpty() ) | 612 | if ( !uids.isEmpty() ) |
613 | beamVCard( uids ); | 613 | beamVCard( uids ); |
614 | } | 614 | } |
615 | 615 | ||
616 | 616 | ||
617 | void KABCore::beamVCard(const QStringList& uids) | 617 | void KABCore::beamVCard(const QStringList& uids) |
618 | { | 618 | { |
619 | /*US | 619 | /*US |
620 | QString beamFilename; | 620 | QString beamFilename; |
621 | Opie::OPimContact c; | 621 | Opie::OPimContact c; |
622 | if ( actionPersonal->isOn() ) { | 622 | if ( actionPersonal->isOn() ) { |
623 | beamFilename = addressbookPersonalVCardName(); | 623 | beamFilename = addressbookPersonalVCardName(); |
624 | if ( !QFile::exists( beamFilename ) ) | 624 | if ( !QFile::exists( beamFilename ) ) |
625 | return; // can't beam a non-existent file | 625 | return; // can't beam a non-existent file |
626 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 626 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
627 | beamFilename ); | 627 | beamFilename ); |
628 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 628 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
629 | Opie::OPimContactAccess::List allList = access->allRecords(); | 629 | Opie::OPimContactAccess::List allList = access->allRecords(); |
630 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first | 630 | Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first |
631 | c = *it; | 631 | c = *it; |
632 | 632 | ||
633 | delete access; | 633 | delete access; |
634 | } else { | 634 | } else { |
635 | unlink( beamfile ); // delete if exists | 635 | unlink( beamfile ); // delete if exists |
636 | mkdir("/tmp/obex/", 0755); | 636 | mkdir("/tmp/obex/", 0755); |
637 | c = m_abView -> currentEntry(); | 637 | c = m_abView -> currentEntry(); |
638 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, | 638 | Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, |
639 | beamfile ); | 639 | beamfile ); |
640 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 640 | Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
641 | access->add( c ); | 641 | access->add( c ); |
642 | access->save(); | 642 | access->save(); |
643 | delete access; | 643 | delete access; |
644 | 644 | ||
645 | beamFilename = beamfile; | 645 | beamFilename = beamfile; |
646 | } | 646 | } |
647 | 647 | ||
648 | owarn << "Beaming: " << beamFilename << oendl; | 648 | owarn << "Beaming: " << beamFilename << oendl; |
649 | */ | 649 | */ |
650 | 650 | ||
651 | #if 0 | 651 | #if 0 |
652 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 652 | QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
653 | 653 | ||
654 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); | 654 | QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); |
655 | 655 | ||
656 | QString name = "contact.vcf"; | 656 | QString name = "contact.vcf"; |
657 | 657 | ||
658 | QString fileName = dirName + "/" + name; | 658 | QString fileName = dirName + "/" + name; |
659 | #endif | 659 | #endif |
660 | // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory | 660 | // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory |
661 | // | 661 | // |
662 | QString fileName = "/tmp/kapibeamfile.vcf"; | 662 | QString fileName = "/tmp/kapibeamfile.vcf"; |
663 | 663 | ||
664 | 664 | ||
665 | //QDir().mkdir( dirName, true ); | 665 | //QDir().mkdir( dirName, true ); |
666 | 666 | ||
667 | 667 | ||
668 | KABC::VCardConverter converter; | 668 | KABC::VCardConverter converter; |
669 | QString description; | 669 | QString description; |
670 | QString datastream; | 670 | QString datastream; |
671 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 671 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
672 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 672 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
673 | 673 | ||
674 | if ( a.isEmpty() ) | 674 | if ( a.isEmpty() ) |
675 | continue; | 675 | continue; |
676 | 676 | ||
677 | if (description.isEmpty()) | 677 | if (description.isEmpty()) |
678 | description = a.formattedName(); | 678 | description = a.formattedName(); |
679 | 679 | ||
680 | QString vcard; | 680 | QString vcard; |
681 | converter.addresseeToVCard( a, vcard ); | 681 | converter.addresseeToVCard( a, vcard ); |
682 | int start = 0; | 682 | int start = 0; |
683 | int next; | 683 | int next; |
684 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 684 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
685 | int semi = vcard.find(";", next); | 685 | int semi = vcard.find(";", next); |
686 | int dopp = vcard.find(":", next); | 686 | int dopp = vcard.find(":", next); |
687 | int sep; | 687 | int sep; |
688 | if ( semi < dopp && semi >= 0 ) | 688 | if ( semi < dopp && semi >= 0 ) |
689 | sep = semi ; | 689 | sep = semi ; |
690 | else | 690 | else |
691 | sep = dopp; | 691 | sep = dopp; |
692 | datastream +=vcard.mid( start, next - start); | 692 | datastream +=vcard.mid( start, next - start); |
693 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | 693 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); |
694 | start = sep; | 694 | start = sep; |
695 | } | 695 | } |
696 | datastream += vcard.mid( start,vcard.length() ); | 696 | datastream += vcard.mid( start,vcard.length() ); |
697 | } | 697 | } |
698 | #ifndef DESKTOP_VERSION | 698 | #ifndef DESKTOP_VERSION |
699 | QFile outFile(fileName); | 699 | QFile outFile(fileName); |
700 | if ( outFile.open(IO_WriteOnly) ) { | 700 | if ( outFile.open(IO_WriteOnly) ) { |
701 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 701 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
702 | QTextStream t( &outFile ); // use a text stream | 702 | QTextStream t( &outFile ); // use a text stream |
703 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 703 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
704 | t <<datastream; | 704 | t <<datastream; |
705 | outFile.close(); | 705 | outFile.close(); |
706 | Ir *ir = new Ir( this ); | 706 | Ir *ir = new Ir( this ); |
707 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 707 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
708 | ir->send( fileName, description, "text/x-vCard" ); | 708 | ir->send( fileName, description, "text/x-vCard" ); |
709 | } else { | 709 | } else { |
710 | qDebug("Error open temp beam file "); | 710 | qDebug("Error open temp beam file "); |
711 | return; | 711 | return; |
712 | } | 712 | } |
713 | #endif | 713 | #endif |
714 | 714 | ||
715 | } | 715 | } |
716 | 716 | ||
717 | void KABCore::beamDone( Ir *ir ) | 717 | void KABCore::beamDone( Ir *ir ) |
718 | { | 718 | { |
719 | #ifndef DESKTOP_VERSION | 719 | #ifndef DESKTOP_VERSION |
720 | delete ir; | 720 | delete ir; |
721 | #endif | 721 | #endif |
722 | } | 722 | } |
723 | 723 | ||
724 | 724 | ||
725 | void KABCore::browse( const QString& url ) | 725 | void KABCore::browse( const QString& url ) |
726 | { | 726 | { |
727 | #ifndef KAB_EMBEDDED | 727 | #ifndef KAB_EMBEDDED |
728 | kapp->invokeBrowser( url ); | 728 | kapp->invokeBrowser( url ); |
729 | #else //KAB_EMBEDDED | 729 | #else //KAB_EMBEDDED |
730 | qDebug("KABCore::browse must be fixed"); | 730 | qDebug("KABCore::browse must be fixed"); |
731 | #endif //KAB_EMBEDDED | 731 | #endif //KAB_EMBEDDED |
732 | } | 732 | } |
733 | 733 | ||
734 | void KABCore::selectAllContacts() | 734 | void KABCore::selectAllContacts() |
735 | { | 735 | { |
736 | mViewManager->setSelected( QString::null, true ); | 736 | mViewManager->setSelected( QString::null, true ); |
737 | } | 737 | } |
738 | 738 | ||
739 | void KABCore::deleteContacts() | 739 | void KABCore::deleteContacts() |
740 | { | 740 | { |
741 | QStringList uidList = mViewManager->selectedUids(); | 741 | QStringList uidList = mViewManager->selectedUids(); |
742 | deleteContacts( uidList ); | 742 | deleteContacts( uidList ); |
743 | } | 743 | } |
744 | 744 | ||
745 | void KABCore::deleteContacts( const QStringList &uids ) | 745 | void KABCore::deleteContacts( const QStringList &uids ) |
746 | { | 746 | { |
747 | if ( uids.count() > 0 ) { | 747 | if ( uids.count() > 0 ) { |
748 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); | 748 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); |
749 | UndoStack::instance()->push( command ); | 749 | UndoStack::instance()->push( command ); |
750 | RedoStack::instance()->clear(); | 750 | RedoStack::instance()->clear(); |
751 | 751 | ||
752 | // now if we deleted anything, refresh | 752 | // now if we deleted anything, refresh |
753 | setContactSelected( QString::null ); | 753 | setContactSelected( QString::null ); |
754 | setModified( true ); | 754 | setModified( true ); |
755 | } | 755 | } |
756 | } | 756 | } |
757 | 757 | ||
758 | void KABCore::copyContacts() | 758 | void KABCore::copyContacts() |
759 | { | 759 | { |
760 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 760 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
761 | 761 | ||
762 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); | 762 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); |
763 | 763 | ||
764 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; | 764 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; |
765 | 765 | ||
766 | QClipboard *cb = QApplication::clipboard(); | 766 | QClipboard *cb = QApplication::clipboard(); |
767 | cb->setText( clipText ); | 767 | cb->setText( clipText ); |
768 | } | 768 | } |
769 | 769 | ||
770 | void KABCore::cutContacts() | 770 | void KABCore::cutContacts() |
771 | { | 771 | { |
772 | QStringList uidList = mViewManager->selectedUids(); | 772 | QStringList uidList = mViewManager->selectedUids(); |
773 | 773 | ||
774 | //US if ( uidList.size() > 0 ) { | 774 | //US if ( uidList.size() > 0 ) { |
775 | if ( uidList.count() > 0 ) { | 775 | if ( uidList.count() > 0 ) { |
776 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); | 776 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); |
777 | UndoStack::instance()->push( command ); | 777 | UndoStack::instance()->push( command ); |
778 | RedoStack::instance()->clear(); | 778 | RedoStack::instance()->clear(); |
779 | 779 | ||
780 | setModified( true ); | 780 | setModified( true ); |
781 | } | 781 | } |
782 | } | 782 | } |
783 | 783 | ||
784 | void KABCore::pasteContacts() | 784 | void KABCore::pasteContacts() |
785 | { | 785 | { |
786 | QClipboard *cb = QApplication::clipboard(); | 786 | QClipboard *cb = QApplication::clipboard(); |
787 | 787 | ||
788 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); | 788 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); |
789 | 789 | ||
790 | pasteContacts( list ); | 790 | pasteContacts( list ); |
791 | } | 791 | } |
792 | 792 | ||
793 | void KABCore::pasteContacts( KABC::Addressee::List &list ) | 793 | void KABCore::pasteContacts( KABC::Addressee::List &list ) |
794 | { | 794 | { |
795 | KABC::Resource *resource = requestResource( this ); | 795 | KABC::Resource *resource = requestResource( this ); |
796 | KABC::Addressee::List::Iterator it; | 796 | KABC::Addressee::List::Iterator it; |
797 | for ( it = list.begin(); it != list.end(); ++it ) | 797 | for ( it = list.begin(); it != list.end(); ++it ) |
798 | (*it).setResource( resource ); | 798 | (*it).setResource( resource ); |
799 | 799 | ||
800 | PwPasteCommand *command = new PwPasteCommand( this, list ); | 800 | PwPasteCommand *command = new PwPasteCommand( this, list ); |
801 | UndoStack::instance()->push( command ); | 801 | UndoStack::instance()->push( command ); |
802 | RedoStack::instance()->clear(); | 802 | RedoStack::instance()->clear(); |
803 | 803 | ||
804 | setModified( true ); | 804 | setModified( true ); |
805 | } | 805 | } |
806 | 806 | ||
807 | void KABCore::setWhoAmI() | 807 | void KABCore::setWhoAmI() |
808 | { | 808 | { |
809 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 809 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
810 | 810 | ||
811 | if ( addrList.count() > 1 ) { | 811 | if ( addrList.count() > 1 ) { |
812 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 812 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
813 | return; | 813 | return; |
814 | } | 814 | } |
815 | 815 | ||
816 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 816 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
817 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 817 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
818 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 818 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
819 | } | 819 | } |
820 | 820 | ||
821 | void KABCore::setCategories() | 821 | void KABCore::setCategories() |
822 | { | 822 | { |
823 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 823 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
824 | if ( !dlg.exec() ) | 824 | if ( !dlg.exec() ) |
825 | return; | 825 | return; |
826 | 826 | ||
827 | bool merge = false; | 827 | bool merge = false; |
828 | QString msg = i18n( "Merge with existing categories?" ); | 828 | QString msg = i18n( "Merge with existing categories?" ); |
829 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) | 829 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) |
830 | merge = true; | 830 | merge = true; |
831 | 831 | ||
832 | QStringList categories = dlg.selectedCategories(); | 832 | QStringList categories = dlg.selectedCategories(); |
833 | 833 | ||
834 | QStringList uids = mViewManager->selectedUids(); | 834 | QStringList uids = mViewManager->selectedUids(); |
835 | QStringList::Iterator it; | 835 | QStringList::Iterator it; |
836 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 836 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
837 | KABC::Addressee addr = mAddressBook->findByUid( *it ); | 837 | KABC::Addressee addr = mAddressBook->findByUid( *it ); |
838 | if ( !addr.isEmpty() ) { | 838 | if ( !addr.isEmpty() ) { |
839 | if ( !merge ) | 839 | if ( !merge ) |
840 | addr.setCategories( categories ); | 840 | addr.setCategories( categories ); |
841 | else { | 841 | else { |
842 | QStringList addrCategories = addr.categories(); | 842 | QStringList addrCategories = addr.categories(); |
843 | QStringList::Iterator catIt; | 843 | QStringList::Iterator catIt; |
844 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 844 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
845 | if ( !addrCategories.contains( *catIt ) ) | 845 | if ( !addrCategories.contains( *catIt ) ) |
846 | addrCategories.append( *catIt ); | 846 | addrCategories.append( *catIt ); |
847 | } | 847 | } |
848 | addr.setCategories( addrCategories ); | 848 | addr.setCategories( addrCategories ); |
849 | } | 849 | } |
850 | 850 | ||
851 | mAddressBook->insertAddressee( addr ); | 851 | mAddressBook->insertAddressee( addr ); |
852 | } | 852 | } |
853 | } | 853 | } |
854 | 854 | ||
855 | if ( uids.count() > 0 ) | 855 | if ( uids.count() > 0 ) |
856 | setModified( true ); | 856 | setModified( true ); |
857 | } | 857 | } |
858 | 858 | ||
859 | void KABCore::setSearchFields( const KABC::Field::List &fields ) | 859 | void KABCore::setSearchFields( const KABC::Field::List &fields ) |
860 | { | 860 | { |
861 | mIncSearchWidget->setFields( fields ); | 861 | mIncSearchWidget->setFields( fields ); |
862 | } | 862 | } |
863 | 863 | ||
864 | void KABCore::incrementalSearch( const QString& text ) | 864 | void KABCore::incrementalSearch( const QString& text ) |
865 | { | 865 | { |
866 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); | 866 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); |
867 | } | 867 | } |
868 | 868 | ||
869 | void KABCore::setModified() | 869 | void KABCore::setModified() |
870 | { | 870 | { |
871 | setModified( true ); | 871 | setModified( true ); |
872 | } | 872 | } |
873 | 873 | ||
874 | void KABCore::setModifiedWOrefresh() | 874 | void KABCore::setModifiedWOrefresh() |
875 | { | 875 | { |
876 | // qDebug("KABCore::setModifiedWOrefresh() "); | 876 | // qDebug("KABCore::setModifiedWOrefresh() "); |
877 | mModified = true; | 877 | mModified = true; |
878 | mActionSave->setEnabled( mModified ); | 878 | mActionSave->setEnabled( mModified ); |
879 | #ifdef DESKTOP_VERSION | 879 | #ifdef DESKTOP_VERSION |
880 | mDetails->refreshView(); | 880 | mDetails->refreshView(); |
881 | #endif | 881 | #endif |
882 | 882 | ||
883 | } | 883 | } |
884 | void KABCore::setModified( bool modified ) | 884 | void KABCore::setModified( bool modified ) |
885 | { | 885 | { |
886 | mModified = modified; | 886 | mModified = modified; |
887 | mActionSave->setEnabled( mModified ); | 887 | mActionSave->setEnabled( mModified ); |
888 | 888 | ||
889 | if ( modified ) | 889 | if ( modified ) |
890 | mJumpButtonBar->recreateButtons(); | 890 | mJumpButtonBar->recreateButtons(); |
891 | 891 | ||
892 | mViewManager->refreshView(); | 892 | mViewManager->refreshView(); |
893 | mDetails->refreshView(); | 893 | mDetails->refreshView(); |
894 | 894 | ||
895 | } | 895 | } |
896 | 896 | ||
897 | bool KABCore::modified() const | 897 | bool KABCore::modified() const |
898 | { | 898 | { |
899 | return mModified; | 899 | return mModified; |
900 | } | 900 | } |
901 | 901 | ||
902 | void KABCore::contactModified( const KABC::Addressee &addr ) | 902 | void KABCore::contactModified( const KABC::Addressee &addr ) |
903 | { | 903 | { |
904 | 904 | ||
905 | Command *command = 0; | 905 | Command *command = 0; |
906 | QString uid; | 906 | QString uid; |
907 | 907 | ||
908 | // check if it exists already | 908 | // check if it exists already |
909 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); | 909 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); |
910 | if ( origAddr.isEmpty() ) | 910 | if ( origAddr.isEmpty() ) |
911 | command = new PwNewCommand( mAddressBook, addr ); | 911 | command = new PwNewCommand( mAddressBook, addr ); |
912 | else { | 912 | else { |
913 | command = new PwEditCommand( mAddressBook, origAddr, addr ); | 913 | command = new PwEditCommand( mAddressBook, origAddr, addr ); |
914 | uid = addr.uid(); | 914 | uid = addr.uid(); |
915 | } | 915 | } |
916 | 916 | ||
917 | UndoStack::instance()->push( command ); | 917 | UndoStack::instance()->push( command ); |
918 | RedoStack::instance()->clear(); | 918 | RedoStack::instance()->clear(); |
919 | 919 | ||
920 | setModified( true ); | 920 | setModified( true ); |
921 | } | 921 | } |
922 | 922 | ||
923 | void KABCore::newContact() | 923 | void KABCore::newContact() |
924 | { | 924 | { |
925 | 925 | ||
926 | 926 | ||
927 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); | 927 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); |
928 | 928 | ||
929 | QPtrList<KRES::Resource> kresResources; | 929 | QPtrList<KRES::Resource> kresResources; |
930 | QPtrListIterator<KABC::Resource> it( kabcResources ); | 930 | QPtrListIterator<KABC::Resource> it( kabcResources ); |
931 | KABC::Resource *resource; | 931 | KABC::Resource *resource; |
932 | while ( ( resource = it.current() ) != 0 ) { | 932 | while ( ( resource = it.current() ) != 0 ) { |
933 | ++it; | 933 | ++it; |
934 | if ( !resource->readOnly() ) { | 934 | if ( !resource->readOnly() ) { |
935 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 935 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
936 | if ( res ) | 936 | if ( res ) |
937 | kresResources.append( res ); | 937 | kresResources.append( res ); |
938 | } | 938 | } |
939 | } | 939 | } |
940 | 940 | ||
941 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); | 941 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); |
942 | resource = static_cast<KABC::Resource*>( res ); | 942 | resource = static_cast<KABC::Resource*>( res ); |
943 | 943 | ||
944 | if ( resource ) { | 944 | if ( resource ) { |
945 | KABC::Addressee addr; | 945 | KABC::Addressee addr; |
946 | addr.setResource( resource ); | 946 | addr.setResource( resource ); |
947 | mEditorDialog->setAddressee( addr ); | 947 | mEditorDialog->setAddressee( addr ); |
948 | KApplication::execDialog ( mEditorDialog ); | 948 | KApplication::execDialog ( mEditorDialog ); |
949 | 949 | ||
950 | } else | 950 | } else |
951 | return; | 951 | return; |
952 | 952 | ||
953 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); | 953 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); |
954 | 954 | ||
955 | 955 | ||
956 | } | 956 | } |
957 | 957 | ||
958 | void KABCore::addEmail( QString aStr ) | 958 | void KABCore::addEmail( QString aStr ) |
959 | { | 959 | { |
960 | #ifndef KAB_EMBEDDED | 960 | #ifndef KAB_EMBEDDED |
961 | QString fullName, email; | 961 | QString fullName, email; |
962 | 962 | ||
963 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); | 963 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); |
964 | 964 | ||
965 | // Try to lookup the addressee matching the email address | 965 | // Try to lookup the addressee matching the email address |
966 | bool found = false; | 966 | bool found = false; |
967 | QStringList emailList; | 967 | QStringList emailList; |
968 | KABC::AddressBook::Iterator it; | 968 | KABC::AddressBook::Iterator it; |
969 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { | 969 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { |
970 | emailList = (*it).emails(); | 970 | emailList = (*it).emails(); |
971 | if ( emailList.contains( email ) > 0 ) { | 971 | if ( emailList.contains( email ) > 0 ) { |
972 | found = true; | 972 | found = true; |
973 | (*it).setNameFromString( fullName ); | 973 | (*it).setNameFromString( fullName ); |
974 | editContact( (*it).uid() ); | 974 | editContact( (*it).uid() ); |
975 | } | 975 | } |
976 | } | 976 | } |
977 | 977 | ||
978 | if ( !found ) { | 978 | if ( !found ) { |
979 | KABC::Addressee addr; | 979 | KABC::Addressee addr; |
980 | addr.setNameFromString( fullName ); | 980 | addr.setNameFromString( fullName ); |
981 | addr.insertEmail( email, true ); | 981 | addr.insertEmail( email, true ); |
982 | 982 | ||
983 | mAddressBook->insertAddressee( addr ); | 983 | mAddressBook->insertAddressee( addr ); |
984 | mViewManager->refreshView( addr.uid() ); | 984 | mViewManager->refreshView( addr.uid() ); |
985 | editContact( addr.uid() ); | 985 | editContact( addr.uid() ); |
986 | } | 986 | } |
987 | #else //KAB_EMBEDDED | 987 | #else //KAB_EMBEDDED |
988 | qDebug("KABCore::addEmail finsih method"); | 988 | qDebug("KABCore::addEmail finsih method"); |
989 | #endif //KAB_EMBEDDED | 989 | #endif //KAB_EMBEDDED |
990 | } | 990 | } |
991 | 991 | ||
992 | void KABCore::importVCard( const KURL &url, bool showPreview ) | 992 | void KABCore::importVCard( const KURL &url, bool showPreview ) |
993 | { | 993 | { |
994 | mXXPortManager->importVCard( url, showPreview ); | 994 | mXXPortManager->importVCard( url, showPreview ); |
995 | } | 995 | } |
996 | void KABCore::importFromOL() | 996 | void KABCore::importFromOL() |
997 | { | 997 | { |
998 | #ifdef _WIN32_ | 998 | #ifdef _WIN32_ |
999 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); | 999 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); |
1000 | idgl->exec(); | 1000 | idgl->exec(); |
1001 | KABC::Addressee::List list = idgl->getAddressList(); | 1001 | KABC::Addressee::List list = idgl->getAddressList(); |
1002 | if ( list.count() > 0 ) { | 1002 | if ( list.count() > 0 ) { |
1003 | KABC::Addressee::List listNew; | 1003 | KABC::Addressee::List listNew; |
1004 | KABC::Addressee::List listExisting; | 1004 | KABC::Addressee::List listExisting; |
1005 | KABC::Addressee::List::Iterator it; | 1005 | KABC::Addressee::List::Iterator it; |
1006 | KABC::AddressBook::Iterator iter; | 1006 | KABC::AddressBook::Iterator iter; |
1007 | for ( it = list.begin(); it != list.end(); ++it ) { | 1007 | for ( it = list.begin(); it != list.end(); ++it ) { |
1008 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) | 1008 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) |
1009 | listNew.append( (*it) ); | 1009 | listNew.append( (*it) ); |
1010 | else | 1010 | else |
1011 | listExisting.append( (*it) ); | 1011 | listExisting.append( (*it) ); |
1012 | } | 1012 | } |
1013 | if ( listExisting.count() > 0 ) | 1013 | if ( listExisting.count() > 0 ) |
1014 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); | 1014 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); |
1015 | if ( listNew.count() > 0 ) { | 1015 | if ( listNew.count() > 0 ) { |
1016 | pasteWithNewUid = false; | 1016 | pasteWithNewUid = false; |
1017 | pasteContacts( listNew ); | 1017 | pasteContacts( listNew ); |
1018 | pasteWithNewUid = true; | 1018 | pasteWithNewUid = true; |
1019 | } | 1019 | } |
1020 | } | 1020 | } |
1021 | delete idgl; | 1021 | delete idgl; |
1022 | #endif | 1022 | #endif |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | void KABCore::importVCard( const QString &vCard, bool showPreview ) | 1025 | void KABCore::importVCard( const QString &vCard, bool showPreview ) |
1026 | { | 1026 | { |
1027 | mXXPortManager->importVCard( vCard, showPreview ); | 1027 | mXXPortManager->importVCard( vCard, showPreview ); |
1028 | } | 1028 | } |
1029 | 1029 | ||
1030 | //US added a second method without defaultparameter | 1030 | //US added a second method without defaultparameter |
1031 | void KABCore::editContact2() { | 1031 | void KABCore::editContact2() { |
1032 | editContact( QString::null ); | 1032 | editContact( QString::null ); |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | void KABCore::editContact( const QString &uid ) | 1035 | void KABCore::editContact( const QString &uid ) |
1036 | { | 1036 | { |
1037 | 1037 | ||
1038 | if ( mExtensionManager->isQuickEditVisible() ) | 1038 | if ( mExtensionManager->isQuickEditVisible() ) |
1039 | return; | 1039 | return; |
1040 | 1040 | ||
1041 | // First, locate the contact entry | 1041 | // First, locate the contact entry |
1042 | QString localUID = uid; | 1042 | QString localUID = uid; |
1043 | if ( localUID.isNull() ) { | 1043 | if ( localUID.isNull() ) { |
1044 | QStringList uidList = mViewManager->selectedUids(); | 1044 | QStringList uidList = mViewManager->selectedUids(); |
1045 | if ( uidList.count() > 0 ) | 1045 | if ( uidList.count() > 0 ) |
1046 | localUID = *( uidList.at( 0 ) ); | 1046 | localUID = *( uidList.at( 0 ) ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); | 1049 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); |
1050 | if ( !addr.isEmpty() ) { | 1050 | if ( !addr.isEmpty() ) { |
1051 | mEditorDialog->setAddressee( addr ); | 1051 | mEditorDialog->setAddressee( addr ); |
1052 | KApplication::execDialog ( mEditorDialog ); | 1052 | KApplication::execDialog ( mEditorDialog ); |
1053 | } | 1053 | } |
1054 | } | 1054 | } |
1055 | 1055 | ||
1056 | /** | 1056 | /** |
1057 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 1057 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
1058 | the method will try to find a selected addressee in the view. | 1058 | the method will try to find a selected addressee in the view. |
1059 | */ | 1059 | */ |
1060 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | 1060 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) |
1061 | { | 1061 | { |
1062 | if ( mMultipleViewsAtOnce ) | 1062 | if ( mMultipleViewsAtOnce ) |
1063 | { | 1063 | { |
1064 | editContact( uid ); | 1064 | editContact( uid ); |
1065 | } | 1065 | } |
1066 | else | 1066 | else |
1067 | { | 1067 | { |
1068 | setDetailsVisible( true ); | 1068 | setDetailsVisible( true ); |
1069 | mActionDetails->setChecked(true); | 1069 | mActionDetails->setChecked(true); |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | void KABCore::save() | 1074 | void KABCore::save() |
1075 | { | 1075 | { |
1076 | if (mBlockSaveFlag) | 1076 | if (mBlockSaveFlag) |
1077 | return; | 1077 | return; |
1078 | mBlockSaveFlag = true; | 1078 | mBlockSaveFlag = true; |
1079 | if ( !mModified ) | 1079 | if ( !mModified ) |
1080 | return; | 1080 | return; |
1081 | QString text = i18n( "There was an error while attempting to save\n the " | 1081 | QString text = i18n( "There was an error while attempting to save\n the " |
1082 | "address book. Please check that some \nother application is " | 1082 | "address book. Please check that some \nother application is " |
1083 | "not using it. " ); | 1083 | "not using it. " ); |
1084 | statusMessage(i18n("Saving addressbook ... ")); | 1084 | statusMessage(i18n("Saving addressbook ... ")); |
1085 | #ifndef KAB_EMBEDDED | 1085 | #ifndef KAB_EMBEDDED |
1086 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); | 1086 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); |
1087 | if ( !b || !b->save() ) { | 1087 | if ( !b || !b->save() ) { |
1088 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); | 1088 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); |
1089 | } | 1089 | } |
1090 | #else //KAB_EMBEDDED | 1090 | #else //KAB_EMBEDDED |
1091 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); | 1091 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); |
1092 | if ( !b || !b->save() ) { | 1092 | if ( !b || !b->save() ) { |
1093 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1093 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1094 | } | 1094 | } |
1095 | #endif //KAB_EMBEDDED | 1095 | #endif //KAB_EMBEDDED |
1096 | 1096 | ||
1097 | statusMessage(i18n("Addressbook saved!")); | 1097 | statusMessage(i18n("Addressbook saved!")); |
1098 | setModified( false ); | 1098 | setModified( false ); |
1099 | mBlockSaveFlag = false; | 1099 | mBlockSaveFlag = false; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | void KABCore::statusMessage(QString mess , int time ) | 1102 | void KABCore::statusMessage(QString mess , int time ) |
1103 | { | 1103 | { |
1104 | //topLevelWidget()->setCaption( mess ); | 1104 | //topLevelWidget()->setCaption( mess ); |
1105 | // pending setting timer to revome message | 1105 | // pending setting timer to revome message |
1106 | } | 1106 | } |
1107 | void KABCore::undo() | 1107 | void KABCore::undo() |
1108 | { | 1108 | { |
1109 | UndoStack::instance()->undo(); | 1109 | UndoStack::instance()->undo(); |
1110 | 1110 | ||
1111 | // Refresh the view | 1111 | // Refresh the view |
1112 | mViewManager->refreshView(); | 1112 | mViewManager->refreshView(); |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | void KABCore::redo() | 1115 | void KABCore::redo() |
1116 | { | 1116 | { |
1117 | RedoStack::instance()->redo(); | 1117 | RedoStack::instance()->redo(); |
1118 | 1118 | ||
1119 | // Refresh the view | 1119 | // Refresh the view |
1120 | mViewManager->refreshView(); | 1120 | mViewManager->refreshView(); |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | void KABCore::setJumpButtonBarVisible( bool visible ) | 1123 | void KABCore::setJumpButtonBarVisible( bool visible ) |
1124 | { | 1124 | { |
1125 | if (mMultipleViewsAtOnce) | 1125 | if (mMultipleViewsAtOnce) |
1126 | { | 1126 | { |
1127 | if ( visible ) | 1127 | if ( visible ) |
1128 | mJumpButtonBar->show(); | 1128 | mJumpButtonBar->show(); |
1129 | else | 1129 | else |
1130 | mJumpButtonBar->hide(); | 1130 | mJumpButtonBar->hide(); |
1131 | } | 1131 | } |
1132 | else | 1132 | else |
1133 | { | 1133 | { |
1134 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" | 1134 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" |
1135 | if (mViewManager->isVisible()) | 1135 | if (mViewManager->isVisible()) |
1136 | { | 1136 | { |
1137 | if ( visible ) | 1137 | if ( visible ) |
1138 | mJumpButtonBar->show(); | 1138 | mJumpButtonBar->show(); |
1139 | else | 1139 | else |
1140 | mJumpButtonBar->hide(); | 1140 | mJumpButtonBar->hide(); |
1141 | } | 1141 | } |
1142 | else | 1142 | else |
1143 | { | 1143 | { |
1144 | mJumpButtonBar->hide(); | 1144 | mJumpButtonBar->hide(); |
1145 | } | 1145 | } |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | 1149 | ||
1150 | void KABCore::setDetailsToState() | 1150 | void KABCore::setDetailsToState() |
1151 | { | 1151 | { |
1152 | setDetailsVisible( mActionDetails->isChecked() ); | 1152 | setDetailsVisible( mActionDetails->isChecked() ); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | 1155 | ||
1156 | 1156 | ||
1157 | void KABCore::setDetailsVisible( bool visible ) | 1157 | void KABCore::setDetailsVisible( bool visible ) |
1158 | { | 1158 | { |
1159 | if (visible && mDetails->isHidden()) | 1159 | if (visible && mDetails->isHidden()) |
1160 | { | 1160 | { |
1161 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 1161 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
1162 | if ( addrList.count() > 0 ) | 1162 | if ( addrList.count() > 0 ) |
1163 | mDetails->setAddressee( addrList[ 0 ] ); | 1163 | mDetails->setAddressee( addrList[ 0 ] ); |
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between | 1166 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between |
1167 | // the listview and the detailview. We do that by changing the splitbar size. | 1167 | // the listview and the detailview. We do that by changing the splitbar size. |
1168 | if (mMultipleViewsAtOnce) | 1168 | if (mMultipleViewsAtOnce) |
1169 | { | 1169 | { |
1170 | if ( visible ) | 1170 | if ( visible ) |
1171 | mDetails->show(); | 1171 | mDetails->show(); |
1172 | else | 1172 | else |
1173 | mDetails->hide(); | 1173 | mDetails->hide(); |
1174 | } | 1174 | } |
1175 | else | 1175 | else |
1176 | { | 1176 | { |
1177 | if ( visible ) { | 1177 | if ( visible ) { |
1178 | mViewManager->hide(); | 1178 | mViewManager->hide(); |
1179 | mDetails->show(); | 1179 | mDetails->show(); |
1180 | } | 1180 | } |
1181 | else { | 1181 | else { |
1182 | mViewManager->show(); | 1182 | mViewManager->show(); |
1183 | mDetails->hide(); | 1183 | mDetails->hide(); |
1184 | } | 1184 | } |
1185 | setJumpButtonBarVisible( !visible ); | 1185 | setJumpButtonBarVisible( !visible ); |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | } | 1188 | } |
1189 | 1189 | ||
1190 | void KABCore::extensionChanged( int id ) | 1190 | void KABCore::extensionChanged( int id ) |
1191 | { | 1191 | { |
1192 | //change the details view only for non desktop systems | 1192 | //change the details view only for non desktop systems |
1193 | #ifndef DESKTOP_VERSION | 1193 | #ifndef DESKTOP_VERSION |
1194 | 1194 | ||
1195 | if (id == 0) | 1195 | if (id == 0) |
1196 | { | 1196 | { |
1197 | //the user disabled the extension. | 1197 | //the user disabled the extension. |
1198 | 1198 | ||
1199 | if (mMultipleViewsAtOnce) | 1199 | if (mMultipleViewsAtOnce) |
1200 | { // enable detailsview again | 1200 | { // enable detailsview again |
1201 | setDetailsVisible( true ); | 1201 | setDetailsVisible( true ); |
1202 | mActionDetails->setChecked( true ); | 1202 | mActionDetails->setChecked( true ); |
1203 | } | 1203 | } |
1204 | else | 1204 | else |
1205 | { //go back to the listview | 1205 | { //go back to the listview |
1206 | setDetailsVisible( false ); | 1206 | setDetailsVisible( false ); |
1207 | mActionDetails->setChecked( false ); | 1207 | mActionDetails->setChecked( false ); |
1208 | mActionDetails->setEnabled(true); | 1208 | mActionDetails->setEnabled(true); |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | } | 1211 | } |
1212 | else | 1212 | else |
1213 | { | 1213 | { |
1214 | //the user enabled the extension. | 1214 | //the user enabled the extension. |
1215 | setDetailsVisible( false ); | 1215 | setDetailsVisible( false ); |
1216 | mActionDetails->setChecked( false ); | 1216 | mActionDetails->setChecked( false ); |
1217 | 1217 | ||
1218 | if (!mMultipleViewsAtOnce) | 1218 | if (!mMultipleViewsAtOnce) |
1219 | { | 1219 | { |
1220 | mActionDetails->setEnabled(false); | 1220 | mActionDetails->setEnabled(false); |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | mExtensionManager->setSelectionChanged(); | 1223 | mExtensionManager->setSelectionChanged(); |
1224 | 1224 | ||
1225 | } | 1225 | } |
1226 | 1226 | ||
1227 | #endif// DESKTOP_VERSION | 1227 | #endif// DESKTOP_VERSION |
1228 | 1228 | ||
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | 1231 | ||
1232 | void KABCore::extensionModified( const KABC::Addressee::List &list ) | 1232 | void KABCore::extensionModified( const KABC::Addressee::List &list ) |
1233 | { | 1233 | { |
1234 | 1234 | ||
1235 | if ( list.count() != 0 ) { | 1235 | if ( list.count() != 0 ) { |
1236 | KABC::Addressee::List::ConstIterator it; | 1236 | KABC::Addressee::List::ConstIterator it; |
1237 | for ( it = list.begin(); it != list.end(); ++it ) | 1237 | for ( it = list.begin(); it != list.end(); ++it ) |
1238 | mAddressBook->insertAddressee( *it ); | 1238 | mAddressBook->insertAddressee( *it ); |
1239 | if ( list.count() > 1 ) | 1239 | if ( list.count() > 1 ) |
1240 | setModified(); | 1240 | setModified(); |
1241 | else | 1241 | else |
1242 | setModifiedWOrefresh(); | 1242 | setModifiedWOrefresh(); |
1243 | } | 1243 | } |
1244 | if ( list.count() == 0 ) | 1244 | if ( list.count() == 0 ) |
1245 | mViewManager->refreshView(); | 1245 | mViewManager->refreshView(); |
1246 | else | 1246 | else |
1247 | mViewManager->refreshView( list[ 0 ].uid() ); | 1247 | mViewManager->refreshView( list[ 0 ].uid() ); |
1248 | 1248 | ||
1249 | 1249 | ||
1250 | 1250 | ||
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | QString KABCore::getNameByPhone( const QString &phone ) | 1253 | QString KABCore::getNameByPhone( const QString &phone ) |
1254 | { | 1254 | { |
1255 | #ifndef KAB_EMBEDDED | 1255 | #ifndef KAB_EMBEDDED |
1256 | QRegExp r( "[/*/-/ ]" ); | 1256 | QRegExp r( "[/*/-/ ]" ); |
1257 | QString localPhone( phone ); | 1257 | QString localPhone( phone ); |
1258 | 1258 | ||
1259 | bool found = false; | 1259 | bool found = false; |
1260 | QString ownerName = ""; | 1260 | QString ownerName = ""; |
1261 | KABC::AddressBook::Iterator iter; | 1261 | KABC::AddressBook::Iterator iter; |
1262 | KABC::PhoneNumber::List::Iterator phoneIter; | 1262 | KABC::PhoneNumber::List::Iterator phoneIter; |
1263 | KABC::PhoneNumber::List phoneList; | 1263 | KABC::PhoneNumber::List phoneList; |
1264 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { | 1264 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { |
1265 | phoneList = (*iter).phoneNumbers(); | 1265 | phoneList = (*iter).phoneNumbers(); |
1266 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); | 1266 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); |
1267 | ++phoneIter) { | 1267 | ++phoneIter) { |
1268 | // Get rid of separator chars so just the numbers are compared. | 1268 | // Get rid of separator chars so just the numbers are compared. |
1269 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { | 1269 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { |
1270 | ownerName = (*iter).formattedName(); | 1270 | ownerName = (*iter).formattedName(); |
1271 | found = true; | 1271 | found = true; |
1272 | } | 1272 | } |
1273 | } | 1273 | } |
1274 | } | 1274 | } |
1275 | 1275 | ||
1276 | return ownerName; | 1276 | return ownerName; |
1277 | #else //KAB_EMBEDDED | 1277 | #else //KAB_EMBEDDED |
1278 | qDebug("KABCore::getNameByPhone finsih method"); | 1278 | qDebug("KABCore::getNameByPhone finsih method"); |
1279 | return ""; | 1279 | return ""; |
1280 | #endif //KAB_EMBEDDED | 1280 | #endif //KAB_EMBEDDED |
1281 | 1281 | ||
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | void KABCore::openConfigDialog() | 1284 | void KABCore::openConfigDialog() |
1285 | { | 1285 | { |
1286 | KABPrefs* kab_prefs = KABPrefs::instance(); | 1286 | KABPrefs* kab_prefs = KABPrefs::instance(); |
1287 | KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance(); | 1287 | KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance(); |
1288 | 1288 | ||
1289 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); | 1289 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); |
1290 | KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); | 1290 | KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); |
1291 | ConfigureDialog->addModule(kabcfg ); | 1291 | ConfigureDialog->addModule(kabcfg ); |
1292 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 1292 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
1293 | ConfigureDialog->addModule(kdelibcfg ); | 1293 | ConfigureDialog->addModule(kdelibcfg ); |
1294 | 1294 | ||
1295 | 1295 | ||
1296 | 1296 | ||
1297 | connect( ConfigureDialog, SIGNAL( applyClicked() ), | 1297 | connect( ConfigureDialog, SIGNAL( applyClicked() ), |
1298 | this, SLOT( configurationChanged() ) ); | 1298 | this, SLOT( configurationChanged() ) ); |
1299 | connect( ConfigureDialog, SIGNAL( okClicked() ), | 1299 | connect( ConfigureDialog, SIGNAL( okClicked() ), |
1300 | this, SLOT( configurationChanged() ) ); | 1300 | this, SLOT( configurationChanged() ) ); |
1301 | saveSettings(); | 1301 | saveSettings(); |
1302 | #ifndef DESKTOP_VERSION | 1302 | #ifndef DESKTOP_VERSION |
1303 | ConfigureDialog->showMaximized(); | 1303 | ConfigureDialog->showMaximized(); |
1304 | #endif | 1304 | #endif |
1305 | if ( ConfigureDialog->exec() ) | 1305 | if ( ConfigureDialog->exec() ) |
1306 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 1306 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
1307 | delete ConfigureDialog; | 1307 | delete ConfigureDialog; |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | void KABCore::openLDAPDialog() | 1310 | void KABCore::openLDAPDialog() |
1311 | { | 1311 | { |
1312 | #ifndef KAB_EMBEDDED | 1312 | #ifndef KAB_EMBEDDED |
1313 | if ( !mLdapSearchDialog ) { | 1313 | if ( !mLdapSearchDialog ) { |
1314 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); | 1314 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); |
1315 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, | 1315 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, |
1316 | SLOT( refreshView() ) ); | 1316 | SLOT( refreshView() ) ); |
1317 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, | 1317 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, |
1318 | SLOT( setModified() ) ); | 1318 | SLOT( setModified() ) ); |
1319 | } else | 1319 | } else |
1320 | mLdapSearchDialog->restoreSettings(); | 1320 | mLdapSearchDialog->restoreSettings(); |
1321 | 1321 | ||
1322 | if ( mLdapSearchDialog->isOK() ) | 1322 | if ( mLdapSearchDialog->isOK() ) |
1323 | mLdapSearchDialog->exec(); | 1323 | mLdapSearchDialog->exec(); |
1324 | #else //KAB_EMBEDDED | 1324 | #else //KAB_EMBEDDED |
1325 | qDebug("KABCore::openLDAPDialog() finsih method"); | 1325 | qDebug("KABCore::openLDAPDialog() finsih method"); |
1326 | #endif //KAB_EMBEDDED | 1326 | #endif //KAB_EMBEDDED |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | void KABCore::print() | 1329 | void KABCore::print() |
1330 | { | 1330 | { |
1331 | #ifndef KAB_EMBEDDED | 1331 | #ifndef KAB_EMBEDDED |
1332 | KPrinter printer; | 1332 | KPrinter printer; |
1333 | if ( !printer.setup( this ) ) | 1333 | if ( !printer.setup( this ) ) |
1334 | return; | 1334 | return; |
1335 | 1335 | ||
1336 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, | 1336 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, |
1337 | mViewManager->selectedUids(), this ); | 1337 | mViewManager->selectedUids(), this ); |
1338 | 1338 | ||
1339 | wizard.exec(); | 1339 | wizard.exec(); |
1340 | #else //KAB_EMBEDDED | 1340 | #else //KAB_EMBEDDED |
1341 | qDebug("KABCore::print() finsih method"); | 1341 | qDebug("KABCore::print() finsih method"); |
1342 | #endif //KAB_EMBEDDED | 1342 | #endif //KAB_EMBEDDED |
1343 | 1343 | ||
1344 | } | 1344 | } |
1345 | 1345 | ||
1346 | 1346 | ||
1347 | void KABCore::addGUIClient( KXMLGUIClient *client ) | 1347 | void KABCore::addGUIClient( KXMLGUIClient *client ) |
1348 | { | 1348 | { |
1349 | if ( mGUIClient ) | 1349 | if ( mGUIClient ) |
1350 | mGUIClient->insertChildClient( client ); | 1350 | mGUIClient->insertChildClient( client ); |
1351 | else | 1351 | else |
1352 | KMessageBox::error( this, "no KXMLGUICLient"); | 1352 | KMessageBox::error( this, "no KXMLGUICLient"); |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | 1355 | ||
1356 | void KABCore::configurationChanged() | 1356 | void KABCore::configurationChanged() |
1357 | { | 1357 | { |
1358 | mExtensionManager->reconfigure(); | 1358 | mExtensionManager->reconfigure(); |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | void KABCore::addressBookChanged() | 1361 | void KABCore::addressBookChanged() |
1362 | { | 1362 | { |
1363 | /*US | 1363 | /*US |
1364 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); | 1364 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); |
1365 | while ( it.current() ) { | 1365 | while ( it.current() ) { |
1366 | if ( it.current()->dirty() ) { | 1366 | if ( it.current()->dirty() ) { |
1367 | QString text = i18n( "Data has been changed externally. Unsaved " | 1367 | QString text = i18n( "Data has been changed externally. Unsaved " |
1368 | "changes will be lost." ); | 1368 | "changes will be lost." ); |
1369 | KMessageBox::information( this, text ); | 1369 | KMessageBox::information( this, text ); |
1370 | } | 1370 | } |
1371 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); | 1371 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); |
1372 | ++it; | 1372 | ++it; |
1373 | } | 1373 | } |
1374 | */ | 1374 | */ |
1375 | if (mEditorDialog) | 1375 | if (mEditorDialog) |
1376 | { | 1376 | { |
1377 | if (mEditorDialog->dirty()) | 1377 | if (mEditorDialog->dirty()) |
1378 | { | 1378 | { |
1379 | QString text = i18n( "Data has been changed externally. Unsaved " | 1379 | QString text = i18n( "Data has been changed externally. Unsaved " |
1380 | "changes will be lost." ); | 1380 | "changes will be lost." ); |
1381 | KMessageBox::information( this, text ); | 1381 | KMessageBox::information( this, text ); |
1382 | } | 1382 | } |
1383 | QString currentuid = mEditorDialog->addressee().uid(); | 1383 | QString currentuid = mEditorDialog->addressee().uid(); |
1384 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); | 1384 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); |
1385 | } | 1385 | } |
1386 | mViewManager->refreshView(); | 1386 | mViewManager->refreshView(); |
1387 | // mDetails->refreshView(); | 1387 | // mDetails->refreshView(); |
1388 | 1388 | ||
1389 | 1389 | ||
1390 | } | 1390 | } |
1391 | 1391 | ||
1392 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, | 1392 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, |
1393 | const char *name ) | 1393 | const char *name ) |
1394 | { | 1394 | { |
1395 | 1395 | ||
1396 | if ( mEditorDialog == 0 ) { | 1396 | if ( mEditorDialog == 0 ) { |
1397 | mEditorDialog = new AddresseeEditorDialog( this, parent, | 1397 | mEditorDialog = new AddresseeEditorDialog( this, parent, |
1398 | name ? name : "editorDialog" ); | 1398 | name ? name : "editorDialog" ); |
1399 | 1399 | ||
1400 | 1400 | ||
1401 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), | 1401 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), |
1402 | SLOT( contactModified( const KABC::Addressee& ) ) ); | 1402 | SLOT( contactModified( const KABC::Addressee& ) ) ); |
1403 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), | 1403 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), |
1404 | // SLOT( slotEditorDestroyed( const QString& ) ) ; | 1404 | // SLOT( slotEditorDestroyed( const QString& ) ) ; |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | return mEditorDialog; | 1407 | return mEditorDialog; |
1408 | } | 1408 | } |
1409 | 1409 | ||
1410 | void KABCore::slotEditorDestroyed( const QString &uid ) | 1410 | void KABCore::slotEditorDestroyed( const QString &uid ) |
1411 | { | 1411 | { |
1412 | //mEditorDict.remove( uid ); | 1412 | //mEditorDict.remove( uid ); |
1413 | } | 1413 | } |
1414 | 1414 | ||
1415 | void KABCore::initGUI() | 1415 | void KABCore::initGUI() |
1416 | { | 1416 | { |
1417 | #ifndef KAB_EMBEDDED | 1417 | #ifndef KAB_EMBEDDED |
1418 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1418 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1419 | topLayout->setSpacing( KDialogBase::spacingHint() ); | 1419 | topLayout->setSpacing( KDialogBase::spacingHint() ); |
1420 | 1420 | ||
1421 | mExtensionBarSplitter = new QSplitter( this ); | 1421 | mExtensionBarSplitter = new QSplitter( this ); |
1422 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); | 1422 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); |
1423 | 1423 | ||
1424 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); | 1424 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); |
1425 | 1425 | ||
1426 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1426 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1427 | mIncSearchWidget = new IncSearchWidget( viewSpace ); | 1427 | mIncSearchWidget = new IncSearchWidget( viewSpace ); |
1428 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1428 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1429 | SLOT( incrementalSearch( const QString& ) ) ); | 1429 | SLOT( incrementalSearch( const QString& ) ) ); |
1430 | 1430 | ||
1431 | mViewManager = new ViewManager( this, viewSpace ); | 1431 | mViewManager = new ViewManager( this, viewSpace ); |
1432 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1432 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1433 | 1433 | ||
1434 | mDetails = new ViewContainer( mDetailsSplitter ); | 1434 | mDetails = new ViewContainer( mDetailsSplitter ); |
1435 | 1435 | ||
1436 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1436 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1437 | 1437 | ||
1438 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1438 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1439 | 1439 | ||
1440 | topLayout->addWidget( mExtensionBarSplitter ); | 1440 | topLayout->addWidget( mExtensionBarSplitter ); |
1441 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); | 1441 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); |
1442 | topLayout->addWidget( mJumpButtonBar ); | 1442 | topLayout->addWidget( mJumpButtonBar ); |
1443 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); | 1443 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); |
1444 | 1444 | ||
1445 | mXXPortManager = new XXPortManager( this, this ); | 1445 | mXXPortManager = new XXPortManager( this, this ); |
1446 | 1446 | ||
1447 | #else //KAB_EMBEDDED | 1447 | #else //KAB_EMBEDDED |
1448 | //US initialize viewMenu before settingup viewmanager. | 1448 | //US initialize viewMenu before settingup viewmanager. |
1449 | // Viewmanager needs this menu to plugin submenues. | 1449 | // Viewmanager needs this menu to plugin submenues. |
1450 | viewMenu = new QPopupMenu( this ); | 1450 | viewMenu = new QPopupMenu( this ); |
1451 | settingsMenu = new QPopupMenu( this ); | 1451 | settingsMenu = new QPopupMenu( this ); |
1452 | //filterMenu = new QPopupMenu( this ); | 1452 | //filterMenu = new QPopupMenu( this ); |
1453 | ImportMenu = new QPopupMenu( this ); | 1453 | ImportMenu = new QPopupMenu( this ); |
1454 | ExportMenu = new QPopupMenu( this ); | 1454 | ExportMenu = new QPopupMenu( this ); |
1455 | syncMenu = new QPopupMenu( this ); | 1455 | syncMenu = new QPopupMenu( this ); |
1456 | changeMenu= new QPopupMenu( this ); | 1456 | changeMenu= new QPopupMenu( this ); |
1457 | 1457 | ||
1458 | //US since we have no splitter for the embedded system, setup | 1458 | //US since we have no splitter for the embedded system, setup |
1459 | // a layout with two frames. One left and one right. | 1459 | // a layout with two frames. One left and one right. |
1460 | 1460 | ||
1461 | QBoxLayout *topLayout; | 1461 | QBoxLayout *topLayout; |
1462 | 1462 | ||
1463 | // = new QHBoxLayout( this ); | 1463 | // = new QHBoxLayout( this ); |
1464 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); | 1464 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); |
1465 | 1465 | ||
1466 | // QWidget *mainBox = new QWidget( this ); | 1466 | // QWidget *mainBox = new QWidget( this ); |
1467 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); | 1467 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); |
1468 | 1468 | ||
1469 | #ifdef DESKTOP_VERSION | 1469 | #ifdef DESKTOP_VERSION |
1470 | topLayout = new QHBoxLayout( this ); | 1470 | topLayout = new QHBoxLayout( this ); |
1471 | 1471 | ||
1472 | 1472 | ||
1473 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1473 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1474 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1474 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1475 | 1475 | ||
1476 | topLayout->addWidget(mMiniSplitter ); | 1476 | topLayout->addWidget(mMiniSplitter ); |
1477 | 1477 | ||
1478 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); | 1478 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); |
1479 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1479 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1480 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); | 1480 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); |
1481 | mDetails = new ViewContainer( mMiniSplitter ); | 1481 | mDetails = new ViewContainer( mMiniSplitter ); |
1482 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1482 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1483 | #else | 1483 | #else |
1484 | if ( QApplication::desktop()->width() > 480 ) { | 1484 | if ( QApplication::desktop()->width() > 480 ) { |
1485 | topLayout = new QHBoxLayout( this ); | 1485 | topLayout = new QHBoxLayout( this ); |
1486 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1486 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1487 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1487 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1488 | } else { | 1488 | } else { |
1489 | 1489 | ||
1490 | topLayout = new QHBoxLayout( this ); | 1490 | topLayout = new QHBoxLayout( this ); |
1491 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 1491 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
1492 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1492 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1493 | } | 1493 | } |
1494 | 1494 | ||
1495 | topLayout->addWidget(mMiniSplitter ); | 1495 | topLayout->addWidget(mMiniSplitter ); |
1496 | mViewManager = new ViewManager( this, mMiniSplitter ); | 1496 | mViewManager = new ViewManager( this, mMiniSplitter ); |
1497 | mDetails = new ViewContainer( mMiniSplitter ); | 1497 | mDetails = new ViewContainer( mMiniSplitter ); |
1498 | 1498 | ||
1499 | 1499 | ||
1500 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); | 1500 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); |
1501 | #endif | 1501 | #endif |
1502 | //eh->hide(); | 1502 | //eh->hide(); |
1503 | // topLayout->addWidget(mExtensionManager ); | 1503 | // topLayout->addWidget(mExtensionManager ); |
1504 | 1504 | ||
1505 | 1505 | ||
1506 | /*US | 1506 | /*US |
1507 | #ifndef KAB_NOSPLITTER | 1507 | #ifndef KAB_NOSPLITTER |
1508 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1508 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1509 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1509 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1510 | topLayout->setSpacing( 10 ); | 1510 | topLayout->setSpacing( 10 ); |
1511 | 1511 | ||
1512 | mDetailsSplitter = new QSplitter( this ); | 1512 | mDetailsSplitter = new QSplitter( this ); |
1513 | 1513 | ||
1514 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1514 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1515 | 1515 | ||
1516 | mViewManager = new ViewManager( this, viewSpace ); | 1516 | mViewManager = new ViewManager( this, viewSpace ); |
1517 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1517 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1518 | 1518 | ||
1519 | mDetails = new ViewContainer( mDetailsSplitter ); | 1519 | mDetails = new ViewContainer( mDetailsSplitter ); |
1520 | 1520 | ||
1521 | topLayout->addWidget( mDetailsSplitter ); | 1521 | topLayout->addWidget( mDetailsSplitter ); |
1522 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1522 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1523 | #else //KAB_NOSPLITTER | 1523 | #else //KAB_NOSPLITTER |
1524 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1524 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1525 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1525 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1526 | topLayout->setSpacing( 10 ); | 1526 | topLayout->setSpacing( 10 ); |
1527 | 1527 | ||
1528 | // mDetailsSplitter = new QSplitter( this ); | 1528 | // mDetailsSplitter = new QSplitter( this ); |
1529 | 1529 | ||
1530 | QVBox *viewSpace = new QVBox( this ); | 1530 | QVBox *viewSpace = new QVBox( this ); |
1531 | 1531 | ||
1532 | mViewManager = new ViewManager( this, viewSpace ); | 1532 | mViewManager = new ViewManager( this, viewSpace ); |
1533 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1533 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1534 | 1534 | ||
1535 | mDetails = new ViewContainer( this ); | 1535 | mDetails = new ViewContainer( this ); |
1536 | 1536 | ||
1537 | topLayout->addWidget( viewSpace ); | 1537 | topLayout->addWidget( viewSpace ); |
1538 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1538 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1539 | topLayout->addWidget( mDetails ); | 1539 | topLayout->addWidget( mDetails ); |
1540 | #endif //KAB_NOSPLITTER | 1540 | #endif //KAB_NOSPLITTER |
1541 | */ | 1541 | */ |
1542 | 1542 | ||
1543 | 1543 | ||
1544 | #endif //KAB_EMBEDDED | 1544 | #endif //KAB_EMBEDDED |
1545 | initActions(); | 1545 | initActions(); |
1546 | 1546 | ||
1547 | #ifdef KAB_EMBEDDED | 1547 | #ifdef KAB_EMBEDDED |
1548 | addActionsManually(); | 1548 | addActionsManually(); |
1549 | //US make sure the export and import menues are initialized before creating the xxPortManager. | 1549 | //US make sure the export and import menues are initialized before creating the xxPortManager. |
1550 | mXXPortManager = new XXPortManager( this, this ); | 1550 | mXXPortManager = new XXPortManager( this, this ); |
1551 | 1551 | ||
1552 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); | 1552 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); |
1553 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); | 1553 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); |
1554 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1554 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1555 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); | 1555 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); |
1556 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); | 1556 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); |
1557 | // mIncSearchWidget->hide(); | 1557 | // mIncSearchWidget->hide(); |
1558 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1558 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1559 | SLOT( incrementalSearch( const QString& ) ) ); | 1559 | SLOT( incrementalSearch( const QString& ) ) ); |
1560 | 1560 | ||
1561 | 1561 | ||
1562 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1562 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1563 | 1563 | ||
1564 | topLayout->addWidget( mJumpButtonBar ); | 1564 | topLayout->addWidget( mJumpButtonBar ); |
1565 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); | 1565 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); |
1566 | 1566 | ||
1567 | // mMainWindow->getIconToolBar()->raise(); | 1567 | // mMainWindow->getIconToolBar()->raise(); |
1568 | 1568 | ||
1569 | #endif //KAB_EMBEDDED | 1569 | #endif //KAB_EMBEDDED |
1570 | 1570 | ||
1571 | } | 1571 | } |
1572 | void KABCore::initActions() | 1572 | void KABCore::initActions() |
1573 | { | 1573 | { |
1574 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1574 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1575 | 1575 | ||
1576 | #ifndef KAB_EMBEDDED | 1576 | #ifndef KAB_EMBEDDED |
1577 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), | 1577 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), |
1578 | SLOT( clipboardDataChanged() ) ); | 1578 | SLOT( clipboardDataChanged() ) ); |
1579 | #endif //KAB_EMBEDDED | 1579 | #endif //KAB_EMBEDDED |
1580 | 1580 | ||
1581 | // file menu | 1581 | // file menu |
1582 | if ( mIsPart ) { | 1582 | if ( mIsPart ) { |
1583 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, | 1583 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, |
1584 | SLOT( sendMail() ), actionCollection(), | 1584 | SLOT( sendMail() ), actionCollection(), |
1585 | "kaddressbook_mail" ); | 1585 | "kaddressbook_mail" ); |
1586 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, | 1586 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, |
1587 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); | 1587 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); |
1588 | 1588 | ||
1589 | } else { | 1589 | } else { |
1590 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); | 1590 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); |
1591 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); | 1591 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); |
1592 | } | 1592 | } |
1593 | 1593 | ||
1594 | 1594 | ||
1595 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1595 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
1596 | SLOT( save() ), actionCollection(), "file_sync" ); | 1596 | SLOT( save() ), actionCollection(), "file_sync" ); |
1597 | 1597 | ||
1598 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, | 1598 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, |
1599 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1599 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1600 | 1600 | ||
1601 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1601 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1602 | this, SLOT( mailVCard() ), | 1602 | this, SLOT( mailVCard() ), |
1603 | actionCollection(), "file_mail_vcard"); | 1603 | actionCollection(), "file_mail_vcard"); |
1604 | 1604 | ||
1605 | mActionBeamVCard = 0; | 1605 | mActionBeamVCard = 0; |
1606 | mActionBeam = 0; | 1606 | mActionBeam = 0; |
1607 | 1607 | ||
1608 | #ifndef DESKTOP_VERSION | 1608 | #ifndef DESKTOP_VERSION |
1609 | if ( Ir::supported() ) { | 1609 | if ( Ir::supported() ) { |
1610 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, | 1610 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, |
1611 | SLOT( beamVCard() ), actionCollection(), | 1611 | SLOT( beamVCard() ), actionCollection(), |
1612 | "kaddressbook_beam_vcard" ); | 1612 | "kaddressbook_beam_vcard" ); |
1613 | 1613 | ||
1614 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, | 1614 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, |
1615 | SLOT( beamMySelf() ), actionCollection(), | 1615 | SLOT( beamMySelf() ), actionCollection(), |
1616 | "kaddressbook_beam_myself" ); | 1616 | "kaddressbook_beam_myself" ); |
1617 | } | 1617 | } |
1618 | #endif | 1618 | #endif |
1619 | 1619 | ||
1620 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1620 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
1621 | this, SLOT( editContact2() ), | 1621 | this, SLOT( editContact2() ), |
1622 | actionCollection(), "file_properties" ); | 1622 | actionCollection(), "file_properties" ); |
1623 | 1623 | ||
1624 | #ifdef KAB_EMBEDDED | 1624 | #ifdef KAB_EMBEDDED |
1625 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); | 1625 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); |
1626 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, | 1626 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, |
1627 | mMainWindow, SLOT( exit() ), | 1627 | mMainWindow, SLOT( exit() ), |
1628 | actionCollection(), "quit" ); | 1628 | actionCollection(), "quit" ); |
1629 | #endif //KAB_EMBEDDED | 1629 | #endif //KAB_EMBEDDED |
1630 | 1630 | ||
1631 | // edit menu | 1631 | // edit menu |
1632 | if ( mIsPart ) { | 1632 | if ( mIsPart ) { |
1633 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, | 1633 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, |
1634 | SLOT( copyContacts() ), actionCollection(), | 1634 | SLOT( copyContacts() ), actionCollection(), |
1635 | "kaddressbook_copy" ); | 1635 | "kaddressbook_copy" ); |
1636 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, | 1636 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, |
1637 | SLOT( cutContacts() ), actionCollection(), | 1637 | SLOT( cutContacts() ), actionCollection(), |
1638 | "kaddressbook_cut" ); | 1638 | "kaddressbook_cut" ); |
1639 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, | 1639 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, |
1640 | SLOT( pasteContacts() ), actionCollection(), | 1640 | SLOT( pasteContacts() ), actionCollection(), |
1641 | "kaddressbook_paste" ); | 1641 | "kaddressbook_paste" ); |
1642 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, | 1642 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, |
1643 | SLOT( selectAllContacts() ), actionCollection(), | 1643 | SLOT( selectAllContacts() ), actionCollection(), |
1644 | "kaddressbook_select_all" ); | 1644 | "kaddressbook_select_all" ); |
1645 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, | 1645 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, |
1646 | SLOT( undo() ), actionCollection(), | 1646 | SLOT( undo() ), actionCollection(), |
1647 | "kaddressbook_undo" ); | 1647 | "kaddressbook_undo" ); |
1648 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, | 1648 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, |
1649 | this, SLOT( redo() ), actionCollection(), | 1649 | this, SLOT( redo() ), actionCollection(), |
1650 | "kaddressbook_redo" ); | 1650 | "kaddressbook_redo" ); |
1651 | } else { | 1651 | } else { |
1652 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); | 1652 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); |
1653 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); | 1653 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); |
1654 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); | 1654 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); |
1655 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); | 1655 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); |
1656 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); | 1656 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); |
1657 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); | 1657 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); |
1658 | } | 1658 | } |
1659 | 1659 | ||
1660 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", | 1660 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", |
1661 | Key_Delete, this, SLOT( deleteContacts() ), | 1661 | Key_Delete, this, SLOT( deleteContacts() ), |
1662 | actionCollection(), "edit_delete" ); | 1662 | actionCollection(), "edit_delete" ); |
1663 | 1663 | ||
1664 | mActionUndo->setEnabled( false ); | 1664 | mActionUndo->setEnabled( false ); |
1665 | mActionRedo->setEnabled( false ); | 1665 | mActionRedo->setEnabled( false ); |
1666 | 1666 | ||
1667 | // settings menu | 1667 | // settings menu |
1668 | #ifdef KAB_EMBEDDED | 1668 | #ifdef KAB_EMBEDDED |
1669 | //US special menuentry to configure the addressbook resources. On KDE | 1669 | //US special menuentry to configure the addressbook resources. On KDE |
1670 | // you do that through the control center !!! | 1670 | // you do that through the control center !!! |
1671 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, | 1671 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, |
1672 | SLOT( configureResources() ), actionCollection(), | 1672 | SLOT( configureResources() ), actionCollection(), |
1673 | "kaddressbook_configure_resources" ); | 1673 | "kaddressbook_configure_resources" ); |
1674 | #endif //KAB_EMBEDDED | 1674 | #endif //KAB_EMBEDDED |
1675 | 1675 | ||
1676 | if ( mIsPart ) { | 1676 | if ( mIsPart ) { |
1677 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, | 1677 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, |
1678 | SLOT( openConfigDialog() ), actionCollection(), | 1678 | SLOT( openConfigDialog() ), actionCollection(), |
1679 | "kaddressbook_configure" ); | 1679 | "kaddressbook_configure" ); |
1680 | 1680 | ||
1681 | mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, | 1681 | mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, |
1682 | this, SLOT( configureKeyBindings() ), actionCollection(), | 1682 | this, SLOT( configureKeyBindings() ), actionCollection(), |
1683 | "kaddressbook_configure_shortcuts" ); | 1683 | "kaddressbook_configure_shortcuts" ); |
1684 | #ifdef KAB_EMBEDDED | 1684 | #ifdef KAB_EMBEDDED |
1685 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); | 1685 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); |
1686 | mActionConfigureToolbars->setEnabled( false ); | 1686 | mActionConfigureToolbars->setEnabled( false ); |
1687 | #endif //KAB_EMBEDDED | 1687 | #endif //KAB_EMBEDDED |
1688 | 1688 | ||
1689 | } else { | 1689 | } else { |
1690 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); | 1690 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); |
1691 | 1691 | ||
1692 | mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); | 1692 | mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); |
1693 | } | 1693 | } |
1694 | 1694 | ||
1695 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, | 1695 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, |
1696 | actionCollection(), "options_show_jump_bar" ); | 1696 | actionCollection(), "options_show_jump_bar" ); |
1697 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); | 1697 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); |
1698 | 1698 | ||
1699 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, | 1699 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, |
1700 | actionCollection(), "options_show_details" ); | 1700 | actionCollection(), "options_show_details" ); |
1701 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); | 1701 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); |
1702 | 1702 | ||
1703 | // misc | 1703 | // misc |
1704 | // only enable LDAP lookup if we can handle the protocol | 1704 | // only enable LDAP lookup if we can handle the protocol |
1705 | #ifndef KAB_EMBEDDED | 1705 | #ifndef KAB_EMBEDDED |
1706 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { | 1706 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { |
1707 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, | 1707 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, |
1708 | this, SLOT( openLDAPDialog() ), actionCollection(), | 1708 | this, SLOT( openLDAPDialog() ), actionCollection(), |
1709 | "ldap_lookup" ); | 1709 | "ldap_lookup" ); |
1710 | } | 1710 | } |
1711 | #else //KAB_EMBEDDED | 1711 | #else //KAB_EMBEDDED |
1712 | //qDebug("KABCore::initActions() LDAP has to be implemented"); | 1712 | //qDebug("KABCore::initActions() LDAP has to be implemented"); |
1713 | #endif //KAB_EMBEDDED | 1713 | #endif //KAB_EMBEDDED |
1714 | 1714 | ||
1715 | 1715 | ||
1716 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1716 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1717 | SLOT( setWhoAmI() ), actionCollection(), | 1717 | SLOT( setWhoAmI() ), actionCollection(), |
1718 | "set_personal" ); | 1718 | "set_personal" ); |
1719 | 1719 | ||
1720 | 1720 | ||
1721 | 1721 | ||
1722 | 1722 | ||
1723 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1723 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1724 | SLOT( setCategories() ), actionCollection(), | 1724 | SLOT( setCategories() ), actionCollection(), |
1725 | "edit_set_categories" ); | 1725 | "edit_set_categories" ); |
1726 | 1726 | ||
1727 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1727 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1728 | SLOT( removeVoice() ), actionCollection(), | 1728 | SLOT( removeVoice() ), actionCollection(), |
1729 | "remove_voice" ); | 1729 | "remove_voice" ); |
1730 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, | 1730 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, |
1731 | SLOT( importFromOL() ), actionCollection(), | 1731 | SLOT( importFromOL() ), actionCollection(), |
1732 | "import_OL" ); | 1732 | "import_OL" ); |
1733 | #ifdef KAB_EMBEDDED | 1733 | #ifdef KAB_EMBEDDED |
1734 | mActionLicence = new KAction( i18n( "Licence" ), 0, | 1734 | mActionLicence = new KAction( i18n( "Licence" ), 0, |
1735 | this, SLOT( showLicence() ), actionCollection(), | 1735 | this, SLOT( showLicence() ), actionCollection(), |
1736 | "licence_about_data" ); | 1736 | "licence_about_data" ); |
1737 | mActionFaq = new KAction( i18n( "Faq" ), 0, | 1737 | mActionFaq = new KAction( i18n( "Faq" ), 0, |
1738 | this, SLOT( faq() ), actionCollection(), | 1738 | this, SLOT( faq() ), actionCollection(), |
1739 | "faq_about_data" ); | 1739 | "faq_about_data" ); |
1740 | 1740 | ||
1741 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, | 1741 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, |
1742 | this, SLOT( createAboutData() ), actionCollection(), | 1742 | this, SLOT( createAboutData() ), actionCollection(), |
1743 | "kaddressbook_about_data" ); | 1743 | "kaddressbook_about_data" ); |
1744 | #endif //KAB_EMBEDDED | 1744 | #endif //KAB_EMBEDDED |
1745 | 1745 | ||
1746 | clipboardDataChanged(); | 1746 | clipboardDataChanged(); |
1747 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1747 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1748 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1748 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1749 | } | 1749 | } |
1750 | 1750 | ||
1751 | //US we need this function, to plug all actions into the correct menues. | 1751 | //US we need this function, to plug all actions into the correct menues. |
1752 | // KDE uses a XML format to plug the actions, but we work her without this overhead. | 1752 | // KDE uses a XML format to plug the actions, but we work her without this overhead. |
1753 | void KABCore::addActionsManually() | 1753 | void KABCore::addActionsManually() |
1754 | { | 1754 | { |
1755 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1755 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1756 | 1756 | ||
1757 | #ifdef KAB_EMBEDDED | 1757 | #ifdef KAB_EMBEDDED |
1758 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 1758 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
1759 | QPopupMenu *editMenu = new QPopupMenu( this ); | 1759 | QPopupMenu *editMenu = new QPopupMenu( this ); |
1760 | QPopupMenu *helpMenu = new QPopupMenu( this ); | 1760 | QPopupMenu *helpMenu = new QPopupMenu( this ); |
1761 | 1761 | ||
1762 | KToolBar* tb = mMainWindow->toolBar(); | 1762 | KToolBar* tb = mMainWindow->toolBar(); |
1763 | 1763 | ||
1764 | #ifdef DESKTOP_VERSION | 1764 | #ifdef DESKTOP_VERSION |
1765 | QMenuBar* mb = mMainWindow->menuBar(); | 1765 | QMenuBar* mb = mMainWindow->menuBar(); |
1766 | 1766 | ||
1767 | //US setup menubar. | 1767 | //US setup menubar. |
1768 | //Disable the following block if you do not want to have a menubar. | 1768 | //Disable the following block if you do not want to have a menubar. |
1769 | mb->insertItem( "&File", fileMenu ); | 1769 | mb->insertItem( "&File", fileMenu ); |
1770 | mb->insertItem( "&Edit", editMenu ); | 1770 | mb->insertItem( "&Edit", editMenu ); |
1771 | mb->insertItem( "&View", viewMenu ); | 1771 | mb->insertItem( "&View", viewMenu ); |
1772 | mb->insertItem( "&Settings", settingsMenu ); | 1772 | mb->insertItem( "&Settings", settingsMenu ); |
1773 | mb->insertItem( i18n("Synchronize"), syncMenu ); | 1773 | mb->insertItem( i18n("Synchronize"), syncMenu ); |
1774 | mb->insertItem( "&Change selected", changeMenu ); | 1774 | mb->insertItem( "&Change selected", changeMenu ); |
1775 | mb->insertItem( "&Help", helpMenu ); | 1775 | mb->insertItem( "&Help", helpMenu ); |
1776 | mIncSearchWidget = new IncSearchWidget( tb ); | 1776 | mIncSearchWidget = new IncSearchWidget( tb ); |
1777 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 1777 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
1778 | 1778 | ||
1779 | #else | 1779 | #else |
1780 | //US setup toolbar | 1780 | //US setup toolbar |
1781 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); | 1781 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); |
1782 | QPopupMenu *popupBarTB = new QPopupMenu( this ); | 1782 | QPopupMenu *popupBarTB = new QPopupMenu( this ); |
1783 | menuBarTB->insertItem( "ME", popupBarTB); | 1783 | menuBarTB->insertItem( "ME", popupBarTB); |
1784 | tb->insertWidget(-1, 0, menuBarTB); | 1784 | tb->insertWidget(-1, 0, menuBarTB); |
1785 | mIncSearchWidget = new IncSearchWidget( tb ); | 1785 | mIncSearchWidget = new IncSearchWidget( tb ); |
1786 | 1786 | ||
1787 | tb->enableMoving(false); | 1787 | tb->enableMoving(false); |
1788 | popupBarTB->insertItem( "&File", fileMenu ); | 1788 | popupBarTB->insertItem( "&File", fileMenu ); |
1789 | popupBarTB->insertItem( "&Edit", editMenu ); | 1789 | popupBarTB->insertItem( "&Edit", editMenu ); |
1790 | popupBarTB->insertItem( "&View", viewMenu ); | 1790 | popupBarTB->insertItem( "&View", viewMenu ); |
1791 | popupBarTB->insertItem( "&Settings", settingsMenu ); | 1791 | popupBarTB->insertItem( "&Settings", settingsMenu ); |
1792 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | 1792 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); |
1793 | mViewManager->getFilterAction()->plug ( popupBarTB); | 1793 | mViewManager->getFilterAction()->plug ( popupBarTB); |
1794 | popupBarTB->insertItem( "&Change selected", changeMenu ); | 1794 | popupBarTB->insertItem( "&Change selected", changeMenu ); |
1795 | popupBarTB->insertItem( "&Help", helpMenu ); | 1795 | popupBarTB->insertItem( "&Help", helpMenu ); |
1796 | if (QApplication::desktop()->width() > 320 ) { | 1796 | if (QApplication::desktop()->width() > 320 ) { |
1797 | // mViewManager->getFilterAction()->plug ( tb); | 1797 | // mViewManager->getFilterAction()->plug ( tb); |
1798 | } | 1798 | } |
1799 | #endif | 1799 | #endif |
1800 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1800 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1801 | 1801 | ||
1802 | 1802 | ||
1803 | 1803 | ||
1804 | //US Now connect the actions with the menue entries. | 1804 | //US Now connect the actions with the menue entries. |
1805 | mActionPrint->plug( fileMenu ); | 1805 | mActionPrint->plug( fileMenu ); |
1806 | mActionMail->plug( fileMenu ); | 1806 | mActionMail->plug( fileMenu ); |
1807 | fileMenu->insertSeparator(); | 1807 | fileMenu->insertSeparator(); |
1808 | 1808 | ||
1809 | mActionNewContact->plug( fileMenu ); | 1809 | mActionNewContact->plug( fileMenu ); |
1810 | mActionNewContact->plug( tb ); | 1810 | mActionNewContact->plug( tb ); |
1811 | 1811 | ||
1812 | mActionEditAddressee->plug( fileMenu ); | 1812 | mActionEditAddressee->plug( fileMenu ); |
1813 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || | 1813 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || |
1814 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) | 1814 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) |
1815 | mActionEditAddressee->plug( tb ); | 1815 | mActionEditAddressee->plug( tb ); |
1816 | 1816 | ||
1817 | fileMenu->insertSeparator(); | 1817 | fileMenu->insertSeparator(); |
1818 | mActionSave->plug( fileMenu ); | 1818 | mActionSave->plug( fileMenu ); |
1819 | fileMenu->insertItem( "&Import", ImportMenu ); | 1819 | fileMenu->insertItem( "&Import", ImportMenu ); |
1820 | fileMenu->insertItem( "&Export", ExportMenu ); | 1820 | fileMenu->insertItem( "&Export", ExportMenu ); |
1821 | fileMenu->insertSeparator(); | 1821 | fileMenu->insertSeparator(); |
1822 | mActionMailVCard->plug( fileMenu ); | 1822 | mActionMailVCard->plug( fileMenu ); |
1823 | #ifndef DESKTOP_VERSION | 1823 | #ifndef DESKTOP_VERSION |
1824 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); | 1824 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); |
1825 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); | 1825 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); |
1826 | #endif | 1826 | #endif |
1827 | fileMenu->insertSeparator(); | 1827 | fileMenu->insertSeparator(); |
1828 | mActionQuit->plug( fileMenu ); | 1828 | mActionQuit->plug( fileMenu ); |
1829 | #ifdef _WIN32_ | 1829 | #ifdef _WIN32_ |
1830 | mActionImportOL->plug( ImportMenu ); | 1830 | mActionImportOL->plug( ImportMenu ); |
1831 | #endif | 1831 | #endif |
1832 | // edit menu | 1832 | // edit menu |
1833 | mActionUndo->plug( editMenu ); | 1833 | mActionUndo->plug( editMenu ); |
1834 | mActionRedo->plug( editMenu ); | 1834 | mActionRedo->plug( editMenu ); |
1835 | editMenu->insertSeparator(); | 1835 | editMenu->insertSeparator(); |
1836 | mActionCut->plug( editMenu ); | 1836 | mActionCut->plug( editMenu ); |
1837 | mActionCopy->plug( editMenu ); | 1837 | mActionCopy->plug( editMenu ); |
1838 | mActionPaste->plug( editMenu ); | 1838 | mActionPaste->plug( editMenu ); |
1839 | mActionDelete->plug( editMenu ); | 1839 | mActionDelete->plug( editMenu ); |
1840 | editMenu->insertSeparator(); | 1840 | editMenu->insertSeparator(); |
1841 | mActionSelectAll->plug( editMenu ); | 1841 | mActionSelectAll->plug( editMenu ); |
1842 | 1842 | ||
1843 | mActionRemoveVoice->plug( changeMenu ); | 1843 | mActionRemoveVoice->plug( changeMenu ); |
1844 | // settings menu | 1844 | // settings menu |
1845 | //US special menuentry to configure the addressbook resources. On KDE | 1845 | //US special menuentry to configure the addressbook resources. On KDE |
1846 | // you do that through the control center !!! | 1846 | // you do that through the control center !!! |
1847 | mActionConfigResources->plug( settingsMenu ); | 1847 | mActionConfigResources->plug( settingsMenu ); |
1848 | settingsMenu->insertSeparator(); | 1848 | settingsMenu->insertSeparator(); |
1849 | 1849 | ||
1850 | mActionConfigKAddressbook->plug( settingsMenu ); | 1850 | mActionConfigKAddressbook->plug( settingsMenu ); |
1851 | 1851 | ||
1852 | if ( mIsPart ) { | 1852 | if ( mIsPart ) { |
1853 | mActionConfigShortcuts->plug( settingsMenu ); | 1853 | mActionConfigShortcuts->plug( settingsMenu ); |
1854 | mActionConfigureToolbars->plug( settingsMenu ); | 1854 | mActionConfigureToolbars->plug( settingsMenu ); |
1855 | 1855 | ||
1856 | } else { | 1856 | } else { |
1857 | mActionKeyBindings->plug( settingsMenu ); | 1857 | mActionKeyBindings->plug( settingsMenu ); |
1858 | } | 1858 | } |
1859 | 1859 | ||
1860 | settingsMenu->insertSeparator(); | 1860 | settingsMenu->insertSeparator(); |
1861 | 1861 | ||
1862 | mActionJumpBar->plug( settingsMenu ); | 1862 | mActionJumpBar->plug( settingsMenu ); |
1863 | mActionDetails->plug( settingsMenu ); | 1863 | mActionDetails->plug( settingsMenu ); |
1864 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 1864 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
1865 | mActionDetails->plug( tb ); | 1865 | mActionDetails->plug( tb ); |
1866 | settingsMenu->insertSeparator(); | 1866 | settingsMenu->insertSeparator(); |
1867 | 1867 | ||
1868 | mActionWhoAmI->plug( settingsMenu ); | 1868 | mActionWhoAmI->plug( settingsMenu ); |
1869 | mActionCategories->plug( settingsMenu ); | 1869 | mActionCategories->plug( settingsMenu ); |
1870 | 1870 | ||
1871 | mActionLicence->plug( helpMenu ); | 1871 | mActionLicence->plug( helpMenu ); |
1872 | mActionFaq->plug( helpMenu ); | 1872 | mActionFaq->plug( helpMenu ); |
1873 | mActionAboutKAddressbook->plug( helpMenu ); | 1873 | mActionAboutKAddressbook->plug( helpMenu ); |
1874 | 1874 | ||
1875 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { | 1875 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { |
1876 | 1876 | ||
1877 | mActionSave->plug( tb ); | 1877 | mActionSave->plug( tb ); |
1878 | mViewManager->getFilterAction()->plug ( tb); | 1878 | mViewManager->getFilterAction()->plug ( tb); |
1879 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { | 1879 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { |
1880 | mActionUndo->plug( tb ); | 1880 | mActionUndo->plug( tb ); |
1881 | mActionDelete->plug( tb ); | 1881 | mActionDelete->plug( tb ); |
1882 | mActionRedo->plug( tb ); | 1882 | mActionRedo->plug( tb ); |
1883 | } | 1883 | } |
1884 | } | 1884 | } |
1885 | //mActionQuit->plug ( tb ); | 1885 | //mActionQuit->plug ( tb ); |
1886 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); | 1886 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); |
1887 | 1887 | ||
1888 | //US link the searchwidget first to this. | 1888 | //US link the searchwidget first to this. |
1889 | // The real linkage to the toolbar happens later. | 1889 | // The real linkage to the toolbar happens later. |
1890 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); | 1890 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); |
1891 | //US tb->insertItem( mIncSearchWidget ); | 1891 | //US tb->insertItem( mIncSearchWidget ); |
1892 | /*US | 1892 | /*US |
1893 | mIncSearchWidget = new IncSearchWidget( tb ); | 1893 | mIncSearchWidget = new IncSearchWidget( tb ); |
1894 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1894 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1895 | SLOT( incrementalSearch( const QString& ) ) ); | 1895 | SLOT( incrementalSearch( const QString& ) ) ); |
1896 | 1896 | ||
1897 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1897 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1898 | 1898 | ||
1899 | //US topLayout->addWidget( mJumpButtonBar ); | 1899 | //US topLayout->addWidget( mJumpButtonBar ); |
1900 | this->layout()->add( mJumpButtonBar ); | 1900 | this->layout()->add( mJumpButtonBar ); |
1901 | */ | 1901 | */ |
1902 | 1902 | ||
1903 | #endif //KAB_EMBEDDED | 1903 | #endif //KAB_EMBEDDED |
1904 | 1904 | ||
1905 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); | 1905 | connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); |
1906 | fillSyncMenu(); | 1906 | fillSyncMenu(); |
1907 | 1907 | ||
1908 | } | 1908 | } |
1909 | void KABCore::showLicence() | 1909 | void KABCore::showLicence() |
1910 | { | 1910 | { |
1911 | KApplication::showLicence(); | 1911 | KApplication::showLicence(); |
1912 | } | 1912 | } |
1913 | void KABCore::removeVoice() | 1913 | void KABCore::removeVoice() |
1914 | { | 1914 | { |
1915 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) | 1915 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) |
1916 | return; | 1916 | return; |
1917 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 1917 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
1918 | KABC::Addressee::List::Iterator it; | 1918 | KABC::Addressee::List::Iterator it; |
1919 | for ( it = list.begin(); it != list.end(); ++it ) { | 1919 | for ( it = list.begin(); it != list.end(); ++it ) { |
1920 | PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); | 1920 | PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); |
1921 | PhoneNumber::List::Iterator phoneIt; | 1921 | PhoneNumber::List::Iterator phoneIt; |
1922 | bool found = false; | 1922 | bool found = false; |
1923 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { | 1923 | for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { |
1924 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 1924 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
1925 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 1925 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
1926 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 1926 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
1927 | (*it).insertPhoneNumber( (*phoneIt) ); | 1927 | (*it).insertPhoneNumber( (*phoneIt) ); |
1928 | found = true; | 1928 | found = true; |
1929 | } | 1929 | } |
1930 | } | 1930 | } |
1931 | 1931 | ||
1932 | } | 1932 | } |
1933 | if ( found ) | 1933 | if ( found ) |
1934 | contactModified((*it) ); | 1934 | contactModified((*it) ); |
1935 | } | 1935 | } |
1936 | } | 1936 | } |
1937 | 1937 | ||
1938 | 1938 | ||
1939 | 1939 | ||
1940 | void KABCore::clipboardDataChanged() | 1940 | void KABCore::clipboardDataChanged() |
1941 | { | 1941 | { |
1942 | 1942 | ||
1943 | if ( mReadWrite ) | 1943 | if ( mReadWrite ) |
1944 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); | 1944 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); |
1945 | 1945 | ||
1946 | } | 1946 | } |
1947 | 1947 | ||
1948 | void KABCore::updateActionMenu() | 1948 | void KABCore::updateActionMenu() |
1949 | { | 1949 | { |
1950 | UndoStack *undo = UndoStack::instance(); | 1950 | UndoStack *undo = UndoStack::instance(); |
1951 | RedoStack *redo = RedoStack::instance(); | 1951 | RedoStack *redo = RedoStack::instance(); |
1952 | 1952 | ||
1953 | if ( undo->isEmpty() ) | 1953 | if ( undo->isEmpty() ) |
1954 | mActionUndo->setText( i18n( "Undo" ) ); | 1954 | mActionUndo->setText( i18n( "Undo" ) ); |
1955 | else | 1955 | else |
1956 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); | 1956 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); |
1957 | 1957 | ||
1958 | mActionUndo->setEnabled( !undo->isEmpty() ); | 1958 | mActionUndo->setEnabled( !undo->isEmpty() ); |
1959 | 1959 | ||
1960 | if ( !redo->top() ) | 1960 | if ( !redo->top() ) |
1961 | mActionRedo->setText( i18n( "Redo" ) ); | 1961 | mActionRedo->setText( i18n( "Redo" ) ); |
1962 | else | 1962 | else |
1963 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); | 1963 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); |
1964 | 1964 | ||
1965 | mActionRedo->setEnabled( !redo->isEmpty() ); | 1965 | mActionRedo->setEnabled( !redo->isEmpty() ); |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | void KABCore::configureKeyBindings() | 1968 | void KABCore::configureKeyBindings() |
1969 | { | 1969 | { |
1970 | #ifndef KAB_EMBEDDED | 1970 | #ifndef KAB_EMBEDDED |
1971 | KKeyDialog::configure( actionCollection(), true ); | 1971 | KKeyDialog::configure( actionCollection(), true ); |
1972 | #else //KAB_EMBEDDED | 1972 | #else //KAB_EMBEDDED |
1973 | qDebug("KABCore::configureKeyBindings() not implemented"); | 1973 | qDebug("KABCore::configureKeyBindings() not implemented"); |
1974 | #endif //KAB_EMBEDDED | 1974 | #endif //KAB_EMBEDDED |
1975 | } | 1975 | } |
1976 | 1976 | ||
1977 | #ifdef KAB_EMBEDDED | 1977 | #ifdef KAB_EMBEDDED |
1978 | void KABCore::configureResources() | 1978 | void KABCore::configureResources() |
1979 | { | 1979 | { |
1980 | KRES::KCMKResources dlg( this, "" , 0 ); | 1980 | KRES::KCMKResources dlg( this, "" , 0 ); |
1981 | 1981 | ||
1982 | if ( !dlg.exec() ) | 1982 | if ( !dlg.exec() ) |
1983 | return; | 1983 | return; |
1984 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 1984 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
1985 | } | 1985 | } |
1986 | #endif //KAB_EMBEDDED | 1986 | #endif //KAB_EMBEDDED |
1987 | 1987 | ||
1988 | 1988 | ||
1989 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 1989 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
1990 | * for the attendees list of an event. | 1990 | * for the attendees list of an event. |
1991 | */ | 1991 | */ |
1992 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 1992 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
1993 | { | 1993 | { |
1994 | QStringList nameList; | 1994 | QStringList nameList; |
1995 | QStringList emailList; | 1995 | QStringList emailList; |
1996 | QStringList uidList; | 1996 | QStringList uidList; |
1997 | 1997 | ||
1998 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 1998 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
1999 | uint i=0; | 1999 | uint i=0; |
2000 | for (i=0; i < list.count(); i++) | 2000 | for (i=0; i < list.count(); i++) |
2001 | { | 2001 | { |
2002 | nameList.append(list[i].realName()); | 2002 | nameList.append(list[i].realName()); |
2003 | emailList.append(list[i].preferredEmail()); | 2003 | emailList.append(list[i].preferredEmail()); |
2004 | uidList.append(list[i].uid()); | 2004 | uidList.append(list[i].uid()); |
2005 | } | 2005 | } |
2006 | 2006 | ||
2007 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2007 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2008 | 2008 | ||
2009 | } | 2009 | } |
2010 | 2010 | ||
2011 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2011 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2012 | */ | 2012 | */ |
2013 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2013 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2014 | { | 2014 | { |
2015 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2015 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2016 | 2016 | ||
2017 | QString foundUid = QString::null; | 2017 | QString foundUid = QString::null; |
2018 | if ( ! uid.isEmpty() ) { | 2018 | if ( ! uid.isEmpty() ) { |
2019 | Addressee adrr = mAddressBook->findByUid( uid ); | 2019 | Addressee adrr = mAddressBook->findByUid( uid ); |
2020 | if ( !adrr.isEmpty() ) { | 2020 | if ( !adrr.isEmpty() ) { |
2021 | foundUid = uid; | 2021 | foundUid = uid; |
2022 | } | 2022 | } |
2023 | if ( email == "sendbacklist" ) { | 2023 | if ( email == "sendbacklist" ) { |
2024 | //qDebug("ssssssssssssssssssssssend "); | 2024 | //qDebug("ssssssssssssssssssssssend "); |
2025 | QStringList nameList; | 2025 | QStringList nameList; |
2026 | QStringList emailList; | 2026 | QStringList emailList; |
2027 | QStringList uidList; | 2027 | QStringList uidList; |
2028 | nameList.append(adrr.realName()); | 2028 | nameList.append(adrr.realName()); |
2029 | emailList = adrr.emails(); | 2029 | emailList = adrr.emails(); |
2030 | uidList.append( adrr.preferredEmail()); | 2030 | uidList.append( adrr.preferredEmail()); |
2031 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2031 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2032 | return; | 2032 | return; |
2033 | } | 2033 | } |
2034 | 2034 | ||
2035 | } | 2035 | } |
2036 | 2036 | ||
2037 | if ( email == "sendbacklist" ) | 2037 | if ( email == "sendbacklist" ) |
2038 | return; | 2038 | return; |
2039 | if (foundUid.isEmpty()) | 2039 | if (foundUid.isEmpty()) |
2040 | { | 2040 | { |
2041 | //find the uid of the person first | 2041 | //find the uid of the person first |
2042 | Addressee::List namelist; | 2042 | Addressee::List namelist; |
2043 | Addressee::List emaillist; | 2043 | Addressee::List emaillist; |
2044 | 2044 | ||
2045 | if (!name.isEmpty()) | 2045 | if (!name.isEmpty()) |
2046 | namelist = mAddressBook->findByName( name ); | 2046 | namelist = mAddressBook->findByName( name ); |
2047 | 2047 | ||
2048 | if (!email.isEmpty()) | 2048 | if (!email.isEmpty()) |
2049 | emaillist = mAddressBook->findByEmail( email ); | 2049 | emaillist = mAddressBook->findByEmail( email ); |
2050 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2050 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2051 | //check if we have a match in Namelist and Emaillist | 2051 | //check if we have a match in Namelist and Emaillist |
2052 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2052 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2053 | foundUid = emaillist[0].uid(); | 2053 | foundUid = emaillist[0].uid(); |
2054 | } | 2054 | } |
2055 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2055 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2056 | foundUid = namelist[0].uid(); | 2056 | foundUid = namelist[0].uid(); |
2057 | else | 2057 | else |
2058 | { | 2058 | { |
2059 | for (int i = 0; i < namelist.count(); i++) | 2059 | for (int i = 0; i < namelist.count(); i++) |
2060 | { | 2060 | { |
2061 | for (int j = 0; j < emaillist.count(); j++) | 2061 | for (int j = 0; j < emaillist.count(); j++) |
2062 | { | 2062 | { |
2063 | if (namelist[i] == emaillist[j]) | 2063 | if (namelist[i] == emaillist[j]) |
2064 | { | 2064 | { |
2065 | foundUid = namelist[i].uid(); | 2065 | foundUid = namelist[i].uid(); |
2066 | } | 2066 | } |
2067 | } | 2067 | } |
2068 | } | 2068 | } |
2069 | } | 2069 | } |
2070 | } | 2070 | } |
2071 | else | 2071 | else |
2072 | { | 2072 | { |
2073 | foundUid = uid; | 2073 | foundUid = uid; |
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | if (!foundUid.isEmpty()) | 2076 | if (!foundUid.isEmpty()) |
2077 | { | 2077 | { |
2078 | 2078 | ||
2079 | // raise Ka/Pi if it is in the background | 2079 | // raise Ka/Pi if it is in the background |
2080 | #ifndef DESKTOP_VERSION | 2080 | #ifndef DESKTOP_VERSION |
2081 | #ifndef KORG_NODCOP | 2081 | #ifndef KORG_NODCOP |
2082 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2082 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2083 | #endif | 2083 | #endif |
2084 | #endif | 2084 | #endif |
2085 | 2085 | ||
2086 | mMainWindow->showMaximized(); | 2086 | mMainWindow->showMaximized(); |
2087 | mMainWindow-> raise(); | 2087 | mMainWindow-> raise(); |
2088 | 2088 | ||
2089 | mViewManager->setSelected( "", false); | 2089 | mViewManager->setSelected( "", false); |
2090 | mViewManager->refreshView( "" ); | 2090 | mViewManager->refreshView( "" ); |
2091 | mViewManager->setSelected( foundUid, true ); | 2091 | mViewManager->setSelected( foundUid, true ); |
2092 | mViewManager->refreshView( foundUid ); | 2092 | mViewManager->refreshView( foundUid ); |
2093 | 2093 | ||
2094 | if ( !mMultipleViewsAtOnce ) | 2094 | if ( !mMultipleViewsAtOnce ) |
2095 | { | 2095 | { |
2096 | setDetailsVisible( true ); | 2096 | setDetailsVisible( true ); |
2097 | mActionDetails->setChecked(true); | 2097 | mActionDetails->setChecked(true); |
2098 | } | 2098 | } |
2099 | } | 2099 | } |
2100 | } | 2100 | } |
2101 | 2101 | ||
2102 | 2102 | ||
2103 | void KABCore::faq() | 2103 | void KABCore::faq() |
2104 | { | 2104 | { |
2105 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2105 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | 2108 | ||
2109 | void KABCore::fillSyncMenu() | 2109 | void KABCore::fillSyncMenu() |
2110 | { | 2110 | { |
2111 | if ( syncMenu->count() ) | 2111 | if ( syncMenu->count() ) |
2112 | syncMenu->clear(); | 2112 | syncMenu->clear(); |
2113 | syncMenu->insertItem( i18n("Configure..."), 0 ); | 2113 | syncMenu->insertItem( i18n("Configure..."), 0 ); |
2114 | syncMenu->insertSeparator(); | 2114 | syncMenu->insertSeparator(); |
2115 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); | 2115 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); |
2116 | syncMenu->insertSeparator(); | 2116 | syncMenu->insertSeparator(); |
2117 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2117 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2118 | config.setGroup("General"); | 2118 | config.setGroup("General"); |
2119 | QStringList prof = config.readListEntry("SyncProfileNames"); | 2119 | QStringList prof = config.readListEntry("SyncProfileNames"); |
2120 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 2120 | KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
2121 | if ( prof.count() < 3 ) { | 2121 | if ( prof.count() < 3 ) { |
2122 | prof.clear(); | 2122 | prof.clear(); |
2123 | prof << i18n("Sharp_DTM"); | 2123 | prof << i18n("Sharp_DTM"); |
2124 | prof << i18n("Local_file"); | 2124 | prof << i18n("Local_file"); |
2125 | prof << i18n("Last_file"); | 2125 | prof << i18n("Last_file"); |
2126 | KSyncProfile* temp = new KSyncProfile (); | 2126 | KSyncProfile* temp = new KSyncProfile (); |
2127 | temp->setName( prof[0] ); | 2127 | temp->setName( prof[0] ); |
2128 | temp->writeConfig(&config); | 2128 | temp->writeConfig(&config); |
2129 | temp->setName( prof[1] ); | 2129 | temp->setName( prof[1] ); |
2130 | temp->writeConfig(&config); | 2130 | temp->writeConfig(&config); |
2131 | temp->setName( prof[2] ); | 2131 | temp->setName( prof[2] ); |
2132 | temp->writeConfig(&config); | 2132 | temp->writeConfig(&config); |
2133 | config.setGroup("General"); | 2133 | config.setGroup("General"); |
2134 | config.writeEntry("SyncProfileNames",prof); | 2134 | config.writeEntry("SyncProfileNames",prof); |
2135 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 2135 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
2136 | config.sync(); | 2136 | config.sync(); |
2137 | delete temp; | 2137 | delete temp; |
2138 | } | 2138 | } |
2139 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 2139 | KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
2140 | KABPrefs::instance()->mSyncProfileNames = prof; | 2140 | KABPrefs::instance()->mSyncProfileNames = prof; |
2141 | int i; | 2141 | int i; |
2142 | for ( i = 0; i < prof.count(); ++i ) { | 2142 | for ( i = 0; i < prof.count(); ++i ) { |
2143 | 2143 | ||
2144 | syncMenu->insertItem( prof[i], 1000+i ); | 2144 | syncMenu->insertItem( prof[i], 1000+i ); |
2145 | if ( i == 2 ) | 2145 | if ( i == 2 ) |
2146 | syncMenu->insertSeparator(); | 2146 | syncMenu->insertSeparator(); |
2147 | } | 2147 | } |
2148 | QDir app_dir; | 2148 | QDir app_dir; |
2149 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 2149 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
2150 | syncMenu->setItemEnabled( false , 1000 ); | 2150 | syncMenu->setItemEnabled( false , 1000 ); |
2151 | } | 2151 | } |
2152 | //probaly useless | 2152 | //probaly useless |
2153 | //mView->setupExternSyncProfiles(); | 2153 | //mView->setupExternSyncProfiles(); |
2154 | } | 2154 | } |
2155 | void KABCore::slotSyncMenu( int action ) | 2155 | void KABCore::slotSyncMenu( int action ) |
2156 | { | 2156 | { |
2157 | //qDebug("syncaction %d ", action); | 2157 | //qDebug("syncaction %d ", action); |
2158 | if ( action == 0 ) { | 2158 | if ( action == 0 ) { |
2159 | 2159 | ||
2160 | // seems to be a Qt2 event handling bug | 2160 | // seems to be a Qt2 event handling bug |
2161 | // syncmenu.clear causes a segfault at first time | 2161 | // syncmenu.clear causes a segfault at first time |
2162 | // when we call it after the main event loop, it is ok | 2162 | // when we call it after the main event loop, it is ok |
2163 | // same behaviour when calling OM/Pi via QCOP for the first time | 2163 | // same behaviour when calling OM/Pi via QCOP for the first time |
2164 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 2164 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
2165 | //confSync(); | 2165 | //confSync(); |
2166 | 2166 | ||
2167 | return; | 2167 | return; |
2168 | } | 2168 | } |
2169 | if ( action == 1 ) { | 2169 | if ( action == 1 ) { |
2170 | multiSync( true ); | 2170 | multiSync( true ); |
2171 | return; | 2171 | return; |
2172 | } | 2172 | } |
2173 | 2173 | ||
2174 | if (mBlockSaveFlag) | 2174 | if (mBlockSaveFlag) |
2175 | return; | 2175 | return; |
2176 | mBlockSaveFlag = true; | 2176 | mBlockSaveFlag = true; |
2177 | mCurrentSyncProfile = action - 1000 ; | 2177 | mCurrentSyncProfile = action - 1000 ; |
2178 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; | 2178 | mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; |
2179 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; | 2179 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; |
2180 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2180 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2181 | KSyncProfile* temp = new KSyncProfile (); | 2181 | KSyncProfile* temp = new KSyncProfile (); |
2182 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2182 | temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2183 | temp->readConfig(&config); | 2183 | temp->readConfig(&config); |
2184 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2184 | KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2185 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | 2185 | KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); |
2186 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2186 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2187 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2187 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2188 | KABPrefs::instance()->mWriteBackInFuture = 0; | 2188 | KABPrefs::instance()->mWriteBackInFuture = 0; |
2189 | if ( temp->getWriteBackFuture() ) | 2189 | if ( temp->getWriteBackFuture() ) |
2190 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2190 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2191 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 2191 | KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
2192 | if ( action == 1000 ) { | 2192 | if ( action == 1000 ) { |
2193 | syncSharp(); | 2193 | syncSharp(); |
2194 | 2194 | ||
2195 | } else if ( action == 1001 ) { | 2195 | } else if ( action == 1001 ) { |
2196 | syncLocalFile(); | 2196 | syncLocalFile(); |
2197 | 2197 | ||
2198 | } else if ( action == 1002 ) { | 2198 | } else if ( action == 1002 ) { |
2199 | quickSyncLocalFile(); | 2199 | quickSyncLocalFile(); |
2200 | 2200 | ||
2201 | } else if ( action >= 1003 ) { | 2201 | } else if ( action >= 1003 ) { |
2202 | if ( temp->getIsLocalFileSync() ) { | 2202 | if ( temp->getIsLocalFileSync() ) { |
2203 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 2203 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
2204 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 2204 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2205 | } else { | 2205 | } else { |
2206 | if ( temp->getIsPhoneSync() ) { | 2206 | if ( temp->getIsPhoneSync() ) { |
2207 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2207 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
2208 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 2208 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
2209 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 2209 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
2210 | syncPhone(); | 2210 | syncPhone(); |
2211 | } else | 2211 | } else |
2212 | syncRemote( temp ); | 2212 | syncRemote( temp ); |
2213 | 2213 | ||
2214 | } | 2214 | } |
2215 | } | 2215 | } |
2216 | delete temp; | 2216 | delete temp; |
2217 | mBlockSaveFlag = false; | 2217 | mBlockSaveFlag = false; |
2218 | } | 2218 | } |
2219 | 2219 | ||
2220 | void KABCore::syncLocalFile() | 2220 | void KABCore::syncLocalFile() |
2221 | { | 2221 | { |
2222 | 2222 | ||
2223 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; | 2223 | QString fn =KABPrefs::instance()->mLastSyncedLocalFile; |
2224 | 2224 | ||
2225 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | 2225 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); |
2226 | if ( fn == "" ) | 2226 | if ( fn == "" ) |
2227 | return; | 2227 | return; |
2228 | if ( syncWithFile( fn, false ) ) { | 2228 | if ( syncWithFile( fn, false ) ) { |
2229 | qDebug("syncLocalFile() successful "); | 2229 | qDebug("syncLocalFile() successful "); |
2230 | } | 2230 | } |
2231 | 2231 | ||
2232 | } | 2232 | } |
2233 | bool KABCore::syncWithFile( QString fn , bool quick ) | 2233 | bool KABCore::syncWithFile( QString fn , bool quick ) |
2234 | { | 2234 | { |
2235 | bool ret = false; | 2235 | bool ret = false; |
2236 | QFileInfo info; | 2236 | QFileInfo info; |
2237 | info.setFile( fn ); | 2237 | info.setFile( fn ); |
2238 | QString mess; | 2238 | QString mess; |
2239 | bool loadbup = true; | 2239 | bool loadbup = true; |
2240 | if ( !info. exists() ) { | 2240 | if ( !info. exists() ) { |
2241 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 2241 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
2242 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2242 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2243 | mess ); | 2243 | mess ); |
2244 | return ret; | 2244 | return ret; |
2245 | } | 2245 | } |
2246 | int result = 0; | 2246 | int result = 0; |
2247 | if ( !quick ) { | 2247 | if ( !quick ) { |
2248 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 2248 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
2249 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2249 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2250 | mess, | 2250 | mess, |
2251 | i18n("Sync"), i18n("Cancel"), 0, | 2251 | i18n("Sync"), i18n("Cancel"), 0, |
2252 | 0, 1 ); | 2252 | 0, 1 ); |
2253 | if ( result ) | 2253 | if ( result ) |
2254 | return false; | 2254 | return false; |
2255 | } | 2255 | } |
2256 | if ( KABPrefs::instance()->mAskForPreferences ) | 2256 | if ( KABPrefs::instance()->mAskForPreferences ) |
2257 | edit_sync_options(); | 2257 | edit_sync_options(); |
2258 | if ( result == 0 ) { | 2258 | if ( result == 0 ) { |
2259 | //qDebug("Now sycing ... "); | 2259 | //qDebug("Now sycing ... "); |
2260 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) | 2260 | if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) |
2261 | setCaption( i18n("Synchronization successful") ); | 2261 | setCaption( i18n("Synchronization successful") ); |
2262 | else | 2262 | else |
2263 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 2263 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
2264 | if ( ! quick ) | 2264 | if ( ! quick ) |
2265 | KABPrefs::instance()->mLastSyncedLocalFile = fn; | 2265 | KABPrefs::instance()->mLastSyncedLocalFile = fn; |
2266 | setModified(); | 2266 | setModified(); |
2267 | } | 2267 | } |
2268 | return ret; | 2268 | return ret; |
2269 | } | 2269 | } |
2270 | void KABCore::quickSyncLocalFile() | 2270 | void KABCore::quickSyncLocalFile() |
2271 | { | 2271 | { |
2272 | 2272 | ||
2273 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { | 2273 | if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { |
2274 | qDebug("quick syncLocalFile() successful "); | 2274 | qDebug("quick syncLocalFile() successful "); |
2275 | 2275 | ||
2276 | } | 2276 | } |
2277 | } | 2277 | } |
2278 | void KABCore::multiSync( bool askforPrefs ) | 2278 | void KABCore::multiSync( bool askforPrefs ) |
2279 | { | 2279 | { |
2280 | if (mBlockSaveFlag) | 2280 | if (mBlockSaveFlag) |
2281 | return; | 2281 | return; |
2282 | mBlockSaveFlag = true; | 2282 | mBlockSaveFlag = true; |
2283 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 2283 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
2284 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2284 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2285 | question, | 2285 | question, |
2286 | i18n("Yes"), i18n("No"), | 2286 | i18n("Yes"), i18n("No"), |
2287 | 0, 0 ) != 0 ) { | 2287 | 0, 0 ) != 0 ) { |
2288 | mBlockSaveFlag = false; | 2288 | mBlockSaveFlag = false; |
2289 | setCaption(i18n("Aborted! Nothing synced!")); | 2289 | setCaption(i18n("Aborted! Nothing synced!")); |
2290 | return; | 2290 | return; |
2291 | } | 2291 | } |
2292 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 2292 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
2293 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; | 2293 | KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; |
2294 | if ( askforPrefs ) { | 2294 | if ( askforPrefs ) { |
2295 | edit_sync_options(); | 2295 | edit_sync_options(); |
2296 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; | 2296 | KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; |
2297 | } | 2297 | } |
2298 | setCaption(i18n("Multiple sync started.") ); | 2298 | setCaption(i18n("Multiple sync started.") ); |
2299 | qApp->processEvents(); | 2299 | qApp->processEvents(); |
2300 | int num = ringSync() ; | 2300 | int num = ringSync() ; |
2301 | if ( num > 1 ) | 2301 | if ( num > 1 ) |
2302 | ringSync(); | 2302 | ringSync(); |
2303 | mBlockSaveFlag = false; | 2303 | mBlockSaveFlag = false; |
2304 | if ( num ) | 2304 | if ( num ) |
2305 | save(); | 2305 | save(); |
2306 | if ( num ) | 2306 | if ( num ) |
2307 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | 2307 | setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); |
2308 | else | 2308 | else |
2309 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 2309 | setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
2310 | return; | 2310 | return; |
2311 | } | 2311 | } |
2312 | int KABCore::ringSync() | 2312 | int KABCore::ringSync() |
2313 | { | 2313 | { |
2314 | int syncedProfiles = 0; | 2314 | int syncedProfiles = 0; |
2315 | int i; | 2315 | int i; |
2316 | QTime timer; | 2316 | QTime timer; |
2317 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2317 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2318 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; | 2318 | QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; |
2319 | KSyncProfile* temp = new KSyncProfile (); | 2319 | KSyncProfile* temp = new KSyncProfile (); |
2320 | KABPrefs::instance()->mAskForPreferences = false; | 2320 | KABPrefs::instance()->mAskForPreferences = false; |
2321 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 2321 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
2322 | mCurrentSyncProfile = i; | 2322 | mCurrentSyncProfile = i; |
2323 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 2323 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
2324 | temp->readConfig(&config); | 2324 | temp->readConfig(&config); |
2325 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { | 2325 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { |
2326 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 2326 | setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
2327 | ++syncedProfiles; | 2327 | ++syncedProfiles; |
2328 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2328 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2329 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2329 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2330 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2330 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2331 | KABPrefs::instance()->mWriteBackInFuture = 0; | 2331 | KABPrefs::instance()->mWriteBackInFuture = 0; |
2332 | if ( temp->getWriteBackFuture() ) | 2332 | if ( temp->getWriteBackFuture() ) |
2333 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2333 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2334 | KABPrefs::instance()->mShowSyncSummary = false; | 2334 | KABPrefs::instance()->mShowSyncSummary = false; |
2335 | mCurrentSyncDevice = syncProfileNames[i] ; | 2335 | mCurrentSyncDevice = syncProfileNames[i] ; |
2336 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; | 2336 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; |
2337 | if ( i == 0 ) { | 2337 | if ( i == 0 ) { |
2338 | syncSharp(); | 2338 | syncSharp(); |
2339 | } else { | 2339 | } else { |
2340 | if ( temp->getIsLocalFileSync() ) { | 2340 | if ( temp->getIsLocalFileSync() ) { |
2341 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) | 2341 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) |
2342 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 2342 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2343 | } else { | 2343 | } else { |
2344 | if ( temp->getIsPhoneSync() ) { | 2344 | if ( temp->getIsPhoneSync() ) { |
2345 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2345 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
2346 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 2346 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
2347 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 2347 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
2348 | syncPhone(); | 2348 | syncPhone(); |
2349 | } else | 2349 | } else |
2350 | syncRemote( temp, false ); | 2350 | syncRemote( temp, false ); |
2351 | 2351 | ||
2352 | } | 2352 | } |
2353 | } | 2353 | } |
2354 | timer.start(); | 2354 | timer.start(); |
2355 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | 2355 | setCaption(i18n("Multiple sync in progress ... please wait!") ); |
2356 | while ( timer.elapsed () < 2000 ) { | 2356 | while ( timer.elapsed () < 2000 ) { |
2357 | qApp->processEvents(); | 2357 | qApp->processEvents(); |
2358 | #ifndef _WIN32_ | 2358 | #ifndef _WIN32_ |
2359 | sleep (1); | 2359 | sleep (1); |
2360 | #endif | 2360 | #endif |
2361 | } | 2361 | } |
2362 | 2362 | ||
2363 | } | 2363 | } |
2364 | 2364 | ||
2365 | } | 2365 | } |
2366 | delete temp; | 2366 | delete temp; |
2367 | return syncedProfiles; | 2367 | return syncedProfiles; |
2368 | } | 2368 | } |
2369 | 2369 | ||
2370 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | 2370 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) |
2371 | { | 2371 | { |
2372 | QString question; | 2372 | QString question; |
2373 | if ( ask ) { | 2373 | if ( ask ) { |
2374 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 2374 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
2375 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2375 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2376 | question, | 2376 | question, |
2377 | i18n("Yes"), i18n("No"), | 2377 | i18n("Yes"), i18n("No"), |
2378 | 0, 0 ) != 0 ) | 2378 | 0, 0 ) != 0 ) |
2379 | return; | 2379 | return; |
2380 | } | 2380 | } |
2381 | QString command = prof->getPreSyncCommandAB(); | 2381 | QString command = prof->getPreSyncCommandAB(); |
2382 | int fi; | 2382 | int fi; |
2383 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2383 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2384 | QString pwd = getPassword(); | 2384 | QString pwd = getPassword(); |
2385 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2385 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2386 | 2386 | ||
2387 | } | 2387 | } |
2388 | int maxlen = 30; | 2388 | int maxlen = 30; |
2389 | if ( QApplication::desktop()->width() > 320 ) | 2389 | if ( QApplication::desktop()->width() > 320 ) |
2390 | maxlen += 25; | 2390 | maxlen += 25; |
2391 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2391 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2392 | int fileSize = 0; | 2392 | int fileSize = 0; |
2393 | int result = system ( command ); | 2393 | int result = system ( command ); |
2394 | // 0 : okay | 2394 | // 0 : okay |
2395 | // 256: no such file or dir | 2395 | // 256: no such file or dir |
2396 | // | 2396 | // |
2397 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2397 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2398 | if ( result != 0 ) { | 2398 | if ( result != 0 ) { |
2399 | int len = maxlen; | 2399 | int len = maxlen; |
2400 | while ( len < command.length() ) { | 2400 | while ( len < command.length() ) { |
2401 | command.insert( len , "\n" ); | 2401 | command.insert( len , "\n" ); |
2402 | len += maxlen +2; | 2402 | len += maxlen +2; |
2403 | } | 2403 | } |
2404 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; | 2404 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; |
2405 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2405 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2406 | question, | 2406 | question, |
2407 | i18n("Okay!")) ; | 2407 | i18n("Okay!")) ; |
2408 | setCaption ("KO/Pi"); | 2408 | setCaption ("KO/Pi"); |
2409 | return; | 2409 | return; |
2410 | } | 2410 | } |
2411 | setCaption ( i18n( "Copying succeed." ) ); | 2411 | setCaption ( i18n( "Copying succeed." ) ); |
2412 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2412 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2413 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { | 2413 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { |
2414 | // Event* e = mView->getLastSyncEvent(); | 2414 | // Event* e = mView->getLastSyncEvent(); |
2415 | // e->setReadOnly( false ); | 2415 | // e->setReadOnly( false ); |
2416 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2416 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2417 | // e->setReadOnly( true ); | 2417 | // e->setReadOnly( true ); |
2418 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2418 | if ( KABPrefs::instance()->mWriteBackFile ) { |
2419 | command = prof->getPostSyncCommandAB(); | 2419 | command = prof->getPostSyncCommandAB(); |
2420 | int fi; | 2420 | int fi; |
2421 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2421 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2422 | QString pwd = getPassword(); | 2422 | QString pwd = getPassword(); |
2423 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2423 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2424 | 2424 | ||
2425 | } | 2425 | } |
2426 | setCaption ( i18n( "Writing back file ..." ) ); | 2426 | setCaption ( i18n( "Writing back file ..." ) ); |
2427 | result = system ( command ); | 2427 | result = system ( command ); |
2428 | qDebug("KO: Writing back file result: %d ", result); | 2428 | qDebug("KO: Writing back file result: %d ", result); |
2429 | if ( result != 0 ) { | 2429 | if ( result != 0 ) { |
2430 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 2430 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
2431 | return; | 2431 | return; |
2432 | } else { | 2432 | } else { |
2433 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2433 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2434 | } | 2434 | } |
2435 | } | 2435 | } |
2436 | } | 2436 | } |
2437 | return; | 2437 | return; |
2438 | } | 2438 | } |
2439 | #include <qpushbutton.h> | 2439 | #include <qpushbutton.h> |
2440 | #include <qradiobutton.h> | 2440 | #include <qradiobutton.h> |
2441 | #include <qbuttongroup.h> | 2441 | #include <qbuttongroup.h> |
2442 | void KABCore::edit_sync_options() | 2442 | void KABCore::edit_sync_options() |
2443 | { | 2443 | { |
2444 | //mDialogManager->showSyncOptions(); | 2444 | //mDialogManager->showSyncOptions(); |
2445 | //KABPrefs::instance()->mSyncAlgoPrefs | 2445 | //KABPrefs::instance()->mSyncAlgoPrefs |
2446 | QDialog dia( this, "dia", true ); | 2446 | QDialog dia( this, "dia", true ); |
2447 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 2447 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
2448 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 2448 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
2449 | QVBoxLayout lay ( &dia ); | 2449 | QVBoxLayout lay ( &dia ); |
2450 | lay.setSpacing( 2 ); | 2450 | lay.setSpacing( 2 ); |
2451 | lay.setMargin( 3 ); | 2451 | lay.setMargin( 3 ); |
2452 | lay.addWidget(&gr); | 2452 | lay.addWidget(&gr); |
2453 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 2453 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
2454 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 2454 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
2455 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 2455 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
2456 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 2456 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
2457 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 2457 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
2458 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 2458 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
2459 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 2459 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
2460 | QPushButton pb ( "OK", &dia); | 2460 | QPushButton pb ( "OK", &dia); |
2461 | lay.addWidget( &pb ); | 2461 | lay.addWidget( &pb ); |
2462 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2462 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2463 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { | 2463 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { |
2464 | case 0: | 2464 | case 0: |
2465 | loc.setChecked( true); | 2465 | loc.setChecked( true); |
2466 | break; | 2466 | break; |
2467 | case 1: | 2467 | case 1: |
2468 | rem.setChecked( true ); | 2468 | rem.setChecked( true ); |
2469 | break; | 2469 | break; |
2470 | case 2: | 2470 | case 2: |
2471 | newest.setChecked( true); | 2471 | newest.setChecked( true); |
2472 | break; | 2472 | break; |
2473 | case 3: | 2473 | case 3: |
2474 | ask.setChecked( true); | 2474 | ask.setChecked( true); |
2475 | break; | 2475 | break; |
2476 | case 4: | 2476 | case 4: |
2477 | f_loc.setChecked( true); | 2477 | f_loc.setChecked( true); |
2478 | break; | 2478 | break; |
2479 | case 5: | 2479 | case 5: |
2480 | f_rem.setChecked( true); | 2480 | f_rem.setChecked( true); |
2481 | break; | 2481 | break; |
2482 | case 6: | 2482 | case 6: |
2483 | // both.setChecked( true); | 2483 | // both.setChecked( true); |
2484 | break; | 2484 | break; |
2485 | default: | 2485 | default: |
2486 | break; | 2486 | break; |
2487 | } | 2487 | } |
2488 | if ( dia.exec() ) { | 2488 | if ( dia.exec() ) { |
2489 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 2489 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
2490 | } | 2490 | } |
2491 | 2491 | ||
2492 | 2492 | ||
2493 | } | 2493 | } |
2494 | QString KABCore::getPassword( ) | 2494 | QString KABCore::getPassword( ) |
2495 | { | 2495 | { |
2496 | QString retfile = ""; | 2496 | QString retfile = ""; |
2497 | QDialog dia ( this, "input-dialog", true ); | 2497 | QDialog dia ( this, "input-dialog", true ); |
2498 | QLineEdit lab ( &dia ); | 2498 | QLineEdit lab ( &dia ); |
2499 | lab.setEchoMode( QLineEdit::Password ); | 2499 | lab.setEchoMode( QLineEdit::Password ); |
2500 | QVBoxLayout lay( &dia ); | 2500 | QVBoxLayout lay( &dia ); |
2501 | lay.setMargin(7); | 2501 | lay.setMargin(7); |
2502 | lay.setSpacing(7); | 2502 | lay.setSpacing(7); |
2503 | lay.addWidget( &lab); | 2503 | lay.addWidget( &lab); |
2504 | dia.setFixedSize( 230,50 ); | 2504 | dia.setFixedSize( 230,50 ); |
2505 | dia.setCaption( i18n("Enter password") ); | 2505 | dia.setCaption( i18n("Enter password") ); |
2506 | QPushButton pb ( "OK", &dia); | 2506 | QPushButton pb ( "OK", &dia); |
2507 | lay.addWidget( &pb ); | 2507 | lay.addWidget( &pb ); |
2508 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2508 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2509 | dia.show(); | 2509 | dia.show(); |
2510 | int res = dia.exec(); | 2510 | int res = dia.exec(); |
2511 | if ( res ) | 2511 | if ( res ) |
2512 | retfile = lab.text(); | 2512 | retfile = lab.text(); |
2513 | dia.hide(); | 2513 | dia.hide(); |
2514 | qApp->processEvents(); | 2514 | qApp->processEvents(); |
2515 | return retfile; | 2515 | return retfile; |
2516 | 2516 | ||
2517 | } | 2517 | } |
2518 | #include <libkcal/syncdefines.h> | 2518 | #include <libkcal/syncdefines.h> |
2519 | 2519 | ||
2520 | KABC::Addressee KABCore::getLastSyncAddressee() | 2520 | KABC::Addressee KABCore::getLastSyncAddressee() |
2521 | { | 2521 | { |
2522 | Addressee lse; | 2522 | Addressee lse; |
2523 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2523 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2524 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2524 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2525 | if (lse.isEmpty()) { | 2525 | if (lse.isEmpty()) { |
2526 | qDebug("Creating new last-syncAddressee "); | 2526 | qDebug("Creating new last-syncAddressee "); |
2527 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2527 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2528 | QString sum = ""; | 2528 | QString sum = ""; |
2529 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2529 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2530 | sum = "E: "; | 2530 | sum = "E: "; |
2531 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2531 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2532 | lse.setRevision( mLastAddressbookSync ); | 2532 | lse.setRevision( mLastAddressbookSync ); |
2533 | lse.setCategories( i18n("SyncEvent") ); | 2533 | lse.setCategories( i18n("SyncEvent") ); |
2534 | mAddressBook->insertAddressee( lse ); | 2534 | mAddressBook->insertAddressee( lse ); |
2535 | } | 2535 | } |
2536 | return lse; | 2536 | return lse; |
2537 | } | 2537 | } |
2538 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2538 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2539 | { | 2539 | { |
2540 | 2540 | ||
2541 | //void setZaurusId(int id); | 2541 | //void setZaurusId(int id); |
2542 | // int zaurusId() const; | 2542 | // int zaurusId() const; |
2543 | // void setZaurusUid(int id); | 2543 | // void setZaurusUid(int id); |
2544 | // int zaurusUid() const; | 2544 | // int zaurusUid() const; |
2545 | // void setZaurusStat(int id); | 2545 | // void setZaurusStat(int id); |
2546 | // int zaurusStat() const; | 2546 | // int zaurusStat() const; |
2547 | // 0 equal | 2547 | // 0 equal |
2548 | // 1 take local | 2548 | // 1 take local |
2549 | // 2 take remote | 2549 | // 2 take remote |
2550 | // 3 cancel | 2550 | // 3 cancel |
2551 | QDateTime lastSync = mLastAddressbookSync; | 2551 | QDateTime lastSync = mLastAddressbookSync; |
2552 | QDateTime localMod = local->revision(); | ||
2553 | QDateTime remoteMod = remote->revision(); | ||
2552 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2554 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2553 | bool remCh, locCh; | 2555 | bool remCh, locCh; |
2554 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2556 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2555 | 2557 | ||
2556 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2558 | qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2557 | locCh = ( local->revision() > mLastAddressbookSync ); | 2559 | locCh = ( localMod > mLastAddressbookSync ); |
2558 | if ( !remCh && ! locCh ) { | 2560 | if ( !remCh && ! locCh ) { |
2559 | //qDebug("both not changed "); | 2561 | qDebug("both not changed "); |
2560 | lastSync = local->revision().addDays(1); | 2562 | lastSync = localMod.addDays(1); |
2561 | if ( mode <= SYNC_PREF_ASK ) | 2563 | if ( mode <= SYNC_PREF_ASK ) |
2562 | return 0; | 2564 | return 0; |
2563 | } else { | 2565 | } else { |
2564 | if ( locCh ) { | 2566 | if ( locCh ) { |
2565 | //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2567 | qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2566 | lastSync = local->revision().addDays( -1 ); | 2568 | lastSync = localMod.addDays( -1 ); |
2567 | if ( !remCh ) | 2569 | if ( !remCh ) |
2568 | remote->setRevision( lastSync.addDays( -1 ) ); | 2570 | remoteMod =( lastSync.addDays( -1 ) ); |
2569 | } else { | 2571 | } else { |
2570 | //qDebug(" not loc changed "); | 2572 | //qDebug(" not loc changed "); |
2571 | lastSync = local->revision().addDays( 1 ); | 2573 | lastSync = localMod.addDays( 1 ); |
2572 | if ( remCh ) | 2574 | if ( remCh ) |
2573 | remote->setRevision( lastSync.addDays( 1 ) ); | 2575 | remoteMod =( lastSync.addDays( 1 ) ); |
2574 | 2576 | ||
2575 | } | 2577 | } |
2576 | } | 2578 | } |
2577 | full = true; | 2579 | full = true; |
2578 | if ( mode < SYNC_PREF_ASK ) | 2580 | if ( mode < SYNC_PREF_ASK ) |
2579 | mode = SYNC_PREF_ASK; | 2581 | mode = SYNC_PREF_ASK; |
2580 | } else { | 2582 | } else { |
2581 | if ( local->revision() == remote->revision() ) | 2583 | if ( localMod == remoteMod ) |
2582 | return 0; | 2584 | return 0; |
2583 | 2585 | ||
2584 | } | 2586 | } |
2585 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2587 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2586 | 2588 | ||
2587 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 2589 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2588 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2590 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2589 | //full = true; //debug only | 2591 | //full = true; //debug only |
2590 | if ( full ) { | 2592 | if ( full ) { |
2591 | bool equ = ( (*local) == (*remote) ); | 2593 | bool equ = ( (*local) == (*remote) ); |
2592 | if ( equ ) { | 2594 | if ( equ ) { |
2593 | //qDebug("equal "); | 2595 | //qDebug("equal "); |
2594 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2596 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2595 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2597 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2596 | } | 2598 | } |
2597 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2599 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2598 | return 0; | 2600 | return 0; |
2599 | 2601 | ||
2600 | }//else //debug only | 2602 | }//else //debug only |
2601 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2603 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2602 | } | 2604 | } |
2603 | int result; | 2605 | int result; |
2604 | bool localIsNew; | 2606 | bool localIsNew; |
2605 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2607 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2606 | 2608 | ||
2607 | if ( full && mode < SYNC_PREF_NEWEST ) | 2609 | if ( full && mode < SYNC_PREF_NEWEST ) |
2608 | mode = SYNC_PREF_ASK; | 2610 | mode = SYNC_PREF_ASK; |
2609 | 2611 | ||
2610 | switch( mode ) { | 2612 | switch( mode ) { |
2611 | case SYNC_PREF_LOCAL: | 2613 | case SYNC_PREF_LOCAL: |
2612 | if ( lastSync > remote->revision() ) | 2614 | if ( lastSync > remoteMod ) |
2613 | return 1; | 2615 | return 1; |
2614 | if ( lastSync > local->revision() ) | 2616 | if ( lastSync > localMod ) |
2615 | return 2; | 2617 | return 2; |
2616 | return 1; | 2618 | return 1; |
2617 | break; | 2619 | break; |
2618 | case SYNC_PREF_REMOTE: | 2620 | case SYNC_PREF_REMOTE: |
2619 | if ( lastSync > remote->revision() ) | 2621 | if ( lastSync > remoteMod ) |
2620 | return 1; | 2622 | return 1; |
2621 | if ( lastSync > local->revision() ) | 2623 | if ( lastSync > localMod ) |
2622 | return 2; | 2624 | return 2; |
2623 | return 2; | 2625 | return 2; |
2624 | break; | 2626 | break; |
2625 | case SYNC_PREF_NEWEST: | 2627 | case SYNC_PREF_NEWEST: |
2626 | if ( local->revision() > remote->revision() ) | 2628 | if ( localMod > remoteMod ) |
2627 | return 1; | 2629 | return 1; |
2628 | else | 2630 | else |
2629 | return 2; | 2631 | return 2; |
2630 | break; | 2632 | break; |
2631 | case SYNC_PREF_ASK: | 2633 | case SYNC_PREF_ASK: |
2632 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); | 2634 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2633 | if ( lastSync > remote->revision() ) | 2635 | if ( lastSync > remoteMod ) |
2634 | return 1; | 2636 | return 1; |
2635 | if ( lastSync > local->revision() ) | 2637 | if ( lastSync > localMod ) |
2636 | return 2; | 2638 | return 2; |
2637 | localIsNew = local->revision() >= remote->revision(); | 2639 | localIsNew = localMod >= remoteMod; |
2638 | //qDebug("conflict! ************************************** "); | 2640 | //qDebug("conflict! ************************************** "); |
2639 | { | 2641 | { |
2640 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2642 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2641 | result = acd.executeD(localIsNew); | 2643 | result = acd.executeD(localIsNew); |
2642 | return result; | 2644 | return result; |
2643 | } | 2645 | } |
2644 | break; | 2646 | break; |
2645 | case SYNC_PREF_FORCE_LOCAL: | 2647 | case SYNC_PREF_FORCE_LOCAL: |
2646 | return 1; | 2648 | return 1; |
2647 | break; | 2649 | break; |
2648 | case SYNC_PREF_FORCE_REMOTE: | 2650 | case SYNC_PREF_FORCE_REMOTE: |
2649 | return 2; | 2651 | return 2; |
2650 | break; | 2652 | break; |
2651 | 2653 | ||
2652 | default: | 2654 | default: |
2653 | // SYNC_PREF_TAKE_BOTH not implemented | 2655 | // SYNC_PREF_TAKE_BOTH not implemented |
2654 | break; | 2656 | break; |
2655 | } | 2657 | } |
2656 | return 0; | 2658 | return 0; |
2657 | } | 2659 | } |
2658 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2660 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2659 | { | 2661 | { |
2660 | bool syncOK = true; | 2662 | bool syncOK = true; |
2661 | int addedAddressee = 0; | 2663 | int addedAddressee = 0; |
2662 | int addedAddresseeR = 0; | 2664 | int addedAddresseeR = 0; |
2663 | int deletedAddresseeR = 0; | 2665 | int deletedAddresseeR = 0; |
2664 | int deletedAddresseeL = 0; | 2666 | int deletedAddresseeL = 0; |
2665 | int changedLocal = 0; | 2667 | int changedLocal = 0; |
2666 | int changedRemote = 0; | 2668 | int changedRemote = 0; |
2667 | //QPtrList<Addressee> el = local->rawAddressees(); | 2669 | //QPtrList<Addressee> el = local->rawAddressees(); |
2668 | Addressee addresseeR; | 2670 | Addressee addresseeR; |
2669 | QString uid; | 2671 | QString uid; |
2670 | int take; | 2672 | int take; |
2671 | Addressee addresseeL; | 2673 | Addressee addresseeL; |
2672 | Addressee addresseeRSync; | 2674 | Addressee addresseeRSync; |
2673 | Addressee addresseeLSync; | 2675 | Addressee addresseeLSync; |
2674 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2676 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2675 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2677 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2676 | bool fullDateRange = false; | 2678 | bool fullDateRange = false; |
2677 | local->resetTempSyncStat(); | 2679 | local->resetTempSyncStat(); |
2678 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2680 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2679 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2681 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2680 | addresseeLSync = getLastSyncAddressee(); | 2682 | addresseeLSync = getLastSyncAddressee(); |
2681 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2683 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2682 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2684 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2683 | if ( !addresseeR.isEmpty() ) { | 2685 | if ( !addresseeR.isEmpty() ) { |
2684 | addresseeRSync = addresseeR; | 2686 | addresseeRSync = addresseeR; |
2685 | remote->removeAddressee(addresseeR ); | 2687 | remote->removeAddressee(addresseeR ); |
2686 | 2688 | ||
2687 | } else { | 2689 | } else { |
2688 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2690 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2689 | addresseeRSync = addresseeLSync ; | 2691 | addresseeRSync = addresseeLSync ; |
2690 | } else { | 2692 | } else { |
2691 | qDebug("FULLDATE 1"); | 2693 | qDebug("FULLDATE 1"); |
2692 | fullDateRange = true; | 2694 | fullDateRange = true; |
2693 | Addressee newAdd; | 2695 | Addressee newAdd; |
2694 | addresseeRSync = newAdd; | 2696 | addresseeRSync = newAdd; |
2695 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2697 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2696 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2698 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2697 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2699 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2698 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2700 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2699 | } | 2701 | } |
2700 | } | 2702 | } |
2701 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2703 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2702 | qDebug("FULLDATE 2"); | 2704 | qDebug("FULLDATE 2"); |
2703 | fullDateRange = true; | 2705 | fullDateRange = true; |
2704 | } | 2706 | } |
2705 | if ( ! fullDateRange ) { | 2707 | if ( ! fullDateRange ) { |
2706 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2708 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2707 | 2709 | ||
2708 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2710 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2709 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2711 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2710 | fullDateRange = true; | 2712 | fullDateRange = true; |
2711 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2713 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2712 | } | 2714 | } |
2713 | } | 2715 | } |
2714 | // fullDateRange = true; // debug only! | 2716 | // fullDateRange = true; // debug only! |
2715 | if ( fullDateRange ) | 2717 | if ( fullDateRange ) |
2716 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2718 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2717 | else | 2719 | else |
2718 | mLastAddressbookSync = addresseeLSync.revision(); | 2720 | mLastAddressbookSync = addresseeLSync.revision(); |
2719 | // for resyncing if own file has changed | 2721 | // for resyncing if own file has changed |
2720 | // PENDING fixme later when implemented | 2722 | // PENDING fixme later when implemented |
2721 | #if 0 | 2723 | #if 0 |
2722 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2724 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2723 | mLastAddressbookSync = loadedFileVersion; | 2725 | mLastAddressbookSync = loadedFileVersion; |
2724 | qDebug("setting mLastAddressbookSync "); | 2726 | qDebug("setting mLastAddressbookSync "); |
2725 | } | 2727 | } |
2726 | #endif | 2728 | #endif |
2727 | 2729 | ||
2728 | //qDebug("*************************** "); | 2730 | //qDebug("*************************** "); |
2729 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2731 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2730 | QStringList er = remote->uidList(); | 2732 | QStringList er = remote->uidList(); |
2731 | Addressee inR ;//= er.first(); | 2733 | Addressee inR ;//= er.first(); |
2732 | Addressee inL; | 2734 | Addressee inL; |
2733 | QProgressBar bar( er.count(),0 ); | 2735 | QProgressBar bar( er.count(),0 ); |
2734 | bar.setCaption (i18n("Syncing - close to abort!") ); | 2736 | bar.setCaption (i18n("Syncing - close to abort!") ); |
2735 | 2737 | ||
2736 | int w = 300; | 2738 | int w = 300; |
2737 | if ( QApplication::desktop()->width() < 320 ) | 2739 | if ( QApplication::desktop()->width() < 320 ) |
2738 | w = 220; | 2740 | w = 220; |
2739 | int h = bar.sizeHint().height() ; | 2741 | int h = bar.sizeHint().height() ; |
2740 | int dw = QApplication::desktop()->width(); | 2742 | int dw = QApplication::desktop()->width(); |
2741 | int dh = QApplication::desktop()->height(); | 2743 | int dh = QApplication::desktop()->height(); |
2742 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2744 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2743 | bar.show(); | 2745 | bar.show(); |
2744 | int modulo = (er.count()/10)+1; | 2746 | int modulo = (er.count()/10)+1; |
2745 | int incCounter = 0; | 2747 | int incCounter = 0; |
2746 | while ( incCounter < er.count()) { | 2748 | while ( incCounter < er.count()) { |
2747 | if ( ! bar.isVisible() ) | 2749 | if ( ! bar.isVisible() ) |
2748 | return false; | 2750 | return false; |
2749 | if ( incCounter % modulo == 0 ) | 2751 | if ( incCounter % modulo == 0 ) |
2750 | bar.setProgress( incCounter ); | 2752 | bar.setProgress( incCounter ); |
2751 | uid = er[ incCounter ]; | 2753 | uid = er[ incCounter ]; |
2752 | bool skipIncidence = false; | 2754 | bool skipIncidence = false; |
2753 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2755 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2754 | skipIncidence = true; | 2756 | skipIncidence = true; |
2755 | QString idS,OidS; | 2757 | QString idS,OidS; |
2756 | qApp->processEvents(); | 2758 | qApp->processEvents(); |
2757 | if ( !skipIncidence ) { | 2759 | if ( !skipIncidence ) { |
2758 | inL = local->findByUid( uid ); | 2760 | inL = local->findByUid( uid ); |
2759 | inR = remote->findByUid( uid ); | 2761 | inR = remote->findByUid( uid ); |
2760 | //inL.setResource( 0 ); | 2762 | //inL.setResource( 0 ); |
2761 | //inR.setResource( 0 ); | 2763 | //inR.setResource( 0 ); |
2762 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2764 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2763 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2765 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2764 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2766 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2765 | if ( take == 3 ) | 2767 | if ( take == 3 ) |
2766 | return false; | 2768 | return false; |
2767 | if ( take == 1 ) {// take local | 2769 | if ( take == 1 ) {// take local |
2768 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2770 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2769 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2771 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2770 | local->insertAddressee( inL, false ); | 2772 | local->insertAddressee( inL, false ); |
2771 | idS = inR.externalUID(); | 2773 | idS = inR.externalUID(); |
2772 | OidS = inR.originalExternalUID(); | 2774 | OidS = inR.originalExternalUID(); |
2773 | } | 2775 | } |
2774 | else | 2776 | else |
2775 | idS = inR.IDStr(); | 2777 | idS = inR.IDStr(); |
2776 | remote->removeAddressee( inR ); | 2778 | remote->removeAddressee( inR ); |
2777 | inR = inL; | 2779 | inR = inL; |
2778 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2780 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2779 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2781 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2780 | inR.setOriginalExternalUID( OidS ); | 2782 | inR.setOriginalExternalUID( OidS ); |
2781 | inR.setExternalUID( idS ); | 2783 | inR.setExternalUID( idS ); |
2782 | } else { | 2784 | } else { |
2783 | inR.setIDStr( idS ); | 2785 | inR.setIDStr( idS ); |
2784 | } | 2786 | } |
2785 | inR.setResource( 0 ); | 2787 | inR.setResource( 0 ); |
2786 | remote->insertAddressee( inR , false); | 2788 | remote->insertAddressee( inR , false); |
2787 | ++changedRemote; | 2789 | ++changedRemote; |
2788 | } else { // take == 2 take remote | 2790 | } else { // take == 2 take remote |
2791 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2792 | if ( inR.revision().date().year() < 2004 ) | ||
2793 | inR.setRevision( modifiedCalendar ); | ||
2794 | } | ||
2789 | idS = inL.IDStr(); | 2795 | idS = inL.IDStr(); |
2790 | local->removeAddressee( inL ); | 2796 | local->removeAddressee( inL ); |
2791 | inL = inR; | 2797 | inL = inR; |
2792 | inL.setIDStr( idS ); | 2798 | inL.setIDStr( idS ); |
2793 | inL.setResource( 0 ); | 2799 | inL.setResource( 0 ); |
2794 | local->insertAddressee( inL , false ); | 2800 | local->insertAddressee( inL , false ); |
2795 | ++changedLocal; | 2801 | ++changedLocal; |
2796 | } | 2802 | } |
2797 | } | 2803 | } |
2798 | } else { // no conflict | 2804 | } else { // no conflict |
2799 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2805 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2800 | QString des = addresseeLSync.note(); | 2806 | QString des = addresseeLSync.note(); |
2801 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2807 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2802 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2808 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2803 | remote->insertAddressee( inR, false ); | 2809 | remote->insertAddressee( inR, false ); |
2804 | ++deletedAddresseeR; | 2810 | ++deletedAddresseeR; |
2805 | } else { | 2811 | } else { |
2806 | inR.setRevision( modifiedCalendar ); | 2812 | inR.setRevision( modifiedCalendar ); |
2807 | remote->insertAddressee( inR, false ); | 2813 | remote->insertAddressee( inR, false ); |
2808 | inL = inR; | 2814 | inL = inR; |
2809 | inL.setResource( 0 ); | 2815 | inL.setResource( 0 ); |
2810 | local->insertAddressee( inL , false); | 2816 | local->insertAddressee( inL , false); |
2811 | ++addedAddressee; | 2817 | ++addedAddressee; |
2812 | } | 2818 | } |
2813 | } else { | 2819 | } else { |
2814 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2820 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2815 | inR.setRevision( modifiedCalendar ); | 2821 | inR.setRevision( modifiedCalendar ); |
2816 | remote->insertAddressee( inR, false ); | 2822 | remote->insertAddressee( inR, false ); |
2817 | inR.setResource( 0 ); | 2823 | inR.setResource( 0 ); |
2818 | local->insertAddressee( inR, false ); | 2824 | local->insertAddressee( inR, false ); |
2819 | ++addedAddressee; | 2825 | ++addedAddressee; |
2820 | } else { | 2826 | } else { |
2821 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2827 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2822 | remote->removeAddressee( inR ); | 2828 | remote->removeAddressee( inR ); |
2823 | ++deletedAddresseeR; | 2829 | ++deletedAddresseeR; |
2824 | } | 2830 | } |
2825 | } | 2831 | } |
2826 | } | 2832 | } |
2827 | } | 2833 | } |
2828 | ++incCounter; | 2834 | ++incCounter; |
2829 | } | 2835 | } |
2830 | er.clear(); | 2836 | er.clear(); |
2831 | QStringList el = local->uidList(); | 2837 | QStringList el = local->uidList(); |
2832 | modulo = (el.count()/10)+1; | 2838 | modulo = (el.count()/10)+1; |
2833 | bar.setCaption (i18n("Add / remove addressees") ); | 2839 | bar.setCaption (i18n("Add / remove addressees") ); |
2834 | bar.setTotalSteps ( el.count() ) ; | 2840 | bar.setTotalSteps ( el.count() ) ; |
2835 | bar.show(); | 2841 | bar.show(); |
2836 | incCounter = 0; | 2842 | incCounter = 0; |
2837 | while ( incCounter < el.count()) { | 2843 | while ( incCounter < el.count()) { |
2838 | qApp->processEvents(); | 2844 | qApp->processEvents(); |
2839 | if ( ! bar.isVisible() ) | 2845 | if ( ! bar.isVisible() ) |
2840 | return false; | 2846 | return false; |
2841 | if ( incCounter % modulo == 0 ) | 2847 | if ( incCounter % modulo == 0 ) |
2842 | bar.setProgress( incCounter ); | 2848 | bar.setProgress( incCounter ); |
2843 | uid = el[ incCounter ]; | 2849 | uid = el[ incCounter ]; |
2844 | bool skipIncidence = false; | 2850 | bool skipIncidence = false; |
2845 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2851 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2846 | skipIncidence = true; | 2852 | skipIncidence = true; |
2847 | if ( !skipIncidence ) { | 2853 | if ( !skipIncidence ) { |
2848 | inL = local->findByUid( uid ); | 2854 | inL = local->findByUid( uid ); |
2849 | inR = remote->findByUid( uid ); | 2855 | inR = remote->findByUid( uid ); |
2850 | if ( inR.isEmpty() ) { | 2856 | if ( inR.isEmpty() ) { |
2851 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2857 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2852 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2858 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2853 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2859 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2854 | local->removeAddressee( inL ); | 2860 | local->removeAddressee( inL ); |
2855 | ++deletedAddresseeL; | 2861 | ++deletedAddresseeL; |
2856 | } else { | 2862 | } else { |
2857 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2863 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2858 | inL.removeID(mCurrentSyncDevice ); | 2864 | inL.removeID(mCurrentSyncDevice ); |
2859 | ++addedAddresseeR; | 2865 | ++addedAddresseeR; |
2860 | inL.setRevision( modifiedCalendar ); | 2866 | inL.setRevision( modifiedCalendar ); |
2861 | local->insertAddressee( inL, false ); | 2867 | local->insertAddressee( inL, false ); |
2862 | inR = inL; | 2868 | inR = inL; |
2863 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2869 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2864 | inR.setResource( 0 ); | 2870 | inR.setResource( 0 ); |
2865 | remote->insertAddressee( inR, false ); | 2871 | remote->insertAddressee( inR, false ); |
2866 | } | 2872 | } |
2867 | } | 2873 | } |
2868 | } else { | 2874 | } else { |
2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2875 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2870 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2876 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2871 | local->removeAddressee( inL ); | 2877 | local->removeAddressee( inL ); |
2872 | ++deletedAddresseeL; | 2878 | ++deletedAddresseeL; |
2873 | } else { | 2879 | } else { |
2874 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2880 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2875 | ++addedAddresseeR; | 2881 | ++addedAddresseeR; |
2876 | inL.setRevision( modifiedCalendar ); | 2882 | inL.setRevision( modifiedCalendar ); |
2877 | local->insertAddressee( inL, false ); | 2883 | local->insertAddressee( inL, false ); |
2878 | inR = inL; | 2884 | inR = inL; |
2879 | inR.setResource( 0 ); | 2885 | inR.setResource( 0 ); |
2880 | remote->insertAddressee( inR, false ); | 2886 | remote->insertAddressee( inR, false ); |
2881 | } | 2887 | } |
2882 | } | 2888 | } |
2883 | } | 2889 | } |
2884 | } | 2890 | } |
2885 | } | 2891 | } |
2886 | ++incCounter; | 2892 | ++incCounter; |
2887 | } | 2893 | } |
2888 | el.clear(); | 2894 | el.clear(); |
2889 | bar.hide(); | 2895 | bar.hide(); |
2890 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2896 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2891 | // get rid of micro seconds | 2897 | // get rid of micro seconds |
2892 | QTime t = mLastAddressbookSync.time(); | 2898 | QTime t = mLastAddressbookSync.time(); |
2893 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2899 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2894 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2900 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2895 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2901 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2896 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2902 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2897 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2903 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2898 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2904 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2899 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2905 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2900 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2906 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2901 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2907 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2902 | addresseeRSync.setNote( "" ) ; | 2908 | addresseeRSync.setNote( "" ) ; |
2903 | addresseeLSync.setNote( "" ); | 2909 | addresseeLSync.setNote( "" ); |
2904 | 2910 | ||
2905 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2911 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2906 | remote->insertAddressee( addresseeRSync, false ); | 2912 | remote->insertAddressee( addresseeRSync, false ); |
2907 | local->insertAddressee( addresseeLSync, false ); | 2913 | local->insertAddressee( addresseeLSync, false ); |
2908 | QString mes; | 2914 | QString mes; |
2909 | 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 ); | 2915 | 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 ); |
2910 | if ( KABPrefs::instance()->mShowSyncSummary ) { | 2916 | if ( KABPrefs::instance()->mShowSyncSummary ) { |
2911 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2917 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2912 | } | 2918 | } |
2913 | qDebug( mes ); | 2919 | qDebug( mes ); |
2914 | return syncOK; | 2920 | return syncOK; |
2915 | } | 2921 | } |
2916 | 2922 | ||
2917 | bool KABCore::syncAB(QString filename, int mode) | 2923 | bool KABCore::syncAB(QString filename, int mode) |
2918 | { | 2924 | { |
2919 | 2925 | ||
2920 | //pending prepare addresseeview for output | 2926 | //pending prepare addresseeview for output |
2921 | //pending detect, if remote file has REV field. if not switch to external sync | 2927 | //pending detect, if remote file has REV field. if not switch to external sync |
2922 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2928 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2923 | AddressBook abLocal(filename,"syncContact"); | 2929 | AddressBook abLocal(filename,"syncContact"); |
2924 | bool syncOK = false; | 2930 | bool syncOK = false; |
2925 | if ( abLocal.load() ) { | 2931 | if ( abLocal.load() ) { |
2926 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2932 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2927 | bool external = false; | 2933 | bool external = false; |
2928 | 2934 | bool isXML = false; | |
2929 | if ( filename.right(4) == ".xml") { | 2935 | if ( filename.right(4) == ".xml") { |
2930 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2936 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2937 | isXML = true; | ||
2931 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2938 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2932 | } else { | 2939 | } else { |
2933 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2940 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2934 | if ( ! lse.isEmpty() ) { | 2941 | if ( ! lse.isEmpty() ) { |
2935 | if ( lse.familyName().left(4) == "!E: " ) | 2942 | if ( lse.familyName().left(4) == "!E: " ) |
2936 | external = true; | 2943 | external = true; |
2937 | } else { | 2944 | } else { |
2938 | bool found = false; | 2945 | bool found = false; |
2939 | QDateTime dt( QDate( 2004,1,1)); | ||
2940 | AddressBook::Iterator it; | 2946 | AddressBook::Iterator it; |
2941 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2947 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2942 | if ( (*it).revision() != dt ) { | 2948 | if ( (*it).revision().date().year() > 2003 ) { |
2943 | found = true; | 2949 | found = true; |
2944 | break; | 2950 | break; |
2945 | } | 2951 | } |
2946 | } | 2952 | } |
2947 | external = ! found; | 2953 | external = ! found; |
2948 | } | 2954 | } |
2949 | 2955 | ||
2950 | if ( external ) { | 2956 | if ( external ) { |
2951 | qDebug("Setting vcf mode to external "); | 2957 | qDebug("Setting vcf mode to external "); |
2952 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2958 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2953 | AddressBook::Iterator it; | 2959 | AddressBook::Iterator it; |
2954 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2960 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2955 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2961 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2956 | (*it).computeCsum( mCurrentSyncDevice ); | 2962 | (*it).computeCsum( mCurrentSyncDevice ); |
2957 | } | 2963 | } |
2958 | } | 2964 | } |
2959 | } | 2965 | } |
2960 | //AddressBook::Iterator it; | 2966 | //AddressBook::Iterator it; |
2961 | //QStringList vcards; | 2967 | //QStringList vcards; |
2962 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2968 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2963 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2969 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2964 | //} | 2970 | //} |
2965 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2971 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2966 | if ( syncOK ) { | 2972 | if ( syncOK ) { |
2967 | if ( KABPrefs::instance()->mWriteBackFile ) | 2973 | if ( KABPrefs::instance()->mWriteBackFile ) |
2968 | { | 2974 | { |
2969 | if ( external && filename.right(4) != ".xml") | 2975 | if ( external ) |
2970 | abLocal.removeDeletedAddressees(); | 2976 | abLocal.removeSyncAddressees( !isXML); |
2971 | qDebug("Saving remote AB "); | 2977 | qDebug("Saving remote AB "); |
2972 | abLocal.saveAB(); | 2978 | abLocal.saveAB(); |
2973 | if ( external && filename.right(4) == ".xml") { | 2979 | if ( isXML ) { |
2974 | // afterwrite processing | 2980 | // afterwrite processing |
2975 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2981 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2976 | } | 2982 | } |
2977 | } | 2983 | } |
2978 | } | 2984 | } |
2979 | setModified(); | 2985 | setModified(); |
2980 | 2986 | ||
2981 | } | 2987 | } |
2982 | if ( syncOK ) | 2988 | if ( syncOK ) |
2983 | mViewManager->refreshView(); | 2989 | mViewManager->refreshView(); |
2984 | return syncOK; | 2990 | return syncOK; |
2985 | #if 0 | 2991 | #if 0 |
2986 | 2992 | ||
2987 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2993 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2988 | getEventViewerDialog()->setSyncMode( true ); | 2994 | getEventViewerDialog()->setSyncMode( true ); |
2989 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2995 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2990 | getEventViewerDialog()->setSyncMode( false ); | 2996 | getEventViewerDialog()->setSyncMode( false ); |
2991 | if ( syncOK ) { | 2997 | if ( syncOK ) { |
2992 | if ( KOPrefs::instance()->mWriteBackFile ) | 2998 | if ( KOPrefs::instance()->mWriteBackFile ) |
2993 | { | 2999 | { |
2994 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 3000 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2995 | storage->save(); | 3001 | storage->save(); |
2996 | } | 3002 | } |
2997 | } | 3003 | } |
2998 | setModified(); | 3004 | setModified(); |
2999 | } | 3005 | } |
3000 | 3006 | ||
3001 | #endif | 3007 | #endif |
3002 | } | 3008 | } |
3003 | 3009 | ||
3004 | void KABCore::confSync() | 3010 | void KABCore::confSync() |
3005 | { | 3011 | { |
3006 | static KSyncPrefsDialog* sp = 0; | 3012 | static KSyncPrefsDialog* sp = 0; |
3007 | if ( ! sp ) { | 3013 | if ( ! sp ) { |
3008 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 3014 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
3009 | } | 3015 | } |
3010 | sp->usrReadConfig(); | 3016 | sp->usrReadConfig(); |
3011 | #ifndef DESKTOP_VERSION | 3017 | #ifndef DESKTOP_VERSION |
3012 | sp->showMaximized(); | 3018 | sp->showMaximized(); |
3013 | #else | 3019 | #else |
3014 | sp->show(); | 3020 | sp->show(); |
3015 | #endif | 3021 | #endif |
3016 | sp->exec(); | 3022 | sp->exec(); |
3017 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 3023 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
3018 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 3024 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
3019 | fillSyncMenu(); | 3025 | fillSyncMenu(); |
3020 | } | 3026 | } |
3021 | void KABCore::syncSharp() | 3027 | void KABCore::syncSharp() |
3022 | { | 3028 | { |
3023 | if ( mModified ) | 3029 | if ( mModified ) |
3024 | save(); | 3030 | save(); |
3025 | qDebug("pending syncSharp() "); | 3031 | qDebug("pending syncSharp() "); |
3026 | //mView->syncSharp(); | 3032 | //mView->syncSharp(); |
3027 | setModified(); | 3033 | setModified(); |
3028 | 3034 | ||
3029 | } | 3035 | } |
3030 | void KABCore::syncPhone() | 3036 | void KABCore::syncPhone() |
3031 | { | 3037 | { |
3032 | if ( mModified ) | 3038 | if ( mModified ) |
3033 | save(); | 3039 | save(); |
3034 | qDebug("pending syncPhone(); "); | 3040 | qDebug("pending syncPhone(); "); |
3035 | //mView->syncPhone(); | 3041 | //mView->syncPhone(); |
3036 | setModified(); | 3042 | setModified(); |
3037 | 3043 | ||
3038 | } | 3044 | } |
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 0c75632..8e83723 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1,2871 +1,2873 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Requires the Qt and KDE widget libraries, available at no cost at | 4 | Requires the Qt and KDE widget libraries, available at no cost at |
5 | http://www.troll.no and http://www.kde.org respectively | 5 | http://www.troll.no and http://www.kde.org respectively |
6 | 6 | ||
7 | Copyright (c) 1997, 1998, 1999 | 7 | Copyright (c) 1997, 1998, 1999 |
8 | Preston Brown (preston.brown@yale.edu) | 8 | Preston Brown (preston.brown@yale.edu) |
9 | Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) | 9 | Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) |
10 | Ian Dawes (iadawes@globalserve.net) | 10 | Ian Dawes (iadawes@globalserve.net) |
11 | Laszlo Boloni (boloni@cs.purdue.edu) | 11 | Laszlo Boloni (boloni@cs.purdue.edu) |
12 | 12 | ||
13 | Copyright (c) 2000, 2001, 2002 | 13 | Copyright (c) 2000, 2001, 2002 |
14 | Cornelius Schumacher <schumacher@kde.org> | 14 | Cornelius Schumacher <schumacher@kde.org> |
15 | 15 | ||
16 | This program is free software; you can redistribute it and/or modify | 16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | 17 | it under the terms of the GNU General Public License as published by |
18 | the Free Software Foundation; either version 2 of the License, or | 18 | the Free Software Foundation; either version 2 of the License, or |
19 | (at your option) any later version. | 19 | (at your option) any later version. |
20 | 20 | ||
21 | This program is distributed in the hope that it will be useful, | 21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
24 | GNU General Public License for more details. | 24 | GNU General Public License for more details. |
25 | 25 | ||
26 | You should have received a copy of the GNU General Public License | 26 | You should have received a copy of the GNU General Public License |
27 | along with this program; if not, write to the Free Software | 27 | along with this program; if not, write to the Free Software |
28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | 32 | ||
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qradiobutton.h> | 34 | #include <qradiobutton.h> |
35 | #include <qbuttongroup.h> | 35 | #include <qbuttongroup.h> |
36 | #include <qlayout.h> | 36 | #include <qlayout.h> |
37 | #include <qclipboard.h> | 37 | #include <qclipboard.h> |
38 | #include <qcursor.h> | 38 | #include <qcursor.h> |
39 | #include <qmessagebox.h> | 39 | #include <qmessagebox.h> |
40 | #include <qprogressbar.h> | 40 | #include <qprogressbar.h> |
41 | #include <qmultilineedit.h> | 41 | #include <qmultilineedit.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qwidgetstack.h> | 43 | #include <qwidgetstack.h> |
44 | #include <qptrlist.h> | 44 | #include <qptrlist.h> |
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | #include <qgroupbox.h> | 46 | #include <qgroupbox.h> |
47 | #include <qfile.h> | 47 | #include <qfile.h> |
48 | #include <qdir.h> | 48 | #include <qdir.h> |
49 | #ifndef KORG_NOSPLITTER | 49 | #ifndef KORG_NOSPLITTER |
50 | #include <qsplitter.h> | 50 | #include <qsplitter.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #include <kglobal.h> | 53 | #include <kglobal.h> |
54 | #include <kdebug.h> | 54 | #include <kdebug.h> |
55 | #include <kstandarddirs.h> | 55 | #include <kstandarddirs.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | #include <kmessagebox.h> | 57 | #include <kmessagebox.h> |
58 | #include <knotifyclient.h> | 58 | #include <knotifyclient.h> |
59 | #include <kconfig.h> | 59 | #include <kconfig.h> |
60 | 60 | ||
61 | #include <libkdepim/ksyncprefsdialog.h> | 61 | #include <libkdepim/ksyncprefsdialog.h> |
62 | #include <krun.h> | 62 | #include <krun.h> |
63 | #include <kdirwatch.h> | 63 | #include <kdirwatch.h> |
64 | #include <libkdepim/kdatepicker.h> | 64 | #include <libkdepim/kdatepicker.h> |
65 | #include <libkdepim/ksyncprofile.h> | 65 | #include <libkdepim/ksyncprofile.h> |
66 | 66 | ||
67 | #include <libkcal/vcaldrag.h> | 67 | #include <libkcal/vcaldrag.h> |
68 | #include <libkcal/icaldrag.h> | 68 | #include <libkcal/icaldrag.h> |
69 | #include <libkcal/icalformat.h> | 69 | #include <libkcal/icalformat.h> |
70 | #include <libkcal/vcalformat.h> | 70 | #include <libkcal/vcalformat.h> |
71 | #include <libkcal/scheduler.h> | 71 | #include <libkcal/scheduler.h> |
72 | #include <libkcal/calendarlocal.h> | 72 | #include <libkcal/calendarlocal.h> |
73 | #include <libkcal/journal.h> | 73 | #include <libkcal/journal.h> |
74 | #include <libkcal/calfilter.h> | 74 | #include <libkcal/calfilter.h> |
75 | #include <libkcal/attendee.h> | 75 | #include <libkcal/attendee.h> |
76 | #include <libkcal/dndfactory.h> | 76 | #include <libkcal/dndfactory.h> |
77 | #include <libkcal/freebusy.h> | 77 | #include <libkcal/freebusy.h> |
78 | #include <libkcal/filestorage.h> | 78 | #include <libkcal/filestorage.h> |
79 | #include <libkcal/calendarresources.h> | 79 | #include <libkcal/calendarresources.h> |
80 | #include <libkcal/qtopiaformat.h> | 80 | #include <libkcal/qtopiaformat.h> |
81 | #include "../kalarmd/alarmdialog.h" | 81 | #include "../kalarmd/alarmdialog.h" |
82 | 82 | ||
83 | #ifndef DESKTOP_VERSION | 83 | #ifndef DESKTOP_VERSION |
84 | #include <libkcal/sharpformat.h> | 84 | #include <libkcal/sharpformat.h> |
85 | #endif | 85 | #endif |
86 | #include <libkcal/phoneformat.h> | 86 | #include <libkcal/phoneformat.h> |
87 | #ifndef KORG_NOMAIL | 87 | #ifndef KORG_NOMAIL |
88 | #include "komailclient.h" | 88 | #include "komailclient.h" |
89 | #endif | 89 | #endif |
90 | #ifndef KORG_NOPRINTER | 90 | #ifndef KORG_NOPRINTER |
91 | #include "calprinter.h" | 91 | #include "calprinter.h" |
92 | #endif | 92 | #endif |
93 | #ifndef KORG_NOPLUGINS | 93 | #ifndef KORG_NOPLUGINS |
94 | #include "kocore.h" | 94 | #include "kocore.h" |
95 | #endif | 95 | #endif |
96 | #include "koeventeditor.h" | 96 | #include "koeventeditor.h" |
97 | #include "kotodoeditor.h" | 97 | #include "kotodoeditor.h" |
98 | #include "koprefs.h" | 98 | #include "koprefs.h" |
99 | #include "koeventviewerdialog.h" | 99 | #include "koeventviewerdialog.h" |
100 | #include "publishdialog.h" | 100 | #include "publishdialog.h" |
101 | #include "kofilterview.h" | 101 | #include "kofilterview.h" |
102 | #include "koglobals.h" | 102 | #include "koglobals.h" |
103 | #include "koviewmanager.h" | 103 | #include "koviewmanager.h" |
104 | #include "koagendaview.h" | 104 | #include "koagendaview.h" |
105 | #include "kodialogmanager.h" | 105 | #include "kodialogmanager.h" |
106 | #include "outgoingdialog.h" | 106 | #include "outgoingdialog.h" |
107 | #include "incomingdialog.h" | 107 | #include "incomingdialog.h" |
108 | #include "statusdialog.h" | 108 | #include "statusdialog.h" |
109 | #include "kdatenavigator.h" | 109 | #include "kdatenavigator.h" |
110 | #include "kotodoview.h" | 110 | #include "kotodoview.h" |
111 | #include "datenavigator.h" | 111 | #include "datenavigator.h" |
112 | #include "resourceview.h" | 112 | #include "resourceview.h" |
113 | #include "navigatorbar.h" | 113 | #include "navigatorbar.h" |
114 | #include "searchdialog.h" | 114 | #include "searchdialog.h" |
115 | #include "mainwindow.h" | 115 | #include "mainwindow.h" |
116 | 116 | ||
117 | #include "calendarview.h" | 117 | #include "calendarview.h" |
118 | #ifndef DESKTOP_VERSION | 118 | #ifndef DESKTOP_VERSION |
119 | #include <qtopia/alarmserver.h> | 119 | #include <qtopia/alarmserver.h> |
120 | #endif | 120 | #endif |
121 | #ifndef _WIN32_ | 121 | #ifndef _WIN32_ |
122 | #include <stdlib.h> | 122 | #include <stdlib.h> |
123 | #include <stdio.h> | 123 | #include <stdio.h> |
124 | #include <unistd.h> | 124 | #include <unistd.h> |
125 | #else | 125 | #else |
126 | #include <qprocess.h> | 126 | #include <qprocess.h> |
127 | #endif | 127 | #endif |
128 | using namespace KOrg; | 128 | using namespace KOrg; |
129 | using namespace KCal; | 129 | using namespace KCal; |
130 | extern int globalFlagBlockAgenda; | 130 | extern int globalFlagBlockAgenda; |
131 | extern int globalFlagBlockStartup; | 131 | extern int globalFlagBlockStartup; |
132 | 132 | ||
133 | 133 | ||
134 | 134 | ||
135 | class KOBeamPrefs : public QDialog | 135 | class KOBeamPrefs : public QDialog |
136 | { | 136 | { |
137 | public: | 137 | public: |
138 | KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : | 138 | KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : |
139 | QDialog( parent, name, true ) | 139 | QDialog( parent, name, true ) |
140 | { | 140 | { |
141 | setCaption( i18n("Beam Options") ); | 141 | setCaption( i18n("Beam Options") ); |
142 | QVBoxLayout* lay = new QVBoxLayout( this ); | 142 | QVBoxLayout* lay = new QVBoxLayout( this ); |
143 | lay->setSpacing( 3 ); | 143 | lay->setSpacing( 3 ); |
144 | lay->setMargin( 3 ); | 144 | lay->setMargin( 3 ); |
145 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); | 145 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); |
146 | lay->addWidget( format ); | 146 | lay->addWidget( format ); |
147 | format->setExclusive ( true ) ; | 147 | format->setExclusive ( true ) ; |
148 | QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); | 148 | QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); |
149 | lay->addWidget( time ); time->setExclusive ( true ) ; | 149 | lay->addWidget( time ); time->setExclusive ( true ) ; |
150 | vcal = new QRadioButton(" vCalendar ", format ); | 150 | vcal = new QRadioButton(" vCalendar ", format ); |
151 | ical = new QRadioButton(" iCalendar ", format ); | 151 | ical = new QRadioButton(" iCalendar ", format ); |
152 | vcal->setChecked( true ); | 152 | vcal->setChecked( true ); |
153 | tz = new QRadioButton(i18n(" With timezone "), time ); | 153 | tz = new QRadioButton(i18n(" With timezone "), time ); |
154 | local = new QRadioButton(i18n(" Local time "), time ); | 154 | local = new QRadioButton(i18n(" Local time "), time ); |
155 | tz->setChecked( true ); | 155 | tz->setChecked( true ); |
156 | QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); | 156 | QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); |
157 | lay->addWidget( ok ); | 157 | lay->addWidget( ok ); |
158 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 158 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
159 | lay->addWidget( cancel ); | 159 | lay->addWidget( cancel ); |
160 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 160 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
161 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 161 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
162 | resize( 200, 200 ); | 162 | resize( 200, 200 ); |
163 | } | 163 | } |
164 | 164 | ||
165 | bool beamVcal() { return vcal->isChecked(); } | 165 | bool beamVcal() { return vcal->isChecked(); } |
166 | bool beamLocal() { return local->isChecked(); } | 166 | bool beamLocal() { return local->isChecked(); } |
167 | private: | 167 | private: |
168 | QRadioButton* vcal, *ical, *local, *tz; | 168 | QRadioButton* vcal, *ical, *local, *tz; |
169 | }; | 169 | }; |
170 | class KOCatPrefs : public QDialog | 170 | class KOCatPrefs : public QDialog |
171 | { | 171 | { |
172 | public: | 172 | public: |
173 | KOCatPrefs( QWidget *parent=0, const char *name=0 ) : | 173 | KOCatPrefs( QWidget *parent=0, const char *name=0 ) : |
174 | QDialog( parent, name, true ) | 174 | QDialog( parent, name, true ) |
175 | { | 175 | { |
176 | setCaption( i18n("Manage new Categories") ); | 176 | setCaption( i18n("Manage new Categories") ); |
177 | QVBoxLayout* lay = new QVBoxLayout( this ); | 177 | QVBoxLayout* lay = new QVBoxLayout( this ); |
178 | lay->setSpacing( 3 ); | 178 | lay->setSpacing( 3 ); |
179 | lay->setMargin( 3 ); | 179 | lay->setMargin( 3 ); |
180 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); | 180 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); |
181 | lay->addWidget( lab ); | 181 | lay->addWidget( lab ); |
182 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); | 182 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); |
183 | lay->addWidget( format ); | 183 | lay->addWidget( format ); |
184 | format->setExclusive ( true ) ; | 184 | format->setExclusive ( true ) ; |
185 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); | 185 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); |
186 | new QRadioButton(i18n("Remove from Events/Todos"), format ); | 186 | new QRadioButton(i18n("Remove from Events/Todos"), format ); |
187 | addCatBut->setChecked( true ); | 187 | addCatBut->setChecked( true ); |
188 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | 188 | QPushButton * ok = new QPushButton( i18n("OK"), this ); |
189 | lay->addWidget( ok ); | 189 | lay->addWidget( ok ); |
190 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 190 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
191 | lay->addWidget( cancel ); | 191 | lay->addWidget( cancel ); |
192 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 192 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
193 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 193 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
194 | resize( 200, 200 ); | 194 | resize( 200, 200 ); |
195 | } | 195 | } |
196 | 196 | ||
197 | bool addCat() { return addCatBut->isChecked(); } | 197 | bool addCat() { return addCatBut->isChecked(); } |
198 | private: | 198 | private: |
199 | QRadioButton* addCatBut; | 199 | QRadioButton* addCatBut; |
200 | }; | 200 | }; |
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | CalendarView::CalendarView( CalendarResources *calendar, | 204 | CalendarView::CalendarView( CalendarResources *calendar, |
205 | QWidget *parent, const char *name ) | 205 | QWidget *parent, const char *name ) |
206 | : CalendarViewBase( parent, name ), | 206 | : CalendarViewBase( parent, name ), |
207 | mCalendar( calendar ), | 207 | mCalendar( calendar ), |
208 | mResourceManager( calendar->resourceManager() ) | 208 | mResourceManager( calendar->resourceManager() ) |
209 | { | 209 | { |
210 | 210 | ||
211 | mEventEditor = 0; | 211 | mEventEditor = 0; |
212 | mTodoEditor = 0; | 212 | mTodoEditor = 0; |
213 | 213 | ||
214 | init(); | 214 | init(); |
215 | } | 215 | } |
216 | 216 | ||
217 | CalendarView::CalendarView( Calendar *calendar, | 217 | CalendarView::CalendarView( Calendar *calendar, |
218 | QWidget *parent, const char *name ) | 218 | QWidget *parent, const char *name ) |
219 | : CalendarViewBase( parent, name ), | 219 | : CalendarViewBase( parent, name ), |
220 | mCalendar( calendar ), | 220 | mCalendar( calendar ), |
221 | mResourceManager( 0 ) | 221 | mResourceManager( 0 ) |
222 | { | 222 | { |
223 | 223 | ||
224 | mEventEditor = 0; | 224 | mEventEditor = 0; |
225 | mTodoEditor = 0; | 225 | mTodoEditor = 0; |
226 | init();} | 226 | init();} |
227 | 227 | ||
228 | void CalendarView::init() | 228 | void CalendarView::init() |
229 | { | 229 | { |
230 | beamDialog = new KOBeamPrefs(); | 230 | beamDialog = new KOBeamPrefs(); |
231 | mDatePickerMode = 0; | 231 | mDatePickerMode = 0; |
232 | mCurrentSyncDevice = ""; | 232 | mCurrentSyncDevice = ""; |
233 | writeLocale(); | 233 | writeLocale(); |
234 | mViewManager = new KOViewManager( this ); | 234 | mViewManager = new KOViewManager( this ); |
235 | mDialogManager = new KODialogManager( this ); | 235 | mDialogManager = new KODialogManager( this ); |
236 | mEventViewerDialog = 0; | 236 | mEventViewerDialog = 0; |
237 | mModified = false; | 237 | mModified = false; |
238 | mReadOnly = false; | 238 | mReadOnly = false; |
239 | mSelectedIncidence = 0; | 239 | mSelectedIncidence = 0; |
240 | mCalPrinter = 0; | 240 | mCalPrinter = 0; |
241 | mFilters.setAutoDelete(true); | 241 | mFilters.setAutoDelete(true); |
242 | 242 | ||
243 | mCalendar->registerObserver( this ); | 243 | mCalendar->registerObserver( this ); |
244 | // TODO: Make sure that view is updated, when calendar is changed. | 244 | // TODO: Make sure that view is updated, when calendar is changed. |
245 | 245 | ||
246 | mStorage = new FileStorage( mCalendar ); | 246 | mStorage = new FileStorage( mCalendar ); |
247 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); | 247 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); |
248 | 248 | ||
249 | QBoxLayout *topLayout = (QBoxLayout*)layout(); | 249 | QBoxLayout *topLayout = (QBoxLayout*)layout(); |
250 | #ifndef KORG_NOSPLITTER | 250 | #ifndef KORG_NOSPLITTER |
251 | // create the main layout frames. | 251 | // create the main layout frames. |
252 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); | 252 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); |
253 | topLayout->addWidget(mPanner); | 253 | topLayout->addWidget(mPanner); |
254 | 254 | ||
255 | mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, | 255 | mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, |
256 | "CalendarView::LeftFrame"); | 256 | "CalendarView::LeftFrame"); |
257 | mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); | 257 | mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); |
258 | 258 | ||
259 | mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, | 259 | mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, |
260 | "CalendarView::DateNavigator", QDate::currentDate() ); | 260 | "CalendarView::DateNavigator", QDate::currentDate() ); |
261 | mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); | 261 | mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); |
262 | mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); | 262 | mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); |
263 | mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); | 263 | mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); |
264 | 264 | ||
265 | #ifdef KORG_NORESOURCEVIEW | 265 | #ifdef KORG_NORESOURCEVIEW |
266 | mResourceView = 0; | 266 | mResourceView = 0; |
267 | #else | 267 | #else |
268 | if ( mResourceManager ) { | 268 | if ( mResourceManager ) { |
269 | mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); | 269 | mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); |
270 | mResourceView->updateView(); | 270 | mResourceView->updateView(); |
271 | connect( mResourceView, SIGNAL( resourcesChanged() ), | 271 | connect( mResourceView, SIGNAL( resourcesChanged() ), |
272 | SLOT( updateView() ) ); | 272 | SLOT( updateView() ) ); |
273 | } else { | 273 | } else { |
274 | mResourceView = 0; | 274 | mResourceView = 0; |
275 | } | 275 | } |
276 | #endif | 276 | #endif |
277 | QWidget *rightBox = new QWidget( mPanner ); | 277 | QWidget *rightBox = new QWidget( mPanner ); |
278 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); | 278 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); |
279 | 279 | ||
280 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); | 280 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); |
281 | rightLayout->addWidget( mNavigatorBar ); | 281 | rightLayout->addWidget( mNavigatorBar ); |
282 | 282 | ||
283 | mRightFrame = new QWidgetStack( rightBox ); | 283 | mRightFrame = new QWidgetStack( rightBox ); |
284 | rightLayout->addWidget( mRightFrame, 1 ); | 284 | rightLayout->addWidget( mRightFrame, 1 ); |
285 | 285 | ||
286 | mLeftFrame = mLeftSplitter; | 286 | mLeftFrame = mLeftSplitter; |
287 | #else | 287 | #else |
288 | QWidget *mainBox = new QWidget( this ); | 288 | QWidget *mainBox = new QWidget( this ); |
289 | QWidget *leftFrame = new QWidget( mainBox ); | 289 | QWidget *leftFrame = new QWidget( mainBox ); |
290 | 290 | ||
291 | QBoxLayout * mainBoxLayout; | 291 | QBoxLayout * mainBoxLayout; |
292 | QBoxLayout * leftFrameLayout; | 292 | QBoxLayout * leftFrameLayout; |
293 | if ( KOPrefs::instance()->mVerticalScreen ) { | 293 | if ( KOPrefs::instance()->mVerticalScreen ) { |
294 | mainBoxLayout = new QVBoxLayout(mainBox); | 294 | mainBoxLayout = new QVBoxLayout(mainBox); |
295 | leftFrameLayout = new QHBoxLayout(leftFrame ); | 295 | leftFrameLayout = new QHBoxLayout(leftFrame ); |
296 | } else { | 296 | } else { |
297 | mainBoxLayout = new QHBoxLayout(mainBox); | 297 | mainBoxLayout = new QHBoxLayout(mainBox); |
298 | leftFrameLayout = new QVBoxLayout(leftFrame ); | 298 | leftFrameLayout = new QVBoxLayout(leftFrame ); |
299 | } | 299 | } |
300 | topLayout->addWidget( mainBox ); | 300 | topLayout->addWidget( mainBox ); |
301 | mainBoxLayout->addWidget (leftFrame); | 301 | mainBoxLayout->addWidget (leftFrame); |
302 | mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, | 302 | mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, |
303 | "CalendarView::DateNavigator", QDate::currentDate()); | 303 | "CalendarView::DateNavigator", QDate::currentDate()); |
304 | // mDateNavigator->blockSignals( true ); | 304 | // mDateNavigator->blockSignals( true ); |
305 | leftFrameLayout->addWidget( mDateNavigator ); | 305 | leftFrameLayout->addWidget( mDateNavigator ); |
306 | mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); | 306 | mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); |
307 | mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); | 307 | mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); |
308 | 308 | ||
309 | if ( QApplication::desktop()->width() < 480 ) { | 309 | if ( QApplication::desktop()->width() < 480 ) { |
310 | leftFrameLayout->addWidget(mFilterView); | 310 | leftFrameLayout->addWidget(mFilterView); |
311 | leftFrameLayout->addWidget(mTodoList, 2 ); | 311 | leftFrameLayout->addWidget(mTodoList, 2 ); |
312 | 312 | ||
313 | } else { | 313 | } else { |
314 | leftFrameLayout->addWidget(mTodoList,2 ); | 314 | leftFrameLayout->addWidget(mTodoList,2 ); |
315 | leftFrameLayout->addWidget(mFilterView ); | 315 | leftFrameLayout->addWidget(mFilterView ); |
316 | } | 316 | } |
317 | mFilterView->hide(); | 317 | mFilterView->hide(); |
318 | QWidget *rightBox = new QWidget( mainBox ); | 318 | QWidget *rightBox = new QWidget( mainBox ); |
319 | mainBoxLayout->addWidget ( rightBox, 10 ); | 319 | mainBoxLayout->addWidget ( rightBox, 10 ); |
320 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); | 320 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); |
321 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); | 321 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); |
322 | mRightFrame = new QWidgetStack( rightBox ); | 322 | mRightFrame = new QWidgetStack( rightBox ); |
323 | rightLayout->addWidget( mNavigatorBar ); | 323 | rightLayout->addWidget( mNavigatorBar ); |
324 | rightLayout->addWidget( mRightFrame, 10 ); | 324 | rightLayout->addWidget( mRightFrame, 10 ); |
325 | 325 | ||
326 | mLeftFrame = leftFrame; | 326 | mLeftFrame = leftFrame; |
327 | if ( KOPrefs::instance()->mVerticalScreen ) { | 327 | if ( KOPrefs::instance()->mVerticalScreen ) { |
328 | mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); | 328 | mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); |
329 | leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); | 329 | leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); |
330 | } else { | 330 | } else { |
331 | mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); | 331 | mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); |
332 | leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); | 332 | leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); |
333 | } | 333 | } |
334 | 334 | ||
335 | //qDebug("Calendarview Size %d %d ", width(), height()); | 335 | //qDebug("Calendarview Size %d %d ", width(), height()); |
336 | #endif | 336 | #endif |
337 | 337 | ||
338 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 338 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
339 | SLOT( showDates( const KCal::DateList & ) ) ); | 339 | SLOT( showDates( const KCal::DateList & ) ) ); |
340 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 340 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
341 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 341 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
342 | 342 | ||
343 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), | 343 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), |
344 | mNavigator, SLOT( selectPreviousYear() ) ); | 344 | mNavigator, SLOT( selectPreviousYear() ) ); |
345 | connect( mNavigatorBar, SIGNAL( goNextYear() ), | 345 | connect( mNavigatorBar, SIGNAL( goNextYear() ), |
346 | mNavigator, SLOT( selectNextYear() ) ); | 346 | mNavigator, SLOT( selectNextYear() ) ); |
347 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), | 347 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), |
348 | mNavigator, SLOT( selectPreviousMonth() ) ); | 348 | mNavigator, SLOT( selectPreviousMonth() ) ); |
349 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), | 349 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), |
350 | mNavigator, SLOT( selectNextMonth() ) ); | 350 | mNavigator, SLOT( selectNextMonth() ) ); |
351 | 351 | ||
352 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 352 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
353 | mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); | 353 | mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); |
354 | 354 | ||
355 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), | 355 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), |
356 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); | 356 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); |
357 | 357 | ||
358 | connect( mDateNavigator, SIGNAL( goPrevYear() ), | 358 | connect( mDateNavigator, SIGNAL( goPrevYear() ), |
359 | mNavigator, SLOT( selectPreviousYear() ) ); | 359 | mNavigator, SLOT( selectPreviousYear() ) ); |
360 | connect( mDateNavigator, SIGNAL( goNextYear() ), | 360 | connect( mDateNavigator, SIGNAL( goNextYear() ), |
361 | mNavigator, SLOT( selectNextYear() ) ); | 361 | mNavigator, SLOT( selectNextYear() ) ); |
362 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), | 362 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), |
363 | mNavigator, SLOT( selectPreviousMonth() ) ); | 363 | mNavigator, SLOT( selectPreviousMonth() ) ); |
364 | connect( mDateNavigator, SIGNAL( goNextMonth() ), | 364 | connect( mDateNavigator, SIGNAL( goNextMonth() ), |
365 | mNavigator, SLOT( selectNextMonth() ) ); | 365 | mNavigator, SLOT( selectNextMonth() ) ); |
366 | 366 | ||
367 | connect( mDateNavigator, SIGNAL( goPrevious() ), | 367 | connect( mDateNavigator, SIGNAL( goPrevious() ), |
368 | mNavigator, SLOT( selectPrevious() ) ); | 368 | mNavigator, SLOT( selectPrevious() ) ); |
369 | connect( mDateNavigator, SIGNAL( goNext() ), | 369 | connect( mDateNavigator, SIGNAL( goNext() ), |
370 | mNavigator, SLOT( selectNext() ) ); | 370 | mNavigator, SLOT( selectNext() ) ); |
371 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), | 371 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), |
372 | mNavigator, SLOT( slotMonthSelect( int ) ) ); | 372 | mNavigator, SLOT( slotMonthSelect( int ) ) ); |
373 | connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), | 373 | connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), |
374 | mNavigator, SLOT( slotMonthSelect( int ) ) ); | 374 | mNavigator, SLOT( slotMonthSelect( int ) ) ); |
375 | 375 | ||
376 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 376 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
377 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 377 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
378 | 378 | ||
379 | connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), | 379 | connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), |
380 | SLOT( eventAdded( Event *) ) ); | 380 | SLOT( eventAdded( Event *) ) ); |
381 | 381 | ||
382 | connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); | 382 | connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); |
383 | 383 | ||
384 | connect( this, SIGNAL( configChanged() ), | 384 | connect( this, SIGNAL( configChanged() ), |
385 | mDateNavigator, SLOT( updateConfig() ) ); | 385 | mDateNavigator, SLOT( updateConfig() ) ); |
386 | 386 | ||
387 | connect( mTodoList, SIGNAL( newTodoSignal() ), | 387 | connect( mTodoList, SIGNAL( newTodoSignal() ), |
388 | SLOT( newTodo() ) ); | 388 | SLOT( newTodo() ) ); |
389 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), | 389 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), |
390 | SLOT( newSubTodo( Todo * ) ) ); | 390 | SLOT( newSubTodo( Todo * ) ) ); |
391 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), | 391 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), |
392 | SLOT( editTodo( Todo * ) ) ); | 392 | SLOT( editTodo( Todo * ) ) ); |
393 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), | 393 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), |
394 | SLOT( showTodo( Todo *) ) ); | 394 | SLOT( showTodo( Todo *) ) ); |
395 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), | 395 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), |
396 | SLOT( deleteTodo( Todo *) ) ); | 396 | SLOT( deleteTodo( Todo *) ) ); |
397 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); | 397 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); |
398 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), | 398 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), |
399 | SLOT( purgeCompleted() ) ); | 399 | SLOT( purgeCompleted() ) ); |
400 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), | 400 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), |
401 | SIGNAL( todoModified( Todo *, int ) ) ); | 401 | SIGNAL( todoModified( Todo *, int ) ) ); |
402 | 402 | ||
403 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), | 403 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), |
404 | this, SLOT ( cloneIncidence( Incidence * ) ) ); | 404 | this, SLOT ( cloneIncidence( Incidence * ) ) ); |
405 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), | 405 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), |
406 | this, SLOT (cancelIncidence( Incidence * ) ) ); | 406 | this, SLOT (cancelIncidence( Incidence * ) ) ); |
407 | 407 | ||
408 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), | 408 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), |
409 | this, SLOT ( moveIncidence( Incidence * ) ) ); | 409 | this, SLOT ( moveIncidence( Incidence * ) ) ); |
410 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), | 410 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), |
411 | this, SLOT ( beamIncidence( Incidence * ) ) ); | 411 | this, SLOT ( beamIncidence( Incidence * ) ) ); |
412 | 412 | ||
413 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), | 413 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), |
414 | this, SLOT ( todo_unsub( Todo * ) ) ); | 414 | this, SLOT ( todo_unsub( Todo * ) ) ); |
415 | 415 | ||
416 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, | 416 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, |
417 | SLOT( updateTodo( Todo *, int ) ) ); | 417 | SLOT( updateTodo( Todo *, int ) ) ); |
418 | connect( this, SIGNAL( todoModified( Todo *, int )), this, | 418 | connect( this, SIGNAL( todoModified( Todo *, int )), this, |
419 | SLOT( changeTodoDisplay( Todo *, int ) ) ); | 419 | SLOT( changeTodoDisplay( Todo *, int ) ) ); |
420 | 420 | ||
421 | 421 | ||
422 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); | 422 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); |
423 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); | 423 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); |
424 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); | 424 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); |
425 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); | 425 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); |
426 | 426 | ||
427 | 427 | ||
428 | 428 | ||
429 | 429 | ||
430 | 430 | ||
431 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), | 431 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), |
432 | SLOT(checkClipboard())); | 432 | SLOT(checkClipboard())); |
433 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), | 433 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), |
434 | SLOT( processTodoListSelection( Incidence * ) ) ); | 434 | SLOT( processTodoListSelection( Incidence * ) ) ); |
435 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); | 435 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); |
436 | 436 | ||
437 | // kdDebug() << "CalendarView::CalendarView() done" << endl; | 437 | // kdDebug() << "CalendarView::CalendarView() done" << endl; |
438 | 438 | ||
439 | mDateFrame = new QVBox(0,0,WType_Popup); | 439 | mDateFrame = new QVBox(0,0,WType_Popup); |
440 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 440 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
441 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 441 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
442 | mDateFrame->setLineWidth(3); | 442 | mDateFrame->setLineWidth(3); |
443 | mDateFrame->hide(); | 443 | mDateFrame->hide(); |
444 | mDateFrame->setCaption( i18n( "Pick a date to display")); | 444 | mDateFrame->setCaption( i18n( "Pick a date to display")); |
445 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); | 445 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); |
446 | 446 | ||
447 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); | 447 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); |
448 | 448 | ||
449 | mEventEditor = mDialogManager->getEventEditor(); | 449 | mEventEditor = mDialogManager->getEventEditor(); |
450 | mTodoEditor = mDialogManager->getTodoEditor(); | 450 | mTodoEditor = mDialogManager->getTodoEditor(); |
451 | 451 | ||
452 | mFlagEditDescription = false; | 452 | mFlagEditDescription = false; |
453 | 453 | ||
454 | mSuspendTimer = new QTimer( this ); | 454 | mSuspendTimer = new QTimer( this ); |
455 | mAlarmTimer = new QTimer( this ); | 455 | mAlarmTimer = new QTimer( this ); |
456 | mRecheckAlarmTimer = new QTimer( this ); | 456 | mRecheckAlarmTimer = new QTimer( this ); |
457 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); | 457 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); |
458 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); | 458 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); |
459 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); | 459 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); |
460 | mAlarmDialog = new AlarmDialog( this ); | 460 | mAlarmDialog = new AlarmDialog( this ); |
461 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); | 461 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); |
462 | mAlarmDialog->setServerNotification( false ); | 462 | mAlarmDialog->setServerNotification( false ); |
463 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); | 463 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | CalendarView::~CalendarView() | 467 | CalendarView::~CalendarView() |
468 | { | 468 | { |
469 | // kdDebug() << "~CalendarView()" << endl; | 469 | // kdDebug() << "~CalendarView()" << endl; |
470 | //qDebug("CalendarView::~CalendarView() "); | 470 | //qDebug("CalendarView::~CalendarView() "); |
471 | delete mDialogManager; | 471 | delete mDialogManager; |
472 | delete mViewManager; | 472 | delete mViewManager; |
473 | delete mStorage; | 473 | delete mStorage; |
474 | delete mDateFrame ; | 474 | delete mDateFrame ; |
475 | delete beamDialog; | 475 | delete beamDialog; |
476 | //kdDebug() << "~CalendarView() done" << endl; | 476 | //kdDebug() << "~CalendarView() done" << endl; |
477 | } | 477 | } |
478 | void CalendarView::timerAlarm() | 478 | void CalendarView::timerAlarm() |
479 | { | 479 | { |
480 | //qDebug("CalendarView::timerAlarm() "); | 480 | //qDebug("CalendarView::timerAlarm() "); |
481 | computeAlarm(mAlarmNotification ); | 481 | computeAlarm(mAlarmNotification ); |
482 | } | 482 | } |
483 | 483 | ||
484 | void CalendarView::suspendAlarm() | 484 | void CalendarView::suspendAlarm() |
485 | { | 485 | { |
486 | //qDebug(" CalendarView::suspendAlarm() "); | 486 | //qDebug(" CalendarView::suspendAlarm() "); |
487 | computeAlarm(mSuspendAlarmNotification ); | 487 | computeAlarm(mSuspendAlarmNotification ); |
488 | 488 | ||
489 | } | 489 | } |
490 | 490 | ||
491 | void CalendarView::startAlarm( QString mess , QString filename) | 491 | void CalendarView::startAlarm( QString mess , QString filename) |
492 | { | 492 | { |
493 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 493 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
494 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); | 494 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); |
495 | 495 | ||
496 | } | 496 | } |
497 | 497 | ||
498 | void CalendarView::checkNextTimerAlarm() | 498 | void CalendarView::checkNextTimerAlarm() |
499 | { | 499 | { |
500 | mCalendar->checkAlarmForIncidence( 0, true ); | 500 | mCalendar->checkAlarmForIncidence( 0, true ); |
501 | } | 501 | } |
502 | 502 | ||
503 | void CalendarView::computeAlarm( QString msg ) | 503 | void CalendarView::computeAlarm( QString msg ) |
504 | { | 504 | { |
505 | 505 | ||
506 | QString mess = msg; | 506 | QString mess = msg; |
507 | QString mAlarmMessage = mess.mid( 9 ); | 507 | QString mAlarmMessage = mess.mid( 9 ); |
508 | QString filename = MainWindow::resourcePath(); | 508 | QString filename = MainWindow::resourcePath(); |
509 | filename += "koalarm.wav"; | 509 | filename += "koalarm.wav"; |
510 | QString tempfilename; | 510 | QString tempfilename; |
511 | if ( mess.left( 13 ) == "suspend_alarm") { | 511 | if ( mess.left( 13 ) == "suspend_alarm") { |
512 | bool error = false; | 512 | bool error = false; |
513 | int len = mess.mid( 13 ).find("+++"); | 513 | int len = mess.mid( 13 ).find("+++"); |
514 | if ( len < 2 ) | 514 | if ( len < 2 ) |
515 | error = true; | 515 | error = true; |
516 | else { | 516 | else { |
517 | tempfilename = mess.mid( 13, len ); | 517 | tempfilename = mess.mid( 13, len ); |
518 | if ( !QFile::exists( tempfilename ) ) | 518 | if ( !QFile::exists( tempfilename ) ) |
519 | error = true; | 519 | error = true; |
520 | } | 520 | } |
521 | if ( ! error ) { | 521 | if ( ! error ) { |
522 | filename = tempfilename; | 522 | filename = tempfilename; |
523 | } | 523 | } |
524 | mAlarmMessage = mess.mid( 13+len+3 ); | 524 | mAlarmMessage = mess.mid( 13+len+3 ); |
525 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 525 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
526 | startAlarm( mAlarmMessage, filename); | 526 | startAlarm( mAlarmMessage, filename); |
527 | return; | 527 | return; |
528 | } | 528 | } |
529 | if ( mess.left( 11 ) == "timer_alarm") { | 529 | if ( mess.left( 11 ) == "timer_alarm") { |
530 | //mTimerTime = 0; | 530 | //mTimerTime = 0; |
531 | startAlarm( mess.mid( 11 ), filename ); | 531 | startAlarm( mess.mid( 11 ), filename ); |
532 | return; | 532 | return; |
533 | } | 533 | } |
534 | if ( mess.left( 10 ) == "proc_alarm") { | 534 | if ( mess.left( 10 ) == "proc_alarm") { |
535 | bool error = false; | 535 | bool error = false; |
536 | int len = mess.mid( 10 ).find("+++"); | 536 | int len = mess.mid( 10 ).find("+++"); |
537 | if ( len < 2 ) | 537 | if ( len < 2 ) |
538 | error = true; | 538 | error = true; |
539 | else { | 539 | else { |
540 | tempfilename = mess.mid( 10, len ); | 540 | tempfilename = mess.mid( 10, len ); |
541 | if ( !QFile::exists( tempfilename ) ) | 541 | if ( !QFile::exists( tempfilename ) ) |
542 | error = true; | 542 | error = true; |
543 | } | 543 | } |
544 | if ( error ) { | 544 | if ( error ) { |
545 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 545 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
546 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 546 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
547 | } else { | 547 | } else { |
548 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 548 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
549 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 549 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
550 | #ifndef _WIN32_ | 550 | #ifndef _WIN32_ |
551 | if ( vfork () == 0 ) { | 551 | if ( vfork () == 0 ) { |
552 | execl ( tempfilename.latin1(), 0 ); | 552 | execl ( tempfilename.latin1(), 0 ); |
553 | return; | 553 | return; |
554 | } | 554 | } |
555 | #else | 555 | #else |
556 | QProcess* p = new QProcess(); | 556 | QProcess* p = new QProcess(); |
557 | p->addArgument( tempfilename.latin1() ); | 557 | p->addArgument( tempfilename.latin1() ); |
558 | p->start(); | 558 | p->start(); |
559 | return; | 559 | return; |
560 | #endif | 560 | #endif |
561 | 561 | ||
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | 564 | ||
565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
566 | } | 566 | } |
567 | if ( mess.left( 11 ) == "audio_alarm") { | 567 | if ( mess.left( 11 ) == "audio_alarm") { |
568 | bool error = false; | 568 | bool error = false; |
569 | int len = mess.mid( 11 ).find("+++"); | 569 | int len = mess.mid( 11 ).find("+++"); |
570 | if ( len < 2 ) | 570 | if ( len < 2 ) |
571 | error = true; | 571 | error = true; |
572 | else { | 572 | else { |
573 | tempfilename = mess.mid( 11, len ); | 573 | tempfilename = mess.mid( 11, len ); |
574 | if ( !QFile::exists( tempfilename ) ) | 574 | if ( !QFile::exists( tempfilename ) ) |
575 | error = true; | 575 | error = true; |
576 | } | 576 | } |
577 | if ( ! error ) { | 577 | if ( ! error ) { |
578 | filename = tempfilename; | 578 | filename = tempfilename; |
579 | } | 579 | } |
580 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 580 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
581 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 581 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
582 | } | 582 | } |
583 | if ( mess.left( 9 ) == "cal_alarm") { | 583 | if ( mess.left( 9 ) == "cal_alarm") { |
584 | mAlarmMessage = mess.mid( 9 ) ; | 584 | mAlarmMessage = mess.mid( 9 ) ; |
585 | } | 585 | } |
586 | 586 | ||
587 | startAlarm( mAlarmMessage, filename ); | 587 | startAlarm( mAlarmMessage, filename ); |
588 | 588 | ||
589 | 589 | ||
590 | } | 590 | } |
591 | 591 | ||
592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
593 | { | 593 | { |
594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
595 | 595 | ||
596 | mSuspendAlarmNotification = noti; | 596 | mSuspendAlarmNotification = noti; |
597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
599 | mSuspendTimer->start( ms , true ); | 599 | mSuspendTimer->start( ms , true ); |
600 | 600 | ||
601 | } | 601 | } |
602 | 602 | ||
603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
604 | { | 604 | { |
605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
607 | #ifndef DESKTOP_VERSION | 607 | #ifndef DESKTOP_VERSION |
608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); | 608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); |
609 | #endif | 609 | #endif |
610 | return; | 610 | return; |
611 | } | 611 | } |
612 | int maxSec; | 612 | int maxSec; |
613 | //maxSec = 5; //testing only | 613 | //maxSec = 5; //testing only |
614 | maxSec = 86400+3600; // one day+1hour | 614 | maxSec = 86400+3600; // one day+1hour |
615 | mAlarmNotification = noti; | 615 | mAlarmNotification = noti; |
616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
617 | if ( sec > maxSec ) { | 617 | if ( sec > maxSec ) { |
618 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 618 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
620 | return; | 620 | return; |
621 | } else { | 621 | } else { |
622 | mRecheckAlarmTimer->stop(); | 622 | mRecheckAlarmTimer->stop(); |
623 | } | 623 | } |
624 | //qDebug("Alarm timer started with secs: %d ", sec); | 624 | //qDebug("Alarm timer started with secs: %d ", sec); |
625 | mAlarmTimer->start( sec *1000 , true ); | 625 | mAlarmTimer->start( sec *1000 , true ); |
626 | 626 | ||
627 | } | 627 | } |
628 | // called by mRecheckAlarmTimer to get next alarm | 628 | // called by mRecheckAlarmTimer to get next alarm |
629 | // we need this, because a QTimer has only a max range of 25 days | 629 | // we need this, because a QTimer has only a max range of 25 days |
630 | void CalendarView::recheckTimerAlarm() | 630 | void CalendarView::recheckTimerAlarm() |
631 | { | 631 | { |
632 | mAlarmTimer->stop(); | 632 | mAlarmTimer->stop(); |
633 | mRecheckAlarmTimer->stop(); | 633 | mRecheckAlarmTimer->stop(); |
634 | mCalendar->checkAlarmForIncidence( 0, true ); | 634 | mCalendar->checkAlarmForIncidence( 0, true ); |
635 | } | 635 | } |
636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
637 | { | 637 | { |
638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
640 | #ifndef DESKTOP_VERSION | 640 | #ifndef DESKTOP_VERSION |
641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); | 641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); |
642 | #endif | 642 | #endif |
643 | return; | 643 | return; |
644 | } | 644 | } |
645 | mAlarmTimer->stop(); | 645 | mAlarmTimer->stop(); |
646 | } | 646 | } |
647 | void CalendarView::selectWeekNum ( int num ) | 647 | void CalendarView::selectWeekNum ( int num ) |
648 | { | 648 | { |
649 | dateNavigator()->selectWeek( num ); | 649 | dateNavigator()->selectWeek( num ); |
650 | mViewManager->showWeekView(); | 650 | mViewManager->showWeekView(); |
651 | } | 651 | } |
652 | KOViewManager *CalendarView::viewManager() | 652 | KOViewManager *CalendarView::viewManager() |
653 | { | 653 | { |
654 | return mViewManager; | 654 | return mViewManager; |
655 | } | 655 | } |
656 | 656 | ||
657 | KODialogManager *CalendarView::dialogManager() | 657 | KODialogManager *CalendarView::dialogManager() |
658 | { | 658 | { |
659 | return mDialogManager; | 659 | return mDialogManager; |
660 | } | 660 | } |
661 | 661 | ||
662 | QDate CalendarView::startDate() | 662 | QDate CalendarView::startDate() |
663 | { | 663 | { |
664 | DateList dates = mNavigator->selectedDates(); | 664 | DateList dates = mNavigator->selectedDates(); |
665 | 665 | ||
666 | return dates.first(); | 666 | return dates.first(); |
667 | } | 667 | } |
668 | 668 | ||
669 | QDate CalendarView::endDate() | 669 | QDate CalendarView::endDate() |
670 | { | 670 | { |
671 | DateList dates = mNavigator->selectedDates(); | 671 | DateList dates = mNavigator->selectedDates(); |
672 | 672 | ||
673 | return dates.last(); | 673 | return dates.last(); |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | void CalendarView::createPrinter() | 677 | void CalendarView::createPrinter() |
678 | { | 678 | { |
679 | #ifndef KORG_NOPRINTER | 679 | #ifndef KORG_NOPRINTER |
680 | if (!mCalPrinter) { | 680 | if (!mCalPrinter) { |
681 | mCalPrinter = new CalPrinter(this, mCalendar); | 681 | mCalPrinter = new CalPrinter(this, mCalendar); |
682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
683 | } | 683 | } |
684 | #endif | 684 | #endif |
685 | } | 685 | } |
686 | 686 | ||
687 | void CalendarView::confSync() | 687 | void CalendarView::confSync() |
688 | { | 688 | { |
689 | static KSyncPrefsDialog* sp = 0; | 689 | static KSyncPrefsDialog* sp = 0; |
690 | if ( ! sp ) { | 690 | if ( ! sp ) { |
691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
692 | } | 692 | } |
693 | sp->usrReadConfig(); | 693 | sp->usrReadConfig(); |
694 | #ifndef DESKTOP_VERSION | 694 | #ifndef DESKTOP_VERSION |
695 | sp->showMaximized(); | 695 | sp->showMaximized(); |
696 | #else | 696 | #else |
697 | sp->show(); | 697 | sp->show(); |
698 | #endif | 698 | #endif |
699 | sp->exec(); | 699 | sp->exec(); |
700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
702 | } | 702 | } |
703 | 703 | ||
704 | 704 | ||
705 | //KOPrefs::instance()->mWriteBackFile | 705 | //KOPrefs::instance()->mWriteBackFile |
706 | //KOPrefs::instance()->mWriteBackExistingOnly | 706 | //KOPrefs::instance()->mWriteBackExistingOnly |
707 | 707 | ||
708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
714 | 714 | ||
715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
716 | { | 716 | { |
717 | 717 | ||
718 | //void setZaurusId(int id); | 718 | //void setZaurusId(int id); |
719 | // int zaurusId() const; | 719 | // int zaurusId() const; |
720 | // void setZaurusUid(int id); | 720 | // void setZaurusUid(int id); |
721 | // int zaurusUid() const; | 721 | // int zaurusUid() const; |
722 | // void setZaurusStat(int id); | 722 | // void setZaurusStat(int id); |
723 | // int zaurusStat() const; | 723 | // int zaurusStat() const; |
724 | // 0 equal | 724 | // 0 equal |
725 | // 1 take local | 725 | // 1 take local |
726 | // 2 take remote | 726 | // 2 take remote |
727 | // 3 cancel | 727 | // 3 cancel |
728 | QDateTime lastSync = mLastCalendarSync; | 728 | QDateTime lastSync = mLastCalendarSync; |
729 | QDateTime localMod = local->lastModified(); | ||
730 | QDateTime remoteMod = remote->lastModified(); | ||
729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 731 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
730 | bool remCh, locCh; | 732 | bool remCh, locCh; |
731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 733 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
732 | //if ( remCh ) | 734 | //if ( remCh ) |
733 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 735 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
734 | locCh = ( local->lastModified() > mLastCalendarSync ); | 736 | locCh = ( localMod > mLastCalendarSync ); |
735 | if ( !remCh && ! locCh ) { | 737 | if ( !remCh && ! locCh ) { |
736 | //qDebug("both not changed "); | 738 | //qDebug("both not changed "); |
737 | lastSync = local->lastModified().addDays(1); | 739 | lastSync = localMod.addDays(1); |
738 | if ( mode <= SYNC_PREF_ASK ) | 740 | if ( mode <= SYNC_PREF_ASK ) |
739 | return 0; | 741 | return 0; |
740 | } else { | 742 | } else { |
741 | if ( locCh ) { | 743 | if ( locCh ) { |
742 | //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); | 744 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
743 | lastSync = local->lastModified().addDays( -1 ); | 745 | lastSync = localMod.addDays( -1 ); |
744 | if ( !remCh ) | 746 | if ( !remCh ) |
745 | remote->setLastModified( lastSync.addDays( -1 ) ); | 747 | remoteMod = ( lastSync.addDays( -1 ) ); |
746 | } else { | 748 | } else { |
747 | //qDebug(" not loc changed "); | 749 | //qDebug(" not loc changed "); |
748 | lastSync = local->lastModified().addDays( 1 ); | 750 | lastSync = localMod.addDays( 1 ); |
749 | if ( remCh ) | 751 | if ( remCh ) |
750 | remote->setLastModified( lastSync.addDays( 1 ) ); | 752 | remoteMod =( lastSync.addDays( 1 ) ); |
751 | 753 | ||
752 | } | 754 | } |
753 | } | 755 | } |
754 | full = true; | 756 | full = true; |
755 | if ( mode < SYNC_PREF_ASK ) | 757 | if ( mode < SYNC_PREF_ASK ) |
756 | mode = SYNC_PREF_ASK; | 758 | mode = SYNC_PREF_ASK; |
757 | } else { | 759 | } else { |
758 | if ( local->lastModified() == remote->lastModified() ) | 760 | if ( localMod == remoteMod ) |
759 | if ( local->revision() == remote->revision() ) | 761 | if ( local->revision() == remote->revision() ) |
760 | return 0; | 762 | return 0; |
761 | 763 | ||
762 | } | 764 | } |
763 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 765 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
764 | 766 | ||
765 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 767 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
766 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 768 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
767 | //full = true; //debug only | 769 | //full = true; //debug only |
768 | if ( full ) { | 770 | if ( full ) { |
769 | bool equ = false; | 771 | bool equ = false; |
770 | if ( local->type() == "Event" ) { | 772 | if ( local->type() == "Event" ) { |
771 | equ = (*((Event*) local) == *((Event*) remote)); | 773 | equ = (*((Event*) local) == *((Event*) remote)); |
772 | } | 774 | } |
773 | else if ( local->type() =="Todo" ) | 775 | else if ( local->type() =="Todo" ) |
774 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 776 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
775 | else if ( local->type() =="Journal" ) | 777 | else if ( local->type() =="Journal" ) |
776 | equ = (*((Journal*) local) == *((Journal*) remote)); | 778 | equ = (*((Journal*) local) == *((Journal*) remote)); |
777 | if ( equ ) { | 779 | if ( equ ) { |
778 | //qDebug("equal "); | 780 | //qDebug("equal "); |
779 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 781 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
780 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 782 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
781 | } | 783 | } |
782 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 784 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
783 | return 0; | 785 | return 0; |
784 | 786 | ||
785 | }//else //debug only | 787 | }//else //debug only |
786 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 788 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
787 | } | 789 | } |
788 | int result; | 790 | int result; |
789 | bool localIsNew; | 791 | bool localIsNew; |
790 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 792 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); |
791 | 793 | ||
792 | if ( full && mode < SYNC_PREF_NEWEST ) | 794 | if ( full && mode < SYNC_PREF_NEWEST ) |
793 | mode = SYNC_PREF_ASK; | 795 | mode = SYNC_PREF_ASK; |
794 | 796 | ||
795 | switch( mode ) { | 797 | switch( mode ) { |
796 | case SYNC_PREF_LOCAL: | 798 | case SYNC_PREF_LOCAL: |
797 | if ( lastSync > remote->lastModified() ) | 799 | if ( lastSync > remoteMod ) |
798 | return 1; | 800 | return 1; |
799 | if ( lastSync > local->lastModified() ) | 801 | if ( lastSync > localMod ) |
800 | return 2; | 802 | return 2; |
801 | return 1; | 803 | return 1; |
802 | break; | 804 | break; |
803 | case SYNC_PREF_REMOTE: | 805 | case SYNC_PREF_REMOTE: |
804 | if ( lastSync > remote->lastModified() ) | 806 | if ( lastSync > remoteMod ) |
805 | return 1; | 807 | return 1; |
806 | if ( lastSync > local->lastModified() ) | 808 | if ( lastSync > localMod ) |
807 | return 2; | 809 | return 2; |
808 | return 2; | 810 | return 2; |
809 | break; | 811 | break; |
810 | case SYNC_PREF_NEWEST: | 812 | case SYNC_PREF_NEWEST: |
811 | if ( local->lastModified() > remote->lastModified() ) | 813 | if ( localMod > remoteMod ) |
812 | return 1; | 814 | return 1; |
813 | else | 815 | else |
814 | return 2; | 816 | return 2; |
815 | break; | 817 | break; |
816 | case SYNC_PREF_ASK: | 818 | case SYNC_PREF_ASK: |
817 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 819 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
818 | if ( lastSync > remote->lastModified() ) | 820 | if ( lastSync > remoteMod ) |
819 | return 1; | 821 | return 1; |
820 | if ( lastSync > local->lastModified() ) | 822 | if ( lastSync > localMod ) |
821 | return 2; | 823 | return 2; |
822 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 824 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
823 | localIsNew = local->lastModified() >= remote->lastModified(); | 825 | localIsNew = localMod >= remoteMod; |
824 | if ( localIsNew ) | 826 | if ( localIsNew ) |
825 | getEventViewerDialog()->setColorMode( 1 ); | 827 | getEventViewerDialog()->setColorMode( 1 ); |
826 | else | 828 | else |
827 | getEventViewerDialog()->setColorMode( 2 ); | 829 | getEventViewerDialog()->setColorMode( 2 ); |
828 | getEventViewerDialog()->setIncidence(local); | 830 | getEventViewerDialog()->setIncidence(local); |
829 | if ( localIsNew ) | 831 | if ( localIsNew ) |
830 | getEventViewerDialog()->setColorMode( 2 ); | 832 | getEventViewerDialog()->setColorMode( 2 ); |
831 | else | 833 | else |
832 | getEventViewerDialog()->setColorMode( 1 ); | 834 | getEventViewerDialog()->setColorMode( 1 ); |
833 | getEventViewerDialog()->addIncidence(remote); | 835 | getEventViewerDialog()->addIncidence(remote); |
834 | getEventViewerDialog()->setColorMode( 0 ); | 836 | getEventViewerDialog()->setColorMode( 0 ); |
835 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 837 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
836 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 838 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
837 | getEventViewerDialog()->showMe(); | 839 | getEventViewerDialog()->showMe(); |
838 | result = getEventViewerDialog()->executeS( localIsNew ); | 840 | result = getEventViewerDialog()->executeS( localIsNew ); |
839 | return result; | 841 | return result; |
840 | 842 | ||
841 | break; | 843 | break; |
842 | case SYNC_PREF_FORCE_LOCAL: | 844 | case SYNC_PREF_FORCE_LOCAL: |
843 | return 1; | 845 | return 1; |
844 | break; | 846 | break; |
845 | case SYNC_PREF_FORCE_REMOTE: | 847 | case SYNC_PREF_FORCE_REMOTE: |
846 | return 2; | 848 | return 2; |
847 | break; | 849 | break; |
848 | 850 | ||
849 | default: | 851 | default: |
850 | // SYNC_PREF_TAKE_BOTH not implemented | 852 | // SYNC_PREF_TAKE_BOTH not implemented |
851 | break; | 853 | break; |
852 | } | 854 | } |
853 | return 0; | 855 | return 0; |
854 | } | 856 | } |
855 | Event* CalendarView::getLastSyncEvent() | 857 | Event* CalendarView::getLastSyncEvent() |
856 | { | 858 | { |
857 | Event* lse; | 859 | Event* lse; |
858 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 860 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
859 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 861 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
860 | if (!lse) { | 862 | if (!lse) { |
861 | lse = new Event(); | 863 | lse = new Event(); |
862 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 864 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
863 | QString sum = ""; | 865 | QString sum = ""; |
864 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 866 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
865 | sum = "E: "; | 867 | sum = "E: "; |
866 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 868 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
867 | lse->setDtStart( mLastCalendarSync ); | 869 | lse->setDtStart( mLastCalendarSync ); |
868 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 870 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
869 | lse->setCategories( i18n("SyncEvent") ); | 871 | lse->setCategories( i18n("SyncEvent") ); |
870 | lse->setReadOnly( true ); | 872 | lse->setReadOnly( true ); |
871 | mCalendar->addEvent( lse ); | 873 | mCalendar->addEvent( lse ); |
872 | } | 874 | } |
873 | 875 | ||
874 | return lse; | 876 | return lse; |
875 | 877 | ||
876 | } | 878 | } |
877 | // probaly useless | 879 | // probaly useless |
878 | void CalendarView::setupExternSyncProfiles() | 880 | void CalendarView::setupExternSyncProfiles() |
879 | { | 881 | { |
880 | Event* lse; | 882 | Event* lse; |
881 | mExternLastSyncEvent.clear(); | 883 | mExternLastSyncEvent.clear(); |
882 | int i; | 884 | int i; |
883 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { | 885 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { |
884 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); | 886 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); |
885 | if ( lse ) | 887 | if ( lse ) |
886 | mExternLastSyncEvent.append( lse ); | 888 | mExternLastSyncEvent.append( lse ); |
887 | else | 889 | else |
888 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); | 890 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); |
889 | } | 891 | } |
890 | 892 | ||
891 | } | 893 | } |
892 | // we check, if the to delete event has a id for a profile | 894 | // we check, if the to delete event has a id for a profile |
893 | // if yes, we set this id in the profile to delete | 895 | // if yes, we set this id in the profile to delete |
894 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 896 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
895 | { | 897 | { |
896 | if ( lastSync.count() == 0 ) { | 898 | if ( lastSync.count() == 0 ) { |
897 | //qDebug(" lastSync.count() == 0"); | 899 | //qDebug(" lastSync.count() == 0"); |
898 | return; | 900 | return; |
899 | } | 901 | } |
900 | if ( toDelete->type() == "Journal" ) | 902 | if ( toDelete->type() == "Journal" ) |
901 | return; | 903 | return; |
902 | 904 | ||
903 | Event* eve = lastSync.first(); | 905 | Event* eve = lastSync.first(); |
904 | 906 | ||
905 | while ( eve ) { | 907 | while ( eve ) { |
906 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 908 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
907 | if ( !id.isEmpty() ) { | 909 | if ( !id.isEmpty() ) { |
908 | QString des = eve->description(); | 910 | QString des = eve->description(); |
909 | QString pref = "e"; | 911 | QString pref = "e"; |
910 | if ( toDelete->type() == "Todo" ) | 912 | if ( toDelete->type() == "Todo" ) |
911 | pref = "t"; | 913 | pref = "t"; |
912 | des += pref+ id + ","; | 914 | des += pref+ id + ","; |
913 | eve->setReadOnly( false ); | 915 | eve->setReadOnly( false ); |
914 | eve->setDescription( des ); | 916 | eve->setDescription( des ); |
915 | //qDebug("setdes %s ", des.latin1()); | 917 | //qDebug("setdes %s ", des.latin1()); |
916 | eve->setReadOnly( true ); | 918 | eve->setReadOnly( true ); |
917 | } | 919 | } |
918 | eve = lastSync.next(); | 920 | eve = lastSync.next(); |
919 | } | 921 | } |
920 | 922 | ||
921 | } | 923 | } |
922 | void CalendarView::checkExternalId( Incidence * inc ) | 924 | void CalendarView::checkExternalId( Incidence * inc ) |
923 | { | 925 | { |
924 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 926 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
925 | checkExternSyncEvent( lastSync, inc ); | 927 | checkExternSyncEvent( lastSync, inc ); |
926 | 928 | ||
927 | } | 929 | } |
928 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 930 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
929 | { | 931 | { |
930 | bool syncOK = true; | 932 | bool syncOK = true; |
931 | int addedEvent = 0; | 933 | int addedEvent = 0; |
932 | int addedEventR = 0; | 934 | int addedEventR = 0; |
933 | int deletedEventR = 0; | 935 | int deletedEventR = 0; |
934 | int deletedEventL = 0; | 936 | int deletedEventL = 0; |
935 | int changedLocal = 0; | 937 | int changedLocal = 0; |
936 | int changedRemote = 0; | 938 | int changedRemote = 0; |
937 | //QPtrList<Event> el = local->rawEvents(); | 939 | //QPtrList<Event> el = local->rawEvents(); |
938 | Event* eventR; | 940 | Event* eventR; |
939 | QString uid; | 941 | QString uid; |
940 | int take; | 942 | int take; |
941 | Event* eventL; | 943 | Event* eventL; |
942 | Event* eventRSync; | 944 | Event* eventRSync; |
943 | Event* eventLSync; | 945 | Event* eventLSync; |
944 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 946 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
945 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 947 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
946 | bool fullDateRange = false; | 948 | bool fullDateRange = false; |
947 | local->resetTempSyncStat(); | 949 | local->resetTempSyncStat(); |
948 | mLastCalendarSync = QDateTime::currentDateTime(); | 950 | mLastCalendarSync = QDateTime::currentDateTime(); |
949 | QDateTime modifiedCalendar = mLastCalendarSync;; | 951 | QDateTime modifiedCalendar = mLastCalendarSync;; |
950 | eventLSync = getLastSyncEvent(); | 952 | eventLSync = getLastSyncEvent(); |
951 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 953 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
952 | if ( eventR ) { | 954 | if ( eventR ) { |
953 | eventRSync = (Event*) eventR->clone(); | 955 | eventRSync = (Event*) eventR->clone(); |
954 | remote->deleteEvent(eventR ); | 956 | remote->deleteEvent(eventR ); |
955 | 957 | ||
956 | } else { | 958 | } else { |
957 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 959 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
958 | eventRSync = (Event*)eventLSync->clone(); | 960 | eventRSync = (Event*)eventLSync->clone(); |
959 | } else { | 961 | } else { |
960 | fullDateRange = true; | 962 | fullDateRange = true; |
961 | eventRSync = new Event(); | 963 | eventRSync = new Event(); |
962 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 964 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
963 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 965 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
964 | eventRSync->setDtStart( mLastCalendarSync ); | 966 | eventRSync->setDtStart( mLastCalendarSync ); |
965 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 967 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
966 | eventRSync->setCategories( i18n("SyncEvent") ); | 968 | eventRSync->setCategories( i18n("SyncEvent") ); |
967 | } | 969 | } |
968 | } | 970 | } |
969 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 971 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
970 | fullDateRange = true; | 972 | fullDateRange = true; |
971 | 973 | ||
972 | if ( ! fullDateRange ) { | 974 | if ( ! fullDateRange ) { |
973 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 975 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
974 | 976 | ||
975 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 977 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
976 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 978 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
977 | fullDateRange = true; | 979 | fullDateRange = true; |
978 | } | 980 | } |
979 | } | 981 | } |
980 | if ( fullDateRange ) | 982 | if ( fullDateRange ) |
981 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 983 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
982 | else | 984 | else |
983 | mLastCalendarSync = eventLSync->dtStart(); | 985 | mLastCalendarSync = eventLSync->dtStart(); |
984 | // for resyncing if own file has changed | 986 | // for resyncing if own file has changed |
985 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 987 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
986 | mLastCalendarSync = loadedFileVersion; | 988 | mLastCalendarSync = loadedFileVersion; |
987 | qDebug("setting mLastCalendarSync "); | 989 | qDebug("setting mLastCalendarSync "); |
988 | } | 990 | } |
989 | //qDebug("*************************** "); | 991 | //qDebug("*************************** "); |
990 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | 992 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); |
991 | QPtrList<Incidence> er = remote->rawIncidences(); | 993 | QPtrList<Incidence> er = remote->rawIncidences(); |
992 | Incidence* inR = er.first(); | 994 | Incidence* inR = er.first(); |
993 | Incidence* inL; | 995 | Incidence* inL; |
994 | QProgressBar bar( er.count(),0 ); | 996 | QProgressBar bar( er.count(),0 ); |
995 | bar.setCaption (i18n("Syncing - close to abort!") ); | 997 | bar.setCaption (i18n("Syncing - close to abort!") ); |
996 | 998 | ||
997 | int w = 300; | 999 | int w = 300; |
998 | if ( QApplication::desktop()->width() < 320 ) | 1000 | if ( QApplication::desktop()->width() < 320 ) |
999 | w = 220; | 1001 | w = 220; |
1000 | int h = bar.sizeHint().height() ; | 1002 | int h = bar.sizeHint().height() ; |
1001 | int dw = QApplication::desktop()->width(); | 1003 | int dw = QApplication::desktop()->width(); |
1002 | int dh = QApplication::desktop()->height(); | 1004 | int dh = QApplication::desktop()->height(); |
1003 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1005 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1004 | bar.show(); | 1006 | bar.show(); |
1005 | int modulo = (er.count()/10)+1; | 1007 | int modulo = (er.count()/10)+1; |
1006 | int incCounter = 0; | 1008 | int incCounter = 0; |
1007 | while ( inR ) { | 1009 | while ( inR ) { |
1008 | if ( ! bar.isVisible() ) | 1010 | if ( ! bar.isVisible() ) |
1009 | return false; | 1011 | return false; |
1010 | if ( incCounter % modulo == 0 ) | 1012 | if ( incCounter % modulo == 0 ) |
1011 | bar.setProgress( incCounter ); | 1013 | bar.setProgress( incCounter ); |
1012 | ++incCounter; | 1014 | ++incCounter; |
1013 | uid = inR->uid(); | 1015 | uid = inR->uid(); |
1014 | bool skipIncidence = false; | 1016 | bool skipIncidence = false; |
1015 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1017 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1016 | skipIncidence = true; | 1018 | skipIncidence = true; |
1017 | QString idS; | 1019 | QString idS; |
1018 | qApp->processEvents(); | 1020 | qApp->processEvents(); |
1019 | if ( !skipIncidence ) { | 1021 | if ( !skipIncidence ) { |
1020 | inL = local->incidence( uid ); | 1022 | inL = local->incidence( uid ); |
1021 | if ( inL ) { // maybe conflict - same uid in both calendars | 1023 | if ( inL ) { // maybe conflict - same uid in both calendars |
1022 | int maxrev = inL->revision(); | 1024 | int maxrev = inL->revision(); |
1023 | if ( maxrev < inR->revision() ) | 1025 | if ( maxrev < inR->revision() ) |
1024 | maxrev = inR->revision(); | 1026 | maxrev = inR->revision(); |
1025 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1027 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1026 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1028 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1027 | if ( take == 3 ) | 1029 | if ( take == 3 ) |
1028 | return false; | 1030 | return false; |
1029 | if ( take == 1 ) {// take local | 1031 | if ( take == 1 ) {// take local |
1030 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1032 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1031 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1033 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1032 | else | 1034 | else |
1033 | idS = inR->IDStr(); | 1035 | idS = inR->IDStr(); |
1034 | remote->deleteIncidence( inR ); | 1036 | remote->deleteIncidence( inR ); |
1035 | if ( inL->revision() < maxrev ) | 1037 | if ( inL->revision() < maxrev ) |
1036 | inL->setRevision( maxrev ); | 1038 | inL->setRevision( maxrev ); |
1037 | inR = inL->clone(); | 1039 | inR = inL->clone(); |
1038 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1040 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1039 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1041 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1040 | inR->setIDStr( idS ); | 1042 | inR->setIDStr( idS ); |
1041 | remote->addIncidence( inR ); | 1043 | remote->addIncidence( inR ); |
1042 | ++changedRemote; | 1044 | ++changedRemote; |
1043 | } else { | 1045 | } else { |
1044 | if ( inR->revision() < maxrev ) | 1046 | if ( inR->revision() < maxrev ) |
1045 | inR->setRevision( maxrev ); | 1047 | inR->setRevision( maxrev ); |
1046 | idS = inL->IDStr(); | 1048 | idS = inL->IDStr(); |
1047 | local->deleteIncidence( inL ); | 1049 | local->deleteIncidence( inL ); |
1048 | inL = inR->clone(); | 1050 | inL = inR->clone(); |
1049 | inL->setIDStr( idS ); | 1051 | inL->setIDStr( idS ); |
1050 | local->addIncidence( inL ); | 1052 | local->addIncidence( inL ); |
1051 | ++changedLocal; | 1053 | ++changedLocal; |
1052 | } | 1054 | } |
1053 | } | 1055 | } |
1054 | } else { // no conflict | 1056 | } else { // no conflict |
1055 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1057 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1056 | QString des = eventLSync->description(); | 1058 | QString des = eventLSync->description(); |
1057 | QString pref = "e"; | 1059 | QString pref = "e"; |
1058 | if ( inR->type() == "Todo" ) | 1060 | if ( inR->type() == "Todo" ) |
1059 | pref = "t"; | 1061 | pref = "t"; |
1060 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1062 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1061 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1063 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1062 | //remote->deleteIncidence( inR ); | 1064 | //remote->deleteIncidence( inR ); |
1063 | ++deletedEventR; | 1065 | ++deletedEventR; |
1064 | } else { | 1066 | } else { |
1065 | inR->setLastModified( modifiedCalendar ); | 1067 | inR->setLastModified( modifiedCalendar ); |
1066 | inL = inR->clone(); | 1068 | inL = inR->clone(); |
1067 | local->addIncidence( inL ); | 1069 | local->addIncidence( inL ); |
1068 | ++addedEvent; | 1070 | ++addedEvent; |
1069 | } | 1071 | } |
1070 | } else { | 1072 | } else { |
1071 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1073 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1072 | inR->setLastModified( modifiedCalendar ); | 1074 | inR->setLastModified( modifiedCalendar ); |
1073 | local->addIncidence( inR->clone() ); | 1075 | local->addIncidence( inR->clone() ); |
1074 | ++addedEvent; | 1076 | ++addedEvent; |
1075 | } else { | 1077 | } else { |
1076 | checkExternSyncEvent(eventRSyncSharp, inR); | 1078 | checkExternSyncEvent(eventRSyncSharp, inR); |
1077 | remote->deleteIncidence( inR ); | 1079 | remote->deleteIncidence( inR ); |
1078 | ++deletedEventR; | 1080 | ++deletedEventR; |
1079 | } | 1081 | } |
1080 | } | 1082 | } |
1081 | } | 1083 | } |
1082 | } | 1084 | } |
1083 | inR = er.next(); | 1085 | inR = er.next(); |
1084 | } | 1086 | } |
1085 | QPtrList<Incidence> el = local->rawIncidences(); | 1087 | QPtrList<Incidence> el = local->rawIncidences(); |
1086 | inL = el.first(); | 1088 | inL = el.first(); |
1087 | modulo = (el.count()/10)+1; | 1089 | modulo = (el.count()/10)+1; |
1088 | bar.setCaption (i18n("Add / remove events") ); | 1090 | bar.setCaption (i18n("Add / remove events") ); |
1089 | bar.setTotalSteps ( el.count() ) ; | 1091 | bar.setTotalSteps ( el.count() ) ; |
1090 | bar.show(); | 1092 | bar.show(); |
1091 | incCounter = 0; | 1093 | incCounter = 0; |
1092 | 1094 | ||
1093 | while ( inL ) { | 1095 | while ( inL ) { |
1094 | 1096 | ||
1095 | qApp->processEvents(); | 1097 | qApp->processEvents(); |
1096 | if ( ! bar.isVisible() ) | 1098 | if ( ! bar.isVisible() ) |
1097 | return false; | 1099 | return false; |
1098 | if ( incCounter % modulo == 0 ) | 1100 | if ( incCounter % modulo == 0 ) |
1099 | bar.setProgress( incCounter ); | 1101 | bar.setProgress( incCounter ); |
1100 | ++incCounter; | 1102 | ++incCounter; |
1101 | uid = inL->uid(); | 1103 | uid = inL->uid(); |
1102 | bool skipIncidence = false; | 1104 | bool skipIncidence = false; |
1103 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1105 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1104 | skipIncidence = true; | 1106 | skipIncidence = true; |
1105 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1107 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1106 | skipIncidence = true; | 1108 | skipIncidence = true; |
1107 | if ( !skipIncidence ) { | 1109 | if ( !skipIncidence ) { |
1108 | inR = remote->incidence( uid ); | 1110 | inR = remote->incidence( uid ); |
1109 | if ( ! inR ) { | 1111 | if ( ! inR ) { |
1110 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1112 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1111 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1113 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1112 | checkExternSyncEvent(eventLSyncSharp, inL); | 1114 | checkExternSyncEvent(eventLSyncSharp, inL); |
1113 | local->deleteIncidence( inL ); | 1115 | local->deleteIncidence( inL ); |
1114 | ++deletedEventL; | 1116 | ++deletedEventL; |
1115 | } else { | 1117 | } else { |
1116 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1118 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1117 | inL->removeID(mCurrentSyncDevice ); | 1119 | inL->removeID(mCurrentSyncDevice ); |
1118 | ++addedEventR; | 1120 | ++addedEventR; |
1119 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1121 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1120 | inL->setLastModified( modifiedCalendar ); | 1122 | inL->setLastModified( modifiedCalendar ); |
1121 | inR = inL->clone(); | 1123 | inR = inL->clone(); |
1122 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1124 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1123 | remote->addIncidence( inR ); | 1125 | remote->addIncidence( inR ); |
1124 | } | 1126 | } |
1125 | } | 1127 | } |
1126 | } else { | 1128 | } else { |
1127 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1129 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1128 | checkExternSyncEvent(eventLSyncSharp, inL); | 1130 | checkExternSyncEvent(eventLSyncSharp, inL); |
1129 | local->deleteIncidence( inL ); | 1131 | local->deleteIncidence( inL ); |
1130 | ++deletedEventL; | 1132 | ++deletedEventL; |
1131 | } else { | 1133 | } else { |
1132 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1134 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1133 | ++addedEventR; | 1135 | ++addedEventR; |
1134 | inL->setLastModified( modifiedCalendar ); | 1136 | inL->setLastModified( modifiedCalendar ); |
1135 | remote->addIncidence( inL->clone() ); | 1137 | remote->addIncidence( inL->clone() ); |
1136 | } | 1138 | } |
1137 | } | 1139 | } |
1138 | } | 1140 | } |
1139 | } | 1141 | } |
1140 | } | 1142 | } |
1141 | inL = el.next(); | 1143 | inL = el.next(); |
1142 | } | 1144 | } |
1143 | int delFut = 0; | 1145 | int delFut = 0; |
1144 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 1146 | if ( KOPrefs::instance()->mWriteBackInFuture ) { |
1145 | er = remote->rawIncidences(); | 1147 | er = remote->rawIncidences(); |
1146 | inR = er.first(); | 1148 | inR = er.first(); |
1147 | QDateTime dt; | 1149 | QDateTime dt; |
1148 | QDateTime cur = QDateTime::currentDateTime(); | 1150 | QDateTime cur = QDateTime::currentDateTime(); |
1149 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | 1151 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); |
1150 | while ( inR ) { | 1152 | while ( inR ) { |
1151 | if ( inR->type() == "Todo" ) { | 1153 | if ( inR->type() == "Todo" ) { |
1152 | Todo * t = (Todo*)inR; | 1154 | Todo * t = (Todo*)inR; |
1153 | if ( t->hasDueDate() ) | 1155 | if ( t->hasDueDate() ) |
1154 | dt = t->dtDue(); | 1156 | dt = t->dtDue(); |
1155 | else | 1157 | else |
1156 | dt = cur.addSecs( 62 ); | 1158 | dt = cur.addSecs( 62 ); |
1157 | } | 1159 | } |
1158 | else if (inR->type() == "Event" ) { | 1160 | else if (inR->type() == "Event" ) { |
1159 | bool ok; | 1161 | bool ok; |
1160 | dt = inR->getNextOccurence( cur, &ok ); | 1162 | dt = inR->getNextOccurence( cur, &ok ); |
1161 | if ( !ok ) | 1163 | if ( !ok ) |
1162 | dt = cur.addSecs( -62 ); | 1164 | dt = cur.addSecs( -62 ); |
1163 | } | 1165 | } |
1164 | else | 1166 | else |
1165 | dt = inR->dtStart(); | 1167 | dt = inR->dtStart(); |
1166 | if ( dt < cur || dt > end ) { | 1168 | if ( dt < cur || dt > end ) { |
1167 | remote->deleteIncidence( inR ); | 1169 | remote->deleteIncidence( inR ); |
1168 | ++delFut; | 1170 | ++delFut; |
1169 | } | 1171 | } |
1170 | inR = er.next(); | 1172 | inR = er.next(); |
1171 | } | 1173 | } |
1172 | } | 1174 | } |
1173 | bar.hide(); | 1175 | bar.hide(); |
1174 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1176 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1175 | eventLSync->setReadOnly( false ); | 1177 | eventLSync->setReadOnly( false ); |
1176 | eventLSync->setDtStart( mLastCalendarSync ); | 1178 | eventLSync->setDtStart( mLastCalendarSync ); |
1177 | eventRSync->setDtStart( mLastCalendarSync ); | 1179 | eventRSync->setDtStart( mLastCalendarSync ); |
1178 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1180 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1179 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1181 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1180 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1182 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1181 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1183 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1182 | eventLSync->setReadOnly( true ); | 1184 | eventLSync->setReadOnly( true ); |
1183 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 1185 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
1184 | remote->addEvent( eventRSync ); | 1186 | remote->addEvent( eventRSync ); |
1185 | QString mes; | 1187 | QString mes; |
1186 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); | 1188 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); |
1187 | QString delmess; | 1189 | QString delmess; |
1188 | if ( delFut ) { | 1190 | if ( delFut ) { |
1189 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | 1191 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); |
1190 | mes += delmess; | 1192 | mes += delmess; |
1191 | } | 1193 | } |
1192 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 1194 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
1193 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1195 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1194 | } | 1196 | } |
1195 | qDebug( mes ); | 1197 | qDebug( mes ); |
1196 | mCalendar->checkAlarmForIncidence( 0, true ); | 1198 | mCalendar->checkAlarmForIncidence( 0, true ); |
1197 | return syncOK; | 1199 | return syncOK; |
1198 | } | 1200 | } |
1199 | 1201 | ||
1200 | void CalendarView::setSyncDevice( QString s ) | 1202 | void CalendarView::setSyncDevice( QString s ) |
1201 | { | 1203 | { |
1202 | mCurrentSyncDevice= s; | 1204 | mCurrentSyncDevice= s; |
1203 | } | 1205 | } |
1204 | void CalendarView::setSyncName( QString s ) | 1206 | void CalendarView::setSyncName( QString s ) |
1205 | { | 1207 | { |
1206 | mCurrentSyncName= s; | 1208 | mCurrentSyncName= s; |
1207 | } | 1209 | } |
1208 | bool CalendarView::syncCalendar(QString filename, int mode) | 1210 | bool CalendarView::syncCalendar(QString filename, int mode) |
1209 | { | 1211 | { |
1210 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1212 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1211 | CalendarLocal* calendar = new CalendarLocal(); | 1213 | CalendarLocal* calendar = new CalendarLocal(); |
1212 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1214 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1213 | FileStorage* storage = new FileStorage( calendar ); | 1215 | FileStorage* storage = new FileStorage( calendar ); |
1214 | bool syncOK = false; | 1216 | bool syncOK = false; |
1215 | storage->setFileName( filename ); | 1217 | storage->setFileName( filename ); |
1216 | // qDebug("loading ... "); | 1218 | // qDebug("loading ... "); |
1217 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1219 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1218 | getEventViewerDialog()->setSyncMode( true ); | 1220 | getEventViewerDialog()->setSyncMode( true ); |
1219 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1221 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1220 | getEventViewerDialog()->setSyncMode( false ); | 1222 | getEventViewerDialog()->setSyncMode( false ); |
1221 | if ( syncOK ) { | 1223 | if ( syncOK ) { |
1222 | if ( KOPrefs::instance()->mWriteBackFile ) | 1224 | if ( KOPrefs::instance()->mWriteBackFile ) |
1223 | { | 1225 | { |
1224 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1226 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1225 | storage->save(); | 1227 | storage->save(); |
1226 | } | 1228 | } |
1227 | } | 1229 | } |
1228 | setModified( true ); | 1230 | setModified( true ); |
1229 | } | 1231 | } |
1230 | delete storage; | 1232 | delete storage; |
1231 | delete calendar; | 1233 | delete calendar; |
1232 | if ( syncOK ) | 1234 | if ( syncOK ) |
1233 | updateView(); | 1235 | updateView(); |
1234 | return syncOK; | 1236 | return syncOK; |
1235 | } | 1237 | } |
1236 | void CalendarView::syncPhone() | 1238 | void CalendarView::syncPhone() |
1237 | { | 1239 | { |
1238 | syncExternal( 1 ); | 1240 | syncExternal( 1 ); |
1239 | } | 1241 | } |
1240 | void CalendarView::syncExternal( int mode ) | 1242 | void CalendarView::syncExternal( int mode ) |
1241 | { | 1243 | { |
1242 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1244 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1243 | //mCurrentSyncDevice = "sharp-DTM"; | 1245 | //mCurrentSyncDevice = "sharp-DTM"; |
1244 | if ( KOPrefs::instance()->mAskForPreferences ) | 1246 | if ( KOPrefs::instance()->mAskForPreferences ) |
1245 | edit_sync_options(); | 1247 | edit_sync_options(); |
1246 | qApp->processEvents(); | 1248 | qApp->processEvents(); |
1247 | CalendarLocal* calendar = new CalendarLocal(); | 1249 | CalendarLocal* calendar = new CalendarLocal(); |
1248 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1250 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1249 | bool syncOK = false; | 1251 | bool syncOK = false; |
1250 | bool loadSuccess = false; | 1252 | bool loadSuccess = false; |
1251 | PhoneFormat* phoneFormat = 0; | 1253 | PhoneFormat* phoneFormat = 0; |
1252 | #ifndef DESKTOP_VERSION | 1254 | #ifndef DESKTOP_VERSION |
1253 | SharpFormat* sharpFormat = 0; | 1255 | SharpFormat* sharpFormat = 0; |
1254 | if ( mode == 0 ) { // sharp | 1256 | if ( mode == 0 ) { // sharp |
1255 | sharpFormat = new SharpFormat () ; | 1257 | sharpFormat = new SharpFormat () ; |
1256 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1258 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1257 | 1259 | ||
1258 | } else | 1260 | } else |
1259 | #endif | 1261 | #endif |
1260 | if ( mode == 1 ) { // phone | 1262 | if ( mode == 1 ) { // phone |
1261 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1263 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1262 | KOPrefs::instance()->mPhoneDevice, | 1264 | KOPrefs::instance()->mPhoneDevice, |
1263 | KOPrefs::instance()->mPhoneConnection, | 1265 | KOPrefs::instance()->mPhoneConnection, |
1264 | KOPrefs::instance()->mPhoneModel); | 1266 | KOPrefs::instance()->mPhoneModel); |
1265 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1267 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1266 | 1268 | ||
1267 | } else | 1269 | } else |
1268 | return; | 1270 | return; |
1269 | if ( loadSuccess ) { | 1271 | if ( loadSuccess ) { |
1270 | getEventViewerDialog()->setSyncMode( true ); | 1272 | getEventViewerDialog()->setSyncMode( true ); |
1271 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1273 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1272 | getEventViewerDialog()->setSyncMode( false ); | 1274 | getEventViewerDialog()->setSyncMode( false ); |
1273 | qApp->processEvents(); | 1275 | qApp->processEvents(); |
1274 | if ( syncOK ) { | 1276 | if ( syncOK ) { |
1275 | if ( KOPrefs::instance()->mWriteBackFile ) | 1277 | if ( KOPrefs::instance()->mWriteBackFile ) |
1276 | { | 1278 | { |
1277 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1279 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1278 | Incidence* inc = iL.first(); | 1280 | Incidence* inc = iL.first(); |
1279 | if ( phoneFormat ) { | 1281 | if ( phoneFormat ) { |
1280 | while ( inc ) { | 1282 | while ( inc ) { |
1281 | inc->removeID(mCurrentSyncDevice); | 1283 | inc->removeID(mCurrentSyncDevice); |
1282 | inc = iL.next(); | 1284 | inc = iL.next(); |
1283 | } | 1285 | } |
1284 | } | 1286 | } |
1285 | #ifndef DESKTOP_VERSION | 1287 | #ifndef DESKTOP_VERSION |
1286 | if ( sharpFormat ) | 1288 | if ( sharpFormat ) |
1287 | sharpFormat->save(calendar); | 1289 | sharpFormat->save(calendar); |
1288 | #endif | 1290 | #endif |
1289 | if ( phoneFormat ) | 1291 | if ( phoneFormat ) |
1290 | phoneFormat->save(calendar); | 1292 | phoneFormat->save(calendar); |
1291 | iL = calendar->rawIncidences(); | 1293 | iL = calendar->rawIncidences(); |
1292 | inc = iL.first(); | 1294 | inc = iL.first(); |
1293 | Incidence* loc; | 1295 | Incidence* loc; |
1294 | while ( inc ) { | 1296 | while ( inc ) { |
1295 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1297 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1296 | loc = mCalendar->incidence(inc->uid() ); | 1298 | loc = mCalendar->incidence(inc->uid() ); |
1297 | if ( loc ) { | 1299 | if ( loc ) { |
1298 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1300 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1299 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1301 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1300 | } | 1302 | } |
1301 | } | 1303 | } |
1302 | inc = iL.next(); | 1304 | inc = iL.next(); |
1303 | } | 1305 | } |
1304 | Incidence* lse = getLastSyncEvent(); | 1306 | Incidence* lse = getLastSyncEvent(); |
1305 | if ( lse ) { | 1307 | if ( lse ) { |
1306 | lse->setReadOnly( false ); | 1308 | lse->setReadOnly( false ); |
1307 | lse->setDescription( "" ); | 1309 | lse->setDescription( "" ); |
1308 | lse->setReadOnly( true ); | 1310 | lse->setReadOnly( true ); |
1309 | } | 1311 | } |
1310 | } | 1312 | } |
1311 | } | 1313 | } |
1312 | setModified( true ); | 1314 | setModified( true ); |
1313 | } else { | 1315 | } else { |
1314 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1316 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1315 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1317 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1316 | question, i18n("Ok")) ; | 1318 | question, i18n("Ok")) ; |
1317 | 1319 | ||
1318 | } | 1320 | } |
1319 | delete calendar; | 1321 | delete calendar; |
1320 | updateView(); | 1322 | updateView(); |
1321 | return ;//syncOK; | 1323 | return ;//syncOK; |
1322 | 1324 | ||
1323 | } | 1325 | } |
1324 | void CalendarView::syncSharp() | 1326 | void CalendarView::syncSharp() |
1325 | { | 1327 | { |
1326 | syncExternal( 0 ); | 1328 | syncExternal( 0 ); |
1327 | 1329 | ||
1328 | } | 1330 | } |
1329 | 1331 | ||
1330 | 1332 | ||
1331 | //#include <kabc/stdaddressbook.h> | 1333 | //#include <kabc/stdaddressbook.h> |
1332 | bool CalendarView::importBday() | 1334 | bool CalendarView::importBday() |
1333 | { | 1335 | { |
1334 | #if 0 | 1336 | #if 0 |
1335 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1337 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1336 | KABC::AddressBook::Iterator it; | 1338 | KABC::AddressBook::Iterator it; |
1337 | int count = 0; | 1339 | int count = 0; |
1338 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1340 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1339 | ++count; | 1341 | ++count; |
1340 | } | 1342 | } |
1341 | QProgressBar bar(count,0 ); | 1343 | QProgressBar bar(count,0 ); |
1342 | int w = 300; | 1344 | int w = 300; |
1343 | if ( QApplication::desktop()->width() < 320 ) | 1345 | if ( QApplication::desktop()->width() < 320 ) |
1344 | w = 220; | 1346 | w = 220; |
1345 | int h = bar.sizeHint().height() ; | 1347 | int h = bar.sizeHint().height() ; |
1346 | int dw = QApplication::desktop()->width(); | 1348 | int dw = QApplication::desktop()->width(); |
1347 | int dh = QApplication::desktop()->height(); | 1349 | int dh = QApplication::desktop()->height(); |
1348 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1350 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1349 | bar.show(); | 1351 | bar.show(); |
1350 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1352 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1351 | qApp->processEvents(); | 1353 | qApp->processEvents(); |
1352 | count = 0; | 1354 | count = 0; |
1353 | int addCount = 0; | 1355 | int addCount = 0; |
1354 | KCal::Attendee* a = 0; | 1356 | KCal::Attendee* a = 0; |
1355 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1357 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1356 | if ( ! bar.isVisible() ) | 1358 | if ( ! bar.isVisible() ) |
1357 | return false; | 1359 | return false; |
1358 | bar.setProgress( count++ ); | 1360 | bar.setProgress( count++ ); |
1359 | qApp->processEvents(); | 1361 | qApp->processEvents(); |
1360 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1362 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1361 | if ( (*it).birthday().date().isValid() ){ | 1363 | if ( (*it).birthday().date().isValid() ){ |
1362 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1364 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1363 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1365 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1364 | ++addCount; | 1366 | ++addCount; |
1365 | } | 1367 | } |
1366 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1368 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1367 | if ( anni.isValid() ){ | 1369 | if ( anni.isValid() ){ |
1368 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1370 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1369 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1371 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1370 | ++addCount; | 1372 | ++addCount; |
1371 | } | 1373 | } |
1372 | } | 1374 | } |
1373 | updateView(); | 1375 | updateView(); |
1374 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1376 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1375 | #endif | 1377 | #endif |
1376 | return true; | 1378 | return true; |
1377 | } | 1379 | } |
1378 | 1380 | ||
1379 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1381 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1380 | { | 1382 | { |
1381 | //qDebug("addAnni "); | 1383 | //qDebug("addAnni "); |
1382 | Event * ev = new Event(); | 1384 | Event * ev = new Event(); |
1383 | if ( a ) { | 1385 | if ( a ) { |
1384 | ev->addAttendee( a ); | 1386 | ev->addAttendee( a ); |
1385 | } | 1387 | } |
1386 | QString kind; | 1388 | QString kind; |
1387 | if ( birthday ) | 1389 | if ( birthday ) |
1388 | kind = i18n( "Birthday" ); | 1390 | kind = i18n( "Birthday" ); |
1389 | else | 1391 | else |
1390 | kind = i18n( "Anniversary" ); | 1392 | kind = i18n( "Anniversary" ); |
1391 | ev->setSummary( name + " - " + kind ); | 1393 | ev->setSummary( name + " - " + kind ); |
1392 | ev->setOrganizer( "nobody@nowhere" ); | 1394 | ev->setOrganizer( "nobody@nowhere" ); |
1393 | ev->setCategories( kind ); | 1395 | ev->setCategories( kind ); |
1394 | ev->setDtStart( QDateTime(date) ); | 1396 | ev->setDtStart( QDateTime(date) ); |
1395 | ev->setDtEnd( QDateTime(date) ); | 1397 | ev->setDtEnd( QDateTime(date) ); |
1396 | ev->setFloats( true ); | 1398 | ev->setFloats( true ); |
1397 | Recurrence * rec = ev->recurrence(); | 1399 | Recurrence * rec = ev->recurrence(); |
1398 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1400 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1399 | rec->addYearlyNum( date.month() ); | 1401 | rec->addYearlyNum( date.month() ); |
1400 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1402 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1401 | delete ev; | 1403 | delete ev; |
1402 | return false; | 1404 | return false; |
1403 | } | 1405 | } |
1404 | return true; | 1406 | return true; |
1405 | 1407 | ||
1406 | } | 1408 | } |
1407 | bool CalendarView::importQtopia( const QString &categories, | 1409 | bool CalendarView::importQtopia( const QString &categories, |
1408 | const QString &datebook, | 1410 | const QString &datebook, |
1409 | const QString &todolist ) | 1411 | const QString &todolist ) |
1410 | { | 1412 | { |
1411 | 1413 | ||
1412 | QtopiaFormat qtopiaFormat; | 1414 | QtopiaFormat qtopiaFormat; |
1413 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1415 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1414 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1416 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1415 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1417 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1416 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1418 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1417 | 1419 | ||
1418 | updateView(); | 1420 | updateView(); |
1419 | return true; | 1421 | return true; |
1420 | 1422 | ||
1421 | #if 0 | 1423 | #if 0 |
1422 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1424 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1423 | mCurrentSyncDevice = "qtopia-XML"; | 1425 | mCurrentSyncDevice = "qtopia-XML"; |
1424 | if ( KOPrefs::instance()->mAskForPreferences ) | 1426 | if ( KOPrefs::instance()->mAskForPreferences ) |
1425 | edit_sync_options(); | 1427 | edit_sync_options(); |
1426 | qApp->processEvents(); | 1428 | qApp->processEvents(); |
1427 | CalendarLocal* calendar = new CalendarLocal(); | 1429 | CalendarLocal* calendar = new CalendarLocal(); |
1428 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1430 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1429 | bool syncOK = false; | 1431 | bool syncOK = false; |
1430 | QtopiaFormat qtopiaFormat; | 1432 | QtopiaFormat qtopiaFormat; |
1431 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1433 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1432 | bool loadOk = true; | 1434 | bool loadOk = true; |
1433 | if ( !categories.isEmpty() ) | 1435 | if ( !categories.isEmpty() ) |
1434 | loadOk = qtopiaFormat.load( calendar, categories ); | 1436 | loadOk = qtopiaFormat.load( calendar, categories ); |
1435 | if ( loadOk && !datebook.isEmpty() ) | 1437 | if ( loadOk && !datebook.isEmpty() ) |
1436 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1438 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1437 | if ( loadOk && !todolist.isEmpty() ) | 1439 | if ( loadOk && !todolist.isEmpty() ) |
1438 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1440 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1439 | 1441 | ||
1440 | if ( loadOk ) { | 1442 | if ( loadOk ) { |
1441 | getEventViewerDialog()->setSyncMode( true ); | 1443 | getEventViewerDialog()->setSyncMode( true ); |
1442 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1444 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1443 | getEventViewerDialog()->setSyncMode( false ); | 1445 | getEventViewerDialog()->setSyncMode( false ); |
1444 | qApp->processEvents(); | 1446 | qApp->processEvents(); |
1445 | if ( syncOK ) { | 1447 | if ( syncOK ) { |
1446 | if ( KOPrefs::instance()->mWriteBackFile ) | 1448 | if ( KOPrefs::instance()->mWriteBackFile ) |
1447 | { | 1449 | { |
1448 | // write back XML file | 1450 | // write back XML file |
1449 | 1451 | ||
1450 | } | 1452 | } |
1451 | setModified( true ); | 1453 | setModified( true ); |
1452 | } | 1454 | } |
1453 | } else { | 1455 | } else { |
1454 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1456 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1455 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1457 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1456 | question, i18n("Ok")) ; | 1458 | question, i18n("Ok")) ; |
1457 | } | 1459 | } |
1458 | delete calendar; | 1460 | delete calendar; |
1459 | updateView(); | 1461 | updateView(); |
1460 | return syncOK; | 1462 | return syncOK; |
1461 | 1463 | ||
1462 | 1464 | ||
1463 | #endif | 1465 | #endif |
1464 | 1466 | ||
1465 | } | 1467 | } |
1466 | 1468 | ||
1467 | void CalendarView::setSyncEventsReadOnly() | 1469 | void CalendarView::setSyncEventsReadOnly() |
1468 | { | 1470 | { |
1469 | Event * ev; | 1471 | Event * ev; |
1470 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1472 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1471 | ev = eL.first(); | 1473 | ev = eL.first(); |
1472 | while ( ev ) { | 1474 | while ( ev ) { |
1473 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1475 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1474 | ev->setReadOnly( true ); | 1476 | ev->setReadOnly( true ); |
1475 | ev = eL.next(); | 1477 | ev = eL.next(); |
1476 | } | 1478 | } |
1477 | } | 1479 | } |
1478 | bool CalendarView::openCalendar(QString filename, bool merge) | 1480 | bool CalendarView::openCalendar(QString filename, bool merge) |
1479 | { | 1481 | { |
1480 | 1482 | ||
1481 | if (filename.isEmpty()) { | 1483 | if (filename.isEmpty()) { |
1482 | return false; | 1484 | return false; |
1483 | } | 1485 | } |
1484 | 1486 | ||
1485 | if (!QFile::exists(filename)) { | 1487 | if (!QFile::exists(filename)) { |
1486 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1488 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1487 | return false; | 1489 | return false; |
1488 | } | 1490 | } |
1489 | 1491 | ||
1490 | globalFlagBlockAgenda = 1; | 1492 | globalFlagBlockAgenda = 1; |
1491 | if (!merge) mCalendar->close(); | 1493 | if (!merge) mCalendar->close(); |
1492 | 1494 | ||
1493 | mStorage->setFileName( filename ); | 1495 | mStorage->setFileName( filename ); |
1494 | 1496 | ||
1495 | if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1497 | if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1496 | if ( merge ) ;//setModified( true ); | 1498 | if ( merge ) ;//setModified( true ); |
1497 | else { | 1499 | else { |
1498 | //setModified( true ); | 1500 | //setModified( true ); |
1499 | mViewManager->setDocumentId( filename ); | 1501 | mViewManager->setDocumentId( filename ); |
1500 | mDialogManager->setDocumentId( filename ); | 1502 | mDialogManager->setDocumentId( filename ); |
1501 | mTodoList->setDocumentId( filename ); | 1503 | mTodoList->setDocumentId( filename ); |
1502 | } | 1504 | } |
1503 | globalFlagBlockAgenda = 2; | 1505 | globalFlagBlockAgenda = 2; |
1504 | // if ( getLastSyncEvent() ) | 1506 | // if ( getLastSyncEvent() ) |
1505 | // getLastSyncEvent()->setReadOnly( true ); | 1507 | // getLastSyncEvent()->setReadOnly( true ); |
1506 | mCalendar->reInitAlarmSettings(); | 1508 | mCalendar->reInitAlarmSettings(); |
1507 | setSyncEventsReadOnly(); | 1509 | setSyncEventsReadOnly(); |
1508 | updateUnmanagedViews(); | 1510 | updateUnmanagedViews(); |
1509 | updateView(); | 1511 | updateView(); |
1510 | if ( filename != MainWindow::defaultFileName() ) | 1512 | if ( filename != MainWindow::defaultFileName() ) |
1511 | saveCalendar( MainWindow::defaultFileName() ); | 1513 | saveCalendar( MainWindow::defaultFileName() ); |
1512 | loadedFileVersion = QDateTime::currentDateTime(); | 1514 | loadedFileVersion = QDateTime::currentDateTime(); |
1513 | return true; | 1515 | return true; |
1514 | } else { | 1516 | } else { |
1515 | // while failing to load, the calendar object could | 1517 | // while failing to load, the calendar object could |
1516 | // have become partially populated. Clear it out. | 1518 | // have become partially populated. Clear it out. |
1517 | if ( !merge ) mCalendar->close(); | 1519 | if ( !merge ) mCalendar->close(); |
1518 | 1520 | ||
1519 | KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1521 | KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1520 | 1522 | ||
1521 | globalFlagBlockAgenda = 2; | 1523 | globalFlagBlockAgenda = 2; |
1522 | updateView(); | 1524 | updateView(); |
1523 | } | 1525 | } |
1524 | return false; | 1526 | return false; |
1525 | } | 1527 | } |
1526 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1528 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1527 | { | 1529 | { |
1528 | loadedFileVersion = dt; | 1530 | loadedFileVersion = dt; |
1529 | } | 1531 | } |
1530 | bool CalendarView::checkFileChanged(QString fn) | 1532 | bool CalendarView::checkFileChanged(QString fn) |
1531 | { | 1533 | { |
1532 | QFileInfo finf ( fn ); | 1534 | QFileInfo finf ( fn ); |
1533 | if ( !finf.exists() ) | 1535 | if ( !finf.exists() ) |
1534 | return true; | 1536 | return true; |
1535 | QDateTime dt = finf.lastModified (); | 1537 | QDateTime dt = finf.lastModified (); |
1536 | if ( dt <= loadedFileVersion ) | 1538 | if ( dt <= loadedFileVersion ) |
1537 | return false; | 1539 | return false; |
1538 | return true; | 1540 | return true; |
1539 | 1541 | ||
1540 | } | 1542 | } |
1541 | bool CalendarView::checkFileVersion(QString fn) | 1543 | bool CalendarView::checkFileVersion(QString fn) |
1542 | { | 1544 | { |
1543 | QFileInfo finf ( fn ); | 1545 | QFileInfo finf ( fn ); |
1544 | if ( !finf.exists() ) | 1546 | if ( !finf.exists() ) |
1545 | return true; | 1547 | return true; |
1546 | QDateTime dt = finf.lastModified (); | 1548 | QDateTime dt = finf.lastModified (); |
1547 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 1549 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
1548 | //qDebug("file on disk version %s",dt.toString().latin1()); | 1550 | //qDebug("file on disk version %s",dt.toString().latin1()); |
1549 | if ( dt <= loadedFileVersion ) | 1551 | if ( dt <= loadedFileVersion ) |
1550 | return true; | 1552 | return true; |
1551 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , | 1553 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , |
1552 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 1554 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
1553 | i18n("Sync+save")); | 1555 | i18n("Sync+save")); |
1554 | 1556 | ||
1555 | if ( km == KMessageBox::Cancel ) | 1557 | if ( km == KMessageBox::Cancel ) |
1556 | return false; | 1558 | return false; |
1557 | if ( km == KMessageBox::Yes ) | 1559 | if ( km == KMessageBox::Yes ) |
1558 | return true; | 1560 | return true; |
1559 | 1561 | ||
1560 | setSyncDevice("deleteaftersync" ); | 1562 | setSyncDevice("deleteaftersync" ); |
1561 | KOPrefs::instance()->mAskForPreferences = true; | 1563 | KOPrefs::instance()->mAskForPreferences = true; |
1562 | KOPrefs::instance()->mSyncAlgoPrefs = 3; | 1564 | KOPrefs::instance()->mSyncAlgoPrefs = 3; |
1563 | KOPrefs::instance()->mWriteBackFile = false; | 1565 | KOPrefs::instance()->mWriteBackFile = false; |
1564 | KOPrefs::instance()->mWriteBackExistingOnly = false; | 1566 | KOPrefs::instance()->mWriteBackExistingOnly = false; |
1565 | KOPrefs::instance()->mShowSyncSummary = false; | 1567 | KOPrefs::instance()->mShowSyncSummary = false; |
1566 | syncCalendar( fn, 3 ); | 1568 | syncCalendar( fn, 3 ); |
1567 | Event * e = getLastSyncEvent(); | 1569 | Event * e = getLastSyncEvent(); |
1568 | mCalendar->deleteEvent ( e ); | 1570 | mCalendar->deleteEvent ( e ); |
1569 | updateView(); | 1571 | updateView(); |
1570 | return true; | 1572 | return true; |
1571 | } | 1573 | } |
1572 | 1574 | ||
1573 | bool CalendarView::saveCalendar( QString filename ) | 1575 | bool CalendarView::saveCalendar( QString filename ) |
1574 | { | 1576 | { |
1575 | 1577 | ||
1576 | // Store back all unsaved data into calendar object | 1578 | // Store back all unsaved data into calendar object |
1577 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 1579 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
1578 | if ( mViewManager->currentView() ) | 1580 | if ( mViewManager->currentView() ) |
1579 | mViewManager->currentView()->flushView(); | 1581 | mViewManager->currentView()->flushView(); |
1580 | 1582 | ||
1581 | //mStorage->setFileName( filename ); | 1583 | //mStorage->setFileName( filename ); |
1582 | 1584 | ||
1583 | mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1585 | mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1584 | mStorage->setFileName( filename ); | 1586 | mStorage->setFileName( filename ); |
1585 | bool success; | 1587 | bool success; |
1586 | success = mStorage->save(); | 1588 | success = mStorage->save(); |
1587 | if ( !success ) { | 1589 | if ( !success ) { |
1588 | return false; | 1590 | return false; |
1589 | } | 1591 | } |
1590 | 1592 | ||
1591 | return true; | 1593 | return true; |
1592 | } | 1594 | } |
1593 | 1595 | ||
1594 | void CalendarView::closeCalendar() | 1596 | void CalendarView::closeCalendar() |
1595 | { | 1597 | { |
1596 | 1598 | ||
1597 | // child windows no longer valid | 1599 | // child windows no longer valid |
1598 | emit closingDown(); | 1600 | emit closingDown(); |
1599 | 1601 | ||
1600 | mCalendar->close(); | 1602 | mCalendar->close(); |
1601 | setModified(false); | 1603 | setModified(false); |
1602 | updateView(); | 1604 | updateView(); |
1603 | } | 1605 | } |
1604 | 1606 | ||
1605 | void CalendarView::archiveCalendar() | 1607 | void CalendarView::archiveCalendar() |
1606 | { | 1608 | { |
1607 | mDialogManager->showArchiveDialog(); | 1609 | mDialogManager->showArchiveDialog(); |
1608 | } | 1610 | } |
1609 | 1611 | ||
1610 | 1612 | ||
1611 | void CalendarView::readSettings() | 1613 | void CalendarView::readSettings() |
1612 | { | 1614 | { |
1613 | 1615 | ||
1614 | 1616 | ||
1615 | // mViewManager->showAgendaView(); | 1617 | // mViewManager->showAgendaView(); |
1616 | QString str; | 1618 | QString str; |
1617 | //qDebug("CalendarView::readSettings() "); | 1619 | //qDebug("CalendarView::readSettings() "); |
1618 | // read settings from the KConfig, supplying reasonable | 1620 | // read settings from the KConfig, supplying reasonable |
1619 | // defaults where none are to be found | 1621 | // defaults where none are to be found |
1620 | KConfig *config = KOGlobals::config(); | 1622 | KConfig *config = KOGlobals::config(); |
1621 | #ifndef KORG_NOSPLITTER | 1623 | #ifndef KORG_NOSPLITTER |
1622 | config->setGroup("KOrganizer Geometry"); | 1624 | config->setGroup("KOrganizer Geometry"); |
1623 | 1625 | ||
1624 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 1626 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
1625 | if (sizes.count() != 2) { | 1627 | if (sizes.count() != 2) { |
1626 | sizes << mDateNavigator->minimumSizeHint().width(); | 1628 | sizes << mDateNavigator->minimumSizeHint().width(); |
1627 | sizes << 300; | 1629 | sizes << 300; |
1628 | } | 1630 | } |
1629 | mPanner->setSizes(sizes); | 1631 | mPanner->setSizes(sizes); |
1630 | 1632 | ||
1631 | sizes = config->readIntListEntry("Separator2"); | 1633 | sizes = config->readIntListEntry("Separator2"); |
1632 | if ( ( mResourceView && sizes.count() == 4 ) || | 1634 | if ( ( mResourceView && sizes.count() == 4 ) || |
1633 | ( !mResourceView && sizes.count() == 3 ) ) { | 1635 | ( !mResourceView && sizes.count() == 3 ) ) { |
1634 | mLeftSplitter->setSizes(sizes); | 1636 | mLeftSplitter->setSizes(sizes); |
1635 | } | 1637 | } |
1636 | #endif | 1638 | #endif |
1637 | globalFlagBlockAgenda = 1; | 1639 | globalFlagBlockAgenda = 1; |
1638 | mViewManager->showAgendaView(); | 1640 | mViewManager->showAgendaView(); |
1639 | //mViewManager->readSettings( config ); | 1641 | //mViewManager->readSettings( config ); |
1640 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 1642 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
1641 | readFilterSettings(config); | 1643 | readFilterSettings(config); |
1642 | config->setGroup( "Views" ); | 1644 | config->setGroup( "Views" ); |
1643 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 1645 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
1644 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 1646 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
1645 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 1647 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
1646 | else mNavigator->selectDates( dateCount ); | 1648 | else mNavigator->selectDates( dateCount ); |
1647 | // mViewManager->readSettings( config ); | 1649 | // mViewManager->readSettings( config ); |
1648 | updateConfig(); | 1650 | updateConfig(); |
1649 | globalFlagBlockAgenda = 2; | 1651 | globalFlagBlockAgenda = 2; |
1650 | mViewManager->readSettings( config ); | 1652 | mViewManager->readSettings( config ); |
1651 | #ifdef DESKTOP_VERSION | 1653 | #ifdef DESKTOP_VERSION |
1652 | config->setGroup("WidgetLayout"); | 1654 | config->setGroup("WidgetLayout"); |
1653 | QStringList list; | 1655 | QStringList list; |
1654 | list = config->readListEntry("MainLayout"); | 1656 | list = config->readListEntry("MainLayout"); |
1655 | int x,y,w,h; | 1657 | int x,y,w,h; |
1656 | if ( ! list.isEmpty() ) { | 1658 | if ( ! list.isEmpty() ) { |
1657 | x = list[0].toInt(); | 1659 | x = list[0].toInt(); |
1658 | y = list[1].toInt(); | 1660 | y = list[1].toInt(); |
1659 | w = list[2].toInt(); | 1661 | w = list[2].toInt(); |
1660 | h = list[3].toInt(); | 1662 | h = list[3].toInt(); |
1661 | topLevelWidget()->setGeometry(x,y,w,h); | 1663 | topLevelWidget()->setGeometry(x,y,w,h); |
1662 | 1664 | ||
1663 | } else { | 1665 | } else { |
1664 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 1666 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
1665 | } | 1667 | } |
1666 | list = config->readListEntry("EditEventLayout"); | 1668 | list = config->readListEntry("EditEventLayout"); |
1667 | if ( ! list.isEmpty() ) { | 1669 | if ( ! list.isEmpty() ) { |
1668 | x = list[0].toInt(); | 1670 | x = list[0].toInt(); |
1669 | y = list[1].toInt(); | 1671 | y = list[1].toInt(); |
1670 | w = list[2].toInt(); | 1672 | w = list[2].toInt(); |
1671 | h = list[3].toInt(); | 1673 | h = list[3].toInt(); |
1672 | mEventEditor->setGeometry(x,y,w,h); | 1674 | mEventEditor->setGeometry(x,y,w,h); |
1673 | 1675 | ||
1674 | } | 1676 | } |
1675 | list = config->readListEntry("EditTodoLayout"); | 1677 | list = config->readListEntry("EditTodoLayout"); |
1676 | if ( ! list.isEmpty() ) { | 1678 | if ( ! list.isEmpty() ) { |
1677 | x = list[0].toInt(); | 1679 | x = list[0].toInt(); |
1678 | y = list[1].toInt(); | 1680 | y = list[1].toInt(); |
1679 | w = list[2].toInt(); | 1681 | w = list[2].toInt(); |
1680 | h = list[3].toInt(); | 1682 | h = list[3].toInt(); |
1681 | mTodoEditor->setGeometry(x,y,w,h); | 1683 | mTodoEditor->setGeometry(x,y,w,h); |
1682 | 1684 | ||
1683 | } | 1685 | } |
1684 | list = config->readListEntry("ViewerLayout"); | 1686 | list = config->readListEntry("ViewerLayout"); |
1685 | if ( ! list.isEmpty() ) { | 1687 | if ( ! list.isEmpty() ) { |
1686 | x = list[0].toInt(); | 1688 | x = list[0].toInt(); |
1687 | y = list[1].toInt(); | 1689 | y = list[1].toInt(); |
1688 | w = list[2].toInt(); | 1690 | w = list[2].toInt(); |
1689 | h = list[3].toInt(); | 1691 | h = list[3].toInt(); |
1690 | getEventViewerDialog()->setGeometry(x,y,w,h); | 1692 | getEventViewerDialog()->setGeometry(x,y,w,h); |
1691 | } | 1693 | } |
1692 | #endif | 1694 | #endif |
1693 | 1695 | ||
1694 | } | 1696 | } |
1695 | 1697 | ||
1696 | 1698 | ||
1697 | void CalendarView::writeSettings() | 1699 | void CalendarView::writeSettings() |
1698 | { | 1700 | { |
1699 | // kdDebug() << "CalendarView::writeSettings" << endl; | 1701 | // kdDebug() << "CalendarView::writeSettings" << endl; |
1700 | 1702 | ||
1701 | KConfig *config = KOGlobals::config(); | 1703 | KConfig *config = KOGlobals::config(); |
1702 | 1704 | ||
1703 | #ifndef KORG_NOSPLITTER | 1705 | #ifndef KORG_NOSPLITTER |
1704 | config->setGroup("KOrganizer Geometry"); | 1706 | config->setGroup("KOrganizer Geometry"); |
1705 | 1707 | ||
1706 | QValueList<int> list = mPanner->sizes(); | 1708 | QValueList<int> list = mPanner->sizes(); |
1707 | config->writeEntry("Separator1",list); | 1709 | config->writeEntry("Separator1",list); |
1708 | 1710 | ||
1709 | list = mLeftSplitter->sizes(); | 1711 | list = mLeftSplitter->sizes(); |
1710 | config->writeEntry("Separator2",list); | 1712 | config->writeEntry("Separator2",list); |
1711 | #endif | 1713 | #endif |
1712 | 1714 | ||
1713 | mViewManager->writeSettings( config ); | 1715 | mViewManager->writeSettings( config ); |
1714 | mTodoList->saveLayout(config,QString("Todo Layout")); | 1716 | mTodoList->saveLayout(config,QString("Todo Layout")); |
1715 | mDialogManager->writeSettings( config ); | 1717 | mDialogManager->writeSettings( config ); |
1716 | //KOPrefs::instance()->usrWriteConfig(); | 1718 | //KOPrefs::instance()->usrWriteConfig(); |
1717 | KOPrefs::instance()->writeConfig(); | 1719 | KOPrefs::instance()->writeConfig(); |
1718 | 1720 | ||
1719 | writeFilterSettings(config); | 1721 | writeFilterSettings(config); |
1720 | 1722 | ||
1721 | config->setGroup( "Views" ); | 1723 | config->setGroup( "Views" ); |
1722 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); | 1724 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); |
1723 | 1725 | ||
1724 | #ifdef DESKTOP_VERSION | 1726 | #ifdef DESKTOP_VERSION |
1725 | config->setGroup("WidgetLayout"); | 1727 | config->setGroup("WidgetLayout"); |
1726 | QStringList list ;//= config->readListEntry("MainLayout"); | 1728 | QStringList list ;//= config->readListEntry("MainLayout"); |
1727 | int x,y,w,h; | 1729 | int x,y,w,h; |
1728 | QWidget* wid; | 1730 | QWidget* wid; |
1729 | wid = topLevelWidget(); | 1731 | wid = topLevelWidget(); |
1730 | x = wid->geometry().x(); | 1732 | x = wid->geometry().x(); |
1731 | y = wid->geometry().y(); | 1733 | y = wid->geometry().y(); |
1732 | w = wid->width(); | 1734 | w = wid->width(); |
1733 | h = wid->height(); | 1735 | h = wid->height(); |
1734 | list.clear(); | 1736 | list.clear(); |
1735 | list << QString::number( x ); | 1737 | list << QString::number( x ); |
1736 | list << QString::number( y ); | 1738 | list << QString::number( y ); |
1737 | list << QString::number( w ); | 1739 | list << QString::number( w ); |
1738 | list << QString::number( h ); | 1740 | list << QString::number( h ); |
1739 | config->writeEntry("MainLayout",list ); | 1741 | config->writeEntry("MainLayout",list ); |
1740 | 1742 | ||
1741 | wid = mEventEditor; | 1743 | wid = mEventEditor; |
1742 | x = wid->geometry().x(); | 1744 | x = wid->geometry().x(); |
1743 | y = wid->geometry().y(); | 1745 | y = wid->geometry().y(); |
1744 | w = wid->width(); | 1746 | w = wid->width(); |
1745 | h = wid->height(); | 1747 | h = wid->height(); |
1746 | list.clear(); | 1748 | list.clear(); |
1747 | list << QString::number( x ); | 1749 | list << QString::number( x ); |
1748 | list << QString::number( y ); | 1750 | list << QString::number( y ); |
1749 | list << QString::number( w ); | 1751 | list << QString::number( w ); |
1750 | list << QString::number( h ); | 1752 | list << QString::number( h ); |
1751 | config->writeEntry("EditEventLayout",list ); | 1753 | config->writeEntry("EditEventLayout",list ); |
1752 | 1754 | ||
1753 | wid = mTodoEditor; | 1755 | wid = mTodoEditor; |
1754 | x = wid->geometry().x(); | 1756 | x = wid->geometry().x(); |
1755 | y = wid->geometry().y(); | 1757 | y = wid->geometry().y(); |
1756 | w = wid->width(); | 1758 | w = wid->width(); |
1757 | h = wid->height(); | 1759 | h = wid->height(); |
1758 | list.clear(); | 1760 | list.clear(); |
1759 | list << QString::number( x ); | 1761 | list << QString::number( x ); |
1760 | list << QString::number( y ); | 1762 | list << QString::number( y ); |
1761 | list << QString::number( w ); | 1763 | list << QString::number( w ); |
1762 | list << QString::number( h ); | 1764 | list << QString::number( h ); |
1763 | config->writeEntry("EditTodoLayout",list ); | 1765 | config->writeEntry("EditTodoLayout",list ); |
1764 | wid = getEventViewerDialog(); | 1766 | wid = getEventViewerDialog(); |
1765 | x = wid->geometry().x(); | 1767 | x = wid->geometry().x(); |
1766 | y = wid->geometry().y(); | 1768 | y = wid->geometry().y(); |
1767 | w = wid->width(); | 1769 | w = wid->width(); |
1768 | h = wid->height(); | 1770 | h = wid->height(); |
1769 | list.clear(); | 1771 | list.clear(); |
1770 | list << QString::number( x ); | 1772 | list << QString::number( x ); |
1771 | list << QString::number( y ); | 1773 | list << QString::number( y ); |
1772 | list << QString::number( w ); | 1774 | list << QString::number( w ); |
1773 | list << QString::number( h ); | 1775 | list << QString::number( h ); |
1774 | config->writeEntry("ViewerLayout",list ); | 1776 | config->writeEntry("ViewerLayout",list ); |
1775 | wid = mDialogManager->getSearchDialog(); | 1777 | wid = mDialogManager->getSearchDialog(); |
1776 | if ( wid ) { | 1778 | if ( wid ) { |
1777 | x = wid->geometry().x(); | 1779 | x = wid->geometry().x(); |
1778 | y = wid->geometry().y(); | 1780 | y = wid->geometry().y(); |
1779 | w = wid->width(); | 1781 | w = wid->width(); |
1780 | h = wid->height(); | 1782 | h = wid->height(); |
1781 | list.clear(); | 1783 | list.clear(); |
1782 | list << QString::number( x ); | 1784 | list << QString::number( x ); |
1783 | list << QString::number( y ); | 1785 | list << QString::number( y ); |
1784 | list << QString::number( w ); | 1786 | list << QString::number( w ); |
1785 | list << QString::number( h ); | 1787 | list << QString::number( h ); |
1786 | config->writeEntry("SearchLayout",list ); | 1788 | config->writeEntry("SearchLayout",list ); |
1787 | } | 1789 | } |
1788 | #endif | 1790 | #endif |
1789 | 1791 | ||
1790 | 1792 | ||
1791 | config->sync(); | 1793 | config->sync(); |
1792 | } | 1794 | } |
1793 | 1795 | ||
1794 | void CalendarView::readFilterSettings(KConfig *config) | 1796 | void CalendarView::readFilterSettings(KConfig *config) |
1795 | { | 1797 | { |
1796 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; | 1798 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; |
1797 | 1799 | ||
1798 | mFilters.clear(); | 1800 | mFilters.clear(); |
1799 | 1801 | ||
1800 | config->setGroup("General"); | 1802 | config->setGroup("General"); |
1801 | QStringList filterList = config->readListEntry("CalendarFilters"); | 1803 | QStringList filterList = config->readListEntry("CalendarFilters"); |
1802 | 1804 | ||
1803 | QStringList::ConstIterator it = filterList.begin(); | 1805 | QStringList::ConstIterator it = filterList.begin(); |
1804 | QStringList::ConstIterator end = filterList.end(); | 1806 | QStringList::ConstIterator end = filterList.end(); |
1805 | while(it != end) { | 1807 | while(it != end) { |
1806 | // kdDebug() << " filter: " << (*it) << endl; | 1808 | // kdDebug() << " filter: " << (*it) << endl; |
1807 | 1809 | ||
1808 | CalFilter *filter; | 1810 | CalFilter *filter; |
1809 | filter = new CalFilter(*it); | 1811 | filter = new CalFilter(*it); |
1810 | config->setGroup("Filter_" + (*it)); | 1812 | config->setGroup("Filter_" + (*it)); |
1811 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); | 1813 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); |
1812 | filter->setCriteria(config->readNumEntry("Criteria",0)); | 1814 | filter->setCriteria(config->readNumEntry("Criteria",0)); |
1813 | filter->setCategoryList(config->readListEntry("CategoryList")); | 1815 | filter->setCategoryList(config->readListEntry("CategoryList")); |
1814 | mFilters.append(filter); | 1816 | mFilters.append(filter); |
1815 | 1817 | ||
1816 | ++it; | 1818 | ++it; |
1817 | } | 1819 | } |
1818 | 1820 | ||
1819 | if (mFilters.count() == 0) { | 1821 | if (mFilters.count() == 0) { |
1820 | CalFilter *filter = new CalFilter(i18n("Default")); | 1822 | CalFilter *filter = new CalFilter(i18n("Default")); |
1821 | mFilters.append(filter); | 1823 | mFilters.append(filter); |
1822 | } | 1824 | } |
1823 | mFilterView->updateFilters(); | 1825 | mFilterView->updateFilters(); |
1824 | config->setGroup("FilterView"); | 1826 | config->setGroup("FilterView"); |
1825 | 1827 | ||
1826 | mFilterView->blockSignals(true); | 1828 | mFilterView->blockSignals(true); |
1827 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); | 1829 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); |
1828 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); | 1830 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); |
1829 | mFilterView->blockSignals(false); | 1831 | mFilterView->blockSignals(false); |
1830 | // We do it manually to avoid it being done twice by the above calls | 1832 | // We do it manually to avoid it being done twice by the above calls |
1831 | updateFilter(); | 1833 | updateFilter(); |
1832 | } | 1834 | } |
1833 | 1835 | ||
1834 | void CalendarView::writeFilterSettings(KConfig *config) | 1836 | void CalendarView::writeFilterSettings(KConfig *config) |
1835 | { | 1837 | { |
1836 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; | 1838 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; |
1837 | 1839 | ||
1838 | QStringList filterList; | 1840 | QStringList filterList; |
1839 | 1841 | ||
1840 | CalFilter *filter = mFilters.first(); | 1842 | CalFilter *filter = mFilters.first(); |
1841 | while(filter) { | 1843 | while(filter) { |
1842 | // kdDebug() << " fn: " << filter->name() << endl; | 1844 | // kdDebug() << " fn: " << filter->name() << endl; |
1843 | filterList << filter->name(); | 1845 | filterList << filter->name(); |
1844 | config->setGroup("Filter_" + filter->name()); | 1846 | config->setGroup("Filter_" + filter->name()); |
1845 | config->writeEntry("Criteria",filter->criteria()); | 1847 | config->writeEntry("Criteria",filter->criteria()); |
1846 | config->writeEntry("CategoryList",filter->categoryList()); | 1848 | config->writeEntry("CategoryList",filter->categoryList()); |
1847 | filter = mFilters.next(); | 1849 | filter = mFilters.next(); |
1848 | } | 1850 | } |
1849 | config->setGroup("General"); | 1851 | config->setGroup("General"); |
1850 | config->writeEntry("CalendarFilters",filterList); | 1852 | config->writeEntry("CalendarFilters",filterList); |
1851 | 1853 | ||
1852 | config->setGroup("FilterView"); | 1854 | config->setGroup("FilterView"); |
1853 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); | 1855 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); |
1854 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); | 1856 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); |
1855 | } | 1857 | } |
1856 | 1858 | ||
1857 | 1859 | ||
1858 | void CalendarView::goToday() | 1860 | void CalendarView::goToday() |
1859 | { | 1861 | { |
1860 | mNavigator->selectToday(); | 1862 | mNavigator->selectToday(); |
1861 | } | 1863 | } |
1862 | 1864 | ||
1863 | void CalendarView::goNext() | 1865 | void CalendarView::goNext() |
1864 | { | 1866 | { |
1865 | mNavigator->selectNext(); | 1867 | mNavigator->selectNext(); |
1866 | } | 1868 | } |
1867 | 1869 | ||
1868 | void CalendarView::goPrevious() | 1870 | void CalendarView::goPrevious() |
1869 | { | 1871 | { |
1870 | mNavigator->selectPrevious(); | 1872 | mNavigator->selectPrevious(); |
1871 | } | 1873 | } |
1872 | void CalendarView::goNextMonth() | 1874 | void CalendarView::goNextMonth() |
1873 | { | 1875 | { |
1874 | mNavigator->selectNextMonth(); | 1876 | mNavigator->selectNextMonth(); |
1875 | } | 1877 | } |
1876 | 1878 | ||
1877 | void CalendarView::goPreviousMonth() | 1879 | void CalendarView::goPreviousMonth() |
1878 | { | 1880 | { |
1879 | mNavigator->selectPreviousMonth(); | 1881 | mNavigator->selectPreviousMonth(); |
1880 | } | 1882 | } |
1881 | void CalendarView::writeLocale() | 1883 | void CalendarView::writeLocale() |
1882 | { | 1884 | { |
1883 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); | 1885 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); |
1884 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); | 1886 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); |
1885 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); | 1887 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); |
1886 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); | 1888 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); |
1887 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; | 1889 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; |
1888 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); | 1890 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); |
1889 | dummy = KOPrefs::instance()->mUserDateFormatShort; | 1891 | dummy = KOPrefs::instance()->mUserDateFormatShort; |
1890 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); | 1892 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); |
1891 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, | 1893 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, |
1892 | KOPrefs::instance()->mDaylightsavingStart, | 1894 | KOPrefs::instance()->mDaylightsavingStart, |
1893 | KOPrefs::instance()->mDaylightsavingEnd ); | 1895 | KOPrefs::instance()->mDaylightsavingEnd ); |
1894 | KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); | 1896 | KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); |
1895 | } | 1897 | } |
1896 | void CalendarView::updateConfig() | 1898 | void CalendarView::updateConfig() |
1897 | { | 1899 | { |
1898 | writeLocale(); | 1900 | writeLocale(); |
1899 | if ( KOPrefs::instance()->mUseAppColors ) | 1901 | if ( KOPrefs::instance()->mUseAppColors ) |
1900 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); | 1902 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); |
1901 | emit configChanged(); | 1903 | emit configChanged(); |
1902 | mTodoList->updateConfig(); | 1904 | mTodoList->updateConfig(); |
1903 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); | 1905 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); |
1904 | mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1906 | mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1905 | // To make the "fill window" configurations work | 1907 | // To make the "fill window" configurations work |
1906 | //mViewManager->raiseCurrentView(); | 1908 | //mViewManager->raiseCurrentView(); |
1907 | } | 1909 | } |
1908 | 1910 | ||
1909 | 1911 | ||
1910 | void CalendarView::eventChanged(Event *event) | 1912 | void CalendarView::eventChanged(Event *event) |
1911 | { | 1913 | { |
1912 | changeEventDisplay(event,KOGlobals::EVENTEDITED); | 1914 | changeEventDisplay(event,KOGlobals::EVENTEDITED); |
1913 | //updateUnmanagedViews(); | 1915 | //updateUnmanagedViews(); |
1914 | } | 1916 | } |
1915 | 1917 | ||
1916 | void CalendarView::eventAdded(Event *event) | 1918 | void CalendarView::eventAdded(Event *event) |
1917 | { | 1919 | { |
1918 | changeEventDisplay(event,KOGlobals::EVENTADDED); | 1920 | changeEventDisplay(event,KOGlobals::EVENTADDED); |
1919 | } | 1921 | } |
1920 | 1922 | ||
1921 | void CalendarView::eventToBeDeleted(Event *) | 1923 | void CalendarView::eventToBeDeleted(Event *) |
1922 | { | 1924 | { |
1923 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; | 1925 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; |
1924 | } | 1926 | } |
1925 | 1927 | ||
1926 | void CalendarView::eventDeleted() | 1928 | void CalendarView::eventDeleted() |
1927 | { | 1929 | { |
1928 | changeEventDisplay(0,KOGlobals::EVENTDELETED); | 1930 | changeEventDisplay(0,KOGlobals::EVENTDELETED); |
1929 | } | 1931 | } |
1930 | void CalendarView::changeTodoDisplay(Todo *which, int action) | 1932 | void CalendarView::changeTodoDisplay(Todo *which, int action) |
1931 | { | 1933 | { |
1932 | changeIncidenceDisplay((Incidence *)which, action); | 1934 | changeIncidenceDisplay((Incidence *)which, action); |
1933 | mDateNavigator->updateView(); | 1935 | mDateNavigator->updateView(); |
1934 | //mDialogManager->updateSearchDialog(); | 1936 | //mDialogManager->updateSearchDialog(); |
1935 | 1937 | ||
1936 | if (which) { | 1938 | if (which) { |
1937 | mViewManager->currentView()->updateView(); | 1939 | mViewManager->currentView()->updateView(); |
1938 | //mTodoList->updateView(); | 1940 | //mTodoList->updateView(); |
1939 | } | 1941 | } |
1940 | 1942 | ||
1941 | } | 1943 | } |
1942 | 1944 | ||
1943 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) | 1945 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) |
1944 | { | 1946 | { |
1945 | updateUnmanagedViews(); | 1947 | updateUnmanagedViews(); |
1946 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); | 1948 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); |
1947 | if ( action == KOGlobals::EVENTDELETED ) { //delete | 1949 | if ( action == KOGlobals::EVENTDELETED ) { //delete |
1948 | mCalendar->checkAlarmForIncidence( 0, true ); | 1950 | mCalendar->checkAlarmForIncidence( 0, true ); |
1949 | if ( mEventViewerDialog ) | 1951 | if ( mEventViewerDialog ) |
1950 | mEventViewerDialog->hide(); | 1952 | mEventViewerDialog->hide(); |
1951 | } | 1953 | } |
1952 | else | 1954 | else |
1953 | mCalendar->checkAlarmForIncidence( which , false ); | 1955 | mCalendar->checkAlarmForIncidence( which , false ); |
1954 | } | 1956 | } |
1955 | 1957 | ||
1956 | // most of the changeEventDisplays() right now just call the view's | 1958 | // most of the changeEventDisplays() right now just call the view's |
1957 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. | 1959 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. |
1958 | void CalendarView::changeEventDisplay(Event *which, int action) | 1960 | void CalendarView::changeEventDisplay(Event *which, int action) |
1959 | { | 1961 | { |
1960 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; | 1962 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; |
1961 | changeIncidenceDisplay((Incidence *)which, action); | 1963 | changeIncidenceDisplay((Incidence *)which, action); |
1962 | mDateNavigator->updateView(); | 1964 | mDateNavigator->updateView(); |
1963 | //mDialogManager->updateSearchDialog(); | 1965 | //mDialogManager->updateSearchDialog(); |
1964 | 1966 | ||
1965 | if (which) { | 1967 | if (which) { |
1966 | // If there is an event view visible update the display | 1968 | // If there is an event view visible update the display |
1967 | mViewManager->currentView()->changeEventDisplay(which,action); | 1969 | mViewManager->currentView()->changeEventDisplay(which,action); |
1968 | // TODO: check, if update needed | 1970 | // TODO: check, if update needed |
1969 | // if (which->getTodoStatus()) { | 1971 | // if (which->getTodoStatus()) { |
1970 | mTodoList->updateView(); | 1972 | mTodoList->updateView(); |
1971 | // } | 1973 | // } |
1972 | } else { | 1974 | } else { |
1973 | mViewManager->currentView()->updateView(); | 1975 | mViewManager->currentView()->updateView(); |
1974 | } | 1976 | } |
1975 | } | 1977 | } |
1976 | 1978 | ||
1977 | 1979 | ||
1978 | void CalendarView::updateTodoViews() | 1980 | void CalendarView::updateTodoViews() |
1979 | { | 1981 | { |
1980 | 1982 | ||
1981 | mTodoList->updateView(); | 1983 | mTodoList->updateView(); |
1982 | mViewManager->currentView()->updateView(); | 1984 | mViewManager->currentView()->updateView(); |
1983 | 1985 | ||
1984 | } | 1986 | } |
1985 | 1987 | ||
1986 | 1988 | ||
1987 | void CalendarView::updateView(const QDate &start, const QDate &end) | 1989 | void CalendarView::updateView(const QDate &start, const QDate &end) |
1988 | { | 1990 | { |
1989 | mTodoList->updateView(); | 1991 | mTodoList->updateView(); |
1990 | mViewManager->updateView(start, end); | 1992 | mViewManager->updateView(start, end); |
1991 | //mDateNavigator->updateView(); | 1993 | //mDateNavigator->updateView(); |
1992 | } | 1994 | } |
1993 | 1995 | ||
1994 | void CalendarView::updateView() | 1996 | void CalendarView::updateView() |
1995 | { | 1997 | { |
1996 | DateList tmpList = mNavigator->selectedDates(); | 1998 | DateList tmpList = mNavigator->selectedDates(); |
1997 | 1999 | ||
1998 | // We assume that the navigator only selects consecutive days. | 2000 | // We assume that the navigator only selects consecutive days. |
1999 | updateView( tmpList.first(), tmpList.last() ); | 2001 | updateView( tmpList.first(), tmpList.last() ); |
2000 | } | 2002 | } |
2001 | 2003 | ||
2002 | void CalendarView::updateUnmanagedViews() | 2004 | void CalendarView::updateUnmanagedViews() |
2003 | { | 2005 | { |
2004 | mDateNavigator->updateDayMatrix(); | 2006 | mDateNavigator->updateDayMatrix(); |
2005 | } | 2007 | } |
2006 | 2008 | ||
2007 | int CalendarView::msgItemDelete() | 2009 | int CalendarView::msgItemDelete() |
2008 | { | 2010 | { |
2009 | return KMessageBox::warningContinueCancel(this, | 2011 | return KMessageBox::warningContinueCancel(this, |
2010 | i18n("This item will be\npermanently deleted."), | 2012 | i18n("This item will be\npermanently deleted."), |
2011 | i18n("KO/Pi Confirmation"),i18n("Delete")); | 2013 | i18n("KO/Pi Confirmation"),i18n("Delete")); |
2012 | } | 2014 | } |
2013 | 2015 | ||
2014 | 2016 | ||
2015 | void CalendarView::edit_cut() | 2017 | void CalendarView::edit_cut() |
2016 | { | 2018 | { |
2017 | Event *anEvent=0; | 2019 | Event *anEvent=0; |
2018 | 2020 | ||
2019 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2021 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2020 | 2022 | ||
2021 | if (mViewManager->currentView()->isEventView()) { | 2023 | if (mViewManager->currentView()->isEventView()) { |
2022 | if ( incidence && incidence->type() == "Event" ) { | 2024 | if ( incidence && incidence->type() == "Event" ) { |
2023 | anEvent = static_cast<Event *>(incidence); | 2025 | anEvent = static_cast<Event *>(incidence); |
2024 | } | 2026 | } |
2025 | } | 2027 | } |
2026 | 2028 | ||
2027 | if (!anEvent) { | 2029 | if (!anEvent) { |
2028 | KNotifyClient::beep(); | 2030 | KNotifyClient::beep(); |
2029 | return; | 2031 | return; |
2030 | } | 2032 | } |
2031 | DndFactory factory( mCalendar ); | 2033 | DndFactory factory( mCalendar ); |
2032 | factory.cutEvent(anEvent); | 2034 | factory.cutEvent(anEvent); |
2033 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2035 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2034 | } | 2036 | } |
2035 | 2037 | ||
2036 | void CalendarView::edit_copy() | 2038 | void CalendarView::edit_copy() |
2037 | { | 2039 | { |
2038 | Event *anEvent=0; | 2040 | Event *anEvent=0; |
2039 | 2041 | ||
2040 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2042 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2041 | 2043 | ||
2042 | if (mViewManager->currentView()->isEventView()) { | 2044 | if (mViewManager->currentView()->isEventView()) { |
2043 | if ( incidence && incidence->type() == "Event" ) { | 2045 | if ( incidence && incidence->type() == "Event" ) { |
2044 | anEvent = static_cast<Event *>(incidence); | 2046 | anEvent = static_cast<Event *>(incidence); |
2045 | } | 2047 | } |
2046 | } | 2048 | } |
2047 | 2049 | ||
2048 | if (!anEvent) { | 2050 | if (!anEvent) { |
2049 | KNotifyClient::beep(); | 2051 | KNotifyClient::beep(); |
2050 | return; | 2052 | return; |
2051 | } | 2053 | } |
2052 | DndFactory factory( mCalendar ); | 2054 | DndFactory factory( mCalendar ); |
2053 | factory.copyEvent(anEvent); | 2055 | factory.copyEvent(anEvent); |
2054 | } | 2056 | } |
2055 | 2057 | ||
2056 | void CalendarView::edit_paste() | 2058 | void CalendarView::edit_paste() |
2057 | { | 2059 | { |
2058 | QDate date = mNavigator->selectedDates().first(); | 2060 | QDate date = mNavigator->selectedDates().first(); |
2059 | 2061 | ||
2060 | DndFactory factory( mCalendar ); | 2062 | DndFactory factory( mCalendar ); |
2061 | Event *pastedEvent = factory.pasteEvent( date ); | 2063 | Event *pastedEvent = factory.pasteEvent( date ); |
2062 | 2064 | ||
2063 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); | 2065 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); |
2064 | } | 2066 | } |
2065 | 2067 | ||
2066 | void CalendarView::edit_options() | 2068 | void CalendarView::edit_options() |
2067 | { | 2069 | { |
2068 | mDialogManager->showOptionsDialog(); | 2070 | mDialogManager->showOptionsDialog(); |
2069 | //writeSettings(); | 2071 | //writeSettings(); |
2070 | } | 2072 | } |
2071 | void CalendarView::edit_sync_options() | 2073 | void CalendarView::edit_sync_options() |
2072 | { | 2074 | { |
2073 | //mDialogManager->showSyncOptions(); | 2075 | //mDialogManager->showSyncOptions(); |
2074 | //KOPrefs::instance()->mSyncAlgoPrefs | 2076 | //KOPrefs::instance()->mSyncAlgoPrefs |
2075 | QDialog dia( this, "dia", true ); | 2077 | QDialog dia( this, "dia", true ); |
2076 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 2078 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
2077 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 2079 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
2078 | QVBoxLayout lay ( &dia ); | 2080 | QVBoxLayout lay ( &dia ); |
2079 | lay.setSpacing( 2 ); | 2081 | lay.setSpacing( 2 ); |
2080 | lay.setMargin( 3 ); | 2082 | lay.setMargin( 3 ); |
2081 | lay.addWidget(&gr); | 2083 | lay.addWidget(&gr); |
2082 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 2084 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
2083 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 2085 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
2084 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 2086 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
2085 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 2087 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
2086 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 2088 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
2087 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 2089 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
2088 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 2090 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
2089 | QPushButton pb ( "OK", &dia); | 2091 | QPushButton pb ( "OK", &dia); |
2090 | lay.addWidget( &pb ); | 2092 | lay.addWidget( &pb ); |
2091 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2093 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2092 | switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { | 2094 | switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { |
2093 | case 0: | 2095 | case 0: |
2094 | loc.setChecked( true); | 2096 | loc.setChecked( true); |
2095 | break; | 2097 | break; |
2096 | case 1: | 2098 | case 1: |
2097 | rem.setChecked( true ); | 2099 | rem.setChecked( true ); |
2098 | break; | 2100 | break; |
2099 | case 2: | 2101 | case 2: |
2100 | newest.setChecked( true); | 2102 | newest.setChecked( true); |
2101 | break; | 2103 | break; |
2102 | case 3: | 2104 | case 3: |
2103 | ask.setChecked( true); | 2105 | ask.setChecked( true); |
2104 | break; | 2106 | break; |
2105 | case 4: | 2107 | case 4: |
2106 | f_loc.setChecked( true); | 2108 | f_loc.setChecked( true); |
2107 | break; | 2109 | break; |
2108 | case 5: | 2110 | case 5: |
2109 | f_rem.setChecked( true); | 2111 | f_rem.setChecked( true); |
2110 | break; | 2112 | break; |
2111 | case 6: | 2113 | case 6: |
2112 | // both.setChecked( true); | 2114 | // both.setChecked( true); |
2113 | break; | 2115 | break; |
2114 | default: | 2116 | default: |
2115 | break; | 2117 | break; |
2116 | } | 2118 | } |
2117 | if ( dia.exec() ) { | 2119 | if ( dia.exec() ) { |
2118 | KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 2120 | KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
2119 | } | 2121 | } |
2120 | 2122 | ||
2121 | } | 2123 | } |
2122 | 2124 | ||
2123 | void CalendarView::slotSelectPickerDate( QDate d) | 2125 | void CalendarView::slotSelectPickerDate( QDate d) |
2124 | { | 2126 | { |
2125 | mDateFrame->hide(); | 2127 | mDateFrame->hide(); |
2126 | if ( mDatePickerMode == 1 ) { | 2128 | if ( mDatePickerMode == 1 ) { |
2127 | mNavigator->slotDaySelect( d ); | 2129 | mNavigator->slotDaySelect( d ); |
2128 | } else if ( mDatePickerMode == 2 ) { | 2130 | } else if ( mDatePickerMode == 2 ) { |
2129 | if ( mMoveIncidence->type() == "Todo" ) { | 2131 | if ( mMoveIncidence->type() == "Todo" ) { |
2130 | Todo * to = (Todo *) mMoveIncidence; | 2132 | Todo * to = (Todo *) mMoveIncidence; |
2131 | QTime tim; | 2133 | QTime tim; |
2132 | if ( to->hasDueDate() ) | 2134 | if ( to->hasDueDate() ) |
2133 | tim = to->dtDue().time(); | 2135 | tim = to->dtDue().time(); |
2134 | else { | 2136 | else { |
2135 | tim = QTime ( 0,0,0 ); | 2137 | tim = QTime ( 0,0,0 ); |
2136 | to->setFloats( true ); | 2138 | to->setFloats( true ); |
2137 | to->setHasDueDate( true ); | 2139 | to->setHasDueDate( true ); |
2138 | } | 2140 | } |
2139 | QDateTime dt ( d,tim ); | 2141 | QDateTime dt ( d,tim ); |
2140 | to->setDtDue( dt ); | 2142 | to->setDtDue( dt ); |
2141 | todoChanged( to ); | 2143 | todoChanged( to ); |
2142 | } else { | 2144 | } else { |
2143 | QTime tim = mMoveIncidence->dtStart().time(); | 2145 | QTime tim = mMoveIncidence->dtStart().time(); |
2144 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); | 2146 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); |
2145 | QDateTime dt ( d,tim ); | 2147 | QDateTime dt ( d,tim ); |
2146 | mMoveIncidence->setDtStart( dt ); | 2148 | mMoveIncidence->setDtStart( dt ); |
2147 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); | 2149 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); |
2148 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); | 2150 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); |
2149 | } | 2151 | } |
2150 | 2152 | ||
2151 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); | 2153 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); |
2152 | } | 2154 | } |
2153 | } | 2155 | } |
2154 | 2156 | ||
2155 | void CalendarView::removeCategories() | 2157 | void CalendarView::removeCategories() |
2156 | { | 2158 | { |
2157 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2159 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2158 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2160 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2159 | QStringList catIncList; | 2161 | QStringList catIncList; |
2160 | QStringList newCatList; | 2162 | QStringList newCatList; |
2161 | Incidence* inc = incList.first(); | 2163 | Incidence* inc = incList.first(); |
2162 | int i; | 2164 | int i; |
2163 | int count = 0; | 2165 | int count = 0; |
2164 | while ( inc ) { | 2166 | while ( inc ) { |
2165 | newCatList.clear(); | 2167 | newCatList.clear(); |
2166 | catIncList = inc->categories() ; | 2168 | catIncList = inc->categories() ; |
2167 | for( i = 0; i< catIncList.count(); ++i ) { | 2169 | for( i = 0; i< catIncList.count(); ++i ) { |
2168 | if ( catList.contains (catIncList[i])) | 2170 | if ( catList.contains (catIncList[i])) |
2169 | newCatList.append( catIncList[i] ); | 2171 | newCatList.append( catIncList[i] ); |
2170 | } | 2172 | } |
2171 | newCatList.sort(); | 2173 | newCatList.sort(); |
2172 | inc->setCategories( newCatList.join(",") ); | 2174 | inc->setCategories( newCatList.join(",") ); |
2173 | inc = incList.next(); | 2175 | inc = incList.next(); |
2174 | } | 2176 | } |
2175 | } | 2177 | } |
2176 | 2178 | ||
2177 | int CalendarView::addCategories() | 2179 | int CalendarView::addCategories() |
2178 | { | 2180 | { |
2179 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2181 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2180 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2182 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2181 | QStringList catIncList; | 2183 | QStringList catIncList; |
2182 | Incidence* inc = incList.first(); | 2184 | Incidence* inc = incList.first(); |
2183 | int i; | 2185 | int i; |
2184 | int count = 0; | 2186 | int count = 0; |
2185 | while ( inc ) { | 2187 | while ( inc ) { |
2186 | catIncList = inc->categories() ; | 2188 | catIncList = inc->categories() ; |
2187 | for( i = 0; i< catIncList.count(); ++i ) { | 2189 | for( i = 0; i< catIncList.count(); ++i ) { |
2188 | if ( !catList.contains (catIncList[i])) { | 2190 | if ( !catList.contains (catIncList[i])) { |
2189 | catList.append( catIncList[i] ); | 2191 | catList.append( catIncList[i] ); |
2190 | //qDebug("add cat %s ", catIncList[i].latin1()); | 2192 | //qDebug("add cat %s ", catIncList[i].latin1()); |
2191 | ++count; | 2193 | ++count; |
2192 | } | 2194 | } |
2193 | } | 2195 | } |
2194 | inc = incList.next(); | 2196 | inc = incList.next(); |
2195 | } | 2197 | } |
2196 | catList.sort(); | 2198 | catList.sort(); |
2197 | KOPrefs::instance()->mCustomCategories = catList; | 2199 | KOPrefs::instance()->mCustomCategories = catList; |
2198 | return count; | 2200 | return count; |
2199 | } | 2201 | } |
2200 | 2202 | ||
2201 | void CalendarView::manageCategories() | 2203 | void CalendarView::manageCategories() |
2202 | { | 2204 | { |
2203 | KOCatPrefs* cp = new KOCatPrefs(); | 2205 | KOCatPrefs* cp = new KOCatPrefs(); |
2204 | cp->show(); | 2206 | cp->show(); |
2205 | int w =cp->sizeHint().width() ; | 2207 | int w =cp->sizeHint().width() ; |
2206 | int h = cp->sizeHint().height() ; | 2208 | int h = cp->sizeHint().height() ; |
2207 | int dw = QApplication::desktop()->width(); | 2209 | int dw = QApplication::desktop()->width(); |
2208 | int dh = QApplication::desktop()->height(); | 2210 | int dh = QApplication::desktop()->height(); |
2209 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2211 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2210 | if ( !cp->exec() ) { | 2212 | if ( !cp->exec() ) { |
2211 | delete cp; | 2213 | delete cp; |
2212 | return; | 2214 | return; |
2213 | } | 2215 | } |
2214 | int count = 0; | 2216 | int count = 0; |
2215 | if ( cp->addCat() ) { | 2217 | if ( cp->addCat() ) { |
2216 | count = addCategories(); | 2218 | count = addCategories(); |
2217 | if ( count ) { | 2219 | if ( count ) { |
2218 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); | 2220 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); |
2219 | writeSettings(); | 2221 | writeSettings(); |
2220 | } | 2222 | } |
2221 | } else { | 2223 | } else { |
2222 | removeCategories(); | 2224 | removeCategories(); |
2223 | updateView(); | 2225 | updateView(); |
2224 | } | 2226 | } |
2225 | delete cp; | 2227 | delete cp; |
2226 | } | 2228 | } |
2227 | 2229 | ||
2228 | void CalendarView::beamIncidence(Incidence * Inc) | 2230 | void CalendarView::beamIncidence(Incidence * Inc) |
2229 | { | 2231 | { |
2230 | QPtrList<Incidence> delSel ; | 2232 | QPtrList<Incidence> delSel ; |
2231 | delSel.append(Inc); | 2233 | delSel.append(Inc); |
2232 | beamIncidenceList( delSel ); | 2234 | beamIncidenceList( delSel ); |
2233 | } | 2235 | } |
2234 | void CalendarView::beamCalendar() | 2236 | void CalendarView::beamCalendar() |
2235 | { | 2237 | { |
2236 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); | 2238 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); |
2237 | //qDebug("beamCalendar() "); | 2239 | //qDebug("beamCalendar() "); |
2238 | beamIncidenceList( delSel ); | 2240 | beamIncidenceList( delSel ); |
2239 | } | 2241 | } |
2240 | void CalendarView::beamFilteredCalendar() | 2242 | void CalendarView::beamFilteredCalendar() |
2241 | { | 2243 | { |
2242 | QPtrList<Incidence> delSel = mCalendar->incidences(); | 2244 | QPtrList<Incidence> delSel = mCalendar->incidences(); |
2243 | //qDebug("beamFilteredCalendar() "); | 2245 | //qDebug("beamFilteredCalendar() "); |
2244 | beamIncidenceList( delSel ); | 2246 | beamIncidenceList( delSel ); |
2245 | } | 2247 | } |
2246 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) | 2248 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) |
2247 | { | 2249 | { |
2248 | if ( beamDialog->exec () == QDialog::Rejected ) | 2250 | if ( beamDialog->exec () == QDialog::Rejected ) |
2249 | return; | 2251 | return; |
2250 | 2252 | ||
2251 | QString fn = "/tmp/kopibeamfile"; | 2253 | QString fn = "/tmp/kopibeamfile"; |
2252 | QString mes; | 2254 | QString mes; |
2253 | bool createbup = true; | 2255 | bool createbup = true; |
2254 | if ( createbup ) { | 2256 | if ( createbup ) { |
2255 | QString description = "\n"; | 2257 | QString description = "\n"; |
2256 | CalendarLocal* cal = new CalendarLocal(); | 2258 | CalendarLocal* cal = new CalendarLocal(); |
2257 | if ( beamDialog->beamLocal() ) | 2259 | if ( beamDialog->beamLocal() ) |
2258 | cal->setLocalTime(); | 2260 | cal->setLocalTime(); |
2259 | else | 2261 | else |
2260 | cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 2262 | cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
2261 | Incidence *incidence = delSel.first(); | 2263 | Incidence *incidence = delSel.first(); |
2262 | bool addText = false; | 2264 | bool addText = false; |
2263 | if ( delSel.count() < 10 ) | 2265 | if ( delSel.count() < 10 ) |
2264 | addText = true; | 2266 | addText = true; |
2265 | else { | 2267 | else { |
2266 | description.sprintf(i18n(" %d items?"),delSel.count() ); | 2268 | description.sprintf(i18n(" %d items?"),delSel.count() ); |
2267 | } | 2269 | } |
2268 | while ( incidence ) { | 2270 | while ( incidence ) { |
2269 | Incidence *in = incidence->clone(); | 2271 | Incidence *in = incidence->clone(); |
2270 | if ( addText ) | 2272 | if ( addText ) |
2271 | description += in->summary() + "\n"; | 2273 | description += in->summary() + "\n"; |
2272 | cal->addIncidence( in ); | 2274 | cal->addIncidence( in ); |
2273 | incidence = delSel.next(); | 2275 | incidence = delSel.next(); |
2274 | } | 2276 | } |
2275 | if ( beamDialog->beamVcal() ) { | 2277 | if ( beamDialog->beamVcal() ) { |
2276 | fn += ".vcs"; | 2278 | fn += ".vcs"; |
2277 | FileStorage storage( cal, fn, new VCalFormat ); | 2279 | FileStorage storage( cal, fn, new VCalFormat ); |
2278 | storage.save(); | 2280 | storage.save(); |
2279 | } else { | 2281 | } else { |
2280 | fn += ".ics"; | 2282 | fn += ".ics"; |
2281 | FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2283 | FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2282 | storage.save(); | 2284 | storage.save(); |
2283 | } | 2285 | } |
2284 | delete cal; | 2286 | delete cal; |
2285 | mes = i18n("KO/Pi: Ready for beaming"); | 2287 | mes = i18n("KO/Pi: Ready for beaming"); |
2286 | setCaption(mes); | 2288 | setCaption(mes); |
2287 | 2289 | ||
2288 | #ifndef DESKTOP_VERSION | 2290 | #ifndef DESKTOP_VERSION |
2289 | Ir *ir = new Ir( this ); | 2291 | Ir *ir = new Ir( this ); |
2290 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 2292 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
2291 | ir->send( fn, description, "text/x-vCalendar" ); | 2293 | ir->send( fn, description, "text/x-vCalendar" ); |
2292 | #endif | 2294 | #endif |
2293 | } | 2295 | } |
2294 | } | 2296 | } |
2295 | void CalendarView::beamDone( Ir *ir ) | 2297 | void CalendarView::beamDone( Ir *ir ) |
2296 | { | 2298 | { |
2297 | #ifndef DESKTOP_VERSION | 2299 | #ifndef DESKTOP_VERSION |
2298 | delete ir; | 2300 | delete ir; |
2299 | #endif | 2301 | #endif |
2300 | } | 2302 | } |
2301 | 2303 | ||
2302 | void CalendarView::moveIncidence(Incidence * inc ) | 2304 | void CalendarView::moveIncidence(Incidence * inc ) |
2303 | { | 2305 | { |
2304 | if ( !inc ) return; | 2306 | if ( !inc ) return; |
2305 | // qDebug("showDatePickerForIncidence( ) "); | 2307 | // qDebug("showDatePickerForIncidence( ) "); |
2306 | if ( mDateFrame->isVisible() ) | 2308 | if ( mDateFrame->isVisible() ) |
2307 | mDateFrame->hide(); | 2309 | mDateFrame->hide(); |
2308 | else { | 2310 | else { |
2309 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; | 2311 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; |
2310 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; | 2312 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; |
2311 | int dw = QApplication::desktop()->width(); | 2313 | int dw = QApplication::desktop()->width(); |
2312 | int dh = QApplication::desktop()->height(); | 2314 | int dh = QApplication::desktop()->height(); |
2313 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2315 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2314 | mDateFrame->show(); | 2316 | mDateFrame->show(); |
2315 | } | 2317 | } |
2316 | mDatePickerMode = 2; | 2318 | mDatePickerMode = 2; |
2317 | mMoveIncidence = inc ; | 2319 | mMoveIncidence = inc ; |
2318 | QDate da; | 2320 | QDate da; |
2319 | if ( mMoveIncidence->type() == "Todo" ) { | 2321 | if ( mMoveIncidence->type() == "Todo" ) { |
2320 | Todo * to = (Todo *) mMoveIncidence; | 2322 | Todo * to = (Todo *) mMoveIncidence; |
2321 | if ( to->hasDueDate() ) | 2323 | if ( to->hasDueDate() ) |
2322 | da = to->dtDue().date(); | 2324 | da = to->dtDue().date(); |
2323 | else | 2325 | else |
2324 | da = QDate::currentDate(); | 2326 | da = QDate::currentDate(); |
2325 | } else { | 2327 | } else { |
2326 | da = mMoveIncidence->dtStart().date(); | 2328 | da = mMoveIncidence->dtStart().date(); |
2327 | } | 2329 | } |
2328 | mDatePicker->setDate( da ); | 2330 | mDatePicker->setDate( da ); |
2329 | } | 2331 | } |
2330 | void CalendarView::showDatePicker( ) | 2332 | void CalendarView::showDatePicker( ) |
2331 | { | 2333 | { |
2332 | //qDebug("CalendarView::showDatePicker( ) "); | 2334 | //qDebug("CalendarView::showDatePicker( ) "); |
2333 | if ( mDateFrame->isVisible() ) | 2335 | if ( mDateFrame->isVisible() ) |
2334 | mDateFrame->hide(); | 2336 | mDateFrame->hide(); |
2335 | else { | 2337 | else { |
2336 | int w =mDatePicker->sizeHint().width() ; | 2338 | int w =mDatePicker->sizeHint().width() ; |
2337 | int h = mDatePicker->sizeHint().height() ; | 2339 | int h = mDatePicker->sizeHint().height() ; |
2338 | int dw = QApplication::desktop()->width(); | 2340 | int dw = QApplication::desktop()->width(); |
2339 | int dh = QApplication::desktop()->height(); | 2341 | int dh = QApplication::desktop()->height(); |
2340 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2342 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2341 | mDateFrame->show(); | 2343 | mDateFrame->show(); |
2342 | } | 2344 | } |
2343 | mDatePickerMode = 1; | 2345 | mDatePickerMode = 1; |
2344 | mDatePicker->setDate( mNavigator->selectedDates().first() ); | 2346 | mDatePicker->setDate( mNavigator->selectedDates().first() ); |
2345 | } | 2347 | } |
2346 | 2348 | ||
2347 | void CalendarView::showEventEditor() | 2349 | void CalendarView::showEventEditor() |
2348 | { | 2350 | { |
2349 | #ifdef DESKTOP_VERSION | 2351 | #ifdef DESKTOP_VERSION |
2350 | mEventEditor->show(); | 2352 | mEventEditor->show(); |
2351 | #else | 2353 | #else |
2352 | mEventEditor->showMaximized(); | 2354 | mEventEditor->showMaximized(); |
2353 | #endif | 2355 | #endif |
2354 | } | 2356 | } |
2355 | void CalendarView::showTodoEditor() | 2357 | void CalendarView::showTodoEditor() |
2356 | { | 2358 | { |
2357 | #ifdef DESKTOP_VERSION | 2359 | #ifdef DESKTOP_VERSION |
2358 | mTodoEditor->show(); | 2360 | mTodoEditor->show(); |
2359 | #else | 2361 | #else |
2360 | mTodoEditor->showMaximized(); | 2362 | mTodoEditor->showMaximized(); |
2361 | #endif | 2363 | #endif |
2362 | } | 2364 | } |
2363 | void CalendarView::cancelIncidence(Incidence * inc ) | 2365 | void CalendarView::cancelIncidence(Incidence * inc ) |
2364 | { | 2366 | { |
2365 | inc->setCancelled( ! inc->cancelled() ); | 2367 | inc->setCancelled( ! inc->cancelled() ); |
2366 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); | 2368 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); |
2367 | updateView(); | 2369 | updateView(); |
2368 | } | 2370 | } |
2369 | void CalendarView::cloneIncidence(Incidence * orgInc ) | 2371 | void CalendarView::cloneIncidence(Incidence * orgInc ) |
2370 | { | 2372 | { |
2371 | Incidence * newInc = orgInc->clone(); | 2373 | Incidence * newInc = orgInc->clone(); |
2372 | newInc->recreate(); | 2374 | newInc->recreate(); |
2373 | 2375 | ||
2374 | if ( newInc->type() == "Todo" ) { | 2376 | if ( newInc->type() == "Todo" ) { |
2375 | Todo* t = (Todo*) newInc; | 2377 | Todo* t = (Todo*) newInc; |
2376 | mTodoEditor->editTodo( t ); | 2378 | mTodoEditor->editTodo( t ); |
2377 | showTodoEditor(); | 2379 | showTodoEditor(); |
2378 | if ( mTodoEditor->exec() ) { | 2380 | if ( mTodoEditor->exec() ) { |
2379 | mCalendar->addTodo( t ); | 2381 | mCalendar->addTodo( t ); |
2380 | updateView(); | 2382 | updateView(); |
2381 | } else { | 2383 | } else { |
2382 | delete t; | 2384 | delete t; |
2383 | } | 2385 | } |
2384 | } | 2386 | } |
2385 | else { | 2387 | else { |
2386 | Event* e = (Event*) newInc; | 2388 | Event* e = (Event*) newInc; |
2387 | mEventEditor->editEvent( e ); | 2389 | mEventEditor->editEvent( e ); |
2388 | showEventEditor(); | 2390 | showEventEditor(); |
2389 | if ( mEventEditor->exec() ) { | 2391 | if ( mEventEditor->exec() ) { |
2390 | mCalendar->addEvent( e ); | 2392 | mCalendar->addEvent( e ); |
2391 | updateView(); | 2393 | updateView(); |
2392 | } else { | 2394 | } else { |
2393 | delete e; | 2395 | delete e; |
2394 | } | 2396 | } |
2395 | } | 2397 | } |
2396 | } | 2398 | } |
2397 | 2399 | ||
2398 | void CalendarView::newEvent() | 2400 | void CalendarView::newEvent() |
2399 | { | 2401 | { |
2400 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. | 2402 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. |
2401 | KOAgendaView *aView = mViewManager->agendaView(); | 2403 | KOAgendaView *aView = mViewManager->agendaView(); |
2402 | if (aView) { | 2404 | if (aView) { |
2403 | if (aView->selectionStart().isValid()) { | 2405 | if (aView->selectionStart().isValid()) { |
2404 | if (aView->selectedIsAllDay()) { | 2406 | if (aView->selectedIsAllDay()) { |
2405 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); | 2407 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); |
2406 | } else { | 2408 | } else { |
2407 | newEvent(aView->selectionStart(),aView->selectionEnd()); | 2409 | newEvent(aView->selectionStart(),aView->selectionEnd()); |
2408 | } | 2410 | } |
2409 | return; | 2411 | return; |
2410 | } | 2412 | } |
2411 | } | 2413 | } |
2412 | 2414 | ||
2413 | QDate date = mNavigator->selectedDates().first(); | 2415 | QDate date = mNavigator->selectedDates().first(); |
2414 | QDateTime current = QDateTime::currentDateTime(); | 2416 | QDateTime current = QDateTime::currentDateTime(); |
2415 | if ( date <= current.date() ) { | 2417 | if ( date <= current.date() ) { |
2416 | int hour = current.time().hour() +1; | 2418 | int hour = current.time().hour() +1; |
2417 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), | 2419 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), |
2418 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2420 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2419 | } else | 2421 | } else |
2420 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), | 2422 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), |
2421 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + | 2423 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + |
2422 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2424 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2423 | } | 2425 | } |
2424 | 2426 | ||
2425 | void CalendarView::newEvent(QDateTime fh) | 2427 | void CalendarView::newEvent(QDateTime fh) |
2426 | { | 2428 | { |
2427 | newEvent(fh, | 2429 | newEvent(fh, |
2428 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); | 2430 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); |
2429 | } | 2431 | } |
2430 | 2432 | ||
2431 | void CalendarView::newEvent(QDate dt) | 2433 | void CalendarView::newEvent(QDate dt) |
2432 | { | 2434 | { |
2433 | newEvent(QDateTime(dt, QTime(0,0,0)), | 2435 | newEvent(QDateTime(dt, QTime(0,0,0)), |
2434 | QDateTime(dt, QTime(0,0,0)), true); | 2436 | QDateTime(dt, QTime(0,0,0)), true); |
2435 | } | 2437 | } |
2436 | 2438 | ||
2437 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) | 2439 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) |
2438 | { | 2440 | { |
2439 | 2441 | ||
2440 | mEventEditor->newEvent(fromHint,toHint,allDay); | 2442 | mEventEditor->newEvent(fromHint,toHint,allDay); |
2441 | if ( mFilterView->filtersEnabled() ) { | 2443 | if ( mFilterView->filtersEnabled() ) { |
2442 | CalFilter *filter = mFilterView->selectedFilter(); | 2444 | CalFilter *filter = mFilterView->selectedFilter(); |
2443 | if (filter && filter->showCategories()) { | 2445 | if (filter && filter->showCategories()) { |
2444 | mEventEditor->setCategories(filter->categoryList().join(",") ); | 2446 | mEventEditor->setCategories(filter->categoryList().join(",") ); |
2445 | } | 2447 | } |
2446 | if ( filter ) | 2448 | if ( filter ) |
2447 | mEventEditor->setSecrecy( filter->getSecrecy() ); | 2449 | mEventEditor->setSecrecy( filter->getSecrecy() ); |
2448 | } | 2450 | } |
2449 | showEventEditor(); | 2451 | showEventEditor(); |
2450 | } | 2452 | } |
2451 | void CalendarView::todoAdded(Todo * t) | 2453 | void CalendarView::todoAdded(Todo * t) |
2452 | { | 2454 | { |
2453 | 2455 | ||
2454 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); | 2456 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); |
2455 | updateTodoViews(); | 2457 | updateTodoViews(); |
2456 | } | 2458 | } |
2457 | void CalendarView::todoChanged(Todo * t) | 2459 | void CalendarView::todoChanged(Todo * t) |
2458 | { | 2460 | { |
2459 | emit todoModified( t, 4 ); | 2461 | emit todoModified( t, 4 ); |
2460 | // updateTodoViews(); | 2462 | // updateTodoViews(); |
2461 | } | 2463 | } |
2462 | void CalendarView::todoToBeDeleted(Todo *) | 2464 | void CalendarView::todoToBeDeleted(Todo *) |
2463 | { | 2465 | { |
2464 | //qDebug("todoToBeDeleted(Todo *) "); | 2466 | //qDebug("todoToBeDeleted(Todo *) "); |
2465 | updateTodoViews(); | 2467 | updateTodoViews(); |
2466 | } | 2468 | } |
2467 | void CalendarView::todoDeleted() | 2469 | void CalendarView::todoDeleted() |
2468 | { | 2470 | { |
2469 | //qDebug(" todoDeleted()"); | 2471 | //qDebug(" todoDeleted()"); |
2470 | updateTodoViews(); | 2472 | updateTodoViews(); |
2471 | } | 2473 | } |
2472 | 2474 | ||
2473 | 2475 | ||
2474 | 2476 | ||
2475 | void CalendarView::newTodo() | 2477 | void CalendarView::newTodo() |
2476 | { | 2478 | { |
2477 | 2479 | ||
2478 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); | 2480 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); |
2479 | if ( mFilterView->filtersEnabled() ) { | 2481 | if ( mFilterView->filtersEnabled() ) { |
2480 | CalFilter *filter = mFilterView->selectedFilter(); | 2482 | CalFilter *filter = mFilterView->selectedFilter(); |
2481 | if (filter && filter->showCategories()) { | 2483 | if (filter && filter->showCategories()) { |
2482 | mTodoEditor->setCategories(filter->categoryList().join(",") ); | 2484 | mTodoEditor->setCategories(filter->categoryList().join(",") ); |
2483 | } | 2485 | } |
2484 | if ( filter ) | 2486 | if ( filter ) |
2485 | mTodoEditor->setSecrecy( filter->getSecrecy() ); | 2487 | mTodoEditor->setSecrecy( filter->getSecrecy() ); |
2486 | } | 2488 | } |
2487 | showTodoEditor(); | 2489 | showTodoEditor(); |
2488 | } | 2490 | } |
2489 | 2491 | ||
2490 | void CalendarView::newSubTodo() | 2492 | void CalendarView::newSubTodo() |
2491 | { | 2493 | { |
2492 | Todo *todo = selectedTodo(); | 2494 | Todo *todo = selectedTodo(); |
2493 | if ( todo ) newSubTodo( todo ); | 2495 | if ( todo ) newSubTodo( todo ); |
2494 | } | 2496 | } |
2495 | 2497 | ||
2496 | void CalendarView::newSubTodo(Todo *parentEvent) | 2498 | void CalendarView::newSubTodo(Todo *parentEvent) |
2497 | { | 2499 | { |
2498 | 2500 | ||
2499 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); | 2501 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); |
2500 | showTodoEditor(); | 2502 | showTodoEditor(); |
2501 | } | 2503 | } |
2502 | 2504 | ||
2503 | void CalendarView::newFloatingEvent() | 2505 | void CalendarView::newFloatingEvent() |
2504 | { | 2506 | { |
2505 | DateList tmpList = mNavigator->selectedDates(); | 2507 | DateList tmpList = mNavigator->selectedDates(); |
2506 | QDate date = tmpList.first(); | 2508 | QDate date = tmpList.first(); |
2507 | 2509 | ||
2508 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), | 2510 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), |
2509 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); | 2511 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); |
2510 | } | 2512 | } |
2511 | 2513 | ||
2512 | 2514 | ||
2513 | void CalendarView::editEvent( Event *event ) | 2515 | void CalendarView::editEvent( Event *event ) |
2514 | { | 2516 | { |
2515 | 2517 | ||
2516 | if ( !event ) return; | 2518 | if ( !event ) return; |
2517 | if ( event->isReadOnly() ) { | 2519 | if ( event->isReadOnly() ) { |
2518 | showEvent( event ); | 2520 | showEvent( event ); |
2519 | return; | 2521 | return; |
2520 | } | 2522 | } |
2521 | mEventEditor->editEvent( event , mFlagEditDescription); | 2523 | mEventEditor->editEvent( event , mFlagEditDescription); |
2522 | showEventEditor(); | 2524 | showEventEditor(); |
2523 | } | 2525 | } |
2524 | void CalendarView::editJournal( Journal *jour ) | 2526 | void CalendarView::editJournal( Journal *jour ) |
2525 | { | 2527 | { |
2526 | if ( !jour ) return; | 2528 | if ( !jour ) return; |
2527 | mDialogManager->hideSearchDialog(); | 2529 | mDialogManager->hideSearchDialog(); |
2528 | mViewManager->showJournalView(); | 2530 | mViewManager->showJournalView(); |
2529 | mNavigator->slotDaySelect( jour->dtStart().date() ); | 2531 | mNavigator->slotDaySelect( jour->dtStart().date() ); |
2530 | } | 2532 | } |
2531 | void CalendarView::editTodo( Todo *todo ) | 2533 | void CalendarView::editTodo( Todo *todo ) |
2532 | { | 2534 | { |
2533 | if ( !todo ) return; | 2535 | if ( !todo ) return; |
2534 | 2536 | ||
2535 | if ( todo->isReadOnly() ) { | 2537 | if ( todo->isReadOnly() ) { |
2536 | showTodo( todo ); | 2538 | showTodo( todo ); |
2537 | return; | 2539 | return; |
2538 | } | 2540 | } |
2539 | mTodoEditor->editTodo( todo ,mFlagEditDescription); | 2541 | mTodoEditor->editTodo( todo ,mFlagEditDescription); |
2540 | showTodoEditor(); | 2542 | showTodoEditor(); |
2541 | 2543 | ||
2542 | } | 2544 | } |
2543 | 2545 | ||
2544 | KOEventViewerDialog* CalendarView::getEventViewerDialog() | 2546 | KOEventViewerDialog* CalendarView::getEventViewerDialog() |
2545 | { | 2547 | { |
2546 | if ( !mEventViewerDialog ) { | 2548 | if ( !mEventViewerDialog ) { |
2547 | mEventViewerDialog = new KOEventViewerDialog(this); | 2549 | mEventViewerDialog = new KOEventViewerDialog(this); |
2548 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); | 2550 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); |
2549 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); | 2551 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); |
2550 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), | 2552 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), |
2551 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); | 2553 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); |
2552 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), | 2554 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), |
2553 | viewManager(), SLOT( showAgendaView( bool ) ) ); | 2555 | viewManager(), SLOT( showAgendaView( bool ) ) ); |
2554 | mEventViewerDialog->resize( 640, 480 ); | 2556 | mEventViewerDialog->resize( 640, 480 ); |
2555 | 2557 | ||
2556 | } | 2558 | } |
2557 | return mEventViewerDialog; | 2559 | return mEventViewerDialog; |
2558 | } | 2560 | } |
2559 | void CalendarView::showEvent(Event *event) | 2561 | void CalendarView::showEvent(Event *event) |
2560 | { | 2562 | { |
2561 | getEventViewerDialog()->setEvent(event); | 2563 | getEventViewerDialog()->setEvent(event); |
2562 | getEventViewerDialog()->showMe(); | 2564 | getEventViewerDialog()->showMe(); |
2563 | } | 2565 | } |
2564 | 2566 | ||
2565 | void CalendarView::showTodo(Todo *event) | 2567 | void CalendarView::showTodo(Todo *event) |
2566 | { | 2568 | { |
2567 | getEventViewerDialog()->setTodo(event); | 2569 | getEventViewerDialog()->setTodo(event); |
2568 | getEventViewerDialog()->showMe(); | 2570 | getEventViewerDialog()->showMe(); |
2569 | } | 2571 | } |
2570 | void CalendarView::showJournal( Journal *jour ) | 2572 | void CalendarView::showJournal( Journal *jour ) |
2571 | { | 2573 | { |
2572 | getEventViewerDialog()->setJournal(jour); | 2574 | getEventViewerDialog()->setJournal(jour); |
2573 | getEventViewerDialog()->showMe(); | 2575 | getEventViewerDialog()->showMe(); |
2574 | 2576 | ||
2575 | } | 2577 | } |
2576 | // void CalendarView::todoModified (Todo *event, int changed) | 2578 | // void CalendarView::todoModified (Todo *event, int changed) |
2577 | // { | 2579 | // { |
2578 | // // if (mDialogList.find (event) != mDialogList.end ()) { | 2580 | // // if (mDialogList.find (event) != mDialogList.end ()) { |
2579 | // // kdDebug() << "Todo modified and open" << endl; | 2581 | // // kdDebug() << "Todo modified and open" << endl; |
2580 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; | 2582 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; |
2581 | // // temp->modified (changed); | 2583 | // // temp->modified (changed); |
2582 | 2584 | ||
2583 | // // } | 2585 | // // } |
2584 | 2586 | ||
2585 | // mViewManager->updateView(); | 2587 | // mViewManager->updateView(); |
2586 | // } | 2588 | // } |
2587 | 2589 | ||
2588 | void CalendarView::appointment_show() | 2590 | void CalendarView::appointment_show() |
2589 | { | 2591 | { |
2590 | Event *anEvent = 0; | 2592 | Event *anEvent = 0; |
2591 | 2593 | ||
2592 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2594 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2593 | 2595 | ||
2594 | if (mViewManager->currentView()->isEventView()) { | 2596 | if (mViewManager->currentView()->isEventView()) { |
2595 | if ( incidence && incidence->type() == "Event" ) { | 2597 | if ( incidence && incidence->type() == "Event" ) { |
2596 | anEvent = static_cast<Event *>(incidence); | 2598 | anEvent = static_cast<Event *>(incidence); |
2597 | } | 2599 | } |
2598 | } | 2600 | } |
2599 | 2601 | ||
2600 | if (!anEvent) { | 2602 | if (!anEvent) { |
2601 | KNotifyClient::beep(); | 2603 | KNotifyClient::beep(); |
2602 | return; | 2604 | return; |
2603 | } | 2605 | } |
2604 | 2606 | ||
2605 | showEvent(anEvent); | 2607 | showEvent(anEvent); |
2606 | } | 2608 | } |
2607 | 2609 | ||
2608 | void CalendarView::appointment_edit() | 2610 | void CalendarView::appointment_edit() |
2609 | { | 2611 | { |
2610 | Event *anEvent = 0; | 2612 | Event *anEvent = 0; |
2611 | 2613 | ||
2612 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2614 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2613 | 2615 | ||
2614 | if (mViewManager->currentView()->isEventView()) { | 2616 | if (mViewManager->currentView()->isEventView()) { |
2615 | if ( incidence && incidence->type() == "Event" ) { | 2617 | if ( incidence && incidence->type() == "Event" ) { |
2616 | anEvent = static_cast<Event *>(incidence); | 2618 | anEvent = static_cast<Event *>(incidence); |
2617 | } | 2619 | } |
2618 | } | 2620 | } |
2619 | 2621 | ||
2620 | if (!anEvent) { | 2622 | if (!anEvent) { |
2621 | KNotifyClient::beep(); | 2623 | KNotifyClient::beep(); |
2622 | return; | 2624 | return; |
2623 | } | 2625 | } |
2624 | 2626 | ||
2625 | editEvent(anEvent); | 2627 | editEvent(anEvent); |
2626 | } | 2628 | } |
2627 | 2629 | ||
2628 | void CalendarView::appointment_delete() | 2630 | void CalendarView::appointment_delete() |
2629 | { | 2631 | { |
2630 | Event *anEvent = 0; | 2632 | Event *anEvent = 0; |
2631 | 2633 | ||
2632 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2634 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2633 | 2635 | ||
2634 | if (mViewManager->currentView()->isEventView()) { | 2636 | if (mViewManager->currentView()->isEventView()) { |
2635 | if ( incidence && incidence->type() == "Event" ) { | 2637 | if ( incidence && incidence->type() == "Event" ) { |
2636 | anEvent = static_cast<Event *>(incidence); | 2638 | anEvent = static_cast<Event *>(incidence); |
2637 | } | 2639 | } |
2638 | } | 2640 | } |
2639 | 2641 | ||
2640 | if (!anEvent) { | 2642 | if (!anEvent) { |
2641 | KNotifyClient::beep(); | 2643 | KNotifyClient::beep(); |
2642 | return; | 2644 | return; |
2643 | } | 2645 | } |
2644 | 2646 | ||
2645 | deleteEvent(anEvent); | 2647 | deleteEvent(anEvent); |
2646 | } | 2648 | } |
2647 | 2649 | ||
2648 | void CalendarView::todo_unsub(Todo *anTodo ) | 2650 | void CalendarView::todo_unsub(Todo *anTodo ) |
2649 | { | 2651 | { |
2650 | // Todo *anTodo = selectedTodo(); | 2652 | // Todo *anTodo = selectedTodo(); |
2651 | if (!anTodo) return; | 2653 | if (!anTodo) return; |
2652 | if (!anTodo->relatedTo()) return; | 2654 | if (!anTodo->relatedTo()) return; |
2653 | anTodo->relatedTo()->removeRelation(anTodo); | 2655 | anTodo->relatedTo()->removeRelation(anTodo); |
2654 | anTodo->setRelatedTo(0); | 2656 | anTodo->setRelatedTo(0); |
2655 | anTodo->updated(); | 2657 | anTodo->updated(); |
2656 | anTodo->setRelatedToUid(""); | 2658 | anTodo->setRelatedToUid(""); |
2657 | setModified(true); | 2659 | setModified(true); |
2658 | updateView(); | 2660 | updateView(); |
2659 | } | 2661 | } |
2660 | 2662 | ||
2661 | void CalendarView::deleteTodo(Todo *todo) | 2663 | void CalendarView::deleteTodo(Todo *todo) |
2662 | { | 2664 | { |
2663 | if (!todo) { | 2665 | if (!todo) { |
2664 | KNotifyClient::beep(); | 2666 | KNotifyClient::beep(); |
2665 | return; | 2667 | return; |
2666 | } | 2668 | } |
2667 | if (KOPrefs::instance()->mConfirm) { | 2669 | if (KOPrefs::instance()->mConfirm) { |
2668 | switch (msgItemDelete()) { | 2670 | switch (msgItemDelete()) { |
2669 | case KMessageBox::Continue: // OK | 2671 | case KMessageBox::Continue: // OK |
2670 | if (!todo->relations().isEmpty()) { | 2672 | if (!todo->relations().isEmpty()) { |
2671 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2673 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2672 | i18n("Delete To-Do")); | 2674 | i18n("Delete To-Do")); |
2673 | } else { | 2675 | } else { |
2674 | checkExternalId( todo ); | 2676 | checkExternalId( todo ); |
2675 | calendar()->deleteTodo(todo); | 2677 | calendar()->deleteTodo(todo); |
2676 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2678 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2677 | updateView(); | 2679 | updateView(); |
2678 | } | 2680 | } |
2679 | break; | 2681 | break; |
2680 | } // switch | 2682 | } // switch |
2681 | } else { | 2683 | } else { |
2682 | if (!todo->relations().isEmpty()) { | 2684 | if (!todo->relations().isEmpty()) { |
2683 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2685 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2684 | i18n("Delete To-Do")); | 2686 | i18n("Delete To-Do")); |
2685 | } else { | 2687 | } else { |
2686 | checkExternalId( todo ); | 2688 | checkExternalId( todo ); |
2687 | mCalendar->deleteTodo(todo); | 2689 | mCalendar->deleteTodo(todo); |
2688 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2690 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2689 | updateView(); | 2691 | updateView(); |
2690 | } | 2692 | } |
2691 | } | 2693 | } |
2692 | emit updateSearchDialog(); | 2694 | emit updateSearchDialog(); |
2693 | } | 2695 | } |
2694 | void CalendarView::deleteJournal(Journal *jour) | 2696 | void CalendarView::deleteJournal(Journal *jour) |
2695 | { | 2697 | { |
2696 | if (!jour) { | 2698 | if (!jour) { |
2697 | KNotifyClient::beep(); | 2699 | KNotifyClient::beep(); |
2698 | return; | 2700 | return; |
2699 | } | 2701 | } |
2700 | if (KOPrefs::instance()->mConfirm) { | 2702 | if (KOPrefs::instance()->mConfirm) { |
2701 | switch (msgItemDelete()) { | 2703 | switch (msgItemDelete()) { |
2702 | case KMessageBox::Continue: // OK | 2704 | case KMessageBox::Continue: // OK |
2703 | calendar()->deleteJournal(jour); | 2705 | calendar()->deleteJournal(jour); |
2704 | updateView(); | 2706 | updateView(); |
2705 | break; | 2707 | break; |
2706 | } // switch | 2708 | } // switch |
2707 | } else { | 2709 | } else { |
2708 | calendar()->deleteJournal(jour);; | 2710 | calendar()->deleteJournal(jour);; |
2709 | updateView(); | 2711 | updateView(); |
2710 | } | 2712 | } |
2711 | emit updateSearchDialog(); | 2713 | emit updateSearchDialog(); |
2712 | } | 2714 | } |
2713 | 2715 | ||
2714 | void CalendarView::deleteEvent(Event *anEvent) | 2716 | void CalendarView::deleteEvent(Event *anEvent) |
2715 | { | 2717 | { |
2716 | if (!anEvent) { | 2718 | if (!anEvent) { |
2717 | KNotifyClient::beep(); | 2719 | KNotifyClient::beep(); |
2718 | return; | 2720 | return; |
2719 | } | 2721 | } |
2720 | 2722 | ||
2721 | if (anEvent->recurrence()->doesRecur()) { | 2723 | if (anEvent->recurrence()->doesRecur()) { |
2722 | QDate itemDate = mViewManager->currentSelectionDate(); | 2724 | QDate itemDate = mViewManager->currentSelectionDate(); |
2723 | int km; | 2725 | int km; |
2724 | if (!itemDate.isValid()) { | 2726 | if (!itemDate.isValid()) { |
2725 | //kdDebug() << "Date Not Valid" << endl; | 2727 | //kdDebug() << "Date Not Valid" << endl; |
2726 | if (KOPrefs::instance()->mConfirm) { | 2728 | if (KOPrefs::instance()->mConfirm) { |
2727 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2729 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2728 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), | 2730 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), |
2729 | i18n("KO/Pi Confirmation"),i18n("Delete All")); | 2731 | i18n("KO/Pi Confirmation"),i18n("Delete All")); |
2730 | if ( km == KMessageBox::Continue ) | 2732 | if ( km == KMessageBox::Continue ) |
2731 | km = KMessageBox::No; // No = all below | 2733 | km = KMessageBox::No; // No = all below |
2732 | } else | 2734 | } else |
2733 | km = KMessageBox::No; | 2735 | km = KMessageBox::No; |
2734 | } else { | 2736 | } else { |
2735 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + | 2737 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + |
2736 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ | 2738 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ |
2737 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), | 2739 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), |
2738 | i18n("KO/Pi Confirmation"),i18n("Current"), | 2740 | i18n("KO/Pi Confirmation"),i18n("Current"), |
2739 | i18n("All")); | 2741 | i18n("All")); |
2740 | } | 2742 | } |
2741 | switch(km) { | 2743 | switch(km) { |
2742 | 2744 | ||
2743 | case KMessageBox::No: // Continue // all | 2745 | case KMessageBox::No: // Continue // all |
2744 | //qDebug("KMessageBox::No "); | 2746 | //qDebug("KMessageBox::No "); |
2745 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2747 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2746 | schedule(Scheduler::Cancel,anEvent); | 2748 | schedule(Scheduler::Cancel,anEvent); |
2747 | 2749 | ||
2748 | checkExternalId( anEvent); | 2750 | checkExternalId( anEvent); |
2749 | mCalendar->deleteEvent(anEvent); | 2751 | mCalendar->deleteEvent(anEvent); |
2750 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); | 2752 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); |
2751 | break; | 2753 | break; |
2752 | 2754 | ||
2753 | // Disabled because it does not work | 2755 | // Disabled because it does not work |
2754 | //#if 0 | 2756 | //#if 0 |
2755 | case KMessageBox::Yes: // just this one | 2757 | case KMessageBox::Yes: // just this one |
2756 | //QDate qd = mNavigator->selectedDates().first(); | 2758 | //QDate qd = mNavigator->selectedDates().first(); |
2757 | //if (!qd.isValid()) { | 2759 | //if (!qd.isValid()) { |
2758 | // kdDebug() << "no date selected, or invalid date" << endl; | 2760 | // kdDebug() << "no date selected, or invalid date" << endl; |
2759 | // KNotifyClient::beep(); | 2761 | // KNotifyClient::beep(); |
2760 | // return; | 2762 | // return; |
2761 | //} | 2763 | //} |
2762 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); | 2764 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); |
2763 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { | 2765 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { |
2764 | anEvent->addExDate(itemDate); | 2766 | anEvent->addExDate(itemDate); |
2765 | int duration = anEvent->recurrence()->duration(); | 2767 | int duration = anEvent->recurrence()->duration(); |
2766 | if ( duration > 0 ) { | 2768 | if ( duration > 0 ) { |
2767 | anEvent->recurrence()->setDuration( duration - 1 ); | 2769 | anEvent->recurrence()->setDuration( duration - 1 ); |
2768 | } | 2770 | } |
2769 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); | 2771 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); |
2770 | } | 2772 | } |
2771 | break; | 2773 | break; |
2772 | //#endif | 2774 | //#endif |
2773 | } // switch | 2775 | } // switch |
2774 | } else { | 2776 | } else { |
2775 | if (KOPrefs::instance()->mConfirm) { | 2777 | if (KOPrefs::instance()->mConfirm) { |
2776 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2778 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2777 | i18n("\nAre you sure you want\nto delete this event?"), | 2779 | i18n("\nAre you sure you want\nto delete this event?"), |
2778 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { | 2780 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { |
2779 | case KMessageBox::Continue: // OK | 2781 | case KMessageBox::Continue: // OK |
2780 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2782 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2781 | schedule(Scheduler::Cancel,anEvent); | 2783 | schedule(Scheduler::Cancel,anEvent); |
2782 | checkExternalId( anEvent); | 2784 | checkExternalId( anEvent); |
2783 | mCalendar->deleteEvent(anEvent); | 2785 | mCalendar->deleteEvent(anEvent); |
2784 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2786 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2785 | break; | 2787 | break; |
2786 | } // switch | 2788 | } // switch |
2787 | } else { | 2789 | } else { |
2788 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2790 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2789 | schedule(Scheduler::Cancel,anEvent); | 2791 | schedule(Scheduler::Cancel,anEvent); |
2790 | checkExternalId( anEvent); | 2792 | checkExternalId( anEvent); |
2791 | mCalendar->deleteEvent(anEvent); | 2793 | mCalendar->deleteEvent(anEvent); |
2792 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2794 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2793 | } | 2795 | } |
2794 | } // if-else | 2796 | } // if-else |
2795 | emit updateSearchDialog(); | 2797 | emit updateSearchDialog(); |
2796 | } | 2798 | } |
2797 | 2799 | ||
2798 | bool CalendarView::deleteEvent(const QString &uid) | 2800 | bool CalendarView::deleteEvent(const QString &uid) |
2799 | { | 2801 | { |
2800 | Event *ev = mCalendar->event(uid); | 2802 | Event *ev = mCalendar->event(uid); |
2801 | if (ev) { | 2803 | if (ev) { |
2802 | deleteEvent(ev); | 2804 | deleteEvent(ev); |
2803 | return true; | 2805 | return true; |
2804 | } else { | 2806 | } else { |
2805 | return false; | 2807 | return false; |
2806 | } | 2808 | } |
2807 | } | 2809 | } |
2808 | 2810 | ||
2809 | /*****************************************************************************/ | 2811 | /*****************************************************************************/ |
2810 | 2812 | ||
2811 | void CalendarView::action_mail() | 2813 | void CalendarView::action_mail() |
2812 | { | 2814 | { |
2813 | #ifndef KORG_NOMAIL | 2815 | #ifndef KORG_NOMAIL |
2814 | KOMailClient mailClient; | 2816 | KOMailClient mailClient; |
2815 | 2817 | ||
2816 | Incidence *incidence = currentSelection(); | 2818 | Incidence *incidence = currentSelection(); |
2817 | 2819 | ||
2818 | if (!incidence) { | 2820 | if (!incidence) { |
2819 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2821 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2820 | return; | 2822 | return; |
2821 | } | 2823 | } |
2822 | if(incidence->attendeeCount() == 0 ) { | 2824 | if(incidence->attendeeCount() == 0 ) { |
2823 | KMessageBox::sorry(this, | 2825 | KMessageBox::sorry(this, |
2824 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2826 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2825 | return; | 2827 | return; |
2826 | } | 2828 | } |
2827 | 2829 | ||
2828 | CalendarLocal cal_tmp; | 2830 | CalendarLocal cal_tmp; |
2829 | Event *event = 0; | 2831 | Event *event = 0; |
2830 | Event *ev = 0; | 2832 | Event *ev = 0; |
2831 | if ( incidence && incidence->type() == "Event" ) { | 2833 | if ( incidence && incidence->type() == "Event" ) { |
2832 | event = static_cast<Event *>(incidence); | 2834 | event = static_cast<Event *>(incidence); |
2833 | ev = new Event(*event); | 2835 | ev = new Event(*event); |
2834 | cal_tmp.addEvent(ev); | 2836 | cal_tmp.addEvent(ev); |
2835 | } | 2837 | } |
2836 | ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); | 2838 | ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); |
2837 | QString attachment = mForm.toString( &cal_tmp ); | 2839 | QString attachment = mForm.toString( &cal_tmp ); |
2838 | if (ev) delete(ev); | 2840 | if (ev) delete(ev); |
2839 | 2841 | ||
2840 | mailClient.mailAttendees(currentSelection(), attachment); | 2842 | mailClient.mailAttendees(currentSelection(), attachment); |
2841 | 2843 | ||
2842 | #endif | 2844 | #endif |
2843 | 2845 | ||
2844 | #if 0 | 2846 | #if 0 |
2845 | Event *anEvent = 0; | 2847 | Event *anEvent = 0; |
2846 | if (mViewManager->currentView()->isEventView()) { | 2848 | if (mViewManager->currentView()->isEventView()) { |
2847 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); | 2849 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); |
2848 | } | 2850 | } |
2849 | 2851 | ||
2850 | if (!anEvent) { | 2852 | if (!anEvent) { |
2851 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2853 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2852 | return; | 2854 | return; |
2853 | } | 2855 | } |
2854 | if(anEvent->attendeeCount() == 0 ) { | 2856 | if(anEvent->attendeeCount() == 0 ) { |
2855 | KMessageBox::sorry(this, | 2857 | KMessageBox::sorry(this, |
2856 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2858 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2857 | return; | 2859 | return; |
2858 | } | 2860 | } |
2859 | 2861 | ||
2860 | mailobject.emailEvent(anEvent); | 2862 | mailobject.emailEvent(anEvent); |
2861 | #endif | 2863 | #endif |
2862 | } | 2864 | } |
2863 | 2865 | ||
2864 | 2866 | ||
2865 | void CalendarView::schedule_publish(Incidence *incidence) | 2867 | void CalendarView::schedule_publish(Incidence *incidence) |
2866 | { | 2868 | { |
2867 | Event *event = 0; | 2869 | Event *event = 0; |
2868 | Todo *todo = 0; | 2870 | Todo *todo = 0; |
2869 | 2871 | ||
2870 | if (incidence == 0) { | 2872 | if (incidence == 0) { |
2871 | incidence = mViewManager->currentView()->selectedIncidences().first(); | 2873 | incidence = mViewManager->currentView()->selectedIncidences().first(); |