korganizer

koattendeeeditor.cpp

00001 /*
00002     Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
00003     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00004     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00005 
00006         This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <config.h> // for KDEPIM_NEW_DISTRLISTS
00022 
00023 #include "koattendeeeditor.h"
00024 #include "koprefs.h"
00025 #include "koglobals.h"
00026 
00027 #ifndef KORG_NOKABC
00028 #include <kabc/addresseedialog.h>
00029 #include <libkdepim/addressesdialog.h>
00030 #include <libkdepim/addresseelineedit.h>
00031 #endif
00032 
00033 #include <libkcal/incidence.h>
00034 
00035 #include <libemailfunctions/email.h>
00036 
00037 #ifdef KDEPIM_NEW_DISTRLISTS
00038 #include "distributionlist.h"
00039 #else
00040 #include <kabc/distributionlist.h>
00041 #endif
00042 #include <kabc/stdaddressbook.h>
00043 
00044 #include <kiconloader.h>
00045 #include <klocale.h>
00046 #include <kmessagebox.h>
00047 
00048 #include <qcheckbox.h>
00049 #include <qcombobox.h>
00050 #include <qhbox.h>
00051 #include <qlabel.h>
00052 #include <qlayout.h>
00053 #include <qpushbutton.h>
00054 #include <qwhatsthis.h>
00055 
00056 using namespace KCal;
00057 
00058 enum {
00059   EXPAND_DISTLIST_TIMEOUT = 2000 // milisecs
00060 };
00061 
00062 KOAttendeeEditor::KOAttendeeEditor( QWidget * parent, const char *name ) :
00063     QWidget( parent, name ),
00064     mDisableItemUpdate( true )
00065 {
00066 }
00067 
00068 void KOAttendeeEditor::initOrganizerWidgets(QWidget * parent, QBoxLayout * layout)
00069 {
00070   mOrganizerHBox = new QHBox( parent );
00071   layout->addWidget( mOrganizerHBox );
00072   // If creating a new event, then the user is the organizer -> show the
00073   // identity combo
00074   // readEvent will delete it and set another label text instead, if the user
00075   // isn't the organizer.
00076   // Note that the i18n text below is duplicated in readEvent
00077   QString whatsThis = i18n("Sets the identity corresponding to "
00078                            "the organizer of this to-do or event. "
00079                            "Identities can be set in the 'Personal' "
00080                            "section of the KOrganizer configuration, or in the "
00081                            "'Security & Privacy'->'Password & User Account' "
00082                            "section of the KDE Control Center. In addition, "
00083                            "identities are gathered from your KMail settings "
00084                            "and from your address book. If you choose "
00085                            "to set it globally for KDE in the Control Center, "
00086                            "be sure to check 'Use email settings from "
00087                            "Control Center' in the 'Personal' section of the "
00088                            "KOrganizer configuration.");
00089   mOrganizerLabel = new QLabel( i18n( "Identity as organizer:" ),
00090                                 mOrganizerHBox );
00091   mOrganizerCombo = new QComboBox( mOrganizerHBox );
00092   QWhatsThis::add( mOrganizerLabel, whatsThis );
00093   QWhatsThis::add( mOrganizerCombo, whatsThis );
00094   fillOrganizerCombo();
00095   mOrganizerHBox->setStretchFactor( mOrganizerCombo, 100 );
00096 }
00097 
00098 void KOAttendeeEditor::initEditWidgets(QWidget * parent, QBoxLayout * layout)
00099 {
00100   QGridLayout *topLayout = new QGridLayout();
00101   layout->addLayout( topLayout );
00102 
00103   QString whatsThis = i18n("Edits the name of the attendee selected in the list "
00104                            "above, or adds a new attendee if there are no attendees"
00105                            "in the list.");
00106   QLabel *attendeeLabel = new QLabel( parent );
00107   QWhatsThis::add( attendeeLabel, whatsThis );
00108   attendeeLabel->setText( i18n("Na&me:") );
00109   topLayout->addWidget( attendeeLabel, 0, 0 );
00110 
00111   mNameEdit = new KPIM::AddresseeLineEdit( parent );
00112   QWhatsThis::add( mNameEdit, whatsThis );
00113   mNameEdit->setClickMessage( i18n("Click to add a new attendee") );
00114   attendeeLabel->setBuddy( mNameEdit );
00115   mNameEdit->installEventFilter( this );
00116   connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
00117            SLOT( updateAttendee() ) );
00118   connect( mNameEdit, SIGNAL(returnPressed()), SLOT(expandAttendee()) );
00119   topLayout->addMultiCellWidget( mNameEdit, 0, 0, 1, 2 );
00120 
00121   whatsThis = i18n("Edits the role of the attendee selected "
00122                    "in the list above.");
00123   QLabel *attendeeRoleLabel = new QLabel( parent );
00124   QWhatsThis::add( attendeeRoleLabel, whatsThis );
00125   attendeeRoleLabel->setText( i18n("Ro&le:") );
00126   topLayout->addWidget( attendeeRoleLabel, 1, 0 );
00127 
00128   mRoleCombo = new QComboBox( false, parent );
00129   QWhatsThis::add( mRoleCombo, whatsThis );
00130   mRoleCombo->insertStringList( Attendee::roleList() );
00131   attendeeRoleLabel->setBuddy( mRoleCombo );
00132   connect( mRoleCombo, SIGNAL( activated( int ) ),
00133            SLOT( updateAttendee() ) );
00134   topLayout->addWidget( mRoleCombo, 1, 1 );
00135 
00136   mDelegateLabel = new QLabel( parent );
00137   topLayout->addWidget( mDelegateLabel, 1, 2 );
00138 
00139   whatsThis = i18n("Edits the current attendance status of the attendee "
00140                    "selected in the list above.");
00141   QLabel *statusLabel = new QLabel( parent );
00142   QWhatsThis::add( statusLabel, whatsThis );
00143   statusLabel->setText( i18n("Stat&us:") );
00144   topLayout->addWidget( statusLabel, 2, 0 );
00145 
00146   mStatusCombo = new QComboBox( false, parent );
00147   QWhatsThis::add( mStatusCombo, whatsThis );
00148 //   mStatusCombo->insertStringList( Attendee::statusList() );
00149   mStatusCombo->insertItem( SmallIcon( "help" ), Attendee::statusName( Attendee::NeedsAction ) );
00150   mStatusCombo->insertItem( KOGlobals::self()->smallIcon( "ok" ), Attendee::statusName( Attendee::Accepted ) );
00151   mStatusCombo->insertItem( KOGlobals::self()->smallIcon( "no" ), Attendee::statusName( Attendee::Declined ) );
00152   mStatusCombo->insertItem( KOGlobals::self()->smallIcon( "apply" ), Attendee::statusName( Attendee::Tentative ) );
00153   mStatusCombo->insertItem( KOGlobals::self()->smallIcon( "mail_forward" ), Attendee::statusName( Attendee::Delegated ) );
00154   mStatusCombo->insertItem( Attendee::statusName( Attendee::Completed ) );
00155   mStatusCombo->insertItem( KOGlobals::self()->smallIcon( "help" ), Attendee::statusName( Attendee::InProcess ) );
00156 
00157   statusLabel->setBuddy( mStatusCombo );
00158   connect( mStatusCombo, SIGNAL( activated( int ) ),
00159            SLOT( updateAttendee() ) );
00160   topLayout->addWidget( mStatusCombo, 2, 1 );
00161 
00162   topLayout->setColStretch( 2, 1 );
00163 
00164   mRsvpButton = new QCheckBox( parent );
00165   QWhatsThis::add( mRsvpButton,
00166            i18n("Edits whether to send an email to the attendee "
00167             "selected in the list above to request "
00168             "a response concerning attendance.") );
00169   mRsvpButton->setText( i18n("Re&quest response") );
00170   connect( mRsvpButton, SIGNAL( clicked() ), SLOT( updateAttendee() ) );
00171   topLayout->addWidget( mRsvpButton, 2, 2 );
00172 
00173   QWidget *buttonBox = new QWidget( parent );
00174   QVBoxLayout *buttonLayout = new QVBoxLayout( buttonBox );
00175 
00176   mAddButton = new QPushButton( i18n("&New"), buttonBox );
00177   QWhatsThis::add( mAddButton,
00178            i18n("Adds a new attendee to the list. Once the "
00179             "attendee is added, you will be able to "
00180             "edit the attendee's name, role, attendance "
00181             "status, and whether or not the attendee is required "
00182             "to respond to the invitation. To select an attendee "
00183             "from your addressbook, click the 'Select Addressee' "
00184             "button instead.") );
00185   buttonLayout->addWidget( mAddButton );
00186   connect( mAddButton, SIGNAL( clicked() ), SLOT( addNewAttendee() ) );
00187 
00188   mRemoveButton = new QPushButton( i18n("&Remove"), buttonBox );
00189   QWhatsThis::add( mRemoveButton,
00190            i18n("Removes the attendee selected in "
00191             "the list above.") );
00192   buttonLayout->addWidget( mRemoveButton );
00193 
00194   mAddressBookButton = new QPushButton( i18n("Select Addressee..."),
00195                                         buttonBox );
00196   QWhatsThis::add( mAddressBookButton,
00197            i18n("Opens your address book, allowing you to select "
00198             "new attendees from it.") );
00199   buttonLayout->addWidget( mAddressBookButton );
00200   connect( mAddressBookButton, SIGNAL( clicked() ), SLOT( openAddressBook() ) );
00201 
00202   topLayout->addMultiCellWidget( buttonBox, 0, 3, 3, 3 );
00203 
00204 #ifdef KORG_NOKABC
00205   mAddressBookButton->hide();
00206 #endif
00207 
00208   connect( &mExpandDistListTimer, SIGNAL(timeout()), SLOT(expandAttendee()) );
00209 }
00210 
00211 void KOAttendeeEditor::openAddressBook()
00212 {
00213 #ifndef KORG_NOKABC
00214   KPIM::AddressesDialog *dia = new KPIM::AddressesDialog( this, "adddialog" );
00215   dia->setShowCC( false );
00216   dia->setShowBCC( false );
00217   if ( dia->exec() ) {
00218     KABC::Addressee::List aList = dia->allToAddressesNoDuplicates();
00219     for ( KABC::Addressee::List::iterator itr = aList.begin();
00220           itr != aList.end(); ++itr ) {
00221       insertAttendeeFromAddressee( (*itr) );
00222     }
00223   }
00224   delete dia;
00225   return;
00226 #endif
00227 }
00228 
00229 void KOAttendeeEditor::insertAttendeeFromAddressee(const KABC::Addressee &a, const Attendee * at)
00230 {
00231   bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() );
00232   bool sameAsOrganizer = mOrganizerCombo &&
00233   KPIM::compareEmail( a.preferredEmail(), mOrganizerCombo->currentText(), false );
00234   KCal::Attendee::PartStat partStat = at? at->status() : KCal::Attendee::NeedsAction;
00235   bool rsvp = at? at->RSVP() : true;
00236 
00237   if ( myself && sameAsOrganizer ) {
00238     partStat = KCal::Attendee::Accepted;
00239     rsvp = false;
00240   }
00241   Attendee *newAt = new Attendee( a.realName(),
00242                                   a.preferredEmail(),
00243                                   !myself, partStat,
00244                                   at ? at->role() : Attendee::ReqParticipant,
00245                                   a.uid() );
00246   newAt->setRSVP( rsvp );
00247   insertAttendee( newAt, true );
00248   mnewAttendees.append( newAt );
00249 }
00250 
00251 void KOAttendeeEditor::fillOrganizerCombo()
00252 {
00253   Q_ASSERT( mOrganizerCombo );
00254   // Get all emails from KOPrefs (coming from various places),
00255   // and insert them - removing duplicates
00256   const QStringList lst = KOPrefs::instance()->fullEmails();
00257   QStringList uniqueList;
00258   for( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
00259     if ( uniqueList.find( *it ) == uniqueList.end() )
00260       uniqueList << *it;
00261   }
00262   mOrganizerCombo->insertStringList( uniqueList );
00263 }
00264 
00265 void KOAttendeeEditor::addNewAttendee()
00266 {
00267   // check if there's still an unchanged example entry, and if so
00268   // suggest to edit that first
00269   if ( QListViewItem* item = hasExampleAttendee() ) {
00270       KMessageBox::information( this,
00271           i18n( "Please edit the example attendee, before adding more." ), QString::null,
00272           "EditExistingExampleAttendeeFirst" );
00273       // make sure the example attendee is selected
00274       item->setSelected( true );
00275       item->listView()->setCurrentItem( item );
00276       return;
00277   }
00278   Attendee *a = new Attendee( i18n("Firstname Lastname"),
00279                               i18n("name") + "@example.net", true );
00280   insertAttendee( a, false );
00281   mnewAttendees.append( a );
00282   updateAttendeeInput();
00283   // We don't want the hint again
00284   mNameEdit->setClickMessage( "" );
00285   mNameEdit->setFocus();
00286   QTimer::singleShot( 0, mNameEdit, SLOT( selectAll() ) );
00287 }
00288 
00289 void KOAttendeeEditor::readEvent(KCal::Incidence * incidence)
00290 {
00291   mdelAttendees.clear();
00292   mnewAttendees.clear();
00293   if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) || incidence->organizer().isEmpty() ) {
00294     if ( !mOrganizerCombo ) {
00295       mOrganizerCombo = new QComboBox( mOrganizerHBox );
00296       fillOrganizerCombo();
00297     }
00298     mOrganizerLabel->setText( i18n( "Identity as organizer:" ) );
00299 
00300     int found = -1;
00301     QString fullOrganizer = incidence->organizer().fullName();
00302     for ( int i = 0 ; i < mOrganizerCombo->count(); ++i ) {
00303       if ( mOrganizerCombo->text( i ) == fullOrganizer ) {
00304         found = i;
00305         mOrganizerCombo->setCurrentItem( i );
00306         break;
00307       }
00308     }
00309     if ( found < 0 ) {
00310       mOrganizerCombo->insertItem( fullOrganizer, 0 );
00311       mOrganizerCombo->setCurrentItem( 0 );
00312     }
00313   } else { // someone else is the organizer
00314     if ( mOrganizerCombo ) {
00315       delete mOrganizerCombo;
00316       mOrganizerCombo = 0;
00317     }
00318     mOrganizerLabel->setText( i18n( "Organizer: %1" ).arg( incidence->organizer().fullName() ) );
00319   }
00320 
00321   Attendee::List al = incidence->attendees();
00322   Attendee::List::ConstIterator it;
00323   Attendee *first = 0;
00324   for( it = al.begin(); it != al.end(); ++it ) {
00325     Attendee *a = new Attendee( **it );
00326     if ( !first ) {
00327       first = a;
00328     }
00329     insertAttendee( a, true );
00330   }
00331 
00332   // Set the initial editing values to the first attendee in the list.
00333   if ( first ) {
00334     // Don't update the item here, the user didn't edit it, so it's not needed.
00335     // Also, AttendeeEditor's subclasses didn't set the current Item at this point
00336     // so if updateAttendee is called now what will happen is that a random item
00337     // will get the text of "first".
00338     mDisableItemUpdate = true;
00339 
00340     setSelected( 0 );
00341     mNameEdit->setText( first->fullName() );
00342     mUid = first->uid();
00343     mRoleCombo->setCurrentItem( first->role() );
00344     if ( first->status() != KCal::Attendee::None ) {
00345       mStatusCombo->setCurrentItem( first->status() );
00346     } else {
00347       mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
00348     }
00349     mRsvpButton->setChecked( first->RSVP() );
00350     mRsvpButton->setEnabled( true );
00351     mDisableItemUpdate = false;
00352   }
00353 }
00354 
00355 void KOAttendeeEditor::writeEvent(KCal::Incidence * incidence)
00356 {
00357   if ( mOrganizerCombo ) {
00358     // TODO: Don't take a string and split it up... Is there a better way?
00359     incidence->setOrganizer( mOrganizerCombo->currentText() );
00360   }
00361 }
00362 
00363 void KOAttendeeEditor::setEnableAttendeeInput(bool enabled)
00364 {
00365   //mNameEdit->setEnabled( enabled );
00366   mRoleCombo->setEnabled( enabled );
00367   mStatusCombo->setEnabled( enabled );
00368   mRsvpButton->setEnabled( enabled );
00369 
00370   mRemoveButton->setEnabled( enabled );
00371 }
00372 
00373 void KOAttendeeEditor::clearAttendeeInput()
00374 {
00375   mNameEdit->setText("");
00376   mUid = QString::null;
00377   mRoleCombo->setCurrentItem(0);
00378   mStatusCombo->setCurrentItem(0);
00379   mRsvpButton->setChecked(true);
00380   setEnableAttendeeInput( false );
00381   mDelegateLabel->setText( QString() );
00382 }
00383 
00384 void KOAttendeeEditor::expandAttendee()
00385 {
00386   mExpandDistListTimer.stop();
00387 
00388   /* When return is pressed mNameEdit emits returnPressed() and then a textChanged() signal.
00389    * The textChanged() signal triggers the updateAttendee() slot to be called which will
00390    * change the wrong Attendee, because after expandAttendee() is executed, the currentItem()
00391    * will be some other Attendee.
00392    * That's why we delay this call with a singleShot
00393    * */
00394   if ( sender() != mNameEdit ) {
00395     KABC::Addressee::List aList = expandDistList( mNameEdit->text() );
00396     KCal::Attendee *current = currentAttendee();
00397     if ( !aList.isEmpty() ) {
00398       for ( KABC::Addressee::List::iterator itr = aList.begin(); itr != aList.end(); ++itr ) {
00399         insertAttendeeFromAddressee( (*itr) );
00400       }
00401       removeAttendee( current );
00402       setSelected( 0 );
00403     }
00404   } else {
00405     // delay this call.
00406     QTimer::singleShot( 0, this, SLOT(expandAttendee()) );
00407   }
00408 }
00409 
00410 void KOAttendeeEditor::updateAttendee()
00411 {
00412   mExpandDistListTimer.stop();
00413 
00414   Attendee *a = currentAttendee();
00415   if ( !a || mDisableItemUpdate )
00416     return;
00417 
00418   QString text = mNameEdit->text();
00419   if ( !mNameEdit->text().startsWith( "\"" ) ) {
00420     // Quote the text as it might contain commas and other quotable chars.
00421     text = KPIM::quoteNameIfNecessary( text );
00422   }
00423 
00424   QString name, email;
00425   if ( KPIM::getNameAndMail( text, name, email ) ) {
00426     name.remove( '"' );
00427     email.remove( '"' ).remove( '>' );
00428   } else {
00429     name = QString();
00430     email = mNameEdit->text();
00431   }
00432 
00433   const bool iAmTheOrganizer = mOrganizerCombo &&
00434     KOPrefs::instance()->thatIsMe( mOrganizerCombo->currentText() );
00435   if ( iAmTheOrganizer ) {
00436     bool myself =
00437       KPIM::compareEmail( email, mOrganizerCombo->currentText(), false );
00438     bool wasMyself =
00439       KPIM::compareEmail( a->email(), mOrganizerCombo->currentText(), false );
00440     if ( myself ) {
00441       mRsvpButton->setChecked( false );
00442       mRsvpButton->setEnabled( false );
00443     } else if ( wasMyself ) {
00444       // this was me, but is no longer, reset
00445       mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
00446       mRsvpButton->setChecked( true );
00447       mRsvpButton->setEnabled( true );
00448     }
00449   }
00450   a->setName( name );
00451   a->setUid( mUid );
00452   a->setEmail( email );
00453   a->setRole( Attendee::Role( mRoleCombo->currentItem() ) );
00454   a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
00455   a->setRSVP( mRsvpButton->isChecked() );
00456 
00457   updateCurrentItem();
00458 
00459   /*
00460    * This editor has dynamic insertion, we don't know when the user finished writting
00461    * the attendee's name. He doesn't press any button when he's done. So how can we
00462    * know when to expand the distlist?
00463    *
00464    * After a 2 seconds without typing, we expand it.
00465    */
00466   mExpandDistListTimer.start( EXPAND_DISTLIST_TIMEOUT, true );
00467 }
00468 
00469 void KOAttendeeEditor::fillAttendeeInput( KCal::Attendee *a )
00470 {
00471   mDisableItemUpdate = true;
00472 
00473   QString tname, temail;
00474   QString username = a->name();
00475   if ( !a->email().isEmpty() ) {
00476     username = KPIM::quoteNameIfNecessary( username );
00477 
00478     KPIM::getNameAndMail( username, tname, temail ); // ignore return value
00479                                                      // which is always false
00480     tname += " <" + a->email() + '>';
00481   }
00482 
00483   bool myself = KOPrefs::instance()->thatIsMe( a->email() );
00484   bool sameAsOrganizer = mOrganizerCombo &&
00485           KPIM::compareEmail( a->email(),
00486                                    mOrganizerCombo->currentText(), false );
00487   KCal::Attendee::PartStat partStat = a->status();
00488   bool rsvp = a->RSVP();
00489 
00490   if ( myself && sameAsOrganizer && a->status() == KCal::Attendee::None ) {
00491       partStat = KCal::Attendee::Accepted;
00492       rsvp = false;
00493   }
00494 
00495   mNameEdit->setText(tname);
00496   mUid = a->uid();
00497   mRoleCombo->setCurrentItem(a->role());
00498   if ( partStat != KCal::Attendee::None ) {
00499     mStatusCombo->setCurrentItem( partStat );
00500   } else {
00501     mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
00502   }
00503   mRsvpButton->setChecked( rsvp );
00504 
00505   mDisableItemUpdate = false;
00506   setEnableAttendeeInput( true );
00507 
00508   if ( a->status() == Attendee::Delegated ) {
00509     if ( !a->delegate().isEmpty() )
00510       mDelegateLabel->setText( i18n( "Delegated to %1" ).arg( a->delegate() ) );
00511     else if ( !a->delegator().isEmpty() )
00512       mDelegateLabel->setText( i18n( "Delegated from %1" ).arg( a->delegator() ) );
00513     else
00514       mDelegateLabel->setText( i18n( "Not delegated" ) );
00515   }
00516   if( myself )
00517     mRsvpButton->setEnabled( false );
00518 
00519 }
00520 
00521 void KOAttendeeEditor::updateAttendeeInput()
00522 {
00523   setEnableAttendeeInput(!mNameEdit->text().isEmpty());
00524   Attendee* a = currentAttendee();
00525   if ( a ) {
00526     fillAttendeeInput( a );
00527   } else {
00528     clearAttendeeInput();
00529   }
00530 }
00531 
00532 void KOAttendeeEditor::cancelAttendeeEvent( KCal::Incidence *incidence )
00533 {
00534   incidence->clearAttendees();
00535 
00536   if ( mdelAttendees.isEmpty() ) {
00537     return;
00538   }
00539 
00540   Attendee *att;
00541   for ( att = mdelAttendees.first(); att; att = mdelAttendees.next() ) {
00542     bool isNewAttendee = false;
00543     if ( !mnewAttendees.isEmpty() ) {
00544       for ( Attendee *newAtt = mnewAttendees.first(); newAtt; newAtt = mnewAttendees.next() ) {
00545         if ( *att == *newAtt ) {
00546           isNewAttendee = true;
00547           break;
00548         }
00549       }
00550     }
00551     if ( !isNewAttendee ) {
00552       incidence->addAttendee( new Attendee( *att ) );
00553     }
00554   }
00555   mdelAttendees.clear();
00556 }
00557 
00558 void KOAttendeeEditor::acceptForMe()
00559 {
00560   changeStatusForMe( Attendee::Accepted );
00561 }
00562 
00563 void KOAttendeeEditor::declineForMe()
00564 {
00565   changeStatusForMe( Attendee::Declined );
00566 }
00567 
00568 bool KOAttendeeEditor::eventFilter(QObject *watched, QEvent *ev)
00569 {
00570   if ( watched && watched == mNameEdit && ev->type() == QEvent::FocusIn &&
00571        currentAttendee() == 0 ) {
00572     addNewAttendee();
00573   }
00574 
00575   return QWidget::eventFilter( watched, ev );
00576 }
00577 
00578 bool KOAttendeeEditor::isExampleAttendee( const KCal::Attendee* attendee ) const
00579 {
00580     if ( !attendee ) return false;
00581     if ( attendee->name() == i18n( "Firstname Lastname" )
00582         && attendee->email().endsWith( "example.net" ) ) {
00583         return true;
00584     }
00585     return false;
00586 }
00587 
00588 KABC::Addressee::List KOAttendeeEditor::expandDistList( const QString &text )  const
00589 {
00590   KABC::Addressee::List aList;
00591   KABC::AddressBook *abook = KABC::StdAddressBook::self( true );
00592 
00593 #ifdef KDEPIM_NEW_DISTRLISTS
00594   const QValueList<KPIM::DistributionList::Entry> eList =
00595     KPIM::DistributionList::findByName( abook, text ).entries( abook );
00596   QValueList<KPIM::DistributionList::Entry>::ConstIterator eit;
00597   for ( eit = eList.begin(); eit != eList.end(); ++eit ) {
00598     KABC::Addressee a = (*eit).addressee;
00599     if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
00600       aList.append( a ) ;
00601     }
00602   }
00603 
00604 #else
00605   KABC::DistributionListManager manager( abook );
00606   manager.load();
00607   const QStringList dList = manager.listNames();
00608   for ( QStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) {
00609     if ( (*it) == text ) {
00610       const QValueList<KABC::DistributionList::Entry> eList = manager.list( *it )->entries();
00611       QValueList<KABC::DistributionList::Entry>::ConstIterator eit;
00612       for ( eit = eList.begin(); eit != eList.end(); ++eit ) {
00613         KABC::Addressee a = (*eit).addressee;
00614         if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
00615           aList.append( a ) ;
00616         }
00617       }
00618     }
00619   }
00620 #endif
00621   return aList;
00622 }
00623 
00624 
00625 #include "koattendeeeditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys