summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccessbackend.cpp
blob: c7ce123f90957526cb4449918e29dcb7096b0ede (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
                             This file is part of the Opie Project
                             Copyright (C) The Main Author <main-author@whereever.org>
              =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library 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/otodoaccessbackend.h>
#include <opie2/private/opimtodosortvector.h>
#include <opie2/otodoaccess.h>

#include <qintdict.h>

namespace Opie {
OPimTodoAccessBackend::OPimTodoAccessBackend()
    : OPimAccessBackend<OPimTodo>()
{
}
OPimTodoAccessBackend::~OPimTodoAccessBackend() {

}

const uint OPimTodoAccessBackend::querySettings() const
{
	return 0;
}

bool OPimTodoAccessBackend::hasQuerySettings (uint querySettings) const
{
	return false;
}


UIDArray OPimTodoAccessBackend::queryByExample( const UIDArray& uidlist, const OPimTodo& query, int settings,
                                                 const QDateTime& startperiod )const 
{
	qDebug( "Accessing OPimTodoAccessBackend::queryByExample() which is not implemented!" );
	return UIDArray();
    
//     odebug << "Using Unaccelerated OPimContactAccessBackend implementation of queryByExample!" << oendl;

//     UIDArray m_currentQuery( uid_array.count() );
//     uint arraycounter = 0;

//     for( uint it = 0; it < uid_array.count(); ++it ){
// 	    /* Search all fields and compare them with query object. Store them into list
// 	     * if all fields matches.
// 	     */
//     }


}

UIDArray OPimTodoAccessBackend::sorted( const UIDArray& events, bool asc,
                                        int sortOrder, int sortFilter,
                                        const QArray<int>& categories )const {
    odebug << "Using Unaccelerated TodoList sorted Implementation" << oendl;
    Internal::OPimTodoSortVector vector(events.count(), asc,sortOrder );
    int item = 0;

    bool bCat = sortFilter  & OPimTodoAccess::FilterCategory ? true : false;
    bool bOnly = sortFilter & OPimTodoAccess::OnlyOverDue ? true : false;
    bool comp = sortFilter  & OPimTodoAccess::DoNotShowCompleted ? true : false;
    bool catPassed = false;
    int cat;

    for ( uint i = 0; i < events.count(); ++i ) {
        OPimTodo todo = find( events[i], events, i, Frontend::Forward );
        if ( todo.isEmpty() )
            continue;

        /* show category */
        /* -1 == unfiled */
        catPassed = false;
        for ( uint cat_nu = 0; cat_nu < categories.count(); ++cat_nu ) {
            cat = categories[cat_nu];
            if ( bCat && cat == -1 ) {
                if(!todo.categories().isEmpty() )
                    continue;
            } else if ( bCat && cat != 0)
                if (!todo.categories().contains( cat ) )
                    continue;
            catPassed = true;
            break;
        }

        /*
         * If none of the Categories matched
         * continue
         */
        if ( !catPassed )
            continue;
        if ( !todo.isOverdue() && bOnly )
            continue;
        if (todo.isCompleted() && comp )
            continue;

        vector.insert(item++, todo );
    }

    vector.resize( item );
    /* sort it now */
    vector.sort();
    /* now get the uids */
    UIDArray array( vector.count() );
    for (uint i= 0; i < vector.count(); i++ )
        array[i] = vector.uidAt( i );

    return array;
}

OPimBackendOccurrence::List OPimTodoAccessBackend::occurrences( const QDate& start,
                                                                const QDate& end )const {
    OPimBackendOccurrence::List lst;
    UIDArray effective = effectiveToDos( start, end, false );
    UIDArray overdue = overDue();
    uint count = effective.count();
    int uid;
    QIntDict<int> hash;
    hash.setAutoDelete( true );
    OPimTodo todo;

    for ( uint i = 0; i < count; ++i ) {
        uid = effective[i];
        todo = find( uid, effective, i, Frontend::Forward );
        /*
         * If isOverdue but in the 'normal' range we will fill
         * the hash so we won't have duplicates in OPimBackendOccurrence
         */
        if ( todo.isOverdue() )
            hash.insert( uid, new int(6) );
        OPimBackendOccurrence oc = todo.hasStartDate() ?
                                   OPimBackendOccurrence( todo.startDate(),
                                                          todo.dueDate(), uid ) :
                                   OPimBackendOccurrence( todo.dueDate(), uid, QString::null );
        oc.setSummary( todo.summary() );
        lst.append( oc );
    }

    /*
     * Create the OverDue items but skip
     * the already handled Records
     */
    if ( !overdue.isEmpty() ) {
        QDate today = QDate::currentDate();
        QDate dueDate = (start >= today && today <= end ) ? today : start;
        count = overdue.count();
        for ( uint i = 0; i < count; ++i ) {
            uid = overdue[i];
            if (!hash.find( uid ) )
                continue;
            todo = find( uid, overdue, i, Frontend::Forward );
            lst.append( OPimBackendOccurrence(dueDate, uid, todo.summary() ) );
        }
    }

    return lst;
}
}