summaryrefslogtreecommitdiff
path: root/libopie/todoevent.cpp
Unidiff
Diffstat (limited to 'libopie/todoevent.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/todoevent.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index fb7073c..b35ac9d 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -1,269 +1,282 @@
1 1
2#include <opie/todoevent.h> 2#include <opie/todoevent.h>
3 3
4 4
5#include <qpe/palmtopuidgen.h> 5#include <qpe/palmtopuidgen.h>
6#include <qpe/stringutil.h> 6#include <qpe/stringutil.h>
7#include <qpe/palmtoprecord.h> 7#include <qpe/palmtoprecord.h>
8 8
9#include <qpe/stringutil.h> 9#include <qpe/stringutil.h>
10#include <qpe/categories.h> 10#include <qpe/categories.h>
11#include <qpe/categoryselect.h> 11#include <qpe/categoryselect.h>
12 12
13#include <qobject.h> 13#include <qobject.h>
14 14
15ToDoEvent::ToDoEvent(const ToDoEvent &event ) 15ToDoEvent::ToDoEvent(const ToDoEvent &event )
16{ 16{
17 *this = event; 17 *this = event;
18} 18}
19 19
20ToDoEvent::ToDoEvent(bool completed, int priority, 20ToDoEvent::ToDoEvent(bool completed, int priority,
21 const QStringList &category, 21 const QStringList &category,
22 const QString& summary, 22 const QString& summary,
23 const QString &description, 23 const QString &description,
24 ushort progress,
24 bool hasDate, QDate date, int uid ) 25 bool hasDate, QDate date, int uid )
25{ 26{
26 m_date = date; 27 m_date = date;
27 m_isCompleted = completed; 28 m_isCompleted = completed;
28 m_hasDate = hasDate; 29 m_hasDate = hasDate;
29 m_priority = priority; 30 m_priority = priority;
30 m_category = category; 31 m_category = category;
31 m_sum = summary; 32 m_sum = summary;
33 m_prog = progress;
32 m_desc = Qtopia::simplifyMultiLineSpace(description ); 34 m_desc = Qtopia::simplifyMultiLineSpace(description );
33 if (uid == -1 ) { 35 if (uid == -1 ) {
34 Qtopia::UidGen *uidgen = new Qtopia::UidGen(); 36 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
35 uid = uidgen->generate(); 37 uid = uidgen->generate();
36 delete uidgen; 38 delete uidgen;
37 }// generate the ids 39 }// generate the ids
38 m_uid = uid; 40 m_uid = uid;
39} 41}
40QArray<int> ToDoEvent::categories()const 42QArray<int> ToDoEvent::categories()const
41{ 43{
42 QArray<int> array(m_category.count() ); // currently the datebook can be only in one category 44 QArray<int> array(m_category.count() ); // currently the datebook can be only in one category
43 array = Qtopia::Record::idsFromString( m_category.join(";") ); 45 array = Qtopia::Record::idsFromString( m_category.join(";") );
44 return array; 46 return array;
45} 47}
46bool ToDoEvent::match( const QRegExp &regExp )const 48bool ToDoEvent::match( const QRegExp &regExp )const
47{ 49{
48 if( QString::number( m_priority ).find( regExp ) != -1 ){ 50 if( QString::number( m_priority ).find( regExp ) != -1 ){
49 return true; 51 return true;
50 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ 52 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
51 return true; 53 return true;
52 }else if(m_desc.find( regExp ) != -1 ){ 54 }else if(m_desc.find( regExp ) != -1 ){
53 return true; 55 return true;
54 } 56 }
55 return false; 57 return false;
56} 58}
57bool ToDoEvent::isCompleted() const 59bool ToDoEvent::isCompleted() const
58{ 60{
59 return m_isCompleted; 61 return m_isCompleted;
60} 62}
61bool ToDoEvent::hasDate() const 63bool ToDoEvent::hasDate() const
62{ 64{
63 return m_hasDate; 65 return m_hasDate;
64} 66}
65int ToDoEvent::priority()const 67int ToDoEvent::priority()const
66{ 68{
67 return m_priority; 69 return m_priority;
68} 70}
69QStringList ToDoEvent::allCategories()const 71QStringList ToDoEvent::allCategories()const
70{ 72{
71 return m_category; 73 return m_category;
72} 74}
73QString ToDoEvent::extra(const QString& )const 75QString ToDoEvent::extra(const QString& )const
74{ 76{
75 return QString::null; 77 return QString::null;
76} 78}
77QString ToDoEvent::summary() const 79QString ToDoEvent::summary() const
78{ 80{
79 return m_sum; 81 return m_sum;
80} 82}
83ushort ToDoEvent::progress() const
84{
85 return m_prog;
86}
81void ToDoEvent::insertCategory(const QString &str ) 87void ToDoEvent::insertCategory(const QString &str )
82{ 88{
83 m_category.append( str ); 89 m_category.append( str );
84} 90}
85void ToDoEvent::clearCategories() 91void ToDoEvent::clearCategories()
86{ 92{
87 m_category.clear(); 93 m_category.clear();
88} 94}
89void ToDoEvent::setCategories(const QStringList &list ) 95void ToDoEvent::setCategories(const QStringList &list )
90{ 96{
91 m_category = list; 97 m_category = list;
92} 98}
93QDate ToDoEvent::date()const 99QDate ToDoEvent::date()const
94{ 100{
95 return m_date; 101 return m_date;
96} 102}
97 103
98QString ToDoEvent::description()const 104QString ToDoEvent::description()const
99{ 105{
100 return m_desc; 106 return m_desc;
101} 107}
102void ToDoEvent::setCompleted( bool completed ) 108void ToDoEvent::setCompleted( bool completed )
103{ 109{
104 m_isCompleted = completed; 110 m_isCompleted = completed;
105} 111}
106void ToDoEvent::setHasDate( bool hasDate ) 112void ToDoEvent::setHasDate( bool hasDate )
107{ 113{
108 m_hasDate = hasDate; 114 m_hasDate = hasDate;
109} 115}
110void ToDoEvent::setDescription(const QString &desc ) 116void ToDoEvent::setDescription(const QString &desc )
111{ 117{
112 m_desc = Qtopia::simplifyMultiLineSpace(desc ); 118 m_desc = Qtopia::simplifyMultiLineSpace(desc );
113} 119}
114void ToDoEvent::setExtra( const QString&, const QString& ) 120void ToDoEvent::setExtra( const QString&, const QString& )
115{ 121{
116 122
117} 123}
118void ToDoEvent::setSummary( const QString& sum ) 124void ToDoEvent::setSummary( const QString& sum )
119{ 125{
120 m_sum = sum; 126 m_sum = sum;
121} 127}
122void ToDoEvent::setCategory( const QString &cat ) 128void ToDoEvent::setCategory( const QString &cat )
123{ 129{
124 qWarning("setCategory %s", cat.latin1() ); 130 qWarning("setCategory %s", cat.latin1() );
125 m_category.clear(); 131 m_category.clear();
126 m_category << cat; 132 m_category << cat;
127} 133}
128void ToDoEvent::setPriority(int prio ) 134void ToDoEvent::setPriority(int prio )
129{ 135{
130 m_priority = prio; 136 m_priority = prio;
131} 137}
132void ToDoEvent::setDate( QDate date ) 138void ToDoEvent::setDate( QDate date )
133{ 139{
134 m_date = date; 140 m_date = date;
135} 141}
136bool ToDoEvent::isOverdue( ) 142bool ToDoEvent::isOverdue( )
137{ 143{
138 if( m_hasDate ) 144 if( m_hasDate )
139 return QDate::currentDate() > m_date; 145 return QDate::currentDate() > m_date;
140 return false; 146 return false;
141} 147}
142 148void ToDoEvent::setProgress(ushort progress )
149{
150 m_prog = progress;
151}
143/*! 152/*!
144 Returns a richt text string 153 Returns a richt text string
145*/ 154*/
146QString ToDoEvent::richText() const 155QString ToDoEvent::richText() const
147{ 156{
148 QString text; 157 QString text;
149 QStringList catlist; 158 QStringList catlist;
150 159
151 // Description of the todo 160 // Description of the todo
152 if ( !description().isEmpty() ){ 161 if ( !description().isEmpty() ){
153 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 162 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
154 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 163 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
155 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 164 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
156 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 165 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br><br><br>";
157 } 166 }
158 text += "<b>" + QObject::tr( "Priority:") +" </b>" 167 text += "<b>" + QObject::tr( "Priority:") +" </b>"
159 + QString::number( priority() ) + "<br>"; 168 + QString::number( priority() ) + " <br>";
169 text += "<b>" + QObject::tr( "Progress:") + " </b>"
170 + QString::number( progress() ) + " %<br>";
160 if (hasDate() ){ 171 if (hasDate() ){
161 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 172 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
162 text += date().toString(); 173 text += date().toString();
163 text += "<br>"; 174 text += "<br>";
164 } 175 }
165 176
166 // Open database of all categories and get the list of 177 // Open database of all categories and get the list of
167 // the categories this todoevent belongs to. 178 // the categories this todoevent belongs to.
168 // Then print them... 179 // Then print them...
169 // I am not sure whether there is no better way doing this !? 180 // I am not sure whether there is no better way doing this !?
170 Categories catdb; 181 Categories catdb;
171 bool firstloop = true; 182 bool firstloop = true;
172 catdb.load( categoryFileName() ); 183 catdb.load( categoryFileName() );
173 catlist = allCategories(); 184 catlist = allCategories();
174 185
175 text += "<b>" + QObject::tr( "Category:") + "</b> "; 186 text += "<b>" + QObject::tr( "Category:") + "</b> ";
176 for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { 187 for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) {
177 if (!firstloop){ 188 if (!firstloop){
178 text += ", "; 189 text += ", ";
179 } 190 }
180 firstloop = false; 191 firstloop = false;
181 text += catdb.label ("todo", (*it).toInt()); 192 text += catdb.label ("todo", (*it).toInt());
182 } 193 }
183 text += "<br>"; 194 text += "<br>";
184 return text; 195 return text;
185} 196}
186 197
187bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ 198bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
188 if( !hasDate() && !toDoEvent.hasDate() ) return true; 199 if( !hasDate() && !toDoEvent.hasDate() ) return true;
189 if( !hasDate() && toDoEvent.hasDate() ) return true; 200 if( !hasDate() && toDoEvent.hasDate() ) return false;
190 if( hasDate() && toDoEvent.hasDate() ){ 201 if( hasDate() && toDoEvent.hasDate() ){
191 if( date() == toDoEvent.date() ){ // let's the priority decide 202 if( date() == toDoEvent.date() ){ // let's the priority decide
192 return priority() < toDoEvent.priority(); 203 return priority() < toDoEvent.priority();
193 }else{ 204 }else{
194 return date() < toDoEvent.date(); 205 return date() < toDoEvent.date();
195 } 206 }
196 } 207 }
197 return false; 208 return false;
198} 209}
199bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const 210bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const
200{ 211{
201 if( !hasDate() && !toDoEvent.hasDate() ) return true; 212 if( !hasDate() && !toDoEvent.hasDate() ) return true;
202 if( !hasDate() && toDoEvent.hasDate() ) return true; 213 if( !hasDate() && toDoEvent.hasDate() ) return true;
203 if( hasDate() && toDoEvent.hasDate() ){ 214 if( hasDate() && toDoEvent.hasDate() ){
204 if( date() == toDoEvent.date() ){ // let's the priority decide 215 if( date() == toDoEvent.date() ){ // let's the priority decide
205 return priority() <= toDoEvent.priority(); 216 return priority() <= toDoEvent.priority();
206 }else{ 217 }else{
207 return date() <= toDoEvent.date(); 218 return date() <= toDoEvent.date();
208 } 219 }
209 } 220 }
210 return true; 221 return true;
211} 222}
212bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const 223bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const
213{ 224{
214 if( !hasDate() && !toDoEvent.hasDate() ) return false; 225 if( !hasDate() && !toDoEvent.hasDate() ) return false;
215 if( !hasDate() && toDoEvent.hasDate() ) return false; 226 if( !hasDate() && toDoEvent.hasDate() ) return false;
216 if( hasDate() && toDoEvent.hasDate() ){ 227 if( hasDate() && toDoEvent.hasDate() ){
217 if( date() == toDoEvent.date() ){ // let's the priority decide 228 if( date() == toDoEvent.date() ){ // let's the priority decide
218 return priority() > toDoEvent.priority(); 229 return priority() > toDoEvent.priority();
219 }else{ 230 }else{
220 return date() > toDoEvent.date(); 231 return date() > toDoEvent.date();
221 } 232 }
222 } 233 }
223 return false; 234 return false;
224} 235}
225bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const 236bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const
226{ 237{
227 if( !hasDate() && !toDoEvent.hasDate() ) return true; 238 if( !hasDate() && !toDoEvent.hasDate() ) return true;
228 if( !hasDate() && toDoEvent.hasDate() ) return false; 239 if( !hasDate() && toDoEvent.hasDate() ) return false;
229 if( hasDate() && toDoEvent.hasDate() ){ 240 if( hasDate() && toDoEvent.hasDate() ){
230 if( date() == toDoEvent.date() ){ // let's the priority decide 241 if( date() == toDoEvent.date() ){ // let's the priority decide
231 return priority() > toDoEvent.priority(); 242 return priority() > toDoEvent.priority();
232 }else{ 243 }else{
233 return date() > toDoEvent.date(); 244 return date() > toDoEvent.date();
234 } 245 }
235 } 246 }
236 return true; 247 return true;
237} 248}
238bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const 249bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const
239{ 250{
240 if( m_priority == toDoEvent.m_priority && 251 if( m_priority == toDoEvent.m_priority &&
252 m_priority == toDoEvent.m_prog &&
241 m_isCompleted == toDoEvent.m_isCompleted && 253 m_isCompleted == toDoEvent.m_isCompleted &&
242 m_hasDate == toDoEvent.m_hasDate && 254 m_hasDate == toDoEvent.m_hasDate &&
243 m_date == toDoEvent.m_date && 255 m_date == toDoEvent.m_date &&
244 m_category == toDoEvent.m_category && 256 m_category == toDoEvent.m_category &&
245 m_sum == toDoEvent.m_sum && 257 m_sum == toDoEvent.m_sum &&
246 m_desc == toDoEvent.m_desc ) 258 m_desc == toDoEvent.m_desc )
247 return true; 259 return true;
248 return false; 260 return false;
249} 261}
250ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) 262ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item )
251{ 263{
252 m_date = item.m_date; 264 m_date = item.m_date;
253 m_isCompleted = item.m_isCompleted; 265 m_isCompleted = item.m_isCompleted;
254 m_hasDate = item.m_hasDate; 266 m_hasDate = item.m_hasDate;
255 m_priority = item.m_priority; 267 m_priority = item.m_priority;
256 m_category = item.m_category; 268 m_category = item.m_category;
257 m_desc = item.m_desc; 269 m_desc = item.m_desc;
258 m_uid = item.m_uid; 270 m_uid = item.m_uid;
259 m_sum = item.m_sum; 271 m_sum = item.m_sum;
272 m_prog = item.m_prog;
260 return *this; 273 return *this;
261} 274}
262 275
263 276
264 277
265 278
266 279
267 280
268 281
269 282