korganizer

kojournaleditor.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 1997, 1998 Preston Brown <pbrown@kde.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "koeditordetails.h"
00031 #include "kodialogmanager.h"
00032 #include "koprefs.h"
00033 
00034 #include <libkcal/journal.h>
00035 #include <libkcal/calendarlocal.h>
00036 #include <korganizer/baseview.h>
00037 
00038 #include <kmessagebox.h>
00039 #include <klocale.h>
00040 #include <kdebug.h>
00041 
00042 #include <qlayout.h>
00043 
00044 using namespace KCal;
00045 
00046 KOJournalEditor::KOJournalEditor( Calendar *calendar, QWidget *parent ) :
00047   KOIncidenceEditor( i18n("Edit Journal Entry"), calendar, parent )
00048 {
00049   mJournal = 0;
00050 }
00051 
00052 KOJournalEditor::~KOJournalEditor()
00053 {
00054   emit dialogClose( mJournal );
00055 }
00056 
00057 void KOJournalEditor::init()
00058 {
00059   setupGeneral();
00060   setupAttendeesTab();
00061 }
00062 
00063 void KOJournalEditor::reload()
00064 {
00065   kdDebug(5851)<<"reloading Journal"<<endl;
00066   if ( mJournal ) readJournal( mJournal );
00067 }
00068 
00069 void KOJournalEditor::setupGeneral()
00070 {
00071   mGeneral = new KOEditorGeneralJournal(this);
00072 
00073   if (KOPrefs::instance()->mCompactDialogs) {
00074     QFrame *topFrame = addPage(i18n("General"));
00075 
00076     QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00077     topLayout->setMargin( marginHint() );
00078     topLayout->setSpacing( spacingHint() );
00079 
00080     mGeneral->initTitle( topFrame, topLayout );
00081     mGeneral->initDate( topFrame, topLayout );
00082     mGeneral->initDescription( topFrame, topLayout );
00083   } else {
00084     QFrame *topFrame = addPage(i18n("&General"));
00085 
00086     QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00087     topLayout->setSpacing(spacingHint());
00088 
00089     mGeneral->initTitle( topFrame, topLayout );
00090     mGeneral->initDate( topFrame, topLayout );
00091     mGeneral->initDescription( topFrame, topLayout );
00092   }
00093 
00094   mGeneral->finishSetup();
00095 }
00096 
00097 void KOJournalEditor::editIncidence( Incidence *incidence )
00098 {
00099   Journal *journal=dynamic_cast<Journal*>(incidence);
00100   if (journal)
00101   {
00102     init();
00103 
00104     mJournal = journal;
00105     readJournal(mJournal);
00106   }
00107 }
00108 
00109 
00110 void KOJournalEditor::newJournal()
00111 {
00112   init();
00113   mJournal = 0;
00114   loadDefaults();
00115 }
00116 
00117 void KOJournalEditor::setTexts( const QString &summary, const QString &description )
00118 {
00119   if ( description.isEmpty() && summary.contains("\n") ) {
00120     mGeneral->setDescription( summary );
00121     int pos = summary.find( "\n" );
00122     mGeneral->setSummary( summary.left( pos ) );
00123   } else {
00124     mGeneral->setSummary( summary );
00125     mGeneral->setDescription( description );
00126   }
00127 }
00128 
00129 
00130 
00131 void KOJournalEditor::loadDefaults()
00132 {
00133   setDate( QDate::currentDate() );
00134 }
00135 
00136 bool KOJournalEditor::processInput()
00137 {
00138   if ( !validateInput() ) return false;
00139 
00140   if ( mJournal ) {
00141     Journal *oldJournal = mJournal->clone();
00142     writeJournal( mJournal );
00143     mChanger->changeIncidence( oldJournal, mJournal );
00144     delete oldJournal;
00145   } else {
00146     mJournal = new Journal;
00147     mJournal->setOrganizer( Person( KOPrefs::instance()->fullName(),
00148                             KOPrefs::instance()->email() ) );
00149 
00150     writeJournal( mJournal );
00151 
00152     if ( !mChanger->addIncidence( mJournal, this ) ) {
00153       KODialogManager::errorSaveIncidence( this, mJournal );
00154       delete mJournal;
00155       mJournal = 0;
00156       return false;
00157     }
00158   }
00159 
00160   return true;
00161 }
00162 
00163 void KOJournalEditor::deleteJournal()
00164 {
00165   kdDebug(5850) << "Delete journal" << endl;
00166 
00167   if ( mJournal )
00168     emit deleteIncidenceSignal( mJournal );
00169   emit dialogClose( mJournal );
00170   reject();
00171 }
00172 
00173 void KOJournalEditor::setDate( const QDate &date )
00174 {
00175   mGeneral->setDefaults( date );
00176   mDetails->setDefaults();
00177 }
00178 
00179 void KOJournalEditor::readJournal( Journal *journal )
00180 {
00181   kdDebug(5851)<<"read Journal"<<endl;
00182   mGeneral->readJournal( journal );
00183   mDetails->readEvent( journal );
00184 }
00185 
00186 void KOJournalEditor::writeJournal( Journal *journal )
00187 {
00188   mGeneral->writeJournal( journal );
00189   mDetails->writeEvent( journal );
00190 }
00191 
00192 bool KOJournalEditor::validateInput()
00193 {
00194   return mGeneral->validateInput() && mDetails->validateInput();
00195 }
00196 
00197 int KOJournalEditor::msgItemDelete()
00198 {
00199   return KMessageBox::warningContinueCancel( this,
00200       i18n("This journal entry will be permanently deleted."),
00201       i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" ));
00202 }
00203 
00204 void KOJournalEditor::modified( int /*modification*/)
00205 {
00206   // Play dump, just reload the Journal. This dialog has become so complicated that
00207   // there is no point in trying to be smart here...
00208   reload();
00209 }
00210 
00211 void KOJournalEditor::loadTemplate( /*const*/ CalendarLocal& cal)
00212 {
00213   Journal::List journals = cal.journals();
00214   if ( journals.count() == 0 ) {
00215     KMessageBox::error( this,
00216         i18n("Template does not contain a valid journal.") );
00217   } else {
00218     readJournal( journals.first() );
00219   }
00220 }
00221 
00222 void KOJournalEditor::slotSaveTemplate( const QString &templateName )
00223 {
00224   Journal *journal = new Journal;
00225   writeJournal( journal );
00226   saveAsTemplate( journal, templateName );
00227 }
00228 
00229 QStringList& KOJournalEditor::templates() const
00230 {
00231   return KOPrefs::instance()->mJournalTemplates;
00232 }
00233 #include "kojournaleditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys