summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccessxml.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 285d2b8..69b7ab4 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -521,256 +521,272 @@ QString OTodoAccessXML::toString( const OTodo& ev )const {
str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" ";
if ( ev.hasState() )
str += "State=\""+QString::number( ev.state().state() )+"\" ";
return str;
}
QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
return Qtopia::Record::idsToString( ints );
}
/* internal class for sorting
*
* Inspired by todoxmlio.cpp from TT
*/
struct OTodoXMLContainer {
OTodo todo;
};
namespace {
inline QString string( const OTodo& todo) {
return todo.summary().isEmpty() ?
todo.description().left(20 ) :
todo.summary();
}
inline int completed( const OTodo& todo1, const OTodo& todo2) {
int ret = 0;
if ( todo1.isCompleted() ) ret++;
if ( todo2.isCompleted() ) ret--;
return ret;
}
inline int priority( const OTodo& t1, const OTodo& t2) {
return ( t1.priority() - t2.priority() );
}
inline int description( const OTodo& t1, const OTodo& t2) {
return QString::compare( string(t1), string(t2) );
}
inline int deadline( const OTodo& t1, const OTodo& t2) {
int ret = 0;
if ( t1.hasDueDate() &&
t2.hasDueDate() )
ret = t2.dueDate().daysTo( t1.dueDate() );
else if ( t1.hasDueDate() )
ret = -1;
else if ( t2.hasDueDate() )
ret = 1;
else
ret = 0;
return ret;
}
};
/*
* Returns:
* 0 if item1 == item2
*
* non-zero if item1 != item2
*
* This function returns int rather than bool so that reimplementations
* can return one of three values and use it to sort by:
*
* 0 if item1 == item2
*
* > 0 (positive integer) if item1 > item2
*
* < 0 (negative integer) if item1 < item2
*
*/
class OTodoXMLVector : public QVector<OTodoXMLContainer> {
public:
OTodoXMLVector(int size, bool asc, int sort)
: QVector<OTodoXMLContainer>( size )
{
setAutoDelete( true );
m_asc = asc;
m_sort = sort;
}
/* return the summary/description */
QString string( const OTodo& todo) {
return todo.summary().isEmpty() ?
todo.description().left(20 ) :
todo.summary();
}
/**
* we take the sortorder( switch on it )
*
*/
int compareItems( Item d1, Item d2 ) {
bool seComp, sePrio, seDesc, seDeadline;
seComp = sePrio = seDeadline = seDesc = false;
int ret =0;
OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
/* same item */
if ( con1->todo.uid() == con2->todo.uid() )
return 0;
switch ( m_sort ) {
/* completed */
case 0: {
ret = completed( con1->todo, con2->todo );
seComp = TRUE;
break;
}
/* priority */
case 1: {
ret = priority( con1->todo, con2->todo );
sePrio = TRUE;
break;
}
/* description */
case 2: {
ret = description( con1->todo, con2->todo );
seDesc = TRUE;
break;
}
/* deadline */
case 3: {
ret = deadline( con1->todo, con2->todo );
seDeadline = TRUE;
break;
}
default:
ret = 0;
break;
};
/*
* FIXME do better sorting if the first sort criteria
* ret equals 0 start with complete and so on...
*/
/* twist it we're not ascending*/
if (!m_asc)
ret = ret * -1;
if ( ret )
return ret;
// default did not gave difference let's try it other way around
/*
* General try if already checked if not test
* and return
* 1.Completed
* 2.Priority
* 3.Description
* 4.DueDate
*/
if (!seComp ) {
if ( (ret = completed( con1->todo, con2->todo ) ) ) {
if (!m_asc ) ret *= -1;
return ret;
}
}
if (!sePrio ) {
if ( (ret = priority( con1->todo, con2->todo ) ) ) {
if (!m_asc ) ret *= -1;
return ret;
}
}
if (!seDesc ) {
if ( (ret = description(con1->todo, con2->todo ) ) ) {
if (!m_asc) ret *= -1;
return ret;
}
}
if (!seDeadline) {
if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
if (!m_asc) ret *= -1;
return ret;
}
}
return 0;
}
private:
bool m_asc;
int m_sort;
};
QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
int sortFilter, int cat ) {
qWarning("sorted! %d cat", cat);
OTodoXMLVector vector(m_events.count(), asc,sortOrder );
QMap<int, OTodo>::Iterator it;
int item = 0;
bool bCat = sortFilter & 1 ? true : false;
bool bOnly = sortFilter & 2 ? true : false;
bool comp = sortFilter & 4 ? true : false;
for ( it = m_events.begin(); it != m_events.end(); ++it ) {
/* show category */
if ( bCat && cat != 0)
if (!(*it).categories().contains( cat ) ) {
qWarning("category mis match");
continue;
}
/* isOverdue but we should not show overdue - why?*/
/* if ( (*it).isOverdue() && !bOnly ) {
qWarning("item is overdue but !bOnly");
continue;
}
*/
if ( !(*it).isOverdue() && bOnly ) {
qWarning("item is not overdue but bOnly checked");
continue;
}
if ((*it).isCompleted() && comp ) {
qWarning("completed continue!");
continue;
}
OTodoXMLContainer* con = new OTodoXMLContainer();
con->todo = (*it);
vector.insert(item, con );
item++;
}
qWarning("XXX %d Items added", item);
vector.resize( item );
/* sort it now */
vector.sort();
/* now get the uids */
QArray<int> array( vector.count() );
for (uint i= 0; i < vector.count(); i++ ) {
array[i] = ( vector.at(i) )->todo.uid();
}
return array;
};
void OTodoAccessXML::removeAllCompleted() {
for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
if ( (*it).isCompleted() )
m_events.remove( it );
}
}
QBitArray OTodoAccessXML::supports()const {
static QBitArray ar = sup();
return ar;
}
QBitArray OTodoAccessXML::sup() {
QBitArray ar( OTodo::CompletedDate +1 );
ar.fill( true );
ar[OTodo::CrossReference] = false;
ar[OTodo::State ] = false;
ar[OTodo::Reminders] = false;
ar[OTodo::Notifiers] = false;
ar[OTodo::Maintainer] = false;
return ar;
}
+QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const
+{
+ QArray<int> m_currentQuery( m_events.count() );
+ uint arraycounter = 0;
+
+ QMap<int, OTodo>::ConstIterator it;
+ for (it = m_events.begin(); it != m_events.end(); ++it ) {
+ if ( it.data().match( r ) )
+ m_currentQuery[arraycounter++] = it.data().uid();
+
+ }
+ // Shrink to fit..
+ m_currentQuery.resize(arraycounter);
+
+ return m_currentQuery;
+}