author | zautrix <zautrix> | 2005-09-25 01:04:17 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-09-25 01:04:17 (UTC) |
commit | bd991f0a33d85385735ed4911b794b8740e4d296 (patch) (unidiff) | |
tree | f69fdacca2283e2602619e24bcbc30b46998d298 /libkcal | |
parent | bada5cffd8f1b5f4f3719299e3615d7d06a1f0dc (diff) | |
download | kdepimpi-bd991f0a33d85385735ed4911b794b8740e4d296.zip kdepimpi-bd991f0a33d85385735ed4911b794b8740e4d296.tar.gz kdepimpi-bd991f0a33d85385735ed4911b794b8740e4d296.tar.bz2 |
todo timer fix
-rw-r--r-- | libkcal/todo.cpp | 31 | ||||
-rw-r--r-- | libkcal/todo.h | 4 |
2 files changed, 33 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 48d37d5..de07496 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -16,108 +16,135 @@ | |||
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 | ||
32 | #define SAVETIMER_TIMEOUT_SECONDS 300 | ||
33 | //#define SAVETIMER_TIMEOUT_SECONDS 8 | ||
34 | #define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 | ||
35 | |||
32 | using namespace KCal; | 36 | using namespace KCal; |
33 | 37 | ||
34 | Todo::Todo(): QObject(), Incidence() | 38 | Todo::Todo(): QObject(), Incidence() |
35 | { | 39 | { |
36 | // mStatus = TENTATIVE; | 40 | // mStatus = TENTATIVE; |
37 | 41 | ||
38 | mHasDueDate = false; | 42 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 43 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 44 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 45 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 46 | mPercentComplete = 0; |
43 | mRunning = false; | 47 | mRunning = false; |
44 | mRunSaveTimer = 0; | 48 | mRunSaveTimer = 0; |
45 | setFloats( true ); | 49 | setFloats( true ); |
50 | mCurrentTimerDelay = 0; | ||
46 | } | 51 | } |
47 | 52 | ||
48 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 53 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
49 | { | 54 | { |
50 | mDtDue = t.mDtDue; | 55 | mDtDue = t.mDtDue; |
51 | mHasDueDate = t.mHasDueDate; | 56 | mHasDueDate = t.mHasDueDate; |
52 | mCompleted = t.mCompleted; | 57 | mCompleted = t.mCompleted; |
53 | mHasCompletedDate = t.mHasCompletedDate; | 58 | mHasCompletedDate = t.mHasCompletedDate; |
54 | mPercentComplete = t.mPercentComplete; | 59 | mPercentComplete = t.mPercentComplete; |
55 | mRunning = false; | 60 | mRunning = false; |
56 | mRunSaveTimer = 0; | 61 | mRunSaveTimer = 0; |
62 | mCurrentTimerDelay = 0; | ||
57 | } | 63 | } |
58 | 64 | ||
59 | Todo::~Todo() | 65 | Todo::~Todo() |
60 | { | 66 | { |
61 | setRunning( false ); | 67 | setRunning( false ); |
62 | //qDebug("Todo::~Todo() "); | 68 | //qDebug("Todo::~Todo() "); |
63 | } | 69 | } |
64 | 70 | ||
65 | void Todo::setRunningFalse( QString s ) | 71 | void Todo::setRunningFalse( QString s ) |
66 | { | 72 | { |
67 | if ( ! mRunning ) | 73 | if ( ! mRunning ) |
68 | return; | 74 | return; |
69 | mRunning = false; | 75 | mRunning = false; |
70 | if ( mRunSaveTimer ) | 76 | if ( mRunSaveTimer ) |
71 | mRunSaveTimer->stop(); | 77 | mRunSaveTimer->stop(); |
72 | saveRunningInfoToFile( s ); | 78 | saveRunningInfoToFile( s ); |
73 | } | 79 | } |
74 | void Todo::stopRunning() | 80 | void Todo::stopRunning() |
75 | { | 81 | { |
76 | if ( !mRunning ) | 82 | if ( !mRunning ) |
77 | return; | 83 | return; |
78 | if ( mRunSaveTimer ) | 84 | if ( mRunSaveTimer ) |
79 | mRunSaveTimer->stop(); | 85 | mRunSaveTimer->stop(); |
80 | mRunning = false; | 86 | mRunning = false; |
81 | } | 87 | } |
82 | void Todo::setRunning( bool run ) | 88 | void Todo::setRunning( bool run ) |
83 | { | 89 | { |
84 | if ( run == mRunning ) | 90 | if ( run == mRunning ) |
85 | return; | 91 | return; |
86 | //qDebug("Todo::setRunning %d ", run); | 92 | //qDebug("Todo::setRunning %d ", run); |
87 | if ( !mRunSaveTimer ) { | 93 | if ( !mRunSaveTimer ) { |
88 | mRunSaveTimer = new QTimer ( this ); | 94 | mRunSaveTimer = new QTimer ( this ); |
89 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 95 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); |
90 | } | 96 | } |
91 | mRunning = run; | 97 | mRunning = run; |
98 | mRunLastSave = QDateTime::currentDateTime(); | ||
92 | if ( mRunning ) { | 99 | if ( mRunning ) { |
93 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 100 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min |
94 | mRunStart = QDateTime::currentDateTime(); | 101 | mRunStart = QDateTime::currentDateTime(); |
102 | mRunLastSave = QDateTime::currentDateTime(); | ||
103 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; | ||
95 | } else { | 104 | } else { |
96 | mRunSaveTimer->stop(); | 105 | mRunSaveTimer->stop(); |
97 | saveRunningInfoToFile(); | 106 | saveRunningInfoToFile(); |
98 | } | 107 | } |
99 | } | 108 | } |
100 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 109 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
101 | { | 110 | { |
102 | if ( !mRunning) return; | 111 | if ( !mRunning) return; |
103 | mRunning = false; | 112 | mRunning = false; |
104 | mRunStart = start; | 113 | mRunStart = start; |
105 | mRunEnd = end; | 114 | mRunEnd = end; |
106 | saveRunningInfoToFile( comment ); | 115 | saveRunningInfoToFile( comment ); |
107 | } | 116 | } |
117 | void Todo::timerSlotSaveRunningInfoToFile() | ||
118 | { | ||
119 | mRunEnd = QDateTime::currentDateTime(); | ||
120 | int secsTo = mRunLastSave.secsTo( mRunEnd ); | ||
121 | if( secsTo == 8 ) ++secsTo; | ||
122 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); | ||
123 | if ( secsTo > mCurrentTimerDelay ) { | ||
124 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); | ||
125 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_RETRY_SECONDS * 1000 ); | ||
126 | mRunLastSave = QDateTime::currentDateTime(); | ||
127 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_RETRY_SECONDS; | ||
128 | return; | ||
129 | } | ||
130 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min | ||
131 | mRunLastSave = QDateTime::currentDateTime(); | ||
132 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; | ||
133 | saveRunningInfoToFile( QString::null ); | ||
134 | } | ||
108 | void Todo::saveRunningInfoToFile() | 135 | void Todo::saveRunningInfoToFile() |
109 | { | 136 | { |
110 | mRunEnd = QDateTime::currentDateTime(); | 137 | mRunEnd = QDateTime::currentDateTime(); |
111 | saveRunningInfoToFile( QString::null ); | 138 | saveRunningInfoToFile( QString::null ); |
112 | } | 139 | } |
113 | void Todo::saveRunningInfoToFile( QString comment ) | 140 | void Todo::saveRunningInfoToFile( QString comment ) |
114 | { | 141 | { |
115 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 142 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
116 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 143 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
117 | qDebug("Running time < 15 seconds. Skipped. "); | 144 | qDebug("Running time < 15 seconds. Skipped. "); |
118 | return; | 145 | return; |
119 | } | 146 | } |
120 | QString dir = KGlobalSettings::timeTrackerDir(); | 147 | QString dir = KGlobalSettings::timeTrackerDir(); |
121 | //qDebug("%s ", dir.latin1()); | 148 | //qDebug("%s ", dir.latin1()); |
122 | QString file = "%1%2%3-%4%5%6-"; | 149 | QString file = "%1%2%3-%4%5%6-"; |
123 | 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 ); | 150 | 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 ); |
diff --git a/libkcal/todo.h b/libkcal/todo.h index 7feb32e..e6b8a21 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -118,36 +118,40 @@ namespace KCal { | |||
118 | bool contains ( Todo*); | 118 | bool contains ( Todo*); |
119 | void checkSetCompletedFalse(); | 119 | void checkSetCompletedFalse(); |
120 | bool setRecurDates(); | 120 | bool setRecurDates(); |
121 | bool isRunning() {return mRunning;} | 121 | bool isRunning() {return mRunning;} |
122 | bool hasRunningSub(); | 122 | bool hasRunningSub(); |
123 | void setRunning( bool ); | 123 | void setRunning( bool ); |
124 | void setRunningFalse( QString ); | 124 | void setRunningFalse( QString ); |
125 | void stopRunning(); | 125 | void stopRunning(); |
126 | int runTime(); | 126 | int runTime(); |
127 | QDateTime runStart () const { return mRunStart;} | 127 | QDateTime runStart () const { return mRunStart;} |
128 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); | 128 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); |
129 | public slots: | 129 | public slots: |
130 | void saveRunningInfoToFile( QString st ); | 130 | void saveRunningInfoToFile( QString st ); |
131 | void saveRunningInfoToFile( ); | 131 | void saveRunningInfoToFile( ); |
132 | void saveParents(); | 132 | void saveParents(); |
133 | QString durationText(); | 133 | QString durationText(); |
134 | private slots: | ||
135 | void timerSlotSaveRunningInfoToFile( ); | ||
134 | private: | 136 | private: |
137 | int mCurrentTimerDelay; | ||
135 | bool mRunning; | 138 | bool mRunning; |
136 | QTimer * mRunSaveTimer; | 139 | QTimer * mRunSaveTimer; |
137 | QDateTime mRunStart; | 140 | QDateTime mRunStart; |
141 | QDateTime mRunLastSave; | ||
138 | QDateTime mRunEnd; | 142 | QDateTime mRunEnd; |
139 | bool accept(Visitor &v) { return v.visit(this); } | 143 | bool accept(Visitor &v) { return v.visit(this); } |
140 | 144 | ||
141 | QDateTime mDtDue; // due date of todo | 145 | QDateTime mDtDue; // due date of todo |
142 | 146 | ||
143 | bool mHasDueDate; // if todo has associated due date | 147 | bool mHasDueDate; // if todo has associated due date |
144 | 148 | ||
145 | // int mStatus; // confirmed/delegated/tentative/etc | 149 | // int mStatus; // confirmed/delegated/tentative/etc |
146 | 150 | ||
147 | QDateTime mCompleted; | 151 | QDateTime mCompleted; |
148 | bool mHasCompletedDate; | 152 | bool mHasCompletedDate; |
149 | 153 | ||
150 | int mPercentComplete; | 154 | int mPercentComplete; |
151 | }; | 155 | }; |
152 | 156 | ||
153 | bool operator==( const Todo&, const Todo& ); | 157 | bool operator==( const Todo&, const Todo& ); |