korganizer Library API Documentation

koviewmanager.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001
00005     Cornelius Schumacher <schumacher@kde.org>
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., 675 Mass Ave, Cambridge, MA 02139, 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 
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 
00041 #include "koviewmanager.h"
00042 #include "koviewmanager.moc"
00043 
00044 KOViewManager::KOViewManager( CalendarView *mainView ) :
00045   QObject(), mMainView( mainView )
00046 {
00047   mCurrentView = 0;
00048 
00049   mWhatsNextView = 0;
00050   mTodoView = 0;
00051   mAgendaView = 0;
00052   mMonthView = 0;
00053   mListView = 0;
00054   mJournalView = 0;
00055   mTimeSpanView = 0;
00056 }
00057 
00058 KOViewManager::~KOViewManager()
00059 {
00060 }
00061 
00062 
00063 KOrg::BaseView *KOViewManager::currentView()
00064 {
00065   return mCurrentView;
00066 }
00067 
00068 void KOViewManager::readSettings(KConfig *config)
00069 {
00070   config->setGroup("General");
00071   QString view = config->readEntry("Current View");
00072 
00073   if (view == "WhatsNext") showWhatsNextView();
00074   else if (view == "Month") showMonthView();
00075   else if (view == "List") showListView();
00076   else if (view == "Journal") showJournalView();
00077   else if (view == "TimeSpan") showTimeSpanView();
00078   else if (view == "Todo") showTodoView();
00079   else showAgendaView();
00080 }
00081 
00082 void KOViewManager::writeSettings(KConfig *config)
00083 {
00084   config->setGroup("General");
00085 
00086   QString view;
00087   if (mCurrentView == mWhatsNextView) view = "WhatsNext";
00088   else if (mCurrentView == mMonthView) view = "Month";
00089   else if (mCurrentView == mListView) view = "List";
00090   else if (mCurrentView == mJournalView) view = "Journal";
00091   else if (mCurrentView == mTimeSpanView) view = "TimeSpan";
00092   else if (mCurrentView == mTodoView) view = "Todo";
00093   else view = "Agenda";
00094 
00095   config->writeEntry("Current View",view);
00096 
00097   if (mAgendaView) {
00098     mAgendaView->writeSettings(config);
00099   }
00100   if (mTimeSpanView) {
00101     mTimeSpanView->writeSettings(config);
00102   }
00103   if (mListView) {
00104     mListView->writeSettings(config);
00105   }
00106   if (mTodoView) {
00107     mTodoView->saveLayout(config,"Todo View");
00108   }
00109 }
00110 
00111 void KOViewManager::showView(KOrg::BaseView *view)
00112 {
00113   if(view == mCurrentView) return;
00114 
00115   if ( mAgendaView ) mAgendaView->deleteSelectedDateTime();
00116   mCurrentView = view;
00117 
00118   raiseCurrentView();
00119   mMainView->processIncidenceSelection( 0 );
00120 
00121   mMainView->updateView();
00122 
00123   mMainView->adaptNavigationUnits();
00124 }
00125 
00126 void KOViewManager::raiseCurrentView()
00127 {
00128   if ((mMonthView && KOPrefs::instance()->mFullViewMonth && mCurrentView == mMonthView) ||
00129       (mTodoView && KOPrefs::instance()->mFullViewTodo && mCurrentView == mTodoView)) {
00130     mMainView->leftFrame()->hide();
00131   } else {
00132     mMainView->leftFrame()->show();
00133   }
00134   mMainView->viewStack()->raiseWidget(mCurrentView);
00135 }
00136 
00137 void KOViewManager::updateView()
00138 {
00139   if ( mCurrentView ) mCurrentView->updateView();
00140 }
00141 
00142 void KOViewManager::updateView(const QDate &start, const QDate &end)
00143 {
00144 //  kdDebug() << "KOViewManager::updateView()" << endl;
00145 
00146   if (mCurrentView) mCurrentView->showDates(start, end);
00147 
00148   if (mTodoView) mTodoView->updateView();
00149 }
00150 
00151 
00152 void KOViewManager::showWhatsNextView()
00153 {
00154   if (!mWhatsNextView) {
00155     mWhatsNextView = new KOWhatsNextView(mMainView->calendar(),mMainView->viewStack(),
00156                                          "KOViewManager::WhatsNextView");
00157     addView(mWhatsNextView);
00158   }
00159 
00160   showView(mWhatsNextView);
00161 }
00162 
00163 void KOViewManager::showListView()
00164 {
00165   if (!mListView) {
00166     mListView = new KOListView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::ListView");
00167     addView(mListView);
00168 
00169     connect(mListView, SIGNAL(showEventSignal(Event *)),
00170             mMainView, SLOT(showEvent(Event *)));
00171     connect(mListView, SIGNAL(editEventSignal(Event *)),
00172             mMainView, SLOT(editEvent(Event *)));
00173     connect(mListView, SIGNAL(deleteEventSignal(Event *)),
00174             mMainView, SLOT(deleteEvent(Event *)));
00175 
00176     connect( mListView, SIGNAL( incidenceSelected( Incidence * ) ),
00177              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00178 
00179     connect(mMainView, SIGNAL(configChanged()), mListView, SLOT(updateConfig()));
00180   }
00181 
00182   showView(mListView);
00183 }
00184 
00185 void KOViewManager::showAgendaView()
00186 {
00187   if (!mAgendaView) {
00188     mAgendaView = new KOAgendaView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::AgendaView");
00189                                         
00190     addView(mAgendaView);
00191 
00192     connect( mAgendaView, SIGNAL( eventChanged() ),
00193              mMainView, SLOT( updateUnmanagedViews() ) );
00194 
00195     // SIGNALS/SLOTS FOR DAY/WEEK VIEW
00196     connect(mAgendaView,SIGNAL(newEventSignal(QDateTime)),
00197             mMainView, SLOT(newEvent(QDateTime)));
00198     connect(mAgendaView,SIGNAL(newEventSignal(QDateTime,QDateTime)),
00199             mMainView, SLOT(newEvent(QDateTime,QDateTime)));
00200     connect(mAgendaView,SIGNAL(newEventSignal(QDate)),
00201             mMainView, SLOT(newEvent(QDate)));
00202     connect(mAgendaView, SIGNAL(editEventSignal(Event *)),
00203             mMainView, SLOT(editEvent(Event *)));
00204     connect(mAgendaView, SIGNAL(showEventSignal(Event *)),
00205             mMainView, SLOT(showEvent(Event *)));
00206     connect(mAgendaView, SIGNAL(deleteEventSignal(Event *)),
00207             mMainView, SLOT(deleteEvent(Event *)));
00208 
00209     connect( mAgendaView, SIGNAL( incidenceSelected( Incidence * ) ),
00210              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00211 
00212     connect(mAgendaView, SIGNAL( toggleExpand() ),
00213             mMainView, SLOT( toggleExpand() ) );
00214     connect(mMainView, SIGNAL( calendarViewExpanded( bool ) ),
00215             mAgendaView, SLOT( setExpandedButton( bool ) ) );
00216 
00217     connect(mMainView, SIGNAL(configChanged()), mAgendaView, SLOT(updateConfig()));
00218 
00219     mAgendaView->readSettings();
00220   }
00221 
00222   showView(mAgendaView);
00223 }
00224 
00225 void KOViewManager::showDayView()
00226 {
00227   showAgendaView();
00228   mMainView->dateNavigator()->selectDates( 1 );
00229 }
00230 
00231 void KOViewManager::showWorkWeekView()
00232 {
00233   showAgendaView();
00234   mMainView->dateNavigator()->selectWorkWeek();
00235 }
00236 
00237 void KOViewManager::showWeekView()
00238 {
00239   showAgendaView();
00240   mMainView->dateNavigator()->selectWeek();
00241 }
00242 
00243 void KOViewManager::showNextXView()
00244 {
00245   showAgendaView();
00246   mMainView->dateNavigator()->selectDates( QDate::currentDate(),
00247                                            KOPrefs::instance()->mNextXDays );
00248 }
00249 
00250 void KOViewManager::showMonthView()
00251 {
00252   if (!mMonthView) {
00253     mMonthView = new KOMonthView(mMainView->calendar(), mMainView->viewStack(), "KOViewManager::MonthView");
00254     addView(mMonthView);
00255 
00256     // SIGNALS/SLOTS FOR MONTH VIEW
00257     connect(mMonthView, SIGNAL(showEventSignal(Event *)),
00258             mMainView, SLOT(showEvent(Event *)));
00259     connect(mMonthView, SIGNAL(newEventSignal(QDateTime)),
00260             mMainView, SLOT(newEvent(QDateTime)));
00261     connect(mMonthView, SIGNAL(editEventSignal(Event *)),
00262             mMainView, SLOT(editEvent(Event *)));
00263     connect(mMonthView, SIGNAL(deleteEventSignal(Event *)),
00264             mMainView, SLOT(deleteEvent(Event *)));
00265 
00266     connect( mMonthView, SIGNAL( incidenceSelected( Incidence * ) ),
00267              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00268 
00269     connect(mMainView, SIGNAL(configChanged()), mMonthView, SLOT(updateConfig()));
00270   }
00271 
00272   showView(mMonthView);
00273 }
00274 
00275 void KOViewManager::showTodoView()
00276 {
00277   if ( !mTodoView ) {
00278     mTodoView = new KOTodoView( mMainView->calendar(), mMainView->viewStack(),
00279                                 "KOViewManager::TodoView" );
00280     addView( mTodoView );
00281 
00282     // SIGNALS/SLOTS FOR TODO VIEW
00283     connect( mTodoView, SIGNAL( newTodoSignal() ),
00284              mMainView, SLOT( newTodo() ) );
00285     connect( mTodoView, SIGNAL( newSubTodoSignal( Todo * ) ),
00286              mMainView, SLOT( newSubTodo( Todo *) ) );
00287     connect( mTodoView, SIGNAL( showTodoSignal( Todo *) ),
00288              mMainView, SLOT( showTodo( Todo * ) ) );
00289     connect( mTodoView, SIGNAL( editTodoSignal( Todo * ) ),
00290              mMainView, SLOT( editTodo( Todo * ) ) );
00291     connect( mTodoView, SIGNAL( deleteTodoSignal( Todo * ) ),
00292              mMainView, SLOT( deleteTodo( Todo * ) ) );
00293     connect( mTodoView, SIGNAL( purgeCompletedSignal() ),
00294              mMainView, SLOT( purgeCompleted() ) );
00295 
00296     connect( mTodoView, SIGNAL( incidenceSelected( Incidence * ) ),
00297              mMainView, SLOT( processMainViewSelection( Incidence * ) ) );
00298 
00299     connect( mMainView, SIGNAL( configChanged() ), mTodoView,
00300              SLOT( updateConfig() ) );
00301     connect( mTodoView, SIGNAL( todoModifiedSignal( Todo *, int ) ),
00302              mMainView, SLOT ( todoModified( Todo *, int ) ) );
00303 
00304     KConfig *config = KGlobal::config();
00305     mTodoView->restoreLayout(config,"Todo View");
00306   }
00307 
00308   showView( mTodoView );
00309 }
00310 
00311 void KOViewManager::showJournalView()
00312 {
00313   if (!mJournalView) {
00314     mJournalView = new KOJournalView(mMainView->calendar(),mMainView->viewStack(),
00315                                      "KOViewManager::JournalView");
00316     addView(mJournalView);
00317   }
00318 
00319   showView(mJournalView);
00320 }
00321 
00322 void KOViewManager::showTimeSpanView()
00323 {
00324   if (!mTimeSpanView) {
00325     mTimeSpanView = new KOTimeSpanView(mMainView->calendar(),mMainView->viewStack(),
00326                                        "KOViewManager::TimeSpanView");
00327     addView(mTimeSpanView);
00328 
00329     mTimeSpanView->readSettings();
00330   }
00331 
00332   showView(mTimeSpanView);
00333 }
00334 
00335 Incidence *KOViewManager::currentSelection()
00336 {
00337   if (!mCurrentView) return 0;
00338   
00339   return mCurrentView->selectedIncidences().first();
00340 }
00341 
00342 QDate KOViewManager::currentSelectionDate()
00343 {
00344   QDate qd;
00345   if (mCurrentView) {
00346     DateList qvl = mCurrentView->selectedDates();
00347     if (!qvl.isEmpty()) qd = qvl.first();
00348   }
00349   return qd;
00350 }
00351 
00352 void KOViewManager::addView(KOrg::BaseView *view)
00353 {
00354   mMainView->viewStack()->addWidget(view,1);
00355 }
00356 
00357 void KOViewManager::setDocumentId( const QString &id )
00358 {
00359   if (mTodoView) mTodoView->setDocumentId( id );
00360 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:32 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001