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 
00028 #include <kconfig.h>
00029 #include <kglobal.h>
00030 
00031 #include "calendarview.h"
00032 #include "datenavigator.h"
00033 #include "kotodoview.h"
00034 #include "koagendaview.h"
00035 #include "komonthview.h"
00036 #include "kolistview.h"
00037 #include "kowhatsnextview.h"
00038 #include "kojournalview.h"
00039 #include "koprefs.h"
00040 #include "koglobals.h"
00041 #include "navigatorbar.h"
00042 
00043 #include "koviewmanager.h"
00044 #include "koviewmanager.moc"
00045 
00046 KOViewManager::KOViewManager( CalendarView *mainView ) :
00047   QObject(), mMainView( mainView )
00048 {
00049   mCurrentView = 0;
00050 
00051   mLastEventView = 0;
00052 
00053   mWhatsNextView = 0;
00054   mTodoView = 0;
00055   mAgendaView = 0;
00056   mMonthView = 0;
00057   mListView = 0;
00058   mJournalView = 0;
00059 }
00060 
00061 KOViewManager::~KOViewManager()
00062 {
00063 }
00064 
00065 
00066 KOrg::BaseView *KOViewManager::currentView()
00067 {
00068   return mCurrentView;
00069 }
00070 
00071 void KOViewManager::readSettings(KConfig *config)
00072 {
00073   config->setGroup("General");
00074   QString view = config->readEntry("Current View");
00075 
00076   if (view == "WhatsNext") showWhatsNextView();
00077   else if (view == "Month") showMonthView();
00078   else if (view == "List") showListView();
00079   else if (view == "Journal") showJournalView();
00080   else if (view == "Todo") showTodoView();
00081   else showAgendaView();
00082 }
00083 
00084 void KOViewManager::writeSettings(KConfig *config)
00085 {
00086   config->setGroup("General");
00087 
00088   QString view;
00089   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00090   else if (mCurrentView == mMonthView) view = "Month";
00091   else if (mCurrentView == mListView) view = "List";
00092   else if (mCurrentView == mJournalView) view = "Journal";
00093   else if (mCurrentView == mTodoView) view = "Todo";
00094   else view = "Agenda";
00095 
00096   config->writeEntry("Current View",view);
00097 
00098   if (mAgendaView) {
00099     mAgendaView->writeSettings(config);
00100   }
00101   if (mListView) {
00102     mListView->writeSettings(config);
00103   }
00104   if (mTodoView) {
00105     mTodoView->saveLayout(config,"Todo View");
00106   }
00107 }
00108 
00109 void KOViewManager::showView(KOrg::BaseView *view)
00110 {
00111   if( view == mCurrentView ) return;
00112 
00113   mCurrentView = view;
00114 
00115   if ( mCurrentView && mCurrentView->isEventView() ) {
00116     mLastEventView = mCurrentView;
00117   }
00118 
00119   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00120 
00121   raiseCurrentView();
00122   mMainView->processIncidenceSelection( 0 );
00123 
00124   mMainView->updateView();
00125 
00126   mMainView->adaptNavigationUnits();
00127 }
00128 
00129 void KOViewManager::raiseCurrentView()
00130 {
00131   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00132       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00133     mMainView->showLeftFrame( false );
00134     if ( mCurrentView == mTodoView ) {
00135       mMainView->navigatorBar()->hide();
00136     } else {
00137       mMainView->navigatorBar()->show();
00138     }
00139   } else {
00140     mMainView->showLeftFrame( true );
00141     mMainView->navigatorBar()->hide();
00142   }
00143   mMainView->viewStack()->raiseWidget(mCurrentView);
00144 }
00145 
00146 void KOViewManager::updateView()
00147 {
00148   if ( mCurrentView ) mCurrentView->updateView();
00149 }
00150 
00151 void KOViewManager::updateView(const QDate &start, const QDate &end)
00152 {
00153 //  kdDebug(5850) << "KOViewManager::updateView()" << endl;
00154 
00155   if (mCurrentView) mCurrentView->showDates(start, end);
00156 
00157   if (mTodoView) mTodoView->updateView();
00158 }
00159 
00160 void KOViewManager::connectView(KOrg::BaseView *view)
00161 {
00162   if (!view) return;
00163 
00164   // selecting an incidence
00165   connect( view, SIGNAL( incidenceSelected( Incidence * ) ),
00166            mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00167 
00168   // showing/editing/deleting an incidence. The calendar view takes care of the action.
00169   connect(view, SIGNAL(showIncidenceSignal(Incidence *)),
00170           mMainView, SLOT(showIncidence(Incidence *)));
00171   connect(view, SIGNAL(editIncidenceSignal(Incidence *)),
00172           mMainView, SLOT(editIncidence(Incidence *)));
00173   connect(view, SIGNAL(deleteIncidenceSignal(Incidence *)),
00174           mMainView, SLOT(deleteIncidence(Incidence *)));
00175   connect(view, SIGNAL(copyIncidenceSignal(Incidence *)),
00176           mMainView, SLOT(copyIncidence(Incidence *)));
00177   connect(view, SIGNAL(cutIncidenceSignal(Incidence *)),
00178           mMainView, SLOT(cutIncidence(Incidence *)));
00179   connect(view, SIGNAL(toggleAlarmSignal(Incidence *)),
00180           mMainView, SLOT(toggleAlarm(Incidence *)));
00181   connect(view,SIGNAL(dissociateOccurrenceSignal( Incidence *, const QDate & )),
00182           mMainView, SLOT(dissociateOccurrence( Incidence *, const QDate & )));
00183   connect(view,SIGNAL(dissociateFutureOccurrenceSignal( Incidence *, const QDate & )),
00184           mMainView, SLOT(dissociateFutureOccurrence( Incidence *, const QDate & )));
00185 
00186   // signals to create new incidences
00187   connect( view, SIGNAL( newEventSignal() ),
00188            mMainView, SLOT( newEvent() ) );
00189   connect( view, SIGNAL( newEventSignal( const QDateTime & ) ),
00190            mMainView, SLOT( newEvent( const QDateTime & ) ) );
00191   connect( view, SIGNAL( newEventSignal( const QDateTime &, const QDateTime & ) ),
00192            mMainView, SLOT( newEvent( const QDateTime &, const QDateTime & ) ) );
00193   connect( view, SIGNAL( newEventSignal( const QDate & ) ),
00194            mMainView, SLOT( newEvent( const QDate & ) ) );
00195   connect( view, SIGNAL( newTodoSignal( const QDate & ) ),
00196            mMainView, SLOT( newTodo( const QDate & ) ) );
00197   connect( view, SIGNAL( newSubTodoSignal( Todo * ) ),
00198            mMainView, SLOT( newSubTodo( Todo *) ) );
00199   connect( view, SIGNAL( newJournalSignal( const QDate & ) ),
00200            mMainView, SLOT( newJournal( const QDate & ) ) );
00201 
00202   // reload settings
00203   connect(mMainView, SIGNAL(configChanged()), view, SLOT(updateConfig()));
00204 
00205   // Notifications about added, changed and deleted incidences
00206   connect( mMainView, SIGNAL( dayPassed( const QDate & ) ),
00207            view, SLOT( dayPassed( const QDate & ) ) );
00208   connect( view, SIGNAL( startMultiModify( const QString & ) ),
00209            mMainView, SLOT( startMultiModify( const QString & ) ) );
00210   connect( view, SIGNAL( endMultiModify() ),
00211            mMainView, SLOT( endMultiModify() ) );
00212 
00213   connect( mMainView, SIGNAL( newIncidenceChanger( IncidenceChangerBase* ) ),
00214            view, SLOT( setIncidenceChanger( IncidenceChangerBase * ) ) );
00215   view->setIncidenceChanger( mMainView->incidenceChanger() );
00216 }
00217 
00218 void KOViewManager::connectTodoView( KOTodoView* todoView )
00219 {
00220   if (!todoView) return;
00221 
00222   // SIGNALS/SLOTS FOR TODO VIEW
00223   connect( todoView, SIGNAL( purgeCompletedSignal() ),
00224            mMainView, SLOT( purgeCompleted() ) );
00225   connect( todoView, SIGNAL( unSubTodoSignal() ),
00226            mMainView, SLOT( todo_unsub() ) );
00227   connect( todoView, SIGNAL( unAllSubTodoSignal() ),
00228            mMainView, SLOT( makeSubTodosIndependents() ) );
00229 }
00230 
00231 void KOViewManager::zoomInHorizontally()
00232 {
00233   if( mAgendaView == mCurrentView ) mAgendaView->zoomInHorizontally();
00234 }
00235 void KOViewManager::zoomOutHorizontally()
00236 {
00237   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutHorizontally();
00238 }
00239 void KOViewManager::zoomInVertically()
00240 {
00241   if( mAgendaView== mCurrentView ) mAgendaView->zoomInVertically();
00242 }
00243 void KOViewManager::zoomOutVertically()
00244 {
00245   if( mAgendaView== mCurrentView ) mAgendaView->zoomOutVertically();
00246 }
00247 
00248 void KOViewManager::addView(KOrg::BaseView *view)
00249 {
00250   connectView( view );
00251 #if QT_VERSION >= 300
00252   mMainView->viewStack()->addWidget( view );
00253 #else
00254   mMainView->viewStack()->addWidget( view, 1 );
00255 #endif
00256 }
00257 
00258 void KOViewManager::showWhatsNextView()
00259 {
00260   if (!mWhatsNextView) {
00261     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00262                                          "KOViewManager::WhatsNextView");
00263     addView(mWhatsNextView);
00264   }
00265   showView(mWhatsNextView);
00266 }
00267 
00268 void KOViewManager::showListView()
00269 {
00270   if (!mListView) {
00271     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00272     addView(mListView);
00273   }
00274   showView(mListView);
00275 }
00276 
00277 void KOViewManager::showAgendaView()
00278 {
00279   if (!mAgendaView) {
00280     mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
00281 
00282     addView(mAgendaView);
00283 
00284     connect(mAgendaView, SIGNAL( toggleExpand() ),
00285             mMainView, SLOT( toggleExpand() ) );
00286     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00287             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00288 
00289     connect( mAgendaView,SIGNAL( zoomViewHorizontally(const QDate &, int )),
00290       mMainView->dateNavigator(),SLOT( selectDates( const QDate &, int ) ) );
00291     mAgendaView->readSettings();
00292   }
00293 
00294   showView(mAgendaView);
00295 }
00296 
00297 void KOViewManager::showDayView()
00298 {
00299   showAgendaView();
00300   mMainView->dateNavigator()->selectDates( 1 );
00301 }
00302 
00303 void KOViewManager::showWorkWeekView()
00304 {
00305   showAgendaView();
00306   mMainView->dateNavigator()->selectWorkWeek();
00307 }
00308 
00309 void KOViewManager::showWeekView()
00310 {
00311   showAgendaView();
00312   mMainView->dateNavigator()->selectWeek();
00313 }
00314 
00315 void KOViewManager::showNextXView()
00316 {
00317   showAgendaView();
00318   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00319                                            KOPrefs::instance()->mNextXDays );
00320 }
00321 
00322 void KOViewManager::showMonthView()
00323 {
00324   if (!mMonthView) {
00325     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00326     addView(mMonthView);
00327   }
00328 
00329   showView(mMonthView);
00330 }
00331 
00332 void KOViewManager::showTodoView()
00333 {
00334   if ( !mTodoView ) {
00335     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00336                                 "KOViewManager::TodoView" );
00337     mTodoView->setCalendar( mMainView->calendar() );
00338     addView( mTodoView );
00339     connectTodoView( mTodoView );
00340 
00341     KConfig *config = KOGlobals::self()->config();
00342     mTodoView->restoreLayout( config, "Todo View" );
00343   }
00344 
00345   showView( mTodoView );
00346 }
00347 
00348 void KOViewManager::showJournalView()
00349 {
00350   if (!mJournalView) {
00351     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00352                                      "KOViewManager::JournalView");
00353     addView(mJournalView);
00354   }
00355 
00356   showView(mJournalView);
00357 }
00358 
00359 void KOViewManager::showEventView()
00360 {
00361   if ( mLastEventView ) showView( mLastEventView );
00362   else showWeekView();
00363 }
00364 
00365 Incidence *KOViewManager::currentSelection()
00366 {
00367   if ( !mCurrentView ) return 0;
00368   Incidence::List incidenceList = mCurrentView->selectedIncidences();
00369   if ( incidenceList.isEmpty() ) return 0;
00370 
00371   return incidenceList.first();
00372 }
00373 
00374 QDate KOViewManager::currentSelectionDate()
00375 {
00376   QDate qd;
00377   if (mCurrentView) {
00378     DateList qvl = mCurrentView->selectedDates();
00379     if (!qvl.isEmpty()) qd = qvl.first();
00380   }
00381   return qd;
00382 }
00383 
00384 void KOViewManager::setDocumentId( const QString &id )
00385 {
00386   if (mTodoView) mTodoView->setDocumentId( id );
00387 }
KDE Home | KDE Accessibility Home | Description of Access Keys