Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

todotemplatemanager.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
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); // generate a new uid
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 }

Generated on Sat Nov 5 16:15:56 2005 for OPIE by  doxygen 1.4.2