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 <qlabel.h>
00028
#include <qlayout.h>
00029
00030
#include <kdebug.h>
00031
#include <kglobal.h>
00032
#include <klocale.h>
00033
#include <ktextedit.h>
00034
00035
#include <libkcal/journal.h>
00036
#include <libkcal/calendar.h>
00037
00038
#include "kodialogmanager.h"
00039
00040
#include "journalentry.h"
00041
#include "journalentry.moc"
00042
00043 JournalEntry::JournalEntry(Calendar *calendar,
QWidget *parent) :
00044
QVBox(parent)
00045 {
00046
00047 mCalendar = calendar;
00048 mJournal = 0;
00049 mDirty =
false;
00050
00051 mTitleLabel =
new QLabel(i18n(
"Title"),
this);
00052 mTitleLabel->setMargin(2);
00053 mTitleLabel->setAlignment(AlignCenter);
00054
00055 mEditor =
new KTextEdit(
this);
00056 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
00057
00058 mEditor->installEventFilter(
this);
00059 }
00060
00061 JournalEntry::~JournalEntry()
00062 {
00063 writeJournal();
00064 }
00065
00066
void JournalEntry::setDate(
const QDate &date)
00067 {
00068 writeJournal();
00069 mTitleLabel->setText(KGlobal::locale()->formatDate(date));
00070 mDate = date;
00071 }
00072
00073
void JournalEntry::setJournal(Journal *journal)
00074 {
00075 writeJournal();
00076
00077 mJournal = journal;
00078
if (mJournal)
00079 mEditor->setText(mJournal->description());
00080
else mEditor->clear();
00081 mDirty =
false;
00082 }
00083
00084
void JournalEntry::setDirty()
00085 {
00086 mDirty =
true;
00087
00088 }
00089
00090
void JournalEntry::clear()
00091 {
00092 mJournal = 0;
00093 mEditor->setText(
"");
00094 writeJournal();
00095 }
00096
00097
bool JournalEntry::eventFilter(
QObject *o,
QEvent *e )
00098 {
00099
00100
00101
if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Hide ||
00102 e->type() == QEvent::Close ) {
00103 writeJournal();
00104 }
00105
return QFrame::eventFilter( o, e );
00106 }
00107
00108
void JournalEntry::writeJournal()
00109 {
00110
00111
00112
if (!mDirty)
return;
00113
bool newJournal =
false;
00114
00115
if (mEditor->text().isEmpty() ) {
00116
if (mJournal ) {
00117 emit incidenceToBeDeleted( mJournal );
00118 mCalendar->deleteJournal( mJournal );
00119 emit incidenceDeleted( mJournal );
00120 }
00121 mJournal = 0;
00122
return;
00123 }
00124
00125
00126
00127
if (!mJournal) {
00128 newJournal =
true;
00129 mJournal =
new Journal;
00130 mJournal->setDtStart(
QDateTime(mDate,
QTime(0,0,0)));
00131
if ( !mCalendar->addJournal( mJournal ) ) {
00132 KODialogManager::errorSaveJournal(
this );
00133
delete mJournal;
00134 mJournal = 0;
00135
return;
00136 }
00137 }
00138
00139 Journal* oldJournal = mJournal->clone();
00140 mJournal->setDescription(mEditor->text());
00141
if (newJournal) {
00142 emit incidenceAdded( mJournal );
00143 }
else {
00144 emit incidenceChanged( oldJournal, mJournal );
00145
delete oldJournal;
00146 }
00147
00148 mDirty =
false;
00149 }
00150
00151
void JournalEntry::flushEntry()
00152 {
00153
if (!mDirty)
return;
00154
00155 writeJournal();
00156 }