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
#include <qtooltip.h>
00026
#include <qframe.h>
00027
#include <qpixmap.h>
00028
#include <qlayout.h>
00029
#include <qwidgetstack.h>
00030
00031
#include <kabc/addressee.h>
00032
#include <kiconloader.h>
00033
#include <kdebug.h>
00034
#include <klocale.h>
00035
#include <kmessagebox.h>
00036
#include <libkcal/calendarresources.h>
00037
#include <libkcal/resourcecalendar.h>
00038
00039
#include <libkdepim/categoryselectdialog.h>
00040
#include <libkcal/calendarlocal.h>
00041
00042
#include "koprefs.h"
00043
#include "koeditorgeneralevent.h"
00044
#include "koeditorrecurrence.h"
00045
#include "koeditordetails.h"
00046
#include "koeditorattachments.h"
00047
#include "koeditorfreebusy.h"
00048
#include "kogroupware.h"
00049
#include "kodialogmanager.h"
00050
00051
#include "koeventeditor.h"
00052
00053 KOEventEditor::KOEventEditor( Calendar *calendar,
QWidget *parent )
00054 :
KOIncidenceEditor( i18n(
"Edit Event"), calendar, parent ),
00055 mEvent( 0 )
00056 {
00057 }
00058
00059 KOEventEditor::~KOEventEditor()
00060 {
00061 emit dialogClose( mEvent );
00062 }
00063
00064 void KOEventEditor::init()
00065 {
00066 setupGeneral();
00067 setupAttendeesTab();
00068 setupRecurrence();
00069 setupAttachmentsTab();
00070 setupFreeBusy();
00071 mDetails->setFreeBusyWidget( mFreeBusy );
00072
00073
00074 connect( mGeneral, SIGNAL( dateTimesChanged(
QDateTime,
QDateTime ) ),
00075 mRecurrence, SLOT( setDateTimes(
QDateTime,
QDateTime ) ) );
00076 connect( mGeneral, SIGNAL( dateTimeStrChanged(
const QString & ) ),
00077 mRecurrence, SLOT( setDateTimeStr(
const QString & ) ) );
00078 connect( mFreeBusy, SIGNAL( dateTimesChanged(
QDateTime,
QDateTime ) ),
00079 mRecurrence, SLOT( setDateTimes(
QDateTime,
QDateTime ) ) );
00080
00081
00082 connect( mGeneral, SIGNAL( dateTimesChanged(
QDateTime,
QDateTime ) ),
00083 mFreeBusy, SLOT( slotUpdateGanttView(
QDateTime,
QDateTime ) ) );
00084 connect( mFreeBusy, SIGNAL( dateTimesChanged(
QDateTime,
QDateTime ) ),
00085 mGeneral, SLOT( setDateTimes(
QDateTime,
QDateTime ) ) );
00086
00087
00088 connect( mGeneral, SIGNAL( openCategoryDialog() ),
00089 mCategoryDialog, SLOT( show() ) );
00090 connect( mCategoryDialog, SIGNAL( categoriesSelected(
const QString & ) ),
00091 mGeneral, SLOT( setCategories(
const QString & ) ) );
00092
00093 connect( mGeneral, SIGNAL( focusReceivedSignal() ),
00094 SIGNAL( focusReceivedSignal() ) );
00095 }
00096
00097
void KOEventEditor::reload()
00098 {
00099 kdDebug() <<
"KOEventEditor::reload()" << endl;
00100
00101
if ( mEvent )
readEvent( mEvent );
00102 }
00103
00104
void KOEventEditor::setupGeneral()
00105 {
00106 mGeneral =
new KOEditorGeneralEvent(
this );
00107
00108
if( KOPrefs::instance()->mCompactDialogs ) {
00109
QFrame *topFrame = addPage(i18n(
"General"));
00110
00111
QBoxLayout *topLayout =
new QVBoxLayout(topFrame);
00112 topLayout->
setSpacing(spacingHint());
00113
00114 mGeneral->initHeader(topFrame,topLayout);
00115 mGeneral->initTime(topFrame,topLayout);
00116
00117 mGeneral->initAlarm(topFrame,topLayout);
00118 mGeneral->enableAlarm(
false );
00119 mGeneral->initCategories( topFrame, topLayout );
00120
00121 topLayout->addStretch( 1 );
00122
00123
QFrame *topFrame2 = addPage(i18n(
"Details"));
00124
00125
QBoxLayout *topLayout2 =
new QVBoxLayout(topFrame2);
00126 topLayout2->
setSpacing(spacingHint());
00127
00128 mGeneral->initClass(topFrame2,topLayout2);
00129 mGeneral->initSecrecy( topFrame2, topLayout2 );
00130 mGeneral->initDescription(topFrame2,topLayout2);
00131 }
else {
00132
QFrame *topFrame = addPage(i18n(
"&General"));
00133
00134
QBoxLayout *topLayout =
new QVBoxLayout(topFrame);
00135 topLayout->
setSpacing(spacingHint());
00136
00137 mGeneral->initHeader(topFrame,topLayout);
00138 mGeneral->initTime(topFrame,topLayout);
00139
QBoxLayout *alarmLineLayout =
new QHBoxLayout(topLayout);
00140 mGeneral->initAlarm(topFrame,alarmLineLayout);
00141 mGeneral->initClass(topFrame,alarmLineLayout);
00142 mGeneral->initDescription(topFrame,topLayout);
00143
QBoxLayout *detailsLayout =
new QHBoxLayout(topLayout);
00144 mGeneral->initCategories( topFrame, detailsLayout );
00145 mGeneral->initSecrecy( topFrame, detailsLayout );
00146 }
00147
00148 mGeneral->finishSetup();
00149 }
00150
00151 void KOEventEditor::modified (
int )
00152 {
00153
00154
00155 reload();
00156 }
00157
00158
void KOEventEditor::setupRecurrence()
00159 {
00160
QFrame *topFrame = addPage( i18n(
"Rec&urrence") );
00161
00162
QBoxLayout *topLayout =
new QVBoxLayout( topFrame );
00163
00164 mRecurrence =
new KOEditorRecurrence( topFrame );
00165 topLayout->
addWidget( mRecurrence );
00166 }
00167
00168
void KOEventEditor::setupFreeBusy()
00169 {
00170
QFrame *freeBusyPage = addPage( i18n(
"&Free/Busy") );
00171
00172
QBoxLayout *topLayout =
new QVBoxLayout( freeBusyPage );
00173
00174 mFreeBusy =
new KOEditorFreeBusy( spacingHint(), freeBusyPage );
00175 topLayout->
addWidget( mFreeBusy );
00176 }
00177
00178 void KOEventEditor::editIncidence(Incidence *incidence)
00179 {
00180 Event*event = dynamic_cast<Event*>(incidence);
00181
if (event) {
00182
init();
00183
00184 mEvent = event;
00185
readEvent(mEvent);
00186 }
00187 }
00188
00189 void KOEventEditor::newEvent(
QDateTime from,
QDateTime to,
bool allDay )
00190 {
00191
init();
00192
00193 mEvent = 0;
00194
setDefaults(from,to,allDay);
00195 }
00196
00197 void KOEventEditor::newEvent(
const QString &text )
00198 {
00199
init();
00200
00201 mEvent = 0;
00202
00203 loadDefaults();
00204
00205 mGeneral->setDescription( text );
00206
00207
int pos = text.find(
"\n" );
00208
if ( pos > 0 ) {
00209 mGeneral->setSummary( text.left( pos ) );
00210 mGeneral->setDescription( text );
00211 }
else {
00212 mGeneral->setSummary( text );
00213 }
00214 }
00215
00216 void KOEventEditor::newEvent(
const QString &summary,
00217
const QString &description,
00218
const QString &attachment )
00219 {
00220
init();
00221
00222 mEvent = 0;
00223
00224 loadDefaults();
00225
00226 mGeneral->setSummary( summary );
00227 mGeneral->setDescription( description );
00228
00229
if ( !attachment.isEmpty() ) {
00230 mAttachments->addAttachment( attachment );
00231 }
00232 }
00233
00234 void KOEventEditor::newEvent(
const QString &summary,
00235
const QString &description,
00236
const QString &attachment,
00237
const QStringList &attendees )
00238 {
00239
newEvent( summary, description, attachment );
00240
00241 QStringList::ConstIterator it;
00242
for ( it = attendees.begin(); it != attendees.end(); ++it ) {
00243
QString name, email;
00244 KABC::Addressee::parseEmailAddress( *it, name, email );
00245 mDetails->insertAttendee(
new Attendee( name, email ) );
00246 }
00247 }
00248
00249
void KOEventEditor::loadDefaults()
00250 {
00251
QTime defaultDuration( KOPrefs::instance()->mDefaultDuration.time() );
00252
00253
QDateTime from(QDate::currentDate(), KOPrefs::instance()->mStartTime.time() );
00254
QDateTime to( from.addSecs(defaultDuration.hour()*3600 +
00255 defaultDuration.minute()*60 + defaultDuration.second()) );
00256
00257
setDefaults(from,to,
false);
00258 }
00259
00260
00261 bool KOEventEditor::processInput()
00262 {
00263 kdDebug(5850) <<
"KOEventEditor::processInput()" << endl;
00264
00265
if ( !
validateInput() )
return false;
00266
00267
if ( mEvent ) {
00268
bool rc =
true;
00269 Event *event = mEvent->clone();
00270 Event *oldEvent = mEvent->clone();
00271 kdDebug(5850) <<
"KOEventEditor::processInput() write event." << endl;
00272
writeEvent( event );
00273 kdDebug(5850) <<
"KOEventEditor::processInput() event written." << endl;
00274
00275
if( *mEvent == *event )
00276
00277 kdDebug(5850) <<
"Event not changed\n";
00278
else {
00279 kdDebug(5850) <<
"Event changed\n";
00280
int revision = event->revision();
00281 event->setRevision( revision + 1 );
00282
if( !KOPrefs::instance()->mUseGroupwareCommunication ||
00283 KOGroupware::instance()->sendICalMessage(
this,
00284 KCal::Scheduler::Request,
00285 event ) ) {
00286
00287
writeEvent( mEvent );
00288 mEvent->setRevision( revision + 1 );
00289 emit incidenceChanged( oldEvent, mEvent );
00290 }
else {
00291
00292 event->setRevision( revision );
00293 rc =
false;
00294 }
00295 }
00296
delete event;
00297
delete oldEvent;
00298
return rc;
00299 }
else {
00300 mEvent =
new Event;
00301 mEvent->setOrganizer( KOPrefs::instance()->email() );
00302
writeEvent( mEvent );
00303
if ( KOPrefs::instance()->mUseGroupwareCommunication ) {
00304
if ( !KOGroupware::instance()->sendICalMessage(
this,
00305 KCal::Scheduler::Request,
00306 mEvent ) ) {
00307 kdError() <<
"sendIcalMessage failed." << endl;
00308 }
00309 }
00310
if ( mCalendar->addEvent( mEvent ) ) {
00311 emit incidenceAdded( mEvent );
00312 }
else {
00313 KODialogManager::errorSaveEvent(
this );
00314
delete mEvent;
00315 mEvent = 0;
00316
return false;
00317 }
00318 }
00319
00320
if ( mFreeBusy ) mFreeBusy->cancelReload();
00321
00322
return true;
00323 }
00324
00325
void KOEventEditor::processCancel()
00326 {
00327 kdDebug() <<
"KOEventEditor::processCancel()" << endl;
00328
00329
if ( mEvent ) {
00330 emit editCanceled( mEvent );
00331 }
00332
00333
if ( mFreeBusy ) mFreeBusy->cancelReload();
00334 }
00335
00336
void KOEventEditor::deleteEvent()
00337 {
00338 kdDebug(5850) <<
"Delete event" << endl;
00339
00340
if (mEvent) {
00341
bool groupwareCheck = KOPrefs::instance()->mConfirm &&
00342 (!KOPrefs::instance()->mUseGroupwareCommunication ||
00343 KOPrefs::instance()->thatIsMe( mEvent->organizer() ) );
00344
if (!groupwareCheck || (msgItemDelete()==KMessageBox::Continue)) {
00345
00346 emit incidenceToBeDeleted(mEvent);
00347 emit dialogClose(mEvent);
00348 mCalendar->deleteEvent(mEvent);
00349 emit incidenceDeleted(mEvent);
00350 reject();
00351 }
00352 }
else {
00353 reject();
00354 }
00355 }
00356
00357 void KOEventEditor::setDefaults(
QDateTime from,
QDateTime to,
bool allDay )
00358 {
00359 mGeneral->setDefaults( from, to, allDay );
00360 mDetails->setDefaults();
00361 mAttachments->setDefaults();
00362 mRecurrence->setDefaults( from, to, allDay );
00363
if( mFreeBusy ) {
00364
if ( allDay )
00365 mFreeBusy->setDateTimes( from, to.addDays( 1 ) );
00366
else
00367 mFreeBusy->setDateTimes( from, to );
00368 }
00369 }
00370
00371 void KOEventEditor::readEvent( Event *event,
bool tmpl )
00372 {
00373 mGeneral->readEvent( event, tmpl );
00374 mDetails->readEvent( event );
00375 mRecurrence->readIncidence( event );
00376 mAttachments->readIncidence( event );
00377
if( mFreeBusy ) {
00378 mFreeBusy->readEvent( event );
00379 mFreeBusy->triggerReload();
00380 }
00381
00382
00383 mCategoryDialog->setSelected( event->categories() );
00384 }
00385
00386 void KOEventEditor::writeEvent( Event *event )
00387 {
00388 mGeneral->writeEvent( event );
00389 mDetails->writeEvent( event );
00390 mAttachments->writeIncidence( event );
00391
00392 cancelRemovedAttendees( event );
00393
00394 mRecurrence->writeIncidence( event );
00395 }
00396
00397 bool KOEventEditor::validateInput()
00398 {
00399
if ( !mGeneral->validateInput() )
return false;
00400
if ( !mDetails->validateInput() )
return false;
00401
if ( !mRecurrence->validateInput() )
return false;
00402
00403
return true;
00404 }
00405
00406
int KOEventEditor::msgItemDelete()
00407 {
00408
return KMessageBox::warningContinueCancel(
this,
00409 i18n(
"This item will be permanently deleted."),
00410 i18n(
"KOrganizer Confirmation"),KGuiItem(i18n(
"Delete"),
"editdelete"));
00411 }
00412
00413
void KOEventEditor::slotLoadTemplate()
00414 {
00415 CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00416 Event *event =
new Event;
00417
QString templateName = loadTemplate( &cal, event->type(),
00418 KOPrefs::instance()->mEventTemplates );
00419
delete event;
00420
if ( templateName.isEmpty() ) {
00421
return;
00422 }
00423
00424 Event::List events = cal.events();
00425
if ( events.count() == 0 ) {
00426 KMessageBox::error(
this,
00427 i18n(
"Template does not contain a valid event.")
00428 .arg( templateName ) );
00429 }
else {
00430 kdDebug(5850) <<
"KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
00431
readEvent( events.first(),
true );
00432 }
00433 }
00434
00435
void KOEventEditor::saveTemplate(
const QString &templateName )
00436 {
00437 Event *event =
new Event;
00438
writeEvent( event );
00439 saveAsTemplate( event, templateName );
00440 }
00441
00442
QObject *KOEventEditor::typeAheadReceiver()
const
00443
{
00444
return mGeneral->typeAheadReceiver();
00445 }
00446
00447
#include "koeventeditor.moc"