-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 | |||
@@ -48,64 +48,65 @@ namespace KCal { | |||
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) |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8c4dde1..18f1af8 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -118,64 +118,70 @@ void CalendarLocal::addCalendar( Calendar* cal ) | |||
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 { |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 0286b48..d32597f 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -17,64 +17,65 @@ | |||
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 | */ |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9a8b6e4..5260051 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -82,66 +82,66 @@ void Todo::setRunning( bool run ) | |||
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 | } |