00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qtooltip.h>
00025 #include <qframe.h>
00026 #include <qpixmap.h>
00027 #include <qlayout.h>
00028 #include <qwidgetstack.h>
00029
00030 #include <kiconloader.h>
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033 #include <kmessagebox.h>
00034
00035 #include <libkdepim/categoryselectdialog.h>
00036 #include <libkcal/calendarlocal.h>
00037
00038 #include "koprefs.h"
00039
00040 #include "koeventeditor.h"
00041 #include "koeventeditor.moc"
00042
00043 KOEventEditor::KOEventEditor( Calendar *calendar, QWidget *parent ) :
00044 KOIncidenceEditor( i18n("Edit Event"), calendar, parent )
00045 {
00046 mEvent = 0;
00047 }
00048
00049 KOEventEditor::~KOEventEditor()
00050 {
00051 emit dialogClose( mEvent );
00052 }
00053
00054 void KOEventEditor::init()
00055 {
00056 setupGeneral();
00057 setupAttendeesTab();
00058 #ifndef KORG_NORECURRENCE
00059 setupRecurrence();
00060
00061
00062 connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)),
00063 mRecurrence,SLOT(setDateTimes(QDateTime,QDateTime)));
00064 connect(mGeneral,SIGNAL(dateTimeStrChanged(const QString &)),
00065 mRecurrence,SLOT(setDateTimeStr(const QString &)));
00066
00067
00068 connect(mGeneral,SIGNAL(recursChanged(bool)),
00069 SLOT(enableRecurrence(bool)));
00070 #endif
00071
00072
00073 connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show()));
00074 connect(mCategoryDialog,SIGNAL(categoriesSelected(const QString &)),
00075 mGeneral,SLOT(setCategories(const QString &)));
00076 }
00077
00078 void KOEventEditor::reload()
00079 {
00080 if ( mEvent ) readEvent( mEvent );
00081 }
00082
00083 void KOEventEditor::setupGeneral()
00084 {
00085 mGeneral = new KOEditorGeneralEvent( this );
00086
00087 if( KOPrefs::instance()->mCompactDialogs ) {
00088 QFrame *topFrame = addPage(i18n("General"));
00089
00090 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00091 topLayout->setMargin(marginHint());
00092 topLayout->setSpacing(spacingHint());
00093
00094 mGeneral->initHeader(topFrame,topLayout);
00095 mGeneral->initTime(topFrame,topLayout);
00096
00097 mGeneral->initAlarm(topFrame,topLayout);
00098 mGeneral->enableAlarm( false );
00099 mGeneral->initCategories( topFrame, topLayout );
00100
00101 topLayout->addStretch( 1 );
00102
00103 QFrame *topFrame2 = addPage(i18n("Details"));
00104
00105 QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2);
00106 topLayout2->setMargin(marginHint());
00107 topLayout2->setSpacing(spacingHint());
00108
00109 mGeneral->initClass(topFrame2,topLayout2);
00110 mGeneral->initSecrecy( topFrame2, topLayout2 );
00111 mGeneral->initDescription(topFrame2,topLayout2);
00112 } else {
00113 QFrame *topFrame = addPage(i18n("General"));
00114
00115 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00116 topLayout->setSpacing(spacingHint());
00117
00118 mGeneral->initHeader(topFrame,topLayout);
00119 mGeneral->initTime(topFrame,topLayout);
00120 QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
00121 mGeneral->initAlarm(topFrame,alarmLineLayout);
00122 mGeneral->initClass(topFrame,alarmLineLayout);
00123 mGeneral->initDescription(topFrame,topLayout);
00124 QBoxLayout *detailsLayout = new QHBoxLayout(topLayout);
00125 mGeneral->initCategories( topFrame, detailsLayout );
00126 mGeneral->initSecrecy( topFrame, detailsLayout );
00127 }
00128
00129 mGeneral->finishSetup();
00130 }
00131
00132 void KOEventEditor::setupRecurrence()
00133 {
00134 QFrame *topFrame = addPage(i18n("Recurrence"));
00135
00136 QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00137
00138 mRecurrenceStack = new QWidgetStack(topFrame);
00139 topLayout->addWidget(mRecurrenceStack);
00140
00141 mRecurrence = new KOEditorRecurrence(spacingHint(),mRecurrenceStack);
00142 mRecurrenceStack->addWidget(mRecurrence,0);
00143
00144 mRecurrenceDisabled = new QLabel(
00145 i18n("This event does not recur.\nEnable Recurrence in General Tab."),
00146 mRecurrenceStack);
00147 mRecurrenceDisabled->setAlignment(AlignCenter);
00148 mRecurrenceStack->addWidget(mRecurrenceDisabled,1);
00149 }
00150
00151 void KOEventEditor::enableRecurrence(bool enable)
00152 {
00153 if (enable) mRecurrenceStack->raiseWidget(mRecurrence);
00154 else mRecurrenceStack->raiseWidget(mRecurrenceDisabled);
00155
00156 mRecurrence->setEnabled(enable);
00157 }
00158
00159 void KOEventEditor::editEvent(Event *event)
00160 {
00161 init();
00162
00163 mEvent = event;
00164 readEvent(mEvent);
00165 }
00166
00167 void KOEventEditor::newEvent( QDateTime from, QDateTime to, bool allDay )
00168 {
00169 init();
00170
00171 mEvent = 0;
00172 setDefaults(from,to,allDay);
00173 }
00174
00175 void KOEventEditor::loadDefaults()
00176 {
00177 int fmt = KOPrefs::instance()->mStartTime;
00178
00179 QDateTime from(QDate::currentDate(), QTime(fmt,0,0));
00180 QDateTime to(QDate::currentDate(),
00181 QTime(fmt+KOPrefs::instance()->mDefaultDuration,0,0));
00182
00183 setDefaults(from,to,false);
00184 }
00185
00186 bool KOEventEditor::processInput()
00187 {
00188 if (!validateInput()) return false;
00189
00190 Event *event = 0;
00191
00192 if (mEvent) event = mEvent;
00193 else {
00194 event = new Event;
00195 event->setOrganizer(KOPrefs::instance()->email());
00196 }
00197
00198 writeEvent(event);
00199
00200 if (mEvent) {
00201 event->setRevision(event->revision()+1);
00202 emit eventChanged(event);
00203 } else {
00204 mCalendar->addEvent(event);
00205 mEvent = event;
00206 emit eventAdded(event);
00207 }
00208
00209 return true;
00210 }
00211
00212 void KOEventEditor::deleteEvent()
00213 {
00214 kdDebug() << "Delete event" << endl;
00215 if (mEvent) {
00216 if (KOPrefs::instance()->mConfirm) {
00217 switch (msgItemDelete()) {
00218 case KMessageBox::Continue:
00219 emit eventToBeDeleted(mEvent);
00220 emit dialogClose(mEvent);
00221 mCalendar->deleteEvent(mEvent);
00222 emit eventDeleted();
00223 reject();
00224 break;
00225 }
00226 }
00227 else {
00228 emit eventToBeDeleted(mEvent);
00229 emit dialogClose(mEvent);
00230 mCalendar->deleteEvent(mEvent);
00231 emit eventDeleted();
00232 reject();
00233 }
00234 } else {
00235 reject();
00236 }
00237 }
00238
00239 void KOEventEditor::setDefaults(QDateTime from, QDateTime to, bool allDay)
00240 {
00241 mGeneral->setDefaults(from,to,allDay);
00242 mDetails->setDefaults();
00243 #ifndef KORG_NORECURRENCE
00244 mRecurrence->setDefaults(from,to,allDay);
00245
00246 enableRecurrence(false);
00247 #endif
00248 }
00249
00250 void KOEventEditor::readEvent( Event *event, bool tmpl )
00251 {
00252 mGeneral->readEvent( event, tmpl );
00253 mDetails->readEvent( event );
00254 #ifndef KORG_NORECURRENCE
00255 mRecurrence->readEvent( event );
00256
00257 enableRecurrence( event->recurrence()->doesRecur() );
00258 #endif
00259
00260
00261 mCategoryDialog->setSelected( event->categories() );
00262 }
00263
00264 void KOEventEditor::writeEvent(Event *event)
00265 {
00266 mGeneral->writeEvent( event );
00267 mDetails->writeEvent( event );
00268
00269 if ( event->organizer() == KOPrefs::instance()->email() ) {
00270 Event *ev = new Event( *event );
00271 ev->registerObserver(0);
00272 mDetails->cancelAttendeeEvent( ev );
00273 if ( ev->attendeeCount() > 0 ) {
00274 emit deleteAttendee( ev );
00275 }
00276 delete(ev);
00277 }
00278
00279 #ifndef KORG_NORECURRENCE
00280 mRecurrence->writeEvent(event);
00281 #endif
00282 }
00283
00284 bool KOEventEditor::validateInput()
00285 {
00286 if (!mGeneral->validateInput()) return false;
00287 if (!mDetails->validateInput()) return false;
00288 #ifndef KORG_NORECURRENCE
00289 if (!mRecurrence->validateInput()) return false;
00290 #endif
00291 return true;
00292 }
00293
00294 int KOEventEditor::msgItemDelete()
00295 {
00296 return KMessageBox::warningContinueCancel(this,
00297 i18n("This item will be permanently deleted."),
00298 i18n("KOrganizer Confirmation"),i18n("Delete"));
00299 }
00300
00301 void KOEventEditor::slotLoadTemplate()
00302 {
00303 CalendarLocal cal;
00304 Event *event = new Event;
00305 QString templateName = loadTemplate( &cal, event->type(),
00306 KOPrefs::instance()->mEventTemplates );
00307 delete event;
00308 if ( templateName.isEmpty() ) {
00309 return;
00310 }
00311
00312 QPtrList<Event> events = cal.events();
00313 event = events.first();
00314 if ( !event ) {
00315 KMessageBox::error( this,
00316 i18n("Template does not contain a valid Event.")
00317 .arg( templateName ) );
00318 } else {
00319 kdDebug() << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
00320 readEvent( event, true );
00321 }
00322 }
00323
00324 void KOEventEditor::slotSaveTemplate()
00325 {
00326 createSaveTemplateDialog( SaveTemplateDialog::EventType );
00327 }
00328
00329 void KOEventEditor::saveTemplate( const QString &templateName )
00330 {
00331 Event *event = new Event;
00332 writeEvent( event );
00333 saveAsTemplate( event, templateName );
00334 }