summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/tododb.cpp2
-rw-r--r--libopie/xmltree.cc1
-rw-r--r--libopie/xmltree.h5
3 files changed, 8 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,104 +1,106 @@
#include <qdir.h>
#include <opie/tododb.h>
#include <opie/xmltree.h>
#include <opie/todoresource.h>
#include <qpe/palmtoprecord.h>
#include <qpe/global.h>
+using namespace Opie;
+
namespace {
class FileToDoResource : public ToDoResource {
public:
FileToDoResource() {};
bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
// prepare the XML
XMLElement *tasks = new XMLElement( );
tasks->setTagName("Tasks" );
for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
XMLElement::AttributeMap map;
XMLElement *task = new XMLElement();
map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
map.insert( "Priority", QString::number( (*it).priority() ) );
QArray<int> arrat = (*it).categories();
QString attr;
for(uint i=0; i < arrat.count(); i++ ){
attr.append(QString::number(arrat[i])+";" );
}
if(!attr.isEmpty() ) // remove the last ;
attr.remove(attr.length()-1, 1 );
map.insert( "Categories", attr );
//else
//map.insert( "Categories", QString::null );
map.insert( "Description", (*it).description() );
if( (*it).hasDate() ){
map.insert("DateYear", QString::number( (*it).date().year() ) );
map.insert("DateMonth", QString::number( (*it).date().month() ) );
map.insert("DateDay", QString::number( (*it).date().day() ) );
}
map.insert("Uid", QString::number( (*it).uid() ) );
task->setTagName("Task" );
task->setAttributes( map );
tasks->appendChild(task);
}
QFile file( name);
if( file.open(IO_WriteOnly ) ){
QTextStream stream(&file );
stream.setEncoding( QTextStream::UnicodeUTF8 );
stream << "<!DOCTYPE Tasks>" << endl;
tasks->save(stream );
delete tasks;
stream << "</Tasks>" << endl;
file.close();
return true;
}
return false;
}
QValueList<ToDoEvent> load( const QString &name ){
qWarning("loading tododb" );
QValueList<ToDoEvent> m_todos;
XMLElement *root = XMLElement::load( name );
if(root != 0l ){ // start parsing
qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() );
//if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start
XMLElement *element = root->firstChild();
element = element->firstChild();
while( element ){
if( element->tagName() != QString::fromLatin1("Task") ){
element = element->nextChild();
continue;
}
qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() );
QString dummy;
ToDoEvent event;
bool ok;
int dumInt;
// completed
dummy = element->attribute("Completed" );
dumInt = dummy.toInt(&ok );
if(ok ) event.setCompleted( dumInt == 0 ? false : true );
// hasDate
dummy = element->attribute("HasDate" );
dumInt = dummy.toInt(&ok );
if(ok ) event.setHasDate( dumInt == 0 ? false: true );
// set the date
bool hasDa = dumInt;
if ( hasDa ) { //parse the date
int year, day, month = 0;
year = day = month;
// year
dummy = element->attribute("DateYear" );
dumInt = dummy.toInt(&ok );
if( ok ) year = dumInt;
// month
dummy = element->attribute("DateMonth" );
dumInt = dummy.toInt(&ok );
if(ok ) month = dumInt;
dummy = element->attribute("DateDay" );
dumInt = dummy.toInt(&ok );
if(ok ) day = dumInt;
// set the date
QDate date( year, month, day );
event.setDate( date);
}
diff --git a/libopie/xmltree.cc b/libopie/xmltree.cc
index 408e3c6..27db5b3 100644
--- a/libopie/xmltree.cc
+++ b/libopie/xmltree.cc
@@ -1,122 +1,123 @@
/* This file is part of the KDE project
Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qpe/stringutil.h>
#include <opie/xmltree.h>
#include <qxml.h>
#include <assert.h>
+using namespace Opie;
XMLElement::XMLElement()
: m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 )
{
}
XMLElement::~XMLElement()
{
XMLElement *n = m_first;
while ( n )
{
XMLElement *tmp = n;
n = n->m_next;
delete tmp;
}
}
void XMLElement::appendChild( XMLElement *child )
{
if ( child->m_parent )
child->m_parent->removeChild( child );
child->m_parent = this;
if ( m_last )
m_last->m_next = child;
child->m_prev = m_last;
if ( !m_first )
m_first = child;
m_last = child;
}
void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild )
{
assert( newChild != refChild );
if ( refChild == m_last )
{
appendChild( newChild );
return;
}
assert( refChild );
assert( refChild->m_parent );
assert( refChild->m_parent == this );
if ( newChild->m_parent && newChild != refChild )
newChild->m_parent->removeChild( newChild );
newChild->m_parent = this;
XMLElement *next = refChild->m_next;
refChild->m_next = newChild;
newChild->m_prev = refChild;
newChild->m_next = next;
if ( next )
next->m_prev = newChild;
}
QString XMLElement::attribute( const QString &attr ) const
{
AttributeMap::ConstIterator it = m_attributes.find( attr );
if ( it == m_attributes.end() )
return QString::null;
return it.data();
}
void XMLElement::setAttribute( const QString &attr, const QString &value )
{
m_attributes.replace( attr, value );
}
void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild )
{
assert( refChild );
assert( refChild->m_parent );
assert( refChild->m_parent == this );
assert( newChild != refChild );
if ( newChild->m_parent && newChild != refChild )
newChild->m_parent->removeChild( newChild );
newChild->m_parent = this;
XMLElement *prev = refChild->m_prev;
refChild->m_prev = newChild;
newChild->m_prev = prev;
diff --git a/libopie/xmltree.h b/libopie/xmltree.h
index ed93c23..4a6b6d9 100644
--- a/libopie/xmltree.h
+++ b/libopie/xmltree.h
@@ -1,112 +1,117 @@
/* This file is part of the KDE project
Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __bookmarks_h__
#define __bookmarks_h__
#include <qstring.h>
#include <qmap.h>
#include <qtextstream.h>
+namespace Opie
+{
+
/**
* A small xml lib written by Simon Hausmann.
*/
class XMLElement
{
public:
typedef QMap<QString, QString> AttributeMap;
/**
* The constructor of XMLElement
*/
XMLElement();
~XMLElement();
/** appendChild appends a child to the XMLElement behind the last element.
* The ownership of the child get's transfered to the
* this XMLElement.
* If child is already the child of another parent
* it's get removed from the other parent first.
*/
void appendChild( XMLElement *child );
/** inserts newChild after refChild. If newChild is the child
* of another parent the child will get removed.
* The ownership of child gets transfered.
*
*/
void insertAfter( XMLElement *newChild, XMLElement *refChild );
/** same as insertAfter but the element get's inserted before refChild.
*
*/
void insertBefore( XMLElement *newChild, XMLElement *refChild );
/** removeChild removes the child from the XMLElement.
* The ownership gets dropped. You need to delete the
* child yourself.
*/
void removeChild( XMLElement *child );
/** parent() returns the parent of this XMLElement
* If there is no parent 0l gets returned
*/
XMLElement *parent() const { return m_parent; }
XMLElement *firstChild() const { return m_first; }
XMLElement *nextChild() const { return m_next; }
XMLElement *prevChild() const { return m_prev; }
XMLElement *lastChild() const { return m_last; }
void setTagName( const QString &tag ) { m_tag = tag; }
QString tagName() const { return m_tag; }
void setValue( const QString &val ) { m_value = val; }
QString value() const { return m_value; }
void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; }
AttributeMap attributes() const { return m_attributes; }
AttributeMap &attributes() { return m_attributes; }
QString attribute( const QString & ) const;
void setAttribute( const QString &attr, const QString &value );
void save( QTextStream &stream, uint indent = 0 );
XMLElement *namedItem( const QString &name );
XMLElement *clone() const;
static XMLElement *load( const QString &fileName );
private:
QString m_tag;
QString m_value;
AttributeMap m_attributes;
XMLElement *m_parent;
XMLElement *m_next;
XMLElement *m_prev;
XMLElement *m_first;
XMLElement *m_last;
XMLElement( const XMLElement &rhs );
XMLElement &operator=( const XMLElement &rhs );
};
+} // namespace Opie
+
#endif