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., 675 Mass Ave, Cambridge, MA 02139, 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 
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kiconloader.h>
00036 #include <kmessagebox.h>
00037 #include <kdebug.h>
00038 #ifndef KORG_NOKABC
00039 #include <kabc/addresseedialog.h>
00040 #endif
00041 
00042 #include <libkcal/incidence.h>
00043 
00044 #include "koprefs.h"
00045 
00046 #include "koeditordetails.h"
00047 #include "koeditordetails.moc"
00048 
00049 template <>
00050 CustomListViewItem<class Attendee *>::~CustomListViewItem()
00051 {
00052   delete mData;
00053 }
00054 
00055 template <>
00056 void CustomListViewItem<class Attendee *>::updateItem()
00057 {
00058   setText(0,mData->name());
00059   setText(1,mData->email());
00060   setText(2,mData->roleStr());
00061   setText(3,mData->statusStr());
00062   if (mData->RSVP() && !mData->email().isEmpty())
00063     setPixmap(4,SmallIcon("mailappt"));
00064   else
00065     setPixmap(4,SmallIcon("nomailappt"));
00066 }
00067 
00068 
00069 KOEditorDetails::KOEditorDetails (int spacing,QWidget* parent,const char* name)
00070   : QWidget( parent, name), mDisableItemUpdate( false )
00071 {
00072   QGridLayout *topLayout = new QGridLayout(this);
00073   topLayout->setSpacing(spacing);
00074 
00075   QString organizer = KOPrefs::instance()->email();
00076   mOrganizerLabel = new QLabel(i18n("Organizer: %1").arg(organizer),this);
00077 
00078   mListView = new QListView(this,"mListView");
00079   mListView->addColumn(i18n("Name"),180);
00080   mListView->addColumn(i18n("Email"),180);
00081   mListView->addColumn(i18n("Role"),60);
00082   mListView->addColumn(i18n("Status"),100);
00083   mListView->addColumn(i18n("RSVP"),35);
00084   if ( KOPrefs::instance()->mCompactDialogs ) {
00085     mListView->setFixedHeight(78);
00086   }
00087 
00088   connect(mListView,SIGNAL(selectionChanged(QListViewItem *)),
00089           SLOT(updateAttendeeInput()));
00090 
00091   QLabel *attendeeLabel = new QLabel(this);
00092   attendeeLabel->setText(i18n("Name:"));
00093 
00094   mNameEdit = new QLineEdit(this);
00095   connect(mNameEdit,SIGNAL(textChanged(const QString &)),
00096           SLOT(updateAttendeeItem()));
00097 
00098   mUidEdit = new QLineEdit(0);
00099   mUidEdit->setText("");
00100 
00101   QLabel *emailLabel = new QLabel(this);
00102   emailLabel->setText(i18n("Email:"));
00103 
00104   mEmailEdit = new QLineEdit(this);
00105   connect(mEmailEdit,SIGNAL(textChanged(const QString &)),
00106           SLOT(updateAttendeeItem()));
00107 
00108   QLabel *attendeeRoleLabel = new QLabel(this);
00109   attendeeRoleLabel->setText(i18n("Role:"));
00110 
00111   mRoleCombo = new QComboBox(false,this);
00112   mRoleCombo->insertStringList(Attendee::roleList());
00113   connect(mRoleCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00114 
00115   QLabel *statusLabel = new QLabel(this);
00116   statusLabel->setText( i18n("Status:") );
00117 
00118   mStatusCombo = new QComboBox(false,this);
00119   mStatusCombo->insertStringList(Attendee::statusList());
00120   connect(mStatusCombo,SIGNAL(activated(int)),SLOT(updateAttendeeItem()));
00121 
00122   mRsvpButton = new QCheckBox(this);
00123   mRsvpButton->setText(i18n("Request response"));
00124   connect(mRsvpButton,SIGNAL(clicked()),SLOT(updateAttendeeItem()));
00125 
00126   QWidget *buttonBox = new QWidget(this);
00127   QVBoxLayout *buttonLayout = new QVBoxLayout(buttonBox);
00128 
00129   QPushButton *newButton = new QPushButton(i18n("&New"),buttonBox);
00130   buttonLayout->addWidget(newButton);
00131   connect(newButton,SIGNAL(clicked()),SLOT(addNewAttendee()));
00132 
00133   mRemoveButton = new QPushButton(i18n("&Remove"),buttonBox);
00134   buttonLayout->addWidget(mRemoveButton);
00135   connect(mRemoveButton, SIGNAL(clicked()),SLOT(removeAttendee()));
00136 
00137   mAddressBookButton = new QPushButton(i18n("Address &Book..."),buttonBox);
00138   buttonLayout->addWidget(mAddressBookButton);
00139   connect(mAddressBookButton,SIGNAL(clicked()),SLOT(openAddressBook()));
00140 
00141   topLayout->addMultiCellWidget(mOrganizerLabel,0,0,0,5);
00142   topLayout->addMultiCellWidget(mListView,1,1,0,5);
00143   topLayout->addWidget(attendeeLabel,2,0);
00144   topLayout->addMultiCellWidget(mNameEdit,2,2,1,1);
00145   topLayout->addWidget(emailLabel,3,0);
00146   topLayout->addMultiCellWidget(mEmailEdit,3,3,1,1);
00147   topLayout->addWidget(attendeeRoleLabel,4,0);
00148   topLayout->addWidget(mRoleCombo,4,1);
00149 #if 0
00150   topLayout->setColStretch(2,1);
00151   topLayout->addWidget(statusLabel,3,3);
00152   topLayout->addWidget(mStatusCombo,3,4);
00153 #else
00154   topLayout->addWidget(statusLabel,5,0);
00155   topLayout->addWidget(mStatusCombo,5,1);
00156 #endif
00157   topLayout->addMultiCellWidget(mRsvpButton,6,6,0,1);
00158   topLayout->addMultiCellWidget(buttonBox,2,5,5,5);
00159 
00160 #ifdef KORG_NOKABC
00161   mAddressBookButton->hide();
00162 #endif
00163 
00164   updateAttendeeInput();
00165 }
00166 
00167 KOEditorDetails::~KOEditorDetails()
00168 {
00169 }
00170 
00171 void KOEditorDetails::removeAttendee()
00172 {
00173   AttendeeListItem *aItem = (AttendeeListItem *)mListView->selectedItem();
00174   if (!aItem) return;
00175 
00176   Attendee *delA = new Attendee(aItem->data()->name(),aItem->data()->email(),
00177     aItem->data()->RSVP(),aItem->data()->status(),aItem->data()->role(),
00178     aItem->data()->uid());
00179   mdelAttendees.append(delA);
00180 
00181   delete aItem;
00182 
00183   updateAttendeeInput();
00184 }
00185 
00186 
00187 void KOEditorDetails::openAddressBook()
00188 {
00189 #ifndef KORG_NOKABC
00190   KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00191   if (!a.isEmpty()) {
00192     insertAttendee( new Attendee( a.realName(), a.preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,a.uid()) );
00193   }
00194 #endif
00195 }
00196 
00197 
00198 void KOEditorDetails::addNewAttendee()
00199 {
00200 #if 0
00201   // this is cool.  If they didn't enter an email address,
00202   // try to look it up in the address book and fill it in for them.
00203   if (QString(mEmailEdit->text()).stripWhiteSpace().isEmpty()) {
00204     KabAPI addrBook;
00205     QString name;
00206     std::list<AddressBook::Entry> entries;
00207     name = mNameEdit->text();
00208     if (addrBook.init() == AddressBook::NoError) {
00209       if (addrBook.getEntryByName(name, entries, 1) == AddressBook::NoError) {
00210         kdDebug() << "positive match" << endl;
00211         // take first email address
00212         if (!entries.front().emails.isEmpty() &&
00213             entries.front().emails.first().length()>0)
00214           mEmailEdit->setText(entries.front().emails.first());
00215       }
00216     }
00217   }
00218 #endif
00219 
00220   Attendee *a = new Attendee(i18n("(EmptyName)"),i18n("(EmptyEmail)"));
00221   insertAttendee(a);
00222 }
00223 
00224 
00225 void KOEditorDetails::insertAttendee(Attendee *a)
00226 {
00227   AttendeeListItem *item = new AttendeeListItem(a,mListView);
00228   mListView->setSelected( item, true );
00229 }
00230 
00231 void KOEditorDetails::setDefaults()
00232 {
00233   mRsvpButton->setChecked(true);
00234 }
00235 
00236 void KOEditorDetails::readEvent(Incidence *event)
00237 {
00238   mListView->clear();
00239   mdelAttendees.clear();
00240   QPtrList<Attendee> tmpAList = event->attendees();
00241   Attendee *a;
00242   for (a = tmpAList.first(); a; a = tmpAList.next())
00243     insertAttendee(new Attendee(*a));
00244 
00245   mListView->setSelected( mListView->firstChild(), true );
00246   mOrganizerLabel->setText(i18n("Organizer: %1").arg(event->organizer()));
00247 }
00248 
00249 void KOEditorDetails::writeEvent(Incidence *event)
00250 {
00251   event->clearAttendees();
00252   QListViewItem *item;
00253   AttendeeListItem *a;
00254   for (item = mListView->firstChild(); item;
00255        item = item->nextSibling()) {
00256     a = (AttendeeListItem *)item;
00257     event->addAttendee(new Attendee(*(a->data())));
00258   }
00259 }
00260 
00261 void KOEditorDetails::cancelAttendeeEvent(Incidence *event)
00262 {
00263   event->clearAttendees();
00264   Attendee * att;
00265   for (att=mdelAttendees.first();att;att=mdelAttendees.next()) {
00266     event->addAttendee(new Attendee(*att));
00267   }
00268   mdelAttendees.clear();
00269 }
00270 
00271 bool KOEditorDetails::validateInput()
00272 {
00273   return true;
00274 }
00275 
00276 void KOEditorDetails::updateAttendeeInput()
00277 {
00278   QListViewItem *item = mListView->selectedItem();
00279   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00280   if (aItem) {
00281     fillAttendeeInput( aItem );
00282   } else {
00283     clearAttendeeInput();
00284   }
00285 }
00286 
00287 void KOEditorDetails::clearAttendeeInput()
00288 {
00289   mNameEdit->setText("");
00290   mUidEdit->setText("");
00291   mEmailEdit->setText("");
00292   mRoleCombo->setCurrentItem(0);
00293   mStatusCombo->setCurrentItem(0);
00294   mRsvpButton->setChecked(true);
00295   setEnabledAttendeeInput( false );
00296 }
00297 
00298 void KOEditorDetails::fillAttendeeInput( AttendeeListItem *aItem )
00299 {
00300   Attendee *a = aItem->data();
00301   mDisableItemUpdate = true;
00302   mNameEdit->setText(a->name());
00303   mUidEdit->setText(a->uid());
00304   mEmailEdit->setText(a->email());
00305   mRoleCombo->setCurrentItem(a->role());
00306   mStatusCombo->setCurrentItem(a->status());
00307   mRsvpButton->setChecked(a->RSVP());
00308 
00309   mDisableItemUpdate = false;
00310 
00311   setEnabledAttendeeInput( true );
00312 }
00313 
00314 void KOEditorDetails::setEnabledAttendeeInput( bool enabled )
00315 {
00316   mNameEdit->setEnabled( enabled );
00317   mEmailEdit->setEnabled( enabled );
00318   mRoleCombo->setEnabled( enabled );
00319   mStatusCombo->setEnabled( enabled );
00320   mRsvpButton->setEnabled( enabled );
00321 
00322   mRemoveButton->setEnabled( enabled );
00323 }
00324 
00325 void KOEditorDetails::updateAttendeeItem()
00326 {
00327   if (mDisableItemUpdate) return;
00328 
00329   QListViewItem *item = mListView->selectedItem();
00330   AttendeeListItem *aItem = static_cast<AttendeeListItem *>( item );
00331   if ( !aItem ) return;
00332 
00333   Attendee *a = aItem->data();
00334 
00335   a->setName( mNameEdit->text() );
00336   a->setUid( mUidEdit->text() );
00337   a->setEmail( mEmailEdit->text() );
00338   a->setRole( Attendee::Role( mRoleCombo->currentItem() ) );
00339   a->setStatus( Attendee::PartStat( mStatusCombo->currentItem() ) );
00340   a->setRSVP( mRsvpButton->isChecked() );
00341   aItem->updateItem();
00342 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001