summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index ebd03bb..3913661 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -102,49 +102,51 @@ namespace {
OverDueQuery();
~OverDueQuery();
QString query()const;
};
class EffQuery : public OSQLQuery {
public:
EffQuery( const QDate&, const QDate&, bool inc );
~EffQuery();
QString query()const;
private:
QString with()const;
QString out()const;
QDate m_start;
QDate m_end;
bool m_inc :1;
};
CreateQuery::CreateQuery() : OSQLQuery() {}
CreateQuery::~CreateQuery() {}
QString CreateQuery::query()const {
QString qu;
qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
qu += "description, summary, priority, DueDate, progress , state, ";
- qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);";
+ // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers)
+ qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
+ qu += "reminders, alarms, maintainer, startdate, completeddate);";
qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
return qu;
}
LoadQuery::LoadQuery() : OSQLQuery() {}
LoadQuery::~LoadQuery() {}
QString LoadQuery::query()const {
QString qu;
// We do not need "distinct" here. The primary key is always unique..
//qu += "select distinct uid from todolist";
qu += "select uid from todolist";
return qu;
}
InsertQuery::InsertQuery( const OTodo& todo )
: OSQLQuery(), m_todo( todo ) {
}
InsertQuery::~InsertQuery() {
}
/*
* converts from a OTodo to a query
* we leave out X-Ref + Alarms
*/
@@ -153,61 +155,69 @@ namespace {
int year, month, day;
year = month = day = 0;
if (m_todo.hasDueDate() ) {
QDate date = m_todo.dueDate();
year = date.year();
month = date.month();
day = date.day();
}
int sYear = 0, sMonth = 0, sDay = 0;
if( m_todo.hasStartDate() ){
QDate sDate = m_todo.startDate();
sYear = sDate.year();
sMonth= sDate.month();
sDay = sDate.day();
}
int eYear = 0, eMonth = 0, eDay = 0;
if( m_todo.hasCompletedDate() ){
QDate eDate = m_todo.completedDate();
eYear = eDate.year();
eMonth= eDate.month();
eDay = eDate.day();
}
QString qu;
+ QMap<int, QString> recMap = m_todo.recurrence().toMap();
qu = "insert into todolist VALUES("
+ QString::number( m_todo.uid() ) + ","
+ "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
+ QString::number( m_todo.isCompleted() ) + ","
+ "'" + m_todo.description() + "'" + ","
+ "'" + m_todo.summary() + "'" + ","
+ QString::number(m_todo.priority() ) + ","
+ "'" + QString::number(year) + "-"
+ QString::number(month)
+ "-" + QString::number( day ) + "'" + ","
+ QString::number( m_todo.progress() ) + ","
+ QString::number( m_todo.state().state() ) + ","
- + "'" + m_todo.recurrence().toString() + "'"+ ",";
+ + "'" + recMap[ ORecur::RType ] + "'" + ","
+ + "'" + recMap[ ORecur::RWeekdays ] + "'" + ","
+ + "'" + recMap[ ORecur::RPosition ] + "'" + ","
+ + "'" + recMap[ ORecur::RFreq ] + "'" + ","
+ + "'" + recMap[ ORecur::RHasEndDate ] + "'" + ","
+ + "'" + recMap[ ORecur::EndDate ] + "'" + ","
+ + "'" + recMap[ ORecur::Created ] + "'" + ","
+ + "'" + recMap[ ORecur::Exceptions ] + "'" + ",";
if ( m_todo.hasNotifiers() ) {
OPimNotifyManager manager = m_todo.notifiers();
qu += "'" + manager.remindersToString() + "'" + ","
+ "'" + manager.alarmsToString() + "'" + ",";
}
else{
qu += QString( "''" ) + ","
+ "''" + ",";
}
qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
+ "'" + QString::number(sYear) + "-"
+ QString::number(sMonth)
+ "-" + QString::number(sDay) + "'" + ","
+ "'" + QString::number(eYear) + "-"
+ QString::number(eMonth)
+ "-"+QString::number(eDay) + "'"
+ ")";
qWarning("add %s", qu.latin1() );
return qu;
}
@@ -503,78 +513,91 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
if ( res.state() == OSQLResult::Failure ) {
OTodo to;
return to;
}
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
qWarning("todo1");
OTodo to = todo( (*it) );
cache( to );
++it;
for ( ; it != list.end(); ++it ) {
qWarning("caching");
cache( todo( (*it) ) );
}
return to;
}
OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
qWarning("todo");
bool hasDueDate = false; QDate dueDate = QDate::currentDate();
hasDueDate = date( dueDate, item.data("DueDate") );
QStringList cats = QStringList::split(";", item.data("categories") );
+ qWarning("Item is completed: %d", item.data("completed").toInt() );
+
OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
cats, item.data("summary"), item.data("description"),
item.data("progress").toUShort(), hasDueDate, dueDate,
item.data("uid").toInt() );
bool isOk;
int prioInt = QString( item.data("priority") ).toInt( &isOk );
if ( isOk )
to.setPriority( prioInt );
bool hasStartDate = false; QDate startDate = QDate::currentDate();
hasStartDate = date( startDate, item.data("startdate") );
bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
hasCompletedDate = date( completedDate, item.data("completeddate") );
if ( hasStartDate )
to.setStartDate( startDate );
if ( hasCompletedDate )
to.setCompletedDate( completedDate );
OPimNotifyManager& manager = to.notifiers();
manager.alarmsFromString( item.data("alarms") );
manager.remindersFromString( item.data("reminders") );
OPimState pimState;
pimState.setState( QString( item.data("state") ).toInt() );
to.setState( pimState );
- // Recurrence not supported yet
- // to.setRecurrence(
+ QMap<int, QString> recMap;
+ recMap.insert( ORecur::RType , item.data("RType") );
+ recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") );
+ recMap.insert( ORecur::RPosition , item.data("RPosition") );
+ recMap.insert( ORecur::RFreq , item.data("RFreq") );
+ recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") );
+ recMap.insert( ORecur::EndDate , item.data("EndDate") );
+ recMap.insert( ORecur::Created , item.data("Created") );
+ recMap.insert( ORecur::Exceptions , item.data("Exceptions") );
+
+ ORecur recur;
+ recur.fromMap( recMap );
+ to.setRecurrence( recur );
return to;
}
OTodo OTodoAccessBackendSQL::todo( int uid )const {
FindQuery find( uid );
return todo( m_driver->query(&find) );
}
/*
* update the dict
*/
void OTodoAccessBackendSQL::fillDict() {
/* initialize dict */
/*
* UPDATE dict if you change anything!!!
* FIXME: Isn't this dict obsolete ? (eilers)
*/
m_dict.setAutoDelete( TRUE );
m_dict.insert("Categories" , new int(OTodo::Category) );
m_dict.insert("Uid" , new int(OTodo::Uid) );
m_dict.insert("HasDate" , new int(OTodo::HasDate) );
m_dict.insert("Completed" , new int(OTodo::Completed) );
m_dict.insert("Description" , new int(OTodo::Description) );
m_dict.insert("Summary" , new int(OTodo::Summary) );
m_dict.insert("Priority" , new int(OTodo::Priority) );