korganizer Library API Documentation

koeditordetails.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qtooltip.h>
00025 #include <qfiledialog.h>
00026 #include <qlayout.h>
00027 #include <qvbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qvgroupbox.h>
00030 #include <qwidgetstack.h>
00031 #include <qdatetime.h>
00032 #include <qdragobject.h>
00033 
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036 #include <kiconloader.h>
00037 #include <kmessagebox.h>
00038 #ifndef KORG_NOKABC
00039 #include <kabc/addresseedialog.h>
00040 #include <kabc/vcardconverter.h>
00041 #endif
00042 #include <libkdepim/kvcarddrag.h>
00043 
00044 #include <libkcal/incidence.h>
00045 
00046 #include "koprefs.h"
00047 #include "koglobals.h"
00048 
00049 #include "koeditorgantt.h"
00050 #include "koeditordetails.h"
00051 #include "koeditordetails.moc"
00052 
00053 template <>
00054 CustomListViewItem<class Attendee *>::~CustomListViewItem()
00055 {
00056   delete mData;
00057 }
00058 
00059 template <>
00060 void CustomListViewItem<class Attendee *>::updateItem()
00061 {
00062   setText(0,mData->name());
00063   setText(1,mData->email());
00064   setText(2,mData->roleStr());
00065   setText(3,mData->statusStr());
00066   if (mData->RSVP() && !mData->email().isEmpty())
00067     setPixmap(4,KOGlobals::self()->smallIcon("mailappt"));
00068   else
00069     setPixmap(4,KOGlobals::self()->smallIcon("nomailappt"));
00070 }
00071 
00072 KOAttendeeListView::KOAttendeeListView (QWidget *parent, const char *name)
00073     : KListView(parent, name)
00074 {
00075   setAcceptDrops(true);
00076 }
00077 
00083 KOAttendeeListView::~KOAttendeeListView()
00084 {
00085 }
00086 
00087 void KOAttendeeListView::contentsDragEnterEvent( QDragEnterEvent *e )
00088 {
00089   dragEnterEvent(e);
00090 }
00091 
00092 void KOAttendeeListView::contentsDragMoveEvent(QDragMoveEvent *e)
00093 {
00094 #ifndef KORG_NODND
00095   if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) {
00096     e->accept();
00097   } else {
00098     e->ignore();
00099   }
00100 #endif
00101 }
00102 void KOAttendeeListView::dragEnterEvent( QDragEnterEvent *e )
00103 {
00104 #ifndef KORG_NODND
00105   if ( KVCardDrag::canDecode( e ) || QTextDrag::canDecode( e ) ) {
00106     e->accept();
00107   } else {
00108     e->ignore();
00109   }
00110 #endif
00111 }
00112 
00113 void KOAttendeeListView::addAttendee(QString newAttendee)
00114 {
00115   kdDebug(5850) << " Email: " << newAttendee << endl;
00116   int pos = newAttendee.find("<");
00117   QString name = newAttendee.left(pos);
00118   QString email = newAttendee.mid(pos);
00119   if (!email.isEmpty()) {
00120     emit dropped(new Attendee(name,email));
00121   } else if (name.contains("@")) {
00122     emit dropped(new Attendee(name, name));
00123   } else
00124     emit dropped(new Attendee(name, QString::null));
00125 }
00126 
00127 void KOAttendeeListView::contentsDropEvent( QDropEvent *e )
00128 {
00129   dropEvent(e);
00130 }
00131 
00132 void KOAttendeeListView::dropEvent( QDropEvent *e )
00133 {
00134 #ifndef KORG_NODND
00135   QString text;
00136   QString vcards;
00137 
00138 #ifndef KORG_NOKABC
00139   if ( KVCardDrag::decode( e, vcards ) ) {
00140     KABC::VCardConverter converter;
00141 
00142     KABC::Addressee::List list = converter.parseVCards( vcards );
00143     KABC::Addressee::List::Iterator it;
00144     for ( it = list.begin(); it != list.end(); ++it ) {
00145       QString em( (*it).fullEmail() );
00146       if (em.isEmpty()) {
00147         em=(*it).realName();
00148       }
00149       addAttendee( em );
00150     }
00151   } else
00152 #endif // KORG_NOKABC
00153   if (QTextDrag::decode(e,text)) {
00154     kdDebug(5850) << "Dropped : " << text << endl;
00155     QStringList emails = QStringList::split(",",text);
00156     for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
00157       addAttendee(*it);
00158     }
00159   }
00160 #endif //KORG_NODND
00161 }
00162 
00163 
00164 KOEditorDetails::KOEditorDetails (int spacing,QWidget* parent,const char* name)
00165   : QWidget( parent, name), mDisableItemUpdate( false ), mGantt( 0 )
00166 {
00167   QGridLayout *topLayout = new QGridLayout(this);
00168   topLayout->setSpacing(spacing);
00169 
00170   QString organizer = KOPrefs::instance()->email();
00171   mOrganizerLabel = new QLabel(i18n("Organizer: %1").arg(organizer),this);
00172 
00173   mListView = new KOAttendeeListView(this,"mListView");
00174   mListView->addColumn(i18n("Name"),180);
00175   mListView->addColumn(i18n("Email"),180);
00176   mListView->addColumn(i18n("Role"),60);
00177   mListView->addColumn(i18n("Status"),100);
00178   mListView->addColumn(i18n("RSVP"),35);
00179   if ( KOPrefs::instance()->mCompactDialogs ) {
00180     mListView->setFixedHeight(78);
00181   }
00182 
00183   connect(mListView,SIGNAL(selectionChanged(QListViewItem *)),
00184           SLOT(updateAttendeeInput()));
00185 #ifndef KORG_NODND
00186   connect(mListView, SIGNAL(dropped( Attendee *)),
00187           SLOT(insertAttendee(Attendee *)));
00188 #endif
00189 
00190   QLabel *attendeeLabel = new QLabel(this);
00191   attendeeLabel->setText(i18n("Na&me:"));
00192 
00193   mNameEdit = new QLineEdit(this);
00194   attendeeLabel->setBuddy( mNameEdit );
00195   connect(mNameEdit,SIGNAL(textChanged(const QString &)),
00196           SLOT(updateAttendeeItem()));
00197 
00198   mUidEdit = new QLineEdit(0);
00199   mUidEdit->setText("");
00200 
00201   QLabel *emailLabel = new QLabel(this);
00202   emailLabel->setText(i18n("&Email:"));
00203 
00204   mEmailEdit = new QLineEdit(this);
00205   emailLabel->setBuddy( mEmailEdit );
00206   connect(mEmailEdit,SIGNAL(textChanged(const QString &)),
00207           SLOT(updateAttendeeItem()));
00208 
00209   QLabel *attendeeRoleLabel = new QLabel(this);
00210   attendeeRoleLabel->setText(i18n("Ro&le:"));
00211 
00212   mRoleCombo = new QComboBox(false,this);
00213   mRoleCombo->insertStringList(Attendee::roleList());
00214   attendeeRoleLabel->setBuddy( mRoleCombo );
00215   connect(mRoleCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00216 
00217   QLabel *statusLabel = new QLabel(this);
00218   statusLabel->setText( i18n("Stat&us:") );
00219 
00220   mStatusCombo = new QComboBox(false,this);
00221   mStatusCombo->insertStringList(Attendee::statusList());
00222   statusLabel->setBuddy( mStatusCombo );
00223   connect(mStatusCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00224 
00225   mRsvpButton = new QCheckBox(this);
00226   mRsvpButton->setText(i18n("Re&quest response"));
00227   connect(mRsvpButton,SIGNAL(clicked()),SLOT(updateAttendeeItem()));
00228 
00229   QWidget *buttonBox = new QWidget(this);
00230   QVBoxLayout *buttonLayout = new QVBoxLayout(buttonBox);
00231 
00232   QPushButton *newButton = new QPushButton(i18n("&New"),buttonBox);
00233   buttonLayout->addWidget(newButton);
00234   connect(newButton,SIGNAL(clicked()),SLOT(addNewAttendee()));
00235 
00236   mRemoveButton = new QPushButton(i18n("&Remove"),buttonBox);
00237   buttonLayout->addWidget(mRemoveButton);
00238   connect(mRemoveButton, SIGNAL(clicked()),SLOT(removeAttendee()));
00239 
00240   mAddressBookButton = new QPushButton(i18n("Select Addressee..."),buttonBox);
00241   buttonLayout->addWidget(mAddressBookButton);
00242   connect(mAddressBookButton,SIGNAL(clicked()),SLOT(openAddressBook()));
00243 
00244   topLayout->addMultiCellWidget(mOrganizerLabel,0,0,0,5);
00245   topLayout->addMultiCellWidget(mListView,1,1,0,5);
00246   topLayout->addWidget(attendeeLabel,2,0);
00247   topLayout->addMultiCellWidget(mNameEdit,2,2,1,1);
00248   topLayout->addWidget(emailLabel,3,0);
00249   topLayout->addMultiCellWidget(mEmailEdit,3,3,1,1);
00250   topLayout->addWidget(attendeeRoleLabel,4,0);
00251   topLayout->addWidget(mRoleCombo,4,1);
00252 #if 0
00253   topLayout->setColStretch(2,1);
00254   topLayout->addWidget(statusLabel,3,3);
00255   topLayout->addWidget(mStatusCombo,3,4);
00256 #else
00257   topLayout->addWidget(statusLabel,5,0);
00258   topLayout->addWidget(mStatusCombo,5,1);
00259 #endif
00260   topLayout->addMultiCellWidget(mRsvpButton,6,6,0,1);
00261   topLayout->addMultiCellWidget(buttonBox,2,5,5,5);
00262 
00263 #ifdef KORG_NOKABC
00264   mAddressBookButton->hide();
00265 #endif
00266 
00267   updateAttendeeInput();
00268 }
00269 
00270 KOEditorDetails::~KOEditorDetails()
00271 {
00272 }
00273 
00274 void KOEditorDetails::removeAttendee()
00275 {
00276   AttendeeListItem *aItem = (AttendeeListItem *)mListView->selectedItem();
00277   if (!aItem) return;
00278 
00279   Attendee *delA = new Attendee(aItem->data()->name(),aItem->data()->email(),
00280     aItem->data()->RSVP(),aItem->data()->status(),aItem->data()->role(),
00281     aItem->data()->uid());
00282   mdelAttendees.append(delA);
00283 
00284   if( mGantt ) mGantt->removeAttendee( aItem->data() );
00285   delete aItem;
00286 
00287   updateAttendeeInput();
00288 }
00289 
00290 
00291 void KOEditorDetails::openAddressBook()
00292 {
00293 #ifndef KORG_NOKABC
00294   KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00295   if (!a.isEmpty()) {
00296     insertAttendee( new Attendee( a.realName(), a.preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,a.uid()) );
00297   }
00298 #endif
00299 }
00300 
00301 
00302 void KOEditorDetails::addNewAttendee()
00303 {
00304 #if 0
00305   // this is cool.  If they didn't enter an email address,
00306   // try to look it up in the address book and fill it in for them.
00307   if (QString(mEmailEdit->text()).stripWhiteSpace().isEmpty()) {
00308     KabAPI addrBook;
00309     QString name;
00310     std::list<AddressBook::Entry> entries;
00311     name = mNameEdit->text();
00312     if (addrBook.init() == AddressBook::NoError) {
00313       if (addrBook.getEntryByName(name, entries, 1) == AddressBook::NoError) {
00314         kdDebug(5850) << "positive match" << endl;
00315         // take first email address
00316         if (!entries.front().emails.isEmpty() &&
00317             entries.front().emails.first().length()>0)
00318           mEmailEdit->setText(entries.front().emails.first());
00319       }
00320     }
00321   }
00322 #endif
00323 
00324   Attendee *a = new Attendee(i18n("(EmptyName)"),i18n("(EmptyEmail)"));
00325   insertAttendee(a);
00326 }
00327 
00328 
00329 void KOEditorDetails::insertAttendee(Attendee *a)
00330 {
00331   AttendeeListItem *item = new AttendeeListItem(a,mListView);
00332   mListView->setSelected( item, true );
00333   if( mGantt ) mGantt->insertAttendee( a );
00334 }
00335 
00336 void KOEditorDetails::setDefaults()
00337 {
00338   mRsvpButton->setChecked(true);
00339 }
00340 
00341 void KOEditorDetails::readEvent(Incidence *event)
00342 {
00343   // Stop flickering in the gantt view (not sure if this is necessary)
00344   bool block;
00345   if( mGantt ) {
00346     block = mGantt->updateEnabled();
00347     mGantt->setUpdateEnabled( false );
00348     mGantt->clearAttendees();
00349   }
00350 
00351   mListView->clear();
00352   mdelAttendees.clear();
00353   Attendee::List al = event->attendees();
00354   Attendee::List::ConstIterator it;
00355   for( it = al.begin(); it != al.end(); ++it )
00356     insertAttendee( new Attendee( **it ) );
00357 
00358   mListView->setSelected( mListView->firstChild(), true );
00359   mOrganizerLabel->setText(i18n("Organizer: %1").arg(event->organizer()));
00360 
00361   // Reinstate Gantt view updates
00362   if( mGantt ) mGantt->setUpdateEnabled( block );
00363 }
00364 
00365 void KOEditorDetails::writeEvent(Incidence *event)
00366 {
00367   event->clearAttendees();
00368   QListViewItem *item;
00369   AttendeeListItem *a;
00370   for (item = mListView->firstChild(); item;
00371        item = item->nextSibling()) {
00372     a = (AttendeeListItem *)item;
00373     event->addAttendee(new Attendee(*(a->data())));
00374   }
00375 }
00376 
00377 void KOEditorDetails::cancelAttendeeEvent(Incidence *event)
00378 {
00379   event->clearAttendees();
00380   Attendee * att;
00381   for (att=mdelAttendees.first();att;att=mdelAttendees.next()) {
00382     event->addAttendee(new Attendee(*att));
00383   }
00384   mdelAttendees.clear();
00385 }
00386 
00387 bool KOEditorDetails::validateInput()
00388 {
00389   return true;
00390 }
00391 
00392 void KOEditorDetails::updateAttendeeInput()
00393 {
00394   QListViewItem *item = mListView->selectedItem();
00395   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00396   if (aItem) {
00397     fillAttendeeInput( aItem );
00398   } else {
00399     clearAttendeeInput();
00400   }
00401 }
00402 
00403 void KOEditorDetails::clearAttendeeInput()
00404 {
00405   mNameEdit->setText("");
00406   mUidEdit->setText("");
00407   mEmailEdit->setText("");
00408   mRoleCombo->setCurrentItem(0);
00409   mStatusCombo->setCurrentItem(0);
00410   mRsvpButton->setChecked(true);
00411   setEnabledAttendeeInput( false );
00412 }
00413 
00414 void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem )
00415 {
00416   Attendee *a = aItem->data();
00417   mDisableItemUpdate = true;
00418   mNameEdit->setText(a->name());
00419   mUidEdit->setText(a->uid());
00420   mEmailEdit->setText(a->email());
00421   mRoleCombo->setCurrentItem(a->role());
00422   mStatusCombo->setCurrentItem(a->status());
00423   mRsvpButton->setChecked(a->RSVP());
00424 
00425   mDisableItemUpdate = false;
00426 
00427   setEnabledAttendeeInput( true );
00428 }
00429 
00430 void KOEditorDetails::setEnabledAttendeeInput( bool enabled )
00431 {
00432   mNameEdit->setEnabled( enabled );
00433   mEmailEdit->setEnabled( enabled );
00434   mRoleCombo->setEnabled( enabled );
00435   mStatusCombo->setEnabled( enabled );
00436   mRsvpButton->setEnabled( enabled );
00437 
00438   mRemoveButton->setEnabled( enabled );
00439 }
00440 
00441 void KOEditorDetails::updateAttendeeItem()
00442 {
00443   if (mDisableItemUpdate) return;
00444 
00445   QListViewItem *item = mListView->selectedItem();
00446   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00447   if ( !aItem ) return;
00448 
00449   Attendee *a = aItem->data();
00450 
00451   a->setName( mNameEdit->text() );
00452   a->setUid( mUidEdit->text() );
00453   a->setEmail( mEmailEdit->text() );
00454   a->setRole( Attendee::Role( mRoleCombo->currentItem() ) );
00455   a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
00456   a->setRSVP( mRsvpButton->isChecked() );
00457   aItem->updateItem();
00458   if( mGantt ) mGantt->updateAttendee( a );
00459 }
00460 
00461 void KOEditorDetails::setGanttWidget( KOEditorGantt* gantt )
00462 {
00463   mGantt = gantt;
00464 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:29 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003