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 ) {
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 writeJournal( mJournal );
00145 mChanger->changeIncidence( oldJournal, mJournal, KOGlobals::NOTHING_MODIFIED, this );
00146 delete oldJournal;
00147 } else {
00148 mJournal = new Journal;
00149 mJournal->setOrganizer( Person( KOPrefs::instance()->fullName(),
00150 KOPrefs::instance()->email() ) );
00151
00152 writeJournal( mJournal );
00153
00154 if ( !mChanger->addIncidence( mJournal, mResource, mSubResource, this ) ) {
00155 delete mJournal;
00156 mJournal = 0;
00157 return false;
00158 }
00159 }
00160
00161 return true;
00162 }
00163
00164 void KOJournalEditor::deleteJournal()
00165 {
00166 kdDebug(5850) << "Delete journal" << endl;
00167
00168 if ( mJournal )
00169 emit deleteIncidenceSignal( mJournal );
00170 emit dialogClose( mJournal );
00171 reject();
00172 }
00173
00174 void KOJournalEditor::setDate( const QDate &date )
00175 {
00176 mGeneral->setDefaults( date );
00177 mDetails->setDefaults();
00178 }
00179
00180 void KOJournalEditor::readJournal( Journal *journal, const QDate &date )
00181 {
00182 kdDebug(5851)<<"read Journal"<<endl;
00183 mGeneral->readJournal( journal, date );
00184 mDetails->readEvent( journal );
00185 }
00186
00187 void KOJournalEditor::writeJournal( Journal *journal )
00188 {
00189 mGeneral->writeJournal( journal );
00190 mDetails->writeEvent( journal );
00191 }
00192
00193 bool KOJournalEditor::validateInput()
00194 {
00195 return mGeneral->validateInput() && mDetails->validateInput();
00196 }
00197
00198 int KOJournalEditor::msgItemDelete()
00199 {
00200 return KMessageBox::warningContinueCancel( this,
00201 i18n("This journal entry will be permanently deleted."),
00202 i18n("KOrganizer Confirmation"), KGuiItem( i18n("Delete"), "editdelete" ));
00203 }
00204
00205 void KOJournalEditor::modified()
00206 {
00207
00208
00209 reload();
00210 }
00211
00212 void KOJournalEditor::loadTemplate( CalendarLocal& cal)
00213 {
00214 Journal::List journals = cal.journals();
00215 if ( journals.count() == 0 ) {
00216 KMessageBox::error( this,
00217 i18n("Template does not contain a valid journal.") );
00218 } else {
00219 readJournal( journals.first(), QDate() );
00220 }
00221 }
00222
00223 void KOJournalEditor::slotSaveTemplate( const QString &templateName )
00224 {
00225 Journal *journal = new Journal;
00226 writeJournal( journal );
00227 saveAsTemplate( journal, templateName );
00228 }
00229
00230 QStringList& KOJournalEditor::templates() const
00231 {
00232 return KOPrefs::instance()->mJournalTemplates;
00233 }
00234 #include "kojournaleditor.moc"
|