-rw-r--r-- | korganizer/kotodoeditor.cpp | 29 | ||||
-rw-r--r-- | korganizer/kotodoviewitem.cpp | 42 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 9 | ||||
-rw-r--r-- | libkcal/incidence.h | 5 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 51 | ||||
-rw-r--r-- | libkcal/todo.h | 2 |
8 files changed, 133 insertions, 10 deletions
diff --git a/korganizer/kotodoeditor.cpp b/korganizer/kotodoeditor.cpp index 069dda8..9232e09 100644 --- a/korganizer/kotodoeditor.cpp +++ b/korganizer/kotodoeditor.cpp @@ -68,359 +68,388 @@ KOTodoEditor::~KOTodoEditor() void KOTodoEditor::init() { setupGeneral(); setupAttendeesTab(); setupRecurrence(); connect(mGeneral,SIGNAL(datesChecked()),this ,SLOT(checkRecurrence())); } void KOTodoEditor::setupRecurrence() { QFrame *topFrame = addPage( i18n("Recurrence") ); QBoxLayout *topLayout = new QVBoxLayout( topFrame ); mRecurrence = new KOEditorRecurrence( topFrame ); topLayout->addWidget( mRecurrence ); } void KOTodoEditor::setCategories( QString s ) { mGeneral->setCategories(s); } void KOTodoEditor::setSecrecy( int sec ) { mGeneral->setSecrecy( sec ); } void KOTodoEditor::reload() { if ( mTodo ) readTodo( mTodo ); } void KOTodoEditor::setupGeneral() { mGeneral = new KOEditorGeneralTodo(this); connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); //connect(mCategoryDialog, SIGNAL(categoriesSelected(const QString &)), // mGeneral,SLOT(setCategories(const QString &))); if (KOPrefs::instance()->mCompactDialogs) { QFrame *topFrame = addPage(i18n("General")); QBoxLayout *topLayout = new QVBoxLayout(topFrame); if ( QApplication::desktop()->width() < 480 ) { topLayout->setMargin(1); topLayout->setSpacing(1); } else { topLayout->setMargin(marginHint()-1); topLayout->setSpacing(spacingHint()-1); } mGeneral->initHeader(topFrame,topLayout); mGeneral->initTime(topFrame,topLayout); mGeneral->initAlarm(topFrame,topLayout); mGeneral->enableAlarm( false ); QBoxLayout *priorityLayout; if ( QApplication::desktop()->width() < 500 ) priorityLayout = new QVBoxLayout( topLayout ); else priorityLayout = new QHBoxLayout( topLayout ); QWidget* prioWidget = new QWidget (topFrame); priorityLayout->addWidget( prioWidget ); QHBoxLayout* priorityLayout2 = new QHBoxLayout( prioWidget); QIconSet icon; if ( QApplication::desktop()->width() < 321 ) icon = SmallIcon("fileexport16"); else icon = SmallIcon("fileexport"); QPushButton * saveTemplate = new QPushButton( prioWidget); saveTemplate->setIconSet (icon ) ; int size = saveTemplate->sizeHint().height(); saveTemplate->setFixedSize( size, size ); if ( QApplication::desktop()->width() < 321 ) icon = SmallIcon("fileimport16"); else icon = SmallIcon("fileimport"); QPushButton * loadTemplate = new QPushButton( prioWidget); loadTemplate->setIconSet (icon ) ; loadTemplate->setFixedSize( size, size ); priorityLayout2->addWidget(loadTemplate); priorityLayout2->addWidget(saveTemplate); mGeneral->initPriority(prioWidget,priorityLayout2); mGeneral->initCategories( topFrame, priorityLayout ); topLayout->addStretch(1); QFrame *topFrame2 = addPage(i18n("Details")); QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); topLayout2->setMargin(marginHint()); topLayout2->setSpacing(spacingHint()); QHBoxLayout *completionLayout = new QHBoxLayout( topLayout2 ); mGeneral->initCompletion(topFrame2,completionLayout); mGeneral->initSecrecy( topFrame2, topLayout2 ); mGeneral->initDescription(topFrame2,topLayout2); // QHBox * hb = new QHBox ( topFrame2 ); // topLayout2->addWidget(hb); // hb->setSpacing( 3 ); connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); } else { QFrame *topFrame = addPage(i18n("General")); QBoxLayout *topLayout = new QVBoxLayout(topFrame); topLayout->setSpacing(spacingHint()); mGeneral->initHeader(topFrame,topLayout); mGeneral->initTime(topFrame,topLayout); mGeneral->initStatus(topFrame,topLayout); QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); mGeneral->initAlarm(topFrame,alarmLineLayout); mGeneral->initDescription(topFrame,topLayout); QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); mGeneral->initCategories( topFrame, detailsLayout ); mGeneral->initSecrecy( topFrame, detailsLayout ); } mGeneral->finishSetup(); } void KOTodoEditor::editTodo(Todo *todo, bool editDescription) { //init(); mTodo = todo; readTodo(mTodo); if ( editDescription ) { showPage( 1 ); mGeneral->setFocusOn( 1 ); } else { showPage( 0 ); mGeneral->setFocusOn( 2 ); } checkRecurrence(); } void KOTodoEditor::newTodo(QDateTime due,Todo *relatedTodo,bool allDay) { //init(); mTodo = 0; setDefaults(due,relatedTodo,allDay); } void KOTodoEditor::loadDefaults() { setDefaults(QDateTime::currentDateTime().addDays(7),0,false); } bool KOTodoEditor::processInput( bool emitTime ) { if (!validateInput()) return false; Todo *todo = 0; if (mTodo) todo = mTodo; else { todo = new Todo; todo->setOrganizer(KOPrefs::instance()->email()); } writeTodo(todo); if ( emitTime ) { globalFlagBlockAgenda = 1; emit showAgendaView( false ); if ( todo->hasDueDate() ) emit jumpToTime( todo->dtDue().date() ); globalFlagBlockAgenda = 2; } if (mTodo) { todo->setRevision(todo->revision()+1); emit todoChanged(todo); } else { mCalendar->addTodo(todo); mTodo = todo; emit todoAdded(todo); } return true; } void KOTodoEditor::deleteTodo() { if (mTodo) { if (KOPrefs::instance()->mConfirm) { switch (msgItemDelete()) { case KMessageBox::Continue: // OK emit todoToBeDeleted(mTodo); emit dialogClose(mTodo); mCalendar->deleteTodo(mTodo); emit todoDeleted(); reject(); break; } } else { emit todoToBeDeleted(mTodo); emit dialogClose(mTodo); mCalendar->deleteTodo(mTodo); emit todoDeleted(); reject(); } } else { reject(); } } void KOTodoEditor::setDefaults(QDateTime due,Todo *relatedEvent,bool allDay) { mRelatedTodo = relatedEvent; mGeneral->setDefaults(due,allDay); mDetails->setDefaults(); showPage( 0 ); if ( mRelatedTodo ) { mGeneral->setCategories (mRelatedTodo->categoriesStr ()); mGeneral->setSecrecy (mRelatedTodo->secrecy ()); if ( mRelatedTodo->priority() < 3 ) mGeneral->mPriorityCombo->setCurrentItem(mRelatedTodo->priority()-1); mGeneral->mSummaryEdit->lineEdit()->setText(mRelatedTodo->summary()+": "); int len = mRelatedTodo->summary().length(); mGeneral->mSummaryEdit->lineEdit()->setFocus(); mGeneral->mSummaryEdit->lineEdit()->setCursorPosition ( len+2 ); mGeneral->mSummaryEdit->lineEdit()->setSelection ( 0, len+2 ); } else mGeneral->setFocusOn( 2 ); tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); } void KOTodoEditor::checkRecurrence() { if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), true ); if ( mTodo ) mRecurrence->readEvent( mTodo ); else { bool time = mGeneral->mTimeButton->isChecked(); QDateTime from,to; if ( time ) { to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; } else { to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; } + if ( to < from ) + to = from; mRecurrence->setDefaults(from,to,!time); } } else { tabWidget()->setTabEnabled ( mRecurrence->parentWidget(), false ); mRecurrence->setDefaults(QDateTime::currentDateTime(),QDateTime::currentDateTime().addSecs( 3600 ),true); } } void KOTodoEditor::readTodo(Todo *todo) { mGeneral->readTodo(todo); mDetails->readEvent(todo); mRelatedTodo = 0;//todo->relatedTo(); // categories // mCategoryDialog->setSelected(todo->categories()); // We should handle read-only events here. } void KOTodoEditor::writeTodo(Todo *event) { mGeneral->writeTodo(event); mDetails->writeEvent(event); // set related event, i.e. parent to-do in this case. if (mRelatedTodo) { event->setRelatedTo(mRelatedTodo); } if ( mGeneral->mDueCheck->isChecked() && mGeneral->mStartCheck->isChecked()) { mRecurrence->writeEvent(event); + event->setRecurrenceID( event->dtStart().addSecs(-1) ); + event->setRecurDates(); +#if 0 + bool ok; + QDateTime next = event->getNextOccurence( event->dtStart().addSecs(-1), &ok ); + if ( ok ) { + QDateTime from,to; + bool time = mGeneral->mTimeButton->isChecked(); + if ( time ) { + to = QDateTime( mGeneral->mDueDateEdit->date(), mGeneral->mDueTimeEdit->getTime() ) ; + from = QDateTime( mGeneral->mStartDateEdit->date(),mGeneral->mStartTimeEdit->getTime( )) ; + } else { + to = QDateTime( mGeneral->mDueDateEdit->date(), QTime( 0,0,0) ) ; + from = QDateTime( mGeneral->mStartDateEdit->date(),QTime( 0,0,0) ) ; + } + if ( to < from ) + to = from; + int secs = from.secsTo( to ); + event->setRecurrenceID( next ); + event->setDtStart( next ); + event->setDtDue( next.addSecs( secs ) ); + } + else { + event->setHasRecurrenceID( false ); + event->recurrence()->unsetRecurs(); + } +#endif } else event->recurrence()->unsetRecurs(); } bool KOTodoEditor::validateInput() { if (!mGeneral->validateInput()) return false; if (!mDetails->validateInput()) return false; return true; } int KOTodoEditor::msgItemDelete() { return KMessageBox::warningContinueCancel(this, i18n("This item will be permanently deleted."), i18n("KOrganizer Confirmation"),i18n("Delete")); } void KOTodoEditor::modified (int modification) { if (modification == KOGlobals::CATEGORY_MODIFIED || KOGlobals::UNKNOWN_MODIFIED == modification ) // mCategoryDialog->setSelected (mTodo->categories ()); mGeneral->modified (mTodo, modification); } void KOTodoEditor::slotLoadTemplate() { QString fileName =locateLocal( "templates", "todos" ); QDir t_dir; if ( !t_dir.exists(fileName) ) t_dir.mkdir ( fileName ); fileName += "/todo"; fileName = KFileDialog::getSaveFileName( fileName , "Load Todo template", this ); if ( fileName.length() == 0 ) return; CalendarLocal cal; ICalFormat format; if ( !format.load( &cal, fileName ) ) { KMessageBox::error( this, i18n("Error loading template file\n '%1'.") .arg( fileName ) ); return ; } QPtrList<Todo> todos = cal.todos(); Todo * todo = todos.first(); if ( !todo ) { KMessageBox::error( this, i18n("Template does not\ncontain a valid Todo.")); } else { readTodo( todo ); } } void KOTodoEditor::slotSaveTemplate() { QString fileName =locateLocal( "templates", "todos" ); QDir t_dir; if ( !t_dir.exists(fileName) ) t_dir.mkdir ( fileName ); fileName += "/todo"; fileName = KFileDialog::getSaveFileName( fileName , "Save as Todo template", this ); if ( fileName.length() > 0 ) saveTemplate( fileName ); } void KOTodoEditor::saveTemplate( const QString &templateName ) { Todo *todo = new Todo; writeTodo( todo ); saveAsTemplate( todo, templateName ); } diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp index 0e847c2..70f00c6 100644 --- a/korganizer/kotodoviewitem.cpp +++ b/korganizer/kotodoviewitem.cpp @@ -1,461 +1,499 @@ /* This file is part of KOrganizer. Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <klocale.h> #include <kdebug.h> #include <qapp.h> #include <kiconloader.h> #include "kotodoviewitem.h" #include "kotodoview.h" #include "koprefs.h" KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) { construct(); } KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) { construct(); } QString KOTodoViewItem::key(int column,bool) const { QMap<int,QString>::ConstIterator it = mKeyMap.find(column); if (it == mKeyMap.end()) { return text(column).lower(); } else { return *it; } } void KOTodoViewItem:: setup() { int h = 20; if ( listView () ) { QFontMetrics fm ( listView ()->font () ); h = fm.height(); } setHeight( h ); } void KOTodoViewItem::setSortKey(int column,const QString &key) { mKeyMap.insert(column,key); } #if QT_VERSION >= 0x030000 void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, int y,int h) { QListViewItem::paintBranches(p,cg,w,y,h); } #else #endif void KOTodoViewItem::construct() { // qDebug("KOTodoViewItem::construct() "); m_init = true; QString keyd = "=="; QString keyt = "=="; QString skeyd = "=="; QString skeyt = "=="; setOn(mTodo->isCompleted()); setText(0,mTodo->summary()); setText(1,QString::number(mTodo->priority())); setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); if (mTodo->percentComplete()<100) { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(mTodo->percentComplete())); } else { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(99)); } if (mTodo->hasDueDate()) { setText(3, mTodo->dtDueDateStr()); QDate d = mTodo->dtDue().date(); keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); // setSortKey(3,keyd); if (mTodo->doesFloat()) { setText(4,""); } else { setText(4,mTodo->dtDueTimeStr()); QTime t = mTodo->dtDue().time(); keyt.sprintf("%02d%02d",t.hour(),t.minute()); //setSortKey(4,keyt); } } else { setText(3,""); setText(4,""); } setSortKey(3,keyd); setSortKey(4,keyt); if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); if (mTodo->hasStartDate()) { setText(5, mTodo->dtStartDateStr()); QDate d = mTodo->dtStart().date(); skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); if (mTodo->doesFloat()) { setText(6,""); } else { setText(6,mTodo->dtStartTimeStr()); QTime t = mTodo->dtStart().time(); skeyt.sprintf("%02d%02d",t.hour(),t.minute()); } } else { setText(5,""); setText(6,""); } setSortKey(5,skeyd); setSortKey(6,skeyt); setText(7,mTodo->cancelled() ? i18n("Yes") : i18n("No")); setText(8,mTodo->categoriesStr()); #if 0 // Find sort id in description. It's the text behind the last '#' character // found in the description. White spaces are removed from beginning and end // of sort id. int pos = mTodo->description().findRev('#'); if (pos < 0) { setText(6,""); } else { QString str = mTodo->description().mid(pos+1); str.stripWhiteSpace(); setText(6,str); } #endif m_known = false; m_init = false; setMyPixmap(); } void KOTodoViewItem::setMyPixmap() { int size = 5; QPixmap pixi = QPixmap( 1, 1 ); // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { // pixi = SmallIcon("redcross16"); // } else { QPainter p; int pixSize = 0; QPixmap pPix = QPixmap( size, size ); if ( mTodo->description().length() > 0 ) { pixi.resize(size, pixSize+size); pPix.fill( Qt::darkGreen ); p.begin( &pixi ); p. drawPixmap ( 0, pixSize, pPix); p.end(); pixSize += size; } if ( mTodo->isAlarmEnabled() ) { pixi.resize(size, pixSize+size); pPix.fill( Qt::red ); p.begin( &pixi ); p. drawPixmap ( 0, pixSize, pPix); p.end(); pixSize += size; + } + if ( mTodo->doesRecur() ) { + pixi.resize(size, pixSize+size); + pPix.fill( Qt::blue ); + p.begin( &pixi ); + p. drawPixmap ( 0, pixSize, pPix); + p.end(); + pixSize += size; } // } if ( pixi.width() > 1 ) { setPixmap ( 0,pixi ) ; } else { setPixmap ( 0,QPixmap() ) ; } } void KOTodoViewItem::stateChange(bool state) { - // qDebug("KOTodoViewItem::stateChange "); + // qDebug("KOTodoViewItem::stateChange %d ", state); // do not change setting on startup if ( m_init ) return; if (isOn()!=state) { setOn(state); //qDebug("SETON "); return; } if ( mTodo->isCompleted() == state ) { //qDebug("STATECHANGE:nothing to do "); return; } QString keyd = "=="; QString keyt = "=="; //qDebug("KOTodoViewItem::stateChange %s ", text(0).latin1()); - mTodo->setCompleted(state); + if ( mTodo->doesRecur() ){ + QDateTime start = mTodo->dtStart(); + mTodo->setCompleted(state); + if ( start != mTodo->dtStart() ) { + if ( state && !mTodo->isCompleted() ) { + setOn( false ); + state = false; + } + } + } else + mTodo->setCompleted(state); + if (state) mTodo->setCompleted(QDateTime::currentDateTime()); if (mTodo->hasDueDate()) { setText(3, mTodo->dtDueDateStr()); QDate d = mTodo->dtDue().date(); keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); setSortKey(3,keyd); if (mTodo->doesFloat()) { setText(4,""); } else { setText(4,mTodo->dtDueTimeStr()); QTime t = mTodo->dtDue().time(); keyt.sprintf("%02d%02d",t.hour(),t.minute()); setSortKey(4,keyt); } } + if (mTodo->hasStartDate()) { + QString skeyt = "=="; + QString skeyd = "=="; + setText(5, mTodo->dtStartDateStr()); + QDate d = mTodo->dtStart().date(); + skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); + + if (mTodo->doesFloat()) { + setText(6,""); + } + else { + setText(6,mTodo->dtStartTimeStr()); + QTime t = mTodo->dtStart().time(); + skeyt.sprintf("%02d%02d",t.hour(),t.minute()); + + } + setSortKey(5,skeyd); + setSortKey(6,skeyt); + } if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); if (mTodo->percentComplete()<100) { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(mTodo->percentComplete())); } else { if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); else setSortKey(2,QString::number(99)); } if ( state ) { QListViewItem * myChild = firstChild(); KOTodoViewItem *item; while( myChild ) { //qDebug("stateCH "); item = static_cast<KOTodoViewItem*>(myChild); item->stateChange(state); myChild = myChild->nextSibling(); } } else { QListViewItem * myChild = parent(); if ( myChild ) (static_cast<KOTodoViewItem*>(myChild))->stateChange(state); } mTodoView->modified(true); setMyPixmap(); mTodoView->setTodoModified( mTodo ); } bool KOTodoViewItem::isAlternate() { KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); if (lv && lv->alternateBackground().isValid()) { KOTodoViewItem *above = 0; above = static_cast<KOTodoViewItem *>(itemAbove()); m_known = above ? above->m_known : true; if (m_known) { m_odd = above ? !above->m_odd : false; } else { KOTodoViewItem *item; bool previous = true; if (QListViewItem::parent()) { item = static_cast<KOTodoViewItem *>(QListViewItem::parent()); if (item) previous = item->m_odd; item = static_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); } else { item = static_cast<KOTodoViewItem *>(lv->firstChild()); } while(item) { item->m_odd = previous = !previous; item->m_known = true; item = static_cast<KOTodoViewItem *>(item->nextSibling()); } } return m_odd; } return false; } void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) { QColorGroup _cg = cg; QColorGroup::ColorRole role; if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) role = QColorGroup::Text; else role = QColorGroup::Base; //#ifndef KORG_NOLVALTERNATION if (isAlternate()) _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; QColor colorToSet; if ( setColor ) { QStringList categories = mTodo->categories(); QString cat = categories.first(); if ( !cat.isEmpty()) { colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); } else setColor = false; } int odue = mTodo->hasDueSubTodo( !isOpen()); if (odue == 2) { colorToSet = KOPrefs::instance()->mTodoOverdueColor; setColor = true; } else if ( odue == 1 ) { colorToSet = KOPrefs::instance()->mTodoDueTodayColor; setColor = true; } if ( setColor ) { _cg.setColor(role,colorToSet ); if ( role == QColorGroup::Base) { int rgb = colorToSet.red(); rgb += colorToSet.blue()/2; rgb += colorToSet.green(); if ( rgb < 200 ) _cg.setColor(QColorGroup::Text,Qt::white ); } } //#endif if ( column > 0 ){ if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { p->save(); int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); p->fillRect( 0, 0, width, height(), _cg.base() ); // background // p->setPen(Qt::black ); //border // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling QColor fc = KOPrefs::instance()->mHighlightColor; if ( mTodo->percentComplete() == 100 ) fc = darkGreen; p->drawRect( 2, 2, width-4, height()-4); p->fillRect( 3, 3, progress, height()-6, fc ); p->restore(); } else { QCheckListItem::paintCell(p, _cg, column, width, alignment); } return; } int align = alignment; if ( !p ) return; p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); QListView *lv = listView(); if ( !lv ) return; int marg = 2;//lv->itemMargin(); int r = 0; QCheckListItem::Type myType = QCheckListItem::CheckBox; int BoxSize = 20; int boxOffset = 2; int xOffset = 2; if (qApp->desktop()->width() < 300 ) { BoxSize = 14; boxOffset = -1; xOffset = 1; // marg = 0; } if ( height() < BoxSize ) { boxOffset = boxOffset - ((BoxSize - height())/2) ; // qDebug("boxOffset %d height %d", boxOffset, height() ); BoxSize = height(); } //bool winStyle = lv->style() == WindowsStyle; int lineStart = 5; if ( myType == Controller ) { if ( !pixmap( 0 ) ) r += BoxSize + 4; } else { ASSERT( lv ); //### // QFontMetrics fm( lv->font() ); // int d = fm.height(); int x = 0; int y = (height() - BoxSize) / 2; // p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); if ( myType == CheckBox ) { if ( isEnabled() ) p->setPen( QPen( _cg.text(), 1 ) ); else p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); lineStart = x+marg; ///////////////////// x++; y++; if ( isOn() ) { QPointArray a( 7*2 ); int i, xx, yy; xx = x+xOffset+marg+(boxOffset/2); yy = y+5+boxOffset; for ( i=0; i<3; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); // qDebug(" "); xx++; yy++; } yy -= 2; for ( i=3; i<7; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy--; } p->setPen( darkGreen ); p->drawLineSegments( a ); } //////////////////////// } r += BoxSize + 4; } p->translate( r, 0 ); p->setPen( QPen( _cg.text() ) ); QListViewItem::paintCell( p, _cg, column, width - r, align ); if ( mTodo->cancelled () ) { p->setPen( black ); QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); int wid = br.width() +lineStart; if ( wid > width-3 ) wid = width-3; p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); } } diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index dbc159c..0684af2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp @@ -394,256 +394,265 @@ void Incidence::setExDates(const DateList &exDates) recurrence()->setRecurExDatesCount(mExDates.count()); updated(); } void Incidence::addExDate(const QDate &date) { if (mReadOnly) return; mExDates.append(date); recurrence()->setRecurExDatesCount(mExDates.count()); updated(); } DateList Incidence::exDates() const { return mExDates; } bool Incidence::isException(const QDate &date) const { DateList::ConstIterator it; for( it = mExDates.begin(); it != mExDates.end(); ++it ) { if ( (*it) == date ) { return true; } } return false; } void Incidence::addAttachment(Attachment *attachment) { if (mReadOnly || !attachment) return; mAttachments.append(attachment); updated(); } void Incidence::deleteAttachment(Attachment *attachment) { mAttachments.removeRef(attachment); } void Incidence::deleteAttachments(const QString& mime) { Attachment *at = mAttachments.first(); while (at) { if (at->mimeType() == mime) mAttachments.remove(); else at = mAttachments.next(); } } QPtrList<Attachment> Incidence::attachments() const { return mAttachments; } QPtrList<Attachment> Incidence::attachments(const QString& mime) const { QPtrList<Attachment> attachments; QPtrListIterator<Attachment> it( mAttachments ); Attachment *at; while ( (at = it.current()) ) { if (at->mimeType() == mime) attachments.append(at); ++it; } return attachments; } void Incidence::setResources(const QStringList &resources) { if (mReadOnly) return; mResources = resources; updated(); } QStringList Incidence::resources() const { return mResources; } void Incidence::setPriority(int priority) { if (mReadOnly) return; mPriority = priority; updated(); } int Incidence::priority() const { return mPriority; } void Incidence::setSecrecy(int sec) { if (mReadOnly) return; mSecrecy = sec; updated(); } int Incidence::secrecy() const { return mSecrecy; } QString Incidence::secrecyStr() const { return secrecyName(mSecrecy); } QString Incidence::secrecyName(int secrecy) { switch (secrecy) { case SecrecyPublic: return i18n("Public"); break; case SecrecyPrivate: return i18n("Private"); break; case SecrecyConfidential: return i18n("Confidential"); break; default: return i18n("Undefined"); break; } } QStringList Incidence::secrecyList() { QStringList list; list << secrecyName(SecrecyPublic); list << secrecyName(SecrecyPrivate); list << secrecyName(SecrecyConfidential); return list; } QPtrList<Alarm> Incidence::alarms() const { return mAlarms; } Alarm* Incidence::newAlarm() { Alarm* alarm = new Alarm(this); mAlarms.append(alarm); // updated(); return alarm; } void Incidence::addAlarm(Alarm *alarm) { mAlarms.append(alarm); updated(); } void Incidence::removeAlarm(Alarm *alarm) { mAlarms.removeRef(alarm); updated(); } void Incidence::clearAlarms() { mAlarms.clear(); updated(); } bool Incidence::isAlarmEnabled() const { Alarm* alarm; for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { if (alarm->enabled()) return true; } return false; } Recurrence *Incidence::recurrence() const { return mRecurrence; } void Incidence::setRecurrence( Recurrence * r) { delete mRecurrence; mRecurrence = r; } void Incidence::setLocation(const QString &location) { if (mReadOnly) return; mLocation = location; updated(); } QString Incidence::location() const { return mLocation; } ushort Incidence::doesRecur() const { if ( mRecurrence ) return mRecurrence->doesRecur(); else return Recurrence::rNone; } QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const { QDateTime incidenceStart = dt; *ok = false; if ( doesRecur() ) { bool last; recurrence()->getPreviousDateTime( incidenceStart , &last ); int count = 0; if ( !last ) { while ( !last ) { ++count; incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); if ( recursOn( incidenceStart.date() ) ) { last = true; // exit while llop } else { if ( last ) { // no alarm on last recurrence return QDateTime (); } int year = incidenceStart.date().year(); // workaround for bug in recurrence if ( count == 100 || year < 1000 || year > 5000 ) { return QDateTime (); } incidenceStart = incidenceStart.addSecs( 1 ); } } } else { return QDateTime (); } } else { if ( hasStartDate () ) { incidenceStart = dtStart(); } if ( type() =="Todo" ) { if ( ((Todo*)this)->hasDueDate() ) incidenceStart = ((Todo*)this)->dtDue(); } } if ( incidenceStart > dt ) *ok = true; return incidenceStart; } +QDateTime Incidence::dtStart() const +{ + if ( doesRecur() ) { + if ( type() == "Todo" ) { + ((Todo*)this)->checkSetCompletedFalse(); + } + } + return mDtStart; +} diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 38d2aaa..0ae9656 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h @@ -16,293 +16,294 @@ along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef INCIDENCE_H #define INCIDENCE_H // // Incidence - base class of calendaring components // #include <qdatetime.h> #include <qstringlist.h> #include <qvaluelist.h> #include "recurrence.h" #include "alarm.h" #include "attachment.h" #include "listbase.h" #include "incidencebase.h" namespace KCal { class Event; class Todo; class Journal; /** This class provides the base class common to all calendar components. */ class Incidence : public IncidenceBase { public: /** This class provides the interface for a visitor of calendar components. It serves as base class for concrete visitors, which implement certain actions on calendar components. It allows to add functions, which operate on the concrete types of calendar components, without changing the calendar component classes. */ class Visitor { public: /** Destruct Incidence::Visitor */ virtual ~Visitor() {} /** Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions on an Event object. */ virtual bool visit(Event *) { return false; } /** Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions on an Todo object. */ virtual bool visit(Todo *) { return false; } /** Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions on an Journal object. */ virtual bool visit(Journal *) { return false; } protected: /** Constructor is protected to prevent direct creation of visitor base class. */ Visitor() {} }; /** This class implements a visitor for adding an Incidence to a resource supporting addEvent(), addTodo() and addJournal() calls. */ template<class T> class AddVisitor : public Visitor { public: AddVisitor( T *r ) : mResource( r ) {} bool visit( Event *e ) { return mResource->addEvent( e ); } bool visit( Todo *t ) { return mResource->addTodo( t ); } bool visit( Journal *j ) { return mResource->addJournal( j ); } private: T *mResource; }; /** enumeration for describing an event's secrecy. */ enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; typedef ListBase<Incidence> List; Incidence(); Incidence(const Incidence &); ~Incidence(); /** Accept IncidenceVisitor. A class taking part in the visitor mechanism has to provide this implementation: <pre> bool accept(Visitor &v) { return v.visit(this); } </pre> */ virtual bool accept(Visitor &) { return false; } virtual Incidence *clone() = 0; virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; void setReadOnly( bool ); /** Recreate event. The event is made a new unique event, but already stored event information is preserved. Sets uniquie id, creation date, last modification date and revision number. */ void recreate(); Incidence* recreateCloneException(QDate); /** set creation date */ void setCreated(QDateTime); /** return time and date of creation. */ QDateTime created() const; /** set the number of revisions this event has seen */ void setRevision(int rev); /** return the number of revisions this event has seen */ int revision() const; /** Set starting date/time. */ virtual void setDtStart(const QDateTime &dtStart); /** Return the incidence's ending date/time as a QDateTime. */ virtual QDateTime dtEnd() const { return QDateTime(); } /** sets the event's lengthy description. */ void setDescription(const QString &description); /** returns a reference to the event's description. */ QString description() const; /** sets the event's short summary. */ void setSummary(const QString &summary); /** returns a reference to the event's summary. */ QString summary() const; /** set event's applicable categories */ void setCategories(const QStringList &categories); /** set event's categories based on a comma delimited string */ void setCategories(const QString &catStr); /** return categories in a list */ QStringList categories() const; /** return categories as a comma separated string */ QString categoriesStr(); /** point at some other event to which the event relates. This function should * only be used when constructing a calendar before the related Event * exists. */ void setRelatedToUid(const QString &); /** what event does this one relate to? This function should * only be used when constructing a calendar before the related Event * exists. */ QString relatedToUid() const; /** point at some other event to which the event relates */ void setRelatedTo(Incidence *relatedTo); /** what event does this one relate to? */ Incidence *relatedTo() const; /** All events that are related to this event */ QPtrList<Incidence> relations() const; /** Add an event which is related to this event */ void addRelation(Incidence *); /** Remove event that is related to this event */ void removeRelation(Incidence *); /** returns the list of dates which are exceptions to the recurrence rule */ DateList exDates() const; /** sets the list of dates which are exceptions to the recurrence rule */ void setExDates(const DateList &_exDates); void setExDates(const char *dates); /** Add a date to the list of exceptions of the recurrence rule. */ void addExDate(const QDate &date); /** returns true if there is an exception for this date in the recurrence rule set, or false otherwise. */ bool isException(const QDate &qd) const; /** add attachment to this event */ void addAttachment(Attachment *attachment); /** remove and delete a specific attachment */ void deleteAttachment(Attachment *attachment); /** remove and delete all attachments with this mime type */ void deleteAttachments(const QString& mime); /** return list of all associated attachments */ QPtrList<Attachment> attachments() const; /** find a list of attachments with this mime type */ QPtrList<Attachment> attachments(const QString& mime) const; /** sets the event's status the value specified. See the enumeration * above for possible values. */ void setSecrecy(int); /** return the event's secrecy. */ int secrecy() const; /** return the event's secrecy in string format. */ QString secrecyStr() const; /** return list of all availbale secrecy classes */ static QStringList secrecyList(); /** return human-readable name of secrecy class */ static QString secrecyName(int); /** returns TRUE if the date specified is one on which the event will * recur. */ bool recursOn(const QDate &qd) const; // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): /** set resources used, such as Office, Car, etc. */ void setResources(const QStringList &resources); /** return list of current resources */ QStringList resources() const; /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ void setPriority(int priority); /** get the event's priority */ int priority() const; /** All alarms that are associated with this incidence */ QPtrList<Alarm> alarms() const; /** Create a new alarm which is associated with this incidence */ Alarm* newAlarm(); /** Add an alarm which is associated with this incidence */ void addAlarm(Alarm*); /** Remove an alarm that is associated with this incidence */ void removeAlarm(Alarm*); /** Remove all alarms that are associated with this incidence */ void clearAlarms(); /** return whether any alarm associated with this incidence is enabled */ bool isAlarmEnabled() const; /** Return the recurrence rule associated with this incidence. If there is none, returns an appropriate (non-0) object. */ Recurrence *recurrence() const; void setRecurrence(Recurrence * r); /** Forward to Recurrence::doesRecur(). */ ushort doesRecur() const; /** set the event's/todo's location. Do _not_ use it with journal */ void setLocation(const QString &location); /** return the event's/todo's location. Do _not_ use it with journal */ QString location() const; /** returns TRUE or FALSE depending on whether the todo has a start date */ bool hasStartDate() const; /** sets the event's hasStartDate value. */ void setHasStartDate(bool f); QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; bool cancelled() const; void setCancelled( bool b ); bool hasRecurrenceID() const; void setHasRecurrenceID( bool b ); void setRecurrenceID(QDateTime); QDateTime recurrenceID () const; + QDateTime dtStart() const; protected: QPtrList<Alarm> mAlarms; QPtrList<Incidence> mRelations; + QDateTime mRecurrenceID; + bool mHasRecurrenceID; private: int mRevision; bool mCancelled; // base components of jounal, event and todo - QDateTime mRecurrenceID; - bool mHasRecurrenceID; QDateTime mCreated; QString mDescription; QString mSummary; QStringList mCategories; Incidence *mRelatedTo; QString mRelatedToUid; DateList mExDates; QPtrList<Attachment> mAttachments; QStringList mResources; bool mHasStartDate; // if todo has associated start date int mSecrecy; int mPriority; // 1 = highest, 2 = less, etc. //QPtrList<Alarm> mAlarms; Recurrence *mRecurrence; QString mLocation; }; bool operator==( const Incidence&, const Incidence& ); } #endif diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 7525a4a..51f2e9d 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp @@ -1,419 +1,420 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kglobal.h> #include <klocale.h> #include <kdebug.h> #include <kidmanager.h> #include "calformat.h" #include "syncdefines.h" #include "incidencebase.h" using namespace KCal; IncidenceBase::IncidenceBase() : mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), mPilotId(0), mSyncStatus(SYNCMOD) { setUid(CalFormat::createUniqueId()); mOrganizer = ""; mFloats = false; mDuration = 0; mHasDuration = false; mPilotId = 0; mExternalId = ":"; mTempSyncStat = SYNC_TEMPSTATE_INITIAL; mSyncStatus = 0; mAttendees.setAutoDelete( true ); } IncidenceBase::IncidenceBase(const IncidenceBase &i) : CustomProperties( i ) { mReadOnly = i.mReadOnly; mDtStart = i.mDtStart; mDuration = i.mDuration; mHasDuration = i.mHasDuration; mOrganizer = i.mOrganizer; mUid = i.mUid; QPtrList<Attendee> attendees = i.attendees(); for( Attendee *a = attendees.first(); a; a = attendees.next() ) { mAttendees.append( new Attendee( *a ) ); } mFloats = i.mFloats; mLastModified = i.mLastModified; mPilotId = i.mPilotId; mTempSyncStat = i.mTempSyncStat; mSyncStatus = i.mSyncStatus; mExternalId = i.mExternalId; // The copied object is a new one, so it isn't observed by the observer // of the original object. mObservers.clear(); mAttendees.setAutoDelete( true ); } IncidenceBase::~IncidenceBase() { } bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) { // do not compare mSyncStatus and mExternalId if( i1.attendees().count() != i2.attendees().count() ) { return false; // no need to check further } if ( i1.attendees().count() > 0 ) { Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; while ( a1 ) { if ( !( (*a1) == (*a2)) ) { //qDebug("Attendee not equal "); return false; } a1 = i1.attendees().next(); a2 = i2.attendees().next(); } } //if ( i1.dtStart() != i2.dtStart() ) // return false; #if 0 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); qDebug("1 %d ",i1.duration() == i2.duration() ); qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); qDebug("6 %d ",i1.organizer() == i2.organizer() ); #endif return ( i1.organizer() == i2.organizer() && // i1.uid() == i2.uid() && // Don't compare lastModified, otherwise the operator is not // of much use. We are not comparing for identity, after all. i1.doesFloat() == i2.doesFloat() && i1.duration() == i2.duration() && i1.hasDuration() == i2.hasDuration() && i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); // no need to compare mObserver } QDateTime IncidenceBase::getEvenTime( QDateTime dt ) { QTime t = dt.time(); dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); return dt; } void IncidenceBase::setUid(const QString &uid) { mUid = uid; updated(); } QString IncidenceBase::uid() const { return mUid; } void IncidenceBase::setLastModified(const QDateTime &lm) { // DON'T! updated() because we call this from // Calendar::updateEvent(). mLastModified = getEvenTime(lm); //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); } QDateTime IncidenceBase::lastModified() const { return mLastModified; } void IncidenceBase::setOrganizer(const QString &o) { // we don't check for readonly here, because it is // possible that by setting the organizer we are changing // the event's readonly status... mOrganizer = o; if (mOrganizer.left(7).upper() == "MAILTO:") mOrganizer = mOrganizer.remove(0,7); updated(); } QString IncidenceBase::organizer() const { return mOrganizer; } void IncidenceBase::setReadOnly( bool readOnly ) { mReadOnly = readOnly; } void IncidenceBase::setDtStart(const QDateTime &dtStart) { // if (mReadOnly) return; mDtStart = getEvenTime(dtStart); updated(); } + QDateTime IncidenceBase::dtStart() const { return mDtStart; } QString IncidenceBase::dtStartTimeStr() const { return KGlobal::locale()->formatTime(dtStart().time()); } QString IncidenceBase::dtStartDateStr(bool shortfmt) const { return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); } QString IncidenceBase::dtStartStr(bool shortfmt) const { return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); } bool IncidenceBase::doesFloat() const { return mFloats; } void IncidenceBase::setFloats(bool f) { if (mReadOnly) return; mFloats = f; updated(); } bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) { if (mReadOnly) return false; if (a->name().left(7).upper() == "MAILTO:") a->setName(a->name().remove(0,7)); QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (*qli.current() == *a) return false; ++qli; } mAttendees.append(a); if (doupdate) updated(); return true; } #if 0 void IncidenceBase::removeAttendee(Attendee *a) { if (mReadOnly) return; mAttendees.removeRef(a); updated(); } void IncidenceBase::removeAttendee(const char *n) { Attendee *a; if (mReadOnly) return; for (a = mAttendees.first(); a; a = mAttendees.next()) if (a->getName() == n) { mAttendees.remove(); break; } } #endif void IncidenceBase::clearAttendees() { if (mReadOnly) return; mAttendees.clear(); } #if 0 Attendee *IncidenceBase::getAttendee(const char *n) const { QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (qli.current()->getName() == n) return qli.current(); ++qli; } return 0L; } #endif Attendee *IncidenceBase::attendeeByMail(const QString &email) { QPtrListIterator<Attendee> qli(mAttendees); qli.toFirst(); while (qli) { if (qli.current()->email().lower() == email.lower()) return qli.current(); ++qli; } return 0L; } Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) { QPtrListIterator<Attendee> qli(mAttendees); QStringList mails = emails; if (!email.isEmpty()) { mails.append(email); } qli.toFirst(); while (qli) { for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { if (qli.current()->email().lower() == (*it).lower()) return qli.current(); } ++qli; } return 0L; } void IncidenceBase::setDuration(int seconds) { mDuration = seconds; setHasDuration(true); } int IncidenceBase::duration() const { return mDuration; } void IncidenceBase::setHasDuration(bool b) { mHasDuration = b; } bool IncidenceBase::hasDuration() const { return mHasDuration; } void IncidenceBase::setSyncStatus(int stat) { if (mReadOnly) return; mSyncStatus = stat; } int IncidenceBase::syncStatus() const { return mSyncStatus; } void IncidenceBase::setPilotId( int id ) { if (mReadOnly) return; mPilotId = id; } int IncidenceBase::pilotId() const { return mPilotId; } int IncidenceBase::tempSyncStat() const { return mTempSyncStat; } void IncidenceBase::setTempSyncStat( int id ) { if (mReadOnly) return; mTempSyncStat = id; } void IncidenceBase::removeID(const QString &prof) { if ( prof.isEmpty() ) mExternalId = ":"; else mExternalId = KIdManager::removeId ( mExternalId, prof); } void IncidenceBase::setID( const QString & prof , const QString & id ) { mExternalId = KIdManager::setId ( mExternalId, prof, id ); } QString IncidenceBase::getID( const QString & prof) { return KIdManager::getId ( mExternalId, prof ); } // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 void IncidenceBase::setCsum( const QString & prof , const QString & id ) { mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); } QString IncidenceBase::getCsum( const QString & prof) { return KIdManager::getCsum ( mExternalId, prof ); } void IncidenceBase::setIDStr( const QString & s ) { if (mReadOnly) return; mExternalId = s; } QString IncidenceBase::IDStr() const { return mExternalId ; } void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) { if( !mObservers.contains(observer) ) mObservers.append( observer ); } void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) { mObservers.remove( observer ); } void IncidenceBase::updated() { QPtrListIterator<Observer> it(mObservers); while( it.current() ) { Observer *o = it.current(); ++it; o->incidenceUpdated( this ); } } diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index f9a6558..8624786 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h @@ -1,172 +1,172 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef KCAL_INCIDENCEBASE_H #define KCAL_INCIDENCEBASE_H // // Incidence - base class of calendaring components // #include <qdatetime.h> #include <qstringlist.h> #include <qvaluelist.h> #include <qptrlist.h> #include "customproperties.h" #include "attendee.h" namespace KCal { typedef QValueList<QDate> DateList; /** This class provides the base class common to all calendar components. */ class IncidenceBase : public CustomProperties { public: class Observer { public: virtual void incidenceUpdated( IncidenceBase * ) = 0; }; IncidenceBase(); IncidenceBase(const IncidenceBase &); virtual ~IncidenceBase(); virtual QCString type() const = 0; /** Set the unique id for the event */ void setUid(const QString &); /** Return the unique id for the event */ QString uid() const; /** Sets the time the incidence was last modified. */ void setLastModified(const QDateTime &lm); /** Return the time the incidence was last modified. */ QDateTime lastModified() const; /** sets the organizer for the event */ void setOrganizer(const QString &o); QString organizer() const; /** Set readonly status. */ virtual void setReadOnly( bool ); /** Return if the object is read-only. */ bool isReadOnly() const { return mReadOnly; } /** for setting the event's starting date/time with a QDateTime. */ virtual void setDtStart(const QDateTime &dtStart); /** returns an event's starting date/time as a QDateTime. */ - QDateTime dtStart() const; + virtual QDateTime dtStart() const; /** returns an event's starting time as a string formatted according to the users locale settings */ QString dtStartTimeStr() const; /** returns an event's starting date as a string formatted according to the users locale settings */ QString dtStartDateStr(bool shortfmt=true) const; /** returns an event's starting date and time as a string formatted according to the users locale settings */ QString dtStartStr(bool shortfmt=true) const; virtual void setDuration(int seconds); int duration() const; void setHasDuration(bool); bool hasDuration() const; /** Return true or false depending on whether the incidence "floats," * i.e. has a date but no time attached to it. */ bool doesFloat() const; /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ void setFloats(bool f); /** Add Attendee to this incidence. IncidenceBase takes ownership of the Attendee object. */ bool addAttendee(Attendee *a, bool doupdate=true ); // void removeAttendee(Attendee *a); // void removeAttendee(const char *n); /** Remove all Attendees. */ void clearAttendees(); /** Return list of attendees. */ QPtrList<Attendee> attendees() const { return mAttendees; }; /** Return number of attendees. */ int attendeeCount() const { return mAttendees.count(); }; /** Return the Attendee with this email */ Attendee* attendeeByMail(const QString &); /** Return first Attendee with one of this emails */ Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); /** pilot syncronization states */ enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; /** Set synchronisation satus. */ void setSyncStatus(int stat); /** Return synchronisation status. */ int syncStatus() const; /** Set Pilot Id. */ void setPilotId(int id); /** Return Pilot Id. */ int pilotId() const; void setTempSyncStat(int id); int tempSyncStat() const; void setIDStr( const QString & ); QString IDStr() const; void setID( const QString &, const QString & ); QString getID( const QString & ); void setCsum( const QString &, const QString & ); QString getCsum( const QString & ); void removeID(const QString &); void registerObserver( Observer * ); void unRegisterObserver( Observer * ); void updated(); protected: + QDateTime mDtStart; bool mReadOnly; QDateTime getEvenTime( QDateTime ); private: // base components - QDateTime mDtStart; QString mOrganizer; QString mUid; QDateTime mLastModified; QPtrList<Attendee> mAttendees; bool mFloats; int mDuration; bool mHasDuration; QString mExternalId; int mTempSyncStat; // PILOT SYNCHRONIZATION STUFF int mPilotId; // unique id for pilot sync int mSyncStatus; // status (for sync) QPtrList<Observer> mObservers; }; bool operator==( const IncidenceBase&, const IncidenceBase& ); } #endif diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9c04a7e..1f54c2f 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -58,357 +58,400 @@ Incidence *Todo::clone() bool Todo::contains ( Todo* from ) { if ( !from->summary().isEmpty() ) if ( !summary().startsWith( from->summary() )) return false; if ( from->hasStartDate() ) { if ( !hasStartDate() ) return false; if ( from->dtStart() != dtStart()) return false; } if ( from->hasDueDate() ){ if ( !hasDueDate() ) return false; if ( from->dtDue() != dtDue()) return false; } if ( !from->location().isEmpty() ) if ( !location().startsWith( from->location() ) ) return false; if ( !from->description().isEmpty() ) if ( !description().startsWith( from->description() )) return false; if ( from->alarms().count() ) { Alarm *a = from->alarms().first(); if ( a->enabled() ){ if ( !alarms().count() ) return false; Alarm *b = alarms().first(); if( ! b->enabled() ) return false; if ( ! (a->offset() == b->offset() )) return false; } } QStringList cat = categories(); QStringList catFrom = from->categories(); QString nCat; unsigned int iii; for ( iii = 0; iii < catFrom.count();++iii ) { nCat = catFrom[iii]; if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { return false; } } if ( from->isCompleted() ) { if ( !isCompleted() ) return false; } if( priority() != from->priority() ) return false; return true; } bool KCal::operator==( const Todo& t1, const Todo& t2 ) { bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); if ( ! ret ) return false; if ( t1.hasDueDate() == t2.hasDueDate() ) { if ( t1.hasDueDate() ) { if ( t1.doesFloat() == t2.doesFloat() ) { if ( t1.doesFloat() ) { if ( t1.dtDue().date() != t2.dtDue().date() ) return false; } else if ( t1.dtDue() != t2.dtDue() ) return false; } else return false;// float != } } else return false; if ( t1.percentComplete() != t2.percentComplete() ) return false; if ( t1.isCompleted() ) { if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { if ( t1.hasCompletedDate() ) { if ( t1.completed() != t2.completed() ) return false; } } else return false; } return true; } void Todo::setDtDue(const QDateTime &dtDue) { //int diffsecs = mDtDue.secsTo(dtDue); /*if (mReadOnly) return; const QPtrList<Alarm>& alarms = alarms(); for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { if (alarm->enabled()) { alarm->setTime(alarm->time().addSecs(diffsecs)); } }*/ mDtDue = getEvenTime(dtDue); //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; /*const QPtrList<Alarm>& alarms = alarms(); for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) alarm->setAlarmStart(mDtDue);*/ updated(); } QDateTime Todo::dtDue() const { return mDtDue; } QString Todo::dtDueTimeStr() const { return KGlobal::locale()->formatTime(mDtDue.time()); } QString Todo::dtDueDateStr(bool shortfmt) const { return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); } QString Todo::dtDueStr(bool shortfmt) const { return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); } // retval 0 : no found // 1 : due for date found // 2 : overdue for date found int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) { int retval = 0; if ( isCompleted() ) return 0; if ( hasDueDate() ) { if ( dtDue().date() < date ) return 2; // we do not return, because we may find an overdue sub todo if ( dtDue().date() == date ) retval = 1; } if ( checkSubtodos ) { Incidence *aTodo; for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); if ( ret == 2 ) return 2; if ( ret == 1) retval = 1; } } return retval; } int Todo::hasDueSubTodo( bool checkSubtodos ) //= true { return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); } bool Todo::hasDueDate() const { return mHasDueDate; } void Todo::setHasDueDate(bool f) { if (mReadOnly) return; mHasDueDate = f; updated(); } #if 0 void Todo::setStatus(const QString &statStr) { if (mReadOnly) return; QString ss(statStr.upper()); if (ss == "X-ACTION") mStatus = NEEDS_ACTION; else if (ss == "NEEDS ACTION") mStatus = NEEDS_ACTION; else if (ss == "ACCEPTED") mStatus = ACCEPTED; else if (ss == "SENT") mStatus = SENT; else if (ss == "TENTATIVE") mStatus = TENTATIVE; else if (ss == "CONFIRMED") mStatus = CONFIRMED; else if (ss == "DECLINED") mStatus = DECLINED; else if (ss == "COMPLETED") mStatus = COMPLETED; else if (ss == "DELEGATED") mStatus = DELEGATED; updated(); } void Todo::setStatus(int status) { if (mReadOnly) return; mStatus = status; updated(); } int Todo::status() const { return mStatus; } QString Todo::statusStr() const { switch(mStatus) { case NEEDS_ACTION: return QString("NEEDS ACTION"); break; case ACCEPTED: return QString("ACCEPTED"); break; case SENT: return QString("SENT"); break; case TENTATIVE: return QString("TENTATIVE"); break; case CONFIRMED: return QString("CONFIRMED"); break; case DECLINED: return QString("DECLINED"); break; case COMPLETED: return QString("COMPLETED"); break; case DELEGATED: return QString("DELEGATED"); break; } return QString(""); } #endif bool Todo::isCompleted() const { - if (mPercentComplete == 100) return true; - else return false; + if (mPercentComplete == 100) { + return true; + } + else return false; } void Todo::setCompleted(bool completed) { + if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + completed = false; + } if (completed) mPercentComplete = 100; else { mPercentComplete = 0; mHasCompletedDate = false; } updated(); } QDateTime Todo::completed() const { return mCompleted; } QString Todo::completedStr( bool shortF ) const { return KGlobal::locale()->formatDateTime(mCompleted, shortF); } void Todo::setCompleted(const QDateTime &completed) { //qDebug("Todo::setCompleted "); if ( mHasCompletedDate ) { // qDebug("has completed data - return "); return; } mHasCompletedDate = true; mPercentComplete = 100; mCompleted = getEvenTime(completed); updated(); } bool Todo::hasCompletedDate() const { return mHasCompletedDate; } int Todo::percentComplete() const { return mPercentComplete; } - -void Todo::setPercentComplete(int v) +bool Todo::setRecurDates() { + if ( !mHasRecurrenceID ) + return true; + int secs = mDtStart.secsTo( dtDue() ); + bool ok; + qDebug("--------------------setRecurDates() "); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + QDateTime next = getNextOccurence( mRecurrenceID, &ok ); + if ( ok ) { + mRecurrenceID = next; + mDtStart = next; + setDtDue( next.addSecs( secs ) ); + if ( QDateTime::currentDateTime() > next) + return false; + } else { + setHasRecurrenceID( false ); + recurrence()->unsetRecurs(); + } + return true; +} +void Todo::setPercentComplete(int v) +{ + if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + v = 0; + } mPercentComplete = v; if ( v != 100 ) mHasCompletedDate = false; updated(); } QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const { if ( isCompleted() || ! hasDueDate() || cancelled() ) { *ok = false; return QDateTime (); } QDateTime incidenceStart; incidenceStart = dtDue(); bool enabled = false; Alarm* alarm; int off = 0; QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; // if ( QDateTime::currentDateTime() > incidenceStart ){ // *ok = false; // return incidenceStart; // } for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { if (alarm->enabled()) { if ( alarm->hasTime () ) { if ( alarm->time() < alarmStart ) { alarmStart = alarm->time(); enabled = true; off = alarmStart.secsTo( incidenceStart ); } } else { int secs = alarm->startOffset().asSeconds(); if ( incidenceStart.addSecs( secs ) < alarmStart ) { alarmStart = incidenceStart.addSecs( secs ); enabled = true; off = -secs; } } } } if ( enabled ) { if ( alarmStart > QDateTime::currentDateTime() ) { *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } +void Todo::checkSetCompletedFalse() +{ + if ( !hasRecurrenceID() ) { + qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); + } + // qDebug("Todo::checkSetCompletedFalse()"); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { + qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + setCompleted( false ); + qDebug("Todo::checkSetCompletedFalse++++++++++++++++++++++++++++ "); + } +} diff --git a/libkcal/todo.h b/libkcal/todo.h index 137b252..a22d4b7 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -1,134 +1,136 @@ /* This file is part of libkcal. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TODO_H #define TODO_H // // Todo component, representing a VTODO object // #include "incidence.h" namespace KCal { /** This class provides a Todo in the sense of RFC2445. */ class Todo : public Incidence { public: Todo(); Todo(const Todo &); ~Todo(); typedef ListBase<Todo> List; QCString type() const { return "Todo"; } /** Return an exact copy of this todo. */ Incidence *clone(); QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; /** for setting the todo's due date/time with a QDateTime. */ void setDtDue(const QDateTime &dtDue); /** returns an event's Due date/time as a QDateTime. */ QDateTime dtDue() const; /** returns an event's due time as a string formatted according to the users locale settings */ QString dtDueTimeStr() const; /** returns an event's due date as a string formatted according to the users locale settings */ QString dtDueDateStr(bool shortfmt=true) const; /** returns an event's due date and time as a string formatted according to the users locale settings */ QString dtDueStr(bool shortfmt=true) const; /** returns TRUE or FALSE depending on whether the todo has a due date */ bool hasDueDate() const; /** sets the event's hasDueDate value. */ void setHasDueDate(bool f); /* Looks for a subtodo (including itself ) which is not complete and is - overdue, or - due today. It returns 0 for nothing found, 1 for found a todo which is due today and no overdue found 2 for found a overdue todo */ int hasDueSubTodo( bool checkSubtodos = true ); /* same as above, but a specific date can be specified*/ int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); /** sets the event's status to the string specified. The string * must be a recognized value for the status field, i.e. a string * equivalent of the possible status enumerations previously described. */ // void setStatus(const QString &statStr); /** sets the event's status to the value specified. See the enumeration * above for possible values. */ // void setStatus(int); /** return the event's status. */ // int status() const; /** return the event's status in string format. */ // QString statusStr() const; /** return, if this todo is completed */ bool isCompleted() const; /** set completed state of this todo */ void setCompleted(bool); /** Return how many percent of the task are completed. Returns a value between 0 and 100. */ int percentComplete() const; /** Set how many percent of the task are completed. Valid values are in the range from 0 to 100. */ void setPercentComplete(int); /** return date and time when todo was completed */ QDateTime completed() const; QString completedStr(bool shortF = true) const; /** set date and time of completion */ void setCompleted(const QDateTime &completed); /** Return true, if todo has a date associated with completion */ bool hasCompletedDate() const; bool contains ( Todo*); + void checkSetCompletedFalse(); + bool setRecurDates(); private: bool accept(Visitor &v) { return v.visit(this); } QDateTime mDtDue; // due date of todo bool mHasDueDate; // if todo has associated due date // int mStatus; // confirmed/delegated/tentative/etc QDateTime mCompleted; bool mHasCompletedDate; int mPercentComplete; }; bool operator==( const Todo&, const Todo& ); } #endif |