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 <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 //  setupAlarmsTab();
00070   setupRecurrence();
00071   setupAttendeesTab();
00072   setupFreeBusy();
00073   setupAttachmentsTab();
00074   setupDesignerTabs( "event" );
00075 
00076   mDetails->setFreeBusyWidget( mFreeBusy );
00077 
00078   // Propagate date time settings to recurrence tab
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   // Propagate date time settings to gantt tab and back
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 //    QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout);
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 /*modification*/)
00161 {
00162   // Play dump, just reload the event. This dialog has become so complicated
00163   // that there is no point in trying to be smart here...
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   if ( mEvent ) {
00258     bool rc = true;
00259     Event *oldEvent = mEvent->clone();
00260     Event *event = mEvent->clone();
00261 
00262     kdDebug(5850) << "KOEventEditor::processInput() write event." << endl;
00263     writeEvent( event );
00264     kdDebug(5850) << "KOEventEditor::processInput() event written." << endl;
00265 
00266     if( *event == *mEvent )
00267       // Don't do anything
00268       kdDebug(5850) << "Event not changed\n";
00269     else {
00270       kdDebug(5850) << "Event changed\n";
00271       //IncidenceChanger::assignIncidence( mEvent, event );
00272       writeEvent( mEvent );
00273       mChanger->changeIncidence( oldEvent, mEvent );
00274     }
00275     delete event;
00276     delete oldEvent;
00277     return rc;
00278   } else {
00279     mEvent = new Event;
00280     mEvent->setOrganizer( Person( KOPrefs::instance()->fullName(),
00281                           KOPrefs::instance()->email() ) );
00282     writeEvent( mEvent );
00283     if ( !mChanger->addIncidence( mEvent, this ) ) {
00284       delete mEvent;
00285       mEvent = 0;
00286       return false;
00287     }
00288   }
00289 
00290   if ( mFreeBusy ) mFreeBusy->cancelReload();
00291 
00292   return true;
00293 }
00294 
00295 void KOEventEditor::processCancel()
00296 {
00297   kdDebug(5850) << "KOEventEditor::processCancel()" << endl;
00298 
00299   if ( mFreeBusy ) mFreeBusy->cancelReload();
00300 }
00301 
00302 void KOEventEditor::deleteEvent()
00303 {
00304   kdDebug(5850) << "Delete event" << endl;
00305 
00306   if ( mEvent )
00307     emit deleteIncidenceSignal( mEvent );
00308   emit dialogClose( mEvent );
00309   reject();
00310 }
00311 
00312 void KOEventEditor::readEvent( Event *event, bool tmpl )
00313 {
00314   mGeneral->readEvent( event, tmpl );
00315   mDetails->readEvent( event );
00316   mRecurrence->readIncidence( event );
00317   mAttachments->readIncidence( event );
00318 //  mAlarms->readIncidence( event );
00319   if ( mFreeBusy ) {
00320     mFreeBusy->readEvent( event );
00321     mFreeBusy->triggerReload();
00322   }
00323 
00324   createEmbeddedURLPages( event );
00325   readDesignerFields( event );
00326 }
00327 
00328 void KOEventEditor::writeEvent( Event *event )
00329 {
00330   mGeneral->writeEvent( event );
00331   mDetails->writeEvent( event );
00332   mAttachments->writeIncidence( event );
00333 
00334   cancelRemovedAttendees( event );
00335 
00336   mRecurrence->writeIncidence( event );
00337 
00338   writeDesignerFields( event );
00339 }
00340 
00341 bool KOEventEditor::validateInput()
00342 {
00343   if ( !mGeneral->validateInput() ) return false;
00344   if ( !mDetails->validateInput() ) return false;
00345   if ( !mRecurrence->validateInput() ) return false;
00346 
00347   return true;
00348 }
00349 
00350 int KOEventEditor::msgItemDelete()
00351 {
00352   return KMessageBox::warningContinueCancel(this,
00353       i18n("This item will be permanently deleted."),
00354       i18n("KOrganizer Confirmation"),KGuiItem(i18n("Delete"),"editdelete"));
00355 }
00356 
00357 void KOEventEditor::loadTemplate( /*const*/ CalendarLocal& cal )
00358 {
00359   const Event::List events = cal.events();
00360   if ( events.count() == 0 ) {
00361     KMessageBox::error( this,
00362         i18n("Template does not contain a valid event.") );
00363   } else {
00364     kdDebug(5850) << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl;
00365     readEvent( events.first(), true );
00366   }
00367 }
00368 
00369 QStringList& KOEventEditor::templates() const
00370 {
00371   return KOPrefs::instance()->mEventTemplates;
00372 }
00373 
00374 void KOEventEditor::slotSaveTemplate( const QString &templateName )
00375 {
00376   kdDebug(5006) << "SlotSaveTemplate" << endl;
00377   Event *event = new Event;
00378   writeEvent( event );
00379   saveAsTemplate( event, templateName );
00380 }
00381 
00382 QObject *KOEventEditor::typeAheadReceiver() const
00383 {
00384   return mGeneral->typeAheadReceiver();
00385 }
00386 
00387 #include "koeventeditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys