summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/qtopia/qtopiaconverter.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/qtopia/qtopiaconverter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index 9693a68..9b3903b 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -1,123 +1,125 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US 28//US
29#include "kglobal.h" 29#include "kglobal.h"
30#include "klocale.h" 30#include "klocale.h"
31 31
32 32
33#include "qtopiaconverter.h" 33#include "qtopiaconverter.h"
34 34
35#include <qfile.h> 35#include <qfile.h>
36#include <qdir.h> 36#include <qdir.h>
37#include <qtextstream.h> 37#include <q3textstream.h>
38//Added by qt3to4:
39#include <Q3ValueList>
38//#include <.h> 40//#include <.h>
39 41
40#include <libkdepim/ksyncprofile.h> 42#include <libkdepim/ksyncprofile.h>
41 43
42 44
43using namespace KABC; 45using namespace KABC;
44 46
45QtopiaConverter::QtopiaConverter() 47QtopiaConverter::QtopiaConverter()
46{ 48{
47 m_edit = 0; 49 m_edit = 0;
48} 50}
49 51
50QtopiaConverter::~QtopiaConverter() 52QtopiaConverter::~QtopiaConverter()
51{ 53{
52 deinit(); 54 deinit();
53} 55}
54 56
55bool QtopiaConverter::init() 57bool QtopiaConverter::init()
56{ 58{
57 QString fn = QDir::homeDirPath() +"/Settings/Categories.xml"; 59 QString fn = QDir::homeDirPath() +"/Settings/Categories.xml";
58 m_edit = new CategoryEdit( fn); 60 m_edit = new CategoryEdit( fn);
59 return true; 61 return true;
60} 62}
61 63
62void QtopiaConverter::deinit() 64void QtopiaConverter::deinit()
63{ 65{
64 if (m_edit) 66 if (m_edit)
65 { 67 {
66 delete m_edit; 68 delete m_edit;
67 m_edit = 0; 69 m_edit = 0;
68 } 70 }
69} 71}
70QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) 72QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app )
71{ 73{
72 startover: 74 startover:
73 QStringList dummy; 75 QStringList dummy;
74 QValueList<OpieCategories>::ConstIterator catIt; 76 Q3ValueList<OpieCategories>::ConstIterator catIt;
75 QValueList<OpieCategories> categories = m_edit->categories(); 77 Q3ValueList<OpieCategories> categories = m_edit->categories();
76 bool found = false; 78 bool found = false;
77 for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { 79 for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) {
78 /* skip empty category name */ 80 /* skip empty category name */
79 if ( (*listIt).isEmpty() ) continue; 81 if ( (*listIt).isEmpty() ) continue;
80 82
81 found = false; 83 found = false;
82 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 84 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
83 /* 85 /*
84 * We currently do not take app into account 86 * We currently do not take app into account
85 * if name matches and the id isn't already in dummy we'll add it 87 * if name matches and the id isn't already in dummy we'll add it
86 */ 88 */
87 if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name 89 if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name
88 found= true; 90 found= true;
89 dummy << (*catIt).id(); 91 dummy << (*catIt).id();
90 } 92 }
91 } 93 }
92 /* if not found and the category is not empty 94 /* if not found and the category is not empty
93 * 95 *
94 * generate a new category and start over again 96 * generate a new category and start over again
95 * ugly goto to reiterate 97 * ugly goto to reiterate
96 */ 98 */
97 99
98 if ( !found && !(*listIt).isEmpty() ){ 100 if ( !found && !(*listIt).isEmpty() ){
99 m_edit->addCategory( app, (*listIt) ); // generate a new category 101 m_edit->addCategory( app, (*listIt) ); // generate a new category
100 goto startover; 102 goto startover;
101 } 103 }
102 } 104 }
103 105
104 return dummy.join(";"); 106 return dummy.join(";");
105} 107}
106 108
107 109
108// FROM TT timeconversion.cpp GPLed 110// FROM TT timeconversion.cpp GPLed
109QDate QtopiaConverter::fromString( const QString &datestr ) 111QDate QtopiaConverter::fromString( const QString &datestr )
110{ 112{
111 if (datestr.isEmpty() ) 113 if (datestr.isEmpty() )
112 return QDate(); 114 return QDate();
113 115
114 int monthPos = datestr.find('.'); 116 int monthPos = datestr.find('.');
115 int yearPos = datestr.find('.', monthPos+1 ); 117 int yearPos = datestr.find('.', monthPos+1 );
116 if ( monthPos == -1 || yearPos == -1 ) { 118 if ( monthPos == -1 || yearPos == -1 ) {
117 return QDate(); 119 return QDate();
118 } 120 }
119 int d = datestr.left( monthPos ).toInt(); 121 int d = datestr.left( monthPos ).toInt();
120 int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt(); 122 int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt();
121 int y = datestr.mid( yearPos+1 ).toInt(); 123 int y = datestr.mid( yearPos+1 ).toInt();
122 QDate date ( y,m,d ); 124 QDate date ( y,m,d );
123 125
@@ -147,97 +149,97 @@ QDate QtopiaConverter::dateFromString( const QString& s )
147 if ( year < 1900 || year > 3000 ) 149 if ( year < 1900 || year > 3000 )
148 return date; 150 return date;
149 151
150 if ( month < 0 || month > 12 ) 152 if ( month < 0 || month > 12 )
151 return date; 153 return date;
152 154
153 if ( day < 0 || day > 31 ) 155 if ( day < 0 || day > 31 )
154 return date; 156 return date;
155 157
156 158
157 date.setYMD( year, month, day ); 159 date.setYMD( year, month, day );
158 160
159 if ( !date.isValid() ) 161 if ( !date.isValid() )
160 return QDate(); 162 return QDate();
161 163
162 164
163 return date; 165 return date;
164} 166}
165QString QtopiaConverter::dateToString( const QDate &d ) 167QString QtopiaConverter::dateToString( const QDate &d )
166{ 168{
167 if ( d.isNull() || !d.isValid() ) 169 if ( d.isNull() || !d.isValid() )
168 return QString::null; 170 return QString::null;
169 171
170 // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 172 // ISO format in year, month, day (YYYYMMDD); e.g. 20021231
171 QString year = QString::number( d.year() ); 173 QString year = QString::number( d.year() );
172 QString month = QString::number( d.month() ); 174 QString month = QString::number( d.month() );
173 month = month.rightJustify( 2, '0' ); 175 month = month.rightJustify( 2, '0' );
174 QString day = QString::number( d.day() ); 176 QString day = QString::number( d.day() );
175 day = day.rightJustify( 2, '0' ); 177 day = day.rightJustify( 2, '0' );
176 178
177 QString str = year + month + day; 179 QString str = year + month + day;
178 180
179 return str; 181 return str;
180} 182}
181 183
182bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) 184bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr )
183{ 185{
184 { //LR 186 { //LR
185 187
186 adr.setUid( el.attribute("Uid" ) ); 188 adr.setUid( el.attribute("Uid" ) );
187 adr.setFamilyName( el.attribute( "LastName" ) ); 189 adr.setFamilyName( el.attribute( "LastName" ) );
188 adr.setGivenName( el.attribute( "FirstName" ) ); 190 adr.setGivenName( el.attribute( "FirstName" ) );
189 adr.setAdditionalName( el.attribute( "MiddleName" ) ); 191 adr.setAdditionalName( el.attribute( "MiddleName" ) );
190 adr.setSuffix( el.attribute( "Suffix" ) ); 192 adr.setSuffix( el.attribute( "Suffix" ) );
191 adr.setNickName( el.attribute( "Nickname" ) ); 193 adr.setNickName( el.attribute( "Nickname" ) );
192 194
193 QDate date = dateFromString( el.attribute( "Birthday" ) ); 195 QDate date = dateFromString( el.attribute( "Birthday" ) );
194 if ( date.isValid() ) 196 if ( date.isValid() )
195 adr.setBirthday( date ); 197 adr.setBirthday( (QDateTime)date );
196 198
197 adr.setRole( el.attribute( "JobTitle" ) ); 199 adr.setRole( el.attribute( "JobTitle" ) );
198 if ( !el.attribute( "FileAs" ).isEmpty() ) 200 if ( !el.attribute( "FileAs" ).isEmpty() )
199 adr.setFormattedName( el.attribute( "FileAs" ) ); 201 adr.setFormattedName( el.attribute( "FileAs" ) );
200 202
201 adr.setOrganization( el.attribute( "Company" ) ); 203 adr.setOrganization( el.attribute( "Company" ) );
202 204
203 KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), 205 KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ),
204 KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 206 KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
205 KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), 207 KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ),
206 KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 208 KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
207 KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), 209 KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ),
208 KABC::PhoneNumber::Car ); 210 KABC::PhoneNumber::Car );
209 KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), 211 KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ),
210 KABC::PhoneNumber::Pager ); 212 KABC::PhoneNumber::Pager );
211 if ( !businessPhoneNum.number().isEmpty() ) 213 if ( !businessPhoneNum.number().isEmpty() )
212 adr.insertPhoneNumber( businessPhoneNum ); 214 adr.insertPhoneNumber( businessPhoneNum );
213 if ( !businessFaxNum.number().isEmpty() ) 215 if ( !businessFaxNum.number().isEmpty() )
214 adr.insertPhoneNumber( businessFaxNum ); 216 adr.insertPhoneNumber( businessFaxNum );
215 if ( !businessMobile.number().isEmpty() ) 217 if ( !businessMobile.number().isEmpty() )
216 adr.insertPhoneNumber( businessMobile ); 218 adr.insertPhoneNumber( businessMobile );
217 if ( !businessPager.number().isEmpty() ) 219 if ( !businessPager.number().isEmpty() )
218 adr.insertPhoneNumber( businessPager ); 220 adr.insertPhoneNumber( businessPager );
219 221
220 // Handle multiple mail addresses 222 // Handle multiple mail addresses
221 QString DefaultEmail = el.attribute( "DefaultEmail" ); 223 QString DefaultEmail = el.attribute( "DefaultEmail" );
222 if ( !DefaultEmail.isEmpty() ) 224 if ( !DefaultEmail.isEmpty() )
223 adr.insertEmail( DefaultEmail, true ); // preferred 225 adr.insertEmail( DefaultEmail, true ); // preferred
224 226
225 QStringList Emails = QStringList::split(" ",el.attribute("Emails")); 227 QStringList Emails = QStringList::split(" ",el.attribute("Emails"));
226 int i; 228 int i;
227 for (i = 0;i < Emails.count();++i) { 229 for (i = 0;i < Emails.count();++i) {
228 if ( Emails[i] != DefaultEmail ) 230 if ( Emails[i] != DefaultEmail )
229 adr.insertEmail( Emails[i], false ); 231 adr.insertEmail( Emails[i], false );
230 } 232 }
231 233
232 KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ), 234 KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ),
233 KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref); 235 KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref);
234 KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ), 236 KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ),
235 KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 237 KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
236 238
237 KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ), 239 KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ),
238 KABC::PhoneNumber::Cell ); 240 KABC::PhoneNumber::Cell );
239 241
240 if ( !homePhoneNum.number().isEmpty() ) 242 if ( !homePhoneNum.number().isEmpty() )
241 adr.insertPhoneNumber( homePhoneNum ); 243 adr.insertPhoneNumber( homePhoneNum );
242 if ( !homeFax.number().isEmpty() ) 244 if ( !homeFax.number().isEmpty() )
243 adr.insertPhoneNumber( homeFax ); 245 adr.insertPhoneNumber( homeFax );
@@ -272,97 +274,97 @@ bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr )
272 QString cat; 274 QString cat;
273 QStringList added; 275 QStringList added;
274 for ( uint i = 0; i < categories.count(); i++ ) { 276 for ( uint i = 0; i < categories.count(); i++ ) {
275 cat = m_edit->categoryById( categories[ i ], "Contacts" ); 277 cat = m_edit->categoryById( categories[ i ], "Contacts" );
276 278
277 // if name is not empty and we did not add the 279 // if name is not empty and we did not add the
278 // cat try to repair broken files 280 // cat try to repair broken files
279 if ( !cat.isEmpty() && !added.contains( cat ) ) { 281 if ( !cat.isEmpty() && !added.contains( cat ) ) {
280 adr.insertCategory( cat ); 282 adr.insertCategory( cat );
281 added << cat; 283 added << cat;
282 } 284 }
283 } 285 }
284 } 286 }
285 287
286 if ( !el.attribute( "Department" ).isEmpty() ) 288 if ( !el.attribute( "Department" ).isEmpty() )
287 adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) ); 289 adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) );
288 if ( !el.attribute( "HomeWebPage" ).isEmpty() ) 290 if ( !el.attribute( "HomeWebPage" ).isEmpty() )
289 adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) ); 291 adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) );
290 if ( !el.attribute( "Spouse" ).isEmpty() ) 292 if ( !el.attribute( "Spouse" ).isEmpty() )
291 adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) ); 293 adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) );
292 if ( !el.attribute( "Gender" ).isEmpty() ) { 294 if ( !el.attribute( "Gender" ).isEmpty() ) {
293 if ( el.attribute( "Gender" ) == "1" ) 295 if ( el.attribute( "Gender" ) == "1" )
294 adr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); 296 adr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" );
295 else if ( el.attribute( "Gender" ) == "2" ) 297 else if ( el.attribute( "Gender" ) == "2" )
296 adr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); 298 adr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" );
297 } 299 }
298 QDate ann = dateFromString( el.attribute( "Anniversary" ) ); 300 QDate ann = dateFromString( el.attribute( "Anniversary" ) );
299 if ( ann.isValid() ) { 301 if ( ann.isValid() ) {
300 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); 302 QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate);
301 adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt ); 303 adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt );
302 } 304 }
303 305
304 if ( !el.attribute( "Children" ).isEmpty() ) 306 if ( !el.attribute( "Children" ).isEmpty() )
305 adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); 307 adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") );
306 if ( !el.attribute( "Office" ).isEmpty() ) 308 if ( !el.attribute( "Office" ).isEmpty() )
307 adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); 309 adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") );
308 if ( !el.attribute( "Profession" ).isEmpty() ) 310 if ( !el.attribute( "Profession" ).isEmpty() )
309 adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); 311 adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") );
310 if ( !el.attribute( "Assistant" ).isEmpty() ) 312 if ( !el.attribute( "Assistant" ).isEmpty() )
311 adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); 313 adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") );
312 if ( !el.attribute( "Manager" ).isEmpty() ) 314 if ( !el.attribute( "Manager" ).isEmpty() )
313 adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); 315 adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") );
314 316
315 317
316 } 318 }
317 return true; 319 return true;
318} 320}
319 321
320bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) 322bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, Q3TextStream *stream )
321{ 323{
322 *stream << "<Contact "; 324 *stream << "<Contact ";
323 *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; 325 *stream << "FirstName=\"" << escape(ab.givenName()) << "\" ";
324 *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; 326 *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" ";
325 *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; 327 *stream << "LastName=\"" << escape(ab.familyName()) << "\" ";
326 *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; 328 *stream << "Suffix=\"" << escape(ab.suffix()) << "\" ";
327 329
328 QString sortStr; 330 QString sortStr;
329 sortStr = ab.formattedName(); 331 sortStr = ab.formattedName();
330 /* is formattedName is empty we use the assembled name as fallback */ 332 /* is formattedName is empty we use the assembled name as fallback */
331 if (sortStr.isEmpty() ) 333 if (sortStr.isEmpty() )
332 sortStr = ab.assembledName(); 334 sortStr = ab.assembledName();
333 *stream << "FileAs=\"" << escape(sortStr) << "\" "; 335 *stream << "FileAs=\"" << escape(sortStr) << "\" ";
334 336
335 *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; 337 *stream << "JobTitle=\"" << escape(ab.role()) << "\" ";
336 *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; 338 *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" ";
337 *stream << "Company=\"" << escape(ab.organization()) << "\" "; 339 *stream << "Company=\"" << escape(ab.organization()) << "\" ";
338 340
339 KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work ); 341 KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work );
340 *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" "; 342 *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" ";
341 343
342 KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 344 KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
343 *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" "; 345 *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" ";
344 346
345 KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); 347 KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell );
346 *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" "; 348 *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" ";
347 349
348 *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" "; 350 *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" ";
349 QStringList list = ab.emails(); 351 QStringList list = ab.emails();
350 if ( list.count() > 0 ) { 352 if ( list.count() > 0 ) {
351 QStringList::Iterator it = list.begin(); 353 QStringList::Iterator it = list.begin();
352 *stream << "Emails=\"" << escape( *it ); 354 *stream << "Emails=\"" << escape( *it );
353 while (++it != list.end()) 355 while (++it != list.end())
354 *stream << ' ' << escape( *it ); 356 *stream << ' ' << escape( *it );
355 *stream << "\" "; 357 *stream << "\" ";
356 } 358 }
357 359
358 KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home ); 360 KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home );
359 *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" "; 361 *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" ";
360 362
361 KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 363 KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
362 *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" "; 364 *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" ";
363 365
364 KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell ); 366 KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell );
365 *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" "; 367 *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" ";
366 368
367 KABC::Address business = ab.address(KABC::Address::Work ); 369 KABC::Address business = ab.address(KABC::Address::Work );
368 *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" "; 370 *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" ";
@@ -439,200 +441,200 @@ QStringList AddressBook::attributes()const {
439 lst << "DefaultEmail"; 441 lst << "DefaultEmail";
440 lst << "Emails"; 442 lst << "Emails";
441 lst << "HomePhone"; 443 lst << "HomePhone";
442 lst << "HomeFax"; 444 lst << "HomeFax";
443 lst << "HomeMobile"; 445 lst << "HomeMobile";
444 lst << "BusinessStreet"; 446 lst << "BusinessStreet";
445 lst << "BusinessCity"; 447 lst << "BusinessCity";
446 lst << "BusinessZip"; 448 lst << "BusinessZip";
447 lst << "BusinessCountry"; 449 lst << "BusinessCountry";
448 lst << "BusinessState"; 450 lst << "BusinessState";
449 lst << "Office"; 451 lst << "Office";
450 lst << "Profession"; 452 lst << "Profession";
451 lst << "Assistant"; 453 lst << "Assistant";
452 lst << "Manager"; 454 lst << "Manager";
453 lst << "HomeStreet"; 455 lst << "HomeStreet";
454 lst << "HomeCity"; 456 lst << "HomeCity";
455 lst << "HomeState"; 457 lst << "HomeState";
456 lst << "HomeZip"; 458 lst << "HomeZip";
457 lst << "HomeCountry"; 459 lst << "HomeCountry";
458 lst << "HomeWebPage"; 460 lst << "HomeWebPage";
459 lst << "Spouse"; 461 lst << "Spouse";
460 lst << "Gender"; 462 lst << "Gender";
461 lst << "Anniversary"; 463 lst << "Anniversary";
462 lst << "Nickname"; 464 lst << "Nickname";
463 lst << "Children"; 465 lst << "Children";
464 lst << "Notes"; 466 lst << "Notes";
465 lst << "Categories"; 467 lst << "Categories";
466 lst << "Uid"; 468 lst << "Uid";
467 lst << "Birthday"; 469 lst << "Birthday";
468 470
469 return lst; 471 return lst;
470} 472}
471 473
472 474
473 475
474#endif 476#endif
475 477
476 478
477CategoryEdit::CategoryEdit(){ 479CategoryEdit::CategoryEdit(){
478} 480}
479CategoryEdit::CategoryEdit(const QString &fileName){ 481CategoryEdit::CategoryEdit(const QString &fileName){
480 parse( fileName ); 482 parse( fileName );
481} 483}
482CategoryEdit::~CategoryEdit(){ 484CategoryEdit::~CategoryEdit(){
483} 485}
484void CategoryEdit::save(const QString& fileName)const{ 486void CategoryEdit::save(const QString& fileName)const{
485 QFile file( fileName ); 487 QFile file( fileName );
486 QString endl = "\n"; 488 QString endl = "\n";
487 if ( file.open( IO_WriteOnly ) ) { 489 if ( file.open( QIODevice::WriteOnly ) ) {
488 QTextStream stream( &file ); 490 Q3TextStream stream( &file );
489 stream.setEncoding( QTextStream::UnicodeUTF8 ); 491 stream.setEncoding( Q3TextStream::UnicodeUTF8 );
490 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; 492 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
491 stream << "<!DOCTYPE CategoryList>" << endl; 493 stream << "<!DOCTYPE CategoryList>" << endl;
492 stream << "<Categories>" << endl; 494 stream << "<Categories>" << endl;
493 for ( QValueList<OpieCategories>::ConstIterator it = m_categories.begin(); 495 for ( Q3ValueList<OpieCategories>::ConstIterator it = m_categories.begin();
494 it != m_categories.end(); ++it ) 496 it != m_categories.end(); ++it )
495 { 497 {
496 stream << "<Category id=\""<< ( (*it).id() ) << "\" "; 498 stream << "<Category id=\""<< ( (*it).id() ) << "\" ";
497 499
498 if ( !(*it).app().isEmpty() ) 500 if ( !(*it).app().isEmpty() )
499 stream << " app=\""<< ( (*it).app() ) << "\" "; 501 stream << " app=\""<< ( (*it).app() ) << "\" ";
500 502
501 stream << "name=\"" << ( (*it).name() ) << "\" "; 503 stream << "name=\"" << ( (*it).name() ) << "\" ";
502 stream << " />" << endl; 504 stream << " />" << endl;
503 } 505 }
504 stream << "</Categories>" << endl; 506 stream << "</Categories>" << endl;
505 file.close(); 507 file.close();
506 } 508 }
507} 509}
508int CategoryEdit::addCategory( const QString &name, int id ){ 510int CategoryEdit::addCategory( const QString &name, int id ){
509 return addCategory( QString::null, name, id ); 511 return addCategory( QString::null, name, id );
510} 512}
511int CategoryEdit::addCategory( const QString &appName, const QString &name, int id ){ 513int CategoryEdit::addCategory( const QString &appName, const QString &name, int id ){
512 if ( id == 0 ) { 514 if ( id == 0 ) {
513 // code from tt 515 // code from tt
514 //generate uid 516 //generate uid
515 QDateTime dt = QDateTime::currentDateTime(); 517 QDateTime dt = QDateTime::currentDateTime();
516 id = -1 * (int) dt.secsTo( QDateTime(QDate( 2000,1,1)) ); 518 id = -1 * (int) dt.secsTo( QDateTime(QDate( 2000,1,1)) );
517 while ( ids.contains( id ) ){ 519 while ( ids.contains( id ) ){
518 id += -1; 520 id += -1;
519 if ( id > 0 ) 521 if ( id > 0 )
520 id = -1; 522 id = -1;
521 } 523 }
522 } 524 }
523 ids.insert( id, TRUE ); 525 ids.insert( id, TRUE );
524 OpieCategories categories(QString::number(id), name, appName); 526 OpieCategories categories(QString::number(id), name, appName);
525 //pending FIXME LR m_categories.remove( categories); 527 //pending FIXME LR m_categories.remove( categories);
526 m_categories.append( categories); 528 m_categories.append( categories);
527 return id; 529 return id;
528} 530}
529/* 531/*
530 * we parse the simple Category File here 532 * we parse the simple Category File here
531 * We also keep track of global Cats 533 * We also keep track of global Cats
532 * and Of Organizer and Contact cats and then 534 * and Of Organizer and Contact cats and then
533 * we will add them to the kde side... 535 * we will add them to the kde side...
534 */ 536 */
535void CategoryEdit::parse( const QString &tempFile ){ 537void CategoryEdit::parse( const QString &tempFile ){
536 clear(); 538 clear();
537 539
538 QDomDocument doc( "mydocument" ); 540 QDomDocument doc( "mydocument" );
539 QFile f( tempFile ); 541 QFile f( tempFile );
540 if ( !f.open( IO_ReadOnly ) ) 542 if ( !f.open( QIODevice::ReadOnly ) )
541 return; 543 return;
542 544
543 if ( !doc.setContent( &f ) ) { 545 if ( !doc.setContent( &f ) ) {
544 f.close(); 546 f.close();
545 return; 547 return;
546 } 548 }
547 f.close(); 549 f.close();
548 550
549 QStringList global, contact, organizer; 551 QStringList global, contact, organizer;
550 552
551 // print out the element names of all elements that are a direct child 553 // print out the element names of all elements that are a direct child
552 // of the outermost element. 554 // of the outermost element.
553 QDomElement docElem = doc.documentElement(); 555 QDomElement docElem = doc.documentElement();
554 QDomNode n = docElem.firstChild(); 556 QDomNode n = docElem.firstChild();
555 if( docElem.nodeName() == QString::fromLatin1("Categories") ){ 557 if( docElem.nodeName() == QString::fromLatin1("Categories") ){
556 while( !n.isNull() ) { 558 while( !n.isNull() ) {
557 QDomElement e = n.toElement(); // try to convert the node to an element. 559 QDomElement e = n.toElement(); // try to convert the node to an element.
558 if( !e.isNull() ) { // the node was really an element. 560 if( !e.isNull() ) { // the node was really an element.
559 QString id = e.attribute("id" ); 561 QString id = e.attribute("id" );
560 QString app = e.attribute("app" ); 562 QString app = e.attribute("app" );
561 QString name = e.attribute("name"); 563 QString name = e.attribute("name");
562 564
563 /* 565 /*
564 * see where it belongs default to global 566 * see where it belongs default to global
565 */ 567 */
566 if (app == QString::fromLatin1("Calendar") || app == QString::fromLatin1("Todo List") ) 568 if (app == QString::fromLatin1("Calendar") || app == QString::fromLatin1("Todo List") )
567 organizer.append( name ); 569 organizer.append( name );
568 else if ( app == QString::fromLatin1("Contacts") ) 570 else if ( app == QString::fromLatin1("Contacts") )
569 contact.append( name ); 571 contact.append( name );
570 else 572 else
571 global.append( name ); 573 global.append( name );
572 574
573 OpieCategories category( id, name, app ); 575 OpieCategories category( id, name, app );
574 m_categories.append( category ); // cheater 576 m_categories.append( category ); // cheater
575 } 577 }
576 n = n.nextSibling(); 578 n = n.nextSibling();
577 } 579 }
578 } 580 }
579 updateKDE( "kaddressbookrc", global + contact ); 581 updateKDE( "kaddressbookrc", global + contact );
580 updateKDE( "korganizerrc", global + organizer ); 582 updateKDE( "korganizerrc", global + organizer );
581 583
582} 584}
583void CategoryEdit::clear() 585void CategoryEdit::clear()
584{ 586{
585 ids.clear(); 587 ids.clear();
586 m_categories.clear(); 588 m_categories.clear();
587} 589}
588QString CategoryEdit::categoryById( const QString &id, const QString &app )const 590QString CategoryEdit::categoryById( const QString &id, const QString &app )const
589{ 591{
590 QValueList<OpieCategories>::ConstIterator it; 592 Q3ValueList<OpieCategories>::ConstIterator it;
591 QString category; 593 QString category;
592 QString fallback; 594 QString fallback;
593 for( it = m_categories.begin(); it != m_categories.end(); ++it ){ 595 for( it = m_categories.begin(); it != m_categories.end(); ++it ){
594 if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){ 596 if( id.stripWhiteSpace() == (*it).id().stripWhiteSpace() ){
595 if( app == (*it).app() ){ 597 if( app == (*it).app() ){
596 category = (*it).name(); 598 category = (*it).name();
597 break; 599 break;
598 }else{ 600 }else{
599 fallback = (*it).name(); 601 fallback = (*it).name();
600 } 602 }
601 } 603 }
602 } 604 }
603 return category.isEmpty() ? fallback : category; 605 return category.isEmpty() ? fallback : category;
604} 606}
605QStringList CategoryEdit::categoriesByIds( const QStringList& ids, 607QStringList CategoryEdit::categoriesByIds( const QStringList& ids,
606 const QString& app) { 608 const QString& app) {
607 609
608 QStringList list; 610 QStringList list;
609 QStringList::ConstIterator it; 611 QStringList::ConstIterator it;
610 QString temp; 612 QString temp;
611 for ( it = ids.begin(); it != ids.end(); ++it ) { 613 for ( it = ids.begin(); it != ids.end(); ++it ) {
612 temp = categoryById( (*it), app ); 614 temp = categoryById( (*it), app );
613 if (!temp.isEmpty() ) 615 if (!temp.isEmpty() )
614 list << temp; 616 list << temp;
615 } 617 }
616 618
617 return list; 619 return list;
618} 620}
619void CategoryEdit::updateKDE( const QString& configFile, const QStringList& cats ) { 621void CategoryEdit::updateKDE( const QString& configFile, const QStringList& cats ) {
620 KConfig conf(configFile); 622 KConfig conf(configFile);
621 conf.setGroup("General"); 623 conf.setGroup("General");
622 QStringList avail = conf.readListEntry("Custom Categories"); 624 QStringList avail = conf.readListEntry("Custom Categories");
623 for (QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) { 625 for (QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) {
624 if (!avail.contains( (*it) ) ) 626 if (!avail.contains( (*it) ) )
625 avail << (*it); 627 avail << (*it);
626 } 628 }
627 conf.writeEntry("Custom Categories", avail ); 629 conf.writeEntry("Custom Categories", avail );
628} 630}
629 631
630 632
631 633
632OpieCategories::OpieCategories() 634OpieCategories::OpieCategories()
633{ 635{
634 636
635} 637}
636OpieCategories::OpieCategories(const QString &id, const QString &name, const QString &app ) 638OpieCategories::OpieCategories(const QString &id, const QString &name, const QString &app )
637{ 639{
638 m_name = name; 640 m_name = name;