summaryrefslogtreecommitdiff
path: root/libopie/tododb.cpp
authorzecke <zecke>2003-02-21 16:52:49 (UTC)
committer zecke <zecke>2003-02-21 16:52:49 (UTC)
commit0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7 (patch) (unidiff)
treef3ce9c9441a1073762f3e0c61cc85f0d5a1fd81d /libopie/tododb.cpp
parenta298235aa1489937e7657079e6352adfc8746acf (diff)
downloadopie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.zip
opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.gz
opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.bz2
-Remove old Todo classes they're deprecated and today I already using the
new API -Guard against self assignment in OTodo -Add test apps for OPIM -Opiefied Event classes -Added TimeZone handling and pinning of TimeZones to OEvent -Adjust ORecur and the widget to better timezone behaviour
Diffstat (limited to 'libopie/tododb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/tododb.cpp268
1 files changed, 0 insertions, 268 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
deleted file mode 100644
index 17163a0..0000000
--- a/libopie/tododb.cpp
+++ b/dev/null
@@ -1,268 +0,0 @@
1
2#include <qdir.h>
3#include <opie/tododb.h>
4#include <opie/xmltree.h>
5#include <opie/todoresource.h>
6#include <qpe/palmtoprecord.h>
7#include <qpe/global.h>
8
9using namespace Opie;
10
11namespace {
12
13class FileToDoResource : public ToDoResource {
14public:
15 FileToDoResource() {};
16 // FIXME better parsing
17 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
18 // prepare the XML
19 XMLElement *tasks = new XMLElement( );
20 tasks->setTagName("Tasks" );
21 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
22 XMLElement::AttributeMap map;
23 XMLElement *task = new XMLElement();
24 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
25 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
26 map.insert( "Priority", QString::number( (*it).priority() ) );
27 map.insert( "Progress", QString::number( (*it).progress() ) );
28 map.insert( "Summary", (*it).summary() );
29 QArray<int> arrat = (*it).categories();
30 QString attr;
31 for(uint i=0; i < arrat.count(); i++ ){
32 attr.append(QString::number(arrat[i])+";" );
33 }
34 if(!attr.isEmpty() ) // remove the last ;
35 attr.remove(attr.length()-1, 1 );
36 map.insert( "Categories", attr );
37 //else
38 //map.insert( "Categories", QString::null );
39 map.insert( "Description", (*it).description() );
40 if( (*it).hasDate() ){
41 map.insert("DateYear", QString::number( (*it).date().year() ) );
42 map.insert("DateMonth", QString::number( (*it).date().month() ) );
43 map.insert("DateDay", QString::number( (*it).date().day() ) );
44 }
45 map.insert("Uid", QString::number( (*it).uid() ) );
46 task->setTagName("Task" );
47 task->setAttributes( map );
48 tasks->appendChild(task);
49 }
50 QFile file( name);
51 if( file.open(IO_WriteOnly ) ){
52 QTextStream stream(&file );
53 stream.setEncoding( QTextStream::UnicodeUTF8 );
54 stream << "<!DOCTYPE Tasks>" << endl;
55 tasks->save(stream );
56 delete tasks;
57 stream << "</Tasks>" << endl;
58 file.close();
59 return true;
60 }
61 return false;
62 }
63 QValueList<ToDoEvent> load( const QString &name ){
64 qWarning("loading tododb" );
65 QValueList<ToDoEvent> m_todos;
66 XMLElement *root = XMLElement::load( name );
67 if(root != 0l ){ // start parsing
68 qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() );
69 //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start
70 XMLElement *element = root->firstChild();
71 if (element == 0 )
72 return m_todos;
73 element = element->firstChild();
74 while( element ){
75 if( element->tagName() != QString::fromLatin1("Task") ){
76 element = element->nextChild();
77 continue;
78 }
79 qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() );
80 QString dummy;
81 ToDoEvent event;
82 bool ok;
83 int dumInt;
84 // completed
85 dummy = element->attribute("Completed" );
86 dumInt = dummy.toInt(&ok );
87 if(ok ) event.setCompleted( dumInt == 0 ? false : true );
88 // progress
89 dummy = element->attribute("Progress" );
90 {
91 ushort dumShort = dummy.toUShort(&ok);
92 event.setProgress( dumShort );
93
94 }
95 // hasDate
96 dummy = element->attribute("HasDate" );
97 dumInt = dummy.toInt(&ok );
98 if(ok ) event.setHasDate( dumInt == 0 ? false: true );
99 // set the date
100 bool hasDa = dumInt;
101 if ( hasDa ) { //parse the date
102 int year, day, month = 0;
103 year = day = month;
104 // year
105 dummy = element->attribute("DateYear" );
106 dumInt = dummy.toInt(&ok );
107 if( ok ) year = dumInt;
108 // month
109 dummy = element->attribute("DateMonth" );
110 dumInt = dummy.toInt(&ok );
111 if(ok ) month = dumInt;
112 dummy = element->attribute("DateDay" );
113 dumInt = dummy.toInt(&ok );
114 if(ok ) day = dumInt;
115 // set the date
116 QDate date( year, month, day );
117 event.setDate( date);
118 }
119 dummy = element->attribute("Priority" );
120 dumInt = dummy.toInt(&ok );
121 if(!ok ) dumInt = ToDoEvent::NORMAL;
122 event.setPriority( dumInt );
123 //description
124 dummy = element->attribute("Description" );
125 event.setDescription( dummy );
126 dummy = element->attribute("Summary" );
127 event.setSummary( dummy );
128 // category
129 dummy = element->attribute("Categories" );
130 QStringList ids = QStringList::split(";", dummy );
131 event.setCategories( ids );
132
133 //uid
134 dummy = element->attribute("Uid" );
135 dumInt = dummy.toInt(&ok );
136 if(ok ) event.setUid( dumInt );
137 m_todos.append( event );
138 element = element->nextChild(); // next element
139 }
140 //}
141 }else {
142 qWarning("could not load" );
143 }
144 delete root;
145 qWarning("returning" );
146 return m_todos;
147 }
148};
149
150}
151
152ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){
153 m_fileName = fileName;
154 if( fileName.isEmpty() && res == 0 ){
155 m_fileName = Global::applicationFileName("todolist","todolist.xml");
156 res = new FileToDoResource();
157 //qWarning("%s", m_fileName.latin1() );
158 }else if(res == 0 ){ // let's create a ToDoResource for xml
159 res = new FileToDoResource();
160 }
161 m_res = res;
162 load();
163}
164ToDoResource* ToDoDB::resource(){
165 return m_res;
166};
167void ToDoDB::setResource( ToDoResource *res )
168{
169 delete m_res;
170 m_res = res;
171}
172ToDoDB::~ToDoDB()
173{
174 delete m_res;
175}
176QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to,
177 bool all )
178{
179 QValueList<ToDoEvent> events;
180 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
181 if( (*it).hasDate() ){
182 if( (*it).date() >= from && (*it).date() <= to )
183 events.append( (*it) );
184 }else if( all ){
185 events.append( (*it) );
186 }
187 }
188 return events;
189}
190QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from,
191 bool all)
192{
193 return effectiveToDos( from, QDate::currentDate(), all );
194}
195QValueList<ToDoEvent> ToDoDB::overDue()
196{
197 QValueList<ToDoEvent> events;
198 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
199 if( (*it).isOverdue() )
200 events.append((*it) );
201 }
202 return events;
203}
204QValueList<ToDoEvent> ToDoDB::rawToDos()
205{
206 return m_todos;
207}
208void ToDoDB::addEvent( const ToDoEvent &event )
209{
210 m_todos.append( event );
211}
212void ToDoDB::editEvent( const ToDoEvent &event )
213{
214 m_todos.remove( event );
215 m_todos.append( event );
216}
217void ToDoDB::removeEvent( const ToDoEvent &event )
218{
219 m_todos.remove( event );
220}
221void ToDoDB::replaceEvent(const ToDoEvent &event )
222{
223 QValueList<ToDoEvent>::Iterator it;
224 int uid = event.uid();
225 // == is not overloaded as we would like :( so let's search for the uid
226 for(it = m_todos.begin(); it != m_todos.end(); ++it ){
227 if( (*it).uid() == uid ){
228 m_todos.remove( (*it) );
229 break; // should save us the iterate is now borked
230 }
231 }
232 m_todos.append(event);
233}
234void ToDoDB::reload()
235{
236 load();
237}
238void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events )
239{
240 QValueList<ToDoEvent>::ConstIterator it;
241 for( it = events.begin(); it != events.end(); ++it ){
242 replaceEvent( (*it) );
243 }
244}
245void ToDoDB::setFileName(const QString &file )
246{
247 m_fileName =file;
248}
249QString ToDoDB::fileName()const
250{
251 return m_fileName;
252}
253void ToDoDB::load()
254{
255 m_todos = m_res->load( m_fileName );
256}
257bool ToDoDB::save()
258{
259 return m_res->save( m_fileName, m_todos );
260}
261
262
263
264
265
266
267
268