author | zecke <zecke> | 2002-03-20 21:45:51 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-20 21:45:51 (UTC) |
commit | e9189f8d0cc46b0532fdcbcb2377ae3d108666d5 (patch) (unidiff) | |
tree | 20af6104c262510595b82e619ee69b0958596ddd /libopie | |
parent | 0b39bb8d62f67a86128a6bd16afbd2aae004637c (diff) | |
download | opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.zip opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.tar.gz opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.tar.bz2 |
vCal Resource for the tododb
-rw-r--r-- | libopie/libopie.pro | 2 | ||||
-rw-r--r-- | libopie/tododb.cpp | 8 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 6 | ||||
-rw-r--r-- | libopie/todovcalresource.cpp | 153 |
4 files changed, 166 insertions, 3 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index fb00422..1c0bf7b 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = $(OPIEDIR)/include/opie/xmltree.h | 3 | HEADERS = $(OPIEDIR)/include/opie/xmltree.h |
4 | SOURCES = xmltree.cc tododb.cpp todoevent.cpp | 4 | SOURCES = xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp |
5 | TARGET = opie | 5 | TARGET = opie |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index b1b35d0..f9756c6 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -45,173 +45,181 @@ public: | |||
45 | tasks->save(stream ); | 45 | tasks->save(stream ); |
46 | delete tasks; | 46 | delete tasks; |
47 | file.close(); | 47 | file.close(); |
48 | return true; | 48 | return true; |
49 | } | 49 | } |
50 | return false; | 50 | return false; |
51 | } | 51 | } |
52 | QValueList<ToDoEvent> load( const QString &name ){ | 52 | QValueList<ToDoEvent> load( const QString &name ){ |
53 | qWarning("loading tododb" ); | 53 | qWarning("loading tododb" ); |
54 | QValueList<ToDoEvent> m_todos; | 54 | QValueList<ToDoEvent> m_todos; |
55 | XMLElement *root = XMLElement::load( name ); | 55 | XMLElement *root = XMLElement::load( name ); |
56 | if(root != 0l ){ // start parsing | 56 | if(root != 0l ){ // start parsing |
57 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 57 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
58 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 58 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
59 | XMLElement *element = root->firstChild(); | 59 | XMLElement *element = root->firstChild(); |
60 | element = element->firstChild(); | 60 | element = element->firstChild(); |
61 | while( element ){ | 61 | while( element ){ |
62 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 62 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
63 | QString dummy; | 63 | QString dummy; |
64 | ToDoEvent event; | 64 | ToDoEvent event; |
65 | bool ok; | 65 | bool ok; |
66 | int dumInt; | 66 | int dumInt; |
67 | // completed | 67 | // completed |
68 | dummy = element->attribute("Completed" ); | 68 | dummy = element->attribute("Completed" ); |
69 | dumInt = dummy.toInt(&ok ); | 69 | dumInt = dummy.toInt(&ok ); |
70 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 70 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
71 | // hasDate | 71 | // hasDate |
72 | dummy = element->attribute("HasDate" ); | 72 | dummy = element->attribute("HasDate" ); |
73 | dumInt = dummy.toInt(&ok ); | 73 | dumInt = dummy.toInt(&ok ); |
74 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 74 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
75 | // set the date | 75 | // set the date |
76 | bool hasDa = dumInt; | 76 | bool hasDa = dumInt; |
77 | if ( hasDa ) { //parse the date | 77 | if ( hasDa ) { //parse the date |
78 | int year, day, month = 0; | 78 | int year, day, month = 0; |
79 | year = day = month; | 79 | year = day = month; |
80 | // year | 80 | // year |
81 | dummy = element->attribute("DateYear" ); | 81 | dummy = element->attribute("DateYear" ); |
82 | dumInt = dummy.toInt(&ok ); | 82 | dumInt = dummy.toInt(&ok ); |
83 | if( ok ) year = dumInt; | 83 | if( ok ) year = dumInt; |
84 | // month | 84 | // month |
85 | dummy = element->attribute("DateMonth" ); | 85 | dummy = element->attribute("DateMonth" ); |
86 | dumInt = dummy.toInt(&ok ); | 86 | dumInt = dummy.toInt(&ok ); |
87 | if(ok ) month = dumInt; | 87 | if(ok ) month = dumInt; |
88 | dummy = element->attribute("DateDay" ); | 88 | dummy = element->attribute("DateDay" ); |
89 | dumInt = dummy.toInt(&ok ); | 89 | dumInt = dummy.toInt(&ok ); |
90 | if(ok ) day = dumInt; | 90 | if(ok ) day = dumInt; |
91 | // set the date | 91 | // set the date |
92 | QDate date( year, month, day ); | 92 | QDate date( year, month, day ); |
93 | event.setDate( date); | 93 | event.setDate( date); |
94 | } | 94 | } |
95 | dummy = element->attribute("Priority" ); | 95 | dummy = element->attribute("Priority" ); |
96 | dumInt = dummy.toInt(&ok ); | 96 | dumInt = dummy.toInt(&ok ); |
97 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 97 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
98 | event.setPriority( dumInt ); | 98 | event.setPriority( dumInt ); |
99 | //description | 99 | //description |
100 | dummy = element->attribute("Description" ); | 100 | dummy = element->attribute("Description" ); |
101 | event.setDescription( dummy ); | 101 | event.setDescription( dummy ); |
102 | // category | 102 | // category |
103 | dummy = element->attribute("Categories" ); | 103 | dummy = element->attribute("Categories" ); |
104 | dumInt = dummy.toInt(&ok ); | 104 | dumInt = dummy.toInt(&ok ); |
105 | if(ok ) { | 105 | if(ok ) { |
106 | QArray<int> arrat(1); | 106 | QArray<int> arrat(1); |
107 | arrat[0] = dumInt; | 107 | arrat[0] = dumInt; |
108 | event.setCategory( Qtopia::Record::idsToString( arrat ) ); | 108 | event.setCategory( Qtopia::Record::idsToString( arrat ) ); |
109 | } | 109 | } |
110 | //uid | 110 | //uid |
111 | dummy = element->attribute("Uid" ); | 111 | dummy = element->attribute("Uid" ); |
112 | dumInt = dummy.toInt(&ok ); | 112 | dumInt = dummy.toInt(&ok ); |
113 | if(ok ) event.setUid( dumInt ); | 113 | if(ok ) event.setUid( dumInt ); |
114 | m_todos.append( event ); | 114 | m_todos.append( event ); |
115 | element = element->nextChild(); // next element | 115 | element = element->nextChild(); // next element |
116 | } | 116 | } |
117 | //} | 117 | //} |
118 | }else { | 118 | }else { |
119 | qWarning("could not load" ); | 119 | qWarning("could not load" ); |
120 | } | 120 | } |
121 | delete root; | 121 | delete root; |
122 | qWarning("returning" ); | 122 | qWarning("returning" ); |
123 | return m_todos; | 123 | return m_todos; |
124 | } | 124 | } |
125 | }; | 125 | }; |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | ToDoDB::ToDoDB(const QString &fileName = QString::null, ToDoResource *res ){ | 129 | ToDoDB::ToDoDB(const QString &fileName = QString::null, ToDoResource *res ){ |
130 | m_fileName = fileName; | 130 | m_fileName = fileName; |
131 | if( fileName.isEmpty() && res == 0 ){ | 131 | if( fileName.isEmpty() && res == 0 ){ |
132 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 132 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
133 | res = new FileToDoResource(); | 133 | res = new FileToDoResource(); |
134 | //qWarning("%s", m_fileName.latin1() ); | 134 | //qWarning("%s", m_fileName.latin1() ); |
135 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 135 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
136 | res = new FileToDoResource(); | 136 | res = new FileToDoResource(); |
137 | } | 137 | } |
138 | m_res = res; | 138 | m_res = res; |
139 | load(); | 139 | load(); |
140 | } | 140 | } |
141 | ToDoResource* ToDoDB::resource(){ | ||
142 | return m_res; | ||
143 | }; | ||
144 | void ToDoDB::setResource( ToDoResource *res ) | ||
145 | { | ||
146 | delete m_res; | ||
147 | m_res = res; | ||
148 | } | ||
141 | ToDoDB::~ToDoDB() | 149 | ToDoDB::~ToDoDB() |
142 | { | 150 | { |
143 | delete m_res; | 151 | delete m_res; |
144 | } | 152 | } |
145 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 153 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
146 | bool all ) | 154 | bool all ) |
147 | { | 155 | { |
148 | QValueList<ToDoEvent> events; | 156 | QValueList<ToDoEvent> events; |
149 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 157 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
150 | if( (*it).hasDate() ){ | 158 | if( (*it).hasDate() ){ |
151 | if( (*it).date() >= from && (*it).date() <= to ) | 159 | if( (*it).date() >= from && (*it).date() <= to ) |
152 | events.append( (*it) ); | 160 | events.append( (*it) ); |
153 | }else if( all ){ | 161 | }else if( all ){ |
154 | events.append( (*it) ); | 162 | events.append( (*it) ); |
155 | } | 163 | } |
156 | } | 164 | } |
157 | return events; | 165 | return events; |
158 | } | 166 | } |
159 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 167 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
160 | bool all) | 168 | bool all) |
161 | { | 169 | { |
162 | return effectiveToDos( from, QDate::currentDate(), all ); | 170 | return effectiveToDos( from, QDate::currentDate(), all ); |
163 | } | 171 | } |
164 | QValueList<ToDoEvent> ToDoDB::overDue() | 172 | QValueList<ToDoEvent> ToDoDB::overDue() |
165 | { | 173 | { |
166 | QValueList<ToDoEvent> events; | 174 | QValueList<ToDoEvent> events; |
167 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 175 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
168 | if( (*it).isOverdue() ) | 176 | if( (*it).isOverdue() ) |
169 | events.append((*it) ); | 177 | events.append((*it) ); |
170 | } | 178 | } |
171 | return events; | 179 | return events; |
172 | } | 180 | } |
173 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 181 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
174 | { | 182 | { |
175 | return m_todos; | 183 | return m_todos; |
176 | } | 184 | } |
177 | void ToDoDB::addEvent( const ToDoEvent &event ) | 185 | void ToDoDB::addEvent( const ToDoEvent &event ) |
178 | { | 186 | { |
179 | m_todos.append( event ); | 187 | m_todos.append( event ); |
180 | } | 188 | } |
181 | void ToDoDB::editEvent( const ToDoEvent &event ) | 189 | void ToDoDB::editEvent( const ToDoEvent &event ) |
182 | { | 190 | { |
183 | m_todos.remove( event ); | 191 | m_todos.remove( event ); |
184 | m_todos.append( event ); | 192 | m_todos.append( event ); |
185 | } | 193 | } |
186 | void ToDoDB::removeEvent( const ToDoEvent &event ) | 194 | void ToDoDB::removeEvent( const ToDoEvent &event ) |
187 | { | 195 | { |
188 | m_todos.remove( event ); | 196 | m_todos.remove( event ); |
189 | } | 197 | } |
190 | void ToDoDB::reload() | 198 | void ToDoDB::reload() |
191 | { | 199 | { |
192 | load(); | 200 | load(); |
193 | } | 201 | } |
194 | void ToDoDB::setFileName(const QString &file ) | 202 | void ToDoDB::setFileName(const QString &file ) |
195 | { | 203 | { |
196 | m_fileName =file; | 204 | m_fileName =file; |
197 | } | 205 | } |
198 | QString ToDoDB::fileName()const | 206 | QString ToDoDB::fileName()const |
199 | { | 207 | { |
200 | return m_fileName; | 208 | return m_fileName; |
201 | } | 209 | } |
202 | void ToDoDB::load() | 210 | void ToDoDB::load() |
203 | { | 211 | { |
204 | m_todos = m_res->load( m_fileName ); | 212 | m_todos = m_res->load( m_fileName ); |
205 | } | 213 | } |
206 | bool ToDoDB::save() | 214 | bool ToDoDB::save() |
207 | { | 215 | { |
208 | return m_res->save( m_fileName, m_todos ); | 216 | return m_res->save( m_fileName, m_todos ); |
209 | } | 217 | } |
210 | 218 | ||
211 | 219 | ||
212 | 220 | ||
213 | 221 | ||
214 | 222 | ||
215 | 223 | ||
216 | 224 | ||
217 | 225 | ||
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index 4cfe1c0..5fa4472 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,150 +1,152 @@ | |||
1 | 1 | ||
2 | #include <opie/todoevent.h> | 2 | #include <opie/todoevent.h> |
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/stringutil.h> | ||
5 | //#include <qpe/palmtoprecord.h> | ||
4 | 6 | ||
5 | ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, | 7 | ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, |
6 | const QString &description, bool hasDate, QDate date, int uid ) | 8 | const QString &description, bool hasDate, QDate date, int uid ) |
7 | { | 9 | { |
8 | qWarning("todoEvent c'tor" ); | 10 | qWarning("todoEvent c'tor" ); |
9 | m_date = date; | 11 | m_date = date; |
10 | m_isCompleted = completed; | 12 | m_isCompleted = completed; |
11 | m_hasDate = hasDate; | 13 | m_hasDate = hasDate; |
12 | m_priority = priority; | 14 | m_priority = priority; |
13 | m_category = category; | 15 | m_category = category; |
14 | m_desc = description; | 16 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
15 | if (uid == -1 ) { | 17 | if (uid == -1 ) { |
16 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 18 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
17 | uid = uidgen->generate(); | 19 | uid = uidgen->generate(); |
18 | delete uidgen; | 20 | delete uidgen; |
19 | }// generate the ids | 21 | }// generate the ids |
20 | m_uid = uid; | 22 | m_uid = uid; |
21 | } | 23 | } |
22 | bool ToDoEvent::isCompleted() const | 24 | bool ToDoEvent::isCompleted() const |
23 | { | 25 | { |
24 | return m_isCompleted; | 26 | return m_isCompleted; |
25 | } | 27 | } |
26 | bool ToDoEvent::hasDate() const | 28 | bool ToDoEvent::hasDate() const |
27 | { | 29 | { |
28 | return m_hasDate; | 30 | return m_hasDate; |
29 | } | 31 | } |
30 | int ToDoEvent::priority()const | 32 | int ToDoEvent::priority()const |
31 | { | 33 | { |
32 | return m_priority; | 34 | return m_priority; |
33 | } | 35 | } |
34 | QString ToDoEvent::category()const | 36 | QString ToDoEvent::category()const |
35 | { | 37 | { |
36 | return m_category; | 38 | return m_category; |
37 | } | 39 | } |
38 | QDate ToDoEvent::date()const | 40 | QDate ToDoEvent::date()const |
39 | { | 41 | { |
40 | return m_date; | 42 | return m_date; |
41 | } | 43 | } |
42 | QString ToDoEvent::description()const | 44 | QString ToDoEvent::description()const |
43 | { | 45 | { |
44 | return m_desc; | 46 | return m_desc; |
45 | } | 47 | } |
46 | void ToDoEvent::setCompleted( bool completed ) | 48 | void ToDoEvent::setCompleted( bool completed ) |
47 | { | 49 | { |
48 | m_isCompleted = completed; | 50 | m_isCompleted = completed; |
49 | } | 51 | } |
50 | void ToDoEvent::setHasDate( bool hasDate ) | 52 | void ToDoEvent::setHasDate( bool hasDate ) |
51 | { | 53 | { |
52 | m_hasDate = hasDate; | 54 | m_hasDate = hasDate; |
53 | } | 55 | } |
54 | void ToDoEvent::setDescription(const QString &desc ) | 56 | void ToDoEvent::setDescription(const QString &desc ) |
55 | { | 57 | { |
56 | m_desc = desc; | 58 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
57 | } | 59 | } |
58 | void ToDoEvent::setCategory( const QString &cat ) | 60 | void ToDoEvent::setCategory( const QString &cat ) |
59 | { | 61 | { |
60 | m_category = cat; | 62 | m_category = cat; |
61 | } | 63 | } |
62 | void ToDoEvent::setPriority(int prio ) | 64 | void ToDoEvent::setPriority(int prio ) |
63 | { | 65 | { |
64 | m_priority = prio; | 66 | m_priority = prio; |
65 | } | 67 | } |
66 | void ToDoEvent::setDate( QDate date ) | 68 | void ToDoEvent::setDate( QDate date ) |
67 | { | 69 | { |
68 | m_date = date; | 70 | m_date = date; |
69 | } | 71 | } |
70 | bool ToDoEvent::isOverdue( ) | 72 | bool ToDoEvent::isOverdue( ) |
71 | { | 73 | { |
72 | if( m_hasDate ) | 74 | if( m_hasDate ) |
73 | return QDate::currentDate() > m_date; | 75 | return QDate::currentDate() > m_date; |
74 | return false; | 76 | return false; |
75 | } | 77 | } |
76 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 78 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
77 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 79 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
78 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 80 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
79 | if( hasDate() && toDoEvent.hasDate() ){ | 81 | if( hasDate() && toDoEvent.hasDate() ){ |
80 | if( date() == toDoEvent.date() ){ // let's the priority decide | 82 | if( date() == toDoEvent.date() ){ // let's the priority decide |
81 | return priority() < toDoEvent.priority(); | 83 | return priority() < toDoEvent.priority(); |
82 | }else{ | 84 | }else{ |
83 | return date() < toDoEvent.date(); | 85 | return date() < toDoEvent.date(); |
84 | } | 86 | } |
85 | } | 87 | } |
86 | return false; | 88 | return false; |
87 | } | 89 | } |
88 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 90 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
89 | { | 91 | { |
90 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 92 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
91 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 93 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
92 | if( hasDate() && toDoEvent.hasDate() ){ | 94 | if( hasDate() && toDoEvent.hasDate() ){ |
93 | if( date() == toDoEvent.date() ){ // let's the priority decide | 95 | if( date() == toDoEvent.date() ){ // let's the priority decide |
94 | return priority() <= toDoEvent.priority(); | 96 | return priority() <= toDoEvent.priority(); |
95 | }else{ | 97 | }else{ |
96 | return date() <= toDoEvent.date(); | 98 | return date() <= toDoEvent.date(); |
97 | } | 99 | } |
98 | } | 100 | } |
99 | return true; | 101 | return true; |
100 | } | 102 | } |
101 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const | 103 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const |
102 | { | 104 | { |
103 | if( !hasDate() && !toDoEvent.hasDate() ) return false; | 105 | if( !hasDate() && !toDoEvent.hasDate() ) return false; |
104 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 106 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
105 | if( hasDate() && toDoEvent.hasDate() ){ | 107 | if( hasDate() && toDoEvent.hasDate() ){ |
106 | if( date() == toDoEvent.date() ){ // let's the priority decide | 108 | if( date() == toDoEvent.date() ){ // let's the priority decide |
107 | return priority() > toDoEvent.priority(); | 109 | return priority() > toDoEvent.priority(); |
108 | }else{ | 110 | }else{ |
109 | return date() > toDoEvent.date(); | 111 | return date() > toDoEvent.date(); |
110 | } | 112 | } |
111 | } | 113 | } |
112 | return false; | 114 | return false; |
113 | } | 115 | } |
114 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const | 116 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const |
115 | { | 117 | { |
116 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 118 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
117 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 119 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
118 | if( hasDate() && toDoEvent.hasDate() ){ | 120 | if( hasDate() && toDoEvent.hasDate() ){ |
119 | if( date() == toDoEvent.date() ){ // let's the priority decide | 121 | if( date() == toDoEvent.date() ){ // let's the priority decide |
120 | return priority() > toDoEvent.priority(); | 122 | return priority() > toDoEvent.priority(); |
121 | }else{ | 123 | }else{ |
122 | return date() > toDoEvent.date(); | 124 | return date() > toDoEvent.date(); |
123 | } | 125 | } |
124 | } | 126 | } |
125 | return true; | 127 | return true; |
126 | } | 128 | } |
127 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const | 129 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const |
128 | { | 130 | { |
129 | 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_category ) | 131 | 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_category ) |
130 | return true; | 132 | return true; |
131 | return false; | 133 | return false; |
132 | } | 134 | } |
133 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) | 135 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) |
134 | { | 136 | { |
135 | m_date = item.m_date; | 137 | m_date = item.m_date; |
136 | m_isCompleted = item.m_isCompleted; | 138 | m_isCompleted = item.m_isCompleted; |
137 | m_hasDate = item.m_hasDate; | 139 | m_hasDate = item.m_hasDate; |
138 | m_priority = item.m_priority; | 140 | m_priority = item.m_priority; |
139 | m_category = item.m_category; | 141 | m_category = item.m_category; |
140 | m_desc = item.m_desc; | 142 | m_desc = item.m_desc; |
141 | return *this; | 143 | return *this; |
142 | } | 144 | } |
143 | 145 | ||
144 | 146 | ||
145 | 147 | ||
146 | 148 | ||
147 | 149 | ||
148 | 150 | ||
149 | 151 | ||
150 | 152 | ||
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp new file mode 100644 index 0000000..a6afe68 --- a/dev/null +++ b/libopie/todovcalresource.cpp | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> | ||
4 | .>+-= the use of vobject was inspired by libkcal | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <qfile.h> | ||
30 | #include <qvaluelist.h> | ||
31 | #include <opie/todoevent.h> | ||
32 | #include <opie/todovcalresource.h> | ||
33 | |||
34 | #include "../library/backend/vobject_p.h" | ||
35 | #include "../library/backend/timeconversion.h" | ||
36 | #include "../library/backend/qfiledirect_p.h" | ||
37 | |||
38 | static VObject *vobjByEvent( const ToDoEvent &event ) | ||
39 | { | ||
40 | VObject *task = newVObject( VCTodoProp ); | ||
41 | if( task == 0 ) | ||
42 | return 0l; | ||
43 | if( event.hasDate() ) | ||
44 | addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); | ||
45 | |||
46 | if( event.isCompleted() ) | ||
47 | addPropValue( task, VCStatusProp, "COMPLETED"); | ||
48 | |||
49 | QString string = QString::number(event.priority() ); | ||
50 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | ||
51 | addPropValue( task, VCCategoriesProp, event.category().local8Bit() ); | ||
52 | addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); | ||
53 | addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); | ||
54 | return task; | ||
55 | }; | ||
56 | |||
57 | static ToDoEvent eventByVObj( VObject *obj ){ | ||
58 | ToDoEvent event; | ||
59 | VObject *ob; | ||
60 | QCString name; | ||
61 | // no uid, attendees, ... and no fun | ||
62 | // description | ||
63 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | ||
64 | name = vObjectStringZValue( ob ); | ||
65 | event.setDescription( name ); | ||
66 | } | ||
67 | // completed | ||
68 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | ||
69 | name = vObjectStringZValue( ob ); | ||
70 | if( name == "COMPLETED" ){ | ||
71 | event.setCompleted( true ); | ||
72 | }else{ | ||
73 | event.setCompleted( false ); | ||
74 | } | ||
75 | }else | ||
76 | event.setCompleted( false ); | ||
77 | // priority | ||
78 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | ||
79 | name = vObjectStringZValue( ob ); | ||
80 | bool ok; | ||
81 | event.setPriority(name.toInt(&ok) ); | ||
82 | } | ||
83 | //due date | ||
84 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | ||
85 | event.setHasDate( true ); | ||
86 | name = vObjectStringZValue( ob ); | ||
87 | event.setDate( TimeConversion::fromISO8601( name).date() ); | ||
88 | } | ||
89 | // categories | ||
90 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | ||
91 | name = vObjectStringZValue( ob ); | ||
92 | qWarning("Categories:%s", name.data() ); | ||
93 | } | ||
94 | |||
95 | return event; | ||
96 | }; | ||
97 | |||
98 | |||
99 | QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) | ||
100 | { | ||
101 | QValueList<ToDoEvent> events; | ||
102 | VObject *vcal = 0l; | ||
103 | vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject | ||
104 | if(!vcal ) | ||
105 | return events; | ||
106 | // start parsing | ||
107 | |||
108 | VObjectIterator it; | ||
109 | VObject *vobj; | ||
110 | initPropIterator(&it, vcal); | ||
111 | |||
112 | while( moreIteration( &it ) ) { | ||
113 | vobj = ::nextVObject( &it ); | ||
114 | QCString name = ::vObjectName( vobj ); | ||
115 | //QCString objVal = ::vObjectStringZValue( vobj ); | ||
116 | // let's find out the type | ||
117 | if( name == VCTodoProp ){ | ||
118 | events.append( eventByVObj( vobj ) ); | ||
119 | |||
120 | } // parse the value | ||
121 | } | ||
122 | return events; | ||
123 | } | ||
124 | bool ToDoVCalResource::save(const QString &fileName, const QValueList<ToDoEvent>&list ) | ||
125 | { | ||
126 | QFileDirect file ( fileName ); | ||
127 | if(!file.open(IO_WriteOnly ) ) | ||
128 | return false; | ||
129 | // obj | ||
130 | VObject *obj; | ||
131 | obj = newVObject( VCCalProp ); | ||
132 | addPropValue( obj, VCVersionProp, "1.0" ); | ||
133 | VObject *vo; | ||
134 | for(QValueList<ToDoEvent>::ConstIterator it = list.begin(); it != list.end(); ++it ){ | ||
135 | vo = vobjByEvent( (*it) ); | ||
136 | addVObjectProp(obj, vo ); | ||
137 | } | ||
138 | writeVObject( file.directHandle(), obj ); | ||
139 | cleanVObject( obj ); | ||
140 | cleanStrTbl(); | ||
141 | |||
142 | return true; | ||
143 | } | ||
144 | |||
145 | |||
146 | |||
147 | |||
148 | |||
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||