korganizer

kojournalview.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 //
00026 // View of Journal entries
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 //  mVBox->setSpacing( 10 );
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 *,const QDate &)),
00086              this, SIGNAL(editIncidenceSignal(Incidence *,const QDate &)) );
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   // We don't have a selection in the journal view.
00108   // FIXME: The currently edited journal is the selected incidence...
00109   Incidence::List eventList;
00110   return eventList;
00111 }
00112 
00113 void KOJournalView::clearEntries()
00114 {
00115 //  kdDebug(5850)<<"KOJournalView::clearEntries()"<<endl;
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 //  kdDebug(5850) << "KOJournalView::flushView(): "<< endl;
00138   emit flushEntries();
00139 }
00140 
00141 void KOJournalView::showDates( const QDate &start, const QDate &end )
00142 {
00143 //  kdDebug(5850) << "KOJournalView::showDates(): "<<start.toString().latin1()<<" - "<<end.toString().latin1() << endl;
00144   clearEntries();
00145   if ( end < start ) {
00146     return;
00147   }
00148 
00149   Journal::List::ConstIterator it;
00150   Journal::List jnls;
00151   QDate d = start;
00152   for ( QDate d = start; d <= end; d = d.addDays( 1 ) ) {
00153     jnls = calendar()->journals( d );
00154     for ( it = jnls.begin(); it != jnls.end(); ++it ) {
00155       appendJournal( *it, d );
00156     }
00157     if ( jnls.count() < 1 ) {
00158       // create an empty dateentry widget
00159       appendJournal( 0, d );
00160     }
00161   }
00162 }
00163 
00164 void KOJournalView::showIncidences( const Incidence::List &incidences, const QDate & )
00165 {
00166 //  kdDebug(5850) << "KOJournalView::showIncidences(): "<< endl;
00167   clearEntries();
00168   Incidence::List::const_iterator it;
00169   for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
00170     if ( (*it) && ( (*it)->type() == "Journal" ) ) {
00171       Journal *j = static_cast<Journal*>(*it);
00172       if ( j ) {
00173     appendJournal( j, j->dtStart().date() );
00174       }
00175     }
00176   }
00177 }
00178 
00179 CalPrinterBase::PrintType KOJournalView::printType()
00180 {
00181   return CalPrinterBase::Journallist;
00182 }
00183 
00184 void KOJournalView::changeIncidenceDisplay(Incidence *incidence, int action)
00185 {
00186 //  kdDebug(5850) << "KOJournalView::changeIncidenceDisplay(): "<< endl;
00187   Journal *journal = dynamic_cast<Journal*>(incidence);
00188   if (journal) {
00189     switch(action) {
00190       case KOGlobals::INCIDENCEADDED:
00191         appendJournal( journal, journal->dtStart().date() );
00192         break;
00193       case KOGlobals::INCIDENCEEDITED:
00194         emit journalEdited( journal );
00195         break;
00196       case KOGlobals::INCIDENCEDELETED:
00197         emit journalDeleted( journal );
00198         break;
00199       default:
00200         kdDebug(5850) << "KOListView::changeIncidenceDisplay(): Illegal action " << action << endl;
00201     }
00202   }
00203 }
00204 
00205 void KOJournalView::setIncidenceChanger( IncidenceChangerBase *changer )
00206 {
00207   mChanger = changer;
00208   emit setIncidenceChangerSignal( changer );
00209 }
00210 
00211 void KOJournalView::newJournal()
00212 {
00213   emit newJournalSignal( 0/*ResourceCalendar*/, QString()/*subResource*/,
00214                          QDate::currentDate() );
00215 }
00216 
00217 #include "kojournalview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys