korganizer

koviewmanager.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <qwidgetstack.h>
00027 #include <qtabwidget.h>
00028 
00029 #include <kactioncollection.h>
00030 #include <kconfig.h>
00031 #include <kglobal.h>
00032 
00033 #include "actionmanager.h"
00034 #include "calendarview.h"
00035 #include "datenavigator.h"
00036 #include "kotodoview.h"
00037 #include "koagendaview.h"
00038 #include "komonthview.h"
00039 #include "kolistview.h"
00040 #include "kowhatsnextview.h"
00041 #include "kojournalview.h"
00042 #include "kotimelineview.h"
00043 #include "koprefs.h"
00044 #include "koglobals.h"
00045 #include "navigatorbar.h"
00046 #include "multiagendaview.h"
00047 #include <korganizer/mainwindow.h>
00048 
00049 #include "koviewmanager.h"
00050 #include "koviewmanager.moc"
00051 
00052 KOViewManager::KOViewManager( CalendarView *mainView ) :
00053   QObject(), mMainView( mainView )
00054 {
00055   mCurrentView = 0;
00056 
00057   mLastEventView = 0;
00058 
00059   mWhatsNextView = 0;
00060   mTodoView = 0;
00061   mAgendaView = 0;
00062   mAgendaSideBySideView = 0;
00063   mMonthView = 0;
00064   mListView = 0;
00065   mJournalView = 0;
00066   mTimelineView = 0;
00067   mAgendaViewTabs = 0;
00068 }
00069 
00070 KOViewManager::~KOViewManager()
00071 {
00072 }
00073 
00074 
00075 KOrg::BaseView *KOViewManager::currentView()
00076 {
00077   return mCurrentView;
00078 }
00079 
00080 void KOViewManager::readSettings(KConfig *config)
00081 {
00082   config->setGroup("General");
00083   QString view = config->readEntry("Current View");
00084 
00085   if (view == "WhatsNext") showWhatsNextView();
00086   else if (view == "Month") showMonthView();
00087   else if (view == "List") showListView();
00088   else if (view == "Journal") showJournalView();
00089   else if (view == "Todo") showTodoView();
00090   else if (view == "Timeline") showTimelineView();
00091   else showAgendaView();
00092 }
00093 
00094 void KOViewManager::writeSettings(KConfig *config)
00095 {
00096   config->setGroup("General");
00097 
00098   QString view;
00099   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00100   else if (mCurrentView == mMonthView) view = "Month";
00101   else if (mCurrentView == mListView) view = "List";
00102   else if (mCurrentView == mJournalView) view = "Journal";
00103   else if (mCurrentView == mTodoView) view = "Todo";
00104   else if (mCurrentView == mTimelineView) view = "Timeline";
00105   else view = "Agenda";
00106 
00107   config->writeEntry("Current View",view);
00108 
00109   if (mAgendaView) {
00110     mAgendaView->writeSettings(config);
00111   }
00112   if (mListView) {
00113     mListView->writeSettings(config);
00114   }
00115   if (mTodoView) {
00116     mTodoView->saveLayout(config,"Todo View");
00117   }
00118 }
00119 
00120 void KOViewManager::showView(KOrg::BaseView *view)
00121 {
00122   if( view == mCurrentView ) return;
00123 
00124   mCurrentView = view;
00125 
00126   if ( mCurrentView && mCurrentView->isEventView() ) {
00127     mLastEventView = mCurrentView;
00128   }
00129 
00130   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00131 
00132   raiseCurrentView();
00133 
00134   mMainView->processIncidenceSelection( 0, QDate() );
00135 
00136   mMainView->updateView();
00137 
00138   mMainView->adaptNavigationUnits();
00139 }
00140 
00141 void KOViewManager::goMenu( bool enable )
00142 {
00143   KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00144   if ( w ) {
00145     KActionCollection *ac = w->getActionCollection();
00146     if ( ac ) {
00147       KAction *action;
00148       action = ac->action( "go_today" );
00149       if ( action ) {
00150         action->setEnabled( enable );
00151       }
00152       action = ac->action( "go_previous" );
00153       if ( action ) {
00154         action->setEnabled( enable );
00155       }
00156       action = ac->action( "go_next" );
00157       if ( action ) {
00158         action->setEnabled( enable );
00159       }
00160     }
00161   }
00162 }
00163 
00164 void KOViewManager::raiseCurrentView()
00165 {
00166   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00167       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00168     mMainView->showLeftFrame( false );
00169     if ( mCurrentView == mTodoView ) {
00170       mMainView->navigatorBar()->hide();
00171     } else {
00172       mMainView->navigatorBar()->show();
00173     }
00174   } else {
00175     mMainView->showLeftFrame( true );
00176     mMainView->navigatorBar()->hide();
00177   }
00178   mMainView->viewStack()->raiseWidget( widgetForView( mCurrentView  ) );
00179 }
00180 
00181 void KOViewManager::updateView()
00182 {
00183   if ( mCurrentView ) mCurrentView->updateView();
00184 }
00185 
00186 void KOViewManager::updateView(const QDate &start, const QDate &end)
00187 {
00188 //  kdDebug(5850) << "KOViewManager::updateView()" << endl;
00189 
00190   if (mCurrentView) mCurrentView->showDates(start, end);
00191 
00192   if (mTodoView) mTodoView->updateView();
00193 }
00194 
00195 void KOViewManager::connectView(KOrg::BaseView *view)
00196 {
00197   if (!view) return;
00198 
00199   // selecting an incidence
00200   connect( view, SIGNAL( incidenceSelected( Incidence *,const QDate & ) ),
00201            mMainView, SLOT( processMainViewSelection( Incidence *,const QDate & ) ) );
00202 
00203   // showing/editing/deleting an incidence. The calendar view takes care of the action.
00204   connect(view, SIGNAL(showIncidenceSignal(Incidence *)),
00205           mMainView, SLOT(showIncidence(Incidence *)));
00206   connect(view, SIGNAL(editIncidenceSignal(Incidence *)),
00207           mMainView, SLOT(editIncidence(Incidence *)));
00208   connect(view, SIGNAL(deleteIncidenceSignal(Incidence *)),
00209           mMainView, SLOT(deleteIncidence(Incidence *)));
00210   connect(view, SIGNAL(copyIncidenceSignal(Incidence *)),
00211           mMainView, SLOT(copyIncidence(Incidence *)));
00212   connect(view, SIGNAL(cutIncidenceSignal(Incidence *)),
00213           mMainView, SLOT(cutIncidence(Incidence *)));
00214   connect(view, SIGNAL(pasteIncidenceSignal()),
00215           mMainView, SLOT(pasteIncidence()));
00216   connect(view, SIGNAL(toggleAlarmSignal(Incidence *)),
00217           mMainView, SLOT(toggleAlarm(Incidence *)));
00218   connect(view,SIGNAL(dissociateOccurrenceSignal( Incidence *, const QDate & )),
00219           mMainView, SLOT(dissociateOccurrence( Incidence *, const QDate & )));
00220   connect(view,SIGNAL(dissociateFutureOccurrenceSignal( Incidence *, const QDate & )),
00221           mMainView, SLOT(dissociateFutureOccurrence( Incidence *, const QDate & )));
00222 
00223   // signals to create new incidences
00224   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &)),
00225            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &)) );
00226   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDate &)),
00227            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDate &)) );
00228   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDateTime &)),
00229            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDateTime &)) );
00230   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDateTime &,const QDateTime &)),
00231            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDateTime &,const QDateTime &)) );
00232 
00233   connect( view, SIGNAL(newTodoSignal(ResourceCalendar *,const QString &,const QDate &)),
00234            mMainView, SLOT(newTodo(ResourceCalendar *,const QString &,const QDate &)) );
00235   connect( view, SIGNAL(newSubTodoSignal(Todo *)),
00236            mMainView, SLOT(newSubTodo(Todo *)) );
00237 
00238   connect( view, SIGNAL(newJournalSignal(ResourceCalendar *,const QString &,const QDate &)),
00239            mMainView, SLOT(newJournal(ResourceCalendar *,const QString &,const QDate &)) );
00240 
00241   // reload settings
00242   connect(mMainView, SIGNAL(configChanged()), view, SLOT(updateConfig()));
00243 
00244   // Notifications about added, changed and deleted incidences
00245   connect( mMainView, SIGNAL( dayPassed( const QDate & ) ),
00246            view, SLOT( dayPassed( const QDate & ) ) );
00247   connect( view, SIGNAL( startMultiModify( const QString & ) ),
00248            mMainView, SLOT( startMultiModify( const QString & ) ) );
00249   connect( view, SIGNAL( endMultiModify() ),
00250            mMainView, SLOT( endMultiModify() ) );
00251 
00252   connect( mMainView, SIGNAL( newIncidenceChanger( IncidenceChangerBase* ) ),
00253            view, SLOT( setIncidenceChanger( IncidenceChangerBase * ) ) );
00254   view->setIncidenceChanger( mMainView->incidenceChanger() );
00255 }
00256 
00257 void KOViewManager::connectTodoView( KOTodoView* todoView )
00258 {
00259   if (!todoView) return;
00260 
00261   // SIGNALS/SLOTS FOR TODO VIEW
00262   connect( todoView, SIGNAL( purgeCompletedSignal() ),
00263            mMainView, SLOT( purgeCompleted() ) );
00264   connect( todoView, SIGNAL( unSubTodoSignal() ),
00265            mMainView, SLOT( todo_unsub() ) );
00266   connect( todoView, SIGNAL( unAllSubTodoSignal() ),
00267            mMainView, SLOT( makeSubTodosIndependents() ) );
00268 }
00269 
00270 void KOViewManager::zoomInHorizontally()
00271 {
00272   if( mAgendaView == mCurrentView ) mAgendaView->zoomInHorizontally();
00273 }
00274 void KOViewManager::zoomOutHorizontally()
00275 {
00276   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutHorizontally();
00277 }
00278 void KOViewManager::zoomInVertically()
00279 {
00280   if( mAgendaView== mCurrentView ) mAgendaView->zoomInVertically();
00281 }
00282 void KOViewManager::zoomOutVertically()
00283 {
00284   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutVertically();
00285 }
00286 
00287 void KOViewManager::addView(KOrg::BaseView *view)
00288 {
00289   connectView( view );
00290 #if QT_VERSION >= 300
00291   mMainView->viewStack()->addWidget( view );
00292 #else
00293   mMainView->viewStack()->addWidget( view, 1 );
00294 #endif
00295 }
00296 
00297 void KOViewManager::showWhatsNextView()
00298 {
00299   if (!mWhatsNextView) {
00300     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00301                                          "KOViewManager::WhatsNextView");
00302     addView(mWhatsNextView);
00303   }
00304   goMenu( true );
00305   showView(mWhatsNextView);
00306 }
00307 
00308 void KOViewManager::showListView()
00309 {
00310   if (!mListView) {
00311     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00312     addView(mListView);
00313   }
00314   goMenu( true );
00315   showView(mListView);
00316 }
00317 
00318 void KOViewManager::showAgendaView()
00319 {
00320   const bool showBoth = KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::AllCalendarViews;
00321   const bool showMerged = showBoth || KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::CalendarsMerged;
00322   const bool showSideBySide = showBoth || KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::CalendarsSideBySide;
00323 
00324   QWidget *parent = mMainView->viewStack();
00325   if ( !mAgendaViewTabs && showBoth ) {
00326     mAgendaViewTabs = new QTabWidget( mMainView->viewStack() );
00327     connect( mAgendaViewTabs, SIGNAL( currentChanged( QWidget* ) ),
00328              this, SLOT( currentAgendaViewTabChanged( QWidget* ) ) );
00329     parent = mAgendaViewTabs;
00330   }
00331 
00332   if ( !mAgendaView && showMerged ) {
00333     mAgendaView = new KOAgendaView(mMainView->calendar(), parent, "KOViewManager::AgendaView");
00334 
00335     addView(mAgendaView);
00336 
00337     connect(mAgendaView, SIGNAL( toggleExpand() ),
00338             mMainView, SLOT( toggleExpand() ) );
00339     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00340             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00341 
00342     connect( mAgendaView,SIGNAL( zoomViewHorizontally(const QDate &, int )),
00343              mMainView->dateNavigator(),SLOT( selectDates( const QDate &, int ) ) );
00344     mAgendaView->readSettings();
00345   }
00346 
00347   if ( !mAgendaSideBySideView && showSideBySide ) {
00348     mAgendaSideBySideView =
00349       new MultiAgendaView( mMainView->calendar(), parent,
00350                         "KOViewManager::AgendaSideBySideView" );
00351 
00352     addView(mAgendaSideBySideView);
00353 
00354 /*    connect(mAgendaSideBySideView, SIGNAL( toggleExpand() ),
00355             mMainView, SLOT( toggleExpand() ) );
00356     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00357             mAgendaSideBySideView, SLOT( setExpandedButton( bool ) ) );
00358 
00359     connect( mAgendaSideBySideView,SIGNAL( zoomViewHorizontally(const QDate &, int )),
00360              mMainView->dateNavigator(),SLOT( selectDates( const QDate &, int ) ) );*/
00361   }
00362 
00363   if ( showBoth && mAgendaViewTabs ) {
00364     if ( mAgendaView && mAgendaViewTabs->indexOf( mAgendaView ) < 0 )
00365       mAgendaViewTabs->addTab( mAgendaView, i18n("Merged calendar") );
00366     if ( mAgendaSideBySideView  && mAgendaViewTabs->indexOf( mAgendaSideBySideView ) < 0 )
00367       mAgendaViewTabs->addTab( mAgendaSideBySideView, i18n("Calendars Side by Side") );
00368   } else {
00369     if ( mAgendaView && mMainView->viewStack()->id( mAgendaView ) < 0 )
00370       mMainView->viewStack()->addWidget( mAgendaView );
00371     if ( mAgendaSideBySideView && mMainView->viewStack()->id( mAgendaSideBySideView ) < 0 )
00372       mMainView->viewStack()->addWidget( mAgendaSideBySideView );
00373   }
00374 
00375   goMenu( true );
00376   if ( mAgendaViewTabs && showBoth )
00377     showView( static_cast<KOrg::BaseView*>( mAgendaViewTabs->currentPage() ) );
00378   else if ( mAgendaView && showMerged )
00379     showView( mAgendaView );
00380   else if ( mAgendaSideBySideView && showSideBySide )
00381     showView( mAgendaSideBySideView );
00382 }
00383 
00384 void KOViewManager::showDayView()
00385 {
00386   showAgendaView();
00387   mMainView->dateNavigator()->selectDates( 1 );
00388 }
00389 
00390 void KOViewManager::showWorkWeekView()
00391 {
00392   showAgendaView();
00393   mMainView->dateNavigator()->selectWorkWeek();
00394 }
00395 
00396 void KOViewManager::showWeekView()
00397 {
00398   showAgendaView();
00399   mMainView->dateNavigator()->selectWeek();
00400 }
00401 
00402 void KOViewManager::showNextXView()
00403 {
00404   showAgendaView();
00405   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00406                                            KOPrefs::instance()->mNextXDays );
00407 }
00408 
00409 void KOViewManager::showMonthView()
00410 {
00411   if (!mMonthView) {
00412     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00413     addView(mMonthView);
00414   }
00415 
00416   goMenu( true );
00417   showView(mMonthView);
00418 }
00419 
00420 void KOViewManager::showTodoView()
00421 {
00422   if ( !mTodoView ) {
00423     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00424                                 "KOViewManager::TodoView" );
00425     mTodoView->setCalendar( mMainView->calendar() );
00426     addView( mTodoView );
00427     connectTodoView( mTodoView );
00428 
00429     KConfig *config = KOGlobals::self()->config();
00430     mTodoView->restoreLayout( config, "Todo View" );
00431   }
00432 
00433   goMenu( false );
00434   showView( mTodoView );
00435 }
00436 
00437 void KOViewManager::showJournalView()
00438 {
00439   if (!mJournalView) {
00440     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00441                                      "KOViewManager::JournalView");
00442     addView(mJournalView);
00443   }
00444 
00445   goMenu( true );
00446   showView(mJournalView);
00447 }
00448 
00449 
00450 void KOViewManager::showTimelineView()
00451 {
00452   if (!mTimelineView) {
00453     mTimelineView = new KOTimelineView(mMainView->calendar(),mMainView->viewStack(),
00454                                      "KOViewManager::TimelineView");
00455     addView(mTimelineView);
00456   }
00457   goMenu( true );
00458   showView(mTimelineView);
00459 }
00460 
00461 void KOViewManager::showEventView()
00462 {
00463   if ( mLastEventView ) {
00464     goMenu( true );
00465     showView( mLastEventView );
00466   } else {
00467     showWeekView();
00468   }
00469 }
00470 
00471 Incidence *KOViewManager::currentSelection()
00472 {
00473   if ( !mCurrentView ) return 0;
00474   Incidence::List incidenceList = mCurrentView->selectedIncidences();
00475   if ( incidenceList.isEmpty() ) return 0;
00476 
00477   return incidenceList.first();
00478 }
00479 
00480 QDate KOViewManager::currentSelectionDate()
00481 {
00482   QDate qd;
00483   if (mCurrentView) {
00484     DateList qvl = mCurrentView->selectedDates();
00485     if (!qvl.isEmpty()) qd = qvl.first();
00486   }
00487   return qd;
00488 }
00489 
00490 void KOViewManager::setDocumentId( const QString &id )
00491 {
00492   if (mTodoView) mTodoView->setDocumentId( id );
00493 }
00494 
00495 
00496 QWidget* KOViewManager::widgetForView( KOrg::BaseView* view ) const
00497 {
00498   const bool showBoth = KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::AllCalendarViews;
00499   if ( (view == mAgendaView || view == mAgendaSideBySideView) && mAgendaViewTabs && showBoth ) {
00500     return mAgendaViewTabs;
00501   }
00502   return view;
00503 }
00504 
00505 
00506 void KOViewManager::currentAgendaViewTabChanged( QWidget* widget )
00507 {
00508   goMenu( true );
00509   showView( static_cast<KOrg::BaseView*>( widget ) );
00510 }
00511 
00512 void KOViewManager::resourcesChanged()
00513 {
00514   if ( mAgendaView )
00515     mAgendaView->resourcesChanged();
00516   if ( mAgendaSideBySideView )
00517     mAgendaSideBySideView->resourcesChanged();
00518 }
00519 
00520 void KOViewManager::updateMultiCalendarDisplay()
00521 {
00522   if ( mCurrentView == mAgendaView            ||
00523        mCurrentView == mAgendaSideBySideView  ||
00524        ( mAgendaViewTabs && mCurrentView == mAgendaViewTabs->currentPage() ) ) {
00525     showAgendaView();
00526   } else {
00527     updateView();
00528   }
00529 }
KDE Home | KDE Accessibility Home | Description of Access Keys