korganizer Library API Documentation

koeditordetails.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include "koeditordetails.h" 00026 00027 #include <qtooltip.h> 00028 #include <qfiledialog.h> 00029 #include <qlayout.h> 00030 #include <qvbox.h> 00031 #include <qbuttongroup.h> 00032 #include <qvgroupbox.h> 00033 #include <qwidgetstack.h> 00034 #include <qdatetime.h> 00035 #include <qdragobject.h> 00036 #include <qcombobox.h> 00037 #include <qlineedit.h> 00038 #include <qlabel.h> 00039 #include <qcheckbox.h> 00040 #include <qpushbutton.h> 00041 #include <qgroupbox.h> 00042 #include <qradiobutton.h> 00043 00044 #include <kdebug.h> 00045 #include <klocale.h> 00046 #include <kiconloader.h> 00047 #include <kmessagebox.h> 00048 #ifndef KORG_NOKABC 00049 #include <kabc/addresseedialog.h> 00050 #include <kabc/vcardconverter.h> 00051 #include <libkdepim/addressesdialog.h> 00052 #include <libkdepim/addresseelineedit.h> 00053 #include <kabc/distributionlist.h> 00054 #include <kabc/stdaddressbook.h> 00055 #endif 00056 #include <libkdepim/kvcarddrag.h> 00057 #include <libkdepim/email.h> 00058 00059 #include <libkcal/incidence.h> 00060 00061 #include "koprefs.h" 00062 #include "koglobals.h" 00063 00064 #include "koeditorfreebusy.h" 00065 00066 #include "kocore.h" 00067 00068 template <> 00069 CustomListViewItem<class Attendee *>::~CustomListViewItem() 00070 { 00071 delete mData; 00072 } 00073 00074 template <> 00075 void CustomListViewItem<class Attendee *>::updateItem() 00076 { 00077 setText(0,mData->name()); 00078 setText(1,mData->email()); 00079 setText(2,mData->roleStr()); 00080 setText(3,mData->statusStr()); 00081 if (mData->RSVP() && !mData->email().isEmpty()) 00082 setPixmap(4,KOGlobals::self()->smallIcon("mailappt")); 00083 else 00084 setPixmap(4,KOGlobals::self()->smallIcon("nomailappt")); 00085 } 00086 00087 KOAttendeeListView::KOAttendeeListView ( QWidget *parent, const char *name ) 00088 : KListView(parent, name) 00089 { 00090 setAcceptDrops( true ); 00091 setAllColumnsShowFocus( true ); 00092 } 00093 00099 KOAttendeeListView::~KOAttendeeListView() 00100 { 00101 } 00102 00103 void KOAttendeeListView::contentsDragEnterEvent( QDragEnterEvent *e ) 00104 { 00105 dragEnterEvent(e); 00106 } 00107 00108 void KOAttendeeListView::contentsDragMoveEvent( QDragMoveEvent *e ) 00109 { 00110 #ifndef KORG_NODND 00111 if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) { 00112 e->accept(); 00113 } else { 00114 e->ignore(); 00115 } 00116 #endif 00117 } 00118 00119 void KOAttendeeListView::dragEnterEvent( QDragEnterEvent *e ) 00120 { 00121 #ifndef KORG_NODND 00122 if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) { 00123 e->accept(); 00124 } else { 00125 e->ignore(); 00126 } 00127 #endif 00128 } 00129 00130 void KOAttendeeListView::addAttendee( const QString &newAttendee ) 00131 { 00132 kdDebug(5850) << " Email: " << newAttendee << endl; 00133 QString name; 00134 QString email; 00135 KPIM::getNameAndMail( newAttendee, name, email ); 00136 emit dropped( new Attendee( name, email ) ); 00137 } 00138 00139 void KOAttendeeListView::contentsDropEvent( QDropEvent *e ) 00140 { 00141 dropEvent(e); 00142 } 00143 00144 void KOAttendeeListView::dropEvent( QDropEvent *e ) 00145 { 00146 #ifndef KORG_NODND 00147 QString text; 00148 QString vcards; 00149 00150 #ifndef KORG_NOKABC 00151 if ( KVCardDrag::decode( e, vcards ) ) { 00152 KABC::VCardConverter converter; 00153 00154 KABC::Addressee::List list = converter.parseVCards( vcards ); 00155 KABC::Addressee::List::Iterator it; 00156 for ( it = list.begin(); it != list.end(); ++it ) { 00157 QString em( (*it).fullEmail() ); 00158 if (em.isEmpty()) { 00159 em=(*it).realName(); 00160 } 00161 addAttendee( em ); 00162 } 00163 } else 00164 #endif // KORG_NOKABC 00165 if (QTextDrag::decode(e,text)) { 00166 kdDebug(5850) << "Dropped : " << text << endl; 00167 QStringList emails = QStringList::split(",",text); 00168 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 00169 addAttendee(*it); 00170 } 00171 } 00172 #endif //KORG_NODND 00173 } 00174 00175 00176 KOEditorDetails::KOEditorDetails( int spacing, QWidget *parent, 00177 const char *name ) 00178 : QWidget( parent, name), mDisableItemUpdate( false ), mFreeBusy( 0 ) 00179 { 00180 QGridLayout *topLayout = new QGridLayout( this ); 00181 topLayout->setSpacing( spacing ); 00182 00183 mOrganizerHBox = new QHBox( this ); 00184 // If creating a new event, then the user is the organizer -> show the 00185 // identity combo 00186 // readEvent will delete it and set another label text instead, if the user 00187 // isn't the organizer. 00188 // Note that the i18n text below is duplicated in readEvent 00189 mOrganizerLabel = new QLabel( i18n( "Identity as organizer:" ), 00190 mOrganizerHBox ); 00191 mOrganizerCombo = new QComboBox( mOrganizerHBox ); 00192 fillOrganizerCombo(); 00193 mOrganizerHBox->setStretchFactor( mOrganizerCombo, 100 ); 00194 00195 mListView = new KOAttendeeListView( this, "mListView" ); 00196 mListView->addColumn( i18n("Name"), 200 ); 00197 mListView->addColumn( i18n("Email"), 200 ); 00198 mListView->addColumn( i18n("Role"), 60 ); 00199 mListView->addColumn( i18n("Status"), 100 ); 00200 mListView->addColumn( i18n("RSVP"), 35 ); 00201 mListView->setResizeMode( QListView::LastColumn ); 00202 if ( KOPrefs::instance()->mCompactDialogs ) { 00203 mListView->setFixedHeight( 78 ); 00204 } 00205 00206 connect( mListView, SIGNAL( selectionChanged( QListViewItem * ) ), 00207 SLOT( updateAttendeeInput() ) ); 00208 #ifndef KORG_NODND 00209 connect( mListView, SIGNAL( dropped( Attendee * ) ), 00210 SLOT( insertAttendee( Attendee * ) ) ); 00211 #endif 00212 00213 QLabel *attendeeLabel = new QLabel( this ); 00214 attendeeLabel->setText( i18n("Na&me:") ); 00215 00216 mNameEdit = new KPIM::AddresseeLineEdit( this ); 00217 mNameEdit->setClickMessage( i18n("Click to add a new attendee") ); 00218 attendeeLabel->setBuddy( mNameEdit ); 00219 mNameEdit->installEventFilter( this ); 00220 connect( mNameEdit, SIGNAL( textChanged( const QString & ) ), 00221 SLOT( updateAttendeeItem() ) ); 00222 00223 mUidEdit = new QLineEdit( 0 ); 00224 mUidEdit->setText( "" ); 00225 00226 QLabel *attendeeRoleLabel = new QLabel( this ); 00227 attendeeRoleLabel->setText( i18n("Ro&le:") ); 00228 00229 mRoleCombo = new QComboBox( false, this ); 00230 mRoleCombo->insertStringList( Attendee::roleList() ); 00231 attendeeRoleLabel->setBuddy( mRoleCombo ); 00232 connect( mRoleCombo, SIGNAL( activated( int ) ), 00233 SLOT( updateAttendeeItem() ) ); 00234 00235 QLabel *statusLabel = new QLabel( this ); 00236 statusLabel->setText( i18n("Stat&us:") ); 00237 00238 mStatusCombo = new QComboBox( false, this ); 00239 mStatusCombo->insertStringList( Attendee::statusList() ); 00240 statusLabel->setBuddy( mStatusCombo ); 00241 connect( mStatusCombo, SIGNAL( activated( int ) ), 00242 SLOT( updateAttendeeItem() ) ); 00243 00244 mRsvpButton = new QCheckBox( this ); 00245 mRsvpButton->setText( i18n("Re&quest response") ); 00246 connect( mRsvpButton, SIGNAL( clicked() ), SLOT( updateAttendeeItem() ) ); 00247 00248 QWidget *buttonBox = new QWidget( this ); 00249 QVBoxLayout *buttonLayout = new QVBoxLayout( buttonBox ); 00250 00251 QPushButton *newButton = new QPushButton( i18n("&New"), buttonBox ); 00252 buttonLayout->addWidget( newButton ); 00253 connect( newButton, SIGNAL( clicked() ), SLOT( addNewAttendee() ) ); 00254 00255 mRemoveButton = new QPushButton( i18n("&Remove"), buttonBox ); 00256 buttonLayout->addWidget( mRemoveButton ); 00257 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeAttendee() ) ); 00258 00259 mAddressBookButton = new QPushButton( i18n("Select Addressee..."), 00260 buttonBox ); 00261 buttonLayout->addWidget( mAddressBookButton ); 00262 connect( mAddressBookButton, SIGNAL( clicked() ), SLOT( openAddressBook() ) ); 00263 00264 topLayout->addMultiCellWidget( mOrganizerHBox, 0, 0, 0, 5 ); 00265 topLayout->addMultiCellWidget( mListView, 1, 1, 0, 5 ); 00266 topLayout->addWidget( attendeeLabel, 2, 0 ); 00267 topLayout->addMultiCellWidget( mNameEdit, 2, 2, 1, 1 ); 00268 // topLayout->addWidget( emailLabel, 3, 0 ); 00269 topLayout->addWidget( attendeeRoleLabel, 3, 0 ); 00270 topLayout->addWidget( mRoleCombo, 3, 1 ); 00271 #if 0 00272 topLayout->setColStretch( 2, 1 ); 00273 topLayout->addWidget( statusLabel, 3, 3 ); 00274 topLayout->addWidget( mStatusCombo, 3, 4 ); 00275 #else 00276 topLayout->addWidget( statusLabel, 4, 0 ); 00277 topLayout->addWidget( mStatusCombo, 4, 1 ); 00278 #endif 00279 topLayout->addMultiCellWidget( mRsvpButton, 5, 5, 0, 1 ); 00280 topLayout->addMultiCellWidget( buttonBox, 2, 4, 5, 5 ); 00281 00282 #ifdef KORG_NOKABC 00283 mAddressBookButton->hide(); 00284 #endif 00285 00286 updateAttendeeInput(); 00287 } 00288 00289 KOEditorDetails::~KOEditorDetails() 00290 { 00291 } 00292 00293 bool KOEditorDetails::eventFilter( QObject *watched, QEvent *ev) 00294 { 00295 if ( watched && watched == mNameEdit && ev->type() == QEvent::FocusIn && 00296 mListView->childCount() == 0 ) { 00297 addNewAttendee(); 00298 } 00299 00300 return QWidget::eventFilter( watched, ev ); 00301 } 00302 00303 void KOEditorDetails::removeAttendee() 00304 { 00305 AttendeeListItem *aItem = 00306 static_cast<AttendeeListItem *>( mListView->selectedItem() ); 00307 if ( !aItem ) return; 00308 00309 Attendee *delA = new Attendee( aItem->data()->name(), aItem->data()->email(), 00310 aItem->data()->RSVP(), aItem->data()->status(), 00311 aItem->data()->role(), aItem->data()->uid() ); 00312 mdelAttendees.append( delA ); 00313 00314 if ( mFreeBusy ) mFreeBusy->removeAttendee( aItem->data() ); 00315 delete aItem; 00316 00317 updateAttendeeInput(); 00318 } 00319 00320 00321 void KOEditorDetails::openAddressBook() 00322 { 00323 #ifndef KORG_NOKABC 00324 KPIM::AddressesDialog *dia = new KPIM::AddressesDialog( this, "adddialog" ); 00325 dia->setShowCC( false ); 00326 dia->setShowBCC( false ); 00327 if ( dia->exec() ) { 00328 KABC::Addressee::List aList = dia->allToAddressesNoDuplicates(); 00329 for ( KABC::Addressee::List::iterator itr = aList.begin(); 00330 itr != aList.end(); ++itr ) { 00331 KABC::Addressee a = (*itr); 00332 bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() ); 00333 KCal::Attendee::PartStat partStat; 00334 if ( myself ) partStat = KCal::Attendee::Accepted; 00335 else partStat = KCal::Attendee::NeedsAction; 00336 insertAttendee( new Attendee( a.realName(), a.preferredEmail(), 00337 !myself, partStat, 00338 KCal::Attendee::ReqParticipant, a.uid() ) ); 00339 } 00340 } 00341 delete dia; 00342 return; 00343 #if 0 00344 // old code 00345 KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this); 00346 if (!a.isEmpty()) { 00347 // If this is myself, I don't want to get a response but instead 00348 // assume I will be available 00349 bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() ); 00350 KCal::Attendee::PartStat partStat = 00351 myself ? KCal::Attendee::Accepted : KCal::Attendee::NeedsAction; 00352 insertAttendee( new Attendee( a.realName(), a.preferredEmail(), 00353 !myself, partStat, 00354 KCal::Attendee::ReqParticipant, a.uid() ) ); 00355 } 00356 #endif 00357 #endif 00358 } 00359 00360 00361 void KOEditorDetails::addNewAttendee() 00362 { 00363 Attendee *a = new Attendee( i18n("Firstname Lastname"), 00364 i18n("name@domain.com") ); 00365 insertAttendee( a ); 00366 // We don't want the hint again 00367 mNameEdit->setClickMessage( "" ); 00368 mNameEdit->setFocus(); 00369 QTimer::singleShot( 0, mNameEdit, SLOT( selectAll() ) ); 00370 } 00371 00372 00373 void KOEditorDetails::insertAttendee( Attendee *a ) 00374 { 00375 AttendeeListItem *item = new AttendeeListItem( a, mListView ); 00376 mListView->setSelected( item, true ); 00377 if( mFreeBusy ) mFreeBusy->insertAttendee( a ); 00378 } 00379 00380 void KOEditorDetails::setDefaults() 00381 { 00382 mRsvpButton->setChecked( true ); 00383 } 00384 00385 void KOEditorDetails::readEvent( Incidence *event ) 00386 { 00387 // Stop flickering in the free/busy view (not sure if this is necessary) 00388 bool block = false; 00389 if( mFreeBusy ) { 00390 block = mFreeBusy->updateEnabled(); 00391 mFreeBusy->setUpdateEnabled( false ); 00392 mFreeBusy->clearAttendees(); 00393 } 00394 00395 mListView->clear(); 00396 mdelAttendees.clear(); 00397 Attendee::List al = event->attendees(); 00398 Attendee::List::ConstIterator it; 00399 for( it = al.begin(); it != al.end(); ++it ) 00400 insertAttendee( new Attendee( **it ) ); 00401 00402 mListView->setSelected( mListView->firstChild(), true ); 00403 00404 if ( KOPrefs::instance()->thatIsMe( event->organizer() ) ) { 00405 if ( !mOrganizerCombo ) { 00406 mOrganizerCombo = new QComboBox( mOrganizerHBox ); 00407 fillOrganizerCombo(); 00408 } 00409 mOrganizerLabel->setText( i18n( "Identity as organizer:" ) ); 00410 00411 // This might not be enough, if the combo as a full name too, hence the loop below 00412 // mOrganizerCombo->setCurrentText( event->organizer() ); 00413 for ( int i = 0 ; i < mOrganizerCombo->count(); ++i ) { 00414 QString itemTxt = KPIM::getEmailAddr( mOrganizerCombo->text( i ) ); 00415 if ( event->organizer() == itemTxt ) { 00416 mOrganizerCombo->setCurrentItem( i ); 00417 break; 00418 } 00419 } 00420 } else { // someone else is the organizer 00421 if ( mOrganizerCombo ) { 00422 delete mOrganizerCombo; 00423 mOrganizerCombo = 0; 00424 } 00425 mOrganizerLabel->setText( i18n( "Organizer: %1" ).arg( event->organizer() ) ); 00426 } 00427 00428 // Reinstate free/busy view updates 00429 if( mFreeBusy ) mFreeBusy->setUpdateEnabled( block ); 00430 } 00431 00432 void KOEditorDetails::writeEvent(Incidence *event) 00433 { 00434 event->clearAttendees(); 00435 QListViewItem *item; 00436 AttendeeListItem *a; 00437 for (item = mListView->firstChild(); item; 00438 item = item->nextSibling()) { 00439 a = (AttendeeListItem *)item; 00440 event->addAttendee(new Attendee(*(a->data()))); 00441 } 00442 if ( mOrganizerCombo ) { 00443 event->setOrganizer( mOrganizerCombo->currentText() ); 00444 } 00445 } 00446 00447 void KOEditorDetails::cancelAttendeeEvent(Incidence *event) 00448 { 00449 event->clearAttendees(); 00450 Attendee * att; 00451 for (att=mdelAttendees.first();att;att=mdelAttendees.next()) { 00452 event->addAttendee(new Attendee(*att)); 00453 } 00454 mdelAttendees.clear(); 00455 } 00456 00457 bool KOEditorDetails::validateInput() 00458 { 00459 return true; 00460 } 00461 00462 void KOEditorDetails::updateAttendeeInput() 00463 { 00464 00465 setEnableAttendeeInput(!mNameEdit->text().isEmpty()); 00466 QListViewItem *item = mListView->selectedItem(); 00467 AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item ); 00468 if (aItem) { 00469 fillAttendeeInput( aItem ); 00470 } else { 00471 clearAttendeeInput(); 00472 } 00473 } 00474 00475 void KOEditorDetails::clearAttendeeInput() 00476 { 00477 mNameEdit->setText(""); 00478 mUidEdit->setText(""); 00479 mRoleCombo->setCurrentItem(0); 00480 mStatusCombo->setCurrentItem(0); 00481 mRsvpButton->setChecked(true); 00482 setEnableAttendeeInput( false ); 00483 } 00484 00485 void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem ) 00486 { 00487 Attendee *a = aItem->data(); 00488 mDisableItemUpdate = true; 00489 QString name = a->name(); 00490 if (!a->email().isEmpty()) 00491 name += " <" + a->email() + ">"; 00492 mNameEdit->setText(name); 00493 mUidEdit->setText(a->uid()); 00494 mRoleCombo->setCurrentItem(a->role()); 00495 mStatusCombo->setCurrentItem(a->status()); 00496 mRsvpButton->setChecked(a->RSVP()); 00497 00498 mDisableItemUpdate = false; 00499 00500 setEnableAttendeeInput( true ); 00501 } 00502 00503 void KOEditorDetails::setEnableAttendeeInput( bool enabled ) 00504 { 00505 //mNameEdit->setEnabled( enabled ); 00506 mRoleCombo->setEnabled( enabled ); 00507 mStatusCombo->setEnabled( enabled ); 00508 mRsvpButton->setEnabled( enabled ); 00509 00510 mRemoveButton->setEnabled( enabled ); 00511 } 00512 00513 void KOEditorDetails::updateAttendeeItem() 00514 { 00515 if (mDisableItemUpdate) return; 00516 00517 QListViewItem *item = mListView->selectedItem(); 00518 AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item ); 00519 if ( !aItem ) return; 00520 00521 Attendee *a = aItem->data(); 00522 00523 QString name; 00524 QString email; 00525 KPIM::getNameAndMail(mNameEdit->text(), name, email); 00526 a->setName( name ); 00527 a->setUid( mUidEdit->text() ); 00528 a->setEmail( email ); 00529 a->setRole( Attendee::Role( mRoleCombo->currentItem() ) ); 00530 a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) ); 00531 a->setRSVP( mRsvpButton->isChecked() ); 00532 aItem->updateItem(); 00533 if ( mFreeBusy ) mFreeBusy->updateAttendee( a ); 00534 } 00535 00536 void KOEditorDetails::setFreeBusyWidget( KOEditorFreeBusy *v ) 00537 { 00538 mFreeBusy = v; 00539 } 00540 00541 void KOEditorDetails::fillOrganizerCombo() 00542 { 00543 Q_ASSERT( mOrganizerCombo ); 00544 // Get all emails from KOPrefs (coming from various places), 00545 // and insert them - removing duplicates 00546 const QStringList lst = KOPrefs::instance()->allEmails(); 00547 QStringList uniqueList; 00548 for( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { 00549 if ( uniqueList.find( *it ) == uniqueList.end() ) 00550 uniqueList << *it; 00551 } 00552 mOrganizerCombo->insertStringList( uniqueList ); 00553 } 00554 00555 #include "koeditordetails.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:22 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003