bool VCard_LDIFCreator::readContents( const QString &path ) { // read file contents QFile file( path ); if ( !file.open( QIODevice::ReadOnly ) ) return false; QString info; text.truncate(0); // read the file QByteArray contents = file.readAll(); file.close(); // convert the file contents to a KABC::Addressee address KABC::Addressee::List addrList; KABC::Addressee addr; KABC::VCardConverter converter; addrList = converter.parseVCards( contents); if ( addrList.count() == 0 ) { KABC::AddresseeList l; // FIXME porting if ( !KABC::LDIFConverter::LDIFToAddressee( contents, l ) ) return false; // FIXME porting KABC::AddresseeList::ConstIterator it( l.constBegin() ); for ( ; it != l.constEnd(); ++ it ) { addrList.append( *it ); } } if ( addrList.count()>1 ) { // create an overview (list of all names) name = i18np("One contact found:", "%1 contacts found:", addrList.count()); int no, linenr; for (linenr=no=0; linenr<30 && no<addrList.count(); ++no) { addr = addrList[no]; info = addr.formattedName().simplified(); if (info.isEmpty()) info = addr.givenName() + ' ' + addr.familyName(); info = info.simplified(); if (info.isEmpty()) continue; text.append(info); text.append("\n"); ++linenr; } return true; } // create card for _one_ contact addr = addrList[ 0 ]; // prepare the text name = addr.formattedName().simplified(); if ( name.isEmpty() ) name = addr.givenName() + ' ' + addr.familyName(); name = name.simplified(); KABC::PhoneNumber::List pnList = addr.phoneNumbers(); QStringList phoneNumbers; for (int no=0; no<pnList.count(); ++no) { QString pn = pnList[no].number().simplified(); if (!pn.isEmpty() && !phoneNumbers.contains(pn)) phoneNumbers.append(pn); } if ( !phoneNumbers.isEmpty() ) text += phoneNumbers.join("\n") + '\n'; info = addr.organization().simplified(); if ( !info.isEmpty() ) text += info + '\n'; // get an address KABC::Address address = addr.address(KABC::Address::Work); if (address.isEmpty()) address = addr.address(KABC::Address::Home); if (address.isEmpty()) address = addr.address(KABC::Address::Pref); info = address.formattedAddress(); if ( !info.isEmpty() ) text += info + '\n'; return true; }