korganizer Library API Documentation

koviewmanager.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qwidgetstack.h>
00026 
00027 #include <kconfig.h>
00028 #include <kglobal.h>
00029 
00030 #include "calendarview.h"
00031 #include "datenavigator.h"
00032 #include "kotodoview.h"
00033 #include "koagendaview.h"
00034 #include "komonthview.h"
00035 #include "kolistview.h"
00036 #include "kowhatsnextview.h"
00037 #include "kojournalview.h"
00038 #include "kotimespanview.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   mTimeSpanView = 0;
00060 }
00061 
00062 KOViewManager::~KOViewManager()
00063 {
00064 }
00065 
00066 
00067 KOrg::BaseView *KOViewManager::currentView()
00068 {
00069   return mCurrentView;
00070 }
00071 
00072 void KOViewManager::readSettings(KConfig *config)
00073 {
00074   config->setGroup("General");
00075   QString view = config->readEntry("Current View");
00076 
00077   if (view == "WhatsNext") showWhatsNextView();
00078   else if (view == "Month") showMonthView();
00079   else if (view == "List") showListView();
00080   else if (view == "Journal") showJournalView();
00081   else if (view == "TimeSpan") showTimeSpanView();
00082   else if (view == "Todo") showTodoView();
00083   else showAgendaView();
00084 }
00085 
00086 void KOViewManager::writeSettings(KConfig *config)
00087 {
00088   config->setGroup("General");
00089 
00090   QString view;
00091   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00092   else if (mCurrentView == mMonthView) view = "Month";
00093   else if (mCurrentView == mListView) view = "List";
00094   else if (mCurrentView == mJournalView) view = "Journal";
00095   else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
00096   else if (mCurrentView == mTodoView) view = "Todo";
00097   else view = "Agenda";
00098 
00099   config->writeEntry("Current View",view);
00100 
00101   if (mAgendaView) {
00102     mAgendaView->writeSettings(config);
00103   }
00104   if (mTimeSpanView) {
00105     mTimeSpanView->writeSettings(config);
00106   }
00107   if (mListView) {
00108     mListView->writeSettings(config);
00109   }
00110   if (mTodoView) {
00111     mTodoView->saveLayout(config,"Todo View");
00112   }
00113 }
00114 
00115 void KOViewManager::showView(KOrg::BaseView *view)
00116 {
00117   if( view == mCurrentView ) return;
00118 
00119   mCurrentView = view;
00120 
00121   if ( mCurrentView && mCurrentView->isEventView() ) {
00122     mLastEventView = mCurrentView;
00123   }
00124 
00125   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00126 
00127   raiseCurrentView();
00128   mMainView->processIncidenceSelection( 0 );
00129 
00130   mMainView->updateView();
00131 
00132   mMainView->adaptNavigationUnits();
00133 }
00134 
00135 void KOViewManager::raiseCurrentView()
00136 {
00137   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00138       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00139     mMainView->showLeftFrame( false );
00140     if ( mCurrentView == mTodoView ) {
00141       mMainView->navigatorBar()->hide();
00142     } else {
00143       mMainView->navigatorBar()->show();
00144     }
00145   } else {
00146     mMainView->showLeftFrame( true );
00147     mMainView->navigatorBar()->hide();
00148   }
00149   mMainView->viewStack()->raiseWidget(mCurrentView);
00150 }
00151 
00152 void KOViewManager::updateView()
00153 {
00154   if ( mCurrentView ) mCurrentView->updateView();
00155 }
00156 
00157 void KOViewManager::updateView(const QDate &start, const QDate &end)
00158 {
00159 //  kdDebug(5850) << "KOViewManager::updateView()" << endl;
00160 
00161   if (mCurrentView) mCurrentView->showDates(start, end);
00162 
00163   if (mTodoView) mTodoView->updateView();
00164 }
00165 
00166 void KOViewManager::connectView(KOrg::BaseView *view)
00167 {
00168   if (!view) return;
00169 
00170   // selecting an incidence
00171   connect( view, SIGNAL( incidenceSelected( Incidence * ) ),
00172            mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00173 
00174   // showing/editing/deleting an incidence. The calendar view takes care of the action.
00175   connect(view, SIGNAL(showIncidenceSignal(Incidence *)),
00176           mMainView, SLOT(showIncidence(Incidence *)));
00177   connect(view, SIGNAL(editIncidenceSignal(Incidence *)),
00178           mMainView, SLOT(editIncidence(Incidence *)));
00179   connect(view, SIGNAL(deleteIncidenceSignal(Incidence *)),
00180           mMainView, SLOT(deleteIncidence(Incidence *)));
00181   connect(view, SIGNAL(toggleAlarmSignal(Incidence *)),
00182           mMainView, SLOT(toggleAlarm(Incidence *)));
00183 
00184   // signals to create new incidences
00185   connect( view, SIGNAL( newEventSignal() ),
00186            mMainView, SLOT( newEvent() ) );
00187   connect( view, SIGNAL( newEventSignal( QDateTime ) ),
00188            mMainView, SLOT( newEvent( QDateTime ) ) );
00189   connect( view, SIGNAL( newEventSignal( QDateTime, QDateTime ) ),
00190            mMainView, SLOT( newEvent( QDateTime, QDateTime ) ) );
00191   connect( view, SIGNAL( newEventSignal( QDate ) ),
00192            mMainView, SLOT( newEvent( QDate ) ) );
00193   connect( view, SIGNAL( newTodoSignal( QDate ) ),
00194            mMainView, SLOT( newTodo( QDate ) ) );
00195   connect( view, SIGNAL( newSubTodoSignal( Todo * ) ),
00196            mMainView, SLOT( newSubTodo( Todo *) ) );
00197 
00198   // reload settings
00199   connect(mMainView, SIGNAL(configChanged()), view, SLOT(updateConfig()));
00200 
00201   // Notifications about added, changed and deleted incidences
00202   connect( view, SIGNAL( incidenceAdded( Incidence* ) ),
00203            mMainView, SLOT( incidenceAdded( Incidence* ) ) );
00204   connect( view, SIGNAL( incidenceChanged( Incidence*, Incidence* ) ),
00205            mMainView, SLOT( incidenceChanged( Incidence*, Incidence* ) ) );
00206   connect( view, SIGNAL( incidenceChanged( Incidence*, Incidence*, int ) ),
00207            mMainView, SLOT( incidenceChanged( Incidence*, Incidence*, int ) ) );
00208   connect( view, SIGNAL( incidenceToBeDeleted( Incidence* ) ),
00209            mMainView, SLOT( incidenceToBeDeleted( Incidence* ) ) );
00210   connect( view, SIGNAL( incidenceDeleted( Incidence* ) ),
00211            mMainView, SLOT( incidenceDeleted( Incidence* ) ) );
00212   connect( mMainView, SIGNAL( dayPassed( QDate ) ),
00213            view, SLOT( dayPassed( QDate ) ) );
00214   connect( view, SIGNAL( startMultiModify( const QString & ) ),
00215            mMainView, SLOT( startMultiModify( const QString & ) ) );
00216   connect( view, SIGNAL( endMultiModify() ),
00217            mMainView, SLOT( endMultiModify() ) );
00218 }
00219 
00220 void KOViewManager::connectTodoView( KOTodoView* todoView )
00221 {
00222   if (!todoView) return;
00223 
00224   // SIGNALS/SLOTS FOR TODO VIEW
00225   connect( todoView, SIGNAL( purgeCompletedSignal() ),
00226            mMainView, SLOT( purgeCompleted() ) );
00227   connect( todoView, SIGNAL( unSubTodoSignal() ),
00228            mMainView, SLOT( todo_unsub() ) );
00229   connect( todoView, SIGNAL( todoCompleted( Todo * ) ),
00230            mMainView, SLOT( recurTodo( Todo * ) ) );
00231 }
00232 
00233 void KOViewManager::addView(KOrg::BaseView *view)
00234 {
00235   connectView( view );
00236 #if QT_VERSION >= 300
00237   mMainView->viewStack()->addWidget( view );
00238 #else
00239   mMainView->viewStack()->addWidget( view, 1 );
00240 #endif
00241 }
00242 
00243 void KOViewManager::showWhatsNextView()
00244 {
00245   if (!mWhatsNextView) {
00246     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00247                                          "KOViewManager::WhatsNextView");
00248     addView(mWhatsNextView);
00249   }
00250   showView(mWhatsNextView);
00251 }
00252 
00253 void KOViewManager::showListView()
00254 {
00255   if (!mListView) {
00256     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00257     addView(mListView);
00258   }
00259   showView(mListView);
00260 }
00261 
00262 void KOViewManager::showAgendaView()
00263 {
00264   if (!mAgendaView) {
00265     mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
00266 
00267     addView(mAgendaView);
00268 
00269     connect(mAgendaView, SIGNAL( toggleExpand() ),
00270             mMainView, SLOT( toggleExpand() ) );
00271     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00272             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00273 
00274     mAgendaView->readSettings();
00275   }
00276 
00277   showView(mAgendaView);
00278 }
00279 
00280 void KOViewManager::showDayView()
00281 {
00282   showAgendaView();
00283   mMainView->dateNavigator()->selectDates( 1 );
00284 }
00285 
00286 void KOViewManager::showWorkWeekView()
00287 {
00288   showAgendaView();
00289   mMainView->dateNavigator()->selectWorkWeek();
00290 }
00291 
00292 void KOViewManager::showWeekView()
00293 {
00294   showAgendaView();
00295   mMainView->dateNavigator()->selectWeek();
00296 }
00297 
00298 void KOViewManager::showNextXView()
00299 {
00300   showAgendaView();
00301   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00302                                            KOPrefs::instance()->mNextXDays );
00303 }
00304 
00305 void KOViewManager::showMonthView()
00306 {
00307   if (!mMonthView) {
00308     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00309     addView(mMonthView);
00310   }
00311 
00312   showView(mMonthView);
00313 }
00314 
00315 void KOViewManager::showTodoView()
00316 {
00317   if ( !mTodoView ) {
00318     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00319                                 "KOViewManager::TodoView" );
00320     mTodoView->setCalendar( mMainView->calendar() );
00321     addView( mTodoView );
00322     connectTodoView( mTodoView );
00323 
00324     KConfig *config = KOGlobals::self()->config();
00325     mTodoView->restoreLayout( config, "Todo View" );
00326   }
00327 
00328   showView( mTodoView );
00329 }
00330 
00331 void KOViewManager::showJournalView()
00332 {
00333   if (!mJournalView) {
00334     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00335                                      "KOViewManager::JournalView");
00336     addView(mJournalView);
00337   }
00338 
00339   showView(mJournalView);
00340 }
00341 
00342 void KOViewManager::showTimeSpanView()
00343 {
00344   if (!mTimeSpanView) {
00345     mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
00346                                        "KOViewManager::TimeSpanView");
00347     addView(mTimeSpanView);
00348     mTimeSpanView->readSettings();
00349   }
00350 
00351   showView(mTimeSpanView);
00352 }
00353 
00354 void KOViewManager::showEventView()
00355 {
00356   if ( mLastEventView ) showView( mLastEventView );
00357   else showWeekView();
00358 }
00359 
00360 Incidence *KOViewManager::currentSelection()
00361 {
00362   if ( !mCurrentView ) return 0;
00363   Incidence::List incidenceList = mCurrentView->selectedIncidences();
00364   if ( incidenceList.isEmpty() ) return 0;
00365 
00366   return incidenceList.first();
00367 }
00368 
00369 QDate KOViewManager::currentSelectionDate()
00370 {
00371   QDate qd;
00372   if (mCurrentView) {
00373     DateList qvl = mCurrentView->selectedDates();
00374     if (!qvl.isEmpty()) qd = qvl.first();
00375   }
00376   return qd;
00377 }
00378 
00379 void KOViewManager::setDocumentId( const QString &id )
00380 {
00381   if (mTodoView) mTodoView->setDocumentId( id );
00382 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 2 09:56:06 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003