-rw-r--r-- | libkcal/todo.cpp | 36 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
2 files changed, 34 insertions, 3 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 90e7eb9..b89abce 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -20,33 +20,34 @@ | |||
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 | 27 | ||
27 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
28 | #include "icalformat.h" | 29 | #include "icalformat.h" |
29 | #include "todo.h" | 30 | #include "todo.h" |
30 | 31 | ||
31 | using namespace KCal; | 32 | using namespace KCal; |
32 | 33 | ||
33 | Todo::Todo(): Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
34 | { | 35 | { |
35 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
36 | 37 | ||
37 | mHasDueDate = false; | 38 | mHasDueDate = false; |
38 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
39 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
40 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
41 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
42 | mRunning = false; | 43 | mRunning = false; |
43 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
44 | } | 45 | } |
45 | 46 | ||
46 | Todo::Todo(const Todo &t) : Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
47 | { | 48 | { |
48 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
49 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
50 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
51 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
52 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
@@ -78,14 +79,16 @@ void Todo::setRunning( bool run ) | |||
78 | } | 79 | } |
79 | } | 80 | } |
80 | 81 | ||
81 | void Todo::saveRunningInfoToFile() | 82 | void Todo::saveRunningInfoToFile() |
82 | { | 83 | { |
83 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 84 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
84 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) | 85 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
86 | qDebug("Running time < 30 seconds. Skipped. "); | ||
85 | return; | 87 | return; |
88 | } | ||
86 | QString dir = KGlobalSettings::timeTrackerDir(); | 89 | QString dir = KGlobalSettings::timeTrackerDir(); |
87 | //qDebug("%s ", dir.latin1()); | 90 | //qDebug("%s ", dir.latin1()); |
88 | QString file = "%1%2%3-%4%5%6-"; | 91 | QString file = "%1%2%3-%4%5%6-"; |
89 | 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 ); | 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 ); |
90 | file.replace ( QRegExp (" "), "0" ); | 93 | file.replace ( QRegExp (" "), "0" ); |
91 | file += uid(); | 94 | file += uid(); |
@@ -100,14 +103,41 @@ void Todo::saveRunningInfoToFile() | |||
100 | to->setHasDueDate( true ); | 103 | to->setHasDueDate( true ); |
101 | to->setUid( file ); | 104 | to->setUid( file ); |
102 | cal.addIncidence( to ); | 105 | cal.addIncidence( to ); |
103 | ICalFormat format; | 106 | ICalFormat format; |
104 | file = dir +"/" +file +".ics"; | 107 | file = dir +"/" +file +".ics"; |
105 | format.save( &cal, file ); | 108 | format.save( &cal, file ); |
109 | saveParents(); | ||
106 | 110 | ||
107 | } | 111 | } |
112 | void Todo::saveParents() | ||
113 | { | ||
114 | if (!relatedTo() ) | ||
115 | return; | ||
116 | Incidence * inc = relatedTo(); | ||
117 | if ( inc->type() != "Todo" ) | ||
118 | return; | ||
119 | Todo* to = (Todo*)inc; | ||
120 | bool saveTodo = false; | ||
121 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | ||
122 | QFileInfo fi ( file ); | ||
123 | if ( fi.exists() ) { | ||
124 | if ( fi.lastModified () < to->lastModified ()) | ||
125 | saveTodo = true; | ||
126 | } else { | ||
127 | saveTodo = true; | ||
128 | } | ||
129 | if ( saveTodo ) { | ||
130 | CalendarLocal cal; | ||
131 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | ||
132 | Todo * par = (Todo *) to->clone(); | ||
133 | cal.addIncidence( par ); | ||
134 | ICalFormat format; | ||
135 | format.save( &cal, file ); | ||
136 | } | ||
137 | } | ||
108 | 138 | ||
109 | int Todo::runTime() | 139 | int Todo::runTime() |
110 | { | 140 | { |
111 | if ( !mRunning ) | 141 | if ( !mRunning ) |
112 | return 0; | 142 | return 0; |
113 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 143 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
diff --git a/libkcal/todo.h b/libkcal/todo.h index fe43357..ec1ffda 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -121,12 +121,13 @@ namespace KCal { | |||
121 | bool hasRunningSub(); | 121 | bool hasRunningSub(); |
122 | void setRunning( bool ); | 122 | void setRunning( bool ); |
123 | int runTime(); | 123 | int runTime(); |
124 | QDateTime runStart () const { return mRunStart;} | 124 | QDateTime runStart () const { return mRunStart;} |
125 | public slots: | 125 | public slots: |
126 | void saveRunningInfoToFile(); | 126 | void saveRunningInfoToFile(); |
127 | void saveParents(); | ||
127 | private: | 128 | private: |
128 | bool mRunning; | 129 | bool mRunning; |
129 | QTimer * mRunSaveTimer; | 130 | QTimer * mRunSaveTimer; |
130 | QDateTime mRunStart; | 131 | QDateTime mRunStart; |
131 | bool accept(Visitor &v) { return v.visit(this); } | 132 | bool accept(Visitor &v) { return v.visit(this); } |
132 | 133 | ||