-rw-r--r-- | libopie/tododb.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index 3f6dc30..4d6711d 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp @@ -176,52 +176,72 @@ QValueList<ToDoEvent> ToDoDB::overDue() QValueList<ToDoEvent> events; for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ if( (*it).isOverdue() ) events.append((*it) ); } return events; } QValueList<ToDoEvent> ToDoDB::rawToDos() { return m_todos; } void ToDoDB::addEvent( const ToDoEvent &event ) { m_todos.append( event ); } void ToDoDB::editEvent( const ToDoEvent &event ) { m_todos.remove( event ); m_todos.append( event ); } void ToDoDB::removeEvent( const ToDoEvent &event ) { m_todos.remove( event ); } +void ToDoDB::replaceEvent(const ToDoEvent &event ) +{ + QValueList<ToDoEvent>::Iterator it; + int uid = event.uid(); + // == is not overloaded as we would like :( so let's search for the uid + for(it = m_todos.begin(); it != m_todos.end(); ++it ){ + if( (*it).uid() == uid ){ + m_todos.remove( (*it) ); + break; // should save us the iterate is now borked + } + } + m_todos.append(event); +} void ToDoDB::reload() { load(); } +void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) +{ + QValueList<ToDoEvent>::ConstIterator it; + for( it = events.begin(); it != events.end(); ++it ){ + replaceEvent( (*it) ); + } +} void ToDoDB::setFileName(const QString &file ) { m_fileName =file; } QString ToDoDB::fileName()const { return m_fileName; } void ToDoDB::load() { m_todos = m_res->load( m_fileName ); } bool ToDoDB::save() { return m_res->save( m_fileName, m_todos ); } |