summaryrefslogtreecommitdiff
path: root/libopie/tododb.cpp
authorsimon <simon>2002-04-30 14:26:53 (UTC)
committer simon <simon>2002-04-30 14:26:53 (UTC)
commit5dae945f8ec25a811efb10eb71d606ce8da4429f (patch) (unidiff)
treec12689435fbfb2abd6aedfcbd88208c1cb69407f /libopie/tododb.cpp
parent3c1b87ffa621f872c72228733a078511e56d2daf (diff)
downloadopie-5dae945f8ec25a811efb10eb71d606ce8da4429f.zip
opie-5dae945f8ec25a811efb10eb71d606ce8da4429f.tar.gz
opie-5dae945f8ec25a811efb10eb71d606ce8da4429f.tar.bz2
- put the xml tree classes into the Opie namespace
Diffstat (limited to 'libopie/tododb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/tododb.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
index 33fa177..fe8b8bf 100644
--- a/libopie/tododb.cpp
+++ b/libopie/tododb.cpp
@@ -1,56 +1,58 @@
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
9using namespace Opie;
10
9namespace { 11namespace {
10 12
11class FileToDoResource : public ToDoResource { 13class FileToDoResource : public ToDoResource {
12public: 14public:
13 FileToDoResource() {}; 15 FileToDoResource() {};
14 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ 16 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
15 // prepare the XML 17 // prepare the XML
16 XMLElement *tasks = new XMLElement( ); 18 XMLElement *tasks = new XMLElement( );
17 tasks->setTagName("Tasks" ); 19 tasks->setTagName("Tasks" );
18 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ 20 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
19 XMLElement::AttributeMap map; 21 XMLElement::AttributeMap map;
20 XMLElement *task = new XMLElement(); 22 XMLElement *task = new XMLElement();
21 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); 23 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
22 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); 24 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
23 map.insert( "Priority", QString::number( (*it).priority() ) ); 25 map.insert( "Priority", QString::number( (*it).priority() ) );
24 QArray<int> arrat = (*it).categories(); 26 QArray<int> arrat = (*it).categories();
25 QString attr; 27 QString attr;
26 for(uint i=0; i < arrat.count(); i++ ){ 28 for(uint i=0; i < arrat.count(); i++ ){
27 attr.append(QString::number(arrat[i])+";" ); 29 attr.append(QString::number(arrat[i])+";" );
28 } 30 }
29 if(!attr.isEmpty() ) // remove the last ; 31 if(!attr.isEmpty() ) // remove the last ;
30 attr.remove(attr.length()-1, 1 ); 32 attr.remove(attr.length()-1, 1 );
31 map.insert( "Categories", attr ); 33 map.insert( "Categories", attr );
32 //else 34 //else
33 //map.insert( "Categories", QString::null ); 35 //map.insert( "Categories", QString::null );
34 map.insert( "Description", (*it).description() ); 36 map.insert( "Description", (*it).description() );
35 if( (*it).hasDate() ){ 37 if( (*it).hasDate() ){
36 map.insert("DateYear", QString::number( (*it).date().year() ) ); 38 map.insert("DateYear", QString::number( (*it).date().year() ) );
37 map.insert("DateMonth", QString::number( (*it).date().month() ) ); 39 map.insert("DateMonth", QString::number( (*it).date().month() ) );
38 map.insert("DateDay", QString::number( (*it).date().day() ) ); 40 map.insert("DateDay", QString::number( (*it).date().day() ) );
39 } 41 }
40 map.insert("Uid", QString::number( (*it).uid() ) ); 42 map.insert("Uid", QString::number( (*it).uid() ) );
41 task->setTagName("Task" ); 43 task->setTagName("Task" );
42 task->setAttributes( map ); 44 task->setAttributes( map );
43 tasks->appendChild(task); 45 tasks->appendChild(task);
44 } 46 }
45 QFile file( name); 47 QFile file( name);
46 if( file.open(IO_WriteOnly ) ){ 48 if( file.open(IO_WriteOnly ) ){
47 QTextStream stream(&file ); 49 QTextStream stream(&file );
48 stream.setEncoding( QTextStream::UnicodeUTF8 ); 50 stream.setEncoding( QTextStream::UnicodeUTF8 );
49 stream << "<!DOCTYPE Tasks>" << endl; 51 stream << "<!DOCTYPE Tasks>" << endl;
50 tasks->save(stream ); 52 tasks->save(stream );
51 delete tasks; 53 delete tasks;
52 stream << "</Tasks>" << endl; 54 stream << "</Tasks>" << endl;
53 file.close(); 55 file.close();
54 return true; 56 return true;
55 } 57 }
56 return false; 58 return false;