korganizer

koeditordetails.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include "koeditordetails.h"
00027 
00028 #include <qbuttongroup.h>
00029 #include <qcheckbox.h>
00030 #include <qcombobox.h>
00031 #include <qdatetime.h>
00032 #include <qdragobject.h>
00033 #include <qfiledialog.h>
00034 #include <qgroupbox.h>
00035 #include <qlabel.h>
00036 #include <qlayout.h>
00037 #include <qlineedit.h>
00038 #include <qpushbutton.h>
00039 #include <qradiobutton.h>
00040 #include <qregexp.h>
00041 #include <qtooltip.h>
00042 #include <qvbox.h>
00043 #include <qvgroupbox.h>
00044 #include <qwhatsthis.h>
00045 #include <qwidgetstack.h>
00046 #include <qvaluevector.h>
00047 
00048 #include <kdebug.h>
00049 #include <klocale.h>
00050 #include <kiconloader.h>
00051 #include <kmessagebox.h>
00052 #ifndef KORG_NOKABC
00053 #include <kabc/addresseedialog.h>
00054 #include <kabc/vcardconverter.h>
00055 #include <libkdepim/addressesdialog.h>
00056 #include <libkdepim/addresseelineedit.h>
00057 #include <libkdepim/distributionlist.h>
00058 #include <kabc/stdaddressbook.h>
00059 #endif
00060 #include <libkdepim/kvcarddrag.h>
00061 #include <libemailfunctions/email.h>
00062 
00063 #include <libkcal/incidence.h>
00064 
00065 #include "koprefs.h"
00066 #include "koglobals.h"
00067 
00068 #include "koeditorfreebusy.h"
00069 
00070 #include "kocore.h"
00071 
00072 template <>
00073 CustomListViewItem<KCal::Attendee *>::~CustomListViewItem()
00074 {
00075   delete mData;
00076 }
00077 
00078 template <>
00079 void CustomListViewItem<KCal::Attendee *>::updateItem()
00080 {
00081   setText(0,mData->name());
00082   setText(1,mData->email());
00083   setText(2,mData->roleStr());
00084   setText(3,mData->statusStr());
00085   if (mData->RSVP() && !mData->email().isEmpty())
00086     setPixmap(4,KOGlobals::self()->smallIcon("mailappt"));
00087   else
00088     setPixmap(4,KOGlobals::self()->smallIcon("nomailappt"));
00089   setText(5, mData->delegate());
00090   setText(6, mData->delegator());
00091 }
00092 
00093 KOAttendeeListView::KOAttendeeListView ( QWidget *parent, const char *name )
00094   : KListView(parent, name)
00095 {
00096   setAcceptDrops( true );
00097   setAllColumnsShowFocus( true );
00098   setSorting( -1 );
00099 }
00100 
00106 KOAttendeeListView::~KOAttendeeListView()
00107 {
00108 }
00109 
00110 void KOAttendeeListView::contentsDragEnterEvent( QDragEnterEvent *e )
00111 {
00112   dragEnterEvent(e);
00113 }
00114 
00115 void KOAttendeeListView::contentsDragMoveEvent( QDragMoveEvent *e )
00116 {
00117 #ifndef KORG_NODND
00118   if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) {
00119     e->accept();
00120   } else {
00121     e->ignore();
00122   }
00123 #endif
00124 }
00125 
00126 void KOAttendeeListView::dragEnterEvent( QDragEnterEvent *e )
00127 {
00128 #ifndef KORG_NODND
00129   if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) {
00130     e->accept();
00131   } else {
00132     e->ignore();
00133   }
00134 #endif
00135 }
00136 
00137 void KOAttendeeListView::addAttendee( const QString &newAttendee )
00138 {
00139   kdDebug(5850) << " Email: " << newAttendee << endl;
00140   QString name;
00141   QString email;
00142   KPIM::getNameAndMail( newAttendee, name, email );
00143   emit dropped( new Attendee( name, email, true ) );
00144 }
00145 
00146 void KOAttendeeListView::contentsDropEvent( QDropEvent *e )
00147 {
00148   dropEvent(e);
00149 }
00150 
00151 void KOAttendeeListView::dropEvent( QDropEvent *e )
00152 {
00153 #ifndef KORG_NODND
00154   QString text;
00155   QString vcards;
00156 
00157 #ifndef KORG_NOKABC
00158   if ( KVCardDrag::decode( e, vcards ) ) {
00159     KABC::VCardConverter converter;
00160 
00161     KABC::Addressee::List list = converter.parseVCards( vcards );
00162     KABC::Addressee::List::Iterator it;
00163     for ( it = list.begin(); it != list.end(); ++it ) {
00164       QString em( (*it).fullEmail() );
00165       if (em.isEmpty()) {
00166         em=(*it).realName();
00167       }
00168       addAttendee( em );
00169     }
00170   } else
00171 #endif // KORG_NOKABC
00172   if (QTextDrag::decode(e,text)) {
00173     kdDebug(5850) << "Dropped : " << text << endl;
00174     QStringList emails = QStringList::split(",",text);
00175     for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
00176       addAttendee(*it);
00177     }
00178   }
00179 #endif //KORG_NODND
00180 }
00181 
00182 
00183 KOEditorDetails::KOEditorDetails( int spacing, QWidget *parent,
00184                                   const char *name )
00185   : QWidget( parent, name), mDisableItemUpdate( false ), mFreeBusy( 0 )
00186 {
00187   QGridLayout *topLayout = new QGridLayout( this );
00188   topLayout->setSpacing( spacing );
00189 
00190   mOrganizerHBox = new QHBox( this );
00191   // If creating a new event, then the user is the organizer -> show the
00192   // identity combo
00193   // readEvent will delete it and set another label text instead, if the user
00194   // isn't the organizer.
00195   // Note that the i18n text below is duplicated in readEvent
00196   QString whatsThis = i18n("Sets the identity corresponding to "
00197                "the organizer of this to-do or event. "
00198                "Identities can be set in the 'Personal' "
00199                "section of the KOrganizer configuration, or in the "
00200                "'Security & Privacy'->'Password & User Account' "
00201                "section of the KDE Control Center. In addition, "
00202                "identities are gathered from your KMail settings "
00203                "and from your address book. If you choose "
00204                "to set it globally for KDE in the Control Center, "
00205                "be sure to check 'Use email settings from "
00206                "Control Center' in the 'Personal' section of the "
00207                "KOrganizer configuration.");
00208   mOrganizerLabel = new QLabel( i18n( "Identity as organizer:" ),
00209                                 mOrganizerHBox );
00210   mOrganizerCombo = new QComboBox( mOrganizerHBox );
00211   QWhatsThis::add( mOrganizerLabel, whatsThis );
00212   QWhatsThis::add( mOrganizerCombo, whatsThis );
00213   fillOrganizerCombo();
00214   mOrganizerHBox->setStretchFactor( mOrganizerCombo, 100 );
00215 
00216   mListView = new KOAttendeeListView( this, "mListView" );
00217   QWhatsThis::add( mListView,
00218            i18n("Displays information about current attendees. "
00219             "To edit an attendee, select it in this list "
00220             "and modify the values in the area below. "
00221             "Clicking on a column title will sort the list "
00222             "according to that column. The RSVP column "
00223             "indicates whether or not a response is requested "
00224             "from the attendee.") );
00225   mListView->addColumn( i18n("Name"), 200 );
00226   mListView->addColumn( i18n("Email"), 200 );
00227   mListView->addColumn( i18n("Role"), 80 );
00228   mListView->addColumn( i18n("Status"), 100 );
00229   mListView->addColumn( i18n("RSVP"), 55 );
00230   mListView->addColumn( i18n("Delegated to"), 120 );
00231   mListView->addColumn( i18n("Delegated from" ), 120 );
00232   mListView->setResizeMode( QListView::LastColumn );
00233   if ( KOPrefs::instance()->mCompactDialogs ) {
00234     mListView->setFixedHeight( 78 );
00235   }
00236 
00237   connect( mListView, SIGNAL( selectionChanged( QListViewItem * ) ),
00238            SLOT( updateAttendeeInput() ) );
00239 #ifndef KORG_NODND
00240   connect( mListView, SIGNAL( dropped( Attendee * ) ),
00241            SLOT( insertAttendee( Attendee * ) ) );
00242 #endif
00243 
00244   whatsThis = i18n("Edits the name of the attendee selected in the list "
00245            "above, or adds a new attendee if there are no attendees"
00246            "in the list.");
00247   QLabel *attendeeLabel = new QLabel( this );
00248   QWhatsThis::add( attendeeLabel, whatsThis );
00249   attendeeLabel->setText( i18n("Na&me:") );
00250 
00251   mNameEdit = new KPIM::AddresseeLineEdit( this );
00252   QWhatsThis::add( mNameEdit, whatsThis );
00253   mNameEdit->setClickMessage( i18n("Click to add a new attendee") );
00254   attendeeLabel->setBuddy( mNameEdit );
00255   mNameEdit->installEventFilter( this );
00256   connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
00257            SLOT( updateAttendeeItem() ) );
00258 
00259   whatsThis = i18n("Edits the role of the attendee selected "
00260            "in the list above.");
00261   QLabel *attendeeRoleLabel = new QLabel( this );
00262   QWhatsThis::add( attendeeRoleLabel, whatsThis );
00263   attendeeRoleLabel->setText( i18n("Ro&le:") );
00264 
00265   mRoleCombo = new QComboBox( false, this );
00266   QWhatsThis::add( mRoleCombo, whatsThis );
00267   mRoleCombo->insertStringList( Attendee::roleList() );
00268   attendeeRoleLabel->setBuddy( mRoleCombo );
00269   connect( mRoleCombo, SIGNAL( activated( int ) ),
00270            SLOT( updateAttendeeItem() ) );
00271 
00272   whatsThis = i18n("Edits the current attendance status of the attendee "
00273            "selected in the list above.");
00274   QLabel *statusLabel = new QLabel( this );
00275   QWhatsThis::add( statusLabel, whatsThis );
00276   statusLabel->setText( i18n("Stat&us:") );
00277 
00278   mStatusCombo = new QComboBox( false, this );
00279   QWhatsThis::add( mStatusCombo, whatsThis );
00280   mStatusCombo->insertStringList( Attendee::statusList() );
00281   statusLabel->setBuddy( mStatusCombo );
00282   connect( mStatusCombo, SIGNAL( activated( int ) ),
00283            SLOT( updateAttendeeItem() ) );
00284 
00285   mRsvpButton = new QCheckBox( this );
00286   QWhatsThis::add( mRsvpButton,
00287            i18n("Edits whether to send an email to the attendee "
00288             "selected in the list above to request "
00289             "a response concerning attendance.") );
00290   mRsvpButton->setText( i18n("Re&quest response") );
00291   connect( mRsvpButton, SIGNAL( clicked() ), SLOT( updateAttendeeItem() ) );
00292 
00293   QWidget *buttonBox = new QWidget( this );
00294   QVBoxLayout *buttonLayout = new QVBoxLayout( buttonBox );
00295 
00296   QPushButton *newButton = new QPushButton( i18n("&New"), buttonBox );
00297   QWhatsThis::add( newButton,
00298            i18n("Adds a new attendee to the list. Once the "
00299             "attendee is added, you will be able to "
00300             "edit the attendee's name, role, attendance "
00301             "status, and whether or not the attendee is required "
00302             "to respond to the invitation. To select an attendee "
00303             "from your addressbook, click the 'Select Addressee' "
00304             "button instead.") );
00305   buttonLayout->addWidget( newButton );
00306   connect( newButton, SIGNAL( clicked() ), SLOT( addNewAttendee() ) );
00307 
00308   mRemoveButton = new QPushButton( i18n("&Remove"), buttonBox );
00309   QWhatsThis::add( mRemoveButton,
00310            i18n("Removes the attendee selected in "
00311             "the list above.") );
00312   buttonLayout->addWidget( mRemoveButton );
00313   connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeAttendee() ) );
00314 
00315   mAddressBookButton = new QPushButton( i18n("Select Addressee..."),
00316                                         buttonBox );
00317   QWhatsThis::add( mAddressBookButton,
00318            i18n("Opens your address book, allowing you to select "
00319             "new attendees from it.") );
00320   buttonLayout->addWidget( mAddressBookButton );
00321   connect( mAddressBookButton, SIGNAL( clicked() ), SLOT( openAddressBook() ) );
00322 
00323   topLayout->addMultiCellWidget( mOrganizerHBox, 0, 0, 0, 5 );
00324   topLayout->addMultiCellWidget( mListView, 1, 1, 0, 5 );
00325   topLayout->addWidget( attendeeLabel, 2, 0 );
00326   topLayout->addMultiCellWidget( mNameEdit, 2, 2, 1, 1 );
00327 //  topLayout->addWidget( emailLabel, 3, 0 );
00328   topLayout->addWidget( attendeeRoleLabel, 3, 0 );
00329   topLayout->addWidget( mRoleCombo, 3, 1 );
00330 #if 0
00331   topLayout->setColStretch( 2, 1 );
00332   topLayout->addWidget( statusLabel, 3, 3 );
00333   topLayout->addWidget( mStatusCombo, 3, 4 );
00334 #else
00335   topLayout->addWidget( statusLabel, 4, 0 );
00336   topLayout->addWidget( mStatusCombo, 4, 1 );
00337 #endif
00338   topLayout->addMultiCellWidget( mRsvpButton, 5, 5, 0, 1 );
00339   topLayout->addMultiCellWidget( buttonBox, 2, 4, 5, 5 );
00340 
00341 #ifdef KORG_NOKABC
00342   mAddressBookButton->hide();
00343 #endif
00344 
00345   updateAttendeeInput();
00346 }
00347 
00348 KOEditorDetails::~KOEditorDetails()
00349 {
00350 }
00351 
00352 bool KOEditorDetails::hasAttendees()
00353 {
00354   return mListView->childCount() > 0;
00355 }
00356 
00357 bool KOEditorDetails::eventFilter( QObject *watched, QEvent *ev)
00358 {
00359   if ( watched && watched == mNameEdit && ev->type() == QEvent::FocusIn &&
00360        mListView->childCount() == 0 ) {
00361     addNewAttendee();
00362   }
00363 
00364   return QWidget::eventFilter( watched, ev );
00365 }
00366 
00367 void KOEditorDetails::removeAttendee()
00368 {
00369   AttendeeListItem *aItem =
00370       static_cast<AttendeeListItem *>( mListView->selectedItem() );
00371   if ( !aItem ) return;
00372 
00373   Attendee *delA = new Attendee( aItem->data()->name(), aItem->data()->email(),
00374                                  aItem->data()->RSVP(), aItem->data()->status(),
00375                                  aItem->data()->role(), aItem->data()->uid() );
00376   mdelAttendees.append( delA );
00377 
00378   if ( mFreeBusy ) mFreeBusy->removeAttendee( aItem->data() );
00379   delete aItem;
00380 
00381   updateAttendeeInput();
00382 }
00383 
00384 
00385 void KOEditorDetails::openAddressBook()
00386 {
00387 #ifndef KORG_NOKABC
00388   KPIM::AddressesDialog *dia = new KPIM::AddressesDialog( this, "adddialog" );
00389   dia->setShowCC( false );
00390   dia->setShowBCC( false );
00391   if ( dia->exec() ) {
00392     KABC::Addressee::List aList = dia->allToAddressesNoDuplicates();
00393     for ( KABC::Addressee::List::iterator itr = aList.begin();
00394           itr != aList.end(); ++itr ) {
00395       insertAttendeeFromAddressee( (*itr) );
00396     }
00397   }
00398   delete dia;
00399   return;
00400 #if 0
00401     // old code
00402     KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00403     if (!a.isEmpty()) {
00404         // If this is myself, I don't want to get a response but instead
00405         // assume I will be available
00406         bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() );
00407         KCal::Attendee::PartStat partStat =
00408             myself ? KCal::Attendee::Accepted : KCal::Attendee::NeedsAction;
00409         insertAttendee( new Attendee( a.realName(), a.preferredEmail(),
00410                                       !myself, partStat,
00411                                       KCal::Attendee::ReqParticipant, a.uid() ) );
00412     }
00413 #endif
00414 #endif
00415 }
00416 
00417 
00418 void KOEditorDetails::addNewAttendee()
00419 {
00420   Attendee *a = new Attendee( i18n("Firstname Lastname"),
00421                               i18n("name") + "@example.net", true );
00422   insertAttendee( a, false );
00423   // We don't want the hint again
00424   mNameEdit->setClickMessage( "" );
00425   mNameEdit->setFocus();
00426   QTimer::singleShot( 0, mNameEdit, SLOT( selectAll() ) );
00427 }
00428 
00429 
00430 void KOEditorDetails::insertAttendee( Attendee *a )
00431 {
00432   insertAttendee( a, true );
00433 }
00434 
00435 void KOEditorDetails::insertAttendee( Attendee *a, bool goodEmailAddress )
00436 {
00437   // lastItem() is O(n), but for n very small that should be fine
00438   AttendeeListItem *item = new AttendeeListItem( a, mListView,
00439       static_cast<KListViewItem*>( mListView->lastItem() ) );
00440   mListView->setSelected( item, true );
00441   if( mFreeBusy ) mFreeBusy->insertAttendee( a, goodEmailAddress );
00442 }
00443 
00444 void KOEditorDetails::setDefaults()
00445 {
00446   mRsvpButton->setChecked( true );
00447 }
00448 
00449 void KOEditorDetails::readEvent( Incidence *event )
00450 {
00451   // Stop flickering in the free/busy view (not sure if this is necessary)
00452   bool block = false;
00453   if( mFreeBusy ) {
00454     block = mFreeBusy->updateEnabled();
00455     mFreeBusy->setUpdateEnabled( false );
00456     mFreeBusy->clearAttendees();
00457   }
00458 
00459   mListView->clear();
00460   mdelAttendees.clear();
00461   Attendee::List al = event->attendees();
00462   Attendee::List::ConstIterator it;
00463   for( it = al.begin(); it != al.end(); ++it )
00464     insertAttendee( new Attendee( **it ), true );
00465 
00466   mListView->setSelected( mListView->firstChild(), true );
00467 
00468   if ( KOPrefs::instance()->thatIsMe( event->organizer().email() ) ) {
00469     if ( !mOrganizerCombo ) {
00470       mOrganizerCombo = new QComboBox( mOrganizerHBox );
00471       fillOrganizerCombo();
00472     }
00473     mOrganizerLabel->setText( i18n( "Identity as organizer:" ) );
00474 
00475     int found = -1;
00476     QString fullOrganizer = event->organizer().fullName();
00477     for ( int i = 0 ; i < mOrganizerCombo->count(); ++i ) {
00478       if ( mOrganizerCombo->text( i ) == fullOrganizer ) {
00479         found = i;
00480         mOrganizerCombo->setCurrentItem( i );
00481         break;
00482       }
00483     }
00484     if ( found < 0 ) {
00485       mOrganizerCombo->insertItem( fullOrganizer, 0 );
00486       mOrganizerCombo->setCurrentItem( 0 );
00487     }
00488   } else { // someone else is the organizer
00489     if ( mOrganizerCombo ) {
00490       delete mOrganizerCombo;
00491       mOrganizerCombo = 0;
00492     }
00493     mOrganizerLabel->setText( i18n( "Organizer: %1" ).arg( event->organizer().fullName() ) );
00494   }
00495 
00496   // Reinstate free/busy view updates
00497   if( mFreeBusy ) mFreeBusy->setUpdateEnabled( block );
00498 }
00499 
00500 void KOEditorDetails::writeEvent(Incidence *event)
00501 {
00502   event->clearAttendees();
00503   QValueVector<QListViewItem*> toBeDeleted;
00504   QListViewItem *item;
00505   AttendeeListItem *a;
00506   for (item = mListView->firstChild(); item;
00507        item = item->nextSibling()) {
00508     a = (AttendeeListItem *)item;
00509     Attendee *attendee = a->data();
00510     Q_ASSERT( attendee );
00511     /* Check if the attendee is a distribution list and expand it */
00512     if ( attendee->email().isEmpty() ) {
00513       KPIM::DistributionList list = 
00514         KPIM::DistributionList::findByName( KABC::StdAddressBook::self(), attendee->name() );
00515       if ( !list.isEmpty() ) {
00516         toBeDeleted.push_back( item ); // remove it once we are done expanding
00517         KPIM::DistributionList::Entry::List entries = list.entries( KABC::StdAddressBook::self() );
00518         KPIM::DistributionList::Entry::List::Iterator it( entries.begin() );
00519         while ( it != entries.end() ) {
00520           KPIM::DistributionList::Entry &e = ( *it );
00521           ++it;
00522           // this calls insertAttendee, which appends
00523           insertAttendeeFromAddressee( e.addressee, attendee ); 
00524           // TODO: duplicate check, in case it was already added manually
00525         }
00526       }
00527     } else {
00528       bool skip = false;
00529       if ( attendee->email().endsWith( "example.net" ) ) {
00530         if ( KMessageBox::warningYesNo( this, i18n("%1 does not look like a valid email address. "
00531                 "Are you sure you want to invite this participant?").arg( attendee->email() ),
00532               i18n("Invalid email address") ) != KMessageBox::Yes ) {
00533           skip = true;
00534         }
00535       }
00536       if ( !skip ) {
00537         event->addAttendee( new Attendee( *attendee ) );
00538       }
00539     }
00540   }
00541   if ( mOrganizerCombo ) {
00542     // TODO: Don't take a string and split it up... Is there a better way?
00543     event->setOrganizer( mOrganizerCombo->currentText() );
00544   }
00545   // cleanup
00546   QValueVector<QListViewItem*>::iterator it;
00547   for( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
00548     delete *it;
00549   }
00550 }
00551 
00552 void KOEditorDetails::cancelAttendeeEvent(Incidence *event)
00553 {
00554   event->clearAttendees();
00555   Attendee * att;
00556   for (att=mdelAttendees.first();att;att=mdelAttendees.next()) {
00557     event->addAttendee(new Attendee(*att));
00558   }
00559   mdelAttendees.clear();
00560 }
00561 
00562 bool KOEditorDetails::validateInput()
00563 {
00564   return true;
00565 }
00566 
00567 void KOEditorDetails::updateAttendeeInput()
00568 {
00569   setEnableAttendeeInput(!mNameEdit->text().isEmpty());
00570   QListViewItem *item = mListView->selectedItem();
00571   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00572   if (aItem) {
00573     fillAttendeeInput( aItem );
00574   } else {
00575     clearAttendeeInput();
00576   }
00577 }
00578 
00579 void KOEditorDetails::clearAttendeeInput()
00580 {
00581   mNameEdit->setText("");
00582   mUid = QString::null;
00583   mRoleCombo->setCurrentItem(0);
00584   mStatusCombo->setCurrentItem(0);
00585   mRsvpButton->setChecked(true);
00586   setEnableAttendeeInput( false );
00587 }
00588 
00589 void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem )
00590 {
00591   Attendee *a = aItem->data();
00592   mDisableItemUpdate = true;
00593   QString name = a->name();
00594   if (!a->email().isEmpty()) {
00595     name = KPIM::quoteNameIfNecessary( name );
00596     name += " <" + a->email() + ">";
00597   }
00598   mNameEdit->setText(name);
00599   mUid = a->uid();
00600   mRoleCombo->setCurrentItem(a->role());
00601   mStatusCombo->setCurrentItem(a->status());
00602   mRsvpButton->setChecked(a->RSVP());
00603 
00604   mDisableItemUpdate = false;
00605 
00606   setEnableAttendeeInput( true );
00607 }
00608 
00609 void KOEditorDetails::setEnableAttendeeInput( bool enabled )
00610 {
00611   //mNameEdit->setEnabled( enabled );
00612   mRoleCombo->setEnabled( enabled );
00613   mStatusCombo->setEnabled( enabled );
00614   mRsvpButton->setEnabled( enabled );
00615 
00616   mRemoveButton->setEnabled( enabled );
00617 }
00618 
00619 void KOEditorDetails::updateAttendeeItem()
00620 {
00621   if (mDisableItemUpdate) return;
00622 
00623   QListViewItem *item = mListView->selectedItem();
00624   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00625   if ( !aItem ) return;
00626 
00627   Attendee *a = aItem->data();
00628 
00629   QString name;
00630   QString email;
00631   KPIM::getNameAndMail(mNameEdit->text(), name, email);
00632 
00633   bool iAmTheOrganizer = mOrganizerCombo &&
00634     KOPrefs::instance()->thatIsMe( mOrganizerCombo->currentText() );
00635   if ( iAmTheOrganizer ) {
00636     bool myself =
00637       KPIM::compareEmail( email, mOrganizerCombo->currentText(), false );
00638     bool wasMyself =
00639       KPIM::compareEmail( a->email(), mOrganizerCombo->currentText(), false );
00640     if ( myself ) {
00641       mStatusCombo->setCurrentItem( KCal::Attendee::Accepted );
00642       mRsvpButton->setChecked( false );
00643       mRsvpButton->setEnabled( false );
00644     } else if ( wasMyself ) {
00645       // this was me, but is no longer, reset
00646       mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
00647       mRsvpButton->setChecked( true );
00648       mRsvpButton->setEnabled( true );
00649     }
00650   }
00651   a->setName( name );
00652   a->setUid( mUid );
00653   a->setEmail( email );
00654   a->setRole( Attendee::Role( mRoleCombo->currentItem() ) );
00655   a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
00656   a->setRSVP( mRsvpButton->isChecked() );
00657   aItem->updateItem();
00658   if ( mFreeBusy ) mFreeBusy->updateAttendee( a );
00659 }
00660 
00661 void KOEditorDetails::setFreeBusyWidget( KOEditorFreeBusy *v )
00662 {
00663   mFreeBusy = v;
00664 }
00665 
00666 void KOEditorDetails::fillOrganizerCombo()
00667 {
00668   Q_ASSERT( mOrganizerCombo );
00669   // Get all emails from KOPrefs (coming from various places),
00670   // and insert them - removing duplicates
00671   const QStringList lst = KOPrefs::instance()->fullEmails();
00672   QStringList uniqueList;
00673   for( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
00674     if ( uniqueList.find( *it ) == uniqueList.end() )
00675       uniqueList << *it;
00676   }
00677   mOrganizerCombo->insertStringList( uniqueList );
00678 }
00679 
00680 void KOEditorDetails::insertAttendeeFromAddressee( const KABC::Addressee& a,
00681                                                    const Attendee* at )
00682 {
00683   bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() );
00684   bool sameAsOrganizer = mOrganizerCombo &&
00685     KPIM::compareEmail( a.preferredEmail(), mOrganizerCombo->currentText(), false );
00686   KCal::Attendee::PartStat partStat = at? at->status() : KCal::Attendee::NeedsAction;
00687   bool rsvp = at? at->RSVP() : true;
00688   
00689   if ( myself && sameAsOrganizer ) {
00690     partStat = KCal::Attendee::Accepted;
00691     rsvp = false;
00692   }
00693   Attendee *newAt = new Attendee( a.realName(),
00694                                a.preferredEmail(),
00695                                !myself, partStat,
00696                                at ? at->role() : Attendee::ReqParticipant,
00697                                a.uid() );
00698   newAt->setRSVP( rsvp );
00699   insertAttendee( newAt, true );
00700 }
00701 
00702 
00703 #include "koeditordetails.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys