author | zautrix <zautrix> | 2004-10-26 22:19:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-26 22:19:18 (UTC) |
commit | 6385f303bef3cbcd19d097a7b05c30e144d5dd6e (patch) (unidiff) | |
tree | 770795d94ea6ec1dc8bcaa67cc174a9c0add564a | |
parent | 13e996beddabc5e88f4f2fe49b2ce6cb8408eb30 (diff) | |
download | kdepimpi-6385f303bef3cbcd19d097a7b05c30e144d5dd6e.zip kdepimpi-6385f303bef3cbcd19d097a7b05c30e144d5dd6e.tar.gz kdepimpi-6385f303bef3cbcd19d097a7b05c30e144d5dd6e.tar.bz2 |
implemented remove sync info for kopi and kapi
-rw-r--r-- | kabc/addressbook.cpp | 8 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kabc/addressee.cpp | 5 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 4 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 1 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 23 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 5 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 42 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 1 |
11 files changed, 85 insertions, 7 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 3641c0c..2785131 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1211 +1,1219 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | 50 | #include <libkdepim/phoneaccess.h> |
51 | #include "addressbook.h" | 51 | #include "addressbook.h" |
52 | #include "resource.h" | 52 | #include "resource.h" |
53 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
54 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
55 | 55 | ||
56 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
61 | { | 61 | { |
62 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
63 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
64 | Field::List mAllFields; | 64 | Field::List mAllFields; |
65 | KConfig *mConfig; | 65 | KConfig *mConfig; |
66 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
67 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
71 | { | 71 | { |
72 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
76 | { | 76 | { |
77 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
81 | { | 81 | { |
82 | d = new IteratorData; | 82 | d = new IteratorData; |
83 | } | 83 | } |
84 | 84 | ||
85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
86 | { | 86 | { |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | } | 89 | } |
90 | 90 | ||
91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
92 | { | 92 | { |
93 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
94 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
95 | d = new IteratorData; | 95 | d = new IteratorData; |
96 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
97 | return *this; | 97 | return *this; |
98 | } | 98 | } |
99 | 99 | ||
100 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
101 | { | 101 | { |
102 | delete d; | 102 | delete d; |
103 | } | 103 | } |
104 | 104 | ||
105 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
106 | { | 106 | { |
107 | return *(d->mIt); | 107 | return *(d->mIt); |
108 | } | 108 | } |
109 | 109 | ||
110 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
111 | { | 111 | { |
112 | return *(d->mIt); | 112 | return *(d->mIt); |
113 | } | 113 | } |
114 | 114 | ||
115 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
116 | { | 116 | { |
117 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
118 | } | 118 | } |
119 | 119 | ||
120 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
121 | { | 121 | { |
122 | (d->mIt)++; | 122 | (d->mIt)++; |
123 | return *this; | 123 | return *this; |
124 | } | 124 | } |
125 | 125 | ||
126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
127 | { | 127 | { |
128 | (d->mIt)++; | 128 | (d->mIt)++; |
129 | return *this; | 129 | return *this; |
130 | } | 130 | } |
131 | 131 | ||
132 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
133 | { | 133 | { |
134 | (d->mIt)--; | 134 | (d->mIt)--; |
135 | return *this; | 135 | return *this; |
136 | } | 136 | } |
137 | 137 | ||
138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
139 | { | 139 | { |
140 | (d->mIt)--; | 140 | (d->mIt)--; |
141 | return *this; | 141 | return *this; |
142 | } | 142 | } |
143 | 143 | ||
144 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
145 | { | 145 | { |
146 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
147 | } | 147 | } |
148 | 148 | ||
149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
150 | { | 150 | { |
151 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
156 | { | 156 | { |
157 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
158 | } | 158 | } |
159 | 159 | ||
160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
161 | { | 161 | { |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | } | 164 | } |
165 | 165 | ||
166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
167 | { | 167 | { |
168 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
169 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
170 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
171 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami ); | 280 | d->mManager = new KRES::Manager<Resource>( fami ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
396 | if ( !(*it).IDStr().isEmpty() ) { | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
398 | } | 398 | } |
399 | KABC::VCardConverter converter; | 399 | KABC::VCardConverter converter; |
400 | QString vcard; | 400 | QString vcard; |
401 | //Resource *resource() const; | 401 | //Resource *resource() const; |
402 | converter.addresseeToVCard( *it, vcard, version ); | 402 | converter.addresseeToVCard( *it, vcard, version ); |
403 | t << vcard << "\r\n"; | 403 | t << vcard << "\r\n"; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
407 | outFile.close(); | 407 | outFile.close(); |
408 | } | 408 | } |
409 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
411 | { | 411 | { |
412 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
413 | QString datastream; | 413 | QString datastream; |
414 | Iterator it; | 414 | Iterator it; |
415 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
416 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
418 | if ( ! all ) { | 418 | if ( ! all ) { |
419 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
423 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
424 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 425 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
426 | continue; | 426 | continue; |
427 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
428 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
429 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
430 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
431 | 431 | ||
432 | QString vcard; | 432 | QString vcard; |
433 | QString vcardnew; | 433 | QString vcardnew; |
434 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
435 | int start = 0; | 435 | int start = 0; |
436 | int next; | 436 | int next; |
437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
438 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
439 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
440 | int sep; | 440 | int sep; |
441 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
442 | sep = semi ; | 442 | sep = semi ; |
443 | else | 443 | else |
444 | sep = dopp; | 444 | sep = dopp; |
445 | vcardnew +=vcard.mid( start, next - start); | 445 | vcardnew +=vcard.mid( start, next - start); |
446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
447 | start = sep; | 447 | start = sep; |
448 | } | 448 | } |
449 | vcardnew += vcard.mid( start,vcard.length() ); | 449 | vcardnew += vcard.mid( start,vcard.length() ); |
450 | vcard = ""; | 450 | vcard = ""; |
451 | start = 0; | 451 | start = 0; |
452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
453 | int sep = vcardnew.find(":", next); | 453 | int sep = vcardnew.find(":", next); |
454 | vcard +=vcardnew.mid( start, next - start+3); | 454 | vcard +=vcardnew.mid( start, next - start+3); |
455 | start = sep; | 455 | start = sep; |
456 | } | 456 | } |
457 | vcard += vcardnew.mid( start,vcardnew.length() ); | 457 | vcard += vcardnew.mid( start,vcardnew.length() ); |
458 | vcard.replace ( QRegExp(";;;") , "" ); | 458 | vcard.replace ( QRegExp(";;;") , "" ); |
459 | vcard.replace ( QRegExp(";;") , "" ); | 459 | vcard.replace ( QRegExp(";;") , "" ); |
460 | datastream += vcard; | 460 | datastream += vcard; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | QFile outFile(fileName); | 464 | QFile outFile(fileName); |
465 | if ( outFile.open(IO_WriteOnly) ) { | 465 | if ( outFile.open(IO_WriteOnly) ) { |
466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
467 | QTextStream t( &outFile ); // use a text stream | 467 | QTextStream t( &outFile ); // use a text stream |
468 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | t <<datastream; | 469 | t <<datastream; |
470 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
471 | outFile.close(); | 471 | outFile.close(); |
472 | 472 | ||
473 | } else { | 473 | } else { |
474 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
475 | return false; | 475 | return false; |
476 | } | 476 | } |
477 | return true; | 477 | return true; |
478 | 478 | ||
479 | } | 479 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
481 | { | 481 | { |
482 | 482 | ||
483 | if ( removeOld ) | 483 | if ( removeOld ) |
484 | setUntagged( true ); | 484 | setUntagged( true ); |
485 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
486 | QFile file( fileName ); | 486 | QFile file( fileName ); |
487 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
488 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
489 | file.close(); | 489 | file.close(); |
490 | QString data; | 490 | QString data; |
491 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | 513 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | ||
557 | { | ||
558 | Iterator ait; | ||
559 | for ( ait = begin(); ait != end(); ++ait ) { | ||
560 | (*ait).removeID( syncProfile ); | ||
561 | } | ||
562 | |||
563 | } | ||
556 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 564 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
557 | { | 565 | { |
558 | Iterator ait; | 566 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 567 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | QString id = (*ait).IDStr(); | 568 | QString id = (*ait).IDStr(); |
561 | (*ait).setIDStr( ":"); | 569 | (*ait).setIDStr( ":"); |
562 | (*ait).setExternalUID( id ); | 570 | (*ait).setExternalUID( id ); |
563 | (*ait).setOriginalExternalUID( id ); | 571 | (*ait).setOriginalExternalUID( id ); |
564 | if ( isPreSync ) | 572 | if ( isPreSync ) |
565 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 573 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
566 | else { | 574 | else { |
567 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 575 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
568 | (*ait).setID( currentSyncDevice,id ); | 576 | (*ait).setID( currentSyncDevice,id ); |
569 | 577 | ||
570 | } | 578 | } |
571 | } | 579 | } |
572 | } | 580 | } |
573 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 581 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
574 | { | 582 | { |
575 | 583 | ||
576 | setUntagged(); | 584 | setUntagged(); |
577 | KABC::Addressee::List list; | 585 | KABC::Addressee::List list; |
578 | QFile file( fileName ); | 586 | QFile file( fileName ); |
579 | file.open( IO_ReadOnly ); | 587 | file.open( IO_ReadOnly ); |
580 | QByteArray rawData = file.readAll(); | 588 | QByteArray rawData = file.readAll(); |
581 | file.close(); | 589 | file.close(); |
582 | QString data; | 590 | QString data; |
583 | 591 | ||
584 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 592 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
585 | KABC::VCardTool tool; | 593 | KABC::VCardTool tool; |
586 | list = tool.parseVCards( data ); | 594 | list = tool.parseVCards( data ); |
587 | KABC::Addressee::List::Iterator it; | 595 | KABC::Addressee::List::Iterator it; |
588 | for ( it = list.begin(); it != list.end(); ++it ) { | 596 | for ( it = list.begin(); it != list.end(); ++it ) { |
589 | Iterator ait; | 597 | Iterator ait; |
590 | for ( ait = begin(); ait != end(); ++ait ) { | 598 | for ( ait = begin(); ait != end(); ++ait ) { |
591 | if ( !(*ait).tagged() ) { | 599 | if ( !(*ait).tagged() ) { |
592 | if ( (*ait).containsAdr(*it)) { | 600 | if ( (*ait).containsAdr(*it)) { |
593 | (*ait).setTagged(true); | 601 | (*ait).setTagged(true); |
594 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 602 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
595 | (*it).setIDStr( ":"); | 603 | (*it).setIDStr( ":"); |
596 | (*it).setID( currentSyncDevice,id ); | 604 | (*it).setID( currentSyncDevice,id ); |
597 | (*it).setExternalUID( id ); | 605 | (*it).setExternalUID( id ); |
598 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 606 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
599 | (*it).setUid( ( (*ait).uid() )); | 607 | (*it).setUid( ( (*ait).uid() )); |
600 | break; | 608 | break; |
601 | } | 609 | } |
602 | } | 610 | } |
603 | 611 | ||
604 | } | 612 | } |
605 | if ( ait == end() ) | 613 | if ( ait == end() ) |
606 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 614 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
607 | } | 615 | } |
608 | clear(); | 616 | clear(); |
609 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
610 | insertAddressee( (*it) ); | 618 | insertAddressee( (*it) ); |
611 | } | 619 | } |
612 | } | 620 | } |
613 | 621 | ||
614 | bool AddressBook::saveABphone( QString fileName ) | 622 | bool AddressBook::saveABphone( QString fileName ) |
615 | { | 623 | { |
616 | //smplifyAddressees(); | 624 | //smplifyAddressees(); |
617 | qDebug("saveABphone:: saving AB... "); | 625 | qDebug("saveABphone:: saving AB... "); |
618 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 626 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
619 | return false; | 627 | return false; |
620 | qDebug("saveABphone:: writing to phone... "); | 628 | qDebug("saveABphone:: writing to phone... "); |
621 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 629 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
622 | return false; | 630 | return false; |
623 | } | 631 | } |
624 | qDebug("saveABphone:: re-reading from phone... "); | 632 | qDebug("saveABphone:: re-reading from phone... "); |
625 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 633 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
626 | return false; | 634 | return false; |
627 | } | 635 | } |
628 | return true; | 636 | return true; |
629 | } | 637 | } |
630 | bool AddressBook::saveAB() | 638 | bool AddressBook::saveAB() |
631 | { | 639 | { |
632 | bool ok = true; | 640 | bool ok = true; |
633 | 641 | ||
634 | deleteRemovedAddressees(); | 642 | deleteRemovedAddressees(); |
635 | Iterator ait; | 643 | Iterator ait; |
636 | for ( ait = begin(); ait != end(); ++ait ) { | 644 | for ( ait = begin(); ait != end(); ++ait ) { |
637 | if ( !(*ait).IDStr().isEmpty() ) { | 645 | if ( !(*ait).IDStr().isEmpty() ) { |
638 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 646 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
639 | } | 647 | } |
640 | } | 648 | } |
641 | KRES::Manager<Resource>::ActiveIterator it; | 649 | KRES::Manager<Resource>::ActiveIterator it; |
642 | KRES::Manager<Resource> *manager = d->mManager; | 650 | KRES::Manager<Resource> *manager = d->mManager; |
643 | qDebug("SaveAB::saving..." ); | 651 | qDebug("SaveAB::saving..." ); |
644 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 652 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
645 | qDebug("SaveAB::checking resource..." ); | 653 | qDebug("SaveAB::checking resource..." ); |
646 | if ( (*it)->readOnly() ) | 654 | if ( (*it)->readOnly() ) |
647 | qDebug("resource is readonly." ); | 655 | qDebug("resource is readonly." ); |
648 | if ( (*it)->isOpen() ) | 656 | if ( (*it)->isOpen() ) |
649 | qDebug("resource is open" ); | 657 | qDebug("resource is open" ); |
650 | 658 | ||
651 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 659 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
652 | Ticket *ticket = requestSaveTicket( *it ); | 660 | Ticket *ticket = requestSaveTicket( *it ); |
653 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 661 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
654 | if ( !ticket ) { | 662 | if ( !ticket ) { |
655 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 663 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
656 | .arg( (*it)->resourceName() ) ); | 664 | .arg( (*it)->resourceName() ) ); |
657 | return false; | 665 | return false; |
658 | } | 666 | } |
659 | 667 | ||
660 | //if ( !save( ticket ) ) | 668 | //if ( !save( ticket ) ) |
661 | if ( ticket->resource() ) { | 669 | if ( ticket->resource() ) { |
662 | QString name = ticket->resource()->resourceName(); | 670 | QString name = ticket->resource()->resourceName(); |
663 | if ( ! ticket->resource()->save( ticket ) ) | 671 | if ( ! ticket->resource()->save( ticket ) ) |
664 | ok = false; | 672 | ok = false; |
665 | else | 673 | else |
666 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 674 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
667 | 675 | ||
668 | } else | 676 | } else |
669 | ok = false; | 677 | ok = false; |
670 | 678 | ||
671 | } | 679 | } |
672 | } | 680 | } |
673 | return ok; | 681 | return ok; |
674 | } | 682 | } |
675 | 683 | ||
676 | AddressBook::Iterator AddressBook::begin() | 684 | AddressBook::Iterator AddressBook::begin() |
677 | { | 685 | { |
678 | Iterator it = Iterator(); | 686 | Iterator it = Iterator(); |
679 | it.d->mIt = d->mAddressees.begin(); | 687 | it.d->mIt = d->mAddressees.begin(); |
680 | return it; | 688 | return it; |
681 | } | 689 | } |
682 | 690 | ||
683 | AddressBook::ConstIterator AddressBook::begin() const | 691 | AddressBook::ConstIterator AddressBook::begin() const |
684 | { | 692 | { |
685 | ConstIterator it = ConstIterator(); | 693 | ConstIterator it = ConstIterator(); |
686 | it.d->mIt = d->mAddressees.begin(); | 694 | it.d->mIt = d->mAddressees.begin(); |
687 | return it; | 695 | return it; |
688 | } | 696 | } |
689 | 697 | ||
690 | AddressBook::Iterator AddressBook::end() | 698 | AddressBook::Iterator AddressBook::end() |
691 | { | 699 | { |
692 | Iterator it = Iterator(); | 700 | Iterator it = Iterator(); |
693 | it.d->mIt = d->mAddressees.end(); | 701 | it.d->mIt = d->mAddressees.end(); |
694 | return it; | 702 | return it; |
695 | } | 703 | } |
696 | 704 | ||
697 | AddressBook::ConstIterator AddressBook::end() const | 705 | AddressBook::ConstIterator AddressBook::end() const |
698 | { | 706 | { |
699 | ConstIterator it = ConstIterator(); | 707 | ConstIterator it = ConstIterator(); |
700 | it.d->mIt = d->mAddressees.end(); | 708 | it.d->mIt = d->mAddressees.end(); |
701 | return it; | 709 | return it; |
702 | } | 710 | } |
703 | 711 | ||
704 | void AddressBook::clear() | 712 | void AddressBook::clear() |
705 | { | 713 | { |
706 | d->mAddressees.clear(); | 714 | d->mAddressees.clear(); |
707 | } | 715 | } |
708 | 716 | ||
709 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 717 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
710 | { | 718 | { |
711 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 719 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
712 | 720 | ||
713 | if ( !resource ) | 721 | if ( !resource ) |
714 | { | 722 | { |
715 | qDebug("AddressBook::requestSaveTicket no resource" ); | 723 | qDebug("AddressBook::requestSaveTicket no resource" ); |
716 | resource = standardResource(); | 724 | resource = standardResource(); |
717 | } | 725 | } |
718 | 726 | ||
719 | KRES::Manager<Resource>::ActiveIterator it; | 727 | KRES::Manager<Resource>::ActiveIterator it; |
720 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 728 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
721 | if ( (*it) == resource ) { | 729 | if ( (*it) == resource ) { |
722 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 730 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
723 | return 0; | 731 | return 0; |
724 | else | 732 | else |
725 | return (*it)->requestSaveTicket(); | 733 | return (*it)->requestSaveTicket(); |
726 | } | 734 | } |
727 | } | 735 | } |
728 | 736 | ||
729 | return 0; | 737 | return 0; |
730 | } | 738 | } |
731 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 739 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
732 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 740 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
733 | { | 741 | { |
734 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 742 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
735 | //qDebug("block insert "); | 743 | //qDebug("block insert "); |
736 | return; | 744 | return; |
737 | } | 745 | } |
738 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 746 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
739 | bool found = false; | 747 | bool found = false; |
740 | Addressee::List::Iterator it; | 748 | Addressee::List::Iterator it; |
741 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 749 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
742 | if ( a.uid() == (*it).uid() ) { | 750 | if ( a.uid() == (*it).uid() ) { |
743 | 751 | ||
744 | bool changed = false; | 752 | bool changed = false; |
745 | Addressee addr = a; | 753 | Addressee addr = a; |
746 | if ( addr != (*it) ) | 754 | if ( addr != (*it) ) |
747 | changed = true; | 755 | changed = true; |
748 | 756 | ||
749 | if ( takeResource ) { | 757 | if ( takeResource ) { |
750 | Resource * res = (*it).resource(); | 758 | Resource * res = (*it).resource(); |
751 | (*it) = a; | 759 | (*it) = a; |
752 | (*it).setResource( res ); | 760 | (*it).setResource( res ); |
753 | } else { | 761 | } else { |
754 | (*it) = a; | 762 | (*it) = a; |
755 | if ( (*it).resource() == 0 ) | 763 | if ( (*it).resource() == 0 ) |
756 | (*it).setResource( standardResource() ); | 764 | (*it).setResource( standardResource() ); |
757 | } | 765 | } |
758 | if ( changed ) { | 766 | if ( changed ) { |
759 | if ( setRev ) { | 767 | if ( setRev ) { |
760 | 768 | ||
761 | // get rid of micro seconds | 769 | // get rid of micro seconds |
762 | QDateTime dt = QDateTime::currentDateTime(); | 770 | QDateTime dt = QDateTime::currentDateTime(); |
763 | QTime t = dt.time(); | 771 | QTime t = dt.time(); |
764 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 772 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
765 | (*it).setRevision( dt ); | 773 | (*it).setRevision( dt ); |
766 | } | 774 | } |
767 | (*it).setChanged( true ); | 775 | (*it).setChanged( true ); |
768 | } | 776 | } |
769 | 777 | ||
770 | found = true; | 778 | found = true; |
771 | } else { | 779 | } else { |
772 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 780 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
773 | QString name = (*it).uid().mid( 19 ); | 781 | QString name = (*it).uid().mid( 19 ); |
774 | Addressee b = a; | 782 | Addressee b = a; |
775 | QString id = b.getID( name ); | 783 | QString id = b.getID( name ); |
776 | if ( ! id.isEmpty() ) { | 784 | if ( ! id.isEmpty() ) { |
777 | QString des = (*it).note(); | 785 | QString des = (*it).note(); |
778 | int startN; | 786 | int startN; |
779 | if( (startN = des.find( id ) ) >= 0 ) { | 787 | if( (startN = des.find( id ) ) >= 0 ) { |
780 | int endN = des.find( ",", startN+1 ); | 788 | int endN = des.find( ",", startN+1 ); |
781 | des = des.left( startN ) + des.mid( endN+1 ); | 789 | des = des.left( startN ) + des.mid( endN+1 ); |
782 | (*it).setNote( des ); | 790 | (*it).setNote( des ); |
783 | } | 791 | } |
784 | } | 792 | } |
785 | } | 793 | } |
786 | } | 794 | } |
787 | } | 795 | } |
788 | if ( found ) | 796 | if ( found ) |
789 | return; | 797 | return; |
790 | d->mAddressees.append( a ); | 798 | d->mAddressees.append( a ); |
791 | Addressee& addr = d->mAddressees.last(); | 799 | Addressee& addr = d->mAddressees.last(); |
792 | if ( addr.resource() == 0 ) | 800 | if ( addr.resource() == 0 ) |
793 | addr.setResource( standardResource() ); | 801 | addr.setResource( standardResource() ); |
794 | 802 | ||
795 | addr.setChanged( true ); | 803 | addr.setChanged( true ); |
796 | } | 804 | } |
797 | 805 | ||
798 | void AddressBook::removeAddressee( const Addressee &a ) | 806 | void AddressBook::removeAddressee( const Addressee &a ) |
799 | { | 807 | { |
800 | Iterator it; | 808 | Iterator it; |
801 | Iterator it2; | 809 | Iterator it2; |
802 | bool found = false; | 810 | bool found = false; |
803 | for ( it = begin(); it != end(); ++it ) { | 811 | for ( it = begin(); it != end(); ++it ) { |
804 | if ( a.uid() == (*it).uid() ) { | 812 | if ( a.uid() == (*it).uid() ) { |
805 | found = true; | 813 | found = true; |
806 | it2 = it; | 814 | it2 = it; |
807 | } else { | 815 | } else { |
808 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 816 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
809 | QString name = (*it).uid().mid( 19 ); | 817 | QString name = (*it).uid().mid( 19 ); |
810 | Addressee b = a; | 818 | Addressee b = a; |
811 | QString id = b.getID( name ); | 819 | QString id = b.getID( name ); |
812 | if ( ! id.isEmpty() ) { | 820 | if ( ! id.isEmpty() ) { |
813 | QString des = (*it).note(); | 821 | QString des = (*it).note(); |
814 | if( des.find( id ) < 0 ) { | 822 | if( des.find( id ) < 0 ) { |
815 | des += id + ","; | 823 | des += id + ","; |
816 | (*it).setNote( des ); | 824 | (*it).setNote( des ); |
817 | } | 825 | } |
818 | } | 826 | } |
819 | } | 827 | } |
820 | 828 | ||
821 | } | 829 | } |
822 | } | 830 | } |
823 | 831 | ||
824 | if ( found ) | 832 | if ( found ) |
825 | removeAddressee( it2 ); | 833 | removeAddressee( it2 ); |
826 | 834 | ||
827 | } | 835 | } |
828 | 836 | ||
829 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 837 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
830 | { | 838 | { |
831 | Iterator it = begin(); | 839 | Iterator it = begin(); |
832 | Iterator it2 ; | 840 | Iterator it2 ; |
833 | QDateTime dt ( QDate( 2004,1,1) ); | 841 | QDateTime dt ( QDate( 2004,1,1) ); |
834 | while ( it != end() ) { | 842 | while ( it != end() ) { |
835 | (*it).setRevision( dt ); | 843 | (*it).setRevision( dt ); |
836 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 844 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
837 | (*it).setIDStr(""); | 845 | (*it).setIDStr(""); |
838 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 846 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
839 | it2 = it; | 847 | it2 = it; |
840 | //qDebug("removing %s ",(*it).uid().latin1() ); | 848 | //qDebug("removing %s ",(*it).uid().latin1() ); |
841 | ++it; | 849 | ++it; |
842 | removeAddressee( it2 ); | 850 | removeAddressee( it2 ); |
843 | } else { | 851 | } else { |
844 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 852 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
845 | ++it; | 853 | ++it; |
846 | } | 854 | } |
847 | } | 855 | } |
848 | deleteRemovedAddressees(); | 856 | deleteRemovedAddressees(); |
849 | } | 857 | } |
850 | 858 | ||
851 | void AddressBook::removeAddressee( const Iterator &it ) | 859 | void AddressBook::removeAddressee( const Iterator &it ) |
852 | { | 860 | { |
853 | d->mRemovedAddressees.append( (*it) ); | 861 | d->mRemovedAddressees.append( (*it) ); |
854 | d->mAddressees.remove( it.d->mIt ); | 862 | d->mAddressees.remove( it.d->mIt ); |
855 | } | 863 | } |
856 | 864 | ||
857 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 865 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
858 | { | 866 | { |
859 | Iterator it; | 867 | Iterator it; |
860 | for ( it = begin(); it != end(); ++it ) { | 868 | for ( it = begin(); it != end(); ++it ) { |
861 | if ( a.uid() == (*it).uid() ) { | 869 | if ( a.uid() == (*it).uid() ) { |
862 | return it; | 870 | return it; |
863 | } | 871 | } |
864 | } | 872 | } |
865 | return end(); | 873 | return end(); |
866 | } | 874 | } |
867 | 875 | ||
868 | Addressee AddressBook::findByUid( const QString &uid ) | 876 | Addressee AddressBook::findByUid( const QString &uid ) |
869 | { | 877 | { |
870 | Iterator it; | 878 | Iterator it; |
871 | for ( it = begin(); it != end(); ++it ) { | 879 | for ( it = begin(); it != end(); ++it ) { |
872 | if ( uid == (*it).uid() ) { | 880 | if ( uid == (*it).uid() ) { |
873 | return *it; | 881 | return *it; |
874 | } | 882 | } |
875 | } | 883 | } |
876 | return Addressee(); | 884 | return Addressee(); |
877 | } | 885 | } |
878 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 886 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
879 | { | 887 | { |
880 | //qDebug("AddressBook::preExternSync "); | 888 | //qDebug("AddressBook::preExternSync "); |
881 | AddressBook::Iterator it; | 889 | AddressBook::Iterator it; |
882 | for ( it = begin(); it != end(); ++it ) { | 890 | for ( it = begin(); it != end(); ++it ) { |
883 | (*it).setID( csd, (*it).externalUID() ); | 891 | (*it).setID( csd, (*it).externalUID() ); |
884 | (*it).computeCsum( csd ); | 892 | (*it).computeCsum( csd ); |
885 | } | 893 | } |
886 | mergeAB( aBook ,csd, isSubset ); | 894 | mergeAB( aBook ,csd, isSubset ); |
887 | } | 895 | } |
888 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 896 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
889 | { | 897 | { |
890 | //qDebug("AddressBook::postExternSync "); | 898 | //qDebug("AddressBook::postExternSync "); |
891 | AddressBook::Iterator it; | 899 | AddressBook::Iterator it; |
892 | for ( it = begin(); it != end(); ++it ) { | 900 | for ( it = begin(); it != end(); ++it ) { |
893 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 901 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
894 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 902 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
895 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 903 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
896 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 904 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
897 | if ( ad.isEmpty() ) { | 905 | if ( ad.isEmpty() ) { |
898 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 906 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
899 | } else { | 907 | } else { |
900 | (*it).computeCsum( csd ); | 908 | (*it).computeCsum( csd ); |
901 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 909 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
902 | ad.setID( csd, (*it).externalUID() ); | 910 | ad.setID( csd, (*it).externalUID() ); |
903 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 911 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
904 | aBook->insertAddressee( ad ); | 912 | aBook->insertAddressee( ad ); |
905 | } | 913 | } |
906 | } | 914 | } |
907 | } | 915 | } |
908 | } | 916 | } |
909 | 917 | ||
910 | bool AddressBook::containsExternalUid( const QString& uid ) | 918 | bool AddressBook::containsExternalUid( const QString& uid ) |
911 | { | 919 | { |
912 | Iterator it; | 920 | Iterator it; |
913 | for ( it = begin(); it != end(); ++it ) { | 921 | for ( it = begin(); it != end(); ++it ) { |
914 | if ( uid == (*it).externalUID( ) ) | 922 | if ( uid == (*it).externalUID( ) ) |
915 | return true; | 923 | return true; |
916 | } | 924 | } |
917 | return false; | 925 | return false; |
918 | } | 926 | } |
919 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 927 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
920 | { | 928 | { |
921 | Iterator it; | 929 | Iterator it; |
922 | for ( it = begin(); it != end(); ++it ) { | 930 | for ( it = begin(); it != end(); ++it ) { |
923 | if ( uid == (*it).getID( profile ) ) | 931 | if ( uid == (*it).getID( profile ) ) |
924 | return (*it); | 932 | return (*it); |
925 | } | 933 | } |
926 | return Addressee(); | 934 | return Addressee(); |
927 | } | 935 | } |
928 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 936 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
929 | { | 937 | { |
930 | Iterator it; | 938 | Iterator it; |
931 | Addressee ad; | 939 | Addressee ad; |
932 | for ( it = begin(); it != end(); ++it ) { | 940 | for ( it = begin(); it != end(); ++it ) { |
933 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 941 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
934 | if ( !ad.isEmpty() ) { | 942 | if ( !ad.isEmpty() ) { |
935 | (*it).mergeContact( ad ,isSubset); | 943 | (*it).mergeContact( ad ,isSubset); |
936 | } | 944 | } |
937 | } | 945 | } |
938 | #if 0 | 946 | #if 0 |
939 | // test only | 947 | // test only |
940 | for ( it = begin(); it != end(); ++it ) { | 948 | for ( it = begin(); it != end(); ++it ) { |
941 | 949 | ||
942 | qDebug("uid %s ", (*it).uid().latin1()); | 950 | qDebug("uid %s ", (*it).uid().latin1()); |
943 | } | 951 | } |
944 | #endif | 952 | #endif |
945 | } | 953 | } |
946 | 954 | ||
947 | #if 0 | 955 | #if 0 |
948 | Addressee::List AddressBook::getExternLastSyncAddressees() | 956 | Addressee::List AddressBook::getExternLastSyncAddressees() |
949 | { | 957 | { |
950 | Addressee::List results; | 958 | Addressee::List results; |
951 | 959 | ||
952 | Iterator it; | 960 | Iterator it; |
953 | for ( it = begin(); it != end(); ++it ) { | 961 | for ( it = begin(); it != end(); ++it ) { |
954 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 962 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
955 | if ( (*it).familyName().left(4) == "!E: " ) | 963 | if ( (*it).familyName().left(4) == "!E: " ) |
956 | results.append( *it ); | 964 | results.append( *it ); |
957 | } | 965 | } |
958 | } | 966 | } |
959 | 967 | ||
960 | return results; | 968 | return results; |
961 | } | 969 | } |
962 | #endif | 970 | #endif |
963 | void AddressBook::resetTempSyncStat() | 971 | void AddressBook::resetTempSyncStat() |
964 | { | 972 | { |
965 | Iterator it; | 973 | Iterator it; |
966 | for ( it = begin(); it != end(); ++it ) { | 974 | for ( it = begin(); it != end(); ++it ) { |
967 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 975 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
968 | } | 976 | } |
969 | 977 | ||
970 | } | 978 | } |
971 | 979 | ||
972 | QStringList AddressBook:: uidList() | 980 | QStringList AddressBook:: uidList() |
973 | { | 981 | { |
974 | QStringList results; | 982 | QStringList results; |
975 | Iterator it; | 983 | Iterator it; |
976 | for ( it = begin(); it != end(); ++it ) { | 984 | for ( it = begin(); it != end(); ++it ) { |
977 | results.append( (*it).uid() ); | 985 | results.append( (*it).uid() ); |
978 | } | 986 | } |
979 | return results; | 987 | return results; |
980 | } | 988 | } |
981 | 989 | ||
982 | 990 | ||
983 | Addressee::List AddressBook::allAddressees() | 991 | Addressee::List AddressBook::allAddressees() |
984 | { | 992 | { |
985 | return d->mAddressees; | 993 | return d->mAddressees; |
986 | 994 | ||
987 | } | 995 | } |
988 | 996 | ||
989 | Addressee::List AddressBook::findByName( const QString &name ) | 997 | Addressee::List AddressBook::findByName( const QString &name ) |
990 | { | 998 | { |
991 | Addressee::List results; | 999 | Addressee::List results; |
992 | 1000 | ||
993 | Iterator it; | 1001 | Iterator it; |
994 | for ( it = begin(); it != end(); ++it ) { | 1002 | for ( it = begin(); it != end(); ++it ) { |
995 | if ( name == (*it).realName() ) { | 1003 | if ( name == (*it).realName() ) { |
996 | results.append( *it ); | 1004 | results.append( *it ); |
997 | } | 1005 | } |
998 | } | 1006 | } |
999 | 1007 | ||
1000 | return results; | 1008 | return results; |
1001 | } | 1009 | } |
1002 | 1010 | ||
1003 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1011 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1004 | { | 1012 | { |
1005 | Addressee::List results; | 1013 | Addressee::List results; |
1006 | QStringList mailList; | 1014 | QStringList mailList; |
1007 | 1015 | ||
1008 | Iterator it; | 1016 | Iterator it; |
1009 | for ( it = begin(); it != end(); ++it ) { | 1017 | for ( it = begin(); it != end(); ++it ) { |
1010 | mailList = (*it).emails(); | 1018 | mailList = (*it).emails(); |
1011 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1019 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1012 | if ( email == (*ite) ) { | 1020 | if ( email == (*ite) ) { |
1013 | results.append( *it ); | 1021 | results.append( *it ); |
1014 | } | 1022 | } |
1015 | } | 1023 | } |
1016 | } | 1024 | } |
1017 | 1025 | ||
1018 | return results; | 1026 | return results; |
1019 | } | 1027 | } |
1020 | 1028 | ||
1021 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1029 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1022 | { | 1030 | { |
1023 | Addressee::List results; | 1031 | Addressee::List results; |
1024 | 1032 | ||
1025 | Iterator it; | 1033 | Iterator it; |
1026 | for ( it = begin(); it != end(); ++it ) { | 1034 | for ( it = begin(); it != end(); ++it ) { |
1027 | if ( (*it).hasCategory( category) ) { | 1035 | if ( (*it).hasCategory( category) ) { |
1028 | results.append( *it ); | 1036 | results.append( *it ); |
1029 | } | 1037 | } |
1030 | } | 1038 | } |
1031 | 1039 | ||
1032 | return results; | 1040 | return results; |
1033 | } | 1041 | } |
1034 | 1042 | ||
1035 | void AddressBook::dump() const | 1043 | void AddressBook::dump() const |
1036 | { | 1044 | { |
1037 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1045 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1038 | 1046 | ||
1039 | ConstIterator it; | 1047 | ConstIterator it; |
1040 | for( it = begin(); it != end(); ++it ) { | 1048 | for( it = begin(); it != end(); ++it ) { |
1041 | (*it).dump(); | 1049 | (*it).dump(); |
1042 | } | 1050 | } |
1043 | 1051 | ||
1044 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1052 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1045 | } | 1053 | } |
1046 | 1054 | ||
1047 | QString AddressBook::identifier() | 1055 | QString AddressBook::identifier() |
1048 | { | 1056 | { |
1049 | QStringList identifier; | 1057 | QStringList identifier; |
1050 | 1058 | ||
1051 | 1059 | ||
1052 | KRES::Manager<Resource>::ActiveIterator it; | 1060 | KRES::Manager<Resource>::ActiveIterator it; |
1053 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1061 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1054 | if ( !(*it)->identifier().isEmpty() ) | 1062 | if ( !(*it)->identifier().isEmpty() ) |
1055 | identifier.append( (*it)->identifier() ); | 1063 | identifier.append( (*it)->identifier() ); |
1056 | } | 1064 | } |
1057 | 1065 | ||
1058 | return identifier.join( ":" ); | 1066 | return identifier.join( ":" ); |
1059 | } | 1067 | } |
1060 | 1068 | ||
1061 | Field::List AddressBook::fields( int category ) | 1069 | Field::List AddressBook::fields( int category ) |
1062 | { | 1070 | { |
1063 | if ( d->mAllFields.isEmpty() ) { | 1071 | if ( d->mAllFields.isEmpty() ) { |
1064 | d->mAllFields = Field::allFields(); | 1072 | d->mAllFields = Field::allFields(); |
1065 | } | 1073 | } |
1066 | 1074 | ||
1067 | if ( category == Field::All ) return d->mAllFields; | 1075 | if ( category == Field::All ) return d->mAllFields; |
1068 | 1076 | ||
1069 | Field::List result; | 1077 | Field::List result; |
1070 | Field::List::ConstIterator it; | 1078 | Field::List::ConstIterator it; |
1071 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1079 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1072 | if ( (*it)->category() & category ) result.append( *it ); | 1080 | if ( (*it)->category() & category ) result.append( *it ); |
1073 | } | 1081 | } |
1074 | 1082 | ||
1075 | return result; | 1083 | return result; |
1076 | } | 1084 | } |
1077 | 1085 | ||
1078 | bool AddressBook::addCustomField( const QString &label, int category, | 1086 | bool AddressBook::addCustomField( const QString &label, int category, |
1079 | const QString &key, const QString &app ) | 1087 | const QString &key, const QString &app ) |
1080 | { | 1088 | { |
1081 | if ( d->mAllFields.isEmpty() ) { | 1089 | if ( d->mAllFields.isEmpty() ) { |
1082 | d->mAllFields = Field::allFields(); | 1090 | d->mAllFields = Field::allFields(); |
1083 | } | 1091 | } |
1084 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1092 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1085 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1093 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1086 | 1094 | ||
1087 | QString k = key.isNull() ? label : key; | 1095 | QString k = key.isNull() ? label : key; |
1088 | 1096 | ||
1089 | Field *field = Field::createCustomField( label, category, k, a ); | 1097 | Field *field = Field::createCustomField( label, category, k, a ); |
1090 | 1098 | ||
1091 | if ( !field ) return false; | 1099 | if ( !field ) return false; |
1092 | 1100 | ||
1093 | d->mAllFields.append( field ); | 1101 | d->mAllFields.append( field ); |
1094 | 1102 | ||
1095 | return true; | 1103 | return true; |
1096 | } | 1104 | } |
1097 | 1105 | ||
1098 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1106 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1099 | { | 1107 | { |
1100 | if (!ab.d) return s; | 1108 | if (!ab.d) return s; |
1101 | 1109 | ||
1102 | return s << ab.d->mAddressees; | 1110 | return s << ab.d->mAddressees; |
1103 | } | 1111 | } |
1104 | 1112 | ||
1105 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1113 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1106 | { | 1114 | { |
1107 | if (!ab.d) return s; | 1115 | if (!ab.d) return s; |
1108 | 1116 | ||
1109 | s >> ab.d->mAddressees; | 1117 | s >> ab.d->mAddressees; |
1110 | 1118 | ||
1111 | return s; | 1119 | return s; |
1112 | } | 1120 | } |
1113 | 1121 | ||
1114 | bool AddressBook::addResource( Resource *resource ) | 1122 | bool AddressBook::addResource( Resource *resource ) |
1115 | { | 1123 | { |
1116 | if ( !resource->open() ) { | 1124 | if ( !resource->open() ) { |
1117 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1125 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1118 | return false; | 1126 | return false; |
1119 | } | 1127 | } |
1120 | 1128 | ||
1121 | resource->setAddressBook( this ); | 1129 | resource->setAddressBook( this ); |
1122 | 1130 | ||
1123 | d->mManager->add( resource ); | 1131 | d->mManager->add( resource ); |
1124 | return true; | 1132 | return true; |
1125 | } | 1133 | } |
1126 | 1134 | ||
1127 | bool AddressBook::removeResource( Resource *resource ) | 1135 | bool AddressBook::removeResource( Resource *resource ) |
1128 | { | 1136 | { |
1129 | resource->close(); | 1137 | resource->close(); |
1130 | 1138 | ||
1131 | if ( resource == standardResource() ) | 1139 | if ( resource == standardResource() ) |
1132 | d->mManager->setStandardResource( 0 ); | 1140 | d->mManager->setStandardResource( 0 ); |
1133 | 1141 | ||
1134 | resource->setAddressBook( 0 ); | 1142 | resource->setAddressBook( 0 ); |
1135 | 1143 | ||
1136 | d->mManager->remove( resource ); | 1144 | d->mManager->remove( resource ); |
1137 | return true; | 1145 | return true; |
1138 | } | 1146 | } |
1139 | 1147 | ||
1140 | QPtrList<Resource> AddressBook::resources() | 1148 | QPtrList<Resource> AddressBook::resources() |
1141 | { | 1149 | { |
1142 | QPtrList<Resource> list; | 1150 | QPtrList<Resource> list; |
1143 | 1151 | ||
1144 | // qDebug("AddressBook::resources() 1"); | 1152 | // qDebug("AddressBook::resources() 1"); |
1145 | 1153 | ||
1146 | KRES::Manager<Resource>::ActiveIterator it; | 1154 | KRES::Manager<Resource>::ActiveIterator it; |
1147 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1155 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1148 | list.append( *it ); | 1156 | list.append( *it ); |
1149 | 1157 | ||
1150 | return list; | 1158 | return list; |
1151 | } | 1159 | } |
1152 | 1160 | ||
1153 | /*US | 1161 | /*US |
1154 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1162 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1155 | { | 1163 | { |
1156 | delete d->mErrorHandler; | 1164 | delete d->mErrorHandler; |
1157 | d->mErrorHandler = handler; | 1165 | d->mErrorHandler = handler; |
1158 | } | 1166 | } |
1159 | */ | 1167 | */ |
1160 | 1168 | ||
1161 | void AddressBook::error( const QString& msg ) | 1169 | void AddressBook::error( const QString& msg ) |
1162 | { | 1170 | { |
1163 | /*US | 1171 | /*US |
1164 | if ( !d->mErrorHandler ) // create default error handler | 1172 | if ( !d->mErrorHandler ) // create default error handler |
1165 | d->mErrorHandler = new ConsoleErrorHandler; | 1173 | d->mErrorHandler = new ConsoleErrorHandler; |
1166 | 1174 | ||
1167 | if ( d->mErrorHandler ) | 1175 | if ( d->mErrorHandler ) |
1168 | d->mErrorHandler->error( msg ); | 1176 | d->mErrorHandler->error( msg ); |
1169 | else | 1177 | else |
1170 | kdError(5700) << "no error handler defined" << endl; | 1178 | kdError(5700) << "no error handler defined" << endl; |
1171 | */ | 1179 | */ |
1172 | kdDebug(5700) << "msg" << endl; | 1180 | kdDebug(5700) << "msg" << endl; |
1173 | qDebug(msg); | 1181 | qDebug(msg); |
1174 | } | 1182 | } |
1175 | 1183 | ||
1176 | void AddressBook::deleteRemovedAddressees() | 1184 | void AddressBook::deleteRemovedAddressees() |
1177 | { | 1185 | { |
1178 | Addressee::List::Iterator it; | 1186 | Addressee::List::Iterator it; |
1179 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1187 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1180 | Resource *resource = (*it).resource(); | 1188 | Resource *resource = (*it).resource(); |
1181 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1189 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1182 | resource->removeAddressee( *it ); | 1190 | resource->removeAddressee( *it ); |
1183 | } | 1191 | } |
1184 | 1192 | ||
1185 | d->mRemovedAddressees.clear(); | 1193 | d->mRemovedAddressees.clear(); |
1186 | } | 1194 | } |
1187 | 1195 | ||
1188 | void AddressBook::setStandardResource( Resource *resource ) | 1196 | void AddressBook::setStandardResource( Resource *resource ) |
1189 | { | 1197 | { |
1190 | // qDebug("AddressBook::setStandardResource 1"); | 1198 | // qDebug("AddressBook::setStandardResource 1"); |
1191 | d->mManager->setStandardResource( resource ); | 1199 | d->mManager->setStandardResource( resource ); |
1192 | } | 1200 | } |
1193 | 1201 | ||
1194 | Resource *AddressBook::standardResource() | 1202 | Resource *AddressBook::standardResource() |
1195 | { | 1203 | { |
1196 | return d->mManager->standardResource(); | 1204 | return d->mManager->standardResource(); |
1197 | } | 1205 | } |
1198 | 1206 | ||
1199 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1207 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1200 | { | 1208 | { |
1201 | return d->mManager; | 1209 | return d->mManager; |
1202 | } | 1210 | } |
1203 | 1211 | ||
1204 | void AddressBook::cleanUp() | 1212 | void AddressBook::cleanUp() |
1205 | { | 1213 | { |
1206 | KRES::Manager<Resource>::ActiveIterator it; | 1214 | KRES::Manager<Resource>::ActiveIterator it; |
1207 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1215 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1208 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1216 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1209 | (*it)->cleanUp(); | 1217 | (*it)->cleanUp(); |
1210 | } | 1218 | } |
1211 | } | 1219 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 5edca06..f124dc9 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,348 +1,349 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | @short Address Book Const Iterator | 87 | @short Address Book Const Iterator |
88 | 88 | ||
89 | This class provides a const iterator for address book entries. | 89 | This class provides a const iterator for address book entries. |
90 | */ | 90 | */ |
91 | class ConstIterator | 91 | class ConstIterator |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | ConstIterator(); | 94 | ConstIterator(); |
95 | ConstIterator( const ConstIterator & ); | 95 | ConstIterator( const ConstIterator & ); |
96 | ~ConstIterator(); | 96 | ~ConstIterator(); |
97 | 97 | ||
98 | ConstIterator &operator=( const ConstIterator & ); | 98 | ConstIterator &operator=( const ConstIterator & ); |
99 | const Addressee &operator*() const; | 99 | const Addressee &operator*() const; |
100 | const Addressee* operator->() const; | 100 | const Addressee* operator->() const; |
101 | ConstIterator &operator++(); | 101 | ConstIterator &operator++(); |
102 | ConstIterator &operator++(int); | 102 | ConstIterator &operator++(int); |
103 | ConstIterator &operator--(); | 103 | ConstIterator &operator--(); |
104 | ConstIterator &operator--(int); | 104 | ConstIterator &operator--(int); |
105 | bool operator==( const ConstIterator &it ); | 105 | bool operator==( const ConstIterator &it ); |
106 | bool operator!=( const ConstIterator &it ); | 106 | bool operator!=( const ConstIterator &it ); |
107 | 107 | ||
108 | struct ConstIteratorData; | 108 | struct ConstIteratorData; |
109 | ConstIteratorData *d; | 109 | ConstIteratorData *d; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Constructs a address book object. | 113 | Constructs a address book object. |
114 | 114 | ||
115 | @param format File format class. | 115 | @param format File format class. |
116 | */ | 116 | */ |
117 | AddressBook(); | 117 | AddressBook(); |
118 | AddressBook( const QString &config ); | 118 | AddressBook( const QString &config ); |
119 | AddressBook( const QString &config, const QString &family ); | 119 | AddressBook( const QString &config, const QString &family ); |
120 | virtual ~AddressBook(); | 120 | virtual ~AddressBook(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Requests a ticket for saving the addressbook. Calling this function locks | 123 | Requests a ticket for saving the addressbook. Calling this function locks |
124 | the addressbook for all other processes. If the address book is already | 124 | the addressbook for all other processes. If the address book is already |
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | bool saveABphone( QString fileName ); | 145 | bool saveABphone( QString fileName ); |
146 | void smplifyAddressees(); | 146 | void smplifyAddressees(); |
147 | void removeSyncInfo( QString syncProfile); | ||
147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | 148 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); |
148 | void export2File( QString fileName ); | 149 | void export2File( QString fileName ); |
149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); | 150 | bool export2PhoneFormat( QStringList uids ,QString fileName ); |
150 | int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 151 | int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
151 | void setUntagged( bool setNonSyncTagged = false ); | 152 | void setUntagged( bool setNonSyncTagged = false ); |
152 | void removeUntagged(); | 153 | void removeUntagged(); |
153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | 154 | void findNewExtIds( QString fileName, QString currentSyncDevice ); |
154 | /** | 155 | /** |
155 | Returns a iterator for first entry of address book. | 156 | Returns a iterator for first entry of address book. |
156 | */ | 157 | */ |
157 | Iterator begin(); | 158 | Iterator begin(); |
158 | 159 | ||
159 | /** | 160 | /** |
160 | Returns a const iterator for first entry of address book. | 161 | Returns a const iterator for first entry of address book. |
161 | */ | 162 | */ |
162 | ConstIterator begin() const; | 163 | ConstIterator begin() const; |
163 | 164 | ||
164 | /** | 165 | /** |
165 | Returns a iterator for first entry of address book. | 166 | Returns a iterator for first entry of address book. |
166 | */ | 167 | */ |
167 | Iterator end(); | 168 | Iterator end(); |
168 | 169 | ||
169 | /** | 170 | /** |
170 | Returns a const iterator for first entry of address book. | 171 | Returns a const iterator for first entry of address book. |
171 | */ | 172 | */ |
172 | ConstIterator end() const; | 173 | ConstIterator end() const; |
173 | 174 | ||
174 | /** | 175 | /** |
175 | Removes all entries from address book. | 176 | Removes all entries from address book. |
176 | */ | 177 | */ |
177 | void clear(); | 178 | void clear(); |
178 | 179 | ||
179 | /** | 180 | /** |
180 | Insert an Addressee object into address book. If an object with the same | 181 | Insert an Addressee object into address book. If an object with the same |
181 | unique id already exists in the address book it it replaced by the new | 182 | unique id already exists in the address book it it replaced by the new |
182 | one. If not the new object is appended to the address book. | 183 | one. If not the new object is appended to the address book. |
183 | */ | 184 | */ |
184 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 185 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
185 | 186 | ||
186 | /** | 187 | /** |
187 | Removes entry from the address book. | 188 | Removes entry from the address book. |
188 | */ | 189 | */ |
189 | void removeAddressee( const Addressee & ); | 190 | void removeAddressee( const Addressee & ); |
190 | 191 | ||
191 | /** | 192 | /** |
192 | This is like @ref removeAddressee() just above, with the difference that | 193 | This is like @ref removeAddressee() just above, with the difference that |
193 | the first element is a iterator, returned by @ref begin(). | 194 | the first element is a iterator, returned by @ref begin(). |
194 | */ | 195 | */ |
195 | void removeAddressee( const Iterator & ); | 196 | void removeAddressee( const Iterator & ); |
196 | 197 | ||
197 | /** | 198 | /** |
198 | Find the specified entry in address book. Returns end(), if the entry | 199 | Find the specified entry in address book. Returns end(), if the entry |
199 | couldn't be found. | 200 | couldn't be found. |
200 | */ | 201 | */ |
201 | Iterator find( const Addressee & ); | 202 | Iterator find( const Addressee & ); |
202 | 203 | ||
203 | /** | 204 | /** |
204 | Find the entry specified by an unique id. Returns an empty Addressee | 205 | Find the entry specified by an unique id. Returns an empty Addressee |
205 | object, if the address book does not contain an entry with this id. | 206 | object, if the address book does not contain an entry with this id. |
206 | */ | 207 | */ |
207 | Addressee findByUid( const QString & ); | 208 | Addressee findByUid( const QString & ); |
208 | 209 | ||
209 | 210 | ||
210 | /** | 211 | /** |
211 | Returns a list of all addressees in the address book. This list can | 212 | Returns a list of all addressees in the address book. This list can |
212 | be sorted with @ref KABC::AddresseeList for example. | 213 | be sorted with @ref KABC::AddresseeList for example. |
213 | */ | 214 | */ |
214 | Addressee::List allAddressees(); | 215 | Addressee::List allAddressees(); |
215 | 216 | ||
216 | /** | 217 | /** |
217 | Find all entries with the specified name in the address book. Returns | 218 | Find all entries with the specified name in the address book. Returns |
218 | an empty list, if no entries could be found. | 219 | an empty list, if no entries could be found. |
219 | */ | 220 | */ |
220 | Addressee::List findByName( const QString & ); | 221 | Addressee::List findByName( const QString & ); |
221 | 222 | ||
222 | /** | 223 | /** |
223 | Find all entries with the specified email address in the address book. | 224 | Find all entries with the specified email address in the address book. |
224 | Returns an empty list, if no entries could be found. | 225 | Returns an empty list, if no entries could be found. |
225 | */ | 226 | */ |
226 | Addressee::List findByEmail( const QString & ); | 227 | Addressee::List findByEmail( const QString & ); |
227 | 228 | ||
228 | /** | 229 | /** |
229 | Find all entries wich have the specified category in the address book. | 230 | Find all entries wich have the specified category in the address book. |
230 | Returns an empty list, if no entries could be found. | 231 | Returns an empty list, if no entries could be found. |
231 | */ | 232 | */ |
232 | Addressee::List findByCategory( const QString & ); | 233 | Addressee::List findByCategory( const QString & ); |
233 | 234 | ||
234 | /** | 235 | /** |
235 | Return a string identifying this addressbook. | 236 | Return a string identifying this addressbook. |
236 | */ | 237 | */ |
237 | virtual QString identifier(); | 238 | virtual QString identifier(); |
238 | 239 | ||
239 | /** | 240 | /** |
240 | Used for debug output. | 241 | Used for debug output. |
241 | */ | 242 | */ |
242 | void dump() const; | 243 | void dump() const; |
243 | 244 | ||
244 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 245 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
245 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 246 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
246 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 247 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
247 | 248 | ||
248 | /** | 249 | /** |
249 | Return list of all Fields known to the address book which are associated | 250 | Return list of all Fields known to the address book which are associated |
250 | with the given field category. | 251 | with the given field category. |
251 | */ | 252 | */ |
252 | Field::List fields( int category = Field::All ); | 253 | Field::List fields( int category = Field::All ); |
253 | 254 | ||
254 | /** | 255 | /** |
255 | Add custom field to address book. | 256 | Add custom field to address book. |
256 | 257 | ||
257 | @param label User visible label of the field. | 258 | @param label User visible label of the field. |
258 | @param category Ored list of field categories. | 259 | @param category Ored list of field categories. |
259 | @param key Identifier used as key for reading and writing the field. | 260 | @param key Identifier used as key for reading and writing the field. |
260 | @param app String used as application key for reading and writing | 261 | @param app String used as application key for reading and writing |
261 | the field. | 262 | the field. |
262 | */ | 263 | */ |
263 | bool addCustomField( const QString &label, int category = Field::All, | 264 | bool addCustomField( const QString &label, int category = Field::All, |
264 | const QString &key = QString::null, | 265 | const QString &key = QString::null, |
265 | const QString &app = QString::null ); | 266 | const QString &app = QString::null ); |
266 | 267 | ||
267 | 268 | ||
268 | /** | 269 | /** |
269 | Add address book resource. | 270 | Add address book resource. |
270 | */ | 271 | */ |
271 | bool addResource( Resource * ); | 272 | bool addResource( Resource * ); |
272 | 273 | ||
273 | /** | 274 | /** |
274 | Remove address book resource. | 275 | Remove address book resource. |
275 | */ | 276 | */ |
276 | bool removeResource( Resource * ); | 277 | bool removeResource( Resource * ); |
277 | 278 | ||
278 | /** | 279 | /** |
279 | Return pointer list of all resources. | 280 | Return pointer list of all resources. |
280 | */ | 281 | */ |
281 | QPtrList<Resource> resources(); | 282 | QPtrList<Resource> resources(); |
282 | 283 | ||
283 | /** | 284 | /** |
284 | Set the @p ErrorHandler, that is used by @ref error() to | 285 | Set the @p ErrorHandler, that is used by @ref error() to |
285 | provide gui-independend error messages. | 286 | provide gui-independend error messages. |
286 | */ | 287 | */ |
287 | void setErrorHandler( ErrorHandler * ); | 288 | void setErrorHandler( ErrorHandler * ); |
288 | 289 | ||
289 | /** | 290 | /** |
290 | Shows gui independend error messages. | 291 | Shows gui independend error messages. |
291 | */ | 292 | */ |
292 | void error( const QString& ); | 293 | void error( const QString& ); |
293 | 294 | ||
294 | /** | 295 | /** |
295 | Query all resources to clean up their lock files | 296 | Query all resources to clean up their lock files |
296 | */ | 297 | */ |
297 | void cleanUp(); | 298 | void cleanUp(); |
298 | 299 | ||
299 | // sync stuff | 300 | // sync stuff |
300 | //Addressee::List getExternLastSyncAddressees(); | 301 | //Addressee::List getExternLastSyncAddressees(); |
301 | void resetTempSyncStat(); | 302 | void resetTempSyncStat(); |
302 | QStringList uidList(); | 303 | QStringList uidList(); |
303 | void removeSyncAddressees( bool removeDeleted = false ); | 304 | void removeSyncAddressees( bool removeDeleted = false ); |
304 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); | 305 | void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); |
305 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 306 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
306 | bool containsExternalUid( const QString& uid ); | 307 | bool containsExternalUid( const QString& uid ); |
307 | 308 | ||
308 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); | 309 | void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); |
309 | void postExternSync( AddressBook* aBook, const QString& csd ); | 310 | void postExternSync( AddressBook* aBook, const QString& csd ); |
310 | signals: | 311 | signals: |
311 | /** | 312 | /** |
312 | Emitted, when the address book has changed on disk. | 313 | Emitted, when the address book has changed on disk. |
313 | */ | 314 | */ |
314 | void addressBookChanged( AddressBook * ); | 315 | void addressBookChanged( AddressBook * ); |
315 | 316 | ||
316 | /** | 317 | /** |
317 | Emitted, when the address book has been locked for writing. | 318 | Emitted, when the address book has been locked for writing. |
318 | */ | 319 | */ |
319 | void addressBookLocked( AddressBook * ); | 320 | void addressBookLocked( AddressBook * ); |
320 | 321 | ||
321 | /** | 322 | /** |
322 | Emitted, when the address book has been unlocked. | 323 | Emitted, when the address book has been unlocked. |
323 | */ | 324 | */ |
324 | void addressBookUnlocked( AddressBook * ); | 325 | void addressBookUnlocked( AddressBook * ); |
325 | 326 | ||
326 | protected: | 327 | protected: |
327 | void deleteRemovedAddressees(); | 328 | void deleteRemovedAddressees(); |
328 | void setStandardResource( Resource * ); | 329 | void setStandardResource( Resource * ); |
329 | Resource *standardResource(); | 330 | Resource *standardResource(); |
330 | KRES::Manager<Resource> *resourceManager(); | 331 | KRES::Manager<Resource> *resourceManager(); |
331 | 332 | ||
332 | void init(const QString &config, const QString &family); | 333 | void init(const QString &config, const QString &family); |
333 | 334 | ||
334 | private: | 335 | private: |
335 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 336 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
336 | 337 | ||
337 | 338 | ||
338 | struct AddressBookData; | 339 | struct AddressBookData; |
339 | AddressBookData *d; | 340 | AddressBookData *d; |
340 | bool blockLSEchange; | 341 | bool blockLSEchange; |
341 | }; | 342 | }; |
342 | 343 | ||
343 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 344 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
344 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 345 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
345 | 346 | ||
346 | } | 347 | } |
347 | 348 | ||
348 | #endif | 349 | #endif |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 40877ef..a660a9d 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,2116 +1,2119 @@ | |||
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 | static bool matchBinaryPatternA( int value, int pattern ); | 46 | static bool matchBinaryPatternA( int value, int pattern ); |
47 | static bool matchBinaryPatternP( int value, int pattern ); | 47 | static bool matchBinaryPatternP( int value, int pattern ); |
48 | 48 | ||
49 | struct Addressee::AddresseeData : public KShared | 49 | struct Addressee::AddresseeData : public KShared |
50 | { | 50 | { |
51 | QString uid; | 51 | QString uid; |
52 | QString name; | 52 | QString name; |
53 | QString formattedName; | 53 | QString formattedName; |
54 | QString familyName; | 54 | QString familyName; |
55 | QString givenName; | 55 | QString givenName; |
56 | QString additionalName; | 56 | QString additionalName; |
57 | QString prefix; | 57 | QString prefix; |
58 | QString suffix; | 58 | QString suffix; |
59 | QString nickName; | 59 | QString nickName; |
60 | QDateTime birthday; | 60 | QDateTime birthday; |
61 | QString mailer; | 61 | QString mailer; |
62 | TimeZone timeZone; | 62 | TimeZone timeZone; |
63 | Geo geo; | 63 | Geo geo; |
64 | QString title; | 64 | QString title; |
65 | QString role; | 65 | QString role; |
66 | QString organization; | 66 | QString organization; |
67 | QString note; | 67 | QString note; |
68 | QString productId; | 68 | QString productId; |
69 | QDateTime revision; | 69 | QDateTime revision; |
70 | QString sortString; | 70 | QString sortString; |
71 | QString externalUID; | 71 | QString externalUID; |
72 | QString originalExternalUID; | 72 | QString originalExternalUID; |
73 | KURL url; | 73 | KURL url; |
74 | Secrecy secrecy; | 74 | Secrecy secrecy; |
75 | Picture logo; | 75 | Picture logo; |
76 | Picture photo; | 76 | Picture photo; |
77 | Sound sound; | 77 | Sound sound; |
78 | Agent agent; | 78 | Agent agent; |
79 | QString mExternalId; | 79 | QString mExternalId; |
80 | PhoneNumber::List phoneNumbers; | 80 | PhoneNumber::List phoneNumbers; |
81 | Address::List addresses; | 81 | Address::List addresses; |
82 | Key::List keys; | 82 | Key::List keys; |
83 | QStringList emails; | 83 | QStringList emails; |
84 | QStringList categories; | 84 | QStringList categories; |
85 | QStringList custom; | 85 | QStringList custom; |
86 | int mTempSyncStat; | 86 | int mTempSyncStat; |
87 | Resource *resource; | 87 | Resource *resource; |
88 | 88 | ||
89 | bool empty :1; | 89 | bool empty :1; |
90 | bool changed :1; | 90 | bool changed :1; |
91 | bool tagged :1; | 91 | bool tagged :1; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | Addressee::Addressee() | 94 | Addressee::Addressee() |
95 | { | 95 | { |
96 | mData = new AddresseeData; | 96 | mData = new AddresseeData; |
97 | mData->empty = true; | 97 | mData->empty = true; |
98 | mData->changed = false; | 98 | mData->changed = false; |
99 | mData->resource = 0; | 99 | mData->resource = 0; |
100 | mData->mExternalId = ":"; | 100 | mData->mExternalId = ":"; |
101 | mData->revision = QDateTime ( QDate( 2003,1,1)); | 101 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 102 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
103 | } | 103 | } |
104 | 104 | ||
105 | Addressee::~Addressee() | 105 | Addressee::~Addressee() |
106 | { | 106 | { |
107 | } | 107 | } |
108 | 108 | ||
109 | Addressee::Addressee( const Addressee &a ) | 109 | Addressee::Addressee( const Addressee &a ) |
110 | { | 110 | { |
111 | mData = a.mData; | 111 | mData = a.mData; |
112 | } | 112 | } |
113 | 113 | ||
114 | Addressee &Addressee::operator=( const Addressee &a ) | 114 | Addressee &Addressee::operator=( const Addressee &a ) |
115 | { | 115 | { |
116 | mData = a.mData; | 116 | mData = a.mData; |
117 | return (*this); | 117 | return (*this); |
118 | } | 118 | } |
119 | 119 | ||
120 | Addressee Addressee::copy() | 120 | Addressee Addressee::copy() |
121 | { | 121 | { |
122 | Addressee a; | 122 | Addressee a; |
123 | *(a.mData) = *mData; | 123 | *(a.mData) = *mData; |
124 | return a; | 124 | return a; |
125 | } | 125 | } |
126 | 126 | ||
127 | void Addressee::detach() | 127 | void Addressee::detach() |
128 | { | 128 | { |
129 | if ( mData.count() == 1 ) return; | 129 | if ( mData.count() == 1 ) return; |
130 | *this = copy(); | 130 | *this = copy(); |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Addressee::operator==( const Addressee &a ) const | 133 | bool Addressee::operator==( const Addressee &a ) const |
134 | { | 134 | { |
135 | if ( uid() != a.uid() ) return false; | 135 | if ( uid() != a.uid() ) return false; |
136 | if ( mData->name != a.mData->name ) return false; | 136 | if ( mData->name != a.mData->name ) return false; |
137 | if ( mData->formattedName != a.mData->formattedName ) return false; | 137 | if ( mData->formattedName != a.mData->formattedName ) return false; |
138 | if ( mData->familyName != a.mData->familyName ) return false; | 138 | if ( mData->familyName != a.mData->familyName ) return false; |
139 | if ( mData->givenName != a.mData->givenName ) return false; | 139 | if ( mData->givenName != a.mData->givenName ) return false; |
140 | if ( mData->additionalName != a.mData->additionalName ) return false; | 140 | if ( mData->additionalName != a.mData->additionalName ) return false; |
141 | if ( mData->prefix != a.mData->prefix ) return false; | 141 | if ( mData->prefix != a.mData->prefix ) return false; |
142 | if ( mData->suffix != a.mData->suffix ) return false; | 142 | if ( mData->suffix != a.mData->suffix ) return false; |
143 | if ( mData->nickName != a.mData->nickName ) return false; | 143 | if ( mData->nickName != a.mData->nickName ) return false; |
144 | if ( mData->birthday != a.mData->birthday ) return false; | 144 | if ( mData->birthday != a.mData->birthday ) return false; |
145 | if ( mData->mailer != a.mData->mailer ) return false; | 145 | if ( mData->mailer != a.mData->mailer ) return false; |
146 | if ( mData->timeZone != a.mData->timeZone ) return false; | 146 | if ( mData->timeZone != a.mData->timeZone ) return false; |
147 | if ( mData->geo != a.mData->geo ) return false; | 147 | if ( mData->geo != a.mData->geo ) return false; |
148 | if ( mData->title != a.mData->title ) return false; | 148 | if ( mData->title != a.mData->title ) return false; |
149 | if ( mData->role != a.mData->role ) return false; | 149 | if ( mData->role != a.mData->role ) return false; |
150 | if ( mData->organization != a.mData->organization ) return false; | 150 | if ( mData->organization != a.mData->organization ) return false; |
151 | if ( mData->note != a.mData->note ) return false; | 151 | if ( mData->note != a.mData->note ) return false; |
152 | if ( mData->productId != a.mData->productId ) return false; | 152 | if ( mData->productId != a.mData->productId ) return false; |
153 | //if ( mData->revision != a.mData->revision ) return false; | 153 | //if ( mData->revision != a.mData->revision ) return false; |
154 | if ( mData->sortString != a.mData->sortString ) return false; | 154 | if ( mData->sortString != a.mData->sortString ) return false; |
155 | if ( mData->secrecy != a.mData->secrecy ) return false; | 155 | if ( mData->secrecy != a.mData->secrecy ) return false; |
156 | if ( mData->logo != a.mData->logo ) return false; | 156 | if ( mData->logo != a.mData->logo ) return false; |
157 | if ( mData->photo != a.mData->photo ) return false; | 157 | if ( mData->photo != a.mData->photo ) return false; |
158 | if ( mData->sound != a.mData->sound ) return false; | 158 | if ( mData->sound != a.mData->sound ) return false; |
159 | if ( mData->agent != a.mData->agent ) return false; | 159 | if ( mData->agent != a.mData->agent ) return false; |
160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 160 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
161 | ( mData->url != a.mData->url ) ) return false; | 161 | ( mData->url != a.mData->url ) ) return false; |
162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 162 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
163 | if ( mData->addresses != a.mData->addresses ) return false; | 163 | if ( mData->addresses != a.mData->addresses ) return false; |
164 | if ( mData->keys != a.mData->keys ) return false; | 164 | if ( mData->keys != a.mData->keys ) return false; |
165 | if ( mData->emails != a.mData->emails ) return false; | 165 | if ( mData->emails != a.mData->emails ) return false; |
166 | if ( mData->categories != a.mData->categories ) return false; | 166 | if ( mData->categories != a.mData->categories ) return false; |
167 | if ( mData->custom != a.mData->custom ) return false; | 167 | if ( mData->custom != a.mData->custom ) return false; |
168 | 168 | ||
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool Addressee::operator!=( const Addressee &a ) const | 172 | bool Addressee::operator!=( const Addressee &a ) const |
173 | { | 173 | { |
174 | return !( a == *this ); | 174 | return !( a == *this ); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool Addressee::isEmpty() const | 177 | bool Addressee::isEmpty() const |
178 | { | 178 | { |
179 | return mData->empty; | 179 | return mData->empty; |
180 | } | 180 | } |
181 | ulong Addressee::getCsum4List( const QStringList & attList) | 181 | ulong Addressee::getCsum4List( const QStringList & attList) |
182 | { | 182 | { |
183 | int max = attList.count(); | 183 | int max = attList.count(); |
184 | ulong cSum = 0; | 184 | ulong cSum = 0; |
185 | int j,k,i; | 185 | int j,k,i; |
186 | int add; | 186 | int add; |
187 | for ( i = 0; i < max ; ++i ) { | 187 | for ( i = 0; i < max ; ++i ) { |
188 | QString s = attList[i]; | 188 | QString s = attList[i]; |
189 | if ( ! s.isEmpty() ){ | 189 | if ( ! s.isEmpty() ){ |
190 | j = s.length(); | 190 | j = s.length(); |
191 | for ( k = 0; k < j; ++k ) { | 191 | for ( k = 0; k < j; ++k ) { |
192 | int mul = k +1; | 192 | int mul = k +1; |
193 | add = s[k].unicode (); | 193 | add = s[k].unicode (); |
194 | if ( k < 16 ) | 194 | if ( k < 16 ) |
195 | mul = mul * mul; | 195 | mul = mul * mul; |
196 | int ii = i+1; | 196 | int ii = i+1; |
197 | add = add * mul *ii*ii*ii; | 197 | add = add * mul *ii*ii*ii; |
198 | cSum += add; | 198 | cSum += add; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | } | 202 | } |
203 | //QString dump = attList.join(","); | 203 | //QString dump = attList.join(","); |
204 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 204 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
205 | 205 | ||
206 | return cSum; | 206 | return cSum; |
207 | 207 | ||
208 | } | 208 | } |
209 | void Addressee::computeCsum(const QString &dev) | 209 | void Addressee::computeCsum(const QString &dev) |
210 | { | 210 | { |
211 | QStringList l; | 211 | QStringList l; |
212 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 212 | if ( !mData->name.isEmpty() ) l.append(mData->name); |
213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 213 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 214 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 215 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
216 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 216 | if ( !mData->additionalName ) l.append( mData->additionalName ); |
217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 217 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 218 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 219 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 220 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 221 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 222 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 223 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 224 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 225 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 226 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 227 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 228 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 229 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 230 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
231 | // if ( !mData->logo.isEmpty() ) l.append( ); | 231 | // if ( !mData->logo.isEmpty() ) l.append( ); |
232 | //if ( !mData->photo.isEmpty() ) l.append( ); | 232 | //if ( !mData->photo.isEmpty() ) l.append( ); |
233 | //if ( !mData->sound.isEmpty() ) l.append( ); | 233 | //if ( !mData->sound.isEmpty() ) l.append( ); |
234 | //if ( !mData->agent.isEmpty() ) l.append( ); | 234 | //if ( !mData->agent.isEmpty() ) l.append( ); |
235 | if ( mData->url.isValid() ) | 235 | if ( mData->url.isValid() ) |
236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); | 236 | if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); |
237 | KABC::PhoneNumber::List phoneNumbers; | 237 | KABC::PhoneNumber::List phoneNumbers; |
238 | KABC::PhoneNumber::List::Iterator phoneIter; | 238 | KABC::PhoneNumber::List::Iterator phoneIter; |
239 | 239 | ||
240 | QStringList t; | 240 | QStringList t; |
241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 241 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
242 | ++phoneIter ) | 242 | ++phoneIter ) |
243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 243 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
244 | t.sort(); | 244 | t.sort(); |
245 | uint iii; | 245 | uint iii; |
246 | for ( iii = 0; iii < t.count(); ++iii) | 246 | for ( iii = 0; iii < t.count(); ++iii) |
247 | l.append( t[iii] ); | 247 | l.append( t[iii] ); |
248 | t = mData->emails; | 248 | t = mData->emails; |
249 | t.sort(); | 249 | t.sort(); |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->categories; | 252 | t = mData->categories; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->custom; | 256 | t = mData->custom; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | l.append( t[iii] ); | 259 | l.append( t[iii] ); |
260 | KABC::Address::List::Iterator addressIter; | 260 | KABC::Address::List::Iterator addressIter; |
261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 261 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
262 | ++addressIter ) { | 262 | ++addressIter ) { |
263 | t = (*addressIter).asList(); | 263 | t = (*addressIter).asList(); |
264 | t.sort(); | 264 | t.sort(); |
265 | for ( iii = 0; iii < t.count(); ++iii) | 265 | for ( iii = 0; iii < t.count(); ++iii) |
266 | l.append( t[iii] ); | 266 | l.append( t[iii] ); |
267 | } | 267 | } |
268 | uint cs = getCsum4List(l); | 268 | uint cs = getCsum4List(l); |
269 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 269 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
270 | setCsum( dev, QString::number (cs )); | 270 | setCsum( dev, QString::number (cs )); |
271 | } | 271 | } |
272 | 272 | ||
273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | 273 | void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) |
274 | { | 274 | { |
275 | 275 | ||
276 | detach(); | 276 | detach(); |
277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 277 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 278 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 279 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 280 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 281 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 282 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 283 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 284 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
285 | if ( !mData->birthday.isValid() ) | 285 | if ( !mData->birthday.isValid() ) |
286 | if ( ad.mData->birthday.isValid()) | 286 | if ( ad.mData->birthday.isValid()) |
287 | mData->birthday = ad.mData->birthday; | 287 | mData->birthday = ad.mData->birthday; |
288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 288 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 289 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 290 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 291 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 292 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 293 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 294 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 295 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 296 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 297 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 298 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
299 | QStringList t; | 299 | QStringList t; |
300 | QStringList tAD; | 300 | QStringList tAD; |
301 | uint iii; | 301 | uint iii; |
302 | 302 | ||
303 | // ********** phone numbers | 303 | // ********** phone numbers |
304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); | 304 | PhoneNumber::List phoneAD = ad.phoneNumbers(); |
305 | PhoneNumber::List::Iterator phoneItAD; | 305 | PhoneNumber::List::Iterator phoneItAD; |
306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | 306 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { |
307 | bool found = false; | 307 | bool found = false; |
308 | PhoneNumber::List::Iterator it; | 308 | PhoneNumber::List::Iterator it; |
309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 309 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
310 | if ( ( *phoneItAD ).contains( (*it) ) ) { | 310 | if ( ( *phoneItAD ).contains( (*it) ) ) { |
311 | found = true; | 311 | found = true; |
312 | (*it).setType( ( *phoneItAD ).type() ); | 312 | (*it).setType( ( *phoneItAD ).type() ); |
313 | (*it).setNumber( ( *phoneItAD ).number() ); | 313 | (*it).setNumber( ( *phoneItAD ).number() ); |
314 | break; | 314 | break; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | if ( isSubSet && ! found ) | 317 | if ( isSubSet && ! found ) |
318 | mData->phoneNumbers.append( *phoneItAD ); | 318 | mData->phoneNumbers.append( *phoneItAD ); |
319 | } | 319 | } |
320 | if ( isSubSet ) { | 320 | if ( isSubSet ) { |
321 | // ************* emails; | 321 | // ************* emails; |
322 | t = mData->emails; | 322 | t = mData->emails; |
323 | tAD = ad.mData->emails; | 323 | tAD = ad.mData->emails; |
324 | for ( iii = 0; iii < tAD.count(); ++iii) | 324 | for ( iii = 0; iii < tAD.count(); ++iii) |
325 | if ( !t.contains(tAD[iii] ) ) | 325 | if ( !t.contains(tAD[iii] ) ) |
326 | mData->emails.append( tAD[iii] ); | 326 | mData->emails.append( tAD[iii] ); |
327 | } | 327 | } |
328 | 328 | ||
329 | // ************* categories; | 329 | // ************* categories; |
330 | t = mData->categories; | 330 | t = mData->categories; |
331 | tAD = ad.mData->categories; | 331 | tAD = ad.mData->categories; |
332 | for ( iii = 0; iii < tAD.count(); ++iii) | 332 | for ( iii = 0; iii < tAD.count(); ++iii) |
333 | if ( !t.contains(tAD[iii] ) ) | 333 | if ( !t.contains(tAD[iii] ) ) |
334 | mData->categories.append( tAD[iii] ); | 334 | mData->categories.append( tAD[iii] ); |
335 | QStringList::ConstIterator it; | 335 | QStringList::ConstIterator it; |
336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 336 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
337 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 337 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
338 | bool found = false; | 338 | bool found = false; |
339 | QStringList::ConstIterator itL; | 339 | QStringList::ConstIterator itL; |
340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 340 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
341 | if ( (*itL).startsWith( qualifiedName ) ) { | 341 | if ( (*itL).startsWith( qualifiedName ) ) { |
342 | found = true; | 342 | found = true; |
343 | break; | 343 | break; |
344 | } | 344 | } |
345 | } | 345 | } |
346 | if ( ! found ) { | 346 | if ( ! found ) { |
347 | mData->custom.append( *it ); | 347 | mData->custom.append( *it ); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 350 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; |
351 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | 351 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
352 | if ( !mData->sound.isIntern() ) { | 352 | if ( !mData->sound.isIntern() ) { |
353 | if ( mData->sound.url().isEmpty() ) { | 353 | if ( mData->sound.url().isEmpty() ) { |
354 | mData->sound = ad.mData->sound; | 354 | mData->sound = ad.mData->sound; |
355 | } | 355 | } |
356 | } | 356 | } |
357 | if ( !mData->agent.isIntern() ) { | 357 | if ( !mData->agent.isIntern() ) { |
358 | if ( mData->agent.url().isEmpty() ) { | 358 | if ( mData->agent.url().isEmpty() ) { |
359 | mData->agent = ad.mData->agent; | 359 | mData->agent = ad.mData->agent; |
360 | } | 360 | } |
361 | } | 361 | } |
362 | { | 362 | { |
363 | Key::List::Iterator itA; | 363 | Key::List::Iterator itA; |
364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 364 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
365 | bool found = false; | 365 | bool found = false; |
366 | Key::List::Iterator it; | 366 | Key::List::Iterator it; |
367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 367 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
368 | if ( (*it) == (*itA)) { | 368 | if ( (*it) == (*itA)) { |
369 | found = true; | 369 | found = true; |
370 | break; | 370 | break; |
371 | 371 | ||
372 | } | 372 | } |
373 | } | 373 | } |
374 | if ( ! found ) { | 374 | if ( ! found ) { |
375 | mData->keys.append( *itA ); | 375 | mData->keys.append( *itA ); |
376 | } | 376 | } |
377 | } | 377 | } |
378 | } | 378 | } |
379 | KABC::Address::List::Iterator addressIterA; | 379 | KABC::Address::List::Iterator addressIterA; |
380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 380 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
381 | bool found = false; | 381 | bool found = false; |
382 | KABC::Address::List::Iterator addressIter; | 382 | KABC::Address::List::Iterator addressIter; |
383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 383 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
384 | ++addressIter ) { | 384 | ++addressIter ) { |
385 | if ( (*addressIter) == (*addressIterA)) { | 385 | if ( (*addressIter) == (*addressIterA)) { |
386 | found = true; | 386 | found = true; |
387 | (*addressIter).setType( (*addressIterA).type() ); | 387 | (*addressIter).setType( (*addressIterA).type() ); |
388 | break; | 388 | break; |
389 | } | 389 | } |
390 | 390 | ||
391 | } | 391 | } |
392 | if ( isSubSet && ! found ) { | 392 | if ( isSubSet && ! found ) { |
393 | mData->addresses.append( *addressIterA ); | 393 | mData->addresses.append( *addressIterA ); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | //qDebug("merge contact %s ", ad.uid().latin1()); | 396 | //qDebug("merge contact %s ", ad.uid().latin1()); |
397 | setUid( ad.uid() ); | 397 | setUid( ad.uid() ); |
398 | setRevision( ad.revision() ); | 398 | setRevision( ad.revision() ); |
399 | } | 399 | } |
400 | 400 | ||
401 | bool Addressee::removeVoice() | 401 | bool Addressee::removeVoice() |
402 | { | 402 | { |
403 | PhoneNumber::List phoneN = phoneNumbers(); | 403 | PhoneNumber::List phoneN = phoneNumbers(); |
404 | PhoneNumber::List::Iterator phoneIt; | 404 | PhoneNumber::List::Iterator phoneIt; |
405 | bool found = false; | 405 | bool found = false; |
406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 406 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 407 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 408 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 409 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
410 | insertPhoneNumber( (*phoneIt) ); | 410 | insertPhoneNumber( (*phoneIt) ); |
411 | found = true; | 411 | found = true; |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | } | 415 | } |
416 | return found; | 416 | return found; |
417 | } | 417 | } |
418 | 418 | ||
419 | bool Addressee::containsAdr(const Addressee& ad ) | 419 | bool Addressee::containsAdr(const Addressee& ad ) |
420 | { | 420 | { |
421 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 421 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
422 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 422 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
423 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 423 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
424 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 424 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
425 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | 425 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; |
426 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | 426 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; |
427 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | 427 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
428 | 428 | ||
429 | // compare phone numbers | 429 | // compare phone numbers |
430 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 430 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
431 | PhoneNumber::List::Iterator phoneIt; | 431 | PhoneNumber::List::Iterator phoneIt; |
432 | bool found = false; | 432 | bool found = false; |
433 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 433 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
434 | bool found = false; | 434 | bool found = false; |
435 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 435 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
436 | PhoneNumber::List::Iterator phoneItL; | 436 | PhoneNumber::List::Iterator phoneItL; |
437 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 437 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
438 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 438 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
439 | found = true; | 439 | found = true; |
440 | break; | 440 | break; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | if ( ! found ) | 443 | if ( ! found ) |
444 | return false; | 444 | return false; |
445 | } | 445 | } |
446 | return true; | 446 | return true; |
447 | 447 | ||
448 | } | 448 | } |
449 | void Addressee::simplifyAddresses() | 449 | void Addressee::simplifyAddresses() |
450 | { | 450 | { |
451 | 451 | ||
452 | 452 | ||
453 | Address::List list; | 453 | Address::List list; |
454 | Address::List::Iterator it; | 454 | Address::List::Iterator it; |
455 | Address::List::Iterator it2; | 455 | Address::List::Iterator it2; |
456 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 456 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
457 | it2 = it; | 457 | it2 = it; |
458 | ++it2; | 458 | ++it2; |
459 | for( ; it2 != mData->addresses.end(); ++it2 ) { | 459 | for( ; it2 != mData->addresses.end(); ++it2 ) { |
460 | if ( (*it) == (*it2) ) { | 460 | if ( (*it) == (*it2) ) { |
461 | list.append( *it ); | 461 | list.append( *it ); |
462 | break; | 462 | break; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | } | 465 | } |
466 | for( it = list.begin(); it != list.end(); ++it ) { | 466 | for( it = list.begin(); it != list.end(); ++it ) { |
467 | removeAddress( (*it) ); | 467 | removeAddress( (*it) ); |
468 | } | 468 | } |
469 | 469 | ||
470 | list.clear(); | 470 | list.clear(); |
471 | int max = 2; | 471 | int max = 2; |
472 | if ( mData->url.isValid() ) | 472 | if ( mData->url.isValid() ) |
473 | max = 1; | 473 | max = 1; |
474 | if ( mData->addresses.count() <= max ) return ; | 474 | if ( mData->addresses.count() <= max ) return ; |
475 | int count = 0; | 475 | int count = 0; |
476 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 476 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
477 | if ( count >= max ) | 477 | if ( count >= max ) |
478 | list.append( *it ); | 478 | list.append( *it ); |
479 | ++count; | 479 | ++count; |
480 | } | 480 | } |
481 | for( it = list.begin(); it != list.end(); ++it ) { | 481 | for( it = list.begin(); it != list.end(); ++it ) { |
482 | removeAddress( (*it) ); | 482 | removeAddress( (*it) ); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | 485 | ||
486 | // removes all emails but the first | 486 | // removes all emails but the first |
487 | // needed by phone sync | 487 | // needed by phone sync |
488 | void Addressee::simplifyEmails() | 488 | void Addressee::simplifyEmails() |
489 | { | 489 | { |
490 | if ( mData->emails.count() == 0 ) return ; | 490 | if ( mData->emails.count() == 0 ) return ; |
491 | QString email = mData->emails.first(); | 491 | QString email = mData->emails.first(); |
492 | detach(); | 492 | detach(); |
493 | mData->emails.clear(); | 493 | mData->emails.clear(); |
494 | mData->emails.append( email ); | 494 | mData->emails.append( email ); |
495 | } | 495 | } |
496 | 496 | ||
497 | void Addressee::simplifyPhoneNumbers() | 497 | void Addressee::simplifyPhoneNumbers() |
498 | { | 498 | { |
499 | int max = 4; | 499 | int max = 4; |
500 | int inList = mData->phoneNumbers.count(); | 500 | int inList = mData->phoneNumbers.count(); |
501 | KABC::PhoneNumber::List removeNumbers; | 501 | KABC::PhoneNumber::List removeNumbers; |
502 | KABC::PhoneNumber::List::Iterator phoneIter; | 502 | KABC::PhoneNumber::List::Iterator phoneIter; |
503 | if ( inList > max ) { | 503 | if ( inList > max ) { |
504 | // delete non-preferred numbers | 504 | // delete non-preferred numbers |
505 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 505 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
506 | ++phoneIter ) { | 506 | ++phoneIter ) { |
507 | if ( inList > max ) { | 507 | if ( inList > max ) { |
508 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 508 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
509 | removeNumbers.append( ( *phoneIter ) ); | 509 | removeNumbers.append( ( *phoneIter ) ); |
510 | --inList; | 510 | --inList; |
511 | } | 511 | } |
512 | } else | 512 | } else |
513 | break; | 513 | break; |
514 | } | 514 | } |
515 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 515 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
516 | ++phoneIter ) { | 516 | ++phoneIter ) { |
517 | removePhoneNumber(( *phoneIter )); | 517 | removePhoneNumber(( *phoneIter )); |
518 | } | 518 | } |
519 | // delete preferred numbers | 519 | // delete preferred numbers |
520 | if ( inList > max ) { | 520 | if ( inList > max ) { |
521 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 521 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
522 | ++phoneIter ) { | 522 | ++phoneIter ) { |
523 | if ( inList > max ) { | 523 | if ( inList > max ) { |
524 | removeNumbers.append( ( *phoneIter ) ); | 524 | removeNumbers.append( ( *phoneIter ) ); |
525 | --inList; | 525 | --inList; |
526 | } else | 526 | } else |
527 | break; | 527 | break; |
528 | } | 528 | } |
529 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 529 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
530 | ++phoneIter ) { | 530 | ++phoneIter ) { |
531 | removePhoneNumber(( *phoneIter )); | 531 | removePhoneNumber(( *phoneIter )); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | } | 534 | } |
535 | // remove non-numeric characters | 535 | // remove non-numeric characters |
536 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 536 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
537 | ++phoneIter ) { | 537 | ++phoneIter ) { |
538 | if ( ! ( *phoneIter ).simplifyNumber() ) | 538 | if ( ! ( *phoneIter ).simplifyNumber() ) |
539 | removeNumbers.append( ( *phoneIter ) ); | 539 | removeNumbers.append( ( *phoneIter ) ); |
540 | } | 540 | } |
541 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 541 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
542 | ++phoneIter ) { | 542 | ++phoneIter ) { |
543 | removePhoneNumber(( *phoneIter )); | 543 | removePhoneNumber(( *phoneIter )); |
544 | } | 544 | } |
545 | } | 545 | } |
546 | void Addressee::simplifyPhoneNumberTypes() | 546 | void Addressee::simplifyPhoneNumberTypes() |
547 | { | 547 | { |
548 | KABC::PhoneNumber::List::Iterator phoneIter; | 548 | KABC::PhoneNumber::List::Iterator phoneIter; |
549 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 549 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
550 | ++phoneIter ) | 550 | ++phoneIter ) |
551 | ( *phoneIter ).simplifyType(); | 551 | ( *phoneIter ).simplifyType(); |
552 | } | 552 | } |
553 | void Addressee::removeID(const QString &prof) | 553 | void Addressee::removeID(const QString &prof) |
554 | { | 554 | { |
555 | detach(); | 555 | detach(); |
556 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 556 | if ( prof.isEmpty() ) |
557 | mData->mExternalId = ":"; | ||
558 | else | ||
559 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | ||
557 | 560 | ||
558 | } | 561 | } |
559 | void Addressee::setID( const QString & prof , const QString & id ) | 562 | void Addressee::setID( const QString & prof , const QString & id ) |
560 | { | 563 | { |
561 | detach(); | 564 | detach(); |
562 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 565 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
563 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 566 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
564 | } | 567 | } |
565 | void Addressee::setTempSyncStat( int id ) | 568 | void Addressee::setTempSyncStat( int id ) |
566 | { | 569 | { |
567 | if ( mData->mTempSyncStat == id ) return; | 570 | if ( mData->mTempSyncStat == id ) return; |
568 | detach(); | 571 | detach(); |
569 | mData->mTempSyncStat = id; | 572 | mData->mTempSyncStat = id; |
570 | } | 573 | } |
571 | int Addressee::tempSyncStat() const | 574 | int Addressee::tempSyncStat() const |
572 | { | 575 | { |
573 | return mData->mTempSyncStat; | 576 | return mData->mTempSyncStat; |
574 | } | 577 | } |
575 | 578 | ||
576 | QString Addressee::getID( const QString & prof) | 579 | QString Addressee::getID( const QString & prof) |
577 | { | 580 | { |
578 | return KIdManager::getId ( mData->mExternalId, prof ); | 581 | return KIdManager::getId ( mData->mExternalId, prof ); |
579 | } | 582 | } |
580 | 583 | ||
581 | void Addressee::setCsum( const QString & prof , const QString & id ) | 584 | void Addressee::setCsum( const QString & prof , const QString & id ) |
582 | { | 585 | { |
583 | detach(); | 586 | detach(); |
584 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 587 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
585 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 588 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
586 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 589 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
587 | } | 590 | } |
588 | 591 | ||
589 | QString Addressee::getCsum( const QString & prof) | 592 | QString Addressee::getCsum( const QString & prof) |
590 | { | 593 | { |
591 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 594 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
592 | } | 595 | } |
593 | 596 | ||
594 | void Addressee::setIDStr( const QString & s ) | 597 | void Addressee::setIDStr( const QString & s ) |
595 | { | 598 | { |
596 | detach(); | 599 | detach(); |
597 | mData->mExternalId = s; | 600 | mData->mExternalId = s; |
598 | } | 601 | } |
599 | 602 | ||
600 | QString Addressee::IDStr() const | 603 | QString Addressee::IDStr() const |
601 | { | 604 | { |
602 | return mData->mExternalId; | 605 | return mData->mExternalId; |
603 | } | 606 | } |
604 | 607 | ||
605 | void Addressee::setExternalUID( const QString &id ) | 608 | void Addressee::setExternalUID( const QString &id ) |
606 | { | 609 | { |
607 | if ( id == mData->externalUID ) return; | 610 | if ( id == mData->externalUID ) return; |
608 | detach(); | 611 | detach(); |
609 | mData->empty = false; | 612 | mData->empty = false; |
610 | mData->externalUID = id; | 613 | mData->externalUID = id; |
611 | } | 614 | } |
612 | 615 | ||
613 | QString Addressee::externalUID() const | 616 | QString Addressee::externalUID() const |
614 | { | 617 | { |
615 | return mData->externalUID; | 618 | return mData->externalUID; |
616 | } | 619 | } |
617 | void Addressee::setOriginalExternalUID( const QString &id ) | 620 | void Addressee::setOriginalExternalUID( const QString &id ) |
618 | { | 621 | { |
619 | if ( id == mData->originalExternalUID ) return; | 622 | if ( id == mData->originalExternalUID ) return; |
620 | detach(); | 623 | detach(); |
621 | mData->empty = false; | 624 | mData->empty = false; |
622 | //qDebug("*******Set orig uid %s ", id.latin1()); | 625 | //qDebug("*******Set orig uid %s ", id.latin1()); |
623 | mData->originalExternalUID = id; | 626 | mData->originalExternalUID = id; |
624 | } | 627 | } |
625 | 628 | ||
626 | QString Addressee::originalExternalUID() const | 629 | QString Addressee::originalExternalUID() const |
627 | { | 630 | { |
628 | return mData->originalExternalUID; | 631 | return mData->originalExternalUID; |
629 | } | 632 | } |
630 | 633 | ||
631 | void Addressee::setUid( const QString &id ) | 634 | void Addressee::setUid( const QString &id ) |
632 | { | 635 | { |
633 | if ( id == mData->uid ) return; | 636 | if ( id == mData->uid ) return; |
634 | detach(); | 637 | detach(); |
635 | //qDebug("****setuid %s ", id.latin1()); | 638 | //qDebug("****setuid %s ", id.latin1()); |
636 | mData->empty = false; | 639 | mData->empty = false; |
637 | mData->uid = id; | 640 | mData->uid = id; |
638 | } | 641 | } |
639 | 642 | ||
640 | QString Addressee::uid() const | 643 | QString Addressee::uid() const |
641 | { | 644 | { |
642 | if ( mData->uid.isEmpty() ) | 645 | if ( mData->uid.isEmpty() ) |
643 | mData->uid = KApplication::randomString( 10 ); | 646 | mData->uid = KApplication::randomString( 10 ); |
644 | 647 | ||
645 | return mData->uid; | 648 | return mData->uid; |
646 | } | 649 | } |
647 | 650 | ||
648 | QString Addressee::uidLabel() | 651 | QString Addressee::uidLabel() |
649 | { | 652 | { |
650 | return i18n("Unique Identifier"); | 653 | return i18n("Unique Identifier"); |
651 | } | 654 | } |
652 | 655 | ||
653 | void Addressee::setName( const QString &name ) | 656 | void Addressee::setName( const QString &name ) |
654 | { | 657 | { |
655 | if ( name == mData->name ) return; | 658 | if ( name == mData->name ) return; |
656 | detach(); | 659 | detach(); |
657 | mData->empty = false; | 660 | mData->empty = false; |
658 | mData->name = name; | 661 | mData->name = name; |
659 | } | 662 | } |
660 | 663 | ||
661 | QString Addressee::name() const | 664 | QString Addressee::name() const |
662 | { | 665 | { |
663 | return mData->name; | 666 | return mData->name; |
664 | } | 667 | } |
665 | 668 | ||
666 | QString Addressee::nameLabel() | 669 | QString Addressee::nameLabel() |
667 | { | 670 | { |
668 | return i18n("Name"); | 671 | return i18n("Name"); |
669 | } | 672 | } |
670 | 673 | ||
671 | 674 | ||
672 | void Addressee::setFormattedName( const QString &formattedName ) | 675 | void Addressee::setFormattedName( const QString &formattedName ) |
673 | { | 676 | { |
674 | if ( formattedName == mData->formattedName ) return; | 677 | if ( formattedName == mData->formattedName ) return; |
675 | detach(); | 678 | detach(); |
676 | mData->empty = false; | 679 | mData->empty = false; |
677 | mData->formattedName = formattedName; | 680 | mData->formattedName = formattedName; |
678 | } | 681 | } |
679 | 682 | ||
680 | QString Addressee::formattedName() const | 683 | QString Addressee::formattedName() const |
681 | { | 684 | { |
682 | return mData->formattedName; | 685 | return mData->formattedName; |
683 | } | 686 | } |
684 | 687 | ||
685 | QString Addressee::formattedNameLabel() | 688 | QString Addressee::formattedNameLabel() |
686 | { | 689 | { |
687 | return i18n("Formatted Name"); | 690 | return i18n("Formatted Name"); |
688 | } | 691 | } |
689 | 692 | ||
690 | 693 | ||
691 | void Addressee::setFamilyName( const QString &familyName ) | 694 | void Addressee::setFamilyName( const QString &familyName ) |
692 | { | 695 | { |
693 | if ( familyName == mData->familyName ) return; | 696 | if ( familyName == mData->familyName ) return; |
694 | detach(); | 697 | detach(); |
695 | mData->empty = false; | 698 | mData->empty = false; |
696 | mData->familyName = familyName; | 699 | mData->familyName = familyName; |
697 | } | 700 | } |
698 | 701 | ||
699 | QString Addressee::familyName() const | 702 | QString Addressee::familyName() const |
700 | { | 703 | { |
701 | return mData->familyName; | 704 | return mData->familyName; |
702 | } | 705 | } |
703 | 706 | ||
704 | QString Addressee::familyNameLabel() | 707 | QString Addressee::familyNameLabel() |
705 | { | 708 | { |
706 | return i18n("Family Name"); | 709 | return i18n("Family Name"); |
707 | } | 710 | } |
708 | 711 | ||
709 | 712 | ||
710 | void Addressee::setGivenName( const QString &givenName ) | 713 | void Addressee::setGivenName( const QString &givenName ) |
711 | { | 714 | { |
712 | if ( givenName == mData->givenName ) return; | 715 | if ( givenName == mData->givenName ) return; |
713 | detach(); | 716 | detach(); |
714 | mData->empty = false; | 717 | mData->empty = false; |
715 | mData->givenName = givenName; | 718 | mData->givenName = givenName; |
716 | } | 719 | } |
717 | 720 | ||
718 | QString Addressee::givenName() const | 721 | QString Addressee::givenName() const |
719 | { | 722 | { |
720 | return mData->givenName; | 723 | return mData->givenName; |
721 | } | 724 | } |
722 | 725 | ||
723 | QString Addressee::givenNameLabel() | 726 | QString Addressee::givenNameLabel() |
724 | { | 727 | { |
725 | return i18n("Given Name"); | 728 | return i18n("Given Name"); |
726 | } | 729 | } |
727 | 730 | ||
728 | 731 | ||
729 | void Addressee::setAdditionalName( const QString &additionalName ) | 732 | void Addressee::setAdditionalName( const QString &additionalName ) |
730 | { | 733 | { |
731 | if ( additionalName == mData->additionalName ) return; | 734 | if ( additionalName == mData->additionalName ) return; |
732 | detach(); | 735 | detach(); |
733 | mData->empty = false; | 736 | mData->empty = false; |
734 | mData->additionalName = additionalName; | 737 | mData->additionalName = additionalName; |
735 | } | 738 | } |
736 | 739 | ||
737 | QString Addressee::additionalName() const | 740 | QString Addressee::additionalName() const |
738 | { | 741 | { |
739 | return mData->additionalName; | 742 | return mData->additionalName; |
740 | } | 743 | } |
741 | 744 | ||
742 | QString Addressee::additionalNameLabel() | 745 | QString Addressee::additionalNameLabel() |
743 | { | 746 | { |
744 | return i18n("Additional Names"); | 747 | return i18n("Additional Names"); |
745 | } | 748 | } |
746 | 749 | ||
747 | 750 | ||
748 | void Addressee::setPrefix( const QString &prefix ) | 751 | void Addressee::setPrefix( const QString &prefix ) |
749 | { | 752 | { |
750 | if ( prefix == mData->prefix ) return; | 753 | if ( prefix == mData->prefix ) return; |
751 | detach(); | 754 | detach(); |
752 | mData->empty = false; | 755 | mData->empty = false; |
753 | mData->prefix = prefix; | 756 | mData->prefix = prefix; |
754 | } | 757 | } |
755 | 758 | ||
756 | QString Addressee::prefix() const | 759 | QString Addressee::prefix() const |
757 | { | 760 | { |
758 | return mData->prefix; | 761 | return mData->prefix; |
759 | } | 762 | } |
760 | 763 | ||
761 | QString Addressee::prefixLabel() | 764 | QString Addressee::prefixLabel() |
762 | { | 765 | { |
763 | return i18n("Honorific Prefixes"); | 766 | return i18n("Honorific Prefixes"); |
764 | } | 767 | } |
765 | 768 | ||
766 | 769 | ||
767 | void Addressee::setSuffix( const QString &suffix ) | 770 | void Addressee::setSuffix( const QString &suffix ) |
768 | { | 771 | { |
769 | if ( suffix == mData->suffix ) return; | 772 | if ( suffix == mData->suffix ) return; |
770 | detach(); | 773 | detach(); |
771 | mData->empty = false; | 774 | mData->empty = false; |
772 | mData->suffix = suffix; | 775 | mData->suffix = suffix; |
773 | } | 776 | } |
774 | 777 | ||
775 | QString Addressee::suffix() const | 778 | QString Addressee::suffix() const |
776 | { | 779 | { |
777 | return mData->suffix; | 780 | return mData->suffix; |
778 | } | 781 | } |
779 | 782 | ||
780 | QString Addressee::suffixLabel() | 783 | QString Addressee::suffixLabel() |
781 | { | 784 | { |
782 | return i18n("Honorific Suffixes"); | 785 | return i18n("Honorific Suffixes"); |
783 | } | 786 | } |
784 | 787 | ||
785 | 788 | ||
786 | void Addressee::setNickName( const QString &nickName ) | 789 | void Addressee::setNickName( const QString &nickName ) |
787 | { | 790 | { |
788 | if ( nickName == mData->nickName ) return; | 791 | if ( nickName == mData->nickName ) return; |
789 | detach(); | 792 | detach(); |
790 | mData->empty = false; | 793 | mData->empty = false; |
791 | mData->nickName = nickName; | 794 | mData->nickName = nickName; |
792 | } | 795 | } |
793 | 796 | ||
794 | QString Addressee::nickName() const | 797 | QString Addressee::nickName() const |
795 | { | 798 | { |
796 | return mData->nickName; | 799 | return mData->nickName; |
797 | } | 800 | } |
798 | 801 | ||
799 | QString Addressee::nickNameLabel() | 802 | QString Addressee::nickNameLabel() |
800 | { | 803 | { |
801 | return i18n("Nick Name"); | 804 | return i18n("Nick Name"); |
802 | } | 805 | } |
803 | 806 | ||
804 | 807 | ||
805 | void Addressee::setBirthday( const QDateTime &birthday ) | 808 | void Addressee::setBirthday( const QDateTime &birthday ) |
806 | { | 809 | { |
807 | if ( birthday == mData->birthday ) return; | 810 | if ( birthday == mData->birthday ) return; |
808 | detach(); | 811 | detach(); |
809 | mData->empty = false; | 812 | mData->empty = false; |
810 | mData->birthday = birthday; | 813 | mData->birthday = birthday; |
811 | } | 814 | } |
812 | 815 | ||
813 | QDateTime Addressee::birthday() const | 816 | QDateTime Addressee::birthday() const |
814 | { | 817 | { |
815 | return mData->birthday; | 818 | return mData->birthday; |
816 | } | 819 | } |
817 | 820 | ||
818 | QString Addressee::birthdayLabel() | 821 | QString Addressee::birthdayLabel() |
819 | { | 822 | { |
820 | return i18n("Birthday"); | 823 | return i18n("Birthday"); |
821 | } | 824 | } |
822 | 825 | ||
823 | 826 | ||
824 | QString Addressee::homeAddressStreetLabel() | 827 | QString Addressee::homeAddressStreetLabel() |
825 | { | 828 | { |
826 | return i18n("Home Address Street"); | 829 | return i18n("Home Address Street"); |
827 | } | 830 | } |
828 | 831 | ||
829 | 832 | ||
830 | QString Addressee::homeAddressLocalityLabel() | 833 | QString Addressee::homeAddressLocalityLabel() |
831 | { | 834 | { |
832 | return i18n("Home Address Locality"); | 835 | return i18n("Home Address Locality"); |
833 | } | 836 | } |
834 | 837 | ||
835 | 838 | ||
836 | QString Addressee::homeAddressRegionLabel() | 839 | QString Addressee::homeAddressRegionLabel() |
837 | { | 840 | { |
838 | return i18n("Home Address Region"); | 841 | return i18n("Home Address Region"); |
839 | } | 842 | } |
840 | 843 | ||
841 | 844 | ||
842 | QString Addressee::homeAddressPostalCodeLabel() | 845 | QString Addressee::homeAddressPostalCodeLabel() |
843 | { | 846 | { |
844 | return i18n("Home Address Postal Code"); | 847 | return i18n("Home Address Postal Code"); |
845 | } | 848 | } |
846 | 849 | ||
847 | 850 | ||
848 | QString Addressee::homeAddressCountryLabel() | 851 | QString Addressee::homeAddressCountryLabel() |
849 | { | 852 | { |
850 | return i18n("Home Address Country"); | 853 | return i18n("Home Address Country"); |
851 | } | 854 | } |
852 | 855 | ||
853 | 856 | ||
854 | QString Addressee::homeAddressLabelLabel() | 857 | QString Addressee::homeAddressLabelLabel() |
855 | { | 858 | { |
856 | return i18n("Home Address Label"); | 859 | return i18n("Home Address Label"); |
857 | } | 860 | } |
858 | 861 | ||
859 | 862 | ||
860 | QString Addressee::businessAddressStreetLabel() | 863 | QString Addressee::businessAddressStreetLabel() |
861 | { | 864 | { |
862 | return i18n("Business Address Street"); | 865 | return i18n("Business Address Street"); |
863 | } | 866 | } |
864 | 867 | ||
865 | 868 | ||
866 | QString Addressee::businessAddressLocalityLabel() | 869 | QString Addressee::businessAddressLocalityLabel() |
867 | { | 870 | { |
868 | return i18n("Business Address Locality"); | 871 | return i18n("Business Address Locality"); |
869 | } | 872 | } |
870 | 873 | ||
871 | 874 | ||
872 | QString Addressee::businessAddressRegionLabel() | 875 | QString Addressee::businessAddressRegionLabel() |
873 | { | 876 | { |
874 | return i18n("Business Address Region"); | 877 | return i18n("Business Address Region"); |
875 | } | 878 | } |
876 | 879 | ||
877 | 880 | ||
878 | QString Addressee::businessAddressPostalCodeLabel() | 881 | QString Addressee::businessAddressPostalCodeLabel() |
879 | { | 882 | { |
880 | return i18n("Business Address Postal Code"); | 883 | return i18n("Business Address Postal Code"); |
881 | } | 884 | } |
882 | 885 | ||
883 | 886 | ||
884 | QString Addressee::businessAddressCountryLabel() | 887 | QString Addressee::businessAddressCountryLabel() |
885 | { | 888 | { |
886 | return i18n("Business Address Country"); | 889 | return i18n("Business Address Country"); |
887 | } | 890 | } |
888 | 891 | ||
889 | 892 | ||
890 | QString Addressee::businessAddressLabelLabel() | 893 | QString Addressee::businessAddressLabelLabel() |
891 | { | 894 | { |
892 | return i18n("Business Address Label"); | 895 | return i18n("Business Address Label"); |
893 | } | 896 | } |
894 | 897 | ||
895 | 898 | ||
896 | QString Addressee::homePhoneLabel() | 899 | QString Addressee::homePhoneLabel() |
897 | { | 900 | { |
898 | return i18n("Home Phone"); | 901 | return i18n("Home Phone"); |
899 | } | 902 | } |
900 | 903 | ||
901 | 904 | ||
902 | QString Addressee::businessPhoneLabel() | 905 | QString Addressee::businessPhoneLabel() |
903 | { | 906 | { |
904 | return i18n("Business Phone"); | 907 | return i18n("Business Phone"); |
905 | } | 908 | } |
906 | 909 | ||
907 | 910 | ||
908 | QString Addressee::mobilePhoneLabel() | 911 | QString Addressee::mobilePhoneLabel() |
909 | { | 912 | { |
910 | return i18n("Mobile Phone"); | 913 | return i18n("Mobile Phone"); |
911 | } | 914 | } |
912 | 915 | ||
913 | 916 | ||
914 | QString Addressee::homeFaxLabel() | 917 | QString Addressee::homeFaxLabel() |
915 | { | 918 | { |
916 | return i18n("Home Fax"); | 919 | return i18n("Home Fax"); |
917 | } | 920 | } |
918 | 921 | ||
919 | 922 | ||
920 | QString Addressee::businessFaxLabel() | 923 | QString Addressee::businessFaxLabel() |
921 | { | 924 | { |
922 | return i18n("Business Fax"); | 925 | return i18n("Business Fax"); |
923 | } | 926 | } |
924 | 927 | ||
925 | 928 | ||
926 | QString Addressee::carPhoneLabel() | 929 | QString Addressee::carPhoneLabel() |
927 | { | 930 | { |
928 | return i18n("Car Phone"); | 931 | return i18n("Car Phone"); |
929 | } | 932 | } |
930 | 933 | ||
931 | 934 | ||
932 | QString Addressee::isdnLabel() | 935 | QString Addressee::isdnLabel() |
933 | { | 936 | { |
934 | return i18n("ISDN"); | 937 | return i18n("ISDN"); |
935 | } | 938 | } |
936 | 939 | ||
937 | 940 | ||
938 | QString Addressee::pagerLabel() | 941 | QString Addressee::pagerLabel() |
939 | { | 942 | { |
940 | return i18n("Pager"); | 943 | return i18n("Pager"); |
941 | } | 944 | } |
942 | 945 | ||
943 | QString Addressee::sipLabel() | 946 | QString Addressee::sipLabel() |
944 | { | 947 | { |
945 | return i18n("SIP"); | 948 | return i18n("SIP"); |
946 | } | 949 | } |
947 | 950 | ||
948 | QString Addressee::emailLabel() | 951 | QString Addressee::emailLabel() |
949 | { | 952 | { |
950 | return i18n("Email Address"); | 953 | return i18n("Email Address"); |
951 | } | 954 | } |
952 | 955 | ||
953 | 956 | ||
954 | void Addressee::setMailer( const QString &mailer ) | 957 | void Addressee::setMailer( const QString &mailer ) |
955 | { | 958 | { |
956 | if ( mailer == mData->mailer ) return; | 959 | if ( mailer == mData->mailer ) return; |
957 | detach(); | 960 | detach(); |
958 | mData->empty = false; | 961 | mData->empty = false; |
959 | mData->mailer = mailer; | 962 | mData->mailer = mailer; |
960 | } | 963 | } |
961 | 964 | ||
962 | QString Addressee::mailer() const | 965 | QString Addressee::mailer() const |
963 | { | 966 | { |
964 | return mData->mailer; | 967 | return mData->mailer; |
965 | } | 968 | } |
966 | 969 | ||
967 | QString Addressee::mailerLabel() | 970 | QString Addressee::mailerLabel() |
968 | { | 971 | { |
969 | return i18n("Mail Client"); | 972 | return i18n("Mail Client"); |
970 | } | 973 | } |
971 | 974 | ||
972 | 975 | ||
973 | void Addressee::setTimeZone( const TimeZone &timeZone ) | 976 | void Addressee::setTimeZone( const TimeZone &timeZone ) |
974 | { | 977 | { |
975 | if ( timeZone == mData->timeZone ) return; | 978 | if ( timeZone == mData->timeZone ) return; |
976 | detach(); | 979 | detach(); |
977 | mData->empty = false; | 980 | mData->empty = false; |
978 | mData->timeZone = timeZone; | 981 | mData->timeZone = timeZone; |
979 | } | 982 | } |
980 | 983 | ||
981 | TimeZone Addressee::timeZone() const | 984 | TimeZone Addressee::timeZone() const |
982 | { | 985 | { |
983 | return mData->timeZone; | 986 | return mData->timeZone; |
984 | } | 987 | } |
985 | 988 | ||
986 | QString Addressee::timeZoneLabel() | 989 | QString Addressee::timeZoneLabel() |
987 | { | 990 | { |
988 | return i18n("Time Zone"); | 991 | return i18n("Time Zone"); |
989 | } | 992 | } |
990 | 993 | ||
991 | 994 | ||
992 | void Addressee::setGeo( const Geo &geo ) | 995 | void Addressee::setGeo( const Geo &geo ) |
993 | { | 996 | { |
994 | if ( geo == mData->geo ) return; | 997 | if ( geo == mData->geo ) return; |
995 | detach(); | 998 | detach(); |
996 | mData->empty = false; | 999 | mData->empty = false; |
997 | mData->geo = geo; | 1000 | mData->geo = geo; |
998 | } | 1001 | } |
999 | 1002 | ||
1000 | Geo Addressee::geo() const | 1003 | Geo Addressee::geo() const |
1001 | { | 1004 | { |
1002 | return mData->geo; | 1005 | return mData->geo; |
1003 | } | 1006 | } |
1004 | 1007 | ||
1005 | QString Addressee::geoLabel() | 1008 | QString Addressee::geoLabel() |
1006 | { | 1009 | { |
1007 | return i18n("Geographic Position"); | 1010 | return i18n("Geographic Position"); |
1008 | } | 1011 | } |
1009 | 1012 | ||
1010 | 1013 | ||
1011 | void Addressee::setTitle( const QString &title ) | 1014 | void Addressee::setTitle( const QString &title ) |
1012 | { | 1015 | { |
1013 | if ( title == mData->title ) return; | 1016 | if ( title == mData->title ) return; |
1014 | detach(); | 1017 | detach(); |
1015 | mData->empty = false; | 1018 | mData->empty = false; |
1016 | mData->title = title; | 1019 | mData->title = title; |
1017 | } | 1020 | } |
1018 | 1021 | ||
1019 | QString Addressee::title() const | 1022 | QString Addressee::title() const |
1020 | { | 1023 | { |
1021 | return mData->title; | 1024 | return mData->title; |
1022 | } | 1025 | } |
1023 | 1026 | ||
1024 | QString Addressee::titleLabel() | 1027 | QString Addressee::titleLabel() |
1025 | { | 1028 | { |
1026 | return i18n("Title"); | 1029 | return i18n("Title"); |
1027 | } | 1030 | } |
1028 | 1031 | ||
1029 | 1032 | ||
1030 | void Addressee::setRole( const QString &role ) | 1033 | void Addressee::setRole( const QString &role ) |
1031 | { | 1034 | { |
1032 | if ( role == mData->role ) return; | 1035 | if ( role == mData->role ) return; |
1033 | detach(); | 1036 | detach(); |
1034 | mData->empty = false; | 1037 | mData->empty = false; |
1035 | mData->role = role; | 1038 | mData->role = role; |
1036 | } | 1039 | } |
1037 | 1040 | ||
1038 | QString Addressee::role() const | 1041 | QString Addressee::role() const |
1039 | { | 1042 | { |
1040 | return mData->role; | 1043 | return mData->role; |
1041 | } | 1044 | } |
1042 | 1045 | ||
1043 | QString Addressee::roleLabel() | 1046 | QString Addressee::roleLabel() |
1044 | { | 1047 | { |
1045 | return i18n("Role"); | 1048 | return i18n("Role"); |
1046 | } | 1049 | } |
1047 | 1050 | ||
1048 | 1051 | ||
1049 | void Addressee::setOrganization( const QString &organization ) | 1052 | void Addressee::setOrganization( const QString &organization ) |
1050 | { | 1053 | { |
1051 | if ( organization == mData->organization ) return; | 1054 | if ( organization == mData->organization ) return; |
1052 | detach(); | 1055 | detach(); |
1053 | mData->empty = false; | 1056 | mData->empty = false; |
1054 | mData->organization = organization; | 1057 | mData->organization = organization; |
1055 | } | 1058 | } |
1056 | 1059 | ||
1057 | QString Addressee::organization() const | 1060 | QString Addressee::organization() const |
1058 | { | 1061 | { |
1059 | return mData->organization; | 1062 | return mData->organization; |
1060 | } | 1063 | } |
1061 | 1064 | ||
1062 | QString Addressee::organizationLabel() | 1065 | QString Addressee::organizationLabel() |
1063 | { | 1066 | { |
1064 | return i18n("Organization"); | 1067 | return i18n("Organization"); |
1065 | } | 1068 | } |
1066 | 1069 | ||
1067 | 1070 | ||
1068 | void Addressee::setNote( const QString ¬e ) | 1071 | void Addressee::setNote( const QString ¬e ) |
1069 | { | 1072 | { |
1070 | if ( note == mData->note ) return; | 1073 | if ( note == mData->note ) return; |
1071 | detach(); | 1074 | detach(); |
1072 | mData->empty = false; | 1075 | mData->empty = false; |
1073 | mData->note = note; | 1076 | mData->note = note; |
1074 | } | 1077 | } |
1075 | 1078 | ||
1076 | QString Addressee::note() const | 1079 | QString Addressee::note() const |
1077 | { | 1080 | { |
1078 | return mData->note; | 1081 | return mData->note; |
1079 | } | 1082 | } |
1080 | 1083 | ||
1081 | QString Addressee::noteLabel() | 1084 | QString Addressee::noteLabel() |
1082 | { | 1085 | { |
1083 | return i18n("Note"); | 1086 | return i18n("Note"); |
1084 | } | 1087 | } |
1085 | 1088 | ||
1086 | 1089 | ||
1087 | void Addressee::setProductId( const QString &productId ) | 1090 | void Addressee::setProductId( const QString &productId ) |
1088 | { | 1091 | { |
1089 | if ( productId == mData->productId ) return; | 1092 | if ( productId == mData->productId ) return; |
1090 | detach(); | 1093 | detach(); |
1091 | mData->empty = false; | 1094 | mData->empty = false; |
1092 | mData->productId = productId; | 1095 | mData->productId = productId; |
1093 | } | 1096 | } |
1094 | 1097 | ||
1095 | QString Addressee::productId() const | 1098 | QString Addressee::productId() const |
1096 | { | 1099 | { |
1097 | return mData->productId; | 1100 | return mData->productId; |
1098 | } | 1101 | } |
1099 | 1102 | ||
1100 | QString Addressee::productIdLabel() | 1103 | QString Addressee::productIdLabel() |
1101 | { | 1104 | { |
1102 | return i18n("Product Identifier"); | 1105 | return i18n("Product Identifier"); |
1103 | } | 1106 | } |
1104 | 1107 | ||
1105 | 1108 | ||
1106 | void Addressee::setRevision( const QDateTime &revision ) | 1109 | void Addressee::setRevision( const QDateTime &revision ) |
1107 | { | 1110 | { |
1108 | if ( revision == mData->revision ) return; | 1111 | if ( revision == mData->revision ) return; |
1109 | detach(); | 1112 | detach(); |
1110 | mData->empty = false; | 1113 | mData->empty = false; |
1111 | mData->revision = revision; | 1114 | mData->revision = revision; |
1112 | } | 1115 | } |
1113 | 1116 | ||
1114 | QDateTime Addressee::revision() const | 1117 | QDateTime Addressee::revision() const |
1115 | { | 1118 | { |
1116 | return mData->revision; | 1119 | return mData->revision; |
1117 | } | 1120 | } |
1118 | 1121 | ||
1119 | QString Addressee::revisionLabel() | 1122 | QString Addressee::revisionLabel() |
1120 | { | 1123 | { |
1121 | return i18n("Revision Date"); | 1124 | return i18n("Revision Date"); |
1122 | } | 1125 | } |
1123 | 1126 | ||
1124 | 1127 | ||
1125 | void Addressee::setSortString( const QString &sortString ) | 1128 | void Addressee::setSortString( const QString &sortString ) |
1126 | { | 1129 | { |
1127 | if ( sortString == mData->sortString ) return; | 1130 | if ( sortString == mData->sortString ) return; |
1128 | detach(); | 1131 | detach(); |
1129 | mData->empty = false; | 1132 | mData->empty = false; |
1130 | mData->sortString = sortString; | 1133 | mData->sortString = sortString; |
1131 | } | 1134 | } |
1132 | 1135 | ||
1133 | QString Addressee::sortString() const | 1136 | QString Addressee::sortString() const |
1134 | { | 1137 | { |
1135 | return mData->sortString; | 1138 | return mData->sortString; |
1136 | } | 1139 | } |
1137 | 1140 | ||
1138 | QString Addressee::sortStringLabel() | 1141 | QString Addressee::sortStringLabel() |
1139 | { | 1142 | { |
1140 | return i18n("Sort String"); | 1143 | return i18n("Sort String"); |
1141 | } | 1144 | } |
1142 | 1145 | ||
1143 | 1146 | ||
1144 | void Addressee::setUrl( const KURL &url ) | 1147 | void Addressee::setUrl( const KURL &url ) |
1145 | { | 1148 | { |
1146 | if ( url == mData->url ) return; | 1149 | if ( url == mData->url ) return; |
1147 | detach(); | 1150 | detach(); |
1148 | mData->empty = false; | 1151 | mData->empty = false; |
1149 | mData->url = url; | 1152 | mData->url = url; |
1150 | } | 1153 | } |
1151 | 1154 | ||
1152 | KURL Addressee::url() const | 1155 | KURL Addressee::url() const |
1153 | { | 1156 | { |
1154 | return mData->url; | 1157 | return mData->url; |
1155 | } | 1158 | } |
1156 | 1159 | ||
1157 | QString Addressee::urlLabel() | 1160 | QString Addressee::urlLabel() |
1158 | { | 1161 | { |
1159 | return i18n("URL"); | 1162 | return i18n("URL"); |
1160 | } | 1163 | } |
1161 | 1164 | ||
1162 | 1165 | ||
1163 | void Addressee::setSecrecy( const Secrecy &secrecy ) | 1166 | void Addressee::setSecrecy( const Secrecy &secrecy ) |
1164 | { | 1167 | { |
1165 | if ( secrecy == mData->secrecy ) return; | 1168 | if ( secrecy == mData->secrecy ) return; |
1166 | detach(); | 1169 | detach(); |
1167 | mData->empty = false; | 1170 | mData->empty = false; |
1168 | mData->secrecy = secrecy; | 1171 | mData->secrecy = secrecy; |
1169 | } | 1172 | } |
1170 | 1173 | ||
1171 | Secrecy Addressee::secrecy() const | 1174 | Secrecy Addressee::secrecy() const |
1172 | { | 1175 | { |
1173 | return mData->secrecy; | 1176 | return mData->secrecy; |
1174 | } | 1177 | } |
1175 | 1178 | ||
1176 | QString Addressee::secrecyLabel() | 1179 | QString Addressee::secrecyLabel() |
1177 | { | 1180 | { |
1178 | return i18n("Security Class"); | 1181 | return i18n("Security Class"); |
1179 | } | 1182 | } |
1180 | 1183 | ||
1181 | 1184 | ||
1182 | void Addressee::setLogo( const Picture &logo ) | 1185 | void Addressee::setLogo( const Picture &logo ) |
1183 | { | 1186 | { |
1184 | if ( logo == mData->logo ) return; | 1187 | if ( logo == mData->logo ) return; |
1185 | detach(); | 1188 | detach(); |
1186 | mData->empty = false; | 1189 | mData->empty = false; |
1187 | mData->logo = logo; | 1190 | mData->logo = logo; |
1188 | } | 1191 | } |
1189 | 1192 | ||
1190 | Picture Addressee::logo() const | 1193 | Picture Addressee::logo() const |
1191 | { | 1194 | { |
1192 | return mData->logo; | 1195 | return mData->logo; |
1193 | } | 1196 | } |
1194 | 1197 | ||
1195 | QString Addressee::logoLabel() | 1198 | QString Addressee::logoLabel() |
1196 | { | 1199 | { |
1197 | return i18n("Logo"); | 1200 | return i18n("Logo"); |
1198 | } | 1201 | } |
1199 | 1202 | ||
1200 | 1203 | ||
1201 | void Addressee::setPhoto( const Picture &photo ) | 1204 | void Addressee::setPhoto( const Picture &photo ) |
1202 | { | 1205 | { |
1203 | if ( photo == mData->photo ) return; | 1206 | if ( photo == mData->photo ) return; |
1204 | detach(); | 1207 | detach(); |
1205 | mData->empty = false; | 1208 | mData->empty = false; |
1206 | mData->photo = photo; | 1209 | mData->photo = photo; |
1207 | } | 1210 | } |
1208 | 1211 | ||
1209 | Picture Addressee::photo() const | 1212 | Picture Addressee::photo() const |
1210 | { | 1213 | { |
1211 | return mData->photo; | 1214 | return mData->photo; |
1212 | } | 1215 | } |
1213 | 1216 | ||
1214 | QString Addressee::photoLabel() | 1217 | QString Addressee::photoLabel() |
1215 | { | 1218 | { |
1216 | return i18n("Photo"); | 1219 | return i18n("Photo"); |
1217 | } | 1220 | } |
1218 | 1221 | ||
1219 | 1222 | ||
1220 | void Addressee::setSound( const Sound &sound ) | 1223 | void Addressee::setSound( const Sound &sound ) |
1221 | { | 1224 | { |
1222 | if ( sound == mData->sound ) return; | 1225 | if ( sound == mData->sound ) return; |
1223 | detach(); | 1226 | detach(); |
1224 | mData->empty = false; | 1227 | mData->empty = false; |
1225 | mData->sound = sound; | 1228 | mData->sound = sound; |
1226 | } | 1229 | } |
1227 | 1230 | ||
1228 | Sound Addressee::sound() const | 1231 | Sound Addressee::sound() const |
1229 | { | 1232 | { |
1230 | return mData->sound; | 1233 | return mData->sound; |
1231 | } | 1234 | } |
1232 | 1235 | ||
1233 | QString Addressee::soundLabel() | 1236 | QString Addressee::soundLabel() |
1234 | { | 1237 | { |
1235 | return i18n("Sound"); | 1238 | return i18n("Sound"); |
1236 | } | 1239 | } |
1237 | 1240 | ||
1238 | 1241 | ||
1239 | void Addressee::setAgent( const Agent &agent ) | 1242 | void Addressee::setAgent( const Agent &agent ) |
1240 | { | 1243 | { |
1241 | if ( agent == mData->agent ) return; | 1244 | if ( agent == mData->agent ) return; |
1242 | detach(); | 1245 | detach(); |
1243 | mData->empty = false; | 1246 | mData->empty = false; |
1244 | mData->agent = agent; | 1247 | mData->agent = agent; |
1245 | } | 1248 | } |
1246 | 1249 | ||
1247 | Agent Addressee::agent() const | 1250 | Agent Addressee::agent() const |
1248 | { | 1251 | { |
1249 | return mData->agent; | 1252 | return mData->agent; |
1250 | } | 1253 | } |
1251 | 1254 | ||
1252 | QString Addressee::agentLabel() | 1255 | QString Addressee::agentLabel() |
1253 | { | 1256 | { |
1254 | return i18n("Agent"); | 1257 | return i18n("Agent"); |
1255 | } | 1258 | } |
1256 | 1259 | ||
1257 | 1260 | ||
1258 | 1261 | ||
1259 | void Addressee::setNameFromString( const QString &str ) | 1262 | void Addressee::setNameFromString( const QString &str ) |
1260 | { | 1263 | { |
1261 | setFormattedName( str ); | 1264 | setFormattedName( str ); |
1262 | setName( str ); | 1265 | setName( str ); |
1263 | 1266 | ||
1264 | static bool first = true; | 1267 | static bool first = true; |
1265 | static QStringList titles; | 1268 | static QStringList titles; |
1266 | static QStringList suffixes; | 1269 | static QStringList suffixes; |
1267 | static QStringList prefixes; | 1270 | static QStringList prefixes; |
1268 | 1271 | ||
1269 | if ( first ) { | 1272 | if ( first ) { |
1270 | first = false; | 1273 | first = false; |
1271 | titles += i18n( "Dr." ); | 1274 | titles += i18n( "Dr." ); |
1272 | titles += i18n( "Miss" ); | 1275 | titles += i18n( "Miss" ); |
1273 | titles += i18n( "Mr." ); | 1276 | titles += i18n( "Mr." ); |
1274 | titles += i18n( "Mrs." ); | 1277 | titles += i18n( "Mrs." ); |
1275 | titles += i18n( "Ms." ); | 1278 | titles += i18n( "Ms." ); |
1276 | titles += i18n( "Prof." ); | 1279 | titles += i18n( "Prof." ); |
1277 | 1280 | ||
1278 | suffixes += i18n( "I" ); | 1281 | suffixes += i18n( "I" ); |
1279 | suffixes += i18n( "II" ); | 1282 | suffixes += i18n( "II" ); |
1280 | suffixes += i18n( "III" ); | 1283 | suffixes += i18n( "III" ); |
1281 | suffixes += i18n( "Jr." ); | 1284 | suffixes += i18n( "Jr." ); |
1282 | suffixes += i18n( "Sr." ); | 1285 | suffixes += i18n( "Sr." ); |
1283 | 1286 | ||
1284 | prefixes += "van"; | 1287 | prefixes += "van"; |
1285 | prefixes += "von"; | 1288 | prefixes += "von"; |
1286 | prefixes += "de"; | 1289 | prefixes += "de"; |
1287 | 1290 | ||
1288 | KConfig config( locateLocal( "config", "kabcrc") ); | 1291 | KConfig config( locateLocal( "config", "kabcrc") ); |
1289 | config.setGroup( "General" ); | 1292 | config.setGroup( "General" ); |
1290 | titles += config.readListEntry( "Prefixes" ); | 1293 | titles += config.readListEntry( "Prefixes" ); |
1291 | titles.remove( "" ); | 1294 | titles.remove( "" ); |
1292 | prefixes += config.readListEntry( "Inclusions" ); | 1295 | prefixes += config.readListEntry( "Inclusions" ); |
1293 | prefixes.remove( "" ); | 1296 | prefixes.remove( "" ); |
1294 | suffixes += config.readListEntry( "Suffixes" ); | 1297 | suffixes += config.readListEntry( "Suffixes" ); |
1295 | suffixes.remove( "" ); | 1298 | suffixes.remove( "" ); |
1296 | } | 1299 | } |
1297 | 1300 | ||
1298 | // clear all name parts | 1301 | // clear all name parts |
1299 | setPrefix( "" ); | 1302 | setPrefix( "" ); |
1300 | setGivenName( "" ); | 1303 | setGivenName( "" ); |
1301 | setAdditionalName( "" ); | 1304 | setAdditionalName( "" ); |
1302 | setFamilyName( "" ); | 1305 | setFamilyName( "" ); |
1303 | setSuffix( "" ); | 1306 | setSuffix( "" ); |
1304 | 1307 | ||
1305 | if ( str.isEmpty() ) | 1308 | if ( str.isEmpty() ) |
1306 | return; | 1309 | return; |
1307 | 1310 | ||
1308 | int i = str.find(','); | 1311 | int i = str.find(','); |
1309 | if( i < 0 ) { | 1312 | if( i < 0 ) { |
1310 | QStringList parts = QStringList::split( " ", str ); | 1313 | QStringList parts = QStringList::split( " ", str ); |
1311 | int leftOffset = 0; | 1314 | int leftOffset = 0; |
1312 | int rightOffset = parts.count() - 1; | 1315 | int rightOffset = parts.count() - 1; |
1313 | 1316 | ||
1314 | QString suffix; | 1317 | QString suffix; |
1315 | while ( rightOffset >= 0 ) { | 1318 | while ( rightOffset >= 0 ) { |
1316 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1319 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1317 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1320 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1318 | rightOffset--; | 1321 | rightOffset--; |
1319 | } else | 1322 | } else |
1320 | break; | 1323 | break; |
1321 | } | 1324 | } |
1322 | setSuffix( suffix ); | 1325 | setSuffix( suffix ); |
1323 | 1326 | ||
1324 | if ( rightOffset < 0 ) | 1327 | if ( rightOffset < 0 ) |
1325 | return; | 1328 | return; |
1326 | 1329 | ||
1327 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1330 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1328 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1331 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1329 | rightOffset--; | 1332 | rightOffset--; |
1330 | } else | 1333 | } else |
1331 | setFamilyName( parts[ rightOffset ] ); | 1334 | setFamilyName( parts[ rightOffset ] ); |
1332 | 1335 | ||
1333 | QString prefix; | 1336 | QString prefix; |
1334 | while ( leftOffset < rightOffset ) { | 1337 | while ( leftOffset < rightOffset ) { |
1335 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1338 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1336 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1339 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1337 | leftOffset++; | 1340 | leftOffset++; |
1338 | } else | 1341 | } else |
1339 | break; | 1342 | break; |
1340 | } | 1343 | } |
1341 | setPrefix( prefix ); | 1344 | setPrefix( prefix ); |
1342 | 1345 | ||
1343 | if ( leftOffset < rightOffset ) { | 1346 | if ( leftOffset < rightOffset ) { |
1344 | setGivenName( parts[ leftOffset ] ); | 1347 | setGivenName( parts[ leftOffset ] ); |
1345 | leftOffset++; | 1348 | leftOffset++; |
1346 | } | 1349 | } |
1347 | 1350 | ||
1348 | QString additionalName; | 1351 | QString additionalName; |
1349 | while ( leftOffset < rightOffset ) { | 1352 | while ( leftOffset < rightOffset ) { |
1350 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1353 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1351 | leftOffset++; | 1354 | leftOffset++; |
1352 | } | 1355 | } |
1353 | setAdditionalName( additionalName ); | 1356 | setAdditionalName( additionalName ); |
1354 | } else { | 1357 | } else { |
1355 | QString part1 = str.left( i ); | 1358 | QString part1 = str.left( i ); |
1356 | QString part2 = str.mid( i + 1 ); | 1359 | QString part2 = str.mid( i + 1 ); |
1357 | 1360 | ||
1358 | QStringList parts = QStringList::split( " ", part1 ); | 1361 | QStringList parts = QStringList::split( " ", part1 ); |
1359 | int leftOffset = 0; | 1362 | int leftOffset = 0; |
1360 | int rightOffset = parts.count() - 1; | 1363 | int rightOffset = parts.count() - 1; |
1361 | 1364 | ||
1362 | QString suffix; | 1365 | QString suffix; |
1363 | while ( rightOffset >= 0 ) { | 1366 | while ( rightOffset >= 0 ) { |
1364 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1367 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1365 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1368 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1366 | rightOffset--; | 1369 | rightOffset--; |
1367 | } else | 1370 | } else |
1368 | break; | 1371 | break; |
1369 | } | 1372 | } |
1370 | setSuffix( suffix ); | 1373 | setSuffix( suffix ); |
1371 | 1374 | ||
1372 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1375 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1373 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1376 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1374 | rightOffset--; | 1377 | rightOffset--; |
1375 | } else | 1378 | } else |
1376 | setFamilyName( parts[ rightOffset ] ); | 1379 | setFamilyName( parts[ rightOffset ] ); |
1377 | 1380 | ||
1378 | QString prefix; | 1381 | QString prefix; |
1379 | while ( leftOffset < rightOffset ) { | 1382 | while ( leftOffset < rightOffset ) { |
1380 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1383 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1381 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1384 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1382 | leftOffset++; | 1385 | leftOffset++; |
1383 | } else | 1386 | } else |
1384 | break; | 1387 | break; |
1385 | } | 1388 | } |
1386 | 1389 | ||
1387 | parts = QStringList::split( " ", part2 ); | 1390 | parts = QStringList::split( " ", part2 ); |
1388 | 1391 | ||
1389 | leftOffset = 0; | 1392 | leftOffset = 0; |
1390 | rightOffset = parts.count(); | 1393 | rightOffset = parts.count(); |
1391 | 1394 | ||
1392 | while ( leftOffset < rightOffset ) { | 1395 | while ( leftOffset < rightOffset ) { |
1393 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1396 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1394 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1397 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1395 | leftOffset++; | 1398 | leftOffset++; |
1396 | } else | 1399 | } else |
1397 | break; | 1400 | break; |
1398 | } | 1401 | } |
1399 | setPrefix( prefix ); | 1402 | setPrefix( prefix ); |
1400 | 1403 | ||
1401 | if ( leftOffset < rightOffset ) { | 1404 | if ( leftOffset < rightOffset ) { |
1402 | setGivenName( parts[ leftOffset ] ); | 1405 | setGivenName( parts[ leftOffset ] ); |
1403 | leftOffset++; | 1406 | leftOffset++; |
1404 | } | 1407 | } |
1405 | 1408 | ||
1406 | QString additionalName; | 1409 | QString additionalName; |
1407 | while ( leftOffset < rightOffset ) { | 1410 | while ( leftOffset < rightOffset ) { |
1408 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1411 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1409 | leftOffset++; | 1412 | leftOffset++; |
1410 | } | 1413 | } |
1411 | setAdditionalName( additionalName ); | 1414 | setAdditionalName( additionalName ); |
1412 | } | 1415 | } |
1413 | } | 1416 | } |
1414 | 1417 | ||
1415 | QString Addressee::realName() const | 1418 | QString Addressee::realName() const |
1416 | { | 1419 | { |
1417 | if ( !formattedName().isEmpty() ) | 1420 | if ( !formattedName().isEmpty() ) |
1418 | return formattedName(); | 1421 | return formattedName(); |
1419 | 1422 | ||
1420 | QString n = assembledName(); | 1423 | QString n = assembledName(); |
1421 | 1424 | ||
1422 | if ( n.isEmpty() ) | 1425 | if ( n.isEmpty() ) |
1423 | n = name(); | 1426 | n = name(); |
1424 | 1427 | ||
1425 | return n; | 1428 | return n; |
1426 | } | 1429 | } |
1427 | 1430 | ||
1428 | QString Addressee::assembledName() const | 1431 | QString Addressee::assembledName() const |
1429 | { | 1432 | { |
1430 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + | 1433 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + |
1431 | familyName() + " " + suffix(); | 1434 | familyName() + " " + suffix(); |
1432 | 1435 | ||
1433 | return name.simplifyWhiteSpace(); | 1436 | return name.simplifyWhiteSpace(); |
1434 | } | 1437 | } |
1435 | 1438 | ||
1436 | QString Addressee::fullEmail( const QString &email ) const | 1439 | QString Addressee::fullEmail( const QString &email ) const |
1437 | { | 1440 | { |
1438 | QString e; | 1441 | QString e; |
1439 | if ( email.isNull() ) { | 1442 | if ( email.isNull() ) { |
1440 | e = preferredEmail(); | 1443 | e = preferredEmail(); |
1441 | } else { | 1444 | } else { |
1442 | e = email; | 1445 | e = email; |
1443 | } | 1446 | } |
1444 | if ( e.isEmpty() ) return QString::null; | 1447 | if ( e.isEmpty() ) return QString::null; |
1445 | 1448 | ||
1446 | QString text; | 1449 | QString text; |
1447 | if ( realName().isEmpty() ) | 1450 | if ( realName().isEmpty() ) |
1448 | text = e; | 1451 | text = e; |
1449 | else | 1452 | else |
1450 | text = assembledName() + " <" + e + ">"; | 1453 | text = assembledName() + " <" + e + ">"; |
1451 | 1454 | ||
1452 | return text; | 1455 | return text; |
1453 | } | 1456 | } |
1454 | 1457 | ||
1455 | void Addressee::insertEmail( const QString &email, bool preferred ) | 1458 | void Addressee::insertEmail( const QString &email, bool preferred ) |
1456 | { | 1459 | { |
1457 | detach(); | 1460 | detach(); |
1458 | 1461 | ||
1459 | QStringList::Iterator it = mData->emails.find( email ); | 1462 | QStringList::Iterator it = mData->emails.find( email ); |
1460 | 1463 | ||
1461 | if ( it != mData->emails.end() ) { | 1464 | if ( it != mData->emails.end() ) { |
1462 | if ( !preferred || it == mData->emails.begin() ) return; | 1465 | if ( !preferred || it == mData->emails.begin() ) return; |
1463 | mData->emails.remove( it ); | 1466 | mData->emails.remove( it ); |
1464 | mData->emails.prepend( email ); | 1467 | mData->emails.prepend( email ); |
1465 | } else { | 1468 | } else { |
1466 | if ( preferred ) { | 1469 | if ( preferred ) { |
1467 | mData->emails.prepend( email ); | 1470 | mData->emails.prepend( email ); |
1468 | } else { | 1471 | } else { |
1469 | mData->emails.append( email ); | 1472 | mData->emails.append( email ); |
1470 | } | 1473 | } |
1471 | } | 1474 | } |
1472 | } | 1475 | } |
1473 | 1476 | ||
1474 | void Addressee::removeEmail( const QString &email ) | 1477 | void Addressee::removeEmail( const QString &email ) |
1475 | { | 1478 | { |
1476 | detach(); | 1479 | detach(); |
1477 | 1480 | ||
1478 | QStringList::Iterator it = mData->emails.find( email ); | 1481 | QStringList::Iterator it = mData->emails.find( email ); |
1479 | if ( it == mData->emails.end() ) return; | 1482 | if ( it == mData->emails.end() ) return; |
1480 | 1483 | ||
1481 | mData->emails.remove( it ); | 1484 | mData->emails.remove( it ); |
1482 | } | 1485 | } |
1483 | 1486 | ||
1484 | QString Addressee::preferredEmail() const | 1487 | QString Addressee::preferredEmail() const |
1485 | { | 1488 | { |
1486 | if ( mData->emails.count() == 0 ) return QString::null; | 1489 | if ( mData->emails.count() == 0 ) return QString::null; |
1487 | else return mData->emails.first(); | 1490 | else return mData->emails.first(); |
1488 | } | 1491 | } |
1489 | 1492 | ||
1490 | QStringList Addressee::emails() const | 1493 | QStringList Addressee::emails() const |
1491 | { | 1494 | { |
1492 | return mData->emails; | 1495 | return mData->emails; |
1493 | } | 1496 | } |
1494 | void Addressee::setEmails( const QStringList& emails ) { | 1497 | void Addressee::setEmails( const QStringList& emails ) { |
1495 | detach(); | 1498 | detach(); |
1496 | mData->emails = emails; | 1499 | mData->emails = emails; |
1497 | } | 1500 | } |
1498 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) | 1501 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) |
1499 | { | 1502 | { |
1500 | detach(); | 1503 | detach(); |
1501 | mData->empty = false; | 1504 | mData->empty = false; |
1502 | 1505 | ||
1503 | PhoneNumber::List::Iterator it; | 1506 | PhoneNumber::List::Iterator it; |
1504 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1507 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1505 | if ( (*it).id() == phoneNumber.id() ) { | 1508 | if ( (*it).id() == phoneNumber.id() ) { |
1506 | *it = phoneNumber; | 1509 | *it = phoneNumber; |
1507 | return; | 1510 | return; |
1508 | } | 1511 | } |
1509 | } | 1512 | } |
1510 | mData->phoneNumbers.append( phoneNumber ); | 1513 | mData->phoneNumbers.append( phoneNumber ); |
1511 | } | 1514 | } |
1512 | 1515 | ||
1513 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) | 1516 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) |
1514 | { | 1517 | { |
1515 | detach(); | 1518 | detach(); |
1516 | 1519 | ||
1517 | PhoneNumber::List::Iterator it; | 1520 | PhoneNumber::List::Iterator it; |
1518 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1521 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1519 | if ( (*it).id() == phoneNumber.id() ) { | 1522 | if ( (*it).id() == phoneNumber.id() ) { |
1520 | mData->phoneNumbers.remove( it ); | 1523 | mData->phoneNumbers.remove( it ); |
1521 | return; | 1524 | return; |
1522 | } | 1525 | } |
1523 | } | 1526 | } |
1524 | } | 1527 | } |
1525 | 1528 | ||
1526 | PhoneNumber Addressee::phoneNumber( int type ) const | 1529 | PhoneNumber Addressee::phoneNumber( int type ) const |
1527 | { | 1530 | { |
1528 | PhoneNumber phoneNumber( "", type ); | 1531 | PhoneNumber phoneNumber( "", type ); |
1529 | PhoneNumber::List::ConstIterator it; | 1532 | PhoneNumber::List::ConstIterator it; |
1530 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1533 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1531 | if ( matchBinaryPatternP( (*it).type(), type ) ) { | 1534 | if ( matchBinaryPatternP( (*it).type(), type ) ) { |
1532 | if ( (*it).type() & PhoneNumber::Pref ) | 1535 | if ( (*it).type() & PhoneNumber::Pref ) |
1533 | return (*it); | 1536 | return (*it); |
1534 | else if ( phoneNumber.number().isEmpty() ) | 1537 | else if ( phoneNumber.number().isEmpty() ) |
1535 | phoneNumber = (*it); | 1538 | phoneNumber = (*it); |
1536 | } | 1539 | } |
1537 | } | 1540 | } |
1538 | 1541 | ||
1539 | return phoneNumber; | 1542 | return phoneNumber; |
1540 | } | 1543 | } |
1541 | 1544 | ||
1542 | PhoneNumber::List Addressee::phoneNumbers() const | 1545 | PhoneNumber::List Addressee::phoneNumbers() const |
1543 | { | 1546 | { |
1544 | return mData->phoneNumbers; | 1547 | return mData->phoneNumbers; |
1545 | } | 1548 | } |
1546 | 1549 | ||
1547 | PhoneNumber::List Addressee::phoneNumbers( int type ) const | 1550 | PhoneNumber::List Addressee::phoneNumbers( int type ) const |
1548 | { | 1551 | { |
1549 | PhoneNumber::List list; | 1552 | PhoneNumber::List list; |
1550 | 1553 | ||
1551 | PhoneNumber::List::ConstIterator it; | 1554 | PhoneNumber::List::ConstIterator it; |
1552 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1555 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1553 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1556 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1554 | list.append( *it ); | 1557 | list.append( *it ); |
1555 | } | 1558 | } |
1556 | } | 1559 | } |
1557 | return list; | 1560 | return list; |
1558 | } | 1561 | } |
1559 | 1562 | ||
1560 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const | 1563 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const |
1561 | { | 1564 | { |
1562 | PhoneNumber::List::ConstIterator it; | 1565 | PhoneNumber::List::ConstIterator it; |
1563 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1566 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1564 | if ( (*it).id() == id ) { | 1567 | if ( (*it).id() == id ) { |
1565 | return *it; | 1568 | return *it; |
1566 | } | 1569 | } |
1567 | } | 1570 | } |
1568 | return PhoneNumber(); | 1571 | return PhoneNumber(); |
1569 | } | 1572 | } |
1570 | 1573 | ||
1571 | void Addressee::insertKey( const Key &key ) | 1574 | void Addressee::insertKey( const Key &key ) |
1572 | { | 1575 | { |
1573 | detach(); | 1576 | detach(); |
1574 | mData->empty = false; | 1577 | mData->empty = false; |
1575 | 1578 | ||
1576 | Key::List::Iterator it; | 1579 | Key::List::Iterator it; |
1577 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1580 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1578 | if ( (*it).id() == key.id() ) { | 1581 | if ( (*it).id() == key.id() ) { |
1579 | *it = key; | 1582 | *it = key; |
1580 | return; | 1583 | return; |
1581 | } | 1584 | } |
1582 | } | 1585 | } |
1583 | mData->keys.append( key ); | 1586 | mData->keys.append( key ); |
1584 | } | 1587 | } |
1585 | 1588 | ||
1586 | void Addressee::removeKey( const Key &key ) | 1589 | void Addressee::removeKey( const Key &key ) |
1587 | { | 1590 | { |
1588 | detach(); | 1591 | detach(); |
1589 | 1592 | ||
1590 | Key::List::Iterator it; | 1593 | Key::List::Iterator it; |
1591 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1594 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1592 | if ( (*it).id() == key.id() ) { | 1595 | if ( (*it).id() == key.id() ) { |
1593 | mData->keys.remove( key ); | 1596 | mData->keys.remove( key ); |
1594 | return; | 1597 | return; |
1595 | } | 1598 | } |
1596 | } | 1599 | } |
1597 | } | 1600 | } |
1598 | 1601 | ||
1599 | Key Addressee::key( int type, QString customTypeString ) const | 1602 | Key Addressee::key( int type, QString customTypeString ) const |
1600 | { | 1603 | { |
1601 | Key::List::ConstIterator it; | 1604 | Key::List::ConstIterator it; |
1602 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1605 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1603 | if ( (*it).type() == type ) { | 1606 | if ( (*it).type() == type ) { |
1604 | if ( type == Key::Custom ) { | 1607 | if ( type == Key::Custom ) { |
1605 | if ( customTypeString.isEmpty() ) { | 1608 | if ( customTypeString.isEmpty() ) { |
1606 | return *it; | 1609 | return *it; |
1607 | } else { | 1610 | } else { |
1608 | if ( (*it).customTypeString() == customTypeString ) | 1611 | if ( (*it).customTypeString() == customTypeString ) |
1609 | return (*it); | 1612 | return (*it); |
1610 | } | 1613 | } |
1611 | } else { | 1614 | } else { |
1612 | return *it; | 1615 | return *it; |
1613 | } | 1616 | } |
1614 | } | 1617 | } |
1615 | } | 1618 | } |
1616 | return Key( QString(), type ); | 1619 | return Key( QString(), type ); |
1617 | } | 1620 | } |
1618 | void Addressee::setKeys( const Key::List& list ) { | 1621 | void Addressee::setKeys( const Key::List& list ) { |
1619 | detach(); | 1622 | detach(); |
1620 | mData->keys = list; | 1623 | mData->keys = list; |
1621 | } | 1624 | } |
1622 | 1625 | ||
1623 | Key::List Addressee::keys() const | 1626 | Key::List Addressee::keys() const |
1624 | { | 1627 | { |
1625 | return mData->keys; | 1628 | return mData->keys; |
1626 | } | 1629 | } |
1627 | 1630 | ||
1628 | Key::List Addressee::keys( int type, QString customTypeString ) const | 1631 | Key::List Addressee::keys( int type, QString customTypeString ) const |
1629 | { | 1632 | { |
1630 | Key::List list; | 1633 | Key::List list; |
1631 | 1634 | ||
1632 | Key::List::ConstIterator it; | 1635 | Key::List::ConstIterator it; |
1633 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1636 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1634 | if ( (*it).type() == type ) { | 1637 | if ( (*it).type() == type ) { |
1635 | if ( type == Key::Custom ) { | 1638 | if ( type == Key::Custom ) { |
1636 | if ( customTypeString.isEmpty() ) { | 1639 | if ( customTypeString.isEmpty() ) { |
1637 | list.append(*it); | 1640 | list.append(*it); |
1638 | } else { | 1641 | } else { |
1639 | if ( (*it).customTypeString() == customTypeString ) | 1642 | if ( (*it).customTypeString() == customTypeString ) |
1640 | list.append(*it); | 1643 | list.append(*it); |
1641 | } | 1644 | } |
1642 | } else { | 1645 | } else { |
1643 | list.append(*it); | 1646 | list.append(*it); |
1644 | } | 1647 | } |
1645 | } | 1648 | } |
1646 | } | 1649 | } |
1647 | return list; | 1650 | return list; |
1648 | } | 1651 | } |
1649 | 1652 | ||
1650 | Key Addressee::findKey( const QString &id ) const | 1653 | Key Addressee::findKey( const QString &id ) const |
1651 | { | 1654 | { |
1652 | Key::List::ConstIterator it; | 1655 | Key::List::ConstIterator it; |
1653 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1656 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1654 | if ( (*it).id() == id ) { | 1657 | if ( (*it).id() == id ) { |
1655 | return *it; | 1658 | return *it; |
1656 | } | 1659 | } |
1657 | } | 1660 | } |
1658 | return Key(); | 1661 | return Key(); |
1659 | } | 1662 | } |
1660 | 1663 | ||
1661 | QString Addressee::asString() const | 1664 | QString Addressee::asString() const |
1662 | { | 1665 | { |
1663 | return "Smith, agent Smith..."; | 1666 | return "Smith, agent Smith..."; |
1664 | } | 1667 | } |
1665 | 1668 | ||
1666 | void Addressee::dump() const | 1669 | void Addressee::dump() const |
1667 | { | 1670 | { |
1668 | return; | 1671 | return; |
1669 | kdDebug(5700) << "Addressee {" << endl; | 1672 | kdDebug(5700) << "Addressee {" << endl; |
1670 | 1673 | ||
1671 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; | 1674 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; |
1672 | 1675 | ||
1673 | kdDebug(5700) << " Name: '" << name() << "'" << endl; | 1676 | kdDebug(5700) << " Name: '" << name() << "'" << endl; |
1674 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; | 1677 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; |
1675 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; | 1678 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; |
1676 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; | 1679 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; |
1677 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; | 1680 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; |
1678 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; | 1681 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; |
1679 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; | 1682 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; |
1680 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; | 1683 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; |
1681 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; | 1684 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; |
1682 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; | 1685 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; |
1683 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; | 1686 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; |
1684 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; | 1687 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; |
1685 | kdDebug(5700) << " Title: '" << title() << "'" << endl; | 1688 | kdDebug(5700) << " Title: '" << title() << "'" << endl; |
1686 | kdDebug(5700) << " Role: '" << role() << "'" << endl; | 1689 | kdDebug(5700) << " Role: '" << role() << "'" << endl; |
1687 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; | 1690 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; |
1688 | kdDebug(5700) << " Note: '" << note() << "'" << endl; | 1691 | kdDebug(5700) << " Note: '" << note() << "'" << endl; |
1689 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; | 1692 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; |
1690 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; | 1693 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; |
1691 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; | 1694 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; |
1692 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; | 1695 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; |
1693 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; | 1696 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; |
1694 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; | 1697 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; |
1695 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; | 1698 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; |
1696 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; | 1699 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; |
1697 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; | 1700 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; |
1698 | 1701 | ||
1699 | kdDebug(5700) << " Emails {" << endl; | 1702 | kdDebug(5700) << " Emails {" << endl; |
1700 | QStringList e = emails(); | 1703 | QStringList e = emails(); |
1701 | QStringList::ConstIterator it; | 1704 | QStringList::ConstIterator it; |
1702 | for( it = e.begin(); it != e.end(); ++it ) { | 1705 | for( it = e.begin(); it != e.end(); ++it ) { |
1703 | kdDebug(5700) << " " << (*it) << endl; | 1706 | kdDebug(5700) << " " << (*it) << endl; |
1704 | } | 1707 | } |
1705 | kdDebug(5700) << " }" << endl; | 1708 | kdDebug(5700) << " }" << endl; |
1706 | 1709 | ||
1707 | kdDebug(5700) << " PhoneNumbers {" << endl; | 1710 | kdDebug(5700) << " PhoneNumbers {" << endl; |
1708 | PhoneNumber::List p = phoneNumbers(); | 1711 | PhoneNumber::List p = phoneNumbers(); |
1709 | PhoneNumber::List::ConstIterator it2; | 1712 | PhoneNumber::List::ConstIterator it2; |
1710 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { | 1713 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { |
1711 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; | 1714 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; |
1712 | } | 1715 | } |
1713 | kdDebug(5700) << " }" << endl; | 1716 | kdDebug(5700) << " }" << endl; |
1714 | 1717 | ||
1715 | Address::List a = addresses(); | 1718 | Address::List a = addresses(); |
1716 | Address::List::ConstIterator it3; | 1719 | Address::List::ConstIterator it3; |
1717 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { | 1720 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { |
1718 | (*it3).dump(); | 1721 | (*it3).dump(); |
1719 | } | 1722 | } |
1720 | 1723 | ||
1721 | kdDebug(5700) << " Keys {" << endl; | 1724 | kdDebug(5700) << " Keys {" << endl; |
1722 | Key::List k = keys(); | 1725 | Key::List k = keys(); |
1723 | Key::List::ConstIterator it4; | 1726 | Key::List::ConstIterator it4; |
1724 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { | 1727 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { |
1725 | kdDebug(5700) << " Type: " << int((*it4).type()) << | 1728 | kdDebug(5700) << " Type: " << int((*it4).type()) << |
1726 | " Key: " << (*it4).textData() << | 1729 | " Key: " << (*it4).textData() << |
1727 | " CustomString: " << (*it4).customTypeString() << endl; | 1730 | " CustomString: " << (*it4).customTypeString() << endl; |
1728 | } | 1731 | } |
1729 | kdDebug(5700) << " }" << endl; | 1732 | kdDebug(5700) << " }" << endl; |
1730 | 1733 | ||
1731 | kdDebug(5700) << "}" << endl; | 1734 | kdDebug(5700) << "}" << endl; |
1732 | } | 1735 | } |
1733 | 1736 | ||
1734 | 1737 | ||
1735 | void Addressee::insertAddress( const Address &address ) | 1738 | void Addressee::insertAddress( const Address &address ) |
1736 | { | 1739 | { |
1737 | detach(); | 1740 | detach(); |
1738 | mData->empty = false; | 1741 | mData->empty = false; |
1739 | 1742 | ||
1740 | Address::List::Iterator it; | 1743 | Address::List::Iterator it; |
1741 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1744 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1742 | if ( (*it).id() == address.id() ) { | 1745 | if ( (*it).id() == address.id() ) { |
1743 | *it = address; | 1746 | *it = address; |
1744 | return; | 1747 | return; |
1745 | } | 1748 | } |
1746 | } | 1749 | } |
1747 | mData->addresses.append( address ); | 1750 | mData->addresses.append( address ); |
1748 | } | 1751 | } |
1749 | 1752 | ||
1750 | void Addressee::removeAddress( const Address &address ) | 1753 | void Addressee::removeAddress( const Address &address ) |
1751 | { | 1754 | { |
1752 | detach(); | 1755 | detach(); |
1753 | 1756 | ||
1754 | Address::List::Iterator it; | 1757 | Address::List::Iterator it; |
1755 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1758 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1756 | if ( (*it).id() == address.id() ) { | 1759 | if ( (*it).id() == address.id() ) { |
1757 | mData->addresses.remove( it ); | 1760 | mData->addresses.remove( it ); |
1758 | return; | 1761 | return; |
1759 | } | 1762 | } |
1760 | } | 1763 | } |
1761 | } | 1764 | } |
1762 | 1765 | ||
1763 | Address Addressee::address( int type ) const | 1766 | Address Addressee::address( int type ) const |
1764 | { | 1767 | { |
1765 | Address address( type ); | 1768 | Address address( type ); |
1766 | Address::List::ConstIterator it; | 1769 | Address::List::ConstIterator it; |
1767 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1770 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1768 | if ( matchBinaryPatternA( (*it).type(), type ) ) { | 1771 | if ( matchBinaryPatternA( (*it).type(), type ) ) { |
1769 | if ( (*it).type() & Address::Pref ) | 1772 | if ( (*it).type() & Address::Pref ) |
1770 | return (*it); | 1773 | return (*it); |
1771 | else if ( address.isEmpty() ) | 1774 | else if ( address.isEmpty() ) |
1772 | address = (*it); | 1775 | address = (*it); |
1773 | } | 1776 | } |
1774 | } | 1777 | } |
1775 | 1778 | ||
1776 | return address; | 1779 | return address; |
1777 | } | 1780 | } |
1778 | 1781 | ||
1779 | Address::List Addressee::addresses() const | 1782 | Address::List Addressee::addresses() const |
1780 | { | 1783 | { |
1781 | return mData->addresses; | 1784 | return mData->addresses; |
1782 | } | 1785 | } |
1783 | 1786 | ||
1784 | Address::List Addressee::addresses( int type ) const | 1787 | Address::List Addressee::addresses( int type ) const |
1785 | { | 1788 | { |
1786 | Address::List list; | 1789 | Address::List list; |
1787 | 1790 | ||
1788 | Address::List::ConstIterator it; | 1791 | Address::List::ConstIterator it; |
1789 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1792 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1790 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1793 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1791 | list.append( *it ); | 1794 | list.append( *it ); |
1792 | } | 1795 | } |
1793 | } | 1796 | } |
1794 | 1797 | ||
1795 | return list; | 1798 | return list; |
1796 | } | 1799 | } |
1797 | 1800 | ||
1798 | Address Addressee::findAddress( const QString &id ) const | 1801 | Address Addressee::findAddress( const QString &id ) const |
1799 | { | 1802 | { |
1800 | Address::List::ConstIterator it; | 1803 | Address::List::ConstIterator it; |
1801 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1804 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1802 | if ( (*it).id() == id ) { | 1805 | if ( (*it).id() == id ) { |
1803 | return *it; | 1806 | return *it; |
1804 | } | 1807 | } |
1805 | } | 1808 | } |
1806 | return Address(); | 1809 | return Address(); |
1807 | } | 1810 | } |
1808 | 1811 | ||
1809 | void Addressee::insertCategory( const QString &c ) | 1812 | void Addressee::insertCategory( const QString &c ) |
1810 | { | 1813 | { |
1811 | detach(); | 1814 | detach(); |
1812 | mData->empty = false; | 1815 | mData->empty = false; |
1813 | 1816 | ||
1814 | if ( mData->categories.contains( c ) ) return; | 1817 | if ( mData->categories.contains( c ) ) return; |
1815 | 1818 | ||
1816 | mData->categories.append( c ); | 1819 | mData->categories.append( c ); |
1817 | } | 1820 | } |
1818 | 1821 | ||
1819 | void Addressee::removeCategory( const QString &c ) | 1822 | void Addressee::removeCategory( const QString &c ) |
1820 | { | 1823 | { |
1821 | detach(); | 1824 | detach(); |
1822 | 1825 | ||
1823 | QStringList::Iterator it = mData->categories.find( c ); | 1826 | QStringList::Iterator it = mData->categories.find( c ); |
1824 | if ( it == mData->categories.end() ) return; | 1827 | if ( it == mData->categories.end() ) return; |
1825 | 1828 | ||
1826 | mData->categories.remove( it ); | 1829 | mData->categories.remove( it ); |
1827 | } | 1830 | } |
1828 | 1831 | ||
1829 | bool Addressee::hasCategory( const QString &c ) const | 1832 | bool Addressee::hasCategory( const QString &c ) const |
1830 | { | 1833 | { |
1831 | return ( mData->categories.contains( c ) ); | 1834 | return ( mData->categories.contains( c ) ); |
1832 | } | 1835 | } |
1833 | 1836 | ||
1834 | void Addressee::setCategories( const QStringList &c ) | 1837 | void Addressee::setCategories( const QStringList &c ) |
1835 | { | 1838 | { |
1836 | detach(); | 1839 | detach(); |
1837 | mData->empty = false; | 1840 | mData->empty = false; |
1838 | 1841 | ||
1839 | mData->categories = c; | 1842 | mData->categories = c; |
1840 | } | 1843 | } |
1841 | 1844 | ||
1842 | QStringList Addressee::categories() const | 1845 | QStringList Addressee::categories() const |
1843 | { | 1846 | { |
1844 | return mData->categories; | 1847 | return mData->categories; |
1845 | } | 1848 | } |
1846 | 1849 | ||
1847 | void Addressee::insertCustom( const QString &app, const QString &name, | 1850 | void Addressee::insertCustom( const QString &app, const QString &name, |
1848 | const QString &value ) | 1851 | const QString &value ) |
1849 | { | 1852 | { |
1850 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; | 1853 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; |
1851 | 1854 | ||
1852 | detach(); | 1855 | detach(); |
1853 | mData->empty = false; | 1856 | mData->empty = false; |
1854 | 1857 | ||
1855 | QString qualifiedName = app + "-" + name + ":"; | 1858 | QString qualifiedName = app + "-" + name + ":"; |
1856 | 1859 | ||
1857 | QStringList::Iterator it; | 1860 | QStringList::Iterator it; |
1858 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1861 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1859 | if ( (*it).startsWith( qualifiedName ) ) { | 1862 | if ( (*it).startsWith( qualifiedName ) ) { |
1860 | (*it) = qualifiedName + value; | 1863 | (*it) = qualifiedName + value; |
1861 | return; | 1864 | return; |
1862 | } | 1865 | } |
1863 | } | 1866 | } |
1864 | mData->custom.append( qualifiedName + value ); | 1867 | mData->custom.append( qualifiedName + value ); |
1865 | } | 1868 | } |
1866 | 1869 | ||
1867 | void Addressee::removeCustom( const QString &app, const QString &name) | 1870 | void Addressee::removeCustom( const QString &app, const QString &name) |
1868 | { | 1871 | { |
1869 | detach(); | 1872 | detach(); |
1870 | 1873 | ||
1871 | QString qualifiedName = app + "-" + name + ":"; | 1874 | QString qualifiedName = app + "-" + name + ":"; |
1872 | 1875 | ||
1873 | QStringList::Iterator it; | 1876 | QStringList::Iterator it; |
1874 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1877 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1875 | if ( (*it).startsWith( qualifiedName ) ) { | 1878 | if ( (*it).startsWith( qualifiedName ) ) { |
1876 | mData->custom.remove( it ); | 1879 | mData->custom.remove( it ); |
1877 | return; | 1880 | return; |
1878 | } | 1881 | } |
1879 | } | 1882 | } |
1880 | } | 1883 | } |
1881 | 1884 | ||
1882 | QString Addressee::custom( const QString &app, const QString &name ) const | 1885 | QString Addressee::custom( const QString &app, const QString &name ) const |
1883 | { | 1886 | { |
1884 | QString qualifiedName = app + "-" + name + ":"; | 1887 | QString qualifiedName = app + "-" + name + ":"; |
1885 | QString value; | 1888 | QString value; |
1886 | 1889 | ||
1887 | QStringList::ConstIterator it; | 1890 | QStringList::ConstIterator it; |
1888 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1891 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1889 | if ( (*it).startsWith( qualifiedName ) ) { | 1892 | if ( (*it).startsWith( qualifiedName ) ) { |
1890 | value = (*it).mid( (*it).find( ":" ) + 1 ); | 1893 | value = (*it).mid( (*it).find( ":" ) + 1 ); |
1891 | break; | 1894 | break; |
1892 | } | 1895 | } |
1893 | } | 1896 | } |
1894 | 1897 | ||
1895 | return value; | 1898 | return value; |
1896 | } | 1899 | } |
1897 | 1900 | ||
1898 | void Addressee::setCustoms( const QStringList &l ) | 1901 | void Addressee::setCustoms( const QStringList &l ) |
1899 | { | 1902 | { |
1900 | detach(); | 1903 | detach(); |
1901 | mData->empty = false; | 1904 | mData->empty = false; |
1902 | 1905 | ||
1903 | mData->custom = l; | 1906 | mData->custom = l; |
1904 | } | 1907 | } |
1905 | 1908 | ||
1906 | QStringList Addressee::customs() const | 1909 | QStringList Addressee::customs() const |
1907 | { | 1910 | { |
1908 | return mData->custom; | 1911 | return mData->custom; |
1909 | } | 1912 | } |
1910 | 1913 | ||
1911 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, | 1914 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, |
1912 | QString &email) | 1915 | QString &email) |
1913 | { | 1916 | { |
1914 | int startPos, endPos, len; | 1917 | int startPos, endPos, len; |
1915 | QString partA, partB, result; | 1918 | QString partA, partB, result; |
1916 | char endCh = '>'; | 1919 | char endCh = '>'; |
1917 | 1920 | ||
1918 | startPos = rawEmail.find('<'); | 1921 | startPos = rawEmail.find('<'); |
1919 | if (startPos < 0) | 1922 | if (startPos < 0) |
1920 | { | 1923 | { |
1921 | startPos = rawEmail.find('('); | 1924 | startPos = rawEmail.find('('); |
1922 | endCh = ')'; | 1925 | endCh = ')'; |
1923 | } | 1926 | } |
1924 | if (startPos < 0) | 1927 | if (startPos < 0) |
1925 | { | 1928 | { |
1926 | // We couldn't find any separators, so we assume the whole string | 1929 | // We couldn't find any separators, so we assume the whole string |
1927 | // is the email address | 1930 | // is the email address |
1928 | email = rawEmail; | 1931 | email = rawEmail; |
1929 | fullName = ""; | 1932 | fullName = ""; |
1930 | } | 1933 | } |
1931 | else | 1934 | else |
1932 | { | 1935 | { |
1933 | // We have a start position, try to find an end | 1936 | // We have a start position, try to find an end |
1934 | endPos = rawEmail.find(endCh, startPos+1); | 1937 | endPos = rawEmail.find(endCh, startPos+1); |
1935 | 1938 | ||
1936 | if (endPos < 0) | 1939 | if (endPos < 0) |
1937 | { | 1940 | { |
1938 | // We couldn't find the end of the email address. We can only | 1941 | // We couldn't find the end of the email address. We can only |
1939 | // assume the entire string is the email address. | 1942 | // assume the entire string is the email address. |
1940 | email = rawEmail; | 1943 | email = rawEmail; |
1941 | fullName = ""; | 1944 | fullName = ""; |
1942 | } | 1945 | } |
1943 | else | 1946 | else |
1944 | { | 1947 | { |
1945 | // We have a start and end to the email address | 1948 | // We have a start and end to the email address |
1946 | 1949 | ||
1947 | // Grab the name part | 1950 | // Grab the name part |
1948 | fullName = rawEmail.left(startPos).stripWhiteSpace(); | 1951 | fullName = rawEmail.left(startPos).stripWhiteSpace(); |
1949 | 1952 | ||
1950 | // grab the email part | 1953 | // grab the email part |
1951 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); | 1954 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); |
1952 | 1955 | ||
1953 | // Check that we do not have any extra characters on the end of the | 1956 | // Check that we do not have any extra characters on the end of the |
1954 | // strings | 1957 | // strings |
1955 | len = fullName.length(); | 1958 | len = fullName.length(); |
1956 | if (fullName[0]=='"' && fullName[len-1]=='"') | 1959 | if (fullName[0]=='"' && fullName[len-1]=='"') |
1957 | fullName = fullName.mid(1, len-2); | 1960 | fullName = fullName.mid(1, len-2); |
1958 | else if (fullName[0]=='<' && fullName[len-1]=='>') | 1961 | else if (fullName[0]=='<' && fullName[len-1]=='>') |
1959 | fullName = fullName.mid(1, len-2); | 1962 | fullName = fullName.mid(1, len-2); |
1960 | else if (fullName[0]=='(' && fullName[len-1]==')') | 1963 | else if (fullName[0]=='(' && fullName[len-1]==')') |
1961 | fullName = fullName.mid(1, len-2); | 1964 | fullName = fullName.mid(1, len-2); |
1962 | } | 1965 | } |
1963 | } | 1966 | } |
1964 | } | 1967 | } |
1965 | 1968 | ||
1966 | void Addressee::setResource( Resource *resource ) | 1969 | void Addressee::setResource( Resource *resource ) |
1967 | { | 1970 | { |
1968 | detach(); | 1971 | detach(); |
1969 | mData->resource = resource; | 1972 | mData->resource = resource; |
1970 | } | 1973 | } |
1971 | 1974 | ||
1972 | Resource *Addressee::resource() const | 1975 | Resource *Addressee::resource() const |
1973 | { | 1976 | { |
1974 | return mData->resource; | 1977 | return mData->resource; |
1975 | } | 1978 | } |
1976 | 1979 | ||
1977 | //US | 1980 | //US |
1978 | QString Addressee::resourceLabel() | 1981 | QString Addressee::resourceLabel() |
1979 | { | 1982 | { |
1980 | return i18n("Resource"); | 1983 | return i18n("Resource"); |
1981 | } | 1984 | } |
1982 | 1985 | ||
1983 | void Addressee::setChanged( bool value ) | 1986 | void Addressee::setChanged( bool value ) |
1984 | { | 1987 | { |
1985 | detach(); | 1988 | detach(); |
1986 | mData->changed = value; | 1989 | mData->changed = value; |
1987 | } | 1990 | } |
1988 | 1991 | ||
1989 | bool Addressee::changed() const | 1992 | bool Addressee::changed() const |
1990 | { | 1993 | { |
1991 | return mData->changed; | 1994 | return mData->changed; |
1992 | } | 1995 | } |
1993 | 1996 | ||
1994 | void Addressee::setTagged( bool value ) | 1997 | void Addressee::setTagged( bool value ) |
1995 | { | 1998 | { |
1996 | detach(); | 1999 | detach(); |
1997 | mData->tagged = value; | 2000 | mData->tagged = value; |
1998 | } | 2001 | } |
1999 | 2002 | ||
2000 | bool Addressee::tagged() const | 2003 | bool Addressee::tagged() const |
2001 | { | 2004 | { |
2002 | return mData->tagged; | 2005 | return mData->tagged; |
2003 | } | 2006 | } |
2004 | 2007 | ||
2005 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 2008 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
2006 | { | 2009 | { |
2007 | if (!a.mData) return s; | 2010 | if (!a.mData) return s; |
2008 | 2011 | ||
2009 | s << a.uid(); | 2012 | s << a.uid(); |
2010 | 2013 | ||
2011 | s << a.mData->name; | 2014 | s << a.mData->name; |
2012 | s << a.mData->formattedName; | 2015 | s << a.mData->formattedName; |
2013 | s << a.mData->familyName; | 2016 | s << a.mData->familyName; |
2014 | s << a.mData->givenName; | 2017 | s << a.mData->givenName; |
2015 | s << a.mData->additionalName; | 2018 | s << a.mData->additionalName; |
2016 | s << a.mData->prefix; | 2019 | s << a.mData->prefix; |
2017 | s << a.mData->suffix; | 2020 | s << a.mData->suffix; |
2018 | s << a.mData->nickName; | 2021 | s << a.mData->nickName; |
2019 | s << a.mData->birthday; | 2022 | s << a.mData->birthday; |
2020 | s << a.mData->mailer; | 2023 | s << a.mData->mailer; |
2021 | s << a.mData->timeZone; | 2024 | s << a.mData->timeZone; |
2022 | s << a.mData->geo; | 2025 | s << a.mData->geo; |
2023 | s << a.mData->title; | 2026 | s << a.mData->title; |
2024 | s << a.mData->role; | 2027 | s << a.mData->role; |
2025 | s << a.mData->organization; | 2028 | s << a.mData->organization; |
2026 | s << a.mData->note; | 2029 | s << a.mData->note; |
2027 | s << a.mData->productId; | 2030 | s << a.mData->productId; |
2028 | s << a.mData->revision; | 2031 | s << a.mData->revision; |
2029 | s << a.mData->sortString; | 2032 | s << a.mData->sortString; |
2030 | s << a.mData->url; | 2033 | s << a.mData->url; |
2031 | s << a.mData->secrecy; | 2034 | s << a.mData->secrecy; |
2032 | s << a.mData->logo; | 2035 | s << a.mData->logo; |
2033 | s << a.mData->photo; | 2036 | s << a.mData->photo; |
2034 | s << a.mData->sound; | 2037 | s << a.mData->sound; |
2035 | s << a.mData->agent; | 2038 | s << a.mData->agent; |
2036 | s << a.mData->phoneNumbers; | 2039 | s << a.mData->phoneNumbers; |
2037 | s << a.mData->addresses; | 2040 | s << a.mData->addresses; |
2038 | s << a.mData->emails; | 2041 | s << a.mData->emails; |
2039 | s << a.mData->categories; | 2042 | s << a.mData->categories; |
2040 | s << a.mData->custom; | 2043 | s << a.mData->custom; |
2041 | s << a.mData->keys; | 2044 | s << a.mData->keys; |
2042 | return s; | 2045 | return s; |
2043 | } | 2046 | } |
2044 | 2047 | ||
2045 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) | 2048 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) |
2046 | { | 2049 | { |
2047 | if (!a.mData) return s; | 2050 | if (!a.mData) return s; |
2048 | 2051 | ||
2049 | s >> a.mData->uid; | 2052 | s >> a.mData->uid; |
2050 | 2053 | ||
2051 | s >> a.mData->name; | 2054 | s >> a.mData->name; |
2052 | s >> a.mData->formattedName; | 2055 | s >> a.mData->formattedName; |
2053 | s >> a.mData->familyName; | 2056 | s >> a.mData->familyName; |
2054 | s >> a.mData->givenName; | 2057 | s >> a.mData->givenName; |
2055 | s >> a.mData->additionalName; | 2058 | s >> a.mData->additionalName; |
2056 | s >> a.mData->prefix; | 2059 | s >> a.mData->prefix; |
2057 | s >> a.mData->suffix; | 2060 | s >> a.mData->suffix; |
2058 | s >> a.mData->nickName; | 2061 | s >> a.mData->nickName; |
2059 | s >> a.mData->birthday; | 2062 | s >> a.mData->birthday; |
2060 | s >> a.mData->mailer; | 2063 | s >> a.mData->mailer; |
2061 | s >> a.mData->timeZone; | 2064 | s >> a.mData->timeZone; |
2062 | s >> a.mData->geo; | 2065 | s >> a.mData->geo; |
2063 | s >> a.mData->title; | 2066 | s >> a.mData->title; |
2064 | s >> a.mData->role; | 2067 | s >> a.mData->role; |
2065 | s >> a.mData->organization; | 2068 | s >> a.mData->organization; |
2066 | s >> a.mData->note; | 2069 | s >> a.mData->note; |
2067 | s >> a.mData->productId; | 2070 | s >> a.mData->productId; |
2068 | s >> a.mData->revision; | 2071 | s >> a.mData->revision; |
2069 | s >> a.mData->sortString; | 2072 | s >> a.mData->sortString; |
2070 | s >> a.mData->url; | 2073 | s >> a.mData->url; |
2071 | s >> a.mData->secrecy; | 2074 | s >> a.mData->secrecy; |
2072 | s >> a.mData->logo; | 2075 | s >> a.mData->logo; |
2073 | s >> a.mData->photo; | 2076 | s >> a.mData->photo; |
2074 | s >> a.mData->sound; | 2077 | s >> a.mData->sound; |
2075 | s >> a.mData->agent; | 2078 | s >> a.mData->agent; |
2076 | s >> a.mData->phoneNumbers; | 2079 | s >> a.mData->phoneNumbers; |
2077 | s >> a.mData->addresses; | 2080 | s >> a.mData->addresses; |
2078 | s >> a.mData->emails; | 2081 | s >> a.mData->emails; |
2079 | s >> a.mData->categories; | 2082 | s >> a.mData->categories; |
2080 | s >> a.mData->custom; | 2083 | s >> a.mData->custom; |
2081 | s >> a.mData->keys; | 2084 | s >> a.mData->keys; |
2082 | 2085 | ||
2083 | a.mData->empty = false; | 2086 | a.mData->empty = false; |
2084 | 2087 | ||
2085 | return s; | 2088 | return s; |
2086 | } | 2089 | } |
2087 | bool matchBinaryPattern( int value, int pattern ) | 2090 | bool matchBinaryPattern( int value, int pattern ) |
2088 | { | 2091 | { |
2089 | /** | 2092 | /** |
2090 | We want to match all telephonnumbers/addresses which have the bits in the | 2093 | We want to match all telephonnumbers/addresses which have the bits in the |
2091 | pattern set. More are allowed. | 2094 | pattern set. More are allowed. |
2092 | if pattern == 0 we have a special handling, then we want only those with | 2095 | if pattern == 0 we have a special handling, then we want only those with |
2093 | exactly no bit set. | 2096 | exactly no bit set. |
2094 | */ | 2097 | */ |
2095 | if ( pattern == 0 ) | 2098 | if ( pattern == 0 ) |
2096 | return ( value == 0 ); | 2099 | return ( value == 0 ); |
2097 | else | 2100 | else |
2098 | return ( pattern == ( pattern & value ) ); | 2101 | return ( pattern == ( pattern & value ) ); |
2099 | } | 2102 | } |
2100 | 2103 | ||
2101 | bool matchBinaryPatternP( int value, int pattern ) | 2104 | bool matchBinaryPatternP( int value, int pattern ) |
2102 | { | 2105 | { |
2103 | 2106 | ||
2104 | if ( pattern == 0 ) | 2107 | if ( pattern == 0 ) |
2105 | return ( value == 0 ); | 2108 | return ( value == 0 ); |
2106 | else | 2109 | else |
2107 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); | 2110 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); |
2108 | } | 2111 | } |
2109 | bool matchBinaryPatternA( int value, int pattern ) | 2112 | bool matchBinaryPatternA( int value, int pattern ) |
2110 | { | 2113 | { |
2111 | 2114 | ||
2112 | if ( pattern == 0 ) | 2115 | if ( pattern == 0 ) |
2113 | return ( value == 0 ); | 2116 | return ( value == 0 ); |
2114 | else | 2117 | else |
2115 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); | 2118 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); |
2116 | } | 2119 | } |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index efae874..e56e46a 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1,2916 +1,2916 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program 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 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /*s | 24 | /*s |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "kabcore.h" | 31 | #include "kabcore.h" |
32 | 32 | ||
33 | #include <stdaddressbook.h> | 33 | #include <stdaddressbook.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kfiledialog.h> | 35 | #include <kfiledialog.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qlabel.h> | 37 | #include <qlabel.h> |
38 | #include <qregexp.h> | 38 | #include <qregexp.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
41 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
42 | #include <qprogressbar.h> | 42 | #include <qprogressbar.h> |
43 | #include <libkdepim/phoneaccess.h> | 43 | #include <libkdepim/phoneaccess.h> |
44 | 44 | ||
45 | #ifndef KAB_EMBEDDED | 45 | #ifndef KAB_EMBEDDED |
46 | #include <qclipboard.h> | 46 | #include <qclipboard.h> |
47 | #include <qdir.h> | 47 | #include <qdir.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | #include <qapplicaton.h> | 49 | #include <qapplicaton.h> |
50 | #include <qprogressbar.h> | 50 | #include <qprogressbar.h> |
51 | #include <qlayout.h> | 51 | #include <qlayout.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qvbox.h> | 53 | #include <qvbox.h> |
54 | #include <kabc/addresseelist.h> | 54 | #include <kabc/addresseelist.h> |
55 | #include <kabc/errorhandler.h> | 55 | #include <kabc/errorhandler.h> |
56 | #include <kabc/resource.h> | 56 | #include <kabc/resource.h> |
57 | #include <kabc/vcardconverter.h> | 57 | #include <kabc/vcardconverter.h> |
58 | #include <kapplication.h> | 58 | #include <kapplication.h> |
59 | #include <kactionclasses.h> | 59 | #include <kactionclasses.h> |
60 | #include <kcmultidialog.h> | 60 | #include <kcmultidialog.h> |
61 | #include <kdebug.h> | 61 | #include <kdebug.h> |
62 | #include <kdeversion.h> | 62 | #include <kdeversion.h> |
63 | #include <kkeydialog.h> | 63 | #include <kkeydialog.h> |
64 | #include <kmessagebox.h> | 64 | #include <kmessagebox.h> |
65 | #include <kprinter.h> | 65 | #include <kprinter.h> |
66 | #include <kprotocolinfo.h> | 66 | #include <kprotocolinfo.h> |
67 | #include <kresources/selectdialog.h> | 67 | #include <kresources/selectdialog.h> |
68 | #include <kstandarddirs.h> | 68 | #include <kstandarddirs.h> |
69 | #include <ktempfile.h> | 69 | #include <ktempfile.h> |
70 | #include <kxmlguiclient.h> | 70 | #include <kxmlguiclient.h> |
71 | #include <kaboutdata.h> | 71 | #include <kaboutdata.h> |
72 | #include <libkdepim/categoryselectdialog.h> | 72 | #include <libkdepim/categoryselectdialog.h> |
73 | 73 | ||
74 | #include "addresseeutil.h" | 74 | #include "addresseeutil.h" |
75 | #include "addresseeeditordialog.h" | 75 | #include "addresseeeditordialog.h" |
76 | #include "extensionmanager.h" | 76 | #include "extensionmanager.h" |
77 | #include "kstdaction.h" | 77 | #include "kstdaction.h" |
78 | #include "kaddressbookservice.h" | 78 | #include "kaddressbookservice.h" |
79 | #include "ldapsearchdialog.h" | 79 | #include "ldapsearchdialog.h" |
80 | #include "printing/printingwizard.h" | 80 | #include "printing/printingwizard.h" |
81 | #else // KAB_EMBEDDED | 81 | #else // KAB_EMBEDDED |
82 | 82 | ||
83 | #include <kapplication.h> | 83 | #include <kapplication.h> |
84 | #include "KDGanttMinimizeSplitter.h" | 84 | #include "KDGanttMinimizeSplitter.h" |
85 | #include "kaddressbookmain.h" | 85 | #include "kaddressbookmain.h" |
86 | #include "kactioncollection.h" | 86 | #include "kactioncollection.h" |
87 | #include "addresseedialog.h" | 87 | #include "addresseedialog.h" |
88 | //US | 88 | //US |
89 | #include <addresseeview.h> | 89 | #include <addresseeview.h> |
90 | 90 | ||
91 | #include <qapp.h> | 91 | #include <qapp.h> |
92 | #include <qmenubar.h> | 92 | #include <qmenubar.h> |
93 | //#include <qtoolbar.h> | 93 | //#include <qtoolbar.h> |
94 | #include <qmessagebox.h> | 94 | #include <qmessagebox.h> |
95 | #include <kdebug.h> | 95 | #include <kdebug.h> |
96 | #include <kiconloader.h> // needed for SmallIcon | 96 | #include <kiconloader.h> // needed for SmallIcon |
97 | #include <kresources/kcmkresources.h> | 97 | #include <kresources/kcmkresources.h> |
98 | #include <ktoolbar.h> | 98 | #include <ktoolbar.h> |
99 | 99 | ||
100 | 100 | ||
101 | //#include <qlabel.h> | 101 | //#include <qlabel.h> |
102 | 102 | ||
103 | 103 | ||
104 | #ifndef DESKTOP_VERSION | 104 | #ifndef DESKTOP_VERSION |
105 | #include <qpe/ir.h> | 105 | #include <qpe/ir.h> |
106 | #include <qpe/qpemenubar.h> | 106 | #include <qpe/qpemenubar.h> |
107 | #include <qtopia/qcopenvelope_qws.h> | 107 | #include <qtopia/qcopenvelope_qws.h> |
108 | #else | 108 | #else |
109 | 109 | ||
110 | #include <qmenubar.h> | 110 | #include <qmenubar.h> |
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | #endif // KAB_EMBEDDED | 113 | #endif // KAB_EMBEDDED |
114 | #include "kcmconfigs/kcmkabconfig.h" | 114 | #include "kcmconfigs/kcmkabconfig.h" |
115 | #include "kcmconfigs/kcmkdepimconfig.h" | 115 | #include "kcmconfigs/kcmkdepimconfig.h" |
116 | #include "kpimglobalprefs.h" | 116 | #include "kpimglobalprefs.h" |
117 | #include "externalapphandler.h" | 117 | #include "externalapphandler.h" |
118 | 118 | ||
119 | 119 | ||
120 | #include <kresources/selectdialog.h> | 120 | #include <kresources/selectdialog.h> |
121 | #include <kmessagebox.h> | 121 | #include <kmessagebox.h> |
122 | 122 | ||
123 | #include <picture.h> | 123 | #include <picture.h> |
124 | #include <resource.h> | 124 | #include <resource.h> |
125 | 125 | ||
126 | //US#include <qsplitter.h> | 126 | //US#include <qsplitter.h> |
127 | #include <qmap.h> | 127 | #include <qmap.h> |
128 | #include <qdir.h> | 128 | #include <qdir.h> |
129 | #include <qfile.h> | 129 | #include <qfile.h> |
130 | #include <qvbox.h> | 130 | #include <qvbox.h> |
131 | #include <qlayout.h> | 131 | #include <qlayout.h> |
132 | #include <qclipboard.h> | 132 | #include <qclipboard.h> |
133 | #include <qtextstream.h> | 133 | #include <qtextstream.h> |
134 | 134 | ||
135 | #include <libkdepim/categoryselectdialog.h> | 135 | #include <libkdepim/categoryselectdialog.h> |
136 | #include <kabc/vcardconverter.h> | 136 | #include <kabc/vcardconverter.h> |
137 | 137 | ||
138 | 138 | ||
139 | #include "addresseeutil.h" | 139 | #include "addresseeutil.h" |
140 | #include "undocmds.h" | 140 | #include "undocmds.h" |
141 | #include "addresseeeditordialog.h" | 141 | #include "addresseeeditordialog.h" |
142 | #include "viewmanager.h" | 142 | #include "viewmanager.h" |
143 | #include "details/detailsviewcontainer.h" | 143 | #include "details/detailsviewcontainer.h" |
144 | #include "kabprefs.h" | 144 | #include "kabprefs.h" |
145 | #include "xxportmanager.h" | 145 | #include "xxportmanager.h" |
146 | #include "incsearchwidget.h" | 146 | #include "incsearchwidget.h" |
147 | #include "jumpbuttonbar.h" | 147 | #include "jumpbuttonbar.h" |
148 | #include "extensionmanager.h" | 148 | #include "extensionmanager.h" |
149 | #include "addresseeconfig.h" | 149 | #include "addresseeconfig.h" |
150 | #include <kcmultidialog.h> | 150 | #include <kcmultidialog.h> |
151 | 151 | ||
152 | #ifdef _WIN32_ | 152 | #ifdef _WIN32_ |
153 | 153 | ||
154 | #include "kaimportoldialog.h" | 154 | #include "kaimportoldialog.h" |
155 | #else | 155 | #else |
156 | #include <unistd.h> | 156 | #include <unistd.h> |
157 | #endif | 157 | #endif |
158 | // sync includes | 158 | // sync includes |
159 | #include <libkdepim/ksyncprofile.h> | 159 | #include <libkdepim/ksyncprofile.h> |
160 | #include <libkdepim/ksyncprefsdialog.h> | 160 | #include <libkdepim/ksyncprefsdialog.h> |
161 | 161 | ||
162 | class KAex2phonePrefs : public QDialog | 162 | class KAex2phonePrefs : public QDialog |
163 | { | 163 | { |
164 | public: | 164 | public: |
165 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : | 165 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : |
166 | QDialog( parent, name, true ) | 166 | QDialog( parent, name, true ) |
167 | { | 167 | { |
168 | setCaption( i18n("Export to phone options") ); | 168 | setCaption( i18n("Export to phone options") ); |
169 | QVBoxLayout* lay = new QVBoxLayout( this ); | 169 | QVBoxLayout* lay = new QVBoxLayout( this ); |
170 | lay->setSpacing( 3 ); | 170 | lay->setSpacing( 3 ); |
171 | lay->setMargin( 3 ); | 171 | lay->setMargin( 3 ); |
172 | QLabel *lab; | 172 | QLabel *lab; |
173 | lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); | 173 | lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); |
174 | lab->setAlignment (AlignHCenter ); | 174 | lab->setAlignment (AlignHCenter ); |
175 | QHBox* temphb; | 175 | QHBox* temphb; |
176 | temphb = new QHBox( this ); | 176 | temphb = new QHBox( this ); |
177 | new QLabel( i18n("I/O device: "), temphb ); | 177 | new QLabel( i18n("I/O device: "), temphb ); |
178 | mPhoneDevice = new QLineEdit( temphb); | 178 | mPhoneDevice = new QLineEdit( temphb); |
179 | lay->addWidget( temphb ); | 179 | lay->addWidget( temphb ); |
180 | temphb = new QHBox( this ); | 180 | temphb = new QHBox( this ); |
181 | new QLabel( i18n("Connection: "), temphb ); | 181 | new QLabel( i18n("Connection: "), temphb ); |
182 | mPhoneConnection = new QLineEdit( temphb); | 182 | mPhoneConnection = new QLineEdit( temphb); |
183 | lay->addWidget( temphb ); | 183 | lay->addWidget( temphb ); |
184 | temphb = new QHBox( this ); | 184 | temphb = new QHBox( this ); |
185 | new QLabel( i18n("Model(opt.): "), temphb ); | 185 | new QLabel( i18n("Model(opt.): "), temphb ); |
186 | mPhoneModel = new QLineEdit( temphb); | 186 | mPhoneModel = new QLineEdit( temphb); |
187 | lay->addWidget( temphb ); | 187 | lay->addWidget( temphb ); |
188 | // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); | 188 | // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); |
189 | // lay->addWidget( mWriteToSim ); | 189 | // lay->addWidget( mWriteToSim ); |
190 | lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); | 190 | lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); |
191 | lab->setAlignment (AlignHCenter ); | 191 | lab->setAlignment (AlignHCenter ); |
192 | QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); | 192 | QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); |
193 | lay->addWidget( ok ); | 193 | lay->addWidget( ok ); |
194 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 194 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
195 | lay->addWidget( cancel ); | 195 | lay->addWidget( cancel ); |
196 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 196 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
197 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 197 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
198 | resize( 220, 240 ); | 198 | resize( 220, 240 ); |
199 | 199 | ||
200 | } | 200 | } |
201 | 201 | ||
202 | public: | 202 | public: |
203 | QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; | 203 | QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; |
204 | QCheckBox* mWriteToSim; | 204 | QCheckBox* mWriteToSim; |
205 | }; | 205 | }; |
206 | 206 | ||
207 | 207 | ||
208 | bool pasteWithNewUid = true; | 208 | bool pasteWithNewUid = true; |
209 | 209 | ||
210 | #ifdef KAB_EMBEDDED | 210 | #ifdef KAB_EMBEDDED |
211 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) | 211 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) |
212 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), | 212 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
213 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ | 213 | mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ |
214 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) | 214 | mReadWrite( readWrite ), mModified( false ), mMainWindow(client) |
215 | #else //KAB_EMBEDDED | 215 | #else //KAB_EMBEDDED |
216 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) | 216 | KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) |
217 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), | 217 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
218 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), | 218 | mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), |
219 | mReadWrite( readWrite ), mModified( false ) | 219 | mReadWrite( readWrite ), mModified( false ) |
220 | #endif //KAB_EMBEDDED | 220 | #endif //KAB_EMBEDDED |
221 | { | 221 | { |
222 | // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 222 | // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
223 | // syncManager->setBlockSave(false); | 223 | // syncManager->setBlockSave(false); |
224 | mExtensionBarSplitter = 0; | 224 | mExtensionBarSplitter = 0; |
225 | mIsPart = !parent->inherits( "KAddressBookMain" ); | 225 | mIsPart = !parent->inherits( "KAddressBookMain" ); |
226 | mAddressBook = KABC::StdAddressBook::self(); | 226 | mAddressBook = KABC::StdAddressBook::self(); |
227 | KABC::StdAddressBook::setAutomaticSave( false ); | 227 | KABC::StdAddressBook::setAutomaticSave( false ); |
228 | 228 | ||
229 | #ifndef KAB_EMBEDDED | 229 | #ifndef KAB_EMBEDDED |
230 | mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); | 230 | mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); |
231 | #endif //KAB_EMBEDDED | 231 | #endif //KAB_EMBEDDED |
232 | 232 | ||
233 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), | 233 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), |
234 | SLOT( addressBookChanged() ) ); | 234 | SLOT( addressBookChanged() ) ); |
235 | 235 | ||
236 | #if 0 | 236 | #if 0 |
237 | // LP moved to addressbook init method | 237 | // LP moved to addressbook init method |
238 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, | 238 | mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, |
239 | "X-Department", "KADDRESSBOOK" ); | 239 | "X-Department", "KADDRESSBOOK" ); |
240 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 240 | mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
241 | "X-Profession", "KADDRESSBOOK" ); | 241 | "X-Profession", "KADDRESSBOOK" ); |
242 | mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 242 | mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
243 | "X-AssistantsName", "KADDRESSBOOK" ); | 243 | "X-AssistantsName", "KADDRESSBOOK" ); |
244 | mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 244 | mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
245 | "X-ManagersName", "KADDRESSBOOK" ); | 245 | "X-ManagersName", "KADDRESSBOOK" ); |
246 | mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 246 | mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
247 | "X-SpousesName", "KADDRESSBOOK" ); | 247 | "X-SpousesName", "KADDRESSBOOK" ); |
248 | mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, | 248 | mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, |
249 | "X-Office", "KADDRESSBOOK" ); | 249 | "X-Office", "KADDRESSBOOK" ); |
250 | mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 250 | mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
251 | "X-IMAddress", "KADDRESSBOOK" ); | 251 | "X-IMAddress", "KADDRESSBOOK" ); |
252 | mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 252 | mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
253 | "X-Anniversary", "KADDRESSBOOK" ); | 253 | "X-Anniversary", "KADDRESSBOOK" ); |
254 | 254 | ||
255 | //US added this field to become compatible with Opie/qtopia addressbook | 255 | //US added this field to become compatible with Opie/qtopia addressbook |
256 | // values can be "female" or "male" or "". An empty field represents undefined. | 256 | // values can be "female" or "male" or "". An empty field represents undefined. |
257 | mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 257 | mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
258 | "X-Gender", "KADDRESSBOOK" ); | 258 | "X-Gender", "KADDRESSBOOK" ); |
259 | mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, | 259 | mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, |
260 | "X-Children", "KADDRESSBOOK" ); | 260 | "X-Children", "KADDRESSBOOK" ); |
261 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 261 | mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
262 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 262 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
263 | #endif | 263 | #endif |
264 | initGUI(); | 264 | initGUI(); |
265 | 265 | ||
266 | mIncSearchWidget->setFocus(); | 266 | mIncSearchWidget->setFocus(); |
267 | 267 | ||
268 | 268 | ||
269 | connect( mViewManager, SIGNAL( selected( const QString& ) ), | 269 | connect( mViewManager, SIGNAL( selected( const QString& ) ), |
270 | SLOT( setContactSelected( const QString& ) ) ); | 270 | SLOT( setContactSelected( const QString& ) ) ); |
271 | connect( mViewManager, SIGNAL( executed( const QString& ) ), | 271 | connect( mViewManager, SIGNAL( executed( const QString& ) ), |
272 | SLOT( executeContact( const QString& ) ) ); | 272 | SLOT( executeContact( const QString& ) ) ); |
273 | 273 | ||
274 | connect( mViewManager, SIGNAL( deleteRequest( ) ), | 274 | connect( mViewManager, SIGNAL( deleteRequest( ) ), |
275 | SLOT( deleteContacts( ) ) ); | 275 | SLOT( deleteContacts( ) ) ); |
276 | connect( mViewManager, SIGNAL( modified() ), | 276 | connect( mViewManager, SIGNAL( modified() ), |
277 | SLOT( setModified() ) ); | 277 | SLOT( setModified() ) ); |
278 | 278 | ||
279 | connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); | 279 | connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); |
280 | connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); | 280 | connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); |
281 | 281 | ||
282 | connect( mXXPortManager, SIGNAL( modified() ), | 282 | connect( mXXPortManager, SIGNAL( modified() ), |
283 | SLOT( setModified() ) ); | 283 | SLOT( setModified() ) ); |
284 | 284 | ||
285 | connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), | 285 | connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), |
286 | SLOT( incrementalSearch( const QString& ) ) ); | 286 | SLOT( incrementalSearch( const QString& ) ) ); |
287 | connect( mIncSearchWidget, SIGNAL( fieldChanged() ), | 287 | connect( mIncSearchWidget, SIGNAL( fieldChanged() ), |
288 | mJumpButtonBar, SLOT( recreateButtons() ) ); | 288 | mJumpButtonBar, SLOT( recreateButtons() ) ); |
289 | 289 | ||
290 | connect( mDetails, SIGNAL( sendEmail( const QString& ) ), | 290 | connect( mDetails, SIGNAL( sendEmail( const QString& ) ), |
291 | SLOT( sendMail( const QString& ) ) ); | 291 | SLOT( sendMail( const QString& ) ) ); |
292 | 292 | ||
293 | 293 | ||
294 | connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); | 294 | connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); |
295 | connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); | 295 | connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); |
296 | connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); | 296 | connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); |
297 | 297 | ||
298 | 298 | ||
299 | #ifndef KAB_EMBEDDED | 299 | #ifndef KAB_EMBEDDED |
300 | connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), | 300 | connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), |
301 | mXXPortManager, SLOT( importVCard( const KURL& ) ) ); | 301 | mXXPortManager, SLOT( importVCard( const KURL& ) ) ); |
302 | 302 | ||
303 | connect( mDetails, SIGNAL( browse( const QString& ) ), | 303 | connect( mDetails, SIGNAL( browse( const QString& ) ), |
304 | SLOT( browse( const QString& ) ) ); | 304 | SLOT( browse( const QString& ) ) ); |
305 | 305 | ||
306 | 306 | ||
307 | mAddressBookService = new KAddressBookService( this ); | 307 | mAddressBookService = new KAddressBookService( this ); |
308 | 308 | ||
309 | #endif //KAB_EMBEDDED | 309 | #endif //KAB_EMBEDDED |
310 | 310 | ||
311 | mMessageTimer = new QTimer( this ); | 311 | mMessageTimer = new QTimer( this ); |
312 | connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); | 312 | connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); |
313 | mEditorDialog = 0; | 313 | mEditorDialog = 0; |
314 | createAddresseeEditorDialog( this ); | 314 | createAddresseeEditorDialog( this ); |
315 | setModified( false ); | 315 | setModified( false ); |
316 | mBRdisabled = 0; | 316 | mBRdisabled = 0; |
317 | #ifndef DESKTOP_VERSION | 317 | #ifndef DESKTOP_VERSION |
318 | infrared = 0; | 318 | infrared = 0; |
319 | #endif | 319 | #endif |
320 | toggleBeamReceive( ); | 320 | toggleBeamReceive( ); |
321 | } | 321 | } |
322 | 322 | ||
323 | KABCore::~KABCore() | 323 | KABCore::~KABCore() |
324 | { | 324 | { |
325 | // save(); | 325 | // save(); |
326 | //saveSettings(); | 326 | //saveSettings(); |
327 | //KABPrefs::instance()->writeConfig(); | 327 | //KABPrefs::instance()->writeConfig(); |
328 | delete AddresseeConfig::instance(); | 328 | delete AddresseeConfig::instance(); |
329 | mAddressBook = 0; | 329 | mAddressBook = 0; |
330 | KABC::StdAddressBook::close(); | 330 | KABC::StdAddressBook::close(); |
331 | 331 | ||
332 | delete syncManager; | 332 | delete syncManager; |
333 | #ifndef DESKTOP_VERSION | 333 | #ifndef DESKTOP_VERSION |
334 | if ( infrared ) | 334 | if ( infrared ) |
335 | delete infrared; | 335 | delete infrared; |
336 | #endif | 336 | #endif |
337 | } | 337 | } |
338 | void KABCore::receive( const QCString& cmsg, const QByteArray& data ) | 338 | void KABCore::receive( const QCString& cmsg, const QByteArray& data ) |
339 | { | 339 | { |
340 | qDebug("KA: QCOP message received: %s ", cmsg.data() ); | 340 | qDebug("KA: QCOP message received: %s ", cmsg.data() ); |
341 | if ( cmsg == "setDocument(QString)" ) { | 341 | if ( cmsg == "setDocument(QString)" ) { |
342 | QDataStream stream( data, IO_ReadOnly ); | 342 | QDataStream stream( data, IO_ReadOnly ); |
343 | QString fileName; | 343 | QString fileName; |
344 | stream >> fileName; | 344 | stream >> fileName; |
345 | recieve( fileName ); | 345 | recieve( fileName ); |
346 | return; | 346 | return; |
347 | } | 347 | } |
348 | } | 348 | } |
349 | void KABCore::toggleBeamReceive( ) | 349 | void KABCore::toggleBeamReceive( ) |
350 | { | 350 | { |
351 | if ( mBRdisabled ) | 351 | if ( mBRdisabled ) |
352 | return; | 352 | return; |
353 | #ifndef DESKTOP_VERSION | 353 | #ifndef DESKTOP_VERSION |
354 | if ( infrared ) { | 354 | if ( infrared ) { |
355 | qDebug("AB disable BeamReceive "); | 355 | qDebug("AB disable BeamReceive "); |
356 | delete infrared; | 356 | delete infrared; |
357 | infrared = 0; | 357 | infrared = 0; |
358 | mActionBR->setChecked(false); | 358 | mActionBR->setChecked(false); |
359 | return; | 359 | return; |
360 | } | 360 | } |
361 | qDebug("AB enable BeamReceive "); | 361 | qDebug("AB enable BeamReceive "); |
362 | mActionBR->setChecked(true); | 362 | mActionBR->setChecked(true); |
363 | 363 | ||
364 | infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; | 364 | infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; |
365 | QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); | 365 | QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); |
366 | #endif | 366 | #endif |
367 | } | 367 | } |
368 | 368 | ||
369 | 369 | ||
370 | void KABCore::disableBR(bool b) | 370 | void KABCore::disableBR(bool b) |
371 | { | 371 | { |
372 | #ifndef DESKTOP_VERSION | 372 | #ifndef DESKTOP_VERSION |
373 | if ( b ) { | 373 | if ( b ) { |
374 | if ( infrared ) { | 374 | if ( infrared ) { |
375 | toggleBeamReceive( ); | 375 | toggleBeamReceive( ); |
376 | } | 376 | } |
377 | mBRdisabled = true; | 377 | mBRdisabled = true; |
378 | } else { | 378 | } else { |
379 | if ( mBRdisabled ) { | 379 | if ( mBRdisabled ) { |
380 | mBRdisabled = false; | 380 | mBRdisabled = false; |
381 | //toggleBeamReceive( ); | 381 | //toggleBeamReceive( ); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | #endif | 384 | #endif |
385 | 385 | ||
386 | } | 386 | } |
387 | void KABCore::recieve( QString fn ) | 387 | void KABCore::recieve( QString fn ) |
388 | { | 388 | { |
389 | //qDebug("KABCore::recieve "); | 389 | //qDebug("KABCore::recieve "); |
390 | int count = mAddressBook->importFromFile( fn, true ); | 390 | int count = mAddressBook->importFromFile( fn, true ); |
391 | if ( count ) | 391 | if ( count ) |
392 | setModified( true ); | 392 | setModified( true ); |
393 | mViewManager->refreshView(); | 393 | mViewManager->refreshView(); |
394 | message(i18n("%1 contact(s) received!").arg( count )); | 394 | message(i18n("%1 contact(s) received!").arg( count )); |
395 | topLevelWidget()->showMaximized(); | 395 | topLevelWidget()->showMaximized(); |
396 | topLevelWidget()->raise(); | 396 | topLevelWidget()->raise(); |
397 | } | 397 | } |
398 | void KABCore::restoreSettings() | 398 | void KABCore::restoreSettings() |
399 | { | 399 | { |
400 | mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; | 400 | mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; |
401 | 401 | ||
402 | bool state; | 402 | bool state; |
403 | 403 | ||
404 | if (mMultipleViewsAtOnce) | 404 | if (mMultipleViewsAtOnce) |
405 | state = KABPrefs::instance()->mDetailsPageVisible; | 405 | state = KABPrefs::instance()->mDetailsPageVisible; |
406 | else | 406 | else |
407 | state = false; | 407 | state = false; |
408 | 408 | ||
409 | mActionDetails->setChecked( state ); | 409 | mActionDetails->setChecked( state ); |
410 | setDetailsVisible( state ); | 410 | setDetailsVisible( state ); |
411 | 411 | ||
412 | state = KABPrefs::instance()->mJumpButtonBarVisible; | 412 | state = KABPrefs::instance()->mJumpButtonBarVisible; |
413 | 413 | ||
414 | mActionJumpBar->setChecked( state ); | 414 | mActionJumpBar->setChecked( state ); |
415 | setJumpButtonBarVisible( state ); | 415 | setJumpButtonBarVisible( state ); |
416 | /*US | 416 | /*US |
417 | QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; | 417 | QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; |
418 | if ( splitterSize.count() == 0 ) { | 418 | if ( splitterSize.count() == 0 ) { |
419 | splitterSize.append( width() / 2 ); | 419 | splitterSize.append( width() / 2 ); |
420 | splitterSize.append( width() / 2 ); | 420 | splitterSize.append( width() / 2 ); |
421 | } | 421 | } |
422 | mMiniSplitter->setSizes( splitterSize ); | 422 | mMiniSplitter->setSizes( splitterSize ); |
423 | if ( mExtensionBarSplitter ) { | 423 | if ( mExtensionBarSplitter ) { |
424 | splitterSize = KABPrefs::instance()->mExtensionsSplitter; | 424 | splitterSize = KABPrefs::instance()->mExtensionsSplitter; |
425 | if ( splitterSize.count() == 0 ) { | 425 | if ( splitterSize.count() == 0 ) { |
426 | splitterSize.append( width() / 2 ); | 426 | splitterSize.append( width() / 2 ); |
427 | splitterSize.append( width() / 2 ); | 427 | splitterSize.append( width() / 2 ); |
428 | } | 428 | } |
429 | mExtensionBarSplitter->setSizes( splitterSize ); | 429 | mExtensionBarSplitter->setSizes( splitterSize ); |
430 | 430 | ||
431 | } | 431 | } |
432 | */ | 432 | */ |
433 | mViewManager->restoreSettings(); | 433 | mViewManager->restoreSettings(); |
434 | mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); | 434 | mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); |
435 | mExtensionManager->restoreSettings(); | 435 | mExtensionManager->restoreSettings(); |
436 | #ifdef DESKTOP_VERSION | 436 | #ifdef DESKTOP_VERSION |
437 | int wid = width(); | 437 | int wid = width(); |
438 | if ( wid < 10 ) | 438 | if ( wid < 10 ) |
439 | wid = 400; | 439 | wid = 400; |
440 | #else | 440 | #else |
441 | int wid = QApplication::desktop()->width(); | 441 | int wid = QApplication::desktop()->width(); |
442 | if ( wid < 640 ) | 442 | if ( wid < 640 ) |
443 | wid = QApplication::desktop()->height(); | 443 | wid = QApplication::desktop()->height(); |
444 | #endif | 444 | #endif |
445 | QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; | 445 | QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; |
446 | if ( true /*splitterSize.count() == 0*/ ) { | 446 | if ( true /*splitterSize.count() == 0*/ ) { |
447 | splitterSize.append( wid / 2 ); | 447 | splitterSize.append( wid / 2 ); |
448 | splitterSize.append( wid / 2 ); | 448 | splitterSize.append( wid / 2 ); |
449 | } | 449 | } |
450 | mMiniSplitter->setSizes( splitterSize ); | 450 | mMiniSplitter->setSizes( splitterSize ); |
451 | if ( mExtensionBarSplitter ) { | 451 | if ( mExtensionBarSplitter ) { |
452 | //splitterSize = KABPrefs::instance()->mExtensionsSplitter; | 452 | //splitterSize = KABPrefs::instance()->mExtensionsSplitter; |
453 | if ( true /*splitterSize.count() == 0*/ ) { | 453 | if ( true /*splitterSize.count() == 0*/ ) { |
454 | splitterSize.append( wid / 2 ); | 454 | splitterSize.append( wid / 2 ); |
455 | splitterSize.append( wid / 2 ); | 455 | splitterSize.append( wid / 2 ); |
456 | } | 456 | } |
457 | mExtensionBarSplitter->setSizes( splitterSize ); | 457 | mExtensionBarSplitter->setSizes( splitterSize ); |
458 | 458 | ||
459 | } | 459 | } |
460 | 460 | ||
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | void KABCore::saveSettings() | 464 | void KABCore::saveSettings() |
465 | { | 465 | { |
466 | KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); | 466 | KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); |
467 | if ( mExtensionBarSplitter ) | 467 | if ( mExtensionBarSplitter ) |
468 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); | 468 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); |
469 | KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); | 469 | KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); |
470 | KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); | 470 | KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); |
471 | #ifndef KAB_EMBEDDED | 471 | #ifndef KAB_EMBEDDED |
472 | 472 | ||
473 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); | 473 | KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); |
474 | KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); | 474 | KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); |
475 | #endif //KAB_EMBEDDED | 475 | #endif //KAB_EMBEDDED |
476 | mExtensionManager->saveSettings(); | 476 | mExtensionManager->saveSettings(); |
477 | mViewManager->saveSettings(); | 477 | mViewManager->saveSettings(); |
478 | 478 | ||
479 | KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); | 479 | KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); |
480 | } | 480 | } |
481 | 481 | ||
482 | KABC::AddressBook *KABCore::addressBook() const | 482 | KABC::AddressBook *KABCore::addressBook() const |
483 | { | 483 | { |
484 | return mAddressBook; | 484 | return mAddressBook; |
485 | } | 485 | } |
486 | 486 | ||
487 | KConfig *KABCore::config() | 487 | KConfig *KABCore::config() |
488 | { | 488 | { |
489 | #ifndef KAB_EMBEDDED | 489 | #ifndef KAB_EMBEDDED |
490 | return KABPrefs::instance()->config(); | 490 | return KABPrefs::instance()->config(); |
491 | #else //KAB_EMBEDDED | 491 | #else //KAB_EMBEDDED |
492 | return KABPrefs::instance()->getConfig(); | 492 | return KABPrefs::instance()->getConfig(); |
493 | #endif //KAB_EMBEDDED | 493 | #endif //KAB_EMBEDDED |
494 | } | 494 | } |
495 | 495 | ||
496 | KActionCollection *KABCore::actionCollection() const | 496 | KActionCollection *KABCore::actionCollection() const |
497 | { | 497 | { |
498 | return mGUIClient->actionCollection(); | 498 | return mGUIClient->actionCollection(); |
499 | } | 499 | } |
500 | 500 | ||
501 | KABC::Field *KABCore::currentSearchField() const | 501 | KABC::Field *KABCore::currentSearchField() const |
502 | { | 502 | { |
503 | if (mIncSearchWidget) | 503 | if (mIncSearchWidget) |
504 | return mIncSearchWidget->currentField(); | 504 | return mIncSearchWidget->currentField(); |
505 | else | 505 | else |
506 | return 0; | 506 | return 0; |
507 | } | 507 | } |
508 | 508 | ||
509 | QStringList KABCore::selectedUIDs() const | 509 | QStringList KABCore::selectedUIDs() const |
510 | { | 510 | { |
511 | return mViewManager->selectedUids(); | 511 | return mViewManager->selectedUids(); |
512 | } | 512 | } |
513 | 513 | ||
514 | KABC::Resource *KABCore::requestResource( QWidget *parent ) | 514 | KABC::Resource *KABCore::requestResource( QWidget *parent ) |
515 | { | 515 | { |
516 | QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); | 516 | QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); |
517 | 517 | ||
518 | QPtrList<KRES::Resource> kresResources; | 518 | QPtrList<KRES::Resource> kresResources; |
519 | QPtrListIterator<KABC::Resource> resIt( kabcResources ); | 519 | QPtrListIterator<KABC::Resource> resIt( kabcResources ); |
520 | KABC::Resource *resource; | 520 | KABC::Resource *resource; |
521 | while ( ( resource = resIt.current() ) != 0 ) { | 521 | while ( ( resource = resIt.current() ) != 0 ) { |
522 | ++resIt; | 522 | ++resIt; |
523 | if ( !resource->readOnly() ) { | 523 | if ( !resource->readOnly() ) { |
524 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 524 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
525 | if ( res ) | 525 | if ( res ) |
526 | kresResources.append( res ); | 526 | kresResources.append( res ); |
527 | } | 527 | } |
528 | } | 528 | } |
529 | 529 | ||
530 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); | 530 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); |
531 | return static_cast<KABC::Resource*>( res ); | 531 | return static_cast<KABC::Resource*>( res ); |
532 | } | 532 | } |
533 | 533 | ||
534 | #ifndef KAB_EMBEDDED | 534 | #ifndef KAB_EMBEDDED |
535 | KAboutData *KABCore::createAboutData() | 535 | KAboutData *KABCore::createAboutData() |
536 | #else //KAB_EMBEDDED | 536 | #else //KAB_EMBEDDED |
537 | void KABCore::createAboutData() | 537 | void KABCore::createAboutData() |
538 | #endif //KAB_EMBEDDED | 538 | #endif //KAB_EMBEDDED |
539 | { | 539 | { |
540 | #ifndef KAB_EMBEDDED | 540 | #ifndef KAB_EMBEDDED |
541 | KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), | 541 | KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), |
542 | "3.1", I18N_NOOP( "The KDE Address Book" ), | 542 | "3.1", I18N_NOOP( "The KDE Address Book" ), |
543 | KAboutData::License_GPL_V2, | 543 | KAboutData::License_GPL_V2, |
544 | I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); | 544 | I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); |
545 | about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); | 545 | about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); |
546 | about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); | 546 | about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); |
547 | about->addAuthor( "Cornelius Schumacher", | 547 | about->addAuthor( "Cornelius Schumacher", |
548 | I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), | 548 | I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), |
549 | "schumacher@kde.org" ); | 549 | "schumacher@kde.org" ); |
550 | about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), | 550 | about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), |
551 | "mpilone@slac.com" ); | 551 | "mpilone@slac.com" ); |
552 | about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); | 552 | about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); |
553 | about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); | 553 | about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); |
554 | about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), | 554 | about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), |
555 | "michel@klaralvdalens-datakonsult.se" ); | 555 | "michel@klaralvdalens-datakonsult.se" ); |
556 | about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), | 556 | about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), |
557 | "hansen@kde.org" ); | 557 | "hansen@kde.org" ); |
558 | 558 | ||
559 | return about; | 559 | return about; |
560 | #endif //KAB_EMBEDDED | 560 | #endif //KAB_EMBEDDED |
561 | 561 | ||
562 | QString version; | 562 | QString version; |
563 | #include <../version> | 563 | #include <../version> |
564 | QMessageBox::about( this, "About KAddressbook/Pi", | 564 | QMessageBox::about( this, "About KAddressbook/Pi", |
565 | "KAddressbook/Platform-independent\n" | 565 | "KAddressbook/Platform-independent\n" |
566 | "(KA/Pi) " +version + " - " + | 566 | "(KA/Pi) " +version + " - " + |
567 | #ifdef DESKTOP_VERSION | 567 | #ifdef DESKTOP_VERSION |
568 | "Desktop Edition\n" | 568 | "Desktop Edition\n" |
569 | #else | 569 | #else |
570 | "PDA-Edition\n" | 570 | "PDA-Edition\n" |
571 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 571 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
572 | #endif | 572 | #endif |
573 | 573 | ||
574 | "(c) 2004 Ulf Schenk\n" | 574 | "(c) 2004 Ulf Schenk\n" |
575 | "(c) 2004 Lutz Rogowski\n" | 575 | "(c) 2004 Lutz Rogowski\n" |
576 | "(c) 1997-2003, The KDE PIM Team\n" | 576 | "(c) 1997-2003, The KDE PIM Team\n" |
577 | "Tobias Koenig Current maintainer\ntokoe@kde.org\n" | 577 | "Tobias Koenig Current maintainer\ntokoe@kde.org\n" |
578 | "Don Sanders Original author\n" | 578 | "Don Sanders Original author\n" |
579 | "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" | 579 | "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" |
580 | "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" | 580 | "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" |
581 | "Greg Stern DCOP interface\n" | 581 | "Greg Stern DCOP interface\n" |
582 | "Mark Westcot Contact pinning\n" | 582 | "Mark Westcot Contact pinning\n" |
583 | "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" | 583 | "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" |
584 | "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" | 584 | "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" |
585 | #ifdef _WIN32_ | 585 | #ifdef _WIN32_ |
586 | "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" | 586 | "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" |
587 | #endif | 587 | #endif |
588 | ); | 588 | ); |
589 | } | 589 | } |
590 | 590 | ||
591 | void KABCore::setContactSelected( const QString &uid ) | 591 | void KABCore::setContactSelected( const QString &uid ) |
592 | { | 592 | { |
593 | KABC::Addressee addr = mAddressBook->findByUid( uid ); | 593 | KABC::Addressee addr = mAddressBook->findByUid( uid ); |
594 | if ( !mDetails->isHidden() ) | 594 | if ( !mDetails->isHidden() ) |
595 | mDetails->setAddressee( addr ); | 595 | mDetails->setAddressee( addr ); |
596 | 596 | ||
597 | if ( !addr.isEmpty() ) { | 597 | if ( !addr.isEmpty() ) { |
598 | emit contactSelected( addr.formattedName() ); | 598 | emit contactSelected( addr.formattedName() ); |
599 | KABC::Picture pic = addr.photo(); | 599 | KABC::Picture pic = addr.photo(); |
600 | if ( pic.isIntern() ) { | 600 | if ( pic.isIntern() ) { |
601 | //US emit contactSelected( pic.data() ); | 601 | //US emit contactSelected( pic.data() ); |
602 | //US instead use: | 602 | //US instead use: |
603 | QPixmap px; | 603 | QPixmap px; |
604 | if (pic.data().isNull() != true) | 604 | if (pic.data().isNull() != true) |
605 | { | 605 | { |
606 | px.convertFromImage(pic.data()); | 606 | px.convertFromImage(pic.data()); |
607 | } | 607 | } |
608 | 608 | ||
609 | emit contactSelected( px ); | 609 | emit contactSelected( px ); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | mExtensionManager->setSelectionChanged(); | 614 | mExtensionManager->setSelectionChanged(); |
615 | 615 | ||
616 | // update the actions | 616 | // update the actions |
617 | bool selected = !uid.isEmpty(); | 617 | bool selected = !uid.isEmpty(); |
618 | 618 | ||
619 | if ( mReadWrite ) { | 619 | if ( mReadWrite ) { |
620 | mActionCut->setEnabled( selected ); | 620 | mActionCut->setEnabled( selected ); |
621 | mActionPaste->setEnabled( selected ); | 621 | mActionPaste->setEnabled( selected ); |
622 | } | 622 | } |
623 | 623 | ||
624 | mActionCopy->setEnabled( selected ); | 624 | mActionCopy->setEnabled( selected ); |
625 | mActionDelete->setEnabled( selected ); | 625 | mActionDelete->setEnabled( selected ); |
626 | mActionEditAddressee->setEnabled( selected ); | 626 | mActionEditAddressee->setEnabled( selected ); |
627 | mActionMail->setEnabled( selected ); | 627 | mActionMail->setEnabled( selected ); |
628 | mActionMailVCard->setEnabled( selected ); | 628 | mActionMailVCard->setEnabled( selected ); |
629 | //if (mActionBeam) | 629 | //if (mActionBeam) |
630 | //mActionBeam->setEnabled( selected ); | 630 | //mActionBeam->setEnabled( selected ); |
631 | 631 | ||
632 | if (mActionBeamVCard) | 632 | if (mActionBeamVCard) |
633 | mActionBeamVCard->setEnabled( selected ); | 633 | mActionBeamVCard->setEnabled( selected ); |
634 | 634 | ||
635 | mActionExport2phone->setEnabled( selected ); | 635 | mActionExport2phone->setEnabled( selected ); |
636 | mActionWhoAmI->setEnabled( selected ); | 636 | mActionWhoAmI->setEnabled( selected ); |
637 | mActionCategories->setEnabled( selected ); | 637 | mActionCategories->setEnabled( selected ); |
638 | } | 638 | } |
639 | 639 | ||
640 | void KABCore::sendMail() | 640 | void KABCore::sendMail() |
641 | { | 641 | { |
642 | sendMail( mViewManager->selectedEmails().join( ", " ) ); | 642 | sendMail( mViewManager->selectedEmails().join( ", " ) ); |
643 | } | 643 | } |
644 | 644 | ||
645 | void KABCore::sendMail( const QString& emaillist ) | 645 | void KABCore::sendMail( const QString& emaillist ) |
646 | { | 646 | { |
647 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " | 647 | // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " |
648 | if (emaillist.contains(",") > 0) | 648 | if (emaillist.contains(",") > 0) |
649 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); | 649 | ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); |
650 | else | 650 | else |
651 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); | 651 | ExternalAppHandler::instance()->mailToOneContact( emaillist ); |
652 | } | 652 | } |
653 | 653 | ||
654 | 654 | ||
655 | 655 | ||
656 | void KABCore::mailVCard() | 656 | void KABCore::mailVCard() |
657 | { | 657 | { |
658 | QStringList uids = mViewManager->selectedUids(); | 658 | QStringList uids = mViewManager->selectedUids(); |
659 | if ( !uids.isEmpty() ) | 659 | if ( !uids.isEmpty() ) |
660 | mailVCard( uids ); | 660 | mailVCard( uids ); |
661 | } | 661 | } |
662 | 662 | ||
663 | void KABCore::mailVCard( const QStringList& uids ) | 663 | void KABCore::mailVCard( const QStringList& uids ) |
664 | { | 664 | { |
665 | QStringList urls; | 665 | QStringList urls; |
666 | 666 | ||
667 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); | 667 | // QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); |
668 | 668 | ||
669 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); | 669 | QString dirName = "/tmp/" + KApplication::randomString( 8 ); |
670 | 670 | ||
671 | 671 | ||
672 | 672 | ||
673 | QDir().mkdir( dirName, true ); | 673 | QDir().mkdir( dirName, true ); |
674 | 674 | ||
675 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 675 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
676 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 676 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
677 | 677 | ||
678 | if ( a.isEmpty() ) | 678 | if ( a.isEmpty() ) |
679 | continue; | 679 | continue; |
680 | 680 | ||
681 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; | 681 | QString name = a.givenName() + "_" + a.familyName() + ".vcf"; |
682 | 682 | ||
683 | QString fileName = dirName + "/" + name; | 683 | QString fileName = dirName + "/" + name; |
684 | 684 | ||
685 | QFile outFile(fileName); | 685 | QFile outFile(fileName); |
686 | 686 | ||
687 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully | 687 | if ( outFile.open(IO_WriteOnly) ) { // file opened successfully |
688 | KABC::VCardConverter converter; | 688 | KABC::VCardConverter converter; |
689 | QString vcard; | 689 | QString vcard; |
690 | 690 | ||
691 | converter.addresseeToVCard( a, vcard ); | 691 | converter.addresseeToVCard( a, vcard ); |
692 | 692 | ||
693 | QTextStream t( &outFile ); // use a text stream | 693 | QTextStream t( &outFile ); // use a text stream |
694 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 694 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
695 | t << vcard; | 695 | t << vcard; |
696 | 696 | ||
697 | outFile.close(); | 697 | outFile.close(); |
698 | 698 | ||
699 | urls.append( fileName ); | 699 | urls.append( fileName ); |
700 | } | 700 | } |
701 | } | 701 | } |
702 | 702 | ||
703 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); | 703 | bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); |
704 | 704 | ||
705 | 705 | ||
706 | /*US | 706 | /*US |
707 | kapp->invokeMailer( QString::null, QString::null, QString::null, | 707 | kapp->invokeMailer( QString::null, QString::null, QString::null, |
708 | QString::null, // subject | 708 | QString::null, // subject |
709 | QString::null, // body | 709 | QString::null, // body |
710 | QString::null, | 710 | QString::null, |
711 | urls ); // attachments | 711 | urls ); // attachments |
712 | */ | 712 | */ |
713 | 713 | ||
714 | } | 714 | } |
715 | 715 | ||
716 | /** | 716 | /** |
717 | Beams the "WhoAmI contact. | 717 | Beams the "WhoAmI contact. |
718 | */ | 718 | */ |
719 | void KABCore::beamMySelf() | 719 | void KABCore::beamMySelf() |
720 | { | 720 | { |
721 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); | 721 | KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); |
722 | if (!a.isEmpty()) | 722 | if (!a.isEmpty()) |
723 | { | 723 | { |
724 | QStringList uids; | 724 | QStringList uids; |
725 | uids << a.uid(); | 725 | uids << a.uid(); |
726 | 726 | ||
727 | beamVCard(uids); | 727 | beamVCard(uids); |
728 | } else { | 728 | } else { |
729 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 729 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
730 | 730 | ||
731 | 731 | ||
732 | } | 732 | } |
733 | } | 733 | } |
734 | 734 | ||
735 | void KABCore::export2phone() | 735 | void KABCore::export2phone() |
736 | { | 736 | { |
737 | 737 | ||
738 | KAex2phonePrefs ex2phone; | 738 | KAex2phonePrefs ex2phone; |
739 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); | 739 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); |
740 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); | 740 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); |
741 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 741 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
742 | 742 | ||
743 | if ( !ex2phone.exec() ) { | 743 | if ( !ex2phone.exec() ) { |
744 | return; | 744 | return; |
745 | } | 745 | } |
746 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); | 746 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); |
747 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); | 747 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); |
748 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); | 748 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); |
749 | 749 | ||
750 | 750 | ||
751 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, | 751 | PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, |
752 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, | 752 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, |
753 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); | 753 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); |
754 | 754 | ||
755 | QStringList uids = mViewManager->selectedUids(); | 755 | QStringList uids = mViewManager->selectedUids(); |
756 | if ( uids.isEmpty() ) | 756 | if ( uids.isEmpty() ) |
757 | return; | 757 | return; |
758 | 758 | ||
759 | QString fileName = getPhoneFile(); | 759 | QString fileName = getPhoneFile(); |
760 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) | 760 | if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) |
761 | return; | 761 | return; |
762 | 762 | ||
763 | message(i18n("Exporting to phone...")); | 763 | message(i18n("Exporting to phone...")); |
764 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); | 764 | QTimer::singleShot( 1, this , SLOT ( writeToPhone())); |
765 | 765 | ||
766 | } | 766 | } |
767 | QString KABCore::getPhoneFile() | 767 | QString KABCore::getPhoneFile() |
768 | { | 768 | { |
769 | #ifdef DESKTOP_VERSION | 769 | #ifdef DESKTOP_VERSION |
770 | return locateLocal("tmp", "phonefile.vcf"); | 770 | return locateLocal("tmp", "phonefile.vcf"); |
771 | #else | 771 | #else |
772 | return "/tmp/phonefile.vcf"; | 772 | return "/tmp/phonefile.vcf"; |
773 | #endif | 773 | #endif |
774 | 774 | ||
775 | } | 775 | } |
776 | void KABCore::writeToPhone( ) | 776 | void KABCore::writeToPhone( ) |
777 | { | 777 | { |
778 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) | 778 | if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) |
779 | message(i18n("Export to phone finished!")); | 779 | message(i18n("Export to phone finished!")); |
780 | else | 780 | else |
781 | qDebug(i18n("Error exporting to phone")); | 781 | qDebug(i18n("Error exporting to phone")); |
782 | } | 782 | } |
783 | void KABCore::beamVCard() | 783 | void KABCore::beamVCard() |
784 | { | 784 | { |
785 | QStringList uids = mViewManager->selectedUids(); | 785 | QStringList uids = mViewManager->selectedUids(); |
786 | if ( !uids.isEmpty() ) | 786 | if ( !uids.isEmpty() ) |
787 | beamVCard( uids ); | 787 | beamVCard( uids ); |
788 | } | 788 | } |
789 | 789 | ||
790 | 790 | ||
791 | void KABCore::beamVCard(const QStringList& uids) | 791 | void KABCore::beamVCard(const QStringList& uids) |
792 | { | 792 | { |
793 | 793 | ||
794 | // LR: we should use the /tmp dir on the Zaurus, | 794 | // LR: we should use the /tmp dir on the Zaurus, |
795 | // because: /tmp = RAM, (HOME)/kdepim = flash memory | 795 | // because: /tmp = RAM, (HOME)/kdepim = flash memory |
796 | 796 | ||
797 | #ifdef DESKTOP_VERSION | 797 | #ifdef DESKTOP_VERSION |
798 | QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); | 798 | QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); |
799 | #else | 799 | #else |
800 | QString fileName = "/tmp/kapibeamfile.vcf"; | 800 | QString fileName = "/tmp/kapibeamfile.vcf"; |
801 | #endif | 801 | #endif |
802 | 802 | ||
803 | KABC::VCardConverter converter; | 803 | KABC::VCardConverter converter; |
804 | QString description; | 804 | QString description; |
805 | QString datastream; | 805 | QString datastream; |
806 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 806 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
807 | KABC::Addressee a = mAddressBook->findByUid( *it ); | 807 | KABC::Addressee a = mAddressBook->findByUid( *it ); |
808 | 808 | ||
809 | if ( a.isEmpty() ) | 809 | if ( a.isEmpty() ) |
810 | continue; | 810 | continue; |
811 | 811 | ||
812 | if (description.isEmpty()) | 812 | if (description.isEmpty()) |
813 | description = a.formattedName(); | 813 | description = a.formattedName(); |
814 | 814 | ||
815 | QString vcard; | 815 | QString vcard; |
816 | converter.addresseeToVCard( a, vcard ); | 816 | converter.addresseeToVCard( a, vcard ); |
817 | int start = 0; | 817 | int start = 0; |
818 | int next; | 818 | int next; |
819 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 819 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
820 | int semi = vcard.find(";", next); | 820 | int semi = vcard.find(";", next); |
821 | int dopp = vcard.find(":", next); | 821 | int dopp = vcard.find(":", next); |
822 | int sep; | 822 | int sep; |
823 | if ( semi < dopp && semi >= 0 ) | 823 | if ( semi < dopp && semi >= 0 ) |
824 | sep = semi ; | 824 | sep = semi ; |
825 | else | 825 | else |
826 | sep = dopp; | 826 | sep = dopp; |
827 | datastream +=vcard.mid( start, next - start); | 827 | datastream +=vcard.mid( start, next - start); |
828 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | 828 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); |
829 | start = sep; | 829 | start = sep; |
830 | } | 830 | } |
831 | datastream += vcard.mid( start,vcard.length() ); | 831 | datastream += vcard.mid( start,vcard.length() ); |
832 | } | 832 | } |
833 | #ifndef DESKTOP_VERSION | 833 | #ifndef DESKTOP_VERSION |
834 | QFile outFile(fileName); | 834 | QFile outFile(fileName); |
835 | if ( outFile.open(IO_WriteOnly) ) { | 835 | if ( outFile.open(IO_WriteOnly) ) { |
836 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 836 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
837 | QTextStream t( &outFile ); // use a text stream | 837 | QTextStream t( &outFile ); // use a text stream |
838 | //t.setEncoding( QTextStream::UnicodeUTF8 ); | 838 | //t.setEncoding( QTextStream::UnicodeUTF8 ); |
839 | t.setEncoding( QTextStream::Latin1 ); | 839 | t.setEncoding( QTextStream::Latin1 ); |
840 | t <<datastream.latin1(); | 840 | t <<datastream.latin1(); |
841 | outFile.close(); | 841 | outFile.close(); |
842 | Ir *ir = new Ir( this ); | 842 | Ir *ir = new Ir( this ); |
843 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | 843 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); |
844 | ir->send( fileName, description, "text/x-vCard" ); | 844 | ir->send( fileName, description, "text/x-vCard" ); |
845 | } else { | 845 | } else { |
846 | qDebug("Error open temp beam file "); | 846 | qDebug("Error open temp beam file "); |
847 | return; | 847 | return; |
848 | } | 848 | } |
849 | #endif | 849 | #endif |
850 | 850 | ||
851 | } | 851 | } |
852 | 852 | ||
853 | void KABCore::beamDone( Ir *ir ) | 853 | void KABCore::beamDone( Ir *ir ) |
854 | { | 854 | { |
855 | #ifndef DESKTOP_VERSION | 855 | #ifndef DESKTOP_VERSION |
856 | delete ir; | 856 | delete ir; |
857 | #endif | 857 | #endif |
858 | topLevelWidget()->raise(); | 858 | topLevelWidget()->raise(); |
859 | message( i18n("Beaming finished!") ); | 859 | message( i18n("Beaming finished!") ); |
860 | } | 860 | } |
861 | 861 | ||
862 | 862 | ||
863 | void KABCore::browse( const QString& url ) | 863 | void KABCore::browse( const QString& url ) |
864 | { | 864 | { |
865 | #ifndef KAB_EMBEDDED | 865 | #ifndef KAB_EMBEDDED |
866 | kapp->invokeBrowser( url ); | 866 | kapp->invokeBrowser( url ); |
867 | #else //KAB_EMBEDDED | 867 | #else //KAB_EMBEDDED |
868 | qDebug("KABCore::browse must be fixed"); | 868 | qDebug("KABCore::browse must be fixed"); |
869 | #endif //KAB_EMBEDDED | 869 | #endif //KAB_EMBEDDED |
870 | } | 870 | } |
871 | 871 | ||
872 | void KABCore::selectAllContacts() | 872 | void KABCore::selectAllContacts() |
873 | { | 873 | { |
874 | mViewManager->setSelected( QString::null, true ); | 874 | mViewManager->setSelected( QString::null, true ); |
875 | } | 875 | } |
876 | 876 | ||
877 | void KABCore::deleteContacts() | 877 | void KABCore::deleteContacts() |
878 | { | 878 | { |
879 | QStringList uidList = mViewManager->selectedUids(); | 879 | QStringList uidList = mViewManager->selectedUids(); |
880 | deleteContacts( uidList ); | 880 | deleteContacts( uidList ); |
881 | } | 881 | } |
882 | 882 | ||
883 | void KABCore::deleteContacts( const QStringList &uids ) | 883 | void KABCore::deleteContacts( const QStringList &uids ) |
884 | { | 884 | { |
885 | if ( uids.count() > 0 ) { | 885 | if ( uids.count() > 0 ) { |
886 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); | 886 | PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); |
887 | UndoStack::instance()->push( command ); | 887 | UndoStack::instance()->push( command ); |
888 | RedoStack::instance()->clear(); | 888 | RedoStack::instance()->clear(); |
889 | 889 | ||
890 | // now if we deleted anything, refresh | 890 | // now if we deleted anything, refresh |
891 | setContactSelected( QString::null ); | 891 | setContactSelected( QString::null ); |
892 | setModified( true ); | 892 | setModified( true ); |
893 | } | 893 | } |
894 | } | 894 | } |
895 | 895 | ||
896 | void KABCore::copyContacts() | 896 | void KABCore::copyContacts() |
897 | { | 897 | { |
898 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 898 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
899 | 899 | ||
900 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); | 900 | QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); |
901 | 901 | ||
902 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; | 902 | kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; |
903 | 903 | ||
904 | QClipboard *cb = QApplication::clipboard(); | 904 | QClipboard *cb = QApplication::clipboard(); |
905 | cb->setText( clipText ); | 905 | cb->setText( clipText ); |
906 | } | 906 | } |
907 | 907 | ||
908 | void KABCore::cutContacts() | 908 | void KABCore::cutContacts() |
909 | { | 909 | { |
910 | QStringList uidList = mViewManager->selectedUids(); | 910 | QStringList uidList = mViewManager->selectedUids(); |
911 | 911 | ||
912 | //US if ( uidList.size() > 0 ) { | 912 | //US if ( uidList.size() > 0 ) { |
913 | if ( uidList.count() > 0 ) { | 913 | if ( uidList.count() > 0 ) { |
914 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); | 914 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); |
915 | UndoStack::instance()->push( command ); | 915 | UndoStack::instance()->push( command ); |
916 | RedoStack::instance()->clear(); | 916 | RedoStack::instance()->clear(); |
917 | 917 | ||
918 | setModified( true ); | 918 | setModified( true ); |
919 | } | 919 | } |
920 | } | 920 | } |
921 | 921 | ||
922 | void KABCore::pasteContacts() | 922 | void KABCore::pasteContacts() |
923 | { | 923 | { |
924 | QClipboard *cb = QApplication::clipboard(); | 924 | QClipboard *cb = QApplication::clipboard(); |
925 | 925 | ||
926 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); | 926 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); |
927 | 927 | ||
928 | pasteContacts( list ); | 928 | pasteContacts( list ); |
929 | } | 929 | } |
930 | 930 | ||
931 | void KABCore::pasteContacts( KABC::Addressee::List &list ) | 931 | void KABCore::pasteContacts( KABC::Addressee::List &list ) |
932 | { | 932 | { |
933 | KABC::Resource *resource = requestResource( this ); | 933 | KABC::Resource *resource = requestResource( this ); |
934 | KABC::Addressee::List::Iterator it; | 934 | KABC::Addressee::List::Iterator it; |
935 | for ( it = list.begin(); it != list.end(); ++it ) | 935 | for ( it = list.begin(); it != list.end(); ++it ) |
936 | (*it).setResource( resource ); | 936 | (*it).setResource( resource ); |
937 | 937 | ||
938 | PwPasteCommand *command = new PwPasteCommand( this, list ); | 938 | PwPasteCommand *command = new PwPasteCommand( this, list ); |
939 | UndoStack::instance()->push( command ); | 939 | UndoStack::instance()->push( command ); |
940 | RedoStack::instance()->clear(); | 940 | RedoStack::instance()->clear(); |
941 | 941 | ||
942 | setModified( true ); | 942 | setModified( true ); |
943 | } | 943 | } |
944 | 944 | ||
945 | void KABCore::setWhoAmI() | 945 | void KABCore::setWhoAmI() |
946 | { | 946 | { |
947 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 947 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
948 | 948 | ||
949 | if ( addrList.count() > 1 ) { | 949 | if ( addrList.count() > 1 ) { |
950 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 950 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
951 | return; | 951 | return; |
952 | } | 952 | } |
953 | 953 | ||
954 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 954 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
955 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 955 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
956 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 956 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
957 | } | 957 | } |
958 | 958 | ||
959 | void KABCore::setCategories() | 959 | void KABCore::setCategories() |
960 | { | 960 | { |
961 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 961 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
962 | if ( !dlg.exec() ) | 962 | if ( !dlg.exec() ) |
963 | return; | 963 | return; |
964 | 964 | ||
965 | bool merge = false; | 965 | bool merge = false; |
966 | QString msg = i18n( "Merge with existing categories?" ); | 966 | QString msg = i18n( "Merge with existing categories?" ); |
967 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) | 967 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) |
968 | merge = true; | 968 | merge = true; |
969 | 969 | ||
970 | QStringList categories = dlg.selectedCategories(); | 970 | QStringList categories = dlg.selectedCategories(); |
971 | 971 | ||
972 | QStringList uids = mViewManager->selectedUids(); | 972 | QStringList uids = mViewManager->selectedUids(); |
973 | QStringList::Iterator it; | 973 | QStringList::Iterator it; |
974 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 974 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
975 | KABC::Addressee addr = mAddressBook->findByUid( *it ); | 975 | KABC::Addressee addr = mAddressBook->findByUid( *it ); |
976 | if ( !addr.isEmpty() ) { | 976 | if ( !addr.isEmpty() ) { |
977 | if ( !merge ) | 977 | if ( !merge ) |
978 | addr.setCategories( categories ); | 978 | addr.setCategories( categories ); |
979 | else { | 979 | else { |
980 | QStringList addrCategories = addr.categories(); | 980 | QStringList addrCategories = addr.categories(); |
981 | QStringList::Iterator catIt; | 981 | QStringList::Iterator catIt; |
982 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 982 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
983 | if ( !addrCategories.contains( *catIt ) ) | 983 | if ( !addrCategories.contains( *catIt ) ) |
984 | addrCategories.append( *catIt ); | 984 | addrCategories.append( *catIt ); |
985 | } | 985 | } |
986 | addr.setCategories( addrCategories ); | 986 | addr.setCategories( addrCategories ); |
987 | } | 987 | } |
988 | 988 | ||
989 | mAddressBook->insertAddressee( addr ); | 989 | mAddressBook->insertAddressee( addr ); |
990 | } | 990 | } |
991 | } | 991 | } |
992 | 992 | ||
993 | if ( uids.count() > 0 ) | 993 | if ( uids.count() > 0 ) |
994 | setModified( true ); | 994 | setModified( true ); |
995 | } | 995 | } |
996 | 996 | ||
997 | void KABCore::setSearchFields( const KABC::Field::List &fields ) | 997 | void KABCore::setSearchFields( const KABC::Field::List &fields ) |
998 | { | 998 | { |
999 | mIncSearchWidget->setFields( fields ); | 999 | mIncSearchWidget->setFields( fields ); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | void KABCore::incrementalSearch( const QString& text ) | 1002 | void KABCore::incrementalSearch( const QString& text ) |
1003 | { | 1003 | { |
1004 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); | 1004 | mViewManager->doSearch( text, mIncSearchWidget->currentField() ); |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | void KABCore::setModified() | 1007 | void KABCore::setModified() |
1008 | { | 1008 | { |
1009 | setModified( true ); | 1009 | setModified( true ); |
1010 | } | 1010 | } |
1011 | 1011 | ||
1012 | void KABCore::setModifiedWOrefresh() | 1012 | void KABCore::setModifiedWOrefresh() |
1013 | { | 1013 | { |
1014 | // qDebug("KABCore::setModifiedWOrefresh() "); | 1014 | // qDebug("KABCore::setModifiedWOrefresh() "); |
1015 | mModified = true; | 1015 | mModified = true; |
1016 | mActionSave->setEnabled( mModified ); | 1016 | mActionSave->setEnabled( mModified ); |
1017 | #ifdef DESKTOP_VERSION | 1017 | #ifdef DESKTOP_VERSION |
1018 | mDetails->refreshView(); | 1018 | mDetails->refreshView(); |
1019 | #endif | 1019 | #endif |
1020 | 1020 | ||
1021 | } | 1021 | } |
1022 | void KABCore::setModified( bool modified ) | 1022 | void KABCore::setModified( bool modified ) |
1023 | { | 1023 | { |
1024 | mModified = modified; | 1024 | mModified = modified; |
1025 | mActionSave->setEnabled( mModified ); | 1025 | mActionSave->setEnabled( mModified ); |
1026 | 1026 | ||
1027 | if ( modified ) | 1027 | if ( modified ) |
1028 | mJumpButtonBar->recreateButtons(); | 1028 | mJumpButtonBar->recreateButtons(); |
1029 | 1029 | ||
1030 | mViewManager->refreshView(); | 1030 | mViewManager->refreshView(); |
1031 | mDetails->refreshView(); | 1031 | mDetails->refreshView(); |
1032 | 1032 | ||
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | bool KABCore::modified() const | 1035 | bool KABCore::modified() const |
1036 | { | 1036 | { |
1037 | return mModified; | 1037 | return mModified; |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | void KABCore::contactModified( const KABC::Addressee &addr ) | 1040 | void KABCore::contactModified( const KABC::Addressee &addr ) |
1041 | { | 1041 | { |
1042 | 1042 | ||
1043 | Command *command = 0; | 1043 | Command *command = 0; |
1044 | QString uid; | 1044 | QString uid; |
1045 | 1045 | ||
1046 | // check if it exists already | 1046 | // check if it exists already |
1047 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); | 1047 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); |
1048 | if ( origAddr.isEmpty() ) | 1048 | if ( origAddr.isEmpty() ) |
1049 | command = new PwNewCommand( mAddressBook, addr ); | 1049 | command = new PwNewCommand( mAddressBook, addr ); |
1050 | else { | 1050 | else { |
1051 | command = new PwEditCommand( mAddressBook, origAddr, addr ); | 1051 | command = new PwEditCommand( mAddressBook, origAddr, addr ); |
1052 | uid = addr.uid(); | 1052 | uid = addr.uid(); |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | UndoStack::instance()->push( command ); | 1055 | UndoStack::instance()->push( command ); |
1056 | RedoStack::instance()->clear(); | 1056 | RedoStack::instance()->clear(); |
1057 | 1057 | ||
1058 | setModified( true ); | 1058 | setModified( true ); |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | void KABCore::newContact() | 1061 | void KABCore::newContact() |
1062 | { | 1062 | { |
1063 | 1063 | ||
1064 | 1064 | ||
1065 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); | 1065 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); |
1066 | 1066 | ||
1067 | QPtrList<KRES::Resource> kresResources; | 1067 | QPtrList<KRES::Resource> kresResources; |
1068 | QPtrListIterator<KABC::Resource> it( kabcResources ); | 1068 | QPtrListIterator<KABC::Resource> it( kabcResources ); |
1069 | KABC::Resource *resource; | 1069 | KABC::Resource *resource; |
1070 | while ( ( resource = it.current() ) != 0 ) { | 1070 | while ( ( resource = it.current() ) != 0 ) { |
1071 | ++it; | 1071 | ++it; |
1072 | if ( !resource->readOnly() ) { | 1072 | if ( !resource->readOnly() ) { |
1073 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 1073 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
1074 | if ( res ) | 1074 | if ( res ) |
1075 | kresResources.append( res ); | 1075 | kresResources.append( res ); |
1076 | } | 1076 | } |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); | 1079 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); |
1080 | resource = static_cast<KABC::Resource*>( res ); | 1080 | resource = static_cast<KABC::Resource*>( res ); |
1081 | 1081 | ||
1082 | if ( resource ) { | 1082 | if ( resource ) { |
1083 | KABC::Addressee addr; | 1083 | KABC::Addressee addr; |
1084 | addr.setResource( resource ); | 1084 | addr.setResource( resource ); |
1085 | mEditorDialog->setAddressee( addr ); | 1085 | mEditorDialog->setAddressee( addr ); |
1086 | KApplication::execDialog ( mEditorDialog ); | 1086 | KApplication::execDialog ( mEditorDialog ); |
1087 | 1087 | ||
1088 | } else | 1088 | } else |
1089 | return; | 1089 | return; |
1090 | 1090 | ||
1091 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); | 1091 | // mEditorDict.insert( dialog->addressee().uid(), dialog ); |
1092 | 1092 | ||
1093 | 1093 | ||
1094 | } | 1094 | } |
1095 | 1095 | ||
1096 | void KABCore::addEmail( QString aStr ) | 1096 | void KABCore::addEmail( QString aStr ) |
1097 | { | 1097 | { |
1098 | #ifndef KAB_EMBEDDED | 1098 | #ifndef KAB_EMBEDDED |
1099 | QString fullName, email; | 1099 | QString fullName, email; |
1100 | 1100 | ||
1101 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); | 1101 | KABC::Addressee::parseEmailAddress( aStr, fullName, email ); |
1102 | 1102 | ||
1103 | // Try to lookup the addressee matching the email address | 1103 | // Try to lookup the addressee matching the email address |
1104 | bool found = false; | 1104 | bool found = false; |
1105 | QStringList emailList; | 1105 | QStringList emailList; |
1106 | KABC::AddressBook::Iterator it; | 1106 | KABC::AddressBook::Iterator it; |
1107 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { | 1107 | for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { |
1108 | emailList = (*it).emails(); | 1108 | emailList = (*it).emails(); |
1109 | if ( emailList.contains( email ) > 0 ) { | 1109 | if ( emailList.contains( email ) > 0 ) { |
1110 | found = true; | 1110 | found = true; |
1111 | (*it).setNameFromString( fullName ); | 1111 | (*it).setNameFromString( fullName ); |
1112 | editContact( (*it).uid() ); | 1112 | editContact( (*it).uid() ); |
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | if ( !found ) { | 1116 | if ( !found ) { |
1117 | KABC::Addressee addr; | 1117 | KABC::Addressee addr; |
1118 | addr.setNameFromString( fullName ); | 1118 | addr.setNameFromString( fullName ); |
1119 | addr.insertEmail( email, true ); | 1119 | addr.insertEmail( email, true ); |
1120 | 1120 | ||
1121 | mAddressBook->insertAddressee( addr ); | 1121 | mAddressBook->insertAddressee( addr ); |
1122 | mViewManager->refreshView( addr.uid() ); | 1122 | mViewManager->refreshView( addr.uid() ); |
1123 | editContact( addr.uid() ); | 1123 | editContact( addr.uid() ); |
1124 | } | 1124 | } |
1125 | #else //KAB_EMBEDDED | 1125 | #else //KAB_EMBEDDED |
1126 | qDebug("KABCore::addEmail finsih method"); | 1126 | qDebug("KABCore::addEmail finsih method"); |
1127 | #endif //KAB_EMBEDDED | 1127 | #endif //KAB_EMBEDDED |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | void KABCore::importVCard( const KURL &url, bool showPreview ) | 1130 | void KABCore::importVCard( const KURL &url, bool showPreview ) |
1131 | { | 1131 | { |
1132 | mXXPortManager->importVCard( url, showPreview ); | 1132 | mXXPortManager->importVCard( url, showPreview ); |
1133 | } | 1133 | } |
1134 | void KABCore::importFromOL() | 1134 | void KABCore::importFromOL() |
1135 | { | 1135 | { |
1136 | #ifdef _WIN32_ | 1136 | #ifdef _WIN32_ |
1137 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); | 1137 | KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); |
1138 | idgl->exec(); | 1138 | idgl->exec(); |
1139 | KABC::Addressee::List list = idgl->getAddressList(); | 1139 | KABC::Addressee::List list = idgl->getAddressList(); |
1140 | if ( list.count() > 0 ) { | 1140 | if ( list.count() > 0 ) { |
1141 | KABC::Addressee::List listNew; | 1141 | KABC::Addressee::List listNew; |
1142 | KABC::Addressee::List listExisting; | 1142 | KABC::Addressee::List listExisting; |
1143 | KABC::Addressee::List::Iterator it; | 1143 | KABC::Addressee::List::Iterator it; |
1144 | KABC::AddressBook::Iterator iter; | 1144 | KABC::AddressBook::Iterator iter; |
1145 | for ( it = list.begin(); it != list.end(); ++it ) { | 1145 | for ( it = list.begin(); it != list.end(); ++it ) { |
1146 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) | 1146 | if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) |
1147 | listNew.append( (*it) ); | 1147 | listNew.append( (*it) ); |
1148 | else | 1148 | else |
1149 | listExisting.append( (*it) ); | 1149 | listExisting.append( (*it) ); |
1150 | } | 1150 | } |
1151 | if ( listExisting.count() > 0 ) | 1151 | if ( listExisting.count() > 0 ) |
1152 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); | 1152 | KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); |
1153 | if ( listNew.count() > 0 ) { | 1153 | if ( listNew.count() > 0 ) { |
1154 | pasteWithNewUid = false; | 1154 | pasteWithNewUid = false; |
1155 | pasteContacts( listNew ); | 1155 | pasteContacts( listNew ); |
1156 | pasteWithNewUid = true; | 1156 | pasteWithNewUid = true; |
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | delete idgl; | 1159 | delete idgl; |
1160 | #endif | 1160 | #endif |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | void KABCore::importVCard( const QString &vCard, bool showPreview ) | 1163 | void KABCore::importVCard( const QString &vCard, bool showPreview ) |
1164 | { | 1164 | { |
1165 | mXXPortManager->importVCard( vCard, showPreview ); | 1165 | mXXPortManager->importVCard( vCard, showPreview ); |
1166 | } | 1166 | } |
1167 | 1167 | ||
1168 | //US added a second method without defaultparameter | 1168 | //US added a second method without defaultparameter |
1169 | void KABCore::editContact2() { | 1169 | void KABCore::editContact2() { |
1170 | editContact( QString::null ); | 1170 | editContact( QString::null ); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | void KABCore::editContact( const QString &uid ) | 1173 | void KABCore::editContact( const QString &uid ) |
1174 | { | 1174 | { |
1175 | 1175 | ||
1176 | if ( mExtensionManager->isQuickEditVisible() ) | 1176 | if ( mExtensionManager->isQuickEditVisible() ) |
1177 | return; | 1177 | return; |
1178 | 1178 | ||
1179 | // First, locate the contact entry | 1179 | // First, locate the contact entry |
1180 | QString localUID = uid; | 1180 | QString localUID = uid; |
1181 | if ( localUID.isNull() ) { | 1181 | if ( localUID.isNull() ) { |
1182 | QStringList uidList = mViewManager->selectedUids(); | 1182 | QStringList uidList = mViewManager->selectedUids(); |
1183 | if ( uidList.count() > 0 ) | 1183 | if ( uidList.count() > 0 ) |
1184 | localUID = *( uidList.at( 0 ) ); | 1184 | localUID = *( uidList.at( 0 ) ); |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); | 1187 | KABC::Addressee addr = mAddressBook->findByUid( localUID ); |
1188 | if ( !addr.isEmpty() ) { | 1188 | if ( !addr.isEmpty() ) { |
1189 | mEditorDialog->setAddressee( addr ); | 1189 | mEditorDialog->setAddressee( addr ); |
1190 | KApplication::execDialog ( mEditorDialog ); | 1190 | KApplication::execDialog ( mEditorDialog ); |
1191 | } | 1191 | } |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | /** | 1194 | /** |
1195 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 1195 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
1196 | the method will try to find a selected addressee in the view. | 1196 | the method will try to find a selected addressee in the view. |
1197 | */ | 1197 | */ |
1198 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | 1198 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) |
1199 | { | 1199 | { |
1200 | if ( mMultipleViewsAtOnce ) | 1200 | if ( mMultipleViewsAtOnce ) |
1201 | { | 1201 | { |
1202 | editContact( uid ); | 1202 | editContact( uid ); |
1203 | } | 1203 | } |
1204 | else | 1204 | else |
1205 | { | 1205 | { |
1206 | setDetailsVisible( true ); | 1206 | setDetailsVisible( true ); |
1207 | mActionDetails->setChecked(true); | 1207 | mActionDetails->setChecked(true); |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | void KABCore::save() | 1212 | void KABCore::save() |
1213 | { | 1213 | { |
1214 | if (syncManager->blockSave()) | 1214 | if (syncManager->blockSave()) |
1215 | return; | 1215 | return; |
1216 | if ( !mModified ) | 1216 | if ( !mModified ) |
1217 | return; | 1217 | return; |
1218 | 1218 | ||
1219 | syncManager->setBlockSave(true); | 1219 | syncManager->setBlockSave(true); |
1220 | QString text = i18n( "There was an error while attempting to save\n the " | 1220 | QString text = i18n( "There was an error while attempting to save\n the " |
1221 | "address book. Please check that some \nother application is " | 1221 | "address book. Please check that some \nother application is " |
1222 | "not using it. " ); | 1222 | "not using it. " ); |
1223 | message(i18n("Saving addressbook ... ")); | 1223 | message(i18n("Saving addressbook ... ")); |
1224 | #ifndef KAB_EMBEDDED | 1224 | #ifndef KAB_EMBEDDED |
1225 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); | 1225 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); |
1226 | if ( !b || !b->save() ) { | 1226 | if ( !b || !b->save() ) { |
1227 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); | 1227 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); |
1228 | } | 1228 | } |
1229 | #else //KAB_EMBEDDED | 1229 | #else //KAB_EMBEDDED |
1230 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); | 1230 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); |
1231 | if ( !b || !b->save() ) { | 1231 | if ( !b || !b->save() ) { |
1232 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1232 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1233 | } | 1233 | } |
1234 | #endif //KAB_EMBEDDED | 1234 | #endif //KAB_EMBEDDED |
1235 | 1235 | ||
1236 | message(i18n("Addressbook saved!")); | 1236 | message(i18n("Addressbook saved!")); |
1237 | setModified( false ); | 1237 | setModified( false ); |
1238 | syncManager->setBlockSave(false); | 1238 | syncManager->setBlockSave(false); |
1239 | } | 1239 | } |
1240 | 1240 | ||
1241 | 1241 | ||
1242 | void KABCore::undo() | 1242 | void KABCore::undo() |
1243 | { | 1243 | { |
1244 | UndoStack::instance()->undo(); | 1244 | UndoStack::instance()->undo(); |
1245 | 1245 | ||
1246 | // Refresh the view | 1246 | // Refresh the view |
1247 | mViewManager->refreshView(); | 1247 | mViewManager->refreshView(); |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | void KABCore::redo() | 1250 | void KABCore::redo() |
1251 | { | 1251 | { |
1252 | RedoStack::instance()->redo(); | 1252 | RedoStack::instance()->redo(); |
1253 | 1253 | ||
1254 | // Refresh the view | 1254 | // Refresh the view |
1255 | mViewManager->refreshView(); | 1255 | mViewManager->refreshView(); |
1256 | } | 1256 | } |
1257 | 1257 | ||
1258 | void KABCore::setJumpButtonBarVisible( bool visible ) | 1258 | void KABCore::setJumpButtonBarVisible( bool visible ) |
1259 | { | 1259 | { |
1260 | if (mMultipleViewsAtOnce) | 1260 | if (mMultipleViewsAtOnce) |
1261 | { | 1261 | { |
1262 | if ( visible ) | 1262 | if ( visible ) |
1263 | mJumpButtonBar->show(); | 1263 | mJumpButtonBar->show(); |
1264 | else | 1264 | else |
1265 | mJumpButtonBar->hide(); | 1265 | mJumpButtonBar->hide(); |
1266 | } | 1266 | } |
1267 | else | 1267 | else |
1268 | { | 1268 | { |
1269 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" | 1269 | // show the jumpbar only if "the details are hidden" == "viewmanager are shown" |
1270 | if (mViewManager->isVisible()) | 1270 | if (mViewManager->isVisible()) |
1271 | { | 1271 | { |
1272 | if ( visible ) | 1272 | if ( visible ) |
1273 | mJumpButtonBar->show(); | 1273 | mJumpButtonBar->show(); |
1274 | else | 1274 | else |
1275 | mJumpButtonBar->hide(); | 1275 | mJumpButtonBar->hide(); |
1276 | } | 1276 | } |
1277 | else | 1277 | else |
1278 | { | 1278 | { |
1279 | mJumpButtonBar->hide(); | 1279 | mJumpButtonBar->hide(); |
1280 | } | 1280 | } |
1281 | } | 1281 | } |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | 1284 | ||
1285 | void KABCore::setDetailsToState() | 1285 | void KABCore::setDetailsToState() |
1286 | { | 1286 | { |
1287 | setDetailsVisible( mActionDetails->isChecked() ); | 1287 | setDetailsVisible( mActionDetails->isChecked() ); |
1288 | } | 1288 | } |
1289 | 1289 | ||
1290 | 1290 | ||
1291 | 1291 | ||
1292 | void KABCore::setDetailsVisible( bool visible ) | 1292 | void KABCore::setDetailsVisible( bool visible ) |
1293 | { | 1293 | { |
1294 | if (visible && mDetails->isHidden()) | 1294 | if (visible && mDetails->isHidden()) |
1295 | { | 1295 | { |
1296 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 1296 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
1297 | if ( addrList.count() > 0 ) | 1297 | if ( addrList.count() > 0 ) |
1298 | mDetails->setAddressee( addrList[ 0 ] ); | 1298 | mDetails->setAddressee( addrList[ 0 ] ); |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between | 1301 | // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between |
1302 | // the listview and the detailview. We do that by changing the splitbar size. | 1302 | // the listview and the detailview. We do that by changing the splitbar size. |
1303 | if (mMultipleViewsAtOnce) | 1303 | if (mMultipleViewsAtOnce) |
1304 | { | 1304 | { |
1305 | if ( visible ) | 1305 | if ( visible ) |
1306 | mDetails->show(); | 1306 | mDetails->show(); |
1307 | else | 1307 | else |
1308 | mDetails->hide(); | 1308 | mDetails->hide(); |
1309 | } | 1309 | } |
1310 | else | 1310 | else |
1311 | { | 1311 | { |
1312 | if ( visible ) { | 1312 | if ( visible ) { |
1313 | mViewManager->hide(); | 1313 | mViewManager->hide(); |
1314 | mDetails->show(); | 1314 | mDetails->show(); |
1315 | } | 1315 | } |
1316 | else { | 1316 | else { |
1317 | mViewManager->show(); | 1317 | mViewManager->show(); |
1318 | mDetails->hide(); | 1318 | mDetails->hide(); |
1319 | } | 1319 | } |
1320 | setJumpButtonBarVisible( !visible ); | 1320 | setJumpButtonBarVisible( !visible ); |
1321 | } | 1321 | } |
1322 | 1322 | ||
1323 | } | 1323 | } |
1324 | 1324 | ||
1325 | void KABCore::extensionChanged( int id ) | 1325 | void KABCore::extensionChanged( int id ) |
1326 | { | 1326 | { |
1327 | //change the details view only for non desktop systems | 1327 | //change the details view only for non desktop systems |
1328 | #ifndef DESKTOP_VERSION | 1328 | #ifndef DESKTOP_VERSION |
1329 | 1329 | ||
1330 | if (id == 0) | 1330 | if (id == 0) |
1331 | { | 1331 | { |
1332 | //the user disabled the extension. | 1332 | //the user disabled the extension. |
1333 | 1333 | ||
1334 | if (mMultipleViewsAtOnce) | 1334 | if (mMultipleViewsAtOnce) |
1335 | { // enable detailsview again | 1335 | { // enable detailsview again |
1336 | setDetailsVisible( true ); | 1336 | setDetailsVisible( true ); |
1337 | mActionDetails->setChecked( true ); | 1337 | mActionDetails->setChecked( true ); |
1338 | } | 1338 | } |
1339 | else | 1339 | else |
1340 | { //go back to the listview | 1340 | { //go back to the listview |
1341 | setDetailsVisible( false ); | 1341 | setDetailsVisible( false ); |
1342 | mActionDetails->setChecked( false ); | 1342 | mActionDetails->setChecked( false ); |
1343 | mActionDetails->setEnabled(true); | 1343 | mActionDetails->setEnabled(true); |
1344 | } | 1344 | } |
1345 | 1345 | ||
1346 | } | 1346 | } |
1347 | else | 1347 | else |
1348 | { | 1348 | { |
1349 | //the user enabled the extension. | 1349 | //the user enabled the extension. |
1350 | setDetailsVisible( false ); | 1350 | setDetailsVisible( false ); |
1351 | mActionDetails->setChecked( false ); | 1351 | mActionDetails->setChecked( false ); |
1352 | 1352 | ||
1353 | if (!mMultipleViewsAtOnce) | 1353 | if (!mMultipleViewsAtOnce) |
1354 | { | 1354 | { |
1355 | mActionDetails->setEnabled(false); | 1355 | mActionDetails->setEnabled(false); |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | mExtensionManager->setSelectionChanged(); | 1358 | mExtensionManager->setSelectionChanged(); |
1359 | 1359 | ||
1360 | } | 1360 | } |
1361 | 1361 | ||
1362 | #endif// DESKTOP_VERSION | 1362 | #endif// DESKTOP_VERSION |
1363 | 1363 | ||
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | 1366 | ||
1367 | void KABCore::extensionModified( const KABC::Addressee::List &list ) | 1367 | void KABCore::extensionModified( const KABC::Addressee::List &list ) |
1368 | { | 1368 | { |
1369 | 1369 | ||
1370 | if ( list.count() != 0 ) { | 1370 | if ( list.count() != 0 ) { |
1371 | KABC::Addressee::List::ConstIterator it; | 1371 | KABC::Addressee::List::ConstIterator it; |
1372 | for ( it = list.begin(); it != list.end(); ++it ) | 1372 | for ( it = list.begin(); it != list.end(); ++it ) |
1373 | mAddressBook->insertAddressee( *it ); | 1373 | mAddressBook->insertAddressee( *it ); |
1374 | if ( list.count() > 1 ) | 1374 | if ( list.count() > 1 ) |
1375 | setModified(); | 1375 | setModified(); |
1376 | else | 1376 | else |
1377 | setModifiedWOrefresh(); | 1377 | setModifiedWOrefresh(); |
1378 | } | 1378 | } |
1379 | if ( list.count() == 0 ) | 1379 | if ( list.count() == 0 ) |
1380 | mViewManager->refreshView(); | 1380 | mViewManager->refreshView(); |
1381 | else | 1381 | else |
1382 | mViewManager->refreshView( list[ 0 ].uid() ); | 1382 | mViewManager->refreshView( list[ 0 ].uid() ); |
1383 | 1383 | ||
1384 | 1384 | ||
1385 | 1385 | ||
1386 | } | 1386 | } |
1387 | 1387 | ||
1388 | QString KABCore::getNameByPhone( const QString &phone ) | 1388 | QString KABCore::getNameByPhone( const QString &phone ) |
1389 | { | 1389 | { |
1390 | #ifndef KAB_EMBEDDED | 1390 | #ifndef KAB_EMBEDDED |
1391 | QRegExp r( "[/*/-/ ]" ); | 1391 | QRegExp r( "[/*/-/ ]" ); |
1392 | QString localPhone( phone ); | 1392 | QString localPhone( phone ); |
1393 | 1393 | ||
1394 | bool found = false; | 1394 | bool found = false; |
1395 | QString ownerName = ""; | 1395 | QString ownerName = ""; |
1396 | KABC::AddressBook::Iterator iter; | 1396 | KABC::AddressBook::Iterator iter; |
1397 | KABC::PhoneNumber::List::Iterator phoneIter; | 1397 | KABC::PhoneNumber::List::Iterator phoneIter; |
1398 | KABC::PhoneNumber::List phoneList; | 1398 | KABC::PhoneNumber::List phoneList; |
1399 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { | 1399 | for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { |
1400 | phoneList = (*iter).phoneNumbers(); | 1400 | phoneList = (*iter).phoneNumbers(); |
1401 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); | 1401 | for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); |
1402 | ++phoneIter) { | 1402 | ++phoneIter) { |
1403 | // Get rid of separator chars so just the numbers are compared. | 1403 | // Get rid of separator chars so just the numbers are compared. |
1404 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { | 1404 | if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { |
1405 | ownerName = (*iter).formattedName(); | 1405 | ownerName = (*iter).formattedName(); |
1406 | found = true; | 1406 | found = true; |
1407 | } | 1407 | } |
1408 | } | 1408 | } |
1409 | } | 1409 | } |
1410 | 1410 | ||
1411 | return ownerName; | 1411 | return ownerName; |
1412 | #else //KAB_EMBEDDED | 1412 | #else //KAB_EMBEDDED |
1413 | qDebug("KABCore::getNameByPhone finsih method"); | 1413 | qDebug("KABCore::getNameByPhone finsih method"); |
1414 | return ""; | 1414 | return ""; |
1415 | #endif //KAB_EMBEDDED | 1415 | #endif //KAB_EMBEDDED |
1416 | 1416 | ||
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | void KABCore::openConfigDialog() | 1419 | void KABCore::openConfigDialog() |
1420 | { | 1420 | { |
1421 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); | 1421 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); |
1422 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); | 1422 | KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); |
1423 | ConfigureDialog->addModule(kabcfg ); | 1423 | ConfigureDialog->addModule(kabcfg ); |
1424 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 1424 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
1425 | ConfigureDialog->addModule(kdelibcfg ); | 1425 | ConfigureDialog->addModule(kdelibcfg ); |
1426 | 1426 | ||
1427 | connect( ConfigureDialog, SIGNAL( applyClicked() ), | 1427 | connect( ConfigureDialog, SIGNAL( applyClicked() ), |
1428 | this, SLOT( configurationChanged() ) ); | 1428 | this, SLOT( configurationChanged() ) ); |
1429 | connect( ConfigureDialog, SIGNAL( okClicked() ), | 1429 | connect( ConfigureDialog, SIGNAL( okClicked() ), |
1430 | this, SLOT( configurationChanged() ) ); | 1430 | this, SLOT( configurationChanged() ) ); |
1431 | saveSettings(); | 1431 | saveSettings(); |
1432 | #ifndef DESKTOP_VERSION | 1432 | #ifndef DESKTOP_VERSION |
1433 | ConfigureDialog->showMaximized(); | 1433 | ConfigureDialog->showMaximized(); |
1434 | #endif | 1434 | #endif |
1435 | if ( ConfigureDialog->exec() ) | 1435 | if ( ConfigureDialog->exec() ) |
1436 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 1436 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
1437 | delete ConfigureDialog; | 1437 | delete ConfigureDialog; |
1438 | } | 1438 | } |
1439 | 1439 | ||
1440 | void KABCore::openLDAPDialog() | 1440 | void KABCore::openLDAPDialog() |
1441 | { | 1441 | { |
1442 | #ifndef KAB_EMBEDDED | 1442 | #ifndef KAB_EMBEDDED |
1443 | if ( !mLdapSearchDialog ) { | 1443 | if ( !mLdapSearchDialog ) { |
1444 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); | 1444 | mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); |
1445 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, | 1445 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, |
1446 | SLOT( refreshView() ) ); | 1446 | SLOT( refreshView() ) ); |
1447 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, | 1447 | connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, |
1448 | SLOT( setModified() ) ); | 1448 | SLOT( setModified() ) ); |
1449 | } else | 1449 | } else |
1450 | mLdapSearchDialog->restoreSettings(); | 1450 | mLdapSearchDialog->restoreSettings(); |
1451 | 1451 | ||
1452 | if ( mLdapSearchDialog->isOK() ) | 1452 | if ( mLdapSearchDialog->isOK() ) |
1453 | mLdapSearchDialog->exec(); | 1453 | mLdapSearchDialog->exec(); |
1454 | #else //KAB_EMBEDDED | 1454 | #else //KAB_EMBEDDED |
1455 | qDebug("KABCore::openLDAPDialog() finsih method"); | 1455 | qDebug("KABCore::openLDAPDialog() finsih method"); |
1456 | #endif //KAB_EMBEDDED | 1456 | #endif //KAB_EMBEDDED |
1457 | } | 1457 | } |
1458 | 1458 | ||
1459 | void KABCore::print() | 1459 | void KABCore::print() |
1460 | { | 1460 | { |
1461 | #ifndef KAB_EMBEDDED | 1461 | #ifndef KAB_EMBEDDED |
1462 | KPrinter printer; | 1462 | KPrinter printer; |
1463 | if ( !printer.setup( this ) ) | 1463 | if ( !printer.setup( this ) ) |
1464 | return; | 1464 | return; |
1465 | 1465 | ||
1466 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, | 1466 | KABPrinting::PrintingWizard wizard( &printer, mAddressBook, |
1467 | mViewManager->selectedUids(), this ); | 1467 | mViewManager->selectedUids(), this ); |
1468 | 1468 | ||
1469 | wizard.exec(); | 1469 | wizard.exec(); |
1470 | #else //KAB_EMBEDDED | 1470 | #else //KAB_EMBEDDED |
1471 | qDebug("KABCore::print() finsih method"); | 1471 | qDebug("KABCore::print() finsih method"); |
1472 | #endif //KAB_EMBEDDED | 1472 | #endif //KAB_EMBEDDED |
1473 | 1473 | ||
1474 | } | 1474 | } |
1475 | 1475 | ||
1476 | 1476 | ||
1477 | void KABCore::addGUIClient( KXMLGUIClient *client ) | 1477 | void KABCore::addGUIClient( KXMLGUIClient *client ) |
1478 | { | 1478 | { |
1479 | if ( mGUIClient ) | 1479 | if ( mGUIClient ) |
1480 | mGUIClient->insertChildClient( client ); | 1480 | mGUIClient->insertChildClient( client ); |
1481 | else | 1481 | else |
1482 | KMessageBox::error( this, "no KXMLGUICLient"); | 1482 | KMessageBox::error( this, "no KXMLGUICLient"); |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | 1485 | ||
1486 | void KABCore::configurationChanged() | 1486 | void KABCore::configurationChanged() |
1487 | { | 1487 | { |
1488 | mExtensionManager->reconfigure(); | 1488 | mExtensionManager->reconfigure(); |
1489 | } | 1489 | } |
1490 | 1490 | ||
1491 | void KABCore::addressBookChanged() | 1491 | void KABCore::addressBookChanged() |
1492 | { | 1492 | { |
1493 | /*US | 1493 | /*US |
1494 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); | 1494 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); |
1495 | while ( it.current() ) { | 1495 | while ( it.current() ) { |
1496 | if ( it.current()->dirty() ) { | 1496 | if ( it.current()->dirty() ) { |
1497 | QString text = i18n( "Data has been changed externally. Unsaved " | 1497 | QString text = i18n( "Data has been changed externally. Unsaved " |
1498 | "changes will be lost." ); | 1498 | "changes will be lost." ); |
1499 | KMessageBox::information( this, text ); | 1499 | KMessageBox::information( this, text ); |
1500 | } | 1500 | } |
1501 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); | 1501 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); |
1502 | ++it; | 1502 | ++it; |
1503 | } | 1503 | } |
1504 | */ | 1504 | */ |
1505 | if (mEditorDialog) | 1505 | if (mEditorDialog) |
1506 | { | 1506 | { |
1507 | if (mEditorDialog->dirty()) | 1507 | if (mEditorDialog->dirty()) |
1508 | { | 1508 | { |
1509 | QString text = i18n( "Data has been changed externally. Unsaved " | 1509 | QString text = i18n( "Data has been changed externally. Unsaved " |
1510 | "changes will be lost." ); | 1510 | "changes will be lost." ); |
1511 | KMessageBox::information( this, text ); | 1511 | KMessageBox::information( this, text ); |
1512 | } | 1512 | } |
1513 | QString currentuid = mEditorDialog->addressee().uid(); | 1513 | QString currentuid = mEditorDialog->addressee().uid(); |
1514 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); | 1514 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); |
1515 | } | 1515 | } |
1516 | mViewManager->refreshView(); | 1516 | mViewManager->refreshView(); |
1517 | // mDetails->refreshView(); | 1517 | // mDetails->refreshView(); |
1518 | 1518 | ||
1519 | 1519 | ||
1520 | } | 1520 | } |
1521 | 1521 | ||
1522 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, | 1522 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, |
1523 | const char *name ) | 1523 | const char *name ) |
1524 | { | 1524 | { |
1525 | 1525 | ||
1526 | if ( mEditorDialog == 0 ) { | 1526 | if ( mEditorDialog == 0 ) { |
1527 | mEditorDialog = new AddresseeEditorDialog( this, parent, | 1527 | mEditorDialog = new AddresseeEditorDialog( this, parent, |
1528 | name ? name : "editorDialog" ); | 1528 | name ? name : "editorDialog" ); |
1529 | 1529 | ||
1530 | 1530 | ||
1531 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), | 1531 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), |
1532 | SLOT( contactModified( const KABC::Addressee& ) ) ); | 1532 | SLOT( contactModified( const KABC::Addressee& ) ) ); |
1533 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), | 1533 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), |
1534 | // SLOT( slotEditorDestroyed( const QString& ) ) ; | 1534 | // SLOT( slotEditorDestroyed( const QString& ) ) ; |
1535 | } | 1535 | } |
1536 | 1536 | ||
1537 | return mEditorDialog; | 1537 | return mEditorDialog; |
1538 | } | 1538 | } |
1539 | 1539 | ||
1540 | void KABCore::slotEditorDestroyed( const QString &uid ) | 1540 | void KABCore::slotEditorDestroyed( const QString &uid ) |
1541 | { | 1541 | { |
1542 | //mEditorDict.remove( uid ); | 1542 | //mEditorDict.remove( uid ); |
1543 | } | 1543 | } |
1544 | 1544 | ||
1545 | void KABCore::initGUI() | 1545 | void KABCore::initGUI() |
1546 | { | 1546 | { |
1547 | #ifndef KAB_EMBEDDED | 1547 | #ifndef KAB_EMBEDDED |
1548 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1548 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1549 | topLayout->setSpacing( KDialogBase::spacingHint() ); | 1549 | topLayout->setSpacing( KDialogBase::spacingHint() ); |
1550 | 1550 | ||
1551 | mExtensionBarSplitter = new QSplitter( this ); | 1551 | mExtensionBarSplitter = new QSplitter( this ); |
1552 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); | 1552 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); |
1553 | 1553 | ||
1554 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); | 1554 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); |
1555 | 1555 | ||
1556 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1556 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1557 | mIncSearchWidget = new IncSearchWidget( viewSpace ); | 1557 | mIncSearchWidget = new IncSearchWidget( viewSpace ); |
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 | mViewManager = new ViewManager( this, viewSpace ); | 1561 | mViewManager = new ViewManager( this, viewSpace ); |
1562 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1562 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1563 | 1563 | ||
1564 | mDetails = new ViewContainer( mDetailsSplitter ); | 1564 | mDetails = new ViewContainer( mDetailsSplitter ); |
1565 | 1565 | ||
1566 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1566 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1567 | 1567 | ||
1568 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1568 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1569 | 1569 | ||
1570 | topLayout->addWidget( mExtensionBarSplitter ); | 1570 | topLayout->addWidget( mExtensionBarSplitter ); |
1571 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); | 1571 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); |
1572 | topLayout->addWidget( mJumpButtonBar ); | 1572 | topLayout->addWidget( mJumpButtonBar ); |
1573 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); | 1573 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); |
1574 | 1574 | ||
1575 | mXXPortManager = new XXPortManager( this, this ); | 1575 | mXXPortManager = new XXPortManager( this, this ); |
1576 | 1576 | ||
1577 | #else //KAB_EMBEDDED | 1577 | #else //KAB_EMBEDDED |
1578 | //US initialize viewMenu before settingup viewmanager. | 1578 | //US initialize viewMenu before settingup viewmanager. |
1579 | // Viewmanager needs this menu to plugin submenues. | 1579 | // Viewmanager needs this menu to plugin submenues. |
1580 | viewMenu = new QPopupMenu( this ); | 1580 | viewMenu = new QPopupMenu( this ); |
1581 | settingsMenu = new QPopupMenu( this ); | 1581 | settingsMenu = new QPopupMenu( this ); |
1582 | //filterMenu = new QPopupMenu( this ); | 1582 | //filterMenu = new QPopupMenu( this ); |
1583 | ImportMenu = new QPopupMenu( this ); | 1583 | ImportMenu = new QPopupMenu( this ); |
1584 | ExportMenu = new QPopupMenu( this ); | 1584 | ExportMenu = new QPopupMenu( this ); |
1585 | syncMenu = new QPopupMenu( this ); | 1585 | syncMenu = new QPopupMenu( this ); |
1586 | changeMenu= new QPopupMenu( this ); | 1586 | changeMenu= new QPopupMenu( this ); |
1587 | 1587 | ||
1588 | //US since we have no splitter for the embedded system, setup | 1588 | //US since we have no splitter for the embedded system, setup |
1589 | // a layout with two frames. One left and one right. | 1589 | // a layout with two frames. One left and one right. |
1590 | 1590 | ||
1591 | QBoxLayout *topLayout; | 1591 | QBoxLayout *topLayout; |
1592 | 1592 | ||
1593 | // = new QHBoxLayout( this ); | 1593 | // = new QHBoxLayout( this ); |
1594 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); | 1594 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); |
1595 | 1595 | ||
1596 | // QWidget *mainBox = new QWidget( this ); | 1596 | // QWidget *mainBox = new QWidget( this ); |
1597 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); | 1597 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); |
1598 | 1598 | ||
1599 | #ifdef DESKTOP_VERSION | 1599 | #ifdef DESKTOP_VERSION |
1600 | topLayout = new QHBoxLayout( this ); | 1600 | topLayout = new QHBoxLayout( this ); |
1601 | 1601 | ||
1602 | 1602 | ||
1603 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1603 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1604 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1604 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1605 | 1605 | ||
1606 | topLayout->addWidget(mMiniSplitter ); | 1606 | topLayout->addWidget(mMiniSplitter ); |
1607 | 1607 | ||
1608 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); | 1608 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); |
1609 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1609 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1610 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); | 1610 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); |
1611 | mDetails = new ViewContainer( mMiniSplitter ); | 1611 | mDetails = new ViewContainer( mMiniSplitter ); |
1612 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1612 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1613 | #else | 1613 | #else |
1614 | if ( QApplication::desktop()->width() > 480 ) { | 1614 | if ( QApplication::desktop()->width() > 480 ) { |
1615 | topLayout = new QHBoxLayout( this ); | 1615 | topLayout = new QHBoxLayout( this ); |
1616 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1616 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1617 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1617 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1618 | } else { | 1618 | } else { |
1619 | 1619 | ||
1620 | topLayout = new QHBoxLayout( this ); | 1620 | topLayout = new QHBoxLayout( this ); |
1621 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 1621 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
1622 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1622 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1623 | } | 1623 | } |
1624 | 1624 | ||
1625 | topLayout->addWidget(mMiniSplitter ); | 1625 | topLayout->addWidget(mMiniSplitter ); |
1626 | mViewManager = new ViewManager( this, mMiniSplitter ); | 1626 | mViewManager = new ViewManager( this, mMiniSplitter ); |
1627 | mDetails = new ViewContainer( mMiniSplitter ); | 1627 | mDetails = new ViewContainer( mMiniSplitter ); |
1628 | 1628 | ||
1629 | 1629 | ||
1630 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); | 1630 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); |
1631 | #endif | 1631 | #endif |
1632 | //eh->hide(); | 1632 | //eh->hide(); |
1633 | // topLayout->addWidget(mExtensionManager ); | 1633 | // topLayout->addWidget(mExtensionManager ); |
1634 | 1634 | ||
1635 | 1635 | ||
1636 | /*US | 1636 | /*US |
1637 | #ifndef KAB_NOSPLITTER | 1637 | #ifndef KAB_NOSPLITTER |
1638 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1638 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1639 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1639 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1640 | topLayout->setSpacing( 10 ); | 1640 | topLayout->setSpacing( 10 ); |
1641 | 1641 | ||
1642 | mDetailsSplitter = new QSplitter( this ); | 1642 | mDetailsSplitter = new QSplitter( this ); |
1643 | 1643 | ||
1644 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1644 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1645 | 1645 | ||
1646 | mViewManager = new ViewManager( this, viewSpace ); | 1646 | mViewManager = new ViewManager( this, viewSpace ); |
1647 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1647 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1648 | 1648 | ||
1649 | mDetails = new ViewContainer( mDetailsSplitter ); | 1649 | mDetails = new ViewContainer( mDetailsSplitter ); |
1650 | 1650 | ||
1651 | topLayout->addWidget( mDetailsSplitter ); | 1651 | topLayout->addWidget( mDetailsSplitter ); |
1652 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1652 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1653 | #else //KAB_NOSPLITTER | 1653 | #else //KAB_NOSPLITTER |
1654 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1654 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1655 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1655 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1656 | topLayout->setSpacing( 10 ); | 1656 | topLayout->setSpacing( 10 ); |
1657 | 1657 | ||
1658 | // mDetailsSplitter = new QSplitter( this ); | 1658 | // mDetailsSplitter = new QSplitter( this ); |
1659 | 1659 | ||
1660 | QVBox *viewSpace = new QVBox( this ); | 1660 | QVBox *viewSpace = new QVBox( this ); |
1661 | 1661 | ||
1662 | mViewManager = new ViewManager( this, viewSpace ); | 1662 | mViewManager = new ViewManager( this, viewSpace ); |
1663 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1663 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1664 | 1664 | ||
1665 | mDetails = new ViewContainer( this ); | 1665 | mDetails = new ViewContainer( this ); |
1666 | 1666 | ||
1667 | topLayout->addWidget( viewSpace ); | 1667 | topLayout->addWidget( viewSpace ); |
1668 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1668 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1669 | topLayout->addWidget( mDetails ); | 1669 | topLayout->addWidget( mDetails ); |
1670 | #endif //KAB_NOSPLITTER | 1670 | #endif //KAB_NOSPLITTER |
1671 | */ | 1671 | */ |
1672 | 1672 | ||
1673 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 1673 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
1674 | syncManager->setBlockSave(false); | 1674 | syncManager->setBlockSave(false); |
1675 | 1675 | ||
1676 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); | 1676 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); |
1677 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); | 1677 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); |
1678 | syncManager->setDefaultFileName( sentSyncFile()); | 1678 | syncManager->setDefaultFileName( sentSyncFile()); |
1679 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); | 1679 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); |
1680 | 1680 | ||
1681 | #endif //KAB_EMBEDDED | 1681 | #endif //KAB_EMBEDDED |
1682 | initActions(); | 1682 | initActions(); |
1683 | 1683 | ||
1684 | #ifdef KAB_EMBEDDED | 1684 | #ifdef KAB_EMBEDDED |
1685 | addActionsManually(); | 1685 | addActionsManually(); |
1686 | //US make sure the export and import menues are initialized before creating the xxPortManager. | 1686 | //US make sure the export and import menues are initialized before creating the xxPortManager. |
1687 | mXXPortManager = new XXPortManager( this, this ); | 1687 | mXXPortManager = new XXPortManager( this, this ); |
1688 | 1688 | ||
1689 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); | 1689 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); |
1690 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); | 1690 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); |
1691 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1691 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1692 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); | 1692 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); |
1693 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); | 1693 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); |
1694 | // mIncSearchWidget->hide(); | 1694 | // mIncSearchWidget->hide(); |
1695 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1695 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1696 | SLOT( incrementalSearch( const QString& ) ) ); | 1696 | SLOT( incrementalSearch( const QString& ) ) ); |
1697 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); | 1697 | connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); |
1698 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); | 1698 | connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); |
1699 | 1699 | ||
1700 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1700 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1701 | 1701 | ||
1702 | topLayout->addWidget( mJumpButtonBar ); | 1702 | topLayout->addWidget( mJumpButtonBar ); |
1703 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); | 1703 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); |
1704 | 1704 | ||
1705 | // mMainWindow->getIconToolBar()->raise(); | 1705 | // mMainWindow->getIconToolBar()->raise(); |
1706 | 1706 | ||
1707 | #endif //KAB_EMBEDDED | 1707 | #endif //KAB_EMBEDDED |
1708 | 1708 | ||
1709 | } | 1709 | } |
1710 | void KABCore::initActions() | 1710 | void KABCore::initActions() |
1711 | { | 1711 | { |
1712 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1712 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1713 | 1713 | ||
1714 | #ifndef KAB_EMBEDDED | 1714 | #ifndef KAB_EMBEDDED |
1715 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), | 1715 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), |
1716 | SLOT( clipboardDataChanged() ) ); | 1716 | SLOT( clipboardDataChanged() ) ); |
1717 | #endif //KAB_EMBEDDED | 1717 | #endif //KAB_EMBEDDED |
1718 | 1718 | ||
1719 | // file menu | 1719 | // file menu |
1720 | if ( mIsPart ) { | 1720 | if ( mIsPart ) { |
1721 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, | 1721 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, |
1722 | SLOT( sendMail() ), actionCollection(), | 1722 | SLOT( sendMail() ), actionCollection(), |
1723 | "kaddressbook_mail" ); | 1723 | "kaddressbook_mail" ); |
1724 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, | 1724 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, |
1725 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); | 1725 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); |
1726 | 1726 | ||
1727 | } else { | 1727 | } else { |
1728 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); | 1728 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); |
1729 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); | 1729 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); |
1730 | } | 1730 | } |
1731 | 1731 | ||
1732 | 1732 | ||
1733 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1733 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
1734 | SLOT( save() ), actionCollection(), "file_sync" ); | 1734 | SLOT( save() ), actionCollection(), "file_sync" ); |
1735 | 1735 | ||
1736 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, | 1736 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, |
1737 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1737 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1738 | 1738 | ||
1739 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1739 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1740 | this, SLOT( mailVCard() ), | 1740 | this, SLOT( mailVCard() ), |
1741 | actionCollection(), "file_mail_vcard"); | 1741 | actionCollection(), "file_mail_vcard"); |
1742 | 1742 | ||
1743 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, | 1743 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, |
1744 | SLOT( export2phone() ), actionCollection(), | 1744 | SLOT( export2phone() ), actionCollection(), |
1745 | "kaddressbook_ex2phone" ); | 1745 | "kaddressbook_ex2phone" ); |
1746 | 1746 | ||
1747 | mActionBeamVCard = 0; | 1747 | mActionBeamVCard = 0; |
1748 | mActionBeam = 0; | 1748 | mActionBeam = 0; |
1749 | 1749 | ||
1750 | #ifndef DESKTOP_VERSION | 1750 | #ifndef DESKTOP_VERSION |
1751 | if ( Ir::supported() ) { | 1751 | if ( Ir::supported() ) { |
1752 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, | 1752 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, |
1753 | SLOT( beamVCard() ), actionCollection(), | 1753 | SLOT( beamVCard() ), actionCollection(), |
1754 | "kaddressbook_beam_vcard" ); | 1754 | "kaddressbook_beam_vcard" ); |
1755 | 1755 | ||
1756 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, | 1756 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, |
1757 | SLOT( beamMySelf() ), actionCollection(), | 1757 | SLOT( beamMySelf() ), actionCollection(), |
1758 | "kaddressbook_beam_myself" ); | 1758 | "kaddressbook_beam_myself" ); |
1759 | } | 1759 | } |
1760 | #endif | 1760 | #endif |
1761 | 1761 | ||
1762 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1762 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
1763 | this, SLOT( editContact2() ), | 1763 | this, SLOT( editContact2() ), |
1764 | actionCollection(), "file_properties" ); | 1764 | actionCollection(), "file_properties" ); |
1765 | 1765 | ||
1766 | #ifdef KAB_EMBEDDED | 1766 | #ifdef KAB_EMBEDDED |
1767 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); | 1767 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); |
1768 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, | 1768 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, |
1769 | mMainWindow, SLOT( exit() ), | 1769 | mMainWindow, SLOT( exit() ), |
1770 | actionCollection(), "quit" ); | 1770 | actionCollection(), "quit" ); |
1771 | #endif //KAB_EMBEDDED | 1771 | #endif //KAB_EMBEDDED |
1772 | 1772 | ||
1773 | // edit menu | 1773 | // edit menu |
1774 | if ( mIsPart ) { | 1774 | if ( mIsPart ) { |
1775 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, | 1775 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, |
1776 | SLOT( copyContacts() ), actionCollection(), | 1776 | SLOT( copyContacts() ), actionCollection(), |
1777 | "kaddressbook_copy" ); | 1777 | "kaddressbook_copy" ); |
1778 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, | 1778 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, |
1779 | SLOT( cutContacts() ), actionCollection(), | 1779 | SLOT( cutContacts() ), actionCollection(), |
1780 | "kaddressbook_cut" ); | 1780 | "kaddressbook_cut" ); |
1781 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, | 1781 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, |
1782 | SLOT( pasteContacts() ), actionCollection(), | 1782 | SLOT( pasteContacts() ), actionCollection(), |
1783 | "kaddressbook_paste" ); | 1783 | "kaddressbook_paste" ); |
1784 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, | 1784 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, |
1785 | SLOT( selectAllContacts() ), actionCollection(), | 1785 | SLOT( selectAllContacts() ), actionCollection(), |
1786 | "kaddressbook_select_all" ); | 1786 | "kaddressbook_select_all" ); |
1787 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, | 1787 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, |
1788 | SLOT( undo() ), actionCollection(), | 1788 | SLOT( undo() ), actionCollection(), |
1789 | "kaddressbook_undo" ); | 1789 | "kaddressbook_undo" ); |
1790 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, | 1790 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, |
1791 | this, SLOT( redo() ), actionCollection(), | 1791 | this, SLOT( redo() ), actionCollection(), |
1792 | "kaddressbook_redo" ); | 1792 | "kaddressbook_redo" ); |
1793 | } else { | 1793 | } else { |
1794 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); | 1794 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); |
1795 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); | 1795 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); |
1796 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); | 1796 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); |
1797 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); | 1797 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); |
1798 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); | 1798 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); |
1799 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); | 1799 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); |
1800 | } | 1800 | } |
1801 | 1801 | ||
1802 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", | 1802 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", |
1803 | Key_Delete, this, SLOT( deleteContacts() ), | 1803 | Key_Delete, this, SLOT( deleteContacts() ), |
1804 | actionCollection(), "edit_delete" ); | 1804 | actionCollection(), "edit_delete" ); |
1805 | 1805 | ||
1806 | mActionUndo->setEnabled( false ); | 1806 | mActionUndo->setEnabled( false ); |
1807 | mActionRedo->setEnabled( false ); | 1807 | mActionRedo->setEnabled( false ); |
1808 | 1808 | ||
1809 | // settings menu | 1809 | // settings menu |
1810 | #ifdef KAB_EMBEDDED | 1810 | #ifdef KAB_EMBEDDED |
1811 | //US special menuentry to configure the addressbook resources. On KDE | 1811 | //US special menuentry to configure the addressbook resources. On KDE |
1812 | // you do that through the control center !!! | 1812 | // you do that through the control center !!! |
1813 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, | 1813 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, |
1814 | SLOT( configureResources() ), actionCollection(), | 1814 | SLOT( configureResources() ), actionCollection(), |
1815 | "kaddressbook_configure_resources" ); | 1815 | "kaddressbook_configure_resources" ); |
1816 | #endif //KAB_EMBEDDED | 1816 | #endif //KAB_EMBEDDED |
1817 | 1817 | ||
1818 | if ( mIsPart ) { | 1818 | if ( mIsPart ) { |
1819 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, | 1819 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, |
1820 | SLOT( openConfigDialog() ), actionCollection(), | 1820 | SLOT( openConfigDialog() ), actionCollection(), |
1821 | "kaddressbook_configure" ); | 1821 | "kaddressbook_configure" ); |
1822 | 1822 | ||
1823 | //US not implemented yet | 1823 | //US not implemented yet |
1824 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, | 1824 | //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, |
1825 | // this, SLOT( configureKeyBindings() ), actionCollection(), | 1825 | // this, SLOT( configureKeyBindings() ), actionCollection(), |
1826 | // "kaddressbook_configure_shortcuts" ); | 1826 | // "kaddressbook_configure_shortcuts" ); |
1827 | #ifdef KAB_EMBEDDED | 1827 | #ifdef KAB_EMBEDDED |
1828 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); | 1828 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); |
1829 | mActionConfigureToolbars->setEnabled( false ); | 1829 | mActionConfigureToolbars->setEnabled( false ); |
1830 | #endif //KAB_EMBEDDED | 1830 | #endif //KAB_EMBEDDED |
1831 | 1831 | ||
1832 | } else { | 1832 | } else { |
1833 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); | 1833 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); |
1834 | 1834 | ||
1835 | //US not implemented yet | 1835 | //US not implemented yet |
1836 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); | 1836 | //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); |
1837 | } | 1837 | } |
1838 | 1838 | ||
1839 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, | 1839 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, |
1840 | actionCollection(), "options_show_jump_bar" ); | 1840 | actionCollection(), "options_show_jump_bar" ); |
1841 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); | 1841 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); |
1842 | 1842 | ||
1843 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, | 1843 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, |
1844 | actionCollection(), "options_show_details" ); | 1844 | actionCollection(), "options_show_details" ); |
1845 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); | 1845 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); |
1846 | 1846 | ||
1847 | 1847 | ||
1848 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, | 1848 | mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, |
1849 | SLOT( toggleBeamReceive() ), actionCollection(), | 1849 | SLOT( toggleBeamReceive() ), actionCollection(), |
1850 | "kaddressbook_beam_rec" ); | 1850 | "kaddressbook_beam_rec" ); |
1851 | 1851 | ||
1852 | 1852 | ||
1853 | // misc | 1853 | // misc |
1854 | // only enable LDAP lookup if we can handle the protocol | 1854 | // only enable LDAP lookup if we can handle the protocol |
1855 | #ifndef KAB_EMBEDDED | 1855 | #ifndef KAB_EMBEDDED |
1856 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { | 1856 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { |
1857 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, | 1857 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, |
1858 | this, SLOT( openLDAPDialog() ), actionCollection(), | 1858 | this, SLOT( openLDAPDialog() ), actionCollection(), |
1859 | "ldap_lookup" ); | 1859 | "ldap_lookup" ); |
1860 | } | 1860 | } |
1861 | #else //KAB_EMBEDDED | 1861 | #else //KAB_EMBEDDED |
1862 | //qDebug("KABCore::initActions() LDAP has to be implemented"); | 1862 | //qDebug("KABCore::initActions() LDAP has to be implemented"); |
1863 | #endif //KAB_EMBEDDED | 1863 | #endif //KAB_EMBEDDED |
1864 | 1864 | ||
1865 | 1865 | ||
1866 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1866 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1867 | SLOT( setWhoAmI() ), actionCollection(), | 1867 | SLOT( setWhoAmI() ), actionCollection(), |
1868 | "set_personal" ); | 1868 | "set_personal" ); |
1869 | 1869 | ||
1870 | 1870 | ||
1871 | 1871 | ||
1872 | 1872 | ||
1873 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1873 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1874 | SLOT( setCategories() ), actionCollection(), | 1874 | SLOT( setCategories() ), actionCollection(), |
1875 | "edit_set_categories" ); | 1875 | "edit_set_categories" ); |
1876 | 1876 | ||
1877 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1877 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1878 | SLOT( removeVoice() ), actionCollection(), | 1878 | SLOT( removeVoice() ), actionCollection(), |
1879 | "remove_voice" ); | 1879 | "remove_voice" ); |
1880 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, | 1880 | mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, |
1881 | SLOT( importFromOL() ), actionCollection(), | 1881 | SLOT( importFromOL() ), actionCollection(), |
1882 | "import_OL" ); | 1882 | "import_OL" ); |
1883 | #ifdef KAB_EMBEDDED | 1883 | #ifdef KAB_EMBEDDED |
1884 | mActionLicence = new KAction( i18n( "Licence" ), 0, | 1884 | mActionLicence = new KAction( i18n( "Licence" ), 0, |
1885 | this, SLOT( showLicence() ), actionCollection(), | 1885 | this, SLOT( showLicence() ), actionCollection(), |
1886 | "licence_about_data" ); | 1886 | "licence_about_data" ); |
1887 | mActionFaq = new KAction( i18n( "Faq" ), 0, | 1887 | mActionFaq = new KAction( i18n( "Faq" ), 0, |
1888 | this, SLOT( faq() ), actionCollection(), | 1888 | this, SLOT( faq() ), actionCollection(), |
1889 | "faq_about_data" ); | 1889 | "faq_about_data" ); |
1890 | mActionWN = new KAction( i18n( "What's New?" ), 0, | 1890 | mActionWN = new KAction( i18n( "What's New?" ), 0, |
1891 | this, SLOT( whatsnew() ), actionCollection(), | 1891 | this, SLOT( whatsnew() ), actionCollection(), |
1892 | "wn" ); | 1892 | "wn" ); |
1893 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, | 1893 | mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, |
1894 | this, SLOT( synchowto() ), actionCollection(), | 1894 | this, SLOT( synchowto() ), actionCollection(), |
1895 | "sync" ); | 1895 | "sync" ); |
1896 | 1896 | ||
1897 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, | 1897 | mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, |
1898 | this, SLOT( createAboutData() ), actionCollection(), | 1898 | this, SLOT( createAboutData() ), actionCollection(), |
1899 | "kaddressbook_about_data" ); | 1899 | "kaddressbook_about_data" ); |
1900 | #endif //KAB_EMBEDDED | 1900 | #endif //KAB_EMBEDDED |
1901 | 1901 | ||
1902 | clipboardDataChanged(); | 1902 | clipboardDataChanged(); |
1903 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1903 | connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1904 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); | 1904 | connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); |
1905 | } | 1905 | } |
1906 | 1906 | ||
1907 | //US we need this function, to plug all actions into the correct menues. | 1907 | //US we need this function, to plug all actions into the correct menues. |
1908 | // KDE uses a XML format to plug the actions, but we work her without this overhead. | 1908 | // KDE uses a XML format to plug the actions, but we work her without this overhead. |
1909 | void KABCore::addActionsManually() | 1909 | void KABCore::addActionsManually() |
1910 | { | 1910 | { |
1911 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1911 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1912 | 1912 | ||
1913 | #ifdef KAB_EMBEDDED | 1913 | #ifdef KAB_EMBEDDED |
1914 | QPopupMenu *fileMenu = new QPopupMenu( this ); | 1914 | QPopupMenu *fileMenu = new QPopupMenu( this ); |
1915 | QPopupMenu *editMenu = new QPopupMenu( this ); | 1915 | QPopupMenu *editMenu = new QPopupMenu( this ); |
1916 | QPopupMenu *helpMenu = new QPopupMenu( this ); | 1916 | QPopupMenu *helpMenu = new QPopupMenu( this ); |
1917 | 1917 | ||
1918 | KToolBar* tb = mMainWindow->toolBar(); | 1918 | KToolBar* tb = mMainWindow->toolBar(); |
1919 | 1919 | ||
1920 | #ifdef DESKTOP_VERSION | 1920 | #ifdef DESKTOP_VERSION |
1921 | QMenuBar* mb = mMainWindow->menuBar(); | 1921 | QMenuBar* mb = mMainWindow->menuBar(); |
1922 | 1922 | ||
1923 | //US setup menubar. | 1923 | //US setup menubar. |
1924 | //Disable the following block if you do not want to have a menubar. | 1924 | //Disable the following block if you do not want to have a menubar. |
1925 | mb->insertItem( "&File", fileMenu ); | 1925 | mb->insertItem( "&File", fileMenu ); |
1926 | mb->insertItem( "&Edit", editMenu ); | 1926 | mb->insertItem( "&Edit", editMenu ); |
1927 | mb->insertItem( "&View", viewMenu ); | 1927 | mb->insertItem( "&View", viewMenu ); |
1928 | mb->insertItem( "&Settings", settingsMenu ); | 1928 | mb->insertItem( "&Settings", settingsMenu ); |
1929 | mb->insertItem( i18n("Synchronize"), syncMenu ); | 1929 | mb->insertItem( i18n("Synchronize"), syncMenu ); |
1930 | mb->insertItem( "&Change selected", changeMenu ); | 1930 | mb->insertItem( "&Change selected", changeMenu ); |
1931 | mb->insertItem( "&Help", helpMenu ); | 1931 | mb->insertItem( "&Help", helpMenu ); |
1932 | mIncSearchWidget = new IncSearchWidget( tb ); | 1932 | mIncSearchWidget = new IncSearchWidget( tb ); |
1933 | // tb->insertWidget(-1, 0, mIncSearchWidget); | 1933 | // tb->insertWidget(-1, 0, mIncSearchWidget); |
1934 | 1934 | ||
1935 | #else | 1935 | #else |
1936 | //US setup toolbar | 1936 | //US setup toolbar |
1937 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); | 1937 | QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); |
1938 | QPopupMenu *popupBarTB = new QPopupMenu( this ); | 1938 | QPopupMenu *popupBarTB = new QPopupMenu( this ); |
1939 | menuBarTB->insertItem( "ME", popupBarTB); | 1939 | menuBarTB->insertItem( "ME", popupBarTB); |
1940 | tb->insertWidget(-1, 0, menuBarTB); | 1940 | tb->insertWidget(-1, 0, menuBarTB); |
1941 | mIncSearchWidget = new IncSearchWidget( tb ); | 1941 | mIncSearchWidget = new IncSearchWidget( tb ); |
1942 | 1942 | ||
1943 | tb->enableMoving(false); | 1943 | tb->enableMoving(false); |
1944 | popupBarTB->insertItem( "&File", fileMenu ); | 1944 | popupBarTB->insertItem( "&File", fileMenu ); |
1945 | popupBarTB->insertItem( "&Edit", editMenu ); | 1945 | popupBarTB->insertItem( "&Edit", editMenu ); |
1946 | popupBarTB->insertItem( "&View", viewMenu ); | 1946 | popupBarTB->insertItem( "&View", viewMenu ); |
1947 | popupBarTB->insertItem( "&Settings", settingsMenu ); | 1947 | popupBarTB->insertItem( "&Settings", settingsMenu ); |
1948 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); | 1948 | popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); |
1949 | mViewManager->getFilterAction()->plug ( popupBarTB); | 1949 | mViewManager->getFilterAction()->plug ( popupBarTB); |
1950 | popupBarTB->insertItem( "&Change selected", changeMenu ); | 1950 | popupBarTB->insertItem( "&Change selected", changeMenu ); |
1951 | popupBarTB->insertItem( "&Help", helpMenu ); | 1951 | popupBarTB->insertItem( "&Help", helpMenu ); |
1952 | if (QApplication::desktop()->width() > 320 ) { | 1952 | if (QApplication::desktop()->width() > 320 ) { |
1953 | // mViewManager->getFilterAction()->plug ( tb); | 1953 | // mViewManager->getFilterAction()->plug ( tb); |
1954 | } | 1954 | } |
1955 | #endif | 1955 | #endif |
1956 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1956 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1957 | 1957 | ||
1958 | 1958 | ||
1959 | 1959 | ||
1960 | //US Now connect the actions with the menue entries. | 1960 | //US Now connect the actions with the menue entries. |
1961 | mActionPrint->plug( fileMenu ); | 1961 | mActionPrint->plug( fileMenu ); |
1962 | mActionMail->plug( fileMenu ); | 1962 | mActionMail->plug( fileMenu ); |
1963 | fileMenu->insertSeparator(); | 1963 | fileMenu->insertSeparator(); |
1964 | 1964 | ||
1965 | mActionNewContact->plug( fileMenu ); | 1965 | mActionNewContact->plug( fileMenu ); |
1966 | mActionNewContact->plug( tb ); | 1966 | mActionNewContact->plug( tb ); |
1967 | 1967 | ||
1968 | mActionEditAddressee->plug( fileMenu ); | 1968 | mActionEditAddressee->plug( fileMenu ); |
1969 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || | 1969 | if ((KGlobal::getDesktopSize() > KGlobal::Small ) || |
1970 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) | 1970 | (!KABPrefs::instance()->mMultipleViewsAtOnce )) |
1971 | mActionEditAddressee->plug( tb ); | 1971 | mActionEditAddressee->plug( tb ); |
1972 | 1972 | ||
1973 | fileMenu->insertSeparator(); | 1973 | fileMenu->insertSeparator(); |
1974 | mActionSave->plug( fileMenu ); | 1974 | mActionSave->plug( fileMenu ); |
1975 | fileMenu->insertItem( "&Import", ImportMenu ); | 1975 | fileMenu->insertItem( "&Import", ImportMenu ); |
1976 | fileMenu->insertItem( "&Export", ExportMenu ); | 1976 | fileMenu->insertItem( "&Export", ExportMenu ); |
1977 | fileMenu->insertSeparator(); | 1977 | fileMenu->insertSeparator(); |
1978 | mActionMailVCard->plug( fileMenu ); | 1978 | mActionMailVCard->plug( fileMenu ); |
1979 | #ifndef DESKTOP_VERSION | 1979 | #ifndef DESKTOP_VERSION |
1980 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); | 1980 | if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); |
1981 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); | 1981 | if ( Ir::supported() ) mActionBeam->plug(fileMenu ); |
1982 | #endif | 1982 | #endif |
1983 | fileMenu->insertSeparator(); | 1983 | fileMenu->insertSeparator(); |
1984 | mActionQuit->plug( fileMenu ); | 1984 | mActionQuit->plug( fileMenu ); |
1985 | #ifdef _WIN32_ | 1985 | #ifdef _WIN32_ |
1986 | mActionImportOL->plug( ImportMenu ); | 1986 | mActionImportOL->plug( ImportMenu ); |
1987 | #endif | 1987 | #endif |
1988 | // edit menu | 1988 | // edit menu |
1989 | mActionUndo->plug( editMenu ); | 1989 | mActionUndo->plug( editMenu ); |
1990 | mActionRedo->plug( editMenu ); | 1990 | mActionRedo->plug( editMenu ); |
1991 | editMenu->insertSeparator(); | 1991 | editMenu->insertSeparator(); |
1992 | mActionCut->plug( editMenu ); | 1992 | mActionCut->plug( editMenu ); |
1993 | mActionCopy->plug( editMenu ); | 1993 | mActionCopy->plug( editMenu ); |
1994 | mActionPaste->plug( editMenu ); | 1994 | mActionPaste->plug( editMenu ); |
1995 | mActionDelete->plug( editMenu ); | 1995 | mActionDelete->plug( editMenu ); |
1996 | editMenu->insertSeparator(); | 1996 | editMenu->insertSeparator(); |
1997 | mActionSelectAll->plug( editMenu ); | 1997 | mActionSelectAll->plug( editMenu ); |
1998 | 1998 | ||
1999 | mActionRemoveVoice->plug( changeMenu ); | 1999 | mActionRemoveVoice->plug( changeMenu ); |
2000 | // settings menu | 2000 | // settings menu |
2001 | //US special menuentry to configure the addressbook resources. On KDE | 2001 | //US special menuentry to configure the addressbook resources. On KDE |
2002 | // you do that through the control center !!! | 2002 | // you do that through the control center !!! |
2003 | mActionConfigResources->plug( settingsMenu ); | 2003 | mActionConfigResources->plug( settingsMenu ); |
2004 | settingsMenu->insertSeparator(); | 2004 | settingsMenu->insertSeparator(); |
2005 | 2005 | ||
2006 | mActionConfigKAddressbook->plug( settingsMenu ); | 2006 | mActionConfigKAddressbook->plug( settingsMenu ); |
2007 | 2007 | ||
2008 | if ( mIsPart ) { | 2008 | if ( mIsPart ) { |
2009 | //US not implemented yet | 2009 | //US not implemented yet |
2010 | //mActionConfigShortcuts->plug( settingsMenu ); | 2010 | //mActionConfigShortcuts->plug( settingsMenu ); |
2011 | //mActionConfigureToolbars->plug( settingsMenu ); | 2011 | //mActionConfigureToolbars->plug( settingsMenu ); |
2012 | 2012 | ||
2013 | } else { | 2013 | } else { |
2014 | //US not implemented yet | 2014 | //US not implemented yet |
2015 | //mActionKeyBindings->plug( settingsMenu ); | 2015 | //mActionKeyBindings->plug( settingsMenu ); |
2016 | } | 2016 | } |
2017 | 2017 | ||
2018 | settingsMenu->insertSeparator(); | 2018 | settingsMenu->insertSeparator(); |
2019 | 2019 | ||
2020 | mActionJumpBar->plug( settingsMenu ); | 2020 | mActionJumpBar->plug( settingsMenu ); |
2021 | mActionDetails->plug( settingsMenu ); | 2021 | mActionDetails->plug( settingsMenu ); |
2022 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) | 2022 | if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) |
2023 | mActionDetails->plug( tb ); | 2023 | mActionDetails->plug( tb ); |
2024 | settingsMenu->insertSeparator(); | 2024 | settingsMenu->insertSeparator(); |
2025 | mActionBR->plug(settingsMenu ); | 2025 | mActionBR->plug(settingsMenu ); |
2026 | settingsMenu->insertSeparator(); | 2026 | settingsMenu->insertSeparator(); |
2027 | 2027 | ||
2028 | mActionWhoAmI->plug( settingsMenu ); | 2028 | mActionWhoAmI->plug( settingsMenu ); |
2029 | mActionCategories->plug( settingsMenu ); | 2029 | mActionCategories->plug( settingsMenu ); |
2030 | 2030 | ||
2031 | 2031 | ||
2032 | mActionWN->plug( helpMenu ); | 2032 | mActionWN->plug( helpMenu ); |
2033 | mActionSyncHowto->plug( helpMenu ); | 2033 | mActionSyncHowto->plug( helpMenu ); |
2034 | mActionLicence->plug( helpMenu ); | 2034 | mActionLicence->plug( helpMenu ); |
2035 | mActionFaq->plug( helpMenu ); | 2035 | mActionFaq->plug( helpMenu ); |
2036 | mActionAboutKAddressbook->plug( helpMenu ); | 2036 | mActionAboutKAddressbook->plug( helpMenu ); |
2037 | 2037 | ||
2038 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { | 2038 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { |
2039 | 2039 | ||
2040 | mActionSave->plug( tb ); | 2040 | mActionSave->plug( tb ); |
2041 | mViewManager->getFilterAction()->plug ( tb); | 2041 | mViewManager->getFilterAction()->plug ( tb); |
2042 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { | 2042 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { |
2043 | mActionUndo->plug( tb ); | 2043 | mActionUndo->plug( tb ); |
2044 | mActionDelete->plug( tb ); | 2044 | mActionDelete->plug( tb ); |
2045 | mActionRedo->plug( tb ); | 2045 | mActionRedo->plug( tb ); |
2046 | } | 2046 | } |
2047 | } | 2047 | } |
2048 | //mActionQuit->plug ( tb ); | 2048 | //mActionQuit->plug ( tb ); |
2049 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); | 2049 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); |
2050 | 2050 | ||
2051 | //US link the searchwidget first to this. | 2051 | //US link the searchwidget first to this. |
2052 | // The real linkage to the toolbar happens later. | 2052 | // The real linkage to the toolbar happens later. |
2053 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); | 2053 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); |
2054 | //US tb->insertItem( mIncSearchWidget ); | 2054 | //US tb->insertItem( mIncSearchWidget ); |
2055 | /*US | 2055 | /*US |
2056 | mIncSearchWidget = new IncSearchWidget( tb ); | 2056 | mIncSearchWidget = new IncSearchWidget( tb ); |
2057 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 2057 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
2058 | SLOT( incrementalSearch( const QString& ) ) ); | 2058 | SLOT( incrementalSearch( const QString& ) ) ); |
2059 | 2059 | ||
2060 | mJumpButtonBar = new JumpButtonBar( this, this ); | 2060 | mJumpButtonBar = new JumpButtonBar( this, this ); |
2061 | 2061 | ||
2062 | //US topLayout->addWidget( mJumpButtonBar ); | 2062 | //US topLayout->addWidget( mJumpButtonBar ); |
2063 | this->layout()->add( mJumpButtonBar ); | 2063 | this->layout()->add( mJumpButtonBar ); |
2064 | */ | 2064 | */ |
2065 | 2065 | ||
2066 | #endif //KAB_EMBEDDED | 2066 | #endif //KAB_EMBEDDED |
2067 | 2067 | ||
2068 | mActionExport2phone->plug( ExportMenu ); | 2068 | mActionExport2phone->plug( ExportMenu ); |
2069 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 2069 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
2070 | syncManager->fillSyncMenu(); | 2070 | syncManager->fillSyncMenu(); |
2071 | 2071 | ||
2072 | } | 2072 | } |
2073 | void KABCore::showLicence() | 2073 | void KABCore::showLicence() |
2074 | { | 2074 | { |
2075 | KApplication::showLicence(); | 2075 | KApplication::showLicence(); |
2076 | } | 2076 | } |
2077 | void KABCore::removeVoice() | 2077 | void KABCore::removeVoice() |
2078 | { | 2078 | { |
2079 | 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 ) | 2079 | 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 ) |
2080 | return; | 2080 | return; |
2081 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 2081 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
2082 | KABC::Addressee::List::Iterator it; | 2082 | KABC::Addressee::List::Iterator it; |
2083 | for ( it = list.begin(); it != list.end(); ++it ) { | 2083 | for ( it = list.begin(); it != list.end(); ++it ) { |
2084 | 2084 | ||
2085 | if ( (*it).removeVoice() ) | 2085 | if ( (*it).removeVoice() ) |
2086 | contactModified((*it) ); | 2086 | contactModified((*it) ); |
2087 | } | 2087 | } |
2088 | } | 2088 | } |
2089 | 2089 | ||
2090 | 2090 | ||
2091 | 2091 | ||
2092 | void KABCore::clipboardDataChanged() | 2092 | void KABCore::clipboardDataChanged() |
2093 | { | 2093 | { |
2094 | 2094 | ||
2095 | if ( mReadWrite ) | 2095 | if ( mReadWrite ) |
2096 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); | 2096 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); |
2097 | 2097 | ||
2098 | } | 2098 | } |
2099 | 2099 | ||
2100 | void KABCore::updateActionMenu() | 2100 | void KABCore::updateActionMenu() |
2101 | { | 2101 | { |
2102 | UndoStack *undo = UndoStack::instance(); | 2102 | UndoStack *undo = UndoStack::instance(); |
2103 | RedoStack *redo = RedoStack::instance(); | 2103 | RedoStack *redo = RedoStack::instance(); |
2104 | 2104 | ||
2105 | if ( undo->isEmpty() ) | 2105 | if ( undo->isEmpty() ) |
2106 | mActionUndo->setText( i18n( "Undo" ) ); | 2106 | mActionUndo->setText( i18n( "Undo" ) ); |
2107 | else | 2107 | else |
2108 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); | 2108 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); |
2109 | 2109 | ||
2110 | mActionUndo->setEnabled( !undo->isEmpty() ); | 2110 | mActionUndo->setEnabled( !undo->isEmpty() ); |
2111 | 2111 | ||
2112 | if ( !redo->top() ) | 2112 | if ( !redo->top() ) |
2113 | mActionRedo->setText( i18n( "Redo" ) ); | 2113 | mActionRedo->setText( i18n( "Redo" ) ); |
2114 | else | 2114 | else |
2115 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); | 2115 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); |
2116 | 2116 | ||
2117 | mActionRedo->setEnabled( !redo->isEmpty() ); | 2117 | mActionRedo->setEnabled( !redo->isEmpty() ); |
2118 | } | 2118 | } |
2119 | 2119 | ||
2120 | void KABCore::configureKeyBindings() | 2120 | void KABCore::configureKeyBindings() |
2121 | { | 2121 | { |
2122 | #ifndef KAB_EMBEDDED | 2122 | #ifndef KAB_EMBEDDED |
2123 | KKeyDialog::configure( actionCollection(), true ); | 2123 | KKeyDialog::configure( actionCollection(), true ); |
2124 | #else //KAB_EMBEDDED | 2124 | #else //KAB_EMBEDDED |
2125 | qDebug("KABCore::configureKeyBindings() not implemented"); | 2125 | qDebug("KABCore::configureKeyBindings() not implemented"); |
2126 | #endif //KAB_EMBEDDED | 2126 | #endif //KAB_EMBEDDED |
2127 | } | 2127 | } |
2128 | 2128 | ||
2129 | #ifdef KAB_EMBEDDED | 2129 | #ifdef KAB_EMBEDDED |
2130 | void KABCore::configureResources() | 2130 | void KABCore::configureResources() |
2131 | { | 2131 | { |
2132 | KRES::KCMKResources dlg( this, "" , 0 ); | 2132 | KRES::KCMKResources dlg( this, "" , 0 ); |
2133 | 2133 | ||
2134 | if ( !dlg.exec() ) | 2134 | if ( !dlg.exec() ) |
2135 | return; | 2135 | return; |
2136 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 2136 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
2137 | } | 2137 | } |
2138 | #endif //KAB_EMBEDDED | 2138 | #endif //KAB_EMBEDDED |
2139 | 2139 | ||
2140 | 2140 | ||
2141 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 2141 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
2142 | * for the attendees list of an event. | 2142 | * for the attendees list of an event. |
2143 | */ | 2143 | */ |
2144 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 2144 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
2145 | { | 2145 | { |
2146 | QStringList nameList; | 2146 | QStringList nameList; |
2147 | QStringList emailList; | 2147 | QStringList emailList; |
2148 | QStringList uidList; | 2148 | QStringList uidList; |
2149 | 2149 | ||
2150 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 2150 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
2151 | uint i=0; | 2151 | uint i=0; |
2152 | for (i=0; i < list.count(); i++) | 2152 | for (i=0; i < list.count(); i++) |
2153 | { | 2153 | { |
2154 | nameList.append(list[i].realName()); | 2154 | nameList.append(list[i].realName()); |
2155 | emailList.append(list[i].preferredEmail()); | 2155 | emailList.append(list[i].preferredEmail()); |
2156 | uidList.append(list[i].uid()); | 2156 | uidList.append(list[i].uid()); |
2157 | } | 2157 | } |
2158 | 2158 | ||
2159 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2159 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2160 | 2160 | ||
2161 | } | 2161 | } |
2162 | 2162 | ||
2163 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays | 2163 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays |
2164 | * to put them into the calendar. | 2164 | * to put them into the calendar. |
2165 | */ | 2165 | */ |
2166 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) | 2166 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) |
2167 | { | 2167 | { |
2168 | // qDebug("KABCore::requestForBirthdayList"); | 2168 | // qDebug("KABCore::requestForBirthdayList"); |
2169 | QStringList birthdayList; | 2169 | QStringList birthdayList; |
2170 | QStringList anniversaryList; | 2170 | QStringList anniversaryList; |
2171 | QStringList realNameList; | 2171 | QStringList realNameList; |
2172 | QStringList preferredEmailList; | 2172 | QStringList preferredEmailList; |
2173 | QStringList assembledNameList; | 2173 | QStringList assembledNameList; |
2174 | QStringList uidList; | 2174 | QStringList uidList; |
2175 | 2175 | ||
2176 | KABC::AddressBook::Iterator it; | 2176 | KABC::AddressBook::Iterator it; |
2177 | 2177 | ||
2178 | int count = 0; | 2178 | int count = 0; |
2179 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2179 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2180 | ++count; | 2180 | ++count; |
2181 | } | 2181 | } |
2182 | QProgressBar bar(count,0 ); | 2182 | QProgressBar bar(count,0 ); |
2183 | int w = 300; | 2183 | int w = 300; |
2184 | if ( QApplication::desktop()->width() < 320 ) | 2184 | if ( QApplication::desktop()->width() < 320 ) |
2185 | w = 220; | 2185 | w = 220; |
2186 | int h = bar.sizeHint().height() ; | 2186 | int h = bar.sizeHint().height() ; |
2187 | int dw = QApplication::desktop()->width(); | 2187 | int dw = QApplication::desktop()->width(); |
2188 | int dh = QApplication::desktop()->height(); | 2188 | int dh = QApplication::desktop()->height(); |
2189 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2189 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2190 | bar.show(); | 2190 | bar.show(); |
2191 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); | 2191 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); |
2192 | qApp->processEvents(); | 2192 | qApp->processEvents(); |
2193 | 2193 | ||
2194 | QDate bday; | 2194 | QDate bday; |
2195 | QString anni; | 2195 | QString anni; |
2196 | QString formattedbday; | 2196 | QString formattedbday; |
2197 | 2197 | ||
2198 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) | 2198 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) |
2199 | { | 2199 | { |
2200 | if ( ! bar.isVisible() ) | 2200 | if ( ! bar.isVisible() ) |
2201 | return; | 2201 | return; |
2202 | bar.setProgress( count++ ); | 2202 | bar.setProgress( count++ ); |
2203 | qApp->processEvents(); | 2203 | qApp->processEvents(); |
2204 | bday = (*it).birthday().date(); | 2204 | bday = (*it).birthday().date(); |
2205 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); | 2205 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); |
2206 | 2206 | ||
2207 | if ( bday.isValid() || !anni.isEmpty()) | 2207 | if ( bday.isValid() || !anni.isEmpty()) |
2208 | { | 2208 | { |
2209 | if (bday.isValid()) | 2209 | if (bday.isValid()) |
2210 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); | 2210 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); |
2211 | else | 2211 | else |
2212 | formattedbday = "NOTVALID"; | 2212 | formattedbday = "NOTVALID"; |
2213 | if (anni.isEmpty()) | 2213 | if (anni.isEmpty()) |
2214 | anni = "INVALID"; | 2214 | anni = "INVALID"; |
2215 | 2215 | ||
2216 | birthdayList.append(formattedbday); | 2216 | birthdayList.append(formattedbday); |
2217 | anniversaryList.append(anni); //should be ISODate | 2217 | anniversaryList.append(anni); //should be ISODate |
2218 | realNameList.append((*it).realName()); | 2218 | realNameList.append((*it).realName()); |
2219 | preferredEmailList.append((*it).preferredEmail()); | 2219 | preferredEmailList.append((*it).preferredEmail()); |
2220 | assembledNameList.append((*it).assembledName()); | 2220 | assembledNameList.append((*it).assembledName()); |
2221 | uidList.append((*it).uid()); | 2221 | uidList.append((*it).uid()); |
2222 | 2222 | ||
2223 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); | 2223 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); |
2224 | } | 2224 | } |
2225 | } | 2225 | } |
2226 | 2226 | ||
2227 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); | 2227 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); |
2228 | 2228 | ||
2229 | } | 2229 | } |
2230 | 2230 | ||
2231 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2231 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2232 | */ | 2232 | */ |
2233 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2233 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2234 | { | 2234 | { |
2235 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2235 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2236 | 2236 | ||
2237 | QString foundUid = QString::null; | 2237 | QString foundUid = QString::null; |
2238 | if ( ! uid.isEmpty() ) { | 2238 | if ( ! uid.isEmpty() ) { |
2239 | Addressee adrr = mAddressBook->findByUid( uid ); | 2239 | Addressee adrr = mAddressBook->findByUid( uid ); |
2240 | if ( !adrr.isEmpty() ) { | 2240 | if ( !adrr.isEmpty() ) { |
2241 | foundUid = uid; | 2241 | foundUid = uid; |
2242 | } | 2242 | } |
2243 | if ( email == "sendbacklist" ) { | 2243 | if ( email == "sendbacklist" ) { |
2244 | //qDebug("ssssssssssssssssssssssend "); | 2244 | //qDebug("ssssssssssssssssssssssend "); |
2245 | QStringList nameList; | 2245 | QStringList nameList; |
2246 | QStringList emailList; | 2246 | QStringList emailList; |
2247 | QStringList uidList; | 2247 | QStringList uidList; |
2248 | nameList.append(adrr.realName()); | 2248 | nameList.append(adrr.realName()); |
2249 | emailList = adrr.emails(); | 2249 | emailList = adrr.emails(); |
2250 | uidList.append( adrr.preferredEmail()); | 2250 | uidList.append( adrr.preferredEmail()); |
2251 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2251 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2252 | return; | 2252 | return; |
2253 | } | 2253 | } |
2254 | 2254 | ||
2255 | } | 2255 | } |
2256 | 2256 | ||
2257 | if ( email == "sendbacklist" ) | 2257 | if ( email == "sendbacklist" ) |
2258 | return; | 2258 | return; |
2259 | if (foundUid.isEmpty()) | 2259 | if (foundUid.isEmpty()) |
2260 | { | 2260 | { |
2261 | //find the uid of the person first | 2261 | //find the uid of the person first |
2262 | Addressee::List namelist; | 2262 | Addressee::List namelist; |
2263 | Addressee::List emaillist; | 2263 | Addressee::List emaillist; |
2264 | 2264 | ||
2265 | if (!name.isEmpty()) | 2265 | if (!name.isEmpty()) |
2266 | namelist = mAddressBook->findByName( name ); | 2266 | namelist = mAddressBook->findByName( name ); |
2267 | 2267 | ||
2268 | if (!email.isEmpty()) | 2268 | if (!email.isEmpty()) |
2269 | emaillist = mAddressBook->findByEmail( email ); | 2269 | emaillist = mAddressBook->findByEmail( email ); |
2270 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2270 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2271 | //check if we have a match in Namelist and Emaillist | 2271 | //check if we have a match in Namelist and Emaillist |
2272 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2272 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2273 | foundUid = emaillist[0].uid(); | 2273 | foundUid = emaillist[0].uid(); |
2274 | } | 2274 | } |
2275 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2275 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2276 | foundUid = namelist[0].uid(); | 2276 | foundUid = namelist[0].uid(); |
2277 | else | 2277 | else |
2278 | { | 2278 | { |
2279 | for (int i = 0; i < namelist.count(); i++) | 2279 | for (int i = 0; i < namelist.count(); i++) |
2280 | { | 2280 | { |
2281 | for (int j = 0; j < emaillist.count(); j++) | 2281 | for (int j = 0; j < emaillist.count(); j++) |
2282 | { | 2282 | { |
2283 | if (namelist[i] == emaillist[j]) | 2283 | if (namelist[i] == emaillist[j]) |
2284 | { | 2284 | { |
2285 | foundUid = namelist[i].uid(); | 2285 | foundUid = namelist[i].uid(); |
2286 | } | 2286 | } |
2287 | } | 2287 | } |
2288 | } | 2288 | } |
2289 | } | 2289 | } |
2290 | } | 2290 | } |
2291 | else | 2291 | else |
2292 | { | 2292 | { |
2293 | foundUid = uid; | 2293 | foundUid = uid; |
2294 | } | 2294 | } |
2295 | 2295 | ||
2296 | if (!foundUid.isEmpty()) | 2296 | if (!foundUid.isEmpty()) |
2297 | { | 2297 | { |
2298 | 2298 | ||
2299 | // raise Ka/Pi if it is in the background | 2299 | // raise Ka/Pi if it is in the background |
2300 | #ifndef DESKTOP_VERSION | 2300 | #ifndef DESKTOP_VERSION |
2301 | #ifndef KORG_NODCOP | 2301 | #ifndef KORG_NODCOP |
2302 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2302 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2303 | #endif | 2303 | #endif |
2304 | #endif | 2304 | #endif |
2305 | 2305 | ||
2306 | mMainWindow->showMaximized(); | 2306 | mMainWindow->showMaximized(); |
2307 | mMainWindow-> raise(); | 2307 | mMainWindow-> raise(); |
2308 | 2308 | ||
2309 | mViewManager->setSelected( "", false); | 2309 | mViewManager->setSelected( "", false); |
2310 | mViewManager->refreshView( "" ); | 2310 | mViewManager->refreshView( "" ); |
2311 | mViewManager->setSelected( foundUid, true ); | 2311 | mViewManager->setSelected( foundUid, true ); |
2312 | mViewManager->refreshView( foundUid ); | 2312 | mViewManager->refreshView( foundUid ); |
2313 | 2313 | ||
2314 | if ( !mMultipleViewsAtOnce ) | 2314 | if ( !mMultipleViewsAtOnce ) |
2315 | { | 2315 | { |
2316 | setDetailsVisible( true ); | 2316 | setDetailsVisible( true ); |
2317 | mActionDetails->setChecked(true); | 2317 | mActionDetails->setChecked(true); |
2318 | } | 2318 | } |
2319 | } | 2319 | } |
2320 | } | 2320 | } |
2321 | 2321 | ||
2322 | void KABCore::whatsnew() | 2322 | void KABCore::whatsnew() |
2323 | { | 2323 | { |
2324 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 2324 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
2325 | } | 2325 | } |
2326 | void KABCore::synchowto() | 2326 | void KABCore::synchowto() |
2327 | { | 2327 | { |
2328 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 2328 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
2329 | } | 2329 | } |
2330 | 2330 | ||
2331 | void KABCore::faq() | 2331 | void KABCore::faq() |
2332 | { | 2332 | { |
2333 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2333 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2334 | } | 2334 | } |
2335 | 2335 | ||
2336 | #include <libkcal/syncdefines.h> | 2336 | #include <libkcal/syncdefines.h> |
2337 | 2337 | ||
2338 | KABC::Addressee KABCore::getLastSyncAddressee() | 2338 | KABC::Addressee KABCore::getLastSyncAddressee() |
2339 | { | 2339 | { |
2340 | Addressee lse; | 2340 | Addressee lse; |
2341 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2341 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2342 | 2342 | ||
2343 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2343 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2344 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2344 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2345 | if (lse.isEmpty()) { | 2345 | if (lse.isEmpty()) { |
2346 | qDebug("Creating new last-syncAddressee "); | 2346 | qDebug("Creating new last-syncAddressee "); |
2347 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2347 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2348 | QString sum = ""; | 2348 | QString sum = ""; |
2349 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2349 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2350 | sum = "E: "; | 2350 | sum = "E: "; |
2351 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2351 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2352 | lse.setRevision( mLastAddressbookSync ); | 2352 | lse.setRevision( mLastAddressbookSync ); |
2353 | lse.setCategories( i18n("SyncEvent") ); | 2353 | lse.setCategories( i18n("SyncEvent") ); |
2354 | mAddressBook->insertAddressee( lse ); | 2354 | mAddressBook->insertAddressee( lse ); |
2355 | } | 2355 | } |
2356 | return lse; | 2356 | return lse; |
2357 | } | 2357 | } |
2358 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2358 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2359 | { | 2359 | { |
2360 | 2360 | ||
2361 | //void setZaurusId(int id); | 2361 | //void setZaurusId(int id); |
2362 | // int zaurusId() const; | 2362 | // int zaurusId() const; |
2363 | // void setZaurusUid(int id); | 2363 | // void setZaurusUid(int id); |
2364 | // int zaurusUid() const; | 2364 | // int zaurusUid() const; |
2365 | // void setZaurusStat(int id); | 2365 | // void setZaurusStat(int id); |
2366 | // int zaurusStat() const; | 2366 | // int zaurusStat() const; |
2367 | // 0 equal | 2367 | // 0 equal |
2368 | // 1 take local | 2368 | // 1 take local |
2369 | // 2 take remote | 2369 | // 2 take remote |
2370 | // 3 cancel | 2370 | // 3 cancel |
2371 | QDateTime lastSync = mLastAddressbookSync; | 2371 | QDateTime lastSync = mLastAddressbookSync; |
2372 | QDateTime localMod = local->revision(); | 2372 | QDateTime localMod = local->revision(); |
2373 | QDateTime remoteMod = remote->revision(); | 2373 | QDateTime remoteMod = remote->revision(); |
2374 | 2374 | ||
2375 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2375 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2376 | 2376 | ||
2377 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2377 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2378 | bool remCh, locCh; | 2378 | bool remCh, locCh; |
2379 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2379 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2380 | 2380 | ||
2381 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2381 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2382 | locCh = ( localMod > mLastAddressbookSync ); | 2382 | locCh = ( localMod > mLastAddressbookSync ); |
2383 | if ( !remCh && ! locCh ) { | 2383 | if ( !remCh && ! locCh ) { |
2384 | //qDebug("both not changed "); | 2384 | //qDebug("both not changed "); |
2385 | lastSync = localMod.addDays(1); | 2385 | lastSync = localMod.addDays(1); |
2386 | if ( mode <= SYNC_PREF_ASK ) | 2386 | if ( mode <= SYNC_PREF_ASK ) |
2387 | return 0; | 2387 | return 0; |
2388 | } else { | 2388 | } else { |
2389 | if ( locCh ) { | 2389 | if ( locCh ) { |
2390 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2390 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2391 | lastSync = localMod.addDays( -1 ); | 2391 | lastSync = localMod.addDays( -1 ); |
2392 | if ( !remCh ) | 2392 | if ( !remCh ) |
2393 | remoteMod =( lastSync.addDays( -1 ) ); | 2393 | remoteMod =( lastSync.addDays( -1 ) ); |
2394 | } else { | 2394 | } else { |
2395 | //qDebug(" not loc changed "); | 2395 | //qDebug(" not loc changed "); |
2396 | lastSync = localMod.addDays( 1 ); | 2396 | lastSync = localMod.addDays( 1 ); |
2397 | if ( remCh ) | 2397 | if ( remCh ) |
2398 | remoteMod =( lastSync.addDays( 1 ) ); | 2398 | remoteMod =( lastSync.addDays( 1 ) ); |
2399 | 2399 | ||
2400 | } | 2400 | } |
2401 | } | 2401 | } |
2402 | full = true; | 2402 | full = true; |
2403 | if ( mode < SYNC_PREF_ASK ) | 2403 | if ( mode < SYNC_PREF_ASK ) |
2404 | mode = SYNC_PREF_ASK; | 2404 | mode = SYNC_PREF_ASK; |
2405 | } else { | 2405 | } else { |
2406 | if ( localMod == remoteMod ) | 2406 | if ( localMod == remoteMod ) |
2407 | return 0; | 2407 | return 0; |
2408 | 2408 | ||
2409 | } | 2409 | } |
2410 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2410 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2411 | 2411 | ||
2412 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 2412 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2413 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2413 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2414 | //full = true; //debug only | 2414 | //full = true; //debug only |
2415 | if ( full ) { | 2415 | if ( full ) { |
2416 | bool equ = ( (*local) == (*remote) ); | 2416 | bool equ = ( (*local) == (*remote) ); |
2417 | if ( equ ) { | 2417 | if ( equ ) { |
2418 | //qDebug("equal "); | 2418 | //qDebug("equal "); |
2419 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2419 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2420 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2420 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2421 | } | 2421 | } |
2422 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2422 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2423 | return 0; | 2423 | return 0; |
2424 | 2424 | ||
2425 | }//else //debug only | 2425 | }//else //debug only |
2426 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2426 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2427 | } | 2427 | } |
2428 | int result; | 2428 | int result; |
2429 | bool localIsNew; | 2429 | bool localIsNew; |
2430 | //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() ); | 2430 | //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() ); |
2431 | 2431 | ||
2432 | if ( full && mode < SYNC_PREF_NEWEST ) | 2432 | if ( full && mode < SYNC_PREF_NEWEST ) |
2433 | mode = SYNC_PREF_ASK; | 2433 | mode = SYNC_PREF_ASK; |
2434 | 2434 | ||
2435 | switch( mode ) { | 2435 | switch( mode ) { |
2436 | case SYNC_PREF_LOCAL: | 2436 | case SYNC_PREF_LOCAL: |
2437 | if ( lastSync > remoteMod ) | 2437 | if ( lastSync > remoteMod ) |
2438 | return 1; | 2438 | return 1; |
2439 | if ( lastSync > localMod ) | 2439 | if ( lastSync > localMod ) |
2440 | return 2; | 2440 | return 2; |
2441 | return 1; | 2441 | return 1; |
2442 | break; | 2442 | break; |
2443 | case SYNC_PREF_REMOTE: | 2443 | case SYNC_PREF_REMOTE: |
2444 | if ( lastSync > remoteMod ) | 2444 | if ( lastSync > remoteMod ) |
2445 | return 1; | 2445 | return 1; |
2446 | if ( lastSync > localMod ) | 2446 | if ( lastSync > localMod ) |
2447 | return 2; | 2447 | return 2; |
2448 | return 2; | 2448 | return 2; |
2449 | break; | 2449 | break; |
2450 | case SYNC_PREF_NEWEST: | 2450 | case SYNC_PREF_NEWEST: |
2451 | if ( localMod > remoteMod ) | 2451 | if ( localMod > remoteMod ) |
2452 | return 1; | 2452 | return 1; |
2453 | else | 2453 | else |
2454 | return 2; | 2454 | return 2; |
2455 | break; | 2455 | break; |
2456 | case SYNC_PREF_ASK: | 2456 | case SYNC_PREF_ASK: |
2457 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2457 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2458 | if ( lastSync > remoteMod ) | 2458 | if ( lastSync > remoteMod ) |
2459 | return 1; | 2459 | return 1; |
2460 | if ( lastSync > localMod ) | 2460 | if ( lastSync > localMod ) |
2461 | return 2; | 2461 | return 2; |
2462 | localIsNew = localMod >= remoteMod; | 2462 | localIsNew = localMod >= remoteMod; |
2463 | //qDebug("conflict! ************************************** "); | 2463 | //qDebug("conflict! ************************************** "); |
2464 | { | 2464 | { |
2465 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2465 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2466 | result = acd.executeD(localIsNew); | 2466 | result = acd.executeD(localIsNew); |
2467 | return result; | 2467 | return result; |
2468 | } | 2468 | } |
2469 | break; | 2469 | break; |
2470 | case SYNC_PREF_FORCE_LOCAL: | 2470 | case SYNC_PREF_FORCE_LOCAL: |
2471 | return 1; | 2471 | return 1; |
2472 | break; | 2472 | break; |
2473 | case SYNC_PREF_FORCE_REMOTE: | 2473 | case SYNC_PREF_FORCE_REMOTE: |
2474 | return 2; | 2474 | return 2; |
2475 | break; | 2475 | break; |
2476 | 2476 | ||
2477 | default: | 2477 | default: |
2478 | // SYNC_PREF_TAKE_BOTH not implemented | 2478 | // SYNC_PREF_TAKE_BOTH not implemented |
2479 | break; | 2479 | break; |
2480 | } | 2480 | } |
2481 | return 0; | 2481 | return 0; |
2482 | } | 2482 | } |
2483 | 2483 | ||
2484 | 2484 | ||
2485 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2485 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2486 | { | 2486 | { |
2487 | bool syncOK = true; | 2487 | bool syncOK = true; |
2488 | int addedAddressee = 0; | 2488 | int addedAddressee = 0; |
2489 | int addedAddresseeR = 0; | 2489 | int addedAddresseeR = 0; |
2490 | int deletedAddresseeR = 0; | 2490 | int deletedAddresseeR = 0; |
2491 | int deletedAddresseeL = 0; | 2491 | int deletedAddresseeL = 0; |
2492 | int changedLocal = 0; | 2492 | int changedLocal = 0; |
2493 | int changedRemote = 0; | 2493 | int changedRemote = 0; |
2494 | 2494 | ||
2495 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2495 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2496 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2496 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2497 | 2497 | ||
2498 | //QPtrList<Addressee> el = local->rawAddressees(); | 2498 | //QPtrList<Addressee> el = local->rawAddressees(); |
2499 | Addressee addresseeR; | 2499 | Addressee addresseeR; |
2500 | QString uid; | 2500 | QString uid; |
2501 | int take; | 2501 | int take; |
2502 | Addressee addresseeL; | 2502 | Addressee addresseeL; |
2503 | Addressee addresseeRSync; | 2503 | Addressee addresseeRSync; |
2504 | Addressee addresseeLSync; | 2504 | Addressee addresseeLSync; |
2505 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2505 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2506 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2506 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2507 | bool fullDateRange = false; | 2507 | bool fullDateRange = false; |
2508 | local->resetTempSyncStat(); | 2508 | local->resetTempSyncStat(); |
2509 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2509 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2510 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2510 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2511 | addresseeLSync = getLastSyncAddressee(); | 2511 | addresseeLSync = getLastSyncAddressee(); |
2512 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2512 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2513 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2513 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2514 | if ( !addresseeR.isEmpty() ) { | 2514 | if ( !addresseeR.isEmpty() ) { |
2515 | addresseeRSync = addresseeR; | 2515 | addresseeRSync = addresseeR; |
2516 | remote->removeAddressee(addresseeR ); | 2516 | remote->removeAddressee(addresseeR ); |
2517 | 2517 | ||
2518 | } else { | 2518 | } else { |
2519 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2519 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2520 | addresseeRSync = addresseeLSync ; | 2520 | addresseeRSync = addresseeLSync ; |
2521 | } else { | 2521 | } else { |
2522 | qDebug("FULLDATE 1"); | 2522 | qDebug("FULLDATE 1"); |
2523 | fullDateRange = true; | 2523 | fullDateRange = true; |
2524 | Addressee newAdd; | 2524 | Addressee newAdd; |
2525 | addresseeRSync = newAdd; | 2525 | addresseeRSync = newAdd; |
2526 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2526 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2527 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2527 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2528 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2528 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2529 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2529 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2530 | } | 2530 | } |
2531 | } | 2531 | } |
2532 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2532 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2533 | qDebug("FULLDATE 2"); | 2533 | qDebug("FULLDATE 2"); |
2534 | fullDateRange = true; | 2534 | fullDateRange = true; |
2535 | } | 2535 | } |
2536 | if ( ! fullDateRange ) { | 2536 | if ( ! fullDateRange ) { |
2537 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2537 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2538 | 2538 | ||
2539 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2539 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2540 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2540 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2541 | fullDateRange = true; | 2541 | fullDateRange = true; |
2542 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2542 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2543 | } | 2543 | } |
2544 | } | 2544 | } |
2545 | // fullDateRange = true; // debug only! | 2545 | // fullDateRange = true; // debug only! |
2546 | if ( fullDateRange ) | 2546 | if ( fullDateRange ) |
2547 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2547 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2548 | else | 2548 | else |
2549 | mLastAddressbookSync = addresseeLSync.revision(); | 2549 | mLastAddressbookSync = addresseeLSync.revision(); |
2550 | // for resyncing if own file has changed | 2550 | // for resyncing if own file has changed |
2551 | // PENDING fixme later when implemented | 2551 | // PENDING fixme later when implemented |
2552 | #if 0 | 2552 | #if 0 |
2553 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2553 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2554 | mLastAddressbookSync = loadedFileVersion; | 2554 | mLastAddressbookSync = loadedFileVersion; |
2555 | qDebug("setting mLastAddressbookSync "); | 2555 | qDebug("setting mLastAddressbookSync "); |
2556 | } | 2556 | } |
2557 | #endif | 2557 | #endif |
2558 | 2558 | ||
2559 | //qDebug("*************************** "); | 2559 | //qDebug("*************************** "); |
2560 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2560 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2561 | QStringList er = remote->uidList(); | 2561 | QStringList er = remote->uidList(); |
2562 | Addressee inR ;//= er.first(); | 2562 | Addressee inR ;//= er.first(); |
2563 | Addressee inL; | 2563 | Addressee inL; |
2564 | 2564 | ||
2565 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2565 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2566 | 2566 | ||
2567 | int modulo = (er.count()/10)+1; | 2567 | int modulo = (er.count()/10)+1; |
2568 | int incCounter = 0; | 2568 | int incCounter = 0; |
2569 | while ( incCounter < er.count()) { | 2569 | while ( incCounter < er.count()) { |
2570 | if (syncManager->isProgressBarCanceled()) | 2570 | if (syncManager->isProgressBarCanceled()) |
2571 | return false; | 2571 | return false; |
2572 | if ( incCounter % modulo == 0 ) | 2572 | if ( incCounter % modulo == 0 ) |
2573 | syncManager->showProgressBar(incCounter); | 2573 | syncManager->showProgressBar(incCounter); |
2574 | 2574 | ||
2575 | uid = er[ incCounter ]; | 2575 | uid = er[ incCounter ]; |
2576 | bool skipIncidence = false; | 2576 | bool skipIncidence = false; |
2577 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2577 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2578 | skipIncidence = true; | 2578 | skipIncidence = true; |
2579 | QString idS,OidS; | 2579 | QString idS,OidS; |
2580 | qApp->processEvents(); | 2580 | qApp->processEvents(); |
2581 | if ( !skipIncidence ) { | 2581 | if ( !skipIncidence ) { |
2582 | inL = local->findByUid( uid ); | 2582 | inL = local->findByUid( uid ); |
2583 | inR = remote->findByUid( uid ); | 2583 | inR = remote->findByUid( uid ); |
2584 | //inL.setResource( 0 ); | 2584 | //inL.setResource( 0 ); |
2585 | //inR.setResource( 0 ); | 2585 | //inR.setResource( 0 ); |
2586 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2586 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2587 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2587 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2588 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2588 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2589 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2589 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2590 | if ( take == 3 ) | 2590 | if ( take == 3 ) |
2591 | return false; | 2591 | return false; |
2592 | if ( take == 1 ) {// take local | 2592 | if ( take == 1 ) {// take local |
2593 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2593 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2594 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2594 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2595 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2595 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2596 | local->insertAddressee( inL, false ); | 2596 | local->insertAddressee( inL, false ); |
2597 | idS = inR.externalUID(); | 2597 | idS = inR.externalUID(); |
2598 | OidS = inR.originalExternalUID(); | 2598 | OidS = inR.originalExternalUID(); |
2599 | } | 2599 | } |
2600 | else | 2600 | else |
2601 | idS = inR.IDStr(); | 2601 | idS = inR.IDStr(); |
2602 | remote->removeAddressee( inR ); | 2602 | remote->removeAddressee( inR ); |
2603 | inR = inL; | 2603 | inR = inL; |
2604 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2604 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2605 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2605 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2606 | inR.setOriginalExternalUID( OidS ); | 2606 | inR.setOriginalExternalUID( OidS ); |
2607 | inR.setExternalUID( idS ); | 2607 | inR.setExternalUID( idS ); |
2608 | } else { | 2608 | } else { |
2609 | inR.setIDStr( idS ); | 2609 | inR.setIDStr( idS ); |
2610 | } | 2610 | } |
2611 | inR.setResource( 0 ); | 2611 | inR.setResource( 0 ); |
2612 | remote->insertAddressee( inR , false); | 2612 | remote->insertAddressee( inR , false); |
2613 | ++changedRemote; | 2613 | ++changedRemote; |
2614 | } else { // take == 2 take remote | 2614 | } else { // take == 2 take remote |
2615 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2615 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2616 | if ( inR.revision().date().year() < 2004 ) | 2616 | if ( inR.revision().date().year() < 2004 ) |
2617 | inR.setRevision( modifiedCalendar ); | 2617 | inR.setRevision( modifiedCalendar ); |
2618 | } | 2618 | } |
2619 | idS = inL.IDStr(); | 2619 | idS = inL.IDStr(); |
2620 | local->removeAddressee( inL ); | 2620 | local->removeAddressee( inL ); |
2621 | inL = inR; | 2621 | inL = inR; |
2622 | inL.setIDStr( idS ); | 2622 | inL.setIDStr( idS ); |
2623 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2623 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2624 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2624 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2625 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2625 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2626 | } | 2626 | } |
2627 | inL.setResource( 0 ); | 2627 | inL.setResource( 0 ); |
2628 | local->insertAddressee( inL , false ); | 2628 | local->insertAddressee( inL , false ); |
2629 | ++changedLocal; | 2629 | ++changedLocal; |
2630 | } | 2630 | } |
2631 | } | 2631 | } |
2632 | } | 2632 | } |
2633 | } else { // no conflict | 2633 | } else { // no conflict |
2634 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2634 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2635 | QString des = addresseeLSync.note(); | 2635 | QString des = addresseeLSync.note(); |
2636 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2636 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2637 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2637 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2638 | remote->insertAddressee( inR, false ); | 2638 | remote->insertAddressee( inR, false ); |
2639 | ++deletedAddresseeR; | 2639 | ++deletedAddresseeR; |
2640 | } else { | 2640 | } else { |
2641 | inR.setRevision( modifiedCalendar ); | 2641 | inR.setRevision( modifiedCalendar ); |
2642 | remote->insertAddressee( inR, false ); | 2642 | remote->insertAddressee( inR, false ); |
2643 | inL = inR; | 2643 | inL = inR; |
2644 | inL.setResource( 0 ); | 2644 | inL.setResource( 0 ); |
2645 | local->insertAddressee( inL , false); | 2645 | local->insertAddressee( inL , false); |
2646 | ++addedAddressee; | 2646 | ++addedAddressee; |
2647 | } | 2647 | } |
2648 | } else { | 2648 | } else { |
2649 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2649 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2650 | inR.setRevision( modifiedCalendar ); | 2650 | inR.setRevision( modifiedCalendar ); |
2651 | remote->insertAddressee( inR, false ); | 2651 | remote->insertAddressee( inR, false ); |
2652 | inR.setResource( 0 ); | 2652 | inR.setResource( 0 ); |
2653 | local->insertAddressee( inR, false ); | 2653 | local->insertAddressee( inR, false ); |
2654 | ++addedAddressee; | 2654 | ++addedAddressee; |
2655 | } else { | 2655 | } else { |
2656 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2656 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2657 | remote->removeAddressee( inR ); | 2657 | remote->removeAddressee( inR ); |
2658 | ++deletedAddresseeR; | 2658 | ++deletedAddresseeR; |
2659 | } | 2659 | } |
2660 | } | 2660 | } |
2661 | } | 2661 | } |
2662 | } | 2662 | } |
2663 | ++incCounter; | 2663 | ++incCounter; |
2664 | } | 2664 | } |
2665 | er.clear(); | 2665 | er.clear(); |
2666 | QStringList el = local->uidList(); | 2666 | QStringList el = local->uidList(); |
2667 | modulo = (el.count()/10)+1; | 2667 | modulo = (el.count()/10)+1; |
2668 | 2668 | ||
2669 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2669 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2670 | incCounter = 0; | 2670 | incCounter = 0; |
2671 | while ( incCounter < el.count()) { | 2671 | while ( incCounter < el.count()) { |
2672 | qApp->processEvents(); | 2672 | qApp->processEvents(); |
2673 | if (syncManager->isProgressBarCanceled()) | 2673 | if (syncManager->isProgressBarCanceled()) |
2674 | return false; | 2674 | return false; |
2675 | if ( incCounter % modulo == 0 ) | 2675 | if ( incCounter % modulo == 0 ) |
2676 | syncManager->showProgressBar(incCounter); | 2676 | syncManager->showProgressBar(incCounter); |
2677 | uid = el[ incCounter ]; | 2677 | uid = el[ incCounter ]; |
2678 | bool skipIncidence = false; | 2678 | bool skipIncidence = false; |
2679 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2679 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2680 | skipIncidence = true; | 2680 | skipIncidence = true; |
2681 | if ( !skipIncidence ) { | 2681 | if ( !skipIncidence ) { |
2682 | inL = local->findByUid( uid ); | 2682 | inL = local->findByUid( uid ); |
2683 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2683 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2684 | inR = remote->findByUid( uid ); | 2684 | inR = remote->findByUid( uid ); |
2685 | if ( inR.isEmpty() ) { | 2685 | if ( inR.isEmpty() ) { |
2686 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2686 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2687 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2687 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2688 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2688 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2689 | local->removeAddressee( inL ); | 2689 | local->removeAddressee( inL ); |
2690 | ++deletedAddresseeL; | 2690 | ++deletedAddresseeL; |
2691 | } else { | 2691 | } else { |
2692 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2692 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2693 | inL.removeID(mCurrentSyncDevice ); | 2693 | inL.removeID(mCurrentSyncDevice ); |
2694 | ++addedAddresseeR; | 2694 | ++addedAddresseeR; |
2695 | inL.setRevision( modifiedCalendar ); | 2695 | inL.setRevision( modifiedCalendar ); |
2696 | local->insertAddressee( inL, false ); | 2696 | local->insertAddressee( inL, false ); |
2697 | inR = inL; | 2697 | inR = inL; |
2698 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2698 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2699 | inR.setResource( 0 ); | 2699 | inR.setResource( 0 ); |
2700 | remote->insertAddressee( inR, false ); | 2700 | remote->insertAddressee( inR, false ); |
2701 | } | 2701 | } |
2702 | } | 2702 | } |
2703 | } else { | 2703 | } else { |
2704 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2704 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2705 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2705 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2706 | local->removeAddressee( inL ); | 2706 | local->removeAddressee( inL ); |
2707 | ++deletedAddresseeL; | 2707 | ++deletedAddresseeL; |
2708 | } else { | 2708 | } else { |
2709 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2709 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2710 | ++addedAddresseeR; | 2710 | ++addedAddresseeR; |
2711 | inL.setRevision( modifiedCalendar ); | 2711 | inL.setRevision( modifiedCalendar ); |
2712 | local->insertAddressee( inL, false ); | 2712 | local->insertAddressee( inL, false ); |
2713 | inR = inL; | 2713 | inR = inL; |
2714 | inR.setResource( 0 ); | 2714 | inR.setResource( 0 ); |
2715 | remote->insertAddressee( inR, false ); | 2715 | remote->insertAddressee( inR, false ); |
2716 | } | 2716 | } |
2717 | } | 2717 | } |
2718 | } | 2718 | } |
2719 | } | 2719 | } |
2720 | } | 2720 | } |
2721 | } | 2721 | } |
2722 | ++incCounter; | 2722 | ++incCounter; |
2723 | } | 2723 | } |
2724 | el.clear(); | 2724 | el.clear(); |
2725 | syncManager->hideProgressBar(); | 2725 | syncManager->hideProgressBar(); |
2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2727 | // get rid of micro seconds | 2727 | // get rid of micro seconds |
2728 | QTime t = mLastAddressbookSync.time(); | 2728 | QTime t = mLastAddressbookSync.time(); |
2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2730 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2730 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2731 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2731 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2738 | addresseeRSync.setNote( "" ) ; | 2738 | addresseeRSync.setNote( "" ) ; |
2739 | addresseeLSync.setNote( "" ); | 2739 | addresseeLSync.setNote( "" ); |
2740 | 2740 | ||
2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2742 | remote->insertAddressee( addresseeRSync, false ); | 2742 | remote->insertAddressee( addresseeRSync, false ); |
2743 | local->insertAddressee( addresseeLSync, false ); | 2743 | local->insertAddressee( addresseeLSync, false ); |
2744 | QString mes; | 2744 | QString mes; |
2745 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2745 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2746 | if ( syncManager->mShowSyncSummary ) { | 2746 | if ( syncManager->mShowSyncSummary ) { |
2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2748 | } | 2748 | } |
2749 | qDebug( mes ); | 2749 | qDebug( mes ); |
2750 | return syncOK; | 2750 | return syncOK; |
2751 | } | 2751 | } |
2752 | 2752 | ||
2753 | 2753 | ||
2754 | //this is a overwritten callbackmethods from the syncinterface | 2754 | //this is a overwritten callbackmethods from the syncinterface |
2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2756 | { | 2756 | { |
2757 | 2757 | ||
2758 | //pending prepare addresseeview for output | 2758 | //pending prepare addresseeview for output |
2759 | //pending detect, if remote file has REV field. if not switch to external sync | 2759 | //pending detect, if remote file has REV field. if not switch to external sync |
2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2762 | 2762 | ||
2763 | AddressBook abLocal(filename,"syncContact"); | 2763 | AddressBook abLocal(filename,"syncContact"); |
2764 | bool syncOK = false; | 2764 | bool syncOK = false; |
2765 | if ( abLocal.load() ) { | 2765 | if ( abLocal.load() ) { |
2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2767 | bool external = false; | 2767 | bool external = false; |
2768 | bool isXML = false; | 2768 | bool isXML = false; |
2769 | if ( filename.right(4) == ".xml") { | 2769 | if ( filename.right(4) == ".xml") { |
2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2771 | isXML = true; | 2771 | isXML = true; |
2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2773 | } else { | 2773 | } else { |
2774 | external = !manager->mIsKapiFile; | 2774 | external = !manager->mIsKapiFile; |
2775 | if ( external ) { | 2775 | if ( external ) { |
2776 | qDebug("Setting vcf mode to external "); | 2776 | qDebug("Setting vcf mode to external "); |
2777 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2777 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2778 | AddressBook::Iterator it; | 2778 | AddressBook::Iterator it; |
2779 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2779 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2780 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2780 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2781 | (*it).computeCsum( mCurrentSyncDevice ); | 2781 | (*it).computeCsum( mCurrentSyncDevice ); |
2782 | } | 2782 | } |
2783 | } | 2783 | } |
2784 | } | 2784 | } |
2785 | //AddressBook::Iterator it; | 2785 | //AddressBook::Iterator it; |
2786 | //QStringList vcards; | 2786 | //QStringList vcards; |
2787 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2787 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2788 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2788 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2789 | //} | 2789 | //} |
2790 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2790 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2791 | if ( syncOK ) { | 2791 | if ( syncOK ) { |
2792 | if ( syncManager->mWriteBackFile ) | 2792 | if ( syncManager->mWriteBackFile ) |
2793 | { | 2793 | { |
2794 | if ( external ) | 2794 | if ( external ) |
2795 | abLocal.removeSyncAddressees( !isXML); | 2795 | abLocal.removeSyncAddressees( !isXML); |
2796 | qDebug("Saving remote AB "); | 2796 | qDebug("Saving remote AB "); |
2797 | if ( ! abLocal.saveAB()) | 2797 | if ( ! abLocal.saveAB()) |
2798 | qDebug("Error writing back AB to file "); | 2798 | qDebug("Error writing back AB to file "); |
2799 | if ( isXML ) { | 2799 | if ( isXML ) { |
2800 | // afterwrite processing | 2800 | // afterwrite processing |
2801 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2801 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2802 | } | 2802 | } |
2803 | } | 2803 | } |
2804 | } | 2804 | } |
2805 | setModified(); | 2805 | setModified(); |
2806 | 2806 | ||
2807 | } | 2807 | } |
2808 | if ( syncOK ) | 2808 | if ( syncOK ) |
2809 | mViewManager->refreshView(); | 2809 | mViewManager->refreshView(); |
2810 | return syncOK; | 2810 | return syncOK; |
2811 | 2811 | ||
2812 | } | 2812 | } |
2813 | void KABCore::removeSyncInfo( QString syncProfile) | 2813 | void KABCore::removeSyncInfo( QString syncProfile) |
2814 | { | 2814 | { |
2815 | qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); | 2815 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
2816 | 2816 | mAddressBook->removeSyncInfo( syncProfile ); | |
2817 | } | 2817 | } |
2818 | 2818 | ||
2819 | 2819 | ||
2820 | //this is a overwritten callbackmethods from the syncinterface | 2820 | //this is a overwritten callbackmethods from the syncinterface |
2821 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2821 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2822 | { | 2822 | { |
2823 | if ( resource == "phone" ) | 2823 | if ( resource == "phone" ) |
2824 | return syncPhone(); | 2824 | return syncPhone(); |
2825 | disableBR( true ); | 2825 | disableBR( true ); |
2826 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2826 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2827 | 2827 | ||
2828 | AddressBook abLocal( resource,"syncContact"); | 2828 | AddressBook abLocal( resource,"syncContact"); |
2829 | bool syncOK = false; | 2829 | bool syncOK = false; |
2830 | if ( abLocal.load() ) { | 2830 | if ( abLocal.load() ) { |
2831 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2831 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2832 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2832 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2833 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 2833 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
2834 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2834 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2835 | if ( syncOK ) { | 2835 | if ( syncOK ) { |
2836 | if ( syncManager->mWriteBackFile ) { | 2836 | if ( syncManager->mWriteBackFile ) { |
2837 | abLocal.removeSyncAddressees( false ); | 2837 | abLocal.removeSyncAddressees( false ); |
2838 | abLocal.saveAB(); | 2838 | abLocal.saveAB(); |
2839 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2839 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2840 | } | 2840 | } |
2841 | } | 2841 | } |
2842 | setModified(); | 2842 | setModified(); |
2843 | } | 2843 | } |
2844 | if ( syncOK ) | 2844 | if ( syncOK ) |
2845 | mViewManager->refreshView(); | 2845 | mViewManager->refreshView(); |
2846 | disableBR( false ); | 2846 | disableBR( false ); |
2847 | return syncOK; | 2847 | return syncOK; |
2848 | 2848 | ||
2849 | } | 2849 | } |
2850 | void KABCore::message( QString m ) | 2850 | void KABCore::message( QString m ) |
2851 | { | 2851 | { |
2852 | topLevelWidget()->setCaption( m ); | 2852 | topLevelWidget()->setCaption( m ); |
2853 | mMessageTimer->start( 15000, true ); | 2853 | mMessageTimer->start( 15000, true ); |
2854 | } | 2854 | } |
2855 | bool KABCore::syncPhone() | 2855 | bool KABCore::syncPhone() |
2856 | { | 2856 | { |
2857 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2857 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2858 | QString fileName = getPhoneFile(); | 2858 | QString fileName = getPhoneFile(); |
2859 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2859 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2860 | message(i18n("Phone access failed!")); | 2860 | message(i18n("Phone access failed!")); |
2861 | return false; | 2861 | return false; |
2862 | } | 2862 | } |
2863 | AddressBook abLocal( fileName,"syncContact"); | 2863 | AddressBook abLocal( fileName,"syncContact"); |
2864 | bool syncOK = false; | 2864 | bool syncOK = false; |
2865 | { | 2865 | { |
2866 | abLocal.importFromFile( fileName ); | 2866 | abLocal.importFromFile( fileName ); |
2867 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2867 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2868 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2868 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2869 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2869 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2870 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2870 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2871 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2871 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2872 | if ( syncOK ) { | 2872 | if ( syncOK ) { |
2873 | if ( syncManager->mWriteBackFile ) { | 2873 | if ( syncManager->mWriteBackFile ) { |
2874 | abLocal.removeSyncAddressees( true ); | 2874 | abLocal.removeSyncAddressees( true ); |
2875 | abLocal.saveABphone( fileName ); | 2875 | abLocal.saveABphone( fileName ); |
2876 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2876 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2877 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2877 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2878 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2878 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2879 | } | 2879 | } |
2880 | } | 2880 | } |
2881 | setModified(); | 2881 | setModified(); |
2882 | } | 2882 | } |
2883 | if ( syncOK ) | 2883 | if ( syncOK ) |
2884 | mViewManager->refreshView(); | 2884 | mViewManager->refreshView(); |
2885 | return syncOK; | 2885 | return syncOK; |
2886 | } | 2886 | } |
2887 | void KABCore::getFile( bool success ) | 2887 | void KABCore::getFile( bool success ) |
2888 | { | 2888 | { |
2889 | if ( ! success ) { | 2889 | if ( ! success ) { |
2890 | message( i18n("Error receiving file. Nothing changed!") ); | 2890 | message( i18n("Error receiving file. Nothing changed!") ); |
2891 | return; | 2891 | return; |
2892 | } | 2892 | } |
2893 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2893 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2894 | if ( count ) | 2894 | if ( count ) |
2895 | setModified( true ); | 2895 | setModified( true ); |
2896 | message( i18n("Pi-Sync successful!") ); | 2896 | message( i18n("Pi-Sync successful!") ); |
2897 | mViewManager->refreshView(); | 2897 | mViewManager->refreshView(); |
2898 | } | 2898 | } |
2899 | void KABCore::syncFileRequest() | 2899 | void KABCore::syncFileRequest() |
2900 | { | 2900 | { |
2901 | mAddressBook->export2File( sentSyncFile() ); | 2901 | mAddressBook->export2File( sentSyncFile() ); |
2902 | } | 2902 | } |
2903 | QString KABCore::sentSyncFile() | 2903 | QString KABCore::sentSyncFile() |
2904 | { | 2904 | { |
2905 | #ifdef DESKTOP_VERSION | 2905 | #ifdef DESKTOP_VERSION |
2906 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2906 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2907 | #else | 2907 | #else |
2908 | return QString( "/tmp/copysyncab.vcf" ); | 2908 | return QString( "/tmp/copysyncab.vcf" ); |
2909 | #endif | 2909 | #endif |
2910 | } | 2910 | } |
2911 | 2911 | ||
2912 | void KABCore::setCaptionBack() | 2912 | void KABCore::setCaptionBack() |
2913 | { | 2913 | { |
2914 | mMessageTimer->stop(); | 2914 | mMessageTimer->stop(); |
2915 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2915 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2916 | } | 2916 | } |
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index af01625..a08f243 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -699,3074 +699,3075 @@ void CalendarView::createPrinter() | |||
699 | } | 699 | } |
700 | #endif | 700 | #endif |
701 | } | 701 | } |
702 | 702 | ||
703 | 703 | ||
704 | //KOPrefs::instance()->mWriteBackFile | 704 | //KOPrefs::instance()->mWriteBackFile |
705 | //KOPrefs::instance()->mWriteBackExistingOnly | 705 | //KOPrefs::instance()->mWriteBackExistingOnly |
706 | 706 | ||
707 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 707 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
708 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 708 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
709 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 709 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
710 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 710 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
711 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 711 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
712 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 712 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
713 | 713 | ||
714 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 714 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
715 | { | 715 | { |
716 | 716 | ||
717 | // 0 equal | 717 | // 0 equal |
718 | // 1 take local | 718 | // 1 take local |
719 | // 2 take remote | 719 | // 2 take remote |
720 | // 3 cancel | 720 | // 3 cancel |
721 | QDateTime lastSync = mLastCalendarSync; | 721 | QDateTime lastSync = mLastCalendarSync; |
722 | QDateTime localMod = local->lastModified(); | 722 | QDateTime localMod = local->lastModified(); |
723 | QDateTime remoteMod = remote->lastModified(); | 723 | QDateTime remoteMod = remote->lastModified(); |
724 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 724 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
725 | bool remCh, locCh; | 725 | bool remCh, locCh; |
726 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 726 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
727 | //if ( remCh ) | 727 | //if ( remCh ) |
728 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 728 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
729 | locCh = ( localMod > mLastCalendarSync ); | 729 | locCh = ( localMod > mLastCalendarSync ); |
730 | if ( !remCh && ! locCh ) { | 730 | if ( !remCh && ! locCh ) { |
731 | //qDebug("both not changed "); | 731 | //qDebug("both not changed "); |
732 | lastSync = localMod.addDays(1); | 732 | lastSync = localMod.addDays(1); |
733 | if ( mode <= SYNC_PREF_ASK ) | 733 | if ( mode <= SYNC_PREF_ASK ) |
734 | return 0; | 734 | return 0; |
735 | } else { | 735 | } else { |
736 | if ( locCh ) { | 736 | if ( locCh ) { |
737 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); | 737 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
738 | lastSync = localMod.addDays( -1 ); | 738 | lastSync = localMod.addDays( -1 ); |
739 | if ( !remCh ) | 739 | if ( !remCh ) |
740 | remoteMod = ( lastSync.addDays( -1 ) ); | 740 | remoteMod = ( lastSync.addDays( -1 ) ); |
741 | } else { | 741 | } else { |
742 | //qDebug(" not loc changed "); | 742 | //qDebug(" not loc changed "); |
743 | lastSync = localMod.addDays( 1 ); | 743 | lastSync = localMod.addDays( 1 ); |
744 | if ( remCh ) | 744 | if ( remCh ) |
745 | remoteMod =( lastSync.addDays( 1 ) ); | 745 | remoteMod =( lastSync.addDays( 1 ) ); |
746 | 746 | ||
747 | } | 747 | } |
748 | } | 748 | } |
749 | full = true; | 749 | full = true; |
750 | if ( mode < SYNC_PREF_ASK ) | 750 | if ( mode < SYNC_PREF_ASK ) |
751 | mode = SYNC_PREF_ASK; | 751 | mode = SYNC_PREF_ASK; |
752 | } else { | 752 | } else { |
753 | if ( localMod == remoteMod ) | 753 | if ( localMod == remoteMod ) |
754 | // if ( local->revision() == remote->revision() ) | 754 | // if ( local->revision() == remote->revision() ) |
755 | return 0; | 755 | return 0; |
756 | 756 | ||
757 | } | 757 | } |
758 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 758 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
759 | 759 | ||
760 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); | 760 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
761 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); | 761 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
762 | //full = true; //debug only | 762 | //full = true; //debug only |
763 | if ( full ) { | 763 | if ( full ) { |
764 | bool equ = false; | 764 | bool equ = false; |
765 | if ( local->type() == "Event" ) { | 765 | if ( local->type() == "Event" ) { |
766 | equ = (*((Event*) local) == *((Event*) remote)); | 766 | equ = (*((Event*) local) == *((Event*) remote)); |
767 | } | 767 | } |
768 | else if ( local->type() =="Todo" ) | 768 | else if ( local->type() =="Todo" ) |
769 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 769 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
770 | else if ( local->type() =="Journal" ) | 770 | else if ( local->type() =="Journal" ) |
771 | equ = (*((Journal*) local) == *((Journal*) remote)); | 771 | equ = (*((Journal*) local) == *((Journal*) remote)); |
772 | if ( equ ) { | 772 | if ( equ ) { |
773 | //qDebug("equal "); | 773 | //qDebug("equal "); |
774 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 774 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
775 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 775 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
776 | } | 776 | } |
777 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 777 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
778 | return 0; | 778 | return 0; |
779 | 779 | ||
780 | }//else //debug only | 780 | }//else //debug only |
781 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 781 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
782 | } | 782 | } |
783 | int result; | 783 | int result; |
784 | bool localIsNew; | 784 | bool localIsNew; |
785 | //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() ); | 785 | //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() ); |
786 | 786 | ||
787 | if ( full && mode < SYNC_PREF_NEWEST ) | 787 | if ( full && mode < SYNC_PREF_NEWEST ) |
788 | mode = SYNC_PREF_ASK; | 788 | mode = SYNC_PREF_ASK; |
789 | 789 | ||
790 | switch( mode ) { | 790 | switch( mode ) { |
791 | case SYNC_PREF_LOCAL: | 791 | case SYNC_PREF_LOCAL: |
792 | if ( lastSync > remoteMod ) | 792 | if ( lastSync > remoteMod ) |
793 | return 1; | 793 | return 1; |
794 | if ( lastSync > localMod ) | 794 | if ( lastSync > localMod ) |
795 | return 2; | 795 | return 2; |
796 | return 1; | 796 | return 1; |
797 | break; | 797 | break; |
798 | case SYNC_PREF_REMOTE: | 798 | case SYNC_PREF_REMOTE: |
799 | if ( lastSync > remoteMod ) | 799 | if ( lastSync > remoteMod ) |
800 | return 1; | 800 | return 1; |
801 | if ( lastSync > localMod ) | 801 | if ( lastSync > localMod ) |
802 | return 2; | 802 | return 2; |
803 | return 2; | 803 | return 2; |
804 | break; | 804 | break; |
805 | case SYNC_PREF_NEWEST: | 805 | case SYNC_PREF_NEWEST: |
806 | if ( localMod > remoteMod ) | 806 | if ( localMod > remoteMod ) |
807 | return 1; | 807 | return 1; |
808 | else | 808 | else |
809 | return 2; | 809 | return 2; |
810 | break; | 810 | break; |
811 | case SYNC_PREF_ASK: | 811 | case SYNC_PREF_ASK: |
812 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 812 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
813 | if ( lastSync > remoteMod ) | 813 | if ( lastSync > remoteMod ) |
814 | return 1; | 814 | return 1; |
815 | if ( lastSync > localMod ) | 815 | if ( lastSync > localMod ) |
816 | return 2; | 816 | return 2; |
817 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 817 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
818 | localIsNew = localMod >= remoteMod; | 818 | localIsNew = localMod >= remoteMod; |
819 | if ( localIsNew ) | 819 | if ( localIsNew ) |
820 | getEventViewerDialog()->setColorMode( 1 ); | 820 | getEventViewerDialog()->setColorMode( 1 ); |
821 | else | 821 | else |
822 | getEventViewerDialog()->setColorMode( 2 ); | 822 | getEventViewerDialog()->setColorMode( 2 ); |
823 | getEventViewerDialog()->setIncidence(local); | 823 | getEventViewerDialog()->setIncidence(local); |
824 | if ( localIsNew ) | 824 | if ( localIsNew ) |
825 | getEventViewerDialog()->setColorMode( 2 ); | 825 | getEventViewerDialog()->setColorMode( 2 ); |
826 | else | 826 | else |
827 | getEventViewerDialog()->setColorMode( 1 ); | 827 | getEventViewerDialog()->setColorMode( 1 ); |
828 | getEventViewerDialog()->addIncidence(remote); | 828 | getEventViewerDialog()->addIncidence(remote); |
829 | getEventViewerDialog()->setColorMode( 0 ); | 829 | getEventViewerDialog()->setColorMode( 0 ); |
830 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 830 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
831 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 831 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
832 | getEventViewerDialog()->showMe(); | 832 | getEventViewerDialog()->showMe(); |
833 | result = getEventViewerDialog()->executeS( localIsNew ); | 833 | result = getEventViewerDialog()->executeS( localIsNew ); |
834 | return result; | 834 | return result; |
835 | 835 | ||
836 | break; | 836 | break; |
837 | case SYNC_PREF_FORCE_LOCAL: | 837 | case SYNC_PREF_FORCE_LOCAL: |
838 | return 1; | 838 | return 1; |
839 | break; | 839 | break; |
840 | case SYNC_PREF_FORCE_REMOTE: | 840 | case SYNC_PREF_FORCE_REMOTE: |
841 | return 2; | 841 | return 2; |
842 | break; | 842 | break; |
843 | 843 | ||
844 | default: | 844 | default: |
845 | // SYNC_PREF_TAKE_BOTH not implemented | 845 | // SYNC_PREF_TAKE_BOTH not implemented |
846 | break; | 846 | break; |
847 | } | 847 | } |
848 | return 0; | 848 | return 0; |
849 | } | 849 | } |
850 | Event* CalendarView::getLastSyncEvent() | 850 | Event* CalendarView::getLastSyncEvent() |
851 | { | 851 | { |
852 | Event* lse; | 852 | Event* lse; |
853 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 853 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
854 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 854 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
855 | if (!lse) { | 855 | if (!lse) { |
856 | lse = new Event(); | 856 | lse = new Event(); |
857 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 857 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
858 | QString sum = ""; | 858 | QString sum = ""; |
859 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 859 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
860 | sum = "E: "; | 860 | sum = "E: "; |
861 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 861 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
862 | lse->setDtStart( mLastCalendarSync ); | 862 | lse->setDtStart( mLastCalendarSync ); |
863 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 863 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
864 | lse->setCategories( i18n("SyncEvent") ); | 864 | lse->setCategories( i18n("SyncEvent") ); |
865 | lse->setReadOnly( true ); | 865 | lse->setReadOnly( true ); |
866 | mCalendar->addEvent( lse ); | 866 | mCalendar->addEvent( lse ); |
867 | } | 867 | } |
868 | 868 | ||
869 | return lse; | 869 | return lse; |
870 | 870 | ||
871 | } | 871 | } |
872 | 872 | ||
873 | // we check, if the to delete event has a id for a profile | 873 | // we check, if the to delete event has a id for a profile |
874 | // if yes, we set this id in the profile to delete | 874 | // if yes, we set this id in the profile to delete |
875 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 875 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
876 | { | 876 | { |
877 | if ( lastSync.count() == 0 ) { | 877 | if ( lastSync.count() == 0 ) { |
878 | //qDebug(" lastSync.count() == 0"); | 878 | //qDebug(" lastSync.count() == 0"); |
879 | return; | 879 | return; |
880 | } | 880 | } |
881 | if ( toDelete->type() == "Journal" ) | 881 | if ( toDelete->type() == "Journal" ) |
882 | return; | 882 | return; |
883 | 883 | ||
884 | Event* eve = lastSync.first(); | 884 | Event* eve = lastSync.first(); |
885 | 885 | ||
886 | while ( eve ) { | 886 | while ( eve ) { |
887 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 887 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
888 | if ( !id.isEmpty() ) { | 888 | if ( !id.isEmpty() ) { |
889 | QString des = eve->description(); | 889 | QString des = eve->description(); |
890 | QString pref = "e"; | 890 | QString pref = "e"; |
891 | if ( toDelete->type() == "Todo" ) | 891 | if ( toDelete->type() == "Todo" ) |
892 | pref = "t"; | 892 | pref = "t"; |
893 | des += pref+ id + ","; | 893 | des += pref+ id + ","; |
894 | eve->setReadOnly( false ); | 894 | eve->setReadOnly( false ); |
895 | eve->setDescription( des ); | 895 | eve->setDescription( des ); |
896 | //qDebug("setdes %s ", des.latin1()); | 896 | //qDebug("setdes %s ", des.latin1()); |
897 | eve->setReadOnly( true ); | 897 | eve->setReadOnly( true ); |
898 | } | 898 | } |
899 | eve = lastSync.next(); | 899 | eve = lastSync.next(); |
900 | } | 900 | } |
901 | 901 | ||
902 | } | 902 | } |
903 | void CalendarView::checkExternalId( Incidence * inc ) | 903 | void CalendarView::checkExternalId( Incidence * inc ) |
904 | { | 904 | { |
905 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 905 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
906 | checkExternSyncEvent( lastSync, inc ); | 906 | checkExternSyncEvent( lastSync, inc ); |
907 | 907 | ||
908 | } | 908 | } |
909 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 909 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
910 | { | 910 | { |
911 | bool syncOK = true; | 911 | bool syncOK = true; |
912 | int addedEvent = 0; | 912 | int addedEvent = 0; |
913 | int addedEventR = 0; | 913 | int addedEventR = 0; |
914 | int deletedEventR = 0; | 914 | int deletedEventR = 0; |
915 | int deletedEventL = 0; | 915 | int deletedEventL = 0; |
916 | int changedLocal = 0; | 916 | int changedLocal = 0; |
917 | int changedRemote = 0; | 917 | int changedRemote = 0; |
918 | //QPtrList<Event> el = local->rawEvents(); | 918 | //QPtrList<Event> el = local->rawEvents(); |
919 | Event* eventR; | 919 | Event* eventR; |
920 | QString uid; | 920 | QString uid; |
921 | int take; | 921 | int take; |
922 | Event* eventL; | 922 | Event* eventL; |
923 | Event* eventRSync; | 923 | Event* eventRSync; |
924 | Event* eventLSync; | 924 | Event* eventLSync; |
925 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 925 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
926 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 926 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
927 | bool fullDateRange = false; | 927 | bool fullDateRange = false; |
928 | local->resetTempSyncStat(); | 928 | local->resetTempSyncStat(); |
929 | if ( mSyncKDE ) | 929 | if ( mSyncKDE ) |
930 | remote->resetPilotStat(1); | 930 | remote->resetPilotStat(1); |
931 | mLastCalendarSync = QDateTime::currentDateTime(); | 931 | mLastCalendarSync = QDateTime::currentDateTime(); |
932 | QDateTime modifiedCalendar = mLastCalendarSync;; | 932 | QDateTime modifiedCalendar = mLastCalendarSync;; |
933 | eventLSync = getLastSyncEvent(); | 933 | eventLSync = getLastSyncEvent(); |
934 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 934 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
935 | if ( eventR ) { | 935 | if ( eventR ) { |
936 | eventRSync = (Event*) eventR->clone(); | 936 | eventRSync = (Event*) eventR->clone(); |
937 | remote->deleteEvent(eventR ); | 937 | remote->deleteEvent(eventR ); |
938 | 938 | ||
939 | } else { | 939 | } else { |
940 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { | 940 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { |
941 | eventRSync = (Event*)eventLSync->clone(); | 941 | eventRSync = (Event*)eventLSync->clone(); |
942 | } else { | 942 | } else { |
943 | fullDateRange = true; | 943 | fullDateRange = true; |
944 | eventRSync = new Event(); | 944 | eventRSync = new Event(); |
945 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 945 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
946 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 946 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
947 | eventRSync->setDtStart( mLastCalendarSync ); | 947 | eventRSync->setDtStart( mLastCalendarSync ); |
948 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 948 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
949 | eventRSync->setCategories( i18n("SyncEvent") ); | 949 | eventRSync->setCategories( i18n("SyncEvent") ); |
950 | } | 950 | } |
951 | } | 951 | } |
952 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 952 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
953 | fullDateRange = true; | 953 | fullDateRange = true; |
954 | 954 | ||
955 | if ( ! fullDateRange ) { | 955 | if ( ! fullDateRange ) { |
956 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 956 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
957 | 957 | ||
958 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 958 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
959 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 959 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
960 | fullDateRange = true; | 960 | fullDateRange = true; |
961 | } | 961 | } |
962 | } | 962 | } |
963 | if ( mSyncKDE ) { | 963 | if ( mSyncKDE ) { |
964 | fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); | 964 | fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); |
965 | } | 965 | } |
966 | if ( fullDateRange ) | 966 | if ( fullDateRange ) |
967 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 967 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
968 | else | 968 | else |
969 | mLastCalendarSync = eventLSync->dtStart(); | 969 | mLastCalendarSync = eventLSync->dtStart(); |
970 | // for resyncing if own file has changed | 970 | // for resyncing if own file has changed |
971 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 971 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
972 | mLastCalendarSync = loadedFileVersion; | 972 | mLastCalendarSync = loadedFileVersion; |
973 | //qDebug("setting mLastCalendarSync "); | 973 | //qDebug("setting mLastCalendarSync "); |
974 | } | 974 | } |
975 | //qDebug("*************************** "); | 975 | //qDebug("*************************** "); |
976 | qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 976 | qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
977 | QPtrList<Incidence> er = remote->rawIncidences(); | 977 | QPtrList<Incidence> er = remote->rawIncidences(); |
978 | Incidence* inR = er.first(); | 978 | Incidence* inR = er.first(); |
979 | Incidence* inL; | 979 | Incidence* inL; |
980 | QProgressBar bar( er.count(),0 ); | 980 | QProgressBar bar( er.count(),0 ); |
981 | bar.setCaption (i18n("Syncing - close to abort!") ); | 981 | bar.setCaption (i18n("Syncing - close to abort!") ); |
982 | 982 | ||
983 | int w = 300; | 983 | int w = 300; |
984 | if ( QApplication::desktop()->width() < 320 ) | 984 | if ( QApplication::desktop()->width() < 320 ) |
985 | w = 220; | 985 | w = 220; |
986 | int h = bar.sizeHint().height() ; | 986 | int h = bar.sizeHint().height() ; |
987 | int dw = QApplication::desktop()->width(); | 987 | int dw = QApplication::desktop()->width(); |
988 | int dh = QApplication::desktop()->height(); | 988 | int dh = QApplication::desktop()->height(); |
989 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 989 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
990 | bar.show(); | 990 | bar.show(); |
991 | int modulo = (er.count()/10)+1; | 991 | int modulo = (er.count()/10)+1; |
992 | int incCounter = 0; | 992 | int incCounter = 0; |
993 | while ( inR ) { | 993 | while ( inR ) { |
994 | if ( ! bar.isVisible() ) | 994 | if ( ! bar.isVisible() ) |
995 | return false; | 995 | return false; |
996 | if ( incCounter % modulo == 0 ) | 996 | if ( incCounter % modulo == 0 ) |
997 | bar.setProgress( incCounter ); | 997 | bar.setProgress( incCounter ); |
998 | ++incCounter; | 998 | ++incCounter; |
999 | uid = inR->uid(); | 999 | uid = inR->uid(); |
1000 | bool skipIncidence = false; | 1000 | bool skipIncidence = false; |
1001 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1001 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1002 | skipIncidence = true; | 1002 | skipIncidence = true; |
1003 | QString idS; | 1003 | QString idS; |
1004 | qApp->processEvents(); | 1004 | qApp->processEvents(); |
1005 | if ( !skipIncidence ) { | 1005 | if ( !skipIncidence ) { |
1006 | inL = local->incidence( uid ); | 1006 | inL = local->incidence( uid ); |
1007 | if ( inL ) { // maybe conflict - same uid in both calendars | 1007 | if ( inL ) { // maybe conflict - same uid in both calendars |
1008 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1008 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1009 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1009 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1010 | if ( take == 3 ) | 1010 | if ( take == 3 ) |
1011 | return false; | 1011 | return false; |
1012 | if ( take == 1 ) {// take local | 1012 | if ( take == 1 ) {// take local |
1013 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1013 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1014 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1014 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1015 | else | 1015 | else |
1016 | idS = inR->IDStr(); | 1016 | idS = inR->IDStr(); |
1017 | remote->deleteIncidence( inR ); | 1017 | remote->deleteIncidence( inR ); |
1018 | inR = inL->clone(); | 1018 | inR = inL->clone(); |
1019 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1019 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1020 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1020 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1021 | inR->setIDStr( idS ); | 1021 | inR->setIDStr( idS ); |
1022 | remote->addIncidence( inR ); | 1022 | remote->addIncidence( inR ); |
1023 | if ( mSyncKDE ) | 1023 | if ( mSyncKDE ) |
1024 | inR->setPilotId( 2 ); | 1024 | inR->setPilotId( 2 ); |
1025 | ++changedRemote; | 1025 | ++changedRemote; |
1026 | } else { | 1026 | } else { |
1027 | idS = inL->IDStr(); | 1027 | idS = inL->IDStr(); |
1028 | int pid = inL->pilotId(); | 1028 | int pid = inL->pilotId(); |
1029 | local->deleteIncidence( inL ); | 1029 | local->deleteIncidence( inL ); |
1030 | inL = inR->clone(); | 1030 | inL = inR->clone(); |
1031 | if ( mSyncKDE ) | 1031 | if ( mSyncKDE ) |
1032 | inL->setPilotId( pid ); | 1032 | inL->setPilotId( pid ); |
1033 | inL->setIDStr( idS ); | 1033 | inL->setIDStr( idS ); |
1034 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1034 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1035 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1035 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1036 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1036 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1037 | } | 1037 | } |
1038 | local->addIncidence( inL ); | 1038 | local->addIncidence( inL ); |
1039 | ++changedLocal; | 1039 | ++changedLocal; |
1040 | } | 1040 | } |
1041 | } | 1041 | } |
1042 | } else { // no conflict | 1042 | } else { // no conflict |
1043 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1043 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1044 | QString des = eventLSync->description(); | 1044 | QString des = eventLSync->description(); |
1045 | QString pref = "e"; | 1045 | QString pref = "e"; |
1046 | if ( inR->type() == "Todo" ) | 1046 | if ( inR->type() == "Todo" ) |
1047 | pref = "t"; | 1047 | pref = "t"; |
1048 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1048 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1049 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1049 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1050 | //remote->deleteIncidence( inR ); | 1050 | //remote->deleteIncidence( inR ); |
1051 | ++deletedEventR; | 1051 | ++deletedEventR; |
1052 | } else { | 1052 | } else { |
1053 | inR->setLastModified( modifiedCalendar ); | 1053 | inR->setLastModified( modifiedCalendar ); |
1054 | inL = inR->clone(); | 1054 | inL = inR->clone(); |
1055 | inL->setIDStr( ":" ); | 1055 | inL->setIDStr( ":" ); |
1056 | local->addIncidence( inL ); | 1056 | local->addIncidence( inL ); |
1057 | ++addedEvent; | 1057 | ++addedEvent; |
1058 | } | 1058 | } |
1059 | } else { | 1059 | } else { |
1060 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1060 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1061 | inR->setLastModified( modifiedCalendar ); | 1061 | inR->setLastModified( modifiedCalendar ); |
1062 | inL = inR->clone(); | 1062 | inL = inR->clone(); |
1063 | inL->setIDStr( ":" ); | 1063 | inL->setIDStr( ":" ); |
1064 | local->addIncidence( inL ); | 1064 | local->addIncidence( inL ); |
1065 | ++addedEvent; | 1065 | ++addedEvent; |
1066 | } else { | 1066 | } else { |
1067 | checkExternSyncEvent(eventRSyncSharp, inR); | 1067 | checkExternSyncEvent(eventRSyncSharp, inR); |
1068 | remote->deleteIncidence( inR ); | 1068 | remote->deleteIncidence( inR ); |
1069 | ++deletedEventR; | 1069 | ++deletedEventR; |
1070 | } | 1070 | } |
1071 | } | 1071 | } |
1072 | } | 1072 | } |
1073 | } | 1073 | } |
1074 | inR = er.next(); | 1074 | inR = er.next(); |
1075 | } | 1075 | } |
1076 | QPtrList<Incidence> el = local->rawIncidences(); | 1076 | QPtrList<Incidence> el = local->rawIncidences(); |
1077 | inL = el.first(); | 1077 | inL = el.first(); |
1078 | modulo = (el.count()/10)+1; | 1078 | modulo = (el.count()/10)+1; |
1079 | bar.setCaption (i18n("Add / remove events") ); | 1079 | bar.setCaption (i18n("Add / remove events") ); |
1080 | bar.setTotalSteps ( el.count() ) ; | 1080 | bar.setTotalSteps ( el.count() ) ; |
1081 | bar.show(); | 1081 | bar.show(); |
1082 | incCounter = 0; | 1082 | incCounter = 0; |
1083 | 1083 | ||
1084 | while ( inL ) { | 1084 | while ( inL ) { |
1085 | 1085 | ||
1086 | qApp->processEvents(); | 1086 | qApp->processEvents(); |
1087 | if ( ! bar.isVisible() ) | 1087 | if ( ! bar.isVisible() ) |
1088 | return false; | 1088 | return false; |
1089 | if ( incCounter % modulo == 0 ) | 1089 | if ( incCounter % modulo == 0 ) |
1090 | bar.setProgress( incCounter ); | 1090 | bar.setProgress( incCounter ); |
1091 | ++incCounter; | 1091 | ++incCounter; |
1092 | uid = inL->uid(); | 1092 | uid = inL->uid(); |
1093 | bool skipIncidence = false; | 1093 | bool skipIncidence = false; |
1094 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1094 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1095 | skipIncidence = true; | 1095 | skipIncidence = true; |
1096 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1096 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1097 | skipIncidence = true; | 1097 | skipIncidence = true; |
1098 | if ( !skipIncidence ) { | 1098 | if ( !skipIncidence ) { |
1099 | inR = remote->incidence( uid ); | 1099 | inR = remote->incidence( uid ); |
1100 | if ( ! inR ) { | 1100 | if ( ! inR ) { |
1101 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1101 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1102 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1102 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1103 | checkExternSyncEvent(eventLSyncSharp, inL); | 1103 | checkExternSyncEvent(eventLSyncSharp, inL); |
1104 | local->deleteIncidence( inL ); | 1104 | local->deleteIncidence( inL ); |
1105 | ++deletedEventL; | 1105 | ++deletedEventL; |
1106 | } else { | 1106 | } else { |
1107 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1107 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1108 | inL->removeID(mCurrentSyncDevice ); | 1108 | inL->removeID(mCurrentSyncDevice ); |
1109 | ++addedEventR; | 1109 | ++addedEventR; |
1110 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1110 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1111 | inL->setLastModified( modifiedCalendar ); | 1111 | inL->setLastModified( modifiedCalendar ); |
1112 | inR = inL->clone(); | 1112 | inR = inL->clone(); |
1113 | inR->setIDStr( ":" ); | 1113 | inR->setIDStr( ":" ); |
1114 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1114 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1115 | remote->addIncidence( inR ); | 1115 | remote->addIncidence( inR ); |
1116 | } | 1116 | } |
1117 | } | 1117 | } |
1118 | } else { | 1118 | } else { |
1119 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1119 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1120 | checkExternSyncEvent(eventLSyncSharp, inL); | 1120 | checkExternSyncEvent(eventLSyncSharp, inL); |
1121 | local->deleteIncidence( inL ); | 1121 | local->deleteIncidence( inL ); |
1122 | ++deletedEventL; | 1122 | ++deletedEventL; |
1123 | } else { | 1123 | } else { |
1124 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1124 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1125 | ++addedEventR; | 1125 | ++addedEventR; |
1126 | inL->setLastModified( modifiedCalendar ); | 1126 | inL->setLastModified( modifiedCalendar ); |
1127 | inR = inL->clone(); | 1127 | inR = inL->clone(); |
1128 | inR->setIDStr( ":" ); | 1128 | inR->setIDStr( ":" ); |
1129 | remote->addIncidence( inR ); | 1129 | remote->addIncidence( inR ); |
1130 | } | 1130 | } |
1131 | } | 1131 | } |
1132 | } | 1132 | } |
1133 | } | 1133 | } |
1134 | } | 1134 | } |
1135 | inL = el.next(); | 1135 | inL = el.next(); |
1136 | } | 1136 | } |
1137 | int delFut = 0; | 1137 | int delFut = 0; |
1138 | int remRem = 0; | 1138 | int remRem = 0; |
1139 | if ( mSyncManager->mWriteBackInFuture ) { | 1139 | if ( mSyncManager->mWriteBackInFuture ) { |
1140 | er = remote->rawIncidences(); | 1140 | er = remote->rawIncidences(); |
1141 | remRem = er.count(); | 1141 | remRem = er.count(); |
1142 | inR = er.first(); | 1142 | inR = er.first(); |
1143 | QDateTime dt; | 1143 | QDateTime dt; |
1144 | QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); | 1144 | QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); |
1145 | QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); | 1145 | QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); |
1146 | while ( inR ) { | 1146 | while ( inR ) { |
1147 | if ( inR->type() == "Todo" ) { | 1147 | if ( inR->type() == "Todo" ) { |
1148 | Todo * t = (Todo*)inR; | 1148 | Todo * t = (Todo*)inR; |
1149 | if ( t->hasDueDate() ) | 1149 | if ( t->hasDueDate() ) |
1150 | dt = t->dtDue(); | 1150 | dt = t->dtDue(); |
1151 | else | 1151 | else |
1152 | dt = cur.addSecs( 62 ); | 1152 | dt = cur.addSecs( 62 ); |
1153 | } | 1153 | } |
1154 | else if (inR->type() == "Event" ) { | 1154 | else if (inR->type() == "Event" ) { |
1155 | bool ok; | 1155 | bool ok; |
1156 | dt = inR->getNextOccurence( cur, &ok ); | 1156 | dt = inR->getNextOccurence( cur, &ok ); |
1157 | if ( !ok ) | 1157 | if ( !ok ) |
1158 | dt = cur.addSecs( -62 ); | 1158 | dt = cur.addSecs( -62 ); |
1159 | } | 1159 | } |
1160 | else | 1160 | else |
1161 | dt = inR->dtStart(); | 1161 | dt = inR->dtStart(); |
1162 | if ( dt < cur || dt > end ) { | 1162 | if ( dt < cur || dt > end ) { |
1163 | remote->deleteIncidence( inR ); | 1163 | remote->deleteIncidence( inR ); |
1164 | ++delFut; | 1164 | ++delFut; |
1165 | } | 1165 | } |
1166 | inR = er.next(); | 1166 | inR = er.next(); |
1167 | } | 1167 | } |
1168 | } | 1168 | } |
1169 | bar.hide(); | 1169 | bar.hide(); |
1170 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1170 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1171 | eventLSync->setReadOnly( false ); | 1171 | eventLSync->setReadOnly( false ); |
1172 | eventLSync->setDtStart( mLastCalendarSync ); | 1172 | eventLSync->setDtStart( mLastCalendarSync ); |
1173 | eventRSync->setDtStart( mLastCalendarSync ); | 1173 | eventRSync->setDtStart( mLastCalendarSync ); |
1174 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1174 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1175 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1175 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1176 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1176 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1177 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1177 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1178 | eventLSync->setReadOnly( true ); | 1178 | eventLSync->setReadOnly( true ); |
1179 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... | 1179 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncKDE) // kde is abnormal... |
1180 | remote->addEvent( eventRSync ); | 1180 | remote->addEvent( eventRSync ); |
1181 | else | 1181 | else |
1182 | delete eventRSync; | 1182 | delete eventRSync; |
1183 | QString mes; | 1183 | QString mes; |
1184 | 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 ); | 1184 | 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 ); |
1185 | QString delmess; | 1185 | QString delmess; |
1186 | if ( delFut ) { | 1186 | if ( delFut ) { |
1187 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); | 1187 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1188 | mes += delmess; | 1188 | mes += delmess; |
1189 | } | 1189 | } |
1190 | if ( mSyncManager->mShowSyncSummary ) { | 1190 | if ( mSyncManager->mShowSyncSummary ) { |
1191 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1191 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1192 | } | 1192 | } |
1193 | qDebug( mes ); | 1193 | qDebug( mes ); |
1194 | mCalendar->checkAlarmForIncidence( 0, true ); | 1194 | mCalendar->checkAlarmForIncidence( 0, true ); |
1195 | return syncOK; | 1195 | return syncOK; |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void CalendarView::setSyncDevice( QString s ) | 1198 | void CalendarView::setSyncDevice( QString s ) |
1199 | { | 1199 | { |
1200 | mCurrentSyncDevice= s; | 1200 | mCurrentSyncDevice= s; |
1201 | } | 1201 | } |
1202 | void CalendarView::setSyncName( QString s ) | 1202 | void CalendarView::setSyncName( QString s ) |
1203 | { | 1203 | { |
1204 | mCurrentSyncName= s; | 1204 | mCurrentSyncName= s; |
1205 | } | 1205 | } |
1206 | bool CalendarView::syncCalendar(QString filename, int mode) | 1206 | bool CalendarView::syncCalendar(QString filename, int mode) |
1207 | { | 1207 | { |
1208 | //qDebug("syncCalendar %s ", filename.latin1()); | 1208 | //qDebug("syncCalendar %s ", filename.latin1()); |
1209 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1209 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1210 | CalendarLocal* calendar = new CalendarLocal(); | 1210 | CalendarLocal* calendar = new CalendarLocal(); |
1211 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1211 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1212 | FileStorage* storage = new FileStorage( calendar ); | 1212 | FileStorage* storage = new FileStorage( calendar ); |
1213 | bool syncOK = false; | 1213 | bool syncOK = false; |
1214 | storage->setFileName( filename ); | 1214 | storage->setFileName( filename ); |
1215 | // qDebug("loading ... "); | 1215 | // qDebug("loading ... "); |
1216 | if ( storage->load() ) { | 1216 | if ( storage->load() ) { |
1217 | getEventViewerDialog()->setSyncMode( true ); | 1217 | getEventViewerDialog()->setSyncMode( true ); |
1218 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1218 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1219 | getEventViewerDialog()->setSyncMode( false ); | 1219 | getEventViewerDialog()->setSyncMode( false ); |
1220 | if ( syncOK ) { | 1220 | if ( syncOK ) { |
1221 | if ( mSyncManager->mWriteBackFile ) | 1221 | if ( mSyncManager->mWriteBackFile ) |
1222 | { | 1222 | { |
1223 | storage->setSaveFormat( new ICalFormat() ); | 1223 | storage->setSaveFormat( new ICalFormat() ); |
1224 | storage->save(); | 1224 | storage->save(); |
1225 | } | 1225 | } |
1226 | } | 1226 | } |
1227 | setModified( true ); | 1227 | setModified( true ); |
1228 | } | 1228 | } |
1229 | delete storage; | 1229 | delete storage; |
1230 | delete calendar; | 1230 | delete calendar; |
1231 | if ( syncOK ) | 1231 | if ( syncOK ) |
1232 | updateView(); | 1232 | updateView(); |
1233 | return syncOK; | 1233 | return syncOK; |
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | void CalendarView::syncExternal( int mode ) | 1236 | void CalendarView::syncExternal( int mode ) |
1237 | { | 1237 | { |
1238 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1238 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1239 | 1239 | ||
1240 | qApp->processEvents(); | 1240 | qApp->processEvents(); |
1241 | CalendarLocal* calendar = new CalendarLocal(); | 1241 | CalendarLocal* calendar = new CalendarLocal(); |
1242 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1242 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1243 | bool syncOK = false; | 1243 | bool syncOK = false; |
1244 | bool loadSuccess = false; | 1244 | bool loadSuccess = false; |
1245 | PhoneFormat* phoneFormat = 0; | 1245 | PhoneFormat* phoneFormat = 0; |
1246 | emit tempDisableBR(true); | 1246 | emit tempDisableBR(true); |
1247 | #ifndef DESKTOP_VERSION | 1247 | #ifndef DESKTOP_VERSION |
1248 | SharpFormat* sharpFormat = 0; | 1248 | SharpFormat* sharpFormat = 0; |
1249 | if ( mode == 0 ) { // sharp | 1249 | if ( mode == 0 ) { // sharp |
1250 | sharpFormat = new SharpFormat () ; | 1250 | sharpFormat = new SharpFormat () ; |
1251 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1251 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1252 | 1252 | ||
1253 | } else | 1253 | } else |
1254 | #endif | 1254 | #endif |
1255 | if ( mode == 1 ) { // phone | 1255 | if ( mode == 1 ) { // phone |
1256 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1256 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1257 | mSyncManager->mPhoneDevice, | 1257 | mSyncManager->mPhoneDevice, |
1258 | mSyncManager->mPhoneConnection, | 1258 | mSyncManager->mPhoneConnection, |
1259 | mSyncManager->mPhoneModel); | 1259 | mSyncManager->mPhoneModel); |
1260 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1260 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1261 | 1261 | ||
1262 | } else { | 1262 | } else { |
1263 | emit tempDisableBR(false); | 1263 | emit tempDisableBR(false); |
1264 | return; | 1264 | return; |
1265 | } | 1265 | } |
1266 | if ( loadSuccess ) { | 1266 | if ( loadSuccess ) { |
1267 | getEventViewerDialog()->setSyncMode( true ); | 1267 | getEventViewerDialog()->setSyncMode( true ); |
1268 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1268 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1269 | getEventViewerDialog()->setSyncMode( false ); | 1269 | getEventViewerDialog()->setSyncMode( false ); |
1270 | qApp->processEvents(); | 1270 | qApp->processEvents(); |
1271 | if ( syncOK ) { | 1271 | if ( syncOK ) { |
1272 | if ( mSyncManager->mWriteBackFile ) | 1272 | if ( mSyncManager->mWriteBackFile ) |
1273 | { | 1273 | { |
1274 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1274 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1275 | Incidence* inc = iL.first(); | 1275 | Incidence* inc = iL.first(); |
1276 | if ( phoneFormat ) { | 1276 | if ( phoneFormat ) { |
1277 | while ( inc ) { | 1277 | while ( inc ) { |
1278 | inc->removeID(mCurrentSyncDevice); | 1278 | inc->removeID(mCurrentSyncDevice); |
1279 | inc = iL.next(); | 1279 | inc = iL.next(); |
1280 | } | 1280 | } |
1281 | } | 1281 | } |
1282 | #ifndef DESKTOP_VERSION | 1282 | #ifndef DESKTOP_VERSION |
1283 | if ( sharpFormat ) | 1283 | if ( sharpFormat ) |
1284 | sharpFormat->save(calendar); | 1284 | sharpFormat->save(calendar); |
1285 | #endif | 1285 | #endif |
1286 | if ( phoneFormat ) | 1286 | if ( phoneFormat ) |
1287 | phoneFormat->save(calendar); | 1287 | phoneFormat->save(calendar); |
1288 | iL = calendar->rawIncidences(); | 1288 | iL = calendar->rawIncidences(); |
1289 | inc = iL.first(); | 1289 | inc = iL.first(); |
1290 | Incidence* loc; | 1290 | Incidence* loc; |
1291 | while ( inc ) { | 1291 | while ( inc ) { |
1292 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1292 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1293 | loc = mCalendar->incidence(inc->uid() ); | 1293 | loc = mCalendar->incidence(inc->uid() ); |
1294 | if ( loc ) { | 1294 | if ( loc ) { |
1295 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1295 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1296 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1296 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1297 | } | 1297 | } |
1298 | } | 1298 | } |
1299 | inc = iL.next(); | 1299 | inc = iL.next(); |
1300 | } | 1300 | } |
1301 | Incidence* lse = getLastSyncEvent(); | 1301 | Incidence* lse = getLastSyncEvent(); |
1302 | if ( lse ) { | 1302 | if ( lse ) { |
1303 | lse->setReadOnly( false ); | 1303 | lse->setReadOnly( false ); |
1304 | lse->setDescription( "" ); | 1304 | lse->setDescription( "" ); |
1305 | lse->setReadOnly( true ); | 1305 | lse->setReadOnly( true ); |
1306 | } | 1306 | } |
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | setModified( true ); | 1309 | setModified( true ); |
1310 | } else { | 1310 | } else { |
1311 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1311 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1312 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1312 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1313 | question, i18n("Ok")) ; | 1313 | question, i18n("Ok")) ; |
1314 | 1314 | ||
1315 | } | 1315 | } |
1316 | delete calendar; | 1316 | delete calendar; |
1317 | updateView(); | 1317 | updateView(); |
1318 | emit tempDisableBR(false); | 1318 | emit tempDisableBR(false); |
1319 | return ;//syncOK; | 1319 | return ;//syncOK; |
1320 | 1320 | ||
1321 | } | 1321 | } |
1322 | 1322 | ||
1323 | bool CalendarView::importBday() | 1323 | bool CalendarView::importBday() |
1324 | { | 1324 | { |
1325 | #ifndef KORG_NOKABC | 1325 | #ifndef KORG_NOKABC |
1326 | 1326 | ||
1327 | #ifdef DESKTOP_VERSION | 1327 | #ifdef DESKTOP_VERSION |
1328 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1328 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1329 | KABC::AddressBook::Iterator it; | 1329 | KABC::AddressBook::Iterator it; |
1330 | int count = 0; | 1330 | int count = 0; |
1331 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1331 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1332 | ++count; | 1332 | ++count; |
1333 | } | 1333 | } |
1334 | QProgressBar bar(count,0 ); | 1334 | QProgressBar bar(count,0 ); |
1335 | int w = 300; | 1335 | int w = 300; |
1336 | if ( QApplication::desktop()->width() < 320 ) | 1336 | if ( QApplication::desktop()->width() < 320 ) |
1337 | w = 220; | 1337 | w = 220; |
1338 | int h = bar.sizeHint().height() ; | 1338 | int h = bar.sizeHint().height() ; |
1339 | int dw = QApplication::desktop()->width(); | 1339 | int dw = QApplication::desktop()->width(); |
1340 | int dh = QApplication::desktop()->height(); | 1340 | int dh = QApplication::desktop()->height(); |
1341 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1341 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1342 | bar.show(); | 1342 | bar.show(); |
1343 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1343 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1344 | qApp->processEvents(); | 1344 | qApp->processEvents(); |
1345 | count = 0; | 1345 | count = 0; |
1346 | int addCount = 0; | 1346 | int addCount = 0; |
1347 | KCal::Attendee* a = 0; | 1347 | KCal::Attendee* a = 0; |
1348 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1348 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1349 | if ( ! bar.isVisible() ) | 1349 | if ( ! bar.isVisible() ) |
1350 | return false; | 1350 | return false; |
1351 | bar.setProgress( count++ ); | 1351 | bar.setProgress( count++ ); |
1352 | qApp->processEvents(); | 1352 | qApp->processEvents(); |
1353 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1353 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1354 | if ( (*it).birthday().date().isValid() ){ | 1354 | if ( (*it).birthday().date().isValid() ){ |
1355 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1355 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1356 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1356 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1357 | ++addCount; | 1357 | ++addCount; |
1358 | } | 1358 | } |
1359 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1359 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1360 | if ( anni.isValid() ){ | 1360 | if ( anni.isValid() ){ |
1361 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1361 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1362 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1362 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1363 | ++addCount; | 1363 | ++addCount; |
1364 | } | 1364 | } |
1365 | } | 1365 | } |
1366 | updateView(); | 1366 | updateView(); |
1367 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1367 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1368 | #else //DESKTOP_VERSION | 1368 | #else //DESKTOP_VERSION |
1369 | 1369 | ||
1370 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 1370 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
1371 | // the result should now arrive through method insertBirthdays | 1371 | // the result should now arrive through method insertBirthdays |
1372 | 1372 | ||
1373 | #endif //DESKTOP_VERSION | 1373 | #endif //DESKTOP_VERSION |
1374 | 1374 | ||
1375 | #endif //KORG_NOKABC | 1375 | #endif //KORG_NOKABC |
1376 | 1376 | ||
1377 | 1377 | ||
1378 | return true; | 1378 | return true; |
1379 | } | 1379 | } |
1380 | 1380 | ||
1381 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 1381 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
1382 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 1382 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
1383 | const QStringList& anniversaryList, const QStringList& realNameList, | 1383 | const QStringList& anniversaryList, const QStringList& realNameList, |
1384 | const QStringList& emailList, const QStringList& assembledNameList, | 1384 | const QStringList& emailList, const QStringList& assembledNameList, |
1385 | const QStringList& uidList) | 1385 | const QStringList& uidList) |
1386 | { | 1386 | { |
1387 | qDebug("CalendarView::insertBirthdays"); | 1387 | qDebug("CalendarView::insertBirthdays"); |
1388 | if (uid == this->name()) | 1388 | if (uid == this->name()) |
1389 | { | 1389 | { |
1390 | int count = birthdayList.count(); | 1390 | int count = birthdayList.count(); |
1391 | int addCount = 0; | 1391 | int addCount = 0; |
1392 | KCal::Attendee* a = 0; | 1392 | KCal::Attendee* a = 0; |
1393 | 1393 | ||
1394 | qDebug("CalView 1 %i", count); | 1394 | qDebug("CalView 1 %i", count); |
1395 | 1395 | ||
1396 | QProgressBar bar(count,0 ); | 1396 | QProgressBar bar(count,0 ); |
1397 | int w = 300; | 1397 | int w = 300; |
1398 | if ( QApplication::desktop()->width() < 320 ) | 1398 | if ( QApplication::desktop()->width() < 320 ) |
1399 | w = 220; | 1399 | w = 220; |
1400 | int h = bar.sizeHint().height() ; | 1400 | int h = bar.sizeHint().height() ; |
1401 | int dw = QApplication::desktop()->width(); | 1401 | int dw = QApplication::desktop()->width(); |
1402 | int dh = QApplication::desktop()->height(); | 1402 | int dh = QApplication::desktop()->height(); |
1403 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1403 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1404 | bar.show(); | 1404 | bar.show(); |
1405 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 1405 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
1406 | qApp->processEvents(); | 1406 | qApp->processEvents(); |
1407 | 1407 | ||
1408 | QDate birthday; | 1408 | QDate birthday; |
1409 | QDate anniversary; | 1409 | QDate anniversary; |
1410 | QString realName; | 1410 | QString realName; |
1411 | QString email; | 1411 | QString email; |
1412 | QString assembledName; | 1412 | QString assembledName; |
1413 | QString uid; | 1413 | QString uid; |
1414 | bool ok = true; | 1414 | bool ok = true; |
1415 | for ( int i = 0; i < count; i++) | 1415 | for ( int i = 0; i < count; i++) |
1416 | { | 1416 | { |
1417 | if ( ! bar.isVisible() ) | 1417 | if ( ! bar.isVisible() ) |
1418 | return; | 1418 | return; |
1419 | bar.setProgress( i ); | 1419 | bar.setProgress( i ); |
1420 | qApp->processEvents(); | 1420 | qApp->processEvents(); |
1421 | 1421 | ||
1422 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 1422 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
1423 | if (!ok) { | 1423 | if (!ok) { |
1424 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 1424 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
1425 | } | 1425 | } |
1426 | 1426 | ||
1427 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 1427 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
1428 | if (!ok) { | 1428 | if (!ok) { |
1429 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 1429 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
1430 | } | 1430 | } |
1431 | realName = realNameList[i]; | 1431 | realName = realNameList[i]; |
1432 | email = emailList[i]; | 1432 | email = emailList[i]; |
1433 | assembledName = assembledNameList[i]; | 1433 | assembledName = assembledNameList[i]; |
1434 | uid = uidList[i]; | 1434 | uid = uidList[i]; |
1435 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); | 1435 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); |
1436 | 1436 | ||
1437 | if ( birthday.isValid() ){ | 1437 | if ( birthday.isValid() ){ |
1438 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1438 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1439 | KCal::Attendee::ReqParticipant,uid) ; | 1439 | KCal::Attendee::ReqParticipant,uid) ; |
1440 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 1440 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
1441 | ++addCount; | 1441 | ++addCount; |
1442 | } | 1442 | } |
1443 | 1443 | ||
1444 | if ( anniversary.isValid() ){ | 1444 | if ( anniversary.isValid() ){ |
1445 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1445 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1446 | KCal::Attendee::ReqParticipant,uid) ; | 1446 | KCal::Attendee::ReqParticipant,uid) ; |
1447 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 1447 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
1448 | ++addCount; | 1448 | ++addCount; |
1449 | } | 1449 | } |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | updateView(); | 1452 | updateView(); |
1453 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1453 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1454 | 1454 | ||
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | } | 1457 | } |
1458 | 1458 | ||
1459 | 1459 | ||
1460 | 1460 | ||
1461 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1461 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1462 | { | 1462 | { |
1463 | //qDebug("addAnni "); | 1463 | //qDebug("addAnni "); |
1464 | Event * ev = new Event(); | 1464 | Event * ev = new Event(); |
1465 | if ( a ) { | 1465 | if ( a ) { |
1466 | ev->addAttendee( a ); | 1466 | ev->addAttendee( a ); |
1467 | } | 1467 | } |
1468 | QString kind; | 1468 | QString kind; |
1469 | if ( birthday ) | 1469 | if ( birthday ) |
1470 | kind = i18n( "Birthday" ); | 1470 | kind = i18n( "Birthday" ); |
1471 | else | 1471 | else |
1472 | kind = i18n( "Anniversary" ); | 1472 | kind = i18n( "Anniversary" ); |
1473 | ev->setSummary( name + " - " + kind ); | 1473 | ev->setSummary( name + " - " + kind ); |
1474 | ev->setOrganizer(a->email()); | 1474 | ev->setOrganizer(a->email()); |
1475 | ev->setCategories( kind ); | 1475 | ev->setCategories( kind ); |
1476 | ev->setDtStart( QDateTime(date) ); | 1476 | ev->setDtStart( QDateTime(date) ); |
1477 | ev->setDtEnd( QDateTime(date) ); | 1477 | ev->setDtEnd( QDateTime(date) ); |
1478 | ev->setFloats( true ); | 1478 | ev->setFloats( true ); |
1479 | Recurrence * rec = ev->recurrence(); | 1479 | Recurrence * rec = ev->recurrence(); |
1480 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1480 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1481 | rec->addYearlyNum( date.month() ); | 1481 | rec->addYearlyNum( date.month() ); |
1482 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1482 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1483 | delete ev; | 1483 | delete ev; |
1484 | return false; | 1484 | return false; |
1485 | } | 1485 | } |
1486 | return true; | 1486 | return true; |
1487 | 1487 | ||
1488 | } | 1488 | } |
1489 | bool CalendarView::importQtopia( const QString &categories, | 1489 | bool CalendarView::importQtopia( const QString &categories, |
1490 | const QString &datebook, | 1490 | const QString &datebook, |
1491 | const QString &todolist ) | 1491 | const QString &todolist ) |
1492 | { | 1492 | { |
1493 | 1493 | ||
1494 | QtopiaFormat qtopiaFormat; | 1494 | QtopiaFormat qtopiaFormat; |
1495 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1495 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1496 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1496 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1497 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1497 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1498 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1498 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1499 | 1499 | ||
1500 | updateView(); | 1500 | updateView(); |
1501 | return true; | 1501 | return true; |
1502 | 1502 | ||
1503 | #if 0 | 1503 | #if 0 |
1504 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1504 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1505 | mCurrentSyncDevice = "qtopia-XML"; | 1505 | mCurrentSyncDevice = "qtopia-XML"; |
1506 | if ( mSyncManager->mAskForPreferences ) | 1506 | if ( mSyncManager->mAskForPreferences ) |
1507 | edit_sync_options(); | 1507 | edit_sync_options(); |
1508 | qApp->processEvents(); | 1508 | qApp->processEvents(); |
1509 | CalendarLocal* calendar = new CalendarLocal(); | 1509 | CalendarLocal* calendar = new CalendarLocal(); |
1510 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1510 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1511 | bool syncOK = false; | 1511 | bool syncOK = false; |
1512 | QtopiaFormat qtopiaFormat; | 1512 | QtopiaFormat qtopiaFormat; |
1513 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1513 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1514 | bool loadOk = true; | 1514 | bool loadOk = true; |
1515 | if ( !categories.isEmpty() ) | 1515 | if ( !categories.isEmpty() ) |
1516 | loadOk = qtopiaFormat.load( calendar, categories ); | 1516 | loadOk = qtopiaFormat.load( calendar, categories ); |
1517 | if ( loadOk && !datebook.isEmpty() ) | 1517 | if ( loadOk && !datebook.isEmpty() ) |
1518 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1518 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1519 | if ( loadOk && !todolist.isEmpty() ) | 1519 | if ( loadOk && !todolist.isEmpty() ) |
1520 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1520 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1521 | 1521 | ||
1522 | if ( loadOk ) { | 1522 | if ( loadOk ) { |
1523 | getEventViewerDialog()->setSyncMode( true ); | 1523 | getEventViewerDialog()->setSyncMode( true ); |
1524 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1524 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1525 | getEventViewerDialog()->setSyncMode( false ); | 1525 | getEventViewerDialog()->setSyncMode( false ); |
1526 | qApp->processEvents(); | 1526 | qApp->processEvents(); |
1527 | if ( syncOK ) { | 1527 | if ( syncOK ) { |
1528 | if ( mSyncManager->mWriteBackFile ) | 1528 | if ( mSyncManager->mWriteBackFile ) |
1529 | { | 1529 | { |
1530 | // write back XML file | 1530 | // write back XML file |
1531 | 1531 | ||
1532 | } | 1532 | } |
1533 | setModified( true ); | 1533 | setModified( true ); |
1534 | } | 1534 | } |
1535 | } else { | 1535 | } else { |
1536 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1536 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1537 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1537 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1538 | question, i18n("Ok")) ; | 1538 | question, i18n("Ok")) ; |
1539 | } | 1539 | } |
1540 | delete calendar; | 1540 | delete calendar; |
1541 | updateView(); | 1541 | updateView(); |
1542 | return syncOK; | 1542 | return syncOK; |
1543 | 1543 | ||
1544 | 1544 | ||
1545 | #endif | 1545 | #endif |
1546 | 1546 | ||
1547 | } | 1547 | } |
1548 | 1548 | ||
1549 | void CalendarView::setSyncEventsReadOnly() | 1549 | void CalendarView::setSyncEventsReadOnly() |
1550 | { | 1550 | { |
1551 | Event * ev; | 1551 | Event * ev; |
1552 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1552 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1553 | ev = eL.first(); | 1553 | ev = eL.first(); |
1554 | while ( ev ) { | 1554 | while ( ev ) { |
1555 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1555 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1556 | ev->setReadOnly( true ); | 1556 | ev->setReadOnly( true ); |
1557 | ev = eL.next(); | 1557 | ev = eL.next(); |
1558 | } | 1558 | } |
1559 | } | 1559 | } |
1560 | bool CalendarView::openCalendar(QString filename, bool merge) | 1560 | bool CalendarView::openCalendar(QString filename, bool merge) |
1561 | { | 1561 | { |
1562 | 1562 | ||
1563 | if (filename.isEmpty()) { | 1563 | if (filename.isEmpty()) { |
1564 | return false; | 1564 | return false; |
1565 | } | 1565 | } |
1566 | 1566 | ||
1567 | if (!QFile::exists(filename)) { | 1567 | if (!QFile::exists(filename)) { |
1568 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1568 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1569 | return false; | 1569 | return false; |
1570 | } | 1570 | } |
1571 | 1571 | ||
1572 | globalFlagBlockAgenda = 1; | 1572 | globalFlagBlockAgenda = 1; |
1573 | if (!merge) mCalendar->close(); | 1573 | if (!merge) mCalendar->close(); |
1574 | 1574 | ||
1575 | mStorage->setFileName( filename ); | 1575 | mStorage->setFileName( filename ); |
1576 | 1576 | ||
1577 | if ( mStorage->load() ) { | 1577 | if ( mStorage->load() ) { |
1578 | if ( merge ) ;//setModified( true ); | 1578 | if ( merge ) ;//setModified( true ); |
1579 | else { | 1579 | else { |
1580 | //setModified( true ); | 1580 | //setModified( true ); |
1581 | mViewManager->setDocumentId( filename ); | 1581 | mViewManager->setDocumentId( filename ); |
1582 | mDialogManager->setDocumentId( filename ); | 1582 | mDialogManager->setDocumentId( filename ); |
1583 | mTodoList->setDocumentId( filename ); | 1583 | mTodoList->setDocumentId( filename ); |
1584 | } | 1584 | } |
1585 | globalFlagBlockAgenda = 2; | 1585 | globalFlagBlockAgenda = 2; |
1586 | // if ( getLastSyncEvent() ) | 1586 | // if ( getLastSyncEvent() ) |
1587 | // getLastSyncEvent()->setReadOnly( true ); | 1587 | // getLastSyncEvent()->setReadOnly( true ); |
1588 | mCalendar->reInitAlarmSettings(); | 1588 | mCalendar->reInitAlarmSettings(); |
1589 | setSyncEventsReadOnly(); | 1589 | setSyncEventsReadOnly(); |
1590 | updateUnmanagedViews(); | 1590 | updateUnmanagedViews(); |
1591 | updateView(); | 1591 | updateView(); |
1592 | if ( filename != MainWindow::defaultFileName() ) { | 1592 | if ( filename != MainWindow::defaultFileName() ) { |
1593 | saveCalendar( MainWindow::defaultFileName() ); | 1593 | saveCalendar( MainWindow::defaultFileName() ); |
1594 | } else { | 1594 | } else { |
1595 | QFileInfo finf ( MainWindow::defaultFileName()); | 1595 | QFileInfo finf ( MainWindow::defaultFileName()); |
1596 | if ( finf.exists() ) { | 1596 | if ( finf.exists() ) { |
1597 | setLoadedFileVersion( finf.lastModified () ); | 1597 | setLoadedFileVersion( finf.lastModified () ); |
1598 | } | 1598 | } |
1599 | } | 1599 | } |
1600 | return true; | 1600 | return true; |
1601 | } else { | 1601 | } else { |
1602 | // while failing to load, the calendar object could | 1602 | // while failing to load, the calendar object could |
1603 | // have become partially populated. Clear it out. | 1603 | // have become partially populated. Clear it out. |
1604 | if ( !merge ) { | 1604 | if ( !merge ) { |
1605 | mCalendar->close(); | 1605 | mCalendar->close(); |
1606 | mViewManager->setDocumentId( filename ); | 1606 | mViewManager->setDocumentId( filename ); |
1607 | mDialogManager->setDocumentId( filename ); | 1607 | mDialogManager->setDocumentId( filename ); |
1608 | mTodoList->setDocumentId( filename ); | 1608 | mTodoList->setDocumentId( filename ); |
1609 | } | 1609 | } |
1610 | 1610 | ||
1611 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1611 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1612 | 1612 | ||
1613 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 1613 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
1614 | globalFlagBlockAgenda = 2; | 1614 | globalFlagBlockAgenda = 2; |
1615 | mCalendar->reInitAlarmSettings(); | 1615 | mCalendar->reInitAlarmSettings(); |
1616 | setSyncEventsReadOnly(); | 1616 | setSyncEventsReadOnly(); |
1617 | updateUnmanagedViews(); | 1617 | updateUnmanagedViews(); |
1618 | updateView(); | 1618 | updateView(); |
1619 | } | 1619 | } |
1620 | return false; | 1620 | return false; |
1621 | } | 1621 | } |
1622 | void CalendarView::showOpenError() | 1622 | void CalendarView::showOpenError() |
1623 | { | 1623 | { |
1624 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 1624 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
1625 | } | 1625 | } |
1626 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1626 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1627 | { | 1627 | { |
1628 | loadedFileVersion = dt; | 1628 | loadedFileVersion = dt; |
1629 | } | 1629 | } |
1630 | bool CalendarView::checkFileChanged(QString fn) | 1630 | bool CalendarView::checkFileChanged(QString fn) |
1631 | { | 1631 | { |
1632 | QFileInfo finf ( fn ); | 1632 | QFileInfo finf ( fn ); |
1633 | if ( !finf.exists() ) | 1633 | if ( !finf.exists() ) |
1634 | return true; | 1634 | return true; |
1635 | QDateTime dt = finf.lastModified (); | 1635 | QDateTime dt = finf.lastModified (); |
1636 | if ( dt <= loadedFileVersion ) | 1636 | if ( dt <= loadedFileVersion ) |
1637 | return false; | 1637 | return false; |
1638 | return true; | 1638 | return true; |
1639 | 1639 | ||
1640 | } | 1640 | } |
1641 | void CalendarView::watchSavedFile() | 1641 | void CalendarView::watchSavedFile() |
1642 | { | 1642 | { |
1643 | QFileInfo finf ( MainWindow::defaultFileName()); | 1643 | QFileInfo finf ( MainWindow::defaultFileName()); |
1644 | if ( !finf.exists() ) | 1644 | if ( !finf.exists() ) |
1645 | return; | 1645 | return; |
1646 | QDateTime dt = finf.lastModified (); | 1646 | QDateTime dt = finf.lastModified (); |
1647 | if ( dt < loadedFileVersion ) { | 1647 | if ( dt < loadedFileVersion ) { |
1648 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 1648 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
1649 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 1649 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
1650 | return; | 1650 | return; |
1651 | } | 1651 | } |
1652 | loadedFileVersion = dt; | 1652 | loadedFileVersion = dt; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | bool CalendarView::checkFileVersion(QString fn) | 1655 | bool CalendarView::checkFileVersion(QString fn) |
1656 | { | 1656 | { |
1657 | QFileInfo finf ( fn ); | 1657 | QFileInfo finf ( fn ); |
1658 | if ( !finf.exists() ) | 1658 | if ( !finf.exists() ) |
1659 | return true; | 1659 | return true; |
1660 | QDateTime dt = finf.lastModified (); | 1660 | QDateTime dt = finf.lastModified (); |
1661 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 1661 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
1662 | //qDebug("file on disk version %s",dt.toString().latin1()); | 1662 | //qDebug("file on disk version %s",dt.toString().latin1()); |
1663 | if ( dt <= loadedFileVersion ) | 1663 | if ( dt <= loadedFileVersion ) |
1664 | return true; | 1664 | return true; |
1665 | 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, true)) , | 1665 | 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, true)) , |
1666 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 1666 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
1667 | i18n("Sync+save")); | 1667 | i18n("Sync+save")); |
1668 | 1668 | ||
1669 | if ( km == KMessageBox::Cancel ) | 1669 | if ( km == KMessageBox::Cancel ) |
1670 | return false; | 1670 | return false; |
1671 | if ( km == KMessageBox::Yes ) | 1671 | if ( km == KMessageBox::Yes ) |
1672 | return true; | 1672 | return true; |
1673 | 1673 | ||
1674 | setSyncDevice("deleteaftersync" ); | 1674 | setSyncDevice("deleteaftersync" ); |
1675 | mSyncManager->mAskForPreferences = true; | 1675 | mSyncManager->mAskForPreferences = true; |
1676 | mSyncManager->mSyncAlgoPrefs = 3; | 1676 | mSyncManager->mSyncAlgoPrefs = 3; |
1677 | mSyncManager->mWriteBackFile = false; | 1677 | mSyncManager->mWriteBackFile = false; |
1678 | mSyncManager->mWriteBackExistingOnly = false; | 1678 | mSyncManager->mWriteBackExistingOnly = false; |
1679 | mSyncManager->mShowSyncSummary = false; | 1679 | mSyncManager->mShowSyncSummary = false; |
1680 | syncCalendar( fn, 3 ); | 1680 | syncCalendar( fn, 3 ); |
1681 | Event * e = getLastSyncEvent(); | 1681 | Event * e = getLastSyncEvent(); |
1682 | mCalendar->deleteEvent ( e ); | 1682 | mCalendar->deleteEvent ( e ); |
1683 | updateView(); | 1683 | updateView(); |
1684 | return true; | 1684 | return true; |
1685 | } | 1685 | } |
1686 | 1686 | ||
1687 | bool CalendarView::saveCalendar( QString filename ) | 1687 | bool CalendarView::saveCalendar( QString filename ) |
1688 | { | 1688 | { |
1689 | 1689 | ||
1690 | // Store back all unsaved data into calendar object | 1690 | // Store back all unsaved data into calendar object |
1691 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 1691 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
1692 | if ( mViewManager->currentView() ) | 1692 | if ( mViewManager->currentView() ) |
1693 | mViewManager->currentView()->flushView(); | 1693 | mViewManager->currentView()->flushView(); |
1694 | 1694 | ||
1695 | 1695 | ||
1696 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); | 1696 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); |
1697 | mStorage->setSaveFormat( new ICalFormat() ); | 1697 | mStorage->setSaveFormat( new ICalFormat() ); |
1698 | mStorage->setFileName( filename ); | 1698 | mStorage->setFileName( filename ); |
1699 | bool success; | 1699 | bool success; |
1700 | success = mStorage->save(); | 1700 | success = mStorage->save(); |
1701 | if ( !success ) { | 1701 | if ( !success ) { |
1702 | return false; | 1702 | return false; |
1703 | } | 1703 | } |
1704 | if ( filename == MainWindow::defaultFileName() ) { | 1704 | if ( filename == MainWindow::defaultFileName() ) { |
1705 | setLoadedFileVersion( lfv ); | 1705 | setLoadedFileVersion( lfv ); |
1706 | watchSavedFile(); | 1706 | watchSavedFile(); |
1707 | } | 1707 | } |
1708 | return true; | 1708 | return true; |
1709 | } | 1709 | } |
1710 | 1710 | ||
1711 | void CalendarView::closeCalendar() | 1711 | void CalendarView::closeCalendar() |
1712 | { | 1712 | { |
1713 | 1713 | ||
1714 | // child windows no longer valid | 1714 | // child windows no longer valid |
1715 | emit closingDown(); | 1715 | emit closingDown(); |
1716 | 1716 | ||
1717 | mCalendar->close(); | 1717 | mCalendar->close(); |
1718 | setModified(false); | 1718 | setModified(false); |
1719 | updateView(); | 1719 | updateView(); |
1720 | } | 1720 | } |
1721 | 1721 | ||
1722 | void CalendarView::archiveCalendar() | 1722 | void CalendarView::archiveCalendar() |
1723 | { | 1723 | { |
1724 | mDialogManager->showArchiveDialog(); | 1724 | mDialogManager->showArchiveDialog(); |
1725 | } | 1725 | } |
1726 | 1726 | ||
1727 | 1727 | ||
1728 | void CalendarView::readSettings() | 1728 | void CalendarView::readSettings() |
1729 | { | 1729 | { |
1730 | 1730 | ||
1731 | 1731 | ||
1732 | // mViewManager->showAgendaView(); | 1732 | // mViewManager->showAgendaView(); |
1733 | QString str; | 1733 | QString str; |
1734 | //qDebug("CalendarView::readSettings() "); | 1734 | //qDebug("CalendarView::readSettings() "); |
1735 | // read settings from the KConfig, supplying reasonable | 1735 | // read settings from the KConfig, supplying reasonable |
1736 | // defaults where none are to be found | 1736 | // defaults where none are to be found |
1737 | KConfig *config = KOGlobals::config(); | 1737 | KConfig *config = KOGlobals::config(); |
1738 | #ifndef KORG_NOSPLITTER | 1738 | #ifndef KORG_NOSPLITTER |
1739 | config->setGroup("KOrganizer Geometry"); | 1739 | config->setGroup("KOrganizer Geometry"); |
1740 | 1740 | ||
1741 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 1741 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
1742 | if (sizes.count() != 2) { | 1742 | if (sizes.count() != 2) { |
1743 | sizes << mDateNavigator->minimumSizeHint().width(); | 1743 | sizes << mDateNavigator->minimumSizeHint().width(); |
1744 | sizes << 300; | 1744 | sizes << 300; |
1745 | } | 1745 | } |
1746 | mPanner->setSizes(sizes); | 1746 | mPanner->setSizes(sizes); |
1747 | 1747 | ||
1748 | sizes = config->readIntListEntry("Separator2"); | 1748 | sizes = config->readIntListEntry("Separator2"); |
1749 | if ( ( mResourceView && sizes.count() == 4 ) || | 1749 | if ( ( mResourceView && sizes.count() == 4 ) || |
1750 | ( !mResourceView && sizes.count() == 3 ) ) { | 1750 | ( !mResourceView && sizes.count() == 3 ) ) { |
1751 | mLeftSplitter->setSizes(sizes); | 1751 | mLeftSplitter->setSizes(sizes); |
1752 | } | 1752 | } |
1753 | #endif | 1753 | #endif |
1754 | globalFlagBlockAgenda = 1; | 1754 | globalFlagBlockAgenda = 1; |
1755 | mViewManager->showAgendaView(); | 1755 | mViewManager->showAgendaView(); |
1756 | //mViewManager->readSettings( config ); | 1756 | //mViewManager->readSettings( config ); |
1757 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 1757 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
1758 | readFilterSettings(config); | 1758 | readFilterSettings(config); |
1759 | config->setGroup( "Views" ); | 1759 | config->setGroup( "Views" ); |
1760 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 1760 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
1761 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 1761 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
1762 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 1762 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
1763 | else mNavigator->selectDates( dateCount ); | 1763 | else mNavigator->selectDates( dateCount ); |
1764 | // mViewManager->readSettings( config ); | 1764 | // mViewManager->readSettings( config ); |
1765 | updateConfig(); | 1765 | updateConfig(); |
1766 | globalFlagBlockAgenda = 2; | 1766 | globalFlagBlockAgenda = 2; |
1767 | mViewManager->readSettings( config ); | 1767 | mViewManager->readSettings( config ); |
1768 | #ifdef DESKTOP_VERSION | 1768 | #ifdef DESKTOP_VERSION |
1769 | config->setGroup("WidgetLayout"); | 1769 | config->setGroup("WidgetLayout"); |
1770 | QStringList list; | 1770 | QStringList list; |
1771 | list = config->readListEntry("MainLayout"); | 1771 | list = config->readListEntry("MainLayout"); |
1772 | int x,y,w,h; | 1772 | int x,y,w,h; |
1773 | if ( ! list.isEmpty() ) { | 1773 | if ( ! list.isEmpty() ) { |
1774 | x = list[0].toInt(); | 1774 | x = list[0].toInt(); |
1775 | y = list[1].toInt(); | 1775 | y = list[1].toInt(); |
1776 | w = list[2].toInt(); | 1776 | w = list[2].toInt(); |
1777 | h = list[3].toInt(); | 1777 | h = list[3].toInt(); |
1778 | topLevelWidget()->setGeometry(x,y,w,h); | 1778 | topLevelWidget()->setGeometry(x,y,w,h); |
1779 | 1779 | ||
1780 | } else { | 1780 | } else { |
1781 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 1781 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
1782 | } | 1782 | } |
1783 | list = config->readListEntry("EditEventLayout"); | 1783 | list = config->readListEntry("EditEventLayout"); |
1784 | if ( ! list.isEmpty() ) { | 1784 | if ( ! list.isEmpty() ) { |
1785 | x = list[0].toInt(); | 1785 | x = list[0].toInt(); |
1786 | y = list[1].toInt(); | 1786 | y = list[1].toInt(); |
1787 | w = list[2].toInt(); | 1787 | w = list[2].toInt(); |
1788 | h = list[3].toInt(); | 1788 | h = list[3].toInt(); |
1789 | mEventEditor->setGeometry(x,y,w,h); | 1789 | mEventEditor->setGeometry(x,y,w,h); |
1790 | 1790 | ||
1791 | } | 1791 | } |
1792 | list = config->readListEntry("EditTodoLayout"); | 1792 | list = config->readListEntry("EditTodoLayout"); |
1793 | if ( ! list.isEmpty() ) { | 1793 | if ( ! list.isEmpty() ) { |
1794 | x = list[0].toInt(); | 1794 | x = list[0].toInt(); |
1795 | y = list[1].toInt(); | 1795 | y = list[1].toInt(); |
1796 | w = list[2].toInt(); | 1796 | w = list[2].toInt(); |
1797 | h = list[3].toInt(); | 1797 | h = list[3].toInt(); |
1798 | mTodoEditor->setGeometry(x,y,w,h); | 1798 | mTodoEditor->setGeometry(x,y,w,h); |
1799 | 1799 | ||
1800 | } | 1800 | } |
1801 | list = config->readListEntry("ViewerLayout"); | 1801 | list = config->readListEntry("ViewerLayout"); |
1802 | if ( ! list.isEmpty() ) { | 1802 | if ( ! list.isEmpty() ) { |
1803 | x = list[0].toInt(); | 1803 | x = list[0].toInt(); |
1804 | y = list[1].toInt(); | 1804 | y = list[1].toInt(); |
1805 | w = list[2].toInt(); | 1805 | w = list[2].toInt(); |
1806 | h = list[3].toInt(); | 1806 | h = list[3].toInt(); |
1807 | getEventViewerDialog()->setGeometry(x,y,w,h); | 1807 | getEventViewerDialog()->setGeometry(x,y,w,h); |
1808 | } | 1808 | } |
1809 | #endif | 1809 | #endif |
1810 | 1810 | ||
1811 | } | 1811 | } |
1812 | 1812 | ||
1813 | 1813 | ||
1814 | void CalendarView::writeSettings() | 1814 | void CalendarView::writeSettings() |
1815 | { | 1815 | { |
1816 | // kdDebug() << "CalendarView::writeSettings" << endl; | 1816 | // kdDebug() << "CalendarView::writeSettings" << endl; |
1817 | 1817 | ||
1818 | KConfig *config = KOGlobals::config(); | 1818 | KConfig *config = KOGlobals::config(); |
1819 | 1819 | ||
1820 | #ifndef KORG_NOSPLITTER | 1820 | #ifndef KORG_NOSPLITTER |
1821 | config->setGroup("KOrganizer Geometry"); | 1821 | config->setGroup("KOrganizer Geometry"); |
1822 | 1822 | ||
1823 | QValueList<int> list = mPanner->sizes(); | 1823 | QValueList<int> list = mPanner->sizes(); |
1824 | config->writeEntry("Separator1",list); | 1824 | config->writeEntry("Separator1",list); |
1825 | 1825 | ||
1826 | list = mLeftSplitter->sizes(); | 1826 | list = mLeftSplitter->sizes(); |
1827 | config->writeEntry("Separator2",list); | 1827 | config->writeEntry("Separator2",list); |
1828 | #endif | 1828 | #endif |
1829 | 1829 | ||
1830 | mViewManager->writeSettings( config ); | 1830 | mViewManager->writeSettings( config ); |
1831 | mTodoList->saveLayout(config,QString("Todo Layout")); | 1831 | mTodoList->saveLayout(config,QString("Todo Layout")); |
1832 | mDialogManager->writeSettings( config ); | 1832 | mDialogManager->writeSettings( config ); |
1833 | //KOPrefs::instance()->usrWriteConfig(); | 1833 | //KOPrefs::instance()->usrWriteConfig(); |
1834 | KOPrefs::instance()->writeConfig(); | 1834 | KOPrefs::instance()->writeConfig(); |
1835 | 1835 | ||
1836 | writeFilterSettings(config); | 1836 | writeFilterSettings(config); |
1837 | 1837 | ||
1838 | config->setGroup( "Views" ); | 1838 | config->setGroup( "Views" ); |
1839 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); | 1839 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); |
1840 | 1840 | ||
1841 | #ifdef DESKTOP_VERSION | 1841 | #ifdef DESKTOP_VERSION |
1842 | config->setGroup("WidgetLayout"); | 1842 | config->setGroup("WidgetLayout"); |
1843 | QStringList list ;//= config->readListEntry("MainLayout"); | 1843 | QStringList list ;//= config->readListEntry("MainLayout"); |
1844 | int x,y,w,h; | 1844 | int x,y,w,h; |
1845 | QWidget* wid; | 1845 | QWidget* wid; |
1846 | wid = topLevelWidget(); | 1846 | wid = topLevelWidget(); |
1847 | x = wid->geometry().x(); | 1847 | x = wid->geometry().x(); |
1848 | y = wid->geometry().y(); | 1848 | y = wid->geometry().y(); |
1849 | w = wid->width(); | 1849 | w = wid->width(); |
1850 | h = wid->height(); | 1850 | h = wid->height(); |
1851 | list.clear(); | 1851 | list.clear(); |
1852 | list << QString::number( x ); | 1852 | list << QString::number( x ); |
1853 | list << QString::number( y ); | 1853 | list << QString::number( y ); |
1854 | list << QString::number( w ); | 1854 | list << QString::number( w ); |
1855 | list << QString::number( h ); | 1855 | list << QString::number( h ); |
1856 | config->writeEntry("MainLayout",list ); | 1856 | config->writeEntry("MainLayout",list ); |
1857 | 1857 | ||
1858 | wid = mEventEditor; | 1858 | wid = mEventEditor; |
1859 | x = wid->geometry().x(); | 1859 | x = wid->geometry().x(); |
1860 | y = wid->geometry().y(); | 1860 | y = wid->geometry().y(); |
1861 | w = wid->width(); | 1861 | w = wid->width(); |
1862 | h = wid->height(); | 1862 | h = wid->height(); |
1863 | list.clear(); | 1863 | list.clear(); |
1864 | list << QString::number( x ); | 1864 | list << QString::number( x ); |
1865 | list << QString::number( y ); | 1865 | list << QString::number( y ); |
1866 | list << QString::number( w ); | 1866 | list << QString::number( w ); |
1867 | list << QString::number( h ); | 1867 | list << QString::number( h ); |
1868 | config->writeEntry("EditEventLayout",list ); | 1868 | config->writeEntry("EditEventLayout",list ); |
1869 | 1869 | ||
1870 | wid = mTodoEditor; | 1870 | wid = mTodoEditor; |
1871 | x = wid->geometry().x(); | 1871 | x = wid->geometry().x(); |
1872 | y = wid->geometry().y(); | 1872 | y = wid->geometry().y(); |
1873 | w = wid->width(); | 1873 | w = wid->width(); |
1874 | h = wid->height(); | 1874 | h = wid->height(); |
1875 | list.clear(); | 1875 | list.clear(); |
1876 | list << QString::number( x ); | 1876 | list << QString::number( x ); |
1877 | list << QString::number( y ); | 1877 | list << QString::number( y ); |
1878 | list << QString::number( w ); | 1878 | list << QString::number( w ); |
1879 | list << QString::number( h ); | 1879 | list << QString::number( h ); |
1880 | config->writeEntry("EditTodoLayout",list ); | 1880 | config->writeEntry("EditTodoLayout",list ); |
1881 | wid = getEventViewerDialog(); | 1881 | wid = getEventViewerDialog(); |
1882 | x = wid->geometry().x(); | 1882 | x = wid->geometry().x(); |
1883 | y = wid->geometry().y(); | 1883 | y = wid->geometry().y(); |
1884 | w = wid->width(); | 1884 | w = wid->width(); |
1885 | h = wid->height(); | 1885 | h = wid->height(); |
1886 | list.clear(); | 1886 | list.clear(); |
1887 | list << QString::number( x ); | 1887 | list << QString::number( x ); |
1888 | list << QString::number( y ); | 1888 | list << QString::number( y ); |
1889 | list << QString::number( w ); | 1889 | list << QString::number( w ); |
1890 | list << QString::number( h ); | 1890 | list << QString::number( h ); |
1891 | config->writeEntry("ViewerLayout",list ); | 1891 | config->writeEntry("ViewerLayout",list ); |
1892 | wid = mDialogManager->getSearchDialog(); | 1892 | wid = mDialogManager->getSearchDialog(); |
1893 | if ( wid ) { | 1893 | if ( wid ) { |
1894 | x = wid->geometry().x(); | 1894 | x = wid->geometry().x(); |
1895 | y = wid->geometry().y(); | 1895 | y = wid->geometry().y(); |
1896 | w = wid->width(); | 1896 | w = wid->width(); |
1897 | h = wid->height(); | 1897 | h = wid->height(); |
1898 | list.clear(); | 1898 | list.clear(); |
1899 | list << QString::number( x ); | 1899 | list << QString::number( x ); |
1900 | list << QString::number( y ); | 1900 | list << QString::number( y ); |
1901 | list << QString::number( w ); | 1901 | list << QString::number( w ); |
1902 | list << QString::number( h ); | 1902 | list << QString::number( h ); |
1903 | config->writeEntry("SearchLayout",list ); | 1903 | config->writeEntry("SearchLayout",list ); |
1904 | } | 1904 | } |
1905 | #endif | 1905 | #endif |
1906 | 1906 | ||
1907 | 1907 | ||
1908 | config->sync(); | 1908 | config->sync(); |
1909 | } | 1909 | } |
1910 | 1910 | ||
1911 | void CalendarView::readFilterSettings(KConfig *config) | 1911 | void CalendarView::readFilterSettings(KConfig *config) |
1912 | { | 1912 | { |
1913 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; | 1913 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; |
1914 | 1914 | ||
1915 | mFilters.clear(); | 1915 | mFilters.clear(); |
1916 | 1916 | ||
1917 | config->setGroup("General"); | 1917 | config->setGroup("General"); |
1918 | QStringList filterList = config->readListEntry("CalendarFilters"); | 1918 | QStringList filterList = config->readListEntry("CalendarFilters"); |
1919 | 1919 | ||
1920 | QStringList::ConstIterator it = filterList.begin(); | 1920 | QStringList::ConstIterator it = filterList.begin(); |
1921 | QStringList::ConstIterator end = filterList.end(); | 1921 | QStringList::ConstIterator end = filterList.end(); |
1922 | while(it != end) { | 1922 | while(it != end) { |
1923 | // kdDebug() << " filter: " << (*it) << endl; | 1923 | // kdDebug() << " filter: " << (*it) << endl; |
1924 | 1924 | ||
1925 | CalFilter *filter; | 1925 | CalFilter *filter; |
1926 | filter = new CalFilter(*it); | 1926 | filter = new CalFilter(*it); |
1927 | config->setGroup("Filter_" + (*it)); | 1927 | config->setGroup("Filter_" + (*it)); |
1928 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); | 1928 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); |
1929 | filter->setCriteria(config->readNumEntry("Criteria",0)); | 1929 | filter->setCriteria(config->readNumEntry("Criteria",0)); |
1930 | filter->setCategoryList(config->readListEntry("CategoryList")); | 1930 | filter->setCategoryList(config->readListEntry("CategoryList")); |
1931 | mFilters.append(filter); | 1931 | mFilters.append(filter); |
1932 | 1932 | ||
1933 | ++it; | 1933 | ++it; |
1934 | } | 1934 | } |
1935 | 1935 | ||
1936 | if (mFilters.count() == 0) { | 1936 | if (mFilters.count() == 0) { |
1937 | CalFilter *filter = new CalFilter(i18n("Default")); | 1937 | CalFilter *filter = new CalFilter(i18n("Default")); |
1938 | mFilters.append(filter); | 1938 | mFilters.append(filter); |
1939 | } | 1939 | } |
1940 | mFilterView->updateFilters(); | 1940 | mFilterView->updateFilters(); |
1941 | config->setGroup("FilterView"); | 1941 | config->setGroup("FilterView"); |
1942 | 1942 | ||
1943 | mFilterView->blockSignals(true); | 1943 | mFilterView->blockSignals(true); |
1944 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); | 1944 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); |
1945 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); | 1945 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); |
1946 | mFilterView->blockSignals(false); | 1946 | mFilterView->blockSignals(false); |
1947 | // We do it manually to avoid it being done twice by the above calls | 1947 | // We do it manually to avoid it being done twice by the above calls |
1948 | updateFilter(); | 1948 | updateFilter(); |
1949 | } | 1949 | } |
1950 | 1950 | ||
1951 | void CalendarView::writeFilterSettings(KConfig *config) | 1951 | void CalendarView::writeFilterSettings(KConfig *config) |
1952 | { | 1952 | { |
1953 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; | 1953 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; |
1954 | 1954 | ||
1955 | QStringList filterList; | 1955 | QStringList filterList; |
1956 | 1956 | ||
1957 | CalFilter *filter = mFilters.first(); | 1957 | CalFilter *filter = mFilters.first(); |
1958 | while(filter) { | 1958 | while(filter) { |
1959 | // kdDebug() << " fn: " << filter->name() << endl; | 1959 | // kdDebug() << " fn: " << filter->name() << endl; |
1960 | filterList << filter->name(); | 1960 | filterList << filter->name(); |
1961 | config->setGroup("Filter_" + filter->name()); | 1961 | config->setGroup("Filter_" + filter->name()); |
1962 | config->writeEntry("Criteria",filter->criteria()); | 1962 | config->writeEntry("Criteria",filter->criteria()); |
1963 | config->writeEntry("CategoryList",filter->categoryList()); | 1963 | config->writeEntry("CategoryList",filter->categoryList()); |
1964 | filter = mFilters.next(); | 1964 | filter = mFilters.next(); |
1965 | } | 1965 | } |
1966 | config->setGroup("General"); | 1966 | config->setGroup("General"); |
1967 | config->writeEntry("CalendarFilters",filterList); | 1967 | config->writeEntry("CalendarFilters",filterList); |
1968 | 1968 | ||
1969 | config->setGroup("FilterView"); | 1969 | config->setGroup("FilterView"); |
1970 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); | 1970 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); |
1971 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); | 1971 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); |
1972 | } | 1972 | } |
1973 | 1973 | ||
1974 | 1974 | ||
1975 | void CalendarView::goToday() | 1975 | void CalendarView::goToday() |
1976 | { | 1976 | { |
1977 | mNavigator->selectToday(); | 1977 | mNavigator->selectToday(); |
1978 | } | 1978 | } |
1979 | 1979 | ||
1980 | void CalendarView::goNext() | 1980 | void CalendarView::goNext() |
1981 | { | 1981 | { |
1982 | mNavigator->selectNext(); | 1982 | mNavigator->selectNext(); |
1983 | } | 1983 | } |
1984 | 1984 | ||
1985 | void CalendarView::goPrevious() | 1985 | void CalendarView::goPrevious() |
1986 | { | 1986 | { |
1987 | mNavigator->selectPrevious(); | 1987 | mNavigator->selectPrevious(); |
1988 | } | 1988 | } |
1989 | void CalendarView::goNextMonth() | 1989 | void CalendarView::goNextMonth() |
1990 | { | 1990 | { |
1991 | mNavigator->selectNextMonth(); | 1991 | mNavigator->selectNextMonth(); |
1992 | } | 1992 | } |
1993 | 1993 | ||
1994 | void CalendarView::goPreviousMonth() | 1994 | void CalendarView::goPreviousMonth() |
1995 | { | 1995 | { |
1996 | mNavigator->selectPreviousMonth(); | 1996 | mNavigator->selectPreviousMonth(); |
1997 | } | 1997 | } |
1998 | void CalendarView::writeLocale() | 1998 | void CalendarView::writeLocale() |
1999 | { | 1999 | { |
2000 | //KPimGlobalPrefs::instance()->setGlobalConfig(); | 2000 | //KPimGlobalPrefs::instance()->setGlobalConfig(); |
2001 | #if 0 | 2001 | #if 0 |
2002 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); | 2002 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); |
2003 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); | 2003 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); |
2004 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); | 2004 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); |
2005 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); | 2005 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); |
2006 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; | 2006 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; |
2007 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); | 2007 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); |
2008 | dummy = KOPrefs::instance()->mUserDateFormatShort; | 2008 | dummy = KOPrefs::instance()->mUserDateFormatShort; |
2009 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); | 2009 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); |
2010 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, | 2010 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, |
2011 | KOPrefs::instance()->mDaylightsavingStart, | 2011 | KOPrefs::instance()->mDaylightsavingStart, |
2012 | KOPrefs::instance()->mDaylightsavingEnd ); | 2012 | KOPrefs::instance()->mDaylightsavingEnd ); |
2013 | KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); | 2013 | KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); |
2014 | #endif | 2014 | #endif |
2015 | } | 2015 | } |
2016 | void CalendarView::updateConfig() | 2016 | void CalendarView::updateConfig() |
2017 | { | 2017 | { |
2018 | writeLocale(); | 2018 | writeLocale(); |
2019 | if ( KOPrefs::instance()->mUseAppColors ) | 2019 | if ( KOPrefs::instance()->mUseAppColors ) |
2020 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); | 2020 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); |
2021 | emit configChanged(); | 2021 | emit configChanged(); |
2022 | mTodoList->updateConfig(); | 2022 | mTodoList->updateConfig(); |
2023 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); | 2023 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); |
2024 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2024 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
2025 | // To make the "fill window" configurations work | 2025 | // To make the "fill window" configurations work |
2026 | //mViewManager->raiseCurrentView(); | 2026 | //mViewManager->raiseCurrentView(); |
2027 | } | 2027 | } |
2028 | 2028 | ||
2029 | 2029 | ||
2030 | void CalendarView::eventChanged(Event *event) | 2030 | void CalendarView::eventChanged(Event *event) |
2031 | { | 2031 | { |
2032 | changeEventDisplay(event,KOGlobals::EVENTEDITED); | 2032 | changeEventDisplay(event,KOGlobals::EVENTEDITED); |
2033 | //updateUnmanagedViews(); | 2033 | //updateUnmanagedViews(); |
2034 | } | 2034 | } |
2035 | 2035 | ||
2036 | void CalendarView::eventAdded(Event *event) | 2036 | void CalendarView::eventAdded(Event *event) |
2037 | { | 2037 | { |
2038 | changeEventDisplay(event,KOGlobals::EVENTADDED); | 2038 | changeEventDisplay(event,KOGlobals::EVENTADDED); |
2039 | } | 2039 | } |
2040 | 2040 | ||
2041 | void CalendarView::eventToBeDeleted(Event *) | 2041 | void CalendarView::eventToBeDeleted(Event *) |
2042 | { | 2042 | { |
2043 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; | 2043 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; |
2044 | } | 2044 | } |
2045 | 2045 | ||
2046 | void CalendarView::eventDeleted() | 2046 | void CalendarView::eventDeleted() |
2047 | { | 2047 | { |
2048 | changeEventDisplay(0,KOGlobals::EVENTDELETED); | 2048 | changeEventDisplay(0,KOGlobals::EVENTDELETED); |
2049 | } | 2049 | } |
2050 | void CalendarView::changeTodoDisplay(Todo *which, int action) | 2050 | void CalendarView::changeTodoDisplay(Todo *which, int action) |
2051 | { | 2051 | { |
2052 | changeIncidenceDisplay((Incidence *)which, action); | 2052 | changeIncidenceDisplay((Incidence *)which, action); |
2053 | mDateNavigator->updateView(); //LR | 2053 | mDateNavigator->updateView(); //LR |
2054 | //mDialogManager->updateSearchDialog(); | 2054 | //mDialogManager->updateSearchDialog(); |
2055 | 2055 | ||
2056 | if (which) { | 2056 | if (which) { |
2057 | mViewManager->updateWNview(); | 2057 | mViewManager->updateWNview(); |
2058 | //mTodoList->updateView(); | 2058 | //mTodoList->updateView(); |
2059 | } | 2059 | } |
2060 | 2060 | ||
2061 | } | 2061 | } |
2062 | 2062 | ||
2063 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) | 2063 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) |
2064 | { | 2064 | { |
2065 | updateUnmanagedViews(); | 2065 | updateUnmanagedViews(); |
2066 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); | 2066 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); |
2067 | if ( action == KOGlobals::EVENTDELETED ) { //delete | 2067 | if ( action == KOGlobals::EVENTDELETED ) { //delete |
2068 | mCalendar->checkAlarmForIncidence( 0, true ); | 2068 | mCalendar->checkAlarmForIncidence( 0, true ); |
2069 | if ( mEventViewerDialog ) | 2069 | if ( mEventViewerDialog ) |
2070 | mEventViewerDialog->hide(); | 2070 | mEventViewerDialog->hide(); |
2071 | } | 2071 | } |
2072 | else | 2072 | else |
2073 | mCalendar->checkAlarmForIncidence( which , false ); | 2073 | mCalendar->checkAlarmForIncidence( which , false ); |
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | // most of the changeEventDisplays() right now just call the view's | 2076 | // most of the changeEventDisplays() right now just call the view's |
2077 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. | 2077 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. |
2078 | void CalendarView::changeEventDisplay(Event *which, int action) | 2078 | void CalendarView::changeEventDisplay(Event *which, int action) |
2079 | { | 2079 | { |
2080 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; | 2080 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; |
2081 | changeIncidenceDisplay((Incidence *)which, action); | 2081 | changeIncidenceDisplay((Incidence *)which, action); |
2082 | mDateNavigator->updateView(); | 2082 | mDateNavigator->updateView(); |
2083 | //mDialogManager->updateSearchDialog(); | 2083 | //mDialogManager->updateSearchDialog(); |
2084 | 2084 | ||
2085 | if (which) { | 2085 | if (which) { |
2086 | // If there is an event view visible update the display | 2086 | // If there is an event view visible update the display |
2087 | mViewManager->currentView()->changeEventDisplay(which,action); | 2087 | mViewManager->currentView()->changeEventDisplay(which,action); |
2088 | // TODO: check, if update needed | 2088 | // TODO: check, if update needed |
2089 | // if (which->getTodoStatus()) { | 2089 | // if (which->getTodoStatus()) { |
2090 | mTodoList->updateView(); | 2090 | mTodoList->updateView(); |
2091 | // } | 2091 | // } |
2092 | } else { | 2092 | } else { |
2093 | mViewManager->currentView()->updateView(); | 2093 | mViewManager->currentView()->updateView(); |
2094 | } | 2094 | } |
2095 | } | 2095 | } |
2096 | 2096 | ||
2097 | 2097 | ||
2098 | void CalendarView::updateTodoViews() | 2098 | void CalendarView::updateTodoViews() |
2099 | { | 2099 | { |
2100 | 2100 | ||
2101 | mTodoList->updateView(); | 2101 | mTodoList->updateView(); |
2102 | mViewManager->currentView()->updateView(); | 2102 | mViewManager->currentView()->updateView(); |
2103 | 2103 | ||
2104 | } | 2104 | } |
2105 | 2105 | ||
2106 | 2106 | ||
2107 | void CalendarView::updateView(const QDate &start, const QDate &end) | 2107 | void CalendarView::updateView(const QDate &start, const QDate &end) |
2108 | { | 2108 | { |
2109 | mTodoList->updateView(); | 2109 | mTodoList->updateView(); |
2110 | mViewManager->updateView(start, end); | 2110 | mViewManager->updateView(start, end); |
2111 | //mDateNavigator->updateView(); | 2111 | //mDateNavigator->updateView(); |
2112 | } | 2112 | } |
2113 | 2113 | ||
2114 | void CalendarView::updateView() | 2114 | void CalendarView::updateView() |
2115 | { | 2115 | { |
2116 | DateList tmpList = mNavigator->selectedDates(); | 2116 | DateList tmpList = mNavigator->selectedDates(); |
2117 | 2117 | ||
2118 | // We assume that the navigator only selects consecutive days. | 2118 | // We assume that the navigator only selects consecutive days. |
2119 | updateView( tmpList.first(), tmpList.last() ); | 2119 | updateView( tmpList.first(), tmpList.last() ); |
2120 | } | 2120 | } |
2121 | 2121 | ||
2122 | void CalendarView::updateUnmanagedViews() | 2122 | void CalendarView::updateUnmanagedViews() |
2123 | { | 2123 | { |
2124 | mDateNavigator->updateDayMatrix(); | 2124 | mDateNavigator->updateDayMatrix(); |
2125 | } | 2125 | } |
2126 | 2126 | ||
2127 | int CalendarView::msgItemDelete() | 2127 | int CalendarView::msgItemDelete() |
2128 | { | 2128 | { |
2129 | return KMessageBox::warningContinueCancel(this, | 2129 | return KMessageBox::warningContinueCancel(this, |
2130 | i18n("This item will be\npermanently deleted."), | 2130 | i18n("This item will be\npermanently deleted."), |
2131 | i18n("KO/Pi Confirmation"),i18n("Delete")); | 2131 | i18n("KO/Pi Confirmation"),i18n("Delete")); |
2132 | } | 2132 | } |
2133 | 2133 | ||
2134 | 2134 | ||
2135 | void CalendarView::edit_cut() | 2135 | void CalendarView::edit_cut() |
2136 | { | 2136 | { |
2137 | Event *anEvent=0; | 2137 | Event *anEvent=0; |
2138 | 2138 | ||
2139 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2139 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2140 | 2140 | ||
2141 | if (mViewManager->currentView()->isEventView()) { | 2141 | if (mViewManager->currentView()->isEventView()) { |
2142 | if ( incidence && incidence->type() == "Event" ) { | 2142 | if ( incidence && incidence->type() == "Event" ) { |
2143 | anEvent = static_cast<Event *>(incidence); | 2143 | anEvent = static_cast<Event *>(incidence); |
2144 | } | 2144 | } |
2145 | } | 2145 | } |
2146 | 2146 | ||
2147 | if (!anEvent) { | 2147 | if (!anEvent) { |
2148 | KNotifyClient::beep(); | 2148 | KNotifyClient::beep(); |
2149 | return; | 2149 | return; |
2150 | } | 2150 | } |
2151 | DndFactory factory( mCalendar ); | 2151 | DndFactory factory( mCalendar ); |
2152 | factory.cutEvent(anEvent); | 2152 | factory.cutEvent(anEvent); |
2153 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2153 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2154 | } | 2154 | } |
2155 | 2155 | ||
2156 | void CalendarView::edit_copy() | 2156 | void CalendarView::edit_copy() |
2157 | { | 2157 | { |
2158 | Event *anEvent=0; | 2158 | Event *anEvent=0; |
2159 | 2159 | ||
2160 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2160 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2161 | 2161 | ||
2162 | if (mViewManager->currentView()->isEventView()) { | 2162 | if (mViewManager->currentView()->isEventView()) { |
2163 | if ( incidence && incidence->type() == "Event" ) { | 2163 | if ( incidence && incidence->type() == "Event" ) { |
2164 | anEvent = static_cast<Event *>(incidence); | 2164 | anEvent = static_cast<Event *>(incidence); |
2165 | } | 2165 | } |
2166 | } | 2166 | } |
2167 | 2167 | ||
2168 | if (!anEvent) { | 2168 | if (!anEvent) { |
2169 | KNotifyClient::beep(); | 2169 | KNotifyClient::beep(); |
2170 | return; | 2170 | return; |
2171 | } | 2171 | } |
2172 | DndFactory factory( mCalendar ); | 2172 | DndFactory factory( mCalendar ); |
2173 | factory.copyEvent(anEvent); | 2173 | factory.copyEvent(anEvent); |
2174 | } | 2174 | } |
2175 | 2175 | ||
2176 | void CalendarView::edit_paste() | 2176 | void CalendarView::edit_paste() |
2177 | { | 2177 | { |
2178 | QDate date = mNavigator->selectedDates().first(); | 2178 | QDate date = mNavigator->selectedDates().first(); |
2179 | 2179 | ||
2180 | DndFactory factory( mCalendar ); | 2180 | DndFactory factory( mCalendar ); |
2181 | Event *pastedEvent = factory.pasteEvent( date ); | 2181 | Event *pastedEvent = factory.pasteEvent( date ); |
2182 | 2182 | ||
2183 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); | 2183 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); |
2184 | } | 2184 | } |
2185 | 2185 | ||
2186 | void CalendarView::edit_options() | 2186 | void CalendarView::edit_options() |
2187 | { | 2187 | { |
2188 | mDialogManager->showOptionsDialog(); | 2188 | mDialogManager->showOptionsDialog(); |
2189 | //writeSettings(); | 2189 | //writeSettings(); |
2190 | } | 2190 | } |
2191 | 2191 | ||
2192 | void CalendarView::slotSelectPickerDate( QDate d) | 2192 | void CalendarView::slotSelectPickerDate( QDate d) |
2193 | { | 2193 | { |
2194 | mDateFrame->hide(); | 2194 | mDateFrame->hide(); |
2195 | if ( mDatePickerMode == 1 ) { | 2195 | if ( mDatePickerMode == 1 ) { |
2196 | mNavigator->slotDaySelect( d ); | 2196 | mNavigator->slotDaySelect( d ); |
2197 | } else if ( mDatePickerMode == 2 ) { | 2197 | } else if ( mDatePickerMode == 2 ) { |
2198 | if ( mMoveIncidence->type() == "Todo" ) { | 2198 | if ( mMoveIncidence->type() == "Todo" ) { |
2199 | Todo * to = (Todo *) mMoveIncidence; | 2199 | Todo * to = (Todo *) mMoveIncidence; |
2200 | QTime tim; | 2200 | QTime tim; |
2201 | if ( to->hasDueDate() ) | 2201 | if ( to->hasDueDate() ) |
2202 | tim = to->dtDue().time(); | 2202 | tim = to->dtDue().time(); |
2203 | else { | 2203 | else { |
2204 | tim = QTime ( 0,0,0 ); | 2204 | tim = QTime ( 0,0,0 ); |
2205 | to->setFloats( true ); | 2205 | to->setFloats( true ); |
2206 | to->setHasDueDate( true ); | 2206 | to->setHasDueDate( true ); |
2207 | } | 2207 | } |
2208 | QDateTime dt ( d,tim ); | 2208 | QDateTime dt ( d,tim ); |
2209 | to->setDtDue( dt ); | 2209 | to->setDtDue( dt ); |
2210 | todoChanged( to ); | 2210 | todoChanged( to ); |
2211 | } else { | 2211 | } else { |
2212 | QTime tim = mMoveIncidence->dtStart().time(); | 2212 | QTime tim = mMoveIncidence->dtStart().time(); |
2213 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); | 2213 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); |
2214 | QDateTime dt ( d,tim ); | 2214 | QDateTime dt ( d,tim ); |
2215 | mMoveIncidence->setDtStart( dt ); | 2215 | mMoveIncidence->setDtStart( dt ); |
2216 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); | 2216 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); |
2217 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); | 2217 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); |
2218 | } | 2218 | } |
2219 | 2219 | ||
2220 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); | 2220 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); |
2221 | } | 2221 | } |
2222 | } | 2222 | } |
2223 | 2223 | ||
2224 | void CalendarView::removeCategories() | 2224 | void CalendarView::removeCategories() |
2225 | { | 2225 | { |
2226 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2226 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2227 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2227 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2228 | QStringList catIncList; | 2228 | QStringList catIncList; |
2229 | QStringList newCatList; | 2229 | QStringList newCatList; |
2230 | Incidence* inc = incList.first(); | 2230 | Incidence* inc = incList.first(); |
2231 | int i; | 2231 | int i; |
2232 | int count = 0; | 2232 | int count = 0; |
2233 | while ( inc ) { | 2233 | while ( inc ) { |
2234 | newCatList.clear(); | 2234 | newCatList.clear(); |
2235 | catIncList = inc->categories() ; | 2235 | catIncList = inc->categories() ; |
2236 | for( i = 0; i< catIncList.count(); ++i ) { | 2236 | for( i = 0; i< catIncList.count(); ++i ) { |
2237 | if ( catList.contains (catIncList[i])) | 2237 | if ( catList.contains (catIncList[i])) |
2238 | newCatList.append( catIncList[i] ); | 2238 | newCatList.append( catIncList[i] ); |
2239 | } | 2239 | } |
2240 | newCatList.sort(); | 2240 | newCatList.sort(); |
2241 | inc->setCategories( newCatList.join(",") ); | 2241 | inc->setCategories( newCatList.join(",") ); |
2242 | inc = incList.next(); | 2242 | inc = incList.next(); |
2243 | } | 2243 | } |
2244 | } | 2244 | } |
2245 | 2245 | ||
2246 | int CalendarView::addCategories() | 2246 | int CalendarView::addCategories() |
2247 | { | 2247 | { |
2248 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2248 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2249 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2249 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2250 | QStringList catIncList; | 2250 | QStringList catIncList; |
2251 | Incidence* inc = incList.first(); | 2251 | Incidence* inc = incList.first(); |
2252 | int i; | 2252 | int i; |
2253 | int count = 0; | 2253 | int count = 0; |
2254 | while ( inc ) { | 2254 | while ( inc ) { |
2255 | catIncList = inc->categories() ; | 2255 | catIncList = inc->categories() ; |
2256 | for( i = 0; i< catIncList.count(); ++i ) { | 2256 | for( i = 0; i< catIncList.count(); ++i ) { |
2257 | if ( !catList.contains (catIncList[i])) { | 2257 | if ( !catList.contains (catIncList[i])) { |
2258 | catList.append( catIncList[i] ); | 2258 | catList.append( catIncList[i] ); |
2259 | //qDebug("add cat %s ", catIncList[i].latin1()); | 2259 | //qDebug("add cat %s ", catIncList[i].latin1()); |
2260 | ++count; | 2260 | ++count; |
2261 | } | 2261 | } |
2262 | } | 2262 | } |
2263 | inc = incList.next(); | 2263 | inc = incList.next(); |
2264 | } | 2264 | } |
2265 | catList.sort(); | 2265 | catList.sort(); |
2266 | KOPrefs::instance()->mCustomCategories = catList; | 2266 | KOPrefs::instance()->mCustomCategories = catList; |
2267 | return count; | 2267 | return count; |
2268 | } | 2268 | } |
2269 | 2269 | ||
2270 | void CalendarView::manageCategories() | 2270 | void CalendarView::manageCategories() |
2271 | { | 2271 | { |
2272 | KOCatPrefs* cp = new KOCatPrefs(); | 2272 | KOCatPrefs* cp = new KOCatPrefs(); |
2273 | cp->show(); | 2273 | cp->show(); |
2274 | int w =cp->sizeHint().width() ; | 2274 | int w =cp->sizeHint().width() ; |
2275 | int h = cp->sizeHint().height() ; | 2275 | int h = cp->sizeHint().height() ; |
2276 | int dw = QApplication::desktop()->width(); | 2276 | int dw = QApplication::desktop()->width(); |
2277 | int dh = QApplication::desktop()->height(); | 2277 | int dh = QApplication::desktop()->height(); |
2278 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2278 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2279 | if ( !cp->exec() ) { | 2279 | if ( !cp->exec() ) { |
2280 | delete cp; | 2280 | delete cp; |
2281 | return; | 2281 | return; |
2282 | } | 2282 | } |
2283 | int count = 0; | 2283 | int count = 0; |
2284 | if ( cp->addCat() ) { | 2284 | if ( cp->addCat() ) { |
2285 | count = addCategories(); | 2285 | count = addCategories(); |
2286 | if ( count ) { | 2286 | if ( count ) { |
2287 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); | 2287 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); |
2288 | writeSettings(); | 2288 | writeSettings(); |
2289 | } | 2289 | } |
2290 | } else { | 2290 | } else { |
2291 | removeCategories(); | 2291 | removeCategories(); |
2292 | updateView(); | 2292 | updateView(); |
2293 | } | 2293 | } |
2294 | delete cp; | 2294 | delete cp; |
2295 | } | 2295 | } |
2296 | 2296 | ||
2297 | void CalendarView::beamIncidence(Incidence * Inc) | 2297 | void CalendarView::beamIncidence(Incidence * Inc) |
2298 | { | 2298 | { |
2299 | QPtrList<Incidence> delSel ; | 2299 | QPtrList<Incidence> delSel ; |
2300 | delSel.append(Inc); | 2300 | delSel.append(Inc); |
2301 | beamIncidenceList( delSel ); | 2301 | beamIncidenceList( delSel ); |
2302 | } | 2302 | } |
2303 | void CalendarView::beamCalendar() | 2303 | void CalendarView::beamCalendar() |
2304 | { | 2304 | { |
2305 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); | 2305 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); |
2306 | //qDebug("beamCalendar() "); | 2306 | //qDebug("beamCalendar() "); |
2307 | beamIncidenceList( delSel ); | 2307 | beamIncidenceList( delSel ); |
2308 | } | 2308 | } |
2309 | void CalendarView::beamFilteredCalendar() | 2309 | void CalendarView::beamFilteredCalendar() |
2310 | { | 2310 | { |
2311 | QPtrList<Incidence> delSel = mCalendar->incidences(); | 2311 | QPtrList<Incidence> delSel = mCalendar->incidences(); |
2312 | //qDebug("beamFilteredCalendar() "); | 2312 | //qDebug("beamFilteredCalendar() "); |
2313 | beamIncidenceList( delSel ); | 2313 | beamIncidenceList( delSel ); |
2314 | } | 2314 | } |
2315 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) | 2315 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) |
2316 | { | 2316 | { |
2317 | if ( beamDialog->exec () == QDialog::Rejected ) | 2317 | if ( beamDialog->exec () == QDialog::Rejected ) |
2318 | return; | 2318 | return; |
2319 | #ifdef DESKTOP_VERSION | 2319 | #ifdef DESKTOP_VERSION |
2320 | QString fn = locateLocal( "tmp", "kopibeamfile" ); | 2320 | QString fn = locateLocal( "tmp", "kopibeamfile" ); |
2321 | #else | 2321 | #else |
2322 | QString fn = "/tmp/kopibeamfile"; | 2322 | QString fn = "/tmp/kopibeamfile"; |
2323 | #endif | 2323 | #endif |
2324 | QString mes; | 2324 | QString mes; |
2325 | bool createbup = true; | 2325 | bool createbup = true; |
2326 | if ( createbup ) { | 2326 | if ( createbup ) { |
2327 | QString description = "\n"; | 2327 | QString description = "\n"; |
2328 | CalendarLocal* cal = new CalendarLocal(); | 2328 | CalendarLocal* cal = new CalendarLocal(); |
2329 | if ( beamDialog->beamLocal() ) | 2329 | if ( beamDialog->beamLocal() ) |
2330 | cal->setLocalTime(); | 2330 | cal->setLocalTime(); |
2331 | else | 2331 | else |
2332 | cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2332 | cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
2333 | Incidence *incidence = delSel.first(); | 2333 | Incidence *incidence = delSel.first(); |
2334 | bool addText = false; | 2334 | bool addText = false; |
2335 | if ( delSel.count() < 10 ) | 2335 | if ( delSel.count() < 10 ) |
2336 | addText = true; | 2336 | addText = true; |
2337 | else { | 2337 | else { |
2338 | description.sprintf(i18n(" %d items?"),delSel.count() ); | 2338 | description.sprintf(i18n(" %d items?"),delSel.count() ); |
2339 | } | 2339 | } |
2340 | while ( incidence ) { | 2340 | while ( incidence ) { |
2341 | Incidence *in = incidence->clone(); | 2341 | Incidence *in = incidence->clone(); |
2342 | if ( ! in->summary().isEmpty() ) { | 2342 | if ( ! in->summary().isEmpty() ) { |
2343 | in->setDescription(""); | 2343 | in->setDescription(""); |
2344 | } else { | 2344 | } else { |
2345 | in->setSummary( in->description().left(20)); | 2345 | in->setSummary( in->description().left(20)); |
2346 | in->setDescription(""); | 2346 | in->setDescription(""); |
2347 | } | 2347 | } |
2348 | if ( addText ) | 2348 | if ( addText ) |
2349 | description += in->summary() + "\n"; | 2349 | description += in->summary() + "\n"; |
2350 | cal->addIncidence( in ); | 2350 | cal->addIncidence( in ); |
2351 | incidence = delSel.next(); | 2351 | incidence = delSel.next(); |
2352 | } | 2352 | } |
2353 | if ( beamDialog->beamVcal() ) { | 2353 | if ( beamDialog->beamVcal() ) { |
2354 | fn += ".vcs"; | 2354 | fn += ".vcs"; |
2355 | FileStorage storage( cal, fn, new VCalFormat ); | 2355 | FileStorage storage( cal, fn, new VCalFormat ); |
2356 | storage.save(); | 2356 | storage.save(); |
2357 | } else { | 2357 | } else { |
2358 | fn += ".ics"; | 2358 | fn += ".ics"; |
2359 | FileStorage storage( cal, fn, new ICalFormat( ) ); | 2359 | FileStorage storage( cal, fn, new ICalFormat( ) ); |
2360 | storage.save(); | 2360 | storage.save(); |
2361 | } | 2361 | } |
2362 | delete cal; | 2362 | delete cal; |
2363 | mes = i18n("KO/Pi: Ready for beaming"); | 2363 | mes = i18n("KO/Pi: Ready for beaming"); |
2364 | topLevelWidget()->setCaption(mes); | 2364 | topLevelWidget()->setCaption(mes); |
2365 | KApplication::convert2latin1( fn ); | 2365 | KApplication::convert2latin1( fn ); |
2366 | #ifndef DESKTOP_VERSION | 2366 | #ifndef DESKTOP_VERSION |
2367 | Ir *ir = new Ir( this ); | 2367 | Ir *ir = new Ir( this ); |
2368 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 2368 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
2369 | ir->send( fn, description, "text/x-vCalendar" ); | 2369 | ir->send( fn, description, "text/x-vCalendar" ); |
2370 | #endif | 2370 | #endif |
2371 | } | 2371 | } |
2372 | } | 2372 | } |
2373 | void CalendarView::beamDone( Ir *ir ) | 2373 | void CalendarView::beamDone( Ir *ir ) |
2374 | { | 2374 | { |
2375 | #ifndef DESKTOP_VERSION | 2375 | #ifndef DESKTOP_VERSION |
2376 | delete ir; | 2376 | delete ir; |
2377 | #endif | 2377 | #endif |
2378 | topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); | 2378 | topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); |
2379 | topLevelWidget()->raise(); | 2379 | topLevelWidget()->raise(); |
2380 | } | 2380 | } |
2381 | 2381 | ||
2382 | void CalendarView::moveIncidence(Incidence * inc ) | 2382 | void CalendarView::moveIncidence(Incidence * inc ) |
2383 | { | 2383 | { |
2384 | if ( !inc ) return; | 2384 | if ( !inc ) return; |
2385 | // qDebug("showDatePickerForIncidence( ) "); | 2385 | // qDebug("showDatePickerForIncidence( ) "); |
2386 | if ( mDateFrame->isVisible() ) | 2386 | if ( mDateFrame->isVisible() ) |
2387 | mDateFrame->hide(); | 2387 | mDateFrame->hide(); |
2388 | else { | 2388 | else { |
2389 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; | 2389 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; |
2390 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; | 2390 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; |
2391 | int dw = QApplication::desktop()->width(); | 2391 | int dw = QApplication::desktop()->width(); |
2392 | int dh = QApplication::desktop()->height(); | 2392 | int dh = QApplication::desktop()->height(); |
2393 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2393 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2394 | mDateFrame->show(); | 2394 | mDateFrame->show(); |
2395 | } | 2395 | } |
2396 | mDatePickerMode = 2; | 2396 | mDatePickerMode = 2; |
2397 | mMoveIncidence = inc ; | 2397 | mMoveIncidence = inc ; |
2398 | QDate da; | 2398 | QDate da; |
2399 | if ( mMoveIncidence->type() == "Todo" ) { | 2399 | if ( mMoveIncidence->type() == "Todo" ) { |
2400 | Todo * to = (Todo *) mMoveIncidence; | 2400 | Todo * to = (Todo *) mMoveIncidence; |
2401 | if ( to->hasDueDate() ) | 2401 | if ( to->hasDueDate() ) |
2402 | da = to->dtDue().date(); | 2402 | da = to->dtDue().date(); |
2403 | else | 2403 | else |
2404 | da = QDate::currentDate(); | 2404 | da = QDate::currentDate(); |
2405 | } else { | 2405 | } else { |
2406 | da = mMoveIncidence->dtStart().date(); | 2406 | da = mMoveIncidence->dtStart().date(); |
2407 | } | 2407 | } |
2408 | mDatePicker->setDate( da ); | 2408 | mDatePicker->setDate( da ); |
2409 | } | 2409 | } |
2410 | void CalendarView::showDatePicker( ) | 2410 | void CalendarView::showDatePicker( ) |
2411 | { | 2411 | { |
2412 | //qDebug("CalendarView::showDatePicker( ) "); | 2412 | //qDebug("CalendarView::showDatePicker( ) "); |
2413 | if ( mDateFrame->isVisible() ) | 2413 | if ( mDateFrame->isVisible() ) |
2414 | mDateFrame->hide(); | 2414 | mDateFrame->hide(); |
2415 | else { | 2415 | else { |
2416 | int w =mDatePicker->sizeHint().width() ; | 2416 | int w =mDatePicker->sizeHint().width() ; |
2417 | int h = mDatePicker->sizeHint().height() ; | 2417 | int h = mDatePicker->sizeHint().height() ; |
2418 | int dw = QApplication::desktop()->width(); | 2418 | int dw = QApplication::desktop()->width(); |
2419 | int dh = QApplication::desktop()->height(); | 2419 | int dh = QApplication::desktop()->height(); |
2420 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2420 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2421 | mDateFrame->show(); | 2421 | mDateFrame->show(); |
2422 | } | 2422 | } |
2423 | mDatePickerMode = 1; | 2423 | mDatePickerMode = 1; |
2424 | mDatePicker->setDate( mNavigator->selectedDates().first() ); | 2424 | mDatePicker->setDate( mNavigator->selectedDates().first() ); |
2425 | } | 2425 | } |
2426 | 2426 | ||
2427 | void CalendarView::showEventEditor() | 2427 | void CalendarView::showEventEditor() |
2428 | { | 2428 | { |
2429 | #ifdef DESKTOP_VERSION | 2429 | #ifdef DESKTOP_VERSION |
2430 | mEventEditor->show(); | 2430 | mEventEditor->show(); |
2431 | #else | 2431 | #else |
2432 | mEventEditor->showMaximized(); | 2432 | mEventEditor->showMaximized(); |
2433 | #endif | 2433 | #endif |
2434 | } | 2434 | } |
2435 | void CalendarView::showTodoEditor() | 2435 | void CalendarView::showTodoEditor() |
2436 | { | 2436 | { |
2437 | #ifdef DESKTOP_VERSION | 2437 | #ifdef DESKTOP_VERSION |
2438 | mTodoEditor->show(); | 2438 | mTodoEditor->show(); |
2439 | #else | 2439 | #else |
2440 | mTodoEditor->showMaximized(); | 2440 | mTodoEditor->showMaximized(); |
2441 | #endif | 2441 | #endif |
2442 | } | 2442 | } |
2443 | 2443 | ||
2444 | void CalendarView::cloneIncidence() | 2444 | void CalendarView::cloneIncidence() |
2445 | { | 2445 | { |
2446 | Incidence *incidence = currentSelection(); | 2446 | Incidence *incidence = currentSelection(); |
2447 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 2447 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
2448 | if ( incidence ) { | 2448 | if ( incidence ) { |
2449 | cloneIncidence(incidence); | 2449 | cloneIncidence(incidence); |
2450 | } | 2450 | } |
2451 | } | 2451 | } |
2452 | void CalendarView::moveIncidence() | 2452 | void CalendarView::moveIncidence() |
2453 | { | 2453 | { |
2454 | Incidence *incidence = currentSelection(); | 2454 | Incidence *incidence = currentSelection(); |
2455 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 2455 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
2456 | if ( incidence ) { | 2456 | if ( incidence ) { |
2457 | moveIncidence(incidence); | 2457 | moveIncidence(incidence); |
2458 | } | 2458 | } |
2459 | } | 2459 | } |
2460 | void CalendarView::beamIncidence() | 2460 | void CalendarView::beamIncidence() |
2461 | { | 2461 | { |
2462 | Incidence *incidence = currentSelection(); | 2462 | Incidence *incidence = currentSelection(); |
2463 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 2463 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
2464 | if ( incidence ) { | 2464 | if ( incidence ) { |
2465 | beamIncidence(incidence); | 2465 | beamIncidence(incidence); |
2466 | } | 2466 | } |
2467 | } | 2467 | } |
2468 | void CalendarView::toggleCancelIncidence() | 2468 | void CalendarView::toggleCancelIncidence() |
2469 | { | 2469 | { |
2470 | Incidence *incidence = currentSelection(); | 2470 | Incidence *incidence = currentSelection(); |
2471 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 2471 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
2472 | if ( incidence ) { | 2472 | if ( incidence ) { |
2473 | cancelIncidence(incidence); | 2473 | cancelIncidence(incidence); |
2474 | } | 2474 | } |
2475 | } | 2475 | } |
2476 | 2476 | ||
2477 | 2477 | ||
2478 | void CalendarView::cancelIncidence(Incidence * inc ) | 2478 | void CalendarView::cancelIncidence(Incidence * inc ) |
2479 | { | 2479 | { |
2480 | inc->setCancelled( ! inc->cancelled() ); | 2480 | inc->setCancelled( ! inc->cancelled() ); |
2481 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); | 2481 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); |
2482 | updateView(); | 2482 | updateView(); |
2483 | } | 2483 | } |
2484 | void CalendarView::cloneIncidence(Incidence * orgInc ) | 2484 | void CalendarView::cloneIncidence(Incidence * orgInc ) |
2485 | { | 2485 | { |
2486 | Incidence * newInc = orgInc->clone(); | 2486 | Incidence * newInc = orgInc->clone(); |
2487 | newInc->recreate(); | 2487 | newInc->recreate(); |
2488 | 2488 | ||
2489 | if ( newInc->type() == "Todo" ) { | 2489 | if ( newInc->type() == "Todo" ) { |
2490 | Todo* t = (Todo*) newInc; | 2490 | Todo* t = (Todo*) newInc; |
2491 | mTodoEditor->editTodo( t ); | 2491 | mTodoEditor->editTodo( t ); |
2492 | showTodoEditor(); | 2492 | showTodoEditor(); |
2493 | if ( mTodoEditor->exec() ) { | 2493 | if ( mTodoEditor->exec() ) { |
2494 | mCalendar->addTodo( t ); | 2494 | mCalendar->addTodo( t ); |
2495 | updateView(); | 2495 | updateView(); |
2496 | } else { | 2496 | } else { |
2497 | delete t; | 2497 | delete t; |
2498 | } | 2498 | } |
2499 | } | 2499 | } |
2500 | else { | 2500 | else { |
2501 | Event* e = (Event*) newInc; | 2501 | Event* e = (Event*) newInc; |
2502 | mEventEditor->editEvent( e ); | 2502 | mEventEditor->editEvent( e ); |
2503 | showEventEditor(); | 2503 | showEventEditor(); |
2504 | if ( mEventEditor->exec() ) { | 2504 | if ( mEventEditor->exec() ) { |
2505 | mCalendar->addEvent( e ); | 2505 | mCalendar->addEvent( e ); |
2506 | updateView(); | 2506 | updateView(); |
2507 | } else { | 2507 | } else { |
2508 | delete e; | 2508 | delete e; |
2509 | } | 2509 | } |
2510 | } | 2510 | } |
2511 | } | 2511 | } |
2512 | 2512 | ||
2513 | void CalendarView::newEvent() | 2513 | void CalendarView::newEvent() |
2514 | { | 2514 | { |
2515 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. | 2515 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. |
2516 | KOAgendaView *aView = mViewManager->agendaView(); | 2516 | KOAgendaView *aView = mViewManager->agendaView(); |
2517 | if (aView) { | 2517 | if (aView) { |
2518 | if (aView->selectionStart().isValid()) { | 2518 | if (aView->selectionStart().isValid()) { |
2519 | if (aView->selectedIsAllDay()) { | 2519 | if (aView->selectedIsAllDay()) { |
2520 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); | 2520 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); |
2521 | } else { | 2521 | } else { |
2522 | newEvent(aView->selectionStart(),aView->selectionEnd()); | 2522 | newEvent(aView->selectionStart(),aView->selectionEnd()); |
2523 | } | 2523 | } |
2524 | return; | 2524 | return; |
2525 | } | 2525 | } |
2526 | } | 2526 | } |
2527 | 2527 | ||
2528 | QDate date = mNavigator->selectedDates().first(); | 2528 | QDate date = mNavigator->selectedDates().first(); |
2529 | QDateTime current = QDateTime::currentDateTime(); | 2529 | QDateTime current = QDateTime::currentDateTime(); |
2530 | if ( date <= current.date() ) { | 2530 | if ( date <= current.date() ) { |
2531 | int hour = current.time().hour() +1; | 2531 | int hour = current.time().hour() +1; |
2532 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), | 2532 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), |
2533 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2533 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2534 | } else | 2534 | } else |
2535 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), | 2535 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), |
2536 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + | 2536 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + |
2537 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2537 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2538 | } | 2538 | } |
2539 | 2539 | ||
2540 | void CalendarView::newEvent(QDateTime fh) | 2540 | void CalendarView::newEvent(QDateTime fh) |
2541 | { | 2541 | { |
2542 | newEvent(fh, | 2542 | newEvent(fh, |
2543 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); | 2543 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); |
2544 | } | 2544 | } |
2545 | 2545 | ||
2546 | void CalendarView::newEvent(QDate dt) | 2546 | void CalendarView::newEvent(QDate dt) |
2547 | { | 2547 | { |
2548 | newEvent(QDateTime(dt, QTime(0,0,0)), | 2548 | newEvent(QDateTime(dt, QTime(0,0,0)), |
2549 | QDateTime(dt, QTime(0,0,0)), true); | 2549 | QDateTime(dt, QTime(0,0,0)), true); |
2550 | } | 2550 | } |
2551 | 2551 | ||
2552 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) | 2552 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) |
2553 | { | 2553 | { |
2554 | 2554 | ||
2555 | mEventEditor->newEvent(fromHint,toHint,allDay); | 2555 | mEventEditor->newEvent(fromHint,toHint,allDay); |
2556 | if ( mFilterView->filtersEnabled() ) { | 2556 | if ( mFilterView->filtersEnabled() ) { |
2557 | CalFilter *filter = mFilterView->selectedFilter(); | 2557 | CalFilter *filter = mFilterView->selectedFilter(); |
2558 | if (filter && filter->showCategories()) { | 2558 | if (filter && filter->showCategories()) { |
2559 | mEventEditor->setCategories(filter->categoryList().join(",") ); | 2559 | mEventEditor->setCategories(filter->categoryList().join(",") ); |
2560 | } | 2560 | } |
2561 | if ( filter ) | 2561 | if ( filter ) |
2562 | mEventEditor->setSecrecy( filter->getSecrecy() ); | 2562 | mEventEditor->setSecrecy( filter->getSecrecy() ); |
2563 | } | 2563 | } |
2564 | showEventEditor(); | 2564 | showEventEditor(); |
2565 | } | 2565 | } |
2566 | void CalendarView::todoAdded(Todo * t) | 2566 | void CalendarView::todoAdded(Todo * t) |
2567 | { | 2567 | { |
2568 | 2568 | ||
2569 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); | 2569 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); |
2570 | updateTodoViews(); | 2570 | updateTodoViews(); |
2571 | } | 2571 | } |
2572 | void CalendarView::todoChanged(Todo * t) | 2572 | void CalendarView::todoChanged(Todo * t) |
2573 | { | 2573 | { |
2574 | emit todoModified( t, 4 ); | 2574 | emit todoModified( t, 4 ); |
2575 | // updateTodoViews(); | 2575 | // updateTodoViews(); |
2576 | } | 2576 | } |
2577 | void CalendarView::todoToBeDeleted(Todo *) | 2577 | void CalendarView::todoToBeDeleted(Todo *) |
2578 | { | 2578 | { |
2579 | //qDebug("todoToBeDeleted(Todo *) "); | 2579 | //qDebug("todoToBeDeleted(Todo *) "); |
2580 | updateTodoViews(); | 2580 | updateTodoViews(); |
2581 | } | 2581 | } |
2582 | void CalendarView::todoDeleted() | 2582 | void CalendarView::todoDeleted() |
2583 | { | 2583 | { |
2584 | //qDebug(" todoDeleted()"); | 2584 | //qDebug(" todoDeleted()"); |
2585 | updateTodoViews(); | 2585 | updateTodoViews(); |
2586 | } | 2586 | } |
2587 | 2587 | ||
2588 | 2588 | ||
2589 | 2589 | ||
2590 | void CalendarView::newTodo() | 2590 | void CalendarView::newTodo() |
2591 | { | 2591 | { |
2592 | 2592 | ||
2593 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); | 2593 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); |
2594 | if ( mFilterView->filtersEnabled() ) { | 2594 | if ( mFilterView->filtersEnabled() ) { |
2595 | CalFilter *filter = mFilterView->selectedFilter(); | 2595 | CalFilter *filter = mFilterView->selectedFilter(); |
2596 | if (filter && filter->showCategories()) { | 2596 | if (filter && filter->showCategories()) { |
2597 | mTodoEditor->setCategories(filter->categoryList().join(",") ); | 2597 | mTodoEditor->setCategories(filter->categoryList().join(",") ); |
2598 | } | 2598 | } |
2599 | if ( filter ) | 2599 | if ( filter ) |
2600 | mTodoEditor->setSecrecy( filter->getSecrecy() ); | 2600 | mTodoEditor->setSecrecy( filter->getSecrecy() ); |
2601 | } | 2601 | } |
2602 | showTodoEditor(); | 2602 | showTodoEditor(); |
2603 | } | 2603 | } |
2604 | 2604 | ||
2605 | void CalendarView::newSubTodo() | 2605 | void CalendarView::newSubTodo() |
2606 | { | 2606 | { |
2607 | Todo *todo = selectedTodo(); | 2607 | Todo *todo = selectedTodo(); |
2608 | if ( todo ) newSubTodo( todo ); | 2608 | if ( todo ) newSubTodo( todo ); |
2609 | } | 2609 | } |
2610 | 2610 | ||
2611 | void CalendarView::newSubTodo(Todo *parentEvent) | 2611 | void CalendarView::newSubTodo(Todo *parentEvent) |
2612 | { | 2612 | { |
2613 | 2613 | ||
2614 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); | 2614 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); |
2615 | showTodoEditor(); | 2615 | showTodoEditor(); |
2616 | } | 2616 | } |
2617 | 2617 | ||
2618 | void CalendarView::newFloatingEvent() | 2618 | void CalendarView::newFloatingEvent() |
2619 | { | 2619 | { |
2620 | DateList tmpList = mNavigator->selectedDates(); | 2620 | DateList tmpList = mNavigator->selectedDates(); |
2621 | QDate date = tmpList.first(); | 2621 | QDate date = tmpList.first(); |
2622 | 2622 | ||
2623 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), | 2623 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), |
2624 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); | 2624 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); |
2625 | } | 2625 | } |
2626 | 2626 | ||
2627 | 2627 | ||
2628 | void CalendarView::editEvent( Event *event ) | 2628 | void CalendarView::editEvent( Event *event ) |
2629 | { | 2629 | { |
2630 | 2630 | ||
2631 | if ( !event ) return; | 2631 | if ( !event ) return; |
2632 | if ( event->isReadOnly() ) { | 2632 | if ( event->isReadOnly() ) { |
2633 | showEvent( event ); | 2633 | showEvent( event ); |
2634 | return; | 2634 | return; |
2635 | } | 2635 | } |
2636 | mEventEditor->editEvent( event , mFlagEditDescription); | 2636 | mEventEditor->editEvent( event , mFlagEditDescription); |
2637 | showEventEditor(); | 2637 | showEventEditor(); |
2638 | } | 2638 | } |
2639 | void CalendarView::editJournal( Journal *jour ) | 2639 | void CalendarView::editJournal( Journal *jour ) |
2640 | { | 2640 | { |
2641 | if ( !jour ) return; | 2641 | if ( !jour ) return; |
2642 | mDialogManager->hideSearchDialog(); | 2642 | mDialogManager->hideSearchDialog(); |
2643 | mViewManager->showJournalView(); | 2643 | mViewManager->showJournalView(); |
2644 | mNavigator->slotDaySelect( jour->dtStart().date() ); | 2644 | mNavigator->slotDaySelect( jour->dtStart().date() ); |
2645 | } | 2645 | } |
2646 | void CalendarView::editTodo( Todo *todo ) | 2646 | void CalendarView::editTodo( Todo *todo ) |
2647 | { | 2647 | { |
2648 | if ( !todo ) return; | 2648 | if ( !todo ) return; |
2649 | 2649 | ||
2650 | if ( todo->isReadOnly() ) { | 2650 | if ( todo->isReadOnly() ) { |
2651 | showTodo( todo ); | 2651 | showTodo( todo ); |
2652 | return; | 2652 | return; |
2653 | } | 2653 | } |
2654 | mTodoEditor->editTodo( todo ,mFlagEditDescription); | 2654 | mTodoEditor->editTodo( todo ,mFlagEditDescription); |
2655 | showTodoEditor(); | 2655 | showTodoEditor(); |
2656 | 2656 | ||
2657 | } | 2657 | } |
2658 | 2658 | ||
2659 | KOEventViewerDialog* CalendarView::getEventViewerDialog() | 2659 | KOEventViewerDialog* CalendarView::getEventViewerDialog() |
2660 | { | 2660 | { |
2661 | if ( !mEventViewerDialog ) { | 2661 | if ( !mEventViewerDialog ) { |
2662 | mEventViewerDialog = new KOEventViewerDialog(this); | 2662 | mEventViewerDialog = new KOEventViewerDialog(this); |
2663 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); | 2663 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); |
2664 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); | 2664 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); |
2665 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), | 2665 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), |
2666 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); | 2666 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); |
2667 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), | 2667 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), |
2668 | viewManager(), SLOT( showAgendaView( bool ) ) ); | 2668 | viewManager(), SLOT( showAgendaView( bool ) ) ); |
2669 | mEventViewerDialog->resize( 640, 480 ); | 2669 | mEventViewerDialog->resize( 640, 480 ); |
2670 | 2670 | ||
2671 | } | 2671 | } |
2672 | return mEventViewerDialog; | 2672 | return mEventViewerDialog; |
2673 | } | 2673 | } |
2674 | void CalendarView::showEvent(Event *event) | 2674 | void CalendarView::showEvent(Event *event) |
2675 | { | 2675 | { |
2676 | getEventViewerDialog()->setEvent(event); | 2676 | getEventViewerDialog()->setEvent(event); |
2677 | getEventViewerDialog()->showMe(); | 2677 | getEventViewerDialog()->showMe(); |
2678 | } | 2678 | } |
2679 | 2679 | ||
2680 | void CalendarView::showTodo(Todo *event) | 2680 | void CalendarView::showTodo(Todo *event) |
2681 | { | 2681 | { |
2682 | getEventViewerDialog()->setTodo(event); | 2682 | getEventViewerDialog()->setTodo(event); |
2683 | getEventViewerDialog()->showMe(); | 2683 | getEventViewerDialog()->showMe(); |
2684 | } | 2684 | } |
2685 | void CalendarView::showJournal( Journal *jour ) | 2685 | void CalendarView::showJournal( Journal *jour ) |
2686 | { | 2686 | { |
2687 | getEventViewerDialog()->setJournal(jour); | 2687 | getEventViewerDialog()->setJournal(jour); |
2688 | getEventViewerDialog()->showMe(); | 2688 | getEventViewerDialog()->showMe(); |
2689 | 2689 | ||
2690 | } | 2690 | } |
2691 | // void CalendarView::todoModified (Todo *event, int changed) | 2691 | // void CalendarView::todoModified (Todo *event, int changed) |
2692 | // { | 2692 | // { |
2693 | // // if (mDialogList.find (event) != mDialogList.end ()) { | 2693 | // // if (mDialogList.find (event) != mDialogList.end ()) { |
2694 | // // kdDebug() << "Todo modified and open" << endl; | 2694 | // // kdDebug() << "Todo modified and open" << endl; |
2695 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; | 2695 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; |
2696 | // // temp->modified (changed); | 2696 | // // temp->modified (changed); |
2697 | 2697 | ||
2698 | // // } | 2698 | // // } |
2699 | 2699 | ||
2700 | // mViewManager->updateView(); | 2700 | // mViewManager->updateView(); |
2701 | // } | 2701 | // } |
2702 | 2702 | ||
2703 | void CalendarView::appointment_show() | 2703 | void CalendarView::appointment_show() |
2704 | { | 2704 | { |
2705 | Event *anEvent = 0; | 2705 | Event *anEvent = 0; |
2706 | 2706 | ||
2707 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2707 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2708 | 2708 | ||
2709 | if (mViewManager->currentView()->isEventView()) { | 2709 | if (mViewManager->currentView()->isEventView()) { |
2710 | if ( incidence && incidence->type() == "Event" ) { | 2710 | if ( incidence && incidence->type() == "Event" ) { |
2711 | anEvent = static_cast<Event *>(incidence); | 2711 | anEvent = static_cast<Event *>(incidence); |
2712 | } | 2712 | } |
2713 | } | 2713 | } |
2714 | 2714 | ||
2715 | if (!anEvent) { | 2715 | if (!anEvent) { |
2716 | KNotifyClient::beep(); | 2716 | KNotifyClient::beep(); |
2717 | return; | 2717 | return; |
2718 | } | 2718 | } |
2719 | 2719 | ||
2720 | showEvent(anEvent); | 2720 | showEvent(anEvent); |
2721 | } | 2721 | } |
2722 | 2722 | ||
2723 | void CalendarView::appointment_edit() | 2723 | void CalendarView::appointment_edit() |
2724 | { | 2724 | { |
2725 | Event *anEvent = 0; | 2725 | Event *anEvent = 0; |
2726 | 2726 | ||
2727 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2727 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2728 | 2728 | ||
2729 | if (mViewManager->currentView()->isEventView()) { | 2729 | if (mViewManager->currentView()->isEventView()) { |
2730 | if ( incidence && incidence->type() == "Event" ) { | 2730 | if ( incidence && incidence->type() == "Event" ) { |
2731 | anEvent = static_cast<Event *>(incidence); | 2731 | anEvent = static_cast<Event *>(incidence); |
2732 | } | 2732 | } |
2733 | } | 2733 | } |
2734 | 2734 | ||
2735 | if (!anEvent) { | 2735 | if (!anEvent) { |
2736 | KNotifyClient::beep(); | 2736 | KNotifyClient::beep(); |
2737 | return; | 2737 | return; |
2738 | } | 2738 | } |
2739 | 2739 | ||
2740 | editEvent(anEvent); | 2740 | editEvent(anEvent); |
2741 | } | 2741 | } |
2742 | 2742 | ||
2743 | void CalendarView::appointment_delete() | 2743 | void CalendarView::appointment_delete() |
2744 | { | 2744 | { |
2745 | Event *anEvent = 0; | 2745 | Event *anEvent = 0; |
2746 | 2746 | ||
2747 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2747 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2748 | 2748 | ||
2749 | if (mViewManager->currentView()->isEventView()) { | 2749 | if (mViewManager->currentView()->isEventView()) { |
2750 | if ( incidence && incidence->type() == "Event" ) { | 2750 | if ( incidence && incidence->type() == "Event" ) { |
2751 | anEvent = static_cast<Event *>(incidence); | 2751 | anEvent = static_cast<Event *>(incidence); |
2752 | } | 2752 | } |
2753 | } | 2753 | } |
2754 | 2754 | ||
2755 | if (!anEvent) { | 2755 | if (!anEvent) { |
2756 | KNotifyClient::beep(); | 2756 | KNotifyClient::beep(); |
2757 | return; | 2757 | return; |
2758 | } | 2758 | } |
2759 | 2759 | ||
2760 | deleteEvent(anEvent); | 2760 | deleteEvent(anEvent); |
2761 | } | 2761 | } |
2762 | 2762 | ||
2763 | void CalendarView::todo_resub( Todo * parent, Todo * sub ) | 2763 | void CalendarView::todo_resub( Todo * parent, Todo * sub ) |
2764 | { | 2764 | { |
2765 | if (!sub) return; | 2765 | if (!sub) return; |
2766 | if (!parent) return; | 2766 | if (!parent) return; |
2767 | if ( sub->relatedTo() ) | 2767 | if ( sub->relatedTo() ) |
2768 | sub->relatedTo()->removeRelation(sub); | 2768 | sub->relatedTo()->removeRelation(sub); |
2769 | sub->setRelatedTo(parent); | 2769 | sub->setRelatedTo(parent); |
2770 | sub->setRelatedToUid(parent->uid()); | 2770 | sub->setRelatedToUid(parent->uid()); |
2771 | parent->addRelation(sub); | 2771 | parent->addRelation(sub); |
2772 | sub->updated(); | 2772 | sub->updated(); |
2773 | parent->updated(); | 2773 | parent->updated(); |
2774 | setModified(true); | 2774 | setModified(true); |
2775 | updateView(); | 2775 | updateView(); |
2776 | } | 2776 | } |
2777 | void CalendarView::todo_unsub(Todo *anTodo ) | 2777 | void CalendarView::todo_unsub(Todo *anTodo ) |
2778 | { | 2778 | { |
2779 | // Todo *anTodo = selectedTodo(); | 2779 | // Todo *anTodo = selectedTodo(); |
2780 | if (!anTodo) return; | 2780 | if (!anTodo) return; |
2781 | if (!anTodo->relatedTo()) return; | 2781 | if (!anTodo->relatedTo()) return; |
2782 | anTodo->relatedTo()->removeRelation(anTodo); | 2782 | anTodo->relatedTo()->removeRelation(anTodo); |
2783 | anTodo->setRelatedTo(0); | 2783 | anTodo->setRelatedTo(0); |
2784 | anTodo->updated(); | 2784 | anTodo->updated(); |
2785 | anTodo->setRelatedToUid(""); | 2785 | anTodo->setRelatedToUid(""); |
2786 | setModified(true); | 2786 | setModified(true); |
2787 | updateView(); | 2787 | updateView(); |
2788 | } | 2788 | } |
2789 | 2789 | ||
2790 | void CalendarView::deleteTodo(Todo *todo) | 2790 | void CalendarView::deleteTodo(Todo *todo) |
2791 | { | 2791 | { |
2792 | if (!todo) { | 2792 | if (!todo) { |
2793 | KNotifyClient::beep(); | 2793 | KNotifyClient::beep(); |
2794 | return; | 2794 | return; |
2795 | } | 2795 | } |
2796 | if (KOPrefs::instance()->mConfirm) { | 2796 | if (KOPrefs::instance()->mConfirm) { |
2797 | switch (msgItemDelete()) { | 2797 | switch (msgItemDelete()) { |
2798 | case KMessageBox::Continue: // OK | 2798 | case KMessageBox::Continue: // OK |
2799 | if (!todo->relations().isEmpty()) { | 2799 | if (!todo->relations().isEmpty()) { |
2800 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2800 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2801 | i18n("Delete To-Do")); | 2801 | i18n("Delete To-Do")); |
2802 | } else { | 2802 | } else { |
2803 | checkExternalId( todo ); | 2803 | checkExternalId( todo ); |
2804 | calendar()->deleteTodo(todo); | 2804 | calendar()->deleteTodo(todo); |
2805 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2805 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2806 | updateView(); | 2806 | updateView(); |
2807 | } | 2807 | } |
2808 | break; | 2808 | break; |
2809 | } // switch | 2809 | } // switch |
2810 | } else { | 2810 | } else { |
2811 | if (!todo->relations().isEmpty()) { | 2811 | if (!todo->relations().isEmpty()) { |
2812 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2812 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2813 | i18n("Delete To-Do")); | 2813 | i18n("Delete To-Do")); |
2814 | } else { | 2814 | } else { |
2815 | checkExternalId( todo ); | 2815 | checkExternalId( todo ); |
2816 | mCalendar->deleteTodo(todo); | 2816 | mCalendar->deleteTodo(todo); |
2817 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2817 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2818 | updateView(); | 2818 | updateView(); |
2819 | } | 2819 | } |
2820 | } | 2820 | } |
2821 | emit updateSearchDialog(); | 2821 | emit updateSearchDialog(); |
2822 | } | 2822 | } |
2823 | void CalendarView::deleteJournal(Journal *jour) | 2823 | void CalendarView::deleteJournal(Journal *jour) |
2824 | { | 2824 | { |
2825 | if (!jour) { | 2825 | if (!jour) { |
2826 | KNotifyClient::beep(); | 2826 | KNotifyClient::beep(); |
2827 | return; | 2827 | return; |
2828 | } | 2828 | } |
2829 | if (KOPrefs::instance()->mConfirm) { | 2829 | if (KOPrefs::instance()->mConfirm) { |
2830 | switch (msgItemDelete()) { | 2830 | switch (msgItemDelete()) { |
2831 | case KMessageBox::Continue: // OK | 2831 | case KMessageBox::Continue: // OK |
2832 | calendar()->deleteJournal(jour); | 2832 | calendar()->deleteJournal(jour); |
2833 | updateView(); | 2833 | updateView(); |
2834 | break; | 2834 | break; |
2835 | } // switch | 2835 | } // switch |
2836 | } else { | 2836 | } else { |
2837 | calendar()->deleteJournal(jour);; | 2837 | calendar()->deleteJournal(jour);; |
2838 | updateView(); | 2838 | updateView(); |
2839 | } | 2839 | } |
2840 | emit updateSearchDialog(); | 2840 | emit updateSearchDialog(); |
2841 | } | 2841 | } |
2842 | 2842 | ||
2843 | void CalendarView::deleteEvent(Event *anEvent) | 2843 | void CalendarView::deleteEvent(Event *anEvent) |
2844 | { | 2844 | { |
2845 | if (!anEvent) { | 2845 | if (!anEvent) { |
2846 | KNotifyClient::beep(); | 2846 | KNotifyClient::beep(); |
2847 | return; | 2847 | return; |
2848 | } | 2848 | } |
2849 | 2849 | ||
2850 | if (anEvent->recurrence()->doesRecur()) { | 2850 | if (anEvent->recurrence()->doesRecur()) { |
2851 | QDate itemDate = mViewManager->currentSelectionDate(); | 2851 | QDate itemDate = mViewManager->currentSelectionDate(); |
2852 | int km; | 2852 | int km; |
2853 | if (!itemDate.isValid()) { | 2853 | if (!itemDate.isValid()) { |
2854 | //kdDebug() << "Date Not Valid" << endl; | 2854 | //kdDebug() << "Date Not Valid" << endl; |
2855 | if (KOPrefs::instance()->mConfirm) { | 2855 | if (KOPrefs::instance()->mConfirm) { |
2856 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2856 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2857 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), | 2857 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), |
2858 | i18n("KO/Pi Confirmation"),i18n("Delete All")); | 2858 | i18n("KO/Pi Confirmation"),i18n("Delete All")); |
2859 | if ( km == KMessageBox::Continue ) | 2859 | if ( km == KMessageBox::Continue ) |
2860 | km = KMessageBox::No; // No = all below | 2860 | km = KMessageBox::No; // No = all below |
2861 | } else | 2861 | } else |
2862 | km = KMessageBox::No; | 2862 | km = KMessageBox::No; |
2863 | } else { | 2863 | } else { |
2864 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + | 2864 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + |
2865 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ | 2865 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ |
2866 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), | 2866 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), |
2867 | i18n("KO/Pi Confirmation"),i18n("Current"), | 2867 | i18n("KO/Pi Confirmation"),i18n("Current"), |
2868 | i18n("All")); | 2868 | i18n("All")); |
2869 | } | 2869 | } |
2870 | switch(km) { | 2870 | switch(km) { |
2871 | 2871 | ||
2872 | case KMessageBox::No: // Continue // all | 2872 | case KMessageBox::No: // Continue // all |
2873 | //qDebug("KMessageBox::No "); | 2873 | //qDebug("KMessageBox::No "); |
2874 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2874 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2875 | schedule(Scheduler::Cancel,anEvent); | 2875 | schedule(Scheduler::Cancel,anEvent); |
2876 | 2876 | ||
2877 | checkExternalId( anEvent); | 2877 | checkExternalId( anEvent); |
2878 | mCalendar->deleteEvent(anEvent); | 2878 | mCalendar->deleteEvent(anEvent); |
2879 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); | 2879 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); |
2880 | break; | 2880 | break; |
2881 | 2881 | ||
2882 | // Disabled because it does not work | 2882 | // Disabled because it does not work |
2883 | //#if 0 | 2883 | //#if 0 |
2884 | case KMessageBox::Yes: // just this one | 2884 | case KMessageBox::Yes: // just this one |
2885 | //QDate qd = mNavigator->selectedDates().first(); | 2885 | //QDate qd = mNavigator->selectedDates().first(); |
2886 | //if (!qd.isValid()) { | 2886 | //if (!qd.isValid()) { |
2887 | // kdDebug() << "no date selected, or invalid date" << endl; | 2887 | // kdDebug() << "no date selected, or invalid date" << endl; |
2888 | // KNotifyClient::beep(); | 2888 | // KNotifyClient::beep(); |
2889 | // return; | 2889 | // return; |
2890 | //} | 2890 | //} |
2891 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); | 2891 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); |
2892 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { | 2892 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { |
2893 | anEvent->addExDate(itemDate); | 2893 | anEvent->addExDate(itemDate); |
2894 | int duration = anEvent->recurrence()->duration(); | 2894 | int duration = anEvent->recurrence()->duration(); |
2895 | if ( duration > 0 ) { | 2895 | if ( duration > 0 ) { |
2896 | anEvent->recurrence()->setDuration( duration - 1 ); | 2896 | anEvent->recurrence()->setDuration( duration - 1 ); |
2897 | } | 2897 | } |
2898 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); | 2898 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); |
2899 | } | 2899 | } |
2900 | break; | 2900 | break; |
2901 | //#endif | 2901 | //#endif |
2902 | } // switch | 2902 | } // switch |
2903 | } else { | 2903 | } else { |
2904 | if (KOPrefs::instance()->mConfirm) { | 2904 | if (KOPrefs::instance()->mConfirm) { |
2905 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2905 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2906 | i18n("\nAre you sure you want\nto delete this event?"), | 2906 | i18n("\nAre you sure you want\nto delete this event?"), |
2907 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { | 2907 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { |
2908 | case KMessageBox::Continue: // OK | 2908 | case KMessageBox::Continue: // OK |
2909 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2909 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2910 | schedule(Scheduler::Cancel,anEvent); | 2910 | schedule(Scheduler::Cancel,anEvent); |
2911 | checkExternalId( anEvent); | 2911 | checkExternalId( anEvent); |
2912 | mCalendar->deleteEvent(anEvent); | 2912 | mCalendar->deleteEvent(anEvent); |
2913 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2913 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2914 | break; | 2914 | break; |
2915 | } // switch | 2915 | } // switch |
2916 | } else { | 2916 | } else { |
2917 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2917 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2918 | schedule(Scheduler::Cancel,anEvent); | 2918 | schedule(Scheduler::Cancel,anEvent); |
2919 | checkExternalId( anEvent); | 2919 | checkExternalId( anEvent); |
2920 | mCalendar->deleteEvent(anEvent); | 2920 | mCalendar->deleteEvent(anEvent); |
2921 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2921 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2922 | } | 2922 | } |
2923 | } // if-else | 2923 | } // if-else |
2924 | emit updateSearchDialog(); | 2924 | emit updateSearchDialog(); |
2925 | } | 2925 | } |
2926 | 2926 | ||
2927 | bool CalendarView::deleteEvent(const QString &uid) | 2927 | bool CalendarView::deleteEvent(const QString &uid) |
2928 | { | 2928 | { |
2929 | Event *ev = mCalendar->event(uid); | 2929 | Event *ev = mCalendar->event(uid); |
2930 | if (ev) { | 2930 | if (ev) { |
2931 | deleteEvent(ev); | 2931 | deleteEvent(ev); |
2932 | return true; | 2932 | return true; |
2933 | } else { | 2933 | } else { |
2934 | return false; | 2934 | return false; |
2935 | } | 2935 | } |
2936 | } | 2936 | } |
2937 | 2937 | ||
2938 | /*****************************************************************************/ | 2938 | /*****************************************************************************/ |
2939 | 2939 | ||
2940 | void CalendarView::action_mail() | 2940 | void CalendarView::action_mail() |
2941 | { | 2941 | { |
2942 | #ifndef KORG_NOMAIL | 2942 | #ifndef KORG_NOMAIL |
2943 | KOMailClient mailClient; | 2943 | KOMailClient mailClient; |
2944 | 2944 | ||
2945 | Incidence *incidence = currentSelection(); | 2945 | Incidence *incidence = currentSelection(); |
2946 | 2946 | ||
2947 | if (!incidence) { | 2947 | if (!incidence) { |
2948 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2948 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2949 | return; | 2949 | return; |
2950 | } | 2950 | } |
2951 | if(incidence->attendeeCount() == 0 ) { | 2951 | if(incidence->attendeeCount() == 0 ) { |
2952 | KMessageBox::sorry(this, | 2952 | KMessageBox::sorry(this, |
2953 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2953 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2954 | return; | 2954 | return; |
2955 | } | 2955 | } |
2956 | 2956 | ||
2957 | CalendarLocal cal_tmp; | 2957 | CalendarLocal cal_tmp; |
2958 | Event *event = 0; | 2958 | Event *event = 0; |
2959 | Event *ev = 0; | 2959 | Event *ev = 0; |
2960 | if ( incidence && incidence->type() == "Event" ) { | 2960 | if ( incidence && incidence->type() == "Event" ) { |
2961 | event = static_cast<Event *>(incidence); | 2961 | event = static_cast<Event *>(incidence); |
2962 | ev = new Event(*event); | 2962 | ev = new Event(*event); |
2963 | cal_tmp.addEvent(ev); | 2963 | cal_tmp.addEvent(ev); |
2964 | } | 2964 | } |
2965 | ICalFormat mForm(); | 2965 | ICalFormat mForm(); |
2966 | QString attachment = mForm.toString( &cal_tmp ); | 2966 | QString attachment = mForm.toString( &cal_tmp ); |
2967 | if (ev) delete(ev); | 2967 | if (ev) delete(ev); |
2968 | 2968 | ||
2969 | mailClient.mailAttendees(currentSelection(), attachment); | 2969 | mailClient.mailAttendees(currentSelection(), attachment); |
2970 | 2970 | ||
2971 | #endif | 2971 | #endif |
2972 | 2972 | ||
2973 | #if 0 | 2973 | #if 0 |
2974 | Event *anEvent = 0; | 2974 | Event *anEvent = 0; |
2975 | if (mViewManager->currentView()->isEventView()) { | 2975 | if (mViewManager->currentView()->isEventView()) { |
2976 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); | 2976 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); |
2977 | } | 2977 | } |
2978 | 2978 | ||
2979 | if (!anEvent) { | 2979 | if (!anEvent) { |
2980 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2980 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2981 | return; | 2981 | return; |
2982 | } | 2982 | } |
2983 | if(anEvent->attendeeCount() == 0 ) { | 2983 | if(anEvent->attendeeCount() == 0 ) { |
2984 | KMessageBox::sorry(this, | 2984 | KMessageBox::sorry(this, |
2985 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2985 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2986 | return; | 2986 | return; |
2987 | } | 2987 | } |
2988 | 2988 | ||
2989 | mailobject.emailEvent(anEvent); | 2989 | mailobject.emailEvent(anEvent); |
2990 | #endif | 2990 | #endif |
2991 | } | 2991 | } |
2992 | 2992 | ||
2993 | 2993 | ||
2994 | void CalendarView::schedule_publish(Incidence *incidence) | 2994 | void CalendarView::schedule_publish(Incidence *incidence) |
2995 | { | 2995 | { |
2996 | Event *event = 0; | 2996 | Event *event = 0; |
2997 | Todo *todo = 0; | 2997 | Todo *todo = 0; |
2998 | 2998 | ||
2999 | if (incidence == 0) { | 2999 | if (incidence == 0) { |
3000 | incidence = mViewManager->currentView()->selectedIncidences().first(); | 3000 | incidence = mViewManager->currentView()->selectedIncidences().first(); |
3001 | if (incidence == 0) { | 3001 | if (incidence == 0) { |
3002 | incidence = mTodoList->selectedIncidences().first(); | 3002 | incidence = mTodoList->selectedIncidences().first(); |
3003 | } | 3003 | } |
3004 | } | 3004 | } |
3005 | if ( incidence && incidence->type() == "Event" ) { | 3005 | if ( incidence && incidence->type() == "Event" ) { |
3006 | event = static_cast<Event *>(incidence); | 3006 | event = static_cast<Event *>(incidence); |
3007 | } else { | 3007 | } else { |
3008 | if ( incidence && incidence->type() == "Todo" ) { | 3008 | if ( incidence && incidence->type() == "Todo" ) { |
3009 | todo = static_cast<Todo *>(incidence); | 3009 | todo = static_cast<Todo *>(incidence); |
3010 | } | 3010 | } |
3011 | } | 3011 | } |
3012 | 3012 | ||
3013 | if (!event && !todo) { | 3013 | if (!event && !todo) { |
3014 | KMessageBox::sorry(this,i18n("No event selected.")); | 3014 | KMessageBox::sorry(this,i18n("No event selected.")); |
3015 | return; | 3015 | return; |
3016 | } | 3016 | } |
3017 | 3017 | ||
3018 | PublishDialog *publishdlg = new PublishDialog(); | 3018 | PublishDialog *publishdlg = new PublishDialog(); |
3019 | if (incidence->attendeeCount()>0) { | 3019 | if (incidence->attendeeCount()>0) { |
3020 | QPtrList<Attendee> attendees = incidence->attendees(); | 3020 | QPtrList<Attendee> attendees = incidence->attendees(); |
3021 | attendees.first(); | 3021 | attendees.first(); |
3022 | while ( attendees.current()!=0 ) { | 3022 | while ( attendees.current()!=0 ) { |
3023 | publishdlg->addAttendee(attendees.current()); | 3023 | publishdlg->addAttendee(attendees.current()); |
3024 | attendees.next(); | 3024 | attendees.next(); |
3025 | } | 3025 | } |
3026 | } | 3026 | } |
3027 | bool send = true; | 3027 | bool send = true; |
3028 | if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { | 3028 | if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { |
3029 | if ( publishdlg->exec() != QDialog::Accepted ) | 3029 | if ( publishdlg->exec() != QDialog::Accepted ) |
3030 | send = false; | 3030 | send = false; |
3031 | } | 3031 | } |
3032 | if ( send ) { | 3032 | if ( send ) { |
3033 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 3033 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
3034 | if ( event ) { | 3034 | if ( event ) { |
3035 | Event *ev = new Event(*event); | 3035 | Event *ev = new Event(*event); |
3036 | ev->registerObserver(0); | 3036 | ev->registerObserver(0); |
3037 | ev->clearAttendees(); | 3037 | ev->clearAttendees(); |
3038 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { | 3038 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { |
3039 | delete(ev); | 3039 | delete(ev); |
3040 | } | 3040 | } |
3041 | } else { | 3041 | } else { |
3042 | if ( todo ) { | 3042 | if ( todo ) { |
3043 | Todo *ev = new Todo(*todo); | 3043 | Todo *ev = new Todo(*todo); |
3044 | ev->registerObserver(0); | 3044 | ev->registerObserver(0); |
3045 | ev->clearAttendees(); | 3045 | ev->clearAttendees(); |
3046 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { | 3046 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { |
3047 | delete(ev); | 3047 | delete(ev); |
3048 | } | 3048 | } |
3049 | } | 3049 | } |
3050 | } | 3050 | } |
3051 | } | 3051 | } |
3052 | delete publishdlg; | 3052 | delete publishdlg; |
3053 | } | 3053 | } |
3054 | 3054 | ||
3055 | void CalendarView::schedule_request(Incidence *incidence) | 3055 | void CalendarView::schedule_request(Incidence *incidence) |
3056 | { | 3056 | { |
3057 | schedule(Scheduler::Request,incidence); | 3057 | schedule(Scheduler::Request,incidence); |
3058 | } | 3058 | } |
3059 | 3059 | ||
3060 | void CalendarView::schedule_refresh(Incidence *incidence) | 3060 | void CalendarView::schedule_refresh(Incidence *incidence) |
3061 | { | 3061 | { |
3062 | schedule(Scheduler::Refresh,incidence); | 3062 | schedule(Scheduler::Refresh,incidence); |
3063 | } | 3063 | } |
3064 | 3064 | ||
3065 | void CalendarView::schedule_cancel(Incidence *incidence) | 3065 | void CalendarView::schedule_cancel(Incidence *incidence) |
3066 | { | 3066 | { |
3067 | schedule(Scheduler::Cancel,incidence); | 3067 | schedule(Scheduler::Cancel,incidence); |
3068 | } | 3068 | } |
3069 | 3069 | ||
3070 | void CalendarView::schedule_add(Incidence *incidence) | 3070 | void CalendarView::schedule_add(Incidence *incidence) |
3071 | { | 3071 | { |
3072 | schedule(Scheduler::Add,incidence); | 3072 | schedule(Scheduler::Add,incidence); |
3073 | } | 3073 | } |
3074 | 3074 | ||
3075 | void CalendarView::schedule_reply(Incidence *incidence) | 3075 | void CalendarView::schedule_reply(Incidence *incidence) |
3076 | { | 3076 | { |
3077 | schedule(Scheduler::Reply,incidence); | 3077 | schedule(Scheduler::Reply,incidence); |
3078 | } | 3078 | } |
3079 | 3079 | ||
3080 | void CalendarView::schedule_counter(Incidence *incidence) | 3080 | void CalendarView::schedule_counter(Incidence *incidence) |
3081 | { | 3081 | { |
3082 | schedule(Scheduler::Counter,incidence); | 3082 | schedule(Scheduler::Counter,incidence); |
3083 | } | 3083 | } |
3084 | 3084 | ||
3085 | void CalendarView::schedule_declinecounter(Incidence *incidence) | 3085 | void CalendarView::schedule_declinecounter(Incidence *incidence) |
3086 | { | 3086 | { |
3087 | schedule(Scheduler::Declinecounter,incidence); | 3087 | schedule(Scheduler::Declinecounter,incidence); |
3088 | } | 3088 | } |
3089 | 3089 | ||
3090 | void CalendarView::schedule_publish_freebusy(int daysToPublish) | 3090 | void CalendarView::schedule_publish_freebusy(int daysToPublish) |
3091 | { | 3091 | { |
3092 | QDateTime start = QDateTime::currentDateTime(); | 3092 | QDateTime start = QDateTime::currentDateTime(); |
3093 | QDateTime end = start.addDays(daysToPublish); | 3093 | QDateTime end = start.addDays(daysToPublish); |
3094 | 3094 | ||
3095 | FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); | 3095 | FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); |
3096 | freebusy->setOrganizer(KOPrefs::instance()->email()); | 3096 | freebusy->setOrganizer(KOPrefs::instance()->email()); |
3097 | 3097 | ||
3098 | 3098 | ||
3099 | PublishDialog *publishdlg = new PublishDialog(); | 3099 | PublishDialog *publishdlg = new PublishDialog(); |
3100 | if ( publishdlg->exec() == QDialog::Accepted ) { | 3100 | if ( publishdlg->exec() == QDialog::Accepted ) { |
3101 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 3101 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
3102 | if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { | 3102 | if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { |
3103 | delete(freebusy); | 3103 | delete(freebusy); |
3104 | } | 3104 | } |
3105 | } | 3105 | } |
3106 | delete publishdlg; | 3106 | delete publishdlg; |
3107 | } | 3107 | } |
3108 | 3108 | ||
3109 | void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) | 3109 | void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) |
3110 | { | 3110 | { |
3111 | Event *event = 0; | 3111 | Event *event = 0; |
3112 | Todo *todo = 0; | 3112 | Todo *todo = 0; |
3113 | 3113 | ||
3114 | if (incidence == 0) { | 3114 | if (incidence == 0) { |
3115 | incidence = mViewManager->currentView()->selectedIncidences().first(); | 3115 | incidence = mViewManager->currentView()->selectedIncidences().first(); |
3116 | if (incidence == 0) { | 3116 | if (incidence == 0) { |
3117 | incidence = mTodoList->selectedIncidences().first(); | 3117 | incidence = mTodoList->selectedIncidences().first(); |
3118 | } | 3118 | } |
3119 | } | 3119 | } |
3120 | if ( incidence && incidence->type() == "Event" ) { | 3120 | if ( incidence && incidence->type() == "Event" ) { |
3121 | event = static_cast<Event *>(incidence); | 3121 | event = static_cast<Event *>(incidence); |
3122 | } | 3122 | } |
3123 | if ( incidence && incidence->type() == "Todo" ) { | 3123 | if ( incidence && incidence->type() == "Todo" ) { |
3124 | todo = static_cast<Todo *>(incidence); | 3124 | todo = static_cast<Todo *>(incidence); |
3125 | } | 3125 | } |
3126 | 3126 | ||
3127 | if (!event && !todo) { | 3127 | if (!event && !todo) { |
3128 | KMessageBox::sorry(this,i18n("No event selected.")); | 3128 | KMessageBox::sorry(this,i18n("No event selected.")); |
3129 | return; | 3129 | return; |
3130 | } | 3130 | } |
3131 | 3131 | ||
3132 | if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { | 3132 | if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { |
3133 | KMessageBox::sorry(this,i18n("The event has no attendees.")); | 3133 | KMessageBox::sorry(this,i18n("The event has no attendees.")); |
3134 | return; | 3134 | return; |
3135 | } | 3135 | } |
3136 | 3136 | ||
3137 | Event *ev = 0; | 3137 | Event *ev = 0; |
3138 | if (event) ev = new Event(*event); | 3138 | if (event) ev = new Event(*event); |
3139 | Todo *to = 0; | 3139 | Todo *to = 0; |
3140 | if (todo) to = new Todo(*todo); | 3140 | if (todo) to = new Todo(*todo); |
3141 | 3141 | ||
3142 | if (method == Scheduler::Reply || method == Scheduler::Refresh) { | 3142 | if (method == Scheduler::Reply || method == Scheduler::Refresh) { |
3143 | Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); | 3143 | Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); |
3144 | if (!me) { | 3144 | if (!me) { |
3145 | KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); | 3145 | KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); |
3146 | return; | 3146 | return; |
3147 | } | 3147 | } |
3148 | if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { | 3148 | if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { |
3149 | StatusDialog *statdlg = new StatusDialog(this); | 3149 | StatusDialog *statdlg = new StatusDialog(this); |
3150 | if (!statdlg->exec()==QDialog::Accepted) return; | 3150 | if (!statdlg->exec()==QDialog::Accepted) return; |
3151 | me->setStatus( statdlg->status() ); | 3151 | me->setStatus( statdlg->status() ); |
3152 | delete(statdlg); | 3152 | delete(statdlg); |
3153 | } | 3153 | } |
3154 | Attendee *menew = new Attendee(*me); | 3154 | Attendee *menew = new Attendee(*me); |
3155 | if (ev) { | 3155 | if (ev) { |
3156 | ev->clearAttendees(); | 3156 | ev->clearAttendees(); |
3157 | ev->addAttendee(menew,false); | 3157 | ev->addAttendee(menew,false); |
3158 | } else { | 3158 | } else { |
3159 | if (to) { | 3159 | if (to) { |
3160 | todo->clearAttendees(); | 3160 | todo->clearAttendees(); |
3161 | todo->addAttendee(menew,false); | 3161 | todo->addAttendee(menew,false); |
3162 | } | 3162 | } |
3163 | } | 3163 | } |
3164 | } | 3164 | } |
3165 | 3165 | ||
3166 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 3166 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
3167 | if (ev) { | 3167 | if (ev) { |
3168 | if ( !dlg->addMessage(ev,method) ) delete(ev); | 3168 | if ( !dlg->addMessage(ev,method) ) delete(ev); |
3169 | } else { | 3169 | } else { |
3170 | if (to) { | 3170 | if (to) { |
3171 | if ( !dlg->addMessage(to,method) ) delete(to); | 3171 | if ( !dlg->addMessage(to,method) ) delete(to); |
3172 | } | 3172 | } |
3173 | } | 3173 | } |
3174 | } | 3174 | } |
3175 | 3175 | ||
3176 | void CalendarView::openAddressbook() | 3176 | void CalendarView::openAddressbook() |
3177 | { | 3177 | { |
3178 | KRun::runCommand("kaddressbook"); | 3178 | KRun::runCommand("kaddressbook"); |
3179 | } | 3179 | } |
3180 | 3180 | ||
3181 | void CalendarView::setModified(bool modified) | 3181 | void CalendarView::setModified(bool modified) |
3182 | { | 3182 | { |
3183 | if ( modified ) | 3183 | if ( modified ) |
3184 | emit signalmodified(); | 3184 | emit signalmodified(); |
3185 | if (mModified != modified) { | 3185 | if (mModified != modified) { |
3186 | mModified = modified; | 3186 | mModified = modified; |
3187 | emit modifiedChanged(mModified); | 3187 | emit modifiedChanged(mModified); |
3188 | } | 3188 | } |
3189 | } | 3189 | } |
3190 | 3190 | ||
3191 | bool CalendarView::isReadOnly() | 3191 | bool CalendarView::isReadOnly() |
3192 | { | 3192 | { |
3193 | return mReadOnly; | 3193 | return mReadOnly; |
3194 | } | 3194 | } |
3195 | 3195 | ||
3196 | void CalendarView::setReadOnly(bool readOnly) | 3196 | void CalendarView::setReadOnly(bool readOnly) |
3197 | { | 3197 | { |
3198 | if (mReadOnly != readOnly) { | 3198 | if (mReadOnly != readOnly) { |
3199 | mReadOnly = readOnly; | 3199 | mReadOnly = readOnly; |
3200 | emit readOnlyChanged(mReadOnly); | 3200 | emit readOnlyChanged(mReadOnly); |
3201 | } | 3201 | } |
3202 | } | 3202 | } |
3203 | 3203 | ||
3204 | bool CalendarView::isModified() | 3204 | bool CalendarView::isModified() |
3205 | { | 3205 | { |
3206 | return mModified; | 3206 | return mModified; |
3207 | } | 3207 | } |
3208 | 3208 | ||
3209 | void CalendarView::printSetup() | 3209 | void CalendarView::printSetup() |
3210 | { | 3210 | { |
3211 | #ifndef KORG_NOPRINTER | 3211 | #ifndef KORG_NOPRINTER |
3212 | createPrinter(); | 3212 | createPrinter(); |
3213 | 3213 | ||
3214 | mCalPrinter->setupPrinter(); | 3214 | mCalPrinter->setupPrinter(); |
3215 | #endif | 3215 | #endif |
3216 | } | 3216 | } |
3217 | 3217 | ||
3218 | void CalendarView::print() | 3218 | void CalendarView::print() |
3219 | { | 3219 | { |
3220 | #ifndef KORG_NOPRINTER | 3220 | #ifndef KORG_NOPRINTER |
3221 | createPrinter(); | 3221 | createPrinter(); |
3222 | 3222 | ||
3223 | DateList tmpDateList = mNavigator->selectedDates(); | 3223 | DateList tmpDateList = mNavigator->selectedDates(); |
3224 | mCalPrinter->print(CalPrinter::Month, | 3224 | mCalPrinter->print(CalPrinter::Month, |
3225 | tmpDateList.first(), tmpDateList.last()); | 3225 | tmpDateList.first(), tmpDateList.last()); |
3226 | #endif | 3226 | #endif |
3227 | } | 3227 | } |
3228 | 3228 | ||
3229 | void CalendarView::printPreview() | 3229 | void CalendarView::printPreview() |
3230 | { | 3230 | { |
3231 | #ifndef KORG_NOPRINTER | 3231 | #ifndef KORG_NOPRINTER |
3232 | kdDebug() << "CalendarView::printPreview()" << endl; | 3232 | kdDebug() << "CalendarView::printPreview()" << endl; |
3233 | 3233 | ||
3234 | createPrinter(); | 3234 | createPrinter(); |
3235 | 3235 | ||
3236 | DateList tmpDateList = mNavigator->selectedDates(); | 3236 | DateList tmpDateList = mNavigator->selectedDates(); |
3237 | 3237 | ||
3238 | mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), | 3238 | mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), |
3239 | tmpDateList.last()); | 3239 | tmpDateList.last()); |
3240 | #endif | 3240 | #endif |
3241 | } | 3241 | } |
3242 | 3242 | ||
3243 | void CalendarView::exportICalendar() | 3243 | void CalendarView::exportICalendar() |
3244 | { | 3244 | { |
3245 | QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); | 3245 | QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); |
3246 | 3246 | ||
3247 | // Force correct extension | 3247 | // Force correct extension |
3248 | if (filename.right(4) != ".ics") filename += ".ics"; | 3248 | if (filename.right(4) != ".ics") filename += ".ics"; |
3249 | 3249 | ||
3250 | FileStorage storage( mCalendar, filename, new ICalFormat() ); | 3250 | FileStorage storage( mCalendar, filename, new ICalFormat() ); |
3251 | storage.save(); | 3251 | storage.save(); |
3252 | } | 3252 | } |
3253 | 3253 | ||
3254 | bool CalendarView::exportVCalendar( QString filename ) | 3254 | bool CalendarView::exportVCalendar( QString filename ) |
3255 | { | 3255 | { |
3256 | if (mCalendar->journals().count() > 0) { | 3256 | if (mCalendar->journals().count() > 0) { |
3257 | int result = KMessageBox::warningContinueCancel(this, | 3257 | int result = KMessageBox::warningContinueCancel(this, |
3258 | i18n("The journal entries can not be\nexported to a vCalendar file."), | 3258 | i18n("The journal entries can not be\nexported to a vCalendar file."), |
3259 | i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), | 3259 | i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), |
3260 | true); | 3260 | true); |
3261 | if (result != KMessageBox::Continue) return false; | 3261 | if (result != KMessageBox::Continue) return false; |
3262 | } | 3262 | } |
3263 | 3263 | ||
3264 | //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); | 3264 | //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); |
3265 | 3265 | ||
3266 | // Force correct extension | 3266 | // Force correct extension |
3267 | if (filename.right(4) != ".vcs") filename += ".vcs"; | 3267 | if (filename.right(4) != ".vcs") filename += ".vcs"; |
3268 | 3268 | ||
3269 | FileStorage storage( mCalendar, filename, new VCalFormat ); | 3269 | FileStorage storage( mCalendar, filename, new VCalFormat ); |
3270 | return storage.save(); | 3270 | return storage.save(); |
3271 | 3271 | ||
3272 | } | 3272 | } |
3273 | 3273 | ||
3274 | void CalendarView::eventUpdated(Incidence *) | 3274 | void CalendarView::eventUpdated(Incidence *) |
3275 | { | 3275 | { |
3276 | setModified(); | 3276 | setModified(); |
3277 | // Don't call updateView here. The code, which has caused the update of the | 3277 | // Don't call updateView here. The code, which has caused the update of the |
3278 | // event is responsible for updating the view. | 3278 | // event is responsible for updating the view. |
3279 | // updateView(); | 3279 | // updateView(); |
3280 | } | 3280 | } |
3281 | 3281 | ||
3282 | void CalendarView::adaptNavigationUnits() | 3282 | void CalendarView::adaptNavigationUnits() |
3283 | { | 3283 | { |
3284 | if (mViewManager->currentView()->isEventView()) { | 3284 | if (mViewManager->currentView()->isEventView()) { |
3285 | int days = mViewManager->currentView()->currentDateCount(); | 3285 | int days = mViewManager->currentView()->currentDateCount(); |
3286 | if (days == 1) { | 3286 | if (days == 1) { |
3287 | emit changeNavStringPrev(i18n("&Previous Day")); | 3287 | emit changeNavStringPrev(i18n("&Previous Day")); |
3288 | emit changeNavStringNext(i18n("&Next Day")); | 3288 | emit changeNavStringNext(i18n("&Next Day")); |
3289 | } else { | 3289 | } else { |
3290 | emit changeNavStringPrev(i18n("&Previous Week")); | 3290 | emit changeNavStringPrev(i18n("&Previous Week")); |
3291 | emit changeNavStringNext(i18n("&Next Week")); | 3291 | emit changeNavStringNext(i18n("&Next Week")); |
3292 | } | 3292 | } |
3293 | } | 3293 | } |
3294 | } | 3294 | } |
3295 | 3295 | ||
3296 | void CalendarView::processMainViewSelection( Incidence *incidence ) | 3296 | void CalendarView::processMainViewSelection( Incidence *incidence ) |
3297 | { | 3297 | { |
3298 | if ( incidence ) mTodoList->clearSelection(); | 3298 | if ( incidence ) mTodoList->clearSelection(); |
3299 | processIncidenceSelection( incidence ); | 3299 | processIncidenceSelection( incidence ); |
3300 | } | 3300 | } |
3301 | 3301 | ||
3302 | void CalendarView::processTodoListSelection( Incidence *incidence ) | 3302 | void CalendarView::processTodoListSelection( Incidence *incidence ) |
3303 | { | 3303 | { |
3304 | if ( incidence && mViewManager->currentView() ) { | 3304 | if ( incidence && mViewManager->currentView() ) { |
3305 | mViewManager->currentView()->clearSelection(); | 3305 | mViewManager->currentView()->clearSelection(); |
3306 | } | 3306 | } |
3307 | processIncidenceSelection( incidence ); | 3307 | processIncidenceSelection( incidence ); |
3308 | } | 3308 | } |
3309 | 3309 | ||
3310 | void CalendarView::processIncidenceSelection( Incidence *incidence ) | 3310 | void CalendarView::processIncidenceSelection( Incidence *incidence ) |
3311 | { | 3311 | { |
3312 | if ( incidence == mSelectedIncidence ) return; | 3312 | if ( incidence == mSelectedIncidence ) return; |
3313 | 3313 | ||
3314 | mSelectedIncidence = incidence; | 3314 | mSelectedIncidence = incidence; |
3315 | 3315 | ||
3316 | emit incidenceSelected( mSelectedIncidence ); | 3316 | emit incidenceSelected( mSelectedIncidence ); |
3317 | 3317 | ||
3318 | if ( incidence && incidence->type() == "Event" ) { | 3318 | if ( incidence && incidence->type() == "Event" ) { |
3319 | Event *event = static_cast<Event *>( incidence ); | 3319 | Event *event = static_cast<Event *>( incidence ); |
3320 | if ( event->organizer() == KOPrefs::instance()->email() ) { | 3320 | if ( event->organizer() == KOPrefs::instance()->email() ) { |
3321 | emit organizerEventsSelected( true ); | 3321 | emit organizerEventsSelected( true ); |
3322 | } else { | 3322 | } else { |
3323 | emit organizerEventsSelected(false); | 3323 | emit organizerEventsSelected(false); |
3324 | } | 3324 | } |
3325 | if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, | 3325 | if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, |
3326 | KOPrefs::instance()->email() ) ) { | 3326 | KOPrefs::instance()->email() ) ) { |
3327 | emit groupEventsSelected( true ); | 3327 | emit groupEventsSelected( true ); |
3328 | } else { | 3328 | } else { |
3329 | emit groupEventsSelected(false); | 3329 | emit groupEventsSelected(false); |
3330 | } | 3330 | } |
3331 | return; | 3331 | return; |
3332 | } else { | 3332 | } else { |
3333 | if ( incidence && incidence->type() == "Todo" ) { | 3333 | if ( incidence && incidence->type() == "Todo" ) { |
3334 | emit todoSelected( true ); | 3334 | emit todoSelected( true ); |
3335 | Todo *event = static_cast<Todo *>( incidence ); | 3335 | Todo *event = static_cast<Todo *>( incidence ); |
3336 | if ( event->organizer() == KOPrefs::instance()->email() ) { | 3336 | if ( event->organizer() == KOPrefs::instance()->email() ) { |
3337 | emit organizerEventsSelected( true ); | 3337 | emit organizerEventsSelected( true ); |
3338 | } else { | 3338 | } else { |
3339 | emit organizerEventsSelected(false); | 3339 | emit organizerEventsSelected(false); |
3340 | } | 3340 | } |
3341 | if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, | 3341 | if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, |
3342 | KOPrefs::instance()->email() ) ) { | 3342 | KOPrefs::instance()->email() ) ) { |
3343 | emit groupEventsSelected( true ); | 3343 | emit groupEventsSelected( true ); |
3344 | } else { | 3344 | } else { |
3345 | emit groupEventsSelected(false); | 3345 | emit groupEventsSelected(false); |
3346 | } | 3346 | } |
3347 | return; | 3347 | return; |
3348 | } else { | 3348 | } else { |
3349 | emit todoSelected( false ); | 3349 | emit todoSelected( false ); |
3350 | emit organizerEventsSelected(false); | 3350 | emit organizerEventsSelected(false); |
3351 | emit groupEventsSelected(false); | 3351 | emit groupEventsSelected(false); |
3352 | } | 3352 | } |
3353 | return; | 3353 | return; |
3354 | } | 3354 | } |
3355 | 3355 | ||
3356 | /* if ( incidence && incidence->type() == "Todo" ) { | 3356 | /* if ( incidence && incidence->type() == "Todo" ) { |
3357 | emit todoSelected( true ); | 3357 | emit todoSelected( true ); |
3358 | } else { | 3358 | } else { |
3359 | emit todoSelected( false ); | 3359 | emit todoSelected( false ); |
3360 | }*/ | 3360 | }*/ |
3361 | } | 3361 | } |
3362 | 3362 | ||
3363 | 3363 | ||
3364 | void CalendarView::checkClipboard() | 3364 | void CalendarView::checkClipboard() |
3365 | { | 3365 | { |
3366 | #ifndef KORG_NODND | 3366 | #ifndef KORG_NODND |
3367 | if (ICalDrag::canDecode(QApplication::clipboard()->data())) { | 3367 | if (ICalDrag::canDecode(QApplication::clipboard()->data())) { |
3368 | emit pasteEnabled(true); | 3368 | emit pasteEnabled(true); |
3369 | } else { | 3369 | } else { |
3370 | emit pasteEnabled(false); | 3370 | emit pasteEnabled(false); |
3371 | } | 3371 | } |
3372 | #endif | 3372 | #endif |
3373 | } | 3373 | } |
3374 | 3374 | ||
3375 | void CalendarView::showDates(const DateList &selectedDates) | 3375 | void CalendarView::showDates(const DateList &selectedDates) |
3376 | { | 3376 | { |
3377 | // kdDebug() << "CalendarView::selectDates()" << endl; | 3377 | // kdDebug() << "CalendarView::selectDates()" << endl; |
3378 | 3378 | ||
3379 | if ( mViewManager->currentView() ) { | 3379 | if ( mViewManager->currentView() ) { |
3380 | updateView( selectedDates.first(), selectedDates.last() ); | 3380 | updateView( selectedDates.first(), selectedDates.last() ); |
3381 | } else { | 3381 | } else { |
3382 | mViewManager->showAgendaView(); | 3382 | mViewManager->showAgendaView(); |
3383 | } | 3383 | } |
3384 | 3384 | ||
3385 | QString selDates; | 3385 | QString selDates; |
3386 | selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); | 3386 | selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); |
3387 | if (selectedDates.first() < selectedDates.last() ) | 3387 | if (selectedDates.first() < selectedDates.last() ) |
3388 | selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); | 3388 | selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); |
3389 | topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); | 3389 | topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); |
3390 | 3390 | ||
3391 | } | 3391 | } |
3392 | 3392 | ||
3393 | QPtrList<CalFilter> CalendarView::filters() | 3393 | QPtrList<CalFilter> CalendarView::filters() |
3394 | { | 3394 | { |
3395 | return mFilters; | 3395 | return mFilters; |
3396 | 3396 | ||
3397 | } | 3397 | } |
3398 | void CalendarView::editFilters() | 3398 | void CalendarView::editFilters() |
3399 | { | 3399 | { |
3400 | // kdDebug() << "CalendarView::editFilters()" << endl; | 3400 | // kdDebug() << "CalendarView::editFilters()" << endl; |
3401 | 3401 | ||
3402 | CalFilter *filter = mFilters.first(); | 3402 | CalFilter *filter = mFilters.first(); |
3403 | while(filter) { | 3403 | while(filter) { |
3404 | kdDebug() << " Filter: " << filter->name() << endl; | 3404 | kdDebug() << " Filter: " << filter->name() << endl; |
3405 | filter = mFilters.next(); | 3405 | filter = mFilters.next(); |
3406 | } | 3406 | } |
3407 | 3407 | ||
3408 | mDialogManager->showFilterEditDialog(&mFilters); | 3408 | mDialogManager->showFilterEditDialog(&mFilters); |
3409 | } | 3409 | } |
3410 | void CalendarView::toggleFilter() | 3410 | void CalendarView::toggleFilter() |
3411 | { | 3411 | { |
3412 | showFilter(! mFilterView->isVisible()); | 3412 | showFilter(! mFilterView->isVisible()); |
3413 | } | 3413 | } |
3414 | 3414 | ||
3415 | KOFilterView *CalendarView::filterView() | 3415 | KOFilterView *CalendarView::filterView() |
3416 | { | 3416 | { |
3417 | return mFilterView; | 3417 | return mFilterView; |
3418 | } | 3418 | } |
3419 | void CalendarView::selectFilter( int fil ) | 3419 | void CalendarView::selectFilter( int fil ) |
3420 | { | 3420 | { |
3421 | mFilterView->setSelectedFilter( fil ); | 3421 | mFilterView->setSelectedFilter( fil ); |
3422 | } | 3422 | } |
3423 | void CalendarView::showFilter(bool visible) | 3423 | void CalendarView::showFilter(bool visible) |
3424 | { | 3424 | { |
3425 | if (visible) mFilterView->show(); | 3425 | if (visible) mFilterView->show(); |
3426 | else mFilterView->hide(); | 3426 | else mFilterView->hide(); |
3427 | } | 3427 | } |
3428 | void CalendarView::toggleFilerEnabled( ) | 3428 | void CalendarView::toggleFilerEnabled( ) |
3429 | { | 3429 | { |
3430 | mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); | 3430 | mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); |
3431 | if ( !mFilterView->filtersEnabled() ) | 3431 | if ( !mFilterView->filtersEnabled() ) |
3432 | topLevelWidget()->setCaption( i18n("Filter disabled ") ); | 3432 | topLevelWidget()->setCaption( i18n("Filter disabled ") ); |
3433 | 3433 | ||
3434 | } | 3434 | } |
3435 | void CalendarView::updateFilter() | 3435 | void CalendarView::updateFilter() |
3436 | { | 3436 | { |
3437 | CalFilter *filter = mFilterView->selectedFilter(); | 3437 | CalFilter *filter = mFilterView->selectedFilter(); |
3438 | if (filter) { | 3438 | if (filter) { |
3439 | if (mFilterView->filtersEnabled()) { | 3439 | if (mFilterView->filtersEnabled()) { |
3440 | topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); | 3440 | topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); |
3441 | filter->setEnabled(true); | 3441 | filter->setEnabled(true); |
3442 | } | 3442 | } |
3443 | else filter->setEnabled(false); | 3443 | else filter->setEnabled(false); |
3444 | mCalendar->setFilter(filter); | 3444 | mCalendar->setFilter(filter); |
3445 | updateView(); | 3445 | updateView(); |
3446 | } | 3446 | } |
3447 | } | 3447 | } |
3448 | 3448 | ||
3449 | void CalendarView::filterEdited() | 3449 | void CalendarView::filterEdited() |
3450 | { | 3450 | { |
3451 | mFilterView->updateFilters(); | 3451 | mFilterView->updateFilters(); |
3452 | updateFilter(); | 3452 | updateFilter(); |
3453 | writeSettings(); | 3453 | writeSettings(); |
3454 | } | 3454 | } |
3455 | 3455 | ||
3456 | 3456 | ||
3457 | void CalendarView::takeOverEvent() | 3457 | void CalendarView::takeOverEvent() |
3458 | { | 3458 | { |
3459 | Incidence *incidence = currentSelection(); | 3459 | Incidence *incidence = currentSelection(); |
3460 | 3460 | ||
3461 | if (!incidence) return; | 3461 | if (!incidence) return; |
3462 | 3462 | ||
3463 | incidence->setOrganizer(KOPrefs::instance()->email()); | 3463 | incidence->setOrganizer(KOPrefs::instance()->email()); |
3464 | incidence->recreate(); | 3464 | incidence->recreate(); |
3465 | incidence->setReadOnly(false); | 3465 | incidence->setReadOnly(false); |
3466 | 3466 | ||
3467 | updateView(); | 3467 | updateView(); |
3468 | } | 3468 | } |
3469 | 3469 | ||
3470 | void CalendarView::takeOverCalendar() | 3470 | void CalendarView::takeOverCalendar() |
3471 | { | 3471 | { |
3472 | // TODO: Create Calendar::allIncidences() function and use it here | 3472 | // TODO: Create Calendar::allIncidences() function and use it here |
3473 | 3473 | ||
3474 | QPtrList<Event> events = mCalendar->events(); | 3474 | QPtrList<Event> events = mCalendar->events(); |
3475 | for(uint i=0; i<events.count(); ++i) { | 3475 | for(uint i=0; i<events.count(); ++i) { |
3476 | events.at(i)->setOrganizer(KOPrefs::instance()->email()); | 3476 | events.at(i)->setOrganizer(KOPrefs::instance()->email()); |
3477 | events.at(i)->recreate(); | 3477 | events.at(i)->recreate(); |
3478 | events.at(i)->setReadOnly(false); | 3478 | events.at(i)->setReadOnly(false); |
3479 | } | 3479 | } |
3480 | 3480 | ||
3481 | QPtrList<Todo> todos = mCalendar->todos(); | 3481 | QPtrList<Todo> todos = mCalendar->todos(); |
3482 | for(uint i=0; i<todos.count(); ++i) { | 3482 | for(uint i=0; i<todos.count(); ++i) { |
3483 | todos.at(i)->setOrganizer(KOPrefs::instance()->email()); | 3483 | todos.at(i)->setOrganizer(KOPrefs::instance()->email()); |
3484 | todos.at(i)->recreate(); | 3484 | todos.at(i)->recreate(); |
3485 | todos.at(i)->setReadOnly(false); | 3485 | todos.at(i)->setReadOnly(false); |
3486 | } | 3486 | } |
3487 | 3487 | ||
3488 | QPtrList<Journal> journals = mCalendar->journals(); | 3488 | QPtrList<Journal> journals = mCalendar->journals(); |
3489 | for(uint i=0; i<journals.count(); ++i) { | 3489 | for(uint i=0; i<journals.count(); ++i) { |
3490 | journals.at(i)->setOrganizer(KOPrefs::instance()->email()); | 3490 | journals.at(i)->setOrganizer(KOPrefs::instance()->email()); |
3491 | journals.at(i)->recreate(); | 3491 | journals.at(i)->recreate(); |
3492 | journals.at(i)->setReadOnly(false); | 3492 | journals.at(i)->setReadOnly(false); |
3493 | } | 3493 | } |
3494 | 3494 | ||
3495 | updateView(); | 3495 | updateView(); |
3496 | } | 3496 | } |
3497 | 3497 | ||
3498 | void CalendarView::showIntro() | 3498 | void CalendarView::showIntro() |
3499 | { | 3499 | { |
3500 | kdDebug() << "To be implemented." << endl; | 3500 | kdDebug() << "To be implemented." << endl; |
3501 | } | 3501 | } |
3502 | 3502 | ||
3503 | QWidgetStack *CalendarView::viewStack() | 3503 | QWidgetStack *CalendarView::viewStack() |
3504 | { | 3504 | { |
3505 | return mRightFrame; | 3505 | return mRightFrame; |
3506 | } | 3506 | } |
3507 | 3507 | ||
3508 | QWidget *CalendarView::leftFrame() | 3508 | QWidget *CalendarView::leftFrame() |
3509 | { | 3509 | { |
3510 | return mLeftFrame; | 3510 | return mLeftFrame; |
3511 | } | 3511 | } |
3512 | 3512 | ||
3513 | DateNavigator *CalendarView::dateNavigator() | 3513 | DateNavigator *CalendarView::dateNavigator() |
3514 | { | 3514 | { |
3515 | return mNavigator; | 3515 | return mNavigator; |
3516 | } | 3516 | } |
3517 | 3517 | ||
3518 | KDateNavigator* CalendarView::dateNavigatorWidget() | 3518 | KDateNavigator* CalendarView::dateNavigatorWidget() |
3519 | { | 3519 | { |
3520 | return mDateNavigator; | 3520 | return mDateNavigator; |
3521 | } | 3521 | } |
3522 | void CalendarView::toggleDateNavigatorWidget() | 3522 | void CalendarView::toggleDateNavigatorWidget() |
3523 | { | 3523 | { |
3524 | if (mDateNavigator->isVisible()) | 3524 | if (mDateNavigator->isVisible()) |
3525 | mDateNavigator->hide(); | 3525 | mDateNavigator->hide(); |
3526 | else | 3526 | else |
3527 | mDateNavigator->show(); | 3527 | mDateNavigator->show(); |
3528 | } | 3528 | } |
3529 | void CalendarView::addView(KOrg::BaseView *view) | 3529 | void CalendarView::addView(KOrg::BaseView *view) |
3530 | { | 3530 | { |
3531 | mViewManager->addView(view); | 3531 | mViewManager->addView(view); |
3532 | } | 3532 | } |
3533 | 3533 | ||
3534 | void CalendarView::showView(KOrg::BaseView *view) | 3534 | void CalendarView::showView(KOrg::BaseView *view) |
3535 | { | 3535 | { |
3536 | mViewManager->showView(view, mLeftFrame->isVisible()); | 3536 | mViewManager->showView(view, mLeftFrame->isVisible()); |
3537 | } | 3537 | } |
3538 | 3538 | ||
3539 | Incidence *CalendarView::currentSelection() | 3539 | Incidence *CalendarView::currentSelection() |
3540 | { | 3540 | { |
3541 | return mViewManager->currentSelection(); | 3541 | return mViewManager->currentSelection(); |
3542 | } | 3542 | } |
3543 | void CalendarView::toggleAllDaySize() | 3543 | void CalendarView::toggleAllDaySize() |
3544 | { | 3544 | { |
3545 | /* | 3545 | /* |
3546 | if ( KOPrefs::instance()->mAllDaySize > 47 ) | 3546 | if ( KOPrefs::instance()->mAllDaySize > 47 ) |
3547 | KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; | 3547 | KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; |
3548 | else | 3548 | else |
3549 | KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; | 3549 | KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; |
3550 | */ | 3550 | */ |
3551 | viewManager()->agendaView()->toggleAllDay(); | 3551 | viewManager()->agendaView()->toggleAllDay(); |
3552 | } | 3552 | } |
3553 | void CalendarView::toggleExpand() | 3553 | void CalendarView::toggleExpand() |
3554 | { | 3554 | { |
3555 | // if ( mLeftFrame->isHidden() ) { | 3555 | // if ( mLeftFrame->isHidden() ) { |
3556 | // mLeftFrame->show(); | 3556 | // mLeftFrame->show(); |
3557 | // emit calendarViewExpanded( false ); | 3557 | // emit calendarViewExpanded( false ); |
3558 | // } else { | 3558 | // } else { |
3559 | // mLeftFrame->hide(); | 3559 | // mLeftFrame->hide(); |
3560 | // emit calendarViewExpanded( true ); | 3560 | // emit calendarViewExpanded( true ); |
3561 | // } | 3561 | // } |
3562 | 3562 | ||
3563 | globalFlagBlockAgenda = 1; | 3563 | globalFlagBlockAgenda = 1; |
3564 | emit calendarViewExpanded( !mLeftFrame->isHidden() ); | 3564 | emit calendarViewExpanded( !mLeftFrame->isHidden() ); |
3565 | globalFlagBlockAgenda = 5; | 3565 | globalFlagBlockAgenda = 5; |
3566 | mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); | 3566 | mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); |
3567 | //mViewManager->showView( 0, true ); | 3567 | //mViewManager->showView( 0, true ); |
3568 | } | 3568 | } |
3569 | 3569 | ||
3570 | void CalendarView::calendarModified( bool modified, Calendar * ) | 3570 | void CalendarView::calendarModified( bool modified, Calendar * ) |
3571 | { | 3571 | { |
3572 | setModified( modified ); | 3572 | setModified( modified ); |
3573 | } | 3573 | } |
3574 | 3574 | ||
3575 | Todo *CalendarView::selectedTodo() | 3575 | Todo *CalendarView::selectedTodo() |
3576 | { | 3576 | { |
3577 | Incidence *incidence = currentSelection(); | 3577 | Incidence *incidence = currentSelection(); |
3578 | if ( incidence && incidence->type() == "Todo" ) { | 3578 | if ( incidence && incidence->type() == "Todo" ) { |
3579 | return static_cast<Todo *>( incidence ); | 3579 | return static_cast<Todo *>( incidence ); |
3580 | } | 3580 | } |
3581 | 3581 | ||
3582 | incidence = mTodoList->selectedIncidences().first(); | 3582 | incidence = mTodoList->selectedIncidences().first(); |
3583 | if ( incidence && incidence->type() == "Todo" ) { | 3583 | if ( incidence && incidence->type() == "Todo" ) { |
3584 | return static_cast<Todo *>( incidence ); | 3584 | return static_cast<Todo *>( incidence ); |
3585 | } | 3585 | } |
3586 | 3586 | ||
3587 | return 0; | 3587 | return 0; |
3588 | } | 3588 | } |
3589 | 3589 | ||
3590 | void CalendarView::dialogClosing(Incidence *in) | 3590 | void CalendarView::dialogClosing(Incidence *in) |
3591 | { | 3591 | { |
3592 | // mDialogList.remove(in); | 3592 | // mDialogList.remove(in); |
3593 | } | 3593 | } |
3594 | 3594 | ||
3595 | void CalendarView::showIncidence() | 3595 | void CalendarView::showIncidence() |
3596 | { | 3596 | { |
3597 | Incidence *incidence = currentSelection(); | 3597 | Incidence *incidence = currentSelection(); |
3598 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 3598 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
3599 | if ( incidence ) { | 3599 | if ( incidence ) { |
3600 | ShowIncidenceVisitor v; | 3600 | ShowIncidenceVisitor v; |
3601 | v.act( incidence, this ); | 3601 | v.act( incidence, this ); |
3602 | } | 3602 | } |
3603 | } | 3603 | } |
3604 | void CalendarView::editIncidenceDescription() | 3604 | void CalendarView::editIncidenceDescription() |
3605 | { | 3605 | { |
3606 | mFlagEditDescription = true; | 3606 | mFlagEditDescription = true; |
3607 | editIncidence(); | 3607 | editIncidence(); |
3608 | mFlagEditDescription = false; | 3608 | mFlagEditDescription = false; |
3609 | } | 3609 | } |
3610 | void CalendarView::editIncidence() | 3610 | void CalendarView::editIncidence() |
3611 | { | 3611 | { |
3612 | // qDebug("editIncidence() "); | 3612 | // qDebug("editIncidence() "); |
3613 | Incidence *incidence = currentSelection(); | 3613 | Incidence *incidence = currentSelection(); |
3614 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 3614 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
3615 | if ( incidence ) { | 3615 | if ( incidence ) { |
3616 | EditIncidenceVisitor v; | 3616 | EditIncidenceVisitor v; |
3617 | v.act( incidence, this ); | 3617 | v.act( incidence, this ); |
3618 | } | 3618 | } |
3619 | } | 3619 | } |
3620 | 3620 | ||
3621 | void CalendarView::deleteIncidence() | 3621 | void CalendarView::deleteIncidence() |
3622 | { | 3622 | { |
3623 | Incidence *incidence = currentSelection(); | 3623 | Incidence *incidence = currentSelection(); |
3624 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); | 3624 | if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); |
3625 | if ( incidence ) { | 3625 | if ( incidence ) { |
3626 | deleteIncidence(incidence); | 3626 | deleteIncidence(incidence); |
3627 | } | 3627 | } |
3628 | } | 3628 | } |
3629 | 3629 | ||
3630 | void CalendarView::showIncidence(Incidence *incidence) | 3630 | void CalendarView::showIncidence(Incidence *incidence) |
3631 | { | 3631 | { |
3632 | if ( incidence ) { | 3632 | if ( incidence ) { |
3633 | ShowIncidenceVisitor v; | 3633 | ShowIncidenceVisitor v; |
3634 | v.act( incidence, this ); | 3634 | v.act( incidence, this ); |
3635 | } | 3635 | } |
3636 | } | 3636 | } |
3637 | 3637 | ||
3638 | void CalendarView::editIncidence(Incidence *incidence) | 3638 | void CalendarView::editIncidence(Incidence *incidence) |
3639 | { | 3639 | { |
3640 | if ( incidence ) { | 3640 | if ( incidence ) { |
3641 | 3641 | ||
3642 | EditIncidenceVisitor v; | 3642 | EditIncidenceVisitor v; |
3643 | v.act( incidence, this ); | 3643 | v.act( incidence, this ); |
3644 | 3644 | ||
3645 | } | 3645 | } |
3646 | } | 3646 | } |
3647 | 3647 | ||
3648 | void CalendarView::deleteIncidence(Incidence *incidence) | 3648 | void CalendarView::deleteIncidence(Incidence *incidence) |
3649 | { | 3649 | { |
3650 | //qDebug(" CalendarView::deleteIncidence "); | 3650 | //qDebug(" CalendarView::deleteIncidence "); |
3651 | if ( incidence ) { | 3651 | if ( incidence ) { |
3652 | DeleteIncidenceVisitor v; | 3652 | DeleteIncidenceVisitor v; |
3653 | v.act( incidence, this ); | 3653 | v.act( incidence, this ); |
3654 | } | 3654 | } |
3655 | } | 3655 | } |
3656 | 3656 | ||
3657 | 3657 | ||
3658 | void CalendarView::lookForOutgoingMessages() | 3658 | void CalendarView::lookForOutgoingMessages() |
3659 | { | 3659 | { |
3660 | OutgoingDialog *ogd = mDialogManager->outgoingDialog(); | 3660 | OutgoingDialog *ogd = mDialogManager->outgoingDialog(); |
3661 | ogd->loadMessages(); | 3661 | ogd->loadMessages(); |
3662 | } | 3662 | } |
3663 | 3663 | ||
3664 | void CalendarView::lookForIncomingMessages() | 3664 | void CalendarView::lookForIncomingMessages() |
3665 | { | 3665 | { |
3666 | IncomingDialog *icd = mDialogManager->incomingDialog(); | 3666 | IncomingDialog *icd = mDialogManager->incomingDialog(); |
3667 | icd->retrieve(); | 3667 | icd->retrieve(); |
3668 | } | 3668 | } |
3669 | 3669 | ||
3670 | bool CalendarView::removeCompletedSubTodos( Todo* t ) | 3670 | bool CalendarView::removeCompletedSubTodos( Todo* t ) |
3671 | { | 3671 | { |
3672 | bool deleteTodo = true; | 3672 | bool deleteTodo = true; |
3673 | QPtrList<Incidence> subTodos; | 3673 | QPtrList<Incidence> subTodos; |
3674 | Incidence *aTodo; | 3674 | Incidence *aTodo; |
3675 | subTodos = t->relations(); | 3675 | subTodos = t->relations(); |
3676 | for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { | 3676 | for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { |
3677 | if (! removeCompletedSubTodos( (Todo*) aTodo )) | 3677 | if (! removeCompletedSubTodos( (Todo*) aTodo )) |
3678 | deleteTodo = false; | 3678 | deleteTodo = false; |
3679 | } | 3679 | } |
3680 | if ( deleteTodo ) { | 3680 | if ( deleteTodo ) { |
3681 | if ( t->isCompleted() ) { | 3681 | if ( t->isCompleted() ) { |
3682 | checkExternalId( t ); | 3682 | checkExternalId( t ); |
3683 | mCalendar->deleteTodo( t ); | 3683 | mCalendar->deleteTodo( t ); |
3684 | changeTodoDisplay( t,KOGlobals::EVENTDELETED ); | 3684 | changeTodoDisplay( t,KOGlobals::EVENTDELETED ); |
3685 | } | 3685 | } |
3686 | else | 3686 | else |
3687 | deleteTodo = false; | 3687 | deleteTodo = false; |
3688 | } | 3688 | } |
3689 | return deleteTodo; | 3689 | return deleteTodo; |
3690 | 3690 | ||
3691 | } | 3691 | } |
3692 | void CalendarView::purgeCompleted() | 3692 | void CalendarView::purgeCompleted() |
3693 | { | 3693 | { |
3694 | int result = KMessageBox::warningContinueCancel(this, | 3694 | int result = KMessageBox::warningContinueCancel(this, |
3695 | i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); | 3695 | i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); |
3696 | 3696 | ||
3697 | if (result == KMessageBox::Continue) { | 3697 | if (result == KMessageBox::Continue) { |
3698 | 3698 | ||
3699 | QPtrList<Todo> todoCal; | 3699 | QPtrList<Todo> todoCal; |
3700 | QPtrList<Todo> rootTodos; | 3700 | QPtrList<Todo> rootTodos; |
3701 | //QPtrList<Incidence> rel; | 3701 | //QPtrList<Incidence> rel; |
3702 | Todo *aTodo;//, *rTodo; | 3702 | Todo *aTodo;//, *rTodo; |
3703 | Incidence *rIncidence; | 3703 | Incidence *rIncidence; |
3704 | bool childDelete = false; | 3704 | bool childDelete = false; |
3705 | bool deletedOne = true; | 3705 | bool deletedOne = true; |
3706 | todoCal = calendar()->todos(); | 3706 | todoCal = calendar()->todos(); |
3707 | for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { | 3707 | for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { |
3708 | if ( !aTodo->relatedTo() ) | 3708 | if ( !aTodo->relatedTo() ) |
3709 | rootTodos.append( aTodo ); | 3709 | rootTodos.append( aTodo ); |
3710 | } | 3710 | } |
3711 | for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { | 3711 | for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { |
3712 | removeCompletedSubTodos( aTodo ); | 3712 | removeCompletedSubTodos( aTodo ); |
3713 | } | 3713 | } |
3714 | 3714 | ||
3715 | updateView(); | 3715 | updateView(); |
3716 | } | 3716 | } |
3717 | } | 3717 | } |
3718 | 3718 | ||
3719 | void CalendarView::slotCalendarChanged() | 3719 | void CalendarView::slotCalendarChanged() |
3720 | { | 3720 | { |
3721 | ; | 3721 | ; |
3722 | } | 3722 | } |
3723 | 3723 | ||
3724 | NavigatorBar *CalendarView::navigatorBar() | 3724 | NavigatorBar *CalendarView::navigatorBar() |
3725 | { | 3725 | { |
3726 | return mNavigatorBar; | 3726 | return mNavigatorBar; |
3727 | } | 3727 | } |
3728 | 3728 | ||
3729 | 3729 | ||
3730 | 3730 | ||
3731 | void CalendarView::keyPressEvent ( QKeyEvent *e) | 3731 | void CalendarView::keyPressEvent ( QKeyEvent *e) |
3732 | { | 3732 | { |
3733 | //qDebug(" alendarView::keyPressEvent "); | 3733 | //qDebug(" alendarView::keyPressEvent "); |
3734 | e->ignore(); | 3734 | e->ignore(); |
3735 | } | 3735 | } |
3736 | 3736 | ||
3737 | 3737 | ||
3738 | bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) | 3738 | bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) |
3739 | { | 3739 | { |
3740 | // mSyncManager = manager; | 3740 | // mSyncManager = manager; |
3741 | mSyncKDE = false; | 3741 | mSyncKDE = false; |
3742 | if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { | 3742 | if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { |
3743 | qDebug("SyncKDE request detected!"); | 3743 | qDebug("SyncKDE request detected!"); |
3744 | mSyncKDE = true; | 3744 | mSyncKDE = true; |
3745 | } | 3745 | } |
3746 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); | 3746 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); |
3747 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); | 3747 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); |
3748 | return syncCalendar( filename, mode ); | 3748 | return syncCalendar( filename, mode ); |
3749 | } | 3749 | } |
3750 | bool CalendarView::syncExternal(KSyncManager* manager, QString resource) | 3750 | bool CalendarView::syncExternal(KSyncManager* manager, QString resource) |
3751 | { | 3751 | { |
3752 | mSyncKDE = false; | 3752 | mSyncKDE = false; |
3753 | //mSyncManager = manager; | 3753 | //mSyncManager = manager; |
3754 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); | 3754 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); |
3755 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); | 3755 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); |
3756 | if ( resource == "sharp" ) | 3756 | if ( resource == "sharp" ) |
3757 | syncExternal( 0 ); | 3757 | syncExternal( 0 ); |
3758 | if ( resource == "phone" ) | 3758 | if ( resource == "phone" ) |
3759 | syncExternal( 1 ); | 3759 | syncExternal( 1 ); |
3760 | // pending setmodified | 3760 | // pending setmodified |
3761 | return true; | 3761 | return true; |
3762 | } | 3762 | } |
3763 | void CalendarView::setSyncManager(KSyncManager* manager) | 3763 | void CalendarView::setSyncManager(KSyncManager* manager) |
3764 | { | 3764 | { |
3765 | mSyncManager = manager; | 3765 | mSyncManager = manager; |
3766 | } | 3766 | } |
3767 | 3767 | ||
3768 | void CalendarView::removeSyncInfo( QString syncProfile) | 3768 | void CalendarView::removeSyncInfo( QString syncProfile) |
3769 | { | 3769 | { |
3770 | qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); | 3770 | qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); |
3771 | mCalendar->removeSyncInfo( syncProfile ); | ||
3771 | 3772 | ||
3772 | } | 3773 | } |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index b801186..b7d6a1f 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,352 +1,353 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
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 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | void deleteIncidence(Incidence *in); | 68 | void deleteIncidence(Incidence *in); |
69 | void resetTempSyncStat(); | 69 | void resetTempSyncStat(); |
70 | void resetPilotStat(int id); | 70 | void resetPilotStat(int id); |
71 | /** | 71 | /** |
72 | Clears out the current calendar, freeing all used memory etc. | 72 | Clears out the current calendar, freeing all used memory etc. |
73 | */ | 73 | */ |
74 | virtual void close() = 0; | 74 | virtual void close() = 0; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | Sync changes in memory to persistant storage. | 77 | Sync changes in memory to persistant storage. |
78 | */ | 78 | */ |
79 | virtual void save() = 0; | 79 | virtual void save() = 0; |
80 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 80 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
81 | virtual void removeSyncInfo( QString syncProfile) = 0; | ||
81 | virtual bool isSaving() { return false; } | 82 | virtual bool isSaving() { return false; } |
82 | 83 | ||
83 | /** | 84 | /** |
84 | Return the owner of the calendar's full name. | 85 | Return the owner of the calendar's full name. |
85 | */ | 86 | */ |
86 | const QString &getOwner() const; | 87 | const QString &getOwner() const; |
87 | /** | 88 | /** |
88 | Set the owner of the calendar. Should be owner's full name. | 89 | Set the owner of the calendar. Should be owner's full name. |
89 | */ | 90 | */ |
90 | void setOwner( const QString &os ); | 91 | void setOwner( const QString &os ); |
91 | /** | 92 | /** |
92 | Return the email address of the calendar owner. | 93 | Return the email address of the calendar owner. |
93 | */ | 94 | */ |
94 | const QString &getEmail(); | 95 | const QString &getEmail(); |
95 | /** | 96 | /** |
96 | Set the email address of the calendar owner. | 97 | Set the email address of the calendar owner. |
97 | */ | 98 | */ |
98 | void setEmail( const QString & ); | 99 | void setEmail( const QString & ); |
99 | 100 | ||
100 | /** | 101 | /** |
101 | Set time zone from a timezone string (e.g. -2:00) | 102 | Set time zone from a timezone string (e.g. -2:00) |
102 | */ | 103 | */ |
103 | void setTimeZone( const QString &tz ); | 104 | void setTimeZone( const QString &tz ); |
104 | /** | 105 | /** |
105 | Set time zone from a minutes value (e.g. -60) | 106 | Set time zone from a minutes value (e.g. -60) |
106 | */ | 107 | */ |
107 | void setTimeZone( int tz ); | 108 | void setTimeZone( int tz ); |
108 | /** | 109 | /** |
109 | Return time zone as offest in minutes. | 110 | Return time zone as offest in minutes. |
110 | */ | 111 | */ |
111 | int getTimeZone() const; | 112 | int getTimeZone() const; |
112 | /** | 113 | /** |
113 | Compute an ISO 8601 format string from the time zone. | 114 | Compute an ISO 8601 format string from the time zone. |
114 | */ | 115 | */ |
115 | QString getTimeZoneStr() const; | 116 | QString getTimeZoneStr() const; |
116 | /** | 117 | /** |
117 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 118 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
118 | values). | 119 | values). |
119 | */ | 120 | */ |
120 | void setTimeZoneId( const QString & ); | 121 | void setTimeZoneId( const QString & ); |
121 | /** | 122 | /** |
122 | Return time zone id. | 123 | Return time zone id. |
123 | */ | 124 | */ |
124 | QString timeZoneId() const; | 125 | QString timeZoneId() const; |
125 | /** | 126 | /** |
126 | Use local time, not UTC or a time zone. | 127 | Use local time, not UTC or a time zone. |
127 | */ | 128 | */ |
128 | void setLocalTime(); | 129 | void setLocalTime(); |
129 | /** | 130 | /** |
130 | Return whether local time is being used. | 131 | Return whether local time is being used. |
131 | */ | 132 | */ |
132 | bool isLocalTime() const; | 133 | bool isLocalTime() const; |
133 | 134 | ||
134 | /** | 135 | /** |
135 | Add an incidence to calendar. | 136 | Add an incidence to calendar. |
136 | 137 | ||
137 | @return true on success, false on error. | 138 | @return true on success, false on error. |
138 | */ | 139 | */ |
139 | virtual bool addIncidence( Incidence * ); | 140 | virtual bool addIncidence( Incidence * ); |
140 | /** | 141 | /** |
141 | Return filtered list of all incidences of this calendar. | 142 | Return filtered list of all incidences of this calendar. |
142 | */ | 143 | */ |
143 | virtual QPtrList<Incidence> incidences(); | 144 | virtual QPtrList<Incidence> incidences(); |
144 | 145 | ||
145 | /** | 146 | /** |
146 | Return unfiltered list of all incidences of this calendar. | 147 | Return unfiltered list of all incidences of this calendar. |
147 | */ | 148 | */ |
148 | virtual QPtrList<Incidence> rawIncidences(); | 149 | virtual QPtrList<Incidence> rawIncidences(); |
149 | 150 | ||
150 | /** | 151 | /** |
151 | Adds a Event to this calendar object. | 152 | Adds a Event to this calendar object. |
152 | @param anEvent a pointer to the event to add | 153 | @param anEvent a pointer to the event to add |
153 | 154 | ||
154 | @return true on success, false on error. | 155 | @return true on success, false on error. |
155 | */ | 156 | */ |
156 | virtual bool addEventNoDup( Event *event ) = 0; | 157 | virtual bool addEventNoDup( Event *event ) = 0; |
157 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 158 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
158 | virtual bool addEvent( Event *anEvent ) = 0; | 159 | virtual bool addEvent( Event *anEvent ) = 0; |
159 | /** | 160 | /** |
160 | Delete event from calendar. | 161 | Delete event from calendar. |
161 | */ | 162 | */ |
162 | virtual void deleteEvent( Event * ) = 0; | 163 | virtual void deleteEvent( Event * ) = 0; |
163 | /** | 164 | /** |
164 | Retrieves an event on the basis of the unique string ID. | 165 | Retrieves an event on the basis of the unique string ID. |
165 | */ | 166 | */ |
166 | virtual Event *event( const QString &UniqueStr ) = 0; | 167 | virtual Event *event( const QString &UniqueStr ) = 0; |
167 | virtual Event *event( QString, QString ) = 0; | 168 | virtual Event *event( QString, QString ) = 0; |
168 | /** | 169 | /** |
169 | Builds and then returns a list of all events that match for the | 170 | Builds and then returns a list of all events that match for the |
170 | date specified. useful for dayView, etc. etc. | 171 | date specified. useful for dayView, etc. etc. |
171 | The calendar filter is applied. | 172 | The calendar filter is applied. |
172 | */ | 173 | */ |
173 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 174 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
174 | /** | 175 | /** |
175 | Get events, which occur on the given date. | 176 | Get events, which occur on the given date. |
176 | The calendar filter is applied. | 177 | The calendar filter is applied. |
177 | */ | 178 | */ |
178 | QPtrList<Event> events( const QDateTime &qdt ); | 179 | QPtrList<Event> events( const QDateTime &qdt ); |
179 | /** | 180 | /** |
180 | Get events in a range of dates. If inclusive is set to true, only events | 181 | Get events in a range of dates. If inclusive is set to true, only events |
181 | are returned, which are completely included in the range. | 182 | are returned, which are completely included in the range. |
182 | The calendar filter is applied. | 183 | The calendar filter is applied. |
183 | */ | 184 | */ |
184 | QPtrList<Event> events( const QDate &start, const QDate &end, | 185 | QPtrList<Event> events( const QDate &start, const QDate &end, |
185 | bool inclusive = false); | 186 | bool inclusive = false); |
186 | /** | 187 | /** |
187 | Return filtered list of all events in calendar. | 188 | Return filtered list of all events in calendar. |
188 | */ | 189 | */ |
189 | virtual QPtrList<Event> events(); | 190 | virtual QPtrList<Event> events(); |
190 | /** | 191 | /** |
191 | Return unfiltered list of all events in calendar. | 192 | Return unfiltered list of all events in calendar. |
192 | */ | 193 | */ |
193 | virtual QPtrList<Event> rawEvents() = 0; | 194 | virtual QPtrList<Event> rawEvents() = 0; |
194 | 195 | ||
195 | /** | 196 | /** |
196 | Add a todo to the todolist. | 197 | Add a todo to the todolist. |
197 | 198 | ||
198 | @return true on success, false on error. | 199 | @return true on success, false on error. |
199 | */ | 200 | */ |
200 | virtual bool addTodo( Todo *todo ) = 0; | 201 | virtual bool addTodo( Todo *todo ) = 0; |
201 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 202 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
202 | /** | 203 | /** |
203 | Remove a todo from the todolist. | 204 | Remove a todo from the todolist. |
204 | */ | 205 | */ |
205 | virtual void deleteTodo( Todo * ) = 0; | 206 | virtual void deleteTodo( Todo * ) = 0; |
206 | virtual void deleteJournal( Journal * ) = 0; | 207 | virtual void deleteJournal( Journal * ) = 0; |
207 | /** | 208 | /** |
208 | Return filterd list of todos. | 209 | Return filterd list of todos. |
209 | */ | 210 | */ |
210 | virtual QPtrList<Todo> todos(); | 211 | virtual QPtrList<Todo> todos(); |
211 | /** | 212 | /** |
212 | Searches todolist for an event with this unique string identifier, | 213 | Searches todolist for an event with this unique string identifier, |
213 | returns a pointer or null. | 214 | returns a pointer or null. |
214 | */ | 215 | */ |
215 | virtual Todo *todo( const QString &uid ) = 0; | 216 | virtual Todo *todo( const QString &uid ) = 0; |
216 | virtual Todo *todo( QString, QString ) = 0; | 217 | virtual Todo *todo( QString, QString ) = 0; |
217 | /** | 218 | /** |
218 | Returns list of todos due on the specified date. | 219 | Returns list of todos due on the specified date. |
219 | */ | 220 | */ |
220 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 221 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
221 | /** | 222 | /** |
222 | Return unfiltered list of todos. | 223 | Return unfiltered list of todos. |
223 | */ | 224 | */ |
224 | virtual QPtrList<Todo> rawTodos() = 0; | 225 | virtual QPtrList<Todo> rawTodos() = 0; |
225 | 226 | ||
226 | /** | 227 | /** |
227 | Add a Journal entry to calendar. | 228 | Add a Journal entry to calendar. |
228 | 229 | ||
229 | @return true on success, false on error. | 230 | @return true on success, false on error. |
230 | */ | 231 | */ |
231 | virtual bool addJournal( Journal * ) = 0; | 232 | virtual bool addJournal( Journal * ) = 0; |
232 | /** | 233 | /** |
233 | Return Journal for given date. | 234 | Return Journal for given date. |
234 | */ | 235 | */ |
235 | virtual Journal *journal( const QDate & ) = 0; | 236 | virtual Journal *journal( const QDate & ) = 0; |
236 | /** | 237 | /** |
237 | Return Journal with given UID. | 238 | Return Journal with given UID. |
238 | */ | 239 | */ |
239 | virtual Journal *journal( const QString &UID ) = 0; | 240 | virtual Journal *journal( const QString &UID ) = 0; |
240 | /** | 241 | /** |
241 | Return list of all Journal entries. | 242 | Return list of all Journal entries. |
242 | */ | 243 | */ |
243 | virtual QPtrList<Journal> journals() = 0; | 244 | virtual QPtrList<Journal> journals() = 0; |
244 | 245 | ||
245 | /** | 246 | /** |
246 | Searches all incidence types for an incidence with this unique | 247 | Searches all incidence types for an incidence with this unique |
247 | string identifier, returns a pointer or null. | 248 | string identifier, returns a pointer or null. |
248 | */ | 249 | */ |
249 | Incidence* incidence( const QString&UID ); | 250 | Incidence* incidence( const QString&UID ); |
250 | 251 | ||
251 | /** | 252 | /** |
252 | Setup relations for an incidence. | 253 | Setup relations for an incidence. |
253 | */ | 254 | */ |
254 | virtual void setupRelations( Incidence * ); | 255 | virtual void setupRelations( Incidence * ); |
255 | /** | 256 | /** |
256 | Remove all relations to an incidence | 257 | Remove all relations to an incidence |
257 | */ | 258 | */ |
258 | virtual void removeRelations( Incidence * ); | 259 | virtual void removeRelations( Incidence * ); |
259 | 260 | ||
260 | /** | 261 | /** |
261 | Set calendar filter, which filters events for the events() functions. | 262 | Set calendar filter, which filters events for the events() functions. |
262 | The Filter object is owned by the caller. | 263 | The Filter object is owned by the caller. |
263 | */ | 264 | */ |
264 | void setFilter( CalFilter * ); | 265 | void setFilter( CalFilter * ); |
265 | /** | 266 | /** |
266 | Return calendar filter. | 267 | Return calendar filter. |
267 | */ | 268 | */ |
268 | CalFilter *filter(); | 269 | CalFilter *filter(); |
269 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 270 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
270 | virtual QString nextSummary( ) const = 0; | 271 | virtual QString nextSummary( ) const = 0; |
271 | virtual void reInitAlarmSettings() = 0; | 272 | virtual void reInitAlarmSettings() = 0; |
272 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 273 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
273 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 274 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
274 | /** | 275 | /** |
275 | Return all alarms, which ocur in the given time interval. | 276 | Return all alarms, which ocur in the given time interval. |
276 | */ | 277 | */ |
277 | virtual Alarm::List alarms( const QDateTime &from, | 278 | virtual Alarm::List alarms( const QDateTime &from, |
278 | const QDateTime &to ) = 0; | 279 | const QDateTime &to ) = 0; |
279 | 280 | ||
280 | class Observer { | 281 | class Observer { |
281 | public: | 282 | public: |
282 | virtual void calendarModified( bool, Calendar * ) = 0; | 283 | virtual void calendarModified( bool, Calendar * ) = 0; |
283 | }; | 284 | }; |
284 | 285 | ||
285 | void registerObserver( Observer * ); | 286 | void registerObserver( Observer * ); |
286 | 287 | ||
287 | void setModified( bool ); | 288 | void setModified( bool ); |
288 | 289 | ||
289 | /** | 290 | /** |
290 | Set product id returned by loadedProductId(). This function is only | 291 | Set product id returned by loadedProductId(). This function is only |
291 | useful for the calendar loading code. | 292 | useful for the calendar loading code. |
292 | */ | 293 | */ |
293 | void setLoadedProductId( const QString & ); | 294 | void setLoadedProductId( const QString & ); |
294 | /** | 295 | /** |
295 | Return product id taken from file that has been loaded. Returns | 296 | Return product id taken from file that has been loaded. Returns |
296 | QString::null, if no calendar has been loaded. | 297 | QString::null, if no calendar has been loaded. |
297 | */ | 298 | */ |
298 | QString loadedProductId(); | 299 | QString loadedProductId(); |
299 | 300 | ||
300 | signals: | 301 | signals: |
301 | void calendarChanged(); | 302 | void calendarChanged(); |
302 | void calendarSaved(); | 303 | void calendarSaved(); |
303 | void calendarLoaded(); | 304 | void calendarLoaded(); |
304 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 305 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
305 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 306 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
306 | 307 | ||
307 | protected: | 308 | protected: |
308 | /** | 309 | /** |
309 | Get unfiltered events, which occur on the given date. | 310 | Get unfiltered events, which occur on the given date. |
310 | */ | 311 | */ |
311 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 312 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
312 | /** | 313 | /** |
313 | Get unfiltered events, which occur on the given date. | 314 | Get unfiltered events, which occur on the given date. |
314 | */ | 315 | */ |
315 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 316 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
316 | bool sorted = false ) = 0; | 317 | bool sorted = false ) = 0; |
317 | /** | 318 | /** |
318 | Get events in a range of dates. If inclusive is set to true, only events | 319 | Get events in a range of dates. If inclusive is set to true, only events |
319 | are returned, which are completely included in the range. | 320 | are returned, which are completely included in the range. |
320 | */ | 321 | */ |
321 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 322 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
322 | bool inclusive = false ) = 0; | 323 | bool inclusive = false ) = 0; |
323 | Incidence *mNextAlarmIncidence; | 324 | Incidence *mNextAlarmIncidence; |
324 | 325 | ||
325 | private: | 326 | private: |
326 | void init(); | 327 | void init(); |
327 | 328 | ||
328 | QString mOwner; // who the calendar belongs to | 329 | QString mOwner; // who the calendar belongs to |
329 | QString mOwnerEmail; // email address of the owner | 330 | QString mOwnerEmail; // email address of the owner |
330 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 331 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
331 | bool mLocalTime; // use local time, not UTC or a time zone | 332 | bool mLocalTime; // use local time, not UTC or a time zone |
332 | 333 | ||
333 | CalFilter *mFilter; | 334 | CalFilter *mFilter; |
334 | CalFilter *mDefaultFilter; | 335 | CalFilter *mDefaultFilter; |
335 | 336 | ||
336 | QString mTimeZoneId; | 337 | QString mTimeZoneId; |
337 | 338 | ||
338 | Observer *mObserver; | 339 | Observer *mObserver; |
339 | bool mNewObserver; | 340 | bool mNewObserver; |
340 | 341 | ||
341 | bool mModified; | 342 | bool mModified; |
342 | 343 | ||
343 | QString mLoadedProductId; | 344 | QString mLoadedProductId; |
344 | 345 | ||
345 | // This list is used to put together related todos | 346 | // This list is used to put together related todos |
346 | QDict<Incidence> mOrphans; | 347 | QDict<Incidence> mOrphans; |
347 | QDict<Incidence> mOrphanUids; | 348 | QDict<Incidence> mOrphanUids; |
348 | }; | 349 | }; |
349 | 350 | ||
350 | } | 351 | } |
351 | 352 | ||
352 | #endif | 353 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 21b4aaf..3f46d53 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,698 +1,719 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | 155 | ||
156 | 156 | ||
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | removeRelations( todo ); | 204 | removeRelations( todo ); |
205 | 205 | ||
206 | if ( mTodoList.removeRef( todo ) ) { | 206 | if ( mTodoList.removeRef( todo ) ) { |
207 | setModified( true ); | 207 | setModified( true ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | QPtrList<Todo> CalendarLocal::rawTodos() | 211 | QPtrList<Todo> CalendarLocal::rawTodos() |
212 | { | 212 | { |
213 | return mTodoList; | 213 | return mTodoList; |
214 | } | 214 | } |
215 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 215 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
216 | { | 216 | { |
217 | Todo *todo; | 217 | Todo *todo; |
218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
219 | if ( todo->getID( syncProf ) == id ) return todo; | 219 | if ( todo->getID( syncProf ) == id ) return todo; |
220 | } | 220 | } |
221 | 221 | ||
222 | return 0; | 222 | return 0; |
223 | } | 223 | } |
224 | 224 | void CalendarLocal::removeSyncInfo( QString syncProfile) | |
225 | { | ||
226 | QPtrList<Incidence> all = rawIncidences() ; | ||
227 | Incidence *inc; | ||
228 | for ( inc = all.first(); inc; inc = all.next() ) { | ||
229 | inc->removeID( syncProfile ); | ||
230 | } | ||
231 | if ( syncProfile.isEmpty() ) { | ||
232 | QPtrList<Event> el; | ||
233 | Event *todo; | ||
234 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | ||
235 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | ||
236 | el.append( todo ); | ||
237 | } | ||
238 | for ( todo = el.first(); todo; todo = el.next() ) { | ||
239 | deleteIncidence ( todo ); | ||
240 | } | ||
241 | } else { | ||
242 | Event *lse = event( "last-syncEvent-"+ syncProfile); | ||
243 | deleteIncidence ( lse ); | ||
244 | } | ||
245 | } | ||
225 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 246 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
226 | { | 247 | { |
227 | QPtrList<Event> el; | 248 | QPtrList<Event> el; |
228 | Event *todo; | 249 | Event *todo; |
229 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 250 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
230 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 251 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
231 | if ( todo->summary().left(3) == "E: " ) | 252 | if ( todo->summary().left(3) == "E: " ) |
232 | el.append( todo ); | 253 | el.append( todo ); |
233 | } | 254 | } |
234 | 255 | ||
235 | return el; | 256 | return el; |
236 | 257 | ||
237 | } | 258 | } |
238 | Event *CalendarLocal::event( QString syncProf, QString id ) | 259 | Event *CalendarLocal::event( QString syncProf, QString id ) |
239 | { | 260 | { |
240 | Event *todo; | 261 | Event *todo; |
241 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 262 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
242 | if ( todo->getID( syncProf ) == id ) return todo; | 263 | if ( todo->getID( syncProf ) == id ) return todo; |
243 | } | 264 | } |
244 | 265 | ||
245 | return 0; | 266 | return 0; |
246 | } | 267 | } |
247 | Todo *CalendarLocal::todo( const QString &uid ) | 268 | Todo *CalendarLocal::todo( const QString &uid ) |
248 | { | 269 | { |
249 | Todo *todo; | 270 | Todo *todo; |
250 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 271 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
251 | if ( todo->uid() == uid ) return todo; | 272 | if ( todo->uid() == uid ) return todo; |
252 | } | 273 | } |
253 | 274 | ||
254 | return 0; | 275 | return 0; |
255 | } | 276 | } |
256 | QString CalendarLocal::nextSummary() const | 277 | QString CalendarLocal::nextSummary() const |
257 | { | 278 | { |
258 | return mNextSummary; | 279 | return mNextSummary; |
259 | } | 280 | } |
260 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 281 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
261 | { | 282 | { |
262 | return mNextAlarmEventDateTime; | 283 | return mNextAlarmEventDateTime; |
263 | } | 284 | } |
264 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 285 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
265 | { | 286 | { |
266 | //mNextAlarmIncidence | 287 | //mNextAlarmIncidence |
267 | //mNextAlarmDateTime | 288 | //mNextAlarmDateTime |
268 | //return mNextSummary; | 289 | //return mNextSummary; |
269 | //return mNextAlarmEventDateTime; | 290 | //return mNextAlarmEventDateTime; |
270 | bool newNextAlarm = false; | 291 | bool newNextAlarm = false; |
271 | bool computeNextAlarm = false; | 292 | bool computeNextAlarm = false; |
272 | bool ok; | 293 | bool ok; |
273 | int offset; | 294 | int offset; |
274 | QDateTime nextA; | 295 | QDateTime nextA; |
275 | // QString nextSum; | 296 | // QString nextSum; |
276 | //QDateTime nextEvent; | 297 | //QDateTime nextEvent; |
277 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 298 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
278 | computeNextAlarm = true; | 299 | computeNextAlarm = true; |
279 | } else { | 300 | } else { |
280 | if ( ! deleted ) { | 301 | if ( ! deleted ) { |
281 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 302 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
282 | if ( ok ) { | 303 | if ( ok ) { |
283 | if ( nextA < mNextAlarmDateTime ) { | 304 | if ( nextA < mNextAlarmDateTime ) { |
284 | deRegisterAlarm(); | 305 | deRegisterAlarm(); |
285 | mNextAlarmDateTime = nextA; | 306 | mNextAlarmDateTime = nextA; |
286 | mNextSummary = incidence->summary(); | 307 | mNextSummary = incidence->summary(); |
287 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 308 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
288 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 309 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
289 | newNextAlarm = true; | 310 | newNextAlarm = true; |
290 | mNextAlarmIncidence = incidence; | 311 | mNextAlarmIncidence = incidence; |
291 | } else { | 312 | } else { |
292 | if ( incidence == mNextAlarmIncidence ) { | 313 | if ( incidence == mNextAlarmIncidence ) { |
293 | computeNextAlarm = true; | 314 | computeNextAlarm = true; |
294 | } | 315 | } |
295 | } | 316 | } |
296 | } else { | 317 | } else { |
297 | if ( mNextAlarmIncidence == incidence ) { | 318 | if ( mNextAlarmIncidence == incidence ) { |
298 | computeNextAlarm = true; | 319 | computeNextAlarm = true; |
299 | } | 320 | } |
300 | } | 321 | } |
301 | } else { // deleted | 322 | } else { // deleted |
302 | if ( incidence == mNextAlarmIncidence ) { | 323 | if ( incidence == mNextAlarmIncidence ) { |
303 | computeNextAlarm = true; | 324 | computeNextAlarm = true; |
304 | } | 325 | } |
305 | } | 326 | } |
306 | } | 327 | } |
307 | if ( computeNextAlarm ) { | 328 | if ( computeNextAlarm ) { |
308 | deRegisterAlarm(); | 329 | deRegisterAlarm(); |
309 | nextA = nextAlarm( 1000 ); | 330 | nextA = nextAlarm( 1000 ); |
310 | if (! mNextAlarmIncidence ) { | 331 | if (! mNextAlarmIncidence ) { |
311 | return; | 332 | return; |
312 | } | 333 | } |
313 | newNextAlarm = true; | 334 | newNextAlarm = true; |
314 | } | 335 | } |
315 | if ( newNextAlarm ) | 336 | if ( newNextAlarm ) |
316 | registerAlarm(); | 337 | registerAlarm(); |
317 | } | 338 | } |
318 | QString CalendarLocal:: getAlarmNotification() | 339 | QString CalendarLocal:: getAlarmNotification() |
319 | { | 340 | { |
320 | QString ret; | 341 | QString ret; |
321 | // this should not happen | 342 | // this should not happen |
322 | if (! mNextAlarmIncidence ) | 343 | if (! mNextAlarmIncidence ) |
323 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 344 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
324 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 345 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
325 | if ( alarm->type() == Alarm::Procedure ) { | 346 | if ( alarm->type() == Alarm::Procedure ) { |
326 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 347 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
327 | } else { | 348 | } else { |
328 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 349 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
329 | } | 350 | } |
330 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 351 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
331 | if ( mNextSummary.length() > 25 ) | 352 | if ( mNextSummary.length() > 25 ) |
332 | ret += "\n" + mNextSummary.mid(25, 25 ); | 353 | ret += "\n" + mNextSummary.mid(25, 25 ); |
333 | ret+= "\n"+mNextAlarmEventDateTimeString; | 354 | ret+= "\n"+mNextAlarmEventDateTimeString; |
334 | return ret; | 355 | return ret; |
335 | } | 356 | } |
336 | void CalendarLocal::registerAlarm() | 357 | void CalendarLocal::registerAlarm() |
337 | { | 358 | { |
338 | mLastAlarmNotificationString = getAlarmNotification(); | 359 | mLastAlarmNotificationString = getAlarmNotification(); |
339 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 360 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
340 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 361 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
341 | // #ifndef DESKTOP_VERSION | 362 | // #ifndef DESKTOP_VERSION |
342 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 363 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
343 | // #endif | 364 | // #endif |
344 | } | 365 | } |
345 | void CalendarLocal::deRegisterAlarm() | 366 | void CalendarLocal::deRegisterAlarm() |
346 | { | 367 | { |
347 | if ( mLastAlarmNotificationString.isNull() ) | 368 | if ( mLastAlarmNotificationString.isNull() ) |
348 | return; | 369 | return; |
349 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 370 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
350 | 371 | ||
351 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 372 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
352 | // #ifndef DESKTOP_VERSION | 373 | // #ifndef DESKTOP_VERSION |
353 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 374 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
354 | // #endif | 375 | // #endif |
355 | } | 376 | } |
356 | 377 | ||
357 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 378 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
358 | { | 379 | { |
359 | QPtrList<Todo> todos; | 380 | QPtrList<Todo> todos; |
360 | 381 | ||
361 | Todo *todo; | 382 | Todo *todo; |
362 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 383 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
363 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 384 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
364 | todos.append( todo ); | 385 | todos.append( todo ); |
365 | } | 386 | } |
366 | } | 387 | } |
367 | 388 | ||
368 | filter()->apply( &todos ); | 389 | filter()->apply( &todos ); |
369 | return todos; | 390 | return todos; |
370 | } | 391 | } |
371 | void CalendarLocal::reInitAlarmSettings() | 392 | void CalendarLocal::reInitAlarmSettings() |
372 | { | 393 | { |
373 | if ( !mNextAlarmIncidence ) { | 394 | if ( !mNextAlarmIncidence ) { |
374 | nextAlarm( 1000 ); | 395 | nextAlarm( 1000 ); |
375 | } | 396 | } |
376 | deRegisterAlarm(); | 397 | deRegisterAlarm(); |
377 | mNextAlarmIncidence = 0; | 398 | mNextAlarmIncidence = 0; |
378 | checkAlarmForIncidence( 0, false ); | 399 | checkAlarmForIncidence( 0, false ); |
379 | 400 | ||
380 | } | 401 | } |
381 | 402 | ||
382 | 403 | ||
383 | 404 | ||
384 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 405 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
385 | { | 406 | { |
386 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 407 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
387 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 408 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
388 | QDateTime next; | 409 | QDateTime next; |
389 | Event *e; | 410 | Event *e; |
390 | bool ok; | 411 | bool ok; |
391 | bool found = false; | 412 | bool found = false; |
392 | int offset; | 413 | int offset; |
393 | mNextAlarmIncidence = 0; | 414 | mNextAlarmIncidence = 0; |
394 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 415 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
395 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 416 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
396 | if ( ok ) { | 417 | if ( ok ) { |
397 | if ( next < nextA ) { | 418 | if ( next < nextA ) { |
398 | nextA = next; | 419 | nextA = next; |
399 | found = true; | 420 | found = true; |
400 | mNextSummary = e->summary(); | 421 | mNextSummary = e->summary(); |
401 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 422 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
402 | mNextAlarmIncidence = (Incidence *) e; | 423 | mNextAlarmIncidence = (Incidence *) e; |
403 | } | 424 | } |
404 | } | 425 | } |
405 | } | 426 | } |
406 | Todo *t; | 427 | Todo *t; |
407 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 428 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
408 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 429 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
409 | if ( ok ) { | 430 | if ( ok ) { |
410 | if ( next < nextA ) { | 431 | if ( next < nextA ) { |
411 | nextA = next; | 432 | nextA = next; |
412 | found = true; | 433 | found = true; |
413 | mNextSummary = t->summary(); | 434 | mNextSummary = t->summary(); |
414 | mNextAlarmEventDateTime = next.addSecs(offset ); | 435 | mNextAlarmEventDateTime = next.addSecs(offset ); |
415 | mNextAlarmIncidence = (Incidence *) t; | 436 | mNextAlarmIncidence = (Incidence *) t; |
416 | } | 437 | } |
417 | } | 438 | } |
418 | } | 439 | } |
419 | if ( mNextAlarmIncidence ) { | 440 | if ( mNextAlarmIncidence ) { |
420 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 441 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
421 | mNextAlarmDateTime = nextA; | 442 | mNextAlarmDateTime = nextA; |
422 | } | 443 | } |
423 | return nextA; | 444 | return nextA; |
424 | } | 445 | } |
425 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 446 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
426 | { | 447 | { |
427 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 448 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
428 | } | 449 | } |
429 | 450 | ||
430 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 451 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
431 | { | 452 | { |
432 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 453 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
433 | << to.toString() << ")\n"; | 454 | << to.toString() << ")\n"; |
434 | 455 | ||
435 | Alarm::List alarms; | 456 | Alarm::List alarms; |
436 | 457 | ||
437 | Event *e; | 458 | Event *e; |
438 | 459 | ||
439 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 460 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
440 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 461 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
441 | else appendAlarms( alarms, e, from, to ); | 462 | else appendAlarms( alarms, e, from, to ); |
442 | } | 463 | } |
443 | 464 | ||
444 | Todo *t; | 465 | Todo *t; |
445 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 466 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
446 | appendAlarms( alarms, t, from, to ); | 467 | appendAlarms( alarms, t, from, to ); |
447 | } | 468 | } |
448 | 469 | ||
449 | return alarms; | 470 | return alarms; |
450 | } | 471 | } |
451 | 472 | ||
452 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 473 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
453 | const QDateTime &from, const QDateTime &to ) | 474 | const QDateTime &from, const QDateTime &to ) |
454 | { | 475 | { |
455 | QPtrList<Alarm> alarmList = incidence->alarms(); | 476 | QPtrList<Alarm> alarmList = incidence->alarms(); |
456 | Alarm *alarm; | 477 | Alarm *alarm; |
457 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 478 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
458 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 479 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
459 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 480 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
460 | if ( alarm->enabled() ) { | 481 | if ( alarm->enabled() ) { |
461 | if ( alarm->time() >= from && alarm->time() <= to ) { | 482 | if ( alarm->time() >= from && alarm->time() <= to ) { |
462 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 483 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
463 | << "': " << alarm->time().toString() << endl; | 484 | << "': " << alarm->time().toString() << endl; |
464 | alarms.append( alarm ); | 485 | alarms.append( alarm ); |
465 | } | 486 | } |
466 | } | 487 | } |
467 | } | 488 | } |
468 | } | 489 | } |
469 | 490 | ||
470 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 491 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
471 | Incidence *incidence, | 492 | Incidence *incidence, |
472 | const QDateTime &from, | 493 | const QDateTime &from, |
473 | const QDateTime &to ) | 494 | const QDateTime &to ) |
474 | { | 495 | { |
475 | 496 | ||
476 | QPtrList<Alarm> alarmList = incidence->alarms(); | 497 | QPtrList<Alarm> alarmList = incidence->alarms(); |
477 | Alarm *alarm; | 498 | Alarm *alarm; |
478 | QDateTime qdt; | 499 | QDateTime qdt; |
479 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 500 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
480 | if (incidence->recursOn(from.date())) { | 501 | if (incidence->recursOn(from.date())) { |
481 | qdt.setTime(alarm->time().time()); | 502 | qdt.setTime(alarm->time().time()); |
482 | qdt.setDate(from.date()); | 503 | qdt.setDate(from.date()); |
483 | } | 504 | } |
484 | else qdt = alarm->time(); | 505 | else qdt = alarm->time(); |
485 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 506 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
486 | if ( alarm->enabled() ) { | 507 | if ( alarm->enabled() ) { |
487 | if ( qdt >= from && qdt <= to ) { | 508 | if ( qdt >= from && qdt <= to ) { |
488 | alarms.append( alarm ); | 509 | alarms.append( alarm ); |
489 | } | 510 | } |
490 | } | 511 | } |
491 | } | 512 | } |
492 | } | 513 | } |
493 | 514 | ||
494 | 515 | ||
495 | /****************************** PROTECTED METHODS ****************************/ | 516 | /****************************** PROTECTED METHODS ****************************/ |
496 | 517 | ||
497 | // after changes are made to an event, this should be called. | 518 | // after changes are made to an event, this should be called. |
498 | void CalendarLocal::update( IncidenceBase *incidence ) | 519 | void CalendarLocal::update( IncidenceBase *incidence ) |
499 | { | 520 | { |
500 | incidence->setSyncStatus( Event::SYNCMOD ); | 521 | incidence->setSyncStatus( Event::SYNCMOD ); |
501 | incidence->setLastModified( QDateTime::currentDateTime() ); | 522 | incidence->setLastModified( QDateTime::currentDateTime() ); |
502 | // we should probably update the revision number here, | 523 | // we should probably update the revision number here, |
503 | // or internally in the Event itself when certain things change. | 524 | // or internally in the Event itself when certain things change. |
504 | // need to verify with ical documentation. | 525 | // need to verify with ical documentation. |
505 | 526 | ||
506 | setModified( true ); | 527 | setModified( true ); |
507 | } | 528 | } |
508 | 529 | ||
509 | void CalendarLocal::insertEvent( Event *event ) | 530 | void CalendarLocal::insertEvent( Event *event ) |
510 | { | 531 | { |
511 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 532 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
512 | } | 533 | } |
513 | 534 | ||
514 | 535 | ||
515 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 536 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
516 | { | 537 | { |
517 | QPtrList<Event> eventList; | 538 | QPtrList<Event> eventList; |
518 | 539 | ||
519 | Event *event; | 540 | Event *event; |
520 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 541 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
521 | if ( event->doesRecur() ) { | 542 | if ( event->doesRecur() ) { |
522 | if ( event->isMultiDay() ) { | 543 | if ( event->isMultiDay() ) { |
523 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 544 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
524 | int i; | 545 | int i; |
525 | for ( i = 0; i <= extraDays; i++ ) { | 546 | for ( i = 0; i <= extraDays; i++ ) { |
526 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 547 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
527 | eventList.append( event ); | 548 | eventList.append( event ); |
528 | break; | 549 | break; |
529 | } | 550 | } |
530 | } | 551 | } |
531 | } else { | 552 | } else { |
532 | if ( event->recursOn( qd ) ) | 553 | if ( event->recursOn( qd ) ) |
533 | eventList.append( event ); | 554 | eventList.append( event ); |
534 | } | 555 | } |
535 | } else { | 556 | } else { |
536 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 557 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
537 | eventList.append( event ); | 558 | eventList.append( event ); |
538 | } | 559 | } |
539 | } | 560 | } |
540 | } | 561 | } |
541 | 562 | ||
542 | if ( !sorted ) { | 563 | if ( !sorted ) { |
543 | return eventList; | 564 | return eventList; |
544 | } | 565 | } |
545 | 566 | ||
546 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 567 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
547 | // now, we have to sort it based on dtStart.time() | 568 | // now, we have to sort it based on dtStart.time() |
548 | QPtrList<Event> eventListSorted; | 569 | QPtrList<Event> eventListSorted; |
549 | Event *sortEvent; | 570 | Event *sortEvent; |
550 | for ( event = eventList.first(); event; event = eventList.next() ) { | 571 | for ( event = eventList.first(); event; event = eventList.next() ) { |
551 | sortEvent = eventListSorted.first(); | 572 | sortEvent = eventListSorted.first(); |
552 | int i = 0; | 573 | int i = 0; |
553 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 574 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
554 | { | 575 | { |
555 | i++; | 576 | i++; |
556 | sortEvent = eventListSorted.next(); | 577 | sortEvent = eventListSorted.next(); |
557 | } | 578 | } |
558 | eventListSorted.insert( i, event ); | 579 | eventListSorted.insert( i, event ); |
559 | } | 580 | } |
560 | return eventListSorted; | 581 | return eventListSorted; |
561 | } | 582 | } |
562 | 583 | ||
563 | 584 | ||
564 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 585 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
565 | bool inclusive ) | 586 | bool inclusive ) |
566 | { | 587 | { |
567 | Event *event = 0; | 588 | Event *event = 0; |
568 | 589 | ||
569 | QPtrList<Event> eventList; | 590 | QPtrList<Event> eventList; |
570 | 591 | ||
571 | // Get non-recurring events | 592 | // Get non-recurring events |
572 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 593 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
573 | if ( event->doesRecur() ) { | 594 | if ( event->doesRecur() ) { |
574 | QDate rStart = event->dtStart().date(); | 595 | QDate rStart = event->dtStart().date(); |
575 | bool found = false; | 596 | bool found = false; |
576 | if ( inclusive ) { | 597 | if ( inclusive ) { |
577 | if ( rStart >= start && rStart <= end ) { | 598 | if ( rStart >= start && rStart <= end ) { |
578 | // Start date of event is in range. Now check for end date. | 599 | // Start date of event is in range. Now check for end date. |
579 | // if duration is negative, event recurs forever, so do not include it. | 600 | // if duration is negative, event recurs forever, so do not include it. |
580 | if ( event->recurrence()->duration() == 0 ) { // End date set | 601 | if ( event->recurrence()->duration() == 0 ) { // End date set |
581 | QDate rEnd = event->recurrence()->endDate(); | 602 | QDate rEnd = event->recurrence()->endDate(); |
582 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 603 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
583 | found = true; | 604 | found = true; |
584 | } | 605 | } |
585 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 606 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
586 | // TODO: Calculate end date from duration. Should be done in Event | 607 | // TODO: Calculate end date from duration. Should be done in Event |
587 | // For now exclude all events with a duration. | 608 | // For now exclude all events with a duration. |
588 | } | 609 | } |
589 | } | 610 | } |
590 | } else { | 611 | } else { |
591 | bool founOne; | 612 | bool founOne; |
592 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 613 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
593 | if ( founOne ) { | 614 | if ( founOne ) { |
594 | if ( next <= end ) { | 615 | if ( next <= end ) { |
595 | found = true; | 616 | found = true; |
596 | } | 617 | } |
597 | } | 618 | } |
598 | 619 | ||
599 | /* | 620 | /* |
600 | // crap !!! | 621 | // crap !!! |
601 | if ( rStart <= end ) { // Start date not after range | 622 | if ( rStart <= end ) { // Start date not after range |
602 | if ( rStart >= start ) { // Start date within range | 623 | if ( rStart >= start ) { // Start date within range |
603 | found = true; | 624 | found = true; |
604 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 625 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
605 | found = true; | 626 | found = true; |
606 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 627 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
607 | QDate rEnd = event->recurrence()->endDate(); | 628 | QDate rEnd = event->recurrence()->endDate(); |
608 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 629 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
609 | found = true; | 630 | found = true; |
610 | } | 631 | } |
611 | } else { // Duration set | 632 | } else { // Duration set |
612 | // TODO: Calculate end date from duration. Should be done in Event | 633 | // TODO: Calculate end date from duration. Should be done in Event |
613 | // For now include all events with a duration. | 634 | // For now include all events with a duration. |
614 | found = true; | 635 | found = true; |
615 | } | 636 | } |
616 | } | 637 | } |
617 | */ | 638 | */ |
618 | 639 | ||
619 | } | 640 | } |
620 | 641 | ||
621 | if ( found ) eventList.append( event ); | 642 | if ( found ) eventList.append( event ); |
622 | } else { | 643 | } else { |
623 | QDate s = event->dtStart().date(); | 644 | QDate s = event->dtStart().date(); |
624 | QDate e = event->dtEnd().date(); | 645 | QDate e = event->dtEnd().date(); |
625 | 646 | ||
626 | if ( inclusive ) { | 647 | if ( inclusive ) { |
627 | if ( s >= start && e <= end ) { | 648 | if ( s >= start && e <= end ) { |
628 | eventList.append( event ); | 649 | eventList.append( event ); |
629 | } | 650 | } |
630 | } else { | 651 | } else { |
631 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 652 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
632 | eventList.append( event ); | 653 | eventList.append( event ); |
633 | } | 654 | } |
634 | } | 655 | } |
635 | } | 656 | } |
636 | } | 657 | } |
637 | 658 | ||
638 | return eventList; | 659 | return eventList; |
639 | } | 660 | } |
640 | 661 | ||
641 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 662 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
642 | { | 663 | { |
643 | return rawEventsForDate( qdt.date() ); | 664 | return rawEventsForDate( qdt.date() ); |
644 | } | 665 | } |
645 | 666 | ||
646 | QPtrList<Event> CalendarLocal::rawEvents() | 667 | QPtrList<Event> CalendarLocal::rawEvents() |
647 | { | 668 | { |
648 | return mEventList; | 669 | return mEventList; |
649 | } | 670 | } |
650 | 671 | ||
651 | bool CalendarLocal::addJournal(Journal *journal) | 672 | bool CalendarLocal::addJournal(Journal *journal) |
652 | { | 673 | { |
653 | if ( journal->dtStart().isValid()) | 674 | if ( journal->dtStart().isValid()) |
654 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 675 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
655 | else | 676 | else |
656 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 677 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
657 | 678 | ||
658 | mJournalList.append(journal); | 679 | mJournalList.append(journal); |
659 | 680 | ||
660 | journal->registerObserver( this ); | 681 | journal->registerObserver( this ); |
661 | 682 | ||
662 | setModified( true ); | 683 | setModified( true ); |
663 | 684 | ||
664 | return true; | 685 | return true; |
665 | } | 686 | } |
666 | 687 | ||
667 | void CalendarLocal::deleteJournal( Journal *journal ) | 688 | void CalendarLocal::deleteJournal( Journal *journal ) |
668 | { | 689 | { |
669 | if ( mJournalList.removeRef(journal) ) { | 690 | if ( mJournalList.removeRef(journal) ) { |
670 | setModified( true ); | 691 | setModified( true ); |
671 | } | 692 | } |
672 | } | 693 | } |
673 | 694 | ||
674 | Journal *CalendarLocal::journal( const QDate &date ) | 695 | Journal *CalendarLocal::journal( const QDate &date ) |
675 | { | 696 | { |
676 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 697 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
677 | 698 | ||
678 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 699 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
679 | if ( it->dtStart().date() == date ) | 700 | if ( it->dtStart().date() == date ) |
680 | return it; | 701 | return it; |
681 | 702 | ||
682 | return 0; | 703 | return 0; |
683 | } | 704 | } |
684 | 705 | ||
685 | Journal *CalendarLocal::journal( const QString &uid ) | 706 | Journal *CalendarLocal::journal( const QString &uid ) |
686 | { | 707 | { |
687 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 708 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
688 | if ( it->uid() == uid ) | 709 | if ( it->uid() == uid ) |
689 | return it; | 710 | return it; |
690 | 711 | ||
691 | return 0; | 712 | return 0; |
692 | } | 713 | } |
693 | 714 | ||
694 | QPtrList<Journal> CalendarLocal::journals() | 715 | QPtrList<Journal> CalendarLocal::journals() |
695 | { | 716 | { |
696 | return mJournalList; | 717 | return mJournalList; |
697 | } | 718 | } |
698 | 719 | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 5b6c64c..98ec710 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,217 +1,218 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 48 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
49 | calendar. Any information already present is lost. | 49 | calendar. Any information already present is lost. |
50 | @return true, if successfull, false on error. | 50 | @return true, if successfull, false on error. |
51 | @param fileName the name of the calendar on disk. | 51 | @param fileName the name of the calendar on disk. |
52 | */ | 52 | */ |
53 | bool load( const QString &fileName ); | 53 | bool load( const QString &fileName ); |
54 | /** | 54 | /** |
55 | Writes out the calendar to disk in the specified \a format. | 55 | Writes out the calendar to disk in the specified \a format. |
56 | CalendarLocal takes ownership of the CalFormat object. | 56 | CalendarLocal takes ownership of the CalFormat object. |
57 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
58 | @param fileName the name of the file | 58 | @param fileName the name of the file |
59 | */ | 59 | */ |
60 | bool save( const QString &fileName, CalFormat *format = 0 ); | 60 | bool save( const QString &fileName, CalFormat *format = 0 ); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | Clears out the current calendar, freeing all used memory etc. etc. | 63 | Clears out the current calendar, freeing all used memory etc. etc. |
64 | */ | 64 | */ |
65 | void close(); | 65 | void close(); |
66 | 66 | ||
67 | void save() {} | 67 | void save() {} |
68 | 68 | ||
69 | /** | 69 | /** |
70 | Add Event to calendar. | 70 | Add Event to calendar. |
71 | */ | 71 | */ |
72 | void removeSyncInfo( QString syncProfile); | ||
72 | bool addAnniversaryNoDup( Event *event ); | 73 | bool addAnniversaryNoDup( Event *event ); |
73 | bool addEventNoDup( Event *event ); | 74 | bool addEventNoDup( Event *event ); |
74 | bool addEvent( Event *event ); | 75 | bool addEvent( Event *event ); |
75 | /** | 76 | /** |
76 | Deletes an event from this calendar. | 77 | Deletes an event from this calendar. |
77 | */ | 78 | */ |
78 | void deleteEvent( Event *event ); | 79 | void deleteEvent( Event *event ); |
79 | 80 | ||
80 | /** | 81 | /** |
81 | Retrieves an event on the basis of the unique string ID. | 82 | Retrieves an event on the basis of the unique string ID. |
82 | */ | 83 | */ |
83 | Event *event( const QString &uid ); | 84 | Event *event( const QString &uid ); |
84 | /** | 85 | /** |
85 | Return unfiltered list of all events in calendar. | 86 | Return unfiltered list of all events in calendar. |
86 | */ | 87 | */ |
87 | QPtrList<Event> rawEvents(); | 88 | QPtrList<Event> rawEvents(); |
88 | QPtrList<Event> getExternLastSyncEvents(); | 89 | QPtrList<Event> getExternLastSyncEvents(); |
89 | /** | 90 | /** |
90 | Add a todo to the todolist. | 91 | Add a todo to the todolist. |
91 | */ | 92 | */ |
92 | bool addTodo( Todo *todo ); | 93 | bool addTodo( Todo *todo ); |
93 | bool addTodoNoDup( Todo *todo ); | 94 | bool addTodoNoDup( Todo *todo ); |
94 | /** | 95 | /** |
95 | Remove a todo from the todolist. | 96 | Remove a todo from the todolist. |
96 | */ | 97 | */ |
97 | void deleteTodo( Todo * ); | 98 | void deleteTodo( Todo * ); |
98 | /** | 99 | /** |
99 | Searches todolist for an event with this unique string identifier, | 100 | Searches todolist for an event with this unique string identifier, |
100 | returns a pointer or null. | 101 | returns a pointer or null. |
101 | */ | 102 | */ |
102 | Todo *todo( const QString &uid ); | 103 | Todo *todo( const QString &uid ); |
103 | /** | 104 | /** |
104 | Return list of all todos. | 105 | Return list of all todos. |
105 | */ | 106 | */ |
106 | QPtrList<Todo> rawTodos(); | 107 | QPtrList<Todo> rawTodos(); |
107 | /** | 108 | /** |
108 | Returns list of todos due on the specified date. | 109 | Returns list of todos due on the specified date. |
109 | */ | 110 | */ |
110 | QPtrList<Todo> todos( const QDate &date ); | 111 | QPtrList<Todo> todos( const QDate &date ); |
111 | /** | 112 | /** |
112 | Return list of all todos. | 113 | Return list of all todos. |
113 | 114 | ||
114 | Workaround because compiler does not recognize function of base class. | 115 | Workaround because compiler does not recognize function of base class. |
115 | */ | 116 | */ |
116 | QPtrList<Todo> todos() { return Calendar::todos(); } | 117 | QPtrList<Todo> todos() { return Calendar::todos(); } |
117 | 118 | ||
118 | /** | 119 | /** |
119 | Add a Journal entry to calendar. | 120 | Add a Journal entry to calendar. |
120 | */ | 121 | */ |
121 | bool addJournal( Journal * ); | 122 | bool addJournal( Journal * ); |
122 | /** | 123 | /** |
123 | Remove a Journal from the calendar. | 124 | Remove a Journal from the calendar. |
124 | */ | 125 | */ |
125 | void deleteJournal( Journal * ); | 126 | void deleteJournal( Journal * ); |
126 | /** | 127 | /** |
127 | Return Journal for given date. | 128 | Return Journal for given date. |
128 | */ | 129 | */ |
129 | Journal *journal( const QDate & ); | 130 | Journal *journal( const QDate & ); |
130 | /** | 131 | /** |
131 | Return Journal with given UID. | 132 | Return Journal with given UID. |
132 | */ | 133 | */ |
133 | Journal *journal( const QString &uid ); | 134 | Journal *journal( const QString &uid ); |
134 | /** | 135 | /** |
135 | Return list of all Journals stored in calendar. | 136 | Return list of all Journals stored in calendar. |
136 | */ | 137 | */ |
137 | QPtrList<Journal> journals(); | 138 | QPtrList<Journal> journals(); |
138 | 139 | ||
139 | /** | 140 | /** |
140 | Return all alarms, which ocur in the given time interval. | 141 | Return all alarms, which ocur in the given time interval. |
141 | */ | 142 | */ |
142 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 143 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
143 | 144 | ||
144 | /** | 145 | /** |
145 | Return all alarms, which ocur before given date. | 146 | Return all alarms, which ocur before given date. |
146 | */ | 147 | */ |
147 | Alarm::List alarmsTo( const QDateTime &to ); | 148 | Alarm::List alarmsTo( const QDateTime &to ); |
148 | 149 | ||
149 | QDateTime nextAlarm( int daysTo ) ; | 150 | QDateTime nextAlarm( int daysTo ) ; |
150 | QDateTime nextAlarmEventDateTime() const; | 151 | QDateTime nextAlarmEventDateTime() const; |
151 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 152 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
152 | void registerAlarm(); | 153 | void registerAlarm(); |
153 | void deRegisterAlarm(); | 154 | void deRegisterAlarm(); |
154 | QString getAlarmNotification(); | 155 | QString getAlarmNotification(); |
155 | QString nextSummary() const ; | 156 | QString nextSummary() const ; |
156 | /** | 157 | /** |
157 | This method should be called whenever a Event is modified directly | 158 | This method should be called whenever a Event is modified directly |
158 | via it's pointer. It makes sure that the calendar is internally | 159 | via it's pointer. It makes sure that the calendar is internally |
159 | consistent. | 160 | consistent. |
160 | */ | 161 | */ |
161 | void update( IncidenceBase *incidence ); | 162 | void update( IncidenceBase *incidence ); |
162 | 163 | ||
163 | /** | 164 | /** |
164 | Builds and then returns a list of all events that match for the | 165 | Builds and then returns a list of all events that match for the |
165 | date specified. useful for dayView, etc. etc. | 166 | date specified. useful for dayView, etc. etc. |
166 | */ | 167 | */ |
167 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 168 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
168 | /** | 169 | /** |
169 | Get unfiltered events for date \a qdt. | 170 | Get unfiltered events for date \a qdt. |
170 | */ | 171 | */ |
171 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 172 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
172 | /** | 173 | /** |
173 | Get unfiltered events in a range of dates. If inclusive is set to true, | 174 | Get unfiltered events in a range of dates. If inclusive is set to true, |
174 | only events are returned, which are completely included in the range. | 175 | only events are returned, which are completely included in the range. |
175 | */ | 176 | */ |
176 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 177 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
177 | bool inclusive = false ); | 178 | bool inclusive = false ); |
178 | Todo *todo( QString, QString ); | 179 | Todo *todo( QString, QString ); |
179 | Event *event( QString, QString ); | 180 | Event *event( QString, QString ); |
180 | 181 | ||
181 | 182 | ||
182 | 183 | ||
183 | protected: | 184 | protected: |
184 | 185 | ||
185 | // Event* mNextAlarmEvent; | 186 | // Event* mNextAlarmEvent; |
186 | QString mNextSummary; | 187 | QString mNextSummary; |
187 | QString mNextAlarmEventDateTimeString; | 188 | QString mNextAlarmEventDateTimeString; |
188 | QString mLastAlarmNotificationString; | 189 | QString mLastAlarmNotificationString; |
189 | QDateTime mNextAlarmEventDateTime; | 190 | QDateTime mNextAlarmEventDateTime; |
190 | QDateTime mNextAlarmDateTime; | 191 | QDateTime mNextAlarmDateTime; |
191 | void reInitAlarmSettings(); | 192 | void reInitAlarmSettings(); |
192 | 193 | ||
193 | /** Notification function of IncidenceBase::Observer. */ | 194 | /** Notification function of IncidenceBase::Observer. */ |
194 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 195 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
195 | 196 | ||
196 | /** inserts an event into its "proper place" in the calendar. */ | 197 | /** inserts an event into its "proper place" in the calendar. */ |
197 | void insertEvent( Event *event ); | 198 | void insertEvent( Event *event ); |
198 | 199 | ||
199 | /** Append alarms of incidence in interval to list of alarms. */ | 200 | /** Append alarms of incidence in interval to list of alarms. */ |
200 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 201 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
201 | const QDateTime &from, const QDateTime &to ); | 202 | const QDateTime &from, const QDateTime &to ); |
202 | 203 | ||
203 | /** Append alarms of recurring events in interval to list of alarms. */ | 204 | /** Append alarms of recurring events in interval to list of alarms. */ |
204 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 205 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
205 | const QDateTime &from, const QDateTime &to ); | 206 | const QDateTime &from, const QDateTime &to ); |
206 | 207 | ||
207 | private: | 208 | private: |
208 | void init(); | 209 | void init(); |
209 | 210 | ||
210 | QPtrList<Event> mEventList; | 211 | QPtrList<Event> mEventList; |
211 | QPtrList<Todo> mTodoList; | 212 | QPtrList<Todo> mTodoList; |
212 | QPtrList<Journal> mJournalList; | 213 | QPtrList<Journal> mJournalList; |
213 | }; | 214 | }; |
214 | 215 | ||
215 | } | 216 | } |
216 | 217 | ||
217 | #endif | 218 | #endif |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index b36dc1a..9aa517c 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,407 +1,410 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
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 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | #include <kidmanager.h> | 24 | #include <kidmanager.h> |
25 | 25 | ||
26 | #include "calformat.h" | 26 | #include "calformat.h" |
27 | #include "syncdefines.h" | 27 | #include "syncdefines.h" |
28 | 28 | ||
29 | #include "incidencebase.h" | 29 | #include "incidencebase.h" |
30 | 30 | ||
31 | using namespace KCal; | 31 | using namespace KCal; |
32 | 32 | ||
33 | IncidenceBase::IncidenceBase() : | 33 | IncidenceBase::IncidenceBase() : |
34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
35 | mPilotId(0), mSyncStatus(SYNCMOD) | 35 | mPilotId(0), mSyncStatus(SYNCMOD) |
36 | { | 36 | { |
37 | setUid(CalFormat::createUniqueId()); | 37 | setUid(CalFormat::createUniqueId()); |
38 | mOrganizer = ""; | 38 | mOrganizer = ""; |
39 | mFloats = false; | 39 | mFloats = false; |
40 | mDuration = 0; | 40 | mDuration = 0; |
41 | mHasDuration = false; | 41 | mHasDuration = false; |
42 | mPilotId = 0; | 42 | mPilotId = 0; |
43 | mExternalId = ":"; | 43 | mExternalId = ":"; |
44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
45 | mSyncStatus = 0; | 45 | mSyncStatus = 0; |
46 | mAttendees.setAutoDelete( true ); | 46 | mAttendees.setAutoDelete( true ); |
47 | } | 47 | } |
48 | 48 | ||
49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
50 | CustomProperties( i ) | 50 | CustomProperties( i ) |
51 | { | 51 | { |
52 | mReadOnly = i.mReadOnly; | 52 | mReadOnly = i.mReadOnly; |
53 | mDtStart = i.mDtStart; | 53 | mDtStart = i.mDtStart; |
54 | mDuration = i.mDuration; | 54 | mDuration = i.mDuration; |
55 | mHasDuration = i.mHasDuration; | 55 | mHasDuration = i.mHasDuration; |
56 | mOrganizer = i.mOrganizer; | 56 | mOrganizer = i.mOrganizer; |
57 | mUid = i.mUid; | 57 | mUid = i.mUid; |
58 | QPtrList<Attendee> attendees = i.attendees(); | 58 | QPtrList<Attendee> attendees = i.attendees(); |
59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
60 | mAttendees.append( new Attendee( *a ) ); | 60 | mAttendees.append( new Attendee( *a ) ); |
61 | } | 61 | } |
62 | mFloats = i.mFloats; | 62 | mFloats = i.mFloats; |
63 | mLastModified = i.mLastModified; | 63 | mLastModified = i.mLastModified; |
64 | mPilotId = i.mPilotId; | 64 | mPilotId = i.mPilotId; |
65 | mTempSyncStat = i.mTempSyncStat; | 65 | mTempSyncStat = i.mTempSyncStat; |
66 | mSyncStatus = i.mSyncStatus; | 66 | mSyncStatus = i.mSyncStatus; |
67 | mExternalId = i.mExternalId; | 67 | mExternalId = i.mExternalId; |
68 | // The copied object is a new one, so it isn't observed by the observer | 68 | // The copied object is a new one, so it isn't observed by the observer |
69 | // of the original object. | 69 | // of the original object. |
70 | mObservers.clear(); | 70 | mObservers.clear(); |
71 | 71 | ||
72 | mAttendees.setAutoDelete( true ); | 72 | mAttendees.setAutoDelete( true ); |
73 | } | 73 | } |
74 | 74 | ||
75 | IncidenceBase::~IncidenceBase() | 75 | IncidenceBase::~IncidenceBase() |
76 | { | 76 | { |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
81 | { | 81 | { |
82 | // do not compare mSyncStatus and mExternalId | 82 | // do not compare mSyncStatus and mExternalId |
83 | if( i1.attendees().count() != i2.attendees().count() ) { | 83 | if( i1.attendees().count() != i2.attendees().count() ) { |
84 | return false; // no need to check further | 84 | return false; // no need to check further |
85 | } | 85 | } |
86 | if ( i1.attendees().count() > 0 ) { | 86 | if ( i1.attendees().count() > 0 ) { |
87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
88 | while ( a1 ) { | 88 | while ( a1 ) { |
89 | if ( !( (*a1) == (*a2)) ) | 89 | if ( !( (*a1) == (*a2)) ) |
90 | { | 90 | { |
91 | //qDebug("Attendee not equal "); | 91 | //qDebug("Attendee not equal "); |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | a1 = i1.attendees().next(); | 94 | a1 = i1.attendees().next(); |
95 | a2 = i2.attendees().next(); | 95 | a2 = i2.attendees().next(); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | //if ( i1.dtStart() != i2.dtStart() ) | 98 | //if ( i1.dtStart() != i2.dtStart() ) |
99 | // return false; | 99 | // return false; |
100 | #if 0 | 100 | #if 0 |
101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
102 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 102 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
107 | 107 | ||
108 | #endif | 108 | #endif |
109 | return ( i1.organizer() == i2.organizer() && | 109 | return ( i1.organizer() == i2.organizer() && |
110 | // i1.uid() == i2.uid() && | 110 | // i1.uid() == i2.uid() && |
111 | // Don't compare lastModified, otherwise the operator is not | 111 | // Don't compare lastModified, otherwise the operator is not |
112 | // of much use. We are not comparing for identity, after all. | 112 | // of much use. We are not comparing for identity, after all. |
113 | i1.doesFloat() == i2.doesFloat() && | 113 | i1.doesFloat() == i2.doesFloat() && |
114 | i1.duration() == i2.duration() && | 114 | i1.duration() == i2.duration() && |
115 | i1.hasDuration() == i2.hasDuration() && | 115 | i1.hasDuration() == i2.hasDuration() && |
116 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 116 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
117 | // no need to compare mObserver | 117 | // no need to compare mObserver |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 121 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
122 | { | 122 | { |
123 | QTime t = dt.time(); | 123 | QTime t = dt.time(); |
124 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 124 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
125 | return dt; | 125 | return dt; |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | void IncidenceBase::setUid(const QString &uid) | 129 | void IncidenceBase::setUid(const QString &uid) |
130 | { | 130 | { |
131 | mUid = uid; | 131 | mUid = uid; |
132 | updated(); | 132 | updated(); |
133 | } | 133 | } |
134 | 134 | ||
135 | QString IncidenceBase::uid() const | 135 | QString IncidenceBase::uid() const |
136 | { | 136 | { |
137 | return mUid; | 137 | return mUid; |
138 | } | 138 | } |
139 | 139 | ||
140 | void IncidenceBase::setLastModified(const QDateTime &lm) | 140 | void IncidenceBase::setLastModified(const QDateTime &lm) |
141 | { | 141 | { |
142 | // DON'T! updated() because we call this from | 142 | // DON'T! updated() because we call this from |
143 | // Calendar::updateEvent(). | 143 | // Calendar::updateEvent(). |
144 | mLastModified = getEvenTime(lm); | 144 | mLastModified = getEvenTime(lm); |
145 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 145 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
146 | } | 146 | } |
147 | 147 | ||
148 | QDateTime IncidenceBase::lastModified() const | 148 | QDateTime IncidenceBase::lastModified() const |
149 | { | 149 | { |
150 | return mLastModified; | 150 | return mLastModified; |
151 | } | 151 | } |
152 | 152 | ||
153 | void IncidenceBase::setOrganizer(const QString &o) | 153 | void IncidenceBase::setOrganizer(const QString &o) |
154 | { | 154 | { |
155 | // we don't check for readonly here, because it is | 155 | // we don't check for readonly here, because it is |
156 | // possible that by setting the organizer we are changing | 156 | // possible that by setting the organizer we are changing |
157 | // the event's readonly status... | 157 | // the event's readonly status... |
158 | mOrganizer = o; | 158 | mOrganizer = o; |
159 | if (mOrganizer.left(7).upper() == "MAILTO:") | 159 | if (mOrganizer.left(7).upper() == "MAILTO:") |
160 | mOrganizer = mOrganizer.remove(0,7); | 160 | mOrganizer = mOrganizer.remove(0,7); |
161 | 161 | ||
162 | updated(); | 162 | updated(); |
163 | } | 163 | } |
164 | 164 | ||
165 | QString IncidenceBase::organizer() const | 165 | QString IncidenceBase::organizer() const |
166 | { | 166 | { |
167 | return mOrganizer; | 167 | return mOrganizer; |
168 | } | 168 | } |
169 | 169 | ||
170 | void IncidenceBase::setReadOnly( bool readOnly ) | 170 | void IncidenceBase::setReadOnly( bool readOnly ) |
171 | { | 171 | { |
172 | mReadOnly = readOnly; | 172 | mReadOnly = readOnly; |
173 | } | 173 | } |
174 | 174 | ||
175 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 175 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
176 | { | 176 | { |
177 | // if (mReadOnly) return; | 177 | // if (mReadOnly) return; |
178 | mDtStart = getEvenTime(dtStart); | 178 | mDtStart = getEvenTime(dtStart); |
179 | updated(); | 179 | updated(); |
180 | } | 180 | } |
181 | 181 | ||
182 | QDateTime IncidenceBase::dtStart() const | 182 | QDateTime IncidenceBase::dtStart() const |
183 | { | 183 | { |
184 | return mDtStart; | 184 | return mDtStart; |
185 | } | 185 | } |
186 | 186 | ||
187 | QString IncidenceBase::dtStartTimeStr() const | 187 | QString IncidenceBase::dtStartTimeStr() const |
188 | { | 188 | { |
189 | return KGlobal::locale()->formatTime(dtStart().time()); | 189 | return KGlobal::locale()->formatTime(dtStart().time()); |
190 | } | 190 | } |
191 | 191 | ||
192 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 192 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
193 | { | 193 | { |
194 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 194 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
195 | } | 195 | } |
196 | 196 | ||
197 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 197 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
198 | { | 198 | { |
199 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 199 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | bool IncidenceBase::doesFloat() const | 203 | bool IncidenceBase::doesFloat() const |
204 | { | 204 | { |
205 | return mFloats; | 205 | return mFloats; |
206 | } | 206 | } |
207 | 207 | ||
208 | void IncidenceBase::setFloats(bool f) | 208 | void IncidenceBase::setFloats(bool f) |
209 | { | 209 | { |
210 | if (mReadOnly) return; | 210 | if (mReadOnly) return; |
211 | mFloats = f; | 211 | mFloats = f; |
212 | updated(); | 212 | updated(); |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | void IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 216 | void IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
217 | { | 217 | { |
218 | if (mReadOnly) return; | 218 | if (mReadOnly) return; |
219 | if (a->name().left(7).upper() == "MAILTO:") | 219 | if (a->name().left(7).upper() == "MAILTO:") |
220 | a->setName(a->name().remove(0,7)); | 220 | a->setName(a->name().remove(0,7)); |
221 | 221 | ||
222 | mAttendees.append(a); | 222 | mAttendees.append(a); |
223 | if (doupdate) updated(); | 223 | if (doupdate) updated(); |
224 | } | 224 | } |
225 | 225 | ||
226 | #if 0 | 226 | #if 0 |
227 | void IncidenceBase::removeAttendee(Attendee *a) | 227 | void IncidenceBase::removeAttendee(Attendee *a) |
228 | { | 228 | { |
229 | if (mReadOnly) return; | 229 | if (mReadOnly) return; |
230 | mAttendees.removeRef(a); | 230 | mAttendees.removeRef(a); |
231 | updated(); | 231 | updated(); |
232 | } | 232 | } |
233 | 233 | ||
234 | void IncidenceBase::removeAttendee(const char *n) | 234 | void IncidenceBase::removeAttendee(const char *n) |
235 | { | 235 | { |
236 | Attendee *a; | 236 | Attendee *a; |
237 | 237 | ||
238 | if (mReadOnly) return; | 238 | if (mReadOnly) return; |
239 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 239 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
240 | if (a->getName() == n) { | 240 | if (a->getName() == n) { |
241 | mAttendees.remove(); | 241 | mAttendees.remove(); |
242 | break; | 242 | break; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | #endif | 245 | #endif |
246 | 246 | ||
247 | void IncidenceBase::clearAttendees() | 247 | void IncidenceBase::clearAttendees() |
248 | { | 248 | { |
249 | if (mReadOnly) return; | 249 | if (mReadOnly) return; |
250 | mAttendees.clear(); | 250 | mAttendees.clear(); |
251 | } | 251 | } |
252 | 252 | ||
253 | #if 0 | 253 | #if 0 |
254 | Attendee *IncidenceBase::getAttendee(const char *n) const | 254 | Attendee *IncidenceBase::getAttendee(const char *n) const |
255 | { | 255 | { |
256 | QPtrListIterator<Attendee> qli(mAttendees); | 256 | QPtrListIterator<Attendee> qli(mAttendees); |
257 | 257 | ||
258 | qli.toFirst(); | 258 | qli.toFirst(); |
259 | while (qli) { | 259 | while (qli) { |
260 | if (qli.current()->getName() == n) | 260 | if (qli.current()->getName() == n) |
261 | return qli.current(); | 261 | return qli.current(); |
262 | ++qli; | 262 | ++qli; |
263 | } | 263 | } |
264 | return 0L; | 264 | return 0L; |
265 | } | 265 | } |
266 | #endif | 266 | #endif |
267 | 267 | ||
268 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 268 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
269 | { | 269 | { |
270 | QPtrListIterator<Attendee> qli(mAttendees); | 270 | QPtrListIterator<Attendee> qli(mAttendees); |
271 | 271 | ||
272 | qli.toFirst(); | 272 | qli.toFirst(); |
273 | while (qli) { | 273 | while (qli) { |
274 | if (qli.current()->email().lower() == email.lower()) | 274 | if (qli.current()->email().lower() == email.lower()) |
275 | return qli.current(); | 275 | return qli.current(); |
276 | ++qli; | 276 | ++qli; |
277 | } | 277 | } |
278 | return 0L; | 278 | return 0L; |
279 | } | 279 | } |
280 | 280 | ||
281 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 281 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
282 | { | 282 | { |
283 | QPtrListIterator<Attendee> qli(mAttendees); | 283 | QPtrListIterator<Attendee> qli(mAttendees); |
284 | 284 | ||
285 | QStringList mails = emails; | 285 | QStringList mails = emails; |
286 | if (!email.isEmpty()) { | 286 | if (!email.isEmpty()) { |
287 | mails.append(email); | 287 | mails.append(email); |
288 | } | 288 | } |
289 | qli.toFirst(); | 289 | qli.toFirst(); |
290 | while (qli) { | 290 | while (qli) { |
291 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 291 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
292 | if (qli.current()->email().lower() == (*it).lower()) | 292 | if (qli.current()->email().lower() == (*it).lower()) |
293 | return qli.current(); | 293 | return qli.current(); |
294 | } | 294 | } |
295 | 295 | ||
296 | ++qli; | 296 | ++qli; |
297 | } | 297 | } |
298 | return 0L; | 298 | return 0L; |
299 | } | 299 | } |
300 | 300 | ||
301 | void IncidenceBase::setDuration(int seconds) | 301 | void IncidenceBase::setDuration(int seconds) |
302 | { | 302 | { |
303 | mDuration = seconds; | 303 | mDuration = seconds; |
304 | setHasDuration(true); | 304 | setHasDuration(true); |
305 | } | 305 | } |
306 | 306 | ||
307 | int IncidenceBase::duration() const | 307 | int IncidenceBase::duration() const |
308 | { | 308 | { |
309 | return mDuration; | 309 | return mDuration; |
310 | } | 310 | } |
311 | 311 | ||
312 | void IncidenceBase::setHasDuration(bool b) | 312 | void IncidenceBase::setHasDuration(bool b) |
313 | { | 313 | { |
314 | mHasDuration = b; | 314 | mHasDuration = b; |
315 | } | 315 | } |
316 | 316 | ||
317 | bool IncidenceBase::hasDuration() const | 317 | bool IncidenceBase::hasDuration() const |
318 | { | 318 | { |
319 | return mHasDuration; | 319 | return mHasDuration; |
320 | } | 320 | } |
321 | 321 | ||
322 | void IncidenceBase::setSyncStatus(int stat) | 322 | void IncidenceBase::setSyncStatus(int stat) |
323 | { | 323 | { |
324 | if (mReadOnly) return; | 324 | if (mReadOnly) return; |
325 | mSyncStatus = stat; | 325 | mSyncStatus = stat; |
326 | } | 326 | } |
327 | 327 | ||
328 | int IncidenceBase::syncStatus() const | 328 | int IncidenceBase::syncStatus() const |
329 | { | 329 | { |
330 | return mSyncStatus; | 330 | return mSyncStatus; |
331 | } | 331 | } |
332 | 332 | ||
333 | void IncidenceBase::setPilotId( int id ) | 333 | void IncidenceBase::setPilotId( int id ) |
334 | { | 334 | { |
335 | if (mReadOnly) return; | 335 | if (mReadOnly) return; |
336 | mPilotId = id; | 336 | mPilotId = id; |
337 | } | 337 | } |
338 | 338 | ||
339 | int IncidenceBase::pilotId() const | 339 | int IncidenceBase::pilotId() const |
340 | { | 340 | { |
341 | return mPilotId; | 341 | return mPilotId; |
342 | } | 342 | } |
343 | 343 | ||
344 | int IncidenceBase::tempSyncStat() const | 344 | int IncidenceBase::tempSyncStat() const |
345 | { | 345 | { |
346 | return mTempSyncStat; | 346 | return mTempSyncStat; |
347 | } | 347 | } |
348 | void IncidenceBase::setTempSyncStat( int id ) | 348 | void IncidenceBase::setTempSyncStat( int id ) |
349 | { | 349 | { |
350 | if (mReadOnly) return; | 350 | if (mReadOnly) return; |
351 | mTempSyncStat = id; | 351 | mTempSyncStat = id; |
352 | } | 352 | } |
353 | 353 | ||
354 | void IncidenceBase::removeID(const QString &prof) | 354 | void IncidenceBase::removeID(const QString &prof) |
355 | { | 355 | { |
356 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 356 | if ( prof.isEmpty() ) |
357 | mExternalId = ":"; | ||
358 | else | ||
359 | mExternalId = KIdManager::removeId ( mExternalId, prof); | ||
357 | 360 | ||
358 | } | 361 | } |
359 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 362 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
360 | { | 363 | { |
361 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 364 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
362 | } | 365 | } |
363 | QString IncidenceBase::getID( const QString & prof) | 366 | QString IncidenceBase::getID( const QString & prof) |
364 | { | 367 | { |
365 | return KIdManager::getId ( mExternalId, prof ); | 368 | return KIdManager::getId ( mExternalId, prof ); |
366 | } | 369 | } |
367 | 370 | ||
368 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 371 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
369 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 | 372 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 |
370 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) | 373 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) |
371 | { | 374 | { |
372 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); | 375 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); |
373 | } | 376 | } |
374 | QString IncidenceBase::getCsum( const QString & prof) | 377 | QString IncidenceBase::getCsum( const QString & prof) |
375 | { | 378 | { |
376 | return KIdManager::getCsum ( mExternalId, prof ); | 379 | return KIdManager::getCsum ( mExternalId, prof ); |
377 | } | 380 | } |
378 | 381 | ||
379 | void IncidenceBase::setIDStr( const QString & s ) | 382 | void IncidenceBase::setIDStr( const QString & s ) |
380 | { | 383 | { |
381 | if (mReadOnly) return; | 384 | if (mReadOnly) return; |
382 | mExternalId = s; | 385 | mExternalId = s; |
383 | } | 386 | } |
384 | 387 | ||
385 | QString IncidenceBase::IDStr() const | 388 | QString IncidenceBase::IDStr() const |
386 | { | 389 | { |
387 | return mExternalId ; | 390 | return mExternalId ; |
388 | } | 391 | } |
389 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) | 392 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) |
390 | { | 393 | { |
391 | if( !mObservers.contains(observer) ) mObservers.append( observer ); | 394 | if( !mObservers.contains(observer) ) mObservers.append( observer ); |
392 | } | 395 | } |
393 | 396 | ||
394 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) | 397 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) |
395 | { | 398 | { |
396 | mObservers.remove( observer ); | 399 | mObservers.remove( observer ); |
397 | } | 400 | } |
398 | 401 | ||
399 | void IncidenceBase::updated() | 402 | void IncidenceBase::updated() |
400 | { | 403 | { |
401 | QPtrListIterator<Observer> it(mObservers); | 404 | QPtrListIterator<Observer> it(mObservers); |
402 | while( it.current() ) { | 405 | while( it.current() ) { |
403 | Observer *o = it.current(); | 406 | Observer *o = it.current(); |
404 | ++it; | 407 | ++it; |
405 | o->incidenceUpdated( this ); | 408 | o->incidenceUpdated( this ); |
406 | } | 409 | } |
407 | } | 410 | } |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 4390a06..feb184b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,1358 +1,1396 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 58 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
60 | { | 60 | { |
61 | mServerSocket = 0; | 61 | mServerSocket = 0; |
62 | bar = new QProgressBar ( 1, 0 ); | 62 | bar = new QProgressBar ( 1, 0 ); |
63 | bar->setCaption (""); | 63 | bar->setCaption (""); |
64 | 64 | ||
65 | int w = 300; | 65 | int w = 300; |
66 | if ( QApplication::desktop()->width() < 320 ) | 66 | if ( QApplication::desktop()->width() < 320 ) |
67 | w = 220; | 67 | w = 220; |
68 | int h = bar->sizeHint().height() ; | 68 | int h = bar->sizeHint().height() ; |
69 | int dw = QApplication::desktop()->width(); | 69 | int dw = QApplication::desktop()->width(); |
70 | int dh = QApplication::desktop()->height(); | 70 | int dh = QApplication::desktop()->height(); |
71 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 71 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
72 | if ( mPrefs->mPassiveSyncAutoStart ) | 72 | if ( mPrefs->mPassiveSyncAutoStart ) |
73 | enableQuick( false ); | 73 | enableQuick( false ); |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | KSyncManager::~KSyncManager() | 77 | KSyncManager::~KSyncManager() |
78 | { | 78 | { |
79 | delete bar; | 79 | delete bar; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | void KSyncManager::fillSyncMenu() | 83 | void KSyncManager::fillSyncMenu() |
84 | { | 84 | { |
85 | if ( mSyncMenu->count() ) | 85 | if ( mSyncMenu->count() ) |
86 | mSyncMenu->clear(); | 86 | mSyncMenu->clear(); |
87 | 87 | ||
88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
89 | mSyncMenu->insertSeparator(); | 89 | mSyncMenu->insertSeparator(); |
90 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | ||
91 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | ||
92 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | ||
93 | clearMenu->insertSeparator(); | ||
94 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | ||
95 | mSyncMenu->insertSeparator(); | ||
90 | if ( mServerSocket == 0 ) { | 96 | if ( mServerSocket == 0 ) { |
91 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 97 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
92 | } else { | 98 | } else { |
93 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 99 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
94 | } | 100 | } |
95 | mSyncMenu->insertSeparator(); | 101 | mSyncMenu->insertSeparator(); |
96 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 102 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
97 | mSyncMenu->insertSeparator(); | 103 | mSyncMenu->insertSeparator(); |
98 | |||
99 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 104 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
100 | config.setGroup("General"); | 105 | config.setGroup("General"); |
101 | QStringList prof = config.readListEntry("SyncProfileNames"); | 106 | QStringList prof = config.readListEntry("SyncProfileNames"); |
102 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 107 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
103 | if ( prof.count() < 2 ) { | 108 | if ( prof.count() < 2 ) { |
104 | prof.clear(); | 109 | prof.clear(); |
105 | QString externalName; | 110 | QString externalName; |
106 | #ifdef DESKTOP_VERSION | 111 | #ifdef DESKTOP_VERSION |
107 | #ifdef _WIN32_ | 112 | #ifdef _WIN32_ |
108 | externalName = "OutLook(not_implemented)"; | 113 | externalName = "OutLook(not_implemented)"; |
109 | #else | 114 | #else |
110 | externalName = "KDE_Desktop"; | 115 | externalName = "KDE_Desktop"; |
111 | #endif | 116 | #endif |
112 | #else | 117 | #else |
113 | externalName = "Sharp_DTM"; | 118 | externalName = "Sharp_DTM"; |
114 | #endif | 119 | #endif |
115 | prof << externalName; | 120 | prof << externalName; |
116 | prof << i18n("Local_file"); | 121 | prof << i18n("Local_file"); |
117 | prof << i18n("Last_file"); | 122 | prof << i18n("Last_file"); |
118 | KSyncProfile* temp = new KSyncProfile (); | 123 | KSyncProfile* temp = new KSyncProfile (); |
119 | temp->setName( prof[0] ); | 124 | temp->setName( prof[0] ); |
120 | temp->writeConfig(&config); | 125 | temp->writeConfig(&config); |
121 | temp->setName( prof[1] ); | 126 | temp->setName( prof[1] ); |
122 | temp->writeConfig(&config); | 127 | temp->writeConfig(&config); |
123 | temp->setName( prof[2] ); | 128 | temp->setName( prof[2] ); |
124 | temp->writeConfig(&config); | 129 | temp->writeConfig(&config); |
125 | config.setGroup("General"); | 130 | config.setGroup("General"); |
126 | config.writeEntry("SyncProfileNames",prof); | 131 | config.writeEntry("SyncProfileNames",prof); |
127 | config.writeEntry("ExternSyncProfiles",externalName); | 132 | config.writeEntry("ExternSyncProfiles",externalName); |
128 | config.sync(); | 133 | config.sync(); |
129 | delete temp; | 134 | delete temp; |
130 | } | 135 | } |
131 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 136 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
132 | mSyncProfileNames = prof; | 137 | mSyncProfileNames = prof; |
133 | unsigned int i; | 138 | unsigned int i; |
134 | for ( i = 0; i < prof.count(); ++i ) { | 139 | for ( i = 0; i < prof.count(); ++i ) { |
135 | mSyncMenu->insertItem( prof[i], 1000+i ); | 140 | mSyncMenu->insertItem( prof[i], 1000+i ); |
141 | clearMenu->insertItem( prof[i], 1000+i ); | ||
136 | if ( i == 2 ) | 142 | if ( i == 2 ) |
137 | mSyncMenu->insertSeparator(); | 143 | mSyncMenu->insertSeparator(); |
138 | } | 144 | } |
139 | QDir app_dir; | 145 | QDir app_dir; |
140 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 146 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
141 | if ( mTargetApp == PWMPI) { | 147 | if ( mTargetApp == PWMPI) { |
142 | mSyncMenu->removeItem( 1000 ); | 148 | mSyncMenu->removeItem( 1000 ); |
149 | clearMenu->removeItem( 1000 ); | ||
143 | } | 150 | } |
144 | #ifndef DESKTOP_VERSION | 151 | #ifndef DESKTOP_VERSION |
145 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 152 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
146 | mSyncMenu->removeItem( 1000 ); | 153 | mSyncMenu->removeItem( 1000 ); |
154 | clearMenu->removeItem( 1000 ); | ||
147 | } | 155 | } |
148 | #endif | 156 | #endif |
149 | mSyncMenu->removeItem( 1002 ); | 157 | mSyncMenu->removeItem( 1002 ); |
158 | clearMenu->removeItem( 1002 ); | ||
150 | } | 159 | } |
160 | void KSyncManager::slotClearMenu( int action ) | ||
161 | { | ||
162 | QString syncDevice; | ||
163 | if ( action > 999 ) { | ||
164 | syncDevice = mSyncProfileNames[action - 1000] ; | ||
165 | } | ||
151 | 166 | ||
167 | |||
168 | |||
169 | int result = 0; | ||
170 | QString sd; | ||
171 | if ( syncDevice.isEmpty() ) | ||
172 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | ||
173 | else | ||
174 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | ||
175 | |||
176 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | ||
177 | 0, 1 ); | ||
178 | if ( result ) | ||
179 | return; | ||
180 | mImplementation->removeSyncInfo( syncDevice ); | ||
181 | } | ||
152 | void KSyncManager::slotSyncMenu( int action ) | 182 | void KSyncManager::slotSyncMenu( int action ) |
153 | { | 183 | { |
154 | qDebug("syncaction %d ", action); | 184 | qDebug("syncaction %d ", action); |
185 | if ( action == 5000 ) | ||
186 | return; | ||
155 | if ( action == 0 ) { | 187 | if ( action == 0 ) { |
156 | 188 | ||
157 | // seems to be a Qt2 event handling bug | 189 | // seems to be a Qt2 event handling bug |
158 | // syncmenu.clear causes a segfault at first time | 190 | // syncmenu.clear causes a segfault at first time |
159 | // when we call it after the main event loop, it is ok | 191 | // when we call it after the main event loop, it is ok |
160 | // same behaviour when calling OM/Pi via QCOP for the first time | 192 | // same behaviour when calling OM/Pi via QCOP for the first time |
161 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 193 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
162 | //confSync(); | 194 | //confSync(); |
163 | 195 | ||
164 | return; | 196 | return; |
165 | } | 197 | } |
166 | if ( action == 1 ) { | 198 | if ( action == 1 ) { |
167 | multiSync( true ); | 199 | multiSync( true ); |
168 | return; | 200 | return; |
169 | } | 201 | } |
170 | if ( action == 2 ) { | 202 | if ( action == 2 ) { |
171 | enableQuick(); | 203 | enableQuick(); |
172 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 204 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
173 | return; | 205 | return; |
174 | } | 206 | } |
175 | if ( action == 3 ) { | 207 | if ( action == 3 ) { |
176 | delete mServerSocket; | 208 | delete mServerSocket; |
177 | mServerSocket = 0; | 209 | mServerSocket = 0; |
178 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 210 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
179 | return; | 211 | return; |
180 | } | 212 | } |
181 | 213 | ||
182 | if (blockSave()) | 214 | if (blockSave()) |
183 | return; | 215 | return; |
184 | 216 | ||
185 | setBlockSave(true); | 217 | setBlockSave(true); |
186 | bool silent = false; | 218 | bool silent = false; |
187 | if ( action == 999 ) { | 219 | if ( action == 999 ) { |
188 | //special mode for silent syncing | 220 | //special mode for silent syncing |
189 | action = 1000; | 221 | action = 1000; |
190 | silent = true; | 222 | silent = true; |
191 | } | 223 | } |
192 | 224 | ||
193 | mCurrentSyncProfile = action - 1000 ; | 225 | mCurrentSyncProfile = action - 1000 ; |
194 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 226 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
195 | mCurrentSyncName = mLocalMachineName ; | 227 | mCurrentSyncName = mLocalMachineName ; |
196 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 228 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
197 | KSyncProfile* temp = new KSyncProfile (); | 229 | KSyncProfile* temp = new KSyncProfile (); |
198 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 230 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
199 | temp->readConfig(&config); | 231 | temp->readConfig(&config); |
200 | if (silent) { | 232 | if (silent) { |
201 | mAskForPreferences = false; | 233 | mAskForPreferences = false; |
202 | mShowSyncSummary = false; | 234 | mShowSyncSummary = false; |
203 | mWriteBackFile = true; | 235 | mWriteBackFile = true; |
204 | mSyncAlgoPrefs = 2;// take newest | 236 | mSyncAlgoPrefs = 2;// take newest |
205 | } | 237 | } |
206 | else { | 238 | else { |
207 | mAskForPreferences = temp->getAskForPreferences(); | 239 | mAskForPreferences = temp->getAskForPreferences(); |
208 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 240 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
209 | mWriteBackFile = temp->getWriteBackFile(); | 241 | mWriteBackFile = temp->getWriteBackFile(); |
210 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 242 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
211 | } | 243 | } |
212 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 244 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
213 | mIsKapiFile = temp->getIsKapiFile(); | 245 | mIsKapiFile = temp->getIsKapiFile(); |
214 | mWriteBackInFuture = 0; | 246 | mWriteBackInFuture = 0; |
215 | if ( temp->getWriteBackFuture() ) | 247 | if ( temp->getWriteBackFuture() ) |
216 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 248 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
217 | 249 | ||
218 | if ( action == 1000 ) { | 250 | if ( action == 1000 ) { |
219 | #ifdef DESKTOP_VERSION | 251 | #ifdef DESKTOP_VERSION |
220 | syncKDE(); | 252 | syncKDE(); |
221 | #else | 253 | #else |
222 | syncSharp(); | 254 | syncSharp(); |
223 | #endif | 255 | #endif |
224 | 256 | ||
225 | } else if ( action == 1001 ) { | 257 | } else if ( action == 1001 ) { |
226 | syncLocalFile(); | 258 | syncLocalFile(); |
227 | 259 | ||
228 | } else if ( action == 1002 ) { | 260 | } else if ( action == 1002 ) { |
229 | mWriteBackFile = false; | 261 | mWriteBackFile = false; |
230 | mAskForPreferences = false; | 262 | mAskForPreferences = false; |
231 | mShowSyncSummary = false; | 263 | mShowSyncSummary = false; |
232 | mSyncAlgoPrefs = 3; | 264 | mSyncAlgoPrefs = 3; |
233 | quickSyncLocalFile(); | 265 | quickSyncLocalFile(); |
234 | 266 | ||
235 | } else if ( action >= 1003 ) { | 267 | } else if ( action >= 1003 ) { |
236 | if ( temp->getIsLocalFileSync() ) { | 268 | if ( temp->getIsLocalFileSync() ) { |
237 | switch(mTargetApp) | 269 | switch(mTargetApp) |
238 | { | 270 | { |
239 | case (KAPI): | 271 | case (KAPI): |
240 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 272 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
241 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 273 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
242 | break; | 274 | break; |
243 | case (KOPI): | 275 | case (KOPI): |
244 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 276 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
245 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 277 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
246 | break; | 278 | break; |
247 | case (PWMPI): | 279 | case (PWMPI): |
248 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 280 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
249 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 281 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
250 | break; | 282 | break; |
251 | default: | 283 | default: |
252 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 284 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
253 | break; | 285 | break; |
254 | 286 | ||
255 | } | 287 | } |
256 | } else { | 288 | } else { |
257 | if ( temp->getIsPhoneSync() ) { | 289 | if ( temp->getIsPhoneSync() ) { |
258 | mPhoneDevice = temp->getPhoneDevice( ) ; | 290 | mPhoneDevice = temp->getPhoneDevice( ) ; |
259 | mPhoneConnection = temp->getPhoneConnection( ); | 291 | mPhoneConnection = temp->getPhoneConnection( ); |
260 | mPhoneModel = temp->getPhoneModel( ); | 292 | mPhoneModel = temp->getPhoneModel( ); |
261 | syncPhone(); | 293 | syncPhone(); |
262 | } else if ( temp->getIsPiSync() ) { | 294 | } else if ( temp->getIsPiSync() ) { |
263 | if ( mTargetApp == KAPI ) { | 295 | if ( mTargetApp == KAPI ) { |
264 | mPassWordPiSync = temp->getRemotePwAB(); | 296 | mPassWordPiSync = temp->getRemotePwAB(); |
265 | mActiveSyncPort = temp->getRemotePortAB(); | 297 | mActiveSyncPort = temp->getRemotePortAB(); |
266 | mActiveSyncIP = temp->getRemoteIPAB(); | 298 | mActiveSyncIP = temp->getRemoteIPAB(); |
267 | } else if ( mTargetApp == KOPI ) { | 299 | } else if ( mTargetApp == KOPI ) { |
268 | mPassWordPiSync = temp->getRemotePw(); | 300 | mPassWordPiSync = temp->getRemotePw(); |
269 | mActiveSyncPort = temp->getRemotePort(); | 301 | mActiveSyncPort = temp->getRemotePort(); |
270 | mActiveSyncIP = temp->getRemoteIP(); | 302 | mActiveSyncIP = temp->getRemoteIP(); |
271 | } else { | 303 | } else { |
272 | mPassWordPiSync = temp->getRemotePwPWM(); | 304 | mPassWordPiSync = temp->getRemotePwPWM(); |
273 | mActiveSyncPort = temp->getRemotePortPWM(); | 305 | mActiveSyncPort = temp->getRemotePortPWM(); |
274 | mActiveSyncIP = temp->getRemoteIPPWM(); | 306 | mActiveSyncIP = temp->getRemoteIPPWM(); |
275 | } | 307 | } |
276 | syncPi(); | 308 | syncPi(); |
277 | while ( !mPisyncFinished ) { | 309 | while ( !mPisyncFinished ) { |
278 | //qDebug("waiting "); | 310 | //qDebug("waiting "); |
279 | qApp->processEvents(); | 311 | qApp->processEvents(); |
280 | } | 312 | } |
281 | } else | 313 | } else |
282 | syncRemote( temp ); | 314 | syncRemote( temp ); |
283 | 315 | ||
284 | } | 316 | } |
285 | } | 317 | } |
286 | delete temp; | 318 | delete temp; |
287 | setBlockSave(false); | 319 | setBlockSave(false); |
288 | } | 320 | } |
289 | 321 | ||
290 | void KSyncManager::enableQuick( bool ask ) | 322 | void KSyncManager::enableQuick( bool ask ) |
291 | { | 323 | { |
292 | bool autoStart; | 324 | bool autoStart; |
293 | bool changed = false; | 325 | bool changed = false; |
294 | if ( ask ) { | 326 | if ( ask ) { |
295 | QDialog dia ( 0, "input-dialog", true ); | 327 | QDialog dia ( 0, "input-dialog", true ); |
296 | QLineEdit lab ( &dia ); | 328 | QLineEdit lab ( &dia ); |
297 | QVBoxLayout lay( &dia ); | 329 | QVBoxLayout lay( &dia ); |
298 | lab.setText( mPrefs->mPassiveSyncPort ); | 330 | lab.setText( mPrefs->mPassiveSyncPort ); |
299 | lay.setMargin(7); | 331 | lay.setMargin(7); |
300 | lay.setSpacing(7); | 332 | lay.setSpacing(7); |
301 | int po = 9197+mTargetApp; | 333 | int po = 9197+mTargetApp; |
302 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 334 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
303 | lay.addWidget( &label); | 335 | lay.addWidget( &label); |
304 | lay.addWidget( &lab); | 336 | lay.addWidget( &lab); |
305 | 337 | ||
306 | QLineEdit lepw ( &dia ); | 338 | QLineEdit lepw ( &dia ); |
307 | lepw.setText( mPrefs->mPassiveSyncPw ); | 339 | lepw.setText( mPrefs->mPassiveSyncPw ); |
308 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 340 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
309 | lay.addWidget( &label2); | 341 | lay.addWidget( &label2); |
310 | lay.addWidget( &lepw); | 342 | lay.addWidget( &lepw); |
311 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 343 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
312 | lay.addWidget( &autostart); | 344 | lay.addWidget( &autostart); |
313 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 345 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
314 | #ifdef DESKTOP_VERSION | 346 | #ifdef DESKTOP_VERSION |
315 | #ifdef _WIN32_ | 347 | #ifdef _WIN32_ |
316 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 348 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
317 | #else | 349 | #else |
318 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 350 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
319 | #endif | 351 | #endif |
320 | lay.addWidget( &syncdesktop); | 352 | lay.addWidget( &syncdesktop); |
321 | #else | 353 | #else |
322 | mPrefs->mPassiveSyncWithDesktop = false; | 354 | mPrefs->mPassiveSyncWithDesktop = false; |
323 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 355 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
324 | syncdesktop.hide(); | 356 | syncdesktop.hide(); |
325 | #endif | 357 | #endif |
326 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 358 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
327 | 359 | ||
328 | dia.setFixedSize( 230,120 ); | 360 | dia.setFixedSize( 230,120 ); |
329 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 361 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
330 | QPushButton pb ( "OK", &dia); | 362 | QPushButton pb ( "OK", &dia); |
331 | lay.addWidget( &pb ); | 363 | lay.addWidget( &pb ); |
332 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 364 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
333 | dia.show(); | 365 | dia.show(); |
334 | if ( ! dia.exec() ) | 366 | if ( ! dia.exec() ) |
335 | return; | 367 | return; |
336 | dia.hide(); | 368 | dia.hide(); |
337 | qApp->processEvents(); | 369 | qApp->processEvents(); |
338 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 370 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
339 | changed = true; | 371 | changed = true; |
340 | mPrefs->mPassiveSyncPw = lepw.text(); | 372 | mPrefs->mPassiveSyncPw = lepw.text(); |
341 | } | 373 | } |
342 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 374 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
343 | mPrefs->mPassiveSyncPort = lab.text(); | 375 | mPrefs->mPassiveSyncPort = lab.text(); |
344 | changed = true; | 376 | changed = true; |
345 | } | 377 | } |
346 | autoStart = autostart.isChecked(); | 378 | autoStart = autostart.isChecked(); |
347 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 379 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
348 | changed = true; | 380 | changed = true; |
349 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 381 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
350 | } | 382 | } |
351 | } | 383 | } |
352 | else | 384 | else |
353 | autoStart = mPrefs->mPassiveSyncAutoStart; | 385 | autoStart = mPrefs->mPassiveSyncAutoStart; |
354 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 386 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
355 | changed = true; | 387 | changed = true; |
356 | bool ok; | 388 | bool ok; |
357 | mPrefs->mPassiveSyncAutoStart = false; | 389 | mPrefs->mPassiveSyncAutoStart = false; |
358 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 390 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
359 | if ( ! ok ) { | 391 | if ( ! ok ) { |
360 | KMessageBox::information( 0, i18n("No valid port")); | 392 | KMessageBox::information( 0, i18n("No valid port")); |
361 | return; | 393 | return; |
362 | } | 394 | } |
363 | //qDebug("port %d ", port); | 395 | //qDebug("port %d ", port); |
364 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 396 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
365 | mServerSocket->setFileName( defaultFileName() ); | 397 | mServerSocket->setFileName( defaultFileName() ); |
366 | //qDebug("connected "); | 398 | //qDebug("connected "); |
367 | if ( !mServerSocket->ok() ) { | 399 | if ( !mServerSocket->ok() ) { |
368 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 400 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
369 | delete mServerSocket; | 401 | delete mServerSocket; |
370 | mServerSocket = 0; | 402 | mServerSocket = 0; |
371 | return; | 403 | return; |
372 | } | 404 | } |
373 | mPrefs->mPassiveSyncAutoStart = autoStart; | 405 | mPrefs->mPassiveSyncAutoStart = autoStart; |
374 | if ( changed ) { | 406 | if ( changed ) { |
375 | mPrefs->writeConfig(); | 407 | mPrefs->writeConfig(); |
376 | } | 408 | } |
377 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 409 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
378 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 410 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
379 | } | 411 | } |
380 | 412 | ||
381 | void KSyncManager::syncLocalFile() | 413 | void KSyncManager::syncLocalFile() |
382 | { | 414 | { |
383 | 415 | ||
384 | QString fn =mPrefs->mLastSyncedLocalFile; | 416 | QString fn =mPrefs->mLastSyncedLocalFile; |
385 | QString ext; | 417 | QString ext; |
386 | 418 | ||
387 | switch(mTargetApp) | 419 | switch(mTargetApp) |
388 | { | 420 | { |
389 | case (KAPI): | 421 | case (KAPI): |
390 | ext = "(*.vcf)"; | 422 | ext = "(*.vcf)"; |
391 | break; | 423 | break; |
392 | case (KOPI): | 424 | case (KOPI): |
393 | ext = "(*.ics/*.vcs)"; | 425 | ext = "(*.ics/*.vcs)"; |
394 | break; | 426 | break; |
395 | case (PWMPI): | 427 | case (PWMPI): |
396 | ext = "(*.pwm)"; | 428 | ext = "(*.pwm)"; |
397 | break; | 429 | break; |
398 | default: | 430 | default: |
399 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 431 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
400 | break; | 432 | break; |
401 | 433 | ||
402 | } | 434 | } |
403 | 435 | ||
404 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 436 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
405 | if ( fn == "" ) | 437 | if ( fn == "" ) |
406 | return; | 438 | return; |
407 | if ( syncWithFile( fn, false ) ) { | 439 | if ( syncWithFile( fn, false ) ) { |
408 | qDebug("syncLocalFile() successful "); | 440 | qDebug("syncLocalFile() successful "); |
409 | } | 441 | } |
410 | 442 | ||
411 | } | 443 | } |
412 | 444 | ||
413 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 445 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
414 | { | 446 | { |
415 | bool ret = false; | 447 | bool ret = false; |
416 | QFileInfo info; | 448 | QFileInfo info; |
417 | info.setFile( fn ); | 449 | info.setFile( fn ); |
418 | QString mess; | 450 | QString mess; |
419 | bool loadbup = true; | 451 | bool loadbup = true; |
420 | if ( !info. exists() ) { | 452 | if ( !info. exists() ) { |
421 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 453 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
422 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 454 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
423 | mess ); | 455 | mess ); |
424 | return ret; | 456 | return ret; |
425 | } | 457 | } |
426 | int result = 0; | 458 | int result = 0; |
427 | if ( !quick ) { | 459 | if ( !quick ) { |
428 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 460 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
429 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 461 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
430 | mess, | 462 | mess, |
431 | i18n("Sync"), i18n("Cancel"), 0, | 463 | i18n("Sync"), i18n("Cancel"), 0, |
432 | 0, 1 ); | 464 | 0, 1 ); |
433 | if ( result ) | 465 | if ( result ) |
434 | return false; | 466 | return false; |
435 | } | 467 | } |
436 | if ( mAskForPreferences ) | 468 | if ( mAskForPreferences ) |
437 | if ( !edit_sync_options()) { | 469 | if ( !edit_sync_options()) { |
438 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 470 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
439 | return false; | 471 | return false; |
440 | } | 472 | } |
441 | if ( result == 0 ) { | 473 | if ( result == 0 ) { |
442 | //qDebug("Now sycing ... "); | 474 | //qDebug("Now sycing ... "); |
443 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 475 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
444 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 476 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
445 | else | 477 | else |
446 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 478 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
447 | if ( ! quick ) | 479 | if ( ! quick ) |
448 | mPrefs->mLastSyncedLocalFile = fn; | 480 | mPrefs->mLastSyncedLocalFile = fn; |
449 | } | 481 | } |
450 | return ret; | 482 | return ret; |
451 | } | 483 | } |
452 | 484 | ||
453 | void KSyncManager::quickSyncLocalFile() | 485 | void KSyncManager::quickSyncLocalFile() |
454 | { | 486 | { |
455 | 487 | ||
456 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 488 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
457 | qDebug("quick syncLocalFile() successful "); | 489 | qDebug("quick syncLocalFile() successful "); |
458 | 490 | ||
459 | } | 491 | } |
460 | } | 492 | } |
461 | 493 | ||
462 | void KSyncManager::multiSync( bool askforPrefs ) | 494 | void KSyncManager::multiSync( bool askforPrefs ) |
463 | { | 495 | { |
464 | if (blockSave()) | 496 | if (blockSave()) |
465 | return; | 497 | return; |
466 | setBlockSave(true); | 498 | setBlockSave(true); |
467 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 499 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
468 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 500 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
469 | question, | 501 | question, |
470 | i18n("Yes"), i18n("No"), | 502 | i18n("Yes"), i18n("No"), |
471 | 0, 0 ) != 0 ) { | 503 | 0, 0 ) != 0 ) { |
472 | setBlockSave(false); | 504 | setBlockSave(false); |
473 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 505 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
474 | return; | 506 | return; |
475 | } | 507 | } |
476 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 508 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
477 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 509 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
478 | if ( askforPrefs ) { | 510 | if ( askforPrefs ) { |
479 | if ( !edit_sync_options()) { | 511 | if ( !edit_sync_options()) { |
480 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 512 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
481 | return; | 513 | return; |
482 | } | 514 | } |
483 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 515 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
484 | } | 516 | } |
485 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 517 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
486 | qApp->processEvents(); | 518 | qApp->processEvents(); |
487 | int num = ringSync() ; | 519 | int num = ringSync() ; |
488 | if ( num > 1 ) | 520 | if ( num > 1 ) |
489 | ringSync(); | 521 | ringSync(); |
490 | setBlockSave(false); | 522 | setBlockSave(false); |
491 | if ( num ) | 523 | if ( num ) |
492 | emit save(); | 524 | emit save(); |
493 | if ( num ) | 525 | if ( num ) |
494 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 526 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
495 | else | 527 | else |
496 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 528 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
497 | return; | 529 | return; |
498 | } | 530 | } |
499 | 531 | ||
500 | int KSyncManager::ringSync() | 532 | int KSyncManager::ringSync() |
501 | { | 533 | { |
502 | int syncedProfiles = 0; | 534 | int syncedProfiles = 0; |
503 | unsigned int i; | 535 | unsigned int i; |
504 | QTime timer; | 536 | QTime timer; |
505 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 537 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
506 | QStringList syncProfileNames = mSyncProfileNames; | 538 | QStringList syncProfileNames = mSyncProfileNames; |
507 | KSyncProfile* temp = new KSyncProfile (); | 539 | KSyncProfile* temp = new KSyncProfile (); |
508 | mAskForPreferences = false; | 540 | mAskForPreferences = false; |
509 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 541 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
510 | mCurrentSyncProfile = i; | 542 | mCurrentSyncProfile = i; |
511 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 543 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
512 | temp->readConfig(&config); | 544 | temp->readConfig(&config); |
513 | 545 | ||
514 | bool includeInRingSync; | 546 | bool includeInRingSync; |
515 | switch(mTargetApp) | 547 | switch(mTargetApp) |
516 | { | 548 | { |
517 | case (KAPI): | 549 | case (KAPI): |
518 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 550 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
519 | break; | 551 | break; |
520 | case (KOPI): | 552 | case (KOPI): |
521 | includeInRingSync = temp->getIncludeInRingSync(); | 553 | includeInRingSync = temp->getIncludeInRingSync(); |
522 | break; | 554 | break; |
523 | case (PWMPI): | 555 | case (PWMPI): |
524 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 556 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
525 | break; | 557 | break; |
526 | default: | 558 | default: |
527 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 559 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
528 | break; | 560 | break; |
529 | 561 | ||
530 | } | 562 | } |
531 | 563 | ||
532 | 564 | ||
533 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 565 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
534 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 566 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
535 | ++syncedProfiles; | 567 | ++syncedProfiles; |
536 | // mAskForPreferences = temp->getAskForPreferences(); | 568 | // mAskForPreferences = temp->getAskForPreferences(); |
537 | mWriteBackFile = temp->getWriteBackFile(); | 569 | mWriteBackFile = temp->getWriteBackFile(); |
538 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 570 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
539 | mWriteBackInFuture = 0; | 571 | mWriteBackInFuture = 0; |
540 | if ( temp->getWriteBackFuture() ) | 572 | if ( temp->getWriteBackFuture() ) |
541 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 573 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
542 | mShowSyncSummary = false; | 574 | mShowSyncSummary = false; |
543 | mCurrentSyncDevice = syncProfileNames[i] ; | 575 | mCurrentSyncDevice = syncProfileNames[i] ; |
544 | mCurrentSyncName = mLocalMachineName; | 576 | mCurrentSyncName = mLocalMachineName; |
545 | if ( i == 0 ) { | 577 | if ( i == 0 ) { |
546 | #ifdef DESKTOP_VERSION | 578 | #ifdef DESKTOP_VERSION |
547 | syncKDE(); | 579 | syncKDE(); |
548 | #else | 580 | #else |
549 | syncSharp(); | 581 | syncSharp(); |
550 | #endif | 582 | #endif |
551 | } else { | 583 | } else { |
552 | if ( temp->getIsLocalFileSync() ) { | 584 | if ( temp->getIsLocalFileSync() ) { |
553 | switch(mTargetApp) | 585 | switch(mTargetApp) |
554 | { | 586 | { |
555 | case (KAPI): | 587 | case (KAPI): |
556 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 588 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
557 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 589 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
558 | break; | 590 | break; |
559 | case (KOPI): | 591 | case (KOPI): |
560 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 592 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
561 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 593 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
562 | break; | 594 | break; |
563 | case (PWMPI): | 595 | case (PWMPI): |
564 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 596 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
565 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 597 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
566 | break; | 598 | break; |
567 | default: | 599 | default: |
568 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 600 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
569 | break; | 601 | break; |
570 | } | 602 | } |
571 | } else { | 603 | } else { |
572 | if ( temp->getIsPhoneSync() ) { | 604 | if ( temp->getIsPhoneSync() ) { |
573 | mPhoneDevice = temp->getPhoneDevice( ) ; | 605 | mPhoneDevice = temp->getPhoneDevice( ) ; |
574 | mPhoneConnection = temp->getPhoneConnection( ); | 606 | mPhoneConnection = temp->getPhoneConnection( ); |
575 | mPhoneModel = temp->getPhoneModel( ); | 607 | mPhoneModel = temp->getPhoneModel( ); |
576 | syncPhone(); | 608 | syncPhone(); |
577 | } else if ( temp->getIsPiSync() ) { | 609 | } else if ( temp->getIsPiSync() ) { |
578 | if ( mTargetApp == KAPI ) { | 610 | if ( mTargetApp == KAPI ) { |
579 | mPassWordPiSync = temp->getRemotePwAB(); | 611 | mPassWordPiSync = temp->getRemotePwAB(); |
580 | mActiveSyncPort = temp->getRemotePortAB(); | 612 | mActiveSyncPort = temp->getRemotePortAB(); |
581 | mActiveSyncIP = temp->getRemoteIPAB(); | 613 | mActiveSyncIP = temp->getRemoteIPAB(); |
582 | } else if ( mTargetApp == KOPI ) { | 614 | } else if ( mTargetApp == KOPI ) { |
583 | mPassWordPiSync = temp->getRemotePw(); | 615 | mPassWordPiSync = temp->getRemotePw(); |
584 | mActiveSyncPort = temp->getRemotePort(); | 616 | mActiveSyncPort = temp->getRemotePort(); |
585 | mActiveSyncIP = temp->getRemoteIP(); | 617 | mActiveSyncIP = temp->getRemoteIP(); |
586 | } else { | 618 | } else { |
587 | mPassWordPiSync = temp->getRemotePwPWM(); | 619 | mPassWordPiSync = temp->getRemotePwPWM(); |
588 | mActiveSyncPort = temp->getRemotePortPWM(); | 620 | mActiveSyncPort = temp->getRemotePortPWM(); |
589 | mActiveSyncIP = temp->getRemoteIPPWM(); | 621 | mActiveSyncIP = temp->getRemoteIPPWM(); |
590 | } | 622 | } |
591 | syncPi(); | 623 | syncPi(); |
592 | while ( !mPisyncFinished ) { | 624 | while ( !mPisyncFinished ) { |
593 | //qDebug("waiting "); | 625 | //qDebug("waiting "); |
594 | qApp->processEvents(); | 626 | qApp->processEvents(); |
595 | } | 627 | } |
596 | timer.start(); | 628 | timer.start(); |
597 | while ( timer.elapsed () < 2000 ) { | 629 | while ( timer.elapsed () < 2000 ) { |
598 | qApp->processEvents(); | 630 | qApp->processEvents(); |
599 | } | 631 | } |
600 | } else | 632 | } else |
601 | syncRemote( temp, false ); | 633 | syncRemote( temp, false ); |
602 | 634 | ||
603 | } | 635 | } |
604 | } | 636 | } |
605 | timer.start(); | 637 | timer.start(); |
606 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 638 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
607 | while ( timer.elapsed () < 2000 ) { | 639 | while ( timer.elapsed () < 2000 ) { |
608 | qApp->processEvents(); | 640 | qApp->processEvents(); |
609 | #ifndef _WIN32_ | 641 | #ifndef _WIN32_ |
610 | sleep (1); | 642 | sleep (1); |
611 | #endif | 643 | #endif |
612 | } | 644 | } |
613 | 645 | ||
614 | } | 646 | } |
615 | 647 | ||
616 | } | 648 | } |
617 | delete temp; | 649 | delete temp; |
618 | return syncedProfiles; | 650 | return syncedProfiles; |
619 | } | 651 | } |
620 | 652 | ||
621 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 653 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
622 | { | 654 | { |
623 | QString question; | 655 | QString question; |
624 | if ( ask ) { | 656 | if ( ask ) { |
625 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 657 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
626 | if ( QMessageBox::information( mParent, i18n("Sync"), | 658 | if ( QMessageBox::information( mParent, i18n("Sync"), |
627 | question, | 659 | question, |
628 | i18n("Yes"), i18n("No"), | 660 | i18n("Yes"), i18n("No"), |
629 | 0, 0 ) != 0 ) | 661 | 0, 0 ) != 0 ) |
630 | return; | 662 | return; |
631 | } | 663 | } |
632 | 664 | ||
633 | QString preCommand; | 665 | QString preCommand; |
634 | QString localTempFile; | 666 | QString localTempFile; |
635 | QString postCommand; | 667 | QString postCommand; |
636 | 668 | ||
637 | switch(mTargetApp) | 669 | switch(mTargetApp) |
638 | { | 670 | { |
639 | case (KAPI): | 671 | case (KAPI): |
640 | preCommand = prof->getPreSyncCommandAB(); | 672 | preCommand = prof->getPreSyncCommandAB(); |
641 | postCommand = prof->getPostSyncCommandAB(); | 673 | postCommand = prof->getPostSyncCommandAB(); |
642 | localTempFile = prof->getLocalTempFileAB(); | 674 | localTempFile = prof->getLocalTempFileAB(); |
643 | break; | 675 | break; |
644 | case (KOPI): | 676 | case (KOPI): |
645 | preCommand = prof->getPreSyncCommand(); | 677 | preCommand = prof->getPreSyncCommand(); |
646 | postCommand = prof->getPostSyncCommand(); | 678 | postCommand = prof->getPostSyncCommand(); |
647 | localTempFile = prof->getLocalTempFile(); | 679 | localTempFile = prof->getLocalTempFile(); |
648 | break; | 680 | break; |
649 | case (PWMPI): | 681 | case (PWMPI): |
650 | preCommand = prof->getPreSyncCommandPWM(); | 682 | preCommand = prof->getPreSyncCommandPWM(); |
651 | postCommand = prof->getPostSyncCommandPWM(); | 683 | postCommand = prof->getPostSyncCommandPWM(); |
652 | localTempFile = prof->getLocalTempFilePWM(); | 684 | localTempFile = prof->getLocalTempFilePWM(); |
653 | break; | 685 | break; |
654 | default: | 686 | default: |
655 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 687 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
656 | break; | 688 | break; |
657 | } | 689 | } |
658 | 690 | ||
659 | 691 | ||
660 | int fi; | 692 | int fi; |
661 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 693 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
662 | QString pwd = getPassword(); | 694 | QString pwd = getPassword(); |
663 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 695 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
664 | 696 | ||
665 | } | 697 | } |
666 | int maxlen = 30; | 698 | int maxlen = 30; |
667 | if ( QApplication::desktop()->width() > 320 ) | 699 | if ( QApplication::desktop()->width() > 320 ) |
668 | maxlen += 25; | 700 | maxlen += 25; |
669 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 701 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
670 | int fileSize = 0; | 702 | int fileSize = 0; |
671 | int result = system ( preCommand ); | 703 | int result = system ( preCommand ); |
672 | // 0 : okay | 704 | // 0 : okay |
673 | // 256: no such file or dir | 705 | // 256: no such file or dir |
674 | // | 706 | // |
675 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 707 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
676 | if ( result != 0 ) { | 708 | if ( result != 0 ) { |
677 | unsigned int len = maxlen; | 709 | unsigned int len = maxlen; |
678 | while ( len < preCommand.length() ) { | 710 | while ( len < preCommand.length() ) { |
679 | preCommand.insert( len , "\n" ); | 711 | preCommand.insert( len , "\n" ); |
680 | len += maxlen +2; | 712 | len += maxlen +2; |
681 | } | 713 | } |
682 | 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 (preCommand) ; | 714 | 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 (preCommand) ; |
683 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 715 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
684 | question, | 716 | question, |
685 | i18n("Okay!")) ; | 717 | i18n("Okay!")) ; |
686 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 718 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
687 | return; | 719 | return; |
688 | } | 720 | } |
689 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 721 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
690 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 722 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
691 | 723 | ||
692 | if ( syncWithFile( localTempFile, true ) ) { | 724 | if ( syncWithFile( localTempFile, true ) ) { |
693 | 725 | ||
694 | if ( mWriteBackFile ) { | 726 | if ( mWriteBackFile ) { |
695 | int fi; | 727 | int fi; |
696 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 728 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
697 | QString pwd = getPassword(); | 729 | QString pwd = getPassword(); |
698 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 730 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
699 | 731 | ||
700 | } | 732 | } |
701 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 733 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
702 | result = system ( postCommand ); | 734 | result = system ( postCommand ); |
703 | qDebug("Sync:Writing back file result: %d ", result); | 735 | qDebug("Sync:Writing back file result: %d ", result); |
704 | if ( result != 0 ) { | 736 | if ( result != 0 ) { |
705 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 737 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
706 | return; | 738 | return; |
707 | } else { | 739 | } else { |
708 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 740 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
709 | } | 741 | } |
710 | } | 742 | } |
711 | } | 743 | } |
712 | return; | 744 | return; |
713 | } | 745 | } |
714 | bool KSyncManager::edit_pisync_options() | 746 | bool KSyncManager::edit_pisync_options() |
715 | { | 747 | { |
716 | QDialog dia( mParent, "dia", true ); | 748 | QDialog dia( mParent, "dia", true ); |
717 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 749 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
718 | QVBoxLayout lay ( &dia ); | 750 | QVBoxLayout lay ( &dia ); |
719 | lay.setSpacing( 5 ); | 751 | lay.setSpacing( 5 ); |
720 | lay.setMargin( 3 ); | 752 | lay.setMargin( 3 ); |
721 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 753 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
722 | lay.addWidget( &lab1 ); | 754 | lay.addWidget( &lab1 ); |
723 | QLineEdit le1 (&dia ); | 755 | QLineEdit le1 (&dia ); |
724 | lay.addWidget( &le1 ); | 756 | lay.addWidget( &le1 ); |
725 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 757 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
726 | lay.addWidget( &lab2 ); | 758 | lay.addWidget( &lab2 ); |
727 | QLineEdit le2 (&dia ); | 759 | QLineEdit le2 (&dia ); |
728 | lay.addWidget( &le2 ); | 760 | lay.addWidget( &le2 ); |
729 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 761 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
730 | lay.addWidget( &lab3 ); | 762 | lay.addWidget( &lab3 ); |
731 | QLineEdit le3 (&dia ); | 763 | QLineEdit le3 (&dia ); |
732 | lay.addWidget( &le3 ); | 764 | lay.addWidget( &le3 ); |
733 | QPushButton pb ( "OK", &dia); | 765 | QPushButton pb ( "OK", &dia); |
734 | lay.addWidget( &pb ); | 766 | lay.addWidget( &pb ); |
735 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 767 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
736 | le1.setText( mPassWordPiSync ); | 768 | le1.setText( mPassWordPiSync ); |
737 | le2.setText( mActiveSyncIP ); | 769 | le2.setText( mActiveSyncIP ); |
738 | le3.setText( mActiveSyncPort ); | 770 | le3.setText( mActiveSyncPort ); |
739 | if ( dia.exec() ) { | 771 | if ( dia.exec() ) { |
740 | mPassWordPiSync = le1.text(); | 772 | mPassWordPiSync = le1.text(); |
741 | mActiveSyncPort = le3.text(); | 773 | mActiveSyncPort = le3.text(); |
742 | mActiveSyncIP = le2.text(); | 774 | mActiveSyncIP = le2.text(); |
743 | return true; | 775 | return true; |
744 | } | 776 | } |
745 | return false; | 777 | return false; |
746 | } | 778 | } |
747 | bool KSyncManager::edit_sync_options() | 779 | bool KSyncManager::edit_sync_options() |
748 | { | 780 | { |
749 | 781 | ||
750 | QDialog dia( mParent, "dia", true ); | 782 | QDialog dia( mParent, "dia", true ); |
751 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 783 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
752 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 784 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
753 | QVBoxLayout lay ( &dia ); | 785 | QVBoxLayout lay ( &dia ); |
754 | lay.setSpacing( 2 ); | 786 | lay.setSpacing( 2 ); |
755 | lay.setMargin( 3 ); | 787 | lay.setMargin( 3 ); |
756 | lay.addWidget(&gr); | 788 | lay.addWidget(&gr); |
757 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 789 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
758 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 790 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
759 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 791 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
760 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 792 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
761 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 793 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
762 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 794 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
763 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 795 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
764 | QPushButton pb ( "OK", &dia); | 796 | QPushButton pb ( "OK", &dia); |
765 | lay.addWidget( &pb ); | 797 | lay.addWidget( &pb ); |
766 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 798 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
767 | switch ( mSyncAlgoPrefs ) { | 799 | switch ( mSyncAlgoPrefs ) { |
768 | case 0: | 800 | case 0: |
769 | loc.setChecked( true); | 801 | loc.setChecked( true); |
770 | break; | 802 | break; |
771 | case 1: | 803 | case 1: |
772 | rem.setChecked( true ); | 804 | rem.setChecked( true ); |
773 | break; | 805 | break; |
774 | case 2: | 806 | case 2: |
775 | newest.setChecked( true); | 807 | newest.setChecked( true); |
776 | break; | 808 | break; |
777 | case 3: | 809 | case 3: |
778 | ask.setChecked( true); | 810 | ask.setChecked( true); |
779 | break; | 811 | break; |
780 | case 4: | 812 | case 4: |
781 | f_loc.setChecked( true); | 813 | f_loc.setChecked( true); |
782 | break; | 814 | break; |
783 | case 5: | 815 | case 5: |
784 | f_rem.setChecked( true); | 816 | f_rem.setChecked( true); |
785 | break; | 817 | break; |
786 | case 6: | 818 | case 6: |
787 | // both.setChecked( true); | 819 | // both.setChecked( true); |
788 | break; | 820 | break; |
789 | default: | 821 | default: |
790 | break; | 822 | break; |
791 | } | 823 | } |
792 | if ( dia.exec() ) { | 824 | if ( dia.exec() ) { |
793 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 825 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
794 | return true; | 826 | return true; |
795 | } | 827 | } |
796 | return false; | 828 | return false; |
797 | } | 829 | } |
798 | 830 | ||
799 | QString KSyncManager::getPassword( ) | 831 | QString KSyncManager::getPassword( ) |
800 | { | 832 | { |
801 | QString retfile = ""; | 833 | QString retfile = ""; |
802 | QDialog dia ( mParent, "input-dialog", true ); | 834 | QDialog dia ( mParent, "input-dialog", true ); |
803 | QLineEdit lab ( &dia ); | 835 | QLineEdit lab ( &dia ); |
804 | lab.setEchoMode( QLineEdit::Password ); | 836 | lab.setEchoMode( QLineEdit::Password ); |
805 | QVBoxLayout lay( &dia ); | 837 | QVBoxLayout lay( &dia ); |
806 | lay.setMargin(7); | 838 | lay.setMargin(7); |
807 | lay.setSpacing(7); | 839 | lay.setSpacing(7); |
808 | lay.addWidget( &lab); | 840 | lay.addWidget( &lab); |
809 | dia.setFixedSize( 230,50 ); | 841 | dia.setFixedSize( 230,50 ); |
810 | dia.setCaption( i18n("Enter password") ); | 842 | dia.setCaption( i18n("Enter password") ); |
811 | QPushButton pb ( "OK", &dia); | 843 | QPushButton pb ( "OK", &dia); |
812 | lay.addWidget( &pb ); | 844 | lay.addWidget( &pb ); |
813 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 845 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
814 | dia.show(); | 846 | dia.show(); |
815 | int res = dia.exec(); | 847 | int res = dia.exec(); |
816 | if ( res ) | 848 | if ( res ) |
817 | retfile = lab.text(); | 849 | retfile = lab.text(); |
818 | dia.hide(); | 850 | dia.hide(); |
819 | qApp->processEvents(); | 851 | qApp->processEvents(); |
820 | return retfile; | 852 | return retfile; |
821 | 853 | ||
822 | } | 854 | } |
823 | 855 | ||
824 | 856 | ||
825 | void KSyncManager::confSync() | 857 | void KSyncManager::confSync() |
826 | { | 858 | { |
827 | static KSyncPrefsDialog* sp = 0; | 859 | static KSyncPrefsDialog* sp = 0; |
828 | if ( ! sp ) { | 860 | if ( ! sp ) { |
829 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 861 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
830 | } | 862 | } |
831 | sp->usrReadConfig(); | 863 | sp->usrReadConfig(); |
832 | #ifndef DESKTOP_VERSION | 864 | #ifndef DESKTOP_VERSION |
833 | sp->showMaximized(); | 865 | sp->showMaximized(); |
834 | #else | 866 | #else |
835 | sp->show(); | 867 | sp->show(); |
836 | #endif | 868 | #endif |
837 | sp->exec(); | 869 | sp->exec(); |
870 | QStringList oldSyncProfileNames = mSyncProfileNames; | ||
838 | mSyncProfileNames = sp->getSyncProfileNames(); | 871 | mSyncProfileNames = sp->getSyncProfileNames(); |
839 | mLocalMachineName = sp->getLocalMachineName (); | 872 | mLocalMachineName = sp->getLocalMachineName (); |
873 | int ii; | ||
874 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | ||
875 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | ||
876 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | ||
877 | } | ||
840 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 878 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
841 | } | 879 | } |
842 | void KSyncManager::syncKDE() | 880 | void KSyncManager::syncKDE() |
843 | { | 881 | { |
844 | emit save(); | 882 | emit save(); |
845 | switch(mTargetApp) | 883 | switch(mTargetApp) |
846 | { | 884 | { |
847 | case (KAPI): | 885 | case (KAPI): |
848 | 886 | ||
849 | break; | 887 | break; |
850 | case (KOPI): | 888 | case (KOPI): |
851 | { | 889 | { |
852 | #ifdef DESKTOP_VERSION | 890 | #ifdef DESKTOP_VERSION |
853 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 891 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
854 | #else | 892 | #else |
855 | QString command = "kdecaldump"; | 893 | QString command = "kdecaldump"; |
856 | #endif | 894 | #endif |
857 | if ( ! QFile::exists ( command ) ) | 895 | if ( ! QFile::exists ( command ) ) |
858 | command = "kdecaldump"; | 896 | command = "kdecaldump"; |
859 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 897 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
860 | system ( command.latin1()); | 898 | system ( command.latin1()); |
861 | if ( syncWithFile( fileName,true ) ) { | 899 | if ( syncWithFile( fileName,true ) ) { |
862 | if ( mWriteBackFile ) { | 900 | if ( mWriteBackFile ) { |
863 | command += " --read"; | 901 | command += " --read"; |
864 | system ( command.latin1()); | 902 | system ( command.latin1()); |
865 | } | 903 | } |
866 | } | 904 | } |
867 | 905 | ||
868 | } | 906 | } |
869 | break; | 907 | break; |
870 | case (PWMPI): | 908 | case (PWMPI): |
871 | 909 | ||
872 | break; | 910 | break; |
873 | default: | 911 | default: |
874 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 912 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
875 | break; | 913 | break; |
876 | 914 | ||
877 | } | 915 | } |
878 | } | 916 | } |
879 | 917 | ||
880 | void KSyncManager::syncSharp() | 918 | void KSyncManager::syncSharp() |
881 | { | 919 | { |
882 | 920 | ||
883 | if ( ! syncExternalApplication("sharp") ) | 921 | if ( ! syncExternalApplication("sharp") ) |
884 | qDebug("ERROR sync sharp "); | 922 | qDebug("ERROR sync sharp "); |
885 | } | 923 | } |
886 | 924 | ||
887 | bool KSyncManager::syncExternalApplication(QString resource) | 925 | bool KSyncManager::syncExternalApplication(QString resource) |
888 | { | 926 | { |
889 | 927 | ||
890 | emit save(); | 928 | emit save(); |
891 | 929 | ||
892 | if ( mAskForPreferences ) | 930 | if ( mAskForPreferences ) |
893 | if ( !edit_sync_options()) { | 931 | if ( !edit_sync_options()) { |
894 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 932 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
895 | return false; | 933 | return false; |
896 | } | 934 | } |
897 | 935 | ||
898 | qDebug("Sync extern %s", resource.latin1()); | 936 | qDebug("Sync extern %s", resource.latin1()); |
899 | 937 | ||
900 | bool syncOK = mImplementation->syncExternal(this, resource); | 938 | bool syncOK = mImplementation->syncExternal(this, resource); |
901 | 939 | ||
902 | return syncOK; | 940 | return syncOK; |
903 | 941 | ||
904 | } | 942 | } |
905 | 943 | ||
906 | void KSyncManager::syncPhone() | 944 | void KSyncManager::syncPhone() |
907 | { | 945 | { |
908 | 946 | ||
909 | syncExternalApplication("phone"); | 947 | syncExternalApplication("phone"); |
910 | 948 | ||
911 | } | 949 | } |
912 | 950 | ||
913 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 951 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
914 | { | 952 | { |
915 | if (!bar->isVisible()) | 953 | if (!bar->isVisible()) |
916 | { | 954 | { |
917 | bar->setCaption (caption); | 955 | bar->setCaption (caption); |
918 | bar->setTotalSteps ( total ) ; | 956 | bar->setTotalSteps ( total ) ; |
919 | 957 | ||
920 | bar->show(); | 958 | bar->show(); |
921 | } | 959 | } |
922 | 960 | ||
923 | bar->setProgress( percentage ); | 961 | bar->setProgress( percentage ); |
924 | } | 962 | } |
925 | 963 | ||
926 | void KSyncManager::hideProgressBar() | 964 | void KSyncManager::hideProgressBar() |
927 | { | 965 | { |
928 | bar->hide(); | 966 | bar->hide(); |
929 | } | 967 | } |
930 | 968 | ||
931 | bool KSyncManager::isProgressBarCanceled() | 969 | bool KSyncManager::isProgressBarCanceled() |
932 | { | 970 | { |
933 | return !bar->isVisible(); | 971 | return !bar->isVisible(); |
934 | } | 972 | } |
935 | 973 | ||
936 | QString KSyncManager::syncFileName() | 974 | QString KSyncManager::syncFileName() |
937 | { | 975 | { |
938 | 976 | ||
939 | QString fn = "tempfile"; | 977 | QString fn = "tempfile"; |
940 | switch(mTargetApp) | 978 | switch(mTargetApp) |
941 | { | 979 | { |
942 | case (KAPI): | 980 | case (KAPI): |
943 | fn = "tempsyncab.vcf"; | 981 | fn = "tempsyncab.vcf"; |
944 | break; | 982 | break; |
945 | case (KOPI): | 983 | case (KOPI): |
946 | fn = "tempsynccal.ics"; | 984 | fn = "tempsynccal.ics"; |
947 | break; | 985 | break; |
948 | case (PWMPI): | 986 | case (PWMPI): |
949 | fn = "tempsyncpw.pwm"; | 987 | fn = "tempsyncpw.pwm"; |
950 | break; | 988 | break; |
951 | default: | 989 | default: |
952 | break; | 990 | break; |
953 | } | 991 | } |
954 | #ifdef _WIN32_ | 992 | #ifdef _WIN32_ |
955 | return locateLocal( "tmp", fn ); | 993 | return locateLocal( "tmp", fn ); |
956 | #else | 994 | #else |
957 | return (QString( "/tmp/" )+ fn ); | 995 | return (QString( "/tmp/" )+ fn ); |
958 | #endif | 996 | #endif |
959 | } | 997 | } |
960 | 998 | ||
961 | void KSyncManager::syncPi() | 999 | void KSyncManager::syncPi() |
962 | { | 1000 | { |
963 | mPisyncFinished = false; | 1001 | mPisyncFinished = false; |
964 | qApp->processEvents(); | 1002 | qApp->processEvents(); |
965 | if ( mAskForPreferences ) | 1003 | if ( mAskForPreferences ) |
966 | if ( !edit_pisync_options()) { | 1004 | if ( !edit_pisync_options()) { |
967 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1005 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
968 | return; | 1006 | return; |
969 | } | 1007 | } |
970 | bool ok; | 1008 | bool ok; |
971 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1009 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
972 | if ( ! ok ) { | 1010 | if ( ! ok ) { |
973 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1011 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
974 | return; | 1012 | return; |
975 | } | 1013 | } |
976 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1014 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
977 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1015 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
978 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 1016 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
979 | commandSocket->readFile( syncFileName() ); | 1017 | commandSocket->readFile( syncFileName() ); |
980 | } | 1018 | } |
981 | 1019 | ||
982 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1020 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
983 | { | 1021 | { |
984 | //enum { success, errorW, errorR, quiet }; | 1022 | //enum { success, errorW, errorR, quiet }; |
985 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1023 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
986 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1024 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
987 | delete s; | 1025 | delete s; |
988 | if ( state == KCommandSocket::errorR ) { | 1026 | if ( state == KCommandSocket::errorR ) { |
989 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1027 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
990 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1028 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
991 | commandSocket->sendStop(); | 1029 | commandSocket->sendStop(); |
992 | } | 1030 | } |
993 | mPisyncFinished = true; | 1031 | mPisyncFinished = true; |
994 | return; | 1032 | return; |
995 | 1033 | ||
996 | } else if ( state == KCommandSocket::errorW ) { | 1034 | } else if ( state == KCommandSocket::errorW ) { |
997 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1035 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
998 | mPisyncFinished = true; | 1036 | mPisyncFinished = true; |
999 | 1037 | ||
1000 | } else if ( state == KCommandSocket::successR ) { | 1038 | } else if ( state == KCommandSocket::successR ) { |
1001 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1039 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1002 | 1040 | ||
1003 | } else if ( state == KCommandSocket::successW ) { | 1041 | } else if ( state == KCommandSocket::successW ) { |
1004 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1042 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1005 | mPisyncFinished = true; | 1043 | mPisyncFinished = true; |
1006 | } | 1044 | } |
1007 | 1045 | ||
1008 | delete s; | 1046 | delete s; |
1009 | } | 1047 | } |
1010 | 1048 | ||
1011 | void KSyncManager::readFileFromSocket() | 1049 | void KSyncManager::readFileFromSocket() |
1012 | { | 1050 | { |
1013 | QString fileName = syncFileName(); | 1051 | QString fileName = syncFileName(); |
1014 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1052 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1015 | if ( ! syncWithFile( fileName , true ) ) { | 1053 | if ( ! syncWithFile( fileName , true ) ) { |
1016 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1054 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1017 | mPisyncFinished = true; | 1055 | mPisyncFinished = true; |
1018 | return; | 1056 | return; |
1019 | } | 1057 | } |
1020 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1058 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1021 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1059 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1022 | if ( mWriteBackFile ) | 1060 | if ( mWriteBackFile ) |
1023 | commandSocket->writeFile( fileName ); | 1061 | commandSocket->writeFile( fileName ); |
1024 | else { | 1062 | else { |
1025 | commandSocket->sendStop(); | 1063 | commandSocket->sendStop(); |
1026 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1027 | mPisyncFinished = true; | 1065 | mPisyncFinished = true; |
1028 | } | 1066 | } |
1029 | } | 1067 | } |
1030 | 1068 | ||
1031 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1069 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1032 | { | 1070 | { |
1033 | mPassWord = pw; | 1071 | mPassWord = pw; |
1034 | mSocket = 0; | 1072 | mSocket = 0; |
1035 | mSyncActionDialog = 0; | 1073 | mSyncActionDialog = 0; |
1036 | blockRC = false; | 1074 | blockRC = false; |
1037 | }; | 1075 | }; |
1038 | 1076 | ||
1039 | void KServerSocket::newConnection ( int socket ) | 1077 | void KServerSocket::newConnection ( int socket ) |
1040 | { | 1078 | { |
1041 | // qDebug("KServerSocket:New connection %d ", socket); | 1079 | // qDebug("KServerSocket:New connection %d ", socket); |
1042 | if ( mSocket ) { | 1080 | if ( mSocket ) { |
1043 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1081 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1044 | delete mSocket; | 1082 | delete mSocket; |
1045 | mSocket = 0; | 1083 | mSocket = 0; |
1046 | } | 1084 | } |
1047 | mSocket = new QSocket( this ); | 1085 | mSocket = new QSocket( this ); |
1048 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1086 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1049 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1087 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1050 | mSocket->setSocket( socket ); | 1088 | mSocket->setSocket( socket ); |
1051 | } | 1089 | } |
1052 | 1090 | ||
1053 | void KServerSocket::discardClient() | 1091 | void KServerSocket::discardClient() |
1054 | { | 1092 | { |
1055 | //qDebug(" KServerSocket::discardClient()"); | 1093 | //qDebug(" KServerSocket::discardClient()"); |
1056 | if ( mSocket ) { | 1094 | if ( mSocket ) { |
1057 | delete mSocket; | 1095 | delete mSocket; |
1058 | mSocket = 0; | 1096 | mSocket = 0; |
1059 | } | 1097 | } |
1060 | //emit endConnect(); | 1098 | //emit endConnect(); |
1061 | } | 1099 | } |
1062 | void KServerSocket::readClient() | 1100 | void KServerSocket::readClient() |
1063 | { | 1101 | { |
1064 | if ( blockRC ) | 1102 | if ( blockRC ) |
1065 | return; | 1103 | return; |
1066 | if ( mSocket == 0 ) { | 1104 | if ( mSocket == 0 ) { |
1067 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1105 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1068 | return; | 1106 | return; |
1069 | } | 1107 | } |
1070 | //qDebug("KServerSocket::readClient()"); | 1108 | //qDebug("KServerSocket::readClient()"); |
1071 | if ( mSocket->canReadLine() ) { | 1109 | if ( mSocket->canReadLine() ) { |
1072 | QString line = mSocket->readLine(); | 1110 | QString line = mSocket->readLine(); |
1073 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1111 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1074 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1112 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1075 | if ( tokens[0] == "GET" ) { | 1113 | if ( tokens[0] == "GET" ) { |
1076 | if ( tokens[1] == mPassWord ) | 1114 | if ( tokens[1] == mPassWord ) |
1077 | //emit sendFile( mSocket ); | 1115 | //emit sendFile( mSocket ); |
1078 | send_file(); | 1116 | send_file(); |
1079 | else { | 1117 | else { |
1080 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1118 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1081 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1119 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1082 | } | 1120 | } |
1083 | } | 1121 | } |
1084 | if ( tokens[0] == "PUT" ) { | 1122 | if ( tokens[0] == "PUT" ) { |
1085 | if ( tokens[1] == mPassWord ) { | 1123 | if ( tokens[1] == mPassWord ) { |
1086 | //emit getFile( mSocket ); | 1124 | //emit getFile( mSocket ); |
1087 | blockRC = true; | 1125 | blockRC = true; |
1088 | get_file(); | 1126 | get_file(); |
1089 | } | 1127 | } |
1090 | else { | 1128 | else { |
1091 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1129 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1092 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1130 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1093 | } | 1131 | } |
1094 | } | 1132 | } |
1095 | if ( tokens[0] == "STOP" ) { | 1133 | if ( tokens[0] == "STOP" ) { |
1096 | //emit endConnect(); | 1134 | //emit endConnect(); |
1097 | end_connect(); | 1135 | end_connect(); |
1098 | } | 1136 | } |
1099 | } | 1137 | } |
1100 | } | 1138 | } |
1101 | void KServerSocket::end_connect() | 1139 | void KServerSocket::end_connect() |
1102 | { | 1140 | { |
1103 | delete mSyncActionDialog; | 1141 | delete mSyncActionDialog; |
1104 | mSyncActionDialog = 0; | 1142 | mSyncActionDialog = 0; |
1105 | } | 1143 | } |
1106 | void KServerSocket::send_file() | 1144 | void KServerSocket::send_file() |
1107 | { | 1145 | { |
1108 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1146 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1109 | if ( mSyncActionDialog ) | 1147 | if ( mSyncActionDialog ) |
1110 | delete mSyncActionDialog; | 1148 | delete mSyncActionDialog; |
1111 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1149 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1112 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1150 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1113 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1151 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1114 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1152 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1115 | lay->addWidget( label); | 1153 | lay->addWidget( label); |
1116 | lay->setMargin(7); | 1154 | lay->setMargin(7); |
1117 | lay->setSpacing(7); | 1155 | lay->setSpacing(7); |
1118 | mSyncActionDialog->setFixedSize( 230, 120); | 1156 | mSyncActionDialog->setFixedSize( 230, 120); |
1119 | mSyncActionDialog->show(); | 1157 | mSyncActionDialog->show(); |
1120 | mSyncActionDialog->raise(); | 1158 | mSyncActionDialog->raise(); |
1121 | emit request_file(); | 1159 | emit request_file(); |
1122 | qApp->processEvents(); | 1160 | qApp->processEvents(); |
1123 | QString fileName = mFileName; | 1161 | QString fileName = mFileName; |
1124 | QFile file( fileName ); | 1162 | QFile file( fileName ); |
1125 | if (!file.open( IO_ReadOnly ) ) { | 1163 | if (!file.open( IO_ReadOnly ) ) { |
1126 | delete mSyncActionDialog; | 1164 | delete mSyncActionDialog; |
1127 | mSyncActionDialog = 0; | 1165 | mSyncActionDialog = 0; |
1128 | qDebug("KSS::error open file "); | 1166 | qDebug("KSS::error open file "); |
1129 | mSocket->close(); | 1167 | mSocket->close(); |
1130 | if ( mSocket->state() == QSocket::Idle ) | 1168 | if ( mSocket->state() == QSocket::Idle ) |
1131 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1169 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1132 | return ; | 1170 | return ; |
1133 | 1171 | ||
1134 | } | 1172 | } |
1135 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1173 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1136 | QTextStream ts( &file ); | 1174 | QTextStream ts( &file ); |
1137 | ts.setEncoding( QTextStream::Latin1 ); | 1175 | ts.setEncoding( QTextStream::Latin1 ); |
1138 | 1176 | ||
1139 | QTextStream os( mSocket ); | 1177 | QTextStream os( mSocket ); |
1140 | os.setEncoding( QTextStream::Latin1 ); | 1178 | os.setEncoding( QTextStream::Latin1 ); |
1141 | while ( ! ts.atEnd() ) { | 1179 | while ( ! ts.atEnd() ) { |
1142 | os << ts.readLine() << "\r\n"; | 1180 | os << ts.readLine() << "\r\n"; |
1143 | } | 1181 | } |
1144 | //os << ts.read(); | 1182 | //os << ts.read(); |
1145 | file.close(); | 1183 | file.close(); |
1146 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1184 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1147 | mSocket->close(); | 1185 | mSocket->close(); |
1148 | if ( mSocket->state() == QSocket::Idle ) | 1186 | if ( mSocket->state() == QSocket::Idle ) |
1149 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1187 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1150 | } | 1188 | } |
1151 | void KServerSocket::get_file() | 1189 | void KServerSocket::get_file() |
1152 | { | 1190 | { |
1153 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1191 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1154 | 1192 | ||
1155 | piTime.start(); | 1193 | piTime.start(); |
1156 | piFileString = ""; | 1194 | piFileString = ""; |
1157 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1195 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1158 | } | 1196 | } |
1159 | 1197 | ||
1160 | 1198 | ||
1161 | void KServerSocket::readBackFileFromSocket() | 1199 | void KServerSocket::readBackFileFromSocket() |
1162 | { | 1200 | { |
1163 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1201 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1164 | while ( mSocket->canReadLine () ) { | 1202 | while ( mSocket->canReadLine () ) { |
1165 | piTime.restart(); | 1203 | piTime.restart(); |
1166 | QString line = mSocket->readLine (); | 1204 | QString line = mSocket->readLine (); |
1167 | piFileString += line; | 1205 | piFileString += line; |
1168 | //qDebug("readline: %s ", line.latin1()); | 1206 | //qDebug("readline: %s ", line.latin1()); |
1169 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1207 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1170 | 1208 | ||
1171 | } | 1209 | } |
1172 | if ( piTime.elapsed () < 3000 ) { | 1210 | if ( piTime.elapsed () < 3000 ) { |
1173 | // wait for more | 1211 | // wait for more |
1174 | //qDebug("waitformore "); | 1212 | //qDebug("waitformore "); |
1175 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1213 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1176 | return; | 1214 | return; |
1177 | } | 1215 | } |
1178 | QString fileName = mFileName; | 1216 | QString fileName = mFileName; |
1179 | QFile file ( fileName ); | 1217 | QFile file ( fileName ); |
1180 | if (!file.open( IO_WriteOnly ) ) { | 1218 | if (!file.open( IO_WriteOnly ) ) { |
1181 | delete mSyncActionDialog; | 1219 | delete mSyncActionDialog; |
1182 | mSyncActionDialog = 0; | 1220 | mSyncActionDialog = 0; |
1183 | qDebug("KSS:Error open read back file "); | 1221 | qDebug("KSS:Error open read back file "); |
1184 | piFileString = ""; | 1222 | piFileString = ""; |
1185 | emit file_received( false ); | 1223 | emit file_received( false ); |
1186 | blockRC = false; | 1224 | blockRC = false; |
1187 | return ; | 1225 | return ; |
1188 | 1226 | ||
1189 | } | 1227 | } |
1190 | 1228 | ||
1191 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1229 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1192 | QTextStream ts ( &file ); | 1230 | QTextStream ts ( &file ); |
1193 | ts.setEncoding( QTextStream::Latin1 ); | 1231 | ts.setEncoding( QTextStream::Latin1 ); |
1194 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1232 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1195 | ts << piFileString; | 1233 | ts << piFileString; |
1196 | mSocket->close(); | 1234 | mSocket->close(); |
1197 | if ( mSocket->state() == QSocket::Idle ) | 1235 | if ( mSocket->state() == QSocket::Idle ) |
1198 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1236 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1199 | file.close(); | 1237 | file.close(); |
1200 | piFileString = ""; | 1238 | piFileString = ""; |
1201 | emit file_received( true ); | 1239 | emit file_received( true ); |
1202 | delete mSyncActionDialog; | 1240 | delete mSyncActionDialog; |
1203 | mSyncActionDialog = 0; | 1241 | mSyncActionDialog = 0; |
1204 | blockRC = false; | 1242 | blockRC = false; |
1205 | 1243 | ||
1206 | } | 1244 | } |
1207 | 1245 | ||
1208 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1246 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1209 | { | 1247 | { |
1210 | mPassWord = password; | 1248 | mPassWord = password; |
1211 | mSocket = 0; | 1249 | mSocket = 0; |
1212 | mPort = port; | 1250 | mPort = port; |
1213 | mHost = host; | 1251 | mHost = host; |
1214 | 1252 | ||
1215 | mRetVal = quiet; | 1253 | mRetVal = quiet; |
1216 | mTimerSocket = new QTimer ( this ); | 1254 | mTimerSocket = new QTimer ( this ); |
1217 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1255 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1218 | } | 1256 | } |
1219 | void KCommandSocket::readFile( QString fn ) | 1257 | void KCommandSocket::readFile( QString fn ) |
1220 | { | 1258 | { |
1221 | if ( !mSocket ) { | 1259 | if ( !mSocket ) { |
1222 | mSocket = new QSocket( this ); | 1260 | mSocket = new QSocket( this ); |
1223 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1261 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1224 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1262 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1225 | } | 1263 | } |
1226 | mFileString = ""; | 1264 | mFileString = ""; |
1227 | mFileName = fn; | 1265 | mFileName = fn; |
1228 | mFirst = true; | 1266 | mFirst = true; |
1229 | mSocket->connectToHost( mHost, mPort ); | 1267 | mSocket->connectToHost( mHost, mPort ); |
1230 | QTextStream os( mSocket ); | 1268 | QTextStream os( mSocket ); |
1231 | os.setEncoding( QTextStream::Latin1 ); | 1269 | os.setEncoding( QTextStream::Latin1 ); |
1232 | os << "GET " << mPassWord << "\r\n"; | 1270 | os << "GET " << mPassWord << "\r\n"; |
1233 | mTimerSocket->start( 20000 ); | 1271 | mTimerSocket->start( 20000 ); |
1234 | } | 1272 | } |
1235 | 1273 | ||
1236 | void KCommandSocket::writeFile( QString fileName ) | 1274 | void KCommandSocket::writeFile( QString fileName ) |
1237 | { | 1275 | { |
1238 | if ( !mSocket ) { | 1276 | if ( !mSocket ) { |
1239 | mSocket = new QSocket( this ); | 1277 | mSocket = new QSocket( this ); |
1240 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1278 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1241 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1279 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1242 | } | 1280 | } |
1243 | mFileName = fileName ; | 1281 | mFileName = fileName ; |
1244 | mSocket->connectToHost( mHost, mPort ); | 1282 | mSocket->connectToHost( mHost, mPort ); |
1245 | } | 1283 | } |
1246 | void KCommandSocket::writeFileToSocket() | 1284 | void KCommandSocket::writeFileToSocket() |
1247 | { | 1285 | { |
1248 | QFile file2( mFileName ); | 1286 | QFile file2( mFileName ); |
1249 | if (!file2.open( IO_ReadOnly ) ) { | 1287 | if (!file2.open( IO_ReadOnly ) ) { |
1250 | mRetVal= errorW; | 1288 | mRetVal= errorW; |
1251 | mSocket->close(); | 1289 | mSocket->close(); |
1252 | if ( mSocket->state() == QSocket::Idle ) | 1290 | if ( mSocket->state() == QSocket::Idle ) |
1253 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1291 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1254 | return ; | 1292 | return ; |
1255 | } | 1293 | } |
1256 | QTextStream ts2( &file2 ); | 1294 | QTextStream ts2( &file2 ); |
1257 | ts2.setEncoding( QTextStream::Latin1 ); | 1295 | ts2.setEncoding( QTextStream::Latin1 ); |
1258 | QTextStream os2( mSocket ); | 1296 | QTextStream os2( mSocket ); |
1259 | os2.setEncoding( QTextStream::Latin1 ); | 1297 | os2.setEncoding( QTextStream::Latin1 ); |
1260 | os2 << "PUT " << mPassWord << "\r\n";; | 1298 | os2 << "PUT " << mPassWord << "\r\n";; |
1261 | while ( ! ts2.atEnd() ) { | 1299 | while ( ! ts2.atEnd() ) { |
1262 | os2 << ts2.readLine() << "\r\n"; | 1300 | os2 << ts2.readLine() << "\r\n"; |
1263 | } | 1301 | } |
1264 | mRetVal= successW; | 1302 | mRetVal= successW; |
1265 | file2.close(); | 1303 | file2.close(); |
1266 | mSocket->close(); | 1304 | mSocket->close(); |
1267 | if ( mSocket->state() == QSocket::Idle ) | 1305 | if ( mSocket->state() == QSocket::Idle ) |
1268 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1306 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1269 | } | 1307 | } |
1270 | void KCommandSocket::sendStop() | 1308 | void KCommandSocket::sendStop() |
1271 | { | 1309 | { |
1272 | if ( !mSocket ) { | 1310 | if ( !mSocket ) { |
1273 | mSocket = new QSocket( this ); | 1311 | mSocket = new QSocket( this ); |
1274 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1312 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1275 | } | 1313 | } |
1276 | mSocket->connectToHost( mHost, mPort ); | 1314 | mSocket->connectToHost( mHost, mPort ); |
1277 | QTextStream os2( mSocket ); | 1315 | QTextStream os2( mSocket ); |
1278 | os2.setEncoding( QTextStream::Latin1 ); | 1316 | os2.setEncoding( QTextStream::Latin1 ); |
1279 | os2 << "STOP\r\n"; | 1317 | os2 << "STOP\r\n"; |
1280 | mSocket->close(); | 1318 | mSocket->close(); |
1281 | if ( mSocket->state() == QSocket::Idle ) | 1319 | if ( mSocket->state() == QSocket::Idle ) |
1282 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1320 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1283 | } | 1321 | } |
1284 | 1322 | ||
1285 | void KCommandSocket::startReadFileFromSocket() | 1323 | void KCommandSocket::startReadFileFromSocket() |
1286 | { | 1324 | { |
1287 | if ( ! mFirst ) | 1325 | if ( ! mFirst ) |
1288 | return; | 1326 | return; |
1289 | mFirst = false; | 1327 | mFirst = false; |
1290 | mTimerSocket->stop(); | 1328 | mTimerSocket->stop(); |
1291 | mFileString = ""; | 1329 | mFileString = ""; |
1292 | mTime.start(); | 1330 | mTime.start(); |
1293 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1331 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1294 | 1332 | ||
1295 | } | 1333 | } |
1296 | void KCommandSocket::readFileFromSocket() | 1334 | void KCommandSocket::readFileFromSocket() |
1297 | { | 1335 | { |
1298 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1336 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1299 | while ( mSocket->canReadLine () ) { | 1337 | while ( mSocket->canReadLine () ) { |
1300 | mTime.restart(); | 1338 | mTime.restart(); |
1301 | QString line = mSocket->readLine (); | 1339 | QString line = mSocket->readLine (); |
1302 | mFileString += line; | 1340 | mFileString += line; |
1303 | //qDebug("readline: %s ", line.latin1()); | 1341 | //qDebug("readline: %s ", line.latin1()); |
1304 | } | 1342 | } |
1305 | if ( mTime.elapsed () < 3000 ) { | 1343 | if ( mTime.elapsed () < 3000 ) { |
1306 | // wait for more | 1344 | // wait for more |
1307 | //qDebug("waitformore "); | 1345 | //qDebug("waitformore "); |
1308 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1346 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1309 | return; | 1347 | return; |
1310 | } | 1348 | } |
1311 | QString fileName = mFileName; | 1349 | QString fileName = mFileName; |
1312 | QFile file ( fileName ); | 1350 | QFile file ( fileName ); |
1313 | if (!file.open( IO_WriteOnly ) ) { | 1351 | if (!file.open( IO_WriteOnly ) ) { |
1314 | mFileString = ""; | 1352 | mFileString = ""; |
1315 | mRetVal = errorR; | 1353 | mRetVal = errorR; |
1316 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1354 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1317 | deleteSocket(); | 1355 | deleteSocket(); |
1318 | return ; | 1356 | return ; |
1319 | 1357 | ||
1320 | } | 1358 | } |
1321 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1359 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1322 | QTextStream ts ( &file ); | 1360 | QTextStream ts ( &file ); |
1323 | ts.setEncoding( QTextStream::Latin1 ); | 1361 | ts.setEncoding( QTextStream::Latin1 ); |
1324 | ts << mFileString; | 1362 | ts << mFileString; |
1325 | file.close(); | 1363 | file.close(); |
1326 | mFileString = ""; | 1364 | mFileString = ""; |
1327 | mRetVal = successR; | 1365 | mRetVal = successR; |
1328 | mSocket->close(); | 1366 | mSocket->close(); |
1329 | // if state is not idle, deleteSocket(); is called via | 1367 | // if state is not idle, deleteSocket(); is called via |
1330 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1368 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1331 | if ( mSocket->state() == QSocket::Idle ) | 1369 | if ( mSocket->state() == QSocket::Idle ) |
1332 | deleteSocket(); | 1370 | deleteSocket(); |
1333 | } | 1371 | } |
1334 | 1372 | ||
1335 | void KCommandSocket::deleteSocket() | 1373 | void KCommandSocket::deleteSocket() |
1336 | { | 1374 | { |
1337 | //qDebug("KCommandSocket::deleteSocket() "); | 1375 | //qDebug("KCommandSocket::deleteSocket() "); |
1338 | if ( mTimerSocket->isActive () ) { | 1376 | if ( mTimerSocket->isActive () ) { |
1339 | mTimerSocket->stop(); | 1377 | mTimerSocket->stop(); |
1340 | mRetVal = errorTO; | 1378 | mRetVal = errorTO; |
1341 | qDebug("Connection to remote host timed out"); | 1379 | qDebug("Connection to remote host timed out"); |
1342 | if ( mSocket ) { | 1380 | if ( mSocket ) { |
1343 | mSocket->close(); | 1381 | mSocket->close(); |
1344 | //if ( mSocket->state() == QSocket::Idle ) | 1382 | //if ( mSocket->state() == QSocket::Idle ) |
1345 | // deleteSocket(); | 1383 | // deleteSocket(); |
1346 | delete mSocket; | 1384 | delete mSocket; |
1347 | mSocket = 0; | 1385 | mSocket = 0; |
1348 | } | 1386 | } |
1349 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1387 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1350 | emit commandFinished( this, mRetVal ); | 1388 | emit commandFinished( this, mRetVal ); |
1351 | return; | 1389 | return; |
1352 | } | 1390 | } |
1353 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1391 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1354 | if ( mSocket) | 1392 | if ( mSocket) |
1355 | delete mSocket; | 1393 | delete mSocket; |
1356 | mSocket = 0; | 1394 | mSocket = 0; |
1357 | emit commandFinished( this, mRetVal ); | 1395 | emit commandFinished( this, mRetVal ); |
1358 | } | 1396 | } |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index af4f1ab..aa32e28 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -1,212 +1,213 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | $Id$ | 20 | $Id$ |
21 | */ | 21 | */ |
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qsocket.h> | 27 | #include <qsocket.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qserversocket.h> | 29 | #include <qserversocket.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | 32 | ||
33 | class QPopupMenu; | 33 | class QPopupMenu; |
34 | class KSyncProfile; | 34 | class KSyncProfile; |
35 | class KPimPrefs; | 35 | class KPimPrefs; |
36 | class QWidget; | 36 | class QWidget; |
37 | class KSyncManager; | 37 | class KSyncManager; |
38 | class KSyncInterface; | 38 | class KSyncInterface; |
39 | class QProgressBar; | 39 | class QProgressBar; |
40 | 40 | ||
41 | 41 | ||
42 | class KServerSocket : public QServerSocket | 42 | class KServerSocket : public QServerSocket |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | 45 | ||
46 | public: | 46 | public: |
47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
48 | 48 | ||
49 | void newConnection ( int socket ) ; | 49 | void newConnection ( int socket ) ; |
50 | void setFileName( QString fn ) {mFileName = fn;}; | 50 | void setFileName( QString fn ) {mFileName = fn;}; |
51 | signals: | 51 | signals: |
52 | void file_received( bool ); | 52 | void file_received( bool ); |
53 | void request_file(); | 53 | void request_file(); |
54 | void saveFile(); | 54 | void saveFile(); |
55 | void endConnect(); | 55 | void endConnect(); |
56 | private slots: | 56 | private slots: |
57 | void discardClient(); | 57 | void discardClient(); |
58 | void readClient(); | 58 | void readClient(); |
59 | void readBackFileFromSocket(); | 59 | void readBackFileFromSocket(); |
60 | private : | 60 | private : |
61 | bool blockRC; | 61 | bool blockRC; |
62 | void send_file(); | 62 | void send_file(); |
63 | void get_file(); | 63 | void get_file(); |
64 | void end_connect(); | 64 | void end_connect(); |
65 | QDialog* mSyncActionDialog; | 65 | QDialog* mSyncActionDialog; |
66 | QSocket* mSocket; | 66 | QSocket* mSocket; |
67 | QString mPassWord; | 67 | QString mPassWord; |
68 | QString mFileName; | 68 | QString mFileName; |
69 | QTime piTime; | 69 | QTime piTime; |
70 | QString piFileString; | 70 | QString piFileString; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | class KCommandSocket : public QObject | 73 | class KCommandSocket : public QObject |
74 | { | 74 | { |
75 | Q_OBJECT | 75 | Q_OBJECT |
76 | public: | 76 | public: |
77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; | 77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; |
78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); |
79 | void readFile( QString ); | 79 | void readFile( QString ); |
80 | void writeFile( QString ); | 80 | void writeFile( QString ); |
81 | void sendStop(); | 81 | void sendStop(); |
82 | 82 | ||
83 | signals: | 83 | signals: |
84 | void commandFinished( KCommandSocket*, int ); | 84 | void commandFinished( KCommandSocket*, int ); |
85 | private slots: | 85 | private slots: |
86 | void startReadFileFromSocket(); | 86 | void startReadFileFromSocket(); |
87 | void readFileFromSocket(); | 87 | void readFileFromSocket(); |
88 | void deleteSocket(); | 88 | void deleteSocket(); |
89 | void writeFileToSocket(); | 89 | void writeFileToSocket(); |
90 | private : | 90 | private : |
91 | QSocket* mSocket; | 91 | QSocket* mSocket; |
92 | QString mPassWord; | 92 | QString mPassWord; |
93 | Q_UINT16 mPort; | 93 | Q_UINT16 mPort; |
94 | QString mHost; | 94 | QString mHost; |
95 | QString mFileName; | 95 | QString mFileName; |
96 | QTimer* mTimerSocket; | 96 | QTimer* mTimerSocket; |
97 | int mRetVal; | 97 | int mRetVal; |
98 | QTime mTime; | 98 | QTime mTime; |
99 | QString mFileString; | 99 | QString mFileString; |
100 | bool mFirst; | 100 | bool mFirst; |
101 | }; | 101 | }; |
102 | 102 | ||
103 | 103 | ||
104 | class KSyncManager : public QObject | 104 | class KSyncManager : public QObject |
105 | { | 105 | { |
106 | Q_OBJECT | 106 | Q_OBJECT |
107 | 107 | ||
108 | public: | 108 | public: |
109 | enum TargetApp { | 109 | enum TargetApp { |
110 | KOPI = 0, | 110 | KOPI = 0, |
111 | KAPI = 1, | 111 | KAPI = 1, |
112 | PWMPI = 2 }; | 112 | PWMPI = 2 }; |
113 | 113 | ||
114 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | 114 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); |
115 | ~KSyncManager() ; | 115 | ~KSyncManager() ; |
116 | 116 | ||
117 | void multiSync( bool askforPrefs ); | 117 | void multiSync( bool askforPrefs ); |
118 | bool blockSave() { return mBlockSaveFlag; } | 118 | bool blockSave() { return mBlockSaveFlag; } |
119 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | 119 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } |
120 | void setDefaultFileName( QString s) { mDefFileName = s ;} | 120 | void setDefaultFileName( QString s) { mDefFileName = s ;} |
121 | QString defaultFileName() { return mDefFileName ;} | 121 | QString defaultFileName() { return mDefFileName ;} |
122 | QString syncFileName(); | 122 | QString syncFileName(); |
123 | void enableQuick( bool ask = true); | 123 | void enableQuick( bool ask = true); |
124 | 124 | ||
125 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } | 125 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
126 | QString getCurrentSyncName() { return mCurrentSyncName; } | 126 | QString getCurrentSyncName() { return mCurrentSyncName; } |
127 | 127 | ||
128 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); | 128 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); |
129 | void hideProgressBar(); | 129 | void hideProgressBar(); |
130 | bool isProgressBarCanceled(); | 130 | bool isProgressBarCanceled(); |
131 | 131 | ||
132 | // sync stuff | 132 | // sync stuff |
133 | QString mLocalMachineName; | 133 | QString mLocalMachineName; |
134 | QStringList mExternSyncProfiles; | 134 | QStringList mExternSyncProfiles; |
135 | QStringList mSyncProfileNames; | 135 | QStringList mSyncProfileNames; |
136 | bool mAskForPreferences; | 136 | bool mAskForPreferences; |
137 | bool mShowSyncSummary; | 137 | bool mShowSyncSummary; |
138 | bool mIsKapiFile; | 138 | bool mIsKapiFile; |
139 | bool mWriteBackExistingOnly; | 139 | bool mWriteBackExistingOnly; |
140 | int mSyncAlgoPrefs; | 140 | int mSyncAlgoPrefs; |
141 | bool mWriteBackFile; | 141 | bool mWriteBackFile; |
142 | int mWriteBackInFuture; | 142 | int mWriteBackInFuture; |
143 | QString mPhoneDevice; | 143 | QString mPhoneDevice; |
144 | QString mPhoneConnection; | 144 | QString mPhoneConnection; |
145 | QString mPhoneModel; | 145 | QString mPhoneModel; |
146 | QString mPassWordPiSync; | 146 | QString mPassWordPiSync; |
147 | QString mActiveSyncPort; | 147 | QString mActiveSyncPort; |
148 | QString mActiveSyncIP ; | 148 | QString mActiveSyncIP ; |
149 | 149 | ||
150 | signals: | 150 | signals: |
151 | void save(); | 151 | void save(); |
152 | void request_file(); | 152 | void request_file(); |
153 | void getFile( bool ); | 153 | void getFile( bool ); |
154 | 154 | ||
155 | public slots: | 155 | public slots: |
156 | void slotSyncMenu( int ); | 156 | void slotSyncMenu( int ); |
157 | void slotClearMenu( int action ); | ||
157 | void deleteCommandSocket(KCommandSocket*s, int state); | 158 | void deleteCommandSocket(KCommandSocket*s, int state); |
158 | void readFileFromSocket(); | 159 | void readFileFromSocket(); |
159 | void fillSyncMenu(); | 160 | void fillSyncMenu(); |
160 | 161 | ||
161 | private: | 162 | private: |
162 | void syncPi(); | 163 | void syncPi(); |
163 | KServerSocket * mServerSocket; | 164 | KServerSocket * mServerSocket; |
164 | KPimPrefs* mPrefs; | 165 | KPimPrefs* mPrefs; |
165 | QString mDefFileName; | 166 | QString mDefFileName; |
166 | QString mCurrentSyncDevice; | 167 | QString mCurrentSyncDevice; |
167 | QString mCurrentSyncName; | 168 | QString mCurrentSyncName; |
168 | void quickSyncLocalFile(); | 169 | void quickSyncLocalFile(); |
169 | bool syncWithFile( QString fn , bool quick ); | 170 | bool syncWithFile( QString fn , bool quick ); |
170 | void syncLocalFile(); | 171 | void syncLocalFile(); |
171 | void syncPhone(); | 172 | void syncPhone(); |
172 | void syncSharp(); | 173 | void syncSharp(); |
173 | void syncKDE(); | 174 | void syncKDE(); |
174 | bool syncExternalApplication(QString); | 175 | bool syncExternalApplication(QString); |
175 | int mCurrentSyncProfile ; | 176 | int mCurrentSyncProfile ; |
176 | void syncRemote( KSyncProfile* prof, bool ask = true); | 177 | void syncRemote( KSyncProfile* prof, bool ask = true); |
177 | bool edit_sync_options(); | 178 | bool edit_sync_options(); |
178 | bool edit_pisync_options(); | 179 | bool edit_pisync_options(); |
179 | int ringSync(); | 180 | int ringSync(); |
180 | QString getPassword( ); | 181 | QString getPassword( ); |
181 | bool mPisyncFinished; | 182 | bool mPisyncFinished; |
182 | bool mBlockSaveFlag; | 183 | bool mBlockSaveFlag; |
183 | QWidget* mParent; | 184 | QWidget* mParent; |
184 | KSyncInterface* mImplementation; | 185 | KSyncInterface* mImplementation; |
185 | TargetApp mTargetApp; | 186 | TargetApp mTargetApp; |
186 | QPopupMenu* mSyncMenu; | 187 | QPopupMenu* mSyncMenu; |
187 | QProgressBar* bar; | 188 | QProgressBar* bar; |
188 | 189 | ||
189 | private slots: | 190 | private slots: |
190 | void confSync(); | 191 | void confSync(); |
191 | 192 | ||
192 | 193 | ||
193 | }; | 194 | }; |
194 | 195 | ||
195 | 196 | ||
196 | class KSyncInterface | 197 | class KSyncInterface |
197 | { | 198 | { |
198 | public : | 199 | public : |
199 | virtual void removeSyncInfo( QString syncProfile) = 0; | 200 | virtual void removeSyncInfo( QString syncProfile) = 0; |
200 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; | 201 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; |
201 | virtual bool syncExternal(KSyncManager* manager, QString resource) | 202 | virtual bool syncExternal(KSyncManager* manager, QString resource) |
202 | { | 203 | { |
203 | // empty implementation, because some syncable applications do not | 204 | // empty implementation, because some syncable applications do not |
204 | // have an external(sharpdtm) syncmode, like pwmanager. | 205 | // have an external(sharpdtm) syncmode, like pwmanager. |
205 | return false; | 206 | return false; |
206 | } | 207 | } |
207 | 208 | ||
208 | 209 | ||
209 | }; | 210 | }; |
210 | 211 | ||
211 | 212 | ||
212 | #endif | 213 | #endif |