author | zautrix <zautrix> | 2005-06-27 04:48:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-27 04:48:41 (UTC) |
commit | 9b2bf31715226dfa8210f31843616a04f810f012 (patch) (unidiff) | |
tree | b502c4a379b26f74621ba8fabb59fcb53f5a5679 /libkcal | |
parent | 2e566a307bb50ac595fe729ebed0f5336f2af5a8 (diff) | |
download | kdepimpi-9b2bf31715226dfa8210f31843616a04f810f012.zip kdepimpi-9b2bf31715226dfa8210f31843616a04f810f012.tar.gz kdepimpi-9b2bf31715226dfa8210f31843616a04f810f012.tar.bz2 |
strat stop tod fixes
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 6 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/todo.cpp | 4 |
4 files changed, 10 insertions, 2 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 3b7b183..2efa355 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -32,96 +32,97 @@ | |||
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual void setSyncEventsReadOnly() = 0; | 79 | virtual void setSyncEventsReadOnly() = 0; |
80 | virtual void stopAllTodos() = 0; | ||
80 | 81 | ||
81 | /** | 82 | /** |
82 | Sync changes in memory to persistant storage. | 83 | Sync changes in memory to persistant storage. |
83 | */ | 84 | */ |
84 | virtual void save() = 0; | 85 | virtual void save() = 0; |
85 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 86 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
86 | virtual void removeSyncInfo( QString syncProfile) = 0; | 87 | virtual void removeSyncInfo( QString syncProfile) = 0; |
87 | virtual bool isSaving() { return false; } | 88 | virtual bool isSaving() { return false; } |
88 | 89 | ||
89 | /** | 90 | /** |
90 | Return the owner of the calendar's full name. | 91 | Return the owner of the calendar's full name. |
91 | */ | 92 | */ |
92 | const QString &getOwner() const; | 93 | const QString &getOwner() const; |
93 | /** | 94 | /** |
94 | Set the owner of the calendar. Should be owner's full name. | 95 | Set the owner of the calendar. Should be owner's full name. |
95 | */ | 96 | */ |
96 | void setOwner( const QString &os ); | 97 | void setOwner( const QString &os ); |
97 | /** | 98 | /** |
98 | Return the email address of the calendar owner. | 99 | Return the email address of the calendar owner. |
99 | */ | 100 | */ |
100 | const QString &getEmail(); | 101 | const QString &getEmail(); |
101 | /** | 102 | /** |
102 | Set the email address of the calendar owner. | 103 | Set the email address of the calendar owner. |
103 | */ | 104 | */ |
104 | void setEmail( const QString & ); | 105 | void setEmail( const QString & ); |
105 | 106 | ||
106 | /** | 107 | /** |
107 | Set time zone from a timezone string (e.g. -2:00) | 108 | Set time zone from a timezone string (e.g. -2:00) |
108 | */ | 109 | */ |
109 | void setTimeZone( const QString &tz ); | 110 | void setTimeZone( const QString &tz ); |
110 | /** | 111 | /** |
111 | Set time zone from a minutes value (e.g. -60) | 112 | Set time zone from a minutes value (e.g. -60) |
112 | */ | 113 | */ |
113 | void setTimeZone( int tz ); | 114 | void setTimeZone( int tz ); |
114 | /** | 115 | /** |
115 | Return time zone as offest in minutes. | 116 | Return time zone as offest in minutes. |
116 | */ | 117 | */ |
117 | int getTimeZone() const; | 118 | int getTimeZone() const; |
118 | /** | 119 | /** |
119 | Compute an ISO 8601 format string from the time zone. | 120 | Compute an ISO 8601 format string from the time zone. |
120 | */ | 121 | */ |
121 | QString getTimeZoneStr() const; | 122 | QString getTimeZoneStr() const; |
122 | /** | 123 | /** |
123 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 124 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
124 | values). | 125 | values). |
125 | */ | 126 | */ |
126 | void setTimeZoneId( const QString & ); | 127 | void setTimeZoneId( const QString & ); |
127 | /** | 128 | /** |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8c4dde1..18f1af8 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -102,96 +102,102 @@ void CalendarLocal::addCalendar( Calendar* cal ) | |||
102 | } | 102 | } |
103 | } | 103 | } |
104 | { | 104 | { |
105 | 105 | ||
106 | QPtrList<Todo> TodoList = cal->rawTodos(); | 106 | QPtrList<Todo> TodoList = cal->rawTodos(); |
107 | Todo * ev = TodoList.first(); | 107 | Todo * ev = TodoList.first(); |
108 | while ( ev ) { | 108 | while ( ev ) { |
109 | QString rel = ev->relatedToUid(); | 109 | QString rel = ev->relatedToUid(); |
110 | if ( !rel.isEmpty() ){ | 110 | if ( !rel.isEmpty() ){ |
111 | ev->setRelatedTo ( 0 ); | 111 | ev->setRelatedTo ( 0 ); |
112 | ev->setRelatedToUid( rel ); | 112 | ev->setRelatedToUid( rel ); |
113 | } | 113 | } |
114 | ev = TodoList.next(); | 114 | ev = TodoList.next(); |
115 | } | 115 | } |
116 | //TodoList = cal->rawTodos(); | 116 | //TodoList = cal->rawTodos(); |
117 | ev = TodoList.first(); | 117 | ev = TodoList.first(); |
118 | while ( ev ) { | 118 | while ( ev ) { |
119 | ev->unRegisterObserver( cal ); | 119 | ev->unRegisterObserver( cal ); |
120 | ev->registerObserver( this ); | 120 | ev->registerObserver( this ); |
121 | mTodoList.append( ev ); | 121 | mTodoList.append( ev ); |
122 | setupRelations( ev ); | 122 | setupRelations( ev ); |
123 | ev = TodoList.next(); | 123 | ev = TodoList.next(); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | { | 126 | { |
127 | QPtrList<Journal> JournalList = cal->journals(); | 127 | QPtrList<Journal> JournalList = cal->journals(); |
128 | Journal * ev = JournalList.first(); | 128 | Journal * ev = JournalList.first(); |
129 | while ( ev ) { | 129 | while ( ev ) { |
130 | ev->unRegisterObserver( cal ); | 130 | ev->unRegisterObserver( cal ); |
131 | ev->registerObserver( this ); | 131 | ev->registerObserver( this ); |
132 | mJournalList.append( ev ); | 132 | mJournalList.append( ev ); |
133 | ev = JournalList.next(); | 133 | ev = JournalList.next(); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | setModified( true ); | 136 | setModified( true ); |
137 | } | 137 | } |
138 | bool CalendarLocal::load( const QString &fileName ) | 138 | bool CalendarLocal::load( const QString &fileName ) |
139 | { | 139 | { |
140 | FileStorage storage( this, fileName ); | 140 | FileStorage storage( this, fileName ); |
141 | return storage.load(); | 141 | return storage.load(); |
142 | } | 142 | } |
143 | 143 | ||
144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
145 | { | 145 | { |
146 | FileStorage storage( this, fileName, format ); | 146 | FileStorage storage( this, fileName, format ); |
147 | return storage.save(); | 147 | return storage.save(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void CalendarLocal::stopAllTodos() | ||
151 | { | ||
152 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
153 | it->setRunning( false ); | ||
154 | |||
155 | } | ||
150 | void CalendarLocal::close() | 156 | void CalendarLocal::close() |
151 | { | 157 | { |
152 | 158 | ||
153 | Todo * i; | 159 | Todo * i; |
154 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 160 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
155 | 161 | ||
156 | mEventList.setAutoDelete( true ); | 162 | mEventList.setAutoDelete( true ); |
157 | mTodoList.setAutoDelete( true ); | 163 | mTodoList.setAutoDelete( true ); |
158 | mJournalList.setAutoDelete( false ); | 164 | mJournalList.setAutoDelete( false ); |
159 | 165 | ||
160 | mEventList.clear(); | 166 | mEventList.clear(); |
161 | mTodoList.clear(); | 167 | mTodoList.clear(); |
162 | mJournalList.clear(); | 168 | mJournalList.clear(); |
163 | 169 | ||
164 | mEventList.setAutoDelete( false ); | 170 | mEventList.setAutoDelete( false ); |
165 | mTodoList.setAutoDelete( false ); | 171 | mTodoList.setAutoDelete( false ); |
166 | mJournalList.setAutoDelete( false ); | 172 | mJournalList.setAutoDelete( false ); |
167 | 173 | ||
168 | setModified( false ); | 174 | setModified( false ); |
169 | } | 175 | } |
170 | 176 | ||
171 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 177 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
172 | { | 178 | { |
173 | QString cat; | 179 | QString cat; |
174 | bool isBirthday = true; | 180 | bool isBirthday = true; |
175 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 181 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
176 | isBirthday = false; | 182 | isBirthday = false; |
177 | cat = i18n( "Anniversary" ); | 183 | cat = i18n( "Anniversary" ); |
178 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 184 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
179 | isBirthday = true; | 185 | isBirthday = true; |
180 | cat = i18n( "Birthday" ); | 186 | cat = i18n( "Birthday" ); |
181 | } else { | 187 | } else { |
182 | qDebug("addAnniversaryNoDup called without fitting category! "); | 188 | qDebug("addAnniversaryNoDup called without fitting category! "); |
183 | return false; | 189 | return false; |
184 | } | 190 | } |
185 | Event * eve; | 191 | Event * eve; |
186 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 192 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
187 | if ( !(eve->categories().contains( cat ) )) | 193 | if ( !(eve->categories().contains( cat ) )) |
188 | continue; | 194 | continue; |
189 | // now we have an event with fitting category | 195 | // now we have an event with fitting category |
190 | if ( eve->dtStart().date() != event->dtStart().date() ) | 196 | if ( eve->dtStart().date() != event->dtStart().date() ) |
191 | continue; | 197 | continue; |
192 | // now we have an event with fitting category+date | 198 | // now we have an event with fitting category+date |
193 | if ( eve->summary() != event->summary() ) | 199 | if ( eve->summary() != event->summary() ) |
194 | continue; | 200 | continue; |
195 | // now we have an event with fitting category+date+summary | 201 | // now we have an event with fitting category+date+summary |
196 | return false; | 202 | return false; |
197 | } | 203 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 0286b48..d32597f 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,96 +1,97 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | void setSyncEventsReadOnly(); | 48 | void setSyncEventsReadOnly(); |
49 | void stopAllTodos(); | ||
49 | /** | 50 | /** |
50 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 51 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
51 | calendar. Any information already present is lost. | 52 | calendar. Any information already present is lost. |
52 | @return true, if successfull, false on error. | 53 | @return true, if successfull, false on error. |
53 | @param fileName the name of the calendar on disk. | 54 | @param fileName the name of the calendar on disk. |
54 | */ | 55 | */ |
55 | bool load( const QString &fileName ); | 56 | bool load( const QString &fileName ); |
56 | /** | 57 | /** |
57 | Writes out the calendar to disk in the specified \a format. | 58 | Writes out the calendar to disk in the specified \a format. |
58 | CalendarLocal takes ownership of the CalFormat object. | 59 | CalendarLocal takes ownership of the CalFormat object. |
59 | @return true, if successfull, false on error. | 60 | @return true, if successfull, false on error. |
60 | @param fileName the name of the file | 61 | @param fileName the name of the file |
61 | */ | 62 | */ |
62 | bool save( const QString &fileName, CalFormat *format = 0 ); | 63 | bool save( const QString &fileName, CalFormat *format = 0 ); |
63 | 64 | ||
64 | /** | 65 | /** |
65 | Clears out the current calendar, freeing all used memory etc. etc. | 66 | Clears out the current calendar, freeing all used memory etc. etc. |
66 | */ | 67 | */ |
67 | void close(); | 68 | void close(); |
68 | 69 | ||
69 | void save() {} | 70 | void save() {} |
70 | 71 | ||
71 | /** | 72 | /** |
72 | Add Event to calendar. | 73 | Add Event to calendar. |
73 | */ | 74 | */ |
74 | void removeSyncInfo( QString syncProfile); | 75 | void removeSyncInfo( QString syncProfile); |
75 | bool addAnniversaryNoDup( Event *event ); | 76 | bool addAnniversaryNoDup( Event *event ); |
76 | bool addEventNoDup( Event *event ); | 77 | bool addEventNoDup( Event *event ); |
77 | bool addEvent( Event *event ); | 78 | bool addEvent( Event *event ); |
78 | /** | 79 | /** |
79 | Deletes an event from this calendar. | 80 | Deletes an event from this calendar. |
80 | */ | 81 | */ |
81 | void deleteEvent( Event *event ); | 82 | void deleteEvent( Event *event ); |
82 | 83 | ||
83 | /** | 84 | /** |
84 | Retrieves an event on the basis of the unique string ID. | 85 | Retrieves an event on the basis of the unique string ID. |
85 | */ | 86 | */ |
86 | Event *event( const QString &uid ); | 87 | Event *event( const QString &uid ); |
87 | /** | 88 | /** |
88 | Return unfiltered list of all events in calendar. | 89 | Return unfiltered list of all events in calendar. |
89 | */ | 90 | */ |
90 | QPtrList<Event> rawEvents(); | 91 | QPtrList<Event> rawEvents(); |
91 | QPtrList<Event> getExternLastSyncEvents(); | 92 | QPtrList<Event> getExternLastSyncEvents(); |
92 | /** | 93 | /** |
93 | Add a todo to the todolist. | 94 | Add a todo to the todolist. |
94 | */ | 95 | */ |
95 | bool addTodo( Todo *todo ); | 96 | bool addTodo( Todo *todo ); |
96 | bool addTodoNoDup( Todo *todo ); | 97 | bool addTodoNoDup( Todo *todo ); |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9a8b6e4..5260051 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -66,98 +66,98 @@ void Todo::setRunningFalse( QString s ) | |||
66 | if ( ! mRunning ) | 66 | if ( ! mRunning ) |
67 | return; | 67 | return; |
68 | mRunning = false; | 68 | mRunning = false; |
69 | mRunSaveTimer->stop(); | 69 | mRunSaveTimer->stop(); |
70 | saveRunningInfoToFile( s ); | 70 | saveRunningInfoToFile( s ); |
71 | } | 71 | } |
72 | void Todo::stopRunning() | 72 | void Todo::stopRunning() |
73 | { | 73 | { |
74 | if ( !mRunning ) | 74 | if ( !mRunning ) |
75 | return; | 75 | return; |
76 | if ( mRunSaveTimer ) | 76 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 77 | mRunSaveTimer->stop(); |
78 | mRunning = false; | 78 | mRunning = false; |
79 | } | 79 | } |
80 | void Todo::setRunning( bool run ) | 80 | void Todo::setRunning( bool run ) |
81 | { | 81 | { |
82 | if ( run == mRunning ) | 82 | if ( run == mRunning ) |
83 | return; | 83 | return; |
84 | //qDebug("Todo::setRunning %d ", run); | 84 | //qDebug("Todo::setRunning %d ", run); |
85 | if ( !mRunSaveTimer ) { | 85 | if ( !mRunSaveTimer ) { |
86 | mRunSaveTimer = new QTimer ( this ); | 86 | mRunSaveTimer = new QTimer ( this ); |
87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 87 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
88 | } | 88 | } |
89 | mRunning = run; | 89 | mRunning = run; |
90 | if ( mRunning ) { | 90 | if ( mRunning ) { |
91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 91 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
92 | mRunStart = QDateTime::currentDateTime(); | 92 | mRunStart = QDateTime::currentDateTime(); |
93 | } else { | 93 | } else { |
94 | mRunSaveTimer->stop(); | 94 | mRunSaveTimer->stop(); |
95 | saveRunningInfoToFile(); | 95 | saveRunningInfoToFile(); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 98 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
99 | { | 99 | { |
100 | if ( !mRunning) return; | 100 | if ( !mRunning) return; |
101 | mRunning = false; | 101 | mRunning = false; |
102 | mRunStart = start; | 102 | mRunStart = start; |
103 | mRunEnd = end; | 103 | mRunEnd = end; |
104 | saveRunningInfoToFile( comment ); | 104 | saveRunningInfoToFile( comment ); |
105 | } | 105 | } |
106 | void Todo::saveRunningInfoToFile() | 106 | void Todo::saveRunningInfoToFile() |
107 | { | 107 | { |
108 | mRunEnd = QDateTime::currentDateTime(); | 108 | mRunEnd = QDateTime::currentDateTime(); |
109 | saveRunningInfoToFile( QString::null ); | 109 | saveRunningInfoToFile( QString::null ); |
110 | } | 110 | } |
111 | void Todo::saveRunningInfoToFile( QString comment ) | 111 | void Todo::saveRunningInfoToFile( QString comment ) |
112 | { | 112 | { |
113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 113 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
114 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 10 ) { | 114 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
115 | qDebug("Running time < 30 seconds. Skipped. "); | 115 | qDebug("Running time < 15 seconds. Skipped. "); |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | QString dir = KGlobalSettings::timeTrackerDir(); | 118 | QString dir = KGlobalSettings::timeTrackerDir(); |
119 | //qDebug("%s ", dir.latin1()); | 119 | //qDebug("%s ", dir.latin1()); |
120 | QString file = "%1%2%3-%4%5%6-"; | 120 | QString file = "%1%2%3-%4%5%6-"; |
121 | 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 ); | 121 | 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 ); |
122 | file.replace ( QRegExp (" "), "0" ); | 122 | file.replace ( QRegExp (" "), "0" ); |
123 | file += uid(); | 123 | file += uid(); |
124 | //qDebug("File %s ",file.latin1() ); | 124 | //qDebug("File %s ",file.latin1() ); |
125 | CalendarLocal cal; | 125 | CalendarLocal cal; |
126 | cal.setLocalTime(); | 126 | cal.setLocalTime(); |
127 | Todo * to = (Todo*) clone(); | 127 | Todo * to = (Todo*) clone(); |
128 | to->setFloats( false ); | 128 | to->setFloats( false ); |
129 | to->setDtStart( mRunStart ); | 129 | to->setDtStart( mRunStart ); |
130 | to->setHasStartDate( true ); | 130 | to->setHasStartDate( true ); |
131 | to->setDtDue( mRunEnd ); | 131 | to->setDtDue( mRunEnd ); |
132 | to->setHasDueDate( true ); | 132 | to->setHasDueDate( true ); |
133 | to->setUid( file ); | 133 | to->setUid( file ); |
134 | if ( !comment.isEmpty() ) { | 134 | if ( !comment.isEmpty() ) { |
135 | QString des = to->description(); | 135 | QString des = to->description(); |
136 | if ( des.isEmpty () ) | 136 | if ( des.isEmpty () ) |
137 | to->setDescription( "TT-Note: " + comment ); | 137 | to->setDescription( "TT-Note: " + comment ); |
138 | else | 138 | else |
139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 139 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
140 | } | 140 | } |
141 | cal.addIncidence( to ); | 141 | cal.addIncidence( to ); |
142 | ICalFormat format; | 142 | ICalFormat format; |
143 | file = dir +"/" +file +".ics"; | 143 | file = dir +"/" +file +".ics"; |
144 | format.save( &cal, file ); | 144 | format.save( &cal, file ); |
145 | saveParents(); | 145 | saveParents(); |
146 | 146 | ||
147 | } | 147 | } |
148 | void Todo::saveParents() | 148 | void Todo::saveParents() |
149 | { | 149 | { |
150 | if (!relatedTo() ) | 150 | if (!relatedTo() ) |
151 | return; | 151 | return; |
152 | Incidence * inc = relatedTo(); | 152 | Incidence * inc = relatedTo(); |
153 | if ( inc->typeID() != todoID ) | 153 | if ( inc->typeID() != todoID ) |
154 | return; | 154 | return; |
155 | Todo* to = (Todo*)inc; | 155 | Todo* to = (Todo*)inc; |
156 | bool saveTodo = false; | 156 | bool saveTodo = false; |
157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 157 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
158 | QFileInfo fi ( file ); | 158 | QFileInfo fi ( file ); |
159 | if ( fi.exists() ) { | 159 | if ( fi.exists() ) { |
160 | if ( fi.lastModified () < to->lastModified ()) | 160 | if ( fi.lastModified () < to->lastModified ()) |
161 | saveTodo = true; | 161 | saveTodo = true; |
162 | } else { | 162 | } else { |
163 | saveTodo = true; | 163 | saveTodo = true; |