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("@")) {
    emit dropped(new Attendee(name, name));
  } else
    emit dropped(new Attendee(name, QString::null));
}

void KOAttendeeListView::contentsDropEvent( QDropEvent *e )
{
  dropEvent(e);
}

void KOAttendeeListView::dropEvent( QDropEvent *e )
{
#ifndef KORG_NODND
  QString text;
  QString vcards;

#ifndef KORG_NOKABC
  if ( KVCardDrag::decode( e, vcards ) ) {
    KABC::VCardConverter converter;

    KABC::Addressee::List list = converter.parseVCards( vcards );
    KABC::Addressee::List::Iterator it;
    for ( it = list.begin(); it != list.end(); ++it ) {
      QString em( (*it).fullEmail() );
      if (em.isEmpty()) {
        em=(*it).realName();
      }
      addAttendee( em );
    }
  } else
#endif // KORG_NOKABC
  if (QTextDrag::decode(e,text)) {
    kdDebug(5850) << "Dropped : " << text << endl;
00122     QStringList emails = QStringList::split(",",text);
00123     for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
00124       addAttendee(*it);
00125     }
00126   }
00127 #endif //KORG_NODND
00128 }
00129 
00130 
00131 KOEditorDetails::KOEditorDetails (int spacing,QWidget* parent,const char* name)
00132   : QWidget( parent, name), mDisableItemUpdate( false ), mGantt( 0 )
00133 {
00134   QGridLayout *topLayout = new QGridLayout(this);
00135   topLayout->setSpacing(spacing);
00136 
00137   QString organizer = KOPrefs::instance()->email();
00138   mOrganizerLabel = new QLabel(i18n("Organizer: %1").arg(organizer),this);
00139 
00140   mListView = new KOAttendeeListView(this,"mListView");
00141   mListView->addColumn(i18n("Name"),180);
00142   mListView->addColumn(i18n("Email"),180);
00143   mListView->addColumn(i18n("Role"),60);
00144   mListView->addColumn(i18n("Status"),100);
00145   mListView->addColumn(i18n("RSVP"),35);
00146   if ( KOPrefs::instance()->mCompactDialogs ) {
00147     mListView->setFixedHeight(78);
00148   }
00149 
00150   connect(mListView,SIGNAL(selectionChanged(QListViewItem *)),
00151           SLOT(updateAttendeeInput()));
00152 #ifndef KORG_NODND
00153   connect(mListView, SIGNAL(dropped( Attendee *)),
00154           SLOT(insertAttendee(Attendee *)));
00155 #endif
00156 
00157   QLabel *attendeeLabel = new QLabel(this);
00158   attendeeLabel->setText(i18n("Na&me:"));
00159 
00160   mNameEdit = new QLineEdit(this);
00161   attendeeLabel->setBuddy( mNameEdit );
00162   connect(mNameEdit,SIGNAL(textChanged(const QString &)),
00163           SLOT(updateAttendeeItem()));
00164 
00165   mUidEdit = new QLineEdit(0);
00166   mUidEdit->setText("");
00167 
00168   QLabel *emailLabel = new QLabel(this);
00169   emailLabel->setText(i18n("&Email:"));
00170 
00171   mEmailEdit = new QLineEdit(this);
00172   emailLabel->setBuddy( mEmailEdit );
00173   connect(mEmailEdit,SIGNAL(textChanged(const QString &)),
00174           SLOT(updateAttendeeItem()));
00175 
00176   QLabel *attendeeRoleLabel = new QLabel(this);
00177   attendeeRoleLabel->setText(i18n("Ro&le:"));
00178 
00179   mRoleCombo = new QComboBox(false,this);
00180   mRoleCombo->insertStringList(Attendee::roleList());
00181   attendeeRoleLabel->setBuddy( mRoleCombo );
00182   connect(mRoleCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00183 
00184   QLabel *statusLabel = new QLabel(this);
00185   statusLabel->setText( i18n("Stat&us:") );
00186 
00187   mStatusCombo = new QComboBox(false,this);
00188   mStatusCombo->insertStringList(Attendee::statusList());
00189   statusLabel->setBuddy( mStatusCombo );
00190   connect(mStatusCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00191 
00192   mRsvpButton = new QCheckBox(this);
00193   mRsvpButton->setText(i18n("Re&quest response"));
00194   connect(mRsvpButton,SIGNAL(clicked()),SLOT(updateAttendeeItem()));
00195 
00196   QWidget *buttonBox = new QWidget(this);
00197   QVBoxLayout *buttonLayout = new QVBoxLayout(buttonBox);
00198 
00199   QPushButton *newButton = new QPushButton(i18n("&New"),buttonBox);
00200   buttonLayout->addWidget(newButton);
00201   connect(newButton,SIGNAL(clicked()),SLOT(addNewAttendee()));
00202 
00203   mRemoveButton = new QPushButton(i18n("&Remove"),buttonBox);
00204   buttonLayout->addWidget(mRemoveButton);
00205   connect(mRemoveButton, SIGNAL(clicked()),SLOT(removeAttendee()));
00206 
00207   mAddressBookButton = new QPushButton(i18n("Select Addressee..."),buttonBox);
00208   buttonLayout->addWidget(mAddressBookButton);
00209   connect(mAddressBookButton,SIGNAL(clicked()),SLOT(openAddressBook()));
00210 
00211   topLayout->addMultiCellWidget(mOrganizerLabel,0,0,0,5);
00212   topLayout->addMultiCellWidget(mListView,1,1,0,5);
00213   topLayout->addWidget(attendeeLabel,2,0);
00214   topLayout->addMultiCellWidget(mNameEdit,2,2,1,1);
00215   topLayout->addWidget(emailLabel,3,0);
00216   topLayout->addMultiCellWidget(mEmailEdit,3,3,1,1);
00217   topLayout->addWidget(attendeeRoleLabel,4,0);
00218   topLayout->addWidget(mRoleCombo,4,1);
00219 #if 0
00220   topLayout->setColStretch(2,1);
00221   topLayout->addWidget(statusLabel,3,3);
00222   topLayout->addWidget(mStatusCombo,3,4);
00223 #else
00224   topLayout->addWidget(statusLabel,5,0);
00225   topLayout->addWidget(mStatusCombo,5,1);
00226 #endif
00227   topLayout->addMultiCellWidget(mRsvpButton,6,6,0,1);
00228   topLayout->addMultiCellWidget(buttonBox,2,5,5,5);
00229 
00230 #ifdef KORG_NOKABC
00231   mAddressBookButton->hide();
00232 #endif
00233 
00234   updateAttendeeInput();
00235 }
00236 
00237 KOEditorDetails::~KOEditorDetails()
00238 {
00239 }
00240 
00241 void KOEditorDetails::removeAttendee()
00242 {
00243   AttendeeListItem *aItem = (AttendeeListItem *)mListView->selectedItem();
00244   if (!aItem) return;
00245 
00246   Attendee *delA = new Attendee(aItem->data()->name(),aItem->data()->email(),
00247     aItem->data()->RSVP(),aItem->data()->status(),aItem->data()->role(),
00248     aItem->data()->uid());
00249   mdelAttendees.append(delA);
00250 
00251   if( mGantt ) mGantt->removeAttendee( aItem->data() );
00252   delete aItem;
00253 
00254   updateAttendeeInput();
00255 }
00256 
00257 
00258 void KOEditorDetails::openAddressBook()
00259 {
00260 #ifndef KORG_NOKABC
00261   KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00262   if (!a.isEmpty()) {
00263     insertAttendee( new Attendee( a.realName(), a.preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,a.uid()) );
00264   }
00265 #endif
00266 }
00267 
00268 
00269 void KOEditorDetails::addNewAttendee()
00270 {
00271 #if 0
00272   // this is cool.  If they didn't enter an email address,
00273   // try to look it up in the address book and fill it in for them.
00274   if (QString(mEmailEdit->text()).stripWhiteSpace().isEmpty()) {
00275     KabAPI addrBook;
00276     QString name;
00277     std::list<AddressBook::Entry> entries;
00278     name = mNameEdit->text();
00279     if (addrBook.init() == AddressBook::NoError) {
00280       if (addrBook.getEntryByName(name, entries, 1) == AddressBook::NoError) {
00281         kdDebug(5850) << "positive match" << endl;
00282         // take first email address
00283         if (!entries.front().emails.isEmpty() &&
00284             entries.front().emails.first().length()>0)
00285           mEmailEdit->setText(entries.front().emails.first());
00286       }
00287     }
00288   }
00289 #endif
00290 
00291   Attendee *a = new Attendee(i18n("(EmptyName)"),i18n("(EmptyEmail)"));
00292   insertAttendee(a);
00293 }
00294 
00295 
00296 void KOEditorDetails::insertAttendee(Attendee *a)
00297 {
00298   AttendeeListItem *item = new AttendeeListItem(a,mListView);
00299   mListView->setSelected( item, true );
00300   if( mGantt ) mGantt->insertAttendee( a );
00301 }
00302 
00303 void KOEditorDetails::setDefaults()
00304 {
00305   mRsvpButton->setChecked(true);
00306 }
00307 
00308 void KOEditorDetails::readEvent(Incidence *event)
00309 {
00310   // Stop flickering in the gantt view (not sure if this is necessary)
00311   bool block;
00312   if( mGantt ) {
00313     block = mGantt->updateEnabled();
00314     mGantt->setUpdateEnabled( false );
00315     mGantt->clearAttendees();
00316   }
00317 
00318   mListView->clear();
00319   mdelAttendees.clear();
00320   Attendee::List al = event->attendees();
00321   Attendee::List::ConstIterator it;
00322   for( it = al.begin(); it != al.end(); ++it )
00323     insertAttendee( new Attendee( **it ) );
00324 
00325   mListView->setSelected( mListView->firstChild(), true );
00326   mOrganizerLabel->setText(i18n("Organizer: %1").arg(event->organizer()));
00327 
00328   // Reinstate Gantt view updates
00329   if( mGantt ) mGantt->setUpdateEnabled( block );
00330 }
00331 
00332 void KOEditorDetails::writeEvent(Incidence *event)
00333 {
00334   event->clearAttendees();
00335   QListViewItem *item;
00336   AttendeeListItem *a;
00337   for (item = mListView->firstChild(); item;
00338        item = item->nextSibling()) {
00339     a = (AttendeeListItem *)item;
00340     event->addAttendee(new Attendee(*(a->data())));
00341   }
00342 }
00343 
00344 void KOEditorDetails::cancelAttendeeEvent(Incidence *event)
00345 {
00346   event->clearAttendees();
00347   Attendee * att;
00348   for (att=mdelAttendees.first();att;att=mdelAttendees.next()) {
00349     event->addAttendee(new Attendee(*att));
00350   }
00351   mdelAttendees.clear();
00352 }
00353 
00354 bool KOEditorDetails::validateInput()
00355 {
00356   return true;
00357 }
00358 
00359 void KOEditorDetails::updateAttendeeInput()
00360 {
00361   QListViewItem *item = mListView->selectedItem();
00362   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00363   if (aItem) {
00364     fillAttendeeInput( aItem );
00365   } else {
00366     clearAttendeeInput();
00367   }
00368 }
00369 
00370 void KOEditorDetails::clearAttendeeInput()
00371 {
00372   mNameEdit->setText("");
00373   mUidEdit->setText("");
00374   mEmailEdit->setText("");
00375   mRoleCombo->setCurrentItem(0);
00376   mStatusCombo->setCurrentItem(0);
00377   mRsvpButton->setChecked(true);
00378   setEnabledAttendeeInput( false );
00379 }
00380 
00381 void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem )
00382 {
00383   Attendee *a = aItem->data();
00384   mDisableItemUpdate = true;
00385   mNameEdit->setText(a->name());
00386   mUidEdit->setText(a->uid());
00387   mEmailEdit->setText(a->email());
00388   mRoleCombo->setCurrentItem(a->role());
00389   mStatusCombo->setCurrentItem(a->status());
00390   mRsvpButton->setChecked(a->RSVP());
00391 
00392   mDisableItemUpdate = false;
00393 
00394   setEnabledAttendeeInput( true );
00395 }
00396 
00397 void KOEditorDetails::setEnabledAttendeeInput( bool enabled )
00398 {
00399   mNameEdit->setEnabled( enabled );
00400   mEmailEdit->setEnabled( enabled );
00401   mRoleCombo->setEnabled( enabled );
00402   mStatusCombo->setEnabled( enabled );
00403   mRsvpButton->setEnabled( enabled );
00404 
00405   mRemoveButton->setEnabled( enabled );
00406 }
00407 
00408 void KOEditorDetails::updateAttendeeItem()
00409 {
00410   if (mDisableItemUpdate) return;
00411 
00412   QListViewItem *item = mListView->selectedItem();
00413   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00414   if ( !aItem ) return;
00415 
00416   Attendee *a = aItem->data();
00417 
00418   a->setName( mNameEdit->text() );
00419   a->setUid( mUidEdit->text() );
00420   a->setEmail( mEmailEdit->text() );
00421   a->setRole( Attendee::Role( mRoleCombo->currentItem() ) );
00422   a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
00423   a->setRSVP( mRsvpButton->isChecked() );
00424   aItem->updateItem();
00425   if( mGantt ) mGantt->updateAttendee( a );
00426 }
00427 
00428 void KOEditorDetails::setGanttWidget( KOEditorGantt* gantt )
00429 {
00430   mGantt = gantt;
00431 }
00432 
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Mar 6 17:18:32 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003