summaryrefslogtreecommitdiff
path: root/core/pim/todo/todomanager.cpp
blob: 7826747151dacd9f3d51845c050bb7a38bf22045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
               =.            This file is part of the OPIE Project
             .=l.            Copyright (c)  2002 <>
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program 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 <opie2/odebug.h>

#include <qpe/categoryselect.h>

#include "todomanager.h"

using namespace Todo;

TodoManager::TodoManager( QObject *obj )
    : QObject( obj ) {
    m_db = 0l;
    QTime time;
    time.start();
    int el = time.elapsed();
    Opie::Core::owarn << "QTimer for loading " << el/1000 << oendl;
}
TodoManager::~TodoManager() {
    delete m_db;
}
OPimTodo TodoManager::event(int uid ) {
    return m_db->find( uid );
}
void TodoManager::updateList() {
    Opie::Core::owarn << "update lists" << oendl;
    m_list = m_db->allRecords();
}
OPimTodoAccess::List TodoManager::list() const{
    return m_list;
}
OPimTodoAccess::List TodoManager::sorted( bool asc, int so, int f, int cat ) {
    return m_db->sorted( asc, so, f, cat );
}
OPimTodoAccess::List::Iterator TodoManager::overDue() {
    int filter = 2 | 1;
    m_list = m_db->sorted(m_asc, m_sortOrder, filter,  m_ca );
    m_it = m_list.begin();
    return m_it;
}
OPimTodoAccess::List::Iterator TodoManager::fromTo( const QDate& start,
                                      const QDate& end ) {
    m_list = m_db->effectiveToDos( start, end );
    m_it = m_list.begin();
    return m_it;
}
OPimTodoAccess::List::Iterator TodoManager::query( const OPimTodo& ev, int query ) {
    m_list = m_db->queryByExample( ev, query );
    m_it = m_list.begin();
    return m_it;
}
OPimTodoAccess* TodoManager::todoDB() {
    return m_db;
}
void TodoManager::add( const OPimTodo& ev ) {
    m_db->add( ev );
}
void TodoManager::update( int, const SmallTodo& ) {

}
void TodoManager::update( int, const OPimTodo& ev) {
    m_db->replace( ev );
}
bool TodoManager::remove( int uid ) {
    return m_db->remove( uid );
}
void TodoManager::removeAll() {
    m_db->clear();
}
void TodoManager::removeCompleted() {
    m_db->removeAllCompleted();
}
void TodoManager::save() {
    m_db->save();
}
bool TodoManager::saveAll() {
    return m_db->save();
}
void TodoManager::reload() {
    m_db->reload();
}
QStringList TodoManager::categories() {
    m_cat.load(categoryFileName() );
    return m_cat.labels( "Todo List");
}
/*
 * we rely on load beeing called from populateCategories
 */
int TodoManager::catId( const QString& cats ) {
    return m_cat.id( "Todo List", cats );
}
void TodoManager::remove( const QArray<int>& ids) {
    for (uint i=0; i < ids.size(); i++ )
        remove( ids[i] );
}
bool TodoManager::isLoaded()const {
    return (m_db == 0 );
}
void TodoManager::load() {
    if (!m_db) {
        m_db = new OPimTodoAccess();
        m_db->load();
    }
}