summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/komonthview.cpp6
-rw-r--r--libkcal/calendarlocal.cpp1
-rw-r--r--libkcal/icalformat.cpp17
-rw-r--r--libkcal/icalformat.h3
-rw-r--r--libkcal/todo.cpp7
5 files changed, 24 insertions, 10 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index eea9a4d..4aeb20c 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1048,129 +1048,133 @@ void MonthViewCell::resizeEvent ( QResizeEvent * e )
1048 } else { 1048 } else {
1049 mLabel->resize( mLabelSize ); 1049 mLabel->resize( mLabelSize );
1050 text = QString::number( mDate.day() ); 1050 text = QString::number( mDate.day() );
1051 } 1051 }
1052 mLabel->setText( text ); 1052 mLabel->setText( text );
1053 1053
1054 int size = height() - mLabel->height() - lineWidth()-1; 1054 int size = height() - mLabel->height() - lineWidth()-1;
1055 //qDebug("LW %d ", lineWidth()); 1055 //qDebug("LW %d ", lineWidth());
1056 if ( size > 0 ) 1056 if ( size > 0 )
1057 verticalScrollBar()->setMaximumHeight( size ); 1057 verticalScrollBar()->setMaximumHeight( size );
1058 size = width() - mLabel->width() -lineWidth()-1; 1058 size = width() - mLabel->width() -lineWidth()-1;
1059 if ( size > 0 ) 1059 if ( size > 0 )
1060 horizontalScrollBar()->setMaximumWidth( size ); 1060 horizontalScrollBar()->setMaximumWidth( size );
1061 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); 1061 mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
1062 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 1062 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
1063 // mItemList->resize ( width(), height () ); 1063 // mItemList->resize ( width(), height () );
1064 if ( e ) 1064 if ( e )
1065 KNoScrollListBox::resizeEvent ( e ); 1065 KNoScrollListBox::resizeEvent ( e );
1066} 1066}
1067 1067
1068void MonthViewCell::defaultAction( QListBoxItem *item ) 1068void MonthViewCell::defaultAction( QListBoxItem *item )
1069{ 1069{
1070 1070
1071 if ( !item ) { 1071 if ( !item ) {
1072 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1072 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1073 emit newEventSignal( dt ); 1073 emit newEventSignal( dt );
1074 return; 1074 return;
1075 } 1075 }
1076 1076
1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1078 Incidence *incidence = eventItem->incidence(); 1078 Incidence *incidence = eventItem->incidence();
1079 if ( incidence ) mMonthView->defaultAction( incidence ); 1079 if ( incidence ) mMonthView->defaultAction( incidence );
1080} 1080}
1081void MonthViewCell::showDay() 1081void MonthViewCell::showDay()
1082{ 1082{
1083 emit showDaySignal( date() ); 1083 emit showDaySignal( date() );
1084} 1084}
1085void MonthViewCell::newEvent() 1085void MonthViewCell::newEvent()
1086{ 1086{
1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1088 emit newEventSignal( dt ); 1088 emit newEventSignal( dt );
1089} 1089}
1090void MonthViewCell::cellClicked( QListBoxItem *item ) 1090void MonthViewCell::cellClicked( QListBoxItem *item )
1091{ 1091{
1092 mMonthView->setSelectedCell( this ); 1092 mMonthView->setSelectedCell( this );
1093 if ( item == 0 ) { 1093 if ( item == 0 ) {
1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1095 emit newEventSignal( dt ); 1095 emit newEventSignal( dt );
1096 return; 1096 return;
1097 } 1097 }
1098 1098
1099} 1099}
1100 1100
1101void MonthViewCell::contextMenu( QListBoxItem *item ) 1101void MonthViewCell::contextMenu( QListBoxItem *item )
1102{ 1102{
1103 mMonthView->setPopupCell( this ); 1103 mMonthView->setPopupCell( this );
1104 if ( !item ) { 1104 if ( !item ) {
1105 mMonthView->showContextMenu( 0 ); 1105 mMonthView->showContextMenu( 0 );
1106 return; 1106 return;
1107 } 1107 }
1108 //selection( item ); 1108 //selection( item );
1109 //qApp->processEvents(); 1109 //qApp->processEvents();
1110 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1110 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1111 Incidence *incidence = eventItem->incidence(); 1111 Incidence *incidence = eventItem->incidence();
1112 if ( incidence ) mMonthView->showContextMenu( incidence ); 1112 if ( incidence ) {
1113 mMonthView->showContextMenu( incidence );
1114 selection( item );
1115 doHighLight( incidence );
1116 }
1113} 1117}
1114 1118
1115void MonthViewCell::selection( QListBoxItem *item ) 1119void MonthViewCell::selection( QListBoxItem *item )
1116{ 1120{
1117 if ( !item ) { 1121 if ( !item ) {
1118 emit highlightIncidence( 0 , this, 0 ); 1122 emit highlightIncidence( 0 , this, 0 );
1119 return; 1123 return;
1120 } 1124 }
1121 MonthViewItem * it = (static_cast<MonthViewItem *>( item )); 1125 MonthViewItem * it = (static_cast<MonthViewItem *>( item ));
1122 emit highlightIncidence( it->incidence(), this, it->multiDay() ); 1126 emit highlightIncidence( it->incidence(), this, it->multiDay() );
1123 mMonthView->setSelectedCell( this ); 1127 mMonthView->setSelectedCell( this );
1124} 1128}
1125 1129
1126void MonthViewCell::deHighLight() 1130void MonthViewCell::deHighLight()
1127{ 1131{
1128 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1132 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1129 while ( mitem ) { 1133 while ( mitem ) {
1130 if ( mitem->setHighlightedFalse() ) 1134 if ( mitem->setHighlightedFalse() )
1131 updateItem ( mitem ); 1135 updateItem ( mitem );
1132 mitem = (MonthViewItem *)mitem->next(); 1136 mitem = (MonthViewItem *)mitem->next();
1133 } 1137 }
1134} 1138}
1135// returns true if no inc found 1139// returns true if no inc found
1136bool MonthViewCell::doHighLight( Incidence * inc ) 1140bool MonthViewCell::doHighLight( Incidence * inc )
1137{ 1141{
1138 1142
1139 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1143 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1140 while ( mitem ) { 1144 while ( mitem ) {
1141 if ( mitem->incidence() == inc ) { 1145 if ( mitem->incidence() == inc ) {
1142 if ( mitem->setHighlighted( inc ) ) 1146 if ( mitem->setHighlighted( inc ) )
1143 updateItem ( mitem ); 1147 updateItem ( mitem );
1144 return false; 1148 return false;
1145 } 1149 }
1146 mitem = (MonthViewItem *)mitem->next(); 1150 mitem = (MonthViewItem *)mitem->next();
1147 } 1151 }
1148 return true; 1152 return true;
1149} 1153}
1150// ******************************************************************************* 1154// *******************************************************************************
1151// ******************************************************************************* 1155// *******************************************************************************
1152// ******************************************************************************* 1156// *******************************************************************************
1153 1157
1154 1158
1155KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 1159KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
1156 : KOEventView( calendar, parent, name ), 1160 : KOEventView( calendar, parent, name ),
1157 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1161 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1158 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1162 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1159{ 1163{
1160 mFlagKeyPressed = false; 1164 mFlagKeyPressed = false;
1161 mShortDayLabelsM = false; 1165 mShortDayLabelsM = false;
1162 mShortDayLabelsW = false; 1166 mShortDayLabelsW = false;
1163 skipResize = false; 1167 skipResize = false;
1164 clPending = true; 1168 clPending = true;
1165 mPopupCell = 0; 1169 mPopupCell = 0;
1166 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1170 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1167 mWidStack = new QWidgetStack( this ); 1171 mWidStack = new QWidgetStack( this );
1168 QVBoxLayout* hb = new QVBoxLayout( this ); 1172 QVBoxLayout* hb = new QVBoxLayout( this );
1169 mMonthView = new QWidget( mWidStack ); 1173 mMonthView = new QWidget( mWidStack );
1170 mWeekView = new QWidget( mWidStack ); 1174 mWeekView = new QWidget( mWidStack );
1171#if QT_VERSION >= 0x030000 1175#if QT_VERSION >= 0x030000
1172 mWidStack->addWidget(mMonthView ); 1176 mWidStack->addWidget(mMonthView );
1173 mWidStack->addWidget(mWeekView ); 1177 mWidStack->addWidget(mWeekView );
1174#else 1178#else
1175 mWidStack->addWidget( mMonthView, 1 ); 1179 mWidStack->addWidget( mMonthView, 1 );
1176 mWidStack->addWidget( mWeekView , 1 ); 1180 mWidStack->addWidget( mWeekView , 1 );
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e37a7ad..eef8327 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -4,128 +4,129 @@
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 );
68 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
69 close(); 70 close();
70} 71}
71bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
72{ 73{
73 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
77 return true; 78 return true;
78 } 79 }
79 return false; 80 return false;
80} 81}
81 82
82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 84{
84 Todo *todo;; 85 Todo *todo;;
85 Incidence *retVal = 0; 86 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
89 if ( retVal ) { 90 if ( retVal ) {
90 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
91 retVal = todo; 92 retVal = todo;
92 } 93 }
93 } else { 94 } else {
94 retVal = todo; 95 retVal = todo;
95 } 96 }
96 } 97 }
97 } 98 }
98 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
99 Event *event; 100 Event *event;
100 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
101 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
103 if ( retVal ) { 104 if ( retVal ) {
104 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
105 retVal = event; 106 retVal = event;
106 } 107 }
107 } else { 108 } else {
108 retVal = event; 109 retVal = event;
109 } 110 }
110 } 111 }
111 } 112 }
112 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
114 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
116 if ( retVal ) { 117 if ( retVal ) {
117 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
118 retVal = it; 119 retVal = it;
119 } 120 }
120 } else { 121 } else {
121 retVal = it; 122 retVal = it;
122 } 123 }
123 } 124 }
124 return retVal; 125 return retVal;
125} 126}
126 127
127bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
128{ 129{
129 // 1 look for raw inc in local 130 // 1 look for raw inc in local
130 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp
index 5877406..6f3a799 100644
--- a/libkcal/icalformat.cpp
+++ b/libkcal/icalformat.cpp
@@ -1,118 +1,119 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qregexp.h> 24#include <qregexp.h>
25#include <qclipboard.h> 25#include <qclipboard.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28#include <qtextcodec.h> 28#include <qtextcodec.h>
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35extern "C" { 35extern "C" {
36 #include <ical.h> 36 #include <ical.h>
37 #include <icalss.h> 37 #include <icalss.h>
38 #include <icalparser.h> 38 #include <icalparser.h>
39 #include <icalrestriction.h> 39 #include <icalrestriction.h>
40} 40}
41 41
42#include "calendar.h" 42#include "calendar.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44#include "journal.h" 44#include "journal.h"
45 45
46#include "icalformat.h" 46#include "icalformat.h"
47#include "icalformatimpl.h" 47#include "icalformatimpl.h"
48 48
49#define _ICAL_VERSION "2.0" 49#define _ICAL_VERSION "2.0"
50 50
51using namespace KCal; 51using namespace KCal;
52 52
53ICalFormat::ICalFormat( ) 53ICalFormat::ICalFormat( bool pe )
54{ 54{
55 mProcessEvents = pe;
55 mImpl = new ICalFormatImpl( this ); 56 mImpl = new ICalFormatImpl( this );
56 tzOffsetMin = 0; 57 tzOffsetMin = 0;
57 //qDebug("new ICalFormat() "); 58 //qDebug("new ICalFormat() ");
58} 59}
59 60
60ICalFormat::~ICalFormat() 61ICalFormat::~ICalFormat()
61{ 62{
62 delete mImpl; 63 delete mImpl;
63 //qDebug("delete ICalFormat "); 64 //qDebug("delete ICalFormat ");
64} 65}
65 66
66bool ICalFormat::load( Calendar *calendar, const QString &fileName) 67bool ICalFormat::load( Calendar *calendar, const QString &fileName)
67{ 68{
68 69
69 clearException(); 70 clearException();
70 71
71 QFile file( fileName ); 72 QFile file( fileName );
72 if (!file.open( IO_ReadOnly ) ) { 73 if (!file.open( IO_ReadOnly ) ) {
73 setException(new ErrorFormat(ErrorFormat::LoadError)); 74 setException(new ErrorFormat(ErrorFormat::LoadError));
74 return false; 75 return false;
75 } 76 }
76 QTextStream ts( &file ); 77 QTextStream ts( &file );
77 QString text; 78 QString text;
78 79
79 ts.setEncoding( QTextStream::Latin1 ); 80 ts.setEncoding( QTextStream::Latin1 );
80 text = ts.read(); 81 text = ts.read();
81 file.close(); 82 file.close();
82 83
83 return fromString( calendar, text ); 84 return fromString( calendar, text );
84} 85}
85 86
86//#include <qdatetime.h> 87//#include <qdatetime.h>
87bool ICalFormat::save( Calendar *calendar, const QString &fileName ) 88bool ICalFormat::save( Calendar *calendar, const QString &fileName )
88{ 89{
89 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; 90 //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl;
90 //qDebug("ICalFormat::save "); 91 //qDebug("ICalFormat::save ");
91 clearException(); 92 clearException();
92 QString text = toString( calendar ); 93 QString text = toString( calendar );
93 //return false; 94 //return false;
94 // qDebug("to string takes ms: %d ",is.elapsed() ); 95 // qDebug("to string takes ms: %d ",is.elapsed() );
95 if ( text.isNull() ) return false; 96 if ( text.isNull() ) return false;
96 97
97 // TODO: write backup file 98 // TODO: write backup file
98 //is.restart(); 99 //is.restart();
99 QFile file( fileName ); 100 QFile file( fileName );
100 if (!file.open( IO_WriteOnly ) ) { 101 if (!file.open( IO_WriteOnly ) ) {
101 setException(new ErrorFormat(ErrorFormat::SaveError, 102 setException(new ErrorFormat(ErrorFormat::SaveError,
102 i18n("Could not open file '%1'").arg(fileName))); 103 i18n("Could not open file '%1'").arg(fileName)));
103 return false; 104 return false;
104 } 105 }
105 QTextStream ts( &file ); 106 QTextStream ts( &file );
106 107
107 ts.setEncoding( QTextStream::Latin1 ); 108 ts.setEncoding( QTextStream::Latin1 );
108 ts << text; 109 ts << text;
109 file.close(); 110 file.close();
110 //qDebug("saving file takes ms: %d ", is.elapsed() ); 111 //qDebug("saving file takes ms: %d ", is.elapsed() );
111 return true; 112 return true;
112} 113}
113 114
114bool ICalFormat::fromString( Calendar *cal, const QString &text ) 115bool ICalFormat::fromString( Calendar *cal, const QString &text )
115{ 116{
116 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 117 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
117 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); 118 // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1());
118 // Get first VCALENDAR component. 119 // Get first VCALENDAR component.
@@ -128,153 +129,159 @@ bool ICalFormat::fromString( Calendar *cal, const QString &text )
128 } 129 }
129 130
130 bool success = true; 131 bool success = true;
131 132
132 if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { 133 if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) {
133 setException(new ErrorFormat(ErrorFormat::NoCalendar)); 134 setException(new ErrorFormat(ErrorFormat::NoCalendar));
134 success = false; 135 success = false;
135 } else { 136 } else {
136 // put all objects into their proper places 137 // put all objects into their proper places
137 if ( !mImpl->populate( cal, calendar ) ) { 138 if ( !mImpl->populate( cal, calendar ) ) {
138 if ( !exception() ) { 139 if ( !exception() ) {
139 setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); 140 setException(new ErrorFormat(ErrorFormat::ParseErrorKcal));
140 } 141 }
141 success = false; 142 success = false;
142 } else 143 } else
143 mLoadedProductId = mImpl->loadedProductId(); 144 mLoadedProductId = mImpl->loadedProductId();
144 } 145 }
145 146
146 icalcomponent_free( calendar ); 147 icalcomponent_free( calendar );
147 icalmemory_free_ring(); 148 icalmemory_free_ring();
148 149
149 return success; 150 return success;
150} 151}
151 152
152Incidence *ICalFormat::fromString( const QString &text ) 153Incidence *ICalFormat::fromString( const QString &text )
153{ 154{
154 CalendarLocal cal( mTimeZoneId ); 155 CalendarLocal cal( mTimeZoneId );
155 fromString(&cal, text); 156 fromString(&cal, text);
156 157
157 Incidence *ical = 0; 158 Incidence *ical = 0;
158 QPtrList<Event> elist = cal.events(); 159 QPtrList<Event> elist = cal.events();
159 if ( elist.count() > 0 ) { 160 if ( elist.count() > 0 ) {
160 ical = elist.first(); 161 ical = elist.first();
161 } else { 162 } else {
162 QPtrList<Todo> tlist = cal.todos(); 163 QPtrList<Todo> tlist = cal.todos();
163 if ( tlist.count() > 0 ) { 164 if ( tlist.count() > 0 ) {
164 ical = tlist.first(); 165 ical = tlist.first();
165 } else { 166 } else {
166 QPtrList<Journal> jlist = cal.journals(); 167 QPtrList<Journal> jlist = cal.journals();
167 if ( jlist.count() > 0 ) { 168 if ( jlist.count() > 0 ) {
168 ical = jlist.first(); 169 ical = jlist.first();
169 } 170 }
170 } 171 }
171 } 172 }
172 return ical; 173 return ical;
173} 174}
174#include <qapp.h> 175#include <qapp.h>
175 176
176QString ICalFormat::toString( Calendar *cal ) 177QString ICalFormat::toString( Calendar *cal )
177{ 178{
178 179
179 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); 180 setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
180 181
181 icalcomponent *calendar = mImpl->createCalendarComponent(cal); 182 icalcomponent *calendar = mImpl->createCalendarComponent(cal);
182 183
183 icalcomponent *component; 184 icalcomponent *component;
184 185
185 // todos 186 // todos
186 QPtrList<Todo> todoList = cal->rawTodos(); 187 QPtrList<Todo> todoList = cal->rawTodos();
187 QPtrListIterator<Todo> qlt(todoList); 188 QPtrListIterator<Todo> qlt(todoList);
188 for (; qlt.current(); ++qlt) { 189 for (; qlt.current(); ++qlt) {
189 component = mImpl->writeTodo(qlt.current()); 190 component = mImpl->writeTodo(qlt.current());
190 icalcomponent_add_component(calendar,component); 191 icalcomponent_add_component(calendar,component);
191 //qDebug(" todos "); 192 //qDebug(" todos ");
192 qApp->processEvents(); 193 if ( mProcessEvents ) {
194 //qDebug("mProcessEvents ");
195 qApp->processEvents();
196 }
193 } 197 }
194 // events 198 // events
195 QPtrList<Event> events = cal->rawEvents(); 199 QPtrList<Event> events = cal->rawEvents();
196 Event *ev; 200 Event *ev;
197 for(ev=events.first();ev;ev=events.next()) { 201 for(ev=events.first();ev;ev=events.next()) {
198 component = mImpl->writeEvent(ev); 202 component = mImpl->writeEvent(ev);
199 icalcomponent_add_component(calendar,component); 203 icalcomponent_add_component(calendar,component);
200 //qDebug("events "); 204 //qDebug("events ");
201 qApp->processEvents(); 205 if ( mProcessEvents )
206 qApp->processEvents();
202 } 207 }
203 208
204 // journals 209 // journals
205 QPtrList<Journal> journals = cal->journals(); 210 QPtrList<Journal> journals = cal->journals();
206 Journal *j; 211 Journal *j;
207 for(j=journals.first();j;j=journals.next()) { 212 for(j=journals.first();j;j=journals.next()) {
208 component = mImpl->writeJournal(j); 213 component = mImpl->writeJournal(j);
209 icalcomponent_add_component(calendar,component); 214 icalcomponent_add_component(calendar,component);
210 //qDebug("journals "); 215 //qDebug("journals ");
211 qApp->processEvents(); 216 if ( mProcessEvents )
217 qApp->processEvents();
212 } 218 }
213 const char *text; 219 const char *text;
214 QString ret =""; 220 QString ret ="";
215 text = icalcomponent_as_ical_string( calendar ); 221 text = icalcomponent_as_ical_string( calendar );
216 qApp->processEvents(); 222 if ( mProcessEvents )
223 qApp->processEvents();
217 224
218 // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; 225 // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n";
219 226
220 227
221 if ( text ) { 228 if ( text ) {
222 ret = QString ( text ); 229 ret = QString ( text );
223 } 230 }
224 icalcomponent_free( calendar ); 231 icalcomponent_free( calendar );
225 232
226 if (!text) { 233 if (!text) {
227 setException(new ErrorFormat(ErrorFormat::SaveError, 234 setException(new ErrorFormat(ErrorFormat::SaveError,
228 i18n("libical error"))); 235 i18n("libical error")));
229 icalmemory_free_ring(); 236 icalmemory_free_ring();
230 return QString::null; 237 return QString::null;
231 } 238 }
232 icalmemory_free_ring(); 239 icalmemory_free_ring();
233 return ret; 240 return ret;
234} 241}
235 242
236QString ICalFormat::toICalString( Incidence *incidence ) 243QString ICalFormat::toICalString( Incidence *incidence )
237{ 244{
238 CalendarLocal cal( mTimeZoneId ); 245 CalendarLocal cal( mTimeZoneId );
239 cal.addIncidence( incidence->clone() ); 246 cal.addIncidence( incidence->clone() );
240 return toString( &cal ); 247 return toString( &cal );
241} 248}
242 249
243QString ICalFormat::toString( Incidence *incidence ) 250QString ICalFormat::toString( Incidence *incidence )
244{ 251{
245 icalcomponent *component; 252 icalcomponent *component;
246 253
247 component = mImpl->writeIncidence( incidence ); 254 component = mImpl->writeIncidence( incidence );
248 255
249 const char *text = icalcomponent_as_ical_string( component ); 256 const char *text = icalcomponent_as_ical_string( component );
250 257
251 icalcomponent_free( component ); 258 icalcomponent_free( component );
252 259
253 return QString::fromLocal8Bit( text ); 260 return QString::fromLocal8Bit( text );
254} 261}
255 262
256QString ICalFormat::toString( Recurrence *recurrence ) 263QString ICalFormat::toString( Recurrence *recurrence )
257{ 264{
258 icalproperty *property; 265 icalproperty *property;
259 property = mImpl->writeRecurrenceRule( recurrence ); 266 property = mImpl->writeRecurrenceRule( recurrence );
260 const char *text = icalproperty_as_ical_string( property ); 267 const char *text = icalproperty_as_ical_string( property );
261 icalproperty_free( property ); 268 icalproperty_free( property );
262 return QString::fromLocal8Bit( text ); 269 return QString::fromLocal8Bit( text );
263} 270}
264/* 271/*
265bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) 272bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule )
266{ 273{
267 bool success = true; 274 bool success = true;
268 icalerror_clear_errno(); 275 icalerror_clear_errno();
269 struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); 276 struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule );
270 if ( icalerrno != ICAL_NO_ERROR ) { 277 if ( icalerrno != ICAL_NO_ERROR ) {
271 kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; 278 kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl;
272 success = false; 279 success = false;
273 } 280 }
274 281
275 if ( success ) { 282 if ( success ) {
276 mImpl->readRecurrence( recur, recurrence ); 283 mImpl->readRecurrence( recur, recurrence );
277 } 284 }
278 285
279 return success; 286 return success;
280} 287}
diff --git a/libkcal/icalformat.h b/libkcal/icalformat.h
index 485ab6e..a770dbb 100644
--- a/libkcal/icalformat.h
+++ b/libkcal/icalformat.h
@@ -1,115 +1,116 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef ICALFORMAT_H 20#ifndef ICALFORMAT_H
21#define ICALFORMAT_H 21#define ICALFORMAT_H
22 22
23#include <qstring.h> 23#include <qstring.h>
24 24
25#include "scheduler.h" 25#include "scheduler.h"
26 26
27#include "calformat.h" 27#include "calformat.h"
28 28
29namespace KCal { 29namespace KCal {
30 30
31class ICalFormatImpl; 31class ICalFormatImpl;
32 32
33/** 33/**
34 This class implements the iCalendar format. It provides methods for 34 This class implements the iCalendar format. It provides methods for
35 loading/saving/converting iCalendar format data into the internal KOrganizer 35 loading/saving/converting iCalendar format data into the internal KOrganizer
36 representation as Calendar and Events. 36 representation as Calendar and Events.
37 37
38 @short iCalendar format implementation 38 @short iCalendar format implementation
39*/ 39*/
40class ICalFormat : public CalFormat { 40class ICalFormat : public CalFormat {
41 public: 41 public:
42 /** Create new iCalendar format. */ 42 /** Create new iCalendar format. */
43 ICalFormat( ); 43 ICalFormat( bool pe = true);
44 virtual ~ICalFormat(); 44 virtual ~ICalFormat();
45 45
46 /** 46 /**
47 Loads a calendar on disk in iCalendar format into calendar. 47 Loads a calendar on disk in iCalendar format into calendar.
48 Returns true if successful, else returns false. Provides more error 48 Returns true if successful, else returns false. Provides more error
49 information by exception(). 49 information by exception().
50 @param calendar Calendar object to be filled. 50 @param calendar Calendar object to be filled.
51 @param fileName The name of the calendar file on disk. 51 @param fileName The name of the calendar file on disk.
52 */ 52 */
53 bool load( Calendar *, const QString &fileName ); 53 bool load( Calendar *, const QString &fileName );
54 /** 54 /**
55 Writes out the calendar to disk in iCalendar format. Returns true if 55 Writes out the calendar to disk in iCalendar format. Returns true if
56 successful and false on error. 56 successful and false on error.
57 57
58 @param calendar The Calendar object to be written. 58 @param calendar The Calendar object to be written.
59 @param fileName The name of the calendar file on disk. 59 @param fileName The name of the calendar file on disk.
60 */ 60 */
61 bool save( Calendar *, const QString &fileName ); 61 bool save( Calendar *, const QString &fileName );
62 62
63 /** 63 /**
64 Parse string and populate calendar with that information. 64 Parse string and populate calendar with that information.
65 */ 65 */
66 bool fromString( Calendar *, const QString & ); 66 bool fromString( Calendar *, const QString & );
67 /** 67 /**
68 Parse string and return first ical component. 68 Parse string and return first ical component.
69 */ 69 */
70 Incidence *fromString( const QString & ); 70 Incidence *fromString( const QString & );
71 /** 71 /**
72 Return calendar information as string. 72 Return calendar information as string.
73 */ 73 */
74 QString toString( Calendar * ); 74 QString toString( Calendar * );
75 /** 75 /**
76 Return incidence as full iCalendar formatted text. 76 Return incidence as full iCalendar formatted text.
77 */ 77 */
78 QString toICalString( Incidence * ); 78 QString toICalString( Incidence * );
79 /** 79 /**
80 Return incidence as iCalendar formatted text. 80 Return incidence as iCalendar formatted text.
81 */ 81 */
82 QString toString( Incidence * ); 82 QString toString( Incidence * );
83 /** 83 /**
84 Return recurrence as iCalendar formatted text. 84 Return recurrence as iCalendar formatted text.
85 */ 85 */
86 QString toString( Recurrence * ); 86 QString toString( Recurrence * );
87 /** 87 /**
88 Parse string and fill recurrence object with 88 Parse string and fill recurrence object with
89 that information 89 that information
90 */ 90 */
91 //bool fromString ( Recurrence *, const QString& ); 91 //bool fromString ( Recurrence *, const QString& );
92 92
93 /** Create a scheduling message for event \a e using method \m */ 93 /** Create a scheduling message for event \a e using method \m */
94 QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m); 94 QString createScheduleMessage(IncidenceBase *e,Scheduler::Method m);
95 /** Parse scheduling message provided as string \s */ 95 /** Parse scheduling message provided as string \s */
96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s); 96 ScheduleMessage *parseScheduleMessage( Calendar *, const QString &s);
97 97
98 /** Set id of used time zone and whether this time zone is UTC or not. */ 98 /** Set id of used time zone and whether this time zone is UTC or not. */
99 void setTimeZone( const QString &id, bool utc ); 99 void setTimeZone( const QString &id, bool utc );
100 QString timeZoneId() const; 100 QString timeZoneId() const;
101 int timeOffset(); 101 int timeOffset();
102 const char * tzString(); 102 const char * tzString();
103 bool utc() const; 103 bool utc() const;
104 104
105 private: 105 private:
106 bool mProcessEvents;
106 ICalFormatImpl *mImpl; 107 ICalFormatImpl *mImpl;
107 QString mTimeZoneId; 108 QString mTimeZoneId;
108 QCString mTzString; 109 QCString mTzString;
109 int tzOffsetMin; 110 int tzOffsetMin;
110 bool mUtc; 111 bool mUtc;
111}; 112};
112 113
113} 114}
114 115
115#endif 116#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 4ada2d8..7bf756a 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -5,230 +5,231 @@
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 if ( mRunSaveTimer )
70 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 71 saveRunningInfoToFile( s );
71} 72}
72void Todo::stopRunning() 73void Todo::stopRunning()
73{ 74{
74 if ( !mRunning ) 75 if ( !mRunning )
75 return; 76 return;
76 if ( mRunSaveTimer ) 77 if ( mRunSaveTimer )
77 mRunSaveTimer->stop(); 78 mRunSaveTimer->stop();
78 mRunning = false; 79 mRunning = false;
79} 80}
80void Todo::setRunning( bool run ) 81void Todo::setRunning( bool run )
81{ 82{
82 if ( run == mRunning ) 83 if ( run == mRunning )
83 return; 84 return;
84 //qDebug("Todo::setRunning %d ", run); 85 //qDebug("Todo::setRunning %d ", run);
85 if ( !mRunSaveTimer ) { 86 if ( !mRunSaveTimer ) {
86 mRunSaveTimer = new QTimer ( this ); 87 mRunSaveTimer = new QTimer ( this );
87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 88 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
88 } 89 }
89 mRunning = run; 90 mRunning = run;
90 if ( mRunning ) { 91 if ( mRunning ) {
91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 92 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
92 mRunStart = QDateTime::currentDateTime(); 93 mRunStart = QDateTime::currentDateTime();
93 } else { 94 } else {
94 mRunSaveTimer->stop(); 95 mRunSaveTimer->stop();
95 saveRunningInfoToFile(); 96 saveRunningInfoToFile();
96 } 97 }
97} 98}
98void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 99void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
99{ 100{
100 if ( !mRunning) return; 101 if ( !mRunning) return;
101 mRunning = false; 102 mRunning = false;
102 mRunStart = start; 103 mRunStart = start;
103 mRunEnd = end; 104 mRunEnd = end;
104 saveRunningInfoToFile( comment ); 105 saveRunningInfoToFile( comment );
105} 106}
106void Todo::saveRunningInfoToFile() 107void Todo::saveRunningInfoToFile()
107{ 108{
108 mRunEnd = QDateTime::currentDateTime(); 109 mRunEnd = QDateTime::currentDateTime();
109 saveRunningInfoToFile( QString::null ); 110 saveRunningInfoToFile( QString::null );
110} 111}
111void Todo::saveRunningInfoToFile( QString comment ) 112void Todo::saveRunningInfoToFile( QString comment )
112{ 113{
113 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 114 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
114 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 115 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
115 qDebug("Running time < 15 seconds. Skipped. "); 116 qDebug("Running time < 15 seconds. Skipped. ");
116 return; 117 return;
117 } 118 }
118 QString dir = KGlobalSettings::timeTrackerDir(); 119 QString dir = KGlobalSettings::timeTrackerDir();
119 //qDebug("%s ", dir.latin1()); 120 //qDebug("%s ", dir.latin1());
120 QString file = "%1%2%3-%4%5%6-"; 121 QString file = "%1%2%3-%4%5%6-";
121 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 122 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
122 file.replace ( QRegExp (" "), "0" ); 123 file.replace ( QRegExp (" "), "0" );
123 file += uid(); 124 file += uid();
124 //qDebug("File %s ",file.latin1() ); 125 //qDebug("File %s ",file.latin1() );
125 CalendarLocal cal; 126 CalendarLocal cal;
126 cal.setLocalTime(); 127 cal.setLocalTime();
127 Todo * to = (Todo*) clone(); 128 Todo * to = (Todo*) clone();
128 to->setFloats( false ); 129 to->setFloats( false );
129 to->setDtStart( mRunStart ); 130 to->setDtStart( mRunStart );
130 to->setHasStartDate( true ); 131 to->setHasStartDate( true );
131 to->setDtDue( mRunEnd ); 132 to->setDtDue( mRunEnd );
132 to->setHasDueDate( true ); 133 to->setHasDueDate( true );
133 to->setUid( file ); 134 to->setUid( file );
134 if ( !comment.isEmpty() ) { 135 if ( !comment.isEmpty() ) {
135 QString des = to->description(); 136 QString des = to->description();
136 if ( des.isEmpty () ) 137 if ( des.isEmpty () )
137 to->setDescription( "TT-Note: " + comment ); 138 to->setDescription( "TT-Note: " + comment );
138 else 139 else
139 to->setDescription( "TT-Note: " + comment +"\n" + des ); 140 to->setDescription( "TT-Note: " + comment +"\n" + des );
140 } 141 }
141 cal.addIncidence( to ); 142 cal.addIncidence( to );
142 ICalFormat format; 143 ICalFormat format( false );
143 file = dir +"/" +file +".ics"; 144 file = dir +"/" +file +".ics";
144 format.save( &cal, file ); 145 format.save( &cal, file );
145 saveParents(); 146 saveParents();
146 147
147} 148}
148void Todo::saveParents() 149void Todo::saveParents()
149{ 150{
150 if (!relatedTo() ) 151 if (!relatedTo() )
151 return; 152 return;
152 Incidence * inc = relatedTo(); 153 Incidence * inc = relatedTo();
153 if ( inc->typeID() != todoID ) 154 if ( inc->typeID() != todoID )
154 return; 155 return;
155 Todo* to = (Todo*)inc; 156 Todo* to = (Todo*)inc;
156 bool saveTodo = false; 157 bool saveTodo = false;
157 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 158 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
158 QFileInfo fi ( file ); 159 QFileInfo fi ( file );
159 if ( fi.exists() ) { 160 if ( fi.exists() ) {
160 if ( fi.lastModified () < to->lastModified ()) 161 if ( fi.lastModified () < to->lastModified ())
161 saveTodo = true; 162 saveTodo = true;
162 } else { 163 } else {
163 saveTodo = true; 164 saveTodo = true;
164 } 165 }
165 if ( saveTodo ) { 166 if ( saveTodo ) {
166 CalendarLocal cal; 167 CalendarLocal cal;
167 cal.setLocalTime(); 168 cal.setLocalTime();
168 Todo * par = (Todo *) to->clone(); 169 Todo * par = (Todo *) to->clone();
169 cal.addIncidence( par ); 170 cal.addIncidence( par );
170 ICalFormat format; 171 ICalFormat format( false );
171 format.save( &cal, file ); 172 format.save( &cal, file );
172 } 173 }
173 to->saveParents(); 174 to->saveParents();
174} 175}
175 176
176int Todo::runTime() 177int Todo::runTime()
177{ 178{
178 if ( !mRunning ) 179 if ( !mRunning )
179 return 0; 180 return 0;
180 return mRunStart.secsTo( QDateTime::currentDateTime() ); 181 return mRunStart.secsTo( QDateTime::currentDateTime() );
181} 182}
182bool Todo::hasRunningSub() 183bool Todo::hasRunningSub()
183{ 184{
184 if ( mRunning ) 185 if ( mRunning )
185 return true; 186 return true;
186 Incidence *aTodo; 187 Incidence *aTodo;
187 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 188 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
188 if ( ((Todo*)aTodo)->hasRunningSub() ) 189 if ( ((Todo*)aTodo)->hasRunningSub() )
189 return true; 190 return true;
190 } 191 }
191 return false; 192 return false;
192} 193}
193Incidence *Todo::clone() 194Incidence *Todo::clone()
194{ 195{
195 return new Todo(*this); 196 return new Todo(*this);
196} 197}
197 198
198bool Todo::contains ( Todo* from ) 199bool Todo::contains ( Todo* from )
199{ 200{
200 201
201 if ( !from->summary().isEmpty() ) 202 if ( !from->summary().isEmpty() )
202 if ( !summary().startsWith( from->summary() )) 203 if ( !summary().startsWith( from->summary() ))
203 return false; 204 return false;
204 if ( from->hasStartDate() ) { 205 if ( from->hasStartDate() ) {
205 if ( !hasStartDate() ) 206 if ( !hasStartDate() )
206 return false; 207 return false;
207 if ( from->dtStart() != dtStart()) 208 if ( from->dtStart() != dtStart())
208 return false; 209 return false;
209 } 210 }
210 if ( from->hasDueDate() ){ 211 if ( from->hasDueDate() ){
211 if ( !hasDueDate() ) 212 if ( !hasDueDate() )
212 return false; 213 return false;
213 if ( from->dtDue() != dtDue()) 214 if ( from->dtDue() != dtDue())
214 return false; 215 return false;
215 } 216 }
216 if ( !from->location().isEmpty() ) 217 if ( !from->location().isEmpty() )
217 if ( !location().startsWith( from->location() ) ) 218 if ( !location().startsWith( from->location() ) )
218 return false; 219 return false;
219 if ( !from->description().isEmpty() ) 220 if ( !from->description().isEmpty() )
220 if ( !description().startsWith( from->description() )) 221 if ( !description().startsWith( from->description() ))
221 return false; 222 return false;
222 if ( from->alarms().count() ) { 223 if ( from->alarms().count() ) {
223 Alarm *a = from->alarms().first(); 224 Alarm *a = from->alarms().first();
224 if ( a->enabled() ){ 225 if ( a->enabled() ){
225 if ( !alarms().count() ) 226 if ( !alarms().count() )
226 return false; 227 return false;
227 Alarm *b = alarms().first(); 228 Alarm *b = alarms().first();
228 if( ! b->enabled() ) 229 if( ! b->enabled() )
229 return false; 230 return false;
230 if ( ! (a->offset() == b->offset() )) 231 if ( ! (a->offset() == b->offset() ))
231 return false; 232 return false;
232 } 233 }
233 } 234 }
234 235