summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h53
-rw-r--r--libopie2/opiepim/core/otemplatebase.h2
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp71
-rw-r--r--libopie2/opiepim/core/otodoaccess.h79
4 files changed, 180 insertions, 25 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 36f5a99..31ab516 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -11,13 +11,13 @@
/**
* Thats the frontend to our OPIE PIM
* Library. Either you want to use it's
* interface or you want to implement
* your own Access lib
- * Just create a OPimRecord and inherit from
+ * Just create a OPimRecord and inherit from
* the plugins
*/
template <class T = OPimRecord >
class OPimAccessTemplate : public OTemplateBase<T> {
public:
@@ -33,81 +33,82 @@ public:
/**
* c'tor BackEnd
*/
OPimAccessTemplate( BackEnd* end);
virtual ~OPimAccessTemplate();
-
+
/**
* load from the backend
*/
- virtual void load();
-
+ virtual bool load();
+
/**
* reload from the backend
*/
- virtual void reload();
-
+ virtual bool reload();
+
/**
- * save to the backend
+ * save to the backend
*/
- virtual void save();
+ virtual bool save();
/**
* if the resource was changed externally
*/
bool wasChangedExternally()const;
-
+
/**
* return a List of records
* you can iterate over them
*/
virtual List allRecords()const;
-
+
/**
- * queryByExample
+ * queryByExample
*/
virtual List queryByExample( const T& t, int sortOrder );
-
+
/**
* find the OPimRecord uid
*/
- virtual T find( int uid );
+ virtual T find( int uid )const;
/* invalidate cache here */
/**
* clears the backend and invalidates the backend
*/
virtual void clear() ;
-
+
/**
* add T to the backend
*/
virtual bool add( const T& t ) ;
/* only the uid matters */
/**
* remove T from the backend
*/
virtual bool remove( const T& t );
-
+
/**
* remove the OPimRecord with uid
*/
virtual bool remove( int uid );
-
+
/**
* replace T from backend
*/
virtual bool replace( const T& t) ;
protected:
/**
* invalidate the cache
*/
void invalidateCache();
-
+
+ void setBackEnd( BackEnd* end );
/**
* returns the backend
*/
BackEnd* backEnd();
BackEnd* m_backEnd;
@@ -122,22 +123,22 @@ OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
template <class T>
OPimAccessTemplate<T>::~OPimAccessTemplate() {
qWarning("~OPimAccessTemplate<T>");
delete m_backEnd;
}
template <class T>
-void OPimAccessTemplate<T>::load() {
- m_backEnd->load();
+bool OPimAccessTemplate<T>::load() {
+ return m_backEnd->load();
}
template <class T>
-void OPimAccessTemplate<T>::reload() {
- m_backEnd->reload();
+bool OPimAccessTemplate<T>::reload() {
+ return m_backEnd->reload();
}
template <class T>
-void OPimAccessTemplate<T>::save() {
- m_backEnd->save();
+bool OPimAccessTemplate<T>::save() {
+ return m_backEnd->save();
}
template <class T>
OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
QArray<int> ints = m_backEnd->allRecords();
List lis(ints, this );
return lis;
@@ -148,13 +149,13 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
List lis(ints, this );
return lis;
}
template <class T>
-T OPimAccessTemplate<T>::find( int uid ) {
+T OPimAccessTemplate<T>::find( int uid ) const{
T t = m_backEnd->find( uid );
return t;
}
template <class T>
void OPimAccessTemplate<T>::clear() {
invalidateCache();
@@ -185,7 +186,11 @@ OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
return m_backEnd;
}
template <class T>
bool OPimAccessTemplate<T>::wasChangedExternally()const {
return false;
}
+template <class T>
+void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
+ m_backEnd = end;
+}
#endif
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h
index add1de4..f71417b 100644
--- a/libopie2/opiepim/core/otemplatebase.h
+++ b/libopie2/opiepim/core/otemplatebase.h
@@ -10,12 +10,12 @@ template <class T = OPimRecord>
class OTemplateBase {
public:
OTemplateBase() {
};
virtual ~OTemplateBase() {
}
- virtual T find( int uid ) = 0;
+ virtual T find( int uid )const = 0;
};
#endif
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
new file mode 100644
index 0000000..a65cf5c
--- a/dev/null
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -0,0 +1,71 @@
+#include <qdatetime.h>
+
+#include <qpe/alarmserver.h>
+
+#include "otodoaccessxml.h"
+#include "otodoaccess.h"
+
+
+OTodoAccess::OTodoAccess( OTodoAccessBackend* end )
+ : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
+{
+ if (end == 0l )
+ m_todoBackEnd = new OTodoAccessXML( "Todolist" );
+
+ setBackEnd( m_todoBackEnd );
+}
+OTodoAccess::~OTodoAccess() {
+ qWarning("~OTodoAccess");
+}
+void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
+ QValueList<OTodo>::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ replace( (*it) );
+ }
+}
+OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
+ const QDate& end,
+ bool includeNoDates ) {
+ QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
+
+ List lis( ints, this );
+ return lis;
+}
+OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
+ bool includeNoDates ) {
+ return effectiveToDos( start, QDate::currentDate(),
+ includeNoDates );
+}
+OTodoAccess::List OTodoAccess::overDue() {
+ List lis( m_todoBackEnd->overDue(), this );
+ return lis;
+}
+void OTodoAccess::addAlarm( const OTodo& event) {
+ if (!event.hasAlarmDateTime() )
+ return;
+
+ QDateTime now = QDateTime::currentDateTime();
+ QDateTime schedule = event.alarmDateTime();
+
+ if ( schedule > now ){
+ AlarmServer::addAlarm( schedule,
+ "QPE/Application/todolist",
+ "alarm(QDateTime,int)", event.uid() );
+
+ }
+}
+void OTodoAccess::delAlarm( int uid) {
+
+ QDateTime schedule; // Create null DateTime
+
+ // I hope this will remove all scheduled alarms
+ // with the given uid !?
+ // If not: I have to rethink how to remove already
+ // scheduled events... (se)
+ // it should be fine -zecke
+ qWarning("Removing alarm for event with uid %d", uid );
+ AlarmServer::deleteAlarm( schedule ,
+ "QPE/Application/todolist",
+ "alarm(QDateTime,int)", uid );
+}
+
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
new file mode 100644
index 0000000..c43efe9
--- a/dev/null
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -0,0 +1,79 @@
+#ifndef OPIE_TODO_ACCESS_H
+#define OPIE_TODO_ACCESS_H
+
+#include <qobject.h>
+#include <qvaluelist.h>
+
+#include "otodo.h"
+#include "otodoaccessbackend.h"
+#include "opimaccesstemplate.h"
+
+
+/**
+ * OTodoAccess
+ * the class to get access to
+ * the todolist
+ */
+class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
+ Q_OBJECT
+public:
+ /**
+ * if you use 0l
+ * the default resource will be
+ * icked up
+ */
+ OTodoAccess( OTodoAccessBackend* = 0l);
+ ~OTodoAccess();
+
+
+ /* our functions here */
+ /**
+ * include todos from start to end
+ * includeNoDates whether or not to include
+ * events with no dates
+ */
+ List effectiveToDos( const QDate& start,
+ const QDate& end,
+ bool includeNoDates = true );
+
+ /**
+ * start
+ * end date taken from the currentDate()
+ */
+ List effectiveToDos( const QDate& start,
+ bool includeNoDates = true );
+
+
+ /**
+ * return overdue OTodos
+ */
+ List overDue();
+ /**
+ * merge a list of OTodos into
+ * the resource
+ */
+ void mergeWith( const QValueList<OTodo>& );
+
+ /**
+ * add an Alarm to the AlarmServer
+ */
+ void addAlarm( const OTodo& );
+
+ /**
+ * delete an alarm with the uid from
+ * the alarm server
+ */
+ void delAlarm( int uid );
+
+signals:
+ /**
+ * if the OTodoAccess was changed
+ */
+ void signalChanged( const OTodoAccess* );
+private:
+ OTodoAccessBackend* m_todoBackEnd;
+ class OTodoAccessPrivate;
+ OTodoAccessPrivate* d;
+};
+
+#endif