-rw-r--r-- | libopie/tododb.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index 6b10ec2..1e40c40 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -1,116 +1,124 @@ | |||
1 | 1 | ||
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <opie/tododb.h> | 3 | #include <opie/tododb.h> |
4 | #include <opie/xmltree.h> | 4 | #include <opie/xmltree.h> |
5 | #include <opie/todoresource.h> | 5 | #include <opie/todoresource.h> |
6 | #include <qpe/palmtoprecord.h> | 6 | #include <qpe/palmtoprecord.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | using namespace Opie; | 9 | using namespace Opie; |
10 | 10 | ||
11 | namespace { | 11 | namespace { |
12 | 12 | ||
13 | class FileToDoResource : public ToDoResource { | 13 | class FileToDoResource : public ToDoResource { |
14 | public: | 14 | public: |
15 | FileToDoResource() {}; | 15 | FileToDoResource() {}; |
16 | // FIXME better parsing | 16 | // FIXME better parsing |
17 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ | 17 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ |
18 | // prepare the XML | 18 | // prepare the XML |
19 | XMLElement *tasks = new XMLElement( ); | 19 | XMLElement *tasks = new XMLElement( ); |
20 | tasks->setTagName("Tasks" ); | 20 | tasks->setTagName("Tasks" ); |
21 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ | 21 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ |
22 | XMLElement::AttributeMap map; | 22 | XMLElement::AttributeMap map; |
23 | XMLElement *task = new XMLElement(); | 23 | XMLElement *task = new XMLElement(); |
24 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); | 24 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); |
25 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); | 25 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); |
26 | map.insert( "Priority", QString::number( (*it).priority() ) ); | 26 | map.insert( "Priority", QString::number( (*it).priority() ) ); |
27 | map.insert( "Progress", QString::number( (*it).progress() ) ); | ||
27 | map.insert( "Summary", (*it).summary() ); | 28 | map.insert( "Summary", (*it).summary() ); |
28 | QArray<int> arrat = (*it).categories(); | 29 | QArray<int> arrat = (*it).categories(); |
29 | QString attr; | 30 | QString attr; |
30 | for(uint i=0; i < arrat.count(); i++ ){ | 31 | for(uint i=0; i < arrat.count(); i++ ){ |
31 | attr.append(QString::number(arrat[i])+";" ); | 32 | attr.append(QString::number(arrat[i])+";" ); |
32 | } | 33 | } |
33 | if(!attr.isEmpty() ) // remove the last ; | 34 | if(!attr.isEmpty() ) // remove the last ; |
34 | attr.remove(attr.length()-1, 1 ); | 35 | attr.remove(attr.length()-1, 1 ); |
35 | map.insert( "Categories", attr ); | 36 | map.insert( "Categories", attr ); |
36 | //else | 37 | //else |
37 | //map.insert( "Categories", QString::null ); | 38 | //map.insert( "Categories", QString::null ); |
38 | map.insert( "Description", (*it).description() ); | 39 | map.insert( "Description", (*it).description() ); |
39 | if( (*it).hasDate() ){ | 40 | if( (*it).hasDate() ){ |
40 | map.insert("DateYear", QString::number( (*it).date().year() ) ); | 41 | map.insert("DateYear", QString::number( (*it).date().year() ) ); |
41 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); | 42 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); |
42 | map.insert("DateDay", QString::number( (*it).date().day() ) ); | 43 | map.insert("DateDay", QString::number( (*it).date().day() ) ); |
43 | } | 44 | } |
44 | map.insert("Uid", QString::number( (*it).uid() ) ); | 45 | map.insert("Uid", QString::number( (*it).uid() ) ); |
45 | task->setTagName("Task" ); | 46 | task->setTagName("Task" ); |
46 | task->setAttributes( map ); | 47 | task->setAttributes( map ); |
47 | tasks->appendChild(task); | 48 | tasks->appendChild(task); |
48 | } | 49 | } |
49 | QFile file( name); | 50 | QFile file( name); |
50 | if( file.open(IO_WriteOnly ) ){ | 51 | if( file.open(IO_WriteOnly ) ){ |
51 | QTextStream stream(&file ); | 52 | QTextStream stream(&file ); |
52 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 53 | stream.setEncoding( QTextStream::UnicodeUTF8 ); |
53 | stream << "<!DOCTYPE Tasks>" << endl; | 54 | stream << "<!DOCTYPE Tasks>" << endl; |
54 | tasks->save(stream ); | 55 | tasks->save(stream ); |
55 | delete tasks; | 56 | delete tasks; |
56 | stream << "</Tasks>" << endl; | 57 | stream << "</Tasks>" << endl; |
57 | file.close(); | 58 | file.close(); |
58 | return true; | 59 | return true; |
59 | } | 60 | } |
60 | return false; | 61 | return false; |
61 | } | 62 | } |
62 | QValueList<ToDoEvent> load( const QString &name ){ | 63 | QValueList<ToDoEvent> load( const QString &name ){ |
63 | qWarning("loading tododb" ); | 64 | qWarning("loading tododb" ); |
64 | QValueList<ToDoEvent> m_todos; | 65 | QValueList<ToDoEvent> m_todos; |
65 | XMLElement *root = XMLElement::load( name ); | 66 | XMLElement *root = XMLElement::load( name ); |
66 | if(root != 0l ){ // start parsing | 67 | if(root != 0l ){ // start parsing |
67 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 68 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
68 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 69 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
69 | XMLElement *element = root->firstChild(); | 70 | XMLElement *element = root->firstChild(); |
70 | element = element->firstChild(); | 71 | element = element->firstChild(); |
71 | while( element ){ | 72 | while( element ){ |
72 | if( element->tagName() != QString::fromLatin1("Task") ){ | 73 | if( element->tagName() != QString::fromLatin1("Task") ){ |
73 | element = element->nextChild(); | 74 | element = element->nextChild(); |
74 | continue; | 75 | continue; |
75 | } | 76 | } |
76 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 77 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
77 | QString dummy; | 78 | QString dummy; |
78 | ToDoEvent event; | 79 | ToDoEvent event; |
79 | bool ok; | 80 | bool ok; |
80 | int dumInt; | 81 | int dumInt; |
81 | // completed | 82 | // completed |
82 | dummy = element->attribute("Completed" ); | 83 | dummy = element->attribute("Completed" ); |
83 | dumInt = dummy.toInt(&ok ); | 84 | dumInt = dummy.toInt(&ok ); |
84 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 85 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
86 | // progress | ||
87 | dummy = element->attribute("Progress" ); | ||
88 | { | ||
89 | ushort dumShort = dummy.toUShort(&ok); | ||
90 | event.setProgress( dumShort ); | ||
91 | |||
92 | } | ||
85 | // hasDate | 93 | // hasDate |
86 | dummy = element->attribute("HasDate" ); | 94 | dummy = element->attribute("HasDate" ); |
87 | dumInt = dummy.toInt(&ok ); | 95 | dumInt = dummy.toInt(&ok ); |
88 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 96 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
89 | // set the date | 97 | // set the date |
90 | bool hasDa = dumInt; | 98 | bool hasDa = dumInt; |
91 | if ( hasDa ) { //parse the date | 99 | if ( hasDa ) { //parse the date |
92 | int year, day, month = 0; | 100 | int year, day, month = 0; |
93 | year = day = month; | 101 | year = day = month; |
94 | // year | 102 | // year |
95 | dummy = element->attribute("DateYear" ); | 103 | dummy = element->attribute("DateYear" ); |
96 | dumInt = dummy.toInt(&ok ); | 104 | dumInt = dummy.toInt(&ok ); |
97 | if( ok ) year = dumInt; | 105 | if( ok ) year = dumInt; |
98 | // month | 106 | // month |
99 | dummy = element->attribute("DateMonth" ); | 107 | dummy = element->attribute("DateMonth" ); |
100 | dumInt = dummy.toInt(&ok ); | 108 | dumInt = dummy.toInt(&ok ); |
101 | if(ok ) month = dumInt; | 109 | if(ok ) month = dumInt; |
102 | dummy = element->attribute("DateDay" ); | 110 | dummy = element->attribute("DateDay" ); |
103 | dumInt = dummy.toInt(&ok ); | 111 | dumInt = dummy.toInt(&ok ); |
104 | if(ok ) day = dumInt; | 112 | if(ok ) day = dumInt; |
105 | // set the date | 113 | // set the date |
106 | QDate date( year, month, day ); | 114 | QDate date( year, month, day ); |
107 | event.setDate( date); | 115 | event.setDate( date); |
108 | } | 116 | } |
109 | dummy = element->attribute("Priority" ); | 117 | dummy = element->attribute("Priority" ); |
110 | dumInt = dummy.toInt(&ok ); | 118 | dumInt = dummy.toInt(&ok ); |
111 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 119 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
112 | event.setPriority( dumInt ); | 120 | event.setPriority( dumInt ); |
113 | //description | 121 | //description |
114 | dummy = element->attribute("Description" ); | 122 | dummy = element->attribute("Description" ); |
115 | event.setDescription( dummy ); | 123 | event.setDescription( dummy ); |
116 | dummy = element->attribute("Summary" ); | 124 | dummy = element->attribute("Summary" ); |