summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp4
-rw-r--r--libkcal/todo.cpp1
2 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 00a43e5..e75df70 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -37,96 +37,100 @@
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 close(); 68 close();
69} 69}
70 70
71bool CalendarLocal::load( const QString &fileName ) 71bool CalendarLocal::load( const QString &fileName )
72{ 72{
73 FileStorage storage( this, fileName ); 73 FileStorage storage( this, fileName );
74 return storage.load(); 74 return storage.load();
75} 75}
76 76
77bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 77bool CalendarLocal::save( const QString &fileName, CalFormat *format )
78{ 78{
79 FileStorage storage( this, fileName, format ); 79 FileStorage storage( this, fileName, format );
80 return storage.save(); 80 return storage.save();
81} 81}
82 82
83void CalendarLocal::close() 83void CalendarLocal::close()
84{ 84{
85
86 Todo * i;
87 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
88
85 mEventList.setAutoDelete( true ); 89 mEventList.setAutoDelete( true );
86 mTodoList.setAutoDelete( true ); 90 mTodoList.setAutoDelete( true );
87 mJournalList.setAutoDelete( false ); 91 mJournalList.setAutoDelete( false );
88 92
89 mEventList.clear(); 93 mEventList.clear();
90 mTodoList.clear(); 94 mTodoList.clear();
91 mJournalList.clear(); 95 mJournalList.clear();
92 96
93 mEventList.setAutoDelete( false ); 97 mEventList.setAutoDelete( false );
94 mTodoList.setAutoDelete( false ); 98 mTodoList.setAutoDelete( false );
95 mJournalList.setAutoDelete( false ); 99 mJournalList.setAutoDelete( false );
96 100
97 setModified( false ); 101 setModified( false );
98} 102}
99 103
100bool CalendarLocal::addAnniversaryNoDup( Event *event ) 104bool CalendarLocal::addAnniversaryNoDup( Event *event )
101{ 105{
102 QString cat; 106 QString cat;
103 bool isBirthday = true; 107 bool isBirthday = true;
104 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 108 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
105 isBirthday = false; 109 isBirthday = false;
106 cat = i18n( "Anniversary" ); 110 cat = i18n( "Anniversary" );
107 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 111 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
108 isBirthday = true; 112 isBirthday = true;
109 cat = i18n( "Birthday" ); 113 cat = i18n( "Birthday" );
110 } else { 114 } else {
111 qDebug("addAnniversaryNoDup called without fitting category! "); 115 qDebug("addAnniversaryNoDup called without fitting category! ");
112 return false; 116 return false;
113 } 117 }
114 Event * eve; 118 Event * eve;
115 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 119 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
116 if ( !(eve->categories().contains( cat ) )) 120 if ( !(eve->categories().contains( cat ) ))
117 continue; 121 continue;
118 // now we have an event with fitting category 122 // now we have an event with fitting category
119 if ( eve->dtStart().date() != event->dtStart().date() ) 123 if ( eve->dtStart().date() != event->dtStart().date() )
120 continue; 124 continue;
121 // now we have an event with fitting category+date 125 // now we have an event with fitting category+date
122 if ( eve->summary() != event->summary() ) 126 if ( eve->summary() != event->summary() )
123 continue; 127 continue;
124 // now we have an event with fitting category+date+summary 128 // now we have an event with fitting category+date+summary
125 return false; 129 return false;
126 } 130 }
127 return addEvent( event ); 131 return addEvent( event );
128 132
129} 133}
130bool CalendarLocal::addEventNoDup( Event *event ) 134bool CalendarLocal::addEventNoDup( Event *event )
131{ 135{
132 Event * eve; 136 Event * eve;
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index b89abce..5e6ac22 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -20,96 +20,97 @@
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::setRunning( bool run ) 64void Todo::setRunning( bool run )
65{ 65{
66 if ( run == mRunning ) 66 if ( run == mRunning )
67 return; 67 return;
68 //qDebug("Todo::setRunning %d ", run);
68 if ( !mRunSaveTimer ) { 69 if ( !mRunSaveTimer ) {
69 mRunSaveTimer = new QTimer ( this ); 70 mRunSaveTimer = new QTimer ( this );
70 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 71 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
71 } 72 }
72 mRunning = run; 73 mRunning = run;
73 if ( mRunning ) { 74 if ( mRunning ) {
74 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 75 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
75 mRunStart = QDateTime::currentDateTime(); 76 mRunStart = QDateTime::currentDateTime();
76 } else { 77 } else {
77 mRunSaveTimer->stop(); 78 mRunSaveTimer->stop();
78 saveRunningInfoToFile(); 79 saveRunningInfoToFile();
79 } 80 }
80} 81}
81 82
82void Todo::saveRunningInfoToFile() 83void Todo::saveRunningInfoToFile()
83{ 84{
84 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 85 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
85 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { 86 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
86 qDebug("Running time < 30 seconds. Skipped. "); 87 qDebug("Running time < 30 seconds. Skipped. ");
87 return; 88 return;
88 } 89 }
89 QString dir = KGlobalSettings::timeTrackerDir(); 90 QString dir = KGlobalSettings::timeTrackerDir();
90 //qDebug("%s ", dir.latin1()); 91 //qDebug("%s ", dir.latin1());
91 QString file = "%1%2%3-%4%5%6-"; 92 QString file = "%1%2%3-%4%5%6-";
92 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 ); 93 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 );
93 file.replace ( QRegExp (" "), "0" ); 94 file.replace ( QRegExp (" "), "0" );
94 file += uid(); 95 file += uid();
95 //qDebug("File %s ",file.latin1() ); 96 //qDebug("File %s ",file.latin1() );
96 CalendarLocal cal; 97 CalendarLocal cal;
97 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); 98 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
98 Todo * to = (Todo*) clone(); 99 Todo * to = (Todo*) clone();
99 to->setFloats( false ); 100 to->setFloats( false );
100 to->setDtStart( mRunStart ); 101 to->setDtStart( mRunStart );
101 to->setHasStartDate( true ); 102 to->setHasStartDate( true );
102 to->setDtDue( QDateTime::currentDateTime() ); 103 to->setDtDue( QDateTime::currentDateTime() );
103 to->setHasDueDate( true ); 104 to->setHasDueDate( true );
104 to->setUid( file ); 105 to->setUid( file );
105 cal.addIncidence( to ); 106 cal.addIncidence( to );
106 ICalFormat format; 107 ICalFormat format;
107 file = dir +"/" +file +".ics"; 108 file = dir +"/" +file +".ics";
108 format.save( &cal, file ); 109 format.save( &cal, file );
109 saveParents(); 110 saveParents();
110 111
111} 112}
112void Todo::saveParents() 113void Todo::saveParents()
113{ 114{
114 if (!relatedTo() ) 115 if (!relatedTo() )
115 return; 116 return;