korganizer

kojournalview.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 //
26 // View of Journal entries
27 
28 #include <tqlayout.h>
29 #include <tqpopupmenu.h>
30 #include <tqvbox.h>
31 #include <tqlabel.h>
32 #include <tqscrollview.h>
33 
34 #include <tdelocale.h>
35 #include <kdebug.h>
36 
37 #include <libkcal/calendar.h>
38 
39 #include "journalentry.h"
40 
41 #include "kojournalview.h"
42 #include "koglobals.h"
43 using namespace KOrg;
44 
45 KOJournalView::KOJournalView(Calendar *calendar, TQWidget *parent,
46  const char *name)
47  : KOrg::BaseView(calendar, parent, name)
48 {
49  TQVBoxLayout*topLayout = new TQVBoxLayout( this );
50  topLayout->setAutoAdd(true);
51  mSV = new TQScrollView( this, "JournalScrollView" );
52  mVBox = new TQVBox( mSV->viewport() );
53  mSV->setVScrollBarMode( TQScrollView::Auto );
54  mSV->setHScrollBarMode( TQScrollView::AlwaysOff );
55  mSV->setResizePolicy( TQScrollView::AutoOneFit );
56  mSV->addChild( mVBox );
57 // mVBox->setSpacing( 10 );
58 }
59 
60 KOJournalView::~KOJournalView()
61 {
62 }
63 
64 void KOJournalView::appendJournal( Journal*journal, const TQDate &dt)
65 {
66  JournalDateEntry *entry = 0;
67  if ( mEntries.contains( dt ) ) {
68  entry = mEntries[dt];
69  } else {
70  entry = new JournalDateEntry( calendar(), mVBox );
71  entry->setDate( dt );
72  entry->setIncidenceChanger( mChanger );
73  entry->show();
74  connect( this, TQ_SIGNAL(flushEntries()),
75  entry, TQ_SIGNAL(flushEntries()) );
76 
77  connect( this, TQ_SIGNAL(setIncidenceChangerSignal(IncidenceChangerBase *)),
78  entry, TQ_SLOT(setIncidenceChanger( IncidenceChangerBase *)) );
79 
80  connect( this, TQ_SIGNAL(journalEdited(Journal *)),
81  entry, TQ_SLOT(journalEdited(Journal *)) );
82  connect( this, TQ_SIGNAL(journalDeleted(Journal *)),
83  entry, TQ_SLOT(journalDeleted(Journal *)) );
84 
85  connect( entry, TQ_SIGNAL(editIncidence(Incidence *,const TQDate &)),
86  this, TQ_SIGNAL(editIncidenceSignal(Incidence *,const TQDate &)) );
87  connect( entry, TQ_SIGNAL(deleteIncidence(Incidence *)),
88  this, TQ_SIGNAL(deleteIncidenceSignal(Incidence *)) );
89 
90  connect( entry, TQ_SIGNAL(newJournal(ResourceCalendar *,const TQString &,const TQDate &)),
91  this, TQ_SIGNAL(newJournalSignal(ResourceCalendar *,const TQString &,const TQDate &)) );
92  mEntries.insert( dt, entry );
93  }
94 
95  if ( entry && journal ) {
96  entry->addJournal( journal );
97  }
98 }
99 
101 {
102  return mEntries.size();
103 }
104 
106 {
107  // We don't have a selection in the journal view.
108  // FIXME: The currently edited journal is the selected incidence...
109  Incidence::List eventList;
110  return eventList;
111 }
112 
113 void KOJournalView::clearEntries()
114 {
115 // kdDebug(5850)<<"KOJournalView::clearEntries()"<<endl;
116  TQMap<TQDate, JournalDateEntry*>::Iterator it;
117  for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
118  delete (it.data());
119  }
120  mEntries.clear();
121 }
122 void KOJournalView::updateView()
123 {
124  TQMap<TQDate, JournalDateEntry*>::Iterator it;
125  for ( it = mEntries.begin(); it != mEntries.end(); ++it ) {
126  it.data()->clear();
127  Journal::List journals = calendar()->journals( it.key() );
128  Journal::List::Iterator it1;
129  for ( it1 = journals.begin(); it1 != journals.end(); ++it1 ) {
130  it.data()->addJournal( *it1 );
131  }
132  }
133 }
134 
135 void KOJournalView::flushView()
136 {
137 // kdDebug(5850) << "KOJournalView::flushView(): "<< endl;
138  emit flushEntries();
139 }
140 
141 void KOJournalView::showDates( const TQDate &start, const TQDate &end )
142 {
143 // kdDebug(5850) << "KOJournalView::showDates(): "<<start.toString().latin1()<<" - "<<end.toString().latin1() << endl;
144  clearEntries();
145  if ( end < start ) {
146  return;
147  }
148 
149  Journal::List::ConstIterator it;
150  Journal::List jnls;
151  TQDate d = start;
152  for ( TQDate d = start; d <= end; d = d.addDays( 1 ) ) {
153  jnls = calendar()->journals( d );
154  for ( it = jnls.begin(); it != jnls.end(); ++it ) {
155  appendJournal( *it, d );
156  }
157  if ( jnls.count() < 1 ) {
158  // create an empty dateentry widget
159  appendJournal( 0, d );
160  }
161  }
162 }
163 
164 void KOJournalView::showIncidences( const Incidence::List &incidences, const TQDate & )
165 {
166 // kdDebug(5850) << "KOJournalView::showIncidences(): "<< endl;
167  clearEntries();
168  Incidence::List::const_iterator it;
169  for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
170  if ( (*it) && ( (*it)->type() == "Journal" ) ) {
171  Journal *j = static_cast<Journal*>(*it);
172  if ( j ) {
173  appendJournal( j, j->dtStart().date() );
174  }
175  }
176  }
177 }
178 
179 CalPrinterBase::PrintType KOJournalView::printType()
180 {
181  return CalPrinterBase::Journallist;
182 }
183 
184 void KOJournalView::changeIncidenceDisplay(Incidence *incidence, int action)
185 {
186 // kdDebug(5850) << "KOJournalView::changeIncidenceDisplay(): "<< endl;
187  Journal *journal = dynamic_cast<Journal*>(incidence);
188  if (journal) {
189  switch(action) {
190  case KOGlobals::INCIDENCEADDED:
191  appendJournal( journal, journal->dtStart().date() );
192  break;
193  case KOGlobals::INCIDENCEEDITED:
194  emit journalEdited( journal );
195  break;
196  case KOGlobals::INCIDENCEDELETED:
197  emit journalDeleted( journal );
198  break;
199  default:
200  kdDebug(5850) << "KOListView::changeIncidenceDisplay(): Illegal action " << action << endl;
201  }
202  }
203 }
204 
205 void KOJournalView::setIncidenceChanger( IncidenceChangerBase *changer )
206 {
207  mChanger = changer;
208  emit setIncidenceChangerSignal( changer );
209 }
210 
211 void KOJournalView::newJournal()
212 {
213  emit newJournalSignal( 0/*ResourceCalendar*/, TQString()/*subResource*/,
214  TQDate::currentDate() );
215 }
216 
217 #include "kojournalview.moc"
virtual Journal::List journals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
virtual TQDateTime dtStart() const
virtual Incidence::List selectedIncidences()
virtual int currentDateCount()
Return number of currently shown dates.
This class provides an interface for all views being displayed within the main calendar view.
Definition: baseview.h:60
void editIncidenceSignal(Incidence *, const TQDate &)
instructs the receiver to begin editing the incidence specified in some manner.
void deleteIncidenceSignal(Incidence *)
instructs the receiver to delete the Incidence in some manner; some possibilities include automatical...
virtual Calendar * calendar()
Return calendar object of this view.
Definition: baseview.h:89