korganizer Library API Documentation

kojournaleditor.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 1997, 1998 Preston Brown
00005     Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
00006     Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>      
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022     As a special exception, permission is given to link this program
00023     with any edition of Qt, and distribute the resulting executable,
00024     without including the source code for Qt in the source distribution.
00025 */
00026 
00027 #include "kojournaleditor.h"
00028 
00029 #include "koeditorgeneraljournal.h"
00030 #include "kodialogmanager.h"
00031 #include "koprefs.h"
00032 
00033 #include <libkcal/journal.h>
00034 #include <libkcal/calendarlocal.h>
00035 
00036 #include <kmessagebox.h>
00037 #include <klocale.h>
00038 #include <kdebug.h>
00039 
00040 #include <qlayout.h>
00041 
00042 using namespace KCal;
00043 
00044 KOJournalEditor::KOJournalEditor( Calendar *calendar, QWidget *parent ) :
00045   KOIncidenceEditor( i18n("Edit Journal"), calendar, parent )
00046 {
00047   mJournal = 0;
00048 }
00049 
00050 KOJournalEditor::~KOJournalEditor()
00051 {
00052   emit dialogClose( mJournal );
00053 }
00054 
00055 void KOJournalEditor::init()
00056 {
00057   setupGeneral();
00058 }
00059 
00060 void KOJournalEditor::reload()
00061 {
00062   kdDebug(5851)<<"reloading Journal"<<endl;
00063   if ( mJournal ) readJournal( mJournal );
00064 }
00065 
00066 void KOJournalEditor::setupGeneral()
00067 {
00068   mGeneral = new KOEditorGeneralJournal(this);
00069 
00070   if (KOPrefs::instance()->mCompactDialogs) {
00071     QFrame *topFrame = addPage(i18n("General"));
00072 
00073     QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00074     topLayout->setMargin( marginHint() );
00075     topLayout->setSpacing( spacingHint() );
00076 
00077     mGeneral->initDate( topFrame, topLayout );
00078     mGeneral->initDescription( topFrame, topLayout );
00079   } else {
00080     QFrame *topFrame = addPage(i18n("&General"));
00081 
00082     QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00083     topLayout->setSpacing(spacingHint());
00084 
00085     mGeneral->initDate( topFrame, topLayout );
00086     mGeneral->initDescription( topFrame, topLayout );
00087   }
00088 
00089   mGeneral->finishSetup();
00090 }
00091 
00092 void KOJournalEditor::editIncidence( Incidence *incidence )
00093 {
00094   Journal *journal=dynamic_cast<Journal*>(incidence);
00095   if (journal)
00096   {
00097     init();
00098 
00099     mJournal = journal;
00100     readJournal(mJournal);
00101   }
00102 }
00103 
00104 void KOJournalEditor::newJournal( QDate date )
00105 {
00106   init();
00107 
00108   mJournal = 0;
00109   setDefaults( date );
00110 }
00111 
00112 void KOJournalEditor::newJournal( const QString &text )
00113 {
00114   init();
00115 
00116   mJournal = 0;
00117 
00118   loadDefaults();
00119 
00120   mGeneral->setDescription( text );
00121 }
00122 
00123 void KOJournalEditor::newJournal( const QString &text, QDate date )
00124 {
00125   init();
00126 
00127   mJournal = 0;
00128 
00129   loadDefaults();
00130 
00131   mGeneral->setDescription( text );
00132     mGeneral->setDate( date );
00133 }
00134 
00135 void KOJournalEditor::loadDefaults()
00136 {
00137   setDefaults( QDate::currentDate() );
00138 }
00139 
00140 // TODO_RK: make sure calendar()->endChange is called somewhere!
00141 bool KOJournalEditor::processInput()
00142 {
00143   if ( !validateInput() ) return false;
00144 
00145   if ( mJournal ) {
00146     Journal *oldJournal = mJournal->clone();
00147 
00148     writeJournal( mJournal );
00149 
00150     mJournal->setRevision( mJournal->revision() + 1 );
00151 
00152     emit incidenceChanged( oldJournal, mJournal );
00153 
00154     delete oldJournal;
00155   } else {
00156     mJournal = new Journal;
00157 //    mJournal->setOrganizer( KOPrefs::instance()->email() );
00158     mJournal->setOrganizer( Person( KOPrefs::instance()->fullName(), 
00159                             KOPrefs::instance()->email() ) );
00160 
00161     writeJournal( mJournal );
00162 
00163     if ( !mCalendar->addJournal( mJournal ) ) {
00164       KODialogManager::errorSaveJournal( this );
00165       delete mJournal;
00166       mJournal = 0;
00167       return false;
00168     }
00169 
00170     emit incidenceAdded( mJournal );
00171   }
00172 
00173   return true;
00174 }
00175 
00176 void KOJournalEditor::processCancel()
00177 {
00178   if ( mJournal ) {
00179     emit editCanceled( mJournal );
00180   }
00181 }
00182 
00183 void KOJournalEditor::deleteJournal()
00184 {
00185   if ( mJournal ) {
00186     if ( KOPrefs::instance()->mConfirm ) {
00187       switch ( msgItemDelete() ) {
00188         case KMessageBox::Continue: // OK
00189           emit incidenceToBeDeleted( mJournal );
00190           emit dialogClose( mJournal );
00191           mCalendar->deleteJournal( mJournal );
00192           emit incidenceDeleted( mJournal );
00193           reject();
00194           break;
00195       }
00196     }
00197     else {
00198       emit incidenceToBeDeleted( mJournal );
00199       emit dialogClose( mJournal );
00200       mCalendar->deleteJournal( mJournal );
00201       emit incidenceDeleted( mJournal );
00202       reject();
00203     }
00204   } else {
00205     reject();
00206   }
00207 }
00208 
00209 void KOJournalEditor::setDefaults( QDate date )
00210 {
00211   mGeneral->setDefaults( date );
00212 }
00213 
00214 void KOJournalEditor::readJournal( Journal *journal )
00215 {
00216   kdDebug(5851)<<"read Journal"<<endl;
00217   mGeneral->readJournal( journal );
00218 }
00219 
00220 void KOJournalEditor::writeJournal( Journal *journal )
00221 {
00222   mGeneral->writeJournal( journal );
00223 }
00224 
00225 bool KOJournalEditor::validateInput()
00226 {
00227   return mGeneral->validateInput();
00228 }
00229 
00230 int KOJournalEditor::msgItemDelete()
00231 {
00232   return KMessageBox::warningContinueCancel( this,
00233       i18n("This journal entry will be permanently deleted."),
00234       i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" ));
00235 }
00236 
00237 void KOJournalEditor::modified( int /*modification*/)
00238 {
00239   // Play dump, just reload the Journal. This dialog has become so complicated that
00240   // there is no point in trying to be smart here...
00241   reload();
00242 }
00243 
00244 void KOJournalEditor::slotLoadTemplate()
00245 {
00246   CalendarLocal cal( KOPrefs::instance()->mTimeZoneId );
00247   Journal *journal = new Journal;
00248   QString templateName = loadTemplate( &cal, journal->type(),
00249                                        KOPrefs::instance()->mJournalTemplates );
00250   delete journal;
00251   if ( templateName.isEmpty() ) {
00252     return;
00253   }
00254 
00255   Journal::List journals = cal.journals();
00256   if ( journals.count() == 0 ) {
00257     KMessageBox::error( this,
00258         i18n("Template '%1' does not contain a valid journal.")
00259         .arg( templateName ) );
00260   } else {
00261     readJournal( journals.first() );
00262   }
00263 }
00264 
00265 void KOJournalEditor::saveTemplate( const QString &templateName )
00266 {
00267   Journal *journal = new Journal;
00268   writeJournal( journal );
00269   saveAsTemplate( journal, templateName );
00270 }
00271 
00272 #include "kojournaleditor.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:45:25 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003