summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libkcal/todo.cpp36
-rw-r--r--libkcal/todo.h1
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
@@ -14,45 +14,46 @@
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <kglobal.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kdebug.h>
#include <qregexp.h>
+#include <qfileinfo.h>
#include "calendarlocal.h"
#include "icalformat.h"
#include "todo.h"
using namespace KCal;
-Todo::Todo(): Incidence()
+Todo::Todo(): QObject(), Incidence()
{
// mStatus = TENTATIVE;
mHasDueDate = false;
setHasStartDate( false );
mCompleted = getEvenTime(QDateTime::currentDateTime());
mHasCompletedDate = false;
mPercentComplete = 0;
mRunning = false;
mRunSaveTimer = 0;
}
-Todo::Todo(const Todo &t) : Incidence(t)
+Todo::Todo(const Todo &t) : QObject(),Incidence(t)
{
mDtDue = t.mDtDue;
mHasDueDate = t.mHasDueDate;
mCompleted = t.mCompleted;
mHasCompletedDate = t.mHasCompletedDate;
mPercentComplete = t.mPercentComplete;
mRunning = false;
mRunSaveTimer = 0;
}
Todo::~Todo()
{
@@ -72,48 +73,77 @@ void Todo::setRunning( bool run )
if ( mRunning ) {
mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
mRunStart = QDateTime::currentDateTime();
} else {
mRunSaveTimer->stop();
saveRunningInfoToFile();
}
}
void Todo::saveRunningInfoToFile()
{
//qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
- if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 )
+ if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
+ qDebug("Running time < 30 seconds. Skipped. ");
return;
+ }
QString dir = KGlobalSettings::timeTrackerDir();
//qDebug("%s ", dir.latin1());
QString file = "%1%2%3-%4%5%6-";
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 );
file.replace ( QRegExp (" "), "0" );
file += uid();
//qDebug("File %s ",file.latin1() );
CalendarLocal cal;
cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
Todo * to = (Todo*) clone();
to->setFloats( false );
to->setDtStart( mRunStart );
to->setHasStartDate( true );
to->setDtDue( QDateTime::currentDateTime() );
to->setHasDueDate( true );
to->setUid( file );
cal.addIncidence( to );
ICalFormat format;
file = dir +"/" +file +".ics";
format.save( &cal, file );
+ saveParents();
}
+void Todo::saveParents()
+{
+ if (!relatedTo() )
+ return;
+ Incidence * inc = relatedTo();
+ if ( inc->type() != "Todo" )
+ return;
+ Todo* to = (Todo*)inc;
+ bool saveTodo = false;
+ QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
+ QFileInfo fi ( file );
+ if ( fi.exists() ) {
+ if ( fi.lastModified () < to->lastModified ())
+ saveTodo = true;
+ } else {
+ saveTodo = true;
+ }
+ if ( saveTodo ) {
+ CalendarLocal cal;
+ cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
+ Todo * par = (Todo *) to->clone();
+ cal.addIncidence( par );
+ ICalFormat format;
+ format.save( &cal, file );
+ }
+}
int Todo::runTime()
{
if ( !mRunning )
return 0;
return mRunStart.secsTo( QDateTime::currentDateTime() );
}
bool Todo::hasRunningSub()
{
if ( mRunning )
return true;
Incidence *aTodo;
diff --git a/libkcal/todo.h b/libkcal/todo.h
index fe43357..ec1ffda 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -115,24 +115,25 @@ namespace KCal {
/** Return true, if todo has a date associated with completion */
bool hasCompletedDate() const;
bool contains ( Todo*);
void checkSetCompletedFalse();
bool setRecurDates();
bool isRunning() {return mRunning;}
bool hasRunningSub();
void setRunning( bool );
int runTime();
QDateTime runStart () const { return mRunStart;}
public slots:
void saveRunningInfoToFile();
+ void saveParents();
private:
bool mRunning;
QTimer * mRunSaveTimer;
QDateTime mRunStart;
bool accept(Visitor &v) { return v.visit(this); }
QDateTime mDtDue; // due date of todo
bool mHasDueDate; // if todo has associated due date
// int mStatus; // confirmed/delegated/tentative/etc