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
00096 void KOEventEditor::reload()
00097 {
00098 kdDebug(5850) << "KOEventEditor::reload()" << endl;
00099
00100 if ( mEvent ) readEvent( mEvent );
00101 }
00102
00103 void KOEventEditor::setupGeneral()
00104 {
00105 mGeneral = new KOEditorGeneralEvent( this );
00106
00107 if( KOPrefs::instance()->mCompactDialogs ) {
00108 QFrame *topFrame = addPage(i18n("General"));
00109 QWhatsThis::add( topFrame,
00110 i18n("The General tab allows you to set the most common "
00111 "options for the event.") );
00112
00113 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00114 topLayout->setSpacing(spacingHint());
00115
00116 mGeneral->initHeader(topFrame,topLayout);
00117 mGeneral->initTime(topFrame,topLayout);
00118
00119 mGeneral->initAlarm(topFrame,topLayout);
00120 mGeneral->enableAlarm( false );
00121 mGeneral->initCategories( topFrame, topLayout );
00122
00123 topLayout->addStretch( 1 );
00124
00125 QFrame *topFrame2 = addPage(i18n("Details"));
00126
00127 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
00128 topLayout2->setSpacing(spacingHint());
00129
00130 mGeneral->initClass(topFrame2,topLayout2);
00131 mGeneral->initSecrecy( topFrame2, topLayout2 );
00132 mGeneral->initDescription(topFrame2,topLayout2);
00133 } else {
00134 QFrame *topFrame = addPage(i18n("&General"));
00135 QWhatsThis::add( topFrame,
00136 i18n("The General tab allows you to set the most common "
00137 "options for the event.") );
00138
00139 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00140 topLayout->setSpacing(spacingHint());
00141
00142 mGeneral->initHeader(topFrame,topLayout);
00143 mGeneral->initTime(topFrame,topLayout);
00144 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
00145 mGeneral->initAlarm(topFrame,alarmLineLayout);
00146 alarmLineLayout->addStretch( 1 );
00147 mGeneral->initClass(topFrame,alarmLineLayout);
00148 mGeneral->initDescription(topFrame,topLayout);
00149 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
00150 mGeneral->initCategories( topFrame, detailsLayout );
00151 mGeneral->initSecrecy( topFrame, detailsLayout );
00152 }
00153
00154 mGeneral->finishSetup();
00155 }
00156
00157 void KOEventEditor::modified (int )
00158 {
00159
00160
00161 reload();
00162 }
00163
00164 void KOEventEditor::setupRecurrence()
00165 {
00166 QFrame *topFrame = addPage( i18n("Rec&urrence") );
00167
00168 QWhatsThis::add( topFrame,
00169 i18n("The Recurrence tab allows you to set options on "
00170 "how often this event recurs.") );
00171
00172 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00173
00174 mRecurrence = new KOEditorRecurrence( topFrame );
00175 topLayout->addWidget( mRecurrence );
00176 }
00177
00178 void KOEventEditor::setupFreeBusy()
00179 {
00180 QFrame *freeBusyPage = addPage( i18n("&Free/Busy") );
00181 QWhatsThis::add( freeBusyPage,
00182 i18n("The Free/Busy tab allows you to see whether "
00183 "other attendees are free or busy during your event.") );
00184
00185 QBoxLayout *topLayout = new QVBoxLayout( freeBusyPage );
00186
00187 mFreeBusy = new KOEditorFreeBusy( spacingHint(), freeBusyPage );
00188 topLayout->addWidget( mFreeBusy );
00189 }
00190
00191 void KOEventEditor::editIncidence( Incidence *incidence )
00192 {
00193 Event*event = dynamic_cast<Event*>(incidence);
00194 if ( event ) {
00195 init();
00196
00197 mEvent = event;
00198 readEvent(mEvent);
00199 }
00200
00201 setCaption( i18n("Edit Event") );
00202 }
00203
00204 void KOEventEditor::newEvent()
00205 {
00206 init();
00207 mEvent = 0;
00208 loadDefaults();
00209 setCaption( i18n("New Event") );
00210 }
00211
00212 void KOEventEditor::setDates( const QDateTime &from, const QDateTime &to, bool allDay )
00213 {
00214 mGeneral->setDefaults( from, to, allDay );
00215 mDetails->setDefaults();
00216 mAttachments->setDefaults();
00217 mRecurrence->setDefaults( from, to, allDay );
00218 if( mFreeBusy ) {
00219 if ( allDay )
00220 mFreeBusy->setDateTimes( from, to.addDays( 1 ) );
00221 else
00222 mFreeBusy->setDateTimes( from, to );
00223 }
00224 }
00225
00226 void KOEventEditor::setTexts( const QString &summary, const QString &description )
00227 {
00228 if ( description.isEmpty() && summary.contains("\n") ) {
00229 mGeneral->setDescription( summary );
00230 int pos = summary.find( "\n" );
00231 mGeneral->setSummary( summary.left( pos ) );
00232 } else {
00233 mGeneral->setSummary( summary );
00234 mGeneral->setDescription( description );
00235 }
00236 }
00237
00238 void KOEventEditor::loadDefaults()
00239 {
00240 QDateTime from( QDate::currentDate(), KOPrefs::instance()->mStartTime.time() );
00241 int addSecs = ( KOPrefs::instance()->mDefaultDuration.time().hour()*3600 ) +
00242 ( KOPrefs::instance()->mDefaultDuration.time().minute()*60 );
00243 QDateTime to( from.addSecs( addSecs ) );
00244
00245 setDates( from, to, false );
00246 }
00247
00248 bool KOEventEditor::processInput()
00249 {
00250 kdDebug(5850) << "KOEventEditor::processInput()" << endl;
00251
00252 if ( !validateInput() || !mChanger ) return false;
00253
00254 if ( mEvent ) {
00255 bool rc = true;
00256 Event *oldEvent = mEvent->clone();
00257 Event *event = mEvent->clone();
00258
00259 kdDebug(5850) << "KOEventEditor::processInput() write event." << endl;
00260 writeEvent( event );
00261 kdDebug(5850) << "KOEventEditor::processInput() event written." << endl;
00262
00263 if( *event == *mEvent )
00264
00265 kdDebug(5850) << "Event not changed\n";
00266 else {
00267 kdDebug(5850) << "Event changed\n";
00268
00269 writeEvent( mEvent );
00270 mChanger->changeIncidence( oldEvent, mEvent );
00271 }
00272 delete event;
00273 delete oldEvent;
00274 return rc;
00275 } else {
00276 mEvent = new Event;
00277 mEvent->setOrganizer( Person( KOPrefs::instance()->fullName(),
00278 KOPrefs::instance()->email() ) );
00279 writeEvent( mEvent );
00280 if ( !mChanger->addIncidence( mEvent, this ) ) {
00281 delete mEvent;
00282 mEvent = 0;
00283 return false;
00284 }
00285 }
00286
00287 if ( mFreeBusy ) mFreeBusy->cancelReload();
00288
00289 return true;
00290 }
00291
00292 void KOEventEditor::processCancel()
00293 {
00294 kdDebug(5850) << "KOEventEditor::processCancel()" << endl;
00295
00296 if ( mFreeBusy ) mFreeBusy->cancelReload();
00297 }
00298
00299 void KOEventEditor::deleteEvent()
00300 {
00301 kdDebug(5850) << "Delete event" << endl;
00302
00303 if ( mEvent )
00304 emit deleteIncidenceSignal( mEvent );
00305 emit dialogClose( mEvent );
00306 reject();
00307 }
00308
00309 void KOEventEditor::readEvent( Event *event, bool tmpl )
00310 {
00311 mGeneral->readEvent( event, tmpl );
00312 mDetails->readEvent( event );
00313 mRecurrence->readIncidence( event );
00314 mAttachments->readIncidence( event );
00315
00316 if ( mFreeBusy ) {
00317 mFreeBusy->readEvent( event );
00318 mFreeBusy->triggerReload();
00319 }
00320
00321 createEmbeddedURLPages( event );
00322 readDesignerFields( event );
00323 }
00324
00325 void KOEventEditor::writeEvent( Event *event )
00326 {
00327 mGeneral->writeEvent( event );
00328 mDetails->writeEvent( event );
00329 mAttachments->writeIncidence( event );
00330
00331 cancelRemovedAttendees( event );
00332
00333 mRecurrence->writeIncidence( event );
00334
00335 writeDesignerFields( event );
00336 }
00337
00338 bool KOEventEditor::validateInput()
00339 {
00340 if ( !mGeneral->validateInput() ) return false;
00341 if ( !mDetails->validateInput() ) return false;
00342 if ( !mRecurrence->validateInput() ) return false;
00343
00344 return true;
00345 }
00346
00347 int KOEventEditor::msgItemDelete()
00348 {
00349 return KMessageBox::warningContinueCancel(this,
00350 i18n("This item will be permanently deleted."),
00351 i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete"));
00352 }
00353
00354 void KOEventEditor::loadTemplate( CalendarLocal& cal )
00355 {
00356 const Event::List events = cal.events();
00357 if ( events.count() == 0 ) {
00358 KMessageBox::error( this,
00359 i18n("Template does not contain a valid event.") );
00360 } else {
00361 kdDebug(5850) << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
00362 readEvent( events.first(), true );
00363 }
00364 }
00365
00366 QStringList& KOEventEditor::templates() const
00367 {
00368 return KOPrefs::instance()->mEventTemplates;
00369 }
00370
00371 void KOEventEditor::slotSaveTemplate( const QString &templateName )
00372 {
00373 kdDebug(5006) << "SlotSaveTemplate" << endl;
00374 Event *event = new Event;
00375 writeEvent( event );
00376 saveAsTemplate( event, templateName );
00377 }
00378
00379 QObject *KOEventEditor::typeAheadReceiver() const
00380 {
00381 return mGeneral->typeAheadReceiver();
00382 }
00383
00384 #include "koeventeditor.moc"