void TestDistrList::testDuplicate()
{
    kDebug() ;
    // This is a special test for the case where we have a contact and a distr list with the same name
    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    KABC::Addressee addr;
    addr.setName( "foo" );
    addr.insertEmail( "*****@*****.**", true );
    ab->insertAddressee( addr );

#if 0 // we need a findByFormattedName
    KABC::Addressee::List addrList = ab->findByName( "foo" );
    assert( addrList.count() == 2 );

    bool a = DistributionList::isDistributionList( addrList.first() );
    bool b = DistributionList::isDistributionList( addrList.last() );
    // one is a distr list, but not both
    assert( a || b );
    //
    assert( ! ( a && b ) );
#endif

    DistributionList dl = DistributionList::findByName( ab, "foo" );
    assert( !dl.isEmpty() );
    assert( DistributionList::isDistributionList( dl ) );
    assert( dl.formattedName() == "foo" );
}
Example #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();
    }
  }
}
void TestDistrList::testNewList()
{
    kDebug() ;
    DistributionList dl;
    dl.setName( "foo" );
    assert( !dl.isEmpty() );
    check( "name set", dl.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl ) );

    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    ab->insertAddressee( dl );
#if 0 // can't do that until we have KABC::AddressBook::findByFormattedName, or we use setName()
    KABC::Addressee::List addrList = ab->findByName( "foo" );
    assert( addrList.count() == 1 );
    KABC::Addressee addr = addrList.first();
    assert( !addr.isEmpty() );
    check( "correct name", addr.name(), "foo" );
    assert( DistributionList::isDistributionList( addr ) );
#else
    KABC::Addressee addr = dl;
#endif

    DistributionList dl2 = DistributionList::findByName( ab, "foo" );
    assert( !dl2.isEmpty() );
    check( "correct name", dl2.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl2 ) );

    // Test the ctor that takes an addressee
    DistributionList dl3( addr );
    assert( !dl3.isEmpty() );
    assert( DistributionList::isDistributionList( dl3 ) );
    check( "correct name", dl3.formattedName(), "foo" );
}
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 );
          }
        }
      }
    }
  }
}
Example #5
0
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;
}
Example #6
0
/**
 * Send the file to the contact
 * @param uid the KABC uid you are sending to.
 * @param sourceURL a KURL to send.
 * @param altFileName an alternate filename describing the file
 * @param fileSize file size in bytes
 */
