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   mAgendaMode = AGENDA_NONE;
00069 }
00070 
00071 KOViewManager::~KOViewManager()
00072 {
00073 }
00074 
00075 
00076 KOrg::BaseView *KOViewManager::currentView()
00077 {
00078   return mCurrentView;
00079 }
00080 
00081 void KOViewManager::readSettings(KConfig *config)
00082 {
00083   config->setGroup("General");
00084   QString view = config->readEntry("Current View");
00085 
00086   if (view == "WhatsNext") showWhatsNextView();
00087   else if (view == "Month") showMonthView();
00088   else if (view == "List") showListView();
00089   else if (view == "Journal") showJournalView();
00090   else if (view == "Todo") showTodoView();
00091   else if (view == "Timeline") showTimelineView();
00092   else showAgendaView();
00093 }
00094 
00095 void KOViewManager::writeSettings(KConfig *config)
00096 {
00097   config->setGroup("General");
00098 
00099   QString view;
00100   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00101   else if (mCurrentView == mMonthView) view = "Month";
00102   else if (mCurrentView == mListView) view = "List";
00103   else if (mCurrentView == mJournalView) view = "Journal";
00104   else if (mCurrentView == mTodoView) view = "Todo";
00105   else if (mCurrentView == mTimelineView) view = "Timeline";
00106   else view = "Agenda";
00107 
00108   config->writeEntry("Current View",view);
00109 
00110   if (mAgendaView) {
00111     mAgendaView->writeSettings(config);
00112   }
00113   if (mListView) {
00114     mListView->writeSettings(config);
00115   }
00116   if (mTodoView) {
00117     mTodoView->saveLayout(config,"Todo View");
00118   }
00119 }
00120 
00121 void KOViewManager::showView(KOrg::BaseView *view)
00122 {
00123   if( view == mCurrentView ) return;
00124 
00125   mCurrentView = view;
00126 
00127   if ( mCurrentView && mCurrentView->isEventView() ) {
00128     mLastEventView = mCurrentView;
00129   }
00130 
00131   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00132 
00133   raiseCurrentView();
00134 
00135   mMainView->processIncidenceSelection( 0, QDate() );
00136 
00137   mMainView->updateView();
00138 
00139   mMainView->adaptNavigationUnits();
00140 }
00141 
00142 void KOViewManager::goMenu( bool enable )
00143 {
00144   KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00145   if ( w ) {
00146     KActionCollection *ac = w->getActionCollection();
00147     if ( ac ) {
00148       KAction *action;
00149       action = ac->action( "go_today" );
00150       if ( action ) {
00151         action->setEnabled( enable );
00152       }
00153       action = ac->action( "go_previous" );
00154       if ( action ) {
00155         action->setEnabled( enable );
00156       }
00157       action = ac->action( "go_next" );
00158       if ( action ) {
00159         action->setEnabled( enable );
00160       }
00161     }
00162   }
00163 }
00164 
00165 void KOViewManager::raiseCurrentView()
00166 {
00167   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00168       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00169     mMainView->showLeftFrame( false );
00170     if ( mCurrentView == mTodoView ) {
00171       mMainView->navigatorBar()->hide();
00172     } else {
00173       mMainView->navigatorBar()->show();
00174     }
00175   } else {
00176     mMainView->showLeftFrame( true );
00177     mMainView->navigatorBar()->hide();
00178   }
00179   mMainView->viewStack()->raiseWidget( widgetForView( mCurrentView  ) );
00180 }
00181 
00182 void KOViewManager::updateView()
00183 {
00184   if ( mCurrentView ) mCurrentView->updateView();
00185 }
00186 
00187 void KOViewManager::updateView(const QDate &start, const QDate &end)
00188 {
00189 //  kdDebug(5850) << "KOViewManager::updateView()" << endl;
00190 
00191   if (mCurrentView) mCurrentView->showDates(start, end);
00192 
00193   if (mTodoView) mTodoView->updateView();
00194 }
00195 
00196 void KOViewManager::connectView(KOrg::BaseView *view)
00197 {
00198   if (!view) return;
00199 
00200   // selecting an incidence
00201   connect( view, SIGNAL( incidenceSelected( Incidence *,const QDate & ) ),
00202            mMainView, SLOT( processMainViewSelection( Incidence *,const QDate & ) ) );
00203 
00204   // showing/editing/deleting an incidence. The calendar view takes care of the action.
00205   connect(view, SIGNAL(showIncidenceSignal(Incidence *)),
00206           mMainView, SLOT(showIncidence(Incidence *)));
00207   connect(view, SIGNAL(editIncidenceSignal(Incidence *)),
00208           mMainView, SLOT(editIncidence(Incidence *)));
00209   connect(view, SIGNAL(deleteIncidenceSignal(Incidence *)),
00210           mMainView, SLOT(deleteIncidence(Incidence *)));
00211   connect(view, SIGNAL(copyIncidenceSignal(Incidence *)),
00212           mMainView, SLOT(copyIncidence(Incidence *)));
00213   connect(view, SIGNAL(cutIncidenceSignal(Incidence *)),
00214           mMainView, SLOT(cutIncidence(Incidence *)));
00215   connect(view, SIGNAL(pasteIncidenceSignal()),
00216           mMainView, SLOT(pasteIncidence()));
00217   connect(view, SIGNAL(toggleAlarmSignal(Incidence *)),
00218           mMainView, SLOT(toggleAlarm(Incidence *)));
00219   connect(view,SIGNAL(dissociateOccurrenceSignal( Incidence *, const QDate & )),
00220           mMainView, SLOT(dissociateOccurrence( Incidence *, const QDate & )));
00221   connect(view,SIGNAL(dissociateFutureOccurrenceSignal( Incidence *, const QDate & )),
00222           mMainView, SLOT(dissociateFutureOccurrence( Incidence *, const QDate & )));
00223 
00224   // signals to create new incidences
00225   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &)),
00226            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &)) );
00227   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDate &)),
00228            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDate &)) );
00229   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDateTime &)),
00230            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDateTime &)) );
00231   connect( view, SIGNAL(newEventSignal(ResourceCalendar *,const QString &,const QDateTime &,const QDateTime &)),
00232            mMainView, SLOT(newEvent(ResourceCalendar *,const QString &,const QDateTime &,const QDateTime &)) );
00233 
00234   connect( view, SIGNAL(newTodoSignal(ResourceCalendar *,const QString &,const QDate &)),
00235            mMainView, SLOT(newTodo(ResourceCalendar *,const QString &,const QDate &)) );
00236   connect( view, SIGNAL(newSubTodoSignal(Todo *)),
00237            mMainView, SLOT(newSubTodo(Todo *)) );
00238 
00239   connect( view, SIGNAL(newJournalSignal(ResourceCalendar *,const QString &,const QDate &)),
00240            mMainView, SLOT(newJournal(ResourceCalendar *,const QString &,const QDate &)) );
00241 
00242   // reload settings
00243   connect(mMainView, SIGNAL(configChanged()), view, SLOT(updateConfig()));
00244 
00245   // Notifications about added, changed and deleted incidences
00246   connect( mMainView, SIGNAL( dayPassed( const QDate & ) ),
00247            view, SLOT( dayPassed( const QDate & ) ) );
00248   connect( view, SIGNAL( startMultiModify( const QString & ) ),
00249            mMainView, SLOT( startMultiModify( const QString & ) ) );
00250   connect( view, SIGNAL( endMultiModify() ),
00251            mMainView, SLOT( endMultiModify() ) );
00252 
00253   connect( mMainView, SIGNAL( newIncidenceChanger( IncidenceChangerBase* ) ),
00254            view, SLOT( setIncidenceChanger( IncidenceChangerBase * ) ) );
00255   view->setIncidenceChanger( mMainView->incidenceChanger() );
00256 }
00257 
00258 void KOViewManager::connectTodoView( KOTodoView* todoView )
00259 {
00260   if (!todoView) return;
00261 
00262   // SIGNALS/SLOTS FOR TODO VIEW
00263   connect( todoView, SIGNAL( purgeCompletedSignal() ),
00264            mMainView, SLOT( purgeCompleted() ) );
00265   connect( todoView, SIGNAL( unSubTodoSignal() ),
00266            mMainView, SLOT( todo_unsub() ) );
00267   connect( todoView, SIGNAL( unAllSubTodoSignal() ),
00268            mMainView, SLOT( makeSubTodosIndependents() ) );
00269 }
00270 
00271 void KOViewManager::zoomInHorizontally()
00272 {
00273   if( mAgendaView == mCurrentView ) mAgendaView->zoomInHorizontally();
00274 }
00275 void KOViewManager::zoomOutHorizontally()
00276 {
00277   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutHorizontally();
00278 }
00279 void KOViewManager::zoomInVertically()
00280 {
00281   if( mAgendaView== mCurrentView ) mAgendaView->zoomInVertically();
00282 }
00283 void KOViewManager::zoomOutVertically()
00284 {
00285   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutVertically();
00286 }
00287 
00288 void KOViewManager::addView(KOrg::BaseView *view)
00289 {
00290   connectView( view );
00291 #if QT_VERSION >= 300
00292   mMainView->viewStack()->addWidget( view );
00293 #else
00294   mMainView->viewStack()->addWidget( view, 1 );
00295 #endif
00296 }
00297 
00298 void KOViewManager::showWhatsNextView()
00299 {
00300   if (!mWhatsNextView) {
00301     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00302                                          "KOViewManager::WhatsNextView");
00303     addView(mWhatsNextView);
00304   }
00305   goMenu( true );
00306   showView(mWhatsNextView);
00307 }
00308 
00309 void KOViewManager::showListView()
00310 {
00311   if (!mListView) {
00312     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00313     addView(mListView);
00314   }
00315   goMenu( true );
00316   showView(mListView);
00317 }
00318 
00319 void KOViewManager::showAgendaView()
00320 {
00321   const bool showBoth = KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::AllCalendarViews;
00322   const bool showMerged = showBoth || KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::CalendarsMerged;
00323   const bool showSideBySide = showBoth || KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::CalendarsSideBySide;
00324 
00325   QWidget *parent = mMainView->viewStack();
00326   if ( !mAgendaViewTabs && showBoth ) {
00327     mAgendaViewTabs = new QTabWidget( mMainView->viewStack() );
00328     connect( mAgendaViewTabs, SIGNAL( currentChanged( QWidget* ) ),
00329              this, SLOT( currentAgendaViewTabChanged( QWidget* ) ) );
00330     parent = mAgendaViewTabs;
00331   }
00332 
00333   if ( !mAgendaView && showMerged ) {
00334     mAgendaView = new KOAgendaView( mMainView->calendar(),
00335                                     mMainView,
00336                                     parent,
00337                                     "KOViewManager::AgendaView" );
00338 
00339     addView(mAgendaView);
00340 
00341     connect(mAgendaView, SIGNAL( toggleExpand() ),
00342             mMainView, SLOT( toggleExpand() ) );
00343     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00344             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00345 
00346     connect( mAgendaView,SIGNAL( zoomViewHorizontally(const QDate &, int )),
00347              mMainView->dateNavigator(),SLOT( selectDates( const QDate &, int ) ) );
00348     mAgendaView->readSettings();
00349   }
00350 
00351   if ( !mAgendaSideBySideView && showSideBySide ) {
00352     mAgendaSideBySideView =
00353       new MultiAgendaView( mMainView->calendar(), mMainView, parent,
00354                         "KOViewManager::AgendaSideBySideView" );
00355 
00356     addView(mAgendaSideBySideView);
00357 
00358 /*    connect(mAgendaSideBySideView, SIGNAL( toggleExpand() ),
00359             mMainView, SLOT( toggleExpand() ) );
00360     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00361             mAgendaSideBySideView, SLOT( setExpandedButton( bool ) ) );
00362 
00363     connect( mAgendaSideBySideView,SIGNAL( zoomViewHorizontally(const QDate &, int )),
00364              mMainView->dateNavigator(),SLOT( selectDates( const QDate &, int ) ) );*/
00365   }
00366 
00367   if ( showBoth && mAgendaViewTabs ) {
00368     if ( mAgendaView && mAgendaViewTabs->indexOf( mAgendaView ) < 0 )
00369       mAgendaViewTabs->addTab( mAgendaView, i18n("Merged calendar") );
00370     if ( mAgendaSideBySideView  && mAgendaViewTabs->indexOf( mAgendaSideBySideView ) < 0 )
00371       mAgendaViewTabs->addTab( mAgendaSideBySideView, i18n("Calendars Side by Side") );
00372   } else {
00373     if ( mAgendaView && mMainView->viewStack()->id( mAgendaView ) < 0 )
00374       mMainView->viewStack()->addWidget( mAgendaView );
00375     if ( mAgendaSideBySideView && mMainView->viewStack()->id( mAgendaSideBySideView ) < 0 )
00376       mMainView->viewStack()->addWidget( mAgendaSideBySideView );
00377   }
00378 
00379   goMenu( true );
00380   if ( mAgendaViewTabs && showBoth )
00381     showView( static_cast<KOrg::BaseView*>( mAgendaViewTabs->currentPage() ) );
00382   else if ( mAgendaView && showMerged )
00383     showView( mAgendaView );
00384   else if ( mAgendaSideBySideView && showSideBySide )
00385     showView( mAgendaSideBySideView );
00386 }
00387 
00388 void KOViewManager::showDayView()
00389 {
00390   mAgendaMode = AGENDA_DAY;
00391   showAgendaView();
00392   mMainView->dateNavigator()->selectDates( 1 );
00393 }
00394 
00395 void KOViewManager::showWorkWeekView()
00396 {
00397   mAgendaMode = AGENDA_WORK_WEEK;
00398   showAgendaView();
00399   mMainView->dateNavigator()->selectWorkWeek();
00400 }
00401 
00402 void KOViewManager::showWeekView()
00403 {
00404   mAgendaMode = AGENDA_WEEK;
00405   showAgendaView();
00406   mMainView->dateNavigator()->selectWeek();
00407 }
00408 
00409 void KOViewManager::showNextXView()
00410 {
00411   mAgendaMode = AGENDA_NEXTX;
00412   showAgendaView();
00413   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00414                                            KOPrefs::instance()->mNextXDays );
00415 }
00416 
00417 void KOViewManager::showMonthView()
00418 {
00419   if (!mMonthView) {
00420     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00421     addView(mMonthView);
00422   }
00423 
00424   goMenu( true );
00425   showView(mMonthView);
00426 }
00427 
00428 void KOViewManager::showTodoView()
00429 {
00430   if ( !mTodoView ) {
00431     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00432                                 "KOViewManager::TodoView" );
00433     mTodoView->setCalendar( mMainView->calendar() );
00434     addView( mTodoView );
00435     connectTodoView( mTodoView );
00436 
00437     KConfig *config = KOGlobals::self()->config();
00438     mTodoView->restoreLayout( config, "Todo View" );
00439   }
00440 
00441   goMenu( false );
00442   showView( mTodoView );
00443 }
00444 
00445 void KOViewManager::showJournalView()
00446 {
00447   if (!mJournalView) {
00448     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00449                                      "KOViewManager::JournalView");
00450     addView(mJournalView);
00451   }
00452 
00453   goMenu( true );
00454   showView(mJournalView);
00455 }
00456 
00457 
00458 void KOViewManager::showTimelineView()
00459 {
00460   if (!mTimelineView) {
00461     mTimelineView = new KOTimelineView(mMainView->calendar(),mMainView->viewStack(),
00462                                      "KOViewManager::TimelineView");
00463     addView(mTimelineView);
00464   }
00465   goMenu( true );
00466   showView(mTimelineView);
00467 }
00468 
00469 void KOViewManager::showEventView()
00470 {
00471   if ( mLastEventView ) {
00472     goMenu( true );
00473     showView( mLastEventView );
00474   } else {
00475     showWeekView();
00476   }
00477 }
00478 
00479 Incidence *KOViewManager::currentSelection()
00480 {
00481   if ( !mCurrentView ) return 0;
00482   Incidence::List incidenceList = mCurrentView->selectedIncidences();
00483   if ( incidenceList.isEmpty() ) return 0;
00484 
00485   return incidenceList.first();
00486 }
00487 
00488 QDate KOViewManager::currentSelectionDate()
00489 {
00490   QDate qd;
00491   if (mCurrentView) {
00492     DateList qvl = mCurrentView->selectedDates();
00493     if (!qvl.isEmpty()) qd = qvl.first();
00494   }
00495   return qd;
00496 }
00497 
00498 void KOViewManager::setDocumentId( const QString &id )
00499 {
00500   if (mTodoView) mTodoView->setDocumentId( id );
00501 }
00502 
00503 
00504 QWidget* KOViewManager::widgetForView( KOrg::BaseView* view ) const
00505 {
00506   const bool showBoth = KOPrefs::instance()->agendaViewCalendarDisplay() == KOPrefs::AllCalendarViews;
00507   if ( (view == mAgendaView || view == mAgendaSideBySideView) && mAgendaViewTabs && showBoth ) {
00508     return mAgendaViewTabs;
00509   }
00510   return view;
00511 }
00512 
00513 
00514 void KOViewManager::currentAgendaViewTabChanged( QWidget* widget )
00515 {
00516   goMenu( true );
00517   showView( static_cast<KOrg::BaseView*>( widget ) );
00518 }
00519 
00520 void KOViewManager::resourcesChanged()
00521 {
00522   if ( mAgendaView )
00523     mAgendaView->resourcesChanged();
00524   if ( mAgendaSideBySideView )
00525     mAgendaSideBySideView->resourcesChanged();
00526 }
00527 
00528 void KOViewManager::updateMultiCalendarDisplay()
00529 {
00530   if ( mCurrentView == mAgendaView            ||
00531        mCurrentView == mAgendaSideBySideView  ||
00532        ( mAgendaViewTabs && mCurrentView == mAgendaViewTabs->currentPage() ) ) {
00533     showAgendaView();
00534   } else {
00535     updateView();
00536   }
00537 }
KDE Home | KDE Accessibility Home | Description of Access Keys