author | zecke <zecke> | 2002-09-22 23:32:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-22 23:32:49 (UTC) |
commit | d7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f (patch) (unidiff) | |
tree | 5ff52b48fd514c6f24da6d3204bc98b66c48a652 /libopie/pim | |
parent | 4f142e98ee63e88fa0df61161b93228ee719d551 (diff) | |
download | opie-d7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f.zip opie-d7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f.tar.gz opie-d7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f.tar.bz2 |
Two brown paper bags later OTodo is ok again... pointers can be so fscking awesome
I had problems with QShared because I forgot to copy it in &operator=
And the other one was d = 0
-rw-r--r-- | libopie/pim/orecordlist.h | 12 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 25 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 2 |
3 files changed, 21 insertions, 18 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 75bb33c..36728b8 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -1,208 +1,208 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | 17 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 20 | friend class ORecordList<T>; |
21 | public: | 21 | public: |
22 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The c'tor used internally from | 25 | * The c'tor used internally from |
26 | * ORecordList | 26 | * ORecordList |
27 | */ | 27 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The standard c'tor | 31 | * The standard c'tor |
32 | */ | 32 | */ |
33 | ORecordListIterator(); | 33 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
35 | 35 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * a * operator ;) | 40 | * a * operator ;) |
41 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
42 | */ | 42 | */ |
43 | T &operator*(); | 43 | T operator*(); |
44 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
46 | 46 | ||
47 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
49 | 49 | ||
50 | private: | 50 | private: |
51 | QArray<int> m_uids; | 51 | QArray<int> m_uids; |
52 | int m_current; | 52 | int m_current; |
53 | const Base* m_temp; | 53 | const Base* m_temp; |
54 | bool m_end : 1; | 54 | bool m_end : 1; |
55 | T m_record; | 55 | T m_record; |
56 | 56 | ||
57 | /* d pointer for future versions */ | 57 | /* d pointer for future versions */ |
58 | class IteratorPrivate; | 58 | class IteratorPrivate; |
59 | IteratorPrivate *d; | 59 | IteratorPrivate *d; |
60 | }; | 60 | }; |
61 | /** | 61 | /** |
62 | * The recordlist used as a return type | 62 | * The recordlist used as a return type |
63 | * from OPimAccessTemplate | 63 | * from OPimAccessTemplate |
64 | */ | 64 | */ |
65 | template <class T = OPimRecord > | 65 | template <class T = OPimRecord > |
66 | class ORecordList { | 66 | class ORecordList { |
67 | public: | 67 | public: |
68 | typedef OTemplateBase<T> Base; | 68 | typedef OTemplateBase<T> Base; |
69 | typedef ORecordListIterator<T> Iterator; | 69 | typedef ORecordListIterator<T> Iterator; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * c'tor | 72 | * c'tor |
73 | */ | 73 | */ |
74 | ORecordList( const QArray<int>& ids, | 74 | ORecordList( const QArray<int>& ids, |
75 | const Base* ); | 75 | const Base* ); |
76 | ~ORecordList(); | 76 | ~ORecordList(); |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * the first iterator | 79 | * the first iterator |
80 | */ | 80 | */ |
81 | Iterator begin(); | 81 | Iterator begin(); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * the end | 84 | * the end |
85 | */ | 85 | */ |
86 | Iterator end(); | 86 | Iterator end(); |
87 | /* | 87 | /* |
88 | ConstIterator begin()const; | 88 | ConstIterator begin()const; |
89 | ConstIterator end()const; | 89 | ConstIterator end()const; |
90 | */ | 90 | */ |
91 | private: | 91 | private: |
92 | QArray<int> m_ids; | 92 | QArray<int> m_ids; |
93 | const Base* m_acc; | 93 | const Base* m_acc; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | /* ok now implement it */ | 96 | /* ok now implement it */ |
97 | template <class T> | 97 | template <class T> |
98 | ORecordListIterator<T>::ORecordListIterator() { | 98 | ORecordListIterator<T>::ORecordListIterator() { |
99 | m_current = 0; | 99 | m_current = 0; |
100 | m_temp = 0l; | 100 | m_temp = 0l; |
101 | m_end = true; | 101 | m_end = true; |
102 | m_record = T(); | ||
102 | } | 103 | } |
103 | template <class T> | 104 | template <class T> |
104 | ORecordListIterator<T>::~ORecordListIterator() { | 105 | ORecordListIterator<T>::~ORecordListIterator() { |
105 | /* nothing to delete */ | 106 | /* nothing to delete */ |
106 | } | 107 | } |
107 | 108 | ||
108 | template <class T> | 109 | template <class T> |
109 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 110 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
110 | qWarning("ORecordListIterator"); | 111 | // qWarning("ORecordListIterator copy c'tor"); |
111 | m_uids = it.m_uids; | 112 | m_uids = it.m_uids; |
112 | m_current = it.m_current; | 113 | m_current = it.m_current; |
113 | m_temp = it.m_temp; | 114 | m_temp = it.m_temp; |
114 | m_end = it.m_end; | 115 | m_end = it.m_end; |
115 | m_record = it.m_record; | 116 | m_record = it.m_record; |
116 | } | 117 | } |
117 | 118 | ||
118 | template <class T> | 119 | template <class T> |
119 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 120 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
120 | m_uids = it.m_uids; | 121 | m_uids = it.m_uids; |
121 | m_current = it.m_current; | 122 | m_current = it.m_current; |
122 | m_temp = it.m_temp; | 123 | m_temp = it.m_temp; |
123 | m_end = it.m_end; | 124 | m_end = it.m_end; |
124 | m_record = it.m_record; | 125 | // m_record = it.m_record; |
125 | 126 | ||
126 | return *this; | 127 | return *this; |
127 | } | 128 | } |
128 | 129 | ||
129 | template <class T> | 130 | template <class T> |
130 | T &ORecordListIterator<T>::operator*() { | 131 | T ORecordListIterator<T>::operator*() { |
131 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 132 | // qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
132 | if (!m_end ) | 133 | if (!m_end ) |
133 | m_record = m_temp->find( m_uids[m_current] ); | 134 | m_record = m_temp->find( m_uids[m_current] ); |
134 | else | 135 | else |
135 | m_record = T(); | 136 | m_record = T(); |
136 | 137 | ||
137 | return m_record; | 138 | return m_record; |
138 | } | 139 | } |
139 | 140 | ||
140 | template <class T> | 141 | template <class T> |
141 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 142 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
142 | if (m_current < (int)m_uids.count() ) { | 143 | if (m_current < (int)m_uids.count() ) { |
143 | m_end = false; | 144 | m_end = false; |
144 | ++m_current; | 145 | ++m_current; |
145 | }else | 146 | }else |
146 | m_end = true; | 147 | m_end = true; |
147 | 148 | ||
148 | return *this; | 149 | return *this; |
149 | } | 150 | } |
150 | template <class T> | 151 | template <class T> |
151 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 152 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
152 | if ( m_current > 0 ) { | 153 | if ( m_current > 0 ) { |
153 | --m_current; | 154 | --m_current; |
154 | m_end = false; | 155 | m_end = false; |
155 | } else | 156 | } else |
156 | m_end = true; | 157 | m_end = true; |
157 | 158 | ||
158 | return *this; | 159 | return *this; |
159 | } | 160 | } |
160 | 161 | ||
161 | template <class T> | 162 | template <class T> |
162 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 163 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
163 | 164 | ||
164 | /* if both are at we're the same.... */ | 165 | /* if both are at we're the same.... */ |
165 | if ( m_end == it.m_end ) return true; | 166 | if ( m_end == it.m_end ) return true; |
166 | 167 | ||
167 | if ( m_uids != it.m_uids ) return false; | 168 | if ( m_uids != it.m_uids ) return false; |
168 | if ( m_current != it.m_current ) return false; | 169 | if ( m_current != it.m_current ) return false; |
169 | if ( m_temp != it.m_temp ) return false; | 170 | if ( m_temp != it.m_temp ) return false; |
170 | 171 | ||
171 | return true; | 172 | return true; |
172 | } | 173 | } |
173 | template <class T> | 174 | template <class T> |
174 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 175 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
175 | return !(*this == it ); | 176 | return !(*this == it ); |
176 | } | 177 | } |
177 | template <class T> | 178 | template <class T> |
178 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 179 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
179 | const Base* t ) | 180 | const Base* t ) |
180 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) | 181 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) |
181 | { | 182 | { |
182 | } | 183 | } |
183 | 184 | ||
184 | template <class T> | 185 | template <class T> |
185 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 186 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
186 | const Base* acc ) | 187 | const Base* acc ) |
187 | : m_ids( ids ), m_acc( acc ) | 188 | : m_ids( ids ), m_acc( acc ) |
188 | { | 189 | { |
189 | } | 190 | } |
190 | template <class T> | 191 | template <class T> |
191 | ORecordList<T>::~ORecordList() { | 192 | ORecordList<T>::~ORecordList() { |
192 | /* nothing to do here */ | 193 | /* nothing to do here */ |
193 | } | 194 | } |
194 | template <class T> | 195 | template <class T> |
195 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 196 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
196 | qWarning("ORecordList::begin"); | ||
197 | Iterator it( m_ids, m_acc ); | 197 | Iterator it( m_ids, m_acc ); |
198 | return it; | 198 | return it; |
199 | } | 199 | } |
200 | template <class T> | 200 | template <class T> |
201 | ORecordList<T>::Iterator ORecordList<T>::end() { | 201 | ORecordList<T>::Iterator ORecordList<T>::end() { |
202 | Iterator it( m_ids, m_acc ); | 202 | Iterator it( m_ids, m_acc ); |
203 | it.m_end = true; | 203 | it.m_end = true; |
204 | it.m_current = m_ids.count(); | 204 | it.m_current = m_ids.count(); |
205 | 205 | ||
206 | return it; | 206 | return it; |
207 | } | 207 | } |
208 | #endif | 208 | #endif |
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index b3c14e6..cc46b21 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -1,383 +1,386 @@ | |||
1 | 1 | ||
2 | #include <qobject.h> | 2 | #include <qobject.h> |
3 | #include <qshared.h> | 3 | #include <qshared.h> |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
7 | #include <qpe/palmtopuidgen.h> | 7 | #include <qpe/palmtopuidgen.h> |
8 | #include <qpe/stringutil.h> | 8 | #include <qpe/stringutil.h> |
9 | #include <qpe/palmtoprecord.h> | 9 | #include <qpe/palmtoprecord.h> |
10 | #include <qpe/stringutil.h> | 10 | #include <qpe/stringutil.h> |
11 | #include <qpe/categories.h> | 11 | #include <qpe/categories.h> |
12 | #include <qpe/categoryselect.h> | 12 | #include <qpe/categoryselect.h> |
13 | 13 | ||
14 | 14 | ||
15 | 15 | ||
16 | #include "otodo.h" | 16 | #include "otodo.h" |
17 | 17 | ||
18 | 18 | ||
19 | struct OTodo::OTodoData : public QShared { | 19 | struct OTodo::OTodoData : public QShared { |
20 | OTodoData() : QShared() { | 20 | OTodoData() : QShared() { |
21 | }; | 21 | }; |
22 | 22 | ||
23 | QDate date; | 23 | QDate date; |
24 | bool isCompleted:1; | 24 | bool isCompleted:1; |
25 | bool hasDate:1; | 25 | bool hasDate:1; |
26 | int priority; | 26 | int priority; |
27 | QString desc; | 27 | QString desc; |
28 | QString sum; | 28 | QString sum; |
29 | QMap<QString, QString> extra; | 29 | QMap<QString, QString> extra; |
30 | ushort prog; | 30 | ushort prog; |
31 | bool hasAlarmDateTime :1; | 31 | bool hasAlarmDateTime :1; |
32 | QDateTime alarmDateTime; | 32 | QDateTime alarmDateTime; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | OTodo::OTodo(const OTodo &event ) | 35 | OTodo::OTodo(const OTodo &event ) |
36 | : OPimRecord( event ), data( event.data ) | 36 | : OPimRecord( event ), data( event.data ) |
37 | { | 37 | { |
38 | data->ref(); | 38 | data->ref(); |
39 | qWarning("ref up"); | 39 | // qWarning("ref up"); |
40 | } | 40 | } |
41 | OTodo::~OTodo() { | 41 | OTodo::~OTodo() { |
42 | qWarning("~OTodo " + data->sum ); | 42 | |
43 | // qWarning("~OTodo " ); | ||
43 | if ( data->deref() ) { | 44 | if ( data->deref() ) { |
44 | qWarning("OTodo::dereffing"); | 45 | // qWarning("OTodo::dereffing"); |
45 | delete data; | 46 | delete data; |
46 | data = 0l; | 47 | data = 0l; |
47 | } | 48 | } |
48 | } | 49 | } |
49 | OTodo::OTodo(bool completed, int priority, | 50 | OTodo::OTodo(bool completed, int priority, |
50 | const QArray<int> &category, | 51 | const QArray<int> &category, |
51 | const QString& summary, | 52 | const QString& summary, |
52 | const QString &description, | 53 | const QString &description, |
53 | ushort progress, | 54 | ushort progress, |
54 | bool hasDate, QDate date, int uid ) | 55 | bool hasDate, QDate date, int uid ) |
55 | : OPimRecord( uid ) | 56 | : OPimRecord( uid ) |
56 | { | 57 | { |
57 | qWarning("OTodoData " + summary); | 58 | // qWarning("OTodoData " + summary); |
58 | setCategories( category ); | 59 | setCategories( category ); |
59 | 60 | ||
60 | data = new OTodoData; | 61 | data = new OTodoData; |
61 | 62 | ||
62 | data->date = date; | 63 | data->date = date; |
63 | data->isCompleted = completed; | 64 | data->isCompleted = completed; |
64 | data->hasDate = hasDate; | 65 | data->hasDate = hasDate; |
65 | data->priority = priority; | 66 | data->priority = priority; |
66 | data->sum = summary; | 67 | data->sum = summary; |
67 | data->prog = progress; | 68 | data->prog = progress; |
68 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 69 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
69 | data->hasAlarmDateTime = false; | 70 | data->hasAlarmDateTime = false; |
70 | 71 | ||
71 | } | 72 | } |
72 | OTodo::OTodo(bool completed, int priority, | 73 | OTodo::OTodo(bool completed, int priority, |
73 | const QStringList &category, | 74 | const QStringList &category, |
74 | const QString& summary, | 75 | const QString& summary, |
75 | const QString &description, | 76 | const QString &description, |
76 | ushort progress, | 77 | ushort progress, |
77 | bool hasDate, QDate date, int uid ) | 78 | bool hasDate, QDate date, int uid ) |
78 | : OPimRecord( uid ) | 79 | : OPimRecord( uid ) |
79 | { | 80 | { |
80 | qWarning("OTodoData" + summary); | 81 | // qWarning("OTodoData" + summary); |
81 | setCategories( idsFromString( category.join(";") ) ); | 82 | setCategories( idsFromString( category.join(";") ) ); |
82 | 83 | ||
83 | data = new OTodoData; | 84 | data = new OTodoData; |
84 | data->date = date; | ||
85 | 85 | ||
86 | data->date = date; | ||
86 | data->isCompleted = completed; | 87 | data->isCompleted = completed; |
87 | data->hasDate = hasDate; | 88 | data->hasDate = hasDate; |
88 | data->priority = priority; | 89 | data->priority = priority; |
89 | data->sum = summary; | 90 | data->sum = summary; |
90 | data->prog = progress; | 91 | data->prog = progress; |
91 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 92 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
92 | data->hasAlarmDateTime = false; | 93 | data->hasAlarmDateTime = false; |
93 | 94 | ||
94 | } | 95 | } |
95 | bool OTodo::match( const QRegExp ®Exp )const | 96 | bool OTodo::match( const QRegExp ®Exp )const |
96 | { | 97 | { |
97 | if( QString::number( data->priority ).find( regExp ) != -1 ){ | 98 | if( QString::number( data->priority ).find( regExp ) != -1 ){ |
98 | return true; | 99 | return true; |
99 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ | 100 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ |
100 | return true; | 101 | return true; |
101 | }else if(data->desc.find( regExp ) != -1 ){ | 102 | }else if(data->desc.find( regExp ) != -1 ){ |
102 | return true; | 103 | return true; |
103 | }else if(data->sum.find( regExp ) != -1 ) { | 104 | }else if(data->sum.find( regExp ) != -1 ) { |
104 | return true; | 105 | return true; |
105 | } | 106 | } |
106 | return false; | 107 | return false; |
107 | } | 108 | } |
108 | bool OTodo::isCompleted() const | 109 | bool OTodo::isCompleted() const |
109 | { | 110 | { |
110 | return data->isCompleted; | 111 | return data->isCompleted; |
111 | } | 112 | } |
112 | bool OTodo::hasDueDate() const | 113 | bool OTodo::hasDueDate() const |
113 | { | 114 | { |
114 | return data->hasDate; | 115 | return data->hasDate; |
115 | } | 116 | } |
116 | bool OTodo::hasAlarmDateTime() const | 117 | bool OTodo::hasAlarmDateTime() const |
117 | { | 118 | { |
118 | return data->hasAlarmDateTime; | 119 | return data->hasAlarmDateTime; |
119 | } | 120 | } |
120 | int OTodo::priority()const | 121 | int OTodo::priority()const |
121 | { | 122 | { |
122 | return data->priority; | 123 | return data->priority; |
123 | } | 124 | } |
124 | QString OTodo::summary() const | 125 | QString OTodo::summary() const |
125 | { | 126 | { |
126 | return data->sum; | 127 | return data->sum; |
127 | } | 128 | } |
128 | ushort OTodo::progress() const | 129 | ushort OTodo::progress() const |
129 | { | 130 | { |
130 | return data->prog; | 131 | return data->prog; |
131 | } | 132 | } |
132 | QDate OTodo::dueDate()const | 133 | QDate OTodo::dueDate()const |
133 | { | 134 | { |
134 | return data->date; | 135 | return data->date; |
135 | } | 136 | } |
136 | 137 | ||
137 | QDateTime OTodo::alarmDateTime() const | 138 | QDateTime OTodo::alarmDateTime() const |
138 | { | 139 | { |
139 | return data->alarmDateTime; | 140 | return data->alarmDateTime; |
140 | } | 141 | } |
141 | 142 | ||
142 | QString OTodo::description()const | 143 | QString OTodo::description()const |
143 | { | 144 | { |
144 | return data->desc; | 145 | return data->desc; |
145 | } | 146 | } |
146 | void OTodo::setCompleted( bool completed ) | 147 | void OTodo::setCompleted( bool completed ) |
147 | { | 148 | { |
148 | changeOrModify(); | 149 | changeOrModify(); |
149 | data->isCompleted = completed; | 150 | data->isCompleted = completed; |
150 | } | 151 | } |
151 | void OTodo::setHasDueDate( bool hasDate ) | 152 | void OTodo::setHasDueDate( bool hasDate ) |
152 | { | 153 | { |
153 | changeOrModify(); | 154 | changeOrModify(); |
154 | data->hasDate = hasDate; | 155 | data->hasDate = hasDate; |
155 | } | 156 | } |
156 | void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) | 157 | void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) |
157 | { | 158 | { |
158 | changeOrModify(); | 159 | changeOrModify(); |
159 | data->hasAlarmDateTime = hasAlarmDateTime; | 160 | data->hasAlarmDateTime = hasAlarmDateTime; |
160 | } | 161 | } |
161 | void OTodo::setDescription(const QString &desc ) | 162 | void OTodo::setDescription(const QString &desc ) |
162 | { | 163 | { |
164 | qWarning( "desc " + desc ); | ||
163 | changeOrModify(); | 165 | changeOrModify(); |
164 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); | 166 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); |
165 | } | 167 | } |
166 | void OTodo::setSummary( const QString& sum ) | 168 | void OTodo::setSummary( const QString& sum ) |
167 | { | 169 | { |
168 | changeOrModify(); | 170 | changeOrModify(); |
169 | data->sum = sum; | 171 | data->sum = sum; |
170 | } | 172 | } |
171 | void OTodo::setPriority(int prio ) | 173 | void OTodo::setPriority(int prio ) |
172 | { | 174 | { |
173 | changeOrModify(); | 175 | changeOrModify(); |
174 | data->priority = prio; | 176 | data->priority = prio; |
175 | } | 177 | } |
176 | void OTodo::setDueDate( QDate date ) | 178 | void OTodo::setDueDate( QDate date ) |
177 | { | 179 | { |
178 | changeOrModify(); | 180 | changeOrModify(); |
179 | data->date = date; | 181 | data->date = date; |
180 | } | 182 | } |
181 | void OTodo::setAlarmDateTime( const QDateTime& alarm ) | 183 | void OTodo::setAlarmDateTime( const QDateTime& alarm ) |
182 | { | 184 | { |
183 | changeOrModify(); | 185 | changeOrModify(); |
184 | data->alarmDateTime = alarm; | 186 | data->alarmDateTime = alarm; |
185 | } | 187 | } |
186 | bool OTodo::isOverdue( ) | 188 | bool OTodo::isOverdue( ) |
187 | { | 189 | { |
188 | if( data->hasDate ) | 190 | if( data->hasDate ) |
189 | return QDate::currentDate() > data->date; | 191 | return QDate::currentDate() > data->date; |
190 | return false; | 192 | return false; |
191 | } | 193 | } |
192 | void OTodo::setProgress(ushort progress ) | 194 | void OTodo::setProgress(ushort progress ) |
193 | { | 195 | { |
194 | changeOrModify(); | 196 | changeOrModify(); |
195 | data->prog = progress; | 197 | data->prog = progress; |
196 | } | 198 | } |
197 | QString OTodo::toShortText() const { | 199 | QString OTodo::toShortText() const { |
198 | return summary(); | 200 | return summary(); |
199 | } | 201 | } |
200 | /*! | 202 | /*! |
201 | Returns a richt text string | 203 | Returns a richt text string |
202 | */ | 204 | */ |
203 | QString OTodo::toRichText() const | 205 | QString OTodo::toRichText() const |
204 | { | 206 | { |
205 | QString text; | 207 | QString text; |
206 | QStringList catlist; | 208 | QStringList catlist; |
207 | 209 | ||
208 | // Description of the todo | 210 | // Description of the todo |
209 | if ( !summary().isEmpty() ) { | 211 | if ( !summary().isEmpty() ) { |
210 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; | 212 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; |
211 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; | 213 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
212 | } | 214 | } |
213 | if( !description().isEmpty() ){ | 215 | if( !description().isEmpty() ){ |
214 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 216 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; |
215 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; | 217 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; |
216 | } | 218 | } |
217 | text += "<br><br><br>"; | 219 | text += "<br><br><br>"; |
218 | 220 | ||
219 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | 221 | text += "<b>" + QObject::tr( "Priority:") +" </b>" |
220 | + QString::number( priority() ) + " <br>"; | 222 | + QString::number( priority() ) + " <br>"; |
221 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 223 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
222 | + QString::number( progress() ) + " %<br>"; | 224 | + QString::number( progress() ) + " %<br>"; |
223 | if (hasDueDate() ){ | 225 | if (hasDueDate() ){ |
224 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 226 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
225 | text += dueDate().toString(); | 227 | text += dueDate().toString(); |
226 | text += "<br>"; | 228 | text += "<br>"; |
227 | } | 229 | } |
228 | if (hasAlarmDateTime() ){ | 230 | if (hasAlarmDateTime() ){ |
229 | text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; | 231 | text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; |
230 | text += alarmDateTime().toString(); | 232 | text += alarmDateTime().toString(); |
231 | text += "<br>"; | 233 | text += "<br>"; |
232 | } | 234 | } |
233 | 235 | ||
234 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 236 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
235 | text += categoryNames().join(", "); | 237 | text += categoryNames().join(", "); |
236 | text += "<br>"; | 238 | text += "<br>"; |
237 | 239 | ||
238 | return text; | 240 | return text; |
239 | } | 241 | } |
240 | 242 | ||
241 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 243 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
242 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 244 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
243 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 245 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
244 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 246 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
245 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 247 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
246 | return priority() < toDoEvent.priority(); | 248 | return priority() < toDoEvent.priority(); |
247 | }else{ | 249 | }else{ |
248 | return dueDate() < toDoEvent.dueDate(); | 250 | return dueDate() < toDoEvent.dueDate(); |
249 | } | 251 | } |
250 | } | 252 | } |
251 | return false; | 253 | return false; |
252 | } | 254 | } |
253 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 255 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
254 | { | 256 | { |
255 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 257 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
256 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 258 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
257 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 259 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
258 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 260 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
259 | return priority() <= toDoEvent.priority(); | 261 | return priority() <= toDoEvent.priority(); |
260 | }else{ | 262 | }else{ |
261 | return dueDate() <= toDoEvent.dueDate(); | 263 | return dueDate() <= toDoEvent.dueDate(); |
262 | } | 264 | } |
263 | } | 265 | } |
264 | return true; | 266 | return true; |
265 | } | 267 | } |
266 | bool OTodo::operator>(const OTodo &toDoEvent )const | 268 | bool OTodo::operator>(const OTodo &toDoEvent )const |
267 | { | 269 | { |
268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 270 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 271 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 272 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 273 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
272 | return priority() > toDoEvent.priority(); | 274 | return priority() > toDoEvent.priority(); |
273 | }else{ | 275 | }else{ |
274 | return dueDate() > toDoEvent.dueDate(); | 276 | return dueDate() > toDoEvent.dueDate(); |
275 | } | 277 | } |
276 | } | 278 | } |
277 | return false; | 279 | return false; |
278 | } | 280 | } |
279 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 281 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
280 | { | 282 | { |
281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 283 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 284 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 285 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 286 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
285 | return priority() > toDoEvent.priority(); | 287 | return priority() > toDoEvent.priority(); |
286 | }else{ | 288 | }else{ |
287 | return dueDate() > toDoEvent.dueDate(); | 289 | return dueDate() > toDoEvent.dueDate(); |
288 | } | 290 | } |
289 | } | 291 | } |
290 | return true; | 292 | return true; |
291 | } | 293 | } |
292 | bool OTodo::operator==(const OTodo &toDoEvent )const | 294 | bool OTodo::operator==(const OTodo &toDoEvent )const |
293 | { | 295 | { |
294 | if ( data->priority != toDoEvent.data->priority ) return false; | 296 | if ( data->priority != toDoEvent.data->priority ) return false; |
295 | if ( data->priority != toDoEvent.data->prog ) return false; | 297 | if ( data->priority != toDoEvent.data->prog ) return false; |
296 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 298 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
297 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 299 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
298 | if ( data->date != toDoEvent.data->date ) return false; | 300 | if ( data->date != toDoEvent.data->date ) return false; |
299 | if ( data->sum != toDoEvent.data->sum ) return false; | 301 | if ( data->sum != toDoEvent.data->sum ) return false; |
300 | if ( data->desc != toDoEvent.data->desc ) return false; | 302 | if ( data->desc != toDoEvent.data->desc ) return false; |
301 | if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) | 303 | if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) |
302 | return false; | 304 | return false; |
303 | if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) | 305 | if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) |
304 | return false; | 306 | return false; |
305 | 307 | ||
306 | return OPimRecord::operator==( toDoEvent ); | 308 | return OPimRecord::operator==( toDoEvent ); |
307 | } | 309 | } |
308 | void OTodo::deref() { | 310 | void OTodo::deref() { |
309 | 311 | ||
310 | //qWarning("deref in ToDoEvent"); | 312 | // qWarning("deref in ToDoEvent"); |
311 | if ( data->deref() ) { | 313 | if ( data->deref() ) { |
312 | //qWarning("deleting"); | 314 | // qWarning("deleting"); |
313 | delete data; | 315 | delete data; |
314 | d= 0; | 316 | data= 0; |
315 | } | 317 | } |
316 | } | 318 | } |
317 | OTodo &OTodo::operator=(const OTodo &item ) | 319 | OTodo &OTodo::operator=(const OTodo &item ) |
318 | { | 320 | { |
319 | OPimRecord::operator=( item ); | 321 | // OPimRecord::operator=( item ); |
320 | //qWarning("operator= ref "); | 322 | //qWarning("operator= ref "); |
321 | item.data->ref(); | 323 | item.data->ref(); |
322 | deref(); | 324 | deref(); |
325 | data = item.data; | ||
323 | 326 | ||
324 | return *this; | 327 | return *this; |
325 | } | 328 | } |
326 | 329 | ||
327 | QMap<int, QString> OTodo::toMap() const { | 330 | QMap<int, QString> OTodo::toMap() const { |
328 | QMap<int, QString> map; | 331 | QMap<int, QString> map; |
329 | 332 | ||
330 | map.insert( Uid, QString::number( uid() ) ); | 333 | map.insert( Uid, QString::number( uid() ) ); |
331 | map.insert( Category, idsToString( categories() ) ); | 334 | map.insert( Category, idsToString( categories() ) ); |
332 | map.insert( HasDate, QString::number( data->hasDate ) ); | 335 | map.insert( HasDate, QString::number( data->hasDate ) ); |
333 | map.insert( Completed, QString::number( data->isCompleted ) ); | 336 | map.insert( Completed, QString::number( data->isCompleted ) ); |
334 | map.insert( Description, data->desc ); | 337 | map.insert( Description, data->desc ); |
335 | map.insert( Summary, data->sum ); | 338 | map.insert( Summary, data->sum ); |
336 | map.insert( Priority, QString::number( data->priority ) ); | 339 | map.insert( Priority, QString::number( data->priority ) ); |
337 | map.insert( DateDay, QString::number( data->date.day() ) ); | 340 | map.insert( DateDay, QString::number( data->date.day() ) ); |
338 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 341 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
339 | map.insert( DateYear, QString::number( data->date.year() ) ); | 342 | map.insert( DateYear, QString::number( data->date.year() ) ); |
340 | map.insert( Progress, QString::number( data->prog ) ); | 343 | map.insert( Progress, QString::number( data->prog ) ); |
341 | map.insert( CrossReference, crossToString() ); | 344 | map.insert( CrossReference, crossToString() ); |
342 | map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); | 345 | map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); |
343 | map.insert( AlarmDateTime, data->alarmDateTime.toString() ); | 346 | map.insert( AlarmDateTime, data->alarmDateTime.toString() ); |
344 | 347 | ||
345 | return map; | 348 | return map; |
346 | } | 349 | } |
347 | 350 | ||
348 | QMap<QString, QString> OTodo::toExtraMap()const { | 351 | QMap<QString, QString> OTodo::toExtraMap()const { |
349 | return data->extra; | 352 | return data->extra; |
350 | } | 353 | } |
351 | /** | 354 | /** |
352 | * change or modify looks at the ref count and either | 355 | * change or modify looks at the ref count and either |
353 | * creates a new QShared Object or it can modify it | 356 | * creates a new QShared Object or it can modify it |
354 | * right in place | 357 | * right in place |
355 | */ | 358 | */ |
356 | void OTodo::changeOrModify() { | 359 | void OTodo::changeOrModify() { |
357 | if ( data->count != 1 ) { | 360 | if ( data->count != 1 ) { |
358 | qWarning("changeOrModify"); | 361 | // qWarning("changeOrModify"); |
359 | data->deref(); | 362 | data->deref(); |
360 | OTodoData* d2 = new OTodoData(); | 363 | OTodoData* d2 = new OTodoData(); |
361 | copy(data, d2 ); | 364 | copy(data, d2 ); |
362 | data = d2; | 365 | data = d2; |
363 | } | 366 | } |
364 | } | 367 | } |
365 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 368 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
366 | dest->date = src->date; | 369 | dest->date = src->date; |
367 | dest->isCompleted = src->isCompleted; | 370 | dest->isCompleted = src->isCompleted; |
368 | dest->hasDate = src->hasDate; | 371 | dest->hasDate = src->hasDate; |
369 | dest->priority = src->priority; | 372 | dest->priority = src->priority; |
370 | dest->desc = src->desc; | 373 | dest->desc = src->desc; |
371 | dest->sum = src->sum; | 374 | dest->sum = src->sum; |
372 | dest->extra = src->extra; | 375 | dest->extra = src->extra; |
373 | dest->prog = src->prog; | 376 | dest->prog = src->prog; |
374 | dest->hasAlarmDateTime = src->hasAlarmDateTime; | 377 | dest->hasAlarmDateTime = src->hasAlarmDateTime; |
375 | dest->alarmDateTime = src->alarmDateTime; | 378 | dest->alarmDateTime = src->alarmDateTime; |
376 | } | 379 | } |
377 | QString OTodo::type() const { | 380 | QString OTodo::type() const { |
378 | return QString::fromLatin1("OTodo"); | 381 | return QString::fromLatin1("OTodo"); |
379 | } | 382 | } |
380 | QString OTodo::recordField(int id )const { | 383 | QString OTodo::recordField(int id )const { |
381 | return QString::null; | 384 | return QString::null; |
382 | } | 385 | } |
383 | 386 | ||
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 21756c9..3a72881 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -1,362 +1,362 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | 2 | ||
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | #include <qpe/stringutil.h> | 4 | #include <qpe/stringutil.h> |
5 | #include <qpe/timeconversion.h> | 5 | #include <qpe/timeconversion.h> |
6 | 6 | ||
7 | #include <opie/xmltree.h> | 7 | #include <opie/xmltree.h> |
8 | 8 | ||
9 | #include "otodoaccessxml.h" | 9 | #include "otodoaccessxml.h" |
10 | 10 | ||
11 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 11 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
12 | const QString& fileName ) | 12 | const QString& fileName ) |
13 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 13 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
14 | { | 14 | { |
15 | if (!fileName.isEmpty() ) | 15 | if (!fileName.isEmpty() ) |
16 | m_file = fileName; | 16 | m_file = fileName; |
17 | else | 17 | else |
18 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 18 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
19 | } | 19 | } |
20 | OTodoAccessXML::~OTodoAccessXML() { | 20 | OTodoAccessXML::~OTodoAccessXML() { |
21 | 21 | ||
22 | } | 22 | } |
23 | bool OTodoAccessXML::load() { | 23 | bool OTodoAccessXML::load() { |
24 | m_opened = false; | 24 | m_opened = false; |
25 | m_changed = false; | 25 | m_changed = false; |
26 | /* initialize dict */ | 26 | /* initialize dict */ |
27 | /* | 27 | /* |
28 | * UPDATE dict if you change anything!!! | 28 | * UPDATE dict if you change anything!!! |
29 | */ | 29 | */ |
30 | QAsciiDict<int> dict(15); | 30 | QAsciiDict<int> dict(15); |
31 | dict.setAutoDelete( TRUE ); | 31 | dict.setAutoDelete( TRUE ); |
32 | dict.insert("Categories" , new int(OTodo::Category) ); | 32 | dict.insert("Categories" , new int(OTodo::Category) ); |
33 | dict.insert("Uid" , new int(OTodo::Uid) ); | 33 | dict.insert("Uid" , new int(OTodo::Uid) ); |
34 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 34 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
35 | dict.insert("Completed" , new int(OTodo::Completed) ); | 35 | dict.insert("Completed" , new int(OTodo::Completed) ); |
36 | dict.insert("Description" , new int(OTodo::Description) ); | 36 | dict.insert("Description" , new int(OTodo::Description) ); |
37 | dict.insert("Summary" , new int(OTodo::Summary) ); | 37 | dict.insert("Summary" , new int(OTodo::Summary) ); |
38 | dict.insert("Priority" , new int(OTodo::Priority) ); | 38 | dict.insert("Priority" , new int(OTodo::Priority) ); |
39 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 39 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
40 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 40 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
41 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 41 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
42 | dict.insert("Progress" , new int(OTodo::Progress) ); | 42 | dict.insert("Progress" , new int(OTodo::Progress) ); |
43 | dict.insert("Completed", new int(OTodo::Completed) ); | 43 | dict.insert("Completed", new int(OTodo::Completed) ); |
44 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 44 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
45 | dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 45 | dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
46 | dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 46 | dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
47 | 47 | ||
48 | Opie::XMLElement *root = Opie::XMLElement::load( m_file ); | 48 | Opie::XMLElement *root = Opie::XMLElement::load( m_file ); |
49 | int day, year, month; | 49 | int day, year, month; |
50 | day = year = month = -1; | 50 | day = year = month = -1; |
51 | 51 | ||
52 | /* if opened */ | 52 | /* if opened */ |
53 | if ( root != 0l ) { | 53 | if ( root != 0l ) { |
54 | Opie::XMLElement *element = root->firstChild(); | 54 | Opie::XMLElement *element = root->firstChild(); |
55 | if ( element == 0l ) | 55 | if ( element == 0l ) |
56 | return false; | 56 | return false; |
57 | 57 | ||
58 | element = element->firstChild(); | 58 | element = element->firstChild(); |
59 | 59 | ||
60 | while ( element ) { | 60 | while ( element ) { |
61 | if ( element->tagName() != QString::fromLatin1("Task") ) { | 61 | if ( element->tagName() != QString::fromLatin1("Task") ) { |
62 | element = element->nextChild(); | 62 | element = element->nextChild(); |
63 | continue; | 63 | continue; |
64 | } | 64 | } |
65 | /* here is the right element for a task */ | 65 | /* here is the right element for a task */ |
66 | OTodo ev = todo( &dict, element ); | 66 | OTodo ev = todo( &dict, element ); |
67 | m_events.insert( ev.uid(), ev ); | 67 | m_events.insert( ev.uid(), ev ); |
68 | 68 | ||
69 | element = element->nextChild(); | 69 | element = element->nextChild(); |
70 | } | 70 | } |
71 | return true; | ||
72 | }else { | 71 | }else { |
73 | qWarning("could not parse"); | 72 | qWarning("could not parse"); |
74 | return false;; | 73 | return false;; |
75 | } | 74 | } |
76 | delete root; | 75 | delete root; |
77 | 76 | ||
78 | m_opened = true; | 77 | m_opened = true; |
78 | qWarning("Access %d" + m_events.count() ); | ||
79 | return true; | 79 | return true; |
80 | } | 80 | } |
81 | bool OTodoAccessXML::reload() { | 81 | bool OTodoAccessXML::reload() { |
82 | return load(); | 82 | return load(); |
83 | } | 83 | } |
84 | bool OTodoAccessXML::save() { | 84 | bool OTodoAccessXML::save() { |
85 | if (!m_opened || !m_changed ) | 85 | if (!m_opened || !m_changed ) |
86 | return true; | 86 | return true; |
87 | QString strNewFile = m_file + ".new"; | 87 | QString strNewFile = m_file + ".new"; |
88 | QFile f( strNewFile ); | 88 | QFile f( strNewFile ); |
89 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 89 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
90 | return false; | 90 | return false; |
91 | 91 | ||
92 | int written; | 92 | int written; |
93 | QString out; | 93 | QString out; |
94 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 94 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
95 | 95 | ||
96 | // for all todos | 96 | // for all todos |
97 | QMap<int, OTodo>::Iterator it; | 97 | QMap<int, OTodo>::Iterator it; |
98 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 98 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
99 | out+= "<Task " + toString( (*it) ) + " />\n"; | 99 | out+= "<Task " + toString( (*it) ) + " />\n"; |
100 | QCString cstr = out.utf8(); | 100 | QCString cstr = out.utf8(); |
101 | written = f.writeBlock( cstr.data(), cstr.length() ); | 101 | written = f.writeBlock( cstr.data(), cstr.length() ); |
102 | 102 | ||
103 | /* less written then we wanted */ | 103 | /* less written then we wanted */ |
104 | if ( written != (int)cstr.length() ) { | 104 | if ( written != (int)cstr.length() ) { |
105 | f.close(); | 105 | f.close(); |
106 | QFile::remove( strNewFile ); | 106 | QFile::remove( strNewFile ); |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | out = QString::null; | 109 | out = QString::null; |
110 | } | 110 | } |
111 | 111 | ||
112 | out += "</Tasks>"; | 112 | out += "</Tasks>"; |
113 | QCString cstr = out.utf8(); | 113 | QCString cstr = out.utf8(); |
114 | written = f.writeBlock( cstr.data(), cstr.length() ); | 114 | written = f.writeBlock( cstr.data(), cstr.length() ); |
115 | 115 | ||
116 | if ( written != (int)cstr.length() ) { | 116 | if ( written != (int)cstr.length() ) { |
117 | f.close(); | 117 | f.close(); |
118 | QFile::remove( strNewFile ); | 118 | QFile::remove( strNewFile ); |
119 | return false; | 119 | return false; |
120 | } | 120 | } |
121 | /* flush before renaming */ | 121 | /* flush before renaming */ |
122 | f.close(); | 122 | f.close(); |
123 | 123 | ||
124 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 124 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
125 | qWarning("error renaming"); | 125 | qWarning("error renaming"); |
126 | QFile::remove( strNewFile ); | 126 | QFile::remove( strNewFile ); |
127 | } | 127 | } |
128 | 128 | ||
129 | m_changed = false; | 129 | m_changed = false; |
130 | return true; | 130 | return true; |
131 | } | 131 | } |
132 | QArray<int> OTodoAccessXML::allRecords()const { | 132 | QArray<int> OTodoAccessXML::allRecords()const { |
133 | QArray<int> ids( m_events.count() ); | 133 | QArray<int> ids( m_events.count() ); |
134 | QMap<int, OTodo>::ConstIterator it; | 134 | QMap<int, OTodo>::ConstIterator it; |
135 | int i = 0; | 135 | int i = 0; |
136 | 136 | ||
137 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 137 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
138 | ids[i] = it.key(); | 138 | ids[i] = it.key(); |
139 | i++; | 139 | i++; |
140 | } | 140 | } |
141 | return ids; | 141 | return ids; |
142 | } | 142 | } |
143 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) { | 143 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) { |
144 | QArray<int> ids(0); | 144 | QArray<int> ids(0); |
145 | return ids; | 145 | return ids; |
146 | } | 146 | } |
147 | OTodo OTodoAccessXML::find( int uid )const { | 147 | OTodo OTodoAccessXML::find( int uid )const { |
148 | OTodo todo; | 148 | OTodo todo; |
149 | todo.setUid( 0 ); // isEmpty() | 149 | todo.setUid( 0 ); // isEmpty() |
150 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); | 150 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); |
151 | if ( it != m_events.end() ) | 151 | if ( it != m_events.end() ) |
152 | todo = it.data(); | 152 | todo = it.data(); |
153 | 153 | ||
154 | return todo; | 154 | return todo; |
155 | } | 155 | } |
156 | void OTodoAccessXML::clear() { | 156 | void OTodoAccessXML::clear() { |
157 | if (m_opened ) | 157 | if (m_opened ) |
158 | m_changed = true; | 158 | m_changed = true; |
159 | 159 | ||
160 | m_events.clear(); | 160 | m_events.clear(); |
161 | } | 161 | } |
162 | bool OTodoAccessXML::add( const OTodo& todo ) { | 162 | bool OTodoAccessXML::add( const OTodo& todo ) { |
163 | m_changed = true; | 163 | m_changed = true; |
164 | m_events.insert( todo.uid(), todo ); | 164 | m_events.insert( todo.uid(), todo ); |
165 | 165 | ||
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | bool OTodoAccessXML::remove( int uid ) { | 168 | bool OTodoAccessXML::remove( int uid ) { |
169 | m_changed = true; | 169 | m_changed = true; |
170 | m_events.remove( uid ); | 170 | m_events.remove( uid ); |
171 | 171 | ||
172 | return true; | 172 | return true; |
173 | } | 173 | } |
174 | bool OTodoAccessXML::replace( const OTodo& todo) { | 174 | bool OTodoAccessXML::replace( const OTodo& todo) { |
175 | m_changed = true; | 175 | m_changed = true; |
176 | m_events.replace( todo.uid(), todo ); | 176 | m_events.replace( todo.uid(), todo ); |
177 | 177 | ||
178 | return true; | 178 | return true; |
179 | } | 179 | } |
180 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, | 180 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, |
181 | const QDate& end, | 181 | const QDate& end, |
182 | bool includeNoDates ) { | 182 | bool includeNoDates ) { |
183 | QArray<int> ids( m_events.count() ); | 183 | QArray<int> ids( m_events.count() ); |
184 | QMap<int, OTodo>::Iterator it; | 184 | QMap<int, OTodo>::Iterator it; |
185 | 185 | ||
186 | int i = 0; | 186 | int i = 0; |
187 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 187 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
188 | if ( !it.data().hasDueDate() ) { | 188 | if ( !it.data().hasDueDate() ) { |
189 | if ( includeNoDates ) { | 189 | if ( includeNoDates ) { |
190 | ids[i] = it.key(); | 190 | ids[i] = it.key(); |
191 | i++; | 191 | i++; |
192 | } | 192 | } |
193 | }else if ( it.data().dueDate() >= start && | 193 | }else if ( it.data().dueDate() >= start && |
194 | it.data().dueDate() <= end ) { | 194 | it.data().dueDate() <= end ) { |
195 | ids[i] = it.key(); | 195 | ids[i] = it.key(); |
196 | i++; | 196 | i++; |
197 | } | 197 | } |
198 | } | 198 | } |
199 | ids.resize( i ); | 199 | ids.resize( i ); |
200 | return ids; | 200 | return ids; |
201 | } | 201 | } |
202 | QArray<int> OTodoAccessXML::overDue() { | 202 | QArray<int> OTodoAccessXML::overDue() { |
203 | QArray<int> ids( m_events.count() ); | 203 | QArray<int> ids( m_events.count() ); |
204 | int i = 0; | 204 | int i = 0; |
205 | 205 | ||
206 | QMap<int, OTodo>::Iterator it; | 206 | QMap<int, OTodo>::Iterator it; |
207 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 207 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
208 | if ( it.data().isOverdue() ) { | 208 | if ( it.data().isOverdue() ) { |
209 | ids[i] = it.key(); | 209 | ids[i] = it.key(); |
210 | i++; | 210 | i++; |
211 | } | 211 | } |
212 | } | 212 | } |
213 | ids.resize( i ); | 213 | ids.resize( i ); |
214 | return ids; | 214 | return ids; |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | /* private */ | 218 | /* private */ |
219 | OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const { | 219 | OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const { |
220 | qWarning("parse to do from XMLElement" ); | 220 | qWarning("parse to do from XMLElement" ); |
221 | OTodo ev; | 221 | OTodo ev; |
222 | QMap<QString, QString> attributes = element->attributes(); | 222 | QMap<QString, QString> attributes = element->attributes(); |
223 | QMap<QString, QString>::Iterator it; | 223 | QMap<QString, QString>::Iterator it; |
224 | 224 | ||
225 | int *find=0; | 225 | int *find=0; |
226 | int day, month, year; | 226 | int day, month, year; |
227 | day = month = year = -1; | 227 | day = month = year = -1; |
228 | for ( it = attributes.begin(); it != attributes.end(); ++it ) { | 228 | for ( it = attributes.begin(); it != attributes.end(); ++it ) { |
229 | find = (*dict)[ it.key() ]; | 229 | find = (*dict)[ it.key() ]; |
230 | if (!find ) { | 230 | if (!find ) { |
231 | qWarning("Unknown option" + it.key() ); | 231 | qWarning("Unknown option" + it.key() ); |
232 | ev.setCustomField( it.key(), it.data() ); | 232 | ev.setCustomField( it.key(), it.data() ); |
233 | continue; | 233 | continue; |
234 | } | 234 | } |
235 | 235 | ||
236 | switch( *find ) { | 236 | switch( *find ) { |
237 | case OTodo::Uid: | 237 | case OTodo::Uid: |
238 | ev.setUid( it.data().toInt() ); | 238 | ev.setUid( it.data().toInt() ); |
239 | break; | 239 | break; |
240 | case OTodo::Category: | 240 | case OTodo::Category: |
241 | ev.setCategories( ev.idsFromString( it.data() ) ); | 241 | ev.setCategories( ev.idsFromString( it.data() ) ); |
242 | break; | 242 | break; |
243 | case OTodo::HasDate: | 243 | case OTodo::HasDate: |
244 | ev.setHasDueDate( it.data().toInt() ); | 244 | ev.setHasDueDate( it.data().toInt() ); |
245 | break; | 245 | break; |
246 | case OTodo::Completed: | 246 | case OTodo::Completed: |
247 | ev.setCompleted( it.data().toInt() ); | 247 | ev.setCompleted( it.data().toInt() ); |
248 | break; | 248 | break; |
249 | case OTodo::Description: | 249 | case OTodo::Description: |
250 | ev.setDescription( it.data() ); | 250 | ev.setDescription( it.data() ); |
251 | break; | 251 | break; |
252 | case OTodo::Summary: | 252 | case OTodo::Summary: |
253 | ev.setSummary( it.data() ); | 253 | ev.setSummary( it.data() ); |
254 | break; | 254 | break; |
255 | case OTodo::Priority: | 255 | case OTodo::Priority: |
256 | ev.setPriority( it.data().toInt() ); | 256 | ev.setPriority( it.data().toInt() ); |
257 | break; | 257 | break; |
258 | case OTodo::DateDay: | 258 | case OTodo::DateDay: |
259 | day = it.data().toInt(); | 259 | day = it.data().toInt(); |
260 | break; | 260 | break; |
261 | case OTodo::DateMonth: | 261 | case OTodo::DateMonth: |
262 | month = it.data().toInt(); | 262 | month = it.data().toInt(); |
263 | break; | 263 | break; |
264 | case OTodo::DateYear: | 264 | case OTodo::DateYear: |
265 | year = it.data().toInt(); | 265 | year = it.data().toInt(); |
266 | break; | 266 | break; |
267 | case OTodo::Progress: | 267 | case OTodo::Progress: |
268 | ev.setProgress( it.data().toInt() ); | 268 | ev.setProgress( it.data().toInt() ); |
269 | break; | 269 | break; |
270 | case OTodo::CrossReference: | 270 | case OTodo::CrossReference: |
271 | { | 271 | { |
272 | /* | 272 | /* |
273 | * A cross refernce looks like | 273 | * A cross refernce looks like |
274 | * appname,id;appname,id | 274 | * appname,id;appname,id |
275 | * we need to split it up | 275 | * we need to split it up |
276 | */ | 276 | */ |
277 | QStringList refs = QStringList::split(';', it.data() ); | 277 | QStringList refs = QStringList::split(';', it.data() ); |
278 | QStringList::Iterator strIt; | 278 | QStringList::Iterator strIt; |
279 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 279 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
280 | int pos = (*strIt).find(','); | 280 | int pos = (*strIt).find(','); |
281 | if ( pos > -1 ) | 281 | if ( pos > -1 ) |
282 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 282 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
283 | 283 | ||
284 | } | 284 | } |
285 | break; | 285 | break; |
286 | } | 286 | } |
287 | case OTodo::HasAlarmDateTime: | 287 | case OTodo::HasAlarmDateTime: |
288 | ev.setHasAlarmDateTime( it.data().toInt() ); | 288 | ev.setHasAlarmDateTime( it.data().toInt() ); |
289 | break; | 289 | break; |
290 | case OTodo::AlarmDateTime: { | 290 | case OTodo::AlarmDateTime: { |
291 | /* this sounds better ;) zecke */ | 291 | /* this sounds better ;) zecke */ |
292 | ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) ); | 292 | ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) ); |
293 | break; | 293 | break; |
294 | } | 294 | } |
295 | default: | 295 | default: |
296 | break; | 296 | break; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | if ( ev.hasDueDate() ) { | 299 | if ( ev.hasDueDate() ) { |
300 | QDate date( year, month, day ); | 300 | QDate date( year, month, day ); |
301 | ev.setDueDate( date ); | 301 | ev.setDueDate( date ); |
302 | } | 302 | } |
303 | 303 | ||
304 | return ev; | 304 | return ev; |
305 | } | 305 | } |
306 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 306 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
307 | QString str; | 307 | QString str; |
308 | 308 | ||
309 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 309 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
310 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 310 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
311 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 311 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
312 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 312 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
313 | 313 | ||
314 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 314 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
315 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 315 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
316 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 316 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
317 | 317 | ||
318 | if ( ev.hasDueDate() ) { | 318 | if ( ev.hasDueDate() ) { |
319 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 319 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
320 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 320 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
321 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 321 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
322 | } | 322 | } |
323 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 323 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
324 | 324 | ||
325 | // append the extra options | 325 | // append the extra options |
326 | /* FIXME Qtopia::Record this is currently not | 326 | /* FIXME Qtopia::Record this is currently not |
327 | * possible you can set custom fields | 327 | * possible you can set custom fields |
328 | * but don' iterate over the list | 328 | * but don' iterate over the list |
329 | * I may do #define private protected | 329 | * I may do #define private protected |
330 | * for this case - cough --zecke | 330 | * for this case - cough --zecke |
331 | */ | 331 | */ |
332 | /* | 332 | /* |
333 | QMap<QString, QString> extras = ev.extras(); | 333 | QMap<QString, QString> extras = ev.extras(); |
334 | QMap<QString, QString>::Iterator extIt; | 334 | QMap<QString, QString>::Iterator extIt; |
335 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 335 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
336 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 336 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
337 | */ | 337 | */ |
338 | // cross refernce | 338 | // cross refernce |
339 | QStringList list = ev.relatedApps(); | 339 | QStringList list = ev.relatedApps(); |
340 | QStringList::Iterator listIt; | 340 | QStringList::Iterator listIt; |
341 | QString refs; | 341 | QString refs; |
342 | str += "CrossReference=\""; | 342 | str += "CrossReference=\""; |
343 | bool added = false; | 343 | bool added = false; |
344 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { | 344 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { |
345 | added = true; | 345 | added = true; |
346 | QArray<int> ints = ev.relations( (*listIt) ); | 346 | QArray<int> ints = ev.relations( (*listIt) ); |
347 | for ( uint i = 0; i< ints.count(); i++ ) { | 347 | for ( uint i = 0; i< ints.count(); i++ ) { |
348 | str += (*listIt) + "," + QString::number( i ) + ";"; | 348 | str += (*listIt) + "," + QString::number( i ) + ";"; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | if ( added ) | 351 | if ( added ) |
352 | str = str.remove( str.length()-1, 1 ); | 352 | str = str.remove( str.length()-1, 1 ); |
353 | 353 | ||
354 | str += "\" "; | 354 | str += "\" "; |
355 | 355 | ||
356 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; | 356 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; |
357 | 357 | ||
358 | return str; | 358 | return str; |
359 | } | 359 | } |
360 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 360 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
361 | return Qtopia::Record::idsToString( ints ); | 361 | return Qtopia::Record::idsToString( ints ); |
362 | } | 362 | } |