summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp13
-rw-r--r--libkcal/todo.h3
2 files changed, 14 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 002d3f2..f7e38a7 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -52,66 +52,77 @@ Todo::Todo(const Todo &t) : QObject(),Incidence(t)
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::setRunningFalse( QString s )
65{
66 if ( ! mRunning )
67 return;
68 mRunning = false;
69 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s );
71}
64void Todo::setRunning( bool run ) 72void Todo::setRunning( bool run )
65{ 73{
66 if ( run == mRunning ) 74 if ( run == mRunning )
67 return; 75 return;
68 //qDebug("Todo::setRunning %d ", run); 76 //qDebug("Todo::setRunning %d ", run);
69 if ( !mRunSaveTimer ) { 77 if ( !mRunSaveTimer ) {
70 mRunSaveTimer = new QTimer ( this ); 78 mRunSaveTimer = new QTimer ( this );
71 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
72 } 80 }
73 mRunning = run; 81 mRunning = run;
74 if ( mRunning ) { 82 if ( mRunning ) {
75 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
76 mRunStart = QDateTime::currentDateTime(); 84 mRunStart = QDateTime::currentDateTime();
77 } else { 85 } else {
78 mRunSaveTimer->stop(); 86 mRunSaveTimer->stop();
79 saveRunningInfoToFile(); 87 saveRunningInfoToFile();
80 } 88 }
81} 89}
82 90
83void Todo::saveRunningInfoToFile() 91void Todo::saveRunningInfoToFile( QString comment )
84{ 92{
85 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 93 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
86 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { 94 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
87 qDebug("Running time < 30 seconds. Skipped. "); 95 qDebug("Running time < 30 seconds. Skipped. ");
88 return; 96 return;
89 } 97 }
90 QString dir = KGlobalSettings::timeTrackerDir(); 98 QString dir = KGlobalSettings::timeTrackerDir();
91 //qDebug("%s ", dir.latin1()); 99 //qDebug("%s ", dir.latin1());
92 QString file = "%1%2%3-%4%5%6-"; 100 QString file = "%1%2%3-%4%5%6-";
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 ); 101 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 );
94 file.replace ( QRegExp (" "), "0" ); 102 file.replace ( QRegExp (" "), "0" );
95 file += uid(); 103 file += uid();
96 //qDebug("File %s ",file.latin1() ); 104 //qDebug("File %s ",file.latin1() );
97 CalendarLocal cal; 105 CalendarLocal cal;
98 cal.setLocalTime(); 106 cal.setLocalTime();
99 Todo * to = (Todo*) clone(); 107 Todo * to = (Todo*) clone();
100 to->setFloats( false ); 108 to->setFloats( false );
101 to->setDtStart( mRunStart ); 109 to->setDtStart( mRunStart );
102 to->setHasStartDate( true ); 110 to->setHasStartDate( true );
103 to->setDtDue( QDateTime::currentDateTime() ); 111 to->setDtDue( QDateTime::currentDateTime() );
104 to->setHasDueDate( true ); 112 to->setHasDueDate( true );
105 to->setUid( file ); 113 to->setUid( file );
114 if ( !comment.isEmpty() ) {
115 to->setDescription( comment );
116 }
106 cal.addIncidence( to ); 117 cal.addIncidence( to );
107 ICalFormat format; 118 ICalFormat format;
108 file = dir +"/" +file +".ics"; 119 file = dir +"/" +file +".ics";
109 format.save( &cal, file ); 120 format.save( &cal, file );
110 saveParents(); 121 saveParents();
111 122
112} 123}
113void Todo::saveParents() 124void Todo::saveParents()
114{ 125{
115 if (!relatedTo() ) 126 if (!relatedTo() )
116 return; 127 return;
117 Incidence * inc = relatedTo(); 128 Incidence * inc = relatedTo();
diff --git a/libkcal/todo.h b/libkcal/todo.h
index ec1ffda..a5354ce 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -111,28 +111,29 @@ namespace KCal {
111 QString completedStr(bool shortF = true) const; 111 QString completedStr(bool shortF = true) const;
112 /** set date and time of completion */ 112 /** set date and time of completion */
113 void setCompleted(const QDateTime &completed); 113 void setCompleted(const QDateTime &completed);
114 114
115 /** Return true, if todo has a date associated with completion */ 115 /** Return true, if todo has a date associated with completion */
116 bool hasCompletedDate() const; 116 bool hasCompletedDate() const;
117 bool contains ( Todo*); 117 bool contains ( Todo*);
118 void checkSetCompletedFalse(); 118 void checkSetCompletedFalse();
119 bool setRecurDates(); 119 bool setRecurDates();
120 bool isRunning() {return mRunning;} 120 bool isRunning() {return mRunning;}
121 bool hasRunningSub(); 121 bool hasRunningSub();
122 void setRunning( bool ); 122 void setRunning( bool );
123 void setRunningFalse( QString );
123 int runTime(); 124 int runTime();
124 QDateTime runStart () const { return mRunStart;} 125 QDateTime runStart () const { return mRunStart;}
125 public slots: 126 public slots:
126 void saveRunningInfoToFile(); 127 void saveRunningInfoToFile( QString st = QString::null );
127 void saveParents(); 128 void saveParents();
128 private: 129 private:
129 bool mRunning; 130 bool mRunning;
130 QTimer * mRunSaveTimer; 131 QTimer * mRunSaveTimer;
131 QDateTime mRunStart; 132 QDateTime mRunStart;
132 bool accept(Visitor &v) { return v.visit(this); } 133 bool accept(Visitor &v) { return v.visit(this); }
133 134
134 QDateTime mDtDue; // due date of todo 135 QDateTime mDtDue; // due date of todo
135 136
136 bool mHasDueDate; // if todo has associated due date 137 bool mHasDueDate; // if todo has associated due date
137 138
138// int mStatus; // confirmed/delegated/tentative/etc 139// int mStatus; // confirmed/delegated/tentative/etc