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