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/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 //kdDebug(5850)<<"JournalEntry::JournalEntry, parent="<<parent<<endl;
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 //  kdDebug(5850) << "JournalEntry::setDirty()" << endl;
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 //  kdDebug(5850) << "JournalEntry::event received " << e->type() << endl;
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 );    // standard event processing
00106 }
00107 
00108 void JournalEntry::writeJournal()
00109 {
00110 //  kdDebug(5850) << "JournalEntry::writeJournal()" << endl;
00111 
00112   if (!mDirty) return;
00113   bool newJournal = false;
00114  
00115   if (mEditor->text().isEmpty() ) {
00116     if (mJournal ) { // delete the journal
00117       emit incidenceToBeDeleted( mJournal );
00118       mCalendar->deleteJournal( mJournal );
00119       emit incidenceDeleted( mJournal );
00120     } 
00121     mJournal = 0;
00122     return;
00123   }
00124 
00125 //  kdDebug(5850) << "JournalEntry::writeJournal()..." << endl;
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 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 25 11:20:58 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003