summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-09-25 01:27:36 (UTC)
committer zautrix <zautrix>2005-09-25 01:27:36 (UTC)
commit181bc87d92ecc48cb07c288cb2d135d8fde56716 (patch) (unidiff)
tree97d972b99fc1a147cdbb0b9a295527e6d6fe119c
parentbd991f0a33d85385735ed4911b794b8740e4d296 (diff)
downloadkdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.zip
kdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.tar.gz
kdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.tar.bz2
todo timer fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp34
-rw-r--r--libkcal/todo.h1
2 files changed, 24 insertions, 11 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index de07496..f7d40ad 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -52,129 +52,141 @@ Todo::Todo(): QObject(), Incidence()
52 52
53Todo::Todo(const Todo &t) : QObject(),Incidence(t) 53Todo::Todo(const Todo &t) : QObject(),Incidence(t)
54{ 54{
55 mDtDue = t.mDtDue; 55 mDtDue = t.mDtDue;
56 mHasDueDate = t.mHasDueDate; 56 mHasDueDate = t.mHasDueDate;
57 mCompleted = t.mCompleted; 57 mCompleted = t.mCompleted;
58 mHasCompletedDate = t.mHasCompletedDate; 58 mHasCompletedDate = t.mHasCompletedDate;
59 mPercentComplete = t.mPercentComplete; 59 mPercentComplete = t.mPercentComplete;
60 mRunning = false; 60 mRunning = false;
61 mRunSaveTimer = 0; 61 mRunSaveTimer = 0;
62 mCurrentTimerDelay = 0; 62 mCurrentTimerDelay = 0;
63} 63}
64 64
65Todo::~Todo() 65Todo::~Todo()
66{ 66{
67 setRunning( false ); 67 setRunning( false );
68 //qDebug("Todo::~Todo() "); 68 //qDebug("Todo::~Todo() ");
69} 69}
70 70
71void Todo::setRunningFalse( QString s ) 71void Todo::setRunningFalse( QString s )
72{ 72{
73 if ( ! mRunning ) 73 if ( ! mRunning )
74 return; 74 return;
75 mRunning = false; 75 mRunning = false;
76 if ( mRunSaveTimer ) 76 if ( mRunSaveTimer )
77 mRunSaveTimer->stop(); 77 mRunSaveTimer->stop();
78 saveRunningInfoToFile( s ); 78 saveRunningInfoToFile( s );
79} 79}
80void Todo::stopRunning() 80void Todo::stopRunning()
81{ 81{
82 if ( !mRunning ) 82 if ( !mRunning )
83 return; 83 return;
84 if ( mRunSaveTimer ) 84 if ( mRunSaveTimer )
85 mRunSaveTimer->stop(); 85 mRunSaveTimer->stop();
86 mRunning = false; 86 mRunning = false;
87} 87}
88void Todo::setRunning( bool run ) 88void Todo::setRunning( bool run )
89{ 89{
90 if ( run == mRunning ) 90 if ( run == mRunning )
91 return; 91 return;
92 //qDebug("Todo::setRunning %d ", run); 92 //qDebug("Todo::setRunning %d ", run);
93 if ( !mRunSaveTimer ) { 93 if ( !mRunSaveTimer ) {
94 mRunSaveTimer = new QTimer ( this ); 94 mRunSaveTimer = new QTimer ( this );
95 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); 95 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) );
96 } 96 }
97 mRunning = run; 97 mRunning = run;
98 mRunLastSave = QDateTime::currentDateTime(); 98 mRunLastSave = QDateTime::currentDateTime();
99 if ( mRunning ) { 99 if ( mRunning ) {
100 mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min 100 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
101 mRunStart = QDateTime::currentDateTime(); 101 mRunStart = QDateTime::currentDateTime();
102 mRunLastSave = QDateTime::currentDateTime();
103 mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS;
104 } else { 102 } else {
105 mRunSaveTimer->stop(); 103 mRunSaveTimer->stop();
106 saveRunningInfoToFile(); 104 saveRunningInfoToFile();
107 } 105 }
108} 106}
109void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 107void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
110{ 108{
111 if ( !mRunning) return; 109 if ( !mRunning) return;
112 mRunning = false; 110 mRunning = false;
113 mRunStart = start; 111 mRunStart = start;
114 mRunEnd = end; 112 mRunEnd = end;
115 saveRunningInfoToFile( comment ); 113 saveRunningInfoToFile( comment );
116} 114}
115void Todo::restartSaveTimer( int secs )
116{
117 mRunSaveTimer->start( secs * 1000 );
118 mRunLastSave = QDateTime::currentDateTime();
119 mCurrentTimerDelay = secs;
120}
117void Todo::timerSlotSaveRunningInfoToFile() 121void Todo::timerSlotSaveRunningInfoToFile()
118{ 122{
119 mRunEnd = QDateTime::currentDateTime(); 123 mRunEnd = QDateTime::currentDateTime();
120 int secsTo = mRunLastSave.secsTo( mRunEnd ); 124 int secsTo = mRunLastSave.secsTo( mRunEnd );
121 if( secsTo == 8 ) ++secsTo; 125 //if( secsTo == 8 ) ++secsTo;
122 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); 126 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
123 if ( secsTo > mCurrentTimerDelay ) { 127 if ( secsTo > mCurrentTimerDelay ) {
124 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); 128 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
125 mRunSaveTimer->start( SAVETIMER_TIMEOUT_RETRY_SECONDS * 1000 ); 129 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
126 mRunLastSave = QDateTime::currentDateTime();
127 mCurrentTimerDelay = SAVETIMER_TIMEOUT_RETRY_SECONDS;
128 return; 130 return;
129 } 131 }
130 mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min 132 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time());
131 mRunLastSave = QDateTime::currentDateTime(); 133 if ( msecs < 0 ) {
132 mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; 134 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
135 return;
136 }
137 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
138 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) {
139 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
140 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
141 return;
142
143 }
144 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
133 saveRunningInfoToFile( QString::null ); 145 saveRunningInfoToFile( QString::null );
134} 146}
135void Todo::saveRunningInfoToFile() 147void Todo::saveRunningInfoToFile()
136{ 148{
137 mRunEnd = QDateTime::currentDateTime(); 149 mRunEnd = QDateTime::currentDateTime();
138 saveRunningInfoToFile( QString::null ); 150 saveRunningInfoToFile( QString::null );
139} 151}
140void Todo::saveRunningInfoToFile( QString comment ) 152void Todo::saveRunningInfoToFile( QString comment )
141{ 153{
142 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 154 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
143 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 155 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
144 qDebug("Running time < 15 seconds. Skipped. "); 156 qDebug("Running time < 15 seconds. Skipped. ");
145 return; 157 return;
146 } 158 }
147 QString dir = KGlobalSettings::timeTrackerDir(); 159 QString dir = KGlobalSettings::timeTrackerDir();
148 //qDebug("%s ", dir.latin1()); 160 //qDebug("%s ", dir.latin1());
149 QString file = "%1%2%3-%4%5%6-"; 161 QString file = "%1%2%3-%4%5%6-";
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 ); 162 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 );
151 file.replace ( QRegExp (" "), "0" ); 163 file.replace ( QRegExp (" "), "0" );
152 file += uid(); 164 file += uid();
153 //qDebug("File %s ",file.latin1() ); 165 //qDebug("File %s ",file.latin1() );
154 CalendarLocal cal; 166 CalendarLocal cal;
155 cal.setLocalTime(); 167 cal.setLocalTime();
156 Todo * to = (Todo*) clone(); 168 Todo * to = (Todo*) clone();
157 to->setFloats( false ); 169 to->setFloats( false );
158 to->setDtStart( mRunStart ); 170 to->setDtStart( mRunStart );
159 to->setHasStartDate( true ); 171 to->setHasStartDate( true );
160 to->setDtDue( mRunEnd ); 172 to->setDtDue( mRunEnd );
161 to->setHasDueDate( true ); 173 to->setHasDueDate( true );
162 to->setUid( file ); 174 to->setUid( file );
163 if ( !comment.isEmpty() ) { 175 if ( !comment.isEmpty() ) {
164 QString des = to->description(); 176 QString des = to->description();
165 if ( des.isEmpty () ) 177 if ( des.isEmpty () )
166 to->setDescription( "TT-Note: " + comment ); 178 to->setDescription( "TT-Note: " + comment );
167 else 179 else
168 to->setDescription( "TT-Note: " + comment +"\n" + des ); 180 to->setDescription( "TT-Note: " + comment +"\n" + des );
169 } 181 }
170 cal.addIncidence( to ); 182 cal.addIncidence( to );
171 ICalFormat format( false ); 183 ICalFormat format( false );
172 file = dir +"/" +file +".ics"; 184 file = dir +"/" +file +".ics";
173 format.save( &cal, file ); 185 format.save( &cal, file );
174 saveParents(); 186 saveParents();
175 187
176} 188}
177void Todo::saveParents() 189void Todo::saveParents()
178{ 190{
179 if (!relatedTo() ) 191 if (!relatedTo() )
180 return; 192 return;
diff --git a/libkcal/todo.h b/libkcal/todo.h
index e6b8a21..71b7a4e 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -89,72 +89,73 @@ namespace KCal {
89 /** return the event's status. */ 89 /** return the event's status. */
90// int status() const; 90// int status() const;
91 /** return the event's status in string format. */ 91 /** return the event's status in string format. */
92// QString statusStr() const; 92// QString statusStr() const;
93 93
94 /** return, if this todo is completed */ 94 /** return, if this todo is completed */
95 bool isCompleted() const; 95 bool isCompleted() const;
96 /** set completed state of this todo */ 96 /** set completed state of this todo */
97 void setCompleted(bool); 97 void setCompleted(bool);
98 98
99 /** 99 /**
100 Return how many percent of the task are completed. Returns a value 100 Return how many percent of the task are completed. Returns a value
101 between 0 and 100. 101 between 0 and 100.
102 */ 102 */
103 int percentComplete() const; 103 int percentComplete() const;
104 /** 104 /**
105 Set how many percent of the task are completed. Valid values are in the 105 Set how many percent of the task are completed. Valid values are in the
106 range from 0 to 100. 106 range from 0 to 100.
107 */ 107 */
108 void setPercentComplete(int); 108 void setPercentComplete(int);
109 109
110 /** return date and time when todo was completed */ 110 /** return date and time when todo was completed */
111 QDateTime completed() const; 111 QDateTime completed() const;
112 QString completedStr(bool shortF = true) const; 112 QString completedStr(bool shortF = true) const;
113 /** set date and time of completion */ 113 /** set date and time of completion */
114 void setCompleted(const QDateTime &completed); 114 void setCompleted(const QDateTime &completed);
115 115
116 /** Return true, if todo has a date associated with completion */ 116 /** Return true, if todo has a date associated with completion */
117 bool hasCompletedDate() const; 117 bool hasCompletedDate() const;
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: 134 private slots:
135 void timerSlotSaveRunningInfoToFile( ); 135 void timerSlotSaveRunningInfoToFile( );
136 private: 136 private:
137 void restartSaveTimer( int secs );
137 int mCurrentTimerDelay; 138 int mCurrentTimerDelay;
138 bool mRunning; 139 bool mRunning;
139 QTimer * mRunSaveTimer; 140 QTimer * mRunSaveTimer;
140 QDateTime mRunStart; 141 QDateTime mRunStart;
141 QDateTime mRunLastSave; 142 QDateTime mRunLastSave;
142 QDateTime mRunEnd; 143 QDateTime mRunEnd;
143 bool accept(Visitor &v) { return v.visit(this); } 144 bool accept(Visitor &v) { return v.visit(this); }
144 145
145 QDateTime mDtDue; // due date of todo 146 QDateTime mDtDue; // due date of todo
146 147
147 bool mHasDueDate; // if todo has associated due date 148 bool mHasDueDate; // if todo has associated due date
148 149
149// int mStatus; // confirmed/delegated/tentative/etc 150// int mStatus; // confirmed/delegated/tentative/etc
150 151
151 QDateTime mCompleted; 152 QDateTime mCompleted;
152 bool mHasCompletedDate; 153 bool mHasCompletedDate;
153 154
154 int mPercentComplete; 155 int mPercentComplete;
155}; 156};
156 157
157 bool operator==( const Todo&, const Todo& ); 158 bool operator==( const Todo&, const Todo& );
158} 159}
159 160
160#endif 161#endif