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
00028 #include <qlayout.h>
00029 #include <qpopupmenu.h>
00030 #include <qvbox.h>
00031 #include <qlabel.h>
00032 #include <qscrollview.h>
00033
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036
00037 #include <libkcal/calendar.h>
00038
00039 #include "journalentry.h"
00040
00041 #include "kojournalview.h"
00042 #include "koglobals.h"
00043 using namespace KOrg;
00044
00045 KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent,
00046 const char *name)
00047 : KOrg::BaseView(calendar, parent, name)
00048 {
00049 QVBoxLayout*topLayout = new QVBoxLayout( this );
00050 topLayout->setAutoAdd(true);
00051 mSV = new QScrollView( this, "JournalScrollView" );
00052 mVBox = new QVBox( mSV->viewport() );
00053 mSV->setVScrollBarMode( QScrollView::Auto );
00054 mSV->setHScrollBarMode( QScrollView::AlwaysOff );
00055 mSV->setResizePolicy( QScrollView::AutoOneFit );
00056 mSV->addChild( mVBox );
00057
00058 }
00059
00060 KOJournalView::~KOJournalView()
00061 {
00062 }
00063
00064 void KOJournalView::appendJournal( Journal*journal, const QDate &dt)
00065 {
00066 JournalDateEntry *entry = 0;
00067 if ( mEntries.contains( dt ) ) {
00068 entry = mEntries[dt];
00069 } else {
00070 entry = new JournalDateEntry( calendar(), mVBox );
00071 entry->setDate( dt );
00072 entry->setIncidenceChanger( mChanger );
00073 entry->show();
00074 connect( this, SIGNAL(flushEntries()),
00075 entry, SIGNAL(flushEntries()) );
00076
00077 connect( this, SIGNAL(setIncidenceChangerSignal(IncidenceChangerBase *)),
00078 entry, SLOT(setIncidenceChanger( IncidenceChangerBase *)) );
00079
00080 connect( this, SIGNAL(journalEdited(Journal *)),
00081 entry, SLOT(journalEdited(Journal *)) );
00082 connect( this, SIGNAL(journalDeleted(Journal *)),
00083 entry, SLOT(journalDeleted(Journal *)) );
00084
00085 connect( entry, SIGNAL(editIncidence(Incidence *)),
00086 this, SIGNAL(editIncidenceSignal(Incidence *)) );
00087 connect( entry, SIGNAL(deleteIncidence(Incidence *)),
00088 this, SIGNAL(deleteIncidenceSignal(Incidence *)) );
00089
00090 connect( entry, SIGNAL(newJournal(ResourceCalendar *,const QString &,const QDate &)),
00091 this, SIGNAL(newJournalSignal(ResourceCalendar *,const QString &,const QDate &)) );
00092 mEntries.insert( dt, entry );
00093 }
00094
00095 if ( entry && journal ) {
00096 entry->addJournal( journal );
00097 }
00098 }
00099
00100 int KOJournalView::currentDateCount()
00101 {
00102 return mEntries.size();
00103 }
00104
00105 Incidence::List KOJournalView::selectedIncidences()
00106 {
00107
00108
00109 Incidence::List eventList;
00110 return eventList;
00111 }
00112
00113 void KOJournalView::clearEntries()
00114 {
00115
00116 QMap<QDate, JournalDateEntry*>::Iterator it;
00117 for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
00118 delete (it.data());
00119 }
00120 mEntries.clear();
00121 }
00122 void KOJournalView::updateView()
00123 {
00124 QMap<QDate, JournalDateEntry*>::Iterator it;
00125 for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
00126 it.data()->clear();
00127 Journal::List journals = calendar()->journals( it.key() );
00128 Journal::List::Iterator it1;
00129 for ( it1 = journals.begin(); it1 != journals.end(); ++it1 ) {
00130 it.data()->addJournal( *it1 );
00131 }
00132 }
00133 }
00134
00135 void KOJournalView::flushView()
00136 {
00137
00138 emit flushEntries();
00139 }
00140
00141 void KOJournalView::showDates(const QDate &start, const QDate &end)
00142 {
00143
00144 clearEntries();
00145 if ( end<start ) return;
00146
00147 Journal::List::ConstIterator it;
00148 Journal::List jnls;
00149 QDate d=start;
00150 for ( QDate d=start; d<=end; d=d.addDays(1) ) {
00151 jnls = calendar()->journals( d );
00152 for ( it = jnls.begin(); it != jnls.end(); ++it ) {
00153 appendJournal( *it, d );
00154 }
00155 if ( jnls.count() < 1 ) {
00156
00157 appendJournal( 0, d );
00158 }
00159 }
00160 }
00161
00162 void KOJournalView::showIncidences( const Incidence::List &incidences, const QDate & )
00163 {
00164
00165 clearEntries();
00166 Incidence::List::const_iterator it;
00167 for ( it=incidences.constBegin(); it!=incidences.constEnd(); ++it) {
00168 if ((*it) && ( (*it)->type()=="Journal" ) ) {
00169 Journal*j = static_cast<Journal*>(*it);
00170 if ( j ) appendJournal( j, j->dtStart().date() );
00171 }
00172 }
00173 }
00174
00175 CalPrinterBase::PrintType KOJournalView::printType()
00176 {
00177 return CalPrinterBase::Journallist;
00178 }
00179
00180 void KOJournalView::changeIncidenceDisplay(Incidence *incidence, int action)
00181 {
00182
00183 Journal *journal = dynamic_cast<Journal*>(incidence);
00184 if (journal) {
00185 switch(action) {
00186 case KOGlobals::INCIDENCEADDED:
00187 appendJournal( journal, journal->dtStart().date() );
00188 break;
00189 case KOGlobals::INCIDENCEEDITED:
00190 emit journalEdited( journal );
00191 break;
00192 case KOGlobals::INCIDENCEDELETED:
00193 emit journalDeleted( journal );
00194 break;
00195 default:
00196 kdDebug(5850) << "KOListView::changeIncidenceDisplay(): Illegal action " << action << endl;
00197 }
00198 }
00199 }
00200
00201 void KOJournalView::setIncidenceChanger( IncidenceChangerBase *changer )
00202 {
00203 mChanger = changer;
00204 emit setIncidenceChangerSignal( changer );
00205 }
00206
00207 void KOJournalView::newJournal()
00208 {
00209 emit newJournalSignal( 0, QString(),
00210 QDate::currentDate() );
00211 }
00212
00213 #include "kojournalview.moc"