bool GroupDavGlobals::interpretAddressBookDownloadItemsJob( KABC::AddressBookAdaptor *adaptor, KIO::Job *job, const QString &jobData) { kdDebug(5800) << "GroupDavGlobals::interpretAddressBookDownloadItemsJob, vCard=" << endl; kdDebug(5800) << jobData << endl; if(!adaptor || !job) return false; KABC::VCardConverter conv; KABC::Addressee::List addrs(conv.parseVCards(jobData)); if(addrs.count() != 1) { kdError() << "Parsed vCard does not contain exactly one addressee." << endl; return false; } KABC::Addressee a = addrs.first(); KIO::SimpleJob *sjob = dynamic_cast<KIO::SimpleJob *>(job); KURL remoteId; if(sjob) remoteId = sjob->url(); QString fingerprint = extractFingerprint(job, jobData); adaptor->addressbookItemDownloaded(a, a.uid(), remoteId, fingerprint, remoteId.prettyURL()); return true; }
void ResourceGroupwise::slotReadJobData( KIO::Job *job , const QByteArray &data ) { kdDebug() << "ResourceGroupwise::slotReadJobData()" << endl; Q_UNUSED( job ); mJobData.append( data.data() ); KABC::VCardConverter conv; QTime profile; profile.start(); Addressee::List addressees = conv.parseVCards( mJobData ); // kdDebug() << " parsed " << addressees.count() << " contacts in " << profile.elapsed() << "ms, now adding to resource..." << endl; Addressee::List::ConstIterator it; for( it = addressees.begin(); it != addressees.end(); ++it ) { KABC::Addressee addr = *it; if ( !addr.isEmpty() ) { addr.setResource( this ); QString remote = addr.custom( "GWRESOURCE", "UID" ); QString local = idMapper().localId( remote ); if ( local.isEmpty() ) { idMapper().setRemoteId( addr.uid(), remote ); } else { addr.setUid( local ); } insertAddressee( addr ); clearChange( addr ); } } mJobData = QString::null; }
void KOAttendeeListView::dropEvent( QDropEvent *e ) { #ifndef KORG_NODND QString text; QString vcards; #ifndef KORG_NOKABC if ( KVCardDrag::decode( e, vcards ) ) { KABC::VCardConverter converter; KABC::Addressee::List list = converter.parseVCards( vcards ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QString em( (*it).fullEmail() ); if (em.isEmpty()) { em=(*it).realName(); } addAttendee( em ); } } else #endif // KORG_NOKABC if (QTextDrag::decode(e,text)) { kdDebug(5850) << "Dropped : " << text << endl; QStringList emails = QStringList::split(",",text); for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { addAttendee(*it); } } #endif //KORG_NODND }
void KOrganizerPlugin::processDropEvent( QDropEvent *event ) { QString text; KABC::VCardConverter converter; if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) { KABC::Addressee::List contacts = converter.parseVCards( text ); KABC::Addressee::List::Iterator it; QStringList attendees; for ( it = contacts.begin(); it != contacts.end(); ++it ) { QString email = (*it).fullEmail(); if ( email.isEmpty() ) attendees.append( (*it).realName() + "<>" ); else attendees.append( email ); } interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null, attendees ); return; } if ( QTextDrag::decode( event, text ) ) { kdDebug(5602) << "DROP:" << text << endl; interface()->openEventEditor( text ); return; } KPIM::MailList mails; if ( KPIM::MailListDrag::decode( event, mails ) ) { if ( mails.count() != 1 ) { KMessageBox::sorry( core(), i18n("Drops of multiple mails are not supported." ) ); } else { KPIM::MailSummary mail = mails.first(); QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() ) .arg( mail.to() ).arg( mail.subject() ); KTempFile tf; tf.setAutoDelete( true ); QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() ); tf.file()->writeBlock( event->encodedData( "message/rfc822" ) ); tf.close(); interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt, uri, tf.name(), QStringList(), "message/rfc822" ); } return; } KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.") .arg( event->format() ) ); }
void ResourceGroupwise::slotUpdateJobData( KIO::Job *job, const QByteArray &data ) { kdDebug() << "ResourceGroupwise::slotUpdateJobData()" << endl; kdDebug() << " Job address: " << job << endl; KABC::VCardConverter conv; mJobData.append( data.data() ); Addressee::List addressees = conv.parseVCards( mJobData ); Addressee::List::ConstIterator it; for( it = addressees.begin(); it != addressees.end(); ++it ) { KABC::Addressee addr = *it; if ( !addr.isEmpty() ) { // if added or changed QString syncType = addr.custom( "GWRESOURCE", "SYNC" ); QString remote = addr.custom( "GWRESOURCE", "UID" ); QString local = idMapper().localId( remote ); if ( syncType == "ADD" || syncType == "UPD" ) { addr.setResource( this ); if ( local.isEmpty() ) { idMapper().setRemoteId( addr.uid(), remote ); } else { addr.setUid( local ); } insertAddressee( addr ); clearChange( addr ); } else if ( syncType == "DEL" ) { // if deleted if ( !remote.isEmpty() ) { if ( !local.isEmpty() ) { idMapper().removeRemoteId( remote ); KABC::Addressee addrToDelete = findByUid( local ); removeAddressee( addrToDelete ); } } else kdError() << "Addressee to delete did not have a remote UID, unable to find the corresponding local contact" << endl; } } } mJobData = QString::null; }
int main( int argc, char **argv ) { KApplication::disableAutoDcopRegistration(); KAboutData aboutData( "testread", "vCard test reader", "0.1" ); aboutData.addAuthor( "Cornelius Schumacher", 0, "*****@*****.**" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KApplication app( false, false ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() != 1 ) { std::cerr << "Missing argument" << std::endl; return 1; } QString inputFile( args->arg( 0 ) ); QFile file( inputFile ); if ( !file.open( IO_ReadOnly ) ) { qDebug( "Unable to open file '%s' for reading!", file.name().latin1() ); return 1; } QString text; QTextStream s( &file ); s.setEncoding( QTextStream::Latin1 ); text = s.read(); file.close(); KABC::VCardConverter converter; KABC::Addressee::List list = converter.parseVCards( text ); if ( args->isSet( "vcard21" ) ) { text = converter.createVCards( list, KABC::VCardConverter::v2_1 ); // uses version 2.1 } else { text = converter.createVCards( list ); // uses version 3.0 } std::cout << text.utf8(); return 0; }
void ViewManager::dropped(QDropEvent *e) { kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; // don't allow drops from our own drags if(e->source() == this) return; QString clipText, vcards; KURL::List urls; if(KURLDrag::decode(e, urls)) { KURL::List::ConstIterator it = urls.begin(); int c = urls.count(); if(c > 1) { QString questionString = i18n("Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c); if(KMessageBox::questionYesNo(this, questionString, i18n("Import Contacts?"), i18n("Import"), i18n("Do Not Import")) == KMessageBox::Yes) { for(; it != urls.end(); ++it) emit urlDropped(*it); } } else if(c == 1) emit urlDropped(*it); } else if(KVCardDrag::decode(e, vcards)) { KABC::VCardConverter converter; const KABC::Addressee::List list = converter.parseVCards(vcards); KABC::Addressee::List::ConstIterator it; for(it = list.begin(); it != list.end(); ++it) { KABC::Addressee a = mCore->addressBook()->findByUid((*it).uid()); if(a.isEmpty()) // not yet in address book { mCore->addressBook()->insertAddressee(*it); emit modified(); } } mActiveView->refresh(); } }
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; }
KABC::Addressee::List AddresseeUtil::clipboardToAddressees(const QString &data) { KABC::VCardConverter converter; return converter.parseVCards(data); }
KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const { KABC::VCardConverter converter; return converter.parseVCards( data ); }