korganizer

koeventeditor.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <qtooltip.h>
00027 #include <qframe.h>
00028 #include <qguardedptr.h>
00029 #include <qpixmap.h>
00030 #include <qlayout.h>
00031 #include <qwidgetstack.h>
00032 #include <qwhatsthis.h>
00033 
00034 #include <kiconloader.h>
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 #include <libkcal/calendarresources.h>
00039 #include <libkcal/resourcecalendar.h>
00040 
00041 #include <libkcal/calendarlocal.h>
00042 
00043 #include "koprefs.h"
00044 #include "koeditorgeneralevent.h"
00045 #include "koeditoralarms.h"
00046 #include "koeditorrecurrence.h"
00047 #include "koeditordetails.h"
00048 #include "koeditorattachments.h"
00049 #include "koeditorfreebusy.h"
00050 #include "kogroupware.h"
00051 #include "kodialogmanager.h"
00052 #include "incidencechanger.h"
00053 
00054 #include "koeventeditor.h"
00055 
00056 KOEventEditor::KOEventEditor( Calendar *calendar, QWidget *parent )
00057   : KOIncidenceEditor( QString::null, calendar, parent ),
00058     mEvent( 0 ), mGeneral( 0 ), mRecurrence( 0 ), mFreeBusy( 0 )
00059 {
00060 }
00061 
00062 KOEventEditor::~KOEventEditor()
00063 {
00064   emit dialogClose( mEvent );
00065 }
00066 
00067 void KOEventEditor::init()
00068 {
00069   setupGeneral();
00070 //  setupAlarmsTab();
00071   setupRecurrence();
00072   setupAttendeesTab();
00073   setupFreeBusy();
00074   setupAttachmentsTab();
00075   setupDesignerTabs( "event" );
00076 
00077   mDetails->setFreeBusyWidget( mFreeBusy );
00078 
00079   // Propagate date time settings to recurrence tab
00080   connect( mGeneral, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & ) ),
00081            mRecurrence, SLOT( setDateTimes( const QDateTime &, const QDateTime &) ) );
00082   connect( mGeneral, SIGNAL( dateTimeStrChanged( const QString & ) ),
00083            mRecurrence, SLOT( setDateTimeStr( const QString & ) ) );
00084   connect( mFreeBusy, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & ) ),
00085            mRecurrence, SLOT( setDateTimes( const QDateTime &, const QDateTime & ) ) );
00086 
00087   // Propagate date time settings to gantt tab and back
00088   connect( mGeneral, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & ) ),
00089            mFreeBusy, SLOT( slotUpdateGanttView( const QDateTime &, const QDateTime & ) ) );
00090   connect( mFreeBusy, SIGNAL( dateTimesChanged( const QDateTime &, const QDateTime & ) ),
00091            mGeneral, SLOT( setDateTimes( const QDateTime &, const QDateTime & ) ) );
00092 
00093   connect( mGeneral, SIGNAL( focusReceivedSignal() ),
00094            SIGNAL( focusReceivedSignal() ) );
00095 
00096   connect( mGeneral, SIGNAL( openCategoryDialog() ),
00097            SIGNAL( editCategories() ) );
00098 }
00099 
00100 void KOEventEditor::reload()
00101 {
00102   kdDebug(5850) << "KOEventEditor::reload()" << endl;
00103 
00104   if ( mEvent ) readEvent( mEvent );
00105 }
00106 
00107 void KOEventEditor::setupGeneral()
00108 {
00109   mGeneral = new KOEditorGeneralEvent( this );
00110 
00111   if( KOPrefs::instance()->mCompactDialogs ) {
00112     QFrame *topFrame = addPage(i18n("General"));
00113     QWhatsThis::add( topFrame,
00114                      i18n("The General tab allows you to set the most common "
00115                           "options for the event.") );
00116 
00117     QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00118     topLayout->setSpacing(spacingHint());
00119 
00120     mGeneral->initHeader(topFrame,topLayout);
00121     mGeneral->initTime(topFrame,topLayout);
00122 //    QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
00123     mGeneral->initAlarm(topFrame,topLayout);
00124     mGeneral->enableAlarm( false );
00125     mGeneral->initCategories( topFrame, topLayout );
00126 
00127     topLayout->addStretch( 1 );
00128 
00129     QFrame *topFrame2 = addPage(i18n("Details"));
00130 
00131     QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
00132     topLayout2->setSpacing(spacingHint());
00133 
00134     mGeneral->initClass(topFrame2,topLayout2);
00135     mGeneral->initSecrecy( topFrame2, topLayout2 );
00136     mGeneral->initDescription(topFrame2,topLayout2);
00137   } else {
00138     QFrame *topFrame = addPage(i18n("&General"));
00139     QWhatsThis::add( topFrame,
00140                      i18n("The General tab allows you to set the most common "
00141                           "options for the event.") );
00142 
00143     QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00144     topLayout->setSpacing(spacingHint());
00145 
00146     mGeneral->initHeader(topFrame,topLayout);
00147     mGeneral->initTime(topFrame,topLayout);
00148     QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
00149     mGeneral->initAlarm(topFrame,alarmLineLayout);
00150     alarmLineLayout->addStretch( 1 );
00151     mGeneral->initClass(topFrame,alarmLineLayout);
00152     mGeneral->initDescription(topFrame,topLayout);
00153     QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
00154     mGeneral->initCategories( topFrame, detailsLayout );
00155     mGeneral->initSecrecy( topFrame, detailsLayout );
00156   }
00157 
00158   mGeneral->finishSetup();
00159 }
00160 
00161 void KOEventEditor::modified (int /*modification*/)
00162 {
00163   // Play dump, just reload the event. This dialog has become so complicated
00164   // that there is no point in trying to be smart here...
00165   reload();
00166 }
00167 
00168 void KOEventEditor::setupRecurrence()
00169 {
00170   QFrame *topFrame = addPage( i18n("Rec&urrence") );
00171 
00172   QWhatsThis::add( topFrame,
00173         i18n("The Recurrence tab allows you to set options on "
00174        "how often this event recurs.") );
00175 
00176   QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00177 
00178   mRecurrence = new KOEditorRecurrence( topFrame );
00179   topLayout->addWidget( mRecurrence );
00180 }
00181 
00182 void KOEventEditor::setupFreeBusy()
00183 {
00184   QFrame *freeBusyPage = addPage( i18n("&Free/Busy") );
00185   QWhatsThis::add( freeBusyPage,
00186         i18n("The Free/Busy tab allows you to see whether "
00187        "other attendees are free or busy during your event.") );
00188 
00189   QBoxLayout *topLayout = new QVBoxLayout( freeBusyPage );
00190 
00191   mFreeBusy = new KOEditorFreeBusy( spacingHint(), freeBusyPage );
00192   topLayout->addWidget( mFreeBusy );
00193 }
00194 
00195 void KOEventEditor::editIncidence( Incidence *incidence )
00196 {
00197   Event*event = dynamic_cast<Event*>(incidence);
00198   if ( event ) {
00199     init();
00200 
00201     mEvent = event;
00202     readEvent(mEvent);
00203   }
00204 
00205   setCaption( i18n("Edit Event") );
00206 }
00207 
00208 void KOEventEditor::newEvent()
00209 {
00210   init();
00211   mEvent = 0;
00212   loadDefaults();
00213   setCaption( i18n("New Event") );
00214 }
00215 
00216 void KOEventEditor::setDates( const QDateTime &from, const QDateTime &to, bool allDay )
00217 {
00218   mGeneral->setDefaults( from, to, allDay );
00219   mDetails->setDefaults();
00220   mAttachments->setDefaults();
00221   mRecurrence->setDefaults( from, to, allDay );
00222   if( mFreeBusy ) {
00223     if ( allDay )
00224       mFreeBusy->setDateTimes( from, to.addDays( 1 ) );
00225     else
00226       mFreeBusy->setDateTimes( from, to );
00227   }
00228 }
00229 
00230 void KOEventEditor::setTexts( const QString &summary, const QString &description )
00231 {
00232   if ( description.isEmpty() && summary.contains("\n") ) {
00233     mGeneral->setDescription( summary );
00234     int pos = summary.find( "\n" );
00235     mGeneral->setSummary( summary.left( pos ) );
00236   } else {
00237     mGeneral->setSummary( summary );
00238     mGeneral->setDescription( description );
00239   }
00240 }
00241 
00242 void KOEventEditor::loadDefaults()
00243 {
00244   QDateTime from( QDate::currentDate(), KOPrefs::instance()->mStartTime.time() );
00245   int addSecs = ( KOPrefs::instance()->mDefaultDuration.time().hour()*3600 ) +
00246                 ( KOPrefs::instance()->mDefaultDuration.time().minute()*60 );
00247   QDateTime to( from.addSecs( addSecs ) );
00248 
00249   setDates( from, to, false );
00250 }
00251 
00252 bool KOEventEditor::processInput()
00253 {
00254   kdDebug(5850) << "KOEventEditor::processInput()" << endl;
00255 
00256   if ( !validateInput() || !mChanger ) return false;
00257 
00258   QGuardedPtr<KOEditorFreeBusy> freeBusy( mFreeBusy );
00259 
00260   if ( mEvent ) {
00261     bool rc = true;
00262     Event *oldEvent = mEvent->clone();
00263     Event *event = mEvent->clone();
00264 
00265     kdDebug(5850) << "KOEventEditor::processInput() write event." << endl;
00266     writeEvent( event );
00267     kdDebug(5850) << "KOEventEditor::processInput() event written." << endl;
00268 
00269     if( *event == *mEvent )
00270       // Don't do anything
00271       kdDebug(5850) << "Event not changed\n";
00272     else {
00273       kdDebug(5850) << "Event changed\n";
00274       //IncidenceChanger::assignIncidence( mEvent, event );
00275       writeEvent( mEvent );
00276       mChanger->changeIncidence( oldEvent, mEvent );
00277     }
00278     delete event;
00279     delete oldEvent;
00280     return rc;
00281   } else {
00282     mEvent = new Event;
00283     mEvent->setOrganizer( Person( KOPrefs::instance()->fullName(),
00284                           KOPrefs::instance()->email() ) );
00285     writeEvent( mEvent );
00286     if ( !mChanger->addIncidence( mEvent, this ) ) {
00287       delete mEvent;
00288       mEvent = 0;
00289       return false;
00290     }
00291   }
00292   // if "this" was deleted, freeBusy is 0 (being a guardedptr)
00293   if ( freeBusy ) freeBusy->cancelReload();
00294 
00295   return true;
00296 }
00297 
00298 void KOEventEditor::processCancel()
00299 {
00300   kdDebug(5850) << "KOEventEditor::processCancel()" << endl;
00301 
00302   if ( mFreeBusy ) mFreeBusy->cancelReload();
00303 }
00304 
00305 void KOEventEditor::deleteEvent()
00306 {
00307   kdDebug(5850) << "Delete event" << endl;
00308 
00309   if ( mEvent )
00310     emit deleteIncidenceSignal( mEvent );
00311   emit dialogClose( mEvent );
00312   reject();
00313 }
00314 
00315 void KOEventEditor::readEvent( Event *event, bool tmpl )
00316 {
00317   mGeneral->readEvent( event, tmpl );
00318   mDetails->readEvent( event );
00319   mRecurrence->readIncidence( event );
00320   mAttachments->readIncidence( event );
00321 //  mAlarms->readIncidence( event );
00322   if ( mFreeBusy ) {
00323     mFreeBusy->readEvent( event );
00324     mFreeBusy->triggerReload();
00325   }
00326 
00327   createEmbeddedURLPages( event );
00328   readDesignerFields( event );
00329 }
00330 
00331 void KOEventEditor::writeEvent( Event *event )
00332 {
00333   mGeneral->writeEvent( event );
00334   mDetails->writeEvent( event );
00335   mAttachments->writeIncidence( event );
00336 
00337   cancelRemovedAttendees( event );
00338 
00339   mRecurrence->writeIncidence( event );
00340 
00341   writeDesignerFields( event );
00342 }
00343 
00344 bool KOEventEditor::validateInput()
00345 {
00346   if ( !mGeneral->validateInput() ) return false;
00347   if ( !mDetails->validateInput() ) return false;
00348   if ( !mRecurrence->validateInput() ) return false;
00349 
00350   return true;
00351 }
00352 
00353 int KOEventEditor::msgItemDelete()
00354 {
00355   return KMessageBox::warningContinueCancel(this,
00356       i18n("This item will be permanently deleted."),
00357       i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete"));
00358 }
00359 
00360 void KOEventEditor::loadTemplate( /*const*/ CalendarLocal& cal )
00361 {
00362   const Event::List events = cal.events();
00363   if ( events.count() == 0 ) {
00364     KMessageBox::error( this,
00365         i18n("Template does not contain a valid event.") );
00366   } else {
00367     kdDebug(5850) << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
00368     readEvent( events.first(), true );
00369   }
00370 }
00371 
00372 QStringList& KOEventEditor::templates() const
00373 {
00374   return KOPrefs::instance()->mEventTemplates;
00375 }
00376 
00377 void KOEventEditor::slotSaveTemplate( const QString &templateName )
00378 {
00379   kdDebug(5006) << "SlotSaveTemplate" << endl;
00380   Event *event = new Event;
00381   writeEvent( event );
00382   saveAsTemplate( event, templateName );
00383 }
00384 
00385 QObject *KOEventEditor::typeAheadReceiver() const
00386 {
00387   return mGeneral->typeAheadReceiver();
00388 }
00389 
00390 #include "koeventeditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys