QString KAddressBookView::selectedEmails() { bool first = true; QString emailAddrs; const QStringList uidList = selectedUids(); KABC::Addressee addr; QString email; QStringList::ConstIterator it; for(it = uidList.begin(); it != uidList.end(); ++it) { addr = mCore->addressBook()->findByUid(*it); if(!addr.isEmpty()) { QString m = QString::null; if(addr.emails().count() > 1) m = KABC::EmailSelector::getEmail(addr.emails(), addr.preferredEmail(), this); email = addr.fullEmail(m); if(!first) emailAddrs += ", "; else first = false; emailAddrs += email; } } return emailAddrs; }
void EmailEditWidget::loadContact( const KABC::Addressee &contact ) { mEmailList = contact.emails(); if ( !mEmailList.isEmpty() ) { mEmailEdit->setText( mEmailList.first() ); } else { mEmailEdit->setText( QString() ); } }
static QString getEmail2(const KABC::Addressee &addressee) { // preferred might not be the first one, so remove it and take the first of // the remaining instead of always taking the second one QStringList emails = addressee.emails(); emails.removeAll(addressee.preferredEmail()); if (emails.count() >= 1) { return emails[ 0 ]; } return QString(); }
QVariant ContactsTreeModel::entityData( const Item &item, int column, int role ) const { if ( item.mimeType() == KABC::Addressee::mimeType() ) { if ( !item.hasPayload<KABC::Addressee>() ) { // Pass modeltest if ( role == Qt::DisplayRole ) return item.remoteId(); return QVariant(); } const KABC::Addressee contact = item.payload<KABC::Addressee>(); if ( role == Qt::DecorationRole ) { if ( column == 0 ) { const KABC::Picture picture = contact.photo(); if ( picture.isIntern() ) { return picture.data().scaled( QSize( 16, 16 ), Qt::KeepAspectRatio ); } else { return KIcon( QLatin1String( "x-office-contact" ) ); } } return QVariant(); } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) { switch ( mColumns.at( column ) ) { case FullName: return contact.realName(); break; case Birthday: if ( contact.birthday().isValid() ) return KGlobal::locale()->formatDate( contact.birthday().date() ); break; case HomeAddress: { const KABC::Address address = contact.address( KABC::Address::Home ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case BusinessAddress: { const KABC::Address address = contact.address( KABC::Address::Work ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case PhoneNumbers: { QStringList values; const KABC::PhoneNumber::List numbers = contact.phoneNumbers(); foreach ( const KABC::PhoneNumber &number, numbers ) values += number.number(); return values.join( "\n" ); } break; case PreferredEmail: return contact.preferredEmail(); break; case AllEmails: return contact.emails().join( "\n" ); break; case Organization: return contact.organization(); break; case Homepage: return contact.url().url(); break; case Note: return contact.note(); break; } } } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
QString Contact::toXml(const KABC::Addressee &addr) { /** * Handle distribution lists. */ if(KPIM::DistributionList::isDistributionList(addr)) { if(s_distListMap) return (*s_distListMap)[ addr.uid() ]; else return QString(); } /** * Handle normal contacts. */ QString xml; xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; xml += "<contact>\n"; xml += "<direct_ref>" + addr.uid() + "</direct_ref>\n"; xml += "<sensitivity>" + custom("sensitivity", addr, "0") + "</sensitivity>\n"; xml += "<message_class>IPM.Contact</message_class>\n"; xml += "<is_recurring>" + custom("is_recurring", addr, "false") + "</is_recurring>\n"; xml += "<reminder_set>" + custom("reminder_set", addr, "false") + "</reminder_set>\n"; xml += "<send_rich_info>" + custom("send_rich_info", addr, "false") + "</send_rich_info>\n"; xml += "<subject>" + addr.formattedName() + "</subject>\n"; xml += "<last_modification_time>" + addr.revision().toString(Qt::ISODate) + "</last_modification_time>\n"; xml += "<display_name_prefix>" + addr.prefix() + "</display_name_prefix>\n"; xml += "<first_name>" + addr.givenName() + "</first_name>\n"; xml += "<middle_name>" + addr.additionalName() + "</middle_name>\n"; xml += "<last_name>" + addr.familyName() + "</last_name>\n"; xml += "<suffix>" + addr.suffix() + "</suffix>\n"; xml += "<display_name>" + addr.assembledName() + "</display_name>\n"; xml += "<file_as>" + addr.formattedName() + "</file_as>\n"; xml += "<nickname>" + addr.nickName() + "</nickname>\n"; xml += "<web_page_address>" + addr.url().url() + "</web_page_address>\n"; xml += "<company_name>" + addr.organization() + "</company_name>\n"; xml += "<job_title>" + addr.title() + "</job_title>\n"; QStringList emails = addr.emails(); for(uint i = 0; i < 3; ++i) { QString type, address, comment, display; if(i < emails.count()) { type = "SMTP"; address = emails[ i ]; /** * If the contact was created by kontact use the email address as * display name and the formatted name as comment, otherwise we use * the values from the server. */ if(custom("comes_from_scalix", addr) != "true") { comment = addr.formattedName(); display = emails[ i ]; } else { comment = custom(QString("email%1_address_with_comment").arg(i + 1), addr); display = custom(QString("email%1_display_name").arg(i + 1), addr); } } xml += QString("<email%1_address_type>").arg(i + 1) + type + QString("</email%1_address_type>").arg(i + 1) + "\n"; xml += QString("<email%1_address>").arg(i + 1) + address + QString("</email%1_address>").arg(i + 1) + "\n"; xml += QString("<email%1_address_with_comment>").arg(i + 1) + comment + QString("</email%1_address_with_comment>").arg(i + 1) + "\n"; xml += QString("<email%1_display_name>").arg(i + 1) + display + QString("</email%1_display_name>").arg(i + 1) + "\n"; } KABC::PhoneNumber phone = addr.phoneNumber(KABC::PhoneNumber::Home); xml += "<home_phone_number>" + phone.number() + "</home_phone_number>\n"; phone = addr.phoneNumber(KABC::PhoneNumber::Work); xml += "<work_phone_number>" + phone.number() + "</work_phone_number>\n"; phone = addr.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax); xml += "<work_fax_number>" + phone.number() + "</work_fax_number>\n"; phone = addr.phoneNumber(KABC::PhoneNumber::Cell); xml += "<mobile_phone_number>" + phone.number() + "</mobile_phone_number>\n"; const KABC::Address workAddress = addr.address(KABC::Address::Work); xml += "<work_address_street>" + workAddress.street() + "</work_address_street>\n"; xml += "<work_address_zip>" + workAddress.postalCode() + "</work_address_zip>\n"; xml += "<work_address_city>" + workAddress.locality() + "</work_address_city>\n"; xml += "<work_address_state>" + workAddress.region() + "</work_address_state>\n"; xml += "<work_address_country>" + workAddress.country() + "</work_address_country>\n"; const KABC::Address homeAddress = addr.address(KABC::Address::Home); xml += "<home_address_street>" + homeAddress.street() + "</home_address_street>\n"; xml += "<home_address_zip>" + homeAddress.postalCode() + "</home_address_zip>\n"; xml += "<home_address_city>" + homeAddress.locality() + "</home_address_city>\n"; xml += "<home_address_state>" + homeAddress.region() + "</home_address_state>\n"; xml += "<home_address_country>" + homeAddress.country() + "</home_address_country>\n"; const KABC::Address otherAddress = addr.address(KABC::Address::Dom); xml += "<other_address_street>" + otherAddress.street() + "</other_address_street>\n"; xml += "<other_address_zip>" + otherAddress.postalCode() + "</other_address_zip>\n"; xml += "<other_address_city>" + otherAddress.locality() + "</other_address_city>\n"; xml += "<other_address_state>" + otherAddress.region() + "</other_address_state>\n"; xml += "<other_address_country>" + otherAddress.country() + "</other_address_country>\n"; if(homeAddress.type() & KABC::Address::Pref) xml += "<selected_mailing_address>1</selected_mailing_address>\n"; else if(workAddress.type() & KABC::Address::Pref) xml += "<selected_mailing_address>2</selected_mailing_address>\n"; else if(otherAddress.type() & KABC::Address::Pref) xml += "<selected_mailing_address>3</selected_mailing_address>\n"; xml += "<im_address>" + addr.custom("KADDRESSBOOK", "X-IMAddress") + "</im_address>\n"; xml += "<manager>" + addr.custom("KADDRESSBOOK", "X-ManagersName") + "</manager>\n"; xml += "<department>" + addr.custom("KADDRESSBOOK", "X-Department") + "</department>\n"; xml += "<assistant>" + addr.custom("KADDRESSBOOK", "X-AssistantsName") + "</assistant>\n"; xml += "<profession>" + addr.custom("KADDRESSBOOK", "X-Profession") + "</profession>\n"; xml += "<office_location>" + addr.custom("KADDRESSBOOK", "X-Office") + "</office_location>\n"; xml += "<spouse>" + addr.custom("KADDRESSBOOK", "X-SpousesName") + "</spouse>\n"; xml += "<bday>" + addr.birthday().toString(Qt::ISODate) + "</bday>\n"; xml += "<anniversary>" + addr.custom("KADDRESSBOOK", "X-Anniversary") + "</anniversary>\n"; xml += "<mapi_charset>" + custom("mapi_charset", addr, "UTF8") + "</mapi_charset>"; xml += "</contact>\n"; return xml; }
QString AddresseeEmailSelection::email( const KABC::Addressee &addressee, uint index ) const { return addressee.emails()[ index ]; }
bool AddresseeEmailSelection::itemEquals( const KABC::Addressee &addressee, uint index, const QString &pattern ) const { return (pattern == addressee.formattedName() + " " + email( addressee, index )) || (addressee.emails().contains( pattern )); }
bool AddresseeEmailSelection::itemEnabled( const KABC::Addressee &addressee, uint ) const { return addressee.emails().count() != 0; }
uint AddresseeEmailSelection::itemCount( const KABC::Addressee &addressee ) const { return addressee.emails().count(); }