本文整理汇总了C++中kabc::Addressee::organization方法的典型用法代码示例。如果您正苦于以下问题:C++ Addressee::organization方法的具体用法?C++ Addressee::organization怎么用?C++ Addressee::organization使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kabc::Addressee
的用法示例。
在下文中一共展示了Addressee::organization方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formattedName
QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
{
QString name;
switch ( type ) {
case SimpleName:
name = addr.givenName() + " " + addr.familyName();
break;
case FullName:
name = addr.assembledName();
break;
case ReverseNameWithComma:
name = addr.familyName() + ", " + addr.givenName();
break;
case ReverseName:
name = addr.familyName() + " " + addr.givenName();
break;
case Organization:
name = addr.organization();
break;
default:
name = "";
break;
}
return name.simplifyWhiteSpace();
}
示例2: guessedDisplayType
// Tries to guess the display type that is used for the passed contact
static DisplayNameEditWidget::DisplayType guessedDisplayType( const KABC::Addressee &contact )
{
if ( contact.formattedName() == ( contact.givenName() + QLatin1Char( ' ' ) + contact.familyName() ) ) {
return DisplayNameEditWidget::SimpleName;
} else if ( contact.formattedName() == contact.assembledName() ) {
return DisplayNameEditWidget::FullName;
} else if ( contact.formattedName() == ( contact.familyName() + QLatin1String( ", " ) + contact.givenName() ) ) {
return DisplayNameEditWidget::ReverseNameWithComma;
} else if ( contact.formattedName() == ( contact.familyName() + QLatin1Char( ' ' ) + contact.givenName() ) ) {
return DisplayNameEditWidget::ReverseName;
} else if ( contact.formattedName() == contact.organization() ) {
return DisplayNameEditWidget::Organization;
} else {
return DisplayNameEditWidget::CustomName;
}
}
示例3: contactToTemplate
void ReportGenerator::contactToTemplate( TextTemplate *tmpl, const QString& prefix, const KABC::Addressee& contact )
{
if( contact.isEmpty() ) return;
tmpl->setValue( ADDRESS_TAG( prefix, "NAME" ), escapeTrml2pdfXML( contact.realName() ) );
QString co = contact.organization();
if( co.isEmpty() ) {
co = contact.realName();
}
tmpl->setValue( ADDRESS_TAG( prefix, "ORGANISATION" ), escapeTrml2pdfXML( co ) );
tmpl->setValue( ADDRESS_TAG( prefix, "URL" ), escapeTrml2pdfXML( contact.url().prettyUrl() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "EMAIL" ), escapeTrml2pdfXML( contact.preferredEmail() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "PHONE" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Work ).number() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "FAX" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Fax ).number() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "CELL" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Cell ).number() ) );
KABC::Address address;
address = contact.address( KABC::Address::Pref );
if( address.isEmpty() )
address = contact.address(KABC::Address::Work );
if( address.isEmpty() )
address = contact.address(KABC::Address::Home );
if( address.isEmpty() )
address = contact.address(KABC::Address::Postal );
tmpl->setValue( ADDRESS_TAG( prefix, "POSTBOX" ),
escapeTrml2pdfXML( address.postOfficeBox() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "EXTENDED" ),
escapeTrml2pdfXML( address.extended() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "STREET" ),
escapeTrml2pdfXML( address.street() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "LOCALITY" ),
escapeTrml2pdfXML( address.locality() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ),
escapeTrml2pdfXML( address.region() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "POSTCODE" ),
escapeTrml2pdfXML( address.postalCode() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "COUNTRY" ),
escapeTrml2pdfXML( address.country() ) );
tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ),
escapeTrml2pdfXML( address.region() ) );
tmpl->setValue( ADDRESS_TAG( prefix,"LABEL" ),
escapeTrml2pdfXML( address.label() ) );
}
示例4: entityData
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() ) {
示例5: getValue
//.........这里部分代码省略.........
if ( name == "Prefered address: Label" )
{
KABC::Address a = addr.address( KABC::Address::Pref );
return a.label();
}
if ( name == "Home phone" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home );
return phone.number();
}
if ( name == "Business phone" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Work );
return phone.number();
}
if ( name == "Mobile phone" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Cell );
return phone.number();
}
if ( name == "Home fax" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
return phone.number();
}
if ( name == "Business fax" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
return phone.number();
}
if ( name == "Car phone" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Car );
return phone.number();
}
if ( name == "ISDN" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Isdn );
return phone.number();
}
if ( name == "Pager" )
{
KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Pager );
return phone.number();
}
if ( name == "Email" )
return addr.preferredEmail();
if ( name == "Mailer" )
return addr.mailer();
if ( name == "Time zone" )
{
KABC::TimeZone zone = addr.timeZone();
return QString::number( zone.offset() );
}
if ( name == "Geographic position" )
{
KABC::Geo geo = addr.geo();
QString lat;
QString longi;
if( geo.latitude()<0 )
lat = QString( i18n("%1 South") ).arg( -geo.latitude() );
else
lat = QString( i18n("%1 North") ).arg( geo.latitude() );
if( geo.longitude()<0 )
// There is something going wrong, because "W" is replaced by "q ".
// Needs fix.
longi = QString( i18n("%1 West") ).arg( -geo.longitude() );
else
longi = QString( i18n("%1 East") ).arg( geo.longitude() );
return i18n( "Geographic coordinates", "%1, %2" ).arg ( lat, longi );
}
if ( name == "Title" )
return addr.title();
if ( name == "Role" )
return addr.role();
if ( name == "Organization" )
return addr.organization();
if ( name == "Note" )
return addr.note();
if ( name == "productId" )
return addr.productId();
if ( name == "Revision" )
return KGlobal::locale()->formatDate( addr.revision().date() );
if ( name == "sortString" )
return addr.sortString();
if ( name == "URL" )
return addr.url().url();
if ( name == "Secrecy" )
{
KABC::Secrecy secrecy = addr.secrecy();
return KABC::Secrecy::typeLabel( secrecy.type() );
}
return ( i18n("Unkown mail merge variable: %1").arg ( name ) ) ;
}
示例6: readContents
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;
}
示例7: toXml
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);
//.........这里部分代码省略.........
示例8: fieldText
//.........这里部分代码省略.........
text = addressee.address(Address::Home).locality();
break;
case 10: // "Home Address Region"
text = addressee.address(Address::Home).region();
break;
case 11: // "Home Address Postal Code"
text = addressee.address(Address::Home).postalCode();
break;
case 12: // "Home Address Country"
text = addressee.address(Address::Home).country();
break;
case 13: // "Home Address Label"
text = addressee.address(Address::Home).label();
break;
case 14: // "Business Address Street"
text = addressee.address(Address::Work).street();
break;
case 15: // "Business Address Locality"
text = addressee.address(Address::Work).locality();
break;
case 16: // "Business Address Region"
text = addressee.address(Address::Work).region();
break;
case 17: // "Business Address Postal Code"
text = addressee.address(Address::Work).postalCode();
break;
case 18: // "Business Address Country"
text = addressee.address(Address::Work).country();
break;
case 19: // "Business Address Label"
text = addressee.address(Address::Work).label();
break;
case 20: // "Home Phone"
text = addressee.phoneNumber(PhoneNumber::Home).number();
break;
case 21: // "Business Phone"
text = addressee.phoneNumber(PhoneNumber::Work).number();
break;
case 22: // "Mobile Phone"
text = addressee.phoneNumber(PhoneNumber::Cell).number();
break;
case 23: // "Home Fax"
text = addressee.phoneNumber(PhoneNumber::Fax | PhoneNumber::Home).number();
break;
case 24: // "Business Fax"
text = addressee.phoneNumber(PhoneNumber::Fax | PhoneNumber::Work).number();
break;
case 25: // "Car Phone"
text = addressee.phoneNumber(PhoneNumber::Car).number();
break;
case 26: // "Isdn"
text = addressee.phoneNumber(PhoneNumber::Isdn).number();
break;
case 27: // "Pager"
text = addressee.phoneNumber(PhoneNumber::Pager).number();
break;
case 28: // "Email Address"
text = addressee.preferredEmail();
break;
case 29: // "Mail Client"
text = addressee.mailer();
break;
case 30: // "Title"
text = addressee.title();
break;
case 31: // "Role"
text = addressee.role();
break;
case 32: // "Organization"
text = addressee.organization();
break;
case 33: // "Note"
text = addressee.note();
break;
case 34: // "URL"
text = addressee.url().prettyUrl();
break;
case 35: // "Department"
break;
case 36: // "Profession"
break;
case 37: // "Assistant's Name"
break;
case 38: // "Manager's Name"
break;
case 39: // "Spouse's Name"
break;
case 40: // "Office"
break;
case 41: // "IM Address"
break;
case 42: // "Anniversary"
break;
default:
break;
}
return text;
}
示例9: workAddr
static KABC::Addressee convertLdapAttributesToAddressee( const KLDAP::LdapAttrMap &attrs )
{
KABC::Addressee addr;
// name
if ( !attrs.value( "cn" ).isEmpty() ) {
addr.setNameFromString( asUtf8( attrs["cn"].first() ) );
}
// email
KLDAP::LdapAttrValue lst = attrs["mail"];
KLDAP::LdapAttrValue::ConstIterator it = lst.constBegin();
bool pref = true;
while ( it != lst.constEnd() ) {
addr.insertEmail( asUtf8( *it ), pref );
pref = false;
++it;
}
if ( !attrs.value( "o" ).isEmpty() ) {
addr.setOrganization( asUtf8( attrs[ "o" ].first() ) );
}
if ( addr.organization().isEmpty() && !attrs.value( "Company" ).isEmpty() ) {
addr.setOrganization( asUtf8( attrs[ "Company" ].first() ) );
}
// Address
KABC::Address workAddr( KABC::Address::Work );
if ( !attrs.value( "department" ).isEmpty() ) {
addr.setDepartment( asUtf8( attrs[ "department" ].first() ) );
}
if ( !workAddr.isEmpty() ) {
addr.insertAddress( workAddr );
}
// phone
if ( !attrs.value( "homePhone" ).isEmpty() ) {
KABC::PhoneNumber homeNr = asUtf8( attrs[ "homePhone" ].first() );
homeNr.setType( KABC::PhoneNumber::Home );
addr.insertPhoneNumber( homeNr );
}
if ( !attrs.value( "telephoneNumber" ).isEmpty() ) {
KABC::PhoneNumber workNr = asUtf8( attrs[ "telephoneNumber" ].first() );
workNr.setType( KABC::PhoneNumber::Work );
addr.insertPhoneNumber( workNr );
}
if ( !attrs.value( "facsimileTelephoneNumber" ).isEmpty() ) {
KABC::PhoneNumber faxNr = asUtf8( attrs[ "facsimileTelephoneNumber" ].first() );
faxNr.setType( KABC::PhoneNumber::Fax );
addr.insertPhoneNumber( faxNr );
}
if ( !attrs.value( "mobile" ).isEmpty() ) {
KABC::PhoneNumber cellNr = asUtf8( attrs[ "mobile" ].first() );
cellNr.setType( KABC::PhoneNumber::Cell );
addr.insertPhoneNumber( cellNr );
}
if ( !attrs.value( "pager" ).isEmpty() ) {
KABC::PhoneNumber pagerNr = asUtf8( attrs[ "pager" ].first() );
pagerNr.setType( KABC::PhoneNumber::Pager );
addr.insertPhoneNumber( pagerNr );
}
return addr;
}
示例10: event
bool ContactListView::event( QEvent *e )
{
if( e->type() != QEvent::ToolTip )
return K3ListView::event( e );
if ( !tooltips() )
return true;
QHelpEvent * he = static_cast< QHelpEvent * >( e );
QPoint pnt = viewport()->mapFromGlobal( mapToGlobal( he->pos() ) );
Q3ListViewItem * item = itemAt ( pnt );
if ( item )
{
ContactListViewItem *plvi = static_cast<ContactListViewItem *>( item );
QString s;
//kDebug(5720) <<"Tip rec:" << r.x() <<"," << r.y() <<"," << r.width()
// << "," << r.height();
KABC::Addressee a = plvi->addressee();
if (a.isEmpty())
return true;
s += i18nc("label: value", "%1: %2", a.formattedNameLabel(),
a.formattedName());
s += '\n';
s += i18nc("label: value", "%1: %2", a.organizationLabel(),
a.organization());
QString notes = a.note().trimmed();
if ( !notes.isEmpty() ) {
notes += '\n';
s += '\n' + i18nc("label: value", "%1: \n", a.noteLabel());
QFontMetrics fm( font() );
// Begin word wrap code based on QMultiLineEdit code
int i = 0;
bool doBreak = false;
int linew = 0;
int lastSpace = -1;
int a = 0;
int lastw = 0;
while ( i < int(notes.length()) ) {
doBreak = false;
if ( notes[i] != '\n' )
linew += fm.width( notes[i] );
if ( lastSpace >= a && notes[i] != '\n' )
if (linew >= parentWidget()->width()) {
doBreak = true;
if ( lastSpace > a ) {
i = lastSpace;
linew = lastw;
}
else
i = qMax( a, i-1 );
}
if ( notes[i] == '\n' || doBreak ) {
s += notes.mid( a, i - a + (doBreak?1:0) ) +'\n';
a = i + 1;
lastSpace = a;
linew = 0;
}
if ( notes[i].isSpace() ) {
lastSpace = i;
lastw = linew;
}
if ( lastSpace <= a ) {
lastw = linew;
}
++i;
}
}
if ( s.isEmpty() )
QToolTip::hideText();
else
QToolTip::showText( he->globalPos(), s );
}
return true;
}
示例11: getAccountName
static QString getAccountName(const KABC::Addressee &addressee)
{
return addressee.organization();
}
示例12: addEmail
//-----------------------------------------------------------------------------
void KAddrBookExternal::addEmail(const QString &addr, QWidget *parent)
{
QString email;
QString name;
KABC::Addressee::parseEmailAddress(addr, name, email);
KABC::AddressBook *ab = KABC::StdAddressBook::self(true);
ab->setErrorHandler(new KABC::GuiErrorHandler(parent));
// force a reload of the address book file so that changes that were made
// by other programs are loaded
ab->asyncLoad();
// if we have to reload the address book then we should also wait until
// it's completely reloaded
#if KDE_IS_VERSION(3,4,89)
// This ugly hack will be removed in 4.0
while(!ab->loadingHasFinished())
{
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
// use sleep here to reduce cpu usage
usleep(100);
}
#endif
KABC::Addressee::List addressees = ab->findByEmail(email);
if(addressees.isEmpty())
{
KABC::Addressee a;
a.setNameFromString(name);
a.insertEmail(email, true);
{
KConfig config("kaddressbookrc");
config.setGroup("General");
int type = config.readNumEntry("FormattedNameType", 1);
QString name;
switch(type)
{
case 1:
name = a.givenName() + " " + a.familyName();
break;
case 2:
name = a.assembledName();
break;
case 3:
name = a.familyName() + ", " + a.givenName();
break;
case 4:
name = a.familyName() + " " + a.givenName();
break;
case 5:
name = a.organization();
break;
default:
name = "";
break;
}
name.simplifyWhiteSpace();
a.setFormattedName(name);
}
if(KAddrBookExternal::addAddressee(a))
{
QString text = i18n("<qt>The email address <b>%1</b> was added to your "
"addressbook; you can add more information to this "
"entry by opening the addressbook.</qt>").arg(addr);
KMessageBox::information(parent, text, QString::null, "addedtokabc");
}
}
else
{
QString text = i18n("<qt>The email address <b>%1</b> is already in your "
"addressbook.</qt>").arg(addr);
KMessageBox::information(parent, text, QString::null,
"alreadyInAddressBook");
}
ab->setErrorHandler(0);
}