00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <opie2/odebug.h>
00032 #include <opie2/otodoaccess.h>
00033 #include <opie2/otodoaccessxml.h>
00034
00035 #include <qpe/config.h>
00036 #include <qpe/global.h>
00037
00038 #include "todotemplatemanager.h"
00039
00040
00041 using namespace Todo;
00042
00043 TemplateManager::TemplateManager() {
00044 m_path = Global::applicationFileName("todolist", "templates.xml");
00045 }
00046 TemplateManager::~TemplateManager() {
00047 save();
00048 }
00049 void TemplateManager::load() {
00050 Config conf("todolist_templates");
00051 OPimTodoAccessXML *xml = new OPimTodoAccessXML( QString::fromLatin1("template"),
00052 m_path );
00053 OPimTodoAccess todoDB(xml );
00054 todoDB.load();
00055
00056 OPimTodoAccess::List::Iterator it;
00057 OPimTodoAccess::List list = todoDB.allRecords();
00058 for ( it = list.begin(); it != list.end(); ++it ) {
00059 OPimTodo ev = (*it);
00060 conf.setGroup( QString::number( ev.uid() ) );
00061 QString str = conf.readEntry("Name", QString::null );
00062 if (str.isEmpty() )
00063 continue;
00064
00065 m_templates.insert( str, ev );
00066 }
00067 }
00068 void TemplateManager::save() {
00069 Config conf("todolist_templates");
00070
00071 OPimTodoAccessXML *res = new OPimTodoAccessXML( "template",
00072 m_path );
00073 OPimTodoAccess db(res);
00074 db.load();
00075 db.clear();
00076
00077
00078 QMap<QString, OPimTodo>::Iterator it;
00079 for ( it = m_templates.begin(); it != m_templates.end(); ++it ) {
00080 OPimTodo ev = it.data();
00081 conf.setGroup( QString::number( ev.uid() ) );
00082 conf.writeEntry("Name", it.key() );
00083 db.add( ev );
00084 }
00085 db.save();
00086 }
00087 void TemplateManager::addEvent( const QString& str,
00088 const OPimTodo& ev) {
00089 OPimTodo todo = ev;
00090 if( ev.uid() == 0 )
00091 todo.setUid(1);
00092
00093 m_templates.replace( str, todo );
00094 }
00095 void TemplateManager::removeEvent( const QString& str ) {
00096 m_templates.remove( str );
00097 }
00098 QStringList TemplateManager::templates() const {
00099 QStringList list;
00100 QMap<QString, OPimTodo>::ConstIterator it;
00101 for (it = m_templates.begin(); it != m_templates.end(); ++it ) {
00102 list << it.key();
00103 }
00104
00105 return list;
00106 }
00107 OPimTodo TemplateManager::templateEvent( const QString& templateName ) {
00108 return m_templates[templateName];
00109 }