23 #include "koattendeeeditor.h"
25 #include "koglobals.h"
28 #include <tdeabc/addresseedialog.h>
29 #include <libtdepim/addressesdialog.h>
30 #include <libtdepim/addresseelineedit.h>
33 #include <libkcal/incidence.h>
35 #include <libemailfunctions/email.h>
37 #ifdef TDEPIM_NEW_DISTRLISTS
38 #include "distributionlist.h"
40 #include <tdeabc/distributionlist.h>
42 #include <tdeabc/stdaddressbook.h>
44 #include <kiconloader.h>
45 #include <tdelocale.h>
46 #include <tdemessagebox.h>
48 #include <tqcheckbox.h>
49 #include <tqcombobox.h>
53 #include <tqpushbutton.h>
54 #include <tqwhatsthis.h>
58 KOAttendeeEditor::KOAttendeeEditor( TQWidget * parent,
const char *name ) :
59 TQWidget( parent, name ),
60 mDisableItemUpdate( true )
64 void KOAttendeeEditor::initOrganizerWidgets(TQWidget * parent, TQBoxLayout * layout)
66 mOrganizerHBox =
new TQHBox( parent );
67 layout->addWidget( mOrganizerHBox );
73 TQString whatsThis = i18n(
"Sets the identity corresponding to "
74 "the organizer of this to-do or event. "
75 "Identities can be set in the 'Personal' "
76 "section of the KOrganizer configuration, or in the "
77 "'Security & Privacy'->'Password & User Account' "
78 "section of the Trinity Control Center. In addition, "
79 "identities are gathered from your KMail settings "
80 "and from your address book. If you choose "
81 "to set it globally for TDE in the Control Center, "
82 "be sure to check 'Use email settings from "
83 "Control Center' in the 'Personal' section of the "
84 "KOrganizer configuration.");
85 mOrganizerLabel =
new TQLabel( i18n(
"Identity as organizer:" ),
87 mOrganizerCombo =
new TQComboBox( mOrganizerHBox );
88 TQWhatsThis::add( mOrganizerLabel, whatsThis );
89 TQWhatsThis::add( mOrganizerCombo, whatsThis );
91 mOrganizerHBox->setStretchFactor( mOrganizerCombo, 100 );
94 void KOAttendeeEditor::initEditWidgets(TQWidget * parent, TQBoxLayout * layout)
96 TQGridLayout *topLayout =
new TQGridLayout();
97 layout->addLayout( topLayout );
99 TQString whatsThis = i18n(
"Edits the name of the attendee selected in the list "
100 "above, or adds a new attendee if there are no attendees"
102 TQLabel *attendeeLabel =
new TQLabel( parent );
103 TQWhatsThis::add( attendeeLabel, whatsThis );
104 attendeeLabel->setText( i18n(
"Na&me:") );
105 topLayout->addWidget( attendeeLabel, 0, 0 );
107 mNameEdit =
new KPIM::AddresseeLineEdit( parent );
108 TQWhatsThis::add( mNameEdit, whatsThis );
109 mNameEdit->setClickMessage( i18n(
"Click to add a new attendee") );
110 attendeeLabel->setBuddy( mNameEdit );
111 mNameEdit->installEventFilter(
this );
112 connect( mNameEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
113 TQ_SLOT( updateAttendee() ) );
114 connect( mNameEdit, TQ_SIGNAL(returnPressed()), TQ_SLOT(expandAttendee()) );
115 topLayout->addMultiCellWidget( mNameEdit, 0, 0, 1, 2 );
117 whatsThis = i18n(
"Edits the role of the attendee selected "
118 "in the list above.");
119 TQLabel *attendeeRoleLabel =
new TQLabel( parent );
120 TQWhatsThis::add( attendeeRoleLabel, whatsThis );
121 attendeeRoleLabel->setText( i18n(
"Ro&le:") );
122 topLayout->addWidget( attendeeRoleLabel, 1, 0 );
124 mRoleCombo =
new TQComboBox(
false, parent );
125 TQWhatsThis::add( mRoleCombo, whatsThis );
126 mRoleCombo->insertStringList( Attendee::roleList() );
127 attendeeRoleLabel->setBuddy( mRoleCombo );
128 connect( mRoleCombo, TQ_SIGNAL( activated(
int ) ),
129 TQ_SLOT( updateAttendee() ) );
130 topLayout->addWidget( mRoleCombo, 1, 1 );
132 mDelegateLabel =
new TQLabel( parent );
133 topLayout->addWidget( mDelegateLabel, 1, 2 );
135 whatsThis = i18n(
"Edits the current attendance status of the attendee "
136 "selected in the list above.");
137 TQLabel *statusLabel =
new TQLabel( parent );
138 TQWhatsThis::add( statusLabel, whatsThis );
139 statusLabel->setText( i18n(
"Stat&us:") );
140 topLayout->addWidget( statusLabel, 2, 0 );
142 mStatusCombo =
new TQComboBox(
false, parent );
143 TQWhatsThis::add( mStatusCombo, whatsThis );
145 mStatusCombo->insertItem( SmallIcon(
"help" ), Attendee::statusName( Attendee::NeedsAction ) );
146 mStatusCombo->insertItem( KOGlobals::self()->smallIcon(
"ok" ), Attendee::statusName( Attendee::Accepted ) );
147 mStatusCombo->insertItem( KOGlobals::self()->smallIcon(
"no" ), Attendee::statusName( Attendee::Declined ) );
148 mStatusCombo->insertItem( KOGlobals::self()->smallIcon(
"apply" ), Attendee::statusName( Attendee::Tentative ) );
149 mStatusCombo->insertItem( KOGlobals::self()->smallIcon(
"mail-forward" ), Attendee::statusName( Attendee::Delegated ) );
150 mStatusCombo->insertItem( Attendee::statusName( Attendee::Completed ) );
151 mStatusCombo->insertItem( KOGlobals::self()->smallIcon(
"help" ), Attendee::statusName( Attendee::InProcess ) );
153 statusLabel->setBuddy( mStatusCombo );
154 connect( mStatusCombo, TQ_SIGNAL( activated(
int ) ),
155 TQ_SLOT( updateAttendee() ) );
156 topLayout->addWidget( mStatusCombo, 2, 1 );
158 topLayout->setColStretch( 2, 1 );
160 mRsvpButton =
new TQCheckBox( parent );
161 TQWhatsThis::add( mRsvpButton,
162 i18n(
"Edits whether to send an email to the attendee "
163 "selected in the list above to request "
164 "a response concerning attendance.") );
165 mRsvpButton->setText( i18n(
"Re&quest response") );
166 connect( mRsvpButton, TQ_SIGNAL( clicked() ), TQ_SLOT( updateAttendee() ) );
167 topLayout->addWidget( mRsvpButton, 2, 2 );
169 TQWidget *buttonBox =
new TQWidget( parent );
170 TQVBoxLayout *buttonLayout =
new TQVBoxLayout( buttonBox );
172 mAddButton =
new TQPushButton( i18n(
"&New"), buttonBox );
173 TQWhatsThis::add( mAddButton,
174 i18n(
"Adds a new attendee to the list. Once the "
175 "attendee is added, you will be able to "
176 "edit the attendee's name, role, attendance "
177 "status, and whether or not the attendee is required "
178 "to respond to the invitation. To select an attendee "
179 "from your addressbook, click the 'Select Addressee' "
180 "button instead.") );
181 buttonLayout->addWidget( mAddButton );
182 connect( mAddButton, TQ_SIGNAL( clicked() ), TQ_SLOT( addNewAttendee() ) );
184 mRemoveButton =
new TQPushButton( i18n(
"&Remove"), buttonBox );
185 TQWhatsThis::add( mRemoveButton,
186 i18n(
"Removes the attendee selected in "
187 "the list above.") );
188 buttonLayout->addWidget( mRemoveButton );
190 mAddressBookButton =
new TQPushButton( i18n(
"Select Addressee..."),
192 TQWhatsThis::add( mAddressBookButton,
193 i18n(
"Opens your address book, allowing you to select "
194 "new attendees from it.") );
195 buttonLayout->addWidget( mAddressBookButton );
196 connect( mAddressBookButton, TQ_SIGNAL( clicked() ), TQ_SLOT( openAddressBook() ) );
198 topLayout->addMultiCellWidget( buttonBox, 0, 3, 3, 3 );
201 mAddressBookButton->hide();
205 void KOAttendeeEditor::openAddressBook()
208 KPIM::AddressesDialog *dia =
new KPIM::AddressesDialog(
this,
"adddialog" );
209 dia->setShowCC(
false );
210 dia->setShowBCC(
false );
212 TDEABC::Addressee::List aList = dia->allToAddressesNoDuplicates();
213 for ( TDEABC::Addressee::List::iterator itr = aList.begin();
214 itr != aList.end(); ++itr ) {
225 bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() );
226 bool sameAsOrganizer = mOrganizerCombo &&
227 KPIM::compareEmail( a.preferredEmail(), mOrganizerCombo->currentText(),
false );
228 KCal::Attendee::PartStat partStat = at? at->
status() : KCal::Attendee::NeedsAction;
229 bool rsvp = at? at->
RSVP() :
true;
231 if ( myself && sameAsOrganizer ) {
232 partStat = KCal::Attendee::Accepted;
238 at ? at->
role() : Attendee::ReqParticipant,
241 insertAttendee( newAt,
true );
242 mnewAttendees.append( newAt );
245 void KOAttendeeEditor::fillOrganizerCombo()
247 Q_ASSERT( mOrganizerCombo );
250 const TQStringList lst = KOPrefs::instance()->fullEmails();
251 TQStringList uniqueList;
252 for( TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
253 if ( uniqueList.find( *it ) == uniqueList.end() )
256 mOrganizerCombo->insertStringList( uniqueList );
259 void KOAttendeeEditor::addNewAttendee()
263 if ( TQListViewItem* item = hasExampleAttendee() ) {
264 KMessageBox::information(
this,
265 i18n(
"Please edit the example attendee, before adding more." ), TQString(),
266 "EditExistingExampleAttendeeFirst" );
268 item->setSelected(
true );
269 item->listView()->setCurrentItem( item );
273 i18n(
"name") +
"@example.net",
true );
274 insertAttendee( a,
false );
275 mnewAttendees.append( a );
276 updateAttendeeInput();
278 mNameEdit->setClickMessage(
"" );
279 mNameEdit->setFocus();
280 TQTimer::singleShot( 0, mNameEdit, TQ_SLOT( selectAll() ) );
285 mdelAttendees.clear();
286 mnewAttendees.clear();
287 if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) || incidence->organizer().isEmpty() ) {
288 if ( !mOrganizerCombo ) {
289 mOrganizerCombo =
new TQComboBox( mOrganizerHBox );
290 fillOrganizerCombo();
292 mOrganizerLabel->setText( i18n(
"Identity as organizer:" ) );
295 TQString fullOrganizer = incidence->organizer().fullName();
296 for (
int i = 0 ; i < mOrganizerCombo->count(); ++i ) {
297 if ( mOrganizerCombo->text( i ) == fullOrganizer ) {
299 mOrganizerCombo->setCurrentItem( i );
304 mOrganizerCombo->insertItem( fullOrganizer, 0 );
305 mOrganizerCombo->setCurrentItem( 0 );
308 if ( mOrganizerCombo ) {
309 delete mOrganizerCombo;
312 mOrganizerLabel->setText( i18n(
"Organizer: %1" ).arg( incidence->organizer().fullName() ) );
315 Attendee::List al = incidence->
attendees();
316 Attendee::List::ConstIterator it;
318 for( it = al.begin(); it != al.end(); ++it ) {
323 insertAttendee( a,
true );
332 mDisableItemUpdate =
true;
335 mNameEdit->setText( first->fullName() );
337 mRoleCombo->setCurrentItem( first->
role() );
338 if ( first->
status() != KCal::Attendee::None ) {
339 mStatusCombo->setCurrentItem( first->
status() );
341 mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
343 mRsvpButton->setChecked( first->
RSVP() );
344 mRsvpButton->setEnabled(
true );
345 mDisableItemUpdate =
false;
351 if ( mOrganizerCombo ) {
353 incidence->
setOrganizer( mOrganizerCombo->currentText() );
357 void KOAttendeeEditor::setEnableAttendeeInput(
bool enabled)
360 mRoleCombo->setEnabled( enabled );
361 mStatusCombo->setEnabled( enabled );
362 mRsvpButton->setEnabled( enabled );
364 mRemoveButton->setEnabled( enabled );
367 void KOAttendeeEditor::clearAttendeeInput()
369 mNameEdit->setText(
"");
371 mRoleCombo->setCurrentItem(0);
372 mStatusCombo->setCurrentItem(0);
373 mRsvpButton->setChecked(
true);
374 setEnableAttendeeInput(
false );
375 mDelegateLabel->setText( TQString() );
378 void KOAttendeeEditor::expandAttendee()
380 TDEABC::Addressee::List aList = expandDistList( mNameEdit->text() );
381 if ( !aList.isEmpty() ) {
382 int index = selectedIndex();
383 for ( TDEABC::Addressee::List::iterator itr = aList.begin(); itr != aList.end(); ++itr ) {
386 setSelected( index );
387 removeAttendee( currentAttendee() );
391 void KOAttendeeEditor::updateAttendee()
394 if ( !a || mDisableItemUpdate )
397 TQString text = mNameEdit->text();
398 if ( !mNameEdit->text().startsWith(
"\"" ) ) {
400 text = KPIM::quoteNameIfNecessary( text );
403 TQString name, email;
404 if ( KPIM::getNameAndMail( text, name, email ) ) {
406 email.remove(
'"' ).remove(
'>' );
409 email = mNameEdit->text();
412 bool iAmTheOrganizer = mOrganizerCombo &&
413 KOPrefs::instance()->thatIsMe( mOrganizerCombo->currentText() );
414 if ( iAmTheOrganizer ) {
416 KPIM::compareEmail( email, mOrganizerCombo->currentText(),
false );
418 KPIM::compareEmail( a->email(), mOrganizerCombo->currentText(),
false );
420 mRsvpButton->setChecked(
false );
421 mRsvpButton->setEnabled(
false );
422 }
else if ( wasMyself ) {
424 mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
425 mRsvpButton->setChecked(
true );
426 mRsvpButton->setEnabled(
true );
431 a->setEmail( email );
432 a->
setRole( Attendee::Role( mRoleCombo->currentItem() ) );
433 a->
setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
434 a->
setRSVP( mRsvpButton->isChecked() );
441 mDisableItemUpdate =
true;
443 TQString tname, temail;
444 TQString username = a->name();
445 if ( !a->email().isEmpty() ) {
446 username = KPIM::quoteNameIfNecessary( username );
448 KPIM::getNameAndMail( username, tname, temail );
450 tname +=
" <" + a->email() +
'>';
453 bool myself = KOPrefs::instance()->thatIsMe( a->email() );
454 bool sameAsOrganizer = mOrganizerCombo &&
455 KPIM::compareEmail( a->email(),
456 mOrganizerCombo->currentText(),
false );
457 KCal::Attendee::PartStat partStat = a->
status();
458 bool rsvp = a->
RSVP();
460 if ( myself && sameAsOrganizer && a->
status() == KCal::Attendee::None ) {
461 partStat = KCal::Attendee::Accepted;
465 mNameEdit->setText(tname);
467 mRoleCombo->setCurrentItem(a->
role());
468 if ( partStat != KCal::Attendee::None ) {
469 mStatusCombo->setCurrentItem( partStat );
471 mStatusCombo->setCurrentItem( KCal::Attendee::NeedsAction );
473 mRsvpButton->setChecked( rsvp );
475 mDisableItemUpdate =
false;
476 setEnableAttendeeInput(
true );
478 if ( a->
status() == Attendee::Delegated ) {
480 mDelegateLabel->setText( i18n(
"Delegated to %1" ).arg( a->
delegate() ) );
482 mDelegateLabel->setText( i18n(
"Delegated from %1" ).arg( a->
delegator() ) );
484 mDelegateLabel->setText( i18n(
"Not delegated" ) );
487 mRsvpButton->setEnabled(
false );
491 void KOAttendeeEditor::updateAttendeeInput()
493 setEnableAttendeeInput(!mNameEdit->text().isEmpty());
496 fillAttendeeInput( a );
498 clearAttendeeInput();
506 if ( mdelAttendees.isEmpty() ) {
511 for ( att = mdelAttendees.first(); att; att = mdelAttendees.next() ) {
512 bool isNewAttendee =
false;
513 if ( !mnewAttendees.isEmpty() ) {
514 for (
Attendee *newAtt = mnewAttendees.first(); newAtt; newAtt = mnewAttendees.next() ) {
515 if ( *att == *newAtt ) {
516 isNewAttendee =
true;
521 if ( !isNewAttendee ) {
525 mdelAttendees.clear();
528 void KOAttendeeEditor::acceptForMe()
530 changeStatusForMe( Attendee::Accepted );
533 void KOAttendeeEditor::declineForMe()
535 changeStatusForMe( Attendee::Declined );
538 bool KOAttendeeEditor::eventFilter(TQObject *watched, TQEvent *ev)
540 if ( watched && watched == mNameEdit && ev->type() == TQEvent::FocusIn &&
541 currentAttendee() == 0 ) {
545 return TQWidget::eventFilter( watched, ev );
548 bool KOAttendeeEditor::isExampleAttendee(
const KCal::Attendee* attendee )
const
550 if ( !attendee )
return false;
551 if ( attendee->name() == i18n(
"Firstname Lastname" )
552 && attendee->email().endsWith(
"example.net" ) ) {
558 TDEABC::Addressee::List KOAttendeeEditor::expandDistList(
const TQString &text )
const
560 TDEABC::Addressee::List aList;
561 TDEABC::AddressBook *abook = TDEABC::StdAddressBook::self(
true );
563 #ifdef TDEPIM_NEW_DISTRLISTS
564 const TQValueList<KPIM::DistributionList::Entry> eList =
565 KPIM::DistributionList::findByName( abook, text ).entries( abook );
566 TQValueList<KPIM::DistributionList::Entry>::ConstIterator eit;
567 for ( eit = eList.begin(); eit != eList.end(); ++eit ) {
568 TDEABC::Addressee a = (*eit).addressee;
569 if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
575 TDEABC::DistributionListManager manager( abook );
577 const TQStringList dList = manager.listNames();
578 for ( TQStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) {
579 if ( (*it) == text ) {
580 const TQValueList<TDEABC::DistributionList::Entry> eList = manager.list( *it )->entries();
581 TQValueList<TDEABC::DistributionList::Entry>::ConstIterator eit;
582 for ( eit = eList.begin(); eit != eList.end(); ++eit ) {
583 TDEABC::Addressee a = (*eit).addressee;
584 if ( !a.preferredEmail().isEmpty() && aList.find( a ) == aList.end() ) {
595 #include "koattendeeeditor.moc"
void setUid(const TQString &)
TQString delegate() const
TQString delegator() const
void setStatus(PartStat s)
void setOrganizer(const Person &o)
const Attendee::List & attendees() const
void addAttendee(Attendee *attendee, bool doUpdate=true)
void insertAttendeeFromAddressee(const TDEABC::Addressee &a, const KCal::Attendee *at=0)
Reads values from a TDEABC::Addressee and inserts a new Attendee item into the listview with those it...
void cancelAttendeeEvent(KCal::Incidence *incidence)
return a clone of the event with attendees to be canceld