summaryrefslogtreecommitdiff
path: root/core/pim/todo/todotemplatemanager.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/todotemplatemanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotemplatemanager.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/core/pim/todo/todotemplatemanager.cpp b/core/pim/todo/todotemplatemanager.cpp
new file mode 100644
index 0000000..02941ac
--- a/dev/null
+++ b/core/pim/todo/todotemplatemanager.cpp
@@ -0,0 +1,75 @@
1#include <qpe/config.h>
2#include <qpe/global.h>
3
4#include <opie/otodoaccess.h>
5#include <opie/otodoaccessxml.h>
6
7#include "todotemplatemanager.h"
8
9
10using namespace Todo;
11
12TemplateManager::TemplateManager() {
13 m_path = Global::applicationFileName("todolist", "templates.xml");
14}
15TemplateManager::~TemplateManager() {
16
17}
18void TemplateManager::load() {
19 Config conf("todolist_templates");
20 OTodoAccessXML *xml = new OTodoAccessXML( QString::fromLatin1("template"),
21 m_path );
22 OTodoAccess todoDB(xml );
23 todoDB.load();
24
25 OTodoAccess::List::Iterator it;
26 OTodoAccess::List list = todoDB.allRecords();
27 for ( it = list.begin(); it != list.end(); ++it ) {
28 OTodo ev = (*it);
29 conf.setGroup( QString::number( ev.uid() ) );
30 QString str = conf.readEntry("Name", QString::null );
31 if (str.isEmpty() )
32 continue;
33
34 m_templates.insert( str,
35 ev );
36 }
37}
38void TemplateManager::save() {
39 Config conf("todolist_templates");
40
41 OTodoAccessXML *res = new OTodoAccessXML( "template",
42 m_path );
43 OTodoAccess db(res);
44
45
46 QMap<QString, OTodo>::Iterator it;
47 for ( it = m_templates.begin(); it != m_templates.end(); ++it ) {
48 OTodo ev = it.data();
49 conf.setGroup( QString::number( ev.uid() ) );
50 qWarning("Name" + it.key() );
51 conf.writeEntry("Name", it.key() );
52 db.add( ev );
53 }
54 db.save();
55}
56void TemplateManager::addEvent( const QString& str,
57 const OTodo& ev) {
58 qWarning("AddEvent"+ str );
59 m_templates.replace( str, ev );
60}
61void TemplateManager::removeEvent( const QString& str ) {
62 m_templates.remove( str );
63}
64QStringList TemplateManager::templates() const {
65 QStringList list;
66 QMap<QString, OTodo>::ConstIterator it;
67 for (it = m_templates.begin(); it != m_templates.end(); ++it ) {
68 list << it.key();
69 }
70
71 return list;
72}
73OTodo TemplateManager::templateEvent( const QString& templateName ) {
74 return m_templates[templateName];
75}