summaryrefslogtreecommitdiff
authorzecke <zecke>2002-04-25 16:11:10 (UTC)
committer zecke <zecke>2002-04-25 16:11:10 (UTC)
commite944a214e0efeccd2eb9cc479ad8893427c6b81d (patch) (unidiff)
tree263f754a34d23738dac6c3dea9dbcb0ce8b6bb3e
parent48dbc8fb69a5d19f466ea757207e42c3861b4dee (diff)
downloadopie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.zip
opie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.tar.gz
opie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.tar.bz2
This should fix the Umlaut problem
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/tododb.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
index c486723..33fa177 100644
--- a/libopie/tododb.cpp
+++ b/libopie/tododb.cpp
@@ -1,143 +1,144 @@
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
9namespace { 9namespace {
10 10
11class FileToDoResource : public ToDoResource { 11class FileToDoResource : public ToDoResource {
12public: 12public:
13 FileToDoResource() {}; 13 FileToDoResource() {};
14 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ 14 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
15 // prepare the XML 15 // prepare the XML
16 XMLElement *tasks = new XMLElement( ); 16 XMLElement *tasks = new XMLElement( );
17 tasks->setTagName("Tasks" ); 17 tasks->setTagName("Tasks" );
18 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ 18 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
19 XMLElement::AttributeMap map; 19 XMLElement::AttributeMap map;
20 XMLElement *task = new XMLElement(); 20 XMLElement *task = new XMLElement();
21 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); 21 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
22 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); 22 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
23 map.insert( "Priority", QString::number( (*it).priority() ) ); 23 map.insert( "Priority", QString::number( (*it).priority() ) );
24 QArray<int> arrat = (*it).categories(); 24 QArray<int> arrat = (*it).categories();
25 QString attr; 25 QString attr;
26 for(uint i=0; i < arrat.count(); i++ ){ 26 for(uint i=0; i < arrat.count(); i++ ){
27 attr.append(QString::number(arrat[i])+";" ); 27 attr.append(QString::number(arrat[i])+";" );
28 } 28 }
29 if(!attr.isEmpty() ) // remove the last ; 29 if(!attr.isEmpty() ) // remove the last ;
30 attr.remove(attr.length()-1, 1 ); 30 attr.remove(attr.length()-1, 1 );
31 map.insert( "Categories", attr ); 31 map.insert( "Categories", attr );
32 //else 32 //else
33 //map.insert( "Categories", QString::null ); 33 //map.insert( "Categories", QString::null );
34 map.insert( "Description", (*it).description() ); 34 map.insert( "Description", (*it).description() );
35 if( (*it).hasDate() ){ 35 if( (*it).hasDate() ){
36 map.insert("DateYear", QString::number( (*it).date().year() ) ); 36 map.insert("DateYear", QString::number( (*it).date().year() ) );
37 map.insert("DateMonth", QString::number( (*it).date().month() ) ); 37 map.insert("DateMonth", QString::number( (*it).date().month() ) );
38 map.insert("DateDay", QString::number( (*it).date().day() ) ); 38 map.insert("DateDay", QString::number( (*it).date().day() ) );
39 } 39 }
40 map.insert("Uid", QString::number( (*it).uid() ) ); 40 map.insert("Uid", QString::number( (*it).uid() ) );
41 task->setTagName("Task" ); 41 task->setTagName("Task" );
42 task->setAttributes( map ); 42 task->setAttributes( map );
43 tasks->appendChild(task); 43 tasks->appendChild(task);
44 } 44 }
45 QFile file( name); 45 QFile file( name);
46 if( file.open(IO_WriteOnly ) ){ 46 if( file.open(IO_WriteOnly ) ){
47 QTextStream stream(&file ); 47 QTextStream stream(&file );
48 stream.setEncoding( QTextStream::UnicodeUTF8 );
48 stream << "<!DOCTYPE Tasks>" << endl; 49 stream << "<!DOCTYPE Tasks>" << endl;
49 tasks->save(stream ); 50 tasks->save(stream );
50 delete tasks; 51 delete tasks;
51 stream << "</Tasks>" << endl; 52 stream << "</Tasks>" << endl;
52 file.close(); 53 file.close();
53 return true; 54 return true;
54 } 55 }
55 return false; 56 return false;
56 } 57 }
57 QValueList<ToDoEvent> load( const QString &name ){ 58 QValueList<ToDoEvent> load( const QString &name ){
58 qWarning("loading tododb" ); 59 qWarning("loading tododb" );
59 QValueList<ToDoEvent> m_todos; 60 QValueList<ToDoEvent> m_todos;
60 XMLElement *root = XMLElement::load( name ); 61 XMLElement *root = XMLElement::load( name );
61 if(root != 0l ){ // start parsing 62 if(root != 0l ){ // start parsing
62 qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); 63 qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() );
63 //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start 64 //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start
64 XMLElement *element = root->firstChild(); 65 XMLElement *element = root->firstChild();
65 element = element->firstChild(); 66 element = element->firstChild();
66 while( element ){ 67 while( element ){
67 if( element->tagName() != QString::fromLatin1("Task") ){ 68 if( element->tagName() != QString::fromLatin1("Task") ){
68 element = element->nextChild(); 69 element = element->nextChild();
69 continue; 70 continue;
70 } 71 }
71 qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); 72 qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() );
72 QString dummy; 73 QString dummy;
73 ToDoEvent event; 74 ToDoEvent event;
74 bool ok; 75 bool ok;
75 int dumInt; 76 int dumInt;
76 // completed 77 // completed
77 dummy = element->attribute("Completed" ); 78 dummy = element->attribute("Completed" );
78 dumInt = dummy.toInt(&ok ); 79 dumInt = dummy.toInt(&ok );
79 if(ok ) event.setCompleted( dumInt == 0 ? false : true ); 80 if(ok ) event.setCompleted( dumInt == 0 ? false : true );
80 // hasDate 81 // hasDate
81 dummy = element->attribute("HasDate" ); 82 dummy = element->attribute("HasDate" );
82 dumInt = dummy.toInt(&ok ); 83 dumInt = dummy.toInt(&ok );
83 if(ok ) event.setHasDate( dumInt == 0 ? false: true ); 84 if(ok ) event.setHasDate( dumInt == 0 ? false: true );
84 // set the date 85 // set the date
85 bool hasDa = dumInt; 86 bool hasDa = dumInt;
86 if ( hasDa ) { //parse the date 87 if ( hasDa ) { //parse the date
87 int year, day, month = 0; 88 int year, day, month = 0;
88 year = day = month; 89 year = day = month;
89 // year 90 // year
90 dummy = element->attribute("DateYear" ); 91 dummy = element->attribute("DateYear" );
91 dumInt = dummy.toInt(&ok ); 92 dumInt = dummy.toInt(&ok );
92 if( ok ) year = dumInt; 93 if( ok ) year = dumInt;
93 // month 94 // month
94 dummy = element->attribute("DateMonth" ); 95 dummy = element->attribute("DateMonth" );
95 dumInt = dummy.toInt(&ok ); 96 dumInt = dummy.toInt(&ok );
96 if(ok ) month = dumInt; 97 if(ok ) month = dumInt;
97 dummy = element->attribute("DateDay" ); 98 dummy = element->attribute("DateDay" );
98 dumInt = dummy.toInt(&ok ); 99 dumInt = dummy.toInt(&ok );
99 if(ok ) day = dumInt; 100 if(ok ) day = dumInt;
100 // set the date 101 // set the date
101 QDate date( year, month, day ); 102 QDate date( year, month, day );
102 event.setDate( date); 103 event.setDate( date);
103 } 104 }
104 dummy = element->attribute("Priority" ); 105 dummy = element->attribute("Priority" );
105 dumInt = dummy.toInt(&ok ); 106 dumInt = dummy.toInt(&ok );
106 if(!ok ) dumInt = ToDoEvent::NORMAL; 107 if(!ok ) dumInt = ToDoEvent::NORMAL;
107 event.setPriority( dumInt ); 108 event.setPriority( dumInt );
108 //description 109 //description
109 dummy = element->attribute("Description" ); 110 dummy = element->attribute("Description" );
110 event.setDescription( dummy ); 111 event.setDescription( dummy );
111 // category 112 // category
112 dummy = element->attribute("Categories" ); 113 dummy = element->attribute("Categories" );
113 QStringList ids = QStringList::split(";", dummy ); 114 QStringList ids = QStringList::split(";", dummy );
114 event.setCategories( ids ); 115 event.setCategories( ids );
115 116
116 //uid 117 //uid
117 dummy = element->attribute("Uid" ); 118 dummy = element->attribute("Uid" );
118 dumInt = dummy.toInt(&ok ); 119 dumInt = dummy.toInt(&ok );
119 if(ok ) event.setUid( dumInt ); 120 if(ok ) event.setUid( dumInt );
120 m_todos.append( event ); 121 m_todos.append( event );
121 element = element->nextChild(); // next element 122 element = element->nextChild(); // next element
122 } 123 }
123 //} 124 //}
124 }else { 125 }else {
125 qWarning("could not load" ); 126 qWarning("could not load" );
126 } 127 }
127 delete root; 128 delete root;
128 qWarning("returning" ); 129 qWarning("returning" );
129 return m_todos; 130 return m_todos;
130 } 131 }
131}; 132};
132 133
133} 134}
134 135
135ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ 136ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){
136 m_fileName = fileName; 137 m_fileName = fileName;
137 if( fileName.isEmpty() && res == 0 ){ 138 if( fileName.isEmpty() && res == 0 ){
138 m_fileName = Global::applicationFileName("todolist","todolist.xml"); 139 m_fileName = Global::applicationFileName("todolist","todolist.xml");
139 res = new FileToDoResource(); 140 res = new FileToDoResource();
140 //qWarning("%s", m_fileName.latin1() ); 141 //qWarning("%s", m_fileName.latin1() );
141 }else if(res == 0 ){ // let's create a ToDoResource for xml 142 }else if(res == 0 ){ // let's create a ToDoResource for xml
142 res = new FileToDoResource(); 143 res = new FileToDoResource();
143 } 144 }