void Addressbook::sendFile(const QString &uid, const KURL &sourceURL, const QString &altFileName, uint fileSize)
{
    if(uid.isEmpty())
    {
        focusAndShowErrorMessage(i18n("Another KDE application tried to use Konversation to send a file to a contact, but did not specify any contact to send the file to.  This is probably a bug in the other application."));
        return;
    }
    KABC::Addressee addressee = addressBook->findByUid(uid);
    if(addressee.isEmpty())
    {
        focusAndShowErrorMessage(i18n("Another KDE application tried to use Konversation to send a file to a contact, but Konversation could not find the specified contact in the KDE address book."));
        return;
    }
    NickInfoPtr nickInfo = getNickInfo(addressee);
    if(!nickInfo)
    {
        QString user = addressee.fullEmail();
        if(!user.isEmpty()) user = "******" + user + ')';
        focusAndShowErrorMessage(i18n("Another KDE application tried to use Konversation to send a file to a contact, but the requested user%1 is not currently online.").arg(user));
        return;
    }
    nickInfo->getServer()->addDccSend(nickInfo->getNickname(), sourceURL, altFileName, fileSize);
    QWidget *widget = nickInfo->getServer()->getViewContainer()->getWindow();
    KWin::demandAttention(widget->winId());       //If activeWindow request is denied, at least demand attention!
    KWin::activateWindow(widget->winId());        //May or may not work, depending on focus stealing prevention.

}
Example #7
0
QPixmap AddresseeEmailSelection::itemIcon( const KABC::Addressee &addressee, uint ) const
{
  if ( !addressee.photo().data().isNull() )
    return addressee.photo().data().smoothScale( 16, 16 );
  else
    return KGlobal::iconLoader()->loadIcon( "personal", KIcon::Small );
}
Example #8
0
void HtmlExport::formatAttendees( QTextStream *ts, Incidence *event )
{
    Attendee::List attendees = event->attendees();
    if (attendees.count()) {
        *ts << "<em>";
#ifndef KORG_NOKABC
        KABC::AddressBook *add_book = KABC::StdAddressBook::self( true );
        KABC::Addressee::List addressList;
        addressList = add_book->findByEmail(event->organizer().email());
        KABC::Addressee o = addressList.first();
        if (!o.isEmpty() && addressList.size()<2) {
            *ts << "<a href=\"mailto:" << event->organizer().email() << "\">";
            *ts << cleanChars(o.formattedName()) << "</a>\n";
        }
        else *ts << event->organizer().fullName();
#else
        *ts << event->organizer().fullName();
#endif
        *ts << "</em><br />";
        Attendee::List::ConstIterator it;
        for( it = attendees.begin(); it != attendees.end(); ++it ) {
            Attendee *a = *it;
            if (!a->email().isEmpty()) {
                *ts << "<a href=\"mailto:" << a->email();
                *ts << "\">" << cleanChars(a->name()) << "</a>";
            }
            else {
                *ts << "    " << cleanChars(a->name());
            }
            *ts << "<br />" << "\n";
        }
    } else {
        *ts << "    &nbsp;\n";
    }
}
Example #9
0
void VCardXXPort::addKey( KABC::Addressee &addr, KABC::Key::Types type )
{
  QString fingerprint = addr.custom( "KADDRESSBOOK",
                                     (type == KABC::Key::PGP ? "OPENPGPFP" : "SMIMEFP") );
  if ( fingerprint.isEmpty() )
    return;

  GpgME::Context * context = GpgME::Context::createForProtocol( GpgME::Context::OpenPGP );
  if ( !context ) {
    kdError() << "No context available" << endl;
    return;
  }

  context->setArmor( false );
  context->setTextMode( false );

  QGpgME::QByteArrayDataProvider dataProvider;
  GpgME::Data dataObj( &dataProvider );
  GpgME::Error error = context->exportPublicKeys( fingerprint.latin1(), dataObj );
  delete context;

  if ( error ) {
    kdError() << error.asString() << endl;
    return;
  }

  KABC::Key key;
  key.setType( type );
  key.setBinaryData( dataProvider.data() );

  addr.insertKey( key );
}
Example #10
0
void AddresseeEditorDialog::widgetModified()
{
  const KABC::Addressee addressee = mEditorWidget->addressee();
  if ( !addressee.isEmpty() )
    setTitle( addressee );

  enableButton( KDialogBase::Apply, true );
}
Example #11
0
void NameEditWidget::storeContact( KABC::Addressee &contact ) const
{
  contact.setPrefix( mContact.prefix() );
  contact.setGivenName( mContact.givenName() );
  contact.setAdditionalName( mContact.additionalName() );
  contact.setFamilyName( mContact.familyName() );
  contact.setSuffix( mContact.suffix() );
}
Example #12
0
QString ContactsModel::getName(KABC::Addressee contact) const
{
    QString name = contact.formattedName();
    if (name.isEmpty()) {
        name = QString("%1 %2").arg(contact.givenName()).arg(contact.familyName());
    }
    return name;
}
Example #13
0
void KoRdfFoaF::fromKABC(KABC::Addressee addr)
{
    m_name = addr.realName();
    m_nick = addr.nickName();
    KABC::PhoneNumber ph = addr.phoneNumber(KABC::PhoneNumber::Work);
    m_phone = ph.number();
    m_homePage = addr.url().url();
}
Example #14
0
bool KABCHandler::hasNameMatch(const KABC::Addressee& contact, const QString& name)
{
    if (contact.assembledName().lower().find(name) != -1) return true;

    if (contact.formattedName().lower().find(name) != -1) return true;

    return false;
}
Example #15
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;
}
Example #16
0
void AddresseeEmailSelection::setSelectedItem( uint fieldIndex, const QStringList &emails )
{
  QStringList::ConstIterator it;
  for ( it = emails.begin(); it != emails.end(); ++it ) {
    KABC::Addressee addr;
    addr.insertEmail( *it, true );

    selector()->setItemSelected( fieldIndex, addr, 0, *it );
  }
}
Example #17
0
void KraftView::slotAddresseeFound( const QString& uid, const KABC::Addressee& contact )
{
    if( !contact.isEmpty() ) {
        kDebug() << "Addressee Found with uid " << uid;
        slotNewAddress( contact, false );
        kDebug() << "The loaded Contact has this realname: " << contact.realName() << endl;
    } else {
        kDebug() << "No contact found for uid " << uid;
    }
}
KABC::AddresseeList XXPortSelectDialog::contacts()
{
  const QStringList selection = mCore->selectedUIDs();

  KABC::AddresseeList list;
  if ( mUseSelection->isChecked() ) {
    QStringList::ConstIterator it;
    for ( it = selection.constBegin(); it != selection.constEnd(); ++it ) {
      KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
      if ( !addr.isEmpty() )
        list.append( addr );
    }
  } else if ( mUseFilters->isChecked() ) {
    // find contacts that can pass selected filter
    Filter::List::ConstIterator filterIt;
    for ( filterIt = mFilters.constBegin(); filterIt != mFilters.constEnd(); ++filterIt )
      if ( (*filterIt).name() == mFiltersCombo->currentText() )
        break;

    KABC::AddressBook::Iterator it;
    for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
      if ( (*filterIt).filterAddressee( *it ) )
        list.append( *it );
    }
  } else if ( mUseCategories->isChecked() ) {
    const QStringList categorieList = categories();

    KABC::AddressBook::ConstIterator it;
    KABC::AddressBook::ConstIterator addressBookEnd( mCore->addressBook()->constEnd() );
    for ( it = mCore->addressBook()->constBegin(); it != addressBookEnd; ++it ) {
      const QStringList tmp( (*it).categories() );
      QStringList::ConstIterator tmpIt;
      for ( tmpIt = tmp.constBegin(); tmpIt != tmp.constEnd(); ++tmpIt )
        if ( categorieList.contains( *tmpIt ) ) {
          list.append( *it );
          break;
        }
    }
  } else {
    // create a string list of all entries:
    KABC::AddressBook::ConstIterator it;
    for ( it = mCore->addressBook()->constBegin(); it != mCore->addressBook()->constEnd(); ++it )
      list.append( *it );
  }

  if ( mUseSorting ) {
    list.setReverseSorting( mSortTypeCombo->currentIndex() == 1 );
    int pos = mFieldCombo->currentIndex();
    if ( pos < mFields.count() )
      list.sortByField( mFields[ pos ] );
  }

  return list;
}
Example #19
0
QString ContactsModel::getAvatar(KABC::Addressee contact) const
{
    KABC::Picture pic = contact.photo();
    qDebug() << "Picture url: " << pic.url();

    if (pic.isIntern()) {
        QString url = "contacts/"+contact.uid();
        ImageProvider::getInstance()->registerImage(url, pic.data());
        return "image://images/"+url;
    } else
        return pic.url();
}
Example #20
0
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();
}
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() );
  }
}
void KoDocumentInfoDlg::slotLoadFromKABC()
{
#ifdef KDEPIMLIBS_FOUND
    KABC::StdAddressBook *ab = static_cast<KABC::StdAddressBook*>
                               (KABC::StdAddressBook::self());
    if (!ab)
        return;

    KABC::Addressee addr = ab->whoAmI();
    if (addr.isEmpty()) {
        KMessageBox::sorry(0, i18n("No personal contact data set, please use the option \
                                    \"Set as Personal Contact Data\" from the \"Edit\"     menu in KAddressbook to set one."));
        return;
    }
Example #23
0
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();
}
void KCalResourceSlox::parseMembersAttribute( const QDomElement &e,
                                              Incidence *incidence )
{
  incidence->clearAttendees();

  QDomNode n;
  for( n = e.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement memberElement = n.toElement();
    if ( memberElement.tagName() == fieldName( Participant ) ) {
      QString member = memberElement.text();
      KABC::Addressee account;
      if ( mAccounts ) account = mAccounts->lookupUser( member );
      else kError() << "KCalResourceSlox: no accounts set";
      QString name;
      QString email;
      Attendee *a = incidence->attendeeByUid( member );
      if ( account.isEmpty() ) {
        if ( a ) continue;

        name = member;
        email = member + '@' + KUrl( mPrefs->url() ).host();
      } else {
        name = account.realName();
        email = account.preferredEmail();
      }
      if ( a ) {
        a->setName( name );
        a->setEmail( email );
      } else {
        a = new Attendee( name, email );
        a->setUid( member );
        incidence->addAttendee( a );
      }
      QString status = memberElement.attribute( "confirm" );
      if ( !status.isEmpty() ) {
        if ( status == "accept" ) {
          a->setStatus( Attendee::Accepted );
        } else if ( status == "decline" ) {
          a->setStatus( Attendee::Declined );
        } else {
          a->setStatus( Attendee::NeedsAction );
        }
      }
    } else {
      kDebug() << "Unknown tag in members attribute:"
               << memberElement.tagName();
    }
  }
}
Example #25
0
KABC::Addressee::List ViewManager::selectedAddressees() const
{
    KABC::Addressee::List list;

    const QStringList uids = selectedUids();
    QStringList::ConstIterator it;
    for(it = uids.begin(); it != uids.end(); ++it)
    {
        KABC::Addressee addr = mCore->addressBook()->findByUid(*it);
        if(!addr.isEmpty())
            list.append(addr);
    }

    return list;
}
Example #26
0
QString Nick::calculateLabel1()
{
    NickInfoPtr nickinfo = getChannelNick()->getNickInfo();
    KABC::Addressee addressee = nickinfo->getAddressee();

    if(!addressee.realName().isEmpty())           //if no addressee, realName will be empty
    {
        return nickinfo->getNickname() + " (" + addressee.realName() + ')';
    }
    else if(Preferences::showRealNames() && !nickinfo->getRealName().isEmpty())
    {
        return nickinfo->getNickname() + " (" + nickinfo->getRealName() + ')';
    }

    return nickinfo->getNickname();
}
Example #27
0
bool KAddrBookExternal::addVCard(const KABC::Addressee &addressee, QWidget *parent)
{
    KABC::AddressBook *ab = KABC::StdAddressBook::self(true);
    bool inserted = false;

    ab->setErrorHandler(new KABC::GuiErrorHandler(parent));

    KABC::Addressee::List addressees =
        ab->findByEmail(addressee.preferredEmail());

    if(addressees.isEmpty())
    {
        if(KAddrBookExternal::addAddressee(addressee))
        {
            QString text = i18n("The VCard was added to your addressbook; "
                                "you can add more information to this "
                                "entry by opening the addressbook.");
            KMessageBox::information(parent, text, QString::null, "addedtokabc");
            inserted = true;
        }
    }
    else
    {
        QString text = i18n("The VCard's primary email address is already in "
                            "your addressbook; however, you may save the VCard "
                            "into a file and import it into the addressbook "
                            "manually.");
        KMessageBox::information(parent, text);
        inserted = true;
    }

    ab->setErrorHandler(0);
    return inserted;
}
Example #28
0
void AddressEditWidget::storeContact( KABC::Addressee &contact ) const
{
  // delete all previous addresses
  const KABC::Address::List oldAddresses = contact.addresses();
  for ( int i = 0; i < oldAddresses.count(); ++i ) {
    contact.removeAddress( oldAddresses.at( i ) );
  }

  // insert the new ones
  for ( int i = 0; i < mAddressList.count(); ++i ) {
    const KABC::Address address( mAddressList.at( i ) );
    if ( !address.isEmpty() ) {
      contact.insertAddress( address );
    }
  }
}
Example #29
0
    void AddressbookHandler::fakeAddresseeListFromDevice( KABC::Addressee::List &mAddresseeList, QValueList<uint32_t> &idList )
    {
        for ( QValueList<uint32_t>::const_iterator it = idList.begin(); it != idList.end(); ++it ) {
            KABC::Addressee addr;

            QString konId = "RRA-ID-" + QString::number( *it, 16 ).rightJustify( 8, '0' );
            QString kdeId;

            if ((kdeId = mUidHelper->kdeId("SynCEAddressbook", konId, "---")) != "---") {
                addr.setUid(kdeId);
                mUidHelper->removeId("SynCEAddressbook", addr.uid());
                mAddresseeList.push_back( addr );
            }
            kdDebug(2120) << "Contact: " << konId << "  --  " << kdeId << endl;
        }
    }
Example #30
0
static QString custom(const QString &name, const KABC::Addressee &addr, const QString &defaultValue = QString())
{
    const QString value = addr.custom("Scalix", name);
    if(value.isEmpty())
        return defaultValue;
    else
        return value;
}