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