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   topLayout = new QVBoxLayout( mSV->viewport() );
00053   topLayout->setAutoAdd(true);
00054   mVBox = new QVBox( mSV->viewport() );
00055   mSV->setVScrollBarMode( QScrollView::Auto );
00056   mSV->setHScrollBarMode( QScrollView::AlwaysOff );
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()), entry, SIGNAL(flushEntries()) );
00075     connect( this, SIGNAL(setIncidenceChangerSignal( IncidenceChangerBase * ) ),
00076              entry, SLOT(setIncidenceChanger( IncidenceChangerBase * ) ) );
00077     connect( this, SIGNAL( journalEdited( Journal* ) ),
00078              entry, SLOT( journalEdited( Journal* ) ) );
00079     connect( this, SIGNAL( journalDeleted( Journal* ) ),
00080              entry, SLOT( journalDeleted( Journal* ) ) );
00081 
00082     connect( entry, SIGNAL( editIncidence( Incidence* ) ),
00083              this, SIGNAL( editIncidenceSignal( Incidence* ) ) );
00084     connect( entry, SIGNAL( deleteIncidence( Incidence* ) ),
00085              this, SIGNAL( deleteIncidenceSignal( Incidence* ) ) );
00086     connect( entry, SIGNAL( newJournal( const QDate & ) ),
00087              this, SIGNAL( newJournalSignal( const QDate & ) ) );
00088     mEntries.insert( dt, entry );
00089   }
00090 
00091   if ( entry && journal ) {
00092     entry->addJournal( journal );
00093   }
00094 }
00095 
00096 int KOJournalView::currentDateCount()
00097 {
00098   return mEntries.size();
00099 }
00100 
00101 Incidence::List KOJournalView::selectedIncidences()
00102 {
00103   // We don't have a selection in the journal view.
00104   // FIXME: The currently edited journal is the selected incidence...
00105   Incidence::List eventList;
00106   return eventList;
00107 }
00108 
00109 void KOJournalView::clearEntries()
00110 {
00111 //  kdDebug(5850)<<"KOJournalView::clearEntries()"<<endl;
00112   QMap<QDate, JournalDateEntry*>::Iterator it;
00113   for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
00114     delete (it.data());
00115   }
00116   mEntries.clear();
00117 }
00118 void KOJournalView::updateView()
00119 {
00120   QMap<QDate, JournalDateEntry*>::Iterator it;
00121   for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
00122     it.data()->clear();
00123     Journal::List journals = calendar()->journals( it.key() );
00124     Journal::List::Iterator it1;
00125     for ( it1 = journals.begin(); it1 != journals.end(); ++it1 ) {
00126       it.data()->addJournal( *it1 );
00127     }
00128   }
00129 }
00130 
00131 void KOJournalView::flushView()
00132 {
00133 //  kdDebug(5850) << "KOJournalView::flushView(): "<< endl;
00134   emit flushEntries();
00135 }
00136 
00137 void KOJournalView::showDates(const QDate &start, const QDate &end)
00138 {
00139 //  kdDebug(5850) << "KOJournalView::showDates(): "<<start.toString().latin1()<<" - "<<end.toString().latin1() << endl;
00140   clearEntries();
00141   if ( end<start ) return;
00142 
00143   Journal::List::ConstIterator it;
00144   Journal::List jnls;
00145   QDate d=start;
00146   for ( QDate d=start; d<=end; d=d.addDays(1) ) {
00147     jnls = calendar()->journals( d );
00148     for ( it = jnls.begin(); it != jnls.end(); ++it ) {
00149       appendJournal( *it, d );
00150     }
00151     if ( jnls.count() < 1 ) {
00152       // create an empty dateentry widget
00153       appendJournal( 0, d );
00154     }
00155   }
00156 }
00157 
00158 void KOJournalView::showIncidences( const Incidence::List &incidences )
00159 {
00160 //  kdDebug(5850) << "KOJournalView::showIncidences(): "<< endl;
00161   clearEntries();
00162   Incidence::List::const_iterator it;
00163   for ( it=incidences.constBegin(); it!=incidences.constEnd(); ++it) {
00164     if ((*it) && ( (*it)->type()=="Journal" ) ) {
00165       Journal*j = static_cast<Journal*>(*it);
00166       if ( j ) appendJournal( j, j->dtStart().date() );
00167     }
00168   }
00169 }
00170 
00171 CalPrinterBase::PrintType KOJournalView::printType()
00172 {
00173   return CalPrinterBase::Journallist;
00174 }
00175 
00176 void KOJournalView::changeIncidenceDisplay(Incidence *incidence, int action)
00177 {
00178 //  kdDebug(5850) << "KOJournalView::changeIncidenceDisplay(): "<< endl;
00179   Journal *journal = dynamic_cast<Journal*>(incidence);
00180   if (journal) {
00181     switch(action) {
00182       case KOGlobals::INCIDENCEADDED:
00183         appendJournal( journal, journal->dtStart().date() );
00184         break;
00185       case KOGlobals::INCIDENCEEDITED:
00186         emit journalEdited( journal );
00187         break;
00188       case KOGlobals::INCIDENCEDELETED:
00189         emit journalDeleted( journal );
00190         break;
00191       default:
00192         kdDebug(5850) << "KOListView::changeIncidenceDisplay(): Illegal action " << action << endl;
00193     }
00194   }
00195 }
00196 
00197 void KOJournalView::setIncidenceChanger( IncidenceChangerBase *changer )
00198 {
00199   mChanger = changer;
00200   emit setIncidenceChangerSignal( changer );
00201 }
00202 
00203 void KOJournalView::newJournal()
00204 {
00205   emit newJournalSignal( QDate::currentDate() );
00206 }
00207 
00208 #include "kojournalview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys