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 ) {
00067     readJournal( mJournal, QDate() );
00068   }
00069 }
00070 
00071 void KOJournalEditor::setupGeneral()
00072 {
00073   mGeneral = new KOEditorGeneralJournal(this);
00074 
00075   if (KOPrefs::instance()->mCompactDialogs) {
00076     QFrame *topFrame = addPage(i18n("General"));
00077 
00078     QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00079     topLayout->setMargin( marginHint() );
00080     topLayout->setSpacing( spacingHint() );
00081 
00082     mGeneral->initTitle( topFrame, topLayout );
00083     mGeneral->initDate( topFrame, topLayout );
00084     mGeneral->initDescription( topFrame, topLayout );
00085   } else {
00086     QFrame *topFrame = addPage(i18n("&General"));
00087 
00088     QBoxLayout *topLayout = new QVBoxLayout(topFrame);
00089     topLayout->setSpacing(spacingHint());
00090 
00091     mGeneral->initTitle( topFrame, topLayout );
00092     mGeneral->initDate( topFrame, topLayout );
00093     mGeneral->initDescription( topFrame, topLayout );
00094   }
00095 
00096   mGeneral->finishSetup();
00097 }
00098 
00099 void KOJournalEditor::editIncidence( Incidence *incidence, const QDate &date, Calendar * )
00100 {
00101   Journal *journal=dynamic_cast<Journal*>(incidence);
00102   if (journal)
00103   {
00104     init();
00105 
00106     mJournal = journal;
00107     readJournal(mJournal, date);
00108   }
00109 }
00110 
00111 
00112 void KOJournalEditor::newJournal()
00113 {
00114   init();
00115   mJournal = 0;
00116   loadDefaults();
00117 }
00118 
00119 void KOJournalEditor::setTexts( const QString &summary, const QString &description )
00120 {
00121   if ( description.isEmpty() && summary.contains("\n") ) {
00122     mGeneral->setDescription( summary );
00123     int pos = summary.find( "\n" );
00124     mGeneral->setSummary( summary.left( pos ) );
00125   } else {
00126     mGeneral->setSummary( summary );
00127     mGeneral->setDescription( description );
00128   }
00129 }
00130 
00131 
00132 
00133 void KOJournalEditor::loadDefaults()
00134 {
00135   setDate( QDate::currentDate() );
00136 }
00137 
00138 bool KOJournalEditor::processInput()
00139 {
00140   if ( !validateInput() ) return false;
00141 
00142   if ( mJournal ) {
00143     Journal *oldJournal = mJournal->clone();
00144     mJournal->startUpdates();
00145     writeJournal( mJournal );
00146     const bool success = mChanger->changeIncidence( oldJournal, mJournal, KOGlobals::NOTHING_MODIFIED, this );
00147     if ( success ) {
00148       mJournal->endUpdates();
00149     } else {
00150       mJournal->cancelUpdates();
00151     }
00152 
00153     delete oldJournal;
00154   } else {
00155     mJournal = new Journal;
00156     mJournal->setOrganizer( Person( KOPrefs::instance()->fullName(),
00157                             KOPrefs::instance()->email() ) );
00158 
00159     writeJournal( mJournal );
00160 
00161     if ( !mChanger->addIncidence( mJournal, mResource, mSubResource, this ) ) {
00162       delete mJournal;
00163       mJournal = 0;
00164       return false;
00165     }
00166   }
00167 
00168   return true;
00169 }
00170 
00171 void KOJournalEditor::deleteJournal()
00172 {
00173   kdDebug(5850) << "Delete journal" << endl;
00174 
00175   if ( mJournal )
00176     emit deleteIncidenceSignal( mJournal );
00177   emit dialogClose( mJournal );
00178   reject();
00179 }
00180 
00181 void KOJournalEditor::setDate( const QDate &date )
00182 {
00183   mGeneral->setDefaults( date );
00184   mDetails->setDefaults();
00185 }
00186 
00187 void KOJournalEditor::readJournal( Journal *journal, const QDate &date )
00188 {
00189   kdDebug(5851)<<"read Journal"<<endl;
00190   mGeneral->readJournal( journal, date );
00191   mDetails->readEvent( journal );
00192 }
00193 
00194 void KOJournalEditor::writeJournal( Journal *journal )
00195 {
00196   mGeneral->writeJournal( journal );
00197   mDetails->writeEvent( journal );
00198 }
00199 
00200 bool KOJournalEditor::validateInput()
00201 {
00202   return mGeneral->validateInput() && mDetails->validateInput();
00203 }
00204 
00205 int KOJournalEditor::msgItemDelete()
00206 {
00207   return KMessageBox::warningContinueCancel( this,
00208       i18n("This journal entry will be permanently deleted."),
00209       i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" ));
00210 }
00211 
00212 void KOJournalEditor::modified()
00213 {
00214   // Play dump, just reload the Journal. This dialog has become so complicated
00215   // that there is no point in trying to be smart here...
00216   reload();
00217 }
00218 
00219 void KOJournalEditor::loadTemplate( /*const*/ CalendarLocal& cal)
00220 {
00221   Journal::List journals = cal.journals();
00222   if ( journals.count() == 0 ) {
00223     KMessageBox::error( this,
00224         i18n("Template does not contain a valid journal.") );
00225   } else {
00226     readJournal( journals.first(), QDate() );
00227   }
00228 }
00229 
00230 void KOJournalEditor::slotSaveTemplate( const QString &templateName )
00231 {
00232   Journal *journal = new Journal;
00233   writeJournal( journal );
00234   saveAsTemplate( journal, templateName );
00235 }
00236 
00237 QStringList& KOJournalEditor::templates() const
00238 {
00239   return KOPrefs::instance()->mJournalTemplates;
00240 }
00241 #include "kojournaleditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys