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