korganizer Library API Documentation

journalentry.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 // 00025 // Journal Entry 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/calendarresources.h> 00037 #include <libkcal/resourcecalendar.h> 00038 00039 #include "kodialogmanager.h" 00040 00041 #include "journalentry.h" 00042 #include "journalentry.moc" 00043 00044 JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 00045 QFrame(parent) 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 QBoxLayout *topLayout = new QVBoxLayout(this); 00059 topLayout->addWidget(mTitleLabel); 00060 topLayout->addWidget(mEditor); 00061 00062 mEditor->installEventFilter(this); 00063 } 00064 00065 JournalEntry::~JournalEntry() 00066 { 00067 } 00068 00069 void JournalEntry::setDate(const QDate &date) 00070 { 00071 writeJournal(); 00072 00073 mTitleLabel->setText(KGlobal::locale()->formatDate(date)); 00074 00075 00076 mDate = date; 00077 } 00078 00079 void JournalEntry::setJournal(Journal *journal) 00080 { 00081 writeJournal(); 00082 00083 mJournal = journal; 00084 00085 mEditor->setText(mJournal->description()); 00086 00087 mDirty = false; 00088 } 00089 00090 Journal *JournalEntry::journal() const 00091 { 00092 return mJournal; 00093 } 00094 00095 void JournalEntry::setDirty() 00096 { 00097 mDirty = true; 00098 // kdDebug(5850) << "JournalEntry::setDirty()" << endl; 00099 } 00100 00101 void JournalEntry::clear() 00102 { 00103 mJournal = 0; 00104 mEditor->setText(""); 00105 } 00106 00107 bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 00108 { 00109 // kdDebug(5850) << "JournalEntry::event received " << e->type() << endl; 00110 00111 if ( e->type() == QEvent::FocusOut ) { 00112 writeJournal(); 00113 } 00114 return QFrame::eventFilter( o, e ); // standard event processing 00115 } 00116 00117 void JournalEntry::writeJournal() 00118 { 00119 // kdDebug(5850) << "JournalEntry::writeJournal()" << endl; 00120 00121 if (!mDirty) return; 00122 00123 if (mEditor->text().isEmpty()) { 00124 mCalendar->deleteJournal( mJournal ); 00125 delete mJournal; 00126 mJournal = 0; 00127 return; 00128 } 00129 00130 // kdDebug(5850) << "JournalEntry::writeJournal()..." << endl; 00131 00132 if (!mJournal) { 00133 mJournal = new Journal; 00134 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 00135 if ( !mCalendar->addJournal( mJournal ) ) { 00136 KODialogManager::errorSaveJournal( this ); 00137 delete mJournal; 00138 mJournal = 0; 00139 return; 00140 } 00141 } 00142 00143 mJournal->setDescription(mEditor->text()); 00144 00145 mDirty = false; 00146 } 00147 00148 void JournalEntry::flushEntry() 00149 { 00150 if (!mDirty) return; 00151 00152 writeJournal(); 00153 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003