void DistributionListDialog::setRecipients( const Recipient::List &recipients )
{
  Recipient::List::ConstIterator it;
  for( it = recipients.constBegin(); it != recipients.constEnd(); ++it ) {
    QStringList emails = KPIMUtils::splitAddressList( (*it).email() );
    QStringList::ConstIterator it2;
    for( it2 = emails.constBegin(); it2 != emails.constEnd(); ++it2 ) {
      QString name;
      QString email;
      KABC::Addressee::parseEmailAddress( *it2, name, email );
      if ( !email.isEmpty() ) {
        DistributionListItem *item = new DistributionListItem( mRecipientsList );
        KABC::Addressee::List addressees =
          KABC::StdAddressBook::self( true )->findByEmail( email );
        if ( addressees.isEmpty() ) {
          KABC::Addressee a;
          a.setNameFromString( name );
          a.insertEmail( email );
          item->setTransientAddressee( a, email );
          item->setCheckState( 0, Qt::Checked );
        } else {
          KABC::Addressee::List::ConstIterator it3;
          for( it3 = addressees.constBegin(); it3 != addressees.constEnd(); ++it3 ) {
            item->setAddressee( *it3, email );
            if ( it3 == addressees.constBegin() ) item->setCheckState( 0, Qt::Checked );
          }
        }
      }
    }
  }
}
Exemplo n.º 2
0
void RecentAddresses::add( const QString& entry )
{
  if ( !entry.isEmpty() && m_maxCount > 0 ) {
    QStringList list = KPIM::splitEmailAddrList( entry );
    for( QStringList::const_iterator e_it = list.begin(); e_it != list.end(); ++e_it ) {
      KPIM::EmailParseResult errorCode = KPIM::isValidEmailAddress( *e_it );
      if ( errorCode != KPIM::AddressOk ) 
        continue;
      QString email;
      QString fullName;
      KABC::Addressee addr;

      KABC::Addressee::parseEmailAddress( *e_it, fullName, email );

      for ( KABC::Addressee::List::Iterator it = m_addresseeList.begin();
          it != m_addresseeList.end(); ++it )
      {
        if ( email == (*it).preferredEmail() ) {
          //already inside, remove it here and add it later at pos==1
          m_addresseeList.remove( it );
          break;
        }
      }
      addr.setNameFromString( fullName );
      addr.insertEmail( email, true );
      m_addresseeList.prepend( addr );
      adjustSize();
    }
  }
}
Exemplo n.º 3
0
KABC::Addressee KoRdfFoaF::toKABC() const
{
    KABC::Addressee addr;
    addr.setNameFromString(m_name);
    addr.setNickName(m_nick);
    KABC::PhoneNumber ph(m_phone, KABC::PhoneNumber::Work);
    addr.insertPhoneNumber(ph);
    return addr;
}
void
AddressesDialog::setSelectedBCC( const QStringList& l )
{
  QString name, email;
  for ( QStringList::ConstIterator it = l.constBegin(); it != l.constEnd(); ++it ) {
    KABC::Addressee addr;
    KABC::Addressee::parseEmailAddress( *it, name, email );
    addr.setNameFromString( name );
    addr.insertEmail( email );
    addAddresseeToSelected( addr, selectedBccItem() );
  }
}
Exemplo n.º 5
0
void RecentAddresses::load( KConfig *config )
{
    QStringList addresses;
    QString name;
    QString email;

    m_addresseeList.clear();
    KConfigGroupSaver cs( config, "General" );
    m_maxCount = config->readNumEntry( "Maximum Recent Addresses", 40 );
    addresses = config->readListEntry( "Recent Addresses" );
    for ( QStringList::Iterator it = addresses.begin(); it != addresses.end(); ++it ) {
        KABC::Addressee::parseEmailAddress( *it, name, email );
        if ( !email.isEmpty() ) {
            KABC::Addressee addr;
            addr.setNameFromString( name );
            addr.insertEmail( email, true );
            m_addresseeList.append( addr );
        }
    }

    adjustSize();
}
Exemplo n.º 6
0
void AddressBookSelectorWidget::slotAddAddresseeClicked()
{
	// Pop up add addressee dialog
	QString addresseeName = KInputDialog::getText( i18n( "New Address Book Entry" ), i18n( "Name the new entry:" ), QString(), 0, this );

	if ( !addresseeName.isEmpty() )
	{
		KABC::Addressee addr;
		addr.setNameFromString( addresseeName );
		m_addressBook->insertAddressee(addr);
		Kopete::KABCPersistence::self()->writeAddressBook( 0 );
		slotLoadAddressees();
		// select the addressee we just added
		Q3ListViewItem * added = addresseeListView->findItem( addresseeName, 1 );
		kListViewSearchLine->clear();
		kListViewSearchLine->updateSearch();
		kListViewSearchLine->clear();
		kListViewSearchLine->updateSearch();
		addresseeListView->setSelected( added, true );
		addresseeListView->ensureItemVisible( added );
	}
}
Exemplo n.º 7
0
void AddresseeEditorWidget::nameBoxChanged()
{
  KABC::Addressee addr;
  AddresseeConfig config( mAddressee );
  if ( config.automaticNameParsing() ) {
    addr.setNameFromString( mNameEdit->text() );
    mNameLabel->hide();
    mNameEdit->show();
  } else {
    addr = mAddressee;
    mNameEdit->hide();
    mNameLabel->setText( mNameEdit->text() );
    mNameLabel->show();
  }

  if ( mFormattedNameType != NameEditDialog::CustomName ) {
    mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
    mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
  }

  mAddressEditWidget->updateAddressee( mAddressee );
}
Exemplo n.º 8
0
bool KDEAccountsFormat::loadAll( KABC::AddressBook *book,
                              KABC::Resource *resource,
                              QFile *file )
{
    if ( !book || !file ) // eh?
        return false;

    QString uuid = "KDEAccountsEntry.";
    int id = 0;

    QByteArray array = file->readAll();
    file->close();

    QByteArray::ConstIterator it = array.begin();
    QByteArray::ConstIterator end = array.end();
    QByteArray::ConstIterator startLine;
    QString line;
    char eol = '\n';
    char delim = ' ';

    for ( ; it < end; it++ )
    {
        startLine = it;

        for ( ; it && it < end && *it != eol; it++ )
        { } // find eol

        uint length = it - startLine;
        line = QString::fromUtf8( startLine, length ).simplified();

        QString nickName;
        QString name;
        QString email;

        int firstSpace = line.indexOf( delim );
        if ( firstSpace > 0 )
        {
            nickName = line.left( firstSpace );

            int lastSpace = line.lastIndexOf( delim );
            if ( lastSpace > firstSpace )
            {
                email = line.mid( lastSpace +1 );

                int start = firstSpace + 1;
                int length = lastSpace - start;
                name = line.mid( start, length );

                if ( !email.isEmpty() )
                {
                    KABC::Addressee address;
                    address.setNickName( nickName  );
                    address.setNameFromString( name );
                    address.setOrganization("KDE Project");
                    address.insertCategory("KDE Developer");
                    address.insertEmail( email  );
                    address.setUid( uuid + QString::number( id++ ));

                    address.setResource( resource );
                    book->insertAddressee( address );
                }
            }
        }
    }

    return true;
}
Exemplo n.º 9
0
KABC::AddresseeList OperaXXPort::importContacts(const QString &) const
{
    KABC::AddresseeList addrList;

    QString fileName = KFileDialog::getOpenFileName(QDir::homeDirPath() + QString::fromLatin1("/.opera/contacts.adr"));
    if(fileName.isEmpty())
        return addrList;

    QFile file(fileName);
    if(!file.open(IO_ReadOnly))
    {
        QString msg = i18n("<qt>Unable to open <b>%1</b> for reading.</qt>");
        KMessageBox::error(parentWidget(), msg.arg(fileName));
        return addrList;
    }

    QTextStream stream(&file);
    stream.setEncoding(QTextStream::UnicodeUTF8);
    QString line, key, value;
    bool parseContact = false;
    KABC::Addressee addr;

    QRegExp separator("\x02\x02");

    while(!stream.atEnd())
    {
        line = stream.readLine();
        line = line.stripWhiteSpace();
        if(line == QString::fromLatin1("#CONTACT"))
        {
            parseContact = true;
            addr = KABC::Addressee();
            continue;
        }
        else if(line.isEmpty())
        {
            parseContact = false;
            if(!addr.isEmpty())
            {
                addrList.append(addr);
                addr = KABC::Addressee();
            }
            continue;
        }

        if(parseContact == true)
        {
            int sep = line.find('=');
            key = line.left(sep).lower();
            value = line.mid(sep + 1);
            if(key == QString::fromLatin1("name"))
                addr.setNameFromString(value);
            else if(key == QString::fromLatin1("mail"))
            {
                QStringList emails = QStringList::split(separator, value);

                QStringList::Iterator it = emails.begin();
                bool preferred = true;
                for(; it != emails.end(); ++it)
                {
                    addr.insertEmail(*it, preferred);
                    preferred = false;
                }
            }
            else if(key == QString::fromLatin1("phone"))
                addr.insertPhoneNumber(KABC::PhoneNumber(value));
            else if(key == QString::fromLatin1("fax"))
                addr.insertPhoneNumber(KABC::PhoneNumber(value,
                                       KABC::PhoneNumber::Fax | KABC::PhoneNumber::Home));
            else if(key == QString::fromLatin1("postaladdress"))
            {
                KABC::Address address(KABC::Address::Home);
                address.setLabel(value.replace(separator, "\n"));
                addr.insertAddress(address);
            }
            else if(key == QString::fromLatin1("description"))
                addr.setNote(value.replace(separator, "\n"));
            else if(key == QString::fromLatin1("url"))
                addr.setUrl(KURL(value));
            else if(key == QString::fromLatin1("pictureurl"))
            {
                KABC::Picture pic(value);
                addr.setPhoto(pic);
            }
        }
    }

    file.close();

    return addrList;
}
Exemplo n.º 10
0
void readKMailEntry(const QString &kmailEntry, KABC::AddressBook *ab)
{
    kdDebug() << "KMAILENTRY: " << kmailEntry << endl;

    QString entry = kmailEntry.simplifyWhiteSpace();
    if(entry.isEmpty())
        return;

    QString email;
    QString name;
    QString comment;

    if(entry.at(entry.length() - 1) == ')')
    {
        int br = entry.findRev('(');
        if(br >= 0)
        {
            comment = entry.mid(br + 1, entry.length() - br - 2);
            entry.truncate(br);
            if(entry.at(entry.length() - 1).isSpace())
            {
                entry.truncate(br - 1);
            }
        }
    }

    int posSpace = entry.findRev(' ');
    if(posSpace < 0)
    {
        email = entry;
        if(!comment.isEmpty())
        {
            name = comment;
            comment = "";
        }
    }
    else
    {
        email = entry.mid(posSpace + 1);
        name = entry.left(posSpace);
    }

    if(email.at(0) == '<' && email.at(email.length() - 1) == '>')
    {
        email = email.mid(1, email.length() - 2);
    }
    if(name.at(0) == '"' && name.at(name.length() - 1) == '"')
    {
        name = name.mid(1, name.length() - 2);
    }
    if(name.at(0) == '\'' && name.at(name.length() - 1) == '\'')
    {
        name = name.mid(1, name.length() - 2);
    }

    if(name.at(name.length() - 1) == ')')
    {
        int br = name.findRev('(');
        if(br >= 0)
        {
            comment = name.mid(br + 1, name.length() - br - 2) + " " + comment;
            name.truncate(br);
            if(name.at(name.length() - 1).isSpace())
            {
                name.truncate(br - 1);
            }
        }
    }

    kdDebug() << "  EMAIL   : " << email << endl;
    kdDebug() << "  NAME    : " << name << endl;
    kdDebug() << "  COMMENT : " << comment << endl;

    KABC::Addressee::List al = ab->findByEmail(email);
    if(al.isEmpty())
    {
        KABC::Addressee a;
        a.setNameFromString(name);
        a.insertEmail(email);
        a.setNote(comment);

        ab->insertAddressee(a);

        kdDebug() << "--INSERTED: " << a.realName() << endl;
    }
}
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;
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
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);
}