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 "navigatorbar.h"
00041 
00042 #include "koviewmanager.h"
00043 #include "koviewmanager.moc"
00044 
00045 KOViewManager::KOViewManager( CalendarView *mainView ) :
00046   QObject(), mMainView( mainView )
00047 {
00048   mCurrentView = 0;
00049 
00050   mLastEventView = 0;
00051 
00052   mWhatsNextView = 0;
00053   mTodoView = 0;
00054   mAgendaView = 0;
00055   mMonthView = 0;
00056   mListView = 0;
00057   mJournalView = 0;
00058   mTimeSpanView = 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 == "TimeSpan") showTimeSpanView();
00081   else if (view == "Todo") showTodoView();
00082   else showAgendaView();
00083 }
00084 
00085 void KOViewManager::writeSettings(KConfig *config)
00086 {
00087   config->setGroup("General");
00088 
00089   QString view;
00090   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00091   else if (mCurrentView == mMonthView) view = "Month";
00092   else if (mCurrentView == mListView) view = "List";
00093   else if (mCurrentView == mJournalView) view = "Journal";
00094   else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
00095   else if (mCurrentView == mTodoView) view = "Todo";
00096   else view = "Agenda";
00097 
00098   config->writeEntry("Current View",view);
00099 
00100   if (mAgendaView) {
00101     mAgendaView->writeSettings(config);
00102   }
00103   if (mTimeSpanView) {
00104     mTimeSpanView->writeSettings(config);
00105   }
00106   if (mListView) {
00107     mListView->writeSettings(config);
00108   }
00109   if (mTodoView) {
00110     mTodoView->saveLayout(config,"Todo View");
00111   }
00112 }
00113 
00114 void KOViewManager::showView(KOrg::BaseView *view)
00115 {
00116   if( view == mCurrentView ) return;
00117 
00118   mCurrentView = view;
00119 
00120   if ( mCurrentView && mCurrentView->isEventView() ) {
00121     mLastEventView = mCurrentView;
00122   }
00123 
00124   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00125 
00126   raiseCurrentView();
00127   mMainView->processIncidenceSelection( 0 );
00128 
00129   mMainView->updateView();
00130 
00131   mMainView->adaptNavigationUnits();
00132 }
00133 
00134 void KOViewManager::raiseCurrentView()
00135 {
00136   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00137       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00138     mMainView->showLeftFrame( false );
00139     if ( mCurrentView == mTodoView ) {
00140       mMainView->navigatorBar()->hide();
00141     } else {
00142       mMainView->navigatorBar()->show();
00143     }
00144   } else {
00145     mMainView->showLeftFrame( true );
00146     mMainView->navigatorBar()->hide();
00147   }
00148   mMainView->viewStack()->raiseWidget(mCurrentView);
00149 }
00150 
00151 void KOViewManager::updateView()
00152 {
00153   if ( mCurrentView ) mCurrentView->updateView();
00154 }
00155 
00156 void KOViewManager::updateView(const QDate &start, const QDate &end)
00157 {
00158 //  kdDebug(5850) << "KOViewManager::updateView()" << endl;
00159 
00160   if (mCurrentView) mCurrentView->showDates(start, end);
00161 
00162   if (mTodoView) mTodoView->updateView();
00163 }
00164 
00165 
00166 void KOViewManager::showWhatsNextView()
00167 {
00168   if (!mWhatsNextView) {
00169     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00170                                          "KOViewManager::WhatsNextView");
00171     addView(mWhatsNextView);
00172   }
00173 
00174   showView(mWhatsNextView);
00175 }
00176 
00177 void KOViewManager::showListView()
00178 {
00179   if (!mListView) {
00180     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00181     addView(mListView);
00182 
00183     connect(mListView, SIGNAL(showIncidenceSignal(Incidence *)),
00184             mMainView, SLOT(showIncidence(Incidence *)));
00185     connect(mListView, SIGNAL(editIncidenceSignal(Incidence *)),
00186             mMainView, SLOT(editIncidence(Incidence *)));
00187     connect(mListView, SIGNAL(deleteIncidenceSignal(Incidence *)),
00188             mMainView, SLOT(deleteIncidence(Incidence *)));
00189 
00190     connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ),
00191              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00192 
00193     connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig()));
00194   }
00195 
00196   showView(mListView);
00197 }
00198 
00199 void KOViewManager::showAgendaView()
00200 {
00201   if (!mAgendaView) {
00202     mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
00203 
00204     addView(mAgendaView);
00205 
00206     connect( mAgendaView, SIGNAL( incidenceChanged( Incidence*, Incidence* ) ),
00207              mMainView, SLOT( updateUnmanagedViews() ) );
00208     connect( mAgendaView, SIGNAL( incidenceChanged( Incidence*, Incidence* ) ),
00209              mMainView, SLOT( incidenceChanged( Incidence*, Incidence* ) ) );
00210 
00211     // SIGNALS/SLOTS FOR DAY/WEEK VIEW
00212     connect( mAgendaView, SIGNAL( newEventSignal() ),
00213              mMainView, SLOT( newEvent() ) );
00214     connect( mAgendaView, SIGNAL( newEventSignal( QDateTime ) ),
00215              mMainView, SLOT( newEvent( QDateTime ) ) );
00216     connect( mAgendaView, SIGNAL( newEventSignal( QDateTime, QDateTime ) ),
00217              mMainView, SLOT( newEvent( QDateTime, QDateTime ) ) );
00218     connect( mAgendaView, SIGNAL( newEventSignal( QDate ) ),
00219              mMainView, SLOT( newEvent( QDate ) ) );
00220 
00221     connect(mAgendaView, SIGNAL(editIncidenceSignal(Incidence *)),
00222             mMainView, SLOT(editIncidence(Incidence *)));
00223     connect(mAgendaView, SIGNAL(showIncidenceSignal(Incidence *)),
00224             mMainView, SLOT(showIncidence(Incidence *)));
00225     connect(mAgendaView, SIGNAL(deleteIncidenceSignal(Incidence *)),
00226             mMainView, SLOT(deleteIncidence(Incidence *)));
00227 
00228     connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ),
00229              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00230 
00231     connect(mAgendaView, SIGNAL( toggleExpand() ),
00232             mMainView, SLOT( toggleExpand() ) );
00233     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00234             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00235 
00236     connect(mAgendaView, SIGNAL( todoChanged( Todo *, Todo* ) ),
00237             mMainView, SLOT( todoChanged( Todo *, Todo * ) ) );
00238     connect(mAgendaView, SIGNAL( todoDropped( Todo* ) ),
00239             mMainView, SLOT( todoAdded( Todo* ) ) );
00240 
00241     connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig()));
00242 
00243     mAgendaView->readSettings();
00244   }
00245 
00246   showView(mAgendaView);
00247 }
00248 
00249 void KOViewManager::showDayView()
00250 {
00251   showAgendaView();
00252   mMainView->dateNavigator()->selectDates( 1 );
00253 }
00254 
00255 void KOViewManager::showWorkWeekView()
00256 {
00257   showAgendaView();
00258   mMainView->dateNavigator()->selectWorkWeek();
00259 }
00260 
00261 void KOViewManager::showWeekView()
00262 {
00263   showAgendaView();
00264   mMainView->dateNavigator()->selectWeek();
00265 }
00266 
00267 void KOViewManager::showNextXView()
00268 {
00269   showAgendaView();
00270   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00271                                            KOPrefs::instance()->mNextXDays );
00272 }
00273 
00274 void KOViewManager::showMonthView()
00275 {
00276   if (!mMonthView) {
00277     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00278     addView(mMonthView);
00279 
00280     // SIGNALS/SLOTS FOR MONTH VIEW
00281     connect(mMonthView, SIGNAL(newEventSignal(QDateTime)),
00282             mMainView, SLOT(newEvent(QDateTime)));
00283     connect(mMonthView, SIGNAL(newEventSignal(QDate)),
00284             mMainView, SLOT(newEvent(QDate)));
00285     connect(mMonthView, SIGNAL(newEventSignal()),
00286             mMainView, SLOT(newEvent()));
00287 
00288     connect(mMonthView, SIGNAL(showIncidenceSignal(Incidence *)),
00289             mMainView, SLOT(showIncidence(Incidence *)));
00290     connect(mMonthView, SIGNAL(editIncidenceSignal(Incidence *)),
00291             mMainView, SLOT(editIncidence(Incidence *)));
00292     connect(mMonthView, SIGNAL(deleteIncidenceSignal(Incidence *)),
00293             mMainView, SLOT(deleteIncidence(Incidence *)));
00294 
00295     connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ),
00296              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00297 
00298     connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig()));
00299   }
00300 
00301   showView(mMonthView);
00302 }
00303 
00304 void KOViewManager::connectTodoView( KOTodoView* todoView )
00305 {
00306   if (!todoView) return;
00307 
00308   // SIGNALS/SLOTS FOR TODO VIEW
00309   connect( todoView, SIGNAL( newTodoSignal() ),
00310            mMainView, SLOT( newTodo() ) );
00311   connect( todoView, SIGNAL( newSubTodoSignal( Todo * ) ),
00312            mMainView, SLOT( newSubTodo( Todo *) ) );
00313   connect( todoView, SIGNAL( showTodoSignal( Todo *) ),
00314            mMainView, SLOT( showTodo( Todo * ) ) );
00315   connect( todoView, SIGNAL( editTodoSignal( Todo * ) ),
00316            mMainView, SLOT( editTodo( Todo * ) ) );
00317   connect( todoView, SIGNAL( deleteTodoSignal( Todo * ) ),
00318            mMainView, SLOT( deleteTodo( Todo * ) ) );
00319   connect( todoView, SIGNAL( purgeCompletedSignal() ),
00320            mMainView, SLOT( purgeCompleted() ) );
00321   connect( todoView, SIGNAL( unSubTodoSignal() ),
00322            mMainView, SLOT( todo_unsub() ) );
00323   connect( todoView, SIGNAL( todoChanged( Todo*, Todo* ) ),
00324            mMainView, SLOT( todoChanged( Todo*, Todo* ) ) );
00325   connect( todoView, SIGNAL( todoAdded( Todo*) ),
00326            mMainView, SLOT( todoAdded( Todo* ) ) );
00327   connect( todoView, SIGNAL( todoModifiedSignal( Todo *, Todo *, int ) ),
00328            mMainView, SLOT( todoModified( Todo *, Todo *, int ) ) );
00329 
00330   connect( mMainView, SIGNAL( configChanged() ),
00331            todoView, SLOT( updateConfig() ) );
00332 }
00333 
00334 void KOViewManager::showTodoView()
00335 {
00336   if ( !mTodoView ) {
00337     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00338                                 "KOViewManager::TodoView" );
00339     mTodoView->setCalendar( mMainView->calendar() );
00340     addView( mTodoView );
00341     connectTodoView( mTodoView );
00342 
00343     connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ),
00344              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00345 
00346     KConfig *config = KOGlobals::self()->config();
00347     mTodoView->restoreLayout( config, "Todo View" );
00348   }
00349 
00350   showView( mTodoView );
00351 }
00352 
00353 void KOViewManager::showJournalView()
00354 {
00355   if (!mJournalView) {
00356     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00357                                      "KOViewManager::JournalView");
00358     addView(mJournalView);
00359   }
00360 
00361   showView(mJournalView);
00362 }
00363 
00364 void KOViewManager::showTimeSpanView()
00365 {
00366   if (!mTimeSpanView) {
00367     mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
00368                                        "KOViewManager::TimeSpanView");
00369     addView(mTimeSpanView);
00370 
00371     mTimeSpanView->readSettings();
00372   }
00373 
00374   showView(mTimeSpanView);
00375 }
00376 
00377 void KOViewManager::showEventView()
00378 {
00379   if ( mLastEventView ) showView( mLastEventView );
00380   else showWeekView();
00381 }
00382 
00383 Incidence *KOViewManager::currentSelection()
00384 {
00385   if ( !mCurrentView ) return 0;
00386   Incidence::List incidenceList = mCurrentView->selectedIncidences();
00387   if ( incidenceList.isEmpty() ) return 0;
00388 
00389   return incidenceList.first();
00390 }
00391 
00392 QDate KOViewManager::currentSelectionDate()
00393 {
00394   QDate qd;
00395   if (mCurrentView) {
00396     DateList qvl = mCurrentView->selectedDates();
00397     if (!qvl.isEmpty()) qd = qvl.first();
00398   }
00399   return qd;
00400 }
00401 
00402 void KOViewManager::addView(KOrg::BaseView *view)
00403 {
00404 #if QT_VERSION >= 300
00405   mMainView->viewStack()->addWidget( view );
00406 #else
00407   mMainView->viewStack()->addWidget( view, 1 );
00408 #endif
00409 }
00410 
00411 void KOViewManager::setDocumentId( const QString &id )
00412 {
00413   if (mTodoView) mTodoView->setDocumentId( id );
00414 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:31 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003