void FreeBusyManagerPrivate::contactSearchJobFinished( KJob *_job )
{
  const QString email = _job->property( "contactEmail" ).toString();

  if ( _job->error() ) {
    kError() << "Error while searching for contact: "
             << _job->errorString() << ", email = " << email;
    emit freeBusyUrlRetrieved( email, KUrl() );
    return;
  }

  Akonadi::ContactSearchJob *job = qobject_cast<Akonadi::ContactSearchJob*>( _job );
  QString configFile = KStandardDirs::locateLocal( "data",
                                                   QLatin1String( "korganizer/freebusyurls" ) );
  KConfig cfg( configFile );
  KConfigGroup group = cfg.group( email );
  QString url = group.readEntry( QLatin1String( "url" ) );

  QString pref;
  const KABC::Addressee::List contacts = job->contacts();
  foreach ( const KABC::Addressee &contact, contacts ) {
    pref = contact.preferredEmail();
    if ( !pref.isEmpty() && pref != email ) {
      group = cfg.group( pref );
      url = group.readEntry ( "url" );
      kDebug() << "Preferred email of" << email << "is" << pref;
      if ( !url.isEmpty() ) {
        kDebug() << "Taken url from preferred email:" << url;
        emit freeBusyUrlRetrieved( email, replaceVariablesUrl( KUrl( url ), email ) );
        return;
      }
    }
  }
void AliasesExpandJob::start()
{
    // At first we try to expand the recipient to a distribution list
    // or nick name and save the results in a map for later lookup
    foreach (const QString &recipient, mRecipients) {

        // speedup: assume aliases and list names don't contain '@'
        if (recipient.isEmpty() || recipient.contains(QLatin1Char('@'))) {
            continue;
        }

        // check for distribution list
        DistributionListExpandJob *expandJob = new DistributionListExpandJob(recipient, this);
        expandJob->setProperty("recipient", recipient);
        connect(expandJob, &Akonadi::ContactGroupExpandJob::result, this, &AliasesExpandJob::slotDistributionListExpansionDone);
        mDistributionListExpansionJobs++;
        expandJob->start();

        // check for nick name
        Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob(this);
        searchJob->setProperty("recipient", recipient);
        searchJob->setQuery(Akonadi::ContactSearchJob::NickName, recipient.toLower());
        connect(searchJob, &Akonadi::ContactSearchJob::result, this, &AliasesExpandJob::slotNicknameExpansionDone);
        mNicknameExpansionJobs++;
        searchJob->start();
    }

    if (mDistributionListExpansionJobs == 0 && mNicknameExpansionJobs == 0) {
        emitResult();
    }
}
void FreeBusyManagerPrivate::fetchFreeBusyUrl( const QString &email )
{
  // First check if there is a specific FB url for this email
  QString configFile = KStandardDirs::locateLocal( "data",
                                                   QLatin1String( "korganizer/freebusyurls" ) );
  KConfig cfg( configFile );
  KConfigGroup group = cfg.group( email );
  QString url = group.readEntry( QLatin1String( "url" ) );
  if ( !url.isEmpty() ) {
    kDebug() << "Found cached url:" << url;
    KUrl cachedUrl( url );
    if ( KCalPrefs::instance()->thatIsMe( email ) ) {
      cachedUrl.setUser( KCalPrefs::instance()->mFreeBusyRetrieveUser );
      cachedUrl.setPass( KCalPrefs::instance()->mFreeBusyRetrievePassword );
    }
    emit freeBusyUrlRetrieved( email, replaceVariablesUrl( cachedUrl, email ) );
    return;
  }
  // Try with the url configured by preferred email in kcontactmanager
  Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob();
  job->setQuery( Akonadi::ContactSearchJob::Email, email );
  job->setProperty( "contactEmail", QVariant::fromValue( email ) );
  connect( job, SIGNAL(result(KJob*)), this, SLOT(contactSearchJobFinished(KJob*)) );
  job->start();
}
示例#4
0
void VcardMemento::slotSearchJobFinished(KJob *job)
{
    Akonadi::ContactSearchJob *searchJob = static_cast<Akonadi::ContactSearchJob *>(job);
    if (searchJob->error()) {
        qCWarning(VCARD_LOG) << "Unable to fetch contact:" << searchJob->errorText();
        mIndex++;
        continueToCheckEmail();
        return;
    }

    const int contactSize(searchJob->contacts().size());
    if (contactSize >= 1) {
        VCard vcard = mVCardList.at(mIndex);
        vcard.found = true;
        vcard.address = searchJob->contacts().at(0);
        mVCardList[mIndex] = vcard;
        if (contactSize > 1) {
            qCDebug(VCARD_LOG) << " more than 1 contact was found";
        }
    }

    mIndex++;
    continueToCheckEmail();
}
示例#5
0
void VcardMemento::checkEmail()
{
    Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
    searchJob->setQuery(Akonadi::ContactSearchJob::Email, mVCardList.at(mIndex).email.toLower());
    connect(searchJob, &Akonadi::ContactSearchJob::result, this, &VcardMemento::slotSearchJobFinished);
}