void KOEditorDetails::fillIncidence( Incidence *incidence )
{
    incidence->clearAttendees();
    QVector<Q3ListViewItem*> toBeDeleted;
    Q3ListViewItem *item;
    AttendeeListItem *a;
    for ( item = mListView->firstChild(); item; item = item->nextSibling() ) {
        a = (AttendeeListItem *)item;
        Attendee *attendee = a->data();
        Q_ASSERT( attendee );
        /* Check if the attendee is a distribution list and expand it */
        if ( attendee->email().isEmpty() ) {
            KPIM::DistributionList list =
                KPIM::DistributionList::findByName( KABC::StdAddressBook::self(), attendee->name() );
            if ( !list.isEmpty() ) {
                toBeDeleted.push_back( item ); // remove it once we are done expanding
                KPIM::DistributionList::Entry::List entries = list.entries( KABC::StdAddressBook::self() );
                KPIM::DistributionList::Entry::List::Iterator it( entries.begin() );
                while ( it != entries.end() ) {
                    KPIM::DistributionList::Entry &e = ( *it );
                    ++it;
                    // this calls insertAttendee, which appends
                    insertAttendeeFromAddressee( e.addressee, attendee );
                    // TODO: duplicate check, in case it was already added manually
                }
            }
        } else {
            bool skip = false;
            if ( attendee->email().endsWith( QLatin1String( "example.net" ) ) ) {
                if ( KMessageBox::warningYesNo(
                            this,
                            i18nc( "@info",
                                   "%1 does not look like a valid email address. "
                                   "Are you sure you want to invite this participant?",
                                   attendee->email() ),
                            i18nc( "@title", "Invalid Email Address" ) ) != KMessageBox::Yes ) {
                    skip = true;
                }
            }
            if ( !skip ) {
                incidence->addAttendee( new Attendee( *attendee ) );
            }
        }
    }

    KOAttendeeEditor::fillIncidence( incidence );

    // cleanup
    qDeleteAll( toBeDeleted );
    toBeDeleted.clear();
}
Пример #2
0
void KOEditorFreeBusy::writeEvent(KCal::Event * event)
{
  event->clearAttendees();
  QValueVector<FreeBusyItem*> toBeDeleted;
  for ( FreeBusyItem *item = static_cast<FreeBusyItem *>( mGanttView->firstChild() ); item;
        item = static_cast<FreeBusyItem*>( item->nextSibling() ) )
  {
    Attendee *attendee = item->attendee();
    Q_ASSERT( attendee );
    /* Check if the attendee is a distribution list and expand it */
    if ( attendee->email().isEmpty() ) {
      KPIM::DistributionList list =
        KPIM::DistributionList::findByName( KABC::StdAddressBook::self(), attendee->name() );
      if ( !list.isEmpty() ) {
        toBeDeleted.push_back( item ); // remove it once we are done expanding
        KPIM::DistributionList::Entry::List entries = list.entries( KABC::StdAddressBook::self() );
        KPIM::DistributionList::Entry::List::Iterator it( entries.begin() );
        while ( it != entries.end() ) {
          KPIM::DistributionList::Entry &e = ( *it );
          ++it;
          // this calls insertAttendee, which appends
          insertAttendeeFromAddressee( e.addressee, attendee );
          // TODO: duplicate check, in case it was already added manually
        }
      }
    } else {
      bool skip = false;
      if ( attendee->email().endsWith( "example.net" ) ) {
        if ( KMessageBox::warningYesNo( this, i18n("%1 does not look like a valid email address. "
                "Are you sure you want to invite this participant?").arg( attendee->email() ),
              i18n("Invalid email address") ) != KMessageBox::Yes ) {
          skip = true;
        }
      }
      if ( !skip ) {
        event->addAttendee( new Attendee( *attendee ) );
      }
    }
  }

  KOAttendeeEditor::writeEvent( event );

  // cleanup
  QValueVector<FreeBusyItem*>::iterator it;
  for( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
    delete *it;
  }
}
Пример #3
0
void SearchManager::search(const QString &pattern, const KABC::Field::List &fields, Type type)
{
    mPattern = pattern;
    mFields = fields;
    mType = type;

    KABC::Addressee::List allContacts;
    mContacts.clear();

#if KDE_VERSION >= 319
    KABC::AddresseeList list(mAddressBook->allAddressees());
    if(!fields.isEmpty())
        list.sortByField(fields.first());

    allContacts = list;
#else
    KABC::AddressBook::ConstIterator abIt(mAddressBook->begin());
    const KABC::AddressBook::ConstIterator abEndIt(mAddressBook->end());
    for(; abIt != abEndIt; ++abIt)
        allContacts.append(*abIt);
#endif

#ifdef KDEPIM_NEW_DISTRLISTS
    // Extract distribution lists from allContacts
    mDistributionLists.clear();
    KABC::Addressee::List::Iterator rmIt(allContacts.begin());
    const KABC::Addressee::List::Iterator rmEndIt(allContacts.end());
    while(rmIt != rmEndIt)
    {
        if(KPIM::DistributionList::isDistributionList(*rmIt))
        {
            mDistributionLists.append(static_cast<KPIM::DistributionList>(*rmIt));
            rmIt = allContacts.remove(rmIt);
        }
        else
            ++rmIt;
    }

    typedef KPIM::DistributionList::Entry Entry;
    if(!mSelectedDistributionList.isNull())
    {
        const KPIM::DistributionList dl = KPIM::DistributionList::findByName(mAddressBook, mSelectedDistributionList);
        if(!dl.isEmpty())
        {
            allContacts.clear();
            const Entry::List entries = dl.entries(mAddressBook);
            const Entry::List::ConstIterator end = entries.end();
            for(Entry::List::ConstIterator it = entries.begin(); it != end; ++it)
            {
                allContacts.append((*it).addressee);
            }
        }
    }

#endif

    if(mPattern.isEmpty())      // no pattern, return all
    {
        mContacts = allContacts;

        emit contactsUpdated();

        return;
    }

    const KABC::Field::List fieldList = !mFields.isEmpty() ? mFields : KABC::Field::allFields();

    KABC::Addressee::List::ConstIterator it(allContacts.begin());
    const KABC::Addressee::List::ConstIterator endIt(allContacts.end());
    for(; it != endIt; ++it)
    {
#ifdef KDEPIM_NEW_DISTRLISTS
        if(KPIM::DistributionList::isDistributionList(*it))
            continue;
#endif

        bool found = false;
        // search over all fields
        KABC::Field::List::ConstIterator fieldIt(fieldList.begin());
        const KABC::Field::List::ConstIterator fieldEndIt(fieldList.end());
        for(; fieldIt != fieldEndIt; ++fieldIt)
        {

            if(type == StartsWith && (*fieldIt)->value(*it).startsWith(pattern, false))
            {
                mContacts.append(*it);
                found = true;
                break;
            }
            else if(type == EndsWith && (*fieldIt)->value(*it).endsWith(pattern, false))
            {
                mContacts.append(*it);
                found = true;
                break;
            }
            else if(type == Contains && (*fieldIt)->value(*it).find(pattern, 0, false) != -1)
            {
                mContacts.append(*it);
                found = true;
                break;
            }
            else if(type == Equals && (*fieldIt)->value(*it).localeAwareCompare(pattern) == 0)
            {
                mContacts.append(*it);
                found = true;
                break;
            }
        }

        if(!found)
        {
            // search over custom fields
            const QStringList customs = (*it).customs();

            QStringList::ConstIterator customIt(customs.begin());
            const QStringList::ConstIterator customEndIt(customs.end());
            for(; customIt != customEndIt; ++customIt)
            {
                int pos = (*customIt).find(':');
                if(pos != -1)
                {
                    const QString value = (*customIt).mid(pos + 1);
                    if(type == StartsWith && value.startsWith(pattern, false))
                    {
                        mContacts.append(*it);
                        break;
                    }
                    else if(type == EndsWith && value.endsWith(pattern, false))
                    {
                        mContacts.append(*it);
                        break;
                    }
                    else if(type == Contains && value.find(pattern, 0, false) != -1)
                    {
                        mContacts.append(*it);
                        break;
                    }
                    else if(type == Equals && value.localeAwareCompare(pattern) == 0)
                    {
                        mContacts.append(*it);
                        break;
                    }
                }
            }
        }
    }

    emit contactsUpdated();
}