TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

775 lines
25 KiB

  1. /*
  2. This file is part of tdepim.
  3. Copyright (c) 2003 - 2004 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tqapplication.h>
  18. #include <tdeabc/addressee.h>
  19. #include <kabprefs.h>
  20. #include <tdeconfig.h>
  21. #include <kdebug.h>
  22. #include <tdelocale.h>
  23. #include <kmdcodec.h>
  24. #include <kstandarddirs.h>
  25. #include <kstringhandler.h>
  26. #include <libkcal/freebusyurlstore.h>
  27. #include <libtdepim/kpimprefs.h>
  28. #include "tdeabc_egroupwareprefs.h"
  29. #include "tdeabc_resourcexmlrpc.h"
  30. #include "tdeabc_resourcexmlrpcconfig.h"
  31. #include "access.h"
  32. #include "synchronizer.h"
  33. #include "xmlrpciface.h"
  34. using namespace TDEABC;
  35. static const TQString SearchContactsCommand = "addressbook.boaddressbook.search";
  36. static const TQString AddContactCommand = "addressbook.boaddressbook.write";
  37. static const TQString DeleteContactCommand = "addressbook.boaddressbook.delete";
  38. static const TQString LoadCategoriesCommand = "addressbook.boaddressbook.categories";
  39. static const TQString LoadCustomFieldsCommand = "addressbook.boaddressbook.customfields";
  40. static void setRights( TDEABC::Addressee &addr, int rights )
  41. {
  42. addr.insertCustom( "EGWRESOURCE", "RIGHTS", TQString::number( rights ) );
  43. }
  44. static int rights( const TDEABC::Addressee &addr )
  45. {
  46. return addr.custom( "EGWRESOURCE", "RIGHTS" ).toInt();
  47. }
  48. ResourceXMLRPC::ResourceXMLRPC( const TDEConfig *config )
  49. : ResourceCached( config ), mServer( 0 )
  50. {
  51. init();
  52. mPrefs->addGroupPrefix( identifier() );
  53. if ( config ) {
  54. mPrefs->readConfig();
  55. } else {
  56. setResourceName( i18n( "eGroupware Server" ) );
  57. }
  58. initEGroupware();
  59. }
  60. ResourceXMLRPC::ResourceXMLRPC( const TQString &url, const TQString &domain,
  61. const TQString &user, const TQString &password )
  62. : ResourceCached( 0 ), mServer( 0 )
  63. {
  64. init();
  65. mPrefs->addGroupPrefix( identifier() );
  66. mPrefs->setUrl( url );
  67. mPrefs->setDomain( domain );
  68. mPrefs->setUser( user );
  69. mPrefs->setPassword( password );
  70. initEGroupware();
  71. }
  72. void ResourceXMLRPC::init()
  73. {
  74. setType( "xmlrpc" );
  75. mSynchronizer = new Synchronizer;
  76. mPrefs = new EGroupwarePrefs;
  77. }
  78. void ResourceXMLRPC::initEGroupware()
  79. {
  80. KURL url( mPrefs->url() );
  81. mAddrTypes.insert( "dom", Address::Dom );
  82. mAddrTypes.insert( "intl", Address::Intl );
  83. mAddrTypes.insert( "parcel", Address::Parcel );
  84. mAddrTypes.insert( "postal", Address::Postal );
  85. }
  86. ResourceXMLRPC::~ResourceXMLRPC()
  87. {
  88. saveCache();
  89. delete mServer;
  90. mServer = 0;
  91. delete mPrefs;
  92. mPrefs = 0;
  93. delete mSynchronizer;
  94. mSynchronizer = 0;
  95. }
  96. void ResourceXMLRPC::writeConfig( TDEConfig *config )
  97. {
  98. Resource::writeConfig( config );
  99. mPrefs->writeConfig();
  100. }
  101. Ticket *ResourceXMLRPC::requestSaveTicket()
  102. {
  103. if ( !addressBook() ) {
  104. kdDebug(5700) << "no addressbook" << endl;
  105. return 0;
  106. }
  107. return createTicket( this );
  108. }
  109. void ResourceXMLRPC::releaseSaveTicket( Ticket *ticket )
  110. {
  111. delete ticket;
  112. }
  113. bool ResourceXMLRPC::doOpen()
  114. {
  115. if ( mServer )
  116. delete mServer;
  117. mServer = new KXMLRPC::Server( KURL(), this );
  118. mServer->setUrl( KURL( mPrefs->url() ) );
  119. mServer->setUserAgent( "KDE-AddressBook" );
  120. TQStringVariantMap args;
  121. args.insert( "domain", mPrefs->domain() );
  122. args.insert( "username", mPrefs->user() );
  123. args.insert( "password", mPrefs->password() );
  124. mServer->call( "system.login", TQVariant( args ),
  125. this, TQT_SLOT( loginFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  126. this, TQT_SLOT( fault( int, const TQString&, const TQVariant& ) ) );
  127. mSynchronizer->start();
  128. return true;
  129. }
  130. void ResourceXMLRPC::doClose()
  131. {
  132. TQStringVariantMap args;
  133. args.insert( "sessionid", mSessionID );
  134. args.insert( "kp3", mKp3 );
  135. mServer->call( "system.logout", TQVariant( args ),
  136. this, TQT_SLOT( logoutFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  137. this, TQT_SLOT( fault( int, const TQString&, const TQVariant& ) ) );
  138. mSynchronizer->start();
  139. }
  140. bool ResourceXMLRPC::load()
  141. {
  142. mAddrMap.clear();
  143. return true;
  144. }
  145. bool ResourceXMLRPC::asyncLoad()
  146. {
  147. if ( !mServer )
  148. return false;
  149. mAddrMap.clear();
  150. loadCache();
  151. TQStringVariantMap args;
  152. args.insert( "start", "0" );
  153. args.insert( "query", "" );
  154. args.insert( "filter", "" );
  155. args.insert( "sort", "" );
  156. args.insert( "order", "" );
  157. args.insert( "include_users", "calendar" );
  158. mServer->call( SearchContactsCommand, args,
  159. this, TQT_SLOT( listContactsFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  160. this, TQT_SLOT( fault( int, const TQString&, const TQVariant& ) ) );
  161. mServer->call( LoadCategoriesCommand, TQVariant( false ),
  162. this, TQT_SLOT( loadCategoriesFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  163. this, TQT_SLOT( fault( int, const TQString&, const TQVariant& ) ) );
  164. mServer->call( LoadCustomFieldsCommand, TQVariant( TQValueList<TQVariant>() ),
  165. this, TQT_SLOT( loadCustomFieldsFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  166. this, TQT_SLOT( fault( int, const TQString&, const TQVariant& ) ) );
  167. return true;
  168. }
  169. bool ResourceXMLRPC::save( Ticket *ticket )
  170. {
  171. return asyncSave( ticket );
  172. }
  173. bool ResourceXMLRPC::asyncSave( Ticket* )
  174. {
  175. TDEABC::Addressee::List::ConstIterator it;
  176. const TDEABC::Addressee::List addedList = addedAddressees();
  177. for ( it = addedList.begin(); it != addedList.end(); ++it ) {
  178. addContact( *it );
  179. }
  180. const TDEABC::Addressee::List changedList = changedAddressees();
  181. for ( it = changedList.begin(); it != changedList.end(); ++it ) {
  182. updateContact( *it );
  183. }
  184. const TDEABC::Addressee::List deletedList = deletedAddressees();
  185. for ( it = deletedList.begin(); it != deletedList.end(); ++it ) {
  186. deleteContact( *it );
  187. }
  188. return true;
  189. }
  190. void ResourceXMLRPC::addContact( const Addressee& addr )
  191. {
  192. TQStringVariantMap args;
  193. writeContact( addr, args );
  194. mServer->call( AddContactCommand, args,
  195. this, TQT_SLOT( addContactFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  196. this, TQT_SLOT( addContactFault( int, const TQString&, const TQVariant& ) ),
  197. TQVariant( addr.uid() ) );
  198. }
  199. void ResourceXMLRPC::updateContact( const Addressee& addr )
  200. {
  201. if ( !(rights( addr ) & EGW_ACCESS_DELETE) && (rights( addr ) != -1) ) {
  202. clearChange( addr.uid() );
  203. return;
  204. }
  205. TQStringVariantMap args;
  206. writeContact( addr, args );
  207. args.insert( "id", idMapper().remoteId( addr.uid() ) );
  208. mServer->call( AddContactCommand, args,
  209. this, TQT_SLOT( updateContactFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  210. this, TQT_SLOT( updateContactFault( int, const TQString&, const TQVariant& ) ),
  211. TQVariant( addr.uid() ) );
  212. }
  213. void ResourceXMLRPC::deleteContact( const Addressee& addr )
  214. {
  215. if ( !(rights( addr ) & EGW_ACCESS_DELETE) && rights( addr ) != -1 ) {
  216. clearChange( addr.uid() );
  217. idMapper().removeRemoteId( idMapper().remoteId( addr.uid() ) );
  218. return;
  219. }
  220. mServer->call( DeleteContactCommand, idMapper().remoteId( addr.uid() ),
  221. this, TQT_SLOT( deleteContactFinished( const TQValueList<TQVariant>&, const TQVariant& ) ),
  222. this, TQT_SLOT( deleteContactFault( int, const TQString&, const TQVariant& ) ),
  223. TQVariant( addr.uid() ) );
  224. }
  225. void ResourceXMLRPC::loginFinished( const TQValueList<TQVariant> &variant,
  226. const TQVariant& )
  227. {
  228. TQStringVariantMap map = variant[0].toMap();
  229. KURL url( mPrefs->url() );
  230. if ( map[ "GOAWAY" ].toString() == "XOXO" ) { // failed
  231. mSessionID = mKp3 = "";
  232. addressBook()->error( i18n( "Login failed, please check your username and password." ) );
  233. } else {
  234. mSessionID = map[ "sessionid" ].toString();
  235. mKp3 = map[ "kp3" ].toString();
  236. }
  237. url.setUser( mSessionID );
  238. url.setPass( mKp3 );
  239. mServer->setUrl( url );
  240. mSynchronizer->stop();
  241. }
  242. void ResourceXMLRPC::logoutFinished( const TQValueList<TQVariant> &variant,
  243. const TQVariant& )
  244. {
  245. TQStringVariantMap map = variant[0].toMap();
  246. if ( map[ "GOODBYE" ].toString() != "XOXO" )
  247. addressBook()->error( i18n( "Logout failed, please check your username and password." ) );
  248. KURL url( mPrefs->url() );
  249. mSessionID = mKp3 = "";
  250. url.setUser( mSessionID );
  251. url.setPass( mKp3 );
  252. mServer->setUrl( url );
  253. mSynchronizer->stop();
  254. }
  255. void ResourceXMLRPC::listContactsFinished( const TQValueList<TQVariant> &mapList,
  256. const TQVariant& )
  257. {
  258. const TQValueList<TQVariant> contactList = mapList[ 0 ].toList();
  259. TQValueList<TQVariant>::ConstIterator contactIt;
  260. TDEABC::Addressee::List serverContacts;
  261. for ( contactIt = contactList.begin(); contactIt != contactList.end(); ++contactIt ) {
  262. const TQStringVariantMap map = (*contactIt).toMap();
  263. Addressee addr;
  264. TQString uid;
  265. readContact( map, addr, uid );
  266. if ( !addr.isEmpty() ) {
  267. addr.setResource( this );
  268. addr.setChanged( false );
  269. TQString local = idMapper().localId( uid );
  270. if ( local.isEmpty() ) { // new entry
  271. idMapper().setRemoteId( addr.uid(), uid );
  272. } else {
  273. addr.setUid( local );
  274. }
  275. mAddrMap.insert( addr.uid(), addr );
  276. serverContacts.append( addr );
  277. }
  278. }
  279. cleanUpCache( serverContacts );
  280. saveCache();
  281. emit loadingFinished( this );
  282. }
  283. void ResourceXMLRPC::addContactFinished( const TQValueList<TQVariant> &list,
  284. const TQVariant &id )
  285. {
  286. clearChange( id.toString() );
  287. idMapper().setRemoteId( id.toString(), list[ 0 ].toString() );
  288. saveCache();
  289. }
  290. void ResourceXMLRPC::updateContactFinished( const TQValueList<TQVariant>&,
  291. const TQVariant &id )
  292. {
  293. clearChange( id.toString() );
  294. saveCache();
  295. }
  296. void ResourceXMLRPC::deleteContactFinished( const TQValueList<TQVariant>&,
  297. const TQVariant &id )
  298. {
  299. clearChange( id.toString() );
  300. idMapper().removeRemoteId( idMapper().remoteId( id.toString() ) );
  301. saveCache();
  302. }
  303. void ResourceXMLRPC::fault( int error, const TQString &errorMsg,
  304. const TQVariant& )
  305. {
  306. TQString msg = i18n( "<qt>Server sent error %1: <b>%2</b></qt>" ).arg( error ).arg( errorMsg );
  307. if ( addressBook() )
  308. addressBook()->error( msg );
  309. mSynchronizer->stop();
  310. }
  311. void ResourceXMLRPC::addContactFault( int, const TQString &errorMsg,
  312. const TQVariant &id )
  313. {
  314. TDEABC::Addressee addr = mAddrMap[ id.toString() ];
  315. mAddrMap.remove( addr.uid() );
  316. TQString msg = i18n( "Unable to add contact %1 to server. (%2)" );
  317. addressBook()->error( msg.arg( addr.formattedName(), errorMsg ) );
  318. }
  319. void ResourceXMLRPC::updateContactFault( int, const TQString &errorMsg,
  320. const TQVariant &id )
  321. {
  322. TDEABC::Addressee addr = mAddrMap[ id.toString() ];
  323. TQString msg = i18n( "Unable to update contact %1 on server. (%2)" );
  324. addressBook()->error( msg.arg( addr.formattedName(), errorMsg ) );
  325. }
  326. void ResourceXMLRPC::deleteContactFault( int, const TQString &errorMsg,
  327. const TQVariant &id )
  328. {
  329. TDEABC::Addressee addr;
  330. const TDEABC::Addressee::List deletedList = deletedAddressees();
  331. TDEABC::Addressee::List::ConstIterator it;
  332. for ( it = deletedList.begin(); it != deletedList.end(); ++it ) {
  333. if ( (*it).uid() == id.toString() ) {
  334. addr = *it;
  335. break;
  336. }
  337. }
  338. mAddrMap.insert( addr.uid(), addr );
  339. TQString msg = i18n( "Unable to delete contact %1 from server. (%2)" );
  340. addressBook()->error( msg.arg( addr.formattedName(), errorMsg ) );
  341. }
  342. TQString ResourceXMLRPC::addrTypesToTypeStr( int typeMask )
  343. {
  344. TQStringList types;
  345. TQMap<TQString, int>::ConstIterator it;
  346. for ( it = mAddrTypes.begin(); it != mAddrTypes.end(); ++it )
  347. if ( it.data() & typeMask )
  348. types.append( it.key() );
  349. return types.join( ";" );
  350. }
  351. void ResourceXMLRPC::writeContact( const Addressee &addr, TQStringVariantMap &args )
  352. {
  353. args.insert( "access", ( addr.secrecy().type() == Secrecy::Private ? "private" : "public" ) );
  354. args.insert( "fn", addr.formattedName() );
  355. args.insert( "n_given", addr.givenName() );
  356. args.insert( "n_family", addr.familyName() );
  357. args.insert( "n_middle", addr.additionalName() );
  358. args.insert( "n_prefix", addr.prefix() );
  359. args.insert( "n_suffix", addr.suffix() );
  360. // args.insert( "sound", "sound" );
  361. args.insert( "bday", addr.birthday() );
  362. args.insert( "note", addr.note() );
  363. int hours = addr.timeZone().offset() / 60;
  364. args.insert( "tz", hours );
  365. // args.insert( "geo", "geo" );
  366. args.insert( "url", addr.url().url() );
  367. // args.insert( "pubkey", "pubkey" );
  368. args.insert( "org_name", addr.organization() );
  369. // args.insert( "org_unit", "org_unit" );
  370. args.insert( "title", addr.title() );
  371. // CATEGORIES
  372. TQStringList::ConstIterator catIt;
  373. const TQStringList categories = addr.categories();
  374. TQStringVariantMap catMap;
  375. int counter = 0;
  376. for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
  377. TQMap<TQString, int>::ConstIterator it = mCategoryMap.find( *catIt );
  378. if ( it == mCategoryMap.end() ) // new category
  379. catMap.insert( TQString::number( counter-- ), *catIt );
  380. else
  381. catMap.insert( TQString::number( it.data() ), *catIt );
  382. }
  383. args.insert( "cat_id", catMap );
  384. Address workAddr = addr.address( Address::Work );
  385. if ( !workAddr.isEmpty() ) {
  386. args.insert( "adr_one_street", workAddr.street() );
  387. args.insert( "adr_one_locality", workAddr.locality() );
  388. args.insert( "adr_one_region", workAddr.region() );
  389. args.insert( "adr_one_postalcode", workAddr.postalCode() );
  390. args.insert( "adr_one_countryname", workAddr.country() );
  391. args.insert( "adr_one_type", addrTypesToTypeStr( workAddr.type() ) );
  392. args.insert( "label", workAddr.label() );
  393. }
  394. Address homeAddr = addr.address( Address::Home );
  395. if ( !homeAddr.isEmpty() ) {
  396. args.insert( "adr_two_street", homeAddr.street() );
  397. args.insert( "adr_two_locality", homeAddr.locality() );
  398. args.insert( "adr_two_region", homeAddr.region() );
  399. args.insert( "adr_two_postalcode", homeAddr.postalCode() );
  400. args.insert( "adr_two_countryname", homeAddr.country() );
  401. args.insert( "adr_two_type", addrTypesToTypeStr( homeAddr.type() ) );
  402. }
  403. PhoneNumber phone = addr.phoneNumber( PhoneNumber::Work );
  404. if ( !phone.number().isEmpty() )
  405. args.insert( "tel_work", phone.number() );
  406. phone = addr.phoneNumber( PhoneNumber::Home );
  407. if ( !phone.number().isEmpty() )
  408. args.insert( "tel_home", phone.number() );
  409. phone = addr.phoneNumber( PhoneNumber::Voice );
  410. if ( !phone.number().isEmpty() )
  411. args.insert( "tel_voice", phone.number() );
  412. phone = addr.phoneNumber( PhoneNumber::Fax );
  413. if ( !phone.number().isEmpty() )
  414. args.insert( "tel_fax", phone.number() );
  415. phone = addr.phoneNumber( PhoneNumber::Msg );
  416. if ( !phone.number().isEmpty() )
  417. args.insert( "tel_msg", phone.number() );
  418. phone = addr.phoneNumber( PhoneNumber::Cell );
  419. if ( !phone.number().isEmpty() )
  420. args.insert( "tel_cell", phone.number() );
  421. phone = addr.phoneNumber( PhoneNumber::Pager );
  422. if ( !phone.number().isEmpty() )
  423. args.insert( "tel_pager", phone.number() );
  424. phone = addr.phoneNumber( PhoneNumber::Bbs );
  425. if ( !phone.number().isEmpty() )
  426. args.insert( "tel_bbs", phone.number() );
  427. phone = addr.phoneNumber( PhoneNumber::Modem );
  428. if ( !phone.number().isEmpty() )
  429. args.insert( "tel_modem", phone.number() );
  430. phone = addr.phoneNumber( PhoneNumber::Car );
  431. if ( !phone.number().isEmpty() )
  432. args.insert( "tel_car", phone.number() );
  433. phone = addr.phoneNumber( PhoneNumber::Isdn );
  434. if ( !phone.number().isEmpty() )
  435. args.insert( "tel_isdn", phone.number() );
  436. phone = addr.phoneNumber( PhoneNumber::Video );
  437. if ( !phone.number().isEmpty() )
  438. args.insert( "tel_video", phone.number() );
  439. phone = addr.phoneNumber( PhoneNumber::Pref );
  440. if ( !phone.number().isEmpty() )
  441. args.insert( "tel_prefer", phone.number() );
  442. if ( !addr.preferredEmail().isEmpty() ) {
  443. args.insert( "email", addr.preferredEmail() );
  444. args.insert( "email_type", "INTERNET" );
  445. }
  446. if ( addr.emails().count() > 1 ) {
  447. args.insert( "email_home", addr.emails()[ 1 ] );
  448. args.insert( "email_home_type", "INTERNET" );
  449. }
  450. const TQStringList customFields = addr.customs();
  451. TQStringList::ConstIterator it;
  452. for ( it = customFields.begin(); it != customFields.end(); ++it ) {
  453. int colon = (*it).find( ":" );
  454. TQString identifier = (*it).left( colon );
  455. int dash = identifier.find( "-" );
  456. TQString app = identifier.left( dash );
  457. TQString name = identifier.mid( dash + 1 );
  458. TQString value = (*it).mid( colon + 1 );
  459. if ( value.isEmpty() )
  460. continue;
  461. if ( app == "XMLRPCResource" )
  462. args.insert( name, value );
  463. }
  464. TQString url = KCal::FreeBusyUrlStore::self()->readUrl( addr.preferredEmail() );
  465. if ( !url.isEmpty() )
  466. args.insert( "freebusy_url", url );
  467. }
  468. void ResourceXMLRPC::readContact( const TQStringVariantMap &args, Addressee &addr, TQString &uid )
  469. {
  470. Address addrOne, addrTwo;
  471. TQStringVariantMap::ConstIterator it;
  472. for ( it = args.begin(); it != args.end(); ++it ) {
  473. if ( it.key() == "id" ) {
  474. uid = it.data().toString();
  475. } else if ( it.key() == "access" ) {
  476. Secrecy secrecy;
  477. if ( it.data().toString() == "private" )
  478. secrecy.setType( Secrecy::Private );
  479. else
  480. secrecy.setType( Secrecy::Public );
  481. addr.setSecrecy( secrecy );
  482. } else if ( it.key() == "fn" ) {
  483. addr.setFormattedName( it.data().toString() );
  484. } else if ( it.key() == "n_given" ) {
  485. addr.setGivenName( it.data().toString() );
  486. } else if ( it.key() == "n_family" ) {
  487. addr.setFamilyName( it.data().toString() );
  488. } else if ( it.key() == "n_middle" ) {
  489. addr.setAdditionalName( it.data().toString() );
  490. } else if ( it.key() == "n_prefix" ) {
  491. addr.setPrefix( it.data().toString() );
  492. } else if ( it.key() == "n_suffix" ) {
  493. addr.setSuffix( it.data().toString() );
  494. } else if ( it.key() == "sound" ) {
  495. } else if ( it.key() == "bday" ) {
  496. addr.setBirthday( it.data().toDateTime() );
  497. } else if ( it.key() == "note" ) {
  498. addr.setNote( it.data().toString() );
  499. } else if ( it.key() == "tz" ) {
  500. int hour = it.data().toInt();
  501. TimeZone timeZone( hour * 60 );
  502. addr.setTimeZone( timeZone );
  503. } else if ( it.key() == "geo" ) {
  504. } else if ( it.key() == "url" ) {
  505. addr.setUrl( KURL( it.data().toString() ) );
  506. } else if ( it.key() == "pubkey" ) {
  507. } else if ( it.key() == "org_name" ) {
  508. addr.setOrganization( it.data().toString() );
  509. } else if ( it.key() == "org_unit" ) {
  510. } else if ( it.key() == "title" ) {
  511. addr.setTitle( it.data().toString() );
  512. } else if ( it.key() == "adr_one_street" ) {
  513. addrOne.setStreet( it.data().toString() );
  514. } else if ( it.key() == "adr_one_locality" ) {
  515. addrOne.setLocality( it.data().toString() );
  516. } else if ( it.key() == "adr_one_region" ) {
  517. addrOne.setRegion( it.data().toString() );
  518. } else if ( it.key() == "adr_one_postalcode" ) {
  519. addrOne.setPostalCode( it.data().toString() );
  520. } else if ( it.key() == "adr_one_countryname" ) {
  521. addrOne.setCountry( it.data().toString() );
  522. } else if ( it.key() == "adr_one_type" ) {
  523. TQStringList types = TQStringList::split( ';', it.data().toString() );
  524. int type = Address::Work;
  525. for ( uint i = 0; i < types.count(); ++i )
  526. type += mAddrTypes[ types[ i ] ];
  527. addrOne.setType( type );
  528. } else if ( it.key() == "label" ) {
  529. addrOne.setLabel( it.data().toString() );
  530. } else if ( it.key() == "adr_two_street" ) {
  531. addrTwo.setStreet( it.data().toString() );
  532. } else if ( it.key() == "adr_two_locality" ) {
  533. addrTwo.setLocality( it.data().toString() );
  534. } else if ( it.key() == "adr_two_region" ) {
  535. addrTwo.setRegion( it.data().toString() );
  536. } else if ( it.key() == "adr_two_postalcode" ) {
  537. addrTwo.setPostalCode( it.data().toString() );
  538. } else if ( it.key() == "adr_two_countryname" ) {
  539. addrTwo.setCountry( it.data().toString() );
  540. } else if ( it.key() == "adr_two_type" ) {
  541. TQStringList types = TQStringList::split( ';', it.data().toString() );
  542. int type = Address::Home;
  543. for ( uint i = 0; i < types.count(); ++i )
  544. type += mAddrTypes[ types[ i ] ];
  545. addrTwo.setType( type );
  546. } else if ( it.key() == "tel_work" ) {
  547. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Work ) );
  548. } else if ( it.key() == "tel_home" ) {
  549. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Home ) );
  550. } else if ( it.key() == "tel_voice" ) {
  551. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Voice ) );
  552. } else if ( it.key() == "tel_fax" ) {
  553. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Fax ) );
  554. } else if ( it.key() == "tel_msg" ) {
  555. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Msg ) );
  556. } else if ( it.key() == "tel_cell" ) {
  557. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Cell ) );
  558. } else if ( it.key() == "tel_pager" ) {
  559. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Pager ) );
  560. } else if ( it.key() == "tel_bbs" ) {
  561. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Bbs ) );
  562. } else if ( it.key() == "tel_modem" ) {
  563. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Modem ) );
  564. } else if ( it.key() == "tel_car" ) {
  565. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Car ) );
  566. } else if ( it.key() == "tel_isdn" ) {
  567. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Isdn ) );
  568. } else if ( it.key() == "tel_video" ) {
  569. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Video ) );
  570. } else if ( it.key() == "tel_prefer" ) {
  571. addr.insertPhoneNumber( PhoneNumber( it.data().toString(), PhoneNumber::Pref ) );
  572. } else if ( it.key() == "email" ) {
  573. addr.insertEmail( it.data().toString(), true );
  574. } else if ( it.key() == "email_type" ) {
  575. } else if ( it.key() == "email_home" ) {
  576. addr.insertEmail( it.data().toString(), false );
  577. } else if ( it.key() == "email_home_type" ) {
  578. } else if ( it.key() == "cat_id" ) {
  579. const TQStringVariantMap categories = it.data().toMap();
  580. TQStringVariantMap::ConstIterator it;
  581. for ( it = categories.begin(); it != categories.end(); ++it )
  582. addr.insertCategory( it.data().toString() );
  583. } else if ( it.key() == "rights" ) {
  584. setRights( addr, it.data().toInt() );
  585. }
  586. }
  587. TQMap<TQString, TQString>::ConstIterator cfIt;
  588. for ( cfIt = mCustomFieldsMap.begin(); cfIt != mCustomFieldsMap.end(); ++cfIt ) {
  589. if ( args[ cfIt.key() ].toString().isEmpty() )
  590. continue;
  591. if ( cfIt.key() == "freebusy_url" ) {
  592. KCal::FreeBusyUrlStore::self()->writeUrl( addr.preferredEmail(),
  593. args[ cfIt.key() ].toString() );
  594. KCal::FreeBusyUrlStore::self()->sync();
  595. } else
  596. addr.insertCustom( "XMLRPCResource", cfIt.key(), cfIt.data() );
  597. }
  598. if ( !addrOne.isEmpty() )
  599. addr.insertAddress( addrOne );
  600. if ( !addrTwo.isEmpty() )
  601. addr.insertAddress( addrTwo );
  602. }
  603. void ResourceXMLRPC::loadCategoriesFinished( const TQValueList<TQVariant> &mapList,
  604. const TQVariant& )
  605. {
  606. mCategoryMap.clear();
  607. const TQStringVariantMap map = mapList[ 0 ].toMap();
  608. TQStringVariantMap::ConstIterator it;
  609. KABPrefs *prefs = KABPrefs::instance();
  610. for ( it = map.begin(); it != map.end(); ++it ) {
  611. mCategoryMap.insert( it.data().toString(), it.key().toInt() );
  612. TQStringList categories = prefs->customCategories();
  613. if ( categories.find( it.data().toString() ) == categories.end() )
  614. categories.append( it.data().toString() );
  615. prefs->mCustomCategories = categories;
  616. }
  617. }
  618. void ResourceXMLRPC::loadCustomFieldsFinished( const TQValueList<TQVariant> &mapList,
  619. const TQVariant& )
  620. {
  621. mCustomFieldsMap.clear();
  622. const TQStringVariantMap map = mapList[ 0 ].toMap();
  623. TQStringVariantMap::ConstIterator it;
  624. for ( it = map.begin(); it != map.end(); ++it )
  625. mCustomFieldsMap.insert( it.key(), it.data().toString() );
  626. }
  627. #include "tdeabc_resourcexmlrpc.moc"