korganizer Library API Documentation

calendarview.cpp

00001 /*
00002   This file is part of KOrganizer.
00003 
00004   Requires the Qt and KDE widget libraries, available at no cost at
00005   http://www.troll.no and http://www.kde.org respectively
00006 
00007   Copyright (c) 1997, 1998, 1999
00008   Preston Brown (preston.brown@yale.edu)
00009   Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
00010   Ian Dawes (iadawes@globalserve.net)
00011   Laszlo Boloni (boloni@cs.purdue.edu)
00012 
00013   Copyright (c) 2000, 2001, 2002
00014   Cornelius Schumacher <schumacher@kde.org>
00015 
00016   This program is free software; you can redistribute it and/or modify
00017   it under the terms of the GNU General Public License as published by
00018   the Free Software Foundation; either version 2 of the License, or
00019   (at your option) any later version.
00020 
00021   This program is distributed in the hope that it will be useful,
00022   but WITHOUT ANY WARRANTY; without even the implied warranty of
00023   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024   GNU General Public License for more details.
00025 
00026   You should have received a copy of the GNU General Public License
00027   along with this program; if not, write to the Free Software
00028   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00029 */
00030 
00031 #include <stdlib.h>
00032 
00033 #include <qapplication.h>
00034 #include <qcursor.h>
00035 #include <qmultilineedit.h>
00036 #include <qtimer.h>
00037 #include <qwidgetstack.h>
00038 #include <qclipboard.h>
00039 #include <qptrlist.h>
00040 #include <qclipboard.h>
00041 #include <qfile.h>
00042 #ifndef KORG_NOSPLITTER
00043 #include <qsplitter.h>
00044 #endif
00045 
00046 #include <kglobal.h>
00047 #include <kdebug.h>
00048 #include <kstandarddirs.h>
00049 #include <kfiledialog.h>
00050 #include <kmessagebox.h>
00051 #include <knotifyclient.h>
00052 #include <kconfig.h>
00053 #include <krun.h>
00054 #include <kdirwatch.h>
00055 
00056 #include <libkcal/vcaldrag.h>
00057 #include <libkcal/icaldrag.h>
00058 #include <libkcal/icalformat.h>
00059 #include <libkcal/vcalformat.h>
00060 #include <libkcal/scheduler.h>
00061 #include <libkcal/calendarlocal.h>
00062 #include <libkcal/journal.h>
00063 #include <libkcal/calfilter.h>
00064 #include <libkcal/attendee.h>
00065 #include <libkcal/dndfactory.h>
00066 #include <libkcal/freebusy.h>
00067 #include <libkcal/filestorage.h>
00068 
00069 #ifndef KORG_NOMAIL
00070 #include "komailclient.h"
00071 #endif
00072 #ifndef KORG_NOPRINTER
00073 #include "calprinter.h"
00074 #endif
00075 #include "koeventeditor.h"
00076 #include "kotodoeditor.h"
00077 #include "koprefs.h"
00078 #include "koeventviewerdialog.h"
00079 #include "publishdialog.h"
00080 #include "kofilterview.h"
00081 #include "koglobals.h"
00082 #include "koviewmanager.h"
00083 #include "koagendaview.h"
00084 #include "kodialogmanager.h"
00085 #include "outgoingdialog.h"
00086 #include "incomingdialog.h"
00087 #include "statusdialog.h"
00088 #include "kdatenavigator.h"
00089 #include "kotodoview.h"
00090 #include "datenavigator.h"
00091 
00092 #include "calendarview.h"
00093 #include "kocore.h"
00094 using namespace KOrg;
00095 #include "calendarview.moc"
00096 
00097 CalendarView::CalendarView( QWidget *parent, const char *name ) 
00098   : CalendarViewBase(parent,name)
00099 {
00100   kdDebug() << "CalendarView::CalendarView()" << endl;
00101 
00102   mViewManager = new KOViewManager( this );
00103   mDialogManager = new KODialogManager( this );
00104 
00105   mModified = false;
00106   mReadOnly = false;
00107   mSelectedIncidence = 0;
00108 
00109   mCalPrinter = 0;
00110 
00111   mFilters.setAutoDelete(true);
00112 
00113   // Create calendar object, which manages all calendar information associated
00114   // with this calendar view window.
00115   mCalendar = new CalendarLocal(KOPrefs::instance()->mTimeZoneId.local8Bit());
00116   mCalendar->setOwner(KOPrefs::instance()->fullName());
00117   mCalendar->setEmail(KOPrefs::instance()->email());
00118 
00119   mCalendar->registerObserver( this );
00120 
00121   // TODO: Make sure that view is updated, when calendar is changed.
00122 
00123   mStorage = new FileStorage( mCalendar );
00124 
00125   mNavigator = new DateNavigator( this );
00126 
00127   QBoxLayout *topLayout = new QVBoxLayout(this);
00128 
00129 #ifndef KORG_NOSPLITTER
00130   // create the main layout frames.
00131   mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
00132   topLayout->addWidget(mPanner);
00133 
00134   mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
00135                             "CalendarView::LeftFrame");
00136   mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
00137 
00138   mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
00139                         "CalendarView::DateNavigator", QDate::currentDate() ); 
00140   mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
00141   mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist");
00142   mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
00143 
00144   mRightFrame = new QWidgetStack(mPanner, "CalendarView::RightFrame");
00145 
00146   mLeftFrame = mLeftSplitter;
00147 #else
00148   QWidget *mainBox;
00149   QWidget *leftFrame;
00150 
00151   if ( KOPrefs::instance()->mVerticalScreen ) {
00152     mainBox = new QVBox( this );
00153     leftFrame = new QHBox( mainBox );
00154   } else {
00155     mainBox = new QHBox( this );
00156     leftFrame = new QVBox( mainBox );
00157   }
00158 
00159   topLayout->addWidget( mainBox );
00160 
00161   mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
00162                         "CalendarView::DateNavigator", QDate::currentDate()); 
00163   mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist");
00164   mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
00165 
00166   mRightFrame = new QWidgetStack(mainBox, "CalendarView::RightFrame");
00167 
00168   mLeftFrame = leftFrame;
00169 
00170   if ( KOPrefs::instance()->mVerticalScreen ) {
00171 //    mTodoList->setFixedHeight( 60 );
00172     mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
00173   }
00174 #endif
00175 
00176   connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
00177            SLOT( showDates( const KCal::DateList & ) ) );
00178   connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
00179            mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
00180 
00181   connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
00182            mNavigator, SLOT( selectWeek( const QDate & ) ) );
00183 
00184   connect( mDateNavigator, SIGNAL( goPrevYear() ),
00185            mNavigator, SLOT( selectPreviousYear() ) );
00186   connect( mDateNavigator, SIGNAL( goNextYear() ),
00187            mNavigator, SLOT( selectNextYear() ) );
00188   connect( mDateNavigator, SIGNAL( goPrevMonth() ),
00189            mNavigator, SLOT( selectPreviousMonth() ) );
00190   connect( mDateNavigator, SIGNAL( goNextMonth() ),
00191            mNavigator, SLOT( selectNextMonth() ) );
00192 
00193   connect( mDateNavigator, SIGNAL( goPrevious() ),
00194            mNavigator, SLOT( selectPrevious() ) );
00195   connect( mDateNavigator, SIGNAL( goNext() ),
00196            mNavigator, SLOT( selectNext() ) );
00197 
00198   connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
00199            mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
00200 
00201   connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
00202            SLOT( eventAdded( Event *) ) );
00203 
00204   connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
00205 
00206   connect( this, SIGNAL( configChanged() ),
00207            mDateNavigator, SLOT( updateConfig() ) );
00208 
00209   connect( mTodoList, SIGNAL( newTodoSignal() ),
00210            SLOT( newTodo() ) );
00211   connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
00212            SLOT( newSubTodo( Todo * ) ) );
00213   connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
00214            SLOT( editTodo( Todo * ) ) );
00215   connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
00216            SLOT( showTodo( Todo *) ) );
00217   connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
00218            SLOT( deleteTodo( Todo *) ) );
00219   connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
00220   connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
00221            SLOT( purgeCompleted() ) );
00222   connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
00223            SLOT( todoModified( Todo *, int ) ) );
00224 
00225   connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
00226   connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
00227   // Hide filter per default
00228   mFilterView->hide();
00229 
00230   readSettings();
00231 
00232   KDirWatch *messageWatch = new KDirWatch();
00233   messageWatch->addDir(locateLocal("data","korganizer/income/"));
00234   connect (messageWatch,SIGNAL(dirty(const QString &)),SLOT(lookForIncomingMessages()));
00235 
00236   // We should think about seperating startup settings and configuration change.
00237   updateConfig();
00238 
00239   connect(QApplication::clipboard(),SIGNAL(dataChanged()),
00240           SLOT(checkClipboard()));
00241   connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
00242            SLOT( processTodoListSelection( Incidence * ) ) );
00243   connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
00244 
00245   kdDebug() << "CalendarView::CalendarView() done" << endl;
00246 }
00247 
00248 CalendarView::~CalendarView()
00249 {
00250   kdDebug() << "~CalendarView()" << endl;
00251 
00252   // clean up our calender object
00253   mCalendar->close();  // CS: This seems to cause a "Double QObject deletion"
00254   delete mCalendar;
00255   delete mDialogManager;
00256   delete mViewManager;
00257 
00258   kdDebug() << "~CalendarView() done" << endl;
00259 }
00260 
00261 KOViewManager *CalendarView::viewManager()
00262 {
00263   return mViewManager;
00264 }
00265 
00266 KODialogManager *CalendarView::dialogManager()
00267 {
00268   return mDialogManager;
00269 }
00270 
00271 QDate CalendarView::startDate()
00272 {
00273   DateList dates = mNavigator->selectedDates();
00274 
00275   return dates.first();
00276 }
00277 
00278 QDate CalendarView::endDate()
00279 {
00280   DateList dates = mNavigator->selectedDates();
00281 
00282   return dates.last();
00283 }
00284 
00285 
00286 void CalendarView::createPrinter()
00287 {
00288 #ifndef KORG_NOPRINTER
00289   if (!mCalPrinter) {
00290     mCalPrinter = new CalPrinter(this, mCalendar);
00291     connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
00292   }
00293 #endif
00294 }
00295 
00296 
00297 bool CalendarView::openCalendar(QString filename, bool merge)
00298 {
00299   kdDebug() << "CalendarView::openCalendar(): " << filename << endl;
00300 
00301   if (filename.isEmpty()) {
00302     kdDebug() << "CalendarView::openCalendar(): Error! Empty filename." << endl;
00303     return false;
00304   }
00305 
00306   if (!QFile::exists(filename)) {
00307     kdDebug() << "CalendarView::openCalendar(): Error! File '" << filename
00308               << "' doesn't exist." << endl;
00309   }
00310 
00311   if (!merge) mCalendar->close();
00312   
00313   mStorage->setFileName( filename );
00314   
00315   if ( mStorage->load() ) {
00316     if ( merge ) setModified( true );
00317     else {
00318       setModified( false );
00319       mViewManager->setDocumentId( filename );
00320       mDialogManager->setDocumentId( filename );
00321       mTodoList->setDocumentId( filename );
00322     }
00323     updateView();
00324     return true;
00325   } else {
00326     // while failing to load, the calendar object could
00327     // have become partially populated.  Clear it out.
00328     if ( !merge ) mCalendar->close();
00329 
00330     KMessageBox::error(this,i18n("Couldn't load calendar '%1'.").arg(filename));
00331     
00332     return false;
00333   }
00334 }
00335 
00336 bool CalendarView::saveCalendar( QString filename )
00337 {
00338   kdDebug() << "CalendarView::saveCalendar(): " << filename << endl;
00339 
00340   // Store back all unsaved data into calendar object
00341   mViewManager->currentView()->flushView();
00342 
00343   mStorage->setFileName( filename );
00344   mStorage->setSaveFormat( new ICalFormat );
00345 
00346   bool success = mStorage->save();
00347 
00348   if ( !success ) {
00349     return false;
00350   }
00351 
00352   return true;
00353 }
00354 
00355 void CalendarView::closeCalendar()
00356 {
00357   kdDebug() << "CalendarView::closeCalendar()" << endl;
00358 
00359   // child windows no longer valid
00360   emit closingDown();
00361 
00362   mCalendar->close();
00363   setModified(false);
00364   updateView();
00365 }
00366 
00367 void CalendarView::archiveCalendar()
00368 {
00369   mDialogManager->showArchiveDialog();
00370 }
00371 
00372 
00373 void CalendarView::readSettings()
00374 {
00375 //  kdDebug() << "CalendarView::readSettings()" << endl;
00376 
00377   QString str;
00378 
00379   // read settings from the KConfig, supplying reasonable
00380   // defaults where none are to be found
00381 
00382   KConfig *config = KGlobal::config();
00383 
00384 #ifndef KORG_NOSPLITTER
00385   config->setGroup("KOrganizer Geometry");
00386 
00387   QValueList<int> sizes = config->readIntListEntry("Separator1");
00388   if (sizes.count() != 2) {
00389     sizes << mDateNavigator->minimumSizeHint().width();
00390     sizes << 300;
00391   }
00392   mPanner->setSizes(sizes);
00393 
00394   sizes = config->readIntListEntry("Separator2");
00395   if (sizes.count() == 3) {
00396     mLeftSplitter->setSizes(sizes);
00397   }
00398 #endif
00399 
00400   mViewManager->readSettings( config );
00401   mTodoList->restoreLayout(config,QString("Todo Layout"));
00402 
00403   readFilterSettings(config);
00404 
00405   config->setGroup( "Views" );
00406   int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
00407   if ( dateCount == 5 ) mNavigator->selectWorkWeek();
00408   else if ( dateCount == 7 ) mNavigator->selectWeek();
00409   else mNavigator->selectDates( dateCount );
00410 }
00411 
00412 
00413 void CalendarView::writeSettings()
00414 {
00415 //  kdDebug() << "CalendarView::writeSettings" << endl;
00416 
00417   KConfig *config = KGlobal::config();
00418 
00419 #ifndef KORG_NOSPLITTER
00420   config->setGroup("KOrganizer Geometry");
00421 
00422   QValueList<int> list = mPanner->sizes();
00423   config->writeEntry("Separator1",list);
00424 
00425   list = mLeftSplitter->sizes();
00426   config->writeEntry("Separator2",list);
00427 #endif
00428 
00429   mViewManager->writeSettings( config );
00430   mTodoList->saveLayout(config,QString("Todo Layout"));
00431 
00432   KOPrefs::instance()->writeConfig();
00433 
00434   writeFilterSettings(config);
00435 
00436   config->setGroup( "Views" );
00437   config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
00438 
00439   config->sync();
00440 }
00441 
00442 void CalendarView::readFilterSettings(KConfig *config)
00443 {
00444 //  kdDebug() << "CalendarView::readFilterSettings()" << endl;
00445 
00446   mFilters.clear();
00447 
00448   config->setGroup("General");
00449   QStringList filterList = config->readListEntry("CalendarFilters");
00450 
00451   QStringList::ConstIterator it = filterList.begin();
00452   QStringList::ConstIterator end = filterList.end();
00453   while(it != end) {
00454 //    kdDebug() << "  filter: " << (*it) << endl;
00455 
00456     CalFilter *filter;
00457     filter = new CalFilter(*it);
00458     config->setGroup("Filter_" + (*it));
00459     filter->setCriteria(config->readNumEntry("Criteria",0));
00460     filter->setCategoryList(config->readListEntry("CategoryList"));
00461     mFilters.append(filter);
00462 
00463     ++it;
00464   }
00465 
00466   if (mFilters.count() == 0) {
00467     CalFilter *filter = new CalFilter(i18n("Default"));
00468     mFilters.append(filter);
00469   }
00470   mFilterView->updateFilters();
00471   config->setGroup("FilterView");
00472   mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
00473   mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
00474 
00475 }
00476 
00477 void CalendarView::writeFilterSettings(KConfig *config)
00478 {
00479 //  kdDebug() << "CalendarView::writeFilterSettings()" << endl;
00480 
00481   QStringList filterList;
00482 
00483   CalFilter *filter = mFilters.first();
00484   while(filter) {
00485 //    kdDebug() << " fn: " << filter->name() << endl;
00486     filterList << filter->name();
00487     config->setGroup("Filter_" + filter->name());
00488     config->writeEntry("Criteria",filter->criteria());
00489     config->writeEntry("CategoryList",filter->categoryList());
00490     filter = mFilters.next();
00491   }
00492   config->setGroup("General");
00493   config->writeEntry("CalendarFilters",filterList);
00494 
00495   config->setGroup("FilterView");
00496   config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
00497   config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
00498 }
00499 
00500 
00501 void CalendarView::goToday()
00502 {
00503   mNavigator->selectToday();
00504 }
00505 
00506 void CalendarView::goNext()
00507 {
00508   mNavigator->selectNext();
00509 }
00510 
00511 void CalendarView::goPrevious()
00512 {
00513   mNavigator->selectPrevious();
00514 }
00515 
00516 void CalendarView::updateConfig()
00517 {
00518   kdDebug() << "CalendarView::updateConfig()" << endl;
00519   emit configChanged();
00520 
00521   mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId.local8Bit());
00522 
00523   // To make the "fill window" configurations work
00524   mViewManager->raiseCurrentView();
00525 }
00526 
00527 
00528 void CalendarView::eventChanged(Event *event)
00529 {
00530   changeEventDisplay(event,KOGlobals::EVENTEDITED);
00531 }
00532 
00533 void CalendarView::eventAdded(Event *event)
00534 {
00535   changeEventDisplay(event,KOGlobals::EVENTADDED);
00536 }
00537 
00538 void CalendarView::eventToBeDeleted(Event *)
00539 {
00540   kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
00541 }
00542 
00543 void CalendarView::eventDeleted()
00544 {
00545   changeEventDisplay(0,KOGlobals::EVENTDELETED);
00546 }
00547 
00548 
00549 // most of the changeEventDisplays() right now just call the view's
00550 // total update mode, but they SHOULD be recoded to be more refresh-efficient.
00551 void CalendarView::changeEventDisplay(Event *which, int action)
00552 {
00553 //  kdDebug() << "CalendarView::changeEventDisplay" << endl;
00554 
00555   mDateNavigator->updateView();
00556   mDialogManager->updateSearchDialog();
00557 
00558   if (which) {
00559     // If there is an event view visible update the display
00560     mViewManager->currentView()->changeEventDisplay(which,action);
00561 // TODO: check, if update needed
00562 //    if (which->getTodoStatus()) {
00563       mTodoList->updateView();
00564 //    }
00565   } else {
00566     mViewManager->currentView()->updateView();
00567   }
00568 }
00569 
00570 
00571 void CalendarView::updateTodoViews()
00572 {
00573   kdDebug() << "CalendarView::updateTodoViews()" << endl;
00574 
00575   mTodoList->updateView();
00576   mViewManager->currentView()->updateView();
00577 }
00578 
00579 
00580 void CalendarView::updateView(const QDate &start, const QDate &end)
00581 {
00582   mTodoList->updateView();
00583   mViewManager->updateView(start, end);
00584   mDateNavigator->updateView();
00585 }
00586 
00587 void CalendarView::updateView()
00588 {
00589   DateList tmpList = mNavigator->selectedDates();
00590 
00591   // We assume that the navigator only selects consecutive days.
00592   updateView( tmpList.first(), tmpList.last() );
00593 }
00594 
00595 void CalendarView::updateUnmanagedViews()
00596 {
00597   mDateNavigator->updateDayMatrix();
00598 }
00599 
00600 int CalendarView::msgItemDelete()
00601 {
00602   return KMessageBox::warningContinueCancel(this,
00603       i18n("This item will be permanently deleted."),
00604       i18n("KOrganizer Confirmation"),i18n("Delete"));
00605 }
00606 
00607 
00608 void CalendarView::edit_cut()
00609 {
00610   Event *anEvent=0;
00611 
00612   Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
00613 
00614   if (mViewManager->currentView()->isEventView()) {
00615     if ( incidence && incidence->type() == "Event" ) {
00616       anEvent = static_cast<Event *>(incidence);
00617     }
00618   }
00619 
00620   if (!anEvent) {
00621     KNotifyClient::beep();
00622     return;
00623   }
00624   DndFactory factory( mCalendar );
00625   factory.cutEvent(anEvent);
00626   changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
00627 }
00628 
00629 void CalendarView::edit_copy()
00630 {
00631   Event *anEvent=0;
00632 
00633   Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
00634 
00635   if (mViewManager->currentView()->isEventView()) {
00636     if ( incidence && incidence->type() == "Event" ) {
00637       anEvent = static_cast<Event *>(incidence);
00638     }
00639   }
00640 
00641   if (!anEvent) {
00642     KNotifyClient::beep();
00643     return;
00644   }
00645   DndFactory factory( mCalendar );
00646   factory.copyEvent(anEvent);
00647 }
00648 
00649 void CalendarView::edit_paste()
00650 {
00651   QDate date = mNavigator->selectedDates().first();
00652 
00653   DndFactory factory( mCalendar );
00654   Event *pastedEvent = factory.pasteEvent( date );
00655 
00656   changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
00657 }
00658 
00659 void CalendarView::edit_options()
00660 {
00661   mDialogManager->showOptionsDialog();
00662 }
00663 
00664 
00665 void CalendarView::newEvent()
00666 {
00667   // TODO: Replace this code by a common eventDurationHint of KOBaseView.
00668   KOAgendaView *aView = mViewManager->agendaView();
00669   if (aView) {
00670     if (aView->selectionStart().isValid()) {
00671       if (aView->selectedIsAllDay()) {
00672         newEvent(aView->selectionStart(),aView->selectionEnd(),true);
00673       } else {
00674         newEvent(aView->selectionStart(),aView->selectionEnd());
00675       }
00676       return;
00677     }
00678   }
00679 
00680   QDate date = mNavigator->selectedDates().first();
00681 
00682   newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
00683             QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
00684                        KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
00685 }
00686 
00687 void CalendarView::newEvent(QDateTime fh)
00688 {
00689   newEvent(fh,
00690            QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
00691 }
00692 
00693 void CalendarView::newEvent(QDate dt)
00694 {
00695   newEvent(QDateTime(dt, QTime(0,0,0)),
00696            QDateTime(dt, QTime(0,0,0)), true);
00697 }
00698 
00699 void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
00700 {
00701   KOEventEditor *eventEditor = mDialogManager->getEventEditor();
00702   eventEditor->newEvent(fromHint,toHint);
00703   eventEditor->show();
00704 }
00705 
00706 void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
00707 {
00708   KOEventEditor *eventEditor = mDialogManager->getEventEditor();
00709   eventEditor->newEvent(fromHint,toHint,allDay);
00710   eventEditor->show();
00711 }
00712 
00713 
00714 void CalendarView::newTodo()
00715 {
00716   KOTodoEditor *todoEditor = mDialogManager->getTodoEditor();
00717   todoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
00718   todoEditor->show();
00719 }
00720 
00721 void CalendarView::newSubTodo()
00722 {
00723   Todo *todo = selectedTodo();
00724   if ( todo ) newSubTodo( todo );
00725 }
00726 
00727 void CalendarView::newSubTodo(Todo *parentEvent)
00728 {
00729   KOTodoEditor *todoEditor = mDialogManager->getTodoEditor();
00730   todoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
00731   todoEditor->show();
00732 }
00733 
00734 void CalendarView::newFloatingEvent()
00735 {
00736   DateList tmpList = mNavigator->selectedDates();
00737   QDate date = tmpList.first();
00738 
00739   newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
00740             QDateTime( date, QTime( 12, 0, 0 ) ), true );
00741 }
00742 
00743 
00744 void CalendarView::editEvent( Event *event )
00745 {
00746   kdDebug() << "CalendarView::editEvent()" << endl;
00747 
00748   if ( !event ) return;
00749 
00750   if ( mDialogList.find( event ) != mDialogList.end() ) {
00751     kdDebug() << "CalendarView::editEvent() in List" << endl;
00752     mDialogList[ event ]->reload();
00753     mDialogList[ event ]->raise();
00754     mDialogList[ event ]->show();
00755     return;
00756   }
00757 
00758   if ( event->isReadOnly() ) {
00759     showEvent( event );
00760     return;
00761   }
00762   
00763   kdDebug() << "CalendarView::editEvent() new EventEditor" << endl;
00764   KOEventEditor *eventEditor = mDialogManager->getEventEditor();
00765   mDialogList.insert( event, eventEditor );
00766   eventEditor->editEvent( event );
00767   eventEditor->show();
00768 }
00769 
00770 void CalendarView::editTodo( Todo *todo )
00771 {
00772   if ( !todo ) return;
00773   kdDebug() << "CalendarView::editTodo" << endl;
00774 
00775   if ( mDialogList.find( todo ) != mDialogList.end() ) {
00776     kdDebug() << "Already in the list " << endl;
00777     mDialogList[todo]->reload();
00778     mDialogList[todo]->raise();
00779     mDialogList[todo]->show();
00780     return;
00781   }
00782 
00783   if ( todo->isReadOnly() ) {
00784     showTodo( todo );
00785     return;
00786   }
00787 
00788   KOTodoEditor *todoEditor = mDialogManager->getTodoEditor();
00789   kdDebug() << "New editor" << endl;
00790   mDialogList.insert( todo, todoEditor );
00791   todoEditor->editTodo( todo );
00792   todoEditor->show();
00793 }
00794 
00795 void CalendarView::showEvent(Event *event)
00796 {
00797   KOEventViewerDialog *eventViewer = new KOEventViewerDialog(this);
00798   eventViewer->setEvent(event);
00799   eventViewer->show();
00800 }
00801 
00802 void CalendarView::showTodo(Todo *event)
00803 {
00804   KOEventViewerDialog *eventViewer = new KOEventViewerDialog(this);
00805   eventViewer->setTodo(event);
00806   eventViewer->show();
00807 }
00808 
00809 void CalendarView::todoModified (Todo *event, int changed)
00810 {
00811   if (mDialogList.find (event) != mDialogList.end ()) {
00812     kdDebug() << "Todo modified and open" << endl;
00813     KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
00814     temp->modified (changed);
00815 
00816   }
00817   
00818   mViewManager->updateView();
00819 }
00820 
00821 void CalendarView::appointment_show()
00822 {
00823   Event *anEvent = 0;
00824 
00825   Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
00826 
00827   if (mViewManager->currentView()->isEventView()) {
00828     if ( incidence && incidence->type() == "Event" ) {
00829       anEvent = static_cast<Event *>(incidence);
00830     }
00831   }
00832 
00833   if (!anEvent) {
00834     KNotifyClient::beep();
00835     return;
00836   }
00837 
00838   showEvent(anEvent);
00839 }
00840 
00841 void CalendarView::appointment_edit()
00842 {
00843   Event *anEvent = 0;
00844 
00845   Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
00846 
00847   if (mViewManager->currentView()->isEventView()) {
00848     if ( incidence && incidence->type() == "Event" ) {
00849       anEvent = static_cast<Event *>(incidence);
00850     }
00851   }
00852 
00853   if (!anEvent) {
00854     KNotifyClient::beep();
00855     return;
00856   }
00857 
00858   editEvent(anEvent);
00859 }
00860 
00861 void CalendarView::appointment_delete()
00862 {
00863   Event *anEvent = 0;
00864 
00865   Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
00866 
00867   if (mViewManager->currentView()->isEventView()) {
00868     if ( incidence && incidence->type() == "Event" ) {
00869       anEvent = static_cast<Event *>(incidence);
00870     }
00871   }
00872 
00873   if (!anEvent) {
00874     KNotifyClient::beep();
00875     return;
00876   }
00877 
00878   deleteEvent(anEvent);
00879 }
00880 
00881 void CalendarView::todo_unsub()
00882 {
00883   Todo *anTodo = selectedTodo();
00884   if (!anTodo) return;
00885   if (!anTodo->relatedTo()) return;
00886   anTodo->relatedTo()->removeRelation(anTodo);
00887   anTodo->setRelatedTo(0);
00888   anTodo->setRelatedToUid("");
00889   setModified(true);
00890   updateView();
00891 }
00892 
00893 void CalendarView::deleteTodo(Todo *todo)
00894 {
00895   if (!todo) {
00896     KNotifyClient::beep();
00897     return;
00898   }
00899   if (KOPrefs::instance()->mConfirm) {
00900     switch (msgItemDelete()) {
00901       case KMessageBox::Continue: // OK
00902         if (!todo->relations().isEmpty()) {
00903           KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."),
00904                          i18n("Delete To-Do"));
00905         } else {
00906           calendar()->deleteTodo(todo);
00907           updateView();
00908         }
00909         break;
00910     } // switch
00911   } else {
00912     if (!todo->relations().isEmpty()) {
00913         KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."),
00914                          i18n("Delete To-Do"));
00915     } else {
00916       calendar()->deleteTodo(todo);
00917       updateView();
00918     }
00919   }
00920 }
00921 
00922 void CalendarView::deleteEvent(Event *anEvent)
00923 {
00924   if (!anEvent) {
00925     KNotifyClient::beep();
00926     return;
00927   }
00928   
00929   if (anEvent->recurrence()->doesRecur()) {
00930     QDate itemDate = mViewManager->currentSelectionDate();
00931     kdDebug() << "Recurrence-Date: " << itemDate.toString() << endl;
00932     int km;
00933     if (!itemDate.isValid()) {
00934       kdDebug() << "Date Not Valid" << endl;
00935       km = KMessageBox::warningContinueCancel(this,
00936         i18n("This event recurs over multiple dates. "
00937              "Are you sure you want to delete this event "
00938              "and all its recurrences?"),
00939              i18n("KOrganizer Confirmation"),i18n("Delete All"));
00940     } else {
00941       km = KMessageBox::warningYesNoCancel(this,
00942         i18n("This event recurs over multiple dates. "
00943              "Do you want to delete all it's recurrences, "
00944              "or only the current one on "+
00945              KGlobal::locale()->formatDate(itemDate)+"?"),
00946              i18n("KOrganizer Confirmation"),i18n("Delete Current"),
00947              i18n("Delete All"));
00948     }
00949     switch(km) {
00950 
00951       case KMessageBox::No: // Continue // all
00952         if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
00953           schedule(Scheduler::Cancel,anEvent);
00954         mCalendar->deleteEvent(anEvent);
00955         changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
00956         break;
00957 
00958 // Disabled because it does not work
00959 //#if 0
00960       case KMessageBox::Yes: // just this one
00961         //QDate qd = mNavigator->selectedDates().first();
00962         //if (!qd.isValid()) {
00963         //  kdDebug() << "no date selected, or invalid date" << endl;
00964         //  KNotifyClient::beep();
00965         //  return;
00966         //}
00967         //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
00968         if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
00969           anEvent->addExDate(itemDate);
00970           int duration = anEvent->recurrence()->duration();
00971           if ( duration > 0 ) {
00972             anEvent->recurrence()->setDuration( duration - 1 );
00973           }
00974           changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
00975         }
00976         break;
00977 //#endif
00978     } // switch
00979   } else {
00980     if (KOPrefs::instance()->mConfirm) {
00981       switch (msgItemDelete()) {
00982         case KMessageBox::Continue: // OK
00983           if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
00984             schedule(Scheduler::Cancel,anEvent);
00985           mCalendar->deleteEvent(anEvent);
00986           changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
00987           break;
00988       } // switch
00989     } else {
00990       if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
00991         schedule(Scheduler::Cancel,anEvent);
00992       mCalendar->deleteEvent(anEvent);
00993       changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
00994     }
00995   } // if-else
00996 }
00997 
00998 bool CalendarView::deleteEvent(const QString &uid)
00999 {
01000     Event *ev = mCalendar->event(uid);
01001     if (ev) {
01002         deleteEvent(ev);
01003         return true;
01004     } else {
01005         return false;
01006     }
01007 }
01008 
01009 /*****************************************************************************/
01010 
01011 void CalendarView::action_mail()
01012 {
01013 #ifndef KORG_NOMAIL
01014   KOMailClient mailClient;
01015 
01016   Incidence *incidence = currentSelection();
01017 
01018   if (!incidence) {
01019     KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
01020     return;
01021   }
01022   if(incidence->attendeeCount() == 0 ) {
01023     KMessageBox::sorry(this,
01024                        i18n("Can't generate mail:\nNo attendees defined.\n"));
01025     return;
01026   }
01027 
01028   Calendar *cal_tmp = new CalendarLocal();
01029   Event *event = 0;
01030   Event *ev = 0;
01031   if ( incidence && incidence->type() == "Event" ) {
01032     event = static_cast<Event *>(incidence);
01033     ev = new Event(*event);
01034     cal_tmp->addEvent(ev);
01035   }
01036   ICalFormat mForm;
01037   QString attachment = mForm.toString( cal_tmp );
01038   if (ev) delete(ev);
01039   delete(cal_tmp);
01040 
01041   mailClient.mailAttendees(currentSelection(), attachment);
01042 
01043 #endif
01044 
01045 #if 0
01046   Event *anEvent = 0;
01047   if (mViewManager->currentView()->isEventView()) {
01048     anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
01049   }
01050 
01051   if (!anEvent) {
01052     KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
01053     return;
01054   }
01055   if(anEvent->attendeeCount() == 0 ) {
01056     KMessageBox::sorry(this,
01057                        i18n("Can't generate mail:\nNo attendees defined.\n"));
01058     return;
01059   }
01060 
01061   mailobject.emailEvent(anEvent);
01062 #endif
01063 }
01064 
01065 
01066 void CalendarView::schedule_publish(Incidence *incidence)
01067 {
01068   Event *event = 0;
01069   Todo *todo = 0;
01070 
01071   if (incidence == 0) {
01072     incidence = mViewManager->currentView()->selectedIncidences().first();
01073     if (incidence == 0) {
01074       incidence = mTodoList->selectedIncidences().first();
01075     }
01076   }
01077   if ( incidence && incidence->type() == "Event" ) {
01078     event = static_cast<Event *>(incidence);
01079   } else {
01080     if ( incidence && incidence->type() == "Todo" ) {
01081       todo = static_cast<Todo *>(incidence);
01082     }
01083   }
01084 
01085   if (!event && !todo) {
01086     KMessageBox::sorry(this,i18n("No event selected."));
01087     return;
01088   }
01089 
01090   PublishDialog *publishdlg = new PublishDialog();
01091   if (incidence->attendeeCount()>0) {
01092     QPtrList<Attendee> attendees = incidence->attendees();
01093     attendees.first();
01094     while ( attendees.current()!=0 ) {
01095      publishdlg->addAttendee(attendees.current());
01096      attendees.next();
01097    }
01098   }
01099   bool send = true;
01100   if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
01101     if ( publishdlg->exec() != QDialog::Accepted ) 
01102       send = false;
01103   }    
01104   if ( send ) {
01105     OutgoingDialog *dlg = mDialogManager->outgoingDialog();
01106     if ( event ) {
01107       Event *ev = new Event(*event);
01108       ev->registerObserver(0);
01109       ev->clearAttendees();
01110       if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
01111         delete(ev);
01112       }
01113     } else {
01114       if ( todo ) {
01115         Todo *ev = new Todo(*todo);
01116         ev->registerObserver(0);
01117         ev->clearAttendees();
01118         if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
01119           delete(ev);
01120         }
01121       }
01122     }
01123   }
01124   delete publishdlg;
01125 }
01126 
01127 void CalendarView::schedule_request(Incidence *incidence)
01128 {
01129   schedule(Scheduler::Request,incidence);
01130 }
01131 
01132 void CalendarView::schedule_refresh(Incidence *incidence)
01133 {
01134   schedule(Scheduler::Refresh,incidence);
01135 }
01136 
01137 void CalendarView::schedule_cancel(Incidence *incidence)
01138 {
01139   schedule(Scheduler::Cancel,incidence);
01140 }
01141 
01142 void CalendarView::schedule_add(Incidence *incidence)
01143 {
01144   schedule(Scheduler::Add,incidence);
01145 }
01146 
01147 void CalendarView::schedule_reply(Incidence *incidence)
01148 {
01149   schedule(Scheduler::Reply,incidence);
01150 }
01151 
01152 void CalendarView::schedule_counter(Incidence *incidence)
01153 {
01154   schedule(Scheduler::Counter,incidence);
01155 }
01156 
01157 void CalendarView::schedule_declinecounter(Incidence *incidence)
01158 {
01159   schedule(Scheduler::Declinecounter,incidence);
01160 }
01161 
01162 void CalendarView::schedule_publish_freebusy(int daysToPublish)
01163 {
01164   QDateTime start = QDateTime::currentDateTime();
01165   QDateTime end = start.addDays(daysToPublish);
01166 
01167   FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
01168   freebusy->setOrganizer(KOPrefs::instance()->email());
01169 
01170   kdDebug() << "calendarview: schedule_publish_freebusy: startDate: "
01171      << KGlobal::locale()->formatDateTime( start ) << " End Date: " 
01172      << KGlobal::locale()->formatDateTime( end ) << endl;
01173   
01174   PublishDialog *publishdlg = new PublishDialog();
01175   if ( publishdlg->exec() == QDialog::Accepted ) {
01176     OutgoingDialog *dlg = mDialogManager->outgoingDialog();
01177     if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
01178          delete(freebusy);
01179     }
01180   }
01181   delete publishdlg;
01182 }
01183 
01184 void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
01185 {
01186   Event *event = 0;
01187   Todo *todo = 0;
01188 
01189   if (incidence == 0) {
01190     incidence = mViewManager->currentView()->selectedIncidences().first();
01191     if (incidence == 0) {
01192       incidence = mTodoList->selectedIncidences().first();
01193     }
01194   }
01195   if ( incidence && incidence->type() == "Event" ) {
01196     event = static_cast<Event *>(incidence);
01197   }
01198   if ( incidence && incidence->type() == "Todo" ) {
01199     todo = static_cast<Todo *>(incidence);
01200   }
01201 
01202   if (!event && !todo) {
01203     KMessageBox::sorry(this,i18n("No event selected."));
01204     return;
01205   }
01206 
01207   if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
01208     KMessageBox::sorry(this,i18n("The event has no attendees."));
01209     return;
01210   }
01211   
01212   Event *ev = 0;
01213   if (event) ev = new Event(*event);
01214   Todo *to = 0;
01215   if (todo) to = new Todo(*todo);
01216 
01217   if (method == Scheduler::Reply || method == Scheduler::Refresh) {
01218     Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
01219     if (!me) {
01220       KMessageBox::sorry(this,i18n("Could not find your attendee entry. Please check the emails."));
01221       return;
01222     }
01223     if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
01224       StatusDialog *statdlg = new StatusDialog(this);
01225       if (!statdlg->exec()==QDialog::Accepted) return;
01226       me->setStatus( statdlg->status() );
01227       delete(statdlg);
01228     }
01229     Attendee *menew = new Attendee(*me);
01230     if (ev) {
01231       ev->clearAttendees();
01232       ev->addAttendee(menew,false);
01233     } else {
01234       if (to) {
01235         todo->clearAttendees();
01236         todo->addAttendee(menew,false);
01237       }
01238     }
01239   }
01240 
01241   OutgoingDialog *dlg = mDialogManager->outgoingDialog();
01242   if (ev) {
01243     if ( !dlg->addMessage(ev,method) ) delete(ev);
01244   } else {
01245     if (to) {
01246       if ( !dlg->addMessage(to,method) ) delete(to);
01247     }
01248   }
01249 }
01250 
01251 void CalendarView::openAddressbook()
01252 {
01253   KRun::runCommand("kaddressbook");
01254 }
01255 
01256 void CalendarView::setModified(bool modified)
01257 {
01258   if (mModified != modified) {
01259     mModified = modified;
01260     emit modifiedChanged(mModified);
01261   }
01262 }
01263 
01264 bool CalendarView::isReadOnly()
01265 {
01266   return mReadOnly;
01267 }
01268 
01269 void CalendarView::setReadOnly(bool readOnly)
01270 {
01271   if (mReadOnly != readOnly) {
01272     mReadOnly = readOnly;
01273     emit readOnlyChanged(mReadOnly);
01274   }
01275 }
01276 
01277 bool CalendarView::isModified()
01278 {
01279   return mModified;
01280 }
01281 
01282 // TODO: Check, if this function is still needed
01283 void CalendarView::signalAlarmDaemon()
01284 {
01285 #if 0
01286   QFile pidFile;
01287   QString tmpStr;
01288   pid_t pid;
01289   char pidStr[25];
01290 
01291   tmpStr = locateLocal("appdata", "alarm.pid");
01292 
01293   pidFile.setName(tmpStr);
01294 
01295   // only necessary if the file actually is opened
01296   if(pidFile.open(IO_ReadOnly)) {
01297     pidFile.readLine(pidStr, 24);
01298     pidFile.close();
01299     pid = atoi(pidStr);
01300     if (pid > 0)
01301       kill(pid, SIGHUP);
01302   }
01303 #endif
01304 }
01305 
01306 void CalendarView::printSetup()
01307 {
01308 #ifndef KORG_NOPRINTER
01309   createPrinter();
01310 
01311   mCalPrinter->setupPrinter();
01312 #endif
01313 }
01314 
01315 void CalendarView::print()
01316 {
01317 #ifndef KORG_NOPRINTER
01318   createPrinter();
01319 
01320   DateList tmpDateList = mNavigator->selectedDates();
01321   mCalPrinter->print(CalPrinter::Month,
01322                      tmpDateList.first(), tmpDateList.last());
01323 #endif
01324 }
01325 
01326 void CalendarView::printPreview()
01327 {
01328 #ifndef KORG_NOPRINTER
01329   kdDebug() << "CalendarView::printPreview()" << endl;
01330 
01331   createPrinter();
01332 
01333   DateList tmpDateList = mNavigator->selectedDates();
01334 
01335   mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
01336                              tmpDateList.last());
01337 #endif
01338 }
01339 
01340 void CalendarView::exportICalendar()
01341 {
01342   QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
01343 
01344   // Force correct extension
01345   if (filename.right(4) != ".ics") filename += ".ics";
01346 
01347   FileStorage storage( mCalendar, filename, new ICalFormat );
01348   storage.save();
01349 }
01350 
01351 void CalendarView::exportVCalendar()
01352 {
01353   if (mCalendar->journals().count() > 0) {
01354     int result = KMessageBox::warningContinueCancel(this,
01355         i18n("The journal entries can not be exported to a vCalendar file."),
01356         i18n("Data Loss Warning"),i18n("Proceed"),"dontaskVCalExport",
01357         true);
01358     if (result != KMessageBox::Continue) return;
01359   }
01360 
01361   QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
01362 
01363   // Force correct extension
01364   if (filename.right(4) != ".vcs") filename += ".vcs";
01365 
01366   FileStorage storage( mCalendar, filename, new VCalFormat );
01367   storage.save();
01368 }
01369 
01370 void CalendarView::eventUpdated(Incidence *)
01371 {
01372   setModified();
01373   // Don't call updateView here. The code, which has caused the update of the
01374   // event is responsible for updating the view.
01375 //  updateView();
01376 }
01377 
01378 void CalendarView::adaptNavigationUnits()
01379 {
01380   if (mViewManager->currentView()->isEventView()) {
01381     int days = mViewManager->currentView()->currentDateCount();
01382     if (days == 1) {
01383       emit changeNavStringPrev(i18n("&Previous Day"));
01384       emit changeNavStringNext(i18n("&Next Day"));
01385     } else {
01386       emit changeNavStringPrev(i18n("&Previous Week"));
01387       emit changeNavStringNext(i18n("&Next Week"));
01388     }
01389   }
01390 }
01391 
01392 void CalendarView::processMainViewSelection( Incidence *incidence )
01393 {
01394   if ( incidence ) mTodoList->clearSelection();
01395   processIncidenceSelection( incidence );
01396 }
01397 
01398 void CalendarView::processTodoListSelection( Incidence *incidence )
01399 {
01400   if ( incidence && mViewManager->currentView() ) {
01401     mViewManager->currentView()->clearSelection();
01402   }
01403   processIncidenceSelection( incidence );
01404 }
01405 
01406 void CalendarView::processIncidenceSelection( Incidence *incidence )
01407 {
01408   if ( incidence == mSelectedIncidence ) return;
01409   
01410   mSelectedIncidence = incidence;
01411 
01412   emit incidenceSelected( mSelectedIncidence );
01413 
01414   if ( incidence && incidence->type() == "Event" ) {
01415     Event *event = static_cast<Event *>( incidence );
01416     if ( event->organizer() == KOPrefs::instance()->email() ) {
01417       emit organizerEventsSelected( true );
01418     } else {
01419       emit organizerEventsSelected(false);
01420     }
01421     if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
01422                                 KOPrefs::instance()->email() ) ) {
01423       emit groupEventsSelected( true );
01424     } else {
01425       emit groupEventsSelected(false);
01426     }
01427     return;
01428   } else {
01429     if  ( incidence && incidence->type() == "Todo" ) {
01430       emit todoSelected( true );
01431       Todo *event = static_cast<Todo *>( incidence );
01432       if ( event->organizer() == KOPrefs::instance()->email() ) {
01433         emit organizerEventsSelected( true );
01434      } else {
01435         emit organizerEventsSelected(false);
01436       }
01437       if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
01438                                   KOPrefs::instance()->email() ) ) {
01439         emit groupEventsSelected( true );
01440       } else {
01441         emit groupEventsSelected(false);
01442       }
01443       return;
01444     } else {
01445      emit todoSelected( false );
01446      emit organizerEventsSelected(false);
01447      emit groupEventsSelected(false);
01448     }
01449     return;
01450   }
01451 
01452 /*  if  ( incidence && incidence->type() == "Todo" ) {
01453     emit todoSelected( true );
01454   } else {
01455     emit todoSelected( false );
01456   }*/
01457 }
01458 
01459 
01460 void CalendarView::checkClipboard()
01461 {
01462 #ifndef KORG_NODND
01463   if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
01464     kdDebug() << "CalendarView::checkClipboard() true" << endl;
01465     emit pasteEnabled(true);
01466   } else {
01467     kdDebug() << "CalendarView::checkClipboard() false" << endl;
01468     emit pasteEnabled(false);
01469   }
01470 #endif
01471 }
01472 
01473 void CalendarView::showDates(const DateList &selectedDates)
01474 {
01475 //  kdDebug() << "CalendarView::selectDates()" << endl;
01476 
01477   if ( mViewManager->currentView() ) {  
01478     updateView( selectedDates.first(), selectedDates.last() );
01479   } else {
01480     mViewManager->showAgendaView();
01481   }
01482 }
01483 
01484 void CalendarView::editFilters()
01485 {
01486 //  kdDebug() << "CalendarView::editFilters()" << endl;
01487 
01488   CalFilter *filter = mFilters.first();
01489   while(filter) {
01490     kdDebug() << " Filter: " << filter->name() << endl;
01491     filter = mFilters.next();
01492   }
01493 
01494   mDialogManager->showFilterEditDialog(&mFilters);
01495 }
01496 
01497 void CalendarView::showFilter(bool visible)
01498 {
01499   if (visible) mFilterView->show();
01500   else mFilterView->hide();
01501 }
01502 
01503 void CalendarView::updateFilter()
01504 {
01505   CalFilter *filter = mFilterView->selectedFilter();
01506   if (filter) {
01507     if (mFilterView->filtersEnabled()) filter->setEnabled(true);
01508     else filter->setEnabled(false);
01509     mCalendar->setFilter(filter);
01510     updateView();
01511   }
01512 }
01513 
01514 void CalendarView::filterEdited()
01515 {
01516   mFilterView->updateFilters();
01517   updateFilter();
01518 }
01519 
01520 
01521 void CalendarView::takeOverEvent()
01522 {
01523   Incidence *incidence = currentSelection();
01524 
01525   if (!incidence) return;
01526   
01527   incidence->setOrganizer(KOPrefs::instance()->email());
01528   incidence->recreate();
01529   incidence->setReadOnly(false);
01530 
01531   updateView();
01532 }
01533 
01534 void CalendarView::takeOverCalendar()
01535 {
01536   // TODO: Create Calendar::allIncidences() function and use it here
01537 
01538   QPtrList<Event> events = mCalendar->events();  
01539   for(uint i=0; i<events.count(); ++i) {
01540     events.at(i)->setOrganizer(KOPrefs::instance()->email());
01541     events.at(i)->recreate();
01542     events.at(i)->setReadOnly(false);
01543   }
01544 
01545   QPtrList<Todo> todos = mCalendar->todos();
01546   for(uint i=0; i<todos.count(); ++i) {
01547     todos.at(i)->setOrganizer(KOPrefs::instance()->email());
01548     todos.at(i)->recreate();
01549     todos.at(i)->setReadOnly(false);
01550   }
01551 
01552   QPtrList<Journal> journals = mCalendar->journals();
01553   for(uint i=0; i<journals.count(); ++i) {
01554     journals.at(i)->setOrganizer(KOPrefs::instance()->email());
01555     journals.at(i)->recreate();
01556     journals.at(i)->setReadOnly(false);
01557   }
01558   
01559   updateView();
01560 }
01561 
01562 void CalendarView::showIntro()
01563 {
01564   kdDebug() << "To be implemented." << endl;
01565 }
01566 
01567 QWidgetStack *CalendarView::viewStack()
01568 {
01569   return mRightFrame;
01570 }
01571 
01572 QWidget *CalendarView::leftFrame()
01573 {
01574   return mLeftFrame;
01575 }
01576 
01577 DateNavigator *CalendarView::dateNavigator()
01578 {
01579   return mNavigator;
01580 }
01581 
01582 void CalendarView::addView(KOrg::BaseView *view)
01583 {
01584   mViewManager->addView(view);
01585 }
01586 
01587 void CalendarView::showView(KOrg::BaseView *view)
01588 {
01589   mViewManager->showView(view);
01590 }
01591 
01592 Incidence *CalendarView::currentSelection()
01593 {
01594   return mViewManager->currentSelection();
01595 }
01596 
01597 void CalendarView::toggleExpand()
01598 {
01599   if ( mLeftFrame->isHidden() ) {
01600     mLeftFrame->show();
01601     emit calendarViewExpanded( false );
01602   } else {
01603     mLeftFrame->hide();
01604     emit calendarViewExpanded( true );
01605   }
01606 }
01607 
01608 void CalendarView::calendarModified( bool modified, Calendar * )
01609 {
01610   setModified( modified );
01611 }
01612 
01613 Todo *CalendarView::selectedTodo()
01614 {
01615   Incidence *incidence = currentSelection();
01616   if ( incidence && incidence->type() == "Todo" ) {
01617     return static_cast<Todo *>( incidence );
01618   }
01619 
01620   incidence = mTodoList->selectedIncidences().first();
01621   if ( incidence && incidence->type() == "Todo" ) {
01622     return static_cast<Todo *>( incidence );
01623   }
01624 
01625   return 0;
01626 }
01627 
01628 void CalendarView::dialogClosing(Incidence *in)
01629 {
01630   mDialogList.remove(in);
01631 }
01632 
01633 void CalendarView::showIncidence()
01634 {
01635   Incidence *incidence = currentSelection();
01636   if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
01637   if ( incidence ) {
01638     ShowIncidenceVisitor v;
01639     v.act( incidence, this );
01640   }
01641 }
01642 
01643 void CalendarView::editIncidence()
01644 {
01645   Incidence *incidence = currentSelection();
01646   if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
01647   if ( incidence ) {
01648     EditIncidenceVisitor v;
01649     v.act( incidence, this );
01650   }
01651 }
01652 
01653 void CalendarView::deleteIncidence()
01654 {
01655   Incidence *incidence = currentSelection();
01656   if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
01657   if ( incidence ) {
01658     DeleteIncidenceVisitor v;
01659     v.act( incidence, this );
01660   }
01661 }
01662 
01663 
01664 void CalendarView::lookForOutgoingMessages()
01665 {
01666   OutgoingDialog *ogd = mDialogManager->outgoingDialog();
01667   ogd->loadMessages();
01668 }
01669 
01670 void CalendarView::lookForIncomingMessages()
01671 {
01672   IncomingDialog *icd = mDialogManager->incomingDialog();
01673   icd->retrieve();
01674 }
01675 
01676 void CalendarView::purgeCompleted()
01677 {
01678   int result = KMessageBox::warningContinueCancel(this,
01679       i18n("Delete all completed To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
01680 
01681   if (result == KMessageBox::Continue) {
01682     QPtrList<Todo> todoCal;
01683     QPtrList<Incidence> rel;
01684     Todo *aTodo, *rTodo;
01685     Incidence *rIncidence;
01686     bool childDelete = false;
01687     bool deletedOne = true;
01688     while (deletedOne) {
01689       todoCal.clear();
01690       todoCal = calendar()->todos();
01691       deletedOne = false;
01692       for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
01693         if (aTodo->isCompleted()) {
01694           rel = aTodo->relations();
01695           if (!rel.isEmpty()) {
01696             for (rIncidence=rel.first(); rIncidence; rIncidence=rel.next()){
01697               if (rIncidence->type()=="Todo") {
01698                 rTodo = static_cast<Todo*>(rIncidence);
01699                 if (!rTodo->isCompleted()) childDelete = true;
01700               }
01701             }
01702           }
01703           else {
01704             calendar()->deleteTodo(aTodo);
01705             deletedOne = true;
01706           }
01707         }
01708       }
01709     }
01710     if (childDelete) {
01711       KMessageBox::sorry(this,i18n("Cannot purge To-Do which has uncompleted children."),
01712                          i18n("Delete To-Do"));
01713     }
01714     updateView();
01715   }
01716 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001