kojournaleditor.cpp
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
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
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
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:
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 )
00238 {
00239
00240
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"
This file is part of the documentation for korganizer Library Version 3.3.2.