korganizer
kojournaleditor.cpp00001
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 "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 void KOJournalEditor::newJournal( const QDate &date )
00110 {
00111 init();
00112
00113 mJournal = 0;
00114 setDefaults( date );
00115 }
00116
00117 void KOJournalEditor::newJournal( const QString &text )
00118 {
00119 init();
00120
00121 mJournal = 0;
00122
00123 loadDefaults();
00124
00125 mGeneral->setDescription( text );
00126
00127 int pos = text.find( "\n" );
00128 if ( pos > 0 ) {
00129 mGeneral->setSummary( text.left( pos ) );
00130 mGeneral->setDescription( text );
00131 } else {
00132 mGeneral->setSummary( text );
00133 }
00134 }
00135
00136 void KOJournalEditor::newJournal( const QString &text, const QDate &date )
00137 {
00138 init();
00139
00140 mJournal = 0;
00141
00142 loadDefaults();
00143
00144 mGeneral->setDescription( text );
00145 mGeneral->setDate( date );
00146 }
00147
00148 void KOJournalEditor::loadDefaults()
00149 {
00150 setDefaults( QDate::currentDate() );
00151 }
00152
00153 bool KOJournalEditor::processInput()
00154 {
00155 if ( !validateInput() ) return false;
00156
00157 if ( mJournal ) {
00158 Journal *oldJournal = mJournal->clone();
00159 writeJournal( mJournal );
00160 mChanger->changeIncidence( oldJournal, mJournal );
00161 delete oldJournal;
00162 } else {
00163 mJournal = new Journal;
00164 mJournal->setOrganizer( Person( KOPrefs::instance()->fullName(),
00165 KOPrefs::instance()->email() ) );
00166
00167 writeJournal( mJournal );
00168
00169 if ( !mChanger->addIncidence( mJournal ) ) {
00170 KODialogManager::errorSaveIncidence( this, mJournal );
00171 delete mJournal;
00172 mJournal = 0;
00173 return false;
00174 }
00175 }
00176
00177 return true;
00178 }
00179
00180 void KOJournalEditor::deleteJournal()
00181 {
00182 kdDebug(5850) << "Delete journal" << endl;
00183
00184 if ( mJournal )
00185 emit deleteIncidenceSignal( mJournal );
00186 emit dialogClose( mJournal );
00187 reject();
00188 }
00189
00190 void KOJournalEditor::setDefaults( const QDate &date )
00191 {
00192 mGeneral->setDefaults( date );
00193 mDetails->setDefaults();
00194 }
00195
00196 void KOJournalEditor::readJournal( Journal *journal )
00197 {
00198 kdDebug(5851)<<"read Journal"<<endl;
00199 mGeneral->readJournal( journal );
00200 mDetails->readEvent( journal );
00201 }
00202
00203 void KOJournalEditor::writeJournal( Journal *journal )
00204 {
00205 mGeneral->writeJournal( journal );
00206 mDetails->writeEvent( journal );
00207 }
00208
00209 bool KOJournalEditor::validateInput()
00210 {
00211 return mGeneral->validateInput() && mDetails->validateInput();
00212 }
00213
00214 int KOJournalEditor::msgItemDelete()
00215 {
00216 return KMessageBox::warningContinueCancel( this,
00217 i18n("This journal entry will be permanently deleted."),
00218 i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" ));
00219 }
00220
00221 void KOJournalEditor::modified( int )
00222 {
00223
00224
00225 reload();
00226 }
00227
00228 void KOJournalEditor::loadTemplate( CalendarLocal& cal)
00229 {
00230 Journal::List journals = cal.journals();
00231 if ( journals.count() == 0 ) {
00232 KMessageBox::error( this,
00233 i18n("Template does not contain a valid journal.") );
00234 } else {
00235 readJournal( journals.first() );
00236 }
00237 }
00238
00239 void KOJournalEditor::slotSaveTemplate( const QString &templateName )
00240 {
00241 Journal *journal = new Journal;
00242 writeJournal( journal );
00243 saveAsTemplate( journal, templateName );
00244 }
00245
00246 QStringList& KOJournalEditor::templates() const
00247 {
00248 return KOPrefs::instance()->mJournalTemplates;
00249 }
00250 #include "kojournaleditor.moc"
|