korganizer

koviewmanager.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of TQt, and distribute the resulting executable,
23  without including the source code for TQt in the source distribution.
24 */
25 
26 #include <tqwidgetstack.h>
27 #include <tqtabwidget.h>
28 
30 #include <tdeactioncollection.h>
31 #include <tdeconfig.h>
32 #include <tdeglobal.h>
33 
34 #include "actionmanager.h"
35 #include "calendarview.h"
36 #include "datenavigator.h"
37 #include "kotodoview.h"
38 #include "koagendaview.h"
39 #include "komonthview.h"
40 #include "kolistview.h"
41 #include "kowhatsnextview.h"
42 #include "kojournalview.h"
43 #include "kotimelineview.h"
44 #include "koprefs.h"
45 #include "koglobals.h"
46 #include "navigatorbar.h"
47 #include "multiagendaview.h"
48 #include <korganizer/mainwindow.h>
49 
50 #include "koviewmanager.h"
51 #include "koviewmanager.moc"
52 
53 KOViewManager::KOViewManager( CalendarView *mainView ) :
54  TQObject(), mMainView( mainView )
55 {
56  mCurrentView = 0;
57 
58  mLastEventView = 0;
59 
60  mWhatsNextView = 0;
61  mTodoView = 0;
62  mAgendaView = 0;
63  mAgendaSideBySideView = 0;
64  mMonthView = 0;
65  mListView = 0;
66  mJournalView = 0;
67  mTimelineView = 0;
68  mAgendaViewTabs = 0;
69  mAgendaViewTabIndex = 0;
70  mAgendaMode = AGENDA_NONE;
71 }
72 
73 KOViewManager::~KOViewManager()
74 {
75 }
76 
77 
78 KOrg::BaseView *KOViewManager::currentView()
79 {
80  return mCurrentView;
81 }
82 
83 void KOViewManager::readSettings(TDEConfig *config)
84 {
85  config->setGroup("General");
86  TQString view = config->readEntry("Current View");
87 
88  if (view == "WhatsNext") showWhatsNextView();
89  else if (view == "Month") showMonthView();
90  else if (view == "List") showListView();
91  else if (view == "Journal") showJournalView();
92  else if (view == "Todo") showTodoView();
93  else if (view == "Timeline") showTimelineView();
94  else {
95  mAgendaMode = AgendaMode( config->readNumEntry( "Agenda Mode", AGENDA_OTHER ) );
96 
97  switch ( mAgendaMode ) {
98  case AGENDA_WORK_WEEK:
99  showWorkWeekView();
100  break;
101  case AGENDA_WEEK:
102  showWeekView();
103  break;
104  case AGENDA_NEXTX:
105  showNextXView();
106  break;
107  case AGENDA_DAY:
108  showDayView();
109  break;
110  case AGENDA_NONE:
111  // Someone has been playing with the config file.
112  default:
113  mAgendaMode = AGENDA_OTHER;
114  showAgendaView();
115  }
116  }
117 }
118 
119 void KOViewManager::writeSettings(TDEConfig *config)
120 {
121  config->setGroup("General");
122 
123  TQString view;
124  if (mCurrentView == mWhatsNextView) view = "WhatsNext";
125  else if (mCurrentView == mMonthView) view = "Month";
126  else if (mCurrentView == mListView) view = "List";
127  else if (mCurrentView == mJournalView) view = "Journal";
128  else if (mCurrentView == mTodoView) view = "Todo";
129  else if (mCurrentView == mTimelineView) view = "Timeline";
130  else {
131  view = "Agenda";
132  config->writeEntry( "Agenda Mode", mAgendaMode );
133  }
134 
135  config->writeEntry("Current View",view);
136 
137  if (mAgendaView) {
138  mAgendaView->writeSettings(config);
139  }
140  if (mListView) {
141  mListView->writeSettings(config);
142  }
143  if (mTodoView) {
144  mTodoView->saveLayout(config,"Todo View");
145  }
146 }
147 
149 {
150  if( view == mCurrentView ) return;
151 
152  mCurrentView = view;
153 
154  if ( mCurrentView && mCurrentView->isEventView() ) {
155  mLastEventView = mCurrentView;
156  }
157 
158  if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
159 
160  raiseCurrentView();
161 
162  mMainView->processIncidenceSelection( 0, TQDate() );
163 
164  mMainView->updateView();
165 
166  mMainView->adaptNavigationUnits();
167 }
168 
169 void KOViewManager::goMenu( bool enable )
170 {
172  if ( w ) {
173  TDEActionCollection *ac = w->getActionCollection();
174  if ( ac ) {
175  TDEAction *action;
176  action = ac->action( "go_today" );
177  if ( action ) {
178  action->setEnabled( enable );
179  }
180  action = ac->action( "go_previous" );
181  if ( action ) {
182  action->setEnabled( enable );
183  }
184  action = ac->action( "go_next" );
185  if ( action ) {
186  action->setEnabled( enable );
187  }
188  }
189  }
190 }
191 
192 void KOViewManager::raiseCurrentView()
193 {
194  if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
195  (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
196  mMainView->showLeftFrame( false );
197  if ( mCurrentView == mTodoView ) {
198  mMainView->navigatorBar()->hide();
199  } else {
200  mMainView->navigatorBar()->show();
201  }
202  } else {
203  mMainView->showLeftFrame( true );
204  mMainView->navigatorBar()->hide();
205  }
206  mMainView->viewStack()->raiseWidget( widgetForView( mCurrentView ) );
207 }
208 
209 void KOViewManager::updateView()
210 {
211  if ( mCurrentView ) mCurrentView->updateView();
212 }
213 
214 void KOViewManager::updateView(const TQDate &start, const TQDate &end)
215 {
216 // kdDebug(5850) << "KOViewManager::updateView()" << endl;
217 
218  if (mCurrentView) mCurrentView->showDates(start, end);
219 
220  if (mTodoView) mTodoView->updateView();
221 }
222 
223 void KOViewManager::connectView(KOrg::BaseView *view)
224 {
225  if (!view) return;
226 
227  // selecting an incidence
228  connect( view, TQ_SIGNAL( incidenceSelected( Incidence *,const TQDate & ) ),
229  mMainView, TQ_SLOT( processMainViewSelection( Incidence *,const TQDate & ) ) );
230 
231  // showing/editing/deleting an incidence. The calendar view takes care of the action.
232  connect( view, TQ_SIGNAL(showIncidenceSignal(Incidence *,const TQDate &)),
233  mMainView, TQ_SLOT(showIncidence(Incidence *,const TQDate &)) );
234  connect( view, TQ_SIGNAL(editIncidenceSignal(Incidence *,const TQDate &)),
235  mMainView, TQ_SLOT(editIncidence(Incidence *,const TQDate &)) );
236  connect( view, TQ_SIGNAL(deleteIncidenceSignal(Incidence *)),
237  mMainView, TQ_SLOT(deleteIncidence(Incidence *)) );
238  connect( view, TQ_SIGNAL(copyIncidenceSignal(Incidence *)),
239  mMainView, TQ_SLOT(copyIncidence(Incidence *)) );
240  connect( view, TQ_SIGNAL(cutIncidenceSignal(Incidence *)),
241  mMainView, TQ_SLOT(cutIncidence(Incidence *)) );
242  connect( view, TQ_SIGNAL(pasteIncidenceSignal()),
243  mMainView, TQ_SLOT(pasteIncidence()));
244  connect( view, TQ_SIGNAL(toggleAlarmSignal(Incidence *)),
245  mMainView, TQ_SLOT(toggleAlarm(Incidence *)) );
246  connect( view,TQ_SIGNAL(dissociateOccurrenceSignal(Incidence *,const TQDate &)),
247  mMainView, TQ_SLOT(dissociateOccurrence(Incidence *,const TQDate &)) );
248  connect( view,TQ_SIGNAL(dissociateFutureOccurrenceSignal(Incidence *,const TQDate &)),
249  mMainView, TQ_SLOT(dissociateFutureOccurrence(Incidence *,const TQDate &)) );
250 
251  // signals to create new incidences
252  connect( view, TQ_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &)),
253  mMainView, TQ_SLOT(newEvent(ResourceCalendar *,const TQString &)) );
254  connect( view, TQ_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &,const TQDate &)),
255  mMainView, TQ_SLOT(newEvent(ResourceCalendar *,const TQString &,const TQDate &)) );
256  connect( view, TQ_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &,const TQDateTime &)),
257  mMainView, TQ_SLOT(newEvent(ResourceCalendar *,const TQString &,const TQDateTime &)) );
258  connect( view, TQ_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &,const TQDateTime &,const TQDateTime &)),
259  mMainView, TQ_SLOT(newEvent(ResourceCalendar *,const TQString &,const TQDateTime &,const TQDateTime &)) );
260 
261  connect( view, TQ_SIGNAL(newTodoSignal(ResourceCalendar *,const TQString &,const TQDate &)),
262  mMainView, TQ_SLOT(newTodo(ResourceCalendar *,const TQString &,const TQDate &)) );
263  connect( view, TQ_SIGNAL(newSubTodoSignal(Todo *)),
264  mMainView, TQ_SLOT(newSubTodo(Todo *)) );
265 
266  connect( view, TQ_SIGNAL(newJournalSignal(ResourceCalendar *,const TQString &,const TQDate &)),
267  mMainView, TQ_SLOT(newJournal(ResourceCalendar *,const TQString &,const TQDate &)) );
268 
269  // reload settings
270  connect(mMainView, TQ_SIGNAL(configChanged()), view, TQ_SLOT(updateConfig()));
271 
272  // Notifications about added, changed and deleted incidences
273  connect( mMainView, TQ_SIGNAL( dayPassed( const TQDate & ) ),
274  view, TQ_SLOT( dayPassed( const TQDate & ) ) );
275  connect( view, TQ_SIGNAL( startMultiModify( const TQString & ) ),
276  mMainView, TQ_SLOT( startMultiModify( const TQString & ) ) );
277  connect( view, TQ_SIGNAL( endMultiModify() ),
278  mMainView, TQ_SLOT( endMultiModify() ) );
279 
280  connect( mMainView, TQ_SIGNAL( newIncidenceChanger( IncidenceChangerBase* ) ),
281  view, TQ_SLOT( setIncidenceChanger( IncidenceChangerBase * ) ) );
282  view->setIncidenceChanger( mMainView->incidenceChanger() );
283 }
284 
285 void KOViewManager::connectTodoView( KOTodoView* todoView )
286 {
287  if (!todoView) return;
288 
289  // SIGNALS/SLOTS FOR TODO VIEW
290  connect( todoView, TQ_SIGNAL( purgeCompletedSignal() ),
291  mMainView, TQ_SLOT( purgeCompleted() ) );
292  connect( todoView, TQ_SIGNAL( unSubTodoSignal() ),
293  mMainView, TQ_SLOT( todo_unsub() ) );
294  connect( todoView, TQ_SIGNAL( unAllSubTodoSignal() ),
295  mMainView, TQ_SLOT( makeSubTodosIndependent() ) );
296 }
297 
298 void KOViewManager::zoomInHorizontally()
299 {
300  if( mAgendaView == mCurrentView ) mAgendaView->zoomInHorizontally();
301 }
302 void KOViewManager::zoomOutHorizontally()
303 {
304  if( mAgendaView== mCurrentView ) mAgendaView->zoomOutHorizontally();
305 }
306 void KOViewManager::zoomInVertically()
307 {
308  if( mAgendaView== mCurrentView ) mAgendaView->zoomInVertically();
309 }
310 void KOViewManager::zoomOutVertically()
311 {
312  if( mAgendaView== mCurrentView ) mAgendaView->zoomOutVertically();
313 }
314 
315 void KOViewManager::addView(KOrg::BaseView *view)
316 {
317  connectView( view );
318  mMainView->viewStack()->addWidget( view );
319 }
320 
321 void KOViewManager::showWhatsNextView()
322 {
323  if (!mWhatsNextView) {
324  mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
325  "KOViewManager::WhatsNextView");
326  addView(mWhatsNextView);
327  }
328  goMenu( true );
329  showView(mWhatsNextView);
330 }
331 
332 void KOViewManager::showListView()
333 {
334  if (!mListView) {
335  mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
336  addView(mListView);
337  }
338  goMenu( true );
339  showView(mListView);
340 }
341 
342 void KOViewManager::showAgendaView()
343 {
344  // If the user opens a local file, through menu->open ( for example ), then
345  // it doesn't make sense to use multiagenda.
346  CalendarResources *calres = dynamic_cast<CalendarResources*>( mMainView->calendar() );
347  bool isLocalFile = !calres;
348 
349  int mode = KOPrefs::instance()->agendaViewCalendarDisplay();
350 
351  const bool showBoth = ( mode == KOPrefs::AllCalendarViews && !isLocalFile );
352 
353  const bool showMerged = showBoth || mode == KOPrefs::CalendarsMerged || isLocalFile;
354 
355  const bool showSideBySide = !isLocalFile && ( showBoth || mode == KOPrefs::CalendarsSideBySide );
356 
357  TQWidget *parent = mMainView->viewStack();
358  if ( !mAgendaViewTabs && showBoth ) {
359  mAgendaViewTabs = new TQTabWidget( mMainView->viewStack() );
360  connect( mAgendaViewTabs, TQ_SIGNAL( currentChanged( TQWidget* ) ),
361  this, TQ_SLOT( currentAgendaViewTabChanged( TQWidget* ) ) );
362  parent = mAgendaViewTabs;
363 
364  TDEConfig *config = KOGlobals::self()->config();
365  config->setGroup( "Views" );
366  mAgendaViewTabIndex = config->readNumEntry( "Agenda View Tab Index", 0 );
367  }
368 
369  if ( !mAgendaView && showMerged ) {
370  mAgendaView = new KOAgendaView( mMainView->calendar(),
371  mMainView,
372  parent,
373  "KOViewManager::AgendaView" );
374 
375  addView(mAgendaView);
376 
377  connect(mAgendaView, TQ_SIGNAL( toggleExpand() ),
378  mMainView, TQ_SLOT( toggleExpand() ) );
379  connect(mMainView, TQ_SIGNAL( calendarViewExpanded( bool ) ),
380  mAgendaView, TQ_SLOT( setExpandedButton( bool ) ) );
381 
382  connect( mAgendaView,TQ_SIGNAL( zoomViewHorizontally(const TQDate &, int )),
383  mMainView->dateNavigator(),TQ_SLOT( selectDates( const TQDate &, int ) ) );
384  mAgendaView->readSettings();
385  }
386 
387  if ( !mAgendaSideBySideView && showSideBySide ) {
388  mAgendaSideBySideView =
389  new MultiAgendaView( mMainView->calendar(), mMainView, parent,
390  "KOViewManager::AgendaSideBySideView" );
391 
392  addView(mAgendaSideBySideView);
393 
394 /* connect(mAgendaSideBySideView, TQ_SIGNAL( toggleExpand() ),
395  mMainView, TQ_SLOT( toggleExpand() ) );
396  connect(mMainView, TQ_SIGNAL( calendarViewExpanded( bool ) ),
397  mAgendaSideBySideView, TQ_SLOT( setExpandedButton( bool ) ) );
398 
399  connect( mAgendaSideBySideView,TQ_SIGNAL( zoomViewHorizontally(const TQDate &, int )),
400  mMainView->dateNavigator(),TQ_SLOT( selectDates( const TQDate &, int ) ) );*/
401  }
402 
403  if ( showBoth && mAgendaViewTabs ) {
404  if ( mAgendaView && mAgendaViewTabs->indexOf( mAgendaView ) < 0 )
405  mAgendaViewTabs->addTab( mAgendaView, i18n("Merged calendar") );
406  if ( mAgendaSideBySideView && mAgendaViewTabs->indexOf( mAgendaSideBySideView ) < 0 )
407  mAgendaViewTabs->addTab( mAgendaSideBySideView, i18n("Calendars Side by Side") );
408  mAgendaViewTabs->setCurrentPage( mAgendaViewTabIndex );
409  } else {
410  if ( mAgendaView && mMainView->viewStack()->id( mAgendaView ) < 0 )
411  mMainView->viewStack()->addWidget( mAgendaView );
412  if ( mAgendaSideBySideView && mMainView->viewStack()->id( mAgendaSideBySideView ) < 0 )
413  mMainView->viewStack()->addWidget( mAgendaSideBySideView );
414  }
415 
416  goMenu( true );
417  if ( mAgendaViewTabs && showBoth )
418  showView( static_cast<KOrg::BaseView*>( mAgendaViewTabs->currentPage() ) );
419  else if ( mAgendaView && showMerged )
420  showView( mAgendaView );
421  else if ( mAgendaSideBySideView && showSideBySide )
422  showView( mAgendaSideBySideView );
423 }
424 
425 void KOViewManager::showDayView()
426 {
427  mAgendaMode = AGENDA_DAY;
428  showAgendaView();
429  mMainView->dateNavigator()->selectDates( 1 );
430 }
431 
432 void KOViewManager::showWorkWeekView()
433 {
434  mAgendaMode = AGENDA_WORK_WEEK;
435  showAgendaView();
436  mMainView->dateNavigator()->selectWorkWeek();
437 }
438 
439 void KOViewManager::showWeekView()
440 {
441  mAgendaMode = AGENDA_WEEK;
442  showAgendaView();
443  mMainView->dateNavigator()->selectWeek();
444 }
445 
446 void KOViewManager::showNextXView()
447 {
448  mAgendaMode = AGENDA_NEXTX;
449  showAgendaView();
450  mMainView->dateNavigator()->selectDates( TQDate::currentDate(),
451  KOPrefs::instance()->mNextXDays );
452 }
453 
454 void KOViewManager::showMonthView()
455 {
456  if (!mMonthView) {
457  mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
458  addView(mMonthView);
459  }
460 
461  goMenu( true );
462  showView(mMonthView);
463 }
464 
465 void KOViewManager::showTodoView()
466 {
467  if ( !mTodoView ) {
468  mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
469  "KOViewManager::TodoView" );
470  mTodoView->setCalendar( mMainView->calendar() );
471  addView( mTodoView );
472  connectTodoView( mTodoView );
473 
474  TDEConfig *config = KOGlobals::self()->config();
475  mTodoView->restoreLayout( config, "Todo View" );
476  }
477 
478  goMenu( false );
479  showView( mTodoView );
480 }
481 
482 void KOViewManager::showJournalView()
483 {
484  if (!mJournalView) {
485  mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
486  "KOViewManager::JournalView");
487  addView(mJournalView);
488  }
489 
490  goMenu( true );
491  showView(mJournalView);
492 }
493 
494 
495 void KOViewManager::showTimelineView()
496 {
497  if (!mTimelineView) {
498  mTimelineView = new KOTimelineView(mMainView->calendar(),mMainView->viewStack(),
499  "KOViewManager::TimelineView");
500  addView(mTimelineView);
501  }
502  goMenu( true );
503  showView(mTimelineView);
504 }
505 
506 void KOViewManager::showEventView()
507 {
508  if ( mLastEventView ) {
509  goMenu( true );
510  showView( mLastEventView );
511  } else {
512  showWeekView();
513  }
514 }
515 
516 Incidence *KOViewManager::currentSelection()
517 {
518  if ( !mCurrentView ) return 0;
519  Incidence::List incidenceList = mCurrentView->selectedIncidences();
520  if ( incidenceList.isEmpty() ) return 0;
521 
522  return incidenceList.first();
523 }
524 
525 TQDate KOViewManager::currentSelectionDate()
526 {
527  TQDate qd;
528  if (mCurrentView) {
529  DateList qvl = mCurrentView->selectedIncidenceDates();
530  if (!qvl.isEmpty()) qd = qvl.first();
531  }
532  return qd;
533 }
534 
535 void KOViewManager::setDocumentId( const TQString &id )
536 {
537  if (mTodoView) mTodoView->setDocumentId( id );
538 }
539 
540 
541 TQWidget* KOViewManager::widgetForView( KOrg::BaseView* view ) const
542 {
543  const bool showBoth = KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::AllCalendarViews;
544  if ( (view == mAgendaView || view == mAgendaSideBySideView) && mAgendaViewTabs && showBoth ) {
545  return mAgendaViewTabs;
546  }
547  return view;
548 }
549 
550 
551 void KOViewManager::currentAgendaViewTabChanged( TQWidget* widget )
552 {
553  TDEConfig *config = KOGlobals::self()->config();
554  config->setGroup( "Views" );
555  config->writeEntry( "Agenda View Tab Index", mAgendaViewTabs->currentPageIndex() );
556 
557  goMenu( true );
558  showView( static_cast<KOrg::BaseView*>( widget ) );
559 }
560 
561 void KOViewManager::resourcesChanged()
562 {
563  if ( mAgendaView )
564  mAgendaView->resourcesChanged();
565  if ( mAgendaSideBySideView )
566  mAgendaSideBySideView->resourcesChanged();
567 }
568 
569 void KOViewManager::updateMultiCalendarDisplay()
570 {
571  if ( agendaIsSelected() ) {
572  showAgendaView();
573  } else {
574  updateView();
575  }
576 }
577 
578 bool KOViewManager::agendaIsSelected() const
579 {
580  return mCurrentView == mAgendaView ||
581  mCurrentView == mAgendaSideBySideView ||
582  ( mAgendaViewTabs && mCurrentView == mAgendaViewTabs->currentPage() );
583 }
static KOrg::MainWindow * findInstance(const KURL &url)
Is there a instance with this URL?
This is the main calendar widget.
Definition: calendarview.h:82
void adaptNavigationUnits()
Adapt navigation units corresponding to step size of navigation of the current view.
KOAgendaView is the agenda-like view used to display events in a single one or multi-day view.
Definition: koagendaview.h:109
void deleteSelectedDateTime()
make selected start/end invalid
This class provides a journal view.
Definition: kojournalview.h:42
This class provides a multi-column list view of events.
Definition: kolistview.h:69
The class KOMonthView represents the monthly view in KOrganizer.
Definition: komonthview.h:246
This class provides a view ....
This class provides a multi-column list view of todo events.
Definition: kotodoview.h:114
void showView(KOrg::BaseView *)
changes the view to be the currently selected view
This class provides a view of the next events and todos.
This class provides an interface for all views being displayed within the main calendar view.
Definition: baseview.h:60
virtual void showDates(const TQDate &start, const TQDate &end)=0
Show incidences for the given date range.
virtual void updateView()=0
Updates the current display to reflect changes that may have happened in the calendar since the last ...
virtual DateList selectedIncidenceDates()=0
virtual bool isEventView()
Return if this view is a view for displaying events.
Definition: baseview.h:144
virtual Incidence::List selectedIncidences()=0
interface for korganizer main window
Definition: mainwindow.h:41
virtual TDEActionCollection * getActionCollection() const =0
Return actionCollection of this main window.
Shows one agenda for every resource side-by-side.
bool view(TQWidget *parent, Attachment *attachment